3 * Class for a registered user, but not the one viewing the page.
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://../COPYING
9 class User_Registered
extends User_Anonymous
11 function __construct($userid, $prefetch = null)
15 $this->attrcache
= array();
17 $fields = array('`userid`', '`alias`', '`timezone`', '`theme`');
19 $fields = array_merge($fields, $prefetch);
22 $this->attrcache
= $DB->query('SELECT '.implode(', ', $fields).' FROM `users` WHERE `userid` = '.$userid)->fetch_assoc();
23 $this->namecache
[$userid] = $this->alias
;
26 function __get($varname)
30 if ( !array_key_exists($varname, $this->attrcache
) ) {
35 $column = "INET_NTOA(`$varname`)"; break;
37 $column = "AES_DECRYPT(`$varname`, `reg_ip`)"; break;
39 list($this->attrcache
['posts']) =
40 $DB->query('SELECT COUNT(*) FROM `messages` WHERE `userid` = '.$this->attrcache
['userid'])->fetch_row();
41 return $this->attrcache
['posts'];
43 list($this->attrcache
['admin']) =
44 $DB->query('SELECT COUNT(*) FROM `things`
45 WHERE `what` = "admin" AND `userid` = '.$this->attrcache
['userid'])->fetch_row();
46 return $this->attrcache
['admin'];
48 $column = "`$varname`";
51 $tmp = $DB->query('SELECT '.$column.' AS `'.$varname.'` FROM `users` WHERE `userid` = '.$this->attrcache
['userid']);
54 throw new OutOfBoundsException('MySQL error in reguser::_get('.$varname.'): '.$DB->error
);
56 list($this->attrcache
[$varname]) = $tmp->fetch_row();
60 if ( array_key_exists($varname, $this->attrcache
) ) {
61 return $this->attrcache
[$varname];
63 throw new OutOfBoundsException('Invalid attribute name '.$varname);
67 function __set($varname, $value)
71 $this->attrcache
[$varname] = $value;
77 if ( strpos($value, ':') !== false ) { // IPv6
81 $value = 'INET_ATON("'.$DB->string($value).'")';
84 $value = 'AES_ENCRYPT("'.$DB->string($value).'", `reg_ip`)';
87 // Only add an invite if the points are going up, sqrt(points) > total given invites and user has < 5 already
88 if ( $value > $this->points
&& sqrt($value) > $this->invites
&&
89 $DB->query('SELECT COUNT(*) AS `c` FROM `things`
90 WHERE `what` = "invite"
91 AND `userid` = '.$this->userid
)->fetch_object()->c
< 5 ) {
92 $DB->query('INSERT INTO `things` VALUES (NULL, '.$this->attrcache
['userid'].', "invite", UUID())');
93 $DB->query('UPDATE `users` SET `invites` = (`invites` + 1) WHERE `userid` = '.$this->attrcache
['userid']);
96 $DB->query('UPDATE `users` SET `points` = '.intval($value).' WHERE `userid` = '.$this->attrcache
['userid']);
99 if ( is_array($value) ) {
100 $value = implode(',', $value);
102 $value = $DB->string($value);
105 if ( is_string($value) ) {
106 $value = $DB->string($value);
110 $DB->query('UPDATE `users` SET `'.$varname.'` = '.$value.' WHERE `userid` = '.$this->userid
);
112 throw new UnexpectedValueException('MySQL error in reguser::_set('.$varname.' = '.$value.'): '.$DB->error
);
116 function __toString()