BxTimelineConfig.php 19 KB

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