BxNtfsConfig.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 Notifications Notifications
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolPrivacy');
  12. class BxNtfsConfig extends BxBaseModNotificationsConfig
  13. {
  14. protected $_iSummaryMaxLen;
  15. protected $_iOwnerNameMaxLen;
  16. protected $_iContentMaxLen;
  17. protected $_iPushMaxLen;
  18. protected $_iEmailSubjectMaxLen;
  19. protected $_aHandlersHiddenEmail;
  20. protected $_aHandlersHiddenPush;
  21. /**
  22. * Group settings by action. Enabled by default.
  23. */
  24. protected $_bSettingsGrouped;
  25. protected $_aSettingsTypes;
  26. protected $_aDeliveryTypes;
  27. protected $_aModulesProfiles;
  28. protected $_aModulesContexts;
  29. protected $_iDeliveryTimeout;
  30. protected $_bEventsGrouped;
  31. protected $_bClickedIndicator;
  32. /**
  33. * Constructor
  34. */
  35. public function __construct($aModule)
  36. {
  37. parent::__construct($aModule);
  38. $this->CNF = array (
  39. // page URIs
  40. 'URL_HOME' => 'page.php?i=notifications-view',
  41. // some params
  42. 'PARAM_QUEUE_ADD_THRESHOLD' => 0,
  43. 'PARAM_COMMENT_POST_EXT' => 'bx_notifications_enable_comment_post_ext',
  44. 'PARAM_REPLY_AS_COMMENT' => 'bx_notifications_enable_reply_as_comment',
  45. 'PARAM_PROCESSED_EVENT' => 'bx_notifications_processed_event',
  46. // objects
  47. 'OBJECT_MENU_SUBMENU' => 'bx_notifications_submenu', // main module submenu
  48. 'OBJECT_MENU_SETTINGS' => 'bx_notifications_settings', // settings submenu
  49. 'OBJECT_GRID_SETTINGS_ADMINISTRATION' => 'bx_notifications_settings_administration',
  50. 'OBJECT_GRID_SETTINGS_COMMON' => 'bx_notifications_settings_common',
  51. // some language keys
  52. 'T' => array(
  53. 'setting_personal' => '_bx_ntfs_setting_type_personal',
  54. 'setting_follow_member' => '_bx_ntfs_setting_type_follow_member',
  55. 'setting_follow_context' => '_bx_ntfs_setting_type_follow_context',
  56. 'setting_other' => '_bx_ntfs_setting_type_other',
  57. )
  58. );
  59. $this->_aPrefixes = array(
  60. 'style' => 'bx-ntfs',
  61. 'language' => '_bx_ntfs',
  62. 'option' => 'bx_notifications_'
  63. );
  64. $this->_iSummaryMaxLen = 0;
  65. $this->_iOwnerNameMaxLen = 0;
  66. $this->_iContentMaxLen = 0;
  67. $this->_iEmailSubjectMaxLen = 0;
  68. $this->_iPushMaxLen = 0;
  69. $this->_aHandlerDescriptor = array('module_name' => '', 'module_method' => '', 'module_class' => '');
  70. $this->_sHandlersMethod = 'get_notifications_data';
  71. $this->_aHandlersHiddenEmail = array();
  72. $this->_aHandlersHiddenPush = array();
  73. $this->_bSettingsGrouped = true;
  74. $this->_aSettingsTypes = array(
  75. BX_NTFS_STYPE_PERSONAL,
  76. BX_NTFS_STYPE_FOLLOW_MEMBER,
  77. BX_NTFS_STYPE_FOLLOW_CONTEXT,
  78. //BX_NTFS_STYPE_OTHER //TODO: May be it can be removed, because there is no events(alerts) for this type.
  79. );
  80. $this->_aDeliveryTypes = [
  81. BX_NTFS_DTYPE_SITE,
  82. BX_NTFS_DTYPE_EMAIL,
  83. BX_NTFS_DTYPE_PUSH
  84. ];
  85. $this->_aModulesProfiles = false;
  86. $this->_aModulesContexts = false;
  87. $this->_aJsClasses = array(
  88. 'main' => 'BxNtfsMain',
  89. 'view' => 'BxNtfsView',
  90. );
  91. $this->_aJsObjects = array(
  92. 'main' => 'oBxNtfsMain',
  93. 'view' => 'oBxNtfsView',
  94. );
  95. $sHtmlPrefix = str_replace('_', '-', $this->_sName);
  96. $this->_aHtmlIds = array(
  97. 'view' => array(
  98. 'block' => $sHtmlPrefix,
  99. 'events' => $sHtmlPrefix . '-events',
  100. 'event' => $sHtmlPrefix . '-event-'
  101. )
  102. );
  103. }
  104. public function init(&$oDb)
  105. {
  106. parent::init($oDb);
  107. $sOptionPrefix = $this->getPrefix('option');
  108. $this->_aPerPage = array(
  109. 'default' => (int)getParam($sOptionPrefix . 'events_per_page'),
  110. 'preview' => (int)getParam($sOptionPrefix . 'events_per_preview')
  111. );
  112. $this->_bSettingsGrouped = getParam($sOptionPrefix . 'enable_group_settings') == 'on';
  113. $aSettings = array(
  114. 'site' => '',
  115. 'email' => 'Email',
  116. 'push' => 'Push'
  117. );
  118. foreach($aSettings as $sSetting => $sVariable) {
  119. $sHideTimeline = getParam($sOptionPrefix . 'events_hide_' . $sSetting);
  120. if(!empty($sHideTimeline))
  121. $this->{'_aHandlersHidden' . $sVariable} = explode(',', $sHideTimeline);
  122. }
  123. $this->_iDeliveryTimeout = (int)getParam($sOptionPrefix . 'delivery_timeout');
  124. $this->_bEventsGrouped = getParam($sOptionPrefix . 'enable_group_events') == 'on';
  125. $this->_bClickedIndicator = getParam($sOptionPrefix . 'enable_clicked_indicator') == 'on';
  126. $this->_iSummaryMaxLen = (int)getParam($sOptionPrefix . 'summary_chars');
  127. $this->_iOwnerNameMaxLen = (int)getParam($sOptionPrefix . 'owner_name_chars');
  128. $this->_iContentMaxLen = (int)getParam($sOptionPrefix . 'content_chars');
  129. $this->_iEmailSubjectMaxLen = (int)getParam($sOptionPrefix . 'email_subject_chars');
  130. $this->_iPushMaxLen = (int)getParam($sOptionPrefix . 'push_message_chars');
  131. }
  132. public function getSummaryMaxLen()
  133. {
  134. return $this->_iSummaryMaxLen;
  135. }
  136. public function getOwnerNameMaxLen()
  137. {
  138. return $this->_iOwnerNameMaxLen;
  139. }
  140. public function getContentMaxLen()
  141. {
  142. return $this->_iContentMaxLen;
  143. }
  144. public function getPushMaxLen()
  145. {
  146. return $this->_iPushMaxLen;
  147. }
  148. public function getEmailSubjectMaxLen()
  149. {
  150. return $this->_iEmailSubjectMaxLen;
  151. }
  152. public function getHandlersHidden($sType = '')
  153. {
  154. if(!in_array($sType, array('', 'email', 'push')))
  155. return array();
  156. return $this->{'_aHandlersHidden' . ucfirst($sType)};
  157. }
  158. public function isSettingsGrouped()
  159. {
  160. return $this->_bSettingsGrouped;
  161. }
  162. public function getSettingsTypes()
  163. {
  164. return $this->_aSettingsTypes;
  165. }
  166. public function getDeliveryTypes()
  167. {
  168. return $this->_aDeliveryTypes;
  169. }
  170. public function getDeliveryTimeout()
  171. {
  172. return $this->_iDeliveryTimeout;
  173. }
  174. public function isEventsGrouped()
  175. {
  176. return $this->_bEventsGrouped;
  177. }
  178. public function isClickedIndicator()
  179. {
  180. return $this->_bClickedIndicator;
  181. }
  182. public function getProcessedEvent()
  183. {
  184. return (int)getParam($this->CNF['PARAM_PROCESSED_EVENT'], false);
  185. }
  186. public function setProcessedEvent($iEvent)
  187. {
  188. setParam($this->CNF['PARAM_PROCESSED_EVENT'], $iEvent);
  189. }
  190. /**
  191. * Ancillary functions
  192. */
  193. public function getViewUrl()
  194. {
  195. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=notifications-view'));
  196. }
  197. public function getContentModule(&$aEvent)
  198. {
  199. $sModule = $aEvent['type'];
  200. if($this->_oDb->isEnabledByName($sModule))
  201. return $sModule;
  202. $sModule = str_replace(array('_media', '_reactions'), array('', ''), $sModule);
  203. if($this->_oDb->isEnabledByName($sModule))
  204. return $sModule;
  205. return '';
  206. }
  207. public function getContentObjectId(&$aEvent)
  208. {
  209. $bContentObjectId = !empty($aEvent['content']['object_id']);
  210. if(!$bContentObjectId) {
  211. if(in_array($aEvent['action'], ['replyPost']))
  212. return false;
  213. if(strpos($aEvent['type'], '_media') !== false && in_array($aEvent['action'], ['commentPost', 'doVote', 'doVoteUp', 'doVoteDown']))
  214. return false;
  215. }
  216. return $bContentObjectId ? (int)$aEvent['content']['object_id'] : (int)$aEvent['object_id'];
  217. }
  218. public function getProfileBasedModules()
  219. {
  220. if ($this->_aModulesProfiles !== false && $this->_aModulesContexts !== false)
  221. return array($this->_aModulesProfiles, $this->_aModulesContexts);
  222. if (getParam('sys_db_cache_enable')) {
  223. $oDb = BxDolDb::getInstance();
  224. $oCache = $oDb->getDbCacheObject();
  225. $sCacheKey = $oDb->genDbCacheKey('bx_ntfs_profile_based_modules');
  226. $aData = $oCache->getData($sCacheKey);
  227. if (null === $aData) {
  228. $aData = $this->_getProfileBasedModulesData();
  229. $oCache->setData ($sCacheKey, $aData);
  230. }
  231. }
  232. else {
  233. $aData = $this->_getProfileBasedModulesData();
  234. }
  235. return $aData;
  236. }
  237. protected function _getProfileBasedModulesData()
  238. {
  239. $this->_aModulesProfiles = [];
  240. $this->_aModulesContexts = [];
  241. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules']);
  242. foreach($aModules as $aModule) {
  243. if(!bx_is_srv($aModule['name'], 'act_as_profile'))
  244. continue;
  245. if(bx_srv($aModule['name'], 'act_as_profile'))
  246. $this->_aModulesProfiles[] = $aModule['name'];
  247. else
  248. $this->_aModulesContexts[] = $aModule['name'];
  249. }
  250. return [$this->_aModulesProfiles, $this->_aModulesContexts];
  251. }
  252. }
  253. /** @} */