We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

User.php 4.37 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Evan Prodromou's avatar
Evan Prodromou committed
2
/*
Evan Prodromou's avatar
Evan Prodromou committed
3 4
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2008, Controlez-Vous, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
5
 *
Evan Prodromou's avatar
Evan Prodromou committed
6 7 8 9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Evan Prodromou's avatar
Evan Prodromou committed
10
 *
Evan Prodromou's avatar
Evan Prodromou committed
11 12 13 14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
Evan Prodromou's avatar
Evan Prodromou committed
15
 *
Evan Prodromou's avatar
Evan Prodromou committed
16 17 18 19
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

Evan Prodromou's avatar
Evan Prodromou committed
20
if (!defined('LACONICA')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
21 22 23 24
/**
 * Table Definition for user
 */
require_once 'DB/DataObject.php';
25
require_once 'Validate.php';
Evan Prodromou's avatar
Evan Prodromou committed
26

27
class User extends DB_DataObject 
Evan Prodromou's avatar
Evan Prodromou committed
28 29 30 31 32 33
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    public $__table = 'user';                            // table name
    public $id;                              // int(4)  primary_key not_null
Evan Prodromou's avatar
Evan Prodromou committed
34
    public $nickname;                        // varchar(64)  unique_key
35
    public $password;                        // varchar(255)  
Evan Prodromou's avatar
Evan Prodromou committed
36
    public $email;                           // varchar(255)  unique_key
Evan Prodromou's avatar
Evan Prodromou committed
37
    public $incomingemail;                   // varchar(255)  unique_key
38
    public $emailnotifysub;                  // tinyint(1)   default_1
39
    public $emailpost;                       // tinyint(1)   default_1
40
    public $jabber;                          // varchar(255)  unique_key
41 42 43
    public $jabbernotify;                    // tinyint(1)  
    public $jabberreplies;                   // tinyint(1)  
    public $updatefrompresence;              // tinyint(1)  
44
    public $sms;                             // varchar(64)  unique_key
45 46
    public $carrier;                         // int(4)  
    public $smsnotify;                       // tinyint(1)  
Evan Prodromou's avatar
Evan Prodromou committed
47
    public $smsreplies;                      // tinyint(1)  
Evan Prodromou's avatar
Evan Prodromou committed
48
    public $smsemail;                        // varchar(255)  
49
    public $uri;                             // varchar(255)  unique_key
50
    public $autosubscribe;                   // tinyint(1)  
Evan Prodromou's avatar
Evan Prodromou committed
51 52 53 54 55 56 57 58
    public $created;                         // datetime()   not_null
    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP

    /* Static get */
    function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('User',$k,$v); }

    /* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE
Evan Prodromou's avatar
Evan Prodromou committed
59

Evan Prodromou's avatar
Evan Prodromou committed
60
	function getProfile() {
61 62 63 64 65 66 67
		$profile = DB_DataObject::factory('profile');
		$profile->id = $this->id;
		if ($profile->find()) {
			$profile->fetch();
			return $profile;
		}
		return NULL;
Evan Prodromou's avatar
Evan Prodromou committed
68
	}
Evan Prodromou's avatar
Evan Prodromou committed
69

Evan Prodromou's avatar
Evan Prodromou committed
70 71 72 73 74 75 76
	function isSubscribed($other) {
		assert(!is_null($other));
		$sub = DB_DataObject::factory('subscription');
		$sub->subscriber = $this->id;
		$sub->subscribed = $other->id;
		return $sub->find();
	}
77 78

	# 'update' won't write key columns, so we have to do it ourselves.
79

80 81
	function updateKeys(&$orig) {
		$parts = array();
Evan Prodromou's avatar
Evan Prodromou committed
82
		foreach (array('nickname', 'email', 'jabber', 'sms', 'carrier') as $k) {
Evan Prodromou's avatar
Evan Prodromou committed
83
			if (strcmp($this->$k, $orig->$k) != 0) {
84
				$parts[] = $k . ' = ' . $this->_quote($this->$k);
85 86 87 88
			}
		}
		if (count($parts) == 0) {
			# No changes
89
			return true;
90 91
		}
		$toupdate = implode(', ', $parts);
92
		$qry = 'UPDATE ' . $this->tableName() . ' SET ' . $toupdate .
93 94 95
		  ' WHERE id = ' . $this->id;
		return $this->query($qry);
	}
96

97 98 99
	function allowed_nickname($nickname) {
		# XXX: should already be validated for size, content, etc.
		static $blacklist = array('rss', 'xrds', 'doc', 'main',
Evan Prodromou's avatar
Evan Prodromou committed
100
								  'settings', 'notice', 'user',
101
								  'search', 'avatar');
102 103 104
		$merged = array_merge($blacklist, common_config('nickname', 'blacklist'));
		return !in_array($nickname, $merged);
	}
105

106 107
	function getCurrentNotice($dt=NULL) {
		$profile = $this->getProfile();
Evan Prodromou's avatar
Evan Prodromou committed
108 109 110
		if (!$profile) {
			return NULL;
		}
111 112
		return $profile->getCurrentNotice($dt);
	}
Evan Prodromou's avatar
Evan Prodromou committed
113 114 115 116
	
	function getCarrier() {
		return Sms_carrier::staticGet($this->carrier);
	}
Evan Prodromou's avatar
Evan Prodromou committed
117 118 119 120 121 122 123 124 125 126 127 128
	
	function subscribeTo($other) {
		$sub = new Subscription();
		$sub->subscriber = $this->id;
		$sub->subscribed = $other->id;

		$sub->created = DB_DataObject_Cast::dateTime(); # current time

		if (!$sub->insert()) {
			return false;
		}
		
Evan Prodromou's avatar
Evan Prodromou committed
129
		return true;
Evan Prodromou's avatar
Evan Prodromou committed
130
	}
Evan Prodromou's avatar
Evan Prodromou committed
131
}