BxNtfsConfig.php 7.7 KB

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