3 * Class for a registered user, but not the one viewing the page.
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://../COPYING
9 class User_Registered
extends User_Anonymous
13 function __construct($userid)
15 $this->attrcache
= SO2
::$DB->q('SELECT * FROM users WHERE userid = ?', $userid);
16 $this->attrcache
['options'] = explode(',', $this->attrcache
['options']);
17 $this->admin
= ('admin' == $this->attrcache
['level']);
26 return SO2
::$DB->q('SELECT INET_NTOA(?)', $this->attrcache
[$v], SO2_PDO
::QVALUE
);
28 return SO2
::$DB->q('SELECT AES_DECRYPT(?, ?)',
29 array($this->attrcache
[$v], $this->attrcache
['reg_ip']), SO2_PDO
::QVALUE
);
31 return SO2
::$DB->q('SELECT COUNT(*) FROM messages WHERE userid = ?',
32 $this->attrcache
['userid'], SO2_PDO
::QVALUE
);
35 if ( array_key_exists($v, $this->attrcache
) ) {
36 return $this->attrcache
[$v];
39 throw new OutOfBoundsException('Invalid attribute name '.$v);
42 function __set($var, $value)
50 if ( strpos($value, ':') !== false ) { // IPv6
54 $column = 'INET_ATON(?)';
58 $column = 'AES_ENCRYPT(?, reg_ip)';
61 $this->attrcache
['points'] = $value;
64 $invites = SO2
::$DB->q('SELECT COUNT(*) FROM things WHERE what = \'invite\' AND userid = ?',
65 $this->attrcache
['userid'], SO2_PDO
::QVALUE
);
67 if ( floor($tmp) == $tmp
68 && $tmp > $this->attrcache
['invites']
70 SO2
::$DB->q('INSERT INTO things VALUES (NULL, ?, \'invite\', UUID())', $this->attrcache
['userid']);
71 SO2
::$DB->q('UPDATE users SET invites = (invites + 1) WHERE userid = ?', $this->attrcache
['userid']);
75 if ( is_array($value) ) {
76 $this->attrcache
['options'] = $value;
77 $value = implode(',', $value);
81 $this->attrcache
[$var] = $value;
83 SO2
::$DB->q('UPDATE users SET '.$var.' = '.$column.' WHERE userid = ?', array($value, $this->attrcache
['userid']));
88 return $this->attrcache
['alias'];
92 * Check whether the user's password in the DB is Null.
94 public function check_nullpass()
96 return SO2
::$DB->query('SELECT COUNT(*) FROM users WHERE userid = @userid AND passwd IS NULL')->fetchColumn(0);
100 * Access control function
101 * @return mixed Value equivalent to true/false, actual value varies with implementation
103 public function has_access($feature, array $details = array())
108 switch ( $feature ) {
111 if ( $this->points
< 0 ||
'none' == $this->level
) return false;
112 return $this->access_level($details['topic_lvl'], $details['points']);
114 if ( 'none' == $this->level
) return false;
115 return $this->access_level($details['post_lvl'], $details['points']);
117 return $this->access_level($details['view_lvl'], $details['points']);
121 return ($this->attrcache
['points'] >= 10000);
122 case 'moderate': // Return moderator level as integer
123 return ($this->attrcache
['points'] > 0 ?
strlen($this->attrcache
['points']) - 1 : 0);
130 private function access_level($lev, $pts)
136 return ('none' != $this->level
); // True for all but suspended userlevel
138 if ( $this->attrcache
['points'] >= $pts ) return true;
139 // Don't return if false, check userlevel instead
141 return ('vip' == $this->level
);
142 case 'admin': // Admin is handled at start of has_access(), never calls this function
148 public function getopt($name)
150 return in_array($name, $this->attrcache
['options']);