[ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: notification.php 506 2006-05-26 23:10:37Z skalpa $ 3 // ------------------------------------------------------------------------ // 4 // XOOPS - PHP Content Management System // 5 // Copyright (c) 2000 XOOPS.org // 6 // <http://www.xoops.org/> // 7 // ------------------------------------------------------------------------ // 8 // This program is free software; you can redistribute it and/or modify // 9 // it under the terms of the GNU General Public License as published by // 10 // the Free Software Foundation; either version 2 of the License, or // 11 // (at your option) any later version. // 12 // // 13 // You may not change or alter any portion of this comment or credits // 14 // of supporting developers from this source code or any supporting // 15 // source code which is considered copyrighted (c) material of the // 16 // original comment or credit authors. // 17 // // 18 // This program is distributed in the hope that it will be useful, // 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 21 // GNU General Public License for more details. // 22 // // 23 // You should have received a copy of the GNU General Public License // 24 // along with this program; if not, write to the Free Software // 25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // 26 // ------------------------------------------------------------------------ // 27 // Author: Kazumi Ono (AKA onokazu) // 28 // URL: http://www.xoops.org/ http://jp.xoops.org/ http://www.myweb.ne.jp/ // 29 // Project: The XOOPS Project (http://www.xoops.org/) // 30 // ------------------------------------------------------------------------- // 31 32 if (!defined('XOOPS_ROOT_PATH')) { 33 exit(); 34 } 35 // RMV-NOTIFY 36 include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; 37 include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; 38 39 /** 40 * 41 * 42 * @package kernel 43 * @subpackage notification 44 * 45 * @author Michael van Dam <mvandam@caltech.edu> 46 * @copyright copyright (c) 2000-2003 XOOPS.org 47 */ 48 49 /** 50 * A Notification 51 * 52 * @package kernel 53 * @subpackage notification 54 * 55 * @author Michael van Dam <mvandam@caltech.edu> 56 * @copyright copyright (c) 2000-2003 XOOPS.org 57 */ 58 class XoopsNotification extends XoopsObject 59 { 60 61 /** 62 * Constructor 63 **/ 64 function XoopsNotification() 65 { 66 $this->XoopsObject(); 67 $this->initVar('not_id', XOBJ_DTYPE_INT, NULL, false); 68 $this->initVar('not_modid', XOBJ_DTYPE_INT, NULL, false); 69 $this->initVar('not_category', XOBJ_DTYPE_TXTBOX, null, false, 30); 70 $this->initVar('not_itemid', XOBJ_DTYPE_INT, 0, false); 71 $this->initVar('not_event', XOBJ_DTYPE_TXTBOX, null, false, 30); 72 $this->initVar('not_uid', XOBJ_DTYPE_INT, 0, true); 73 $this->initVar('not_mode', XOBJ_DTYPE_INT, 0, false); 74 } 75 76 // FIXME:??? 77 // To send email to multiple users simultaneously, we would need to move 78 // the notify functionality to the handler class. BUT, some of the tags 79 // are user-dependent, so every email msg will be unique. (Unless maybe use 80 // smarty for email templates in the future.) Also we would have to keep 81 // track if each user wanted email or PM. 82 83 /** 84 * Send a notification message to the user 85 * 86 * @param string $template_dir Template directory 87 * @param string $template Template name 88 * @param string $subject Subject line for notification message 89 * @param array $tags Array of substitutions for template variables 90 * 91 * @return bool true if success, false if error 92 **/ 93 function notifyUser($template_dir, $template, $subject, $tags) 94 { 95 // Check the user's notification preference. 96 97 $member_handler =& xoops_gethandler('member'); 98 $user =& $member_handler->getUser($this->getVar('not_uid')); 99 if (!is_object($user)) { 100 return true; 101 } 102 $method = $user->getVar('notify_method'); 103 104 $xoopsMailer =& getMailer(); 105 include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; 106 switch($method) { 107 case XOOPS_NOTIFICATION_METHOD_PM: 108 $xoopsMailer->usePM(); 109 $config_handler =& xoops_gethandler('config'); 110 $xoopsMailerConfig =& $config_handler->getConfigsByCat(XOOPS_CONF_MAILER); 111 $xoopsMailer->setFromUser($member_handler->getUser($xoopsMailerConfig['fromuid'])); 112 foreach ($tags as $k=>$v) { 113 $xoopsMailer->assign($k, $v); 114 } 115 break; 116 case XOOPS_NOTIFICATION_METHOD_EMAIL: 117 $xoopsMailer->useMail(); 118 foreach ($tags as $k=>$v) { 119 $xoopsMailer->assign($k, preg_replace("/&/i", '&', $v)); 120 } 121 break; 122 default: 123 return true; // report error in user's profile?? 124 break; 125 } 126 127 // Set up the mailer 128 $xoopsMailer->setTemplateDir($template_dir); 129 $xoopsMailer->setTemplate($template); 130 $xoopsMailer->setToUsers($user); 131 //global $xoopsConfig; 132 //$xoopsMailer->setFromEmail($xoopsConfig['adminmail']); 133 //$xoopsMailer->setFromName($xoopsConfig['sitename']); 134 $xoopsMailer->setSubject($subject); 135 $success = $xoopsMailer->send(); 136 137 // If send-once-then-delete, delete notification 138 // If send-once-then-wait, disable notification 139 140 include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; 141 $notification_handler =& xoops_gethandler('notification'); 142 143 if ($this->getVar('not_mode') == XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE) { 144 $notification_handler->delete($this); 145 return $success; 146 } 147 148 if ($this->getVar('not_mode') == XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT) { 149 $this->setVar('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN); 150 $notification_handler->insert($this); 151 } 152 return $success; 153 154 } 155 156 } 157 158 /** 159 * XOOPS notification handler class. 160 * 161 * This class is responsible for providing data access mechanisms to the data source 162 * of XOOPS notification class objects. 163 * 164 * 165 * @package kernel 166 * @subpackage notification 167 * 168 * @author Michael van Dam <mvandam@caltech.edu> 169 * @copyright copyright (c) 2000-2003 XOOPS.org 170 */ 171 class XoopsNotificationHandler extends XoopsObjectHandler 172 { 173 174 /** 175 * Create a {@link XoopsNotification} 176 * 177 * @param bool $isNew Flag the object as "new"? 178 * 179 * @return object 180 */ 181 function &create($isNew = true) 182 { 183 $notification = new XoopsNotification(); 184 if ($isNew) { 185 $notification->setNew(); 186 } 187 return $notification; 188 } 189 190 191 /** 192 * Retrieve a {@link XoopsNotification} 193 * 194 * @param int $id ID 195 * 196 * @return object {@link XoopsNotification}, FALSE on fail 197 **/ 198 function &get($id) 199 { 200 $notification = false; 201 $id = intval($id); 202 if ($id > 0) { 203 $sql = 'SELECT * FROM '.$this->db->prefix('xoopsnotifications').' WHERE not_id='.$id; 204 if (!$result = $this->db->query($sql)) { 205 return $notification; 206 } 207 $numrows = $this->db->getRowsNum($result); 208 if ($numrows == 1) { 209 $notification = new XoopsNotification(); 210 $notification->assignVars($this->db->fetchArray($result)); 211 } 212 } 213 return $notification; 214 } 215 216 217 /** 218 * Write a notification(subscription) to database 219 * 220 * @param object &$notification 221 * 222 * @return bool 223 **/ 224 function insert(&$notification) 225 { 226 if (strtolower(get_class($notification)) != 'xoopsnotification') { 227 return false; 228 } 229 if (!$notification->isDirty()) { 230 return true; 231 } 232 if (!$notification->cleanVars()) { 233 return false; 234 } 235 foreach ($notification->cleanVars as $k => $v) { 236 ${$k} = $v; 237 } 238 if ($notification->isNew()) { 239 $not_id = $this->db->genId('xoopsnotifications_not_id_seq'); 240 $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); 241 } else { 242 $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); 243 } 244 if (!$result = $this->db->query($sql)) { 245 return false; 246 } 247 if (empty($not_id)) { 248 $not_id = $this->db->getInsertId(); 249 } 250 $notification->assignVar('not_id', $not_id); 251 return true; 252 } 253 254 /** 255 * Delete a {@link XoopsNotification} from the database 256 * 257 * @param object &$notification 258 * 259 * @return bool 260 **/ 261 function delete(&$notification) 262 { 263 if (strtolower(get_class($notification)) != 'xoopsnotification') { 264 return false; 265 } 266 $sql = sprintf("DELETE FROM %s WHERE not_id = %u", $this->db->prefix('xoopsnotifications'), $notification->getVar('not_id')); 267 if (!$result = $this->db->query($sql)) { 268 return false; 269 } 270 return true; 271 } 272 273 /** 274 * Get some {@link XoopsNotification}s 275 * 276 * @param object $criteria 277 * @param bool $id_as_key Use IDs as keys into the array? 278 * 279 * @return array Array of {@link XoopsNotification} objects 280 **/ 281 function getObjects($criteria = null, $id_as_key = false) 282 { 283 $ret = array(); 284 $limit = $start = 0; 285 $sql = 'SELECT * FROM '.$this->db->prefix('xoopsnotifications'); 286 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 287 $sql .= ' '.$criteria->renderWhere(); 288 $sort = ($criteria->getSort() != '') ? $criteria->getSort() : 'not_id'; 289 $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder(); 290 $limit = $criteria->getLimit(); 291 $start = $criteria->getStart(); 292 } 293 $result = $this->db->query($sql, $limit, $start); 294 if (!$result) { 295 return $ret; 296 } 297 while ($myrow = $this->db->fetchArray($result)) { 298 $notification = new XoopsNotification(); 299 $notification->assignVars($myrow); 300 if (!$id_as_key) { 301 $ret[] =& $notification; 302 } else { 303 $ret[$myrow['not_id']] =& $notification; 304 } 305 unset($notification); 306 } 307 return $ret; 308 } 309 310 // TODO: Need this?? 311 /** 312 * Count Notifications 313 * 314 * @param object $criteria {@link CriteriaElement} 315 * 316 * @return int Count 317 **/ 318 function getCount($criteria = null) 319 { 320 $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('xoopsnotifications'); 321 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 322 $sql .= ' '.$criteria->renderWhere(); 323 } 324 if (!$result =& $this->db->query($sql)) { 325 return 0; 326 } 327 list($count) = $this->db->fetchRow($result); 328 return $count; 329 } 330 331 /** 332 * Delete multiple notifications 333 * 334 * @param object $criteria {@link CriteriaElement} 335 * 336 * @return bool 337 **/ 338 function deleteAll($criteria = null) 339 { 340 $sql = 'DELETE FROM '.$this->db->prefix('xoopsnotifications'); 341 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 342 $sql .= ' '.$criteria->renderWhere(); 343 } 344 if (!$result = $this->db->query($sql)) { 345 return false; 346 } 347 return true; 348 } 349 350 // Need this?? 351 /** 352 * Change a value in multiple notifications 353 * 354 * @param string $fieldname Name of the field 355 * @param string $fieldvalue Value to write 356 * @param object $criteria {@link CriteriaElement} 357 * 358 * @return bool 359 **/ 360 /* 361 function updateAll($fieldname, $fieldvalue, $criteria = null) 362 { 363 $set_clause = is_numeric($fieldvalue) ? $filedname.' = '.$fieldvalue : $filedname." = '".$fieldvalue."'"; 364 $sql = 'UPDATE '.$this->db->prefix('xoopsnotifications').' SET '.$set_clause; 365 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 366 $sql .= ' '.$criteria->renderWhere(); 367 } 368 if (!$result = $this->db->query($sql)) { 369 return false; 370 } 371 return true; 372 } 373 */ 374 375 // TODO: rename this... 376 // Also, should we have get by module, get by category, etc...?? 377 378 function &getNotification ($module_id, $category, $item_id, $event, $user_id) 379 { 380 $criteria = new CriteriaCompo(); 381 $criteria->add(new Criteria('not_modid', intval($module_id))); 382 $criteria->add(new Criteria('not_category', $category)); 383 $criteria->add(new Criteria('not_itemid', intval($item_id))); 384 $criteria->add(new Criteria('not_event', $event)); 385 $criteria->add(new Criteria('not_uid', intval($user_id))); 386 $objects = $this->getObjects($criteria); 387 if (count($objects) == 1) { 388 return $objects[0]; 389 } 390 $inst = false; 391 return $inst; 392 } 393 394 /** 395 * Determine if a user is subscribed to a particular event in 396 * a particular module. 397 * 398 * @param string $category Category of notification event 399 * @param int $item_id Item ID of notification event 400 * @param string $event Event 401 * @param int $module_id ID of module (default current module) 402 * @param int $user_id ID of user (default current user) 403 * return int 0 if not subscribe; non-zero if subscribed 404 */ 405 406 function isSubscribed ($category, $item_id, $event, $module_id, $user_id) 407 { 408 $criteria = new CriteriaCompo(); 409 $criteria->add(new Criteria('not_modid', intval($module_id))); 410 $criteria->add(new Criteria('not_category', $category)); 411 $criteria->add(new Criteria('not_itemid', intval($item_id))); 412 $criteria->add(new Criteria('not_event', $event)); 413 $criteria->add(new Criteria('not_uid', intval($user_id))); 414 return $this->getCount($criteria); 415 416 } 417 418 419 // TODO: how about a function to subscribe a whole group of users??? 420 // e.g. if we want to add all moderators to be notified of subscription 421 // of new threads... 422 423 /** 424 * Subscribe for notification for an event(s) 425 * 426 * @param string $category category of notification 427 * @param int $item_id ID of the item 428 * @param mixed $events event string or array of events 429 * @param int $mode force a particular notification mode 430 * (e.g. once_only) (default to current user preference) 431 * @param int $module_id ID of the module (default to current module) 432 * @param int $user_id ID of the user (default to current user) 433 **/ 434 function subscribe ($category, $item_id, $events, $mode=null, $module_id=null, $user_id=null) 435 { 436 if (!isset($user_id)) { 437 global $xoopsUser; 438 if (empty($xoopsUser)) { 439 return false; // anonymous cannot subscribe 440 } else { 441 $user_id = $xoopsUser->getVar('uid'); 442 } 443 } 444 445 if (!isset($module_id)) { 446 global $xoopsModule; 447 $module_id = $xoopsModule->getVar('mid'); 448 } 449 450 if (!isset($mode)) { 451 $user = new XoopsUser($user_id); 452 $mode = $user->getVar('notify_mode'); 453 } 454 455 if (!is_array($events)) $events = array($events); 456 foreach ($events as $event) { 457 if ($notification =& $this->getNotification($module_id, $category, $item_id, $event, $user_id)) { 458 if ($notification->getVar('not_mode') != $mode) { 459 $this->updateByField($notification, 'not_mode', $mode); 460 } 461 } else { 462 $notification =& $this->create(); 463 $notification->setVar('not_modid', $module_id); 464 $notification->setVar('not_category', $category); 465 $notification->setVar('not_itemid', $item_id); 466 $notification->setVar('not_uid', $user_id); 467 $notification->setVar('not_event', $event); 468 $notification->setVar('not_mode', $mode); 469 $this->insert($notification); 470 } 471 } 472 } 473 474 475 // TODO: this will be to provide a list of everything a particular 476 // user has subscribed to... e.g. for on the 'Profile' page, similar 477 // to how we see the various posts etc. that the user has made. 478 // We may also want to have a function where we can specify module id 479 /** 480 * Get a list of notifications by user ID 481 * 482 * @param int $user_id ID of the user 483 * 484 * @return array Array of {@link XoopsNotification} objects 485 **/ 486 function getByUser ($user_id) 487 { 488 $criteria = new Criteria ('not_uid', $user_id); 489 return $this->getObjects($criteria, true); 490 } 491 492 // TODO: rename this?? 493 /** 494 * Get a list of notification events for the current item/mod/user 495 * 496 **/ 497 function getSubscribedEvents ($category, $item_id, $module_id, $user_id) 498 { 499 $criteria = new CriteriaCompo(); 500 $criteria->add (new Criteria('not_modid', $module_id)); 501 $criteria->add (new Criteria('not_category', $category)); 502 if ($item_id) { 503 $criteria->add (new Criteria('not_itemid', $item_id)); 504 } 505 $criteria->add (new Criteria('not_uid', $user_id)); 506 $results = $this->getObjects($criteria, true); 507 $ret = array(); 508 foreach (array_keys($results) as $i) { 509 $ret[] = $results[$i]->getVar('not_event'); 510 } 511 return $ret; 512 } 513 514 // TODO: is this a useful function?? (Copied from comment_handler) 515 /** 516 * Retrieve items by their ID 517 * 518 * @param int $module_id Module ID 519 * @param int $item_id Item ID 520 * @param string $order Sort order 521 * 522 * @return array Array of {@link XoopsNotification} objects 523 **/ 524 function getByItemId($module_id, $item_id, $order = null, $status = null) 525 { 526 $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id))); 527 $criteria->add(new Criteria('com_itemid', intval($item_id))); 528 if (isset($status)) { 529 $criteria->add(new Criteria('com_status', intval($status))); 530 } 531 if (isset($order)) { 532 $criteria->setOrder($order); 533 } 534 return $this->getObjects($criteria); 535 } 536 537 538 /** 539 * Send notifications to users 540 * 541 * @param string $category notification category 542 * @param int $item_id ID of the item 543 * @param string $event notification event 544 * @param array $extra_tags array of substitutions for template to be 545 * merged with the one from function.. 546 * @param array $user_list only notify the selected users 547 * @param int $module_id ID of the module 548 * @param int $omit_user_id ID of the user to omit from notifications. (default to current user). set to 0 for all users to receive notification. 549 **/ 550 // TODO:(?) - pass in an event LIST. This will help to avoid 551 // problem of sending people multiple emails for similar events. 552 // BUT, then we need an array of mail templates, etc... Unless 553 // mail templates can include logic in the future, then we can 554 // tailor the mail so it makes sense for any of the possible 555 // (or combination of) events. 556 557 function triggerEvents ($category, $item_id, $events, $extra_tags=array(), $user_list=array(), $module_id=null, $omit_user_id=null) 558 { 559 if (!is_array($events)) { 560 $events = array($events); 561 } 562 foreach ($events as $event) { 563 $this->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id); 564 } 565 } 566 567 function triggerEvent ($category, $item_id, $event, $extra_tags=array(), $user_list=array(), $module_id=null, $omit_user_id=null) 568 { 569 570 if (!isset($module_id)) { 571 global $xoopsModule; 572 $module =& $xoopsModule; 573 $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0; 574 } else { 575 $module_handler =& xoops_gethandler('module'); 576 $module =& $module_handler->get($module_id); 577 } 578 579 // Check if event is enabled 580 $config_handler =& xoops_gethandler('config'); 581 $mod_config =& $config_handler->getConfigsByCat(0,$module->getVar('mid')); 582 if (empty($mod_config['notification_enabled'])) { 583 return false; 584 } 585 $category_info =& notificationCategoryInfo ($category, $module_id); 586 $event_info =& notificationEventInfo ($category, $event, $module_id); 587 if (!in_array(notificationGenerateConfig($category_info,$event_info,'option_name'),$mod_config['notification_events']) && empty($event_info['invisible'])) { 588 return false; 589 } 590 591 if (!isset($omit_user_id)) { 592 global $xoopsUser; 593 if (!empty($xoopsUser)) { 594 $omit_user_id = $xoopsUser->getVar('uid'); 595 } else { 596 $omit_user_id = 0; 597 } 598 } 599 $criteria = new CriteriaCompo(); 600 $criteria->add(new Criteria('not_modid', intval($module_id))); 601 $criteria->add(new Criteria('not_category', $category)); 602 $criteria->add(new Criteria('not_itemid', intval($item_id))); 603 $criteria->add(new Criteria('not_event', $event)); 604 $mode_criteria = new CriteriaCompo(); 605 $mode_criteria->add (new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDALWAYS), 'OR'); 606 $mode_criteria->add (new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE), 'OR'); 607 $mode_criteria->add (new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT), 'OR'); 608 $criteria->add($mode_criteria); 609 if (!empty($user_list)) { 610 $user_criteria = new CriteriaCompo(); 611 foreach ($user_list as $user) { 612 $user_criteria->add (new Criteria('not_uid', $user), 'OR'); 613 } 614 $criteria->add($user_criteria); 615 } 616 $notifications =& $this->getObjects($criteria); 617 if (empty($notifications)) { 618 return; 619 } 620 621 // Add some tag substitutions here 622 623 $not_config = $module->getInfo('notification'); 624 $tags = array(); 625 if (!empty($not_config)) { 626 if (!empty($not_config['tags_file'])) { 627 $tags_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['tags_file']; 628 if (file_exists($tags_file)) { 629 include_once $tags_file; 630 if (!empty($not_config['tags_func'])) { 631 $tags_func = $not_config['tags_func']; 632 if (function_exists($tags_func)) { 633 $tags = $tags_func($category, intval($item_id), $event); 634 } 635 } 636 } 637 } 638 // RMV-NEW 639 if (!empty($not_config['lookup_file'])) { 640 $lookup_file = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/' . $not_config['lookup_file']; 641 if (file_exists($lookup_file)) { 642 include_once $lookup_file; 643 if (!empty($not_config['lookup_func'])) { 644 $lookup_func = $not_config['lookup_func']; 645 if (function_exists($lookup_func)) { 646 $item_info = $lookup_func($category, intval($item_id)); 647 } 648 } 649 } 650 } 651 } 652 $tags['X_ITEM_NAME'] = !empty($item_info['name']) ? $item_info['name'] : '[' . _NOT_ITEMNAMENOTAVAILABLE . ']'; 653 $tags['X_ITEM_URL'] = !empty($item_info['url']) ? $item_info['url'] : '[' . _NOT_ITEMURLNOTAVAILABLE . ']'; 654 $tags['X_ITEM_TYPE'] = !empty($category_info['item_name']) ? $category_info['title'] : '[' . _NOT_ITEMTYPENOTAVAILABLE . ']'; 655 $tags['X_MODULE'] = $module->getVar('name'); 656 $tags['X_MODULE_URL'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/'; 657 $tags['X_NOTIFY_CATEGORY'] = $category; 658 $tags['X_NOTIFY_EVENT'] = $event; 659 660 $template_dir = $event_info['mail_template_dir']; 661 $template = $event_info['mail_template'] . '.tpl'; 662 $subject = $event_info['mail_subject']; 663 664 foreach ($notifications as $notification) { 665 if (empty($omit_user_id) || $notification->getVar('not_uid') != $omit_user_id) { 666 // user-specific tags 667 //$tags['X_UNSUBSCRIBE_URL'] = 'TODO'; 668 // TODO: don't show unsubscribe link if it is 'one-time' ?? 669 $tags['X_UNSUBSCRIBE_URL'] = XOOPS_URL . '/notifications.php'; 670 $tags = array_merge ($tags, $extra_tags); 671 672 $notification->notifyUser($template_dir, $template, $subject, $tags); 673 } 674 } 675 } 676 677 678 /** 679 * Delete all notifications for one user 680 * 681 * @param int $user_id ID of the user 682 * @return bool 683 **/ 684 function unsubscribeByUser ($user_id) 685 { 686 $criteria = new Criteria('not_uid', intval($user_id)); 687 return $this->deleteAll($criteria); 688 } 689 690 691 // TODO: allow these to use current module, etc... 692 693 /** 694 * Unsubscribe notifications for an event(s). 695 * 696 * @param string $category category of the events 697 * @param int $item_id ID of the item 698 * @param mixed $events event string or array of events 699 * @param int $module_id ID of the module (default current module) 700 * @param int $user_id UID of the user (default current user) 701 * 702 * @return bool 703 **/ 704 705 function unsubscribe ($category, $item_id, $events, $module_id=null, $user_id=null) 706 { 707 if (!isset($user_id)) { 708 global $xoopsUser; 709 if (empty($xoopsUser)) { 710 return false; // anonymous cannot subscribe 711 } else { 712 $user_id = $xoopsUser->getVar('uid'); 713 } 714 } 715 716 if (!isset($module_id)) { 717 global $xoopsModule; 718 $module_id = $xoopsModule->getVar('mid'); 719 } 720 721 $criteria = new CriteriaCompo(); 722 $criteria->add (new Criteria('not_modid', intval($module_id))); 723 $criteria->add (new Criteria('not_category', $category)); 724 $criteria->add (new Criteria('not_itemid', intval($item_id))); 725 $criteria->add (new Criteria('not_uid', intval($user_id))); 726 if (!is_array($events)) { 727 $events = array($events); 728 } 729 $event_criteria = new CriteriaCompo(); 730 foreach ($events as $event) { 731 $event_criteria->add (new Criteria('not_event', $event), 'OR'); 732 } 733 $criteria->add($event_criteria); 734 return $this->deleteAll($criteria); 735 } 736 737 738 // TODO: When 'update' a module, may need to switch around some 739 // notification classes/IDs... or delete the ones that no longer 740 // exist. 741 742 /** 743 * Delete all notifications for a particular module 744 * 745 * @param int $module_id ID of the module 746 * @return bool 747 **/ 748 function unsubscribeByModule ($module_id) 749 { 750 $criteria = new Criteria('not_modid', intval($module_id)); 751 return $this->deleteAll($criteria); 752 } 753 754 755 /** 756 * Delete all subscriptions for a particular item. 757 * 758 * @param int $module_id ID of the module to which item belongs 759 * @param string $category Notification category of the item 760 * @param int $item_id ID of the item 761 * 762 * @return bool 763 **/ 764 function unsubscribeByItem ($module_id, $category, $item_id) 765 { 766 $criteria = new CriteriaCompo(); 767 $criteria->add (new Criteria('not_modid', intval($module_id))); 768 $criteria->add (new Criteria('not_category', $category)); 769 $criteria->add (new Criteria('not_itemid', intval($item_id))); 770 return $this->deleteAll($criteria); 771 } 772 773 774 /** 775 * Perform notification maintenance activites at login time. 776 * In particular, any notifications for the newly logged-in 777 * user with mode XOOPS_NOTIFICATION_MODE_WAITFORLOGIN are 778 * switched to mode XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT. 779 * 780 * @param int $user_id ID of the user being logged in 781 **/ 782 function doLoginMaintenance ($user_id) 783 { 784 $criteria = new CriteriaCompo(); 785 $criteria->add (new Criteria('not_uid', intval($user_id))); 786 $criteria->add (new Criteria('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN)); 787 788 $notifications = $this->getObjects($criteria, true); 789 foreach ($notifications as $n) { 790 $n->setVar('not_mode', XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT); 791 $this->insert($n); 792 } 793 } 794 795 796 /** 797 * Update 798 * 799 * @param object &$notification {@link XoopsNotification} object 800 * @param string $field_name Name of the field 801 * @param mixed $field_value Value to write 802 * 803 * @return bool 804 **/ 805 function updateByField(&$notification, $field_name, $field_value) 806 { 807 $notification->unsetNew(); 808 $notification->setVar($field_name, $field_value); 809 return $this->insert($notification); 810 } 811 812 813 } 814 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |