3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2005 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
12 * PHP class responsible for ban-management.
\r
14 * $Id: BAN.php,v 1.3 2005-03-12 06:19:05 kimitake Exp $
\r
21 * Checks if a given IP is banned from commenting/voting
\r
23 * Returns 0 when not banned, or a BANINFO object containing the
\r
24 * message and other information of the ban
\r
26 function isBanned($blogid, $ip) {
\r
27 $blogid = intval($blogid);
\r
28 $query = 'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid;
\r
29 $res = sql_query($query);
\r
30 while ($obj = mysql_fetch_object($res)) {
\r
31 $found = strpos ($ip, $obj->iprange);
\r
32 if (!($found === false))
\r
34 return new BANINFO($obj->iprange, $obj->reason);
\r
40 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
\r
42 function addBan($blogid, $iprange, $reason) {
\r
45 $blogid = intval($blogid);
\r
50 'blogid' => $blogid,
\r
51 'iprange' => &$iprange,
\r
52 'reason' => &$reason
\r
56 $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
\r
57 . "($blogid,'".addslashes($iprange)."','".addslashes($reason)."')";
\r
58 $res = sql_query($query);
\r
63 'blogid' => $blogid,
\r
64 'iprange' => $iprange,
\r
69 return $res ? 1 : 0;
\r
73 * Removes a ban from the banlist (correct iprange is needed as argument)
\r
74 * Returns 1 on success, 0 on error
\r
76 function removeBan($blogid, $iprange) {
\r
78 $blogid = intval($blogid);
\r
80 $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
\r
82 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .addslashes($iprange). "'";
\r
85 $result = (mysql_affected_rows() > 0);
\r
87 $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
\r
97 function BANINFO($iprange, $message) {
\r
98 $this->iprange = $iprange;
\r
99 $this->message = $message;
\r