mirror of
https://github.com/Circlepuller/Tinyboard.git
synced 2025-01-17 13:28:31 +01:00
Code 'optimizations'
This commit is contained in:
parent
3aad999359
commit
1bca57d7fe
@ -50,7 +50,7 @@ class Api {
|
|||||||
'size' => 'fsize',
|
'size' => 'fsize',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) == 'array'){
|
if (isset($config['api']['extra_fields']) && gettype($config['api']['extra_fields']) === 'array'){
|
||||||
$this->postFields = array_merge($this->postFields, $config['api']['extra_fields']);
|
$this->postFields = array_merge($this->postFields, $config['api']['extra_fields']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ class Api {
|
|||||||
if (sizeof($post->files) > 1) {
|
if (sizeof($post->files) > 1) {
|
||||||
$extra_files = array();
|
$extra_files = array();
|
||||||
foreach ($post->files as $i => $f) {
|
foreach ($post->files as $i => $f) {
|
||||||
if ($i == 0) continue;
|
if ($i === 0) continue;
|
||||||
|
|
||||||
$extra_file = array();
|
$extra_file = array();
|
||||||
$this->translateFile($f, $post, $extra_file);
|
$this->translateFile($f, $post, $extra_file);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Copyright (c) 2010-2018 Tinyboard Development Group
|
* Copyright (c) 2010-2018 Tinyboard Development Group
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
|
if (realpath($_SERVER['SCRIPT_FILENAME']) === str_replace('\\', '/', __FILE__)) {
|
||||||
// You cannot request this file directly.
|
// You cannot request this file directly.
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -349,7 +349,7 @@ function basic_error_function_because_the_other_isnt_loaded_yet($message, $prior
|
|||||||
|
|
||||||
function fatal_error_handler() {
|
function fatal_error_handler() {
|
||||||
if ($error = error_get_last()) {
|
if ($error = error_get_last()) {
|
||||||
if ($error['type'] == E_ERROR) {
|
if ($error['type'] === E_ERROR) {
|
||||||
if (function_exists('error')) {
|
if (function_exists('error')) {
|
||||||
error('Caught fatal error: ' . $error['message'] . ' in <strong>' . $error['file'] . '</strong> on line ' . $error['line'], LOG_ERR);
|
error('Caught fatal error: ' . $error['message'] . ' in <strong>' . $error['file'] . '</strong> on line ' . $error['line'], LOG_ERR);
|
||||||
} else {
|
} else {
|
||||||
@ -369,7 +369,7 @@ function _syslog($priority, $message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function verbose_error_handler($errno, $errstr, $errfile, $errline) {
|
function verbose_error_handler($errno, $errstr, $errfile, $errline) {
|
||||||
if (error_reporting() == 0)
|
if (error_reporting() === 0)
|
||||||
return false; // Looks like this warning was suppressed by the @ operator.
|
return false; // Looks like this warning was suppressed by the @ operator.
|
||||||
error(utf8tohtml($errstr), true, array(
|
error(utf8tohtml($errstr), true, array(
|
||||||
'file' => $errfile . ':' . $errline,
|
'file' => $errfile . ':' . $errline,
|
||||||
@ -406,19 +406,17 @@ function rebuildThemes($action, $boardname = false) {
|
|||||||
$_board = $board;
|
$_board = $board;
|
||||||
|
|
||||||
// List themes
|
// List themes
|
||||||
if ($themes = Cache::get("themes")) {
|
if ($themes = Cache::get('themes')) {
|
||||||
// OK, we already have themes loaded
|
// OK, we already have themes loaded
|
||||||
}
|
} else {
|
||||||
else {
|
$query = query('SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL') or error(db_error());
|
||||||
$query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error());
|
|
||||||
|
|
||||||
$themes = array();
|
$themes = array();
|
||||||
|
|
||||||
while ($theme = $query->fetch(PDO::FETCH_ASSOC)) {
|
while ($theme = $query->fetch(PDO::FETCH_ASSOC))
|
||||||
$themes[] = $theme;
|
$themes[] = $theme;
|
||||||
}
|
|
||||||
|
|
||||||
Cache::set("themes", $themes);
|
Cache::set('themes', $themes);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($themes as $theme) {
|
foreach ($themes as $theme) {
|
||||||
@ -432,16 +430,14 @@ function rebuildThemes($action, $boardname = false) {
|
|||||||
init_locale($config['locale']);
|
init_locale($config['locale']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PHP_SAPI === 'cli') {
|
if (PHP_SAPI === 'cli')
|
||||||
echo "Rebuilding theme ".$theme['theme']."... ";
|
echo 'Rebuilding theme ' . $theme['theme'] . '... ';
|
||||||
}
|
|
||||||
|
|
||||||
rebuildTheme($theme['theme'], $action, $boardname);
|
rebuildTheme($theme['theme'], $action, $boardname);
|
||||||
|
|
||||||
if (PHP_SAPI === 'cli') {
|
if (PHP_SAPI === 'cli')
|
||||||
echo "done\n";
|
echo "done\n";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Restore them again
|
// Restore them again
|
||||||
$config = $_config;
|
$config = $_config;
|
||||||
@ -482,11 +478,11 @@ function rebuildTheme($theme, $action, $board = false) {
|
|||||||
|
|
||||||
|
|
||||||
function themeSettings($theme) {
|
function themeSettings($theme) {
|
||||||
if ($settings = Cache::get("theme_settings_".$theme)) {
|
if ($settings = Cache::get('theme_settings_' . $theme)) {
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare("SELECT `name`, `value` FROM ``theme_settings`` WHERE `theme` = :theme AND `name` IS NOT NULL");
|
$query = prepare('SELECT `name`, `value` FROM ``theme_settings`` WHERE `theme` = :theme AND `name` IS NOT NULL');
|
||||||
$query->bindValue(':theme', $theme);
|
$query->bindValue(':theme', $theme);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -495,7 +491,7 @@ function themeSettings($theme) {
|
|||||||
$settings[$s['name']] = $s['value'];
|
$settings[$s['name']] = $s['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::set("theme_settings_".$theme, $settings);
|
Cache::set('theme_settings_' . $theme, $settings);
|
||||||
|
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
@ -532,16 +528,16 @@ function setupBoard($array) {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
if (!file_exists($board['dir']))
|
if (!file_exists($board['dir']))
|
||||||
@mkdir($board['dir'], 0777) or error("Couldn't create " . $board['dir'] . ". Check permissions.", true);
|
@mkdir($board['dir'], 0777) or error('Couldn\'t create ' . $board['dir'] . '. Check permissions.', true);
|
||||||
if (!file_exists($board['dir'] . $config['dir']['img']))
|
if (!file_exists($board['dir'] . $config['dir']['img']))
|
||||||
@mkdir($board['dir'] . $config['dir']['img'], 0777)
|
@mkdir($board['dir'] . $config['dir']['img'], 0777)
|
||||||
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
|
or error('Couldn\'t create ' . $board['dir'] . $config['dir']['img'] . '. Check permissions.', true);
|
||||||
if (!file_exists($board['dir'] . $config['dir']['thumb']))
|
if (!file_exists($board['dir'] . $config['dir']['thumb']))
|
||||||
@mkdir($board['dir'] . $config['dir']['thumb'], 0777)
|
@mkdir($board['dir'] . $config['dir']['thumb'], 0777)
|
||||||
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
|
or error('Couldn\'t create ' . $board['dir'] . $config['dir']['img'] . '. Check permissions.', true);
|
||||||
if (!file_exists($board['dir'] . $config['dir']['res']))
|
if (!file_exists($board['dir'] . $config['dir']['res']))
|
||||||
@mkdir($board['dir'] . $config['dir']['res'], 0777)
|
@mkdir($board['dir'] . $config['dir']['res'], 0777)
|
||||||
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
|
or error('Couldn\'t create ' . $board['dir'] . $config['dir']['img'] . '. Check permissions.', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openBoard($uri) {
|
function openBoard($uri) {
|
||||||
@ -551,7 +547,7 @@ function openBoard($uri) {
|
|||||||
$build_pages = array();
|
$build_pages = array();
|
||||||
|
|
||||||
// And what if we don't really need to change a board we have opened?
|
// And what if we don't really need to change a board we have opened?
|
||||||
if (isset ($board) && isset ($board['uri']) && $board['uri'] == $uri) {
|
if (isset ($board) && isset ($board['uri']) && $board['uri'] === $uri) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,7 +567,7 @@ function getBoardInfo($uri) {
|
|||||||
return $board;
|
return $board;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare("SELECT * FROM ``boards`` WHERE `uri` = :uri LIMIT 1");
|
$query = prepare('SELECT * FROM ``boards`` WHERE `uri` = :uri LIMIT 1');
|
||||||
$query->bindValue(':uri', $uri);
|
$query->bindValue(':uri', $uri);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -597,13 +593,13 @@ function purge($uri) {
|
|||||||
// Fix for Unicode
|
// Fix for Unicode
|
||||||
$uri = rawurlencode($uri);
|
$uri = rawurlencode($uri);
|
||||||
|
|
||||||
$noescape = "/!~*()+:";
|
$noescape = '/!~*()+:';
|
||||||
$noescape = preg_split('//', $noescape);
|
$noescape = preg_split('//', $noescape);
|
||||||
$noescape_url = array_map("rawurlencode", $noescape);
|
$noescape_url = array_map('rawurlencode', $noescape);
|
||||||
$uri = str_replace($noescape_url, $noescape, $uri);
|
$uri = str_replace($noescape_url, $noescape, $uri);
|
||||||
|
|
||||||
if (preg_match($config['referer_match'], $config['root']) && isset($_SERVER['REQUEST_URI'])) {
|
if (preg_match($config['referer_match'], $config['root']) && isset($_SERVER['REQUEST_URI'])) {
|
||||||
$uri = (str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) == '/' ? '/' : str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) . '/') . $uri;
|
$uri = (str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) === '/' ? '/' : str_replace('\\', '/', dirname($_SERVER['REQUEST_URI'])) . '/') . $uri;
|
||||||
} else {
|
} else {
|
||||||
$uri = $config['root'] . $uri;
|
$uri = $config['root'] . $uri;
|
||||||
}
|
}
|
||||||
@ -690,11 +686,11 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
|
|||||||
|
|
||||||
if (!$skip_purge && isset($config['purge'])) {
|
if (!$skip_purge && isset($config['purge'])) {
|
||||||
// Purge cache
|
// Purge cache
|
||||||
if (basename($path) == $config['file_index']) {
|
if (basename($path) === $config['file_index']) {
|
||||||
// Index file (/index.html); purge "/" as well
|
// Index file (/index.html); purge "/" as well
|
||||||
$uri = dirname($path);
|
$uri = dirname($path);
|
||||||
// root
|
// root
|
||||||
if ($uri == '.')
|
if ($uri === '.')
|
||||||
$uri = '';
|
$uri = '';
|
||||||
else
|
else
|
||||||
$uri .= '/';
|
$uri .= '/';
|
||||||
@ -729,11 +725,11 @@ function file_unlink($path) {
|
|||||||
|
|
||||||
if (isset($config['purge']) && $path[0] != '/' && isset($_SERVER['HTTP_HOST'])) {
|
if (isset($config['purge']) && $path[0] != '/' && isset($_SERVER['HTTP_HOST'])) {
|
||||||
// Purge cache
|
// Purge cache
|
||||||
if (basename($path) == $config['file_index']) {
|
if (basename($path) === $config['file_index']) {
|
||||||
// Index file (/index.html); purge "/" as well
|
// Index file (/index.html); purge "/" as well
|
||||||
$uri = dirname($path);
|
$uri = dirname($path);
|
||||||
// root
|
// root
|
||||||
if ($uri == '.')
|
if ($uri === '.')
|
||||||
$uri = '';
|
$uri = '';
|
||||||
else
|
else
|
||||||
$uri .= '/';
|
$uri .= '/';
|
||||||
@ -782,11 +778,11 @@ function listBoards($just_uri = false) {
|
|||||||
return $boards;
|
return $boards;
|
||||||
|
|
||||||
if (!$just_uri) {
|
if (!$just_uri) {
|
||||||
$query = query("SELECT * FROM ``boards`` ORDER BY `uri`") or error(db_error());
|
$query = query('SELECT * FROM ``boards`` ORDER BY `uri`') or error(db_error());
|
||||||
$boards = $query->fetchAll();
|
$boards = $query->fetchAll();
|
||||||
} else {
|
} else {
|
||||||
$boards = array();
|
$boards = array();
|
||||||
$query = query("SELECT `uri` FROM ``boards``") or error(db_error());
|
$query = query('SELECT `uri` FROM ``boards``') or error(db_error());
|
||||||
while ($board = $query->fetchColumn()) {
|
while ($board = $query->fetchColumn()) {
|
||||||
$boards[] = $board;
|
$boards[] = $board;
|
||||||
}
|
}
|
||||||
@ -845,7 +841,7 @@ function displayBan($ban) {
|
|||||||
|
|
||||||
if ($ban['post'] && isset($ban['post']['board'], $ban['post']['id'])) {
|
if ($ban['post'] && isset($ban['post']['board'], $ban['post']['id'])) {
|
||||||
if (openBoard($ban['post']['board'])) {
|
if (openBoard($ban['post']['board'])) {
|
||||||
$query = query(sprintf("SELECT `files` FROM ``posts_%s`` WHERE `id` = " .
|
$query = query(sprintf('SELECT `files` FROM ``posts_%s`` WHERE `id` = ' .
|
||||||
(int)$ban['post']['id'], $board['uri']));
|
(int)$ban['post']['id'], $board['uri']));
|
||||||
if ($_post = $query->fetch(PDO::FETCH_ASSOC)) {
|
if ($_post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$ban['post'] = array_merge($ban['post'], $_post);
|
$ban['post'] = array_merge($ban['post'], $_post);
|
||||||
@ -862,7 +858,7 @@ function displayBan($ban) {
|
|||||||
$pending_appeal = false;
|
$pending_appeal = false;
|
||||||
|
|
||||||
if ($config['ban_appeals']) {
|
if ($config['ban_appeals']) {
|
||||||
$query = query("SELECT `time`, `denied` FROM ``ban_appeals`` WHERE `ban_id` = " . (int)$ban['id']) or error(db_error());
|
$query = query('SELECT `time`, `denied` FROM ``ban_appeals`` WHERE `ban_id` = ' . (int)$ban['id']) or error(db_error());
|
||||||
while ($ban_appeal = $query->fetch(PDO::FETCH_ASSOC)) {
|
while ($ban_appeal = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
if ($ban_appeal['denied']) {
|
if ($ban_appeal['denied']) {
|
||||||
$denied_appeals[] = $ban_appeal['time'];
|
$denied_appeals[] = $ban_appeal['time'];
|
||||||
@ -907,7 +903,7 @@ function checkBan($board = false) {
|
|||||||
$ips[] = $_SERVER['REMOTE_ADDR'];
|
$ips[] = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
if ($config['proxy_check'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
if ($config['proxy_check'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||||
$ips = array_merge($ips, explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']));
|
$ips = array_merge($ips, explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($ips as $ip) {
|
foreach ($ips as $ip) {
|
||||||
@ -954,7 +950,7 @@ function threadLocked($id) {
|
|||||||
if (event('check-locked', $id))
|
if (event('check-locked', $id))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT `locked` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
|
$query = prepare(sprintf('SELECT `locked` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error());
|
$query->execute() or error(db_error());
|
||||||
|
|
||||||
@ -972,7 +968,7 @@ function threadSageLocked($id) {
|
|||||||
if (event('check-sage-locked', $id))
|
if (event('check-sage-locked', $id))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT `sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
|
$query = prepare(sprintf('SELECT `sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error());
|
$query->execute() or error(db_error());
|
||||||
|
|
||||||
@ -987,7 +983,7 @@ function threadSageLocked($id) {
|
|||||||
function threadExists($id) {
|
function threadExists($id) {
|
||||||
global $board;
|
global $board;
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT 1 FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
|
$query = prepare(sprintf('SELECT 1 FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error());
|
$query->execute() or error(db_error());
|
||||||
|
|
||||||
@ -1001,7 +997,7 @@ function threadExists($id) {
|
|||||||
function insertFloodPost(array $post) {
|
function insertFloodPost(array $post) {
|
||||||
global $board;
|
global $board;
|
||||||
|
|
||||||
$query = prepare("INSERT INTO ``flood`` VALUES (NULL, :ip, :board, :time, :posthash, :filehash, :isreply)");
|
$query = prepare('INSERT INTO ``flood`` VALUES (NULL, :ip, :board, :time, :posthash, :filehash, :isreply)');
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->bindValue(':board', $board['uri']);
|
$query->bindValue(':board', $board['uri']);
|
||||||
$query->bindValue(':time', time());
|
$query->bindValue(':time', time());
|
||||||
@ -1016,7 +1012,7 @@ function insertFloodPost(array $post) {
|
|||||||
|
|
||||||
function post(array $post) {
|
function post(array $post) {
|
||||||
global $pdo, $board;
|
global $pdo, $board;
|
||||||
$query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, :cycle, 0, :embed, :slug)", $board['uri']));
|
$query = prepare(sprintf('INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, :cycle, 0, :embed, :slug)', $board['uri']));
|
||||||
|
|
||||||
// Basic stuff
|
// Basic stuff
|
||||||
if (!empty($post['subject'])) {
|
if (!empty($post['subject'])) {
|
||||||
@ -1116,7 +1112,7 @@ function bumpThread($id) {
|
|||||||
$build_pages = array_merge(range(1, thread_find_page($id)), $build_pages);
|
$build_pages = array_merge(range(1, thread_find_page($id)), $build_pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare(sprintf("UPDATE ``posts_%s`` SET `bump` = :time WHERE `id` = :id AND `thread` IS NULL", $board['uri']));
|
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `bump` = :time WHERE `id` = :id AND `thread` IS NULL', $board['uri']));
|
||||||
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -1126,7 +1122,7 @@ function bumpThread($id) {
|
|||||||
function deleteFile($id, $remove_entirely_if_already=true, $file=null) {
|
function deleteFile($id, $remove_entirely_if_already=true, $file=null) {
|
||||||
global $board, $config;
|
global $board, $config;
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT `thread`, `files`, `num_files` FROM ``posts_%s`` WHERE `id` = :id LIMIT 1", $board['uri']));
|
$query = prepare(sprintf('SELECT `thread`, `files`, `num_files` FROM ``posts_%s`` WHERE `id` = :id LIMIT 1', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if (!$post = $query->fetch(PDO::FETCH_ASSOC))
|
if (!$post = $query->fetch(PDO::FETCH_ASSOC))
|
||||||
@ -1136,11 +1132,11 @@ function deleteFile($id, $remove_entirely_if_already=true, $file=null) {
|
|||||||
|
|
||||||
if (!$files[0]) error(_('That post has no files.'));
|
if (!$files[0]) error(_('That post has no files.'));
|
||||||
|
|
||||||
if ($files[0]->file == 'deleted' && $post['num_files'] == 1 && !$post['thread'])
|
if ($files[0]->file === 'deleted' && $post['num_files'] == 1 && !$post['thread'])
|
||||||
return; // Can't delete OP's image completely.
|
return; // Can't delete OP's image completely.
|
||||||
|
|
||||||
$query = prepare(sprintf("UPDATE ``posts_%s`` SET `files` = :file WHERE `id` = :id", $board['uri']));
|
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `files` = :file WHERE `id` = :id', $board['uri']));
|
||||||
if (($file && $file_to_delete->file == 'deleted') && $remove_entirely_if_already) {
|
if (($file && $file_to_delete->file === 'deleted') && $remove_entirely_if_already) {
|
||||||
// Already deleted; remove file fully
|
// Already deleted; remove file fully
|
||||||
$files[$file] = null;
|
$files[$file] = null;
|
||||||
} else {
|
} else {
|
||||||
@ -1174,7 +1170,7 @@ function deleteFile($id, $remove_entirely_if_already=true, $file=null) {
|
|||||||
function rebuildPost($id) {
|
function rebuildPost($id) {
|
||||||
global $board, $mod;
|
global $board, $mod;
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1186,7 +1182,7 @@ function rebuildPost($id) {
|
|||||||
event('rebuildpost', $post);
|
event('rebuildpost', $post);
|
||||||
$post = (array)$post;
|
$post = (array)$post;
|
||||||
|
|
||||||
$query = prepare(sprintf("UPDATE ``posts_%s`` SET `body` = :body WHERE `id` = :id", $board['uri']));
|
$query = prepare(sprintf('UPDATE ``posts_%s`` SET `body` = :body WHERE `id` = :id', $board['uri']));
|
||||||
$query->bindValue(':body', $post['body']);
|
$query->bindValue(':body', $post['body']);
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -1201,7 +1197,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
|||||||
global $board, $config;
|
global $board, $config;
|
||||||
|
|
||||||
// Select post and replies (if thread) in one query
|
// Select post and replies (if thread) in one query
|
||||||
$query = prepare(sprintf("SELECT `id`,`thread`,`files`,`slug` FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
$query = prepare(sprintf('SELECT `id`,`thread`,`files`,`slug` FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1227,13 +1223,14 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
|||||||
$antispam_query->bindValue(':board', $board['uri']);
|
$antispam_query->bindValue(':board', $board['uri']);
|
||||||
$antispam_query->bindValue(':thread', $post['id']);
|
$antispam_query->bindValue(':thread', $post['id']);
|
||||||
$antispam_query->execute() or error(db_error($antispam_query));
|
$antispam_query->execute() or error(db_error($antispam_query));
|
||||||
} elseif ($query->rowCount() == 1) {
|
} elseif ($query->rowCount() === 1) {
|
||||||
// Rebuild thread
|
// Rebuild thread
|
||||||
$rebuild = &$post['thread'];
|
$rebuild = &$post['thread'];
|
||||||
}
|
}
|
||||||
if ($post['files']) {
|
if ($post['files']) {
|
||||||
// Delete file
|
// Delete file
|
||||||
foreach (json_decode($post['files']) as $i => $f) {
|
$files = json_decode($post['files']);
|
||||||
|
foreach ($files as $i => $f) {
|
||||||
if ($f->file !== 'deleted') {
|
if ($f->file !== 'deleted') {
|
||||||
file_unlink($board['dir'] . $config['dir']['img'] . $f->file);
|
file_unlink($board['dir'] . $config['dir']['img'] . $f->file);
|
||||||
file_unlink($board['dir'] . $config['dir']['thumb'] . $f->thumb);
|
file_unlink($board['dir'] . $config['dir']['thumb'] . $f->thumb);
|
||||||
@ -1245,11 +1242,11 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare(sprintf("DELETE FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
$query = prepare(sprintf('DELETE FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$query = prepare("SELECT `board`, `post` FROM ``cites`` WHERE `target_board` = :board AND (`target` = " . implode(' OR `target` = ', $ids) . ") ORDER BY `board`");
|
$query = prepare('SELECT `board`, `post` FROM ``cites`` WHERE `target_board` = :board AND (`target` = ' . implode(' OR `target` = ', $ids) . ') ORDER BY `board`');
|
||||||
$query->bindValue(':board', $board['uri']);
|
$query->bindValue(':board', $board['uri']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
|
while ($cite = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
@ -1264,7 +1261,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
|
|||||||
if (isset($tmp_board))
|
if (isset($tmp_board))
|
||||||
openBoard($tmp_board);
|
openBoard($tmp_board);
|
||||||
|
|
||||||
$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 = 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(':board', $board['uri']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1281,7 +1278,7 @@ function clean($pid = false) {
|
|||||||
$offset = round($config['max_pages']*$config['threads_per_page']);
|
$offset = round($config['max_pages']*$config['threads_per_page']);
|
||||||
|
|
||||||
// I too wish there was an easier way of doing this...
|
// I too wish there was an easier way of doing this...
|
||||||
$query = prepare(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri']));
|
$query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001', $board['uri']));
|
||||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||||
|
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -1293,7 +1290,7 @@ function clean($pid = false) {
|
|||||||
// Bump off threads with X replies earlier, spam prevention method
|
// Bump off threads with X replies earlier, spam prevention method
|
||||||
if ($config['early_404']) {
|
if ($config['early_404']) {
|
||||||
$offset = round($config['early_404_page']*$config['threads_per_page']);
|
$offset = round($config['early_404_page']*$config['threads_per_page']);
|
||||||
$query = prepare(sprintf("SELECT `id` AS `thread_id`, (SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri'], $board['uri']));
|
$query = prepare(sprintf('SELECT `id` AS `thread_id`, (SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001', $board['uri'], $board['uri']));
|
||||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1314,7 +1311,7 @@ function clean($pid = false) {
|
|||||||
if ($config['early_404_staged']) {
|
if ($config['early_404_staged']) {
|
||||||
$iter++;
|
$iter++;
|
||||||
|
|
||||||
if ($iter == $config['threads_per_page']) {
|
if ($iter === $config['threads_per_page']) {
|
||||||
$page++;
|
$page++;
|
||||||
$iter = 0;
|
$iter = 0;
|
||||||
}
|
}
|
||||||
@ -1326,7 +1323,7 @@ function clean($pid = false) {
|
|||||||
function thread_find_page($thread) {
|
function thread_find_page($thread) {
|
||||||
global $config, $board;
|
global $config, $board;
|
||||||
|
|
||||||
$query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC", $board['uri'])) or error(db_error($query));
|
$query = query(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC', $board['uri'])) or error(db_error($query));
|
||||||
$threads = $query->fetchAll(PDO::FETCH_COLUMN);
|
$threads = $query->fetchAll(PDO::FETCH_COLUMN);
|
||||||
if (($index = array_search($thread, $threads)) === false)
|
if (($index = array_search($thread, $threads)) === false)
|
||||||
return false;
|
return false;
|
||||||
@ -1340,7 +1337,7 @@ function index($page, $mod=false) {
|
|||||||
$body = '';
|
$body = '';
|
||||||
$offset = round($page*$config['threads_per_page']-$config['threads_per_page']);
|
$offset = round($page*$config['threads_per_page']-$config['threads_per_page']);
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset,:threads_per_page", $board['uri']));
|
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset,:threads_per_page', $board['uri']));
|
||||||
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||||
$query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT);
|
$query->bindValue(':threads_per_page', $config['threads_per_page'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -1367,7 +1364,7 @@ function index($page, $mod=false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($cached)) {
|
if (!isset($cached)) {
|
||||||
$posts = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $board['uri']));
|
$posts = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit', $board['uri']));
|
||||||
$posts->bindValue(':id', $th['id']);
|
$posts->bindValue(':id', $th['id']);
|
||||||
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
||||||
$posts->execute() or error(db_error($posts));
|
$posts->execute() or error(db_error($posts));
|
||||||
@ -1477,7 +1474,7 @@ function getPages($mod=false) {
|
|||||||
$count = $board['thread_count'];
|
$count = $board['thread_count'];
|
||||||
} else {
|
} else {
|
||||||
// Count threads
|
// Count threads
|
||||||
$query = query(sprintf("SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error());
|
$query = query(sprintf('SELECT COUNT(*) FROM ``posts_%s`` WHERE `thread` IS NULL', $board['uri'])) or error(db_error());
|
||||||
$count = $query->fetchColumn();
|
$count = $query->fetchColumn();
|
||||||
}
|
}
|
||||||
$count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']);
|
$count = floor(($config['threads_per_page'] + $count - 1) / $config['threads_per_page']);
|
||||||
@ -1488,7 +1485,7 @@ function getPages($mod=false) {
|
|||||||
for ($x=0;$x<$count && $x<$config['max_pages'];$x++) {
|
for ($x=0;$x<$count && $x<$config['max_pages'];$x++) {
|
||||||
$pages[] = array(
|
$pages[] = array(
|
||||||
'num' => $x+1,
|
'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)
|
'link' => $x===0 ? ($mod ? '?/' : $config['root']) . $board['dir'] . $config['file_index'] : ($mod ? '?/' : $config['root']) . $board['dir'] . sprintf($config['file_page'], $x+1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1535,7 +1532,7 @@ function checkRobot($body) {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
$body = makerobot($body);
|
$body = makerobot($body);
|
||||||
$query = prepare("SELECT 1 FROM ``robot`` WHERE `hash` = :hash LIMIT 1");
|
$query = prepare('SELECT 1 FROM ``robot`` WHERE `hash` = :hash LIMIT 1');
|
||||||
$query->bindValue(':hash', $body);
|
$query->bindValue(':hash', $body);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1544,7 +1541,7 @@ function checkRobot($body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert new hash
|
// Insert new hash
|
||||||
$query = prepare("INSERT INTO ``robot`` VALUES (:hash)");
|
$query = prepare('INSERT INTO ``robot`` VALUES (:hash)');
|
||||||
$query->bindValue(':hash', $body);
|
$query->bindValue(':hash', $body);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1554,7 +1551,7 @@ function checkRobot($body) {
|
|||||||
// Returns an associative array with 'replies' and 'images' keys
|
// Returns an associative array with 'replies' and 'images' keys
|
||||||
function numPosts($id) {
|
function numPosts($id) {
|
||||||
global $board;
|
global $board;
|
||||||
$query = prepare(sprintf("SELECT COUNT(*) AS `replies`, SUM(`num_files`) AS `images` FROM ``posts_%s`` WHERE `thread` = :thread", $board['uri'], $board['uri']));
|
$query = prepare(sprintf('SELECT COUNT(*) AS `replies`, SUM(`num_files`) AS `images` FROM ``posts_%s`` WHERE `thread` = :thread', $board['uri'], $board['uri']));
|
||||||
$query->bindValue(':thread', $id, PDO::PARAM_INT);
|
$query->bindValue(':thread', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1568,7 +1565,7 @@ function muteTime() {
|
|||||||
return $time;
|
return $time;
|
||||||
|
|
||||||
// Find number of mutes in the past X hours
|
// Find number of mutes in the past X hours
|
||||||
$query = prepare("SELECT COUNT(*) FROM ``mutes`` WHERE `time` >= :time AND `ip` = :ip");
|
$query = prepare('SELECT COUNT(*) FROM ``mutes`` WHERE `time` >= :time AND `ip` = :ip');
|
||||||
$query->bindValue(':time', time()-($config['robot_mute_hour']*3600), PDO::PARAM_INT);
|
$query->bindValue(':time', time()-($config['robot_mute_hour']*3600), PDO::PARAM_INT);
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -1580,7 +1577,7 @@ function muteTime() {
|
|||||||
|
|
||||||
function mute() {
|
function mute() {
|
||||||
// Insert mute
|
// Insert mute
|
||||||
$query = prepare("INSERT INTO ``mutes`` VALUES (:ip, :time)");
|
$query = prepare('INSERT INTO ``mutes`` VALUES (:ip, :time)');
|
||||||
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -1601,7 +1598,7 @@ function checkMute() {
|
|||||||
$mutetime = muteTime();
|
$mutetime = muteTime();
|
||||||
if ($mutetime > 0) {
|
if ($mutetime > 0) {
|
||||||
// Find last mute time
|
// Find last mute time
|
||||||
$query = prepare("SELECT `time` FROM ``mutes`` WHERE `ip` = :ip ORDER BY `time` DESC LIMIT 1");
|
$query = prepare('SELECT `time` FROM ``mutes`` WHERE `ip` = :ip ORDER BY `time` DESC LIMIT 1');
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -1624,7 +1621,7 @@ function checkMute() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildIndex($global_api = "yes") {
|
function buildIndex($global_api = 'yes') {
|
||||||
global $board, $config, $build_pages;
|
global $board, $config, $build_pages;
|
||||||
|
|
||||||
$pages = getPages();
|
$pages = getPages();
|
||||||
@ -1637,10 +1634,10 @@ function buildIndex($global_api = "yes") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ($page = 1; $page <= $config['max_pages']; $page++) {
|
for ($page = 1; $page <= $config['max_pages']; $page++) {
|
||||||
$filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page));
|
$filename = $board['dir'] . ($page === 1 ? $config['file_index'] : sprintf($config['file_page'], $page));
|
||||||
$jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
|
$jsonFilename = $board['dir'] . ($page - 1) . '.json'; // pages should start from 0
|
||||||
|
|
||||||
if ((!$config['api']['enabled'] || $global_api == "skip") && $config['try_smarter'] && isset($build_pages)
|
if ((!$config['api']['enabled'] || $global_api === 'skip') && $config['try_smarter'] && isset($build_pages)
|
||||||
&& !empty($build_pages) && !in_array($page, $build_pages))
|
&& !empty($build_pages) && !in_array($page, $build_pages))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1657,7 +1654,7 @@ function buildIndex($global_api = "yes") {
|
|||||||
$catalog[$page-1] = $threads;
|
$catalog[$page-1] = $threads;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!$config['api']['enabled'] || $global_api == "skip") && $config['try_smarter'] && isset($build_pages)
|
if ((!$config['api']['enabled'] || $global_api === 'skip') && $config['try_smarter'] && isset($build_pages)
|
||||||
&& !empty($build_pages) && !in_array($page, $build_pages))
|
&& !empty($build_pages) && !in_array($page, $build_pages))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1678,7 +1675,7 @@ function buildIndex($global_api = "yes") {
|
|||||||
// $action is an action for our last page
|
// $action is an action for our last page
|
||||||
if ($page < $config['max_pages']) {
|
if ($page < $config['max_pages']) {
|
||||||
for (;$page<=$config['max_pages'];$page++) {
|
for (;$page<=$config['max_pages'];$page++) {
|
||||||
$filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page));
|
$filename = $board['dir'] . ($page===1 ? $config['file_index'] : sprintf($config['file_page'], $page));
|
||||||
file_unlink($filename);
|
file_unlink($filename);
|
||||||
|
|
||||||
if ($config['api']['enabled']) {
|
if ($config['api']['enabled']) {
|
||||||
@ -1689,7 +1686,7 @@ function buildIndex($global_api = "yes") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// json api catalog
|
// json api catalog
|
||||||
if ($config['api']['enabled'] && $global_api != "skip") {
|
if ($config['api']['enabled'] && $global_api !== 'skip') {
|
||||||
$json = json_encode($api->translateCatalog($catalog));
|
$json = json_encode($api->translateCatalog($catalog));
|
||||||
$jsonFilename = $board['dir'] . 'catalog.json';
|
$jsonFilename = $board['dir'] . 'catalog.json';
|
||||||
file_write($jsonFilename, $json);
|
file_write($jsonFilename, $json);
|
||||||
@ -1719,7 +1716,7 @@ function buildJavascript() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
// Check if we have translation for the javascripts; if yes, we add it to additional javascripts
|
// Check if we have translation for the javascripts; if yes, we add it to additional javascripts
|
||||||
list($pure_locale) = explode(".", $config['locale']);
|
list($pure_locale) = explode('.', $config['locale']);
|
||||||
if (file_exists ($jsloc = "inc/locale/$pure_locale/LC_MESSAGES/javascript.js")) {
|
if (file_exists ($jsloc = "inc/locale/$pure_locale/LC_MESSAGES/javascript.js")) {
|
||||||
$script = file_get_contents($jsloc) . "\n\n" . $script;
|
$script = file_get_contents($jsloc) . "\n\n" . $script;
|
||||||
}
|
}
|
||||||
@ -1746,7 +1743,7 @@ function checkDNSBL() {
|
|||||||
if (!isset($_SERVER['REMOTE_ADDR']))
|
if (!isset($_SERVER['REMOTE_ADDR']))
|
||||||
return; // Fix your web server configuration
|
return; // Fix your web server configuration
|
||||||
|
|
||||||
if (preg_match("/^(::(ffff:)?)?(127\.|192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|0\.|255\.)/", $_SERVER['REMOTE_ADDR']))
|
if (preg_match('/^(::(ffff:)?)?(127\.|192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|0\.|255\.)/', $_SERVER['REMOTE_ADDR']))
|
||||||
return; // It's pointless to check for local IP addresses in dnsbls, isn't it?
|
return; // It's pointless to check for local IP addresses in dnsbls, isn't it?
|
||||||
|
|
||||||
if (in_array($_SERVER['REMOTE_ADDR'], $config['dnsbl_exceptions']))
|
if (in_array($_SERVER['REMOTE_ADDR'], $config['dnsbl_exceptions']))
|
||||||
@ -1758,7 +1755,7 @@ function checkDNSBL() {
|
|||||||
if (!is_array($blacklist))
|
if (!is_array($blacklist))
|
||||||
$blacklist = array($blacklist);
|
$blacklist = array($blacklist);
|
||||||
|
|
||||||
if (($lookup = str_replace('%', $ipaddr, $blacklist[0])) == $blacklist[0])
|
if (($lookup = str_replace('%', $ipaddr, $blacklist[0])) === $blacklist[0])
|
||||||
$lookup = $ipaddr . '.' . $blacklist[0];
|
$lookup = $ipaddr . '.' . $blacklist[0];
|
||||||
|
|
||||||
if (!$ip = DNS($lookup))
|
if (!$ip = DNS($lookup))
|
||||||
@ -1771,14 +1768,14 @@ function checkDNSBL() {
|
|||||||
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
||||||
} elseif (is_array($blacklist[1])) {
|
} elseif (is_array($blacklist[1])) {
|
||||||
foreach ($blacklist[1] as $octet) {
|
foreach ($blacklist[1] as $octet) {
|
||||||
if ($ip == $octet || $ip == '127.0.0.' . $octet)
|
if ($ip === $octet || $ip === '127.0.0.' . $octet)
|
||||||
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
||||||
}
|
}
|
||||||
} elseif (is_callable($blacklist[1])) {
|
} elseif (is_callable($blacklist[1])) {
|
||||||
if ($blacklist[1]($ip))
|
if ($blacklist[1]($ip))
|
||||||
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
||||||
} else {
|
} else {
|
||||||
if ($ip == $blacklist[1] || $ip == '127.0.0.' . $blacklist[1])
|
if ($ip === $blacklist[1] || $ip === '127.0.0.' . $blacklist[1])
|
||||||
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
error(sprintf($config['error']['dnsbl'], $blacklist_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1814,7 +1811,7 @@ function quote($body, $quote=true) {
|
|||||||
|
|
||||||
$body = strip_tags($body);
|
$body = strip_tags($body);
|
||||||
|
|
||||||
$body = preg_replace("/(^|\n)/", '$1>', $body);
|
$body = preg_replace('/(^|\n)/', '$1>', $body);
|
||||||
|
|
||||||
$body .= "\n";
|
$body .= "\n";
|
||||||
|
|
||||||
@ -1844,7 +1841,7 @@ function markup_url($matches) {
|
|||||||
|
|
||||||
$parts = array();
|
$parts = array();
|
||||||
foreach ($link as $attr => $value) {
|
foreach ($link as $attr => $value) {
|
||||||
if ($attr == 'text' || $attr == 'after')
|
if ($attr === 'text' || $attr === 'after')
|
||||||
continue;
|
continue;
|
||||||
$parts[] = $attr . '="' . $value . '"';
|
$parts[] = $attr . '="' . $value . '"';
|
||||||
}
|
}
|
||||||
@ -1872,7 +1869,7 @@ function extract_modifiers($body) {
|
|||||||
|
|
||||||
if (preg_match_all('@<tinyboard ([\w\s]+)>(.*?)</tinyboard>@us', $body, $matches, PREG_SET_ORDER)) {
|
if (preg_match_all('@<tinyboard ([\w\s]+)>(.*?)</tinyboard>@us', $body, $matches, PREG_SET_ORDER)) {
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
if (preg_match('/^escape /', $match[1]))
|
if (strpos($match[1], 'escape ') === 0)
|
||||||
continue;
|
continue;
|
||||||
$modifiers[$match[1]] = html_entity_decode($match[2]);
|
$modifiers[$match[1]] = html_entity_decode($match[2]);
|
||||||
}
|
}
|
||||||
@ -1893,7 +1890,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||||||
$body = preg_replace('@<tinyboard (?!escape )([\w\s]+)>(.+?)</tinyboard>@us', '', $body);
|
$body = preg_replace('@<tinyboard (?!escape )([\w\s]+)>(.+?)</tinyboard>@us', '', $body);
|
||||||
$body = preg_replace('@<(tinyboard) escape ([\w\s]+)>@i', '<$1 $2>', $body);
|
$body = preg_replace('@<(tinyboard) escape ([\w\s]+)>@i', '<$1 $2>', $body);
|
||||||
|
|
||||||
if (isset($modifiers['raw html']) && $modifiers['raw html'] == '1') {
|
if (isset($modifiers['raw html']) && $modifiers['raw html'] === '1') {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2059,7 +2056,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore old board
|
// Restore old board
|
||||||
if ($board['uri'] != $tmp_board)
|
if ($board['uri'] !== $tmp_board)
|
||||||
openBoard($tmp_board);
|
openBoard($tmp_board);
|
||||||
|
|
||||||
foreach ($cites as $matches) {
|
foreach ($cites as $matches) {
|
||||||
@ -2076,7 +2073,7 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||||||
$link = $cited_posts[$_board][$cite];
|
$link = $cited_posts[$_board][$cite];
|
||||||
|
|
||||||
$replacement = '<a ' .
|
$replacement = '<a ' .
|
||||||
($_board == $board['uri'] ?
|
($_board === $board['uri'] ?
|
||||||
'onclick="highlightReply(\''.$cite.'\', event);" '
|
'onclick="highlightReply(\''.$cite.'\', event);" '
|
||||||
: '') . 'href="' . $link . '">' .
|
: '') . 'href="' . $link . '">' .
|
||||||
'>>>/' . $_board . '/' . $cite .
|
'>>>/' . $_board . '/' . $cite .
|
||||||
@ -2100,20 +2097,20 @@ function markup(&$body, $track_cites = false, $op = false) {
|
|||||||
|
|
||||||
$tracked_cites = array_unique($tracked_cites, SORT_REGULAR);
|
$tracked_cites = array_unique($tracked_cites, SORT_REGULAR);
|
||||||
|
|
||||||
$body = preg_replace("/^\s*>.*$/m", '<span class="quote">$0</span>', $body);
|
$body = preg_replace('/^\s*>.*$/m', '<span class="quote">$0</span>', $body);
|
||||||
|
|
||||||
if ($config['strip_superfluous_returns'])
|
if ($config['strip_superfluous_returns'])
|
||||||
$body = preg_replace('/\s+$/', '', $body);
|
$body = preg_replace('/\s+$/', '', $body);
|
||||||
|
|
||||||
$body = preg_replace("/\n/", '<br/>', $body);
|
$body = preg_replace('/\n/', '<br/>', $body);
|
||||||
|
|
||||||
// Fix code markup
|
// Fix code markup
|
||||||
if ($config['markup_code']) {
|
if ($config['markup_code']) {
|
||||||
foreach ($code_markup as $id => $val) {
|
foreach ($code_markup as $id => $val) {
|
||||||
$code = isset($val[2]) ? $val[2] : $val[1];
|
$code = isset($val[2]) ? $val[2] : $val[1];
|
||||||
$code_lang = isset($val[2]) ? $val[1] : "";
|
$code_lang = isset($val[2]) ? $val[1] : '';
|
||||||
|
|
||||||
$code = "<pre class='code lang-$code_lang'>".str_replace(array("\n","\t"), array(" ","	"), htmlspecialchars($code))."</pre>";
|
$code = "<pre class='code lang-$code_lang'>" . str_replace(["\n", "\t"], [' ', '	'], htmlspecialchars($code)) . '</pre>';
|
||||||
|
|
||||||
$body = str_replace("<code $id>", $code, $body);
|
$body = str_replace("<code $id>", $code, $body);
|
||||||
}
|
}
|
||||||
@ -2202,7 +2199,7 @@ function buildThread($id, $return = false, $mod = false) {
|
|||||||
cache::delete("thread_{$board['uri']}_{$id}");
|
cache::delete("thread_{$board['uri']}_{$id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`", $board['uri']));
|
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id`', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -2265,7 +2262,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
|||||||
$antibot->reset();
|
$antibot->reset();
|
||||||
|
|
||||||
if (!$thread) {
|
if (!$thread) {
|
||||||
$query = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id` DESC LIMIT :limit", $board['uri']));
|
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`id` DESC LIMIT :limit', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->bindValue(':limit', $config['noko50_count']+1, PDO::PARAM_INT);
|
$query->bindValue(':limit', $config['noko50_count']+1, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -2287,9 +2284,9 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
|||||||
error($config['error']['nonexistant']);
|
error($config['error']['nonexistant']);
|
||||||
|
|
||||||
|
|
||||||
if ($query->rowCount() == $config['noko50_count']+1) {
|
if ($query->rowCount() === $config['noko50_count']+1) {
|
||||||
$count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL
|
$count = prepare(sprintf('SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL
|
||||||
SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
|
SELECT SUM(`num_files`) FROM ``posts_%s`` WHERE `files` IS NOT NULL AND `thread` = :thread', $board['uri'], $board['uri']));
|
||||||
$count->bindValue(':thread', $id, PDO::PARAM_INT);
|
$count->bindValue(':thread', $id, PDO::PARAM_INT);
|
||||||
$count->execute() or error(db_error($count));
|
$count->execute() or error(db_error($count));
|
||||||
|
|
||||||
@ -2307,7 +2304,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti
|
|||||||
$thread->posts = array_slice($allPosts, -$config['noko50_count']);
|
$thread->posts = array_slice($allPosts, -$config['noko50_count']);
|
||||||
$thread->omitted += count($allPosts) - count($thread->posts);
|
$thread->omitted += count($allPosts) - count($thread->posts);
|
||||||
foreach ($allPosts as $index => $post) {
|
foreach ($allPosts as $index => $post) {
|
||||||
if ($index == count($allPosts)-count($thread->posts))
|
if ($index === count($allPosts)-count($thread->posts))
|
||||||
break;
|
break;
|
||||||
if ($post->files)
|
if ($post->files)
|
||||||
$thread->omitted_images += $post->num_files;
|
$thread->omitted_images += $post->num_files;
|
||||||
@ -2341,11 +2338,11 @@ function rrmdir($dir) {
|
|||||||
if (is_dir($dir)) {
|
if (is_dir($dir)) {
|
||||||
$objects = scandir($dir);
|
$objects = scandir($dir);
|
||||||
foreach ($objects as $object) {
|
foreach ($objects as $object) {
|
||||||
if ($object != "." && $object != "..") {
|
if ($object !== '.' && $object !== '..') {
|
||||||
if (filetype($dir."/".$object) == "dir")
|
if (filetype($dir . '/' . $object) === 'dir')
|
||||||
rrmdir($dir."/".$object);
|
rrmdir($dir . '/' . $object);
|
||||||
else
|
else
|
||||||
file_unlink($dir."/".$object);
|
file_unlink($dir . '/' . $object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reset($objects);
|
reset($objects);
|
||||||
@ -2407,11 +2404,11 @@ function hcf($a, $b){
|
|||||||
$b = $a-$b;
|
$b = $a-$b;
|
||||||
$a = $a-$b;
|
$a = $a-$b;
|
||||||
}
|
}
|
||||||
if ($b==(round($b/$a))*$a)
|
if ($b===(round($b/$a))*$a)
|
||||||
$gcd=$a;
|
$gcd=$a;
|
||||||
else {
|
else {
|
||||||
for ($i=round($a/2);$i;$i--) {
|
for ($i=round($a/2);$i;$i--) {
|
||||||
if ($a == round($a/$i)*$i && $b == round($b/$i)*$i) {
|
if ($a === round($a/$i)*$i && $b === round($b/$i)*$i) {
|
||||||
$gcd = $i;
|
$gcd = $i;
|
||||||
$i = false;
|
$i = false;
|
||||||
}
|
}
|
||||||
@ -2430,7 +2427,7 @@ function fraction($numerator, $denominator, $sep) {
|
|||||||
|
|
||||||
function getPostByHash($hash) {
|
function getPostByHash($hash) {
|
||||||
global $board;
|
global $board;
|
||||||
$query = prepare(sprintf("SELECT `id`,`thread` FROM ``posts_%s`` WHERE `filehash` = :hash", $board['uri']));
|
$query = prepare(sprintf('SELECT `id`,`thread` FROM ``posts_%s`` WHERE `filehash` = :hash', $board['uri']));
|
||||||
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
|
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -2443,7 +2440,7 @@ function getPostByHash($hash) {
|
|||||||
|
|
||||||
function getPostByHashInThread($hash, $thread) {
|
function getPostByHashInThread($hash, $thread) {
|
||||||
global $board;
|
global $board;
|
||||||
$query = prepare(sprintf("SELECT `id`,`thread` FROM ``posts_%s`` WHERE `filehash` = :hash AND ( `thread` = :thread OR `id` = :thread )", $board['uri']));
|
$query = prepare(sprintf('SELECT `id`,`thread` FROM ``posts_%s`` WHERE `filehash` = :hash AND ( `thread` = :thread OR `id` = :thread )', $board['uri']));
|
||||||
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
|
$query->bindValue(':hash', $hash, PDO::PARAM_STR);
|
||||||
$query->bindValue(':thread', $thread, PDO::PARAM_INT);
|
$query->bindValue(':thread', $thread, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
@ -2486,7 +2483,7 @@ function rDNS($ip_addr) {
|
|||||||
|
|
||||||
$isip = filter_var($host, FILTER_VALIDATE_IP);
|
$isip = filter_var($host, FILTER_VALIDATE_IP);
|
||||||
|
|
||||||
if ($config['fcrdns'] && !$isip && DNS($host) != $ip_addr) {
|
if ($config['fcrdns'] && !$isip && DNS($host) !== $ip_addr) {
|
||||||
$host = $ip_addr;
|
$host = $ip_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2500,7 +2497,7 @@ function DNS($host) {
|
|||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if ($config['cache']['enabled'] && ($ip_addr = cache::get('dns_' . $host))) {
|
if ($config['cache']['enabled'] && ($ip_addr = cache::get('dns_' . $host))) {
|
||||||
return $ip_addr != '?' ? $ip_addr : false;
|
return $ip_addr !== '?' ? $ip_addr : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$config['dns_system']) {
|
if (!$config['dns_system']) {
|
||||||
@ -2553,6 +2550,7 @@ function diceRoller($post) {
|
|||||||
global $config;
|
global $config;
|
||||||
if(strpos(strtolower($post->email), 'dice%20') === 0) {
|
if(strpos(strtolower($post->email), 'dice%20') === 0) {
|
||||||
$dicestr = str_split(substr($post->email, strlen('dice%20')));
|
$dicestr = str_split(substr($post->email, strlen('dice%20')));
|
||||||
|
$dicelen = count($dicestr);
|
||||||
|
|
||||||
// Get params
|
// Get params
|
||||||
$diceX = '';
|
$diceX = '';
|
||||||
@ -2560,7 +2558,7 @@ function diceRoller($post) {
|
|||||||
$diceZ = '';
|
$diceZ = '';
|
||||||
|
|
||||||
$curd = 'diceX';
|
$curd = 'diceX';
|
||||||
for($i = 0; $i < count($dicestr); $i ++) {
|
for($i = 0; $i < $dicelen; $i ++) {
|
||||||
if(is_numeric($dicestr[$i])) {
|
if(is_numeric($dicestr[$i])) {
|
||||||
$$curd .= $dicestr[$i];
|
$$curd .= $dicestr[$i];
|
||||||
} else if($dicestr[$i] == 'd') {
|
} else if($dicestr[$i] == 'd') {
|
||||||
@ -2572,18 +2570,18 @@ function diceRoller($post) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default values for X and Z
|
// Default values for X and Z
|
||||||
if($diceX == '') {
|
if($diceX === '') {
|
||||||
$diceX = '1';
|
$diceX = '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
if($diceZ == '') {
|
if($diceZ === '') {
|
||||||
$diceZ = '+0';
|
$diceZ = '+0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intify them
|
// Intify them
|
||||||
$diceX = intval($diceX);
|
$diceX = (int)$diceX;
|
||||||
$diceY = intval($diceY);
|
$diceY = (int)$diceY;
|
||||||
$diceZ = intval($diceZ);
|
$diceZ = (int)$diceZ;
|
||||||
|
|
||||||
// Continue only if we have valid values
|
// Continue only if we have valid values
|
||||||
if($diceX > 0 && $diceY > 0) {
|
if($diceX > 0 && $diceY > 0) {
|
||||||
@ -2596,7 +2594,7 @@ function diceRoller($post) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepend the result to the post body
|
// Prepend the result to the post body
|
||||||
$modifier = ($diceZ != 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : '';
|
$modifier = ($diceZ !== 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : '';
|
||||||
$dicesum = ($diceX > 1) ? ' = ' . $dicesum : '';
|
$dicesum = ($diceX > 1) ? ' = ' . $dicesum : '';
|
||||||
$post->body = '<table class="diceroll"><tr><td><img src="'.$config['dir']['static'].'d10.svg" alt="Dice roll" width="24"></td><td>Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '</td></tr></table><br/>' . $post->body;
|
$post->body = '<table class="diceroll"><tr><td><img src="'.$config['dir']['static'].'d10.svg" alt="Dice roll" width="24"></td><td>Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '</td></tr></table><br/>' . $post->body;
|
||||||
}
|
}
|
||||||
@ -2606,23 +2604,23 @@ function diceRoller($post) {
|
|||||||
function slugify($post) {
|
function slugify($post) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$slug = "";
|
$slug = '';
|
||||||
|
|
||||||
if (isset($post['subject']) && $post['subject'])
|
if (isset($post['subject']) && $post['subject'])
|
||||||
$slug = $post['subject'];
|
$slug = $post['subject'];
|
||||||
elseif (isset ($post['body_nomarkup']) && $post['body_nomarkup'])
|
elseif (isset($post['body_nomarkup']) && $post['body_nomarkup'])
|
||||||
$slug = $post['body_nomarkup'];
|
$slug = $post['body_nomarkup'];
|
||||||
elseif (isset ($post['body']) && $post['body'])
|
elseif (isset($post['body']) && $post['body'])
|
||||||
$slug = strip_tags($post['body']);
|
$slug = strip_tags($post['body']);
|
||||||
|
|
||||||
// Fix UTF-8 first
|
// Fix UTF-8 first
|
||||||
$slug = mb_convert_encoding($slug, "UTF-8", "UTF-8");
|
$slug = mb_convert_encoding($slug, 'UTF-8', 'UTF-8');
|
||||||
|
|
||||||
// Transliterate local characters like ü, I wonder how would it work for weird alphabets :^)
|
// Transliterate local characters like ü, I wonder how would it work for weird alphabets :^)
|
||||||
$slug = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $slug);
|
$slug = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $slug);
|
||||||
|
|
||||||
// Remove Tinyboard custom markup
|
// Remove Tinyboard custom markup
|
||||||
$slug = preg_replace("/<tinyboard [^>]+>.*?<\/tinyboard>/s", '', $slug);
|
$slug = preg_replace('/<tinyboard [^>]+>.*?<\/tinyboard>/s', '', $slug);
|
||||||
|
|
||||||
// Downcase everything
|
// Downcase everything
|
||||||
$slug = strtolower($slug);
|
$slug = strtolower($slug);
|
||||||
@ -2655,13 +2653,13 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false)
|
|||||||
|
|
||||||
$slug = false;
|
$slug = false;
|
||||||
|
|
||||||
if ($config['slugify'] && ( (isset($post['thread']) && $post['thread']) || !isset ($post['slug']) ) ) {
|
if ($config['slugify'] && ( (isset($post['thread']) && $post['thread']) || !isset($post['slug']) ) ) {
|
||||||
$cvar = "slug_".$b['uri']."_".$id;
|
$cvar = 'slug_' . $b['uri'] . ' ' . $id;
|
||||||
if (!$thread) {
|
if (!$thread) {
|
||||||
$slug = Cache::get($cvar);
|
$slug = Cache::get($cvar);
|
||||||
|
|
||||||
if ($slug === false) {
|
if ($slug === false) {
|
||||||
$query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri']));
|
$query = prepare(sprintf('SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id', $b['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -2671,14 +2669,10 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false)
|
|||||||
|
|
||||||
Cache::set($cvar, $slug);
|
Cache::set($cvar, $slug);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else {
|
|
||||||
$slug = $thread['slug'];
|
$slug = $thread['slug'];
|
||||||
}
|
} elseif ($config['slugify'])
|
||||||
}
|
|
||||||
elseif ($config['slugify']) {
|
|
||||||
$slug = $post['slug'];
|
$slug = $post['slug'];
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( $page50 && $slug) $tpl = $config['file_page50_slug'];
|
if ( $page50 && $slug) $tpl = $config['file_page50_slug'];
|
||||||
|
@ -72,7 +72,7 @@ function ebmlDecodeInt($data, $signed=FALSE, $carryIn=0) {
|
|||||||
if (strlen($data) > 8) throw new Exception('not supported: integer too long');
|
if (strlen($data) > 8) throw new Exception('not supported: integer too long');
|
||||||
for ($i = 0; $i < strlen($data); $i++) {
|
for ($i = 0; $i < strlen($data); $i++) {
|
||||||
if ($n > (PHP_INT_MAX >> 8) || $n < ((-PHP_INT_MAX-1) >> 8)) {
|
if ($n > (PHP_INT_MAX >> 8) || $n < ((-PHP_INT_MAX-1) >> 8)) {
|
||||||
$n = floatval($n);
|
$n = (float)$n;
|
||||||
}
|
}
|
||||||
$n = $n * 0x100 + ord($data[$i]);
|
$n = $n * 0x100 + ord($data[$i]);
|
||||||
if ($i == 0 && $signed && ($n & 0x80) != 0) {
|
if ($i == 0 && $signed && ($n & 0x80) != 0) {
|
||||||
@ -258,7 +258,7 @@ class EBMLReader {
|
|||||||
// Range shift for signed integers
|
// Range shift for signed integers
|
||||||
if ($signed) {
|
if ($signed) {
|
||||||
if ($n == PHP_INT_MAX) {
|
if ($n == PHP_INT_MAX) {
|
||||||
$n = floatval($n);
|
$n = (float)$n;
|
||||||
}
|
}
|
||||||
$n++;
|
$n++;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Portions of this file are derived from Tinyboard code.
|
// Portions of this file are derived from Tinyboard code.
|
||||||
function postHandler($post) {
|
function postHandler($post) {
|
||||||
global $board, $config;
|
global $board, $config;
|
||||||
if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm' || $file->extension == 'mp4') {
|
if ($post->has_file) foreach ($post->files as &$file) if ($file->extension === 'webm' || $file->extension === 'mp4') {
|
||||||
if ($config['webm']['use_ffmpeg']) {
|
if ($config['webm']['use_ffmpeg']) {
|
||||||
require_once dirname(__FILE__) . '/ffmpeg.php';
|
require_once dirname(__FILE__) . '/ffmpeg.php';
|
||||||
$webminfo = get_webm_info($file->file_path);
|
$webminfo = get_webm_info($file->file_path);
|
||||||
@ -51,7 +51,7 @@ function postHandler($post) {
|
|||||||
if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
|
if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
|
||||||
$file->width = $videoDetails['width'];
|
$file->width = $videoDetails['width'];
|
||||||
$file->height = $videoDetails['height'];
|
$file->height = $videoDetails['height'];
|
||||||
if ($file->thumb != 'file' && $file->thumb != 'spoiler') {
|
if ($file->thumb !== 'file' && $file->thumb !== 'spoiler') {
|
||||||
$file = set_thumbnail_dimensions($post, $file);
|
$file = set_thumbnail_dimensions($post, $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,8 +64,8 @@ function set_thumbnail_dimensions($post,$file) {
|
|||||||
$tn_maxw = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
|
$tn_maxw = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
|
||||||
$tn_maxh = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
|
$tn_maxh = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
|
||||||
if ($file->width > $tn_maxw || $file->height > $tn_maxh) {
|
if ($file->width > $tn_maxw || $file->height > $tn_maxh) {
|
||||||
$file->thumbwidth = min($tn_maxw, intval(round($file->width * $tn_maxh / $file->height)));
|
$file->thumbwidth = min($tn_maxw, (int)round($file->width * $tn_maxh / $file->height));
|
||||||
$file->thumbheight = min($tn_maxh, intval(round($file->height * $tn_maxw / $file->width)));
|
$file->thumbheight = min($tn_maxh, (int)round($file->height * $tn_maxw / $file->width));
|
||||||
} else {
|
} else {
|
||||||
$file->thumbwidth = $file->width;
|
$file->thumbwidth = $file->width;
|
||||||
$file->thumbheight = $file->height;
|
$file->thumbheight = $file->height;
|
||||||
|
2
mod.php
2
mod.php
@ -4,7 +4,7 @@
|
|||||||
* Copyright (c) 2010-2018 Tinyboard Development Group
|
* Copyright (c) 2010-2018 Tinyboard Development Group
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'inc/functions.php';
|
require 'inc/functions.php';
|
||||||
|
|
||||||
if ($config['debug'])
|
if ($config['debug'])
|
||||||
$parse_start_time = microtime(true);
|
$parse_start_time = microtime(true);
|
||||||
|
111
post.php
111
post.php
@ -3,7 +3,7 @@
|
|||||||
* Copyright (c) 2010-2018 Tinyboard Development Group
|
* Copyright (c) 2010-2018 Tinyboard Development Group
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'inc/functions.php';
|
require 'inc/functions.php';
|
||||||
require_once 'inc/anti-bot.php';
|
require_once 'inc/anti-bot.php';
|
||||||
require_once 'inc/bans.php';
|
require_once 'inc/bans.php';
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
$password = &$_POST['password'];
|
$password = &$_POST['password'];
|
||||||
|
|
||||||
if ($password == '')
|
if ($password === '')
|
||||||
error($config['error']['invalidpassword']);
|
error($config['error']['invalidpassword']);
|
||||||
|
|
||||||
$delete = array();
|
$delete = array();
|
||||||
@ -35,7 +35,7 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
// Check if board locked
|
// Check if board locked
|
||||||
if (!$is_mod && $config['board_locked'])
|
if (!$is_mod && $config['board_locked'])
|
||||||
error("Board is locked");
|
error('Board is locked');
|
||||||
|
|
||||||
// Check if banned
|
// Check if banned
|
||||||
checkBan($board['uri']);
|
checkBan($board['uri']);
|
||||||
@ -48,24 +48,24 @@ if (isset($_POST['delete'])) {
|
|||||||
error($config['error']['nodelete']);
|
error($config['error']['nodelete']);
|
||||||
|
|
||||||
foreach ($delete as &$id) {
|
foreach ($delete as &$id) {
|
||||||
$query = prepare(sprintf("SELECT `id`,`thread`,`time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
$query = prepare(sprintf('SELECT `id`,`thread`,`time`,`password` FROM ``posts_%s`` WHERE `id` = :id', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
if ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$thread = false;
|
$thread = false;
|
||||||
if ($config['user_moderation'] && $post['thread']) {
|
if ($config['user_moderation'] && $post['thread']) {
|
||||||
$thread_query = prepare(sprintf("SELECT `time`,`password` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
$thread_query = prepare(sprintf('SELECT `time`,`password` FROM ``posts_%s`` WHERE `id` = :id', $board['uri']));
|
||||||
$thread_query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
|
$thread_query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
|
||||||
$thread_query->execute() or error(db_error($query));
|
$thread_query->execute() or error(db_error($query));
|
||||||
|
|
||||||
$thread = $thread_query->fetch(PDO::FETCH_ASSOC);
|
$thread = $thread_query->fetch(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($password != '' && $post['password'] != $password && (!$thread || $thread['password'] != $password))
|
if ($password !== '' && $post['password'] !== $password && (!$thread || $thread['password'] !== $password))
|
||||||
error($config['error']['invalidpassword']);
|
error($config['error']['invalidpassword']);
|
||||||
|
|
||||||
if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] != $password)) {
|
if ($post['time'] > time() - $config['delete_time'] && (!$thread || $thread['password'] !== $password)) {
|
||||||
error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time'])));
|
error(sprintf($config['error']['delete_too_soon'], until($post['time'] + $config['delete_time'])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
// Check if board locked
|
// Check if board locked
|
||||||
if (!$is_mod && $config['board_locked'])
|
if (!$is_mod && $config['board_locked'])
|
||||||
error("Board is locked");
|
error('Board is locked');
|
||||||
|
|
||||||
// Check if banned
|
// Check if banned
|
||||||
checkBan($board['uri']);
|
checkBan($board['uri']);
|
||||||
@ -150,7 +150,7 @@ if (isset($_POST['delete'])) {
|
|||||||
markup($reason);
|
markup($reason);
|
||||||
|
|
||||||
foreach ($report as &$id) {
|
foreach ($report as &$id) {
|
||||||
$query = prepare(sprintf("SELECT `id`, `thread` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
$query = prepare(sprintf('SELECT `id`, `thread` FROM ``posts_%s`` WHERE `id` = :id', $board['uri']));
|
||||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ if (isset($_POST['delete'])) {
|
|||||||
'/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '') .
|
'/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '') .
|
||||||
' for "' . $reason . '"'
|
' for "' . $reason . '"'
|
||||||
);
|
);
|
||||||
$query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)");
|
$query = prepare('INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)');
|
||||||
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
||||||
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
|
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
|
||||||
$query->bindValue(':board', $board['uri'], PDO::PARAM_STR);
|
$query->bindValue(':board', $board['uri'], PDO::PARAM_STR);
|
||||||
@ -195,7 +195,7 @@ if (isset($_POST['delete'])) {
|
|||||||
error($config['error']['noboard']);
|
error($config['error']['noboard']);
|
||||||
|
|
||||||
if (!$is_mod && $config['board_locked'])
|
if (!$is_mod && $config['board_locked'])
|
||||||
error("Board is locked");
|
error('Board is locked');
|
||||||
|
|
||||||
if (!isset($_POST['name']))
|
if (!isset($_POST['name']))
|
||||||
$_POST['name'] = $config['anonymous'];
|
$_POST['name'] = $config['anonymous'];
|
||||||
@ -233,8 +233,8 @@ if (isset($_POST['delete'])) {
|
|||||||
error($config['error']['captcha']);
|
error($config['error']['captcha']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(($post['op'] && $_POST['post'] == $config['button_newtopic']) ||
|
if (!(($post['op'] && $_POST['post'] === $config['button_newtopic']) ||
|
||||||
(!$post['op'] && $_POST['post'] == $config['button_reply'])))
|
(!$post['op'] && $_POST['post'] === $config['button_reply'])))
|
||||||
error($config['error']['bot']);
|
error($config['error']['bot']);
|
||||||
|
|
||||||
// Check the referrer
|
// Check the referrer
|
||||||
@ -275,7 +275,7 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
//Check if thread exists
|
//Check if thread exists
|
||||||
if (!$post['op']) {
|
if (!$post['op']) {
|
||||||
$query = prepare(sprintf("SELECT `sticky`,`locked`,`cycle`,`sage`,`slug` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri']));
|
$query = prepare(sprintf('SELECT `sticky`,`locked`,`cycle`,`sage`,`slug` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1', $board['uri']));
|
||||||
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
|
$query->bindValue(':id', $post['thread'], PDO::PARAM_INT);
|
||||||
$query->execute() or error(db_error());
|
$query->execute() or error(db_error());
|
||||||
|
|
||||||
@ -372,7 +372,7 @@ if (isset($_POST['delete'])) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous'];
|
$post['name'] = $_POST['name'] !== '' ? $_POST['name'] : $config['anonymous'];
|
||||||
$post['subject'] = $_POST['subject'];
|
$post['subject'] = $_POST['subject'];
|
||||||
$post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email']));
|
$post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email']));
|
||||||
$post['body'] = $_POST['body'];
|
$post['body'] = $_POST['body'];
|
||||||
@ -381,7 +381,7 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
if (!($post['has_file'] || isset($post['embed'])) || (($post['op'] && $config['force_body_op']) || (!$post['op'] && $config['force_body']))) {
|
if (!($post['has_file'] || isset($post['embed'])) || (($post['op'] && $config['force_body_op']) || (!$post['op'] && $config['force_body']))) {
|
||||||
$stripped_whitespace = preg_replace('/[\s]/u', '', $post['body']);
|
$stripped_whitespace = preg_replace('/[\s]/u', '', $post['body']);
|
||||||
if ($stripped_whitespace == '')
|
if ($stripped_whitespace === '')
|
||||||
error($config['error']['tooshort_body']);
|
error($config['error']['tooshort_body']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,20 +393,20 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
$numposts = numPosts($post['thread']);
|
$numposts = numPosts($post['thread']);
|
||||||
|
|
||||||
if ($config['reply_hard_limit'] != 0 && $config['reply_hard_limit'] <= $numposts['replies'])
|
if ($config['reply_hard_limit'] !== 0 && $config['reply_hard_limit'] <= $numposts['replies'])
|
||||||
error($config['error']['reply_hard_limit']);
|
error($config['error']['reply_hard_limit']);
|
||||||
|
|
||||||
if ($post['has_file'] && $config['image_hard_limit'] != 0 && $config['image_hard_limit'] <= $numposts['images'])
|
if ($post['has_file'] && $config['image_hard_limit'] !== 0 && $config['image_hard_limit'] <= $numposts['images'])
|
||||||
error($config['error']['image_hard_limit']);
|
error($config['error']['image_hard_limit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($post['has_file']) {
|
if ($post['has_file']) {
|
||||||
// Determine size sanity
|
// Determine size sanity
|
||||||
$size = 0;
|
$size = 0;
|
||||||
if ($config['multiimage_method'] == 'split') {
|
if ($config['multiimage_method'] === 'split') {
|
||||||
foreach ($_FILES as $key => $file)
|
foreach ($_FILES as $key => $file)
|
||||||
$size += $file['size'];
|
$size += $file['size'];
|
||||||
} elseif ($config['multiimage_method'] == 'each') {
|
} elseif ($config['multiimage_method'] === 'each') {
|
||||||
foreach ($_FILES as $key => $file) {
|
foreach ($_FILES as $key => $file) {
|
||||||
if ($file['size'] > $size)
|
if ($file['size'] > $size)
|
||||||
$size = $file['size'];
|
$size = $file['size'];
|
||||||
@ -427,7 +427,7 @@ if (isset($_POST['delete'])) {
|
|||||||
$post['capcode'] = false;
|
$post['capcode'] = false;
|
||||||
|
|
||||||
if ($mod && preg_match('/^((.+) )?## (.+)$/', $post['name'], $matches)) {
|
if ($mod && preg_match('/^((.+) )?## (.+)$/', $post['name'], $matches)) {
|
||||||
$name = $matches[2] != '' ? $matches[2] : $config['anonymous'];
|
$name = $matches[2] !== '' ? $matches[2] : $config['anonymous'];
|
||||||
$cap = $matches[3];
|
$cap = $matches[3];
|
||||||
|
|
||||||
if (isset($config['mod']['capcode'][$mod['type']])) {
|
if (isset($config['mod']['capcode'][$mod['type']])) {
|
||||||
@ -447,10 +447,10 @@ if (isset($_POST['delete'])) {
|
|||||||
$post['trip'] = isset($trip[1]) ? $trip[1] : ''; // XX: Tripcodes
|
$post['trip'] = isset($trip[1]) ? $trip[1] : ''; // XX: Tripcodes
|
||||||
|
|
||||||
$noko = false;
|
$noko = false;
|
||||||
if (strtolower($post['email']) == 'noko') {
|
if (strtolower($post['email']) === 'noko') {
|
||||||
$noko = true;
|
$noko = true;
|
||||||
$post['email'] = '';
|
$post['email'] = '';
|
||||||
} elseif (strtolower($post['email']) == 'nonoko'){
|
} elseif (strtolower($post['email']) === 'nonoko'){
|
||||||
$noko = false;
|
$noko = false;
|
||||||
$post['email'] = '';
|
$post['email'] = '';
|
||||||
} else
|
} else
|
||||||
@ -531,7 +531,8 @@ if (isset($_POST['delete'])) {
|
|||||||
if (strpos($ip, ':') !== false) {
|
if (strpos($ip, ':') !== false) {
|
||||||
if (strpos($ip, '.') > 0)
|
if (strpos($ip, '.') > 0)
|
||||||
$ip = substr($ip, strrpos($ip, ':')+1);
|
$ip = substr($ip, strrpos($ip, ':')+1);
|
||||||
else return $ip; //native ipv6
|
else
|
||||||
|
return $ip; //native ipv6
|
||||||
}
|
}
|
||||||
$iparr = array_pad(explode('.', $ip), 4, 0);
|
$iparr = array_pad(explode('.', $ip), 4, 0);
|
||||||
$part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16);
|
$part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16);
|
||||||
@ -541,8 +542,8 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
if ($country_code = geoip\geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) {
|
if ($country_code = geoip\geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) {
|
||||||
if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2')))
|
if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2')))
|
||||||
$post['body'] .= "\n<tinyboard flag>".strtolower($country_code)."</tinyboard>".
|
$post['body'] .= "\n<tinyboard flag>" . strtolower($country_code) . '</tinyboard>'.
|
||||||
"\n<tinyboard flag alt>".geoip\geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))."</tinyboard>";
|
"\n<tinyboard flag alt>" . geoip\geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR'])) . '</tinyboard>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,17 +556,16 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
$flag_alt = isset($user_flag_alt) ? $user_flag_alt : $config['user_flags'][$user_flag];
|
$flag_alt = isset($user_flag_alt) ? $user_flag_alt : $config['user_flags'][$user_flag];
|
||||||
|
|
||||||
$post['body'] .= "\n<tinyboard flag>" . strtolower($user_flag) . "</tinyboard>" .
|
$post['body'] .= "\n<tinyboard flag>" . strtolower($user_flag) . '</tinyboard>' .
|
||||||
"\n<tinyboard flag alt>" . $flag_alt . "</tinyboard>";
|
"\n<tinyboard flag alt>" . $flag_alt . '</tinyboard>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['allowed_tags'] && $post['op'] && isset($_POST['tag']) && isset($config['allowed_tags'][$_POST['tag']])) {
|
if ($config['allowed_tags'] && $post['op'] && isset($_POST['tag']) && isset($config['allowed_tags'][$_POST['tag']]))
|
||||||
$post['body'] .= "\n<tinyboard tag>" . $_POST['tag'] . "</tinyboard>";
|
$post['body'] .= "\n<tinyboard tag>" . $_POST['tag'] . '</tinyboard>';
|
||||||
}
|
|
||||||
|
|
||||||
if ($config['proxy_save'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
if ($config['proxy_save'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||||
$proxy = preg_replace("/[^0-9a-fA-F.,: ]/", '', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
$proxy = preg_replace("/[^0-9a-fA-F.,: ]/", '', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||||
$post['body'] .= "\n<tinyboard proxy>".$proxy."</tinyboard>";
|
$post['body'] .= "\n<tinyboard proxy>" . $proxy . '</tinyboard>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset
|
$post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset
|
||||||
@ -582,8 +582,7 @@ if (isset($_POST['delete'])) {
|
|||||||
if ($post['op'] && $config['allowed_ext_op']) {
|
if ($post['op'] && $config['allowed_ext_op']) {
|
||||||
if (!in_array($file['extension'], $config['allowed_ext_op']))
|
if (!in_array($file['extension'], $config['allowed_ext_op']))
|
||||||
error($config['error']['unknownext']);
|
error($config['error']['unknownext']);
|
||||||
}
|
} elseif (!in_array($file['extension'], $config['allowed_ext']) && !in_array($file['extension'], $config['allowed_ext_files']))
|
||||||
elseif (!in_array($file['extension'], $config['allowed_ext']) && !in_array($file['extension'], $config['allowed_ext_files']))
|
|
||||||
error($config['error']['unknownext']);
|
error($config['error']['unknownext']);
|
||||||
|
|
||||||
$file['is_an_image'] = !in_array($file['extension'], $config['allowed_ext_files']);
|
$file['is_an_image'] = !in_array($file['extension'], $config['allowed_ext_files']);
|
||||||
@ -597,7 +596,7 @@ if (isset($_POST['delete'])) {
|
|||||||
error($config['error']['nomove']);
|
error($config['error']['nomove']);
|
||||||
|
|
||||||
if ($md5cmd) {
|
if ($md5cmd) {
|
||||||
$output = shell_exec_error($md5cmd . " " . escapeshellarg($upload));
|
$output = shell_exec_error($md5cmd . ' ' . escapeshellarg($upload));
|
||||||
$output = explode(' ', $output);
|
$output = explode(' ', $output);
|
||||||
$hash = $output[0];
|
$hash = $output[0];
|
||||||
}
|
}
|
||||||
@ -609,10 +608,9 @@ if (isset($_POST['delete'])) {
|
|||||||
$allhashes .= $hash;
|
$allhashes .= $hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count ($post['files']) == 1) {
|
if (count($post['files']) === 1) {
|
||||||
$post['filehash'] = $hash;
|
$post['filehash'] = $hash;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$post['filehash'] = md5($allhashes);
|
$post['filehash'] = md5($allhashes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -649,10 +647,10 @@ if (isset($_POST['delete'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($config['convert_auto_orient'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) {
|
if ($config['convert_auto_orient'] && ($file['extension'] === 'jpg' || $file['extension'] === 'jpeg')) {
|
||||||
// The following code corrects the image orientation.
|
// The following code corrects the image orientation.
|
||||||
// Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered.
|
// Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered.
|
||||||
if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool']) && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')))) {
|
if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool']) && ($file['extension'] === 'jpg' || $file['extension'] === 'jpeg')))) {
|
||||||
if (in_array($config['thumb_method'], array('convert', 'convert+gifsicle', 'gm', 'gm+gifsicle'))) {
|
if (in_array($config['thumb_method'], array('convert', 'convert+gifsicle', 'gm', 'gm+gifsicle'))) {
|
||||||
$exif = @exif_read_data($file['tmp_name']);
|
$exif = @exif_read_data($file['tmp_name']);
|
||||||
$gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle'));
|
$gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle'));
|
||||||
@ -707,7 +705,7 @@ if (isset($_POST['delete'])) {
|
|||||||
} elseif ($config['minimum_copy_resize'] &&
|
} elseif ($config['minimum_copy_resize'] &&
|
||||||
$image->size->width <= $config['thumb_width'] &&
|
$image->size->width <= $config['thumb_width'] &&
|
||||||
$image->size->height <= $config['thumb_height'] &&
|
$image->size->height <= $config['thumb_height'] &&
|
||||||
$file['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'])) {
|
$file['extension'] === ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'])) {
|
||||||
|
|
||||||
// Copy, because there's nothing to resize
|
// Copy, because there's nothing to resize
|
||||||
copy($file['tmp_name'], $file['thumb']);
|
copy($file['tmp_name'], $file['thumb']);
|
||||||
@ -729,7 +727,7 @@ if (isset($_POST['delete'])) {
|
|||||||
$thumb->_destroy();
|
$thumb->_destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['redraw_image'] || (!@$file['exif_stripped'] && $config['strip_exif'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg'))) {
|
if ($config['redraw_image'] || (!@$file['exif_stripped'] && $config['strip_exif'] && ($file['extension'] === 'jpg' || $file['extension'] === 'jpeg'))) {
|
||||||
if (!$config['redraw_image'] && $config['use_exiftool']) {
|
if (!$config['redraw_image'] && $config['use_exiftool']) {
|
||||||
if($error = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' .
|
if($error = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' .
|
||||||
escapeshellarg($file['tmp_name'])))
|
escapeshellarg($file['tmp_name'])))
|
||||||
@ -752,22 +750,21 @@ if (isset($_POST['delete'])) {
|
|||||||
$file['thumbheight'] = $size[1];
|
$file['thumbheight'] = $size[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['tesseract_ocr'] && $file['thumb'] != 'file') { // Let's OCR it!
|
if ($config['tesseract_ocr'] && $file['thumb'] !== 'file') { // Let's OCR it!
|
||||||
$fname = $file['tmp_name'];
|
$fname = $file['tmp_name'];
|
||||||
|
|
||||||
if ($file['height'] > 500 || $file['width'] > 500) {
|
if ($file['height'] > 500 || $file['width'] > 500) {
|
||||||
$fname = $file['thumb'];
|
$fname = $file['thumb'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fname == 'spoiler') { // We don't have that much CPU time, do we?
|
if ($fname === 'spoiler') { // We don't have that much CPU time, do we?
|
||||||
}
|
} else {
|
||||||
else {
|
$tmpname = 'tmp/tesseract/' . rand(0,10000000);
|
||||||
$tmpname = "tmp/tesseract/".rand(0,10000000);
|
|
||||||
|
|
||||||
// Preprocess command is an ImageMagick b/w quantization
|
// Preprocess command is an ImageMagick b/w quantization
|
||||||
$error = shell_exec_error(sprintf($config['tesseract_preprocess_command'], escapeshellarg($fname)) . " | " .
|
$error = shell_exec_error(sprintf($config['tesseract_preprocess_command'], escapeshellarg($fname)) . ' | ' .
|
||||||
'tesseract stdin '.escapeshellarg($tmpname).' '.$config['tesseract_params']);
|
'tesseract stdin '.escapeshellarg($tmpname).' '.$config['tesseract_params']);
|
||||||
$tmpname .= ".txt";
|
$tmpname .= '.txt';
|
||||||
|
|
||||||
$value = @file_get_contents($tmpname);
|
$value = @file_get_contents($tmpname);
|
||||||
@unlink($tmpname);
|
@unlink($tmpname);
|
||||||
@ -775,7 +772,7 @@ if (isset($_POST['delete'])) {
|
|||||||
if ($value && trim($value)) {
|
if ($value && trim($value)) {
|
||||||
// This one has an effect, that the body is appended to a post body. So you can write a correct
|
// This one has an effect, that the body is appended to a post body. So you can write a correct
|
||||||
// spamfilter.
|
// spamfilter.
|
||||||
$post['body_nomarkup'] .= "<tinyboard ocr image $key>".htmlspecialchars($value)."</tinyboard>";
|
$post['body_nomarkup'] .= "<tinyboard ocr image $key>" . htmlspecialchars($value) . '</tinyboard>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -838,7 +835,7 @@ if (isset($_POST['delete'])) {
|
|||||||
$file['file_path'] = $file['file'];
|
$file['file_path'] = $file['file'];
|
||||||
$file['thumb_path'] = $file['thumb'];
|
$file['thumb_path'] = $file['thumb'];
|
||||||
$file['file'] = mb_substr($file['file'], mb_strlen($board['dir'] . $config['dir']['img']));
|
$file['file'] = mb_substr($file['file'], mb_strlen($board['dir'] . $config['dir']['img']));
|
||||||
if ($file['is_an_image'] && $file['thumb'] != 'spoiler')
|
if ($file['is_an_image'] && $file['thumb'] !== 'spoiler')
|
||||||
$file['thumb'] = mb_substr($file['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb']));
|
$file['thumb'] = mb_substr($file['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -887,7 +884,7 @@ if (isset($_POST['delete'])) {
|
|||||||
query('INSERT INTO ``cites`` VALUES ' . implode(', ', $insert_rows)) or error(db_error());
|
query('INSERT INTO ``cites`` VALUES ' . implode(', ', $insert_rows)) or error(db_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$post['op'] && strtolower($post['email']) != 'sage' && !$thread['sage'] && ($config['reply_limit'] == 0 || $numposts['replies']+1 < $config['reply_limit'])) {
|
if (!$post['op'] && strtolower($post['email']) !== 'sage' && !$thread['sage'] && ($config['reply_limit'] === 0 || $numposts['replies']+1 < $config['reply_limit'])) {
|
||||||
bumpThread($post['thread']);
|
bumpThread($post['thread']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,26 +978,26 @@ if (isset($_POST['delete'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($ban)) {
|
if (!isset($ban)) {
|
||||||
error(_("That ban doesn't exist or is not for you."));
|
error(_('That ban doesn\'t exist or is not for you.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ban['expires'] && $ban['expires'] - $ban['created'] <= $config['ban_appeals_min_length']) {
|
if ($ban['expires'] && $ban['expires'] - $ban['created'] <= $config['ban_appeals_min_length']) {
|
||||||
error(_("You cannot appeal a ban of this length."));
|
error(_('You cannot appeal a ban of this length.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = query("SELECT `denied` FROM ``ban_appeals`` WHERE `ban_id` = $ban_id") or error(db_error());
|
$query = query("SELECT `denied` FROM ``ban_appeals`` WHERE `ban_id` = $ban_id") or error(db_error());
|
||||||
$ban_appeals = $query->fetchAll(PDO::FETCH_COLUMN);
|
$ban_appeals = $query->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
if (count($ban_appeals) >= $config['ban_appeals_max']) {
|
if (count($ban_appeals) >= $config['ban_appeals_max']) {
|
||||||
error(_("You cannot appeal this ban again."));
|
error(_('You cannot appeal this ban again.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($ban_appeals as $is_denied) {
|
foreach ($ban_appeals as $is_denied) {
|
||||||
if (!$is_denied)
|
if (!$is_denied)
|
||||||
error(_("There is already a pending appeal for this ban."));
|
error(_('There is already a pending appeal for this ban.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = prepare("INSERT INTO ``ban_appeals`` VALUES (NULL, :ban_id, :time, :message, 0)");
|
$query = prepare('INSERT INTO ``ban_appeals`` VALUES (NULL, :ban_id, :time, :message, 0)');
|
||||||
$query->bindValue(':ban_id', $ban_id, PDO::PARAM_INT);
|
$query->bindValue(':ban_id', $ban_id, PDO::PARAM_INT);
|
||||||
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
$query->bindValue(':time', time(), PDO::PARAM_INT);
|
||||||
$query->bindValue(':message', $_POST['appeal']);
|
$query->bindValue(':message', $_POST['appeal']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user