HTML optimised: usernames are only linked first time they're shown on the page.
[specialops2.git] / lib / class.anonuser.php
blobad86565ee70d31a6336bf1c45305a93c87483c71
1 <?php
2 // $Id$
4 /* Anonymous user */
5 class anonuser
7 // Debug stuff
8 public $gets = 0;
9 public $sets = 0;
11 public $userlinks;
12 protected $attrcache;
13 protected $namecache;
15 function __construct()
17 $this->userlinks = array(
18 'Log In' => '#login_u'
21 $this->attrcache = array(
22 'level' => 0,
23 'points' => 0,
24 'theme' => -1,
25 'msglist_layout' => 0,
26 'topiclist_layout' => 0,
27 'boardlist_layout' => 0,
28 'topics_page' => 10,
29 'msgs_page' => 5
33 function __get($varname)
35 $this->gets++;
36 if ( array_key_exists($varname, $this->attrcache) ) {
37 return $this->attrcache[$varname];
38 } else
39 throw new OutOfBoundsException('Error in user->__get('.$varname.'): attribute not available.');
42 function userheader()
44 if ( ! ($GLOBALS['page']->headers & page::Pageheader) )
45 $GLOBALS['page']->pageheader();
47 if ( ! ($GLOBALS['page']->headers & page::Userheader) ) {
48 echo '<ul id="userheader" class="nl">',"\n";
49 foreach ( $this->userlinks as $text => $href )
50 echo ' <li><a href="',$href,'">',$text,"</a></li>\n";
51 echo "</ul>\n";
53 $GLOBALS['page']->headers |= page::Userheader;
57 function namelink($id, $name = null)
59 if ( empty($this->namecache[$id]) ) {
60 if ( $name === null )
61 list($name) = $GLOBALS['DB']->query('SELECT `alias` FROM `users`
62 WHERE `userid` = '.$id)->fetch_row();
64 return ($this->namecache[$id] = $name);
65 } else
66 return $this->namecache[$id];
69 function fillnamecache(mysqli_result $rows)
71 while ( list($a, $b) = $rows->fetch_row() )
72 $this->namecache[$a] = $c[$a] = $b;
73 return $c;
76 function fdate($timestamp)
78 return ( $timestamp == 0 ? 'N/A' : date('Y-m-d H:i:s', $timestamp) );