BAN.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00004  * Copyright (C) 2002-2007 The Nucleus Group
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * (see nucleus/documentation/index.html#license for more info)
00011  */
00021 class BAN {
00022 
00029         function isBanned($blogid, $ip) {
00030                 $blogid = intval($blogid);
00031                 $query = 'SELECT * FROM '.sql_table('ban').' WHERE blogid='.$blogid;
00032                 $res = sql_query($query);
00033                 while ($obj = mysql_fetch_object($res)) {
00034                         $found = strpos ($ip, $obj->iprange);
00035                         if (!($found === false))
00036                                 // found a match!
00037                                         return new BANINFO($obj->iprange, $obj->reason);
00038                 }
00039                 return 0;
00040         }
00041 
00045         function addBan($blogid, $iprange, $reason) {
00046                 global $manager;
00047 
00048                 $blogid = intval($blogid);
00049 
00050                 $manager->notify(
00051                         'PreAddBan',
00052                         array(
00053                                 'blogid' => $blogid,
00054                                 'iprange' => &$iprange,
00055                                 'reason' => &$reason
00056                         )
00057                 );
00058 
00059                 $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
00060                            . "($blogid,'".addslashes($iprange)."','".addslashes($reason)."')";
00061                 $res = sql_query($query);
00062 
00063                 $manager->notify(
00064                         'PostAddBan',
00065                         array(
00066                                 'blogid' => $blogid,
00067                                 'iprange' => $iprange,
00068                                 'reason' => $reason
00069                         )
00070                 );
00071 
00072                 return $res ? 1 : 0;
00073         }
00074 
00079         function removeBan($blogid, $iprange) {
00080                 global $manager;
00081                 $blogid = intval($blogid);
00082 
00083                 $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
00084 
00085                 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .addslashes($iprange). "'";
00086                 sql_query($query);
00087 
00088                 $result = (mysql_affected_rows() > 0);
00089 
00090                 $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
00091 
00092                 return $result;
00093         }
00094 }
00095 
00096 class BANINFO {
00097         var $iprange;
00098         var $message;
00099 
00100         function BANINFO($iprange, $message) {
00101                 $this->iprange = $iprange;
00102                 $this->message = $message;
00103         }
00104 }
00105 
00106 
00107 ?>



Generated on Wed Jun 25 17:25:57 2008 by  doxygen 1.5.5