[ Index ]

PHP Cross Reference of Nucleus CMS v3.51 code documentation

title

Body

[close]

/nucleus/libs/ -> BAN.php (source)

   1  <?php
   2  /*

   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)

   4   * Copyright (C) 2002-2009 The Nucleus Group

   5   *

   6   * This program is free software; you can redistribute it and/or

   7   * modify it under the terms of the GNU General Public License

   8   * as published by the Free Software Foundation; either version 2

   9   * of the License, or (at your option) any later version.

  10   * (see nucleus/documentation/index.html#license for more info)

  11   */
  12  /**

  13   * PHP class responsible for ban-management.

  14   *

  15   * @license http://nucleuscms.org/license.txt GNU General Public License

  16   * @copyright Copyright (C) 2002-2009 The Nucleus Group

  17   * @version $Id: BAN.php 1388 2009-07-18 06:31:28Z shizuki $

  18   */
  19  
  20  class BAN {
  21  
  22      /**

  23        * Checks if a given IP is banned from commenting/voting

  24        *

  25        * Returns 0 when not banned, or a BANINFO object containing the

  26        * message and other information of the ban

  27        */
  28  	function isBanned($blogid, $ip) {
  29          $blogid = intval($blogid);
  30          $query = 'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid;
  31          $res = sql_query($query);
  32          while ($obj = sql_fetch_object($res)) {
  33              $found = strpos ($ip, $obj->iprange);
  34              if (!($found === false))
  35                  // found a match!

  36                      return new BANINFO($obj->iprange, $obj->reason);
  37          }
  38          return 0;
  39      }
  40  
  41      /**

  42        * Adds a new ban to the banlist. Returns 1 on success, 0 on error

  43        */
  44  	function addBan($blogid, $iprange, $reason) {
  45          global $manager;
  46  
  47          $blogid = intval($blogid);
  48  
  49          $manager->notify(
  50              'PreAddBan',
  51              array(
  52                  'blogid' => $blogid,
  53                  'iprange' => &$iprange,
  54                  'reason' => &$reason
  55              )
  56          );
  57  
  58          $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
  59                 . "($blogid,'".addslashes($iprange)."','".addslashes($reason)."')";
  60          $res = sql_query($query);
  61  
  62          $manager->notify(
  63              'PostAddBan',
  64              array(
  65                  'blogid' => $blogid,
  66                  'iprange' => $iprange,
  67                  'reason' => $reason
  68              )
  69          );
  70  
  71          return $res ? 1 : 0;
  72      }
  73  
  74      /**

  75        * Removes a ban from the banlist (correct iprange is needed as argument)

  76        * Returns 1 on success, 0 on error

  77        */
  78  	function removeBan($blogid, $iprange) {
  79          global $manager;
  80          $blogid = intval($blogid);
  81  
  82          $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
  83  
  84          $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .addslashes($iprange). "'";
  85          sql_query($query);
  86  
  87          $result = (sql_affected_rows() > 0);
  88  
  89          $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
  90  
  91          return $result;
  92      }
  93  }
  94  
  95  class BANINFO {
  96      var $iprange;
  97      var $message;
  98  
  99  	function BANINFO($iprange, $message) {
 100          $this->iprange = $iprange;
 101          $this->message = $message;
 102      }
 103  }
 104  
 105  
 106  ?>


Generated: Sun Aug 1 03:56:06 2010
Open Source related documentation for developers.