BxTimelineConfig.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolPrivacy');
  12. class BxTimelineConfig extends BxBaseModNotificationsConfig
  13. {
  14. protected $_aTypeToFormDisplay;
  15. protected $_bAllowEdit;
  16. protected $_bAllowDelete;
  17. protected $_bShowAll;
  18. protected $_bCountAllViews;
  19. protected $_bCacheItem;
  20. protected $_sCacheItemEngine;
  21. protected $_iCacheItemLifetime;
  22. protected $_bCacheList;
  23. protected $_iRssLength;
  24. protected $_iLiveUpdateLength;
  25. protected $_iCharsDisplayMaxTitle;
  26. protected $_sVideosAutoplay;
  27. protected $_iPreloadComments;
  28. protected $_iPreloadCommentsMax;
  29. protected $_bHot;
  30. protected $_iHotInterval;
  31. protected $_bEditorToolbar;
  32. protected $_bUnhideRestored;
  33. protected $_sStorageObject;
  34. protected $_sTranscoderObjectPreview;
  35. protected $_sTranscoderObjectView;
  36. protected $_aPhotoUploaders;
  37. protected $_aVideoUploaders;
  38. protected $_sMenuItemManage;
  39. protected $_sMenuItemActions;
  40. protected $_aRepostDefaults;
  41. protected $_iTimelineVisibilityThreshold;
  42. protected $_aPregPatterns;
  43. /**
  44. * Constructor
  45. */
  46. public function __construct($aModule)
  47. {
  48. parent::__construct($aModule);
  49. $this->CNF = array (
  50. 'ICON' => 'far clock col-green1',
  51. // database tables
  52. 'TABLE_ENTRIES' => $aModule['db_prefix'] . 'events',
  53. // database fields
  54. 'FIELD_ID' => 'id',
  55. 'FIELD_OWNER_ID' => 'owner_id',
  56. 'FIELD_OBJECT_ID' => 'object_id', //Note. For 'Direct Timeline Posts' this field contains post's author profile ID.
  57. 'FIELD_OBJECT_PRIVACY_VIEW' => 'object_privacy_view',
  58. 'FIELD_ADDED' => 'date',
  59. 'FIELD_TITLE' => 'title',
  60. 'FIELD_TEXT' => 'description',
  61. 'FIELD_ANONYMOUS' => 'anonymous',
  62. 'FIELD_CONTROLS' => 'controls',
  63. 'FIELD_LOCATION_PREFIX' => 'location',
  64. // page URIs
  65. 'URI_VIEW_LIST' => 'timeline-view',
  66. 'URI_VIEW_ENTRY' => 'item',
  67. 'URL_HOME' => 'page.php?i=timeline-view-home',
  68. // objects
  69. 'OBJECT_STORAGE' => $this->_sName . '_photos',
  70. 'OBJECT_GRID_ADMINISTRATION' => $this->_sName . '_administration',
  71. 'OBJECT_IMAGES_TRANSCODER_PREVIEW' => $this->_sName . '_photos_preview',
  72. 'OBJECT_MENU_ENTRY_ATTACHMENTS' => $this->_sName . '_menu_post_attachments',
  73. 'OBJECT_METATAGS' => $this->_sName,
  74. 'OBJECT_COMMENTS' => $this->_sName,
  75. 'OBJECT_VIEWS' => $this->_sName,
  76. 'OBJECT_VOTES' => $this->_sName,
  77. 'OBJECT_SCORES' => $this->_sName,
  78. 'OBJECT_REPORTS' => $this->_sName,
  79. // some language keys
  80. 'T' => array (
  81. 'txt_sample_single' => '_bx_timeline_txt_sample',
  82. 'txt_sample_single_ext' => '_bx_timeline_txt_sample_ext',
  83. 'txt_sample_comment_single' => '_bx_timeline_txt_sample_comment_single',
  84. 'txt_sample_vote_single' => '_bx_timeline_txt_sample_vote_single',
  85. 'txt_sample_with_link' => '_bx_timeline_txt_sample_with_link',
  86. 'txt_sample_with_image' => '_bx_timeline_txt_sample_with_image',
  87. 'txt_sample_with_video' => '_bx_timeline_txt_sample_with_video',
  88. 'txt_sample_with_media' => '_bx_timeline_txt_sample_with_media',
  89. 'grid_action_err_delete' => '_bx_timeline_grid_action_err_delete',
  90. 'grid_txt_account_manager' => '_bx_timeline_grid_txt_account_manager',
  91. ),
  92. );
  93. $this->_aTypeToFormDisplay = array(
  94. BX_BASE_MOD_NTFS_TYPE_OWNER => 'form_display_post_add_profile',
  95. BX_BASE_MOD_NTFS_TYPE_PUBLIC => 'form_display_post_add_public',
  96. BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS => 'form_display_post_add'
  97. );
  98. $this->_aPrefixes = array(
  99. 'style' => 'bx-tl',
  100. 'language' => '_bx_timeline',
  101. 'option' => 'bx_timeline_',
  102. 'common_post' => 'timeline_common_',
  103. 'cache_item' => 'bx_timeline_item_'
  104. );
  105. $this->_aObjects = array_merge($this->_aObjects, array(
  106. 'comment' => $this->CNF['OBJECT_COMMENTS'],
  107. 'view' => $this->CNF['OBJECT_VIEWS'],
  108. 'vote' => $this->CNF['OBJECT_VOTES'],
  109. 'score' => $this->CNF['OBJECT_SCORES'],
  110. 'report' => $this->CNF['OBJECT_REPORTS'],
  111. 'metatags' => $this->_sName,
  112. 'storage_photos' => $this->CNF['OBJECT_STORAGE'],
  113. 'storage_videos' => $this->_sName . '_videos',
  114. 'transcoder_photos_preview' => $this->CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'],
  115. 'transcoder_photos_view' => $this->_sName . '_photos_view',
  116. 'transcoder_photos_medium' => $this->_sName . '_photos_medium',
  117. 'transcoder_photos_big' => $this->_sName . '_photos_big',
  118. 'transcoder_videos_poster' => $this->_sName . '_videos_poster',
  119. 'transcoder_videos_mp4' => $this->_sName . '_videos_mp4',
  120. 'transcoder_videos_mp4_hd' => $this->_sName . '_videos_mp4_hd',
  121. 'page_item_brief' => $this->_sName . '_item_brief',
  122. 'menu_item_manage' => $this->_sName . '_menu_item_manage',
  123. 'menu_item_actions' => $this->_sName . '_menu_item_actions',
  124. 'menu_item_meta' => $this->_sName . '_menu_item_meta',
  125. 'menu_post_attachments' => $this->CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'],
  126. 'form_post' => $this->_sName . '_post',
  127. 'form_attach_link' => $this->_sName . '_attach_link',
  128. 'form_display_post_add' => $this->_sName . '_post_add',
  129. 'form_display_post_add_public' => $this->_sName . '_post_add_public',
  130. 'form_display_post_add_profile' => $this->_sName . '_post_add_profile',
  131. 'form_display_post_edit' => $this->_sName . '_post_edit',
  132. 'form_display_attach_link_add' => $this->_sName . '_attach_link_add'
  133. ));
  134. $this->_aHandlerDescriptor = array('module_name' => '', 'module_method' => '', 'module_class' => '', 'groupable' => '', 'group_by' => '');
  135. $this->_sHandlersMethod = 'get_timeline_data';
  136. $this->_aPhotoUploaders = array($this->_sName . '_simple_photo');
  137. $this->_aVideoUploaders = array($this->_sName . '_simple_video');
  138. $this->_bJsMode = false;
  139. $this->_aJsClasses = array(
  140. 'main' => 'BxTimelineMain',
  141. 'view' => 'BxTimelineView',
  142. 'post' => 'BxTimelinePost',
  143. 'repost' => 'BxTimelineRepost',
  144. 'manage_tools' => 'BxTimelineManageTools'
  145. );
  146. $this->_aJsObjects = array(
  147. 'view' => 'oTimelineView',
  148. 'post' => 'oTimelinePost',
  149. 'repost' => 'oTimelineRepost',
  150. 'manage_tools' => 'oBxTimelineManageTools'
  151. );
  152. $this->_aGridObjects = array(
  153. 'administration' => $this->CNF['OBJECT_GRID_ADMINISTRATION']
  154. );
  155. $sHp = str_replace('_', '-', $this->_sName);
  156. $sHpT = BX_TIMELINE_VIEW_TIMELINE;
  157. $sHpO = BX_TIMELINE_VIEW_OUTLINE;
  158. $this->_aHtmlIds = array(
  159. 'view' => array(
  160. 'edit_form' => $sHp . '-edit-',
  161. 'menu_popup' => $sHp . '-menu-popup-',
  162. 'video_iframe' => $sHp . '-video-iframe-',
  163. 'video' => $sHp . '-video-',
  164. 'live_update_popup' => $sHp . '-live-update-popup-',
  165. ),
  166. 'post' => array(
  167. 'attach_link_popup' => $sHp . '-attach-link-popup',
  168. 'attach_link_form_field' => $sHp . '-attach-link-form_field',
  169. 'attach_link_item' => $sHp . '-attach-link-item-',
  170. 'textarea' => $sHp . '-textarea-',
  171. 'main_' . $sHpT => $sHp . '-' . $sHpT,
  172. 'main_' . $sHpO => $sHp . '-' . $sHpO,
  173. ),
  174. 'repost' => array(
  175. 'main' => $sHp . '-repost-',
  176. 'counter' => $sHp . '-repost-counter-',
  177. 'by_popup' => $sHp . '-repost-by-',
  178. )
  179. );
  180. $this->_aRepostDefaults = array(
  181. 'show_do_repost_as_button' => false,
  182. 'show_do_repost_as_button_small' => false,
  183. 'show_do_repost_image' => false,
  184. 'show_do_repost_icon' => true,
  185. 'show_do_repost_text' => false,
  186. 'show_counter' => true,
  187. //--- Images
  188. 'image_do_repost' => '',
  189. //--- Icons
  190. 'icon_do_repost' => 'sync-alt',
  191. //--- Texts
  192. 'text_do_repost' => '_bx_timeline_txt_do_repost',
  193. //--- Templates
  194. 'template_do_repost_label' => '',
  195. 'template_do_repost_label_name' => 'repost_do_repost_label.html',
  196. );
  197. $this->_iTimelineVisibilityThreshold = 0;
  198. $this->_aPregPatterns = array(
  199. "meta_title" => "/<title>(.*)<\/title>/",
  200. "meta_description" => "/<meta[\s]+[^>]*?name[\s]?=[\s\"\']+description[\s\"\']+content[\s]?=[\s\"\']+(.*?)[\"\']+.*?>/",
  201. "url" => "/(([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?/"
  202. );
  203. }
  204. public function init(&$oDb)
  205. {
  206. parent::init($oDb);
  207. $sOptionPrefix = $this->getPrefix('option');
  208. $this->_bAllowEdit = getParam($sOptionPrefix . 'enable_edit') == 'on';
  209. $this->_bAllowDelete = getParam($sOptionPrefix . 'enable_delete') == 'on';
  210. $this->_bShowAll = getParam($sOptionPrefix . 'enable_show_all') == 'on';
  211. $this->_bCountAllViews = getParam($sOptionPrefix . 'enable_count_all_views') == 'on';
  212. $this->_bCacheItem = getParam($sOptionPrefix . 'enable_cache_item') == 'on';
  213. $this->_sCacheItemEngine = getParam($sOptionPrefix . 'cache_item_engine');
  214. $this->_iCacheItemLifetime = (int)getParam($sOptionPrefix . 'cache_item_lifetime');
  215. $this->_bCacheList = getParam($sOptionPrefix . 'enable_cache_list') == 'on';
  216. $this->_aPerPage = array(
  217. 'default' => (int)getParam($sOptionPrefix . 'events_per_page'),
  218. 'profile' => (int)getParam($sOptionPrefix . 'events_per_page_profile'),
  219. 'account' => (int)getParam($sOptionPrefix . 'events_per_page_account'),
  220. 'home' => (int)getParam($sOptionPrefix . 'events_per_page_home')
  221. );
  222. $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');
  223. $this->_iLiveUpdateLength = 10;
  224. $this->_iCharsDisplayMaxTitle = 20;
  225. $this->_sVideosAutoplay = getParam($sOptionPrefix . 'videos_autoplay');
  226. $this->_iPreloadCommentsMax = 7;
  227. $this->_iPreloadComments = (int)getParam($sOptionPrefix . 'preload_comments');
  228. if($this->_iPreloadComments > $this->_iPreloadCommentsMax)
  229. $this->_iPreloadComments = $this->_iPreloadCommentsMax;
  230. $this->_bHot = getParam($sOptionPrefix . 'enable_hot') == 'on';
  231. $this->_iHotInterval = (int)getParam($sOptionPrefix . 'hot_interval');
  232. $this->_bEditorToolbar = getParam($sOptionPrefix . 'enable_editor_toolbar') == 'on';
  233. $this->_bUnhideRestored = false;
  234. }
  235. protected function getNameView($aParams, $bWithOwner = false, $sGlue = '_')
  236. {
  237. $aAddons = array();
  238. if(!empty($aParams['name']))
  239. $aAddons[] = $aParams['name'];
  240. else {
  241. if(!empty($aParams['view']))
  242. $aAddons[] = $aParams['view'];
  243. if(!empty($aParams['type']))
  244. $aAddons[] = $aParams['type'];
  245. }
  246. if($bWithOwner)
  247. $aAddons[] = $aParams['owner_id'];
  248. return !empty($aAddons) ? implode('_', $aAddons) : '';
  249. }
  250. /**
  251. * Generates unique JS object name for View events block.
  252. *
  253. * @param array $aParams - an array with browsing params received in View block service method
  254. * @return string with JS object name
  255. */
  256. public function getJsObjectView($aParams = array())
  257. {
  258. return parent::getJsObject('view') . bx_gen_method_name($this->getNameView($aParams));
  259. }
  260. public function getHtmlIdView($sKey, $aParams, $bWhole = true)
  261. {
  262. $sDiv = '_';
  263. return str_replace($sDiv, '-', $this->_sName . $sDiv . $sKey . $sDiv . $this->getNameView($aParams) . (!$bWhole ? $sDiv : ''));
  264. }
  265. public function isAllowEdit()
  266. {
  267. return $this->_bAllowEdit;
  268. }
  269. public function isAllowDelete()
  270. {
  271. return $this->_bAllowDelete;
  272. }
  273. public function isShowAll()
  274. {
  275. return $this->_bShowAll;
  276. }
  277. public function isCountAllViews()
  278. {
  279. return $this->_bCountAllViews;
  280. }
  281. public function isHot()
  282. {
  283. return $this->_bHot;
  284. }
  285. public function isEditorToolbar()
  286. {
  287. return $this->_bEditorToolbar;
  288. }
  289. public function isUnhideRestored()
  290. {
  291. return $this->_bUnhideRestored;
  292. }
  293. public function isCacheItem()
  294. {
  295. return $this->_bCacheItem;
  296. }
  297. public function isCacheList()
  298. {
  299. return $this->_bCacheList;
  300. }
  301. public function getCacheItemEngine()
  302. {
  303. return $this->_sCacheItemEngine;
  304. }
  305. public function getCacheItemLifetime()
  306. {
  307. return $this->_iCacheItemLifetime;
  308. }
  309. public function getCacheItemKey($iId, $sPostfix = '')
  310. {
  311. return $this->getPrefix('cache_item') . $iId . (!empty($sPostfix) ? '_' . $sPostfix : '') . '.php';
  312. }
  313. public function getPostFormDisplay($sType)
  314. {
  315. if(empty($sType) || !array_key_exists($sType, $this->_aTypeToFormDisplay))
  316. $sType = BX_TIMELINE_TYPE_DEFAULT;
  317. return $this->_aTypeToFormDisplay[$sType];
  318. }
  319. public function getUploaders($sType)
  320. {
  321. $aResult = array();
  322. switch($sType) {
  323. case 'photo':
  324. $aResult = $this->_aPhotoUploaders;
  325. break;
  326. case 'video':
  327. $aResult = $this->_aVideoUploaders;
  328. break;
  329. }
  330. return $aResult;
  331. }
  332. public function getRssLength()
  333. {
  334. return $this->_iRssLength;
  335. }
  336. public function getLiveUpdateLength()
  337. {
  338. return $this->_iLiveUpdateLength;
  339. }
  340. public function getCharsDisplayMaxTitle()
  341. {
  342. return $this->_iCharsDisplayMaxTitle;
  343. }
  344. public function getVideosAutoplay()
  345. {
  346. return $this->_sVideosAutoplay;
  347. }
  348. public function getPreloadComments()
  349. {
  350. return $this->_iPreloadComments;
  351. }
  352. public function getHotInterval()
  353. {
  354. return $this->_iHotInterval;
  355. }
  356. public function getRepostDefaults()
  357. {
  358. return $this->_aRepostDefaults;
  359. }
  360. public function getPregPattern($sType)
  361. {
  362. return $this->_aPregPatterns[$sType];
  363. }
  364. /**
  365. * Ancillary functions
  366. */
  367. public function getTitle($s, $mixedProfile = false)
  368. {
  369. if($mixedProfile !== false) {
  370. if(is_numeric($mixedProfile))
  371. $mixedProfile = BxDolProfile::getInstanceMagic((int)$mixedProfile);
  372. if($mixedProfile instanceof BxDolProfile)
  373. $s = bx_replace_markers($s, array(
  374. 'profile_name' => $mixedProfile->getDisplayName()
  375. ));
  376. }
  377. return strmaxtextlen($s, $this->getCharsDisplayMaxTitle(), '...');
  378. }
  379. public function getTitleDefault($bL, $bP, $bV)
  380. {
  381. $sResult = '';
  382. if($bL && !$bP && !$bV)
  383. $sResult = 'link';
  384. else if(!$bL && $bP && !$bV)
  385. $sResult = 'image';
  386. else if(!$bL && !$bP && $bV)
  387. $sResult = 'video';
  388. else
  389. $sResult = 'media';
  390. return $this->CNF['T']['txt_sample_with_' . $sResult];
  391. }
  392. public function getViewUrl($iOwnerId)
  393. {
  394. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  395. 'i' => $this->CNF['URI_VIEW_LIST'],
  396. 'id' => $iOwnerId
  397. ));
  398. }
  399. public function getHomeViewUrl()
  400. {
  401. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->CNF['URL_HOME']);
  402. }
  403. public function getItemViewUrl($aEvent)
  404. {
  405. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  406. 'i' => $this->CNF['URI_VIEW_ENTRY'],
  407. 'id' => $aEvent['id']
  408. ));
  409. }
  410. public function getLiveUpdateKey($aParams)
  411. {
  412. return $this->getName() . '_live_update_' . $this->getNameView($aParams, true);
  413. }
  414. public function isCommon($sType, $sAction)
  415. {
  416. return !$this->isSystem($sType, $sAction);
  417. }
  418. public function isSystem($sType, $sAction)
  419. {
  420. $sPrefix = $this->getPrefix('common_post');
  421. return strpos($sType, $sPrefix) === false && !empty($sAction);
  422. }
  423. public function getSystemData(&$aEvent, $aBrowseParams = array())
  424. {
  425. $sHandler = $aEvent['type'] . '_' . $aEvent['action'];
  426. if(!$this->isHandler($sHandler))
  427. return false;
  428. $aHandler = $this->getHandlers($sHandler);
  429. if(empty($aHandler['module_name']) || empty($aHandler['module_class']) || empty($aHandler['module_method']))
  430. return false;
  431. return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent, $aBrowseParams), $aHandler['module_class']);
  432. }
  433. public function getSystemDataByDescriptor($sType, $sAction, $iObjectId)
  434. {
  435. $aDescriptor = array(
  436. 'type' => $sType,
  437. 'action' => $sAction,
  438. 'object_id' => $iObjectId
  439. );
  440. return $this->getSystemData($aDescriptor);
  441. }
  442. public function isEqualUrls($sUrl1, $sUrl2)
  443. {
  444. $sUrl1 = trim($sUrl1, "/");
  445. $sUrl2 = trim($sUrl2, "/");
  446. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  447. }
  448. public function addBrowseParams($sUrl, $aParams, $sKey = 'bp')
  449. {
  450. return bx_append_url_params($sUrl, array($sKey => urlencode(base64_encode(serialize($aParams)))));
  451. }
  452. public function getBrowseParams($sValue)
  453. {
  454. return unserialize(base64_decode(urldecode($sValue)));
  455. }
  456. }
  457. /** @} */