BxNtfsConfig.php 10 KB

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