| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
| 20: |
|
| 21: |
|
| 22: | include_once $GLOBALS['xoops']->path('include/notification_constants.php');
|
| 23: | include_once $GLOBALS['xoops']->path('include/notification_functions.php');
|
| 24: |
|
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: |
|
| 34: | class XoopsNotification extends XoopsObject
|
| 35: | {
|
| 36: |
|
| 37: | public $not_id;
|
| 38: | public $not_modid;
|
| 39: | public $not_category;
|
| 40: | public $not_itemid;
|
| 41: | public $not_event;
|
| 42: | public $not_uid;
|
| 43: | public $not_mode;
|
| 44: |
|
| 45: | |
| 46: | |
| 47: |
|
| 48: | public function __construct()
|
| 49: | {
|
| 50: | parent::__construct();
|
| 51: | $this->initVar('not_id', XOBJ_DTYPE_INT, null, false);
|
| 52: | $this->initVar('not_modid', XOBJ_DTYPE_INT, null, false);
|
| 53: | $this->initVar('not_category', XOBJ_DTYPE_TXTBOX, null, false, 30);
|
| 54: | $this->initVar('not_itemid', XOBJ_DTYPE_INT, 0, false);
|
| 55: | $this->initVar('not_event', XOBJ_DTYPE_TXTBOX, null, false, 30);
|
| 56: | $this->initVar('not_uid', XOBJ_DTYPE_INT, 0, true);
|
| 57: | $this->initVar('not_mode', XOBJ_DTYPE_INT, 0, false);
|
| 58: | }
|
| 59: |
|
| 60: |
|
| 61: |
|
| 62: |
|
| 63: |
|
| 64: |
|
| 65: |
|
| 66: |
|
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: |
|
| 72: | public function id($format = 'N')
|
| 73: | {
|
| 74: | return $this->getVar('not_id', $format);
|
| 75: | }
|
| 76: |
|
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: |
|
| 82: | public function not_id($format = '')
|
| 83: | {
|
| 84: | return $this->getVar('not_id', $format);
|
| 85: | }
|
| 86: |
|
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: |
|
| 92: | public function not_modid($format = '')
|
| 93: | {
|
| 94: | return $this->getVar('not_modid', $format);
|
| 95: | }
|
| 96: |
|
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: |
|
| 102: | public function not_category($format = '')
|
| 103: | {
|
| 104: | return $this->getVar('not_category', $format);
|
| 105: | }
|
| 106: |
|
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: |
|
| 112: | public function not_itemid($format = '')
|
| 113: | {
|
| 114: | return $this->getVar('not_itemid', $format);
|
| 115: | }
|
| 116: |
|
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: |
|
| 122: | public function not_event($format = '')
|
| 123: | {
|
| 124: | return $this->getVar('not_event', $format);
|
| 125: | }
|
| 126: |
|
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: |
|
| 132: | public function not_uid($format = '')
|
| 133: | {
|
| 134: | return $this->getVar('not_uid', $format);
|
| 135: | }
|
| 136: |
|
| 137: | |
| 138: | |
| 139: | |
| 140: | |
| 141: |
|
| 142: | public function not_mode($format = '')
|
| 143: | {
|
| 144: | return $this->getVar('not_mode', $format);
|
| 145: | }
|
| 146: |
|
| 147: | |
| 148: | |
| 149: | |
| 150: | |
| 151: | |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: |
|
| 157: | public function notifyUser($template_dir, $template, $subject, $tags)
|
| 158: | {
|
| 159: |
|
| 160: |
|
| 161: | $member_handler = xoops_getHandler('member');
|
| 162: | $user = $member_handler->getUser($this->getVar('not_uid'));
|
| 163: | if (!is_object($user) || !$user->isActive()) {
|
| 164: | return true;
|
| 165: | }
|
| 166: |
|
| 167: | $method = $user->getVar('notify_method');
|
| 168: |
|
| 169: | $xoopsMailer = xoops_getMailer();
|
| 170: | include_once $GLOBALS['xoops']->path('include/notification_constants.php');
|
| 171: | switch ($method) {
|
| 172: | case XOOPS_NOTIFICATION_METHOD_PM:
|
| 173: | $xoopsMailer->usePM();
|
| 174: |
|
| 175: | $config_handler = xoops_getHandler('config');
|
| 176: | $xoopsMailerConfig = $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
|
| 177: | $xoopsMailer->setFromUser($member_handler->getUser($xoopsMailerConfig['fromuid']));
|
| 178: | foreach ($tags as $k => $v) {
|
| 179: | $xoopsMailer->assign($k, $v);
|
| 180: | }
|
| 181: | break;
|
| 182: | case XOOPS_NOTIFICATION_METHOD_EMAIL:
|
| 183: | $xoopsMailer->useMail();
|
| 184: | foreach ($tags as $k => $v) {
|
| 185: | $xoopsMailer->assign($k, preg_replace('/&/i', '&', $v));
|
| 186: | }
|
| 187: | break;
|
| 188: | default:
|
| 189: | return true;
|
| 190: |
|
| 191: | }
|
| 192: |
|
| 193: |
|
| 194: | $xoopsMailer->setTemplateDir($template_dir);
|
| 195: | $xoopsMailer->setTemplate($template);
|
| 196: | $xoopsMailer->setToUsers($user);
|
| 197: |
|
| 198: |
|
| 199: |
|
| 200: | $xoopsMailer->setSubject($subject);
|
| 201: | $success = $xoopsMailer->send();
|
| 202: |
|
| 203: |
|
| 204: |
|
| 205: | include_once $GLOBALS['xoops']->path('include/notification_constants.php');
|
| 206: | $notification_handler = xoops_getHandler('notification');
|
| 207: |
|
| 208: | if ($this->getVar('not_mode') == XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE) {
|
| 209: | $notification_handler->delete($this);
|
| 210: |
|
| 211: | return $success;
|
| 212: | }
|
| 213: |
|
| 214: | if ($this->getVar('not_mode') == XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT) {
|
| 215: | $this->setVar('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN);
|
| 216: | $notification_handler->insert($this);
|
| 217: | }
|
| 218: |
|
| 219: | return $success;
|
| 220: | }
|
| 221: | }
|
| 222: |
|
| 223: | |
| 224: | |
| 225: | |
| 226: | |
| 227: | |
| 228: | |
| 229: | |
| 230: | |
| 231: | |
| 232: | |
| 233: | |
| 234: | |
| 235: |
|
| 236: | class XoopsNotificationHandler extends XoopsObjectHandler
|
| 237: | {
|
| 238: | |
| 239: | |
| 240: | |
| 241: | |
| 242: | |
| 243: | |
| 244: |
|
| 245: | public function create($isNew = true)
|
| 246: | {
|
| 247: | $notification = new XoopsNotification();
|
| 248: | if ($isNew) {
|
| 249: | $notification->setNew();
|
| 250: | }
|
| 251: |
|
| 252: | return $notification;
|
| 253: | }
|
| 254: |
|
| 255: | |
| 256: | |
| 257: | |
| 258: | |
| 259: | |
| 260: | |
| 261: |
|
| 262: | public function get($id)
|
| 263: | {
|
| 264: | $notification = false;
|
| 265: | $id = (int)$id;
|
| 266: | if ($id > 0) {
|
| 267: | $sql = 'SELECT * FROM ' . $this->db->prefix('xoopsnotifications') . ' WHERE not_id=' . $id;
|
| 268: | $result = $this->db->query($sql);
|
| 269: | if (!$this->db->isResultSet($result)) {
|
| 270: | return $notification;
|
| 271: | }
|
| 272: | $numrows = $this->db->getRowsNum($result);
|
| 273: | if ($numrows == 1) {
|
| 274: | $notification = new XoopsNotification();
|
| 275: | $notification->assignVars($this->db->fetchArray($result));
|
| 276: | }
|
| 277: | }
|
| 278: |
|
| 279: | return $notification;
|
| 280: | }
|
| 281: |
|
| 282: | |
| 283: | |
| 284: | |
| 285: | |
| 286: | |
| 287: | |
| 288: |
|
| 289: | public function insert(XoopsObject $notification)
|
| 290: | {
|
| 291: | $className = 'XoopsNotification';
|
| 292: | if (!($notification instanceof $className)) {
|
| 293: | return false;
|
| 294: | }
|
| 295: | if (!$notification->isDirty()) {
|
| 296: | return true;
|
| 297: | }
|
| 298: | if (!$notification->cleanVars()) {
|
| 299: | return false;
|
| 300: | }
|
| 301: | foreach ($notification->cleanVars as $k => $v) {
|
| 302: | ${$k} = $v;
|
| 303: | }
|
| 304: | if ($notification->isNew()) {
|
| 305: | $not_id = $this->db->genId('xoopsnotifications_not_id_seq');
|
| 306: | $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'), $not_id, $not_modid, $not_itemid, $this->db->quoteString($not_category), $not_uid, $this->db->quoteString($not_event), $not_mode);
|
| 307: | } else {
|
| 308: | $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'), $not_modid, $not_itemid, $this->db->quoteString($not_category), $not_uid, $this->db->quoteString($not_event), $not_mode, $not_id);
|
| 309: | }
|
| 310: | if (!$result = $this->db->query($sql)) {
|
| 311: | return false;
|
| 312: | }
|
| 313: | if (empty($not_id)) {
|
| 314: | $not_id = $this->db->getInsertId();
|
| 315: | }
|
| 316: | $notification->assignVar('not_id', $not_id);
|
| 317: |
|
| 318: | return true;
|
| 319: | }
|
| 320: |
|
| 321: | |
| 322: | |
| 323: | |
| 324: | |
| 325: | |
| 326: | |
| 327: |
|
| 328: | public function delete(XoopsObject $notification)
|
| 329: | {
|
| 330: | $className = 'XoopsNotification';
|
| 331: | if (!($notification instanceof $className)) {
|
| 332: | return false;
|
| 333: | }
|
| 334: |
|
| 335: | $sql = sprintf('DELETE FROM %s WHERE not_id = %u', $this->db->prefix('xoopsnotifications'), $notification->getVar('not_id'));
|
| 336: | if (!$result = $this->db->query($sql)) {
|
| 337: | return false;
|
| 338: | }
|
| 339: |
|
| 340: | return true;
|
| 341: | }
|
| 342: |
|
| 343: | |
| 344: | |
| 345: | |
| 346: | |
| 347: | |
| 348: | |
| 349: | |
| 350: |
|
| 351: | public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
|
| 352: | {
|
| 353: | $ret = array();
|
| 354: | $limit = $start = 0;
|
| 355: | $sql = 'SELECT * FROM ' . $this->db->prefix('xoopsnotifications');
|
| 356: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
| 357: | $sql .= ' ' . $criteria->renderWhere();
|
| 358: | $sort = ($criteria->getSort() != '') ? $criteria->getSort() : 'not_id';
|
| 359: | $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
|
| 360: | $limit = $criteria->getLimit();
|
| 361: | $start = $criteria->getStart();
|
| 362: | }
|
| 363: | $result = $this->db->query($sql, $limit, $start);
|
| 364: | if (!$this->db->isResultSet($result)) {
|
| 365: | return $ret;
|
| 366: | }
|
| 367: |
|
| 368: | while (false !== ($myrow = $this->db->fetchArray($result))) {
|
| 369: | $notification = new XoopsNotification();
|
| 370: | $notification->assignVars($myrow);
|
| 371: | if (!$id_as_key) {
|
| 372: | $ret[] = $notification;
|
| 373: | } else {
|
| 374: | $ret[$myrow['not_id']] = $notification;
|
| 375: | }
|
| 376: | unset($notification);
|
| 377: | }
|
| 378: |
|
| 379: | return $ret;
|
| 380: | }
|
| 381: |
|
| 382: |
|
| 383: | |
| 384: | |
| 385: | |
| 386: | |
| 387: | |
| 388: | |
| 389: |
|
| 390: | public function getCount(CriteriaElement $criteria = null)
|
| 391: | {
|
| 392: | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('xoopsnotifications');
|
| 393: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
| 394: | $sql .= ' ' . $criteria->renderWhere();
|
| 395: | }
|
| 396: | $result = $this->db->query($sql);
|
| 397: | if (!$this->db->isResultSet($result)) {
|
| 398: | return 0;
|
| 399: | }
|
| 400: | list($count) = $this->db->fetchRow($result);
|
| 401: |
|
| 402: | return (int)$count;
|
| 403: | }
|
| 404: |
|
| 405: | |
| 406: | |
| 407: | |
| 408: | |
| 409: | |
| 410: | |
| 411: |
|
| 412: | public function deleteAll(CriteriaElement $criteria = null)
|
| 413: | {
|
| 414: | $sql = 'DELETE FROM ' . $this->db->prefix('xoopsnotifications');
|
| 415: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
| 416: | $sql .= ' ' . $criteria->renderWhere();
|
| 417: | }
|
| 418: | if (!$result = $this->db->query($sql)) {
|
| 419: | return false;
|
| 420: | }
|
| 421: |
|
| 422: | return true;
|
| 423: | }
|
| 424: |
|
| 425: |
|
| 426: |
|
| 427: | |
| 428: | |
| 429: | |
| 430: | |
| 431: | |
| 432: | |
| 433: | |
| 434: | |
| 435: |
|
| 436: | public function &getNotification($module_id, $category, $item_id, $event, $user_id)
|
| 437: | {
|
| 438: | $criteria = new CriteriaCompo();
|
| 439: | $criteria->add(new Criteria('not_modid', (int)$module_id));
|
| 440: | $criteria->add(new Criteria('not_category', $this->db->escape($category)));
|
| 441: | $criteria->add(new Criteria('not_itemid', (int)$item_id));
|
| 442: | $criteria->add(new Criteria('not_event', $this->db->escape($event)));
|
| 443: | $criteria->add(new Criteria('not_uid', (int)$user_id));
|
| 444: | $objects = $this->getObjects($criteria);
|
| 445: | if (count($objects) == 1) {
|
| 446: | return $objects[0];
|
| 447: | }
|
| 448: | $inst = false;
|
| 449: |
|
| 450: | return $inst;
|
| 451: | }
|
| 452: |
|
| 453: | |
| 454: | |
| 455: | |
| 456: | |
| 457: | |
| 458: | |
| 459: | |
| 460: | |
| 461: | |
| 462: | |
| 463: | |
| 464: | |
| 465: |
|
| 466: | public function isSubscribed($category, $item_id, $event, $module_id, $user_id)
|
| 467: | {
|
| 468: | $criteria = new CriteriaCompo();
|
| 469: | $criteria->add(new Criteria('not_modid', (int)$module_id));
|
| 470: | $criteria->add(new Criteria('not_category', $this->db->escape($category)));
|
| 471: | $criteria->add(new Criteria('not_itemid', (int)$item_id));
|
| 472: | $criteria->add(new Criteria('not_event', $this->db->escape($event)));
|
| 473: | $criteria->add(new Criteria('not_uid', (int)$user_id));
|
| 474: |
|
| 475: | return $this->getCount($criteria);
|
| 476: | }
|
| 477: |
|
| 478: |
|
| 479: |
|
| 480: |
|
| 481: | |
| 482: | |
| 483: | |
| 484: | |
| 485: | |
| 486: | |
| 487: | |
| 488: | |
| 489: | |
| 490: | |
| 491: | |
| 492: | |
| 493: | |
| 494: |
|
| 495: | public function subscribe($category, $item_id, $events, $mode = null, $module_id = null, $user_id = null)
|
| 496: | {
|
| 497: | if (!isset($user_id)) {
|
| 498: | global $xoopsUser;
|
| 499: | if (empty($xoopsUser)) {
|
| 500: | return false;
|
| 501: | } else {
|
| 502: | $user_id = $xoopsUser->getVar('uid');
|
| 503: | }
|
| 504: | }
|
| 505: |
|
| 506: | if (!isset($module_id)) {
|
| 507: | global $xoopsModule;
|
| 508: | $module_id = $xoopsModule->getVar('mid');
|
| 509: | }
|
| 510: |
|
| 511: | if (!isset($mode)) {
|
| 512: | $user = new XoopsUser($user_id);
|
| 513: | $mode = $user->getVar('notify_mode');
|
| 514: | }
|
| 515: |
|
| 516: | if (!is_array($events)) {
|
| 517: | $events = array($events);
|
| 518: | }
|
| 519: | foreach ($events as $event) {
|
| 520: |
|
| 521: | if ($notification = $this->getNotification($module_id, $category, $item_id, $event, $user_id)) {
|
| 522: | if ($notification->getVar('not_mode') != $mode) {
|
| 523: | $this->updateByField($notification, 'not_mode', $mode);
|
| 524: | }
|
| 525: | } else {
|
| 526: | $notification = $this->create();
|
| 527: | $notification->setVar('not_modid', $module_id);
|
| 528: | $notification->setVar('not_category', $category);
|
| 529: | $notification->setVar('not_itemid', $item_id);
|
| 530: | $notification->setVar('not_uid', $user_id);
|
| 531: | $notification->setVar('not_event', $event);
|
| 532: | $notification->setVar('not_mode', $mode);
|
| 533: | $this->insert($notification);
|
| 534: | }
|
| 535: | }
|
| 536: | return true;
|
| 537: | }
|
| 538: |
|
| 539: |
|
| 540: |
|
| 541: |
|
| 542: |
|
| 543: | |
| 544: | |
| 545: | |
| 546: | |
| 547: | |
| 548: | |
| 549: |
|
| 550: | public function getByUser($user_id)
|
| 551: | {
|
| 552: | $criteria = new Criteria('not_uid', $user_id);
|
| 553: |
|
| 554: | return $this->getObjects($criteria, true);
|
| 555: | }
|
| 556: |
|
| 557: |
|
| 558: | |
| 559: | |
| 560: | |
| 561: | |
| 562: | |
| 563: | |
| 564: | |
| 565: | |
| 566: |
|
| 567: | public function getSubscribedEvents($category, $item_id, $module_id, $user_id)
|
| 568: | {
|
| 569: | $criteria = new CriteriaCompo();
|
| 570: | $criteria->add(new Criteria('not_modid', (int)$module_id));
|
| 571: | $criteria->add(new Criteria('not_category', $this->db->escape($category)));
|
| 572: | if ($item_id) {
|
| 573: | $criteria->add(new Criteria('not_itemid', (int)$item_id));
|
| 574: | }
|
| 575: | $criteria->add(new Criteria('not_uid', (int)$user_id));
|
| 576: | $results = $this->getObjects($criteria, true);
|
| 577: | $ret = array();
|
| 578: | foreach (array_keys($results) as $i) {
|
| 579: | $ret[] = $results[$i]->getVar('not_event');
|
| 580: | }
|
| 581: |
|
| 582: | return $ret;
|
| 583: | }
|
| 584: |
|
| 585: |
|
| 586: | |
| 587: | |
| 588: | |
| 589: | |
| 590: | |
| 591: | |
| 592: | |
| 593: | |
| 594: | |
| 595: | |
| 596: | |
| 597: |
|
| 598: | public function getByItemId($module_id, $item_id, $order = null, $mode = null)
|
| 599: | {
|
| 600: | $criteria = new CriteriaCompo(new Criteria('not_modid', (int)$module_id));
|
| 601: | $criteria->add(new Criteria('not_itemid', (int)$item_id));
|
| 602: | if (isset($mode)) {
|
| 603: | $criteria->add(new Criteria('not_mode', (int)$mode));
|
| 604: | }
|
| 605: | if (isset($order)) {
|
| 606: | $criteria->setOrder($order);
|
| 607: | }
|
| 608: |
|
| 609: | return $this->getObjects($criteria);
|
| 610: | }
|
| 611: |
|
| 612: | |
| 613: | |
| 614: | |
| 615: | |
| 616: | |
| 617: | |
| 618: | |
| 619: | |
| 620: | |
| 621: | |
| 622: | |
| 623: | |
| 624: |
|
| 625: |
|
| 626: |
|
| 627: |
|
| 628: |
|
| 629: |
|
| 630: |
|
| 631: | public function triggerEvents($category, $item_id, $events, $extra_tags = array(), $user_list = array(), $module_id = null, $omit_user_id = null)
|
| 632: | {
|
| 633: | if (!is_array($events)) {
|
| 634: | $events = array($events);
|
| 635: | }
|
| 636: | foreach ($events as $event) {
|
| 637: | $this->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
|
| 638: | }
|
| 639: | }
|
| 640: |
|
| 641: | |
| 642: | |
| 643: | |
| 644: | |
| 645: | |
| 646: | |
| 647: | |
| 648: | |
| 649: | |
| 650: | |
| 651: | |
| 652: |
|
| 653: | public function triggerEvent($category, $item_id, $event, $extra_tags = array(), $user_list = array(), $module_id = null, $omit_user_id = null)
|
| 654: | {
|
| 655: | if (!isset($module_id)) {
|
| 656: | global $xoopsModule;
|
| 657: | $module = $xoopsModule;
|
| 658: | $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0;
|
| 659: | } else {
|
| 660: |
|
| 661: | $module_handler = xoops_getHandler('module');
|
| 662: | $module = $module_handler->get($module_id);
|
| 663: | }
|
| 664: |
|
| 665: |
|
| 666: |
|
| 667: | $config_handler = xoops_getHandler('config');
|
| 668: | $mod_config = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
|
| 669: | if (empty($mod_config['notification_enabled'])) {
|
| 670: | return false;
|
| 671: | }
|
| 672: | $category_info =& notificationCategoryInfo($category, $module_id);
|
| 673: | $event_info =& notificationEventInfo($category, $event, $module_id);
|
| 674: | if (!in_array(notificationGenerateConfig($category_info, $event_info, 'option_name'), $mod_config['notification_events']) && empty($event_info['invisible'])) {
|
| 675: | return false;
|
| 676: | }
|
| 677: |
|
| 678: | if (!isset($omit_user_id)) {
|
| 679: | global $xoopsUser;
|
| 680: | $omit_user_id = 0;
|
| 681: | if (!empty($xoopsUser)) {
|
| 682: | $omit_user_id = $xoopsUser->getVar('uid');
|
| 683: | }
|
| 684: | }
|
| 685: | $criteria = new CriteriaCompo();
|
| 686: | $criteria->add(new Criteria('not_modid', (int)$module_id));
|
| 687: | $criteria->add(new Criteria('not_category', $this->db->escape($category)));
|
| 688: | $criteria->add(new Criteria('not_itemid', (int)$item_id));
|
| 689: | $criteria->add(new Criteria('not_event', $this->db->escape($event)));
|
| 690: | $mode_criteria = new CriteriaCompo();
|
| 691: | $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR');
|
| 692: | $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR');
|
| 693: | $mode_criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR');
|
| 694: | $criteria->add($mode_criteria);
|
| 695: | if (!empty($user_list)) {
|
| 696: | $user_criteria = new CriteriaCompo();
|
| 697: | foreach ($user_list as $user) {
|
| 698: | $user_criteria->add(new Criteria('not_uid', (int)$user), 'OR');
|
| 699: | }
|
| 700: | $criteria->add($user_criteria);
|
| 701: | }
|
| 702: | $notifications = $this->getObjects($criteria);
|
| 703: | if (empty($notifications)) {
|
| 704: | return null;
|
| 705: | }
|
| 706: |
|
| 707: |
|
| 708: |
|
| 709: | $not_config = $module->getInfo('notification');
|
| 710: | $tags = array();
|
| 711: | if (!empty($not_config)) {
|
| 712: | if (!empty($not_config['tags_file'])) {
|
| 713: | $tags_file = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname') . '/' . $not_config['tags_file']);
|
| 714: | if (file_exists($tags_file)) {
|
| 715: | include_once $tags_file;
|
| 716: | if (!empty($not_config['tags_func'])) {
|
| 717: | $tags_func = $not_config['tags_func'];
|
| 718: | if (function_exists($tags_func)) {
|
| 719: | $tags = $tags_func($category, (int)$item_id, $event);
|
| 720: | }
|
| 721: | }
|
| 722: | }
|
| 723: | }
|
| 724: |
|
| 725: | if (!empty($not_config['lookup_file'])) {
|
| 726: | $lookup_file = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file']);
|
| 727: | if (file_exists($lookup_file)) {
|
| 728: | include_once $lookup_file;
|
| 729: | if (!empty($not_config['lookup_func'])) {
|
| 730: | $lookup_func = $not_config['lookup_func'];
|
| 731: | if (function_exists($lookup_func)) {
|
| 732: | $item_info = $lookup_func($category, (int)$item_id);
|
| 733: | }
|
| 734: | }
|
| 735: | }
|
| 736: | }
|
| 737: | }
|
| 738: | $tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _NOT_ITEMNAMENOTAVAILABLE . ']';
|
| 739: | $tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _NOT_ITEMURLNOTAVAILABLE . ']';
|
| 740: | $tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _NOT_ITEMTYPENOTAVAILABLE . ']';
|
| 741: | $tags['X_MODULE'] = $module->getVar('name');
|
| 742: | $tags['X_MODULE_URL'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/';
|
| 743: | $tags['X_NOTIFY_CATEGORY'] = $category;
|
| 744: | $tags['X_NOTIFY_EVENT'] = $event;
|
| 745: |
|
| 746: | $template_dir = $event_info['mail_template_dir'];
|
| 747: | $template = $event_info['mail_template'] . '.tpl';
|
| 748: | $subject = $event_info['mail_subject'];
|
| 749: |
|
| 750: | $merged_tags = array();
|
| 751: |
|
| 752: |
|
| 753: | foreach ($notifications as $notification) {
|
| 754: | if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) {
|
| 755: |
|
| 756: | $tags = array();
|
| 757: | $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php';
|
| 758: |
|
| 759: |
|
| 760: | if (!empty($tags)) {
|
| 761: |
|
| 762: | $merged_tags = array_merge($merged_tags, $tags);
|
| 763: | }
|
| 764: | }
|
| 765: | }
|
| 766: |
|
| 767: |
|
| 768: | foreach ($notifications as $notification) {
|
| 769: | if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) {
|
| 770: | $notification->notifyUser($template_dir, $template, $subject, $merged_tags);
|
| 771: | }
|
| 772: | }
|
| 773: |
|
| 774: | return null;
|
| 775: | }
|
| 776: |
|
| 777: | |
| 778: | |
| 779: | |
| 780: | |
| 781: | |
| 782: |
|
| 783: | public function unsubscribeByUser($user_id)
|
| 784: | {
|
| 785: | $criteria = new Criteria('not_uid', (int)$user_id);
|
| 786: |
|
| 787: | return $this->deleteAll($criteria);
|
| 788: | }
|
| 789: |
|
| 790: |
|
| 791: | |
| 792: | |
| 793: | |
| 794: | |
| 795: | |
| 796: | |
| 797: | |
| 798: | |
| 799: | |
| 800: | |
| 801: |
|
| 802: | public function unsubscribe($category, $item_id, $events, $module_id = null, $user_id = null)
|
| 803: | {
|
| 804: | if (!isset($user_id)) {
|
| 805: | global $xoopsUser;
|
| 806: | if (empty($xoopsUser)) {
|
| 807: | return false;
|
| 808: | } else {
|
| 809: | $user_id = $xoopsUser->getVar('uid');
|
| 810: | }
|
| 811: | }
|
| 812: | if (!isset($module_id)) {
|
| 813: | global $xoopsModule;
|
| 814: | $module_id = $xoopsModule->getVar('mid');
|
| 815: | }
|
| 816: | $criteria = new CriteriaCompo();
|
| 817: | $criteria->add(new Criteria('not_modid', (int)$module_id));
|
| 818: | $criteria->add(new Criteria('not_category', $this->db->escape($category)));
|
| 819: | $criteria->add(new Criteria('not_itemid', (int)$item_id));
|
| 820: | $criteria->add(new Criteria('not_uid', (int)$user_id));
|
| 821: | if (!is_array($events)) {
|
| 822: | $events = array($events);
|
| 823: | }
|
| 824: | $event_criteria = new CriteriaCompo();
|
| 825: | foreach ($events as $event) {
|
| 826: | $event_criteria->add(new Criteria('not_event', $this->db->escape($event)), 'OR');
|
| 827: | }
|
| 828: | $criteria->add($event_criteria);
|
| 829: |
|
| 830: | return $this->deleteAll($criteria);
|
| 831: | }
|
| 832: |
|
| 833: |
|
| 834: |
|
| 835: |
|
| 836: | |
| 837: | |
| 838: | |
| 839: | |
| 840: | |
| 841: |
|
| 842: | public function unsubscribeByModule($module_id)
|
| 843: | {
|
| 844: | $criteria = new Criteria('not_modid', (int)$module_id);
|
| 845: |
|
| 846: | return $this->deleteAll($criteria);
|
| 847: | }
|
| 848: |
|
| 849: | |
| 850: | |
| 851: | |
| 852: | |
| 853: | |
| 854: | |
| 855: | |
| 856: | |
| 857: |
|
| 858: | public function unsubscribeByItem($module_id, $category, $item_id)
|
| 859: | {
|
| 860: | $criteria = new CriteriaCompo();
|
| 861: | $criteria->add(new Criteria('not_modid', (int)$module_id));
|
| 862: | $criteria->add(new Criteria('not_category', $this->db->escape($category)));
|
| 863: | $criteria->add(new Criteria('not_itemid', (int)$item_id));
|
| 864: |
|
| 865: | return $this->deleteAll($criteria);
|
| 866: | }
|
| 867: |
|
| 868: | |
| 869: | |
| 870: | |
| 871: | |
| 872: | |
| 873: | |
| 874: | |
| 875: |
|
| 876: | public function doLoginMaintenance($user_id)
|
| 877: | {
|
| 878: | $criteria = new CriteriaCompo();
|
| 879: | $criteria->add(new Criteria('not_uid', (int)$user_id));
|
| 880: | $criteria->add(new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN));
|
| 881: |
|
| 882: | $notifications = $this->getObjects($criteria, true);
|
| 883: | foreach ($notifications as $n) {
|
| 884: | $n->setVar('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT);
|
| 885: | $this->insert($n);
|
| 886: | }
|
| 887: | }
|
| 888: |
|
| 889: | |
| 890: | |
| 891: | |
| 892: | |
| 893: | |
| 894: | |
| 895: | |
| 896: | |
| 897: |
|
| 898: | public function updateByField(XoopsNotification $notification, $field_name, $field_value)
|
| 899: | {
|
| 900: | $notification->unsetNew();
|
| 901: | $notification->setVar($field_name, $field_value);
|
| 902: |
|
| 903: | return $this->insert($notification);
|
| 904: | }
|
| 905: | }
|
| 906: | |