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. 34
      inc/database.php
  4. 74
      inc/display.php
  5. 9
      inc/events.php
  6. 9
      inc/filters.php
  7. 417
      inc/functions.php
  8. 83
      inc/image.php
  9. 62
      inc/mod.php
  10. 16
      inc/remote.php
  11. 53
      inc/template.php
  12. 10
      inc/user.php
  13. 60
      install.php
  14. 148
      mod.php
  15. 51
      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;
}
?>

34
inc/database.php

@ -1,11 +1,15 @@
<?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;
}
}
class PreparedQueryDebug {
class PreparedQueryDebug {
protected $query;
public function __construct($query) {
@ -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';
@ -35,9 +39,9 @@
return $return;
}
}
}
function sql_open() {
function sql_open() {
global $pdo, $config;
if($pdo) return true;
@ -60,9 +64,9 @@
// Print error
error('Database error: ' . $message);
}
}
}
function prepare($query) {
function prepare($query) {
global $pdo, $debug, $config;
sql_open();
@ -70,9 +74,9 @@
if($config['debug'])
return new PreparedQueryDebug($query);
return $pdo->prepare($query);
}
}
function query($query) {
function query($query) {
global $pdo, $debug, $config;
sql_open();
@ -92,9 +96,9 @@
} else {
return $pdo->query($query);
}
}
}
function db_error($PDOStatement=null) {
function db_error($PDOStatement=null) {
global $pdo;
if(isset($PDOStatement)) {
$err = $PDOStatement->errorInfo();
@ -103,5 +107,5 @@
$err = $pdo->errorInfo();
return $err[2];
}
}
?>
}

74
inc/display.php

@ -1,31 +1,25 @@
<?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]
http://www.php.net/manual/en/function.filesize.php#100097
*/
function format_bytes($size) {
*/
function format_bytes($size) {
$units = array(' B', ' KB', ' MB', ' GB', ' TB');
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
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) {
function doBoardListPart($list, $root) {
global $config;
$body = '';
@ -43,9 +37,9 @@
$body = preg_replace('/\/$/', '', $body);
return $body;
}
}
function createBoardlist($mod=false) {
function createBoardlist($mod=false) {
global $config;
if(!isset($config['boards'])) return Array('top'=>'','bottom'=>'');
@ -60,9 +54,9 @@
'top' => '<div class="boardlist">' . $body . '</div>',
'bottom' => '<div class="boardlist bottom">' . $body . '</div>'
);
}
}
function error($message, $priority = true) {
function error($message, $priority = true) {
global $board, $mod, $config;
if($config['syslog'] && $priority !== false) {
@ -87,9 +81,9 @@
$board['dir'] . $config['file_index'] . "\">Go back</a>.</p>" : '') .
'</center>'
)));
}
}
function loginForm($error=false, $username=false, $redirect=false) {
function loginForm($error=false, $username=false, $redirect=false) {
global $config;
die(Element('page.html', Array(
@ -104,9 +98,9 @@
)
)
)));
}
}
function pm_snippet($body, $len=null) {
function pm_snippet($body, $len=null) {
global $config;
if(!isset($len))
@ -128,9 +122,9 @@
// Re-escape the characters.
return '<em>' . utf8tohtml($body) . ($strlen > $len ? '&hellip;' : '') . '</em>';
}
}
function capcode($cap) {
function capcode($cap) {
global $config;
if(!$cap)
@ -152,9 +146,9 @@
}
return $capcode;
}
}
function truncate($body, $url, $max_lines = false, $max_chars = false) {
function truncate($body, $url, $max_lines = false, $max_chars = false) {
global $config;
if($max_lines === false)
@ -209,20 +203,21 @@
}
return $body;
}
}
function confirmLink($text, $title, $confirm, $href) {
function confirmLink($text, $title, $confirm, $href) {
global $config, $mod;
if($config['mod']['server-side_confirm'])
return '<a onclick="if(confirm(\'' . htmlentities(addslashes($confirm)) . '\')) document.location=\'?/' . htmlentities(addslashes($href)) . '\';return false;" title="' . htmlentities($title) . '" href="?/confirm/' . $href . '">' . $text . '</a>';
else
return '<a onclick="return confirm(\'' . htmlentities(addslashes($confirm)) . '\')" title="' . htmlentities($title) . '" href="?/' . $href . '">' . $text . '</a>';
}
}
class Post {
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;
@ -306,12 +301,13 @@
return Element('post_reply.html', Array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index));
}
};
};
class Thread {
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);
@ -441,5 +437,5 @@
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;

