[ Index ]

PHP Cross Reference of Nucleus CMS 3.32

title

Body

[close]

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

   1  <?php
   2  /*
   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
   4   * Copyright (C) 2002-2007 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-2007 The Nucleus Group
  17   * @version $Id: BAN.php 1116 2007-02-03 08:24:29Z kimitake $
  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 = mysql_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 = (mysql_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: Tue Feb 12 15:34:36 2008 Cross-referenced by PHPXref 0.7