BxTimelineConfig.php 45 KB

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