diff --git a/inc/config.php b/inc/config.php index a8bbde53..819d597a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -21,7 +21,8 @@ 'mod' => Array(), 'spam' => Array(), 'flood_filters' => Array(), - 'wordfilters' => Array() + 'wordfilters' => Array(), + 'custom_capcode' => Array() ); // Database stuff @@ -395,6 +396,29 @@ $config['mod']['link_lock'] = '[Lock]'; $config['mod']['link_unlock'] = '[-Lock]'; + // Moderator capcodes + $config['capcode'] = ' ## %s'; + + // Custom capcodes, by example: + // "## Custom" becomes lightgreen, italic and bold + //$config['custom_capcode']['Custom'] = Array( + // ' ## %s' + //); + + // "## Mod" makes everything purple, including the name and tripcode + //$config['custom_capcode']['Mod'] = Array( + // ' ## %s', + // 'color:purple', // Change name style; optional + // 'color:purple' // Change tripcode style; optional + //); + + // "## Admin" makes everything red and bold, including the name and tripcode + //$config['custom_capcode']['Admin'] = Array( + // ' ## %s', + // 'color:red;font-weight:bold', // Change name style; optional + // 'color:red;font-weight:bold' // Change tripcode style; optional + //); + // Spam filter $config['spam']['hidden_inputs_min'] = 4; $config['spam']['hidden_inputs_max'] = 12; diff --git a/inc/display.php b/inc/display.php index c0d2dde1..f0bbc635 100644 --- a/inc/display.php +++ b/inc/display.php @@ -110,6 +110,18 @@ return '' . utf8tohtml($body) . ''; } + function capcode($cap) { + global $config; + + if(isset($config['custom_capcode'][$cap])) { + if(is_array($config['custom_capcode'][$cap])) + return sprintf($config['custom_capcode'][$cap][0], $cap); + return sprintf($config['custom_capcode'][$cap], $cap); + } + + return sprintf($config['capcode'], $cap); + } + function confirmLink($text, $title, $confirm, $href) { global $config, $mod; if($config['mod']['server-side_confirm']) @@ -119,7 +131,7 @@ } class Post { - public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=null, $mod=false) { + public function __construct($id, $thread, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=null, $mod=false) { global $config; if(!isset($root)) $root = $config['root']; @@ -129,6 +141,7 @@ $this->email = $email; $this->name = utf8tohtml($name); $this->trip = $trip; + $this->capcode = $capcode; $this->body = $body; $this->time = $time; $this->thumb = $thumb; @@ -200,9 +213,19 @@ if(!empty($this->email)) $built .= ''; // Name - $built .= '' . $this->name . '' + $built .= 'capcode) && isset($config['custom_capcode'][$this->capcode][1]) ? + ' style="' . $config['custom_capcode'][$this->capcode][1] . '"' + : '') + . '>' . $this->name . '' // Trip - . (!empty($this->trip) ? ' '.$this->trip.'':''); + . (!empty($this->trip) ? ' capcode) && isset($config['custom_capcode'][$this->capcode][2]) ? + ' style="' . $config['custom_capcode'][$this->capcode][2] . '"' + : '') + . '>'.$this->trip.'':'') + // Capcode + . (!empty($this->capcode) ? capcode($this->capcode) : ''); // End email if(!empty($this->email)) @@ -258,7 +281,7 @@ }; class Thread { - public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $root=null, $mod=false, $hr=true) { + public function __construct($id, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $root=null, $mod=false, $hr=true) { global $config; if(!isset($root)) $root = $config['root']; @@ -267,6 +290,7 @@ $this->email = $email; $this->name = utf8tohtml($name); $this->trip = $trip; + $this->capcode = $capcode; $this->body = $body; $this->time = $time; $this->thumb = $thumb; @@ -375,7 +399,9 @@ // Name $built .= '' . $this->name . '' // Trip - . (!empty($this->trip) ? ' '.$this->trip.'':''); + . (!empty($this->trip) ? ' '.$this->trip.'':'') + // Capcode + . (!empty($this->capcode) ? capcode($this->capcode) : ''); // End email if(!empty($this->email)) diff --git a/inc/functions.php b/inc/functions.php index 9ddbb495..07777b5d 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -317,7 +317,7 @@ function post($post, $OP) { global $pdo, $board; - $query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky, :locked)", $board['uri'])); + $query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky, :locked)", $board['uri'])); // Basic stuff $query->bindValue(':subject', $post['subject']); @@ -341,6 +341,12 @@ $query->bindValue(':locked', 0, PDO::PARAM_INT); } + if($post['mod'] && $post['capcode']) { + $query->bindValue(':capcode', $post['capcode'], PDO::PARAM_INT); + } else { + $query->bindValue(':capcode', NULL, PDO::PARAM_NULL); + } + if($OP) { // No parent thread, image $query->bindValue(':thread', null, PDO::PARAM_NULL); @@ -493,9 +499,9 @@ if($query->rowcount() < 1 && $page > 1) return false; while($th = $query->fetch()) { - $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $mod ? '?/' : $config['root'], $mod); + $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $mod ? '?/' : $config['root'], $mod); - $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); + $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `capcode`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); $posts->bindValue(1, $th['id']); $posts->bindValue(2, ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT); $posts->execute() or error(db_error($posts)); @@ -505,7 +511,7 @@ if($po['file']) $num_images++; - $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : $config['root'], $mod)); + $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : $config['root'], $mod)); } if($posts->rowCount() == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) { @@ -1107,15 +1113,15 @@ global $board, $config; $id = round($id); - $query = prepare(sprintf("SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename`,`ip`,`sticky`,`locked` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri'])); + $query = prepare(sprintf("SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`capcode`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename`,`ip`,`sticky`,`locked` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri'])); $query->bindValue(':id', $id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); while($post = $query->fetch()) { if(!isset($thread)) { - $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $mod ? '?/' : $config['root'], $mod); + $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $mod ? '?/' : $config['root'], $mod); } else { - $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : $config['root'], $mod)); + $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : $config['root'], $mod)); } } diff --git a/install.php b/install.php index fc25999d..d5098499 100644 --- a/install.php +++ b/install.php @@ -1,4 +1,9 @@ -It appears that Tinyboard is already installed! Delete ' . $config['has_installed'] . ' to reinstall.
'; + // Check the version number + $version = file_get_contents($config['has_installed']); + if(empty($version)) { + // v0.9 or v0.9.1 + // Upgrading to v0.9.2 + + sql_open(); + + $boards = listBoards(); + foreach($boards as &$_board) { + openBoard($_board['uri']); + + // Add `capcode` field after `trip` + query(sprintf("ALTER TABLE `posts_%s` ADD `capcode` VARCHAR( 50 ) NULL AFTER `trip`", $board['uri'])) or error(db_error()); + + // Resize `trip` to 15 characters + query(sprintf("ALTER TABLE `posts_%s` CHANGE `trip` `trip` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL", $board['uri'])) or error(db_error()); + } + + file_put_contents($config['has_installed'], VERSION); + + $page['title'] = 'Upgraded'; + $page['body'] = 'Successfully upgraded from v0.9 (or v0.9.1) to ' . VERSION . '.
'; + } elseif($version == VERSION) { + $page['title'] = 'Already installed'; + $page['body'] = 'It appears that Tinyboard is already installed! Delete ' . $config['has_installed'] . ' to reinstall.
'; + } else { + $page['title'] = 'Unknown version'; + $page['body'] = 'Tinyboard was unable to determine what version is currently installed.
'; + } + + + die(Element('page.html', $page)); } @@ -332,7 +368,7 @@ if(!empty($sql_errors)) { $page['body'] .= 'SQL errors were encountered when trying to install the database. This may be the result of using a database which is already occupied with a Tinyboard installation; if so, you can probably ignore this.
The errors encountered were:
I couldn\'t remove install.php. You will have to remove it manually.
Thank you for using Tinyboard. Please remember to report any bugs you discover.
'; - touch($config['has_installed'], 0777); + file_put_contents($config['has_installed'], VERSION); if(!@unlink(__FILE__)) { $page['body'] .= 'I couldn\'t remove install.php. You will have to remove it manually.