Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
Conflicts: inc/config.php inc/functions.php install.php stylesheets/dark_roach.css
This commit is contained in:
@@ -178,11 +178,14 @@ class AntiBot {
|
||||
}
|
||||
|
||||
function _create_antibot($board, $thread) {
|
||||
global $config;
|
||||
global $config, $purged_old_antispam;
|
||||
|
||||
$antibot = new AntiBot(array($board, $thread));
|
||||
|
||||
query('DELETE FROM ``antispam`` WHERE `expires` < UNIX_TIMESTAMP()') or error(db_error());
|
||||
if (!isset($purged_old_antispam)) {
|
||||
$purged_old_antispam = true;
|
||||
query('DELETE FROM ``antispam`` WHERE `expires` < UNIX_TIMESTAMP()') or error(db_error());
|
||||
}
|
||||
|
||||
if ($thread)
|
||||
$query = prepare('UPDATE ``antispam`` SET `expires` = UNIX_TIMESTAMP() + :expires WHERE `board` = :board AND `thread` = :thread AND `expires` IS NULL');
|
||||
|
@@ -77,16 +77,18 @@
|
||||
// Database driver (http://www.php.net/manual/en/pdo.drivers.php)
|
||||
// Only MySQL is supported by Tinyboard at the moment, sorry.
|
||||
$config['db']['type'] = 'mysql';
|
||||
// Hostname or IP address
|
||||
// Hostname, IP address or Unix socket (prefixed with ":")
|
||||
$config['db']['server'] = 'localhost';
|
||||
// Example: Unix socket
|
||||
// $config['db']['server'] = ':/tmp/mysql.sock';
|
||||
// Login
|
||||
$config['db']['user'] = '';
|
||||
$config['db']['password'] = '';
|
||||
// Tinyboard database
|
||||
$config['db']['database'] = '';
|
||||
// Table prefix
|
||||
// Table prefix (optional)
|
||||
$config['db']['prefix'] = '';
|
||||
// Use a persistent connection (experimental)
|
||||
// Use a persistent connection (experimental; benefits unknown)
|
||||
$config['db']['persistent'] = false;
|
||||
// Anything more to add to the DSN string (eg. port=xxx;foo=bar)
|
||||
$config['db']['dsn'] = '';
|
||||
@@ -1350,14 +1352,14 @@
|
||||
* =============
|
||||
*/
|
||||
|
||||
// Whether or not to use the API, disabled by default.
|
||||
// Whether or not to enable the 4chan-compatible API, disabled by default. See
|
||||
// https://github.com/4chan/4chan-API for API specification.
|
||||
$config['api']['enabled'] = false;
|
||||
|
||||
// Extra fields in to be shown in the array that are not 4chan API compatible.
|
||||
// You canget these by taking a look at the schema for posts_ tables. The array should be formatted as $db_name => $translated_name.
|
||||
// For example:
|
||||
|
||||
// $config['api']['extra_fields'] = array('body_nomarkup'=>'com_nomarkup');
|
||||
// Extra fields in to be shown in the array that are not in the 4chan-API. You can get these by taking a
|
||||
// look at the schema for posts_ tables. The array should be formatted as $db_column => $translated_name.
|
||||
// Example: Adding the pre-markup post body to the API as "com_nomarkup".
|
||||
// $config['api']['extra_fields'] = array('body_nomarkup' => 'com_nomarkup');
|
||||
|
||||
/*
|
||||
* ====================
|
||||
|
@@ -43,9 +43,17 @@ class PreparedQueryDebug {
|
||||
|
||||
function sql_open() {
|
||||
global $pdo, $config;
|
||||
if ($pdo) return true;
|
||||
if ($pdo)
|
||||
return true;
|
||||
|
||||
$dsn = $config['db']['type'] . ':host=' . $config['db']['server'] . ';dbname=' . $config['db']['database'];
|
||||
if (isset($config['db']['server'][0]) && $config['db']['server'][0] == ':')
|
||||
$unix_socket = substr($config['db']['server'], 1);
|
||||
else
|
||||
$unix_socket = false;
|
||||
|
||||
$dsn = $config['db']['type'] . ':' .
|
||||
($unix_socket ? 'unix_socket=' . $unix_socket : 'host=' . $config['db']['server']) .
|
||||
';dbname=' . $config['db']['database'];
|
||||
if (!empty($config['db']['dsn']))
|
||||
$dsn .= ';' . $config['db']['dsn'];
|
||||
try {
|
||||
|
@@ -35,6 +35,7 @@ function loadConfig() {
|
||||
|
||||
$arrays = array(
|
||||
'db',
|
||||
'api',
|
||||
'cache',
|
||||
'cookies',
|
||||
'error',
|
||||
@@ -1001,9 +1002,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
||||
if (isset($tmp_board))
|
||||
openBoard($tmp_board);
|
||||
|
||||
$query = prepare("DELETE FROM ``cites`` WHERE (`target_board` = :board AND `target` = :id) OR (`board` = :board AND `post` = :id)");
|
||||
$query = prepare("DELETE FROM ``cites`` WHERE (`target_board` = :board AND `target` = (" . implode(' OR `target` = ', $ids) . ")) OR (`board` = :board AND (`post` = " . implode(' OR `post` = ', $ids) . "))");
|
||||
$query->bindValue(':board', $board['uri']);
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if (isset($rebuild) && $rebuild_after) {
|
||||
@@ -1056,7 +1056,7 @@ function index($page, $mod=false) {
|
||||
return false;
|
||||
|
||||
$threads = array();
|
||||
|
||||
|
||||
while ($th = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
$thread = new Thread($th, $mod ? '?/' : $config['root'], $mod);
|
||||
|
||||
@@ -1097,7 +1097,7 @@ function index($page, $mod=false) {
|
||||
$thread->omitted = $omitted['post_count'] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
|
||||
$thread->omitted_images = $omitted['image_count'] - $num_images;
|
||||
}
|
||||
|
||||
|
||||
$threads[] = $thread;
|
||||
$body .= $thread->build(true);
|
||||
}
|
||||
@@ -1309,7 +1309,8 @@ function buildIndex() {
|
||||
for ($page = 1; $page <= $config['max_pages']; $page++) {
|
||||
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page));
|
||||
|
||||
if ($config['try_smarter'] && isset($build_pages) && count($build_pages) && !in_array($page, $build_pages) && is_file($filename))
|
||||
if ($config['try_smarter'] && isset($build_pages) && count($build_pages)
|
||||
&& !in_array($page, $build_pages) && is_file($filename))
|
||||
continue;
|
||||
$content = index($page);
|
||||
if (!$content)
|
||||
@@ -1326,24 +1327,25 @@ function buildIndex() {
|
||||
$content['antibot'] = $antibot;
|
||||
|
||||
file_write($filename, Element('index.html', $content));
|
||||
|
||||
|
||||
// json api
|
||||
if ($config['api']['enabled']) {
|
||||
$threads = $content['threads'];
|
||||
$json = json_encode($api->translatePage($threads));
|
||||
$jsonFilename = $board['dir'] . ($page-1) . ".json"; // pages should start from 0
|
||||
$jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
|
||||
file_write($jsonFilename, $json);
|
||||
|
||||
$catalog[$page-1] = $threads;
|
||||
$catalog[$page-1] = $threads;
|
||||
}
|
||||
}
|
||||
|
||||
if ($page < $config['max_pages']) {
|
||||
for (;$page<=$config['max_pages'];$page++) {
|
||||
$filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page));
|
||||
file_unlink($filename);
|
||||
|
||||
|
||||
if ($config['api']['enabled']) {
|
||||
$jsonFilename = $board['dir'] . ($page-1) . ".json";
|
||||
$jsonFilename = $board['dir'] . ($page - 1) . '.json';
|
||||
file_unlink($jsonFilename);
|
||||
}
|
||||
}
|
||||
@@ -1352,7 +1354,7 @@ function buildIndex() {
|
||||
// json api catalog
|
||||
if ($config['api']['enabled']) {
|
||||
$json = json_encode($api->translateCatalog($catalog));
|
||||
$jsonFilename = $board['dir'] . "catalog.json";
|
||||
$jsonFilename = $board['dir'] . 'catalog.json';
|
||||
file_write($jsonFilename, $json);
|
||||
}
|
||||
}
|
||||
@@ -1779,7 +1781,7 @@ function buildThread($id, $return = false, $mod = false) {
|
||||
if ($config['api']['enabled']) {
|
||||
$api = new Api();
|
||||
$json = json_encode($api->translateThread($thread));
|
||||
$jsonFilename = $board['dir'] . $config['dir']['res'] . $id . ".json";
|
||||
$jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json';
|
||||
file_write($jsonFilename, $json);
|
||||
}
|
||||
|
||||
@@ -1874,7 +1876,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
||||
}
|
||||
}
|
||||
|
||||
function rrmdir($dir) {
|
||||
function rrmdir($dir) {
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
@@ -2029,7 +2031,7 @@ function DNS($host) {
|
||||
global $config;
|
||||
|
||||
if ($config['cache']['enabled'] && ($ip_addr = cache::get('dns_' . $host))) {
|
||||
return $ip_addr;
|
||||
return $ip_addr != '?' ? $ip_addr : false;
|
||||
}
|
||||
|
||||
if (!$config['dns_system']) {
|
||||
@@ -2045,7 +2047,7 @@ function DNS($host) {
|
||||
}
|
||||
|
||||
if ($config['cache']['enabled'])
|
||||
cache::set('dns_' . $host, $ip_addr, 3600);
|
||||
cache::set('dns_' . $host, $ip_addr !== false ? $ip_addr : '?', 3600);
|
||||
|
||||
return $ip_addr;
|
||||
}
|
||||
|
@@ -314,16 +314,18 @@ class ImageConvert extends ImageBase {
|
||||
$this->destroy();
|
||||
}
|
||||
|
||||
$this->temp = tempnam($config['tmp'], 'imagick');
|
||||
$this->temp = tempnam($config['tmp'], 'convert');
|
||||
|
||||
$config['thumb_keep_animation_frames'] = (int)$config['thumb_keep_animation_frames'];
|
||||
|
||||
if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
|
||||
if ($this->gifsicle) {
|
||||
if (($error = shell_exec("gifsicle -w --unoptimize -O2 --resize {$this->width}x{$this->height} < " .
|
||||
escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" -o " .
|
||||
escapeshellarg($this->temp))) || !file_exists($this->temp))
|
||||
escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" -o " .
|
||||
escapeshellarg($this->temp))) || !file_exists($this->temp)) {
|
||||
$this->destroy();
|
||||
error('Failed to resize image!', null, $error);
|
||||
}
|
||||
} else {
|
||||
if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg'))
|
||||
$convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
|
||||
@@ -338,8 +340,10 @@ class ImageConvert extends ImageBase {
|
||||
escapeshellarg($this->src),
|
||||
$this->width,
|
||||
$this->height,
|
||||
escapeshellarg($this->temp)))) || !file_exists($this->temp))
|
||||
escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
|
||||
$this->destroy();
|
||||
error('Failed to resize image!', null, $error);
|
||||
}
|
||||
if ($size = $this->get_size($this->temp)) {
|
||||
$this->width = $size[0];
|
||||
$this->height = $size[1];
|
||||
@@ -359,8 +363,10 @@ class ImageConvert extends ImageBase {
|
||||
escapeshellarg($this->src . '[0]'),
|
||||
$this->width,
|
||||
$this->height,
|
||||
escapeshellarg($this->temp)))) || !file_exists($this->temp))
|
||||
escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
|
||||
$this->destroy();
|
||||
error('Failed to resize image!', null, $error);
|
||||
}
|
||||
if ($size = $this->get_size($this->temp)) {
|
||||
$this->width = $size[0];
|
||||
$this->height = $size[1];
|
||||
|
@@ -379,7 +379,7 @@ function mod_edit_board($boardName) {
|
||||
$query->bindValue(':uri', $board['uri'], PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$query = prepare("SELECT `board`, `post` FROM ``cites`` WHERE `target_board` = :board");
|
||||
$query = prepare("SELECT `board`, `post` FROM ``cites`` WHERE `target_board` = :board ORDER BY `board`");
|
||||
$query->bindValue(':board', $board['uri']);
|
||||
$query->execute() or error(db_error($query));
|
||||
while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
@@ -391,6 +391,9 @@ function mod_edit_board($boardName) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($tmp_board))
|
||||
$board = $tmp_board;
|
||||
|
||||
$query = prepare('DELETE FROM ``cites`` WHERE `board` = :board OR `target_board` = :board');
|
||||
$query->bindValue(':board', $board['uri']);
|
||||
$query->execute() or error(db_error($query));
|
||||
@@ -1156,7 +1159,7 @@ function mod_move($originBoard, $postID) {
|
||||
if ($post['has_file']) {
|
||||
// copy image
|
||||
$clone($file_src, sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $post['file']);
|
||||
if (!in_array($post['thumb'], array('spoiler', 'deleted')))
|
||||
if (!in_array($post['thumb'], array('spoiler', 'deleted', 'file')))
|
||||
$clone($file_thumb, sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $post['thumb']);
|
||||
}
|
||||
|
||||
@@ -1346,6 +1349,8 @@ function mod_ban_post($board, $delete, $post, $token = false) {
|
||||
modLog("Deleted post #{$post}");
|
||||
// Rebuild board
|
||||
buildIndex();
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
}
|
||||
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
@@ -1409,6 +1414,8 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
|
||||
}
|
||||
|
||||
buildIndex();
|
||||
|
||||
rebuildThemes('post', $board);
|
||||
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']);
|
||||
} else {
|
||||
@@ -1438,7 +1445,8 @@ function mod_delete($board, $post) {
|
||||
modLog("Deleted post #{$post}");
|
||||
// Rebuild board
|
||||
buildIndex();
|
||||
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
// Redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
}
|
||||
@@ -1459,6 +1467,8 @@ function mod_deletefile($board, $post) {
|
||||
|
||||
// Rebuild board
|
||||
buildIndex();
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
|
||||
// Redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
@@ -1497,6 +1507,9 @@ function mod_spoiler_image($board, $post) {
|
||||
|
||||
// Rebuild board
|
||||
buildIndex();
|
||||
|
||||
// Rebuild themes
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
|
||||
// Redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
|
||||
@@ -1547,6 +1560,8 @@ function mod_deletebyip($boardName, $post, $global = false) {
|
||||
|
||||
deletePost($post['id'], false, false);
|
||||
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
|
||||
if ($post['thread'])
|
||||
$threads_to_rebuild[$post['board']][$post['thread']] = true;
|
||||
else
|
||||
|
@@ -26,7 +26,8 @@ function load_twig() {
|
||||
$loader->setPaths($config['dir']['template']);
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'autoescape' => false,
|
||||
'cache' => "{$config['dir']['template']}/cache",
|
||||
'cache' => is_writable('templates') && (!is_dir('templates/cache') || is_writable('templates/cache')) ?
|
||||
"{$config['dir']['template']}/cache" : false,
|
||||
'debug' => $config['debug']
|
||||
));
|
||||
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
|
||||
|
Reference in New Issue
Block a user