BxTimelineConfig.php 41 KB

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