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 1525 2011-06-21 10:20:19Z 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 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 = i18n::strpos ($ip, $obj->iprange);
34 if (!($found === false))
36 return new BANINFO($obj->iprange, $obj->reason);
43 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
45 * @param Integer $blogid ID for weblog
46 * @param String $iprange IP range
47 * @param String $reason reason for banning
51 function addBan($blogid, $iprange, $reason)
55 $blogid = intval($blogid);
61 'iprange' => &$iprange,
66 $query = "INSERT INTO %s (blogid, iprange, reason) VALUES (%d, '%s', '%s')";
67 $query = sprintf($query, sql_table('ban'), $blogid, sql_real_escape_string($iprange), sql_real_escape_string($reason));
68 $res = sql_query($query);
74 'iprange' => $iprange,
82 * Removes a ban from the banlist (correct iprange is needed as argument)
83 * Returns 1 on success, 0 on error
85 function removeBan($blogid, $iprange) {
87 $blogid = intval($blogid);
89 $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
91 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .sql_real_escape_string($iprange). "'";
94 $result = (sql_affected_rows() > 0);
96 $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
106 function BANINFO($iprange, $message) {
107 $this->iprange = $iprange;
108 $this->message = $message;