BxTimelineConfig.php 8.5 KB

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