* Minor TOS change
[specialops2.git] / lib / class.User_Anonymous.php
blob04bc07f9dd8d8d8f952b32efc16a84cbebe662e2
1 <?php
2 /**
3 * Anonymous user class
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
9 * @version $Id$
11 require_once 'iface.User.php';
13 class User_Anonymous implements User
15 /**
16 * Links displayed in div#userheader, in label => url format.
18 public $userlinks = array(
19 '<strong>Register</strong>' => 'register',
20 'Online Users' => 'userlist?online'
23 protected $attrcache;
24 protected $namecache;
26 function __construct()
28 if ( defined('INVITE_ONLY') ) {
29 unset($this->userlinks['<strong>Register</strong>']);
33 function __get($varname)
35 switch ( $varname ) {
36 // implicit typecasting is a hell of a drug.
37 case 'msglist_layout':
38 case 'msglist_style':
39 case 'topiclist_layout':
40 case 'boardlist_layout':
41 case 'points':
42 case 'sig':
43 case 'timezone':
44 return null;
45 case 'theme':
46 return -1;
47 case 'topics_page':
48 case 'msgs_page':
49 return 20;
50 case 'options':
51 return 'cache';
54 throw new OutOfBoundsException('Error in user->__get('.$varname.'): attribute not available.');
57 function __toString()
59 return '[nobody]';
62 /**
63 * Prints the list of user links at the top of each page.
65 public function userheader()
67 global $page;
68 if ( ! ($page->headers & page::Pageheader) ) {
69 $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";
76 echo "</ul>\n";
78 $page->headers |= page::Userheader;
82 /**
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)
90 global $DB;
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);
98 } else
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)
110 $c = array();
111 while ( list($a, $b) = $rows->fetch_row() ) {
112 $this->namecache[$a] = $c[$a] = $b;
115 return $c;
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 )
127 return 'N/A';
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)
143 switch ( $name ) {
144 case 'viewboard':
145 case 'posttopic':
146 return (func_get_arg(1) == 'none');
147 case 'postmessage':
148 return (func_get_arg(1) != 'admin');
149 default:
150 return false;