From f444256feefcd80f0a2eedbbdee538bd491a2959 Mon Sep 17 00:00:00 2001 From: Anthony Parsons Date: Sat, 10 Dec 2005 00:10:32 +0000 Subject: [PATCH] [00:08:21] <~tyrannosaurus> should I just make everything on the boards use simplexml [00:08:50] <%tanook1rby7> sure [00:09:01] <~tyrannosaurus> *stab* YOU FIAL --- README.xml | 5 +++-- con.php | 10 +++++----- detail.php | 11 ++++++++++- index.php | 2 -- lib/class.message.php | 12 ++++++------ lib/class.page.php | 32 ++++++++++++++++---------------- post.php | 4 ++-- res/mysql.example | 1 + 8 files changed, 43 insertions(+), 34 deletions(-) diff --git a/README.xml b/README.xml index 38f43d2..8eb7768 100644 --- a/README.xml +++ b/README.xml @@ -16,7 +16,7 @@

Intro

This project is based on mBoard, a GameFAQs spinoff I started writing one day to try out SQLite. - I had it working in 7 hours and left it at that. Over time it gained users in the

+ I had it working in 7 hours and left it at that. Over time it gained users in the

The code in mBoard as well as SO1.x was a pile of cack, so I threw it all out and rewrote it from scratch.

With this being my third attempt at writing a message board, the design is a lot better thought-out.

@@ -26,7 +26,8 @@

Requirements

-

You need PHP 5 and MySQL 5. And the PHP extensions mysqli and SPL. And an operating system that isn't criminally brain-damaged.

+

You need PHP 5 and MySQL 5. And the PHP extensions mysqli and SPL. + And an operating system that isn't criminally brain-damaged.

Installation

