From c596d457112bb3288c0d650884022f72a9d7f35c Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Tue, 12 Apr 2011 21:08:54 +1000
Subject: [PATCH] New `capcode` field for posts and custom capcodes (run
install.php to upgrade tables)
---
inc/config.php | 26 ++++++++++++++++++++++++-
inc/display.php | 36 ++++++++++++++++++++++++++++++-----
inc/functions.php | 20 +++++++++++++-------
install.php | 46 ++++++++++++++++++++++++++++++++++++++++-----
install.sql | 5 +++--
mod.php | 12 ++++++------
post.php | 7 ++-----
templates/posts.sql | 9 +++++----
8 files changed, 126 insertions(+), 35 deletions(-)
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
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:
Ignore errors and complete installation.
';
} else {
- touch($config['has_installed'], 0777);
+ file_put_contents($config['has_installed'], VERSION);
if(!@unlink(__FILE__)) {
$page['body'] .= 'Delete install.php!
I couldn\'t remove install.php. You will have to remove it manually.
';
}
@@ -343,7 +379,7 @@
$page['title'] = 'Installation complete';
$page['body'] = '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'] .= 'Delete install.php!
I couldn\'t remove install.php. You will have to remove it manually.
';
}
diff --git a/install.sql b/install.sql
index a23b9796..3e85de98 100644
--- a/install.sql
+++ b/install.sql
@@ -185,7 +185,8 @@ CREATE TABLE IF NOT EXISTS `posts_b` (
`subject` varchar(40) NOT NULL,
`email` varchar(30) NOT NULL,
`name` varchar(25) NOT NULL,
- `trip` varchar(100) DEFAULT NULL,
+ `trip` varchar(15) DEFAULT NULL,
+ `capcode` varchar(50) DEFAULT NULL,
`body` text NOT NULL,
`time` int(11) NOT NULL,
`bump` int(11) DEFAULT NULL,
@@ -203,7 +204,7 @@ CREATE TABLE IF NOT EXISTS `posts_b` (
`sticky` int(1) NOT NULL,
`locked` int(1) NOT NULL,
UNIQUE KEY `id` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
--
-- Dumping data for table `posts_b`
diff --git a/mod.php b/mod.php
index b7107fdb..4428f797 100644
--- a/mod.php
+++ b/mod.php
@@ -581,9 +581,9 @@
$temp = '';
while($post = $query->fetch()) {
if(!$post['thread']) {
- $po = 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, false);
+ $po = 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, false);
} else {
- $po = new Post($post['id'], $post['thread'], $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);
+ $po = new Post($post['id'], $post['thread'], $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);
}
$temp .= $po->build(true) . '
';
}
@@ -870,9 +870,9 @@
openBoard($report['uri']);
if(!$post['thread']) {
- $po = 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, false);
+ $po = 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, false);
} else {
- $po = new Post($post['id'], $post['thread'], $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);
+ $po = new Post($post['id'], $post['thread'], $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);
}
$po->body .=
@@ -1664,9 +1664,9 @@
while($post = $query->fetch()) {
if(!$post['thread']) {
- $po = 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, false);
+ $po = 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, false);
} else {
- $po = new Post($post['id'], $post['thread'], $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);
+ $po = new Post($post['id'], $post['thread'], $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);
}
$temp .= $po->build(true) . '
';
}
diff --git a/post.php b/post.php
index 1dd737cc..45c0fdf3 100644
--- a/post.php
+++ b/post.php
@@ -260,11 +260,11 @@
if($mod && $mod['type'] >= MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) {
if(($mod['type'] == MOD && $match[3] == 'Mod') || $mod['type'] >= ADMIN) {
- $post['mod_tag'] = utf8tohtml($match[3]);
+ $post['capcode'] = utf8tohtml($match[3]);
$post['name'] = !empty($match[2])?$match[2]:$config['anonymous'];
}
} else {
- $post['mod_tag'] = false;
+ $post['capcode'] = false;
}
$trip = generate_tripcode($post['name']);
@@ -291,9 +291,6 @@
if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error($config['error']['tooshort_body']);
if(strlen($post['password']) > 20) error(sprintf($config['error']['toolong'], 'password'));
- if($post['mod_tag'])
- $post['trip'] .= ' ## ' . $post['mod_tag'] . '';
-
wordfilters($post['body']);
$post['body_nomarkup'] = $post['body'];
diff --git a/templates/posts.sql b/templates/posts.sql
index b1986aff..d57ee568 100644
--- a/templates/posts.sql
+++ b/templates/posts.sql
@@ -2,9 +2,10 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`thread` int(11) DEFAULT NULL,
`subject` varchar(40) NOT NULL,
- `email` varchar(40) NOT NULL,
- `name` varchar(40) NOT NULL,
- `trip` varchar(100) DEFAULT NULL,
+ `email` varchar(30) NOT NULL,
+ `name` varchar(25) NOT NULL,
+ `trip` varchar(15) DEFAULT NULL,
+ `capcode` varchar(50) DEFAULT NULL,
`body` text NOT NULL,
`time` int(11) NOT NULL,
`bump` int(11) DEFAULT NULL,
@@ -22,4 +23,4 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` (
`sticky` int(1) NOT NULL,
`locked` int(1) NOT NULL,
UNIQUE KEY `id` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
\ No newline at end of file
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
\ No newline at end of file