3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 The Nucleus Group
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)
13 * PHP class responsible for ban-management.
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 1812 2012-05-01 14:59:07Z sakamocchi $
23 * Checks if a given IP is banned from commenting/voting
25 * Returns 0 when not banned, or a BanInfo object containing the
26 * message and other information of the ban
28 public function isBanned($blogid, $ip)
30 $blogid = intval($blogid);
31 $query = sprintf('SELECT * FROM %s WHERE blogid=%d', sql_table('ban'), intval($blogid));
32 $res = DB::getResult($query);
33 foreach ( $res as $row )
35 $found = i18n::strpos ($ip, $row['iprange']);
36 if ( $found !== false )
39 return new BanInfo($row['iprange'], $row['reason']);
47 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
49 * @param Integer $blogid ID for weblog
50 * @param String $iprange IP range
51 * @param String $reason reason for banning
55 public function addBan($blogid, $iprange, $reason)
63 'iprange' => &$iprange,
68 $query = 'INSERT INTO %s (blogid, iprange, reason) VALUES (%d, %s, %s)';
69 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange), DB::quoteValue($reason));
70 $res = DB::execute($query);
76 'iprange' => $iprange,
81 return $res !== FALSE ? 1 : 0;
85 * Removes a ban from the banlist (correct iprange is needed as argument)
86 * Returns 1 on success, 0 on error
88 public function removeBan($blogid, $iprange)
100 $query = 'DELETE FROM %s WHERE blogid=%d and iprange=%s';
101 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange));
102 $res = DB::execute($query);
112 return $res !== FALSE ? 1 : 0;
121 public function __construct($iprange, $message)
123 $this->iprange = $iprange;
124 $this->message = $message;