26function notificationEnabled($style, $module_id=
null)
28 if (isset($GLOBALS[
'xoopsModuleConfig'][
'notification_enabled'])) {
29 $status = $GLOBALS[
'xoopsModuleConfig'][
'notification_enabled'];
31 if (!isset($module_id)) {
34 $module_handler =& xoops_gethandler(
'module');
35 $module =& $module_handler->get($module_id);
36 if (!empty($module) && 1 == $module->getVar(
'hasnotification')) {
37 $config_handler =& xoops_gethandler(
'config');
38 $config = $config_handler->getConfigsByCat(0, $module_id);
39 $status = $config[
'notification_enabled'];
44 include_once XOOPS_ROOT_PATH .
'/include/notification_constants.php';
45 if ((
'block' == $style) && (XOOPS_NOTIFICATION_ENABLEBLOCK == $status || XOOPS_NOTIFICATION_ENABLEBOTH == $status)) {
48 if ((
'inline' == $style) && (XOOPS_NOTIFICATION_ENABLEINLINE == $status || XOOPS_NOTIFICATION_ENABLEBOTH == $status)) {
66function ¬ificationCategoryInfo($category_name =
null, $module_id =
null)
68 if (!isset($module_id)) {
70 $module_id = !empty($xoopsModule) ? $xoopsModule->getVar(
'mid') : 0;
71 $module =& $xoopsModule;
73 $module_handler =& xoops_gethandler(
'module');
74 $module =& $module_handler->get($module_id);
77 if (!is_object($module)) {
82 $not_config =& $module->getInfo(
'notification');
83 if (
null == $category_name) {
84 return $not_config[
'category'];
86 foreach ($not_config[
'category'] as $category) {
87 if ($category[
'name'] == $category_name) {
107function ¬ificationCommentCategoryInfo($module_id=
null)
109 $all_categories =& notificationCategoryInfo(
'', $module_id);
110 if (empty($all_categories)) {
113 foreach ($all_categories as $category) {
114 $all_events =& notificationEvents($category[
'name'],
false, $module_id);
115 if (empty($all_events)) {
118 foreach ($all_events as $event) {
119 if (
'comment' == $event[
'name']) {
140function ¬ificationEvents($category_name, $enabled_only, $module_id=
null)
142 if (!isset($module_id)) {
144 $module_id = !empty($xoopsModule) ? $xoopsModule->getVar(
'mid') : 0;
145 $module =& $xoopsModule;
147 $module_handler =& xoops_gethandler(
'module');
148 $module =& $module_handler->get($module_id);
151 if (!is_object($module)) {
156 $not_config =& $module->getInfo(
'notification');
157 $config_handler =& xoops_gethandler(
'config');
158 $mod_config = $config_handler->getConfigsByCat(0, $module_id);
160 $category =& notificationCategoryInfo($category_name, $module_id);
165 $override_comment =
false;
166 $override_commentsubmit =
false;
167 $override_bookmark =
false;
169 foreach ($not_config[
'event'] as $event) {
170 if ($event[
'category'] == $category_name) {
171 $event[
'mail_template_dir'] = XOOPS_ROOT_PATH .
'/modules/' . $module->getVar(
'dirname') .
'/language/' . $xoopsConfig[
'language'] .
'/mail_template/';
172 if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
173 $event_array[] = $event;
175 if (
'comment' == $event[
'name']) {
176 $override_comment =
true;
178 if (
'comment_submit' == $event[
'name']) {
179 $override_commentsubmit =
true;
181 if (
'bookmark' == $event[
'name']) {
182 $override_bookmark =
true;
188 $root =& XCube_Root::getSingleton();
189 $root->mLanguageManager->loadPageTypeMessageCatalog(
'notification');
193 if ($module->getVar(
'hascomments')) {
194 $com_config = $module->getInfo(
'comments');
195 if (!empty($category[
'item_name']) && $category[
'item_name'] == $com_config[
'itemName']) {
196 $mail_template_dir = XOOPS_ROOT_PATH .
'/language/' . $xoopsConfig[
'language'] .
'/mail_template/';
197 include_once XOOPS_ROOT_PATH .
'/include/comment_constants.php';
198 $config_handler =& xoops_gethandler(
'config');
199 $com_config = $config_handler->getConfigsByCat(0, $module_id);
200 if (!$enabled_only) {
201 $insert_comment =
true;
202 $insert_submit =
true;
204 $insert_comment =
false;
205 $insert_submit =
false;
206 switch ($com_config[
'com_rule']) {
207 case XOOPS_COMMENT_APPROVENONE:
210 case XOOPS_COMMENT_APPROVEALL:
212 if (!$override_comment) {
213 $insert_comment =
true;
216 case XOOPS_COMMENT_APPROVEUSER:
217 case XOOPS_COMMENT_APPROVEADMIN:
219 if (!$override_comment) {
220 $insert_comment =
true;
222 if (!$override_commentsubmit) {
223 $insert_submit =
true;
228 if ($insert_comment) {
229 $event = [
'name' =>
'comment',
'category' => $category[
'name'],
'title' =>_NOT_COMMENT_NOTIFY,
'caption' =>_NOT_COMMENT_NOTIFYCAP,
'description' =>_NOT_COMMENT_NOTIFYDSC,
'mail_template_dir' =>$mail_template_dir,
'mail_template' =>
'comment_notify',
'mail_subject' =>_NOT_COMMENT_NOTIFYSBJ];
230 if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
231 $event_array[] = $event;
234 if ($insert_submit) {
235 $event = [
'name' =>
'comment_submit',
'category' => $category[
'name'],
'title' =>_NOT_COMMENTSUBMIT_NOTIFY,
'caption' =>_NOT_COMMENTSUBMIT_NOTIFYCAP,
'description' =>_NOT_COMMENTSUBMIT_NOTIFYDSC,
'mail_template_dir' =>$mail_template_dir,
'mail_template' =>
'commentsubmit_notify',
'mail_subject' =>_NOT_COMMENTSUBMIT_NOTIFYSBJ,
'admin_only' =>1];
236 if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
237 $event_array[] = $event;
245 if (!empty($category[
'allow_bookmark'])) {
246 if (!$override_bookmark) {
247 $event = [
'name' =>
'bookmark',
'category' => $category[
'name'],
'title' =>_NOT_BOOKMARK_NOTIFY,
'caption' =>_NOT_BOOKMARK_NOTIFYCAP,
'description' =>_NOT_BOOKMARK_NOTIFYDSC];
248 if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
249 $event_array[] = $event;
269function notificationEventEnabled(&$category, &$event, &$module)
271 $config_handler =& xoops_gethandler(
'config');
272 $mod_config = $config_handler->getConfigsByCat(0, $module->getVar(
'mid'));
274 $option_name = notificationGenerateConfig($category, $event,
'option_name');
275 if (is_array($mod_config[
'notification_events']) && in_array($option_name, $mod_config[
'notification_events'])) {
278 $notification_handler =& xoops_gethandler(
'notification');
293function ¬ificationEventInfo($category_name, $event_name, $module_id=
null)
295 $all_events =& notificationEvents($category_name,
false, $module_id);
296 if (is_array($all_events)) {
297 foreach ($all_events as $event) {
298 if ($event[
'name'] == $event_name) {
317function ¬ificationSubscribableCategoryInfo($module_id=
null)
319 $all_categories =& notificationCategoryInfo(
'', $module_id);
322 $script_url = explode(
'/', xoops_getenv(
'PHP_SELF'));
323 $script_name = $script_url[count($script_url)-1];
325 $sub_categories = [];
327 foreach ($all_categories as $category) {
330 $subscribe_from = $category[
'subscribe_from'];
331 if (!is_array($subscribe_from)) {
332 if (
'*' == $subscribe_from) {
333 $subscribe_from = [$script_name];
336 $subscribe_from = [$subscribe_from];
339 if (!in_array($script_name, $subscribe_from)) {
346 if (empty($category[
'item_name'])) {
347 $category[
'item_name'] =
'';
348 $category[
'item_id'] = 0;
349 $sub_categories[] = $category;
351 $item_name = $category[
'item_name'];
352 $id = (
'' !== $item_name && isset($_GET[$item_name])) ? (
int)$_GET[$item_name] : 0;
354 $category[
'item_id'] = $id;
355 $sub_categories[] = $category;
359 return $sub_categories;
376function notificationGenerateConfig(&$category, &$event, $type)
381 return 'notify:' . $category[
'name'] .
'-' . $event[
'name'];
384 return $category[
'name'] .
'-' . $event[
'name'];