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