1
0

BxTimelineConfig.php 13 KB

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