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);
42 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
44 function addBan($blogid, $iprange, $reason) {
47 $blogid = intval($blogid);
53 'iprange' => &$iprange,
58 $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
59 . "($blogid,'".sql_real_escape_string($iprange)."','".sql_real_escape_string($reason)."')";
60 $res = sql_query($query);
66 'iprange' => $iprange,
75 * Removes a ban from the banlist (correct iprange is needed as argument)
76 * Returns 1 on success, 0 on error
78 function removeBan($blogid, $iprange) {
80 $blogid = intval($blogid);
82 $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
84 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .sql_real_escape_string($iprange). "'";
87 $result = (sql_affected_rows() > 0);
89 $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
99 function BANINFO($iprange, $message) {
100 $this->iprange = $iprange;
101 $this->message = $message;