BxTimelineConfig.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 $_iRssLength;
  19. protected $_iCharsDisplayMax;
  20. protected $_iCharsDisplayMaxTitle;
  21. protected $_sVideosAutoplay;
  22. protected $_bHot;
  23. protected $_iHotInterval;
  24. protected $_sStorageObject;
  25. protected $_sTranscoderObjectPreview;
  26. protected $_sTranscoderObjectView;
  27. protected $_aPhotoUploaders;
  28. protected $_aVideoUploaders;
  29. protected $_sMenuItemManage;
  30. protected $_sMenuItemActions;
  31. protected $_aRepostDefaults;
  32. protected $_iTimelineVisibilityThreshold;
  33. protected $_aPregPatterns;
  34. /**
  35. * Constructor
  36. */
  37. public function __construct($aModule)
  38. {
  39. parent::__construct($aModule);
  40. $this->CNF = array (
  41. 'ICON' => 'clock-o col-green1',
  42. // database tables
  43. 'TABLE_ENTRIES' => $aModule['db_prefix'] . 'events',
  44. // database fields
  45. 'FIELD_ID' => 'id',
  46. 'FIELD_OWNER_ID' => 'owner_id',
  47. 'FIELD_ADDED' => 'date',
  48. 'FIELD_TITLE' => 'title',
  49. 'FIELD_TEXT' => 'description',
  50. 'FIELD_CONTROLS' => 'controls',
  51. 'FIELD_LOCATION_PREFIX' => 'location',
  52. // page URIs
  53. 'URI_VIEW_LIST' => 'timeline-view',
  54. 'URI_VIEW_ENTRY' => 'item',
  55. 'URL_HOME' => 'page.php?i=timeline-view-home',
  56. // objects
  57. 'OBJECT_STORAGE' => $this->_sName . '_photos',
  58. 'OBJECT_IMAGES_TRANSCODER_PREVIEW' => $this->_sName . '_photos_preview',
  59. 'OBJECT_METATAGS' => $this->_sName,
  60. 'OBJECT_COMMENTS' => $this->_sName,
  61. 'OBJECT_VIEWS' => $this->_sName,
  62. 'OBJECT_VOTES' => $this->_sName,
  63. 'OBJECT_REPORTS' => $this->_sName,
  64. // some language keys
  65. 'T' => array (
  66. 'txt_sample_single' => '_bx_timeline_txt_sample',
  67. 'txt_sample_single_ext' => '_bx_timeline_txt_sample_ext',
  68. 'txt_sample_comment_single' => '_bx_timeline_txt_sample_comment_single',
  69. 'txt_sample_vote_single' => '_bx_timeline_txt_sample_vote_single',
  70. ),
  71. );
  72. $this->_aTypeToFormDisplay = array(
  73. BX_BASE_MOD_NTFS_TYPE_OWNER => 'form_display_post_add_profile',
  74. BX_BASE_MOD_NTFS_TYPE_PUBLIC => 'form_display_post_add_public',
  75. BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS => 'form_display_post_add'
  76. );
  77. $this->_aPrefixes = array(
  78. 'style' => 'bx-tl',
  79. 'language' => '_bx_timeline',
  80. 'option' => 'bx_timeline_',
  81. 'common_post' => 'timeline_common_'
  82. );
  83. $this->_aObjects = array_merge($this->_aObjects, array(
  84. 'comment' => $this->CNF['OBJECT_COMMENTS'],
  85. 'view' => $this->CNF['OBJECT_VIEWS'],
  86. 'vote' => $this->CNF['OBJECT_VOTES'],
  87. 'report' => $this->CNF['OBJECT_REPORTS'],
  88. 'metatags' => $this->_sName,
  89. 'storage_photos' => $this->CNF['OBJECT_STORAGE'],
  90. 'storage_videos' => $this->_sName . '_videos',
  91. 'transcoder_photos_preview' => $this->CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'],
  92. 'transcoder_photos_view' => $this->_sName . '_photos_view',
  93. 'transcoder_photos_medium' => $this->_sName . '_photos_medium',
  94. 'transcoder_photos_big' => $this->_sName . '_photos_big',
  95. 'transcoder_videos_poster' => $this->_sName . '_videos_poster',
  96. 'transcoder_videos_mp4' => $this->_sName . '_videos_mp4',
  97. 'transcoder_videos_webm' => $this->_sName . '_videos_webm',
  98. 'page_item_brief' => $this->_sName . '_item_brief',
  99. 'menu_item_manage' => $this->_sName . '_menu_item_manage',
  100. 'menu_item_actions' => $this->_sName . '_menu_item_actions',
  101. 'menu_post_attachments' => $this->_sName . '_menu_post_attachments',
  102. 'form_post' => $this->_sName . '_post',
  103. 'form_attach_link' => $this->_sName . '_attach_link',
  104. 'form_display_post_add' => $this->_sName . '_post_add',
  105. 'form_display_post_add_public' => $this->_sName . '_post_add_public',
  106. 'form_display_post_add_profile' => $this->_sName . '_post_add_profile',
  107. 'form_display_post_edit' => $this->_sName . '_post_edit',
  108. 'form_display_attach_link_add' => $this->_sName . '_attach_link_add'
  109. ));
  110. $this->_aHandlerDescriptor = array('module_name' => '', 'module_method' => '', 'module_class' => '', 'groupable' => '', 'group_by' => '');
  111. $this->_sHandlersMethod = 'get_timeline_data';
  112. $this->_aPhotoUploaders = array($this->_sName . '_simple_photo');
  113. $this->_aVideoUploaders = array($this->_sName . '_simple_video');
  114. $this->_bJsMode = false;
  115. $this->_aJsClasses = array(
  116. 'main' => 'BxTimelineMain',
  117. 'view' => 'BxTimelineView',
  118. 'post' => 'BxTimelinePost',
  119. 'repost' => 'BxTimelineRepost'
  120. );
  121. $this->_aJsObjects = array(
  122. 'view' => 'oTimelineView',
  123. 'post' => 'oTimelinePost',
  124. 'repost' => 'oTimelineRepost'
  125. );
  126. $sHp = str_replace('_', '-', $this->_sName);
  127. $sHpI = BX_TIMELINE_VIEW_ITEM;
  128. $sHpT = BX_TIMELINE_VIEW_TIMELINE;
  129. $sHpO = BX_TIMELINE_VIEW_OUTLINE;
  130. $sHpS = BX_TIMELINE_VIEW_SEARCH;
  131. $this->_aHtmlIds = array(
  132. 'view' => array(
  133. 'edit_form' => $sHp . '-edit-',
  134. 'main_' . $sHpI => $sHp . '-' . $sHpI,
  135. 'item_' . $sHpI => $sHp . '-item-' . $sHpI . '-',
  136. 'item_popup_' . $sHpI => $sHp . '-item-popup-' . $sHpI,
  137. 'photo_popup_' . $sHpI => $sHp . '-photo-popup-' . $sHpI,
  138. 'main_' . $sHpT => $sHp . '-' . $sHpT,
  139. 'item_' . $sHpT => $sHp . '-item-' . $sHpT . '-',
  140. 'item_popup_' . $sHpT => $sHp . '-item-popup-' . $sHpT,
  141. 'photo_popup_' . $sHpT => $sHp . '-photo-popup-' . $sHpT,
  142. 'main_' . $sHpO => $sHp . '-' . $sHpO,
  143. 'item_' . $sHpO => $sHp . '-item-' . $sHpO . '-',
  144. 'item_popup_' . $sHpO => $sHp . '-item-popup-' . $sHpO,
  145. 'photo_popup_' . $sHpO => $sHp . '-photo-popup-' . $sHpO,
  146. 'main_' . $sHpS => $sHp . '-' . $sHpS,
  147. 'photo_popup_' . $sHpS => $sHp . '-photo-popup-' . $sHpS,
  148. 'main_item' => $sHp . '-item',
  149. 'menu_popup' => $sHp . '-menu-popup-',
  150. 'video_iframe' => $sHp . '-video-iframe-',
  151. 'video' => $sHp . '-video-',
  152. 'live_update_popup' => $sHp . '-live-update-popup-',
  153. ),
  154. 'post' => array(
  155. 'attach_link_popup' => $sHp . '-attach-link-popup',
  156. 'attach_link_form_field' => $sHp . '-attach-link-form_field',
  157. 'attach_link_item' => $sHp . '-attach-link-item-',
  158. 'textarea' => $sHp . '-textarea-',
  159. 'main_' . $sHpT => $sHp . '-' . $sHpT,
  160. 'main_' . $sHpO => $sHp . '-' . $sHpO,
  161. ),
  162. 'repost' => array(
  163. 'main' => $sHp . '-repost-',
  164. 'counter' => $sHp . '-repost-counter-',
  165. 'by_popup' => $sHp . '-repost-by-',
  166. )
  167. );
  168. $this->_aRepostDefaults = array(
  169. 'show_do_repost_as_button' => false,
  170. 'show_do_repost_as_button_small' => false,
  171. 'show_do_repost_icon' => true,
  172. 'show_do_repost_label' => false,
  173. 'show_counter' => true
  174. );
  175. $this->_iTimelineVisibilityThreshold = 0;
  176. $this->_aPregPatterns = array(
  177. "meta_title" => "/<title>(.*)<\/title>/",
  178. "meta_description" => "/<meta[\s]+[^>]*?name[\s]?=[\s\"\']+description[\s\"\']+content[\s]?=[\s\"\']+(.*?)[\"\']+.*?>/",
  179. "url" => "/(([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?/"
  180. );
  181. }
  182. public function init(&$oDb)
  183. {
  184. parent::init($oDb);
  185. $sOptionPrefix = $this->getPrefix('option');
  186. $this->_bAllowEdit = getParam($sOptionPrefix . 'enable_edit') == 'on';
  187. $this->_bAllowDelete = getParam($sOptionPrefix . 'enable_delete') == 'on';
  188. $this->_bShowAll = getParam($sOptionPrefix . 'enable_show_all') == 'on';
  189. $this->_aPerPage = array(
  190. 'default' => (int)getParam($sOptionPrefix . 'events_per_page'),
  191. 'profile' => (int)getParam($sOptionPrefix . 'events_per_page_profile'),
  192. 'account' => (int)getParam($sOptionPrefix . 'events_per_page_account'),
  193. 'home' => (int)getParam($sOptionPrefix . 'events_per_page_home')
  194. );
  195. $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');
  196. $this->_iCharsDisplayMax = (int)getParam($sOptionPrefix . 'chars_display_max');
  197. $this->_iCharsDisplayMaxTitle = 20;
  198. $this->_sVideosAutoplay = getParam($sOptionPrefix . 'videos_autoplay');
  199. $this->_bHot = getParam($sOptionPrefix . 'enable_hot') == 'on';
  200. $this->_iHotInterval = (int)getParam($sOptionPrefix . 'hot_interval');
  201. }
  202. public function isAllowEdit()
  203. {
  204. return $this->_bAllowEdit;
  205. }
  206. public function isAllowDelete()
  207. {
  208. return $this->_bAllowDelete;
  209. }
  210. public function isShowAll()
  211. {
  212. return $this->_bShowAll;
  213. }
  214. public function isHot()
  215. {
  216. return $this->_bHot;
  217. }
  218. public function getPostFormDisplay($sType)
  219. {
  220. if(empty($sType) || !array_key_exists($sType, $this->_aTypeToFormDisplay))
  221. $sType = BX_TIMELINE_TYPE_DEFAULT;
  222. return $this->_aTypeToFormDisplay[$sType];
  223. }
  224. public function getUploaders($sType)
  225. {
  226. $aResult = array();
  227. switch($sType) {
  228. case 'photo':
  229. $aResult = $this->_aPhotoUploaders;
  230. break;
  231. case 'video':
  232. $aResult = $this->_aVideoUploaders;
  233. break;
  234. }
  235. return $aResult;
  236. }
  237. public function getRssLength()
  238. {
  239. return $this->_iRssLength;
  240. }
  241. public function getCharsDisplayMax()
  242. {
  243. return $this->_iCharsDisplayMax;
  244. }
  245. public function getCharsDisplayMaxTitle()
  246. {
  247. return $this->_iCharsDisplayMaxTitle;
  248. }
  249. public function getVideosAutoplay()
  250. {
  251. return $this->_sVideosAutoplay;
  252. }
  253. public function getHotInterval()
  254. {
  255. return $this->_iHotInterval;
  256. }
  257. public function getRepostDefaults()
  258. {
  259. return $this->_aRepostDefaults;
  260. }
  261. public function getPregPattern($sType)
  262. {
  263. return $this->_aPregPatterns[$sType];
  264. }
  265. /**
  266. * Ancillary functions
  267. */
  268. public function getTitle($s)
  269. {
  270. return strmaxtextlen($s, $this->getCharsDisplayMaxTitle(), '...');
  271. }
  272. public function getViewUrl($iOwnerId)
  273. {
  274. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  275. 'i' => $this->CNF['URI_VIEW_LIST'],
  276. 'id' => $iOwnerId
  277. ));
  278. }
  279. public function getHomeViewUrl()
  280. {
  281. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->CNF['URL_HOME']);
  282. }
  283. public function getItemViewUrl(&$aEvent)
  284. {
  285. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php', array(
  286. 'i' => $this->CNF['URI_VIEW_ENTRY'],
  287. 'id' => $aEvent['id']
  288. ));
  289. }
  290. public function getLiveUpdateKey($sType, $iOwnerId)
  291. {
  292. return $this->getName() . '_live_update_' . $sType . '_' . $iOwnerId;
  293. }
  294. public function isCommon($sType, $sAction)
  295. {
  296. return !$this->isSystem($sType, $sAction);
  297. }
  298. public function isSystem($sType, $sAction)
  299. {
  300. $sPrefix = $this->getPrefix('common_post');
  301. return strpos($sType, $sPrefix) === false && !empty($sAction);
  302. }
  303. public function getSystemData(&$aEvent, $aBrowseParams = array())
  304. {
  305. $sHandler = $aEvent['type'] . '_' . $aEvent['action'];
  306. if(!$this->isHandler($sHandler))
  307. return false;
  308. $aHandler = $this->getHandlers($sHandler);
  309. if(empty($aHandler['module_name']) || empty($aHandler['module_class']) || empty($aHandler['module_method']))
  310. return false;
  311. return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent, $aBrowseParams), $aHandler['module_class']);
  312. }
  313. public function getSystemDataByDescriptor($sType, $sAction, $iObjectId)
  314. {
  315. $aDescriptor = array(
  316. 'type' => $sType,
  317. 'action' => $sAction,
  318. 'object_id' => $iObjectId
  319. );
  320. return $this->getSystemData($aDescriptor);
  321. }
  322. public function isEqualUrls($sUrl1, $sUrl2)
  323. {
  324. $sUrl1 = trim($sUrl1, "/");
  325. $sUrl2 = trim($sUrl2, "/");
  326. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  327. }
  328. }
  329. /** @} */