BxTimelineConfig.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 $_bAllowDelete;
  15. protected $_iRssLength;
  16. protected $_iCharsDisplayMax;
  17. protected $_iCharsDisplayMaxTitle;
  18. protected $_sStorageObject;
  19. protected $_sTranscoderObjectPreview;
  20. protected $_sTranscoderObjectView;
  21. protected $_aPhotoUploaders;
  22. protected $_aVideoUploaders;
  23. protected $_sMenuItemManage;
  24. protected $_sMenuItemActions;
  25. protected $_aRepostDefaults;
  26. protected $_iTimelineVisibilityThreshold;
  27. protected $_aPregPatterns;
  28. /**
  29. * Constructor
  30. */
  31. public function __construct($aModule)
  32. {
  33. parent::__construct($aModule);
  34. $this->CNF = array (
  35. 'ICON' => 'clock-o col-green1',
  36. // database fields
  37. 'FIELD_ID' => 'id',
  38. 'FIELD_LOCATION_PREFIX' => 'location',
  39. // objects
  40. 'OBJECT_COMMENTS' => $this->_sName,
  41. 'OBJECT_VIEWS' => $this->_sName,
  42. 'OBJECT_VOTES' => $this->_sName,
  43. 'OBJECT_REPORTS' => $this->_sName,
  44. // some language keys
  45. 'T' => array (
  46. 'txt_sample_single' => '_bx_timeline_txt_sample',
  47. 'txt_sample_single_ext' => '_bx_timeline_txt_sample_ext',
  48. 'txt_sample_comment_single' => '_bx_timeline_txt_sample_comment_single',
  49. 'txt_sample_vote_single' => '_bx_timeline_txt_sample_vote_single',
  50. ),
  51. );
  52. $this->_aPrefixes = array(
  53. 'style' => 'bx-tl',
  54. 'language' => '_bx_timeline',
  55. 'option' => 'bx_timeline_',
  56. 'common_post' => 'timeline_common_'
  57. );
  58. $this->_aObjects = array_merge($this->_aObjects, array(
  59. 'comment' => $this->CNF['OBJECT_COMMENTS'],
  60. 'view' => $this->CNF['OBJECT_VIEWS'],
  61. 'vote' => $this->CNF['OBJECT_VOTES'],
  62. 'report' => $this->CNF['OBJECT_REPORTS'],
  63. 'metatags' => $this->_sName,
  64. 'storage_photos' => $this->_sName . '_photos',
  65. 'storage_videos' => $this->_sName . '_videos',
  66. 'transcoder_photos_preview' => $this->_sName . '_photos_preview',
  67. 'transcoder_photos_view' => $this->_sName . '_photos_view',
  68. 'transcoder_videos_poster' => $this->_sName . '_videos_poster',
  69. 'transcoder_videos_mp4' => $this->_sName . '_videos_mp4',
  70. 'transcoder_videos_webm' => $this->_sName . '_videos_webm',
  71. 'menu_item_manage' => $this->_sName . '_menu_item_manage',
  72. 'menu_item_actions' => $this->_sName . '_menu_item_actions',
  73. 'menu_post_attachments' => $this->_sName . '_menu_post_attachments',
  74. 'form_post' => $this->_sName . '_post',
  75. 'form_attach_link' => $this->_sName . '_attach_link',
  76. 'form_display_post_add' => $this->_sName . '_post_add',
  77. 'form_display_attach_link_add' => $this->_sName . '_attach_link_add'
  78. ));
  79. $this->_aHandlerDescriptor = array('module_name' => '', 'module_method' => '', 'module_class' => '', 'groupable' => '', 'group_by' => '');
  80. $this->_sHandlersMethod = 'get_timeline_data';
  81. $this->_aPhotoUploaders = array($this->_sName . '_simple_photo');
  82. $this->_aVideoUploaders = array($this->_sName . '_simple_video');
  83. $this->_bJsMode = false;
  84. $this->_aJsClasses = array(
  85. 'main' => 'BxTimelineMain',
  86. 'view' => 'BxTimelineView',
  87. 'post' => 'BxTimelinePost',
  88. 'repost' => 'BxTimelineRepost'
  89. );
  90. $this->_aJsObjects = array(
  91. 'view' => 'oTimelineView',
  92. 'post' => 'oTimelinePost',
  93. 'repost' => 'oTimelineRepost'
  94. );
  95. $sHp = str_replace('_', '-', $this->_sName);
  96. $sHpT = BX_TIMELINE_VIEW_TIMELINE;
  97. $sHpO = BX_TIMELINE_VIEW_OUTLINE;
  98. $sHpS = BX_TIMELINE_VIEW_SEARCH;
  99. $this->_aHtmlIds = array(
  100. 'view' => array(
  101. 'main_' . $sHpT => $sHp . '-' . $sHpT,
  102. 'item_' . $sHpT => $sHp . '-item-' . $sHpT . '-',
  103. 'photo_popup_' . $sHpT => $sHp . '-photo-popup-' . $sHpT,
  104. 'main_' . $sHpO => $sHp . '-' . $sHpO,
  105. 'item_' . $sHpO => $sHp . '-item-' . $sHpO . '-',
  106. 'photo_popup_' . $sHpO => $sHp . '-photo-popup-' . $sHpO,
  107. 'main_' . $sHpS => $sHp . '-' . $sHpS,
  108. 'photo_popup_' . $sHpS => $sHp . '-photo-popup-' . $sHpS,
  109. 'main_item' => $sHp . '-item',
  110. 'menu_popup' => $sHp . '-menu-popup-',
  111. ),
  112. 'post' => array(
  113. 'attach_link_popup' => $sHp . '-attach-link-popup',
  114. 'attach_link_form_field' => $sHp . '-attach-link-form_field',
  115. 'attach_link_item' => $sHp . '-attach-link-item-',
  116. 'main_' . $sHpT => $sHp . '-' . $sHpT,
  117. 'main_' . $sHpO => $sHp . '-' . $sHpO,
  118. ),
  119. 'repost' => array(
  120. 'main' => $sHp . '-repost-',
  121. 'counter' => $sHp . '-repost-counter-',
  122. 'by_popup' => $sHp . '-repost-by-',
  123. )
  124. );
  125. $this->_aRepostDefaults = array(
  126. 'show_do_repost_as_button' => false,
  127. 'show_do_repost_as_button_small' => false,
  128. 'show_do_repost_icon' => true,
  129. 'show_do_repost_label' => false,
  130. 'show_counter' => true
  131. );
  132. $this->_iTimelineVisibilityThreshold = 0;
  133. $this->_aPregPatterns = array(
  134. "meta_title" => "/<title>(.*)<\/title>/",
  135. "meta_description" => "/<meta[\s]+[^>]*?name[\s]?=[\s\"\']+description[\s\"\']+content[\s]?=[\s\"\']+(.*?)[\"\']+.*?>/",
  136. "url" => "/(([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?/"
  137. );
  138. }
  139. public function init(&$oDb)
  140. {
  141. parent::init($oDb);
  142. $sOptionPrefix = $this->getPrefix('option');
  143. $this->_bAllowDelete = getParam($sOptionPrefix . 'enable_delete') == 'on';
  144. $this->_aPerPage = array(
  145. 'default' => (int)getParam($sOptionPrefix . 'events_per_page'),
  146. 'profile' => (int)getParam($sOptionPrefix . 'events_per_page_profile'),
  147. 'account' => (int)getParam($sOptionPrefix . 'events_per_page_account'),
  148. 'home' => (int)getParam($sOptionPrefix . 'events_per_page_home')
  149. );
  150. $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');
  151. $this->_iCharsDisplayMax = (int)getParam($sOptionPrefix . 'chars_display_max');
  152. $this->_iCharsDisplayMaxTitle = 20;
  153. }
  154. public function isAllowDelete()
  155. {
  156. return $this->_bAllowDelete;
  157. }
  158. public function getUploaders($sType)
  159. {
  160. $aResult = array();
  161. switch($sType) {
  162. case 'photo':
  163. $aResult = $this->_aPhotoUploaders;
  164. break;
  165. case 'video':
  166. $aResult = $this->_aVideoUploaders;
  167. break;
  168. }
  169. return $aResult;
  170. }
  171. public function getRssLength()
  172. {
  173. return $this->_iRssLength;
  174. }
  175. public function getCharsDisplayMax()
  176. {
  177. return $this->_iCharsDisplayMax;
  178. }
  179. public function getCharsDisplayMaxTitle()
  180. {
  181. return $this->_iCharsDisplayMaxTitle;
  182. }
  183. public function getRepostDefaults()
  184. {
  185. return $this->_aRepostDefaults;
  186. }
  187. public function getPregPattern($sType)
  188. {
  189. return $this->_aPregPatterns[$sType];
  190. }
  191. /**
  192. * Ancillary functions
  193. */
  194. public function getTitle($s)
  195. {
  196. return strmaxtextlen($s, $this->getCharsDisplayMaxTitle(), '...');
  197. }
  198. public function getViewUrl($iOwnerId)
  199. {
  200. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=timeline-view&id=' . $iOwnerId);
  201. }
  202. public function getHomeViewUrl()
  203. {
  204. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=timeline-view-home');
  205. }
  206. public function getItemViewUrl(&$aEvent)
  207. {
  208. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=timeline-item&id=' . $aEvent['id']);
  209. }
  210. public function isSystem($sType, $sAction)
  211. {
  212. $sPrefix = $this->getPrefix('common_post');
  213. return strpos($sType, $sPrefix) === false && !empty($sAction);
  214. }
  215. public function getSystemData(&$aEvent)
  216. {
  217. $sHandler = $aEvent['type'] . '_' . $aEvent['action'];
  218. if(!$this->isHandler($sHandler))
  219. return false;
  220. $aHandler = $this->getHandlers($sHandler);
  221. if(empty($aHandler['module_name']) || empty($aHandler['module_class']) || empty($aHandler['module_method']))
  222. return false;
  223. return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent), $aHandler['module_class']);
  224. }
  225. public function getSystemDataByDescriptor($sType, $sAction, $iObjectId)
  226. {
  227. $aDescriptor = array(
  228. 'type' => $sType,
  229. 'action' => $sAction,
  230. 'object_id' => $iObjectId
  231. );
  232. return $this->getSystemData($aDescriptor);
  233. }
  234. public function isEqualUrls($sUrl1, $sUrl2)
  235. {
  236. $sUrl1 = trim($sUrl1, "/");
  237. $sUrl2 = trim($sUrl2, "/");
  238. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  239. }
  240. }
  241. /** @} */