Registration_ip.php 3.2 KB

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