]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RegisterThrottle/Registration_ip.php
Make errors work correctly
[quix0rs-gnu-social.git] / plugins / RegisterThrottle / Registration_ip.php
1 <?php
2 /**
3  * Data class for storing IP addresses of new registrants.
4  *
5  * PHP version 5
6  *
7  * @category Data
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2010, StatusNet, Inc.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Affero General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
24  * GNU Affero General Public License for more details.
25  *
26  * You should have received a copy of the GNU Affero General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
35
36 /**
37  * Data class for storing IP addresses of new registrants.
38  *
39  * @category Spam
40  * @package  StatusNet
41  * @author   Evan Prodromou <evan@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://status.net/
44  */
45 class Registration_ip extends Memcached_DataObject
46 {
47     public $__table = 'registration_ip';     // table name
48     public $user_id;                         // int(4)  primary_key not_null
49     public $ipaddress;                       // varchar(15)
50     public $created;                         // timestamp
51
52     /**
53      * Get an instance by key
54      *
55      * @param string $k Key to use to lookup (usually 'user_id' for this class)
56      * @param mixed  $v Value to lookup
57      *
58      * @return User_greeting_count object found, or null for no hits
59      *
60      */
61     function staticGet($k, $v=null)
62     {
63         return Memcached_DataObject::staticGet('Registration_ip', $k, $v);
64     }
65
66     /**
67      * return table definition for DB_DataObject
68      *
69      * @return array array of column definitions
70      */
71     function table()
72     {
73         return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
74                      'ipaddress' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
75                      'created' => DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL);
76     }
77
78     /**
79      * return key definitions for DB_DataObject
80      *
81      * DB_DataObject needs to know about keys that the table has; this function
82      * defines them.
83      *
84      * @return array key definitions
85      */
86     function keys()
87     {
88         return array('user_id' => 'K');
89     }
90
91     /**
92      * return key definitions for Memcached_DataObject
93      *
94      * Our caching system uses the same key definitions, but uses a different
95      * method to get them.
96      *
97      * @return array key definitions
98      */
99     function keyTypes()
100     {
101         return $this->keys();
102     }
103
104     /**
105      * Magic formula for non-autoincrementing integer primary keys
106      *
107      * If a table has a single integer column as its primary key, DB_DataObject
108      * assumes that the column is auto-incrementing and makes a sequence table
109      * to do this incrementation. Since we don't need this for our class, we
110      * overload this method and return the magic formula that DB_DataObject needs.
111      *
112      * @return array magic three-false array that stops auto-incrementing.
113      */
114
115     function sequenceKey()
116     {
117         return array(false, false, false);
118     }
119
120     /**
121      * Get the users who've registered with this ip address.
122      *
123      * @param Array $ipaddress IP address to check for
124      *
125      * @return Array IDs of users who registered with this address.
126      */
127
128     static function usersByIP($ipaddress)
129     {
130         $ids = array();
131
132         $ri            = new Registration_ip();
133         $ri->ipaddress = $ipaddress;
134
135         if ($ri->find()) {
136             while ($ri->fetch()) {
137                 $ids[] = $ri->user_id;
138             }
139         }
140
141         return $ids;
142     }
143 }