Browse Source

New `capcode` field for posts and custom capcodes (run install.php to upgrade tables)

pull/40/head
Savetheinternet 13 years ago
parent
commit
c596d45711
  1. 26
      inc/config.php
  2. 36
      inc/display.php
  3. 20
      inc/functions.php
  4. 46
      install.php
  5. 5
      install.sql
  6. 12
      mod.php
  7. 7
      post.php
  8. 9
      templates/posts.sql

26
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'] = ' <a class="capcode">## %s</a>';
// Custom capcodes, by example:
// "## Custom" becomes lightgreen, italic and bold
//$config['custom_capcode']['Custom'] = Array(
// '<a class="capcode" style="color:lightgreen;font-style:italic;font-weight:bold"> ## %s</a>'
//);
// "## Mod" makes everything purple, including the name and tripcode
//$config['custom_capcode']['Mod'] = Array(
// '<a class="capcode" style="color:purple"> ## %s</a>',
// '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(
// '<a class="capcode" style="color:red;font-weight:bold"> ## %s</a>',
// '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;

36
inc/display.php

@ -110,6 +110,18 @@
return '<em>' . utf8tohtml($body) . '</em>';
}
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 .= '<a class="email" href="mailto:' . $this->email . '">';
// Name
$built .= '<span class="name">' . $this->name . '</span>'
$built .= '<span class="name"' .
(!empty($this->capcode) && isset($config['custom_capcode'][$this->capcode][1]) ?
' style="' . $config['custom_capcode'][$this->capcode][1] . '"'
: '')
. '>' . $this->name . '</span>'
// Trip
. (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'');
. (!empty($this->trip) ? ' <span class="trip"' .
(!empty($this->capcode) && isset($config['custom_capcode'][$this->capcode][2]) ?
' style="' . $config['custom_capcode'][$this->capcode][2] . '"'
: '')
. '>'.$this->trip.'</span>':'')
// 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 .= '<span class="name">' . $this->name . '</span>'
// Trip
. (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'');
. (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'')
// Capcode
. (!empty($this->capcode) ? capcode($this->capcode) : '');
// End email
if(!empty($this->email))

20
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));
}
}

46
install.php

@ -1,4 +1,9 @@
<?php
<?php
// Installation/upgrade file
// Current version: 0.9.2 (or 0.9.1-dev)
define('VERSION', 'v0.9.2-dev');
require 'inc/functions.php';
require 'inc/display.php';
require 'inc/template.php';
@ -12,9 +17,40 @@
);
if(file_exists($config['has_installed'])) {
$page['title'] = 'Pre-installation test';
$page['body'] = '<p style="text-align:center">It appears that Tinyboard is already installed! Delete <strong>' . $config['has_installed'] . '</strong> to reinstall.</p>';
// 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'] = '<p style="text-align:center">Successfully upgraded from v0.9 (or v0.9.1) to <strong>' . VERSION . '</strong>.</p>';
} elseif($version == VERSION) {
$page['title'] = 'Already installed';
$page['body'] = '<p style="text-align:center">It appears that Tinyboard is already installed! Delete <strong>' . $config['has_installed'] . '</strong> to reinstall.</p>';
} else {
$page['title'] = 'Unknown version';
$page['body'] = '<p style="text-align:center">Tinyboard was unable to determine what version is currently installed.</p>';
}
die(Element('page.html', $page));
}
@ -332,7 +368,7 @@
if(!empty($sql_errors)) {
$page['body'] .= '<div class="ban"><h2>SQL errors</h2><p>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.</p><p>The errors encountered were:</p><ul>' . $sql_errors . '</ul><p><a href="?step=5">Ignore errors and complete installation.</a></p></div>';
} else {
touch($config['has_installed'], 0777);
file_put_contents($config['has_installed'], VERSION);
if(!@unlink(__FILE__)) {
$page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>';
}
@ -343,7 +379,7 @@
$page['title'] = 'Installation complete';
$page['body'] = '<p style="text-align:center">Thank you for using Tinyboard. Please remember to report any bugs you discover.</p>';
touch($config['has_installed'], 0777);
file_put_contents($config['has_installed'], VERSION);
if(!@unlink(__FILE__)) {
$page['body'] .= '<div class="ban"><h2>Delete install.php!</h2><p>I couldn\'t remove <strong>install.php</strong>. You will have to remove it manually.</p></div>';
}

5
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`

12
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) . '<hr/>';
}
@ -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) . '<hr/>';
}

7
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'] .= ' <a class="capcode">## ' . $post['mod_tag'] . '</a>';
wordfilters($post['body']);
$post['body_nomarkup'] = $post['body'];

9
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 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
Loading…
Cancel
Save