BxTimelineConfig.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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 $_bRepostOwnActions;
  20. protected $_bHideUponDelete;
  21. protected $_bCacheItem;
  22. protected $_sCacheItemEngine;
  23. protected $_iCacheItemLifetime;
  24. protected $_bCacheTable;
  25. protected $_iCacheTableInterval;
  26. protected $_aCacheTableCheckFields;
  27. protected $_bInfScroll;
  28. protected $_iInfScrollAutoPreloads;
  29. protected $_iRssLength;
  30. protected $_iLiveUpdateLength;
  31. protected $_iCharsDisplayMinTitle;
  32. protected $_iCharsDisplayMaxTitle;
  33. protected $_bBriefCards;
  34. protected $_aBriefCardsTags;
  35. protected $_sVideosPreload;
  36. protected $_sVideosAutoplay;
  37. protected $_iPreloadComments;
  38. protected $_iPreloadCommentsMax;
  39. protected $_bJumpTo;
  40. protected $_bSortByReaction;
  41. protected $_bSortByUnread;
  42. protected $_sAttachmentsLayout;
  43. protected $_bHot;
  44. protected $_iHotInterval;
  45. protected $_iHotThresholdContent;
  46. protected $_iHotThresholdComment;
  47. protected $_iHotThresholdVote;
  48. protected $_aHotSources;
  49. protected $_aHotSourcesList;
  50. protected $_aHotList;
  51. protected $_bEditorToolbar;
  52. protected $_bEditorAutoAttach;
  53. protected $_iLimitAttachLinks;
  54. protected $_bUnhideRestored;
  55. protected $_sStorageObject;
  56. protected $_sTranscoderObjectPreview;
  57. protected $_sTranscoderObjectView;
  58. protected $_aPhotoUploaders;
  59. protected $_aVideoUploaders;
  60. protected $_aItemToUploader;
  61. protected $_sMenuItemManage;
  62. protected $_sMenuItemActions;
  63. protected $_aRepostDefaults;
  64. protected $_iTimelineVisibilityThreshold;
  65. protected $_aPregPatterns;
  66. protected $_sSessionKeyType;
  67. /**
  68. * Constructor
  69. */
  70. public function __construct($aModule)
  71. {
  72. parent::__construct($aModule);
  73. $this->CNF = array (
  74. 'ICON' => 'far clock col-green1',
  75. // database tables
  76. 'TABLE_ENTRIES' => $aModule['db_prefix'] . 'events',
  77. // database fields
  78. 'FIELD_ID' => 'id',
  79. 'FIELD_AUTHOR' => 'object_owner_id',
  80. 'FIELD_OWNER_ID' => 'owner_id',
  81. 'FIELD_SYSTEM' => 'system',
  82. 'FIELD_OBJECT_ID' => 'object_id', //Note. For 'Direct Timeline Posts' ('system' db field == 0) this field contains post's author profile ID.
  83. 'FIELD_OBJECT_OWNER_ID' => 'object_owner_id',
  84. 'FIELD_OBJECT_PRIVACY_VIEW' => 'object_privacy_view',
  85. 'FIELD_CF' => 'object_cf',
  86. 'FIELD_ADDED' => 'date',
  87. 'FIELD_PUBLISHED' => 'published',
  88. 'FIELD_TITLE' => 'title',
  89. 'FIELD_TEXT' => 'description',
  90. 'FIELD_ATTACHMENTS' => 'attachments',
  91. 'FIELD_LINK' => 'link',
  92. 'FIELD_PHOTO' => 'photo',
  93. 'FIELD_VIDEO' => 'video',
  94. 'FIELD_FILE' => 'file',
  95. 'FIELD_STATUS' => 'status',
  96. 'FIELD_STATUS_ADMIN' => 'status_admin',
  97. 'FIELD_STICKED' => 'sticked',
  98. 'FIELD_DATE' => 'date',
  99. 'FIELD_REACTED' => 'reacted',
  100. 'FIELD_ANONYMOUS' => 'anonymous',
  101. 'FIELD_CONTROLS' => 'controls',
  102. 'FIELD_LOCATION' => 'location',
  103. 'FIELD_LOCATION_PREFIX' => 'location',
  104. 'FIELDS_DELAYED_PROCESSING' => 'video', // can be array of fields or comma separated string of field names
  105. // page URIs
  106. 'URI_VIEW_LIST' => 'timeline-view',
  107. 'URI_VIEW_ENTRY' => 'item',
  108. 'URL_HOME' => 'page.php?i=timeline-view-home',
  109. // some params
  110. 'PARAM_AUTO_APPROVE' => $this->_sName . '_enable_auto_approve',
  111. // objects
  112. 'OBJECT_STORAGE' => $this->_sName . '_photos',
  113. 'OBJECT_STORAGE_VIDEOS' => $this->_sName . '_videos',
  114. 'OBJECT_STORAGE_FILES' => $this->_sName . '_files',
  115. 'OBJECT_IMAGES_TRANSCODER_PREVIEW' => $this->_sName . '_photos_preview',
  116. 'OBJECT_VIDEOS_TRANSCODER_PREVIEW' => $this->_sName . '_proxy_preview',
  117. 'OBJECT_VIDEOS_TRANSCODERS' => array(
  118. 'poster' => 'bx_timeline_videos_poster_view',
  119. 'poster_preview' => 'bx_timeline_videos_poster_preview',
  120. 'mp4' => 'bx_timeline_videos_mp4',
  121. 'mp4_hd' => 'bx_timeline_videos_mp4_hd'
  122. ),
  123. 'OBJECT_UPLOADER_PHOTO_SIMPLE' => $this->_sName . '_simple_photo',
  124. 'OBJECT_UPLOADER_PHOTO_HTML5' => $this->_sName . '_html5_photo',
  125. 'OBJECT_UPLOADER_VIDEO_SIMPLE' => $this->_sName . '_simple_video',
  126. 'OBJECT_UPLOADER_VIDEO_HTML5' => $this->_sName . '_html5_video',
  127. 'OBJECT_UPLOADER_VIDEO_RECORD' => $this->_sName . '_record_video',
  128. 'OBJECT_UPLOADER_FILE_HTML5' => $this->_sName . '_html5_file',
  129. 'OBJECT_UPLOADER_FILE_SIMPLE' => $this->_sName . '_simple_file',
  130. 'OBJECT_GRID_ADMINISTRATION' => $this->_sName . '_administration',
  131. 'OBJECT_GRID_COMMON' => $this->_sName . '_common',
  132. 'OBJECT_GRID_MUTE' => $this->_sName . '_mute',
  133. 'OBJECT_MENU_ENTRY_ATTACHMENTS' => $this->_sName . '_menu_post_attachments',
  134. 'OBJECT_METATAGS' => $this->_sName,
  135. 'OBJECT_COMMENTS' => $this->_sName,
  136. 'OBJECT_NOTES' => $this->_sName . '_notes',
  137. 'OBJECT_VIEWS' => $this->_sName,
  138. 'OBJECT_VOTES' => $this->_sName,
  139. 'OBJECT_REACTIONS' => $this->_sName . '_reactions',
  140. 'OBJECT_SCORES' => $this->_sName,
  141. 'OBJECT_REPORTS' => $this->_sName,
  142. 'OBJECT_PRIVACY_VIEW' => $this->_sName . '_privacy_view',
  143. 'OBJECT_CONNECTIONS_MUTE' => $this->_sName . '_mute',
  144. // some language keys
  145. 'T' => array (
  146. 'txt_status_deleted' => '_bx_timeline_txt_status_deleted',
  147. 'txt_sample_single' => '_bx_timeline_txt_sample',
  148. 'txt_sample_single_ext' => '_bx_timeline_txt_sample_ext',
  149. 'txt_sample_comment_single' => '_bx_timeline_txt_sample_comment_single',
  150. 'txt_sample_vote_single' => '_bx_timeline_txt_sample_vote_single',
  151. 'txt_sample_reaction_single' => '_bx_timeline_txt_sample_reaction_single',
  152. 'txt_sample_score_up_single' => '_bx_timeline_txt_sample_score_up_single',
  153. 'txt_sample_score_down_single' => '_bx_timeline_txt_sample_score_down_single',
  154. 'txt_sample_with_link' => '_bx_timeline_txt_sample_with_link',
  155. 'txt_sample_with_image' => '_bx_timeline_txt_sample_with_image',
  156. 'txt_sample_with_video' => '_bx_timeline_txt_sample_with_video',
  157. 'txt_sample_with_file' => '_bx_timeline_txt_sample_with_file',
  158. 'txt_sample_with_media' => '_bx_timeline_txt_sample_with_media',
  159. 'grid_action_err_delete' => '_bx_timeline_grid_action_err_delete',
  160. 'grid_txt_account_manager' => '_bx_timeline_grid_txt_account_manager',
  161. 'filter_item_active' => '_bx_timeline_grid_filter_item_title_adm_active',
  162. 'filter_item_hidden' => '_bx_timeline_grid_filter_item_title_adm_hidden',
  163. 'filter_item_pending' => '_bx_timeline_grid_filter_item_title_adm_pending',
  164. 'filter_item_select_one_filter1' => '_bx_timeline_grid_filter_item_title_adm_select_one_filter1',
  165. 'form_input_title_object_privacy_view' => '_bx_timeline_form_post_input_object_privacy_view',
  166. 'option_vp_auto' => '_bx_timeline_option_videos_preload_auto',
  167. 'option_vp_metadata' => '_bx_timeline_option_videos_preload_metadata',
  168. 'option_vp_none' => '_bx_timeline_option_videos_preload_none',
  169. 'option_vap_off' => '_bx_timeline_option_videos_autoplay_off',
  170. 'option_vap_on_mute' => '_bx_timeline_option_videos_autoplay_on_mute',
  171. 'option_vap_on' => '_bx_timeline_option_videos_autoplay_on',
  172. 'option_al_gallery' => '_bx_timeline_option_attachments_layout_gallery',
  173. 'option_al_showcase' => '_bx_timeline_option_attachments_layout_showcase',
  174. 'option_hs_content' => '_bx_timeline_option_hot_sources_content',
  175. 'option_hs_comment' => '_bx_timeline_option_hot_sources_comment',
  176. 'option_hs_vote' => '_bx_timeline_option_hot_sources_vote',
  177. ),
  178. );
  179. $this->_aTypeToFormDisplay = array(
  180. BX_BASE_MOD_NTFS_TYPE_OWNER => 'form_display_post_add_profile',
  181. BX_BASE_MOD_NTFS_TYPE_PUBLIC => 'form_display_post_add_public',
  182. BX_TIMELINE_TYPE_CHANNELS => 'form_display_post_add',
  183. BX_TIMELINE_TYPE_FEED => 'form_display_post_add',
  184. BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS => 'form_display_post_add'
  185. );
  186. $this->_aPrefixes = array(
  187. 'style' => 'bx-tl',
  188. 'language' => '_bx_timeline',
  189. 'option' => 'bx_timeline_',
  190. 'common_post' => 'timeline_common_',
  191. 'cache_list_hot' => 'bx_timeline_list_hot',
  192. 'cache_item' => 'bx_timeline_item_'
  193. );
  194. $this->_aObjects = array_merge($this->_aObjects, array(
  195. 'comment' => $this->CNF['OBJECT_COMMENTS'],
  196. 'view' => $this->CNF['OBJECT_VIEWS'],
  197. 'vote' => $this->CNF['OBJECT_VOTES'],
  198. 'reaction' => $this->CNF['OBJECT_REACTIONS'],
  199. 'score' => $this->CNF['OBJECT_SCORES'],
  200. 'report' => $this->CNF['OBJECT_REPORTS'],
  201. 'privacy_view' => $this->CNF['OBJECT_PRIVACY_VIEW'],
  202. 'metatags' => $this->_sName,
  203. 'storage_photos' => $this->CNF['OBJECT_STORAGE'],
  204. 'storage_videos' => $this->CNF['OBJECT_STORAGE_VIDEOS'],
  205. 'storage_files' => $this->CNF['OBJECT_STORAGE_FILES'],
  206. 'transcoder_photos_preview' => $this->CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'],
  207. 'transcoder_photos_view' => $this->_sName . '_photos_view',
  208. 'transcoder_photos_medium' => $this->_sName . '_photos_medium',
  209. 'transcoder_photos_big' => $this->_sName . '_photos_big',
  210. 'transcoder_videos_preview' => $this->CNF['OBJECT_VIDEOS_TRANSCODER_PREVIEW'],
  211. 'transcoder_videos_poster' => $this->CNF['OBJECT_VIDEOS_TRANSCODERS']['poster'],
  212. 'transcoder_videos_mp4' => $this->CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4'],
  213. 'transcoder_videos_mp4_hd' => $this->CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd'],
  214. 'transcoder_videos_photo_view' => $this->_sName . '_videos_photo_view',
  215. 'transcoder_videos_photo_big' => $this->_sName . '_videos_photo_big',
  216. 'page_item_brief' => $this->_sName . '_item_brief',
  217. 'menu_view' => $this->_sName . '_menu_view',
  218. 'menu_feeds' => $this->_sName . '_menu_feeds',
  219. 'menu_set_feeds' => $this->_sName . '_menu_feeds',
  220. 'menu_item_manage' => $this->_sName . '_menu_item_manage',
  221. 'menu_item_actions' => $this->_sName . '_menu_item_actions',
  222. 'menu_item_actions_all' => $this->_sName . '_menu_item_actions_all',
  223. 'menu_item_counters' => $this->_sName . '_menu_item_counters',
  224. 'menu_item_meta' => $this->_sName . '_menu_item_meta',
  225. 'menu_post_attachments' => $this->CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'],
  226. 'form_post' => $this->_sName . '_post',
  227. 'form_attach_link' => $this->_sName . '_attach_link',
  228. 'form_repost' => $this->_sName . '_repost',
  229. 'form_display_post_add' => $this->_sName . '_post_add',
  230. 'form_display_post_add_public' => $this->_sName . '_post_add_public',
  231. 'form_display_post_add_profile' => $this->_sName . '_post_add_profile',
  232. 'form_display_post_edit' => $this->_sName . '_post_edit',
  233. 'form_display_post_view' => $this->_sName . '_post_view',
  234. 'form_display_attach_link_add' => $this->_sName . '_attach_link_add',
  235. 'form_display_repost_with' => $this->_sName . '_repost_with',
  236. 'form_display_repost_to' => $this->_sName . '_repost_to',
  237. 'grid_mute' => $this->CNF['OBJECT_GRID_MUTE'],
  238. 'connection_mute' => $this->CNF['OBJECT_CONNECTIONS_MUTE'],
  239. ));
  240. $this->_aHandlerDescriptor = array('module_name' => '', 'module_method' => '', 'module_class' => '', 'groupable' => '', 'group_by' => '');
  241. $this->_sHandlersMethod = 'get_timeline_data';
  242. $this->_aPhotoUploaders = array($this->CNF['OBJECT_UPLOADER_PHOTO_SIMPLE']);
  243. $this->_aVideoUploaders = array($this->CNF['OBJECT_UPLOADER_VIDEO_SIMPLE']);
  244. $this->_aFilesUploaders = array($this->CNF['OBJECT_UPLOADER_FILE_SIMPLE']);
  245. $this->_aItemToUploader = array(
  246. 'add-photo-simple' => $this->CNF['OBJECT_UPLOADER_PHOTO_SIMPLE'],
  247. 'add-photo-html5' => $this->CNF['OBJECT_UPLOADER_PHOTO_HTML5'],
  248. 'add-video-simple' => $this->CNF['OBJECT_UPLOADER_VIDEO_SIMPLE'],
  249. 'add-video-html5' => $this->CNF['OBJECT_UPLOADER_VIDEO_HTML5'],
  250. 'add-video-record' => $this->CNF['OBJECT_UPLOADER_VIDEO_RECORD'],
  251. 'add-file-simple' => $this->CNF['OBJECT_UPLOADER_FILE_SIMPLE'],
  252. 'add-file-html5' => $this->CNF['OBJECT_UPLOADER_FILE_HTML5'],
  253. );
  254. $this->_bJsMode = false;
  255. $this->_aJsClasses = array(
  256. 'main' => 'BxTimelineMain',
  257. 'view' => 'BxTimelineView',
  258. 'post' => 'BxTimelinePost',
  259. 'repost' => 'BxTimelineRepost',
  260. 'manage_tools' => 'BxTimelineManageTools'
  261. );
  262. $this->_aJsObjects = array(
  263. 'view' => 'oTimelineView',
  264. 'post' => 'oTimelinePost',
  265. 'repost' => 'oTimelineRepost',
  266. 'manage_tools' => 'oBxTimelineManageTools'
  267. );
  268. $this->_aGridObjects = array(
  269. 'administration' => $this->CNF['OBJECT_GRID_ADMINISTRATION'],
  270. 'common' => $this->CNF['OBJECT_GRID_COMMON']
  271. );
  272. $sHp = str_replace('_', '-', $this->_sName);
  273. $sHpT = BX_TIMELINE_VIEW_TIMELINE;
  274. $sHpO = BX_TIMELINE_VIEW_OUTLINE;
  275. $this->_aHtmlIds = array(
  276. 'view' => array(
  277. 'edit_form' => $sHp . '-edit-',
  278. 'attach_link_form_field' => $sHp . '-attach-link-form-field-',
  279. 'menu_popup' => $sHp . '-menu-popup-',
  280. 'video_iframe' => $sHp . '-video-iframe-',
  281. 'video' => $sHp . '-video-',
  282. 'live_update_popup' => $sHp . '-live-update-popup-',
  283. ),
  284. 'post' => array(
  285. 'attach_link_popup' => $sHp . '-attach-link-popup',
  286. 'attach_link_form_field' => $sHp . '-attach-link-form-field-',
  287. 'attach_link_item' => $sHp . '-attach-link-item-',
  288. 'textarea' => $sHp . '-textarea-',
  289. 'main_' . $sHpT => $sHp . '-' . $sHpT,
  290. 'main_' . $sHpO => $sHp . '-' . $sHpO,
  291. ),
  292. 'repost' => array(
  293. 'main' => $sHp . '-repost-',
  294. 'counter' => $sHp . '-repost-counter-',
  295. 'by_popup' => $sHp . '-repost-by-',
  296. 'with_popup' => $sHp . '-repost-with',
  297. 'to_popup' => $sHp . '-repost-to',
  298. )
  299. );
  300. $this->_aRepostDefaults = array(
  301. 'do' => 'repost',
  302. 'show_do_repost_as_button' => false,
  303. 'show_do_repost_as_button_small' => false,
  304. 'show_do_repost_icon' => true,
  305. 'show_do_repost_text' => false,
  306. //--- Counter
  307. 'show_counter_label_icon' => false,
  308. 'show_counter_label_text' => true,
  309. 'show_counter' => true,
  310. //--- JS script
  311. 'show_script' => true,
  312. //--- Icons
  313. 'icon_do_repost' => 'redo',
  314. 'icon_do_repost_with' => 'redo',
  315. 'icon_do_repost_to' => 'redo',
  316. //--- Texts
  317. 'text_do_repost' => '_bx_timeline_txt_do_repost',
  318. 'text_do_repost_with' => '_bx_timeline_txt_do_repost_with',
  319. 'text_do_repost_to' => '_bx_timeline_txt_do_repost_to',
  320. //--- Templates
  321. 'template_do_repost_label' => '',
  322. 'template_do_repost_label_name' => 'repost_do_repost_label.html',
  323. );
  324. $this->_iTimelineVisibilityThreshold = 0;
  325. $this->_aPregPatterns = array(
  326. "meta_title" => "/<title>(.*)<\/title>/",
  327. "meta_description" => "/<meta[\s]+[^>]*?name[\s]?=[\s\"\']+description[\s\"\']+content[\s]?=[\s\"\']+(.*?)[\"\']+.*?>/",
  328. "url" => "/(([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%#\/\.\w\-_!\(\)]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?/"
  329. );
  330. $this->_aBriefCardsTags = array('a', 'b', 'i');
  331. $this->_sSessionKeyType = $this->_sName . '_type_';
  332. $this->_aHotSourcesList = [
  333. BX_TIMELINE_HFS_CONTENT,
  334. BX_TIMELINE_HFS_COMMENT,
  335. BX_TIMELINE_HFS_VOTE
  336. ];
  337. }
  338. public function init(&$oDb)
  339. {
  340. parent::init($oDb);
  341. $sOptionPrefix = $this->getPrefix('option');
  342. $this->_bAllowEdit = getParam($sOptionPrefix . 'enable_edit') == 'on';
  343. $this->_bAllowDelete = getParam($sOptionPrefix . 'enable_delete') == 'on';
  344. $this->_bShowAll = getParam($sOptionPrefix . 'enable_show_all') == 'on';
  345. $this->_bCountAllViews = getParam($sOptionPrefix . 'enable_count_all_views') == 'on';
  346. $this->_bRepostOwnActions = getParam($sOptionPrefix . 'enable_repost_own_actions') == 'on';
  347. $this->_bHideUponDelete = getParam($sOptionPrefix . 'enable_hide_upon_delete') == 'on';
  348. $this->_bCacheItem = getParam($sOptionPrefix . 'enable_cache_item') == 'on';
  349. $this->_sCacheItemEngine = getParam($sOptionPrefix . 'cache_item_engine');
  350. $this->_iCacheItemLifetime = (int)getParam($sOptionPrefix . 'cache_item_lifetime');
  351. $this->_bCacheTable = getParam($sOptionPrefix . 'enable_cache_table') == 'on';
  352. $this->_iCacheTableInterval = (int)getParam($sOptionPrefix . 'cache_table_interval');
  353. $this->_aCacheTableCheckFields = [
  354. 'date' => 'date',
  355. 'reacted' => 'date',
  356. 'sticked' => 'flag'
  357. ];
  358. $this->_aPerPage = array(
  359. 'default' => (int)getParam($sOptionPrefix . 'events_per_page'),
  360. 'profile' => (int)getParam($sOptionPrefix . 'events_per_page_profile'),
  361. 'account' => (int)getParam($sOptionPrefix . 'events_per_page_account'),
  362. 'home' => (int)getParam($sOptionPrefix . 'events_per_page_home'),
  363. 'preload' => (int)getParam($sOptionPrefix . 'events_per_preload')
  364. );
  365. $this->_bInfScroll = getParam($sOptionPrefix . 'enable_infinite_scroll') == 'on';
  366. $this->_iInfScrollAutoPreloads = (int)getParam($sOptionPrefix . 'auto_preloads');
  367. $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');
  368. $this->_iLiveUpdateLength = (int)getParam($sOptionPrefix . 'live_updates_length');
  369. $this->_bBriefCards = getParam($sOptionPrefix . 'enable_brief_cards') == 'on';
  370. $this->_iCharsDisplayMinTitle = (int)getParam($sOptionPrefix . 'title_chars_short');
  371. $this->_iCharsDisplayMaxTitle = (int)getParam($sOptionPrefix . 'title_chars');
  372. $this->_sVideosPreload = getParam($sOptionPrefix . 'videos_preload');
  373. $this->_sVideosAutoplay = getParam($sOptionPrefix . 'videos_autoplay');
  374. $this->_iPreloadCommentsMax = 7;
  375. $this->_iPreloadComments = (int)getParam($sOptionPrefix . 'preload_comments');
  376. if($this->_iPreloadComments > $this->_iPreloadCommentsMax)
  377. $this->_iPreloadComments = $this->_iPreloadCommentsMax;
  378. $this->_bJumpTo = getParam($sOptionPrefix . 'enable_jump_to_switcher') == 'on';
  379. $this->_bSortByReaction = getParam($sOptionPrefix . 'enable_sort_by_reaction') == 'on';
  380. $this->_bSortByUnread = getParam($sOptionPrefix . 'enable_sort_by_unread') == 'on';
  381. $this->_sAttachmentsLayout = getParam($sOptionPrefix . 'attachments_layout');
  382. $this->_bHot = getParam($sOptionPrefix . 'enable_hot') == 'on';
  383. $this->_iHotThresholdContent = (int)getParam($sOptionPrefix . 'hot_threshold_age');
  384. $this->_iHotThresholdComment = (int)getParam($sOptionPrefix . 'hot_threshold_comment');
  385. $this->_iHotThresholdVote = (int)getParam($sOptionPrefix . 'hot_threshold_vote');
  386. $this->_iHotInterval = (int)getParam($sOptionPrefix . 'hot_interval');
  387. $this->_aHotSources = explode(',', getParam($sOptionPrefix . 'hot_sources'));
  388. $this->_aHotList = $this->_bHot ? $this->_oDb->getHot() : array();
  389. $this->_bEditorToolbar = getParam($sOptionPrefix . 'enable_editor_toolbar') == 'on';
  390. $this->_bEditorAutoAttach = getParam($sOptionPrefix . 'editor_auto_attach_insertion') == 'on';
  391. $this->_iLimitAttachLinks = (int)getParam($sOptionPrefix . 'limit_attach_links');
  392. $this->_bUnhideRestored = false;
  393. }
  394. /**
  395. * Generate name from parameters.
  396. *
  397. * @param type $aParams - parameters whose values will be used during generation.
  398. * @param type $aRules - generation rules.
  399. * @return string
  400. */
  401. protected function getNameView($aParams, $aRules = array())
  402. {
  403. $bWithView = !isset($aRules['with_view']) || $aRules['with_view'] === true;
  404. $bWithType = !isset($aRules['with_type']) || $aRules['with_type'] === true;
  405. $bWithOwner = isset($aRules['with_owner']) && $aRules['with_owner'] === true;
  406. $sGlue = !empty($aRules['glue']) ? $aRules['glue'] : '_';
  407. $aAddons = array();
  408. if(!empty($aParams['name']))
  409. $aAddons[] = bx_process_output($aParams['name']);
  410. else {
  411. if($bWithView && !empty($aParams['view']))
  412. $aAddons[] = bx_process_output($aParams['view']);
  413. if($bWithType && !empty($aParams['type']))
  414. $aAddons[] = bx_process_output($aParams['type']);
  415. }
  416. if($bWithOwner)
  417. $aAddons[] = (int)$aParams['owner_id'];
  418. return !empty($aAddons) ? implode($sGlue, $aAddons) : '';
  419. }
  420. /**
  421. * Generates unique JS object name for View events block.
  422. *
  423. * @param array $aParams - an array with browsing params received in View block service method
  424. * @return string with JS object name
  425. */
  426. public function getJsObjectView($aParams = array())
  427. {
  428. return parent::getJsObject('view') . bx_gen_method_name($this->getNameView($aParams));
  429. }
  430. public function getHtmlIdView($sKey, $aParams, $aRules = array())
  431. {
  432. $bWhole = !isset($aRules['whole']) || $aRules['whole'] === true;
  433. $sGlue = !empty($aRules['glue']) ? $aRules['glue'] : '_';
  434. return str_replace($sGlue, '-', $this->_sName . $sGlue . $sKey . $sGlue . $this->getNameView($aParams, $aRules) . (!$bWhole ? $sGlue : ''));
  435. }
  436. public function isAllowEdit()
  437. {
  438. return $this->_bAllowEdit;
  439. }
  440. public function isAllowDelete()
  441. {
  442. return $this->_bAllowDelete;
  443. }
  444. public function isInfiniteScroll()
  445. {
  446. return $this->_bInfScroll;
  447. }
  448. public function isShowAll()
  449. {
  450. return $this->_bShowAll;
  451. }
  452. public function isCountAllViews()
  453. {
  454. return $this->_bCountAllViews;
  455. }
  456. public function isRepostOwnActions()
  457. {
  458. return $this->_bRepostOwnActions;
  459. }
  460. public function isHideUponDelete()
  461. {
  462. return $this->_bHideUponDelete;
  463. }
  464. public function isBriefCards()
  465. {
  466. return $this->_bBriefCards;
  467. }
  468. public function isJumpTo()
  469. {
  470. return $this->_bJumpTo;
  471. }
  472. public function isSortByReaction()
  473. {
  474. return $this->_bSortByReaction;
  475. }
  476. public function isSortByUnread()
  477. {
  478. return $this->_bSortByUnread;
  479. }
  480. public function isHot()
  481. {
  482. return $this->_bHot;
  483. }
  484. public function getHotSourcesList()
  485. {
  486. return $this->_aHotSourcesList;
  487. }
  488. public function getHotSources()
  489. {
  490. return $this->_aHotSources;
  491. }
  492. public function isHotSource($sName)
  493. {
  494. return in_array($sName, $this->_aHotSources);
  495. }
  496. public function getHotThreshold($sSource)
  497. {
  498. if(!in_array($sSource, [BX_TIMELINE_HFS_CONTENT, BX_TIMELINE_HFS_COMMENT, BX_TIMELINE_HFS_VOTE]))
  499. return false;
  500. return $this->{'_iHotThreshold' . ucfirst($sSource)};
  501. }
  502. public function isHotEvent($iEventId)
  503. {
  504. return in_array($iEventId, $this->_aHotList);
  505. }
  506. public function isEditorToolbar()
  507. {
  508. return $this->_bEditorToolbar;
  509. }
  510. public function isEditorAutoAttach()
  511. {
  512. return $this->_bEditorAutoAttach;
  513. }
  514. public function isUnhideRestored()
  515. {
  516. return $this->_bUnhideRestored;
  517. }
  518. public function isCacheItem()
  519. {
  520. return $this->_bCacheItem;
  521. }
  522. public function isCacheTable()
  523. {
  524. return $this->_bCacheTable;
  525. }
  526. public function getCacheItemEngine()
  527. {
  528. return $this->_sCacheItemEngine;
  529. }
  530. public function getCacheItemLifetime()
  531. {
  532. return $this->_iCacheItemLifetime;
  533. }
  534. public function getCacheItemKey($iId, $sPostfix = '')
  535. {
  536. return $this->getPrefix('cache_item') . $iId . (bx_is_mobile() ? '_m' : '') . '_r' . bx_get_device_pixel_ratio() . (!empty($sPostfix) ? '_' . $sPostfix : '') . '_' . bx_site_hash() . '.php';
  537. }
  538. public function getCacheHotKey()
  539. {
  540. return $this->getPrefix('cache_list_hot');
  541. }
  542. public function getCacheTableInterval()
  543. {
  544. return 86400 * $this->_iCacheTableInterval;
  545. }
  546. public function getCacheTableCheckFields()
  547. {
  548. $mixedResult = null;
  549. bx_alert($this->getName(), 'cache_table_check_fields', 0, 0, ['check_fields' => $this->_aCacheTableCheckFields, 'override_result' => &$mixedResult]);
  550. if($mixedResult !== null)
  551. return $mixedResult;
  552. return $this->_aCacheTableCheckFields;
  553. }
  554. public function getPostFormDisplay($sType)
  555. {
  556. if(empty($sType) || !array_key_exists($sType, $this->_aTypeToFormDisplay))
  557. $sType = BX_TIMELINE_TYPE_DEFAULT;
  558. return $this->_aTypeToFormDisplay[$sType];
  559. }
  560. public function getUploaders($sField)
  561. {
  562. $aResult = array();
  563. switch($sField) {
  564. case 'photo':
  565. $aResult = $this->_aPhotoUploaders;
  566. break;
  567. case 'video':
  568. $aResult = $this->_aVideoUploaders;
  569. break;
  570. case 'file':
  571. $aResult = $this->_aFilesUploaders;
  572. break;
  573. }
  574. return $aResult;
  575. }
  576. public function getUploaderByMenuItem($sMenuItem)
  577. {
  578. if(!isset($this->_aItemToUploader[$sMenuItem]))
  579. return false;
  580. return $this->_aItemToUploader[$sMenuItem];
  581. }
  582. public function getPerPage($sType = 'default')
  583. {
  584. if($this->isInfiniteScroll())
  585. $sType = 'preload';
  586. return parent::getPerPage($sType);
  587. }
  588. public function getExtenalsEvery($sType = 'default')
  589. {
  590. if($this->isInfiniteScroll())
  591. $sType .= '_preload';
  592. $iExtenalsEvery = (int)getParam($this->getPrefix('option') . 'extenals_every_' . $sType);
  593. if(!$iExtenalsEvery)
  594. return $iExtenalsEvery;
  595. $iPerPage = $this->getPerPage($sType);
  596. if(empty($iPerPage))
  597. $iPerPage = $this->getPerPage();
  598. if($iExtenalsEvery > $iPerPage)
  599. $iExtenalsEvery = $iPerPage;
  600. return $iExtenalsEvery;
  601. }
  602. public function getAutoPreloads()
  603. {
  604. return $this->_iInfScrollAutoPreloads;
  605. }
  606. public function getRssLength()
  607. {
  608. return $this->_iRssLength;
  609. }
  610. public function getLiveUpdateLength()
  611. {
  612. return $this->_iLiveUpdateLength;
  613. }
  614. public function getCharsDisplayMinTitle()
  615. {
  616. return $this->_iCharsDisplayMinTitle;
  617. }
  618. public function getCharsDisplayMaxTitle()
  619. {
  620. return $this->_iCharsDisplayMaxTitle;
  621. }
  622. public function getBriefCardsTags($bAsString = false)
  623. {
  624. return !$bAsString ? $this->_aBriefCardsTags : '<' . implode('><', $this->_aBriefCardsTags) . '>';
  625. }
  626. public function getVideosPreload()
  627. {
  628. return $this->_sVideosPreload;
  629. }
  630. public function getVideosAutoplay()
  631. {
  632. return $this->_sVideosAutoplay;
  633. }
  634. public function getPreloadComments()
  635. {
  636. return $this->_iPreloadComments;
  637. }
  638. public function getAttachmentsLayout()
  639. {
  640. return $this->_sAttachmentsLayout;
  641. }
  642. public function getHotInterval()
  643. {
  644. return $this->_iHotInterval;
  645. }
  646. public function getLimitAttachLinks()
  647. {
  648. return $this->_iLimitAttachLinks;
  649. }
  650. public function getRepostDefaults()
  651. {
  652. return $this->_aRepostDefaults;
  653. }
  654. public function getPregPattern($sType)
  655. {
  656. return $this->_aPregPatterns[$sType];
  657. }
  658. /**
  659. * Ancillary functions
  660. */
  661. public function getTitle($s, $mixedProfile = false, $sMethodLength = 'getCharsDisplayMaxTitle')
  662. {
  663. if(get_mb_substr($s, 0, 1) == '_' && strcmp($s, _t($s)) != 0)
  664. return $s;
  665. if($mixedProfile !== false) {
  666. if(is_numeric($mixedProfile))
  667. $mixedProfile = BxDolProfile::getInstanceMagic((int)$mixedProfile);
  668. if($mixedProfile instanceof BxDolProfile)
  669. $s = bx_replace_markers($s, array(
  670. 'profile_name' => $mixedProfile->getDisplayName()
  671. ));
  672. }
  673. if(!method_exists($this, $sMethodLength))
  674. $sMethodLength = 'getCharsDisplayMaxTitle';
  675. return strmaxtextlen($s, $this->$sMethodLength(), '...');
  676. }
  677. public function getTitleShort($s, $mixedProfile = false)
  678. {
  679. return $this->getTitle($s, $mixedProfile, 'getCharsDisplayMinTitle');
  680. }
  681. public function getTitleDefault($bL, $bP, $bV, $bF)
  682. {
  683. $sResult = '';
  684. if($bL && !$bP && !$bV && !$bF)
  685. $sResult = 'link';
  686. else if(!$bL && $bP && !$bV && !$bF)
  687. $sResult = 'image';
  688. else if(!$bL && !$bP && $bV && !$bF)
  689. $sResult = 'video';
  690. else if(!$bL && !$bP && !$bV && $bF)
  691. $sResult = 'file';
  692. else
  693. $sResult = 'media';
  694. return $this->CNF['T']['txt_sample_with_' . $sResult];
  695. }
  696. public function getViewUrl($iOwnerId, $bAbsolute = true)
  697. {
  698. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->CNF['URI_VIEW_LIST'], ['id' => $iOwnerId]);
  699. return $bAbsolute ? bx_absolute_url($sUrl) : $sUrl;
  700. }
  701. public function getHomeViewUrl($bAbsolute = true)
  702. {
  703. $sUrl = BxDolPermalinks::getInstance()->permalink($this->CNF['URL_HOME']);
  704. return $bAbsolute ? bx_absolute_url($sUrl) : $sUrl;
  705. }
  706. public function getItemViewUrl($aEvent, $bAbsolute = true)
  707. {
  708. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->CNF['URI_VIEW_ENTRY'], ['id' => $aEvent['id']]);
  709. return $bAbsolute ? bx_absolute_url($sUrl) : $sUrl;
  710. }
  711. public function getLiveUpdateKey($aParams)
  712. {
  713. return $this->getName() . '_live_update_' . $this->getNameView($aParams, array('with_owner' => true));
  714. }
  715. public function isCommon($sType, $sAction)
  716. {
  717. return !$this->isSystem($sType, $sAction);
  718. }
  719. public function isSystem($sType, $sAction)
  720. {
  721. $sPrefix = $this->getPrefix('common_post');
  722. return strpos($sType, $sPrefix) === false && !empty($sAction);
  723. }
  724. public function getSystemData(&$aEvent, $aBrowseParams = array())
  725. {
  726. $aHandler = $this->getHandler($aEvent);
  727. if($aHandler === false)
  728. return false;
  729. return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent, $aBrowseParams), $aHandler['module_class']);
  730. }
  731. public function getSystemDataByDescriptor($sType, $sAction, $iObjectId)
  732. {
  733. $aDescriptor = array(
  734. 'type' => $sType,
  735. 'action' => $sAction,
  736. 'object_id' => $iObjectId
  737. );
  738. return $this->getSystemData($aDescriptor);
  739. }
  740. public function isEqualUrls($sUrl1, $sUrl2)
  741. {
  742. $sUrl1 = trim($sUrl1, "/");
  743. $sUrl2 = trim($sUrl2, "/");
  744. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  745. }
  746. public function addBrowseParams($sUrl, $aParams, $sKey = 'bp')
  747. {
  748. return bx_append_url_params($sUrl, [$sKey => base64_encode(json_encode($aParams))]);
  749. }
  750. public function getBrowseParams($sValue)
  751. {
  752. return json_decode(base64_decode(urldecode($sValue)), true);
  753. }
  754. public function setUserChoice($aChoices = array())
  755. {
  756. if(!isLogged() || empty($aChoices))
  757. return;
  758. $iUserId = bx_get_logged_profile_id();
  759. $oSession = BxDolSession::getInstance();
  760. foreach($aChoices as $sKey => $mixedValue) {
  761. $sField = '_sSessionKey' . bx_gen_method_name($sKey);
  762. if(isset($this->$sField) && !empty($mixedValue))
  763. $oSession->setValue($this->$sField . $iUserId, $mixedValue);
  764. }
  765. }
  766. public function getUserChoice($sKey, $iUserId = 0)
  767. {
  768. $sField = '_sSessionKey' . bx_gen_method_name($sKey);
  769. if(!isLogged() || !isset($this->$sField))
  770. return false;
  771. if(!$iUserId)
  772. $iUserId = bx_get_logged_profile_id();
  773. return BxDolSession::getInstance()->getValue($this->$sField . $iUserId);
  774. }
  775. public function prepareParam($sName, $sPattern = "/^[\d\w_]+$/")
  776. {
  777. return $this->processParam(bx_get($sName), $sPattern);
  778. }
  779. public function prepareParamWithDefault($sName, $sDefault, $sPattern = "/^[\d\w_]+$/")
  780. {
  781. return ($sValue = $this->prepareParam($sName, $sPattern)) != '' ? $sValue : $sDefault;
  782. }
  783. public function processParam($sValue, $sPattern = "/^[\d\w_]+$/")
  784. {
  785. return bx_process_url_param($sValue, $sPattern);
  786. }
  787. public function processParamWithDefault($sValue, $sDefault, $sPattern = "/^[\d\w_]+$/")
  788. {
  789. return ($sValue = $this->processParam($sValue, $sPattern)) != '' ? $sValue : $sDefault;
  790. }
  791. }
  792. /** @} */