]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RegisterThrottle/Registration_ip.php
Updating all Memcached_DataObject extended classes to Managed_DataObject
[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 Managed_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      * return table definition for DB_DataObject
54      *
55      * @return array array of column definitions
56      */
57     function table()
58     {
59         return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
60                      'ipaddress' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
61                      'created' => DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL);
62     }
63
64     /**
65      * return key definitions for DB_DataObject
66      *
67      * DB_DataObject needs to know about keys that the table has; this function
68      * defines them.
69      *
70      * @return array key definitions
71      */
72     function keys()
73     {
74         return array('user_id' => 'K');
75     }
76
77     /**
78      * return key definitions for Memcached_DataObject
79      *
80      * Our caching system uses the same key definitions, but uses a different
81      * method to get them.
82      *
83      * @return array key definitions
84      */
85     function keyTypes()
86     {
87         return $this->keys();
88     }
89
90     /**
91      * Magic formula for non-autoincrementing integer primary keys
92      *
93      * If a table has a single integer column as its primary key, DB_DataObject
94      * assumes that the column is auto-incrementing and makes a sequence table
95      * to do this incrementation. Since we don't need this for our class, we
96      * overload this method and return the magic formula that DB_DataObject needs.
97      *
98      * @return array magic three-false array that stops auto-incrementing.
99      */
100     function sequenceKey()
101     {
102         return array(false, false, false);
103     }
104
105     /**
106      * Get the users who've registered with this ip address.
107      *
108      * @param Array $ipaddress IP address to check for
109      *
110      * @return Array IDs of users who registered with this address.
111      */
112     static function usersByIP($ipaddress)
113     {
114         $ids = array();
115
116         $ri            = new Registration_ip();
117         $ri->ipaddress = $ipaddress;
118
119         if ($ri->find()) {
120             while ($ri->fetch()) {
121                 $ids[] = $ri->user_id;
122             }
123         }
124
125         return $ids;
126     }
127 }