OSDN Git Service

Include plugins which the original release includes and Mocchi modified these codes...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / BAN.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2010 The Nucleus Group
5  *
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)
11  */
12 /**
13  * PHP class responsible for ban-management.
14  *
15  * @license http://nucleuscms.org/license.txt GNU General Public License
16  * @copyright Copyright (C) 2002-2010 The Nucleus Group
17  * @version $Id$
18  * $NucleusJP: BAN.php,v 1.6 2006/07/20 08:01:52 kimitake Exp $
19  */
20
21 class BAN {
22
23         /**
24           * Checks if a given IP is banned from commenting/voting
25           *
26           * Returns 0 when not banned, or a BANINFO object containing the
27           * message and other information of the ban
28           */
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))
36                                 // found a match!
37                                         return new BANINFO($obj->iprange, $obj->reason);
38                 }
39                 return 0;
40         }
41
42         /**
43           * Adds a new ban to the banlist. Returns 1 on success, 0 on error
44           */
45         function addBan($blogid, $iprange, $reason) {
46                 global $manager;
47
48                 $blogid = intval($blogid);
49
50                 $manager->notify(
51                         'PreAddBan',
52                         array(
53                                 'blogid' => $blogid,
54                                 'iprange' => &$iprange,
55                                 'reason' => &$reason
56                         )
57                 );
58
59                 $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES "
60                            . "($blogid,'".sql_real_escape_string($iprange)."','".sql_real_escape_string($reason)."')";
61                 $res = sql_query($query);
62
63                 $manager->notify(
64                         'PostAddBan',
65                         array(
66                                 'blogid' => $blogid,
67                                 'iprange' => $iprange,
68                                 'reason' => $reason
69                         )
70                 );
71
72                 return $res ? 1 : 0;
73         }
74
75         /**
76           * Removes a ban from the banlist (correct iprange is needed as argument)
77           * Returns 1 on success, 0 on error
78           */
79         function removeBan($blogid, $iprange) {
80                 global $manager;
81                 $blogid = intval($blogid);
82
83                 $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
84
85                 $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .sql_real_escape_string($iprange). "'";
86                 sql_query($query);
87
88                 $result = (sql_affected_rows() > 0);
89
90                 $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange));
91
92                 return $result;
93         }
94 }
95
96 class BANINFO {
97         var $iprange;
98         var $message;
99
100         function BANINFO($iprange, $message) {
101                 $this->iprange = $iprange;
102                 $this->message = $message;
103         }
104 }
105
106
107 ?>