417
inc/functions.php

File diff suppressed because it is too large

83
inc/image.php

@ -1,11 +1,15 @@
<?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;
}
}
class Image {
class Image {
public $src, $format, $image, $size;
public function __construct($src, $format = false) {
global $config;
@ -84,9 +88,9 @@
public function destroy() {
$this->image->_destroy();
}
}
}
class ImageGD {
class ImageGD {
public function GD_create() {
$this->image = imagecreatetruecolor($this->width, $this->height);
}
@ -97,9 +101,9 @@
$this->GD_create();
$this->GD_copyresampled();
}
}
}
class ImageBase extends ImageGD {
class ImageBase extends ImageGD {
public $image, $src, $original, $original_width, $original_height, $width, $height;
public function valid() {
return (bool)$this->image;
@ -144,9 +148,9 @@
// use default GD functions
$this->GD_resize();
}
}
}
class ImageImagick extends ImageBase {
class ImageImagick extends ImageBase {
public function init() {
$this->image = new Imagick();
$this->image->setBackgroundColor(new ImagickPixel('transparent'));
@ -207,10 +211,10 @@
$this->image->scaleImage($this->width, $this->height, false);
}
}
}
}
class ImageConvert extends ImageBase {
class ImageConvert extends ImageBase {
public $width, $height, $temp;
public function init() {
@ -264,9 +268,9 @@
if(shell_exec("convert -flatten -filter Point -scale {$this->width}x{$this->height} +antialias -quality {$quality} " . escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))
error('Failed to resize image!');
}
}
}
class ImagePNG extends ImageBase {
class ImagePNG extends ImageBase {
public function from() {
$this->image = @imagecreatefrompng($this->src);
}
@ -281,9 +285,9 @@
imagealphablending($this->image, false);
$this->GD_copyresampled();
}
}
}
class ImageGIF extends ImageBase {
class ImageGIF extends ImageBase {
public function from() {
$this->image = @imagecreatefromgif($this->src);
}
@ -296,38 +300,38 @@
imagesavealpha($this->image, true);
$this->GD_copyresampled();
}
}
}
class ImageJPG extends ImageBase {
class ImageJPG extends ImageBase {
public function from() {
$this->image = @imagecreatefromjpeg($this->src);
}
public function to($src) {
imagejpeg($this->image, $src);
}
}
class ImageJPEG extends ImageJPG {
}
}
class ImageJPEG extends ImageJPG {
}
class ImageBMP extends ImageBase {
class ImageBMP extends ImageBase {
public function from() {
$this->image = @imagecreatefrombmp($this->src);
}
public function to($src) {
imagebmp($this->image, $src);
}
}
}
/*********************************************/
/* Fonction: imagecreatefrombmp */
/* Author: DHKold */
/* Contact: [email protected] */
/* Date: The 15th of June 2005 */
/* Version: 2.0B */
/*********************************************/
/*********************************************/
/* Fonction: imagecreatefrombmp */
/* Author: DHKold */
/* Contact: [email protected] */
/* Date: The 15th of June 2005 */
/* Version: 2.0B */
/*********************************************/
function imagecreatefrombmp($filename) {
function imagecreatefrombmp($filename) {
if (! $f1 = fopen($filename,"rb")) return FALSE;
$FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14));
if ($FILE['file_type'] != 19778) return FALSE;
@ -403,9 +407,9 @@
fclose($f1);
return $res;
}
}
function imagebmp(&$img, $filename='') {
function imagebmp(&$img, $filename='') {
$widthOrig = imagesx($img);
$widthFloor = ((floor($widthOrig/16))*16);
$widthCeil = ((ceil($widthOrig/16))*16);
@ -476,13 +480,12 @@
fwrite($file, $result);
fclose($file);
}
}
// imagebmp helpers
function int_to_dword($n) {
}
// imagebmp helpers
function int_to_dword($n) {
return chr($n & 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255);
}
function int_to_word($n) {
}
function int_to_word($n) {
return chr($n & 255).chr(($n >> 8) & 255);
}
}
?>

62
inc/mod.php