diff --git a/con.php b/con.php index 1b402f6..3e1c3d8 100644 --- a/con.php +++ b/con.php @@ -83,7 +83,7 @@ if ( defined('DEVELOPER') ) { /* Using the output buffer lets us switch off XHTML mode later if something buggers up. Fixing PHP errors is a lot less stressful when they're not hidden behind XML ones. */ ob_start(); - + function e_handler($exception) { header('HTTP/1.1 500 Internal Server Error'); @@ -138,27 +138,27 @@ if ( isset($_POST['logout']) ) { $user = new anonuser; } elseif ( isset($_COOKIE['u'], $_COOKIE['p']) ) { - + /* Try to get the user ID from the DB. Also tells the DB to remember your user ID, saves fucking around with PHP globals all the time. */ $q = $DB->query('SELECT @userid := `userid` FROM `users` WHERE `alias` = '.$DB->string($_COOKIE['u']).' AND (`password` = AES_ENCRYPT('.$DB->string($_COOKIE['p']).', `reg_ip`) OR `password` IS NULL)'); - + // If there's a matching row in the DB then they're authenticated if ( 1 === $q->num_rows ) { // Keep people logged in for 24 hours after their last page view setcookie('u', $_COOKIE['u'], time()+86400, '/'); setcookie('p', $_COOKIE['p'], time()+86400, '/'); - + $user = new authuser(isset($prefetch) ? $prefetch : null); } else { /* This block of code gets executed if they fail a login attempt. The relevant insults are in lib/class.page.php */ setcookie('u', null, 1, '/'); setcookie('p', null, 1, '/'); - + $user = new anonuser; } } else diff --git a/detail.php b/detail.php index 3aa6ff1..fb35a97 100644 --- a/detail.php +++ b/detail.php @@ -6,6 +6,7 @@ require 'con.php'; $page->title = 'Message Detail'; +/* Error checks */ if ( ! ($user instanceof authuser) ) $page->errorfooter('login'); @@ -15,13 +16,17 @@ if ( !count($args) || !is_numeric($args[0]) ) if ( count($args) === 2 && !in_array($args[1], array('add', 'sub')) ) $page->errorfooter('request'); + +/* Get topic metadata */ $topic = $DB->query('SELECT `board_name`, `boards`.`boardid`, `topic_title`, `restrict`, `topicid` FROM `boards` NATURAL LEFT JOIN `topics` WHERE `topicid` = (SELECT `topicid` FROM `messages` WHERE `messageid` = '.intval($args[0]).')'); -if ( $topic->num_rows === 0 ) + +/* more error checks plz */ +if ( 0 === $topic->num_rows ) $page->errorfooter('messageid'); else $topic = $topic->fetch_assoc(); @@ -29,10 +34,14 @@ else if ( $topic['restrict'] >= 3 && !defined('DEVELOPER') ) $page->errorfooter('level', $topic['restrict']); + +/* Set header stuff */ $page->title .= ': '.$topic['topic_title'].' (msg#'.$args[0].')'; $page->nav['Topic List: '.$topic['board_name']] = 'topiclist?'.$topic['boardid']; $page->nav['Message List: '.$topic['topic_title']] = 'messagelist?'.$topic['topicid']; + +/* Message data */ $that = $DB->query('SELECT `messages`.`userid`, `alias`, `mtime`, `mtext`, `replyto`, `score`, `messages`.`messageid`, INET_NTOA(`origin_ip`) AS `ip` FROM `message-data` diff --git a/index.php b/index.php index 3c68176..7f1caab 100644 --- a/index.php +++ b/index.php @@ -4,8 +4,6 @@ $prefetch = array('`boardlist_layout`'); require 'con.php'; -$page->title = 'Board List'; - $user->userheader(); switch ( $user->boardlist_layout ) { diff --git a/lib/class.message.php b/lib/class.message.php index a5e3baf..4fd072f 100644 --- a/lib/class.message.php +++ b/lib/class.message.php @@ -32,12 +32,12 @@ class message const M_HTML_NONE = 1; const M_HTML_FILTERED = 2; const M_NO_NEWLINES = 4; - + const M_URL_DISPLAY_LENGTH = 60; - + private $temp_text; public $output = null; - + public static $allowed_html = array( /* These are the order the HTML 5 spec defines them. Yes I know HTML 5 is still a draft. Stop fucking whining. */ @@ -48,7 +48,7 @@ class message 'em', 'strong', 'small', 'abbr', 'dfn', 'code', 'var', 'samp', 'kbd', 'sup', 'sub', 'q', 'cite', 'ins', 'del' ); - + function __construct($input, $formatting = null) { if ( is_null($formatting) ) @@ -101,7 +101,7 @@ class message $this->output = str_replace("\r\n", "\n", $temp); $this->xml_validate(); } - + private static function makeurl($uri, $formatting) { if ( $formatting & self::M_HTML_FILTERED ) @@ -111,7 +111,7 @@ class message htmlentities(substr($uri, 0, self::M_URL_DISPLAY_LENGTH)).'[...]' : $uri ). ''; } - + private function xml_validate() { // Check for malformed XML, doesn't really do much else diff --git a/lib/class.page.php b/lib/class.page.php index e9a37d4..1d29bc9 100644 --- a/lib/class.page.php +++ b/lib/class.page.php @@ -8,11 +8,11 @@ class page public $lang; public $errors = array(); public $nav = array(); - + const Pageheader = 1; const Userheader = 2; public $headers = 0; - + function __construct() { set_error_handler(array($this, 'error_handler')); @@ -20,19 +20,19 @@ class page if ( strpos($_SERVER['PHP_SELF'], 'index') === false ) $this->nav['Board List'] = '.'; } - + function pageheader() { global $user, $DB; switch ( $user->theme ) { case -1: - $css = 'default.css'; break; + $css = array('default.css', 'Default Theme'); break; case 0: - $css = 'u'.$user->userid.'.css'; break; + $css = array('u'.$user->userid.'.css', 'User Theme'); break; default: - list($css) = $DB->query('SELECT `css_file` FROM `themes` - WHERE `themeid` = '.$user->theme)->fetch_row(); + $css = $DB->query('SELECT `css_file`, `theme_name` FROM `themes` + WHERE `themeid` = '.$user->theme)->fetch_row(); } header('Content-Type: application/xhtml+xml; charset=UTF-8'); @@ -40,11 +40,11 @@ class page echo '',"\n", '',"\n", "\n", - ' ',$this->title,' :: ',$this->sitename,"\n", - ' ',"\n", + ' ',( $this->title ? $this->title.' :: '.SITE_NAME : SITE_NAME ),"\n", + ' ',"\n", "\n\n", "\n", - '

',$this->title,"

\n"; + '

',( $this->title ? $this->title : SITE_NAME ),"

\n"; if ( isset($_POST['logout']) && $user instanceof anonuser ) echo '

You are now logged out.

',"\n"; @@ -71,7 +71,7 @@ class page $this->headers |= self::Pageheader; } - + private function finish_headers() { if ( ! ($this->headers & self::Pageheader) ) @@ -79,7 +79,7 @@ class page if ( ! ($this->headers & self::Userheader) ) $GLOBALS['user']->userheader(); } - + function errorfooter($type = 'login', $var = null) { if ( !headers_sent() ) @@ -108,11 +108,11 @@ class page echo '

',$messages[$type],'

'; $this->pagefooter(); } - + function pagefooter() { $this->finish_headers(); - + echo "\n\n", '