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)
61 'iprange' => &$iprange,
64 $manager->notify('PreAddBan', $data);
66 $query = 'INSERT INTO %s (blogid, iprange, reason) VALUES (%d, %s, %s)';
67 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange), DB::quoteValue($reason));
68 $res = DB::execute($query);
70 $manager->notify('PostAddBan', $data);
72 return $res !== FALSE ? 1 : 0;
76 * Removes a ban from the banlist (correct iprange is needed as argument)
77 * Returns 1 on success, 0 on error
79 public function removeBan($blogid, $iprange)
87 $manager->notify('PreDeleteBan', $data);
89 $query = 'DELETE FROM %s WHERE blogid=%d and iprange=%s';
90 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange));
91 $res = DB::execute($query);
93 $manager->notify('PostDeleteBan', $data);
95 return $res !== FALSE ? 1 : 0;
104 public function __construct($iprange, $message)
106 $this->iprange = $iprange;
107 $this->message = $message;