Browse Source

large cleanup

pull/40/head
Michael Save 12 years ago
parent
commit
c9423a2c34
  1. 9
      inc/cache.php
  2. 101
      inc/config.php
  3. 12
      inc/database.php
  4. 24
      inc/display.php
  5. 9
      inc/events.php
  6. 9
      inc/filters.php
  7. 159
      inc/functions.php
  8. 9
      inc/image.php
  9. 8
      inc/mod.php
  10. 12
      inc/remote.php
  11. 47
      inc/template.php
  12. 10
      inc/user.php
  13. 8
      install.php
  14. 128
      mod.php
  15. 31
      post.php

9
inc/cache.php

@ -1,5 +1,14 @@
<?php
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
exit;
}
class Cache {
private static $cache;
public static function init() {

101
inc/config.php

@ -19,6 +19,8 @@
*
* More information: http://tinyboard.org/docs/?p=Config
*
* Tinyboard documentation: http://tinyboard.org/docs/
*
*/
@ -100,8 +102,8 @@
$config['cache']['prefix'] = '';
// Memcached servers to use - http://www.php.net/manual/en/memcached.addservers.php
$config['cache']['memcached'] = Array(
Array('localhost', 11211)
$config['cache']['memcached'] = array(
array('localhost', 11211)
);
/*
@ -144,13 +146,13 @@
// DNS blacklists (DNSBL) http://tinyboard.org/docs/?p=Config/DNSBL
// http://www.sectoor.de/tor.php
$config['dnsbl'][] = Array('tor.dnsbl.sectoor.de', 1); // Tor exit servers
$config['dnsbl'][] = array('tor.dnsbl.sectoor.de', 1); // Tor exit servers
// http://www.sorbs.net/using.shtml
// $config['dnsbl'][] = Array('dnsbl.sorbs.net', Array(2, 3, 4, 5, 6, 7, 8, 9));
// $config['dnsbl'][] = array('dnsbl.sorbs.net', array(2, 3, 4, 5, 6, 7, 8, 9));
// http://www.projecthoneypot.org/httpbl.php
// $config['dnsbl'][] = Array('<your access key>.%.dnsbl.httpbl.org', function($ip) {
// $config['dnsbl'][] = array('<your access key>.%.dnsbl.httpbl.org', function($ip) {
// $octets = explode('.', $ip);
//
// // days since last activity
@ -172,7 +174,7 @@
$config['spam']['hidden_inputs_min'] = 4;
$config['spam']['hidden_inputs_max'] = 12;
// These are fields used to confuse the bots. Make sure they aren't actually used by Tinyboard, or it won't work.
$config['spam']['hidden_input_names'] = Array(
$config['spam']['hidden_input_names'] = array(
'user',
'username',
'login',
@ -185,7 +187,7 @@
'message'
);
// Always update this when adding new valid fields to the post form, or EVERYTHING WILL BE DETECTED AS SPAM!
$config['spam']['valid_inputs'] = Array(
$config['spam']['valid_inputs'] = array(
'hash',
'board',
'thread',
@ -208,10 +210,10 @@
// Custom flood filters. Detect flood attacks and reject new posts if there's a positive match.
// See http://tinyboard.org/wiki/index.php?title=Flood_filters for more information.
//$config['flood_filters'][] = Array(
// 'condition' => Array(
//$config['flood_filters'][] = array(
// 'condition' => array(
// // 100 posts in the past 5 minutes (~20 p/m)
// 'posts_in_past_x_minutes' => Array(100, 5)
// 'posts_in_past_x_minutes' => array(100, 5)
// ),
// // Don't allow the user to post
// 'action' => 'reject',
@ -220,10 +222,10 @@
//);
// Another filter
//$config['flood_filters'][] = Array(
// 'condition' => Array(
//$config['flood_filters'][] = array(
// 'condition' => array(
// // 10 new empty threads in the past 2 minutes
// 'threads_with_no_replies_in_past_x_minutes' => Array(10, 2),
// 'threads_with_no_replies_in_past_x_minutes' => array(10, 2),
// // Allow replies, but not new threads (ie. reject topics only).
// 'OP' => true
// ),
@ -300,10 +302,10 @@
// Wordfilters are used to automatically replace certain words/phrases with something else.
// For a normal string replacement:
// $config['wordfilters'][] = Array('cat', 'dog');
// $config['wordfilters'][] = array('cat', 'dog');
// Advanced raplcement (regular expressions):
// $config['wordfilters'][] = Array('/cat/', 'dog', true); // 'true' means it's a regular expression
// $config['wordfilters'][] = array('/cat/', 'dog', true); // 'true' means it's a regular expression
// Always act as if they had typed "noko" in the email field no mattter what
$config['always_noko'] = false;
@ -333,13 +335,13 @@
*/
// "Wiki" markup syntax ($config['wiki_markup'] in pervious versions):
$config['markup'][] = Array("/'''(.+?)'''/", "<strong>\$1</strong>");
$config['markup'][] = Array("/''(.+?)''/", "<em>\$1</em>");
$config['markup'][] = Array("/\*\*(.+?)\*\*/", "<span class=\"spoiler\">\$1</span>");
$config['markup'][] = Array("/^\s*==(.+?)==\s*$/m", "<span class=\"heading\">\$1</span>");
$config['markup'][] = array("/'''(.+?)'''/", "<strong>\$1</strong>");
$config['markup'][] = array("/''(.+?)''/", "<em>\$1</em>");
$config['markup'][] = array("/\*\*(.+?)\*\*/", "<span class=\"spoiler\">\$1</span>");
$config['markup'][] = array("/^\s*==(.+?)==\s*$/m", "<span class=\"heading\">\$1</span>");
// Highlight PHP code wrapped in <code> tags (PHP 5.3.0+)
// $config['markup'][] = Array(
// $config['markup'][] = array(
// '/^&lt;code&gt;(.+)&lt;\/code&gt;/ms',
// function($matches) {
// return highlight_string(html_entity_decode($matches[1]), true);
@ -507,29 +509,29 @@
// $config['uri_stylesheets'] = 'http://static.example.org/stylesheets/';
// The default stylesheet to use
$config['default_stylesheet'] = Array('Yotsuba B', $config['stylesheets']['Yotsuba B']);
$config['default_stylesheet'] = array('Yotsuba B', $config['stylesheets']['Yotsuba B']);
// Boardlinks
// You can group, order and place the boardlist at the top of every page, using the following template.
//$config['boards'] = Array(
// Array('a', 'b'),
// Array('c', 'd', 'e', 'f', 'g'),
// Array('h', 'i', 'j'),
// Array('k', Array('l', 'm')),
// Array('status' => 'http://status.example.org/')
//$config['boards'] = array(
// array('a', 'b'),
// array('c', 'd', 'e', 'f', 'g'),
// array('h', 'i', 'j'),
// array('k', array('l', 'm')),
// array('status' => 'http://status.example.org/')
//);
// Categories
// Required for the Categories theme.
//$config['categories'] = Array(
// 'Group Name' => Array('a', 'b', 'c'),
// 'Another Group' => Array('d')
//$config['categories'] = array(
// 'Group Name' => array('a', 'b', 'c'),
// 'Another Group' => array('d')
//);
// Custom_categories
// Optional for the Categories theme. Array of name => (title, url) groups for categories with non-board links.
//$config['custom_categories'] = Array(
// 'Links' => Array(
// Optional for the Categories theme. array of name => (title, url) groups for categories with non-board links.
//$config['custom_categories'] = array(
// 'Links' => array(
// 'Tinyboard' => 'http://tinyboard.org',
// 'Donate' => 'donate.html'
// )
@ -576,24 +578,24 @@
// Custom embedding (YouTube, vimeo, etc.)
// It's very important that you match the full string (with ^ and $) or things will not work correctly.
$config['embedding'] = Array(
Array(
$config['embedding'] = array(
array(
'/^https?:\/\/(\w+\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-_]{10,11})(&.+)?$/i',
'<object style="float: left;margin: 10px 20px;" width="%%tb_width%%" height="%%tb_height%%"><param name="movie" value="http://www.youtube.com/v/$2?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$2?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" width="%%tb_width%%" height="%%tb_height%%" allowscriptaccess="always" allowfullscreen="true"></embed></object>'
),
Array(
array(
'/^https?:\/\/(\w+\.)?vimeo\.com\/(\d{2,10})(\?.+)?$/i',
'<object style="float: left;margin: 10px 20px;" width="%%tb_width%%" height="%%tb_height%%"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=$2&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=$2&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="%%tb_width%%" height="%%tb_height%%"></embed></object>'
),
Array(
array(
'/^https?:\/\/(\w+\.)?dailymotion\.com\/video\/([a-zA-Z0-9]{2,10})(_.+)?$/i',
'<object style="float: left;margin: 10px 20px;" width="%%tb_width%%" height="%%tb_height%%"><param name="movie" value="http://www.dailymotion.com/swf/video/$2"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><param name="wmode" value="transparent"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/$2" width="%%tb_width%%" height="%%tb_height%%" wmode="transparent" allowfullscreen="true" allowscriptaccess="always"></embed></object>'
),
Array(
array(
'/^https?:\/\/(\w+\.)?metacafe\.com\/watch\/(\d+)\/([a-zA-Z0-9_\-.]+)\/(\?.+)?$/i',
'<div style="float:left;margin:10px 20px;width:%%tb_width%%px;height:%%tb_height%%px"><embed flashVars="playerVars=showStats=no|autoPlay=no" src="http://www.metacafe.com/fplayer/$2/$3.swf" width="%%tb_width%%" height="%%tb_height%%" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_$2" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>'
),
Array(
array(
'/^https?:\/\/video\.google\.com\/videoplay\?docid=(\d+)([&#](.+)?)?$/i',
'<embed src="http://video.google.com/googleplayer.swf?docid=$1&hl=en&fs=true" style="width:%%tb_width%%px;height:%%tb_height%%px;float:left;margin:10px 20px" allowFullScreen="true" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>'
)
@ -767,14 +769,14 @@
//$config['custom_capcode']['Custom'] ='<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(
//$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(
//$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
@ -996,18 +998,18 @@
// If you use Varnish, Squid, or any similar caching reverse-proxy in front of Tinyboard,
// you can configure Tinyboard to PURGE files when they're written to
//$config['purge'] = Array(
// Array('127.0.0.1', 80)
// Array('127.0.0.1', 80, 'example.org')
//$config['purge'] = array(
// array('127.0.0.1', 80)
// array('127.0.0.1', 80, 'example.org')
//);
// Connection timeout, in seconds
$config['purge_timeout'] = 3;
// Remote servers
// http://tinyboard.org/wiki/index.php?title=Multiple_Servers
//$config['remote']['static'] = Array(
//$config['remote']['static'] = array(
// 'host' => 'static.example.org',
// 'auth' => Array(
// 'auth' => array(
// 'method' => 'plain',
// 'username' => 'username',
// 'password' => 'password!123'
@ -1020,10 +1022,3 @@
// INSANE regular expression for IPv6 addresses
$config['ipv6_regex'] = '((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?';
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
?>

12
inc/database.php

@ -1,7 +1,11 @@
<?php
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
@ -21,7 +25,7 @@
$start = microtime(true);
}
$return = call_user_func_array(Array($this->query, $function), $args);
$return = call_user_func_array(array($this->query, $function), $args);
if($config['debug'] && $function == 'execute') {
$time = round((microtime(true) - $start) * 1000, 2) . 'ms';
@ -104,4 +108,4 @@
return $err[2];
}
}
?>

24
inc/display.php

@ -1,14 +1,13 @@
<?php
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
/*
Stuff to help with the display.
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
exit;
}
/*
[email protected]
@ -20,11 +19,6 @@
return round($size, 2).$units[$i];
}
function commaize($n) {
$n = strval($n);
return (intval($n) < 1000) ? $n : commaize(substr($n, 0, -3)) . ',' . substr($n, -3);
}
function doBoardListPart($list, $root) {
global $config;
@ -222,7 +216,8 @@
class Post {
public function __construct($id, $thread, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $embed, $root=null, $mod=false) {
global $config;
if(!isset($root)) $root = &$config['root'];
if(!isset($root))
$root = &$config['root'];
$this->id = $id;
$this->thread = $thread;
@ -311,7 +306,8 @@
class Thread {
public function __construct($id, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $bumplocked, $embed, $root=null, $mod=false, $hr=true) {
global $config;
if(!isset($root)) $root = &$config['root'];
if(!isset($root))
$root = &$config['root'];
$this->id = $id;
$this->subject = utf8tohtml($subject);
@ -442,4 +438,4 @@
return 'thread_' . ($index ? 'index_' : '') . $board['uri'] . '_' . $this->id;
}
};
?>

9
inc/events.php

@ -1,5 +1,14 @@
<?php
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
exit;
}
function event() {
global $events;

9
inc/filters.php

@ -1,5 +1,14 @@
<?php
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
exit;
}
class Filter {
private $condition;

159
inc/functions.php

@ -1,12 +1,22 @@
<?php
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
require 'inc/events.php';
require 'lib/gettext/gettext.inc';
require_once 'inc/display.php';
require_once 'inc/template.php';
require_once 'inc/database.php';
require_once 'inc/events.php';
require_once 'inc/lib/gettext/gettext.inc';
// the user is not currently logged in as a moderator
$mod = false;
register_shutdown_function('fatal_error_handler');
mb_internal_encoding('UTF-8');
@ -22,11 +32,11 @@
if(!isset($_SERVER['REMOTE_ADDR']))
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
$arrays = Array('db', 'cache', 'cookies', 'error', 'dir', 'mod', 'spam', 'flood_filters', 'wordfilters', 'custom_capcode', 'custom_tripcode', 'dnsbl', 'dnsbl_exceptions', 'remote', 'allowed_ext', 'allowed_ext_files', 'file_icons', 'footer', 'stylesheets', 'additional_javascript', 'markup');
$arrays = array('db', 'cache', 'cookies', 'error', 'dir', 'mod', 'spam', 'flood_filters', 'wordfilters', 'custom_capcode', 'custom_tripcode', 'dnsbl', 'dnsbl_exceptions', 'remote', 'allowed_ext', 'allowed_ext_files', 'file_icons', 'footer', 'stylesheets', 'additional_javascript', 'markup');
$config = Array();
$config = array();
foreach($arrays as $key) {
$config[$key] = Array();
$config[$key] = array();
}
require 'inc/config.php';
@ -45,7 +55,7 @@
if($config['debug']) {
if(!isset($debug)) {
$debug = Array('sql' => Array(), 'purge' => Array(), 'cached' => Array());
$debug = array('sql' => array(), 'purge' => array(), 'cached' => array());
$debug['start'] = microtime(true);
}
}
@ -240,7 +250,7 @@
$query->bindValue(':theme', $theme);
$query->execute() or error(db_error($query));
$settings = Array();
$settings = array();
while($s = $query->fetch()) {
$settings[$s['name']] = $s['value'];
}
@ -260,7 +270,7 @@
function setupBoard($array) {
global $board, $config;
$board = Array(
$board = array(
'id' => $array['id'],
'uri' => $array['uri'],
'name' => $array['title'],
@ -404,7 +414,7 @@
if($config['debug']) {
if(!isset($debug['unlink']))
$debug['unlink'] = Array();
$debug['unlink'] = array();
$debug['unlink'][] = $path;
}
@ -530,10 +540,10 @@
// Show banned page and exit
die(
Element('page.html', Array(
Element('page.html', array(
'title' => 'Banned!',
'config' => $config,
'body' => Element('banned.html', Array(
'body' => Element('banned.html', array(
'config' => $config,
'ban' => $ban
)
@ -641,7 +651,7 @@
} else return false;
}
function post($post) {
function post(array $post) {
global $pdo, $board;
$query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky, :locked, 0, :embed)", $board['uri']));
@ -731,7 +741,10 @@
$query->bindValue(':filehash', null, PDO::PARAM_NULL);
}
$query->execute() or error(db_error($query));
if(!$query->execute()) {
undoImage($post);
error(db_error($query));
}
return $pdo->lastInsertId();
}
@ -909,7 +922,8 @@
$query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
if($query->rowcount() < 1 && $page > 1) return false;
if($query->rowcount() < 1 && $page > 1)
return false;
while($th = $query->fetch()) {
if(!$mod && $config['cache']['enabled']) {
if($built = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
@ -918,7 +932,11 @@
}
}
$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'], $th['sage'], $th['embed'], $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'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
);
$posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $board['uri']));
$posts->bindValue(':id', $th['id']);
@ -930,7 +948,11 @@
if($po['file'])
$num_images++;
$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'], $po['embed'], $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'], $po['embed'], $mod ? '?/' : $config['root'], $mod)
);
}
if($posts->rowCount() == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
@ -950,7 +972,7 @@
$body .= $thread->build(true);
}
return Array(
return array(
'board'=>$board,
'body'=>$body,
'post_url' => $config['post_url'],
@ -962,7 +984,7 @@
function getPageButtons($pages, $mod=false) {
global $config, $board;
$btn = Array();
$btn = array();
$root = ($mod ? '?/' : $config['root']) . $board['dir'];
foreach($pages as $num => $page) {
@ -1017,9 +1039,9 @@
if($count < 1) $count = 1;
$pages = Array();
$pages = array();
for($x=0;$x<$count && $x<$config['max_pages'];$x++) {
$pages[] = Array(
$pages[] = array(
'num' => $x+1,
'link' => $x==0 ? ($mod ? '?/' : $config['root']) . $board['dir'] . $config['file_index'] : ($mod ? '?/' : $config['root']) . $board['dir'] . sprintf($config['file_page'], $x+1)
);
@ -1138,7 +1160,7 @@
}
}
function createHiddenInputs($extra_salt = Array()) {
function createHiddenInputs($extra_salt = array()) {
global $config;
if(!empty($extra_salt)) {
@ -1148,7 +1170,7 @@
$extra_salt = '';
}
$inputs = Array();
$inputs = array();
shuffle($config['spam']['hidden_input_names']);
$hidden_input_names_x = 0;
@ -1184,37 +1206,48 @@
switch($display_type) {
case 0:
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />';
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($value) . '" />';
break;
case 1:
$content .= '<input style="display:none" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />';
$content .= '<input style="display:none" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($value) . '" />';
break;
case 2:
$content .= '<input type="hidden" value="' . htmlspecialchars($value) . '" name="' . htmlspecialchars($name) . '" />';
$content .= '<input type="hidden" value="' . htmlspecialchars($value) . '" name="' .
htmlspecialchars($name) . '" />';
break;
case 3:
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />';
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($value) . '" />';
break;
case 4:
$content .= '<span style="display:none"><input type="text" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" /></span>';
$content .= '<span style="display:none"><input type="text" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($value) .'" /></span>';
break;
case 5:
$content .= '<div style="display:none"><input type="text" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" /></div>';
$content .= '<div style="display:none"><input type="text" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($value) . '" /></div>';
break;
case 6:
if(!empty($value))
$content .= '<textarea style="display:none" name="' . htmlspecialchars($name) . '">' . htmlspecialchars($value) . '</textarea>';
$content .= '<textarea style="display:none" name="' . htmlspecialchars($name) . '">' .
htmlspecialchars($value) . '</textarea>';
else
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />';
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($value) . '" />';
break;
case 7:
if(!empty($value))
$content .= '<textarea name="' . htmlspecialchars($name) . '" style="display:none">' . htmlspecialchars($value) . '</textarea>';
$content .= '<textarea name="' . htmlspecialchars($name) . '" style="display:none">' .
htmlspecialchars($value) . '</textarea>';
else
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />';
$content .= '<input type="hidden" name="' . htmlspecialchars($name) . '" value="' .
htmlspecialchars($value) . '" />';
break;
case 8:
$content .= '<div style="display:none"><textarea name="' . htmlspecialchars($name) . '" style="display:none">' . htmlspecialchars($value) . '</textarea></div>';
$content .= '<div style="display:none"><textarea name="' . htmlspecialchars($name) . '" style="display:none">' .
htmlspecialchars($value) . '</textarea></div>';
break;
}
}
@ -1244,7 +1277,7 @@
return $content;
}
function checkSpam($extra_salt = Array()) {
function checkSpam($extra_salt = array()) {
global $config;
if(!isset($_POST['hash']))
@ -1260,7 +1293,7 @@
}
// Reconsturct the $inputs array
$inputs = Array();
$inputs = array();
foreach($_POST as $name => $value) {
if(in_array($name, $config['spam']['valid_inputs']))
@ -1319,14 +1352,14 @@
function buildJavascript() {
global $config;
$stylesheets = Array();
$stylesheets = array();
foreach($config['stylesheets'] as $name => $uri) {
$stylesheets[] = Array(
$stylesheets[] = array(
'name' => addslashes($name),
'uri' => addslashes((!empty($uri) ? $config['uri_stylesheets'] : '') . $uri));
}
$script = Element('main.js', Array(
$script = Element('main.js', array(
'config' => $config,
'stylesheets' => $stylesheets
));
@ -1361,7 +1394,7 @@
foreach($config['dnsbl'] as $blacklist) {
if(!is_array($blacklist) == 1)
$blacklist = Array($blacklist);
$blacklist = array($blacklist);
if(($lookup = str_replace('%', $ip, $blacklist[0])) == $blacklist[0])
$lookup = $ip . '.' . $blacklist[0];
@ -1394,8 +1427,7 @@
}
function ReverseIPOctets($ip) {
$ipoc = explode('.', $ip);
return $ipoc[3] . '.' . $ipoc[2] . '.' . $ipoc[1] . '.' . $ipoc[0];
return implode('.', array_reverse(explode('.', $ip)));
}
function wordfilters(&$body) {
@ -1467,7 +1499,7 @@
}
if($config['markup_urls']) {
$markup_urls = Array();
$markup_urls = array();
$body = preg_replace_callback(
'/((?:https?:\/\/|ftp:\/\/|irc:\/\/)[^\s<>()"]+?(?:\([^\s<>()"]*?\)[^\s<>()"]*?)*)((?:\s|<|>|"|\.||\]|!|\?|,|&#44;|&quot;)*(?:[\s<>()"]|$))/',
@ -1491,7 +1523,7 @@
// replace tabs with 8 spaces
$body = str_replace("\t", ' ', $body);
$tracked_cites = Array();
$tracked_cites = array();
// Cites
if(isset($board) && preg_match_all('/(^|\s)&gt;&gt;(\d+?)([\s,.)?]|$)/m', $body, $cites)) {
@ -1513,7 +1545,7 @@
$body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[3][$index], $body);
if($track_cites && $config['track_cites'])
$tracked_cites[] = Array($board['uri'], $post['id']);
$tracked_cites[] = array($board['uri'], $post['id']);
}
}
}
@ -1546,7 +1578,7 @@
$body = str_replace($cites[0][$index], $cites[1][$index] . $replacement . $cites[4][$index], $body);
if($track_cites && $config['track_cites'])
$tracked_cites[] = Array($board['uri'], $post['id']);
$tracked_cites[] = array($board['uri'], $post['id']);
}
} else {
$replacement = '<a href="' .
@ -1573,7 +1605,7 @@
}
function utf8tohtml($utf8) {
return mb_encode_numericentity(htmlspecialchars($utf8, ENT_NOQUOTES, 'UTF-8'), Array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
return mb_encode_numericentity(htmlspecialchars($utf8, ENT_NOQUOTES, 'UTF-8'), array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
function buildThread($id, $return=false, $mod=false) {
@ -1595,16 +1627,25 @@
while($post = $query->fetch()) {
if(!isset($thread)) {
$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'], $post['sage'], $post['embed'], $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'], $post['sage'], $post['embed'], $mod ? '?/' : $config['root'], $mod
);
} else {
$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'], $post['embed'], $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'], $post['embed'], $mod ? '?/' : $config['root'], $mod)
);
}
}
// Check if any posts were found
if(!isset($thread)) error($config['error']['nonexistant']);
if(!isset($thread))
error($config['error']['nonexistant']);
$body = Element('thread.html', Array(
$body = Element('thread.html', array(
'board'=>$board,
'body'=>$thread->build(),
'config' => $config,
@ -1653,7 +1694,7 @@
return $trip;
if(!preg_match('/^([^#]+)?(##|#)(.+)$/', $name, $match))
return Array($name);
return array($name);
$name = $match[1];
$secure = $match[2] == '##';
@ -1679,7 +1720,7 @@
$trip = '!' . substr(crypt($trip, $salt), -10);
}
return Array($name, $trip);
return array($name, $trip);
}
// Highest common factor
@ -1726,14 +1767,15 @@
return false;
}
function undoImage($post) {
if($post['has_file']) {
if(isset($post['thumb']))
function undoImage(array $post) {
if(!$post['has_file'])
return;
if(isset($post['file']))
file_unlink($post['file']);
if(isset($post['thumb']))
file_unlink($post['thumb']);
}
}
function rDNS($ip_addr) {
global $config;
@ -1783,4 +1825,3 @@
return $ip_addr;
}

9
inc/image.php

@ -1,7 +1,11 @@
<?php
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
@ -485,4 +489,3 @@
return chr($n & 255).chr(($n >> 8) & 255);
}
?>

8
inc/mod.php

@ -1,7 +1,11 @@
<?php
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}

12
inc/remote.php

@ -1,4 +1,14 @@
<?php
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
exit;
}
class Remote {
public function __construct($config) {
foreach($config as $name => $value) {
@ -54,4 +64,4 @@
}
}
};
?>

47
inc/template.php

@ -1,10 +1,19 @@
<?php
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
if(realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
$twig = false;
function load_twig() {
global $twig, $config;
require 'lib/Twig/Autoloader.php';
Twig_Autoloader::register();
@ -14,9 +23,21 @@
Twig_Autoloader::autoload('Twig_Extensions_Extension_Tinyboard');
$loader = new Twig_Loader_Filesystem($config['dir']['template']);
$loader->setPaths($config['dir']['template']);
$twig = new Twig_Environment($loader, Array(
'autoescape' => false,
'cache' => "{$config['dir']['template']}/cache",
'debug' => ($config['debug'] ? true : false),
));
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
$twig->addExtension(new Twig_Extensions_Extension_I18n());
}
function Element($templateFile, array $options) {
global $config, $debug, $loader;
global $config, $debug, $twig;
if(!$twig)
load_twig();
if(function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod']))) {
$options['pm'] = create_pm_header();
@ -26,21 +47,15 @@
if(isset($debug['start'])) {
$debug['time'] = '~' . round((microtime(true) - $debug['start']) * 1000, 2) . 'ms';
unset($debug['start']);
}
$options['body'] .= '<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . str_replace("\n", '<br/>', utf8tohtml(print_r($debug, true))) . '</pre>';
$debug['included'] = get_included_files();
$debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB';
$options['body'] .=
'<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' .
str_replace("\n", '<br/>', utf8tohtml(print_r($debug, true))) .
'</pre>';
}
$loader->setPaths($config['dir']['template']);
$twig = new Twig_Environment($loader, Array(
'autoescape' => false,
'cache' => "{$config['dir']['template']}/cache",
'debug' => ($config['debug'] ? true : false),
));
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
$twig->addExtension(new Twig_Extensions_Extension_I18n());
// Read the template file
if(@file_get_contents("{$config['dir']['template']}/${templateFile}")) {
$body = $twig->render($templateFile, $options);
@ -54,4 +69,4 @@
throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!");
}
}
?>

10
inc/user.php

@ -1,10 +0,0 @@
<?php
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
// 'false' means that the user is not logged in as a moderator
$mod = false;

8
install.php

@ -1,12 +1,10 @@
<?php
// Installation/upgrade file
define('VERSION', 'v0.9.6-dev-1');
require 'inc/functions.php';
require 'inc/display.php';
require 'inc/template.php';
require 'inc/database.php';
require 'inc/user.php';
$step = isset($_GET['step']) ? round($_GET['step']) : 0;
$page = Array(
'config' => $config,
@ -519,4 +517,4 @@
echo Element('page.html', $page);
}
?>

128
mod.php

@ -1,9 +1,10 @@
<?php
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
require 'inc/functions.php';
require 'inc/display.php';
require 'inc/template.php';
require 'inc/database.php';
require 'inc/user.php';
require 'inc/mod.php';
if (get_magic_quotes_gpc()) {
@ -57,7 +58,7 @@
// A sort of "cache"
// Stops calling preg_quote and str_replace when not needed; only does it once
$regex = Array(
$regex = array(
'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')),
'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')),
'img' => preg_quote($config['dir']['img'], '/'),
@ -68,7 +69,7 @@
if(preg_match('/^\/?$/', $query)) {
// Dashboard
$fieldset = Array(
$fieldset = array(
'Boards' => '',
'Noticeboard' => '',
'Administration' => '',
@ -187,7 +188,7 @@
if($code = @file_get_contents('http://tinyboard.org/version.txt', 0, $ctx)) {
eval($code);
if(preg_match('/v(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $m)) {
$current = Array(
$current = array(
'massive' => (int)$m[1],
'major' => (int)$m[2],
'minor' => (int)$m[3]
@ -236,7 +237,7 @@
$body .= '<fieldset><legend>' . _($title) . '</legend><ul>' . $data . '</ul></fieldset>';
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Dashboard'),
'body'=>$body,
@ -257,7 +258,7 @@
'</p>' .
'<p style="text-align:center"><a style="margin:block;font-size:150%;font-weight:bold" href="?/' . utf8tohtml($uri) . '">Confirm</a></p>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Confirm',
'body'=>$body,
@ -274,7 +275,7 @@
$body = '<div class="ban"><h2>git pull</h2>';
$body .= '<p>' . str_replace("\n", '<br/>', shell_exec('git pull')) . '</p>';
$body .= '</div>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config' => $config,
'title' => 'Upgraded',
'body' => $body
@ -332,7 +333,7 @@
$version = preg_replace('/^savetheinternet-Tinyboard-(\w+)\//', '$1', $dir = $zip->getNameIndex(0));
$errors = Array();
$errors = array();
for($i = 1; $i < $zip->numFiles; $i++) {
$filename = str_replace($dir, '', $zip->getNameIndex($i));
@ -357,7 +358,7 @@
unlink($temp);
echo Element('page.html', Array(
echo Element('page.html', array(
'config' => $config,
'title' => 'Error(s) upgrading',
'body' => $body
@ -371,7 +372,7 @@
unlink($temp);
echo Element('page.html', Array(
echo Element('page.html', array(
'config' => $config,
'title' => 'Upgraded',
'body' => '<p style="text-align:center">Upgrading seems to have gone okay. You are now at revision <strong>' . $version . '</strong>.</p>'
@ -381,7 +382,7 @@
$page = isset($match[2]) ? $match[2] : 1;
$boards = Array();
$boards = array();
$_boards = listBoards();
foreach($_boards as &$_b) {
$boards[$_b['id']] = $_b['uri'];
@ -470,7 +471,7 @@
$body .= '</p>';
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Moderation log'),
'body'=>$body,
@ -483,7 +484,7 @@
// Clearsettings
query("TRUNCATE TABLE `theme_settings`") or error(db_error());
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'No theme',
'body'=>'<p style="text-align:center">Successfully uninstalled all themes.</p>' .
@ -496,7 +497,7 @@
rebuildTheme($match[1], 'all');
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Rebuilt',
'body'=>'<p style="text-align:center">Successfully rebuilt the <strong>' . $match[1] . '</strong> theme.</p>' .
@ -511,7 +512,7 @@
$query->bindValue(':theme', $match[1]);
$query->execute() or error(db_error($query));
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Uninstalled',
'body'=>'<p style="text-align:center">Successfully uninstalled the <strong>' . $match[1] . '</strong> theme.</p>' .
@ -585,7 +586,7 @@
// Build themes
rebuildThemes('all');
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>($result ? 'Installed "' . utf8tohtml($theme['name']) . '"' : 'Installation failed!'),
'body'=>$body,
@ -626,7 +627,7 @@
$body .= '<p style="text-align:center"><input name="install" type="submit" value="Install theme" /></p></form>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Installing "' . utf8tohtml($theme['name']) . '"',
'body'=>$body,
@ -636,14 +637,14 @@
}
} else {
$themes_in_use = Array();
$themes_in_use = array();
$query = query("SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
while($theme = $query->fetch()) {
$themes_in_use[$theme['theme']] = true;
}
// Scan directory for themes
$themes = Array();
$themes = array();
while($file = readdir($dir)) {
if($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) {
$themes[] = $file;
@ -702,7 +703,7 @@
if(!empty($themes_in_use))
$body .= '<p style="text-align:center"><a href="?/themes/none">' . _('Uninstall all themes.') . '</a></p>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Manage themes'),
'body'=>$body,
@ -785,7 +786,7 @@
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Noticeboard'),
'body'=>$body,
@ -867,7 +868,7 @@
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('News'),
'body'=>$body,
@ -916,7 +917,7 @@
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('PM Inbox') . ' (' . ($query->rowCount() == 0 ? _('empty') : $unread_pms . ' ' . _('unread')) . ')',
'body'=>$body,
@ -1002,7 +1003,7 @@
'<p style="text-align:center"><a href="?/new_PM/' . $pm['sender'] . '/' . $pm['id'] . '">Reply with quote</a></p>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Private message',
'body'=>$body,
@ -1042,7 +1043,7 @@
modLog('Sent a PM to ' . $to['username']);
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'PM sent',
'body'=>'<p style="text-align:center">Message sent successfully to ' . utf8tohtml($to['username']) . '.</p>',
@ -1084,7 +1085,7 @@
'</form>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'New PM for ' . utf8tohtml($to['username']),
'body'=>$body,
@ -1109,14 +1110,14 @@
$phrase = &$_POST['search'];
$_body = '';
$filters = Array();
$filters = array();
function search_filters($m) {
global $filters;
$name = $m[2];
$value = isset($m[4]) ? $m[4] : $m[3];
if(!in_array($name, Array('id', 'thread', 'subject', 'email', 'name', 'trip', 'capcode', 'filename', 'filehash', 'ip'))) {
if(!in_array($name, array('id', 'thread', 'subject', 'email', 'name', 'trip', 'capcode', 'filename', 'filehash', 'ip'))) {
// unknown filter
return $m[0];
}
@ -1138,7 +1139,7 @@
$phrase = str_replace('*', '%', $phrase);
$like = '';
$match = Array();
$match = array();
// Find exact phrases
if(preg_match_all('/"(.+?)"/', $phrase, $m)) {
@ -1204,7 +1205,7 @@
$body .= '<p style="text-align:center" class="unimportant">(No results.)</p>';
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Search',
'body'=>$body,
@ -1279,7 +1280,7 @@
$body .= '</form>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Manage users'),
'body'=>$body
@ -1307,7 +1308,7 @@
error(sprintf($config['error']['modexists'], $_mod['id']));
}
$boards = Array();
$boards = array();
foreach($_POST as $name => $null) {
if(preg_match('/^board_(.+)$/', $name, $m))
$boards[] = $m[1];
@ -1327,7 +1328,7 @@
$__boards = '<ul style="list-style:none;padding:2px 5px">';
$boards = array_merge(
Array(Array('uri' => '*', 'title' => 'All')
array(array('uri' => '*', 'title' => 'All')
), listBoards());
foreach($boards as &$_board) {
$__boards .= '<li>' .
@ -1365,7 +1366,7 @@
// End form
'</form></fieldset>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'New user',
'body'=>$body
@ -1419,7 +1420,7 @@
if((isset($_POST['username']) && isset($_POST['password'])) || (isset($change_password_only) && isset($_POST['password']))) {
if(!isset($change_password_only)) {
$boards = Array();
$boards = array();
foreach($_POST as $name => $null) {
if(preg_match('/^board_(.+)$/', $name, $m))
$boards[] = $m[1];
@ -1469,7 +1470,7 @@
$__boards = '<ul style="list-style:none;padding:2px 5px">';
$boards = array_merge(
Array(Array('uri' => '*', 'title' => 'All')
array(array('uri' => '*', 'title' => 'All')
), listBoards());
$_mod['boards'] = explode(',', $_mod['boards']);
@ -1526,7 +1527,7 @@
'</fieldset>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Edit user',
'body'=>$body
@ -1605,7 +1606,7 @@
$body .= '<p class="unimportant" style="text-align:center">Showing ' .
($reports == $count['count'] ? 'all ' . $reports . ' reports' : $reports . ' of ' . $count['count'] . ' reports') . '.</p>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Report queue') . ' (' . $count['count'] . ')',
'body'=>$body,
@ -1761,7 +1762,7 @@
'</fieldset>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Manage &ndash; ' . sprintf($config['board_abbreviation'], $board['uri']),
'body'=>$body,
@ -1874,7 +1875,7 @@
'</form>';
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Ban list'),
'body'=>$body,
@ -1892,7 +1893,7 @@
$body = 'An error occured while trying to flush cache.';
}
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Flushed',
'body'=>'<p style="text-align:center">' . $body . '</p>',
@ -1906,7 +1907,7 @@
$body = '<div class="ban"><h2>Rebuilding&hellip;</h2><p>';
$body .= 'Clearing template cache&hellip;<br/>';
$twig = new Twig_Environment($loader, Array(
$twig = new Twig_Environment($loader, array(
'cache' => "{$config['dir']['template']}/cache"
));
$twig->clearCacheFiles();
@ -1945,7 +1946,7 @@
unset($board);
modLog('Rebuilt everything');
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Rebuilt',
'body'=>$body,
@ -1962,8 +1963,8 @@
$body = '<fieldset><legend>' . _('Configuration') . '</legend><form action="" method="post"><table style="width:100%">';
$var_force_string = Array('blotter');
$var_system = Array('version');
$var_force_string = array('blotter');
$var_system = array('version');
if(isset($_POST['save_changes'])) {
$config_append = '';
@ -2009,7 +2010,7 @@
if($config['minify_html'])
$config_append = str_replace("\n", '&#010;', $config_append);
$page = Array();
$page = array();
$page['title'] = 'Cannot write to file!';
$page['config'] = $config;
$page['body'] = '
@ -2049,7 +2050,7 @@
$body .= '</table><div style="text-align:center"><input name="save_changes" type="submit" value="Save changes"></div></form></fieldset>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Configuration'),
'body'=>$body,
@ -2104,7 +2105,7 @@
'<a href="?/config/edit">[Edit using web editor]</a>' : '') .
'<fieldset><legend>' . _('Configuration') . '</legend><table>' . $data . '</table></fieldset>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>_('Configuration'),
'body'=>$body,
@ -2124,7 +2125,7 @@
!isset($_POST['subtitle'])
) error($config['error']['missedafield']);
$b = Array(
$b = array(
'uri' => $_POST['uri'],
'title' => $_POST['title'],
'subtitle' => $_POST['subtitle']
@ -2165,7 +2166,7 @@
openBoard($b['uri']) or error(_("Couldn't open board after creation."));
// Create the posts table
query(Element('posts.sql', Array('board' => $board['uri']))) or error(db_error());
query(Element('posts.sql', array('board' => $board['uri']))) or error(db_error());
if($config['cache']['enabled'])
cache::delete('all_boards');
@ -2182,7 +2183,7 @@
// TODO: Statistics, etc, in the dashboard.
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'New board',
'body'=>$body,
@ -2316,7 +2317,7 @@
'</table>' .
'</form>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config' => $config,
'body' => $body,
'title' => 'Edit Post #' . $postID
@ -2493,7 +2494,7 @@
if($global)
$boards = listBoards();
else
$boards = Array(Array('uri' => $board['uri']));
$boards = array(array('uri' => $board['uri']));
$query = '';
foreach($boards as $_board) {
@ -2508,7 +2509,7 @@
if($query->rowCount() < 1)
error($config['error']['invalidpost']);
$boards = Array();
$boards = array();
while($post = $query->fetch()) {
openBoard($post['board']);
$boards[] = $post['board'];
@ -2714,7 +2715,7 @@
$query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$replies = Array();
$replies = array();
while($post = $query->fetch()) {
$post['mod'] = true;
$post['thread'] = $newID;
@ -2731,7 +2732,7 @@
$replies[] = $post;
}
$newIDs = Array($postID => $newID);
$newIDs = array($postID => $newID);
openBoard($targetBoard);
foreach($replies as &$post) {
@ -2784,7 +2785,7 @@
$query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$post = Array(
$post = array(
'mod' => true,
'subject' => '',
'email' => '',
@ -2861,7 +2862,7 @@
'</table>' .
'</form></fieldset>';
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'Move #' . $postID,
'body'=>$body,
@ -2897,7 +2898,7 @@
$body = form_newBan($post['ip'], null, '?/' . sprintf($config['board_path'], $board['uri']) . $config['file_index'], $post['id'], $boardName, !$delete);
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'New ban',
'body'=>$body,
@ -3112,7 +3113,7 @@
if(hasPermission($config['mod']['ip_banform']))
$body .= form_newBan($ip, null, '?/IP/' . $ip);
echo Element('page.html', Array(
echo Element('page.html', array(
'config'=>$config,
'title'=>'IP: ' . $ip,
'subtitle' => $host,
@ -3126,4 +3127,3 @@
}
}
?>

31
post.php

@ -1,10 +1,10 @@
<?php
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
require 'inc/functions.php';
require 'inc/display.php';
require 'inc/template.php';
require 'inc/database.php';
require 'inc/user.php';
require 'inc/filters.php';
// Fix for magic quotes
if (get_magic_quotes_gpc()) {
@ -27,7 +27,7 @@
if($password == '')
error($config['error']['invalidpassword']);
$delete = Array();
$delete = array();
foreach($_POST as $post => $value) {
if(preg_match('/^delete_(\d+)$/', $post, $m)) {
$delete[] = (int)$m[1];
@ -84,7 +84,7 @@
if(!isset($_POST['board'], $_POST['password'], $_POST['reason']))
error($config['error']['bot']);
$report = Array();
$report = array();
foreach($_POST as $post => $value) {
if(preg_match('/^delete_(\d+)$/', $post, $m)) {
$report[] = (int)$m[1];
@ -150,7 +150,7 @@
if(!isset($_POST['password']))
$_POST['password'] = '';
$post = Array('board' => $_POST['board']);
$post = array('board' => $_POST['board']);
if(isset($_POST['thread'])) {
$post['op'] = false;
@ -192,7 +192,7 @@
}
}
if(checkSpam(Array($board['uri'], isset($post['thread']) && !($config['quick_reply'] && isset($_POST['quick-reply'])) ? $post['thread'] : null)))
if(checkSpam(array($board['uri'], isset($post['thread']) && !($config['quick_reply'] && isset($_POST['quick-reply'])) ? $post['thread'] : null)))
error($config['error']['spam']);
if($config['robot_enable'] && $config['robot_mute']) {
@ -303,9 +303,10 @@
$size = $_FILES['file']['size'];
if($size > $config['max_filesize'])
error(sprintf3($config['error']['filesize'], array(
'sz'=>commaize($size),
'filesz'=>commaize($size),
'maxsz'=>commaize($config['max_filesize']))));
'sz' => number_format($size),
'filesz' => number_format($size),
'maxsz' => number_format($config['max_filesize'])
)));
}
if($mod && $mod['type'] >= MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) {
@ -361,6 +362,8 @@
error($config['error']['flood']);
}
require_once 'inc/filters.php';
do_filters($post);
if($post['has_file']) {
@ -549,7 +552,7 @@
if(isset($_COOKIE[$config['cookies']['js']]))
$js = json_decode($_COOKIE[$config['cookies']['js']]);
else
$js = (object) Array();
$js = (object) array();
// Tell it to delete the cached post for referer
$js->{$_SERVER['HTTP_REFERER']} = true;
// Encode and set cookie
@ -580,4 +583,4 @@
error($config['error']['nopost']);
}
}
?>

Loading…
Cancel
Save