BxTimelineConfig.php 9.7 KB

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