BxTimelineConfig.php 10 KB

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