@ -1,12 +1,16 @@
<?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;
}
}
// create a hash/salt pair for validate logins
function mkhash($username, $password, $salt = false) {
// create a hash/salt pair for validate logins
function mkhash($username, $password, $salt = false) {
global $config;
if(!$salt) {
@ -23,9 +27,9 @@
return Array($hash, $salt);
else
return $hash;
}
}
function login($username, $password, $makehash=true) {
function login($username, $password, $makehash=true) {
global $mod;
// SHA1 password
@ -47,9 +51,9 @@
'boards' => explode(',', $user['boards'])
);
} else return false;
}
}
function setCookies() {
function setCookies() {
global $mod, $config;
if(!$mod)
error('setCookies() was called for a non-moderator!');
@ -61,15 +65,15 @@
':' .
$mod['hash'][1], // salt
time() + $config['cookies']['expire'], $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, true);
}
}
function destroyCookies() {
function destroyCookies() {
global $config;
// Delete the cookies
setcookie($config['cookies']['mod'], 'deleted', time() - $config['cookies']['expire'], $config['cookies']['jail']?$config['cookies']['path'] : '/', null, false, true);
}
}
function create_pm_header() {
function create_pm_header() {
global $mod;
$query = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1");
$query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
@ -80,9 +84,9 @@
}
return false;
}
}
function modLog($action, $_board=null) {
function modLog($action, $_board=null) {
global $mod, $board, $config;
$query = prepare("INSERT INTO `modlogs` VALUES (:id, :ip, :board, :time, :text)");
$query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
@ -99,11 +103,11 @@
if($config['syslog'])
_syslog(LOG_INFO, '[mod/' . $mod['username'] . ']: ' . $action);
}
}
// Generates a <ul> element with a list of linked
// boards and their subtitles. (without the <ul> opening and ending tags)
function ulBoards() {
// Generates a <ul> element with a list of linked
// boards and their subtitles. (without the <ul> opening and ending tags)
function ulBoards() {
global $mod, $config;
$body = '';
@ -129,9 +133,9 @@
$body .= '<li style="margin-top:15px;"><a href="?/new"><strong>' . _('Create new board') . '</strong></a></li>';
}
return $body;
}
}
function form_newBan($ip=null, $reason='', $continue=false, $delete=false, $board=false, $allow_public = false) {
function form_newBan($ip=null, $reason='', $continue=false, $delete=false, $board=false, $allow_public = false) {
global $config, $mod;
$boards = listBoards();
@ -205,9 +209,9 @@
'</table>' .
'</form>' .
'</fieldset>';
}
}
function form_newBoard() {
function form_newBoard() {
return '<fieldset><legend>New board</legend>' .
'<form action="?/new" method="post">' .
'<table>' .
@ -233,10 +237,10 @@
'</table>' .
'</form>' .
'</fieldset>';
}
}
function removeBan($id) {
function removeBan($id) {
global $config, $memcached;
$query = prepare("DELETE FROM `bans` WHERE `id` = :id");
@ -248,12 +252,12 @@
// TODO
// $memcached->delete("ban_{$id}");
//}
}
}
// Validate session
// Validate session
if(isset($_COOKIE[$config['cookies']['mod']])) {
if(isset($_COOKIE[$config['cookies']['mod']])) {
// Should be username:hash:salt
$cookie = explode(':', $_COOKIE[$config['cookies']['mod']]);
if(count($cookie) != 3) {
@ -279,5 +283,5 @@
'username' => $cookie[0],
'boards' => explode(',', $user['boards'])
);
}
}

16
inc/remote.php

