1: 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: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 909: 910: 911: 912: 913: 914: 915: 916: 917: 918: 919: 920: 921: 922: 923: 924: 925: 926: 927: 928: 929: 930: 931: 932: 933: 934: 935: 936: 937: 938: 939: 940: 941: 942: 943: 944: 945: 946: 947: 948: 949: 950: 951: 952: 953: 954: 955: 956: 957: 958: 959: 960: 961: 962: 963: 964: 965: 966: 967: 968: 969: 970: 971: 972: 973: 974: 975: 976: 977: 978: 979: 980: 981: 982: 983: 984: 985: 986: 987: 988: 989: 990: 991: 992: 993: 994: 995: 996: 997: 998: 999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047:
<?php
defined('ICMS_ROOT_PATH') or die('ImpressCMS root path not defined');
include_once ICMS_ROOT_PATH . '/include/notification_constants.php';
class icms_data_notification_Handler extends icms_core_ObjectHandler {
public function &create($isNew = true) {
$notification = new icms_data_notification_Object();
if ($isNew) {
$notification->setNew();
}
return $notification;
}
public function &get($id) {
$notification = false;
$id = (int) $id;
if ($id > 0) {
$sql = "SELECT * FROM ".$this->db->prefix('xoopsnotifications')." WHERE not_id='".$id."'";
if (!$result = $this->db->query($sql)) {
return $notification;
}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$notification = new icms_data_notification_Object();
$notification->assignVars($this->db->fetchArray($result));
}
}
return $notification;
}
public function insert(&$notification) {
if (!is_a($notification, 'icms_data_notification_Object')) {
return false;
}
if (!$notification->isDirty()) {
return true;
}
if (!$notification->cleanVars()) {
return false;
}
foreach ($notification->cleanVars as $k => $v) {
${$k} = $v;
}
if ($notification->isNew()) {
$not_id = $this->db->genId('xoopsnotifications_not_id_seq');
$sql = sprintf("INSERT INTO %s (not_id, not_modid, not_itemid, not_category, not_uid, not_event, not_mode) VALUES ('%u', '%u', '%u', %s, '%u', %s, '%u')", $this->db->prefix('xoopsnotifications'), (int) $not_id, (int) $not_modid, (int) $not_itemid, $this->db->quoteString($not_category), (int) $not_uid, $this->db->quoteString($not_event), (int) $not_mode);
} else {
$sql = sprintf("UPDATE %s SET not_modid = '%u', not_itemid = '%u', not_category = %s, not_uid = '%u', not_event = %s, not_mode = '%u' WHERE not_id = '%u'", $this->db->prefix('xoopsnotifications'), (int) $not_modid, (int) $not_itemid, $this->db->quoteString($not_category), (int) $not_uid, $this->db->quoteString($not_event), (int) $not_mode, (int) $not_id);
}
if (!$result = $this->db->query($sql)) {
return false;
}
if (empty($not_id)) {
$not_id = $this->db->getInsertId();
}
$notification->assignVar('not_id', (int)$not_id);
return true;
}
public function delete(&$notification) {
if (!is_a($notification, 'icms_data_notification_Object')) {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE not_id = '%u'", $this->db->prefix('xoopsnotifications'), (int)$notification->getVar('not_id'));
if (!$result = $this->db->query($sql)) {
return false;
}
return true;
}
public function getObjects($criteria = null, $id_as_key = false) {
$ret = array();
$limit = $start = 0;
$sql = 'SELECT * FROM '.$this->db->prefix('xoopsnotifications');
if (isset($criteria) && is_subclass_of($criteria, 'icms_db_criteria_Element')) {
$sql .= ' '.$criteria->renderWhere();
$sort = ($criteria->getSort() != '') ? $criteria->getSort() : 'not_id';
$sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder();
$limit = $criteria->getLimit();
$start = $criteria->getStart();
}
$result = $this->db->query($sql, $limit, $start);
if (!$result) {
return $ret;
}
while ($myrow = $this->db->fetchArray($result)) {
$notification = new icms_data_notification_Object();
$notification->assignVars($myrow);
if (!$id_as_key) {
$ret[] =& $notification;
} else {
$ret[$myrow['not_id']] =& $notification;
}
unset($notification);
}
return $ret;
}
public function getCount($criteria = null) {
$sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('xoopsnotifications');
if (isset($criteria) && is_subclass_of($criteria, 'icms_db_criteria_Element')) {
$sql .= ' '.$criteria->renderWhere();
}
if (!$result =& $this->db->query($sql)) {
return 0;
}
list($count) = $this->db->fetchRow($result);
return $count;
}
public function deleteAll($criteria = null) {
$sql = 'DELETE FROM '.$this->db->prefix('xoopsnotifications');
if (isset($criteria) && is_subclass_of($criteria, 'icms_db_criteria_Element')) {
$sql .= ' '.$criteria->renderWhere();
}
if (!$result = $this->db->query($sql)) {
return false;
}
return true;
}
public function &getNotification($module_id, $category, $item_id, $event, $user_id) {
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('not_modid', (int)$module_id));
$criteria->add(new icms_db_criteria_Item('not_category', icms::$xoopsDB->escape($category)));
$criteria->add(new icms_db_criteria_Item('not_itemid', (int)$item_id));
$criteria->add(new icms_db_criteria_Item('not_event', icms::$xoopsDB->escape($event)));
$criteria->add(new icms_db_criteria_Item('not_uid', (int)$user_id));
$objects = $this->getObjects($criteria);
if (count($objects) == 1) {
return $objects[0];
}
$inst = false;
return $inst;
}
public function isSubscribed($category, $item_id, $event, $module_id, $user_id) {
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('not_modid', (int)$module_id));
$criteria->add(new icms_db_criteria_Item('not_category', icms::$xoopsDB->escape($category)));
$criteria->add(new icms_db_criteria_Item('not_itemid', (int)$item_id));
$criteria->add(new icms_db_criteria_Item('not_event', icms::$xoopsDB->escape($event)));
$criteria->add(new icms_db_criteria_Item('not_uid', (int)$user_id));
return $this->getCount($criteria);
}
public function subscribe($category, $item_id, $events, $mode=null, $module_id=null, $user_id=null) {
if (!isset($user_id)) {
if (empty(icms::$user)) {
return false;
} else {
$user_id = icms::$user->getVar('uid');
}
}
if (!isset($module_id)) {
global $icmsModule;
$module_id = $icmsModule->getVar('mid');
}
if (!isset($mode)) {
$user = new icms_member_user_Object($user_id);
$mode = $user->getVar('notify_mode');
}
if (!is_array($events)) $events = array($events);
foreach ($events as $event) {
if ($notification =& $this->getNotification($module_id, $category, $item_id, $event, $user_id)) {
if ($notification->getVar('not_mode') != $mode) {
$this->updateByField($notification, 'not_mode', $mode);
}
} else {
$notification =& $this->create();
$notification->setVar('not_modid', $module_id);
$notification->setVar('not_category', $category);
$notification->setVar('not_itemid', $item_id);
$notification->setVar('not_uid', $user_id);
$notification->setVar('not_event', $event);
$notification->setVar('not_mode', $mode);
$this->insert($notification);
}
}
}
public function getByUser($user_id) {
$criteria = new icms_db_criteria_Item('not_uid', $user_id);
return $this->getObjects($criteria, true);
}
public function getSubscribedEvents($category, $item_id, $module_id, $user_id) {
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('not_modid', (int) $module_id));
$criteria->add(new icms_db_criteria_Item('not_category', icms::$xoopsDB->escape($category)));
if ($item_id) {
$criteria->add(new icms_db_criteria_Item('not_itemid', (int) $item_id));
}
$criteria->add(new icms_db_criteria_Item('not_uid', (int)$user_id));
$results = $this->getObjects($criteria, true);
$ret = array();
foreach (array_keys($results) as $i) {
$ret[] = $results[$i]->getVar('not_event');
}
return $ret;
}
public function getByItemId($module_id, $item_id, $order = null, $status = null) {
$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('com_modid', (int) $module_id));
$criteria->add(new icms_db_criteria_Item('com_itemid', (int) $item_id));
if (isset($status)) {
$criteria->add(new icms_db_criteria_Item('com_status', (int) $status));
}
if (isset($order)) {
$criteria->setOrder($order);
}
return $this->getObjects($criteria);
}
public function triggerEvents($category, $item_id, $events, $extra_tags=array(), $user_list=array(), $module_id=null, $omit_user_id=null) {
if (!is_array($events)) {
$events = array($events);
}
foreach ($events as $event) {
$this->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
}
}
public function triggerEvent($category, $item_id, $event, $extra_tags=array(), $user_list=array(), $module_id=null, $omit_user_id=null) {
if (!isset($module_id)) {
global $icmsModule;
$module =& $icmsModule;
$module_id = !empty($icmsModule) ? $icmsModule->getVar('mid') : 0;
} else {
$module_handler = icms::handler('icms_module');
$module =& $module_handler->get($module_id);
}
$mod_config =& icms::$config->getConfigsByCat(0,$module->getVar('mid'));
if (empty($mod_config['notification_enabled'])) {
return false;
}
$category_info =& $this->categoryInfo($category, $module_id);
$event_info =& $this->eventInfo($category, $event, $module_id);
if (!in_array($this->generateConfig($category_info,$event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) {
return false;
}
if (!isset($omit_user_id)) {
if (!empty(icms::$user)) {
$omit_user_id = icms::$user->getVar('uid');
} else {
$omit_user_id = 0;
}
}
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('not_modid', (int) $module_id));
$criteria->add(new icms_db_criteria_Item('not_category', icms::$xoopsDB->escape($category)));
$criteria->add(new icms_db_criteria_Item('not_itemid', (int) $item_id));
$criteria->add(new icms_db_criteria_Item('not_event', icms::$xoopsDB->escape($event)));
$mode_criteria = new icms_db_criteria_Compo();
$mode_criteria->add(new icms_db_criteria_Item('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR');
$mode_criteria->add(new icms_db_criteria_Item('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR');
$mode_criteria->add(new icms_db_criteria_Item('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR');
$criteria->add($mode_criteria);
if (!empty($user_list)) {
$user_criteria = new icms_db_criteria_Compo();
foreach ($user_list as $user) {
$user_criteria->add(new icms_db_criteria_Item('not_uid', $user), 'OR');
}
$criteria->add($user_criteria);
}
$notifications =& $this->getObjects($criteria);
if (empty($notifications)) {
return;
}
$not_config = $module->getInfo('notification');
$tags = array();
if (!empty($not_config)) {
if (!empty($not_config['tags_file'])) {
$tags_file = ICMS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['tags_file'];
if (file_exists($tags_file)) {
include_once $tags_file;
if (!empty($not_config['tags_func'])) {
$tags_func = $not_config['tags_func'];
if (function_exists($tags_func)) {
$tags = $tags_func(icms::$xoopsDB->escape($category), (int) $item_id, icms::$xoopsDB->escape($event));
}
}
}
}
if (!empty($not_config['lookup_file'])) {
$lookup_file = ICMS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file'];
if (file_exists($lookup_file)) {
include_once $lookup_file;
if (!empty($not_config['lookup_func'])) {
$lookup_func = $not_config['lookup_func'];
if (function_exists($lookup_func)) {
$item_info = $lookup_func(icms::$xoopsDB->escape($category), (int) $item_id);
}
}
}
}
}
$tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _NOT_ITEMNAMENOTAVAILABLE . ']';
$tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _NOT_ITEMURLNOTAVAILABLE . ']';
$tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _NOT_ITEMTYPENOTAVAILABLE . ']';
$tags['X_MODULE'] = $module->getVar('name');
$tags['X_MODULE_URL'] = ICMS_URL . '/modules/' . $module->getVar('dirname') . '/';
$tags['X_NOTIFY_CATEGORY'] = $category;
$tags['X_NOTIFY_EVENT'] = $event;
$template_dir = $event_info['mail_template_dir'];
$template = $event_info['mail_template'] . '.tpl';
$subject = $event_info['mail_subject'];
foreach ($notifications as $notification) {
if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) {
$tags['X_UNSUBSCRIBE_URL'] = ICMS_URL . '/notifications.php';
$tags = array_merge($tags, $extra_tags);
$notification->notifyUser($template_dir, $template, $subject, $tags);
}
}
}
public function unsubscribeByUser($user_id) {
$criteria = new icms_db_criteria_Item('not_uid', (int)$user_id);
return $this->deleteAll($criteria);
}
public function unsubscribe($category, $item_id, $events, $module_id=null, $user_id=null) {
if (!isset($user_id)) {
if (empty(icms::$user)) {
return false;
} else {
$user_id = icms::$user->getVar('uid');
}
}
if (!isset($module_id)) {
global $icmsModule;
$module_id = $icmsModule->getVar('mid');
}
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('not_modid', (int) $module_id));
$criteria->add(new icms_db_criteria_Item('not_category', icms::$xoopsDB->escape($category)));
$criteria->add(new icms_db_criteria_Item('not_itemid', (int) $item_id));
$criteria->add(new icms_db_criteria_Item('not_uid', (int) $user_id));
if (!is_array($events)) {
$events = array($events);
}
$event_criteria = new icms_db_criteria_Compo();
foreach ($events as $event) {
$event_criteria->add(new icms_db_criteria_Item('not_event', icms::$xoopsDB->escape($event)), 'OR');
}
$criteria->add($event_criteria);
return $this->deleteAll($criteria);
}
public function unsubscribeByModule($module_id) {
$criteria = new icms_db_criteria_Item('not_modid', (int)$module_id);
return $this->deleteAll($criteria);
}
public function unsubscribeByItem($module_id, $category, $item_id) {
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('not_modid', (int) $module_id));
$criteria->add(new icms_db_criteria_Item('not_category', icms::$xoopsDB->escape($category)));
$criteria->add(new icms_db_criteria_Item('not_itemid', (int) $item_id));
return $this->deleteAll($criteria);
}
public function doLoginMaintenance($user_id) {
$criteria = new icms_db_criteria_Compo();
$criteria->add(new icms_db_criteria_Item('not_uid', (int) $user_id));
$criteria->add(new icms_db_criteria_Item('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN));
$notifications = $this->getObjects($criteria, true);
foreach ($notifications as $n) {
$n->setVar('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT);
$this->insert($n);
}
}
public function updateByField(&$notification, $field_name, $field_value) {
$notification->unsetNew();
$notification->setVar($field_name, $field_value);
return $this->insert($notification);
}
static public function isEnabled($style, $module_id=null) {
if (isset($GLOBALS['xoopsModuleConfig']['notification_enabled'])) {
$status = $GLOBALS['xoopsModuleConfig']['notification_enabled'];
} else {
if (!isset($module_id)) {
return false;
}
$module_handler = icms::handler('icms_module');
$module =& $module_handler->get($module_id);
if (!empty($module) && $module->getVar('hasnotification') == 1) {
$config = icms::$config->getConfigsByCat(0, $module_id);
$status = $config['notification_enabled'];
} else {
return false;
}
}
include_once ICMS_ROOT_PATH . '/include/notification_constants.php';
if (($style == 'block') && ($status == XOOPS_NOTIFICATION_ENABLEBLOCK || $status == XOOPS_NOTIFICATION_ENABLEBOTH)) {
return true;
}
if (($style == 'inline') && ($status == XOOPS_NOTIFICATION_ENABLEINLINE || $status == XOOPS_NOTIFICATION_ENABLEBOTH)) {
return true;
}
return false;
}
static public function &categoryInfo($category_name='', $module_id=null) {
if (!isset($module_id)) {
global $icmsModule;
$module_id = !empty($icmsModule) ? $icmsModule->getVar('mid') : 0;
$module =& $icmsModule;
} else {
$module_handler = icms::handler('icms_module');
$module =& $module_handler->get($module_id);
}
$not_config =& $module->getInfo('notification');
if (empty($category_name)) {
return $not_config['category'];
}
foreach ($not_config['category'] as $category) {
if ($category['name'] == $category_name) {
return $category;
}
}
$ret = false;
return $ret;
}
static public function &commentCategoryInfo($module_id=null) {
$ret = false;
$all_categories =& self::categoryInfo('', $module_id);
if (empty($all_categories)) {
return $ret;
}
foreach ($all_categories as $category) {
$all_events =& self::categoryEvents($category['name'], false, $module_id);
if (empty($all_events)) {
continue;
}
foreach ($all_events as $event) {
if ($event['name'] == 'comment') {
return $category;
}
}
}
return $ret;
}
static public function &categoryEvents($category_name, $enabled_only, $module_id=null) {
if (!isset($module_id)) {
global $icmsModule;
$module_id = !empty($icmsModule) ? $icmsModule->getVar('mid') : 0;
$module =& $icmsModule;
} else {
$module_handler = icms::handler('icms_module');
$module =& $module_handler->get($module_id);
}
$not_config =& $module->getInfo('notification');
$mod_config = icms::$config->getConfigsByCat(0,$module_id);
$category =& self::categoryInfo($category_name, $module_id);
global $icmsConfig;
$event_array = array();
$override_comment = false;
$override_commentsubmit = false;
$override_bookmark = false;
foreach ($not_config['event'] as $event) {
if ($event['category'] == $category_name) {
$event['mail_template_dir'] = ICMS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/language/' . $icmsConfig['language'] . '/mail_template/';
if (!$enabled_only || self::eventEnabled($category, $event, $module)) {
$event_array[] = $event;
}
if ($event['name'] == 'comment') {
$override_comment = true;
}
if ($event['name'] == 'comment_submit') {
$override_commentsubmit = true;
}
if ($event['name'] == 'bookmark') {
$override_bookmark = true;
}
}
}
icms_loadLanguageFile('core', 'notification');
if ($module->getVar('hascomments')) {
$com_config = $module->getInfo('comments');
if (!empty($category['item_name']) && $category['item_name'] == $com_config['itemName']) {
$mail_template_dir = ICMS_ROOT_PATH . '/language/' . $icmsConfig['language'] . '/mail_template/';
include_once ICMS_ROOT_PATH . '/include/comment_constants.php';
$com_config = icms::$config->getConfigsByCat(0, $module_id);
if (!$enabled_only) {
$insert_comment = true;
$insert_submit = true;
} else {
$insert_comment = false;
$insert_submit = false;
switch($com_config['com_rule']) {
case XOOPS_COMMENT_APPROVENONE:
break;
case XOOPS_COMMENT_APPROVEALL:
if (!$override_comment) {
$insert_comment = true;
}
break;
case XOOPS_COMMENT_APPROVEUSER:
case XOOPS_COMMENT_APPROVEADMIN:
if (!$override_comment) {
$insert_comment = true;
}
if (!$override_commentsubmit) {
$insert_submit = true;
}
break;
}
}
if ($insert_comment) {
$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);
if (!$enabled_only || self::eventEnabled($category, $event, $module)) {
$event_array[] = $event;
}
}
if ($insert_submit) {
$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);
if (!$enabled_only || self::eventEnabled($category, $event, $module)) {
$event_array[] = $event;
}
}
}
}
if (!empty($category['allow_bookmark'])) {
if (!$override_bookmark) {
$event = array('name'=>'bookmark', 'category'=>$category['name'], 'title'=>_NOT_BOOKMARK_NOTIFY, 'caption'=>_NOT_BOOKMARK_NOTIFYCAP, 'description'=>_NOT_BOOKMARK_NOTIFYDSC);
if (!$enabled_only || self::eventEnabled($category, $event, $module)) {
$event_array[] = $event;
}
}
}
return $event_array;
}
static public function eventEnabled(&$category, &$event, &$module) {
$mod_config = icms::$config->getConfigsByCat(0,$module->getVar('mid'));
if (is_array($mod_config['notification_events']) && $mod_config['notification_events'] != array()) {
$option_name = self::generateConfig($category, $event, 'option_name');
if (in_array($option_name, $mod_config['notification_events'])) {
return true;
}
}
return false;
}
static public function &eventInfo($category_name, $event_name, $module_id=null) {
$all_events =& self::categoryEvents($category_name, false, $module_id);
foreach ($all_events as $event) {
if ($event['name'] == $event_name) {
return $event;
}
}
$ret = false;
return $ret;
}
static public function &subscribableCategoryInfo($module_id=null) {
$all_categories =& self::categoryInfo('', $module_id);
$script_url = explode('/', $_SERVER['PHP_SELF']);
$script_name = $script_url[count($script_url)-1];
$sub_categories = array();
foreach ($all_categories as $category) {
$subscribe_from = $category['subscribe_from'];
if (!is_array($subscribe_from)) {
if ($subscribe_from == '*') {
$subscribe_from = array($script_name);
} else {
$subscribe_from = array($subscribe_from);
}
}
if (!in_array($script_name, $subscribe_from)) {
continue;
}
if (empty($category['item_name'])) {
$category['item_name'] = '';
$category['item_id'] = 0;
$sub_categories[] = $category;
} else {
$item_name = $category['item_name'];
$id = ($item_name != '' && isset($_GET[$item_name])) ? (int) ($_GET[$item_name]) : 0;
if ($id > 0) {
$category['item_id'] = $id;
$sub_categories[] = $category;
}
}
}
return $sub_categories;
}
static public function generateConfig(&$category, &$event, $type) {
switch ($type) {
case 'option_value':
case 'name':
return 'notify:' . $category['name'] . '-' . $event['name'];
break;
case 'option_name':
return $category['name'] . '-' . $event['name'];
break;
default:
return false;
break;
}
}
}