Cosmetic changes
[specialops2.git] / lib / class.anonuser.php
blob974ac6f4149181ba4c5faebe62f3e5fc48ce0235
1 <?php
2 // $Id$
4 /**
5 * Anonymous user class
7 * This is used to represent a user that's not logged in.
8 */
9 class anonuser
11 public $userlinks = array(
12 'Log In' => '#login_u',
13 'Register' => 'register'
16 protected $attrcache = array(
17 'alias' => '[nobody]',
18 'points' => 0,
19 'theme' => -1,
20 'topics_page' => 15,
21 'msgs_page' => 10,
22 'sig' => ''
25 protected $namecache;
27 function __get($varname)
29 // Assign these three dynamically so they aren't included every page.
30 switch ( $varname ) {
31 case 'msglist_layout':
32 $this->attrcache['msglist_layout'] = messagelist_flat::ID; break;
33 case 'topiclist_layout':
34 $this->attrcache['topiclist_layout'] = topiclist_default::ID; break;
35 case 'boardlist_layout':
36 $this->attrcache['boardlist_layout'] = boardlist_default::ID; break;
38 if ( array_key_exists($varname, $this->attrcache) ) {
39 return $this->attrcache[$varname];
40 } else
41 throw new OutOfBoundsException('Error in user->__get('.$varname.'): attribute not available.');
44 /**
45 * Prints the list of user links at the top of each page.
47 public function userheader()
49 global $page;
50 if ( ! ($page->headers & page::Pageheader) )
51 $page->pageheader();
53 if ( ! ($page->headers & page::Userheader) ) {
54 echo '<ul id="userheader" class="nl">',"\n";
55 foreach ( $this->userlinks as $text => $href )
56 echo ' <li><a href="',$href,'">',$text,"</a></li>\n";
57 echo "</ul>\n";
59 $page->headers |= page::Userheader;
63 /**
64 * Return a username given the corresponding user ID
66 * @param int $id User ID of username to look up
67 * @param string $name Associate the given ID with this name instead of querying the DB
69 public function namelink($id, $name = null)
71 global $DB;
73 if ( empty($this->namecache[$id]) ) {
74 if ( $name === null )
75 list($name) = $DB->query('SELECT `alias` FROM `users` WHERE `userid` = '.$id)->fetch_row();
77 return ($this->namecache[$id] = $name);
78 } else
79 return $this->namecache[$id];
82 /**
83 * Takes a list of usernames and IDs from the DB and returns it as an array.
84 * This also adds the ID:name pairs to the authuser object's namecache, so namelink() can reuse them.
86 * @param mysqli_result $rows A result set of 1 or more rows consisting of user ID and name.
88 public function fillnamecache(mysqli_result $rows)
90 while ( list($a, $b) = $rows->fetch_row() )
91 $this->namecache[$a] = $c[$a] = $b;
92 return $c;
95 /**
96 * Turn a Unix timestamp into a human-readable date.
97 * Outputs UTC time in ISO-8601 format.
99 public function fdate($timestamp)
101 return ( $timestamp == 0 ? 'N/A' : gmdate('Y-m-d H:i:s', $timestamp) );