3 * Class to represent the XHTML page, do header+footer and display errors in a XHTML-safe way
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://../COPYING
11 public $sitename = 'Special Ops';
14 public $nav = array();
16 private $errors = array();
22 function __construct()
24 set_error_handler(array($this, 'error_handler'));
26 if ( strpos($_SERVER['PHP_SELF'], 'index') === false ) {
27 $this->nav
['Board List'] = '.';
31 public function pageheader()
35 switch ( $user->theme
) {
37 $css = array('default', 'Default Theme'); break;
39 $css = array('u'.$user->userid
, 'User Theme'); break;
41 $css = $DB->query('SELECT `css_file`, `theme_name` FROM `themes` WHERE `themeid` = '.$user->theme
)->fetch_row();
44 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) && ! ($user instanceof authuser
) ) {
45 header('HTTP/1.1 400 Bad Request');
48 header('Content-Type: application/xhtml+xml; charset=UTF-8');
49 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',"\n",
50 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">',"\n",
52 ' <title>',( $this->title ?
$this->title
.' :: '.SITE_NAME
: SITE_NAME
),"</title>\n",
53 ' <link rel="stylesheet" type="text/css" href="css/',$css[0],'.css" title="',$css[1],'"/>',"\n",
55 '<body id="so2-',basename($_SERVER['SCRIPT_NAME'], '.php'),"\">\n",
56 '<h1>',( $this->title ?
$this->title
: SITE_NAME
),"</h1>\n";
58 if ( isset($_POST['logout']) && $user instanceof anonuser
) {
59 echo '<p class="notice">You are now logged out.</p>',"\n";
60 } elseif ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
61 if ( $user instanceof authuser
) {
62 $DB->query('UPDATE `users` SET `last_login_ip` = INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
63 WHERE `userid` = @userid');
64 echo '<p class="notice">You are now logged in.</p>',"\n";
65 if ( $user instanceof authuser
&& $user->check_nullpass() ) {
66 echo '<p class="notice">Your password has been reset by an admin. You should <a href="passwd">set a new one</a> ASAP.</p>';
69 echo '<p class="error">Invalid password or username.</p>',"\n";
74 echo '<ul id="navbar" class="nl">',"\n";
75 foreach ( $this->nav
as $title => $url ) {
76 echo "\t",'<li><a href="',$url,'">',$title,"</a></li>\n";
81 $this->headers |
= self
::Pageheader
;
84 private function finish_headers()
86 if ( ! ($this->headers
& self
::Pageheader
) ) {
89 if ( ! ($this->headers
& self
::Userheader
) ) {
90 $GLOBALS['user']->userheader();
94 public function errorfooter($type = 'login')
96 if ( !headers_sent() ) {
99 header('HTTP/1.1 403 Forbidden');
102 header('HTTP/1.1 400 Bad Request');
106 $this->finish_headers();
109 'level' => 'You can\'t do this.',
110 'login' => 'You must be logged in to do this.',
111 'logout' => 'You must be logged out to do this.',
112 'boardid' => 'Invalid board ID given.',
113 'topicid' => 'Invalid topic ID given.',
114 'messageid' => 'Invalid message ID given.',
115 'userid' => 'Invalid user ID given.',
116 'runtime' => 'A serious error has occured in the page. If this happens again and you don\'t think it\'s your fault, '.
117 'let the site owner know and they\'ll probably fix it. Unless the site owner is Aquatakat.',
118 'request' => 'Invalid request.'
121 echo '<p class="error">',$messages[$type],'</p>';
125 public function pagefooter()
127 $this->finish_headers();
131 '<form id="footer" action="',
132 $_SERVER['PHP_SELF'],'?',htmlspecialchars($_SERVER['QUERY_STRING']),'" method="post">',"\n",
133 '<fieldset><legend>Session:</legend>',"\n";
135 if ( $GLOBALS['user'] instanceof authuser
) {
137 ' <button type="submit" name="logout" onclick="return confirm(\'o rly?\');">Log Out</button>';
140 ' <label>Username: <input type="text" name="u"/></label>',"\n",
141 ' <label>Password: <input type="password" name="p"/></label>',"\n",
142 ' <button type="submit" name="login">Log In</button>';
145 echo "\n</fieldset>\n";
147 if ( defined('DEVELOPER') && count($this->errors
) ) {
148 echo "<h2>Errors on page:</h2>\n<dl>\n";
149 foreach ( $this->errors
as $e ) {
150 vprintf('<dt>File %s at line <var>%s</var></dt><dd>errcode <var>%s</var>: <tt>%s</tt></dd>', $e);
157 '<p><a href="http://specialops.ath.cx">Special Ops Two</a>: <a href="COPYING" rel="copyright">© 2004-2006</a> Ant P | ',
158 ( defined('DEVELOPER') ?
$GLOBALS['DB']->c
.' queries' : count($this->errors
).' errors' ),
159 sprintf(" |\n%.3F", microtime(1) - CLOCK
),'s | <a href="http://specialops.ath.cx/repos/so2/">',SO2VER
,"</a></p>\n</form>\n",
165 public function error_handler($number, $string, $file, $line)
167 // If errors are being returned as unencoded text then try to fix them before they fuck the XHTML
168 if ( ! ini_get('html_errors') ) {
169 $string = new message($string);
170 $string = $string->output
;
172 $this->errors
[] = array($file, $line, $number, $string);