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
18 * $NucleusJP: BAN.php,v 1.6 2006/07/20 08:01:52 kimitake Exp $
24 * Checks if a given IP is banned from commenting/voting
26 * Returns 0 when not banned, or a BANINFO object containing the
27 * message and other information of the ban
29 function isBanned($blogid, $ip) {
30 $blogid = intval($blogid);
31 $query = 'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid;
32 $res = sql_query($query);
33 while ($obj = sql_fetch_object($res)) {
34 $found = strpos ($ip, $obj->iprange);
35 if (!($found === false))
37 return new BANINFO($obj->iprange, $obj->reason);
43 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
45 function addBan($blogid, $iprange, $reason) {
48 $blogid = intval($blogid);
54 'iprange' => &$iprange,
59 $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
60 . "($blogid,'".addslashes($iprange)."','".addslashes($reason)."')";
61 $res = sql_query($query);
67 'iprange' => $iprange,
76 * Removes a ban from the banlist (correct iprange is needed as argument)
77 * Returns 1 on success, 0 on error
79 function removeBan($blogid, $iprange) {
81 $blogid = intval($blogid);
83 $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
85 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .addslashes($iprange). "'";
88 $result = (sql_affected_rows() > 0);
90 $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
100 function BANINFO($iprange, $message) {
101 $this->iprange = $iprange;
102 $this->message = $message;