5 * This is used to represent a user that's not logged in.
7 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
8 * @license file://../COPYING
11 require_once 'iface.User.php';
13 class User_Anonymous
implements User
16 * Links displayed in div#userheader, in label => url format.
18 public $userlinks = array(
19 '<strong>Register</strong>' => 'register',
20 'Online Users' => 'userlist?online'
26 function __construct()
28 if ( defined('INVITE_ONLY') ) {
29 unset($this->userlinks
['<strong>Register</strong>']);
33 function __get($varname)
36 // implicit typecasting is a hell of a drug.
37 case 'msglist_layout':
39 case 'topiclist_layout':
40 case 'boardlist_layout':
54 throw new OutOfBoundsException('Error in user->__get('.$varname.'): attribute not available.');
63 * Prints the list of user links at the top of each page.
65 public function userheader()
68 if ( ! ($page->headers
& page
::Pageheader
) ) {
72 if ( ! ($page->headers
& page
::Userheader
) ) {
73 echo '<ul id="userheader" class="nl">',"\n";
74 foreach ( $this->userlinks
as $text => $href )
75 echo ' <li><a href="',$href,'">',$text,"</a></li>\n";
78 $page->headers |
= page
::Userheader
;
83 * Return a username given the corresponding user ID
85 * @param int $id User ID of username to look up
86 * @param string $name Associate the given ID with this name instead of querying the DB
88 public function namelink($id, $name = null)
92 if ( empty($this->namecache
[$id]) ) {
93 if ( null === $name ) {
94 list($name) = $DB->query('SELECT `alias` FROM `users` WHERE `userid` = '.$id)->fetch_row();
97 return ($this->namecache
[$id] = $name);
99 return $this->namecache
[$id];
103 * Takes a list of usernames and IDs from the DB and returns it as an array.
104 * This also adds the ID:name pairs to the authuser object's namecache, so namelink() can reuse them.
106 * @param mysqli_result $rows A result set of 1 or more rows consisting of user ID and name.
108 public function fillnamecache(mysqli_result
$rows)
111 while ( list($a, $b) = $rows->fetch_row() ) {
112 $this->namecache
[$a] = $c[$a] = $b;
119 * Turn a Unix timestamp into a human-readable date.
120 * Outputs UTC time in ISO-8601 format.
122 * @param int $timestamp Unix timestamp to display
124 public function fdate($timestamp)
126 if ( 0 == $timestamp )
128 if ( time() - 3600 < $timestamp )
129 return '<strong>'.gmdate('Y-m-d H:i:s', $timestamp).'</strong>';
131 return gmdate('Y-m-d H:i:s', $timestamp);
135 * User privilege check, replacement for userlevel system.
136 * The one in authuser makes more use of this.
138 * @param string $name The thing to check for
139 * @return bool True if they have it, false otherwise
141 public function has_priv($name)
146 return (func_get_arg(1) == 'none');
148 return (func_get_arg(1) != 'admin');