[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/include/ -> notification_functions.php (source)

   1  <?php
   2  // $Id: notification_functions.php 759 2006-09-24 21:42:58Z phppp $

   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  // RMV-NOTIFY

  33  
  34  // FIXME: Do some caching, so we don't retrieve the same category / event

  35  // info many times.

  36  
  37  
  38  /**

  39   * Determine if notification is enabled for the selected module.

  40   *

  41   * @param  string  $style      Subscription style: 'block' or 'inline'

  42   * @param  int     $module_id  ID of the module  (default current module)

  43   * @return bool

  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      // if ($status != XOOPS_NOTIFICATION_DISABLE) {

  71      //         return true;

  72      // }

  73      return false;
  74  }
  75  
  76  /**

  77   * Get an associative array of info for a particular notification

  78   * category in the selected module.  If no category is selected,

  79   * return an array of info for all categories.

  80   *

  81   * @param  string  $name       Category name (default all categories)

  82   * @param  int     $module_id  ID of the module (default current module)

  83   * @return mixed

  84   */
  85  function &notificationCategoryInfo ($category_name='', $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      $not_config =& $module->getInfo('notification');
  96      if (empty($category_name)) {
  97          return $not_config['category'];
  98      }
  99      foreach ($not_config['category'] as $category) {
 100          if ($category['name'] == $category_name) {
 101              return $category;
 102          }
 103      }
 104      $ret = false;
 105      return $ret;
 106  }
 107  
 108  /**

 109   * Get associative array of info for the category to which comment events

 110   * belong.

 111   *

 112   * @todo This could be more efficient... maybe specify in

 113   *        $modversion['comments'] the notification category.

 114   *       This would also serve as a way to enable notification

 115   *        of comments, and also remove the restriction that

 116   *        all notification categories must have unique item_name. (TODO)

 117   *

 118   * @param  int  $module_id  ID of the module (default current module)

 119   * @return mixed            Associative array of category info

 120   */
 121  function &notificationCommentCategoryInfo($module_id=null)
 122  {
 123      $ret = false;
 124      $all_categories =& notificationCategoryInfo ('', $module_id);
 125      if (empty($all_categories)) {
 126          return $ret;
 127      }
 128      foreach ($all_categories as $category) {
 129          $all_events =& notificationEvents ($category['name'], false, $module_id);
 130          if (empty($all_events)) {
 131              continue;
 132          }
 133          foreach ($all_events as $event) {
 134              if ($event['name'] == 'comment') {
 135                  return $category;
 136              }
 137          }
 138      }
 139      return $ret;
 140  }
 141  
 142  // TODO: some way to include or exclude admin-only events...

 143  
 144  /**

 145   * Get an array of info for all events (each event has associative array)

 146   * in the selected category of the selected module.

 147   *

 148   * @param  string  $category_name  Category name

 149   * @param  bool    $enabled_only   If true, return only enabled events

 150   * @param  int     $module_id      ID of the module (default current module)

 151   * @return mixed

 152   */
 153  function &notificationEvents ($category_name, $enabled_only, $module_id=null)
 154  {
 155      if (!isset($module_id)) {
 156          global $xoopsModule;
 157          $module_id = !empty($xoopsModule) ? $xoopsModule->getVar('mid') : 0;
 158          $module =& $xoopsModule;
 159      } else {
 160          $module_handler =& xoops_gethandler('module');
 161          $module =& $module_handler->get($module_id);
 162      }
 163      $not_config =& $module->getInfo('notification');
 164      $config_handler =& xoops_gethandler('config');
 165      $mod_config = $config_handler->getConfigsByCat(0,$module_id);
 166  
 167      $category =& notificationCategoryInfo($category_name, $module_id);
 168  
 169      global $xoopsConfig;
 170      $event_array = array();
 171  
 172      $override_comment = false;
 173      $override_commentsubmit = false;
 174      $override_bookmark = false;
 175      
 176      foreach ($not_config['event'] as $event) {
 177          if ($event['category'] == $category_name) {
 178              $event['mail_template_dir'] = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/';
 179              if (!$enabled_only || notificationEventEnabled ($category, $event, $module)) {
 180                  $event_array[] = $event;
 181              }
 182              if ($event['name'] == 'comment') {
 183                  $override_comment = true;
 184              }
 185              if ($event['name'] == 'comment_submit') {
 186                  $override_commentsubmit = true;
 187              }
 188              if ($event['name'] == 'bookmark') {
 189                  $override_bookmark = true;
 190              }
 191          }
 192      }
 193  
 194      include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/notification.php';
 195  
 196      // Insert comment info if applicable

 197      
 198      if ($module->getVar('hascomments')) {
 199          $com_config = $module->getInfo('comments');
 200          if (!empty($category['item_name']) && $category['item_name'] == $com_config['itemName']) {
 201              $mail_template_dir = XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/mail_template/';
 202              include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
 203              $config_handler =& xoops_gethandler('config');
 204              $com_config = $config_handler->getConfigsByCat(0,$module_id);
 205              if (!$enabled_only) {
 206                  $insert_comment = true;
 207                  $insert_submit = true;
 208              } else {
 209                  $insert_comment = false;
 210                  $insert_submit = false;
 211                  switch($com_config['com_rule']) {
 212                  case XOOPS_COMMENT_APPROVENONE:
 213                      // comments disabled, no comment events

 214                      break;
 215                  case XOOPS_COMMENT_APPROVEALL:
 216                      // all comments are automatically approved, no 'submit'

 217                      if (!$override_comment) {
 218                          $insert_comment = true;
 219                      }
 220                      break;
 221                  case XOOPS_COMMENT_APPROVEUSER:
 222                  case XOOPS_COMMENT_APPROVEADMIN:
 223                      // comments first submitted, require later approval

 224                      if (!$override_comment) {
 225                          $insert_comment = true;
 226                      }
 227                      if (!$override_commentsubmit) {
 228                          $insert_submit = true;
 229                      }
 230                      break;
 231                  }
 232              }
 233              if ($insert_comment) {
 234                  $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);
 235                  if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
 236                      $event_array[] = $event;
 237                  }
 238              }
 239              if ($insert_submit) {
 240                  $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);
 241                  if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
 242                      $event_array[] = $event;
 243                  }
 244              }
 245                  
 246  
 247          }
 248      }
 249  
 250      // Insert bookmark info if appropriate

 251  
 252      if (!empty($category['allow_bookmark'])) {
 253          if (!$override_bookmark) {
 254              $event = array ('name'=>'bookmark', 'category'=>$category['name'], 'title'=>_NOT_BOOKMARK_NOTIFY, 'caption'=>_NOT_BOOKMARK_NOTIFYCAP, 'description'=>_NOT_BOOKMARK_NOTIFYDSC);
 255              if (!$enabled_only || notificationEventEnabled($category, $event, $module)) {
 256                  $event_array[] = $event;
 257              }
 258          }    
 259      }
 260  
 261  
 262      return $event_array;
 263      
 264  }
 265  
 266  /**

 267   * Determine whether a particular notification event is enabled.

 268   * Depends on module config options.

 269   *

 270   * @todo  Check that this works correctly for comment and other

 271   *   events which depend on additional config options...

 272   *

 273   * @param  array  $category  Category info array

 274   * @param  array  $event     Event info array

 275   * @param  object $module    Module

 276   * @return bool

 277   **/
 278  function notificationEventEnabled (&$category, &$event, &$module)
 279  {
 280      $config_handler =& xoops_gethandler('config');
 281      $mod_config = $config_handler->getConfigsByCat(0,$module->getVar('mid'));
 282  
 283      if (is_array($mod_config['notification_events']) && $mod_config['notification_events'] != array()) {
 284          $option_name = notificationGenerateConfig ($category, $event, 'option_name');
 285          if (in_array($option_name, $mod_config['notification_events'])) {
 286              return true;
 287          }
 288          $notification_handler =& xoops_gethandler('notification');
 289      }
 290      return false;
 291  }
 292  
 293  
 294  /**

 295   * Get associative array of info for the selected event in the selected

 296   * category (for the selected module).

 297   *

 298   * @param  string  $category_name  Notification category

 299   * @param  string  $event_name     Notification event

 300   * @param  int     $module_id      ID of the module (default current module)

 301   * @return mixed

 302   */
 303  function &notificationEventInfo ($category_name, $event_name, $module_id=null)
 304  {
 305      $all_events =& notificationEvents ($category_name, false, $module_id);
 306      foreach ($all_events as $event) {
 307          if ($event['name'] == $event_name) {
 308              return $event;
 309          }
 310      }
 311      $ret = false;
 312      return $ret;
 313  }
 314  
 315  
 316  /**

 317   * Get an array of associative info arrays for subscribable categories

 318   * for the selected module.

 319   *

 320   * @param  int  $module_id  ID of the module

 321   * @return mixed

 322   */
 323  
 324  function &notificationSubscribableCategoryInfo ($module_id=null)
 325  {
 326      $all_categories =& notificationCategoryInfo ('', $module_id);
 327  
 328      // FIXME: better or more standardized way to do this?

 329      $script_url = explode('/', $_SERVER['PHP_SELF']);
 330      $script_name = $script_url[count($script_url)-1];
 331  
 332      $sub_categories = array();
 333  
 334      foreach ($all_categories as $category) {
 335  
 336          // Check the script name

 337  
 338          $subscribe_from = $category['subscribe_from'];
 339          if (!is_array($subscribe_from)) {
 340              if ($subscribe_from == '*') {
 341                  $subscribe_from = array($script_name);
 342                  // FIXME: this is just a hack: force a match

 343              } else {
 344                  $subscribe_from = array($subscribe_from);
 345              }
 346          }
 347          if (!in_array($script_name, $subscribe_from)) {
 348              continue;
 349          }    
 350  
 351          // If 'item_name' is missing, automatic match.  Otherwise

 352          // check if that argument exists...

 353  
 354          if (empty($category['item_name'])) {
 355              $category['item_name'] = '';
 356              $category['item_id'] = 0;
 357              $sub_categories[] = $category;
 358          } else {
 359              $item_name = $category['item_name'];
 360              $id = ($item_name != '' && isset($_GET[$item_name])) ? intval($_GET[$item_name]) : 0;
 361              if ($id > 0)  {
 362                  $category['item_id'] = $id;
 363                  $sub_categories[] = $category;
 364              }
 365          }
 366      }
 367      return $sub_categories;
 368  
 369  }
 370  
 371  /**

 372   * Generate module config info for a particular category, event pair.

 373   * The selectable config options are given names depending on the

 374   * category and event names, and the text depends on the category

 375   * and event titles.  These are pieced together in this function in

 376   * case we wish to alter the syntax.

 377   *

 378   * @param  array  $category  Array of category info

 379   * @param  array  $event     Array of event info

 380   * @param  string $type      The particular name to generate

 381   * return string

 382   **/
 383  function notificationGenerateConfig (&$category, &$event, $type)
 384  {
 385      switch ($type) {
 386      case 'option_value':
 387      case 'name':
 388          return 'notify:' . $category['name'] . '-' . $event['name'];
 389          break;
 390      case 'option_name':
 391          return $category['name'] . '-' . $event['name'];
 392          break;
 393      default:
 394          return false;
 395          break;
 396      }
 397  }
 398  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics