]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RegisterThrottle/classes/Registration_ip.php
Merge commit 'refs/merge-requests/199' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / plugins / RegisterThrottle / classes / 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('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Data class for storing IP addresses of new registrants.
34  *
35  * @category Spam
36  * @package  StatusNet
37  * @author   Evan Prodromou <evan@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
39  * @link     http://status.net/
40  */
41 class Registration_ip extends Managed_DataObject
42 {
43     public $__table = 'registration_ip';     // table name
44     public $user_id;                         // int(4)  primary_key not_null
45     public $ipaddress;                       // varchar(45)
46     public $created;                         // datetime()   not_null
47     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
48
49     public static function schemaDef()
50     {
51         return array(
52             'fields' => array(
53                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id this registration relates to'),
54                 'ipaddress' => array('type' => 'varchar', 'length' => 45, 'description' => 'IP address, max 45+null in IPv6'),
55                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
56                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
57             ),
58             'primary key' => array('user_id'),
59             'foreign keys' => array(
60                 'registration_ip_user_id_fkey' => array('user', array('user_id' => 'id')),
61             ),
62             'indexes' => array(
63                 'registration_ip_ipaddress_idx' => array('ipaddress'),
64                 'registration_ip_created_idx' => array('created'),
65             ),
66         );
67     }
68
69     /**
70      * Get the users who've registered with this ip address.
71      *
72      * @param Array $ipaddress IP address to check for
73      *
74      * @return Array IDs of users who registered with this address.
75      */
76     static function usersByIP($ipaddress)
77     {
78         $ids = array();
79
80         $ri            = new Registration_ip();
81         $ri->ipaddress = $ipaddress;
82
83         if ($ri->find()) {
84             while ($ri->fetch()) {
85                 $ids[] = $ri->user_id;
86             }
87         }
88
89         return $ids;
90     }
91 }