4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2012 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
14 * PHP class responsible for ban-management.
\r
16 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
18 * @version $Id: BAN.php 1525 2011-06-21 10:20:19Z sakamocchi $
\r
24 * Checks if a given IP is banned from commenting/voting
\r
26 * Returns 0 when not banned, or a BanInfo object containing the
\r
27 * message and other information of the ban
\r
29 public function isBanned($blogid, $ip)
\r
31 $blogid = intval($blogid);
\r
32 $query = sprintf('SELECT * FROM %s WHERE blogid=%d', sql_table('ban'), intval($blogid));
\r
33 $res = DB::getResult($query);
\r
34 foreach ( $res as $row )
\r
36 $found = i18n::strpos ($ip, $row['iprange']);
\r
37 if ( $found !== false )
\r
40 return new BanInfo($row['iprange'], $row['reason']);
\r
48 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
\r
50 * @param Integer $blogid ID for weblog
\r
51 * @param String $iprange IP range
\r
52 * @param String $reason reason for banning
\r
56 public function addBan($blogid, $iprange, $reason)
\r
63 'blogid' => $blogid,
\r
64 'iprange' => &$iprange,
\r
65 'reason' => &$reason
\r
69 $query = 'INSERT INTO %s (blogid, iprange, reason) VALUES (%d, %s, %s)';
\r
70 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange), DB::quoteValue($reason));
\r
71 $res = DB::execute($query);
\r
76 'blogid' => $blogid,
\r
77 'iprange' => $iprange,
\r
82 return $res !== FALSE ? 1 : 0;
\r
86 * Removes a ban from the banlist (correct iprange is needed as argument)
\r
87 * Returns 1 on success, 0 on error
\r
89 public function removeBan($blogid, $iprange)
\r
96 'blogid' => $blogid,
\r
101 $query = 'DELETE FROM %s WHERE blogid=%d and iprange=%s';
\r
102 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange));
\r
103 $res = DB::execute($query);
\r
108 'blogid' => $blogid,
\r
109 'range' => $iprange
\r
113 return $res !== FALSE ? 1 : 0;
\r
122 public function __construct($iprange, $message)
\r
124 $this->iprange = $iprange;
\r
125 $this->message = $message;
\r
132 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
133 * Copyright (C) 2002-2009 The Nucleus Group
135 * This program is free software; you can redistribute it and/or
136 * modify it under the terms of the GNU General Public License
137 * as published by the Free Software Foundation; either version 2
138 * of the License, or (at your option) any later version.
139 * (see nucleus/documentation/index.html#license for more info)
142 * PHP class responsible for ban-management.
144 * @license http://nucleuscms.org/license.txt GNU General Public License
145 * @copyright Copyright (C) 2002-2009 The Nucleus Group
146 * @version $Id: BAN.php 1812 2012-05-01 14:59:07Z sakamocchi $
152 * Checks if a given IP is banned from commenting/voting
154 * Returns 0 when not banned, or a BanInfo object containing the
155 * message and other information of the ban
157 public function isBanned($blogid, $ip)
159 $blogid = intval($blogid);
160 $query = sprintf('SELECT * FROM %s WHERE blogid=%d', sql_table('ban'), intval($blogid));
161 $res = DB::getResult($query);
162 foreach ( $res as $row )
164 $found = i18n::strpos ($ip, $row['iprange']);
165 if ( $found !== false )
168 return new BanInfo($row['iprange'], $row['reason']);
176 * Adds a new ban to the banlist. Returns 1 on success, 0 on error
178 * @param Integer $blogid ID for weblog
179 * @param String $iprange IP range
180 * @param String $reason reason for banning
184 public function addBan($blogid, $iprange, $reason)
190 'iprange' => &$iprange,
193 $manager->notify('PreAddBan', $data);
195 $query = 'INSERT INTO %s (blogid, iprange, reason) VALUES (%d, %s, %s)';
196 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange), DB::quoteValue($reason));
197 $res = DB::execute($query);
199 $manager->notify('PostAddBan', $data);
201 return $res !== FALSE ? 1 : 0;
205 * Removes a ban from the banlist (correct iprange is needed as argument)
206 * Returns 1 on success, 0 on error
208 public function removeBan($blogid, $iprange)
216 $manager->notify('PreDeleteBan', $data);
218 $query = 'DELETE FROM %s WHERE blogid=%d and iprange=%s';
219 $query = sprintf($query, sql_table('ban'), intval($blogid), DB::quoteValue($iprange));
220 $res = DB::execute($query);
222 $manager->notify('PostDeleteBan', $data);
224 return $res !== FALSE ? 1 : 0;
233 public function __construct($iprange, $message)
235 $this->iprange = $iprange;
236 $this->message = $message;
240 >>>>>>> skinnable-master