6 public $sitename = 'Special Ops';
9 public $errors = array();
10 public $nav = array();
16 function __construct()
18 set_error_handler(array($this, 'error_handler'));
20 if ( strpos($_SERVER['PHP_SELF'], 'index') === false )
21 $this->nav
['Board List'] = '.';
26 switch ( $GLOBALS['user']->theme
) {
28 $css = 'default.css'; break;
30 $css = 'u'.$GLOBALS['user']->userid
.'.css'; break;
32 list($css) = $GLOBALS['DB']->query('SELECT `css_file` FROM `themes`
33 WHERE `themeid` = '.$GLOBALS['user']->theme
)->fetch_row();
36 if ( defined('DEVELOPER') && isset($_GET['viewsrc']) )
37 header('Content-Type: text/plain; charset=UTF-8');
39 header('Content-Type: application/xhtml+xml; charset=UTF-8');
41 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',"\n",
42 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">',"\n",
44 ' <title>',$this->title
,' :: ',$this->sitename
,"</title>\n",
45 ' <link rel="stylesheet" type="text/css" href="css/',$css,'"/>',"\n",
48 '<h1>',$this->title
,"</h1>\n";
50 if ( isset($_POST['logout']) && $GLOBALS['user'] instanceof anonuser
)
51 echo '<p class="notice">You are now logged out.</p>',"\n";
52 elseif ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
53 if ( $GLOBALS['user'] instanceof authuser
) {
54 $GLOBALS['DB']->query('UPDATE `users`
55 SET `last_login_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
56 WHERE `userid` = @userid');
57 echo '<p class="notice">You are now logged in.</p>',"\n";
59 echo '<p class="error">Username and/or password is invalid.</p>',"\n";
62 if ( $GLOBALS['user'] instanceof authuser
&& $GLOBALS['user']->password
=== null )
63 echo '<p class="notice">Your password has been reset by an admin. You should set a new one.</p>';
66 echo '<ul id="navbar" class="nl">',"\n";
67 foreach ( $this->nav
as $title => $url )
68 echo "\t",'<li><a href="',$url,'">',$title,"</a></li>\n";
72 $this->headers |
= self
::Pageheader
;
75 function footer($text = null)
81 function errorfooter($type = 'login', $var = null, $var2 = null)
83 if ( !headers_sent() )
87 header('HTTP/1.1 403 Forbidden'); break;
89 header('HTTP/1.1 400 Bad Request');
92 if ( ! ($this->headers
& self
::Pageheader
) )
94 if ( ! ($this->headers
& self
::Userheader
) )
95 $GLOBALS['user']->userheader();
97 'level' => 'You must be at least level '.$var.' to view this page.',
98 'levelpoints' => 'You must be at least level '.$var.' and have '.$var2.' points to view this page.',
99 'login' => 'You must be logged in to view this page.',
100 'logout' => 'You must be logged out to view this page.',
101 'boardid' => 'Invalid board ID given.',
102 'topicid' => 'Invalid topic ID given.',
103 'messageid' => 'Invalid message ID given.',
104 'userid' => 'Invalid user ID given.'
106 echo '<p class="error">',$messages[$type],'</p>';
110 function pagefooter()
113 '<form id="footer" action="',
114 $_SERVER['PHP_SELF'],'?',htmlspecialchars($_SERVER['QUERY_STRING']),'" method="post">',"\n",
115 ' <fieldset><legend>Session:</legend>',"\n";
117 if ( $GLOBALS['user'] instanceof authuser
)
118 echo ' <button type="submit" name="logout" value="yes" onclick="return confirm(\'o rly?\');">Log Out</button>';
121 ' <label>Username: <input type="text" name="u"/></label>',"\n",
122 ' <label>Password: <input type="password" name="p"/></label>',"\n",
123 ' <button type="submit" name="login" value="yes">Log In</button>';
125 echo "\n</fieldset>\n";
127 if ( defined('DEVELOPER') && count($this->errors
) ) {
128 echo "<h2>Errors on page:</h2>\n<dl>\n";
130 foreach ( $this->errors
as $e )
131 printf('<dt>%s:%s</dt><dd>%s:%s</dd>',
142 '<p>© 2004-2005 Ant P | ',round(microtime(1) - CLOCK
, 4),'s | ',
143 ( defined('DEVELOPER') ?
144 sprintf('%d queries | %d $user::gets | %d $user::sets',
146 $GLOBALS['user']->gets
,
147 $GLOBALS['user']->sets
) :
148 count($this->errors
).' errors'
149 ),' | <a href="http://specialops.ath.cx/repos/so2/">',SO2VER
,"</a></p>\n</form>\n",
155 function error_handler($number, $string, $file, $line)
157 // If errors are being returned plaintext with all the <>&s then fix them
158 if ( ! ini_get('html_errors') ) {
159 $string = new message($string);
160 $string = $string->output
;
162 $this->errors
[] = array($number, $string, $file, $line);