@ -1,5 +1,15 @@
<?php
class Remote {
/*
* 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) {
$this->{$name} = $value;
@ -53,5 +63,5 @@
error('Unknown send method.');
}
}
};
?>
};

53
inc/template.php

@ -1,9 +1,18 @@
<?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, $twig;
function Element($templateFile, array $options) {
global $config, $debug, $loader;
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);
@ -53,5 +68,5 @@
} else {
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;

60
install.php

@ -1,24 +1,22 @@
<?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(
// Installation/upgrade file
define('VERSION', 'v0.9.6-dev-1');
require 'inc/functions.php';
$step = isset($_GET['step']) ? round($_GET['step']) : 0;
$page = Array(
'config' => $config,
'title' => 'Install',
'body' => '',
'nojavascript' => true
);
);
// this breaks the dispaly of licenses if enabled
$config['minify_html'] = false;
// this breaks the dispaly of licenses if enabled
$config['minify_html'] = false;
if(file_exists($config['has_installed'])) {
if(file_exists($config['has_installed'])) {
// Check the version number
$version = trim(file_get_contents($config['has_installed']));
@ -194,9 +192,9 @@
}
die(Element('page.html', $page));
}
}
if($step == 0) {
if($step == 0) {
// Agreeement
$page['body'] = '
<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" disabled>' . htmlentities(file_get_contents('LICENSE.md')) . '</textarea>
@ -205,7 +203,7 @@
</p>';
echo Element('page.html', $page);
} elseif($step == 1) {
} elseif($step == 1) {
$page['title'] = 'Pre-installation test';
$page['body'] = '<table class="test">';
@ -255,7 +253,7 @@
</p>';
echo Element('page.html', $page);
} elseif($step == 2) {
} elseif($step == 2) {
// Basic config
$page['title'] = 'Configuration';
@ -264,7 +262,7 @@
}
$page['body'] = '
<form action="?step=3" method="post">
<form action="?step=3" method="post">
<fieldset>
<legend>Database</legend>
<label for="db_type">Type:</label>
@ -412,22 +410,22 @@
<p style="text-align:center">
<input type="submit" value="Complete installation" />
</p>
</form>
</form>
';
echo Element('page.html', $page);
} elseif($step == 3) {
} elseif($step == 3) {
$instance_config =
'<?php
/*
* Instance Configuration
* ----------------------
* Edit this file and not config.php for imageboard configuration.
*
* You can copy values from config.php (defaults) and paste them here.
*/
* Instance Configuration
* ----------------------
* Edit this file and not config.php for imageboard configuration.
*
* You can copy values from config.php (defaults) and paste them here.
*/
';
@ -468,7 +466,7 @@
';
echo Element('page.html', $page);
}
} elseif($step == 4) {
} elseif($step == 4) {
// SQL installation
buildJavascript();
@ -508,7 +506,7 @@
}
echo Element('page.html', $page);
} elseif($step == 5) {
} elseif($step == 5) {
$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>';
@ -518,5 +516,5 @@
}
echo Element('page.html', $page);
}
?>
}

148
mod.php

@ -1,24 +1,25 @@
<?php
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()) {
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
require 'inc/functions.php';
require 'inc/mod.php';
if (get_magic_quotes_gpc()) {
function strip_array($var) {
return is_array($var) ? array_map("strip_array", $var) : stripslashes($var);
}
$_GET = strip_array($_GET);
$_POST = strip_array($_POST);
}
}
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
// If not logged in
if(!$mod) {
// If not logged in
if(!$mod) {
if(isset($_POST['login'])) {
// Check if inputs are set and not empty
if( !isset($_POST['username']) ||
@ -48,7 +49,7 @@
} else {
loginForm(false, false, '?' . $query);
}
} else {
} else {
// Redirect (for index pages)
if(count($_GET) == 2 && isset($_GET['status']) && isset($_GET['r'])) {
header('Location: ' . $_GET['r'], true, $_GET['status']);
@ -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,
@ -3124,6 +3125,5 @@
} else {
error($config['error']['404']);
}
}
}
?>

51
post.php

@ -1,22 +1,22 @@
<?php
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()) {
/*
* Copyright (c) 2010-2012 Tinyboard Development Group
*/
require 'inc/functions.php';
// Fix for magic quotes
if (get_magic_quotes_gpc()) {
function strip_array($var) {
return is_array($var) ? array_map("strip_array", $var) : stripslashes($var);
}
$_GET = strip_array($_GET);
$_POST = strip_array($_POST);
}
}
if(isset($_POST['delete'])) {
if(isset($_POST['delete'])) {
// Delete
if(!isset($_POST['board'], $_POST['password']))
@ -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];
@ -80,11 +80,11 @@
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
} elseif(isset($_POST['report'])) {
} elseif(isset($_POST['report'])) {
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];
@ -136,7 +136,7 @@
$root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
} elseif(isset($_POST['post'])) {
} elseif(isset($_POST['post'])) {
if(!isset($_POST['subject'], $_POST['body'], $_POST['board']))
error($config['error']['bot']);
@ -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
@ -572,12 +575,12 @@
rebuildThemes('post');
header('Location: ' . $redirect, true, $config['redirect_http']);
} else {
} else {
if(!file_exists($config['has_installed'])) {
header('Location: install.php', true, $config['redirect_http']);
} else {
// They opened post.php in their browser manually.
error($config['error']['nopost']);
}
}
?>
}

Loading…
Cancel
Save