]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RegisterThrottle/Registration_ip.php
More info for a proper, fancy-url lighttpd setup
[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;                         // datetime()   not_null
51     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
52
53     public static function schemaDef()
54     {
55         return array(
56             'fields' => array(
57                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id this registration relates to'),
58                 'ipaddress' => array('type' => 'varchar', 'length' => 45, 'description' => 'IP address, max 45+null in IPv6'),
59                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
60                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
61             ),
62             'primary key' => array('user_id'),
63             'foreign keys' => array(
64                 'registration_ip_user_id_fkey' => array('user', array('user_id' => 'id')),
65             ),
66             'indexes' => array(
67                 'registration_ip_ipaddress_idx' => array('ipaddress'),
68                 'registration_ip_created_idx' => array('created'),
69             ),
70         );
71     }
72
73     /**
74      * Get the users who've registered with this ip address.
75      *
76      * @param Array $ipaddress IP address to check for
77      *
78      * @return Array IDs of users who registered with this address.
79      */
80     static function usersByIP($ipaddress)
81     {
82         $ids = array();
83
84         $ri            = new Registration_ip();
85         $ri->ipaddress = $ipaddress;
86
87         if ($ri->find()) {
88             while ($ri->fetch()) {
89                 $ids[] = $ri->user_id;
90             }
91         }
92
93         return $ids;
94     }
95 }