1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: |
|
20: | use Xmf\Request;
|
21: |
|
22: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
23: |
|
24: |
|
25: |
|
26: |
|
27: |
|
28: |
|
29: | |
30: | |
31: | |
32: | |
33: | |
34: | |
35: |
|
36: | function notificationEnabled($style, $module_id = null)
|
37: | {
|
38: | if (isset($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
|
39: | $status = $GLOBALS['xoopsModuleConfig']['notification_enabled'];
|
40: | } else {
|
41: | if (!isset($module_id)) {
|
42: | return false;
|
43: | }
|
44: |
|
45: | $module_handler = xoops_getHandler('module');
|
46: | $module = $module_handler->get($module_id);
|
47: | if (!empty($module) && $module->getVar('hasnotification') == 1) {
|
48: |
|
49: | $config_handler = xoops_getHandler('config');
|
50: | $config = $config_handler->getConfigsByCat(0, $module_id);
|
51: | $status = $config['notification_enabled'];
|
52: | } else {
|
53: | return false;
|
54: | }
|
55: | }
|
56: | include_once $GLOBALS['xoops']->path('include/notification_constants.php');
|
57: | if (($style === 'block') && ($status === XOOPS_NOTIFICATION_ENABLEBLOCK || $status === XOOPS_NOTIFICATION_ENABLEBOTH)) {
|
58: | return true;
|
59: | }
|
60: |
|
61: | return ($style === 'inline') && ($status === XOOPS_NOTIFICATION_ENABLEINLINE || $status === XOOPS_NOTIFICATION_ENABLEBOTH);
|
62: | }
|
63: |
|
64: | |
65: | |
66: | |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | |
73: | |
74: |
|
75: | function ¬ificationCategoryInfo($category_name = '', $module_id = null)
|
76: | {
|
77: | if (!isset($module_id)) {
|
78: | global $xoopsModule;
|
79: | $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0;
|
80: | $module =& $xoopsModule;
|
81: | } else {
|
82: |
|
83: | $module_handler = xoops_getHandler('module');
|
84: | $module = $module_handler->get($module_id);
|
85: | }
|
86: | $not_config = &$module->getInfo('notification');
|
87: | if (empty($category_name)) {
|
88: | return $not_config['category'];
|
89: | }
|
90: | foreach ($not_config['category'] as $category) {
|
91: | if ($category['name'] == $category_name) {
|
92: | return $category;
|
93: | }
|
94: | }
|
95: | $ret = false;
|
96: |
|
97: | return $ret;
|
98: | }
|
99: |
|
100: | |
101: | |
102: | |
103: | |
104: | |
105: | |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: |
|
113: | function ¬ificationCommentCategoryInfo($module_id = null)
|
114: | {
|
115: | $ret = false;
|
116: | $all_categories =& notificationCategoryInfo('', $module_id);
|
117: | if (empty($all_categories)) {
|
118: | return $ret;
|
119: | }
|
120: | foreach ($all_categories as $category) {
|
121: | $all_events =& notificationEvents($category['name'], false, $module_id);
|
122: | if (empty($all_events)) {
|
123: | continue;
|
124: | }
|
125: | foreach ($all_events as $event) {
|
126: | if ($event['name'] === 'comment') {
|
127: | return $category;
|
128: | }
|
129: | }
|
130: | }
|
131: |
|
132: | return $ret;
|
133: | }
|
134: |
|
135: |
|
136: |
|
137: | |
138: | |
139: | |
140: | |
141: | |
142: | |
143: | |
144: | |
145: |
|
146: | function ¬ificationEvents($category_name, $enabled_only, $module_id = null)
|
147: | {
|
148: | if (!isset($module_id)) {
|
149: | global $xoopsModule;
|
150: | $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0;
|
151: | $module =& $xoopsModule;
|
152: | } else {
|
153: |
|
154: | $module_handler = xoops_getHandler('module');
|
155: | $module = $module_handler->get($module_id);
|
156: | }
|
157: | $not_config = $module->getInfo('notification');
|
158: |
|
159: | $config_handler = xoops_getHandler('config');
|
160: | $mod_config = $config_handler->getConfigsByCat(0, $module_id);
|
161: |
|
162: | $category =& notificationCategoryInfo($category_name, $module_id);
|
163: |
|
164: | global $xoopsConfig;
|
165: | $event_array = array();
|
166: |
|
167: | $override_comment = false;
|
168: | $override_commentsubmit = false;
|
169: | $override_bookmark = false;
|
170: |
|
171: | foreach ($not_config['event'] as $event) {
|
172: | if ($event['category'] == $category_name) {
|
173: | if (!is_dir($dir = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/')) {
|
174: | $dir = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/language/english/mail_template/';
|
175: | }
|
176: | $event['mail_template_dir'] = $dir;
|
177: | if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
|
178: | $event_array[] = $event;
|
179: | }
|
180: | if ($event['name'] === 'comment') {
|
181: | $override_comment = true;
|
182: | }
|
183: | if ($event['name'] === 'comment_submit') {
|
184: | $override_commentsubmit = true;
|
185: | }
|
186: | if ($event['name'] === 'bookmark') {
|
187: | $override_bookmark = true;
|
188: | }
|
189: | }
|
190: | }
|
191: |
|
192: | xoops_loadLanguage('notification');
|
193: |
|
194: |
|
195: | if ($module->getVar('hascomments')) {
|
196: | $com_config = $module->getInfo('comments');
|
197: | if (!empty($category['item_name']) && $category['item_name'] == $com_config['itemName']) {
|
198: | if (!is_dir($dir = XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/mail_template/')) {
|
199: | $dir = XOOPS_ROOT_PATH . '/language/english/mail_template/';
|
200: | }
|
201: | $mail_template_dir = $dir;
|
202: |
|
203: | include_once $GLOBALS['xoops']->path('include/comment_constants.php');
|
204: |
|
205: | $config_handler = xoops_getHandler('config');
|
206: | $com_config = $config_handler->getConfigsByCat(0, $module_id);
|
207: | if (!$enabled_only) {
|
208: | $insert_comment = true;
|
209: | $insert_submit = true;
|
210: | } else {
|
211: | $insert_comment = false;
|
212: | $insert_submit = false;
|
213: | switch ($com_config['com_rule']) {
|
214: | case XOOPS_COMMENT_APPROVENONE:
|
215: |
|
216: | break;
|
217: | case XOOPS_COMMENT_APPROVEALL:
|
218: |
|
219: | if (!$override_comment) {
|
220: | $insert_comment = true;
|
221: | }
|
222: | break;
|
223: | case XOOPS_COMMENT_APPROVEUSER:
|
224: | case XOOPS_COMMENT_APPROVEADMIN:
|
225: |
|
226: | if (!$override_comment) {
|
227: | $insert_comment = true;
|
228: | }
|
229: | if (!$override_commentsubmit) {
|
230: | $insert_submit = true;
|
231: | }
|
232: | break;
|
233: | }
|
234: | }
|
235: | if ($insert_comment) {
|
236: | $event = array(
|
237: | 'name' => 'comment',
|
238: | 'category' => $category['name'],
|
239: | 'title' => _NOT_COMMENT_NOTIFY,
|
240: | 'caption' => _NOT_COMMENT_NOTIFYCAP,
|
241: | 'description' => _NOT_COMMENT_NOTIFYDSC,
|
242: | 'mail_template_dir' => $mail_template_dir,
|
243: | 'mail_template' => 'comment_notify',
|
244: | 'mail_subject' => _NOT_COMMENT_NOTIFYSBJ);
|
245: | if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
|
246: | $event_array[] = $event;
|
247: | }
|
248: | }
|
249: | if ($insert_submit) {
|
250: | $event = array(
|
251: | 'name' => 'comment_submit',
|
252: | 'category' => $category['name'],
|
253: | 'title' => _NOT_COMMENTSUBMIT_NOTIFY,
|
254: | 'caption' => _NOT_COMMENTSUBMIT_NOTIFYCAP,
|
255: | 'description' => _NOT_COMMENTSUBMIT_NOTIFYDSC,
|
256: | 'mail_template_dir' => $mail_template_dir,
|
257: | 'mail_template' => 'commentsubmit_notify',
|
258: | 'mail_subject' => _NOT_COMMENTSUBMIT_NOTIFYSBJ,
|
259: | 'admin_only' => 1);
|
260: | if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
|
261: | $event_array[] = $event;
|
262: | }
|
263: | }
|
264: | }
|
265: | }
|
266: |
|
267: |
|
268: |
|
269: | if (!empty($category['allow_bookmark'])) {
|
270: | if (!$override_bookmark) {
|
271: | $event = array(
|
272: | 'name' => 'bookmark',
|
273: | 'category' => $category['name'],
|
274: | 'title' => _NOT_BOOKMARK_NOTIFY,
|
275: | 'caption' => _NOT_BOOKMARK_NOTIFYCAP,
|
276: | 'description' => _NOT_BOOKMARK_NOTIFYDSC);
|
277: | if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
|
278: | $event_array[] = $event;
|
279: | }
|
280: | }
|
281: | }
|
282: |
|
283: | return $event_array;
|
284: | }
|
285: |
|
286: | |
287: | |
288: | |
289: | |
290: | |
291: | |
292: | |
293: | |
294: | |
295: | |
296: | |
297: |
|
298: | function notificationEventEnabled(&$category, &$event, &$module)
|
299: | {
|
300: |
|
301: | $config_handler = xoops_getHandler('config');
|
302: | $mod_config = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
|
303: |
|
304: | if (is_array($mod_config['notification_events']) && $mod_config['notification_events'] != array()) {
|
305: | $option_name = notificationGenerateConfig($category, $event, 'option_name');
|
306: | if (in_array($option_name, $mod_config['notification_events'])) {
|
307: | return true;
|
308: | }
|
309: | $notification_handler = xoops_getHandler('notification');
|
310: | }
|
311: |
|
312: | return false;
|
313: | }
|
314: |
|
315: | |
316: | |
317: | |
318: | |
319: | |
320: | |
321: | |
322: | |
323: |
|
324: | function ¬ificationEventInfo($category_name, $event_name, $module_id = null)
|
325: | {
|
326: | $all_events =& notificationEvents($category_name, false, $module_id);
|
327: | foreach ($all_events as $event) {
|
328: | if ($event['name'] == $event_name) {
|
329: | return $event;
|
330: | }
|
331: | }
|
332: | $ret = false;
|
333: |
|
334: | return $ret;
|
335: | }
|
336: |
|
337: | |
338: | |
339: | |
340: | |
341: | |
342: | |
343: |
|
344: |
|
345: | function ¬ificationSubscribableCategoryInfo($module_id = null)
|
346: | {
|
347: | $all_categories =& notificationCategoryInfo('', $module_id);
|
348: |
|
349: |
|
350: | $script_url = explode('/', $_SERVER['PHP_SELF']);
|
351: | $script_name = $script_url[count($script_url) - 1];
|
352: |
|
353: | $sub_categories = array();
|
354: | if (null != $all_categories) {
|
355: | foreach ($all_categories as $category) {
|
356: |
|
357: | $subscribe_from = $category['subscribe_from'];
|
358: | if (!is_array($subscribe_from)) {
|
359: | if ($subscribe_from === '*') {
|
360: | $subscribe_from = array(
|
361: | $script_name);
|
362: |
|
363: | } else {
|
364: | $subscribe_from = array(
|
365: | $subscribe_from);
|
366: | }
|
367: | }
|
368: | if (!in_array($script_name, $subscribe_from)) {
|
369: | continue;
|
370: | }
|
371: |
|
372: |
|
373: | if (empty($category['item_name'])) {
|
374: | $category['item_name'] = '';
|
375: | $category['item_id'] = 0;
|
376: | $sub_categories[] = $category;
|
377: | } else {
|
378: | $item_name = $category['item_name'];
|
379: | $id = ($item_name != '' && isset($_GET[$item_name])) ? Request::getInt($item_name, 0, 'GET'): 0;
|
380: | if ($id > 0) {
|
381: | $category['item_id'] = $id;
|
382: | $sub_categories[] = $category;
|
383: | }
|
384: | }
|
385: | }
|
386: | }
|
387: | return $sub_categories;
|
388: | }
|
389: |
|
390: | |
391: | |
392: | |
393: | |
394: | |
395: | |
396: | |
397: | |
398: | |
399: | |
400: | |
401: | |
402: | |
403: | |
404: |
|
405: | function notificationGenerateConfig(&$category, &$event, $type)
|
406: | {
|
407: | switch ($type) {
|
408: | case 'option_value':
|
409: | case 'name':
|
410: | return 'notify:' . $category['name'] . '-' . $event['name'];
|
411: | break;
|
412: | case 'option_name':
|
413: | return $category['name'] . '-' . $event['name'];
|
414: | break;
|
415: | default:
|
416: | return false;
|
417: | break;
|
418: | }
|
419: | }
|
420: | |