From 9cee5f6c612974947669ba9ebabe64786d73c9ce Mon Sep 17 00:00:00 2001 From: kaf Date: Thu, 25 Sep 2014 20:59:24 +0000 Subject: [bugfix]ban appeals (was also present in tinyboard) --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 2e16c419..357666d6 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -739,7 +739,7 @@ function displayBan($ban) { $pending_appeal = false; 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)) { if ($ban_appeal['denied']) { $denied_appeals[] = $ban_appeal['time']; -- cgit v1.3 From 8b9932218ffa0e53b05cad5bc769f9317687e6da Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 6 Oct 2014 03:37:13 +0900 Subject: add forward-confirmed reverse DNS --- inc/config.php | 5 ++++- inc/functions.php | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index 1a75cad0..bd5c5db3 100644 --- a/inc/config.php +++ b/inc/config.php @@ -66,7 +66,10 @@ // Use `host` via shell_exec() to lookup hostnames, avoiding query timeouts. May not work on your system. // Requires safe_mode to be disabled. $config['dns_system'] = false; - + + // Check validity of the reverse DNS of IP addresses. Highly recommended. + $config['fcrdns'] = true; + // When executing most command-line tools (such as `convert` for ImageMagick image processing), add this // to the environment path (seperated by :). $config['shell_path'] = '/usr/local/bin'; diff --git a/inc/functions.php b/inc/functions.php index 357666d6..8c5f46b9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2265,6 +2265,7 @@ function rDNS($ip_addr) { if (!$config['dns_system']) { $host = gethostbyaddr($ip_addr); + $isip = filter_var($host, FILTER_VALIDATE_IP); } else { $resp = shell_exec_error('host -W 1 ' . $ip_addr); if (preg_match('/domain name pointer ([^\s]+)$/', $resp, $m)) @@ -2273,6 +2274,10 @@ function rDNS($ip_addr) { $host = $ip_addr; } + if ($config['fcrdns'] && !$isip && gethostbyname($host) != $ip_addr) { + $host = $ip_addr; + } + if ($config['cache']['enabled']) cache::set('rdns_' . $ip_addr, $host); -- cgit v1.3 From 1e95e588110516ed0d89ddb8546548a6324b3e1a Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 6 Oct 2014 04:08:10 +0900 Subject: don't break if dns_system is true --- inc/functions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 8c5f46b9..f45e9055 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2265,7 +2265,6 @@ function rDNS($ip_addr) { if (!$config['dns_system']) { $host = gethostbyaddr($ip_addr); - $isip = filter_var($host, FILTER_VALIDATE_IP); } else { $resp = shell_exec_error('host -W 1 ' . $ip_addr); if (preg_match('/domain name pointer ([^\s]+)$/', $resp, $m)) @@ -2274,6 +2273,8 @@ function rDNS($ip_addr) { $host = $ip_addr; } + $isip = filter_var($host, FILTER_VALIDATE_IP); + if ($config['fcrdns'] && !$isip && gethostbyname($host) != $ip_addr) { $host = $ip_addr; } -- cgit v1.3 From aba8d27ace9b1b95bb7cc71ae0424f0bc8f20809 Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 6 Oct 2014 04:30:32 +0900 Subject: wasn't aware of DNS function --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index f45e9055..3802d19d 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2275,7 +2275,7 @@ function rDNS($ip_addr) { $isip = filter_var($host, FILTER_VALIDATE_IP); - if ($config['fcrdns'] && !$isip && gethostbyname($host) != $ip_addr) { + if ($config['fcrdns'] && !$isip && DNS($host) != $ip_addr) { $host = $ip_addr; } -- cgit v1.3 From c7351dff091583d79688b3ee74099f374a85efdb Mon Sep 17 00:00:00 2001 From: wopot Date: Mon, 6 Oct 2014 17:50:05 +0200 Subject: 4 times "elseif" is not the way and precalc. value sometimes help if well commentent --- inc/functions.php | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 3802d19d..0454a129 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -679,36 +679,38 @@ function listBoards($just_uri = false) { function until($timestamp) { $difference = $timestamp - time(); - if ($difference < 60) { + switch(TRUE){ + case ($difference < 60): return $difference . ' ' . ngettext('second', 'seconds', $difference); - } elseif ($difference < 60*60) { + case ($difference < 3600): //60*60 = 3600 return ($num = round($difference/(60))) . ' ' . ngettext('minute', 'minutes', $num); - } elseif ($difference < 60*60*24) { - return ($num = round($difference/(60*60))) . ' ' . ngettext('hour', 'hours', $num); - } elseif ($difference < 60*60*24*7) { - return ($num = round($difference/(60*60*24))) . ' ' . ngettext('day', 'days', $num); - } elseif ($difference < 60*60*24*365) { - return ($num = round($difference/(60*60*24*7))) . ' ' . ngettext('week', 'weeks', $num); + case ($difference < 86400): //60*60*24 = 86400 + return ($num = round($difference/(3600))) . ' ' . ngettext('hour', 'hours', $num); + case ($difference < 604800): //60*60*24*7 = 604800 + return ($num = round($difference/(86400))) . ' ' . ngettext('day', 'days', $num); + case ($difference < 31536000): //60*60*24*365 = 31536000 + return ($num = round($difference/(604800))) . ' ' . ngettext('week', 'weeks', $num); + default: + return ($num = round($difference/(31536000))) . ' ' . ngettext('year', 'years', $num); } - - return ($num = round($difference/(60*60*24*365))) . ' ' . ngettext('year', 'years', $num); } function ago($timestamp) { $difference = time() - $timestamp; - if ($difference < 60) { + switch(TRUE){ + case ($difference < 60) : return $difference . ' ' . ngettext('second', 'seconds', $difference); - } elseif ($difference < 60*60) { + case ($difference < 3600): //60*60 = 3600 return ($num = round($difference/(60))) . ' ' . ngettext('minute', 'minutes', $num); - } elseif ($difference < 60*60*24) { - return ($num = round($difference/(60*60))) . ' ' . ngettext('hour', 'hours', $num); - } elseif ($difference < 60*60*24*7) { - return ($num = round($difference/(60*60*24))) . ' ' . ngettext('day', 'days', $num); - } elseif ($difference < 60*60*24*365) { - return ($num = round($difference/(60*60*24*7))) . ' ' . ngettext('week', 'weeks', $num); + case ($difference < 86400): //60*60*24 = 86400 + return ($num = round($difference/(3600))) . ' ' . ngettext('hour', 'hours', $num); + case ($difference < 604800): //60*60*24*7 = 604800 + return ($num = round($difference/(86400))) . ' ' . ngettext('day', 'days', $num); + case ($difference < 31536000): //60*60*24*365 = 31536000 + return ($num = round($difference/(604800))) . ' ' . ngettext('week', 'weeks', $num); + default: + return ($num = round($difference/(31536000))) . ' ' . ngettext('year', 'years', $num); } - - return ($num = round($difference/(60*60*24*365))) . ' ' . ngettext('year', 'years', $num); } function displayBan($ban) { -- cgit v1.3 From dfd05e88f9905bbd644e1847fa8ec383a9fc8857 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 9 Oct 2014 03:57:18 +0200 Subject: possible fix of themes` interactions --- inc/functions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) mode change 100644 => 100755 inc/functions.php (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php old mode 100644 new mode 100755 index 0454a129..8f33fdb6 --- a/inc/functions.php +++ b/inc/functions.php @@ -345,10 +345,14 @@ function rebuildThemes($action, $boardname = false) { $query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error()); while ($theme = $query->fetch(PDO::FETCH_ASSOC)) { + // Restore them + $config = $_config; + $board = $_board; + rebuildTheme($theme['theme'], $action, $boardname); } - // Restore them + // Restore them again $config = $_config; $board = $_board; } -- cgit v1.3 From 3a552e5b7696d19fbb9390f9ee7aad4ddc2f223e Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 9 Oct 2014 04:09:30 +0200 Subject: hopefully fix locales --- inc/functions.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 8f33fdb6..06370d32 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -335,7 +335,7 @@ function create_antibot($board, $thread = null) { } function rebuildThemes($action, $boardname = false) { - global $config, $board; + global $config, $board, $current_locale; // Save the global variables $_config = $config; @@ -347,7 +347,14 @@ function rebuildThemes($action, $boardname = false) { while ($theme = $query->fetch(PDO::FETCH_ASSOC)) { // Restore them $config = $_config; - $board = $_board; + $board = $_board; + + // Reload the locale + if ($config['locale'] != $current_locale) { + $current_locale = $config['locale']; + init_locale($config['locale'], $error); + } + rebuildTheme($theme['theme'], $action, $boardname); } @@ -355,6 +362,12 @@ function rebuildThemes($action, $boardname = false) { // Restore them again $config = $_config; $board = $_board; + + // Reload the locale + if ($config['locale'] != $current_locale) { + $current_locale = $config['locale']; + init_locale($config['locale'], $error); + } } -- cgit v1.3 From 0ab8890b67f58c8323fcbe6468dc9c580a4602ec Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 26 Feb 2015 21:44:39 +0100 Subject: tools/rebuild: show currently rebuilded themes --- inc/functions.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 06370d32..ef071592 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -355,8 +355,15 @@ function rebuildThemes($action, $boardname = false) { init_locale($config['locale'], $error); } + if (PHP_SAPI === 'cli') { + echo "Rebuilding theme ".$theme['theme']."... "; + } rebuildTheme($theme['theme'], $action, $boardname); + + if (PHP_SAPI === 'cli') { + echo "done\n"; + } } // Restore them again @@ -583,8 +590,8 @@ function file_write($path, $data, $simple = false, $skip_purge = false) { if ($bytes & ~0x3ff) { // if ($bytes >= 1024) if (file_put_contents($gzpath, gzencode($data), $simple ? 0 : LOCK_EX) === false) error("Unable to write to file: $gzpath"); - if (!touch($gzpath, filemtime($path), fileatime($path))) - error("Unable to touch file: $gzpath"); + //if (!touch($gzpath, filemtime($path), fileatime($path))) + // error("Unable to touch file: $gzpath"); } else { @unlink($gzpath); -- cgit v1.3 From bffe03e65171a4ba7da40573d9f0131b58e9cb48 Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 27 Feb 2015 21:16:03 +0100 Subject: rearrange config processing a bit --- inc/functions.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index ef071592..25362a62 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -124,10 +124,6 @@ function loadConfig() { init_locale($config['locale'], $error); } - if (!isset($__version)) - $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; - $config['version'] = $__version; - date_default_timezone_set($config['timezone']); if (!isset($config['global_message'])) @@ -136,6 +132,7 @@ function loadConfig() { if (!isset($config['post_url'])) $config['post_url'] = $config['root'] . $config['file_post']; + if (!isset($config['referer_match'])) if (isset($_SERVER['HTTP_HOST'])) { $config['referer_match'] = '/^' . @@ -206,10 +203,24 @@ function loadConfig() { if (!isset($config['user_flags'])) $config['user_flags'] = array(); + // Effectful config processing below: + if ($config['root_file']) { chdir($config['root_file']); } + // Keep the original address to properly comply with other board configurations + if (!isset($__ip)) + $__ip = $_SERVER['REMOTE_ADDR']; + + // ::ffff:0.0.0.0 + if (preg_match('/^\:\:(ffff\:)?(\d+\.\d+\.\d+\.\d+)$/', $__ip, $m)) + $_SERVER['REMOTE_ADDR'] = $m[2]; + + if (!isset($__version)) + $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; + $config['version'] = $__version; + if ($config['verbose_errors']) { set_error_handler('verbose_error_handler'); error_reporting(E_ALL); @@ -219,19 +230,12 @@ function loadConfig() { ini_set('display_errors', false); } - // Keep the original address to properly comply with other board configurations - if (!isset($__ip)) - $__ip = $_SERVER['REMOTE_ADDR']; - - // ::ffff:0.0.0.0 - if (preg_match('/^\:\:(ffff\:)?(\d+\.\d+\.\d+\.\d+)$/', $__ip, $m)) - $_SERVER['REMOTE_ADDR'] = $m[2]; - if ($config['syslog']) openlog('tinyboard', LOG_ODELAY, LOG_SYSLOG); // open a connection to sysem logger if ($config['recaptcha']) require_once 'inc/lib/recaptcha/recaptchalib.php'; + if ($config['cache']['enabled']) require_once 'inc/cache.php'; -- cgit v1.3 From bdb6001f3f7e93e0b9655c0491bbef6f1df8a5fa Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 12:48:59 +0100 Subject: support for slugified links; may introduce a few bugs --- inc/config.php | 7 +- inc/display.php | 4 +- inc/functions.php | 92 +++++++++++++++++++++++-- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 3 +- inc/mod/pages.php | 18 ++--- install.php | 6 +- mod.php | 5 ++ post.php | 19 +++-- templates/main.js | 1 + templates/mod/debug/recent_posts.html | 2 +- templates/mod/search_results.html | 4 +- templates/post_reply.html | 4 +- templates/post_thread.html | 10 +-- templates/posts.sql | 1 + templates/themes/catalog/theme.php | 2 +- templates/themes/recent/theme.php | 4 +- templates/themes/sitemap/sitemap.xml | 4 +- templates/themes/sitemap/theme.php | 2 +- 18 files changed, 145 insertions(+), 43 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index edbe7b2a..ac4acaa4 100644 --- a/inc/config.php +++ b/inc/config.php @@ -566,6 +566,9 @@ // Allow dice rolling: an email field of the form "dice XdY+/-Z" will result in X Y-sided dice rolled and summed, // with the modifier Z added, with the result displayed at the top of the post body. $config['allow_roll'] = false; + + // Use semantic URLs for threads, like /b/res/12345/daily-programming-thread.html + $config['slugify'] = false; /* * ==================== @@ -1118,8 +1121,10 @@ // Location of files. $config['file_index'] = 'index.html'; - $config['file_page'] = '%d.html'; + $config['file_page'] = '%d.html'; // NB: page is both an index page and a thread $config['file_page50'] = '%d+50.html'; + $config['file_page_slug'] = '%d-%s.html'; + $config['file_page50_slug'] = '%d-%s+50.html'; $config['file_mod'] = 'mod.php'; $config['file_post'] = 'post.php'; $config['file_script'] = 'main.js'; diff --git a/inc/display.php b/inc/display.php index 1a78e19b..65525ab9 100644 --- a/inc/display.php +++ b/inc/display.php @@ -383,7 +383,7 @@ class Post { public function link($pre = '', $page = false) { global $config, $board; - return $this->root . $board['dir'] . $config['dir']['res'] . sprintf(($page ? $page : $config['file_page']), $this->thread) . '#' . $pre . $this->id; + return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; } public function build($index=false) { @@ -438,7 +438,7 @@ class Thread { public function link($pre = '', $page = false) { global $config, $board; - return $this->root . $board['dir'] . $config['dir']['res'] . sprintf(($page ? $page : $config['file_page']), $this->id) . '#' . $pre . $this->id; + return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; } public function add(Post $post) { $this->posts[] = $post; diff --git a/inc/functions.php b/inc/functions.php index 25362a62..79d06f5c 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -150,7 +150,9 @@ function loadConfig() { preg_quote($config['dir']['res'], '/') . '(' . str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . - str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . + str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . '|' . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')' . '|' . preg_quote($config['file_mod'], '/') . '\?\/.+' . @@ -912,7 +914,7 @@ function insertFloodPost(array $post) { function post(array $post) { global $pdo, $board; - $query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, 0, :embed)", $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, 0, :embed, :slug)", $board['uri'])); // Basic stuff if (!empty($post['subject'])) { @@ -981,6 +983,10 @@ function post(array $post) { $query->bindValue(':filehash', null, PDO::PARAM_NULL); } + if ($post['op']) { + $query->bindValue(':slug', slugify($post)); + } + if (!$query->execute()) { undoImage($post); error(db_error($query)); @@ -1094,8 +1100,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { if (!$post['thread']) { // Delete thread HTML page - file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id'])); - file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $post['id'])); + file_unlink($board['dir'] . $config['dir']['res'] . link_for($post) ); + file_unlink($board['dir'] . $config['dir']['res'] . link_for($post, true) ); // noko50 file_unlink($board['dir'] . $config['dir']['res'] . sprintf('%d.json', $post['id'])); $antispam_query = prepare('DELETE FROM ``antispam`` WHERE `board` = :board AND `thread` = :thread'); @@ -2067,12 +2073,12 @@ function buildThread($id, $return = false, $mod = false) { if ($return) { return $body; } else { - $noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id); + $noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true); if ($hasnoko50 || file_exists($noko50fn)) { buildThread50($id, $return, $mod, $thread, $antibot); } - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); + file_write($board['dir'] . $config['dir']['res'] . link_for($thread), $body); } } @@ -2152,7 +2158,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti if ($return) { return $body; } else { - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body); + file_write($board['dir'] . $config['dir']['res'] . link_for($thread, true), $body); } } @@ -2421,3 +2427,75 @@ function diceRoller($post) { } } } + +function slugify($post) { + $slug = ""; + + if (isset($post['thread']) && $post['thread']) + $slug = $post['thread']; + elseif (isset ($post['body_nomarkup']) && $post['body_nomarkup']) + $slug = $post['body_nomarkup']; + elseif (isset ($post['body']) && $post['body']) + $slug = strip_html($post['body']); + + // Fix UTF-8 first + $slug = mb_convert_encoding($slug, "UTF-8", "UTF-8"); + + // Transliterate local characters like ü, I wonder how would it work for weird alphabets :^) + $slug = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $slug); + + // Downcase everything + $slug = strtolower($slug); + + // Strip bad characters, alphanumerics should suffice + $slug = preg_replace('/[^a-zA-Z0-9]/', '-', $slug); + + // Replace multiple dashes with single ones + $slug = preg_replace('/-+/', '-', $slug); + + // Strip dashes at the beginning and at the end + $slug = preg_replace('/^-|-$/', '', $slug); + + // Slug should be 200 characters long, at max + $slug = substr($slug, 0, 200); + + // Slug is now ready + return $slug; +} + +function link_for($post, $page50 = false, $foreignlink = false, $thread = false) { + global $config, $board; + + $post = (array)$post; + + // Where do we need to look for OP? + $b = $foreignlink ? $foreignlink : $board; + + $id = (isset($post['thread']) && $post['thread']) ? $post['thread'] : $post['id']; + + $slug = false; + + if ($config['slugify'] && isset($post['thread']) && $post['thread']) { + if (!$thread) { + // Oh fuck, we'd better optimize it ASAP + + $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $thread = $query->fetch(PDO::FETCH_ASSOC); + } + $slug = $thread['slug']; + } + elseif ($config['slugify']) { + $slug = $post['slug']; + } + + + if ( $page50 && $slug) $tpl = $config['file_page50_slug']; + else if (!$page50 && $slug) $tpl = $config['file_page_slug']; + else if ( $page50 && !$slug) $tpl = $config['file_page50']; + else if (!$page50 && !$slug) $tpl = $config['file_page']; + + return sprintf($tpl, $id, $slug); +} diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 81276147..028db438 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -45,7 +45,8 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension new Twig_SimpleFunction('hiddenInputsHash', 'hiddenInputsHash'), new Twig_SimpleFunction('ratio', 'twig_ratio_function'), new Twig_SimpleFunction('secure_link_confirm', 'twig_secure_link_confirm'), - new Twig_SimpleFunction('secure_link', 'twig_secure_link') + new Twig_SimpleFunction('secure_link', 'twig_secure_link'), + new Twig_SimpleFunction('link_for', 'link_for') ); } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index c7722763..79d1bf51 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1161,7 +1161,7 @@ function mod_move_reply($originBoard, $postID) { $post = $query->fetch(PDO::FETCH_ASSOC); // redirect - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $newID) . '#' . $newID, true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post) . '#' . $newID, true, $config['redirect_http']); } else { @@ -1322,6 +1322,8 @@ function mod_move($originBoard, $postID) { // trigger themes rebuildThemes('post', $targetBoard); + $newboard = $board; + // return to original board openBoard($originBoard); @@ -1332,7 +1334,7 @@ function mod_move($originBoard, $postID) { $query->execute() or error(db_error($query)); // leave a reply, linking to the new thread - $post = array( + $spost = array( 'mod' => true, 'subject' => '', 'email' => '', @@ -1346,23 +1348,23 @@ function mod_move($originBoard, $postID) { 'op' => false ); - $post['body'] = $post['body_nomarkup'] = sprintf($config['mod']['shadow_mesage'], '>>>/' . $targetBoard . '/' . $newID); + $spost['body'] = $spost['body_nomarkup'] = sprintf($config['mod']['shadow_mesage'], '>>>/' . $targetBoard . '/' . $newID); - markup($post['body']); + markup($spost['body']); - $botID = post($post); + $botID = post($spost); buildThread($postID); buildIndex(); - header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] .sprintf($config['file_page'], $postID) . + header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($post, false, $newboard) . '#' . $botID, true, $config['redirect_http']); } else { deletePost($postID); buildIndex(); openBoard($targetBoard); - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $newID), true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post, false, $newboard), true, $config['redirect_http']); } } @@ -1494,7 +1496,7 @@ function mod_edit_post($board, $edit_raw_html, $postID) { 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']); + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . link_for($post) . '#' . $postID, true, $config['redirect_http']); } else { if ($config['minify_html']) { $post['body_nomarkup'] = str_replace("\n", ' ', utf8tohtml($post['body_nomarkup'])); diff --git a/install.php b/install.php index 2e050eee..95caf8ec 100644 --- a/install.php +++ b/install.php @@ -1,7 +1,7 @@ vichan upgrade path. query("CREATE TABLE IF NOT EXISTS ``search_queries`` ( `ip` varchar(39) NOT NULL, `time` int(11) NOT NULL, `query` text NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error()); diff --git a/mod.php b/mod.php index 384eec88..e06d5db6 100644 --- a/mod.php +++ b/mod.php @@ -105,6 +105,11 @@ $pages = array( str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '!')) => 'view_thread50', '/(\%b)/' . preg_quote($config['dir']['res'], '!') . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread', + + '/(\%b)/' . preg_quote($config['dir']['res'], '!') . + str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '!')) => 'view_thread50', + '/(\%b)/' . preg_quote($config['dir']['res'], '!') . + str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '!')) => 'view_thread', ); diff --git a/post.php b/post.php index d33c8150..93592590 100644 --- a/post.php +++ b/post.php @@ -85,7 +85,7 @@ if (isset($_POST['delete'])) { } _syslog(LOG_INFO, 'Deleted post: ' . - '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '') + '/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '') ); } } @@ -142,7 +142,7 @@ if (isset($_POST['delete'])) { if ($config['syslog']) _syslog(LOG_INFO, 'Reported post: ' . - '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $thread ? $thread : $id) . ($thread ? '#' . $id : '') . + '/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($thread ? '#' . $id : '') . ' for "' . $reason . '"' ); $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); @@ -250,7 +250,7 @@ if (isset($_POST['delete'])) { //Check if thread exists if (!$post['op']) { - $query = prepare(sprintf("SELECT `sticky`,`locked`,`sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); + $query = prepare(sprintf("SELECT `sticky`,`locked`,`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->execute() or error(db_error()); @@ -259,6 +259,9 @@ if (isset($_POST['delete'])) { error($config['error']['nonexistant']); } } + else { + $thread = false; + } // Check for an embed field @@ -782,6 +785,7 @@ if (isset($_POST['delete'])) { $post = (object)$post; $post->files = array_map(function($a) { return (object)$a; }, $post->files); + $error = event('post', $post); $post->files = array_map(function($a) { return (array)$a; }, $post->files); @@ -845,19 +849,20 @@ if (isset($_POST['delete'])) { if ($noko) { $redirect = $root . $board['dir'] . $config['dir']['res'] . - sprintf($config['file_page'], $post['op'] ? $id:$post['thread']) . (!$post['op'] ? '#' . $id : ''); + link_for($post, false, false, $thread) . (!$post['op'] ? '#' . $id : ''); if (!$post['op'] && isset($_SERVER['HTTP_REFERER'])) { $regex = array( 'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')), 'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')), - 'page50' => str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')), + 'page50' => '(' . str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')) . '|' . + str_replace(array('%d', '%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')', 'res' => preg_quote($config['dir']['res'], '/'), ); if (preg_match('/\/' . $regex['board'] . $regex['res'] . $regex['page50'] . '([?&].*)?$/', $_SERVER['HTTP_REFERER'])) { $redirect = $root . $board['dir'] . $config['dir']['res'] . - sprintf($config['file_page50'], $post['op'] ? $id:$post['thread']) . (!$post['op'] ? '#' . $id : ''); + link_for($post, true, false, $thread) . (!$post['op'] ? '#' . $id : ''); } } } else { @@ -867,7 +872,7 @@ if (isset($_POST['delete'])) { if ($config['syslog']) _syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . - sprintf($config['file_page'], $post['op'] ? $id : $post['thread']) . (!$post['op'] ? '#' . $id : '')); + link_for($post) . (!$post['op'] ? '#' . $id : '')); if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"'); diff --git a/templates/main.js b/templates/main.js index ead852fe..e948fd82 100644 --- a/templates/main.js +++ b/templates/main.js @@ -146,6 +146,7 @@ function changeStyle(styleName, link) { {% endraw %} {% if config.stylesheets_board %} {# This is such an unacceptable mess. There needs to be an easier way. #} + {# Needs fix for slugify #} var matches = document.URL.match(/\/(\w+)\/($|{{ config.dir.res|replace({'/': '\\/'}) }}{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }}|{{ config.file_index|replace({'.': '\\.'}) }}|{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }})/); {% raw %} if (matches) { diff --git a/templates/mod/debug/recent_posts.html b/templates/mod/debug/recent_posts.html index e4eb4f3a..ce4cffc4 100644 --- a/templates/mod/debug/recent_posts.html +++ b/templates/mod/debug/recent_posts.html @@ -63,7 +63,7 @@ {% else %} {% set thread = post.id %} {% endif %} - + {{ post.id }} diff --git a/templates/mod/search_results.html b/templates/mod/search_results.html index 0d3c2a10..186ee5db 100644 --- a/templates/mod/search_results.html +++ b/templates/mod/search_results.html @@ -195,7 +195,7 @@ {% else %} {% set thread = post.id %} {% endif %} - + {{ post.id }} @@ -265,4 +265,4 @@ [{{ i + 1 }}] {% endfor %}

-{% endif %} \ No newline at end of file +{% endif %} diff --git a/templates/post_reply.html b/templates/post_reply.html index e7343230..451ff1b9 100644 --- a/templates/post_reply.html +++ b/templates/post_reply.html @@ -12,8 +12,8 @@ {% include 'post/time.html' %} {% include 'post/poster_id.html' %}  - No. - {{ post.id }} + No. + {{ post.id }}

{% include 'post/fileinfo.html' %} {% include 'post/post_controls.html' %} diff --git a/templates/post_thread.html b/templates/post_thread.html index 08b4c4c1..61146491 100644 --- a/templates/post_thread.html +++ b/templates/post_thread.html @@ -15,8 +15,8 @@ {% include 'post/time.html' %} {% include 'post/poster_id.html' %}  - No. - {{ post.id }} + No. + {{ post.id }} {% if post.sticky %} {% if config.font_awesome %} @@ -39,14 +39,14 @@ {% endif %} {% endif %} {% if index %} - [{% trans %}Reply{% endtrans %}] + [{% trans %}Reply{% endtrans %}] {% endif %} {% if isnoko50 %} - [{% trans %}View All{% endtrans %}] + [{% trans %}View All{% endtrans %}] {% endif %} {% if hasnoko50 and not isnoko50 %} {% set lastcount = config.noko50_count %} - [{% trans %}Last 1 Post{% plural lastcount %}Last {{ count }} Posts{% endtrans %}] + [{% trans %}Last 1 Post{% plural lastcount %}Last {{ count }} Posts{% endtrans %}] {% endif %} {% include 'post/post_controls.html' %}

diff --git a/templates/posts.sql b/templates/posts.sql index 9a47c6ad..6b2249ef 100644 --- a/templates/posts.sql +++ b/templates/posts.sql @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` ( `locked` int(1) NOT NULL, `sage` int(1) NOT NULL, `embed` text, + `slug` varchar(256) DEFAULT NULL, UNIQUE KEY `id` (`id`), KEY `thread_id` (`thread`,`id`), KEY `filehash` (`filehash`(40)), diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 9ba2d27a..b3b7caf7 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -42,7 +42,7 @@ $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { - $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])); + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post)); $post['board_name'] = $board['name']; if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) { diff --git a/templates/themes/recent/theme.php b/templates/themes/recent/theme.php index b1153477..2ea6a7b9 100644 --- a/templates/themes/recent/theme.php +++ b/templates/themes/recent/theme.php @@ -62,7 +62,7 @@ // board settings won't be available in the template file, so generate links now $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] - . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; + . link_for($post) . '#' . $post['id']; if ($files) { if ($files[0]->thumb == 'spoiler') { @@ -92,7 +92,7 @@ while ($post = $query->fetch(PDO::FETCH_ASSOC)) { openBoard($post['board']); - $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id']; if ($post['body'] != "") $post['snippet'] = pm_snippet($post['body'], 30); else diff --git a/templates/themes/sitemap/sitemap.xml b/templates/themes/sitemap/sitemap.xml index 733da607..95dfdd26 100644 --- a/templates/themes/sitemap/sitemap.xml +++ b/templates/themes/sitemap/sitemap.xml @@ -9,11 +9,11 @@ {% for board, thread_list in threads %} {% for thread in thread_list %} - {{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ (config.file_page | format(thread.thread_id)) }} + {{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ link_for(thread) }} {{ thread.lastmod | date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }} {{ settings.changefreq }} {% endfor %} {% endfor %} -{% endfilter %} \ No newline at end of file +{% endfilter %} diff --git a/templates/themes/sitemap/theme.php b/templates/themes/sitemap/theme.php index 3e048dd5..1cebcdb6 100644 --- a/templates/themes/sitemap/theme.php +++ b/templates/themes/sitemap/theme.php @@ -26,7 +26,7 @@ $threads = array(); foreach ($boards as $board) { - $query = query(sprintf("SELECT `id` AS `thread_id`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error()); + $query = query(sprintf("SELECT `id`, `slug`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error()); $threads[$board] = $query->fetchAll(PDO::FETCH_ASSOC); } -- cgit v1.3 From f4bba2e9ed7cbce52c1f33c3f6b5bfac6e8261c3 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 12:57:06 +0100 Subject: ... --- inc/functions.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 79d06f5c..b318ff35 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -986,6 +986,9 @@ function post(array $post) { if ($post['op']) { $query->bindValue(':slug', slugify($post)); } + else { + $query->bindValue(':slug', NULL); + } if (!$query->execute()) { undoImage($post); -- cgit v1.3 From 429c9f890f67246a38e1de29436fd37f525393d8 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:02:38 +0100 Subject: ... --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index b318ff35..ef7d3b7d 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2472,7 +2472,7 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false) $post = (array)$post; // Where do we need to look for OP? - $b = $foreignlink ? $foreignlink : $board; + $b = $foreignlink ? $foreignlink : (isset($post['board']) ? array('uri' => $post['board']) : $board); $id = (isset($post['thread']) && $post['thread']) ? $post['thread'] : $post['id']; -- cgit v1.3 From fe7e9c5103d1dc2d0b7c1aad2cdd58a552b218fe Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:03:47 +0100 Subject: ... --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index ef7d3b7d..df5bc426 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2482,7 +2482,7 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false) if (!$thread) { // Oh fuck, we'd better optimize it ASAP - $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); + $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri'])); $query->bindValue(':id', $id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); -- cgit v1.3 From 0062125f5c724183915ec48a9448684cc1b943db Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:09:53 +0100 Subject: ... --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index df5bc426..2a398ae7 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2434,8 +2434,8 @@ function diceRoller($post) { function slugify($post) { $slug = ""; - if (isset($post['thread']) && $post['thread']) - $slug = $post['thread']; + if (isset($post['subject']) && $post['subject']) + $slug = $post['subject']; elseif (isset ($post['body_nomarkup']) && $post['body_nomarkup']) $slug = $post['body_nomarkup']; elseif (isset ($post['body']) && $post['body']) -- cgit v1.3 From d690567b44464962b0f99c9c222ce4530b9b716e Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:13:18 +0100 Subject: ... (minor fix for locales) --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 2a398ae7..846dbdaa 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -358,7 +358,7 @@ function rebuildThemes($action, $boardname = false) { // Reload the locale if ($config['locale'] != $current_locale) { $current_locale = $config['locale']; - init_locale($config['locale'], $error); + init_locale($config['locale']); } if (PHP_SAPI === 'cli') { @@ -379,7 +379,7 @@ function rebuildThemes($action, $boardname = false) { // Reload the locale if ($config['locale'] != $current_locale) { $current_locale = $config['locale']; - init_locale($config['locale'], $error); + init_locale($config['locale']); } } -- cgit v1.3 From 7623de9e2fe8424f35be70cddb9cf68254e49e3e Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:42:10 +0100 Subject: ... (cache) --- inc/functions.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 846dbdaa..6880ad44 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2479,16 +2479,25 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false) $slug = false; if ($config['slugify'] && isset($post['thread']) && $post['thread']) { + $cvar = "slug_".$b['uri']."_".$id; if (!$thread) { - // Oh fuck, we'd better optimize it ASAP + $slug = Cache::get($cvar); - $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri'])); - $query->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + if ($slug === false) { + $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $b['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); - $thread = $query->fetch(PDO::FETCH_ASSOC); + $thread = $query->fetch(PDO::FETCH_ASSOC); + + $slug = $thread['slug']; + + Cache::set($cvar, $slug); + } + } + else { + $slug = $thread['slug']; } - $slug = $thread['slug']; } elseif ($config['slugify']) { $slug = $post['slug']; -- cgit v1.3 From 9f34d334d3d45471ab88fc90a702999cd2cf6bf5 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:52:31 +0100 Subject: .. --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 6880ad44..1beb7f6e 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1085,7 +1085,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { global $board, $config; // Select post and replies (if thread) in one query - $query = prepare(sprintf("SELECT `id`,`thread`,`files` 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->execute() or error(db_error($query)); -- cgit v1.3 From a2544bc596465f9915589a47d112fa1475f54720 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 14:16:27 +0100 Subject: ... (cites) --- inc/functions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 1beb7f6e..4dc516fc 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1810,7 +1810,7 @@ function markup(&$body, $track_cites = false) { if (isset($cited_posts[$cite])) { $replacement = '' . + link_for(array('id' => $cite)) . '#' . $cite . '">' . '>>' . $cite . ''; @@ -1876,12 +1876,12 @@ function markup(&$body, $track_cites = false) { if (!empty($clauses)) { $cited_posts[$_board] = array(); - $query = query(sprintf('SELECT `thread`, `id` FROM ``posts_%s`` WHERE ' . + $query = query(sprintf('SELECT `thread`, `id`, `slug` FROM ``posts_%s`` WHERE ' . implode(' OR ', $clauses), $board['uri'])) or error(db_error()); while ($cite = $query->fetch(PDO::FETCH_ASSOC)) { $cited_posts[$_board][$cite['id']] = $config['root'] . $board['dir'] . $config['dir']['res'] . - ($cite['thread'] ? $cite['thread'] : $cite['id']) . '.html#' . $cite['id']; + link_for($cite) . '#' . $cite['id']; } } @@ -2478,7 +2478,7 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false) $slug = false; - if ($config['slugify'] && isset($post['thread']) && $post['thread']) { + if ($config['slugify'] && ( (isset($post['thread']) && $post['thread']) || !isset ($post['slug']) ) ) { $cvar = "slug_".$b['uri']."_".$id; if (!$thread) { $slug = Cache::get($cvar); -- cgit v1.3 From 4bf525599e7c596e7aec7f483664a091ef0db57b Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 14:19:36 +0100 Subject: ... --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 4dc516fc..704c6600 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1810,7 +1810,7 @@ function markup(&$body, $track_cites = false) { if (isset($cited_posts[$cite])) { $replacement = '' . + link_for(array('id' => $cite, 'thread' => $cited_posts[$cite])) . '#' . $cite . '">' . '>>' . $cite . ''; -- cgit v1.3 From 3851087dce99d3f7368f501a1599564304b62bea Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 12 Mar 2015 00:03:22 +0100 Subject: slug size should be configurable --- inc/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 704c6600..ca918e0a 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2432,6 +2432,8 @@ function diceRoller($post) { } function slugify($post) { + global $config; + $slug = ""; if (isset($post['subject']) && $post['subject']) @@ -2459,8 +2461,8 @@ function slugify($post) { // Strip dashes at the beginning and at the end $slug = preg_replace('/^-|-$/', '', $slug); - // Slug should be 200 characters long, at max - $slug = substr($slug, 0, 200); + // Slug should be X characters long, at max (80?) + $slug = substr($slug, 0, $config['slug_max_size']); // Slug is now ready return $slug; -- cgit v1.3 From 10f93d0d4367ade293c7a8733989cedcd7ca791a Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 24 Mar 2015 05:19:25 +0100 Subject: implement a protection against transparent proxies --- inc/config.php | 6 ++++++ inc/functions.php | 34 ++++++++++++++++++++++------------ post.php | 7 ++++++- 3 files changed, 34 insertions(+), 13 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index 42e1c32b..0ba1952b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -290,6 +290,12 @@ // Ability to lock a board for normal users and still allow mods to post. Could also be useful for making an archive board $config['board_locked'] = false; + // If poster's proxy supplies X-Forwarded-For header, check if poster's real IP is banned. + $config['proxy_check'] = false; + + // If poster's proxy supplies X-Forwarded-For header, save it for further inspection and/or filtering. + $config['proxy_save'] = false; + /* * Custom filters detect certain posts and reject/ban accordingly. They are made up of a condition and an * action (for when ALL conditions are met). As every single post has to be put through each filter, diff --git a/inc/functions.php b/inc/functions.php index ca918e0a..0f70d447 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -810,12 +810,29 @@ function checkBan($board = false) { if (event('check-ban', $board)) return true; - $bans = Bans::find($_SERVER['REMOTE_ADDR'], $board, $config['show_modname']); + $ips = array(); + + $ips[] = $_SERVER['REMOTE_ADDR']; + + if ($config['proxy_check'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $ips = array_merge($ips, explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR'])); + } + + foreach ($ips as $ip) { + $bans = Bans::find($_SERVER['REMOTE_ADDR'], $board, $config['show_modname']); - foreach ($bans as &$ban) { - if ($ban['expires'] && $ban['expires'] < time()) { - Bans::delete($ban['id']); - if ($config['require_ban_view'] && !$ban['seen']) { + foreach ($bans as &$ban) { + if ($ban['expires'] && $ban['expires'] < time()) { + Bans::delete($ban['id']); + if ($config['require_ban_view'] && !$ban['seen']) { + if (!isset($_POST['json_response'])) { + displayBan($ban); + } else { + header('Content-Type: text/json'); + die(json_encode(array('error' => true, 'banned' => true))); + } + } + } else { if (!isset($_POST['json_response'])) { displayBan($ban); } else { @@ -823,13 +840,6 @@ function checkBan($board = false) { die(json_encode(array('error' => true, 'banned' => true))); } } - } else { - if (!isset($_POST['json_response'])) { - displayBan($ban); - } else { - header('Content-Type: text/json'); - die(json_encode(array('error' => true, 'banned' => true))); - } } } diff --git a/post.php b/post.php index 87795aa0..100c3efb 100644 --- a/post.php +++ b/post.php @@ -516,7 +516,7 @@ if (isset($_POST['delete'])) { "\n".geoip\geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR'])).""; } } - + if ($config['user_flag'] && isset($_POST['user_flag'])) if (!empty($_POST['user_flag']) ){ @@ -530,6 +530,11 @@ if (isset($_POST['delete'])) { $post['body'] .= "\n" . strtolower($user_flag) . "" . "\n" . $flag_alt . ""; } + + if ($config['proxy_save'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $proxy = preg_replace("/[^0-9a-fA-F.,: ]/", '', $_SERVER['HTTP_X_FORWARDED_FOR']); + $post['body'] .= "\n".$proxy.""; + } if (mysql_version() >= 50503) { $post['body_nomarkup'] = $post['body']; // Assume we're using the utf8mb4 charset -- cgit v1.3 From 5d8e023fc4ba7692eb81bf690c8a04dac9d561ee Mon Sep 17 00:00:00 2001 From: czaks Date: Mon, 30 Mar 2015 06:26:53 +0200 Subject: remove tinyboard special markup from slugs; thanks stigma for reporting --- inc/functions.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 0f70d447..ab55d214 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2459,6 +2459,9 @@ function slugify($post) { // Transliterate local characters like ü, I wonder how would it work for weird alphabets :^) $slug = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $slug); + // Remove Tinyboard custom markup + $slug = preg_replace("/]+>.*?<\/tinyboard>/s", '', $slug); + // Downcase everything $slug = strtolower($slug); -- cgit v1.3 From 7fd8c75450200c18c5cf42a839183a55a924cb1e Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 16:53:28 +0200 Subject: don`t rebuild a page, when not needed, even if it doesn`t exist --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index ab55d214..7df75ef2 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1494,7 +1494,7 @@ function buildIndex() { $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); if (!$config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages) - && !in_array($page, $build_pages) && is_file($filename)) + && !in_array($page, $build_pages) ) continue; $content = index($page); if (!$content) @@ -1511,7 +1511,7 @@ function buildIndex() { } if ($config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages) - && !in_array($page, $build_pages) && is_file($filename)) + && !in_array($page, $build_pages) ) continue; if ($config['try_smarter']) { -- cgit v1.3 From deefe8299b10cef01db1ef782f09e6cf44e6a773 Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 16:56:17 +0200 Subject: unlink a .gz version of a file if it exists --- inc/functions.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 7df75ef2..bdc03535 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -636,6 +636,13 @@ function file_unlink($path) { } $ret = @unlink($path); + + if ($config['gzip_static']) { + $gzpath = "$path.gz"; + + @unlink($gzpath); + } + if (isset($config['purge']) && $path[0] != '/' && isset($_SERVER['HTTP_HOST'])) { // Purge cache if (basename($path) == $config['file_index']) { -- cgit v1.3 From 4030c42bb49ae3d71c6e252861699cbea30496ba Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 17:07:24 +0200 Subject: add a global_api variable for buildIndex --- inc/functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index bdc03535..eedccae0 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1485,7 +1485,7 @@ function checkMute() { } } -function buildIndex() { +function buildIndex($global_api = "yes") { global $board, $config, $build_pages; $pages = getPages(); @@ -1500,8 +1500,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['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages) - && !in_array($page, $build_pages) ) + if (!$config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages) + && !empty($build_pages) && !in_array($page, $build_pages) ) continue; $content = index($page); if (!$content) @@ -1517,8 +1517,8 @@ function buildIndex() { $catalog[$page-1] = $threads; } - if ($config['api']['enabled'] && $config['try_smarter'] && isset($build_pages) && !empty($build_pages) - && !in_array($page, $build_pages) ) + if ($config['api']['enabled'] && $global_api == "skip" && $config['try_smarter'] && isset($build_pages) + && !empty($build_pages) && !in_array($page, $build_pages) ) continue; if ($config['try_smarter']) { @@ -1547,7 +1547,7 @@ function buildIndex() { } // json api catalog - if ($config['api']['enabled']) { + if ($config['api']['enabled'] && $global_api != "skip") { $json = json_encode($api->translateCatalog($catalog)); $jsonFilename = $board['dir'] . 'catalog.json'; file_write($jsonFilename, $json); -- cgit v1.3 From d4892aca123df1bc04287b0ce37fafb7e71f1f2a Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 17:30:06 +0200 Subject: fix one of the previous commits: fix api_global --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index eedccae0..6f736310 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1500,7 +1500,7 @@ function buildIndex($global_api = "yes") { for ($page = 1; $page <= $config['max_pages']; $page++) { $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); - 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) ) continue; $content = index($page); @@ -1517,7 +1517,7 @@ function buildIndex($global_api = "yes") { $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) ) continue; -- cgit v1.3 From 55277ce3835fecf44bb1a0cc1ba0b02d23846848 Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 18:11:08 +0200 Subject: smart_build for buildIndex --- inc/functions.php | 95 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 39 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 6f736310..568b7f0a 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1488,53 +1488,62 @@ function checkMute() { function buildIndex($global_api = "yes") { global $board, $config, $build_pages; - $pages = getPages(); - if (!$config['try_smarter']) - $antibot = create_antibot($board['uri']); + if (!$config['smart_build']) { + $pages = getPages(); + if (!$config['try_smarter']) + $antibot = create_antibot($board['uri']); - if ($config['api']['enabled']) { - $api = new Api(); - $catalog = array(); + if ($config['api']['enabled']) { + $api = new Api(); + $catalog = array(); + } } for ($page = 1; $page <= $config['max_pages']; $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 - if ((!$config['api']['enabled'] || $global_api == "skip") && $config['try_smarter'] && isset($build_pages) - && !empty($build_pages) && !in_array($page, $build_pages) ) + if ((!$config['api']['enabled'] || $global_api == "skip" || $config['smart_build']) && $config['try_smarter'] + && isset($build_pages) && !empty($build_pages) && !in_array($page, $build_pages) ) continue; - $content = index($page); - if (!$content) - break; - // 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 - file_write($jsonFilename, $json); + if (!$config['smart_build']) { + $content = index($page); + if (!$content) + break; - $catalog[$page-1] = $threads; - } + // json api + if ($config['api']['enabled']) { + $threads = $content['threads']; + $json = json_encode($api->translatePage($threads)); + file_write($jsonFilename, $json); - if ($config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages) - && !empty($build_pages) && !in_array($page, $build_pages) ) - continue; + $catalog[$page-1] = $threads; + } - if ($config['try_smarter']) { - $antibot = create_antibot($board['uri'], 0 - $page); - $content['current_page'] = $page; - } - $antibot->reset(); - $content['pages'] = $pages; - $content['pages'][$page-1]['selected'] = true; - $content['btn'] = getPageButtons($content['pages']); - $content['antibot'] = $antibot; + if ($config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages) + && !empty($build_pages) && !in_array($page, $build_pages) ) + continue; - file_write($filename, Element('index.html', $content)); + if ($config['try_smarter']) { + $antibot = create_antibot($board['uri'], 0 - $page); + $content['current_page'] = $page; + } + $antibot->reset(); + $content['pages'] = $pages; + $content['pages'][$page-1]['selected'] = true; + $content['btn'] = getPageButtons($content['pages']); + $content['antibot'] = $antibot; + + file_write($filename, Element('index.html', $content)); + } + else { + file_unlink($filename); + file_unlink($jsonFilename); + } } - if ($page < $config['max_pages']) { + if (!$config['smart_build'] && $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); @@ -1548,13 +1557,21 @@ function buildIndex($global_api = "yes") { // json api catalog if ($config['api']['enabled'] && $global_api != "skip") { - $json = json_encode($api->translateCatalog($catalog)); - $jsonFilename = $board['dir'] . 'catalog.json'; - file_write($jsonFilename, $json); + if ($config['smart_build']) { + $jsonFilename = $board['dir'] . 'catalog.json'; + file_unlink($jsonFilename); + $jsonFilename = $board['dir'] . 'threads.json'; + file_unlink($jsonFilename); + } + else { + $json = json_encode($api->translateCatalog($catalog)); + $jsonFilename = $board['dir'] . 'catalog.json'; + file_write($jsonFilename, $json); - $json = json_encode($api->translateCatalog($catalog, true)); - $jsonFilename = $board['dir'] . 'threads.json'; - file_write($jsonFilename, $json); + $json = json_encode($api->translateCatalog($catalog, true)); + $jsonFilename = $board['dir'] . 'threads.json'; + file_write($jsonFilename, $json); + } } if ($config['try_smarter']) -- cgit v1.3 From 14671e05353c11b44231c08cebea9a1777d55565 Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 18:13:32 +0200 Subject: functions.php fix: after_open_board support; so that we may disable smart_build immediately after open_board --- inc/functions.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 568b7f0a..1c60393c 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -475,6 +475,11 @@ function openBoard($uri) { $board = getBoardInfo($uri); if ($board) { setupBoard($board); + + if (function_exists('after_open_board')) { + after_open_board(); + } + return true; } return false; -- cgit v1.3 From f2a74812f0a135370969bcdedea8a8c9c3f96aed Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 18:43:48 +0200 Subject: smart_build: buildThread --- inc/functions.php | 85 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 37 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 1c60393c..7ed3af5a 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2068,51 +2068,62 @@ function buildThread($id, $return = false, $mod = false) { 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->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + if (!$config['smart_build'] || $return || $mod) { + $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->execute() or error(db_error($query)); - while ($post = $query->fetch(PDO::FETCH_ASSOC)) { - if (!isset($thread)) { - $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); - } else { - $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + if (!isset($thread)) { + $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); + } else { + $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); + } } - } - // Check if any posts were found - if (!isset($thread)) - error($config['error']['nonexistant']); + // Check if any posts were found + if (!isset($thread)) + error($config['error']['nonexistant']); - $hasnoko50 = $thread->postCount() >= $config['noko50_min']; - $antibot = $mod || $return ? false : create_antibot($board['uri'], $id); - - $body = Element('thread.html', array( - 'board' => $board, - 'thread' => $thread, - 'body' => $thread->build(), - 'config' => $config, - 'id' => $id, - 'mod' => $mod, - 'hasnoko50' => $hasnoko50, - 'isnoko50' => false, - 'antibot' => $antibot, - 'boardlist' => createBoardlist($mod), - 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) - )); - - if ($config['try_smarter'] && !$mod) - $build_pages[] = thread_find_page($id); + $hasnoko50 = $thread->postCount() >= $config['noko50_min']; + $antibot = $mod || $return ? false : create_antibot($board['uri'], $id); - // json api - if ($config['api']['enabled']) { - $api = new Api(); - $json = json_encode($api->translateThread($thread)); + $body = Element('thread.html', array( + 'board' => $board, + 'thread' => $thread, + 'body' => $thread->build(), + 'config' => $config, + 'id' => $id, + 'mod' => $mod, + 'hasnoko50' => $hasnoko50, + 'isnoko50' => false, + 'antibot' => $antibot, + 'boardlist' => createBoardlist($mod), + 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) + )); + + if ($config['try_smarter'] && !$mod) + $build_pages[] = thread_find_page($id); + + // json api + if ($config['api']['enabled']) { + $api = new Api(); + $json = json_encode($api->translateThread($thread)); + $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; + file_write($jsonFilename, $json); + } + } + else { $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; - file_write($jsonFilename, $json); + file_unlink($jsonFilename); } - if ($return) { + if ($config['smart_build'] && !$return && !$mod) { + $noko50fn = $board['dir'] . $config['dir']['res'] . link_for(array('id' => $id), true); + file_unlink($noko50fn); + + file_unlink($board['dir'] . $config['dir']['res'] . link_for(array('id' => $id))); + } else if ($return) { return $body; } else { $noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true); -- cgit v1.3 From b246daa191ed6495ce7a73a369c645599eea610e Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 18:44:01 +0200 Subject: Revert "smart_build: buildThread" (for a moment, something b0rks) This reverts commit f2a74812f0a135370969bcdedea8a8c9c3f96aed. --- inc/functions.php | 85 ++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 48 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 7ed3af5a..1c60393c 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2068,62 +2068,51 @@ function buildThread($id, $return = false, $mod = false) { cache::delete("thread_{$board['uri']}_{$id}"); } - if (!$config['smart_build'] || $return || $mod) { - $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->execute() or error(db_error($query)); + $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->execute() or error(db_error($query)); - while ($post = $query->fetch(PDO::FETCH_ASSOC)) { - if (!isset($thread)) { - $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); - } else { - $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); - } + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + if (!isset($thread)) { + $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); + } else { + $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); } + } - // Check if any posts were found - if (!isset($thread)) - error($config['error']['nonexistant']); + // Check if any posts were found + if (!isset($thread)) + error($config['error']['nonexistant']); - $hasnoko50 = $thread->postCount() >= $config['noko50_min']; - $antibot = $mod || $return ? false : create_antibot($board['uri'], $id); + $hasnoko50 = $thread->postCount() >= $config['noko50_min']; + $antibot = $mod || $return ? false : create_antibot($board['uri'], $id); - $body = Element('thread.html', array( - 'board' => $board, - 'thread' => $thread, - 'body' => $thread->build(), - 'config' => $config, - 'id' => $id, - 'mod' => $mod, - 'hasnoko50' => $hasnoko50, - 'isnoko50' => false, - 'antibot' => $antibot, - 'boardlist' => createBoardlist($mod), - 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) - )); - - if ($config['try_smarter'] && !$mod) - $build_pages[] = thread_find_page($id); - - // json api - if ($config['api']['enabled']) { - $api = new Api(); - $json = json_encode($api->translateThread($thread)); - $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; - file_write($jsonFilename, $json); - } - } - else { + $body = Element('thread.html', array( + 'board' => $board, + 'thread' => $thread, + 'body' => $thread->build(), + 'config' => $config, + 'id' => $id, + 'mod' => $mod, + 'hasnoko50' => $hasnoko50, + 'isnoko50' => false, + 'antibot' => $antibot, + 'boardlist' => createBoardlist($mod), + 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) + )); + + if ($config['try_smarter'] && !$mod) + $build_pages[] = thread_find_page($id); + + // json api + if ($config['api']['enabled']) { + $api = new Api(); + $json = json_encode($api->translateThread($thread)); $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; - file_unlink($jsonFilename); + file_write($jsonFilename, $json); } - if ($config['smart_build'] && !$return && !$mod) { - $noko50fn = $board['dir'] . $config['dir']['res'] . link_for(array('id' => $id), true); - file_unlink($noko50fn); - - file_unlink($board['dir'] . $config['dir']['res'] . link_for(array('id' => $id))); - } else if ($return) { + if ($return) { return $body; } else { $noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true); -- cgit v1.3 From cfb2f55b7a6ae314fa03b516192df34bd9849726 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 2 Apr 2015 19:36:55 +0200 Subject: Revert "smart_build for buildIndex" This reverts commit 55277ce3835fecf44bb1a0cc1ba0b02d23846848. --- inc/functions.php | 95 +++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 56 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 1c60393c..f5fb6360 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1493,62 +1493,53 @@ function checkMute() { function buildIndex($global_api = "yes") { global $board, $config, $build_pages; - if (!$config['smart_build']) { - $pages = getPages(); - if (!$config['try_smarter']) - $antibot = create_antibot($board['uri']); + $pages = getPages(); + if (!$config['try_smarter']) + $antibot = create_antibot($board['uri']); - if ($config['api']['enabled']) { - $api = new Api(); - $catalog = array(); - } + if ($config['api']['enabled']) { + $api = new Api(); + $catalog = array(); } for ($page = 1; $page <= $config['max_pages']; $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 - if ((!$config['api']['enabled'] || $global_api == "skip" || $config['smart_build']) && $config['try_smarter'] - && isset($build_pages) && !empty($build_pages) && !in_array($page, $build_pages) ) + if ((!$config['api']['enabled'] || $global_api == "skip") && $config['try_smarter'] && isset($build_pages) + && !empty($build_pages) && !in_array($page, $build_pages) ) continue; + $content = index($page); + if (!$content) + break; - if (!$config['smart_build']) { - $content = index($page); - if (!$content) - break; - - // json api - if ($config['api']['enabled']) { - $threads = $content['threads']; - $json = json_encode($api->translatePage($threads)); - file_write($jsonFilename, $json); - - $catalog[$page-1] = $threads; - } + // 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 + file_write($jsonFilename, $json); - if ($config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages) - && !empty($build_pages) && !in_array($page, $build_pages) ) - continue; + $catalog[$page-1] = $threads; + } - if ($config['try_smarter']) { - $antibot = create_antibot($board['uri'], 0 - $page); - $content['current_page'] = $page; - } - $antibot->reset(); - $content['pages'] = $pages; - $content['pages'][$page-1]['selected'] = true; - $content['btn'] = getPageButtons($content['pages']); - $content['antibot'] = $antibot; + if ($config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages) + && !empty($build_pages) && !in_array($page, $build_pages) ) + continue; - file_write($filename, Element('index.html', $content)); - } - else { - file_unlink($filename); - file_unlink($jsonFilename); + if ($config['try_smarter']) { + $antibot = create_antibot($board['uri'], 0 - $page); + $content['current_page'] = $page; } + $antibot->reset(); + $content['pages'] = $pages; + $content['pages'][$page-1]['selected'] = true; + $content['btn'] = getPageButtons($content['pages']); + $content['antibot'] = $antibot; + + file_write($filename, Element('index.html', $content)); } - if (!$config['smart_build'] && $page < $config['max_pages']) { + 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); @@ -1562,21 +1553,13 @@ function buildIndex($global_api = "yes") { // json api catalog if ($config['api']['enabled'] && $global_api != "skip") { - if ($config['smart_build']) { - $jsonFilename = $board['dir'] . 'catalog.json'; - file_unlink($jsonFilename); - $jsonFilename = $board['dir'] . 'threads.json'; - file_unlink($jsonFilename); - } - else { - $json = json_encode($api->translateCatalog($catalog)); - $jsonFilename = $board['dir'] . 'catalog.json'; - file_write($jsonFilename, $json); + $json = json_encode($api->translateCatalog($catalog)); + $jsonFilename = $board['dir'] . 'catalog.json'; + file_write($jsonFilename, $json); - $json = json_encode($api->translateCatalog($catalog, true)); - $jsonFilename = $board['dir'] . 'threads.json'; - file_write($jsonFilename, $json); - } + $json = json_encode($api->translateCatalog($catalog, true)); + $jsonFilename = $board['dir'] . 'threads.json'; + file_write($jsonFilename, $json); } if ($config['try_smarter']) -- cgit v1.3 From 99706835c228152fdd42adc20724fb7f4c05488a Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 2 Apr 2015 20:29:43 +0200 Subject: Revert "Revert "smart_build for buildIndex"" This reverts commit cfb2f55b7a6ae314fa03b516192df34bd9849726. --- inc/functions.php | 95 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 39 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index f5fb6360..1c60393c 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1493,53 +1493,62 @@ function checkMute() { function buildIndex($global_api = "yes") { global $board, $config, $build_pages; - $pages = getPages(); - if (!$config['try_smarter']) - $antibot = create_antibot($board['uri']); + if (!$config['smart_build']) { + $pages = getPages(); + if (!$config['try_smarter']) + $antibot = create_antibot($board['uri']); - if ($config['api']['enabled']) { - $api = new Api(); - $catalog = array(); + if ($config['api']['enabled']) { + $api = new Api(); + $catalog = array(); + } } for ($page = 1; $page <= $config['max_pages']; $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 - if ((!$config['api']['enabled'] || $global_api == "skip") && $config['try_smarter'] && isset($build_pages) - && !empty($build_pages) && !in_array($page, $build_pages) ) + if ((!$config['api']['enabled'] || $global_api == "skip" || $config['smart_build']) && $config['try_smarter'] + && isset($build_pages) && !empty($build_pages) && !in_array($page, $build_pages) ) continue; - $content = index($page); - if (!$content) - break; - // 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 - file_write($jsonFilename, $json); + if (!$config['smart_build']) { + $content = index($page); + if (!$content) + break; - $catalog[$page-1] = $threads; - } + // json api + if ($config['api']['enabled']) { + $threads = $content['threads']; + $json = json_encode($api->translatePage($threads)); + file_write($jsonFilename, $json); - if ($config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages) - && !empty($build_pages) && !in_array($page, $build_pages) ) - continue; + $catalog[$page-1] = $threads; + } - if ($config['try_smarter']) { - $antibot = create_antibot($board['uri'], 0 - $page); - $content['current_page'] = $page; - } - $antibot->reset(); - $content['pages'] = $pages; - $content['pages'][$page-1]['selected'] = true; - $content['btn'] = getPageButtons($content['pages']); - $content['antibot'] = $antibot; + if ($config['api']['enabled'] && $global_api != "skip" && $config['try_smarter'] && isset($build_pages) + && !empty($build_pages) && !in_array($page, $build_pages) ) + continue; - file_write($filename, Element('index.html', $content)); + if ($config['try_smarter']) { + $antibot = create_antibot($board['uri'], 0 - $page); + $content['current_page'] = $page; + } + $antibot->reset(); + $content['pages'] = $pages; + $content['pages'][$page-1]['selected'] = true; + $content['btn'] = getPageButtons($content['pages']); + $content['antibot'] = $antibot; + + file_write($filename, Element('index.html', $content)); + } + else { + file_unlink($filename); + file_unlink($jsonFilename); + } } - if ($page < $config['max_pages']) { + if (!$config['smart_build'] && $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); @@ -1553,13 +1562,21 @@ function buildIndex($global_api = "yes") { // json api catalog if ($config['api']['enabled'] && $global_api != "skip") { - $json = json_encode($api->translateCatalog($catalog)); - $jsonFilename = $board['dir'] . 'catalog.json'; - file_write($jsonFilename, $json); + if ($config['smart_build']) { + $jsonFilename = $board['dir'] . 'catalog.json'; + file_unlink($jsonFilename); + $jsonFilename = $board['dir'] . 'threads.json'; + file_unlink($jsonFilename); + } + else { + $json = json_encode($api->translateCatalog($catalog)); + $jsonFilename = $board['dir'] . 'catalog.json'; + file_write($jsonFilename, $json); - $json = json_encode($api->translateCatalog($catalog, true)); - $jsonFilename = $board['dir'] . 'threads.json'; - file_write($jsonFilename, $json); + $json = json_encode($api->translateCatalog($catalog, true)); + $jsonFilename = $board['dir'] . 'threads.json'; + file_write($jsonFilename, $json); + } } if ($config['try_smarter']) -- cgit v1.3 From 67db118f1e77f864aa42fc6e81e2a8a2bf7bbcd4 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 2 Apr 2015 20:30:57 +0200 Subject: Revert "Revert "smart_build: buildThread" (for a moment, something b0rks)" This reverts commit b246daa191ed6495ce7a73a369c645599eea610e. --- inc/functions.php | 85 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 37 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 1c60393c..7ed3af5a 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -2068,51 +2068,62 @@ function buildThread($id, $return = false, $mod = false) { 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->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + if (!$config['smart_build'] || $return || $mod) { + $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->execute() or error(db_error($query)); - while ($post = $query->fetch(PDO::FETCH_ASSOC)) { - if (!isset($thread)) { - $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); - } else { - $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + if (!isset($thread)) { + $thread = new Thread($post, $mod ? '?/' : $config['root'], $mod); + } else { + $thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod)); + } } - } - // Check if any posts were found - if (!isset($thread)) - error($config['error']['nonexistant']); + // Check if any posts were found + if (!isset($thread)) + error($config['error']['nonexistant']); - $hasnoko50 = $thread->postCount() >= $config['noko50_min']; - $antibot = $mod || $return ? false : create_antibot($board['uri'], $id); - - $body = Element('thread.html', array( - 'board' => $board, - 'thread' => $thread, - 'body' => $thread->build(), - 'config' => $config, - 'id' => $id, - 'mod' => $mod, - 'hasnoko50' => $hasnoko50, - 'isnoko50' => false, - 'antibot' => $antibot, - 'boardlist' => createBoardlist($mod), - 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) - )); - - if ($config['try_smarter'] && !$mod) - $build_pages[] = thread_find_page($id); + $hasnoko50 = $thread->postCount() >= $config['noko50_min']; + $antibot = $mod || $return ? false : create_antibot($board['uri'], $id); - // json api - if ($config['api']['enabled']) { - $api = new Api(); - $json = json_encode($api->translateThread($thread)); + $body = Element('thread.html', array( + 'board' => $board, + 'thread' => $thread, + 'body' => $thread->build(), + 'config' => $config, + 'id' => $id, + 'mod' => $mod, + 'hasnoko50' => $hasnoko50, + 'isnoko50' => false, + 'antibot' => $antibot, + 'boardlist' => createBoardlist($mod), + 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) + )); + + if ($config['try_smarter'] && !$mod) + $build_pages[] = thread_find_page($id); + + // json api + if ($config['api']['enabled']) { + $api = new Api(); + $json = json_encode($api->translateThread($thread)); + $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; + file_write($jsonFilename, $json); + } + } + else { $jsonFilename = $board['dir'] . $config['dir']['res'] . $id . '.json'; - file_write($jsonFilename, $json); + file_unlink($jsonFilename); } - if ($return) { + if ($config['smart_build'] && !$return && !$mod) { + $noko50fn = $board['dir'] . $config['dir']['res'] . link_for(array('id' => $id), true); + file_unlink($noko50fn); + + file_unlink($board['dir'] . $config['dir']['res'] . link_for(array('id' => $id))); + } else if ($return) { return $body; } else { $noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true); -- cgit v1.3 From fa2e6cfa800462a6913f53d5b0843d2c5070069f Mon Sep 17 00:00:00 2001 From: Jayme Brereton Date: Sun, 5 Apr 2015 20:14:58 +0930 Subject: made the define_groups function play nice on hhvm --- inc/functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 7ed3af5a..e1d54590 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -328,8 +328,12 @@ function verbose_error_handler($errno, $errstr, $errfile, $errline) { function define_groups() { global $config; - foreach ($config['mod']['groups'] as $group_value => $group_name) - defined($group_name) or define($group_name, $group_value, true); + foreach ($config['mod']['groups'] as $group_value => $group_name) { + $group_name = strtoupper($group_name); + if(!defined($group_name)) { + define($group_name, $group_value, true); + } + } ksort($config['mod']['groups']); } -- cgit v1.3 From cbbebcd20ced5874b97452babbffdbc6d2278d58 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:26:32 +0200 Subject: optimization: if gettext.so is loaded, we don`t need the fallback implementation --- inc/functions.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 7ed3af5a..76b1d9a8 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -19,7 +19,9 @@ require_once 'inc/database.php'; require_once 'inc/events.php'; require_once 'inc/api.php'; require_once 'inc/bans.php'; -require_once 'inc/lib/gettext/gettext.inc'; +if (!extension_loaded('gettext')) { + require_once 'inc/lib/gettext/gettext.inc'; +} // the user is not currently logged in as a moderator $mod = false; @@ -29,14 +31,17 @@ mb_internal_encoding('UTF-8'); loadConfig(); function init_locale($locale, $error='error') { - if (_setlocale(LC_ALL, $locale) === false) { - $error('The specified locale (' . $locale . ') does not exist on your platform!'); - } if (extension_loaded('gettext')) { + if (setlocale(LC_ALL, $locale) === false) { + $error('The specified locale (' . $locale . ') does not exist on your platform!'); + } bindtextdomain('tinyboard', './inc/locale'); bind_textdomain_codeset('tinyboard', 'UTF-8'); textdomain('tinyboard'); } else { + if (_setlocale(LC_ALL, $locale) === false) { + $error('The specified locale (' . $locale . ') does not exist on your platform!'); + } _bindtextdomain('tinyboard', './inc/locale'); _bind_textdomain_codeset('tinyboard', 'UTF-8'); _textdomain('tinyboard'); -- cgit v1.3 From 34eeaccea9f3809fdfa465e9910c8fa84f836011 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:31:20 +0200 Subject: optimization: we don`t need bans.php most of the time and bans.php has big dependencies --- inc/functions.php | 1 - mod.php | 7 ++++--- post.php | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 76b1d9a8..b1b1b042 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -18,7 +18,6 @@ require_once 'inc/template.php'; require_once 'inc/database.php'; require_once 'inc/events.php'; require_once 'inc/api.php'; -require_once 'inc/bans.php'; if (!extension_loaded('gettext')) { require_once 'inc/lib/gettext/gettext.inc'; } diff --git a/mod.php b/mod.php index e06d5db6..5697e2b5 100644 --- a/mod.php +++ b/mod.php @@ -4,9 +4,10 @@ * Copyright (c) 2010-2014 Tinyboard Development Group */ -require 'inc/functions.php'; -require 'inc/mod/pages.php'; -require 'inc/mod/auth.php'; +require_once 'inc/functions.php'; +require_once 'inc/bans.php'; +require_once 'inc/mod/pages.php'; +require_once 'inc/mod/auth.php'; if ($config['debug']) $parse_start_time = microtime(true); diff --git a/post.php b/post.php index 09a5f53f..2b903b1c 100644 --- a/post.php +++ b/post.php @@ -3,8 +3,9 @@ * Copyright (c) 2010-2014 Tinyboard Development Group */ -require 'inc/functions.php'; -require 'inc/anti-bot.php'; +require_once 'inc/functions.php'; +require_once 'inc/anti-bot.php'; +require_once 'inc/bans.php'; // Fix for magic quotes if (get_magic_quotes_gpc()) { -- cgit v1.3 From 71ef3430fc3385f343b9e2c3eb4d05eaeca8607a Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:38:16 +0200 Subject: optimization: get rid of one more sql query related to installed themes --- inc/functions.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index b1b1b042..8a98659b 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -352,9 +352,22 @@ function rebuildThemes($action, $boardname = false) { $_board = $board; // List themes - $query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error()); + if ($themes = Cache::get("themes")) { + // OK, we already have themes loaded + } + else { + $query = query("SELECT `theme` FROM ``theme_settings`` WHERE `name` IS NULL AND `value` IS NULL") or error(db_error()); + + $themes = array(); + + while ($theme = $query->fetch(PDO::FETCH_ASSOC)) { + $themes[] = $theme; + } - while ($theme = $query->fetch(PDO::FETCH_ASSOC)) { + Cache::set("themes", $themes); + } + + foreach ($themes as $theme) { // Restore them $config = $_config; $board = $_board; @@ -415,6 +428,10 @@ function rebuildTheme($theme, $action, $board = false) { function themeSettings($theme) { + if ($settings = Cache::get("theme_settings_".$theme)) { + return $settings; + } + $query = prepare("SELECT `name`, `value` FROM ``theme_settings`` WHERE `theme` = :theme AND `name` IS NOT NULL"); $query->bindValue(':theme', $theme); $query->execute() or error(db_error($query)); @@ -424,6 +441,8 @@ function themeSettings($theme) { $settings[$s['name']] = $s['value']; } + Cache::set("theme_settings_".$theme, $settings); + return $settings; } -- cgit v1.3 From 758cb94e01945b16f730c08775666d3f5e65eb86 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:52:35 +0200 Subject: optimization: locale caching, so we don`t have to reparse instance-config every single time --- inc/functions.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 8a98659b..fc22e6ce 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -96,18 +96,28 @@ function loadConfig() { // Initialize locale as early as possible - $config['locale'] = 'en'; + // Those calls are expensive. Unfortunately, our cache system is not initialized at this point. + // So, we may store the locale in a tmp/ filesystem. - $configstr = file_get_contents('inc/instance-config.php'); + if (file_exists($fn = 'tmp/cache/locale_' . ( isset($board['uri']) ? $board['uri'] : '' ) ) ) { + $config['locale'] = file_get_contents($fn); + } + else { + $config['locale'] = 'en'; + + $configstr = file_get_contents('inc/instance-config.php'); if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) { - $configstr .= file_get_contents($board['dir'] . '/config.php'); + $configstr .= file_get_contents($board['dir'] . '/config.php'); } - $matches = array(); - preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches); - if ($matches && isset ($matches[2]) && $matches[2]) { - $matches = $matches[2]; - $config['locale'] = $matches[count($matches)-1]; + $matches = array(); + preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches); + if ($matches && isset ($matches[2]) && $matches[2]) { + $matches = $matches[2]; + $config['locale'] = $matches[count($matches)-1]; + } + + file_put_contents($fn, $config['locale']); } if ($config['locale'] != $current_locale) { -- cgit v1.3 From dc2928a14dcd29bf8502b6a9dc1357ad0e624251 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 18:48:53 +0200 Subject: cache_config preliminary release --- inc/config.php | 5 ++++ inc/functions.php | 71 +++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 15 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index be1bb8e1..3a63054c 100644 --- a/inc/config.php +++ b/inc/config.php @@ -137,6 +137,11 @@ // Tinyboard to use. $config['cache']['redis'] = array('localhost', 6379, '', 1); + // EXPERIMENTAL: Should we cache configs? Warning: this changes board behaviour, i'd say, a lot. + // If you have any lambdas/includes present in your config, you should move them to instance-functions.php + // (this file will be explicitly loaded during cache hit, but not during cache miss). + $config['cache_config'] = false; + /* * ==================== * Cookie settings diff --git a/inc/functions.php b/inc/functions.php index fc22e6ce..7b4dde7e 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -50,15 +50,40 @@ $current_locale = 'en'; function loadConfig() { - global $board, $config, $__ip, $debug, $__version, $microtime_start, $current_locale; + global $board, $config, $__ip, $debug, $__version, $microtime_start, $current_locale, $events; $error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet'; - reset_events(); + $boardsuffix = isset($board['uri']) ? $board['uri'] : ''; if (!isset($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = '0.0.0.0'; + if (file_exists('tmp/cache/cache_config.php')) { + require_once('tmp/cache/cache_config.php'); + } + + + if (isset($config['cache_config']) && + $config['cache_config'] && + $config = Cache::get('config_' . $boardsuffix ) ) { + $events = Cache::get('events_' . $boardsuffix ); + + if (file_exists('inc/instance-functions.php')) { + require_once('inc/instance-functions.php'); + } + + if ($config['locale'] != $current_locale) { + $current_locale = $config['locale']; + init_locale($config['locale'], $error); + } + } + else { + $config = array(); + // We will indent that later. + + reset_events(); + $arrays = array( 'db', 'api', @@ -86,7 +111,6 @@ function loadConfig() { 'dashboard_links' ); - $config = array(); foreach ($arrays as $key) { $config[$key] = array(); } @@ -99,7 +123,7 @@ function loadConfig() { // Those calls are expensive. Unfortunately, our cache system is not initialized at this point. // So, we may store the locale in a tmp/ filesystem. - if (file_exists($fn = 'tmp/cache/locale_' . ( isset($board['uri']) ? $board['uri'] : '' ) ) ) { + if (file_exists($fn = 'tmp/cache/locale_' . $boardsuffix ) ) { $config['locale'] = file_get_contents($fn); } else { @@ -138,8 +162,6 @@ function loadConfig() { init_locale($config['locale'], $error); } - date_default_timezone_set($config['timezone']); - if (!isset($config['global_message'])) $config['global_message'] = false; @@ -219,8 +241,22 @@ function loadConfig() { if (!isset($config['user_flags'])) $config['user_flags'] = array(); + if (!isset($__version)) + $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; + $config['version'] = $__version; + + if ($config['allow_roll']) + event_handler('post', 'diceRoller'); + + if (is_array($config['anonymous'])) + $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; + + + } // Effectful config processing below: + date_default_timezone_set($config['timezone']); + if ($config['root_file']) { chdir($config['root_file']); } @@ -233,10 +269,6 @@ function loadConfig() { if (preg_match('/^\:\:(ffff\:)?(\d+\.\d+\.\d+\.\d+)$/', $__ip, $m)) $_SERVER['REMOTE_ADDR'] = $m[2]; - if (!isset($__version)) - $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; - $config['version'] = $__version; - if ($config['verbose_errors']) { set_error_handler('verbose_error_handler'); error_reporting(E_ALL); @@ -260,13 +292,22 @@ function loadConfig() { event_handler('post', 'postHandler'); } - if (is_array($config['anonymous'])) - $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; + event('load-config'); - if ($config['allow_roll']) - event_handler('post', 'diceRoller'); + if ($config['cache_config'] && !isset ($config['cache_config_loaded'])) { + file_put_contents('tmp/cache/cache_config.php', ' Date: Sun, 5 Apr 2015 19:12:41 +0200 Subject: indent the file (inc/functions.php) after the latest changes --- inc/functions.php | 312 +++++++++++++++++++++++++++--------------------------- 1 file changed, 155 insertions(+), 157 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 7b4dde7e..12135983 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -80,177 +80,175 @@ function loadConfig() { } else { $config = array(); - // We will indent that later. - - reset_events(); - - $arrays = array( - 'db', - 'api', - 'cache', - 'cookies', - 'error', - 'dir', - 'mod', - 'spam', - 'filters', - 'wordfilters', - 'custom_capcode', - 'custom_tripcode', - 'dnsbl', - 'dnsbl_exceptions', - 'remote', - 'allowed_ext', - 'allowed_ext_files', - 'file_icons', - 'footer', - 'stylesheets', - 'additional_javascript', - 'markup', - 'custom_pages', - 'dashboard_links' - ); - - foreach ($arrays as $key) { - $config[$key] = array(); - } - if (!file_exists('inc/instance-config.php')) - $error('Tinyboard is not configured! Create inc/instance-config.php.'); + reset_events(); + + $arrays = array( + 'db', + 'api', + 'cache', + 'cookies', + 'error', + 'dir', + 'mod', + 'spam', + 'filters', + 'wordfilters', + 'custom_capcode', + 'custom_tripcode', + 'dnsbl', + 'dnsbl_exceptions', + 'remote', + 'allowed_ext', + 'allowed_ext_files', + 'file_icons', + 'footer', + 'stylesheets', + 'additional_javascript', + 'markup', + 'custom_pages', + 'dashboard_links' + ); - // Initialize locale as early as possible + foreach ($arrays as $key) { + $config[$key] = array(); + } - // Those calls are expensive. Unfortunately, our cache system is not initialized at this point. - // So, we may store the locale in a tmp/ filesystem. + if (!file_exists('inc/instance-config.php')) + $error('Tinyboard is not configured! Create inc/instance-config.php.'); - if (file_exists($fn = 'tmp/cache/locale_' . $boardsuffix ) ) { - $config['locale'] = file_get_contents($fn); - } - else { - $config['locale'] = 'en'; + // Initialize locale as early as possible - $configstr = file_get_contents('inc/instance-config.php'); + // Those calls are expensive. Unfortunately, our cache system is not initialized at this point. + // So, we may store the locale in a tmp/ filesystem. - if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) { - $configstr .= file_get_contents($board['dir'] . '/config.php'); - } - $matches = array(); - preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches); - if ($matches && isset ($matches[2]) && $matches[2]) { - $matches = $matches[2]; - $config['locale'] = $matches[count($matches)-1]; + if (file_exists($fn = 'tmp/cache/locale_' . $boardsuffix ) ) { + $config['locale'] = file_get_contents($fn); } + else { + $config['locale'] = 'en'; - file_put_contents($fn, $config['locale']); - } + $configstr = file_get_contents('inc/instance-config.php'); - if ($config['locale'] != $current_locale) { - $current_locale = $config['locale']; - init_locale($config['locale'], $error); - } + if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) { + $configstr .= file_get_contents($board['dir'] . '/config.php'); + } + $matches = array(); + preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches); + if ($matches && isset ($matches[2]) && $matches[2]) { + $matches = $matches[2]; + $config['locale'] = $matches[count($matches)-1]; + } - require 'inc/config.php'; + file_put_contents($fn, $config['locale']); + } - require 'inc/instance-config.php'; + if ($config['locale'] != $current_locale) { + $current_locale = $config['locale']; + init_locale($config['locale'], $error); + } - if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) { - require $board['dir'] . '/config.php'; - } + require 'inc/config.php'; - if ($config['locale'] != $current_locale) { - $current_locale = $config['locale']; - init_locale($config['locale'], $error); - } - - if (!isset($config['global_message'])) - $config['global_message'] = false; - - if (!isset($config['post_url'])) - $config['post_url'] = $config['root'] . $config['file_post']; - - - if (!isset($config['referer_match'])) - if (isset($_SERVER['HTTP_HOST'])) { - $config['referer_match'] = '/^' . - (preg_match('@^https?://@', $config['root']) ? '' : - 'https?:\/\/' . $_SERVER['HTTP_HOST']) . - preg_quote($config['root'], '/') . - '(' . - str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) . - '(' . - preg_quote($config['file_index'], '/') . '|' . - str_replace('%d', '\d+', preg_quote($config['file_page'])) . - ')?' . - '|' . - str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) . - preg_quote($config['dir']['res'], '/') . - '(' . - str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . - str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . '|' . - str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' . - str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . - ')' . - '|' . - preg_quote($config['file_mod'], '/') . '\?\/.+' . - ')([#?](.+)?)?$/ui'; - } else { - // CLI mode - $config['referer_match'] = '//'; - } - if (!isset($config['cookies']['path'])) - $config['cookies']['path'] = &$config['root']; - - if (!isset($config['dir']['static'])) - $config['dir']['static'] = $config['root'] . 'static/'; - - if (!isset($config['image_blank'])) - $config['image_blank'] = $config['dir']['static'] . 'blank.gif'; - - if (!isset($config['image_sticky'])) - $config['image_sticky'] = $config['dir']['static'] . 'sticky.gif'; - if (!isset($config['image_locked'])) - $config['image_locked'] = $config['dir']['static'] . 'locked.gif'; - if (!isset($config['image_bumplocked'])) - $config['image_bumplocked'] = $config['dir']['static'] . 'sage.gif'; - if (!isset($config['image_deleted'])) - $config['image_deleted'] = $config['dir']['static'] . 'deleted.png'; - - if (!isset($config['uri_thumb'])) - $config['uri_thumb'] = $config['root'] . $board['dir'] . $config['dir']['thumb']; - elseif (isset($board['dir'])) - $config['uri_thumb'] = sprintf($config['uri_thumb'], $board['dir']); - - if (!isset($config['uri_img'])) - $config['uri_img'] = $config['root'] . $board['dir'] . $config['dir']['img']; - elseif (isset($board['dir'])) - $config['uri_img'] = sprintf($config['uri_img'], $board['dir']); - - if (!isset($config['uri_stylesheets'])) - $config['uri_stylesheets'] = $config['root'] . 'stylesheets/'; - - if (!isset($config['url_stylesheet'])) - $config['url_stylesheet'] = $config['uri_stylesheets'] . 'style.css'; - if (!isset($config['url_javascript'])) - $config['url_javascript'] = $config['root'] . $config['file_script']; - if (!isset($config['additional_javascript_url'])) - $config['additional_javascript_url'] = $config['root']; - if (!isset($config['uri_flags'])) - $config['uri_flags'] = $config['root'] . 'static/flags/%s.png'; - if (!isset($config['user_flag'])) - $config['user_flag'] = false; - if (!isset($config['user_flags'])) - $config['user_flags'] = array(); - - if (!isset($__version)) - $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; - $config['version'] = $__version; - - if ($config['allow_roll']) - event_handler('post', 'diceRoller'); - - if (is_array($config['anonymous'])) - $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; + require 'inc/instance-config.php'; + if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) { + require $board['dir'] . '/config.php'; + } + + if ($config['locale'] != $current_locale) { + $current_locale = $config['locale']; + init_locale($config['locale'], $error); + } + + if (!isset($config['global_message'])) + $config['global_message'] = false; + + if (!isset($config['post_url'])) + $config['post_url'] = $config['root'] . $config['file_post']; + + + if (!isset($config['referer_match'])) + if (isset($_SERVER['HTTP_HOST'])) { + $config['referer_match'] = '/^' . + (preg_match('@^https?://@', $config['root']) ? '' : + 'https?:\/\/' . $_SERVER['HTTP_HOST']) . + preg_quote($config['root'], '/') . + '(' . + str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) . + '(' . + preg_quote($config['file_index'], '/') . '|' . + str_replace('%d', '\d+', preg_quote($config['file_page'])) . + ')?' . + '|' . + str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) . + preg_quote($config['dir']['res'], '/') . + '(' . + str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . + str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . '|' . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . + ')' . + '|' . + preg_quote($config['file_mod'], '/') . '\?\/.+' . + ')([#?](.+)?)?$/ui'; + } else { + // CLI mode + $config['referer_match'] = '//'; + } + if (!isset($config['cookies']['path'])) + $config['cookies']['path'] = &$config['root']; + + if (!isset($config['dir']['static'])) + $config['dir']['static'] = $config['root'] . 'static/'; + + if (!isset($config['image_blank'])) + $config['image_blank'] = $config['dir']['static'] . 'blank.gif'; + + if (!isset($config['image_sticky'])) + $config['image_sticky'] = $config['dir']['static'] . 'sticky.gif'; + if (!isset($config['image_locked'])) + $config['image_locked'] = $config['dir']['static'] . 'locked.gif'; + if (!isset($config['image_bumplocked'])) + $config['image_bumplocked'] = $config['dir']['static'] . 'sage.gif'; + if (!isset($config['image_deleted'])) + $config['image_deleted'] = $config['dir']['static'] . 'deleted.png'; + + if (!isset($config['uri_thumb'])) + $config['uri_thumb'] = $config['root'] . $board['dir'] . $config['dir']['thumb']; + elseif (isset($board['dir'])) + $config['uri_thumb'] = sprintf($config['uri_thumb'], $board['dir']); + + if (!isset($config['uri_img'])) + $config['uri_img'] = $config['root'] . $board['dir'] . $config['dir']['img']; + elseif (isset($board['dir'])) + $config['uri_img'] = sprintf($config['uri_img'], $board['dir']); + + if (!isset($config['uri_stylesheets'])) + $config['uri_stylesheets'] = $config['root'] . 'stylesheets/'; + + if (!isset($config['url_stylesheet'])) + $config['url_stylesheet'] = $config['uri_stylesheets'] . 'style.css'; + if (!isset($config['url_javascript'])) + $config['url_javascript'] = $config['root'] . $config['file_script']; + if (!isset($config['additional_javascript_url'])) + $config['additional_javascript_url'] = $config['root']; + if (!isset($config['uri_flags'])) + $config['uri_flags'] = $config['root'] . 'static/flags/%s.png'; + if (!isset($config['user_flag'])) + $config['user_flag'] = false; + if (!isset($config['user_flags'])) + $config['user_flags'] = array(); + + if (!isset($__version)) + $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; + $config['version'] = $__version; + + if ($config['allow_roll']) + event_handler('post', 'diceRoller'); + + if (is_array($config['anonymous'])) + $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; } // Effectful config processing below: -- cgit v1.3 From f053450edfc137e369839fe7203d50315d76fccf Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 20:04:27 +0200 Subject: cache_config: fix debug notice --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 12135983..a9e912bd 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -295,9 +295,9 @@ function loadConfig() { if ($config['cache_config'] && !isset ($config['cache_config_loaded'])) { file_put_contents('tmp/cache/cache_config.php', ' Date: Sun, 5 Apr 2015 20:23:57 +0200 Subject: fix a locale issue --- inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index a9e912bd..147d269e 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -32,7 +32,7 @@ loadConfig(); function init_locale($locale, $error='error') { if (extension_loaded('gettext')) { if (setlocale(LC_ALL, $locale) === false) { - $error('The specified locale (' . $locale . ') does not exist on your platform!'); + //$error('The specified locale (' . $locale . ') does not exist on your platform!'); } bindtextdomain('tinyboard', './inc/locale'); bind_textdomain_codeset('tinyboard', 'UTF-8'); -- cgit v1.3 From 9831b582fa4c8fa0581ad8c6ea95ae28bbba8654 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 20:25:57 +0200 Subject: groups were not defined --- inc/functions.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 147d269e..2bd7fd93 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -69,6 +69,8 @@ function loadConfig() { $config = Cache::get('config_' . $boardsuffix ) ) { $events = Cache::get('events_' . $boardsuffix ); + define_groups(); + if (file_exists('inc/instance-functions.php')) { require_once('inc/instance-functions.php'); } -- cgit v1.3 From 094f60d34dce0d639b04ef28d5719e22551db288 Mon Sep 17 00:00:00 2001 From: czaks Date: Mon, 6 Apr 2015 18:59:33 +0200 Subject: try_smarter: fix two bugs. 1. uncovered by the second, during a bump only the page the thread was on and first page were rebuild, despite threads rearranging their positions on the remaining pages. happening always. 2. during smart build, the page wasn`t ordered to be rebuilt --- inc/functions.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/functions.php b/inc/functions.php index 676f5b68..a6c85a19 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1104,8 +1104,9 @@ function bumpThread($id) { if (event('bump', $id)) return true; - if ($config['try_smarter']) - $build_pages[] = thread_find_page($id); + if ($config['try_smarter']) { + $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->bindValue(':time', time(), PDO::PARAM_INT); @@ -2146,6 +2147,9 @@ function buildThread($id, $return = false, $mod = false) { cache::delete("thread_{$board['uri']}_{$id}"); } + if ($config['try_smarter'] && !$mod) + $build_pages[] = thread_find_page($id); + if (!$config['smart_build'] || $return || $mod) { $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); @@ -2180,9 +2184,6 @@ function buildThread($id, $return = false, $mod = false) { 'return' => ($mod ? '?' . $board['url'] . $config['file_index'] : $config['root'] . $board['dir'] . $config['file_index']) )); - if ($config['try_smarter'] && !$mod) - $build_pages[] = thread_find_page($id); - // json api if ($config['api']['enabled']) { $api = new Api(); -- cgit v1.3 From 197d5f236f0d35126f90c767c4580a71600298b4 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 12 Apr 2015 00:32:58 +0200 Subject: [code] tag support --- inc/config.php | 11 ++++------- inc/functions.php | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index 3a63054c..b7c60125 100644 --- a/inc/config.php +++ b/inc/config.php @@ -624,13 +624,10 @@ $config['markup'][] = array("/\*\*(.+?)\*\*/", "\$1"); $config['markup'][] = array("/^[ |\t]*==(.+?)==[ |\t]*$/m", "\$1"); - // Highlight PHP code wrapped in tags (PHP 5.3+) - // $config['markup'][] = array( - // '/^<code>(.+)<\/code>/ms', - // function($matches) { - // return highlight_string(html_entity_decode($matches[1]), true); - // } - // ); + // Code markup. This should be set to a regular expression, using tags you want to use. Examples: + // "/\[code\](.*?)[\/code]/is" + // "/```([a-z0-9-]{0,20})\n(.*?)\n?```/s" + $config['markup_code'] = false; // Repair markup with HTML Tidy. This may be slower, but it solves nesting mistakes. Tinyboad, at the // time of writing this, can not prevent out-of-order markup tags (eg. "**''test**'') without help from diff --git a/inc/functions.php b/inc/functions.php index a6c85a19..5a52d602 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1857,6 +1857,15 @@ function markup(&$body, $track_cites = false) { if (mysql_version() < 50503) $body = mb_encode_numericentity($body, array(0x010000, 0xffffff, 0, 0xffffff), 'UTF-8'); + if ($config['markup_code']) { + $code_markup = array(); + $body = preg_replace_callback($config['markup_code'], function($matches) use (&$code_markup) { + $d = count($code_markup); + $code_markup[] = $matches; + return ""; + }, $body); + } + foreach ($config['markup'] as $markup) { if (is_string($markup[1])) { $body = preg_replace($markup[0], $markup[1], $body); @@ -2054,7 +2063,19 @@ function markup(&$body, $track_cites = false) { $body = preg_replace('/\s+$/', '', $body); $body = preg_replace("/\n/", '
', $body); - + + // Fix code markup + if ($config['markup_code']) { + foreach ($code_markup as $id => $val) { + $code = isset($val[2]) ? $val[2] : $val[1]; + $code_lang = isset($val[2]) ? $val[1] : ""; + + $code = "
".str_replace(array("\n","\t"), array("
","	"), htmlspecialchars($code))."
"; + + $body = str_replace("", $code, $body); + } + } + if ($config['markup_repair_tidy']) { $tidy = new tidy(); $body = str_replace("\t", ' ', $body); @@ -2072,10 +2093,10 @@ function markup(&$body, $track_cites = false) { ), 'utf8'); $body = str_replace("\n", '', $body); } - + // replace tabs with 8 spaces $body = str_replace("\t", ' ', $body); - + return $tracked_cites; } -- cgit v1.3 From 4014682882d0b390dc099d05e6701521e5f64a31 Mon Sep 17 00:00:00 2001 From: Marcin Łabanowski Date: Wed, 22 Apr 2015 05:54:48 +0200 Subject: fileboard support --- inc/config.php | 15 ++++++++++++- inc/display.php | 3 ++- inc/functions.php | 4 ++++ post.php | 17 +++++++++++++-- stylesheets/burichan.css | 2 +- stylesheets/caffe.css | 2 +- stylesheets/confraria.css | 8 +++---- stylesheets/dark.css | 10 ++++----- stylesheets/dark_roach.css | 24 ++++++++++----------- stylesheets/favela.css | 4 ++-- stylesheets/ferus.css | 10 ++++----- stylesheets/futaba+vichan.css | 4 ++-- stylesheets/futaba-light.css | 4 ++-- stylesheets/futaba.css | 4 ++-- stylesheets/gentoochan.css | 4 ++-- stylesheets/jungle.css | 4 ++-- stylesheets/luna.css | 22 +++++++++---------- stylesheets/miku.css | 8 +++---- stylesheets/nigrachan.css | 8 +++---- stylesheets/notsuba.css | 8 +++---- stylesheets/novo_jungle.css | 6 +++--- stylesheets/piwnichan.css | 4 ++-- stylesheets/ricechan.css | 2 +- stylesheets/style.css | 37 +++++++++++++++++++------------ stylesheets/szalet.css | 4 ++-- stylesheets/terminal2.css | 10 ++++----- stylesheets/testorange.css | 2 +- stylesheets/v8ch.css | 2 +- stylesheets/wasabi.css | 18 ++++++++-------- stylesheets/yotsuba.css | 4 ++-- templates/fileboard.html | 15 +++++++++++++ templates/post_form.html | 12 +++++++++++ templates/post_thread_fileboard.html | 42 ++++++++++++++++++++++++++++++++++++ 33 files changed, 216 insertions(+), 107 deletions(-) create mode 100644 templates/fileboard.html create mode 100644 templates/post_thread_fileboard.html (limited to 'inc/functions.php') diff --git a/inc/config.php b/inc/config.php index f11ee5f1..32308bd4 100644 --- a/inc/config.php +++ b/inc/config.php @@ -282,7 +282,8 @@ 'file_url', 'json_response', 'user_flag', - 'no_country' + 'no_country', + 'tag' ); // Enable reCaptcha to make spam even harder. Rarely necessary. @@ -735,6 +736,11 @@ $config['allowed_ext'][] = 'png'; // $config['allowed_ext'][] = 'svg'; + // Allowed extensions for OP. Inherits from the above setting if set to false. Otherwise, it overrides both allowed_ext and + // allowed_ext_files (filetypes for downloadable files should be set in allowed_ext_files as well). This setting is useful + // for creating fileboards. + $config['allowed_ext_op'] = false; + // Allowed additional file extensions (not images; downloadable files). // $config['allowed_ext_files'][] = 'txt'; // $config['allowed_ext_files'][] = 'zip'; @@ -1518,6 +1524,13 @@ // Allow OP to remove arbitrary posts in his thread $config['user_moderation'] = false; + // File board. Like 4chan /f/ + $config['file_board'] = false; + + // Thread tags. Set to false to disable + // Example: array('A' => 'Chinese cartoons', 'M' => 'Music', 'P' => 'Pornography'); + $config['allowed_tags'] = false; + /* * ==================== * Public post search diff --git a/inc/display.php b/inc/display.php index 65525ab9..e7fb9320 100644 --- a/inc/display.php +++ b/inc/display.php @@ -453,7 +453,8 @@ class Thread { event('show-thread', $this); - $built = Element('post_thread.html', array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod)); + $file = ($index && $config['file_board']) ? 'post_thread_fileboard.html' : 'post_thread.html'; + $built = Element($file, array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod)); return $built; } diff --git a/inc/functions.php b/inc/functions.php index 5a52d602..aa91133f 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1358,6 +1358,10 @@ function index($page, $mod=false) { $body .= $thread->build(true); } + if ($config['file_board']) { + $body = Element('fileboard.html', array('body' => $body, 'mod' => $mod)); + } + return array( 'board' => $board, 'body' => $body, diff --git a/post.php b/post.php index 2b903b1c..5081845f 100644 --- a/post.php +++ b/post.php @@ -312,7 +312,12 @@ if (isset($_POST['delete'])) { $url_without_params = $post['file_url']; $post['extension'] = strtolower(mb_substr($url_without_params, mb_strrpos($url_without_params, '.') + 1)); - if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files'])) + + if ($post['op'] && $config['allowed_ext_op']) { + if (!in_array($post['extension'], $config['allowed_ext_op'])) + error($config['error']['unknownext']); + } + else if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files'])) error($config['error']['unknownext']); $post['file_tmp'] = tempnam($config['tmp'], 'url'); @@ -536,6 +541,10 @@ if (isset($_POST['delete'])) { "\n" . $flag_alt . ""; } + if ($config['allowed_tags'] && $_POST['op'] && isset($_POST['tag']) && isset($config['allowed_tags'][$_POST['tag']])) { + $post['body'] .= "\n" . $_POST['tag'] . ""; + } + if ($config['proxy_save'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $proxy = preg_replace("/[^0-9a-fA-F.,: ]/", '', $_SERVER['HTTP_X_FORWARDED_FOR']); $post['body'] .= "\n".$proxy.""; @@ -565,7 +574,11 @@ if (isset($_POST['delete'])) { if ($post['has_file']) { $fnarray = array(); foreach ($post['files'] as $key => &$file) { - if (!in_array($file['extension'], $config['allowed_ext']) && !in_array($file['extension'], $config['allowed_ext_files'])) + if ($post['op'] && $config['allowed_ext_op']) { + if (!in_array($file['extension'], $config['allowed_ext_op'])) + error($config['error']['unknownext']); + } + elseif (!in_array($file['extension'], $config['allowed_ext']) && !in_array($file['extension'], $config['allowed_ext_files'])) error($config['error']['unknownext']); $file['is_an_image'] = !in_array($file['extension'], $config['allowed_ext_files']); diff --git a/stylesheets/burichan.css b/stylesheets/burichan.css index f1bbd8e6..6b1de235 100644 --- a/stylesheets/burichan.css +++ b/stylesheets/burichan.css @@ -36,7 +36,7 @@ div.banner { font-weight: normal; } -p.intro span.name { +.intro span.name { font-family: serif; font-size: 12px; } diff --git a/stylesheets/caffe.css b/stylesheets/caffe.css index aee4d5ab..7ba7bd1c 100644 --- a/stylesheets/caffe.css +++ b/stylesheets/caffe.css @@ -353,7 +353,7 @@ width: 100%; #attention_bar:hover { background-color: rgba(88, 53, 41, 0.3); } -p.intro a.email span.name { +.intro a.email span.name { color: #8e6152; } a.post_no:hover { diff --git a/stylesheets/confraria.css b/stylesheets/confraria.css index 8769c6bb..3b60aaa6 100644 --- a/stylesheets/confraria.css +++ b/stylesheets/confraria.css @@ -55,11 +55,11 @@ form table tr th { padding: 0px 5px; } -p.intro span.name { +.intro span.name { color: #C5C8C6; } -p.intro span.subject { +.intro span.subject { color: #CC1105; font-weight: bold; } @@ -90,11 +90,11 @@ div.post.reply.highlighted { background: #4A4C4F; } -p.intro a.email span.name { +.intro a.email span.name { color: rgb(129, 162, 190); } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: rgb(95, 137, 172); } diff --git a/stylesheets/dark.css b/stylesheets/dark.css index beb12364..e21b264e 100644 --- a/stylesheets/dark.css +++ b/stylesheets/dark.css @@ -23,7 +23,7 @@ div.title, h1 { div.title p { font-size: 10px; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { color: #CCCCCC; text-decoration: none; font-family: sans-serif; @@ -61,21 +61,21 @@ div.post.reply div.body a:link, div.post.reply div.body a:visited { div.post.reply div.body a:link:hover, div.post.reply div.body a:visited:hover { color: #32DD72; } -p.intro span.subject { +.intro span.subject { font-size: 12px; font-family: sans-serif; color: #446655; font-weight: 800; } -p.intro span.name { +.intro span.name { color: #32DD72; font-weight: 800; } -p.intro a.capcode, p.intro a.nametag { +.intro a.capcode, p.intro a.nametag { color: magenta; margin-left: 0; } -p.intro a.email, p.intro a.email span.name, p.intro a.email:hover, p.intro a.email:hover span.name { +.intro a.email, p.intro a.email span.name, p.intro a.email:hover, p.intro a.email:hover span.name { color: #32ddaf; } input[type="text"], textarea, select { diff --git a/stylesheets/dark_roach.css b/stylesheets/dark_roach.css index 7d123c6d..89e050d4 100644 --- a/stylesheets/dark_roach.css +++ b/stylesheets/dark_roach.css @@ -20,7 +20,7 @@ a, a:visited { text-decoration: none; color: #9999CC; } -a:hover, p.intro a.post_no:hover { +a:hover, .intro a.post_no:hover { color: #996699 } a.post_no { @@ -28,19 +28,19 @@ a.post_no { margin: 0; padding: 0; } -p.intro a.post_no { +.intro a.post_no { color: inherit; } -p.intro a.post_no, p.intro a.email { +.intro a.post_no, p.intro a.email { margin: 0; } -p.intro a.email span.name { +.intro a.email span.name { color: #666699; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #663366; } -p.intro label { +.intro label { display: inline; } h2 { @@ -163,7 +163,7 @@ div.post.op { div.post.op hr { border-color: #000000; } -p.intro { +.intro { margin: 0.5em 0; padding: 0; padding-bottom: 0.2em; @@ -172,19 +172,19 @@ input.delete { float: left; margin: 1px 6px 0 0; } -p.intro span.subject { +.intro span.subject { color: #336699; font-weight: bold; } -p.intro span.name { +.intro span.name { color: #336600; font-weight: bold; } -p.intro span.capcode, p.intro a.capcode, p.intro a.nametag { +.intro span.capcode, p.intro a.capcode, p.intro a.nametag { color: #CC0000; margin-left: 0; } -p.intro a { +.intro a { margin-left: 8px; } div.delete { @@ -456,7 +456,7 @@ table.mod.config-editor input[type="text"] { background-color: #333333; opacity: 0.8; } -p.intro.thread-hidden { +.intro.thread-hidden { margin: 0px; padding: 0px; } diff --git a/stylesheets/favela.css b/stylesheets/favela.css index 6c9f6d58..52d24c76 100644 --- a/stylesheets/favela.css +++ b/stylesheets/favela.css @@ -46,7 +46,7 @@ form table tr th { color: #FFF; } -p.intro span.name { +.intro span.name { font-family: serif; } @@ -81,7 +81,7 @@ div[id^="thread_"].highlighted { background: #B5FFDD; } -p.intro a.email span.name { +.intro a.email span.name { color: #345456; } diff --git a/stylesheets/ferus.css b/stylesheets/ferus.css index f84d86ca..2517d3b0 100644 --- a/stylesheets/ferus.css +++ b/stylesheets/ferus.css @@ -16,7 +16,7 @@ div.title, h1 { div.title p { font-size: 13px; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { color: #16C816; text-decoration: underline; font-family: monospace; @@ -51,21 +51,21 @@ div.post.reply div.body a:link, div.post.reply div.body a:visited { div.post.reply div.body a:link:hover, div.post.reply div.body a:visited:hover { color: #00FF00; } -p.intro span.subject { +.intro span.subject { font-size: 12px; font-family: monospace; color: #446655; font-weight: 800; } -p.intro span.name { +.intro span.name { color: #008200; font-weight: 900; } -p.intro a.capcode, p.intro a.nametag { +.intro a.capcode, p.intro a.nametag { color: magenta; margin-left: 0; } -p.intro a.email, p.intro a.email span.name, p.intro a.email:hover, p.intro a.email:hover span.name { +.intro a.email, p.intro a.email span.name, p.intro a.email:hover, p.intro a.email:hover span.name { color: #00CC64; font-family: monospace; } diff --git a/stylesheets/futaba+vichan.css b/stylesheets/futaba+vichan.css index f00dc9b7..16dff61b 100644 --- a/stylesheets/futaba+vichan.css +++ b/stylesheets/futaba+vichan.css @@ -15,7 +15,7 @@ div.title p { div.pages { font-size: 13px !important; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { color: #0000ff; font-size: inherit; text-decoration: inherit; @@ -41,7 +41,7 @@ div.post.reply.highlighted { div.post.reply div.body a { color: navy; } -p.intro span.subject { +.intro span.subject { color: #d00; } form table tr th { diff --git a/stylesheets/futaba-light.css b/stylesheets/futaba-light.css index fc67709f..19166adf 100644 --- a/stylesheets/futaba-light.css +++ b/stylesheets/futaba-light.css @@ -15,7 +15,7 @@ div.title p { div.pages { font-size: 13px !important; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { color: #A32615; font-size: inherit; text-decoration: inherit; @@ -42,7 +42,7 @@ div.post.reply.highlighted { div.post.reply div.body a { color: rgb(190, 79, 43); } -p.intro span.subject { +.intro span.subject { color: #AA4848; } form table tr th { diff --git a/stylesheets/futaba.css b/stylesheets/futaba.css index 02c38351..2b4fc1d2 100644 --- a/stylesheets/futaba.css +++ b/stylesheets/futaba.css @@ -10,7 +10,7 @@ div.title h1 { div.title p { font-size: 10px; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { color: #0000ff; } a:link:hover { @@ -30,7 +30,7 @@ div.post.reply.highlighted { div.post.reply div.body a { color: navy; } -p.intro span.subject { +.intro span.subject { color: #d00; } form table tr th { diff --git a/stylesheets/gentoochan.css b/stylesheets/gentoochan.css index b5075136..ae7ef2f3 100644 --- a/stylesheets/gentoochan.css +++ b/stylesheets/gentoochan.css @@ -2,7 +2,7 @@ body { background: #0E0E0E url(data:image/gif;base64,R0lGODlhGAAMAKEEAOXl5ebm5vDw8PHx8SH+EUNyZWF0ZWQgd2l0aCBHSU1QACwAAAAAGAAMAAACRpQiY6cLa146MyY1EJQKjG81lNGRUPOIkgMJHtquBgIO7xwvpbrpduUSuXq8ntEC0bBEylYitdDAdM1ViaobkgKgZwyDLAAAOw==) repeat 0 0!important; color: #000; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { -webkit-transition: all ease-in 0.3s; -moz-transition: all ease-in 0.3s; color: rgba(0, 0, 0, 0.6); @@ -33,7 +33,7 @@ div.post.reply.highlighted { div.post.reply p.body a { color: navy; } -p.intro span.subject { +.intro span.subject { color: #000; } form table tr th { diff --git a/stylesheets/jungle.css b/stylesheets/jungle.css index 1765b3a9..86cb13b8 100644 --- a/stylesheets/jungle.css +++ b/stylesheets/jungle.css @@ -66,7 +66,7 @@ box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.35); div.post.reply div.body a { color: #00E; } -p.intro span.subject { +.intro span.subject { color: #d00; } form table tr th { @@ -118,7 +118,7 @@ table.modlog tr th { background: #EA8; } -p.intro span.name { +.intro span.name { color: maroon; font-weight: 600; } diff --git a/stylesheets/luna.css b/stylesheets/luna.css index 7439f5ca..e2fd6528 100644 --- a/stylesheets/luna.css +++ b/stylesheets/luna.css @@ -22,7 +22,7 @@ a, a:selected { text-decoration: bold; color: #ffffff; } -a:hover, p.intro a.post_no:hover { +a:hover, .intro a.post_no:hover { color: #ffffff; } a.post_no { @@ -30,19 +30,19 @@ a.post_no { margin: 0; padding: 0; } -p.intro a.post_no { +.intro a.post_no { color: inherit; } -p.intro a.post_no, p.intro a.email { +.intro a.post_no, p.intro a.email { margin: 0; } -p.intro a.email span.name { +.intro a.email span.name { color: #0091ff; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #ffffff; } -p.intro label { +.intro label { display: inline; } h2 { @@ -165,7 +165,7 @@ div.post.op { div.post.op hr { border-color: #040934; } -p.intro { +.intro { margin: 0.5em 0; padding: 0; padding-bottom: 0.2em; @@ -174,19 +174,19 @@ input.delete { float: left; margin: 1px 6px 0 0; } -p.intro span.subject { +.intro span.subject { color: #CCCCEE; font-weight: bold; } -p.intro span.name { +.intro span.name { color: #BBBBDD; font-weight: bold; } -p.intro span.capcode, p.intro a.capcode, p.intro a.nametag { +.intro span.capcode, p.intro a.capcode, p.intro a.nametag { color: #CCCCEE; margin-left: 0; } -p.intro a { +.intro a { margin-left: 8px; } div.delete { diff --git a/stylesheets/miku.css b/stylesheets/miku.css index 84e67933..7a8fb87e 100644 --- a/stylesheets/miku.css +++ b/stylesheets/miku.css @@ -19,11 +19,11 @@ a.post_no { color: #000033; } -p.intro a.email span.name { +.intro a.email span.name { color: #0093AB; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #DD0000; } @@ -43,12 +43,12 @@ div.post.op hr { border-color: #B7C9D5; } -p.intro span.subject { +.intro span.subject { color: #117743; font-weight: 800; } -p.intro span.name { +.intro span.name { color: #117743; font-weight: 800; } diff --git a/stylesheets/nigrachan.css b/stylesheets/nigrachan.css index 6d0a94fa..28ab3eb3 100644 --- a/stylesheets/nigrachan.css +++ b/stylesheets/nigrachan.css @@ -52,7 +52,7 @@ input[type="text"], input[type="password"], textarea, input[type="submit"], inpu border: 1px solid #202020; } -p.intro span.name { +.intro span.name { font-size: 11pt; color: #505050; font-weight: bold; @@ -88,16 +88,16 @@ div.post.reply.highlighted { background: #111111; } -p.intro a.email span.name { +.intro a.email span.name { color: #FFFFFF; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #A0A0A0; text-decoration: underline; } -p.intro span.subject { +.intro span.subject { color: #606060; } diff --git a/stylesheets/notsuba.css b/stylesheets/notsuba.css index ef9e1057..8ecb6b21 100644 --- a/stylesheets/notsuba.css +++ b/stylesheets/notsuba.css @@ -20,11 +20,11 @@ a.post_no { color: #000033; } -p.intro a.email span.name { +.intro a.email span.name { color: #608673; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #DD0000; } @@ -44,12 +44,12 @@ div.post.op hr { border-color: #608673; } -p.intro span.subject { +.intro span.subject { color: #8a2e2e; font-weight: 800; } -p.intro span.name { +.intro span.name { color: #117743; font-weight: 800; } diff --git a/stylesheets/novo_jungle.css b/stylesheets/novo_jungle.css index 70501d0a..8c313723 100644 --- a/stylesheets/novo_jungle.css +++ b/stylesheets/novo_jungle.css @@ -65,7 +65,7 @@ form[name="postcontrols"] { margin: 20px auto; } -p.intro span.name { +.intro span.name { color: #800000; font-weight: 800; } @@ -104,11 +104,11 @@ div.post.reply.highlighted { background-image: url('img/jungle_td_dark.png');; } -p.intro a.email span.name { +.intro a.email span.name { color: #0000EE; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #00990B; } diff --git a/stylesheets/piwnichan.css b/stylesheets/piwnichan.css index 2c1ea49a..7780226e 100644 --- a/stylesheets/piwnichan.css +++ b/stylesheets/piwnichan.css @@ -41,7 +41,7 @@ a.email span.name { color: #5A8C99 !important; } -p.intro span.capcode, p.intro a.capcode, p.intro a.nametag { +.intro span.capcode, p.intro a.capcode, p.intro a.nametag { color: #6E0877; } @@ -157,7 +157,7 @@ div.banner, .replymode, .catalogmode { font-weight:800; } -p.intro span.subject { +.intro span.subject { color: #4D2C80; font-weight: bold; } diff --git a/stylesheets/ricechan.css b/stylesheets/ricechan.css index 79b6d145..f01fc9bf 100644 --- a/stylesheets/ricechan.css +++ b/stylesheets/ricechan.css @@ -190,7 +190,7 @@ blockquote { .de-refmap { color: #4C505E !important; } -p.intro a.email span.name { +.intro a.email span.name { text-decoration: underline; } .quote { diff --git a/stylesheets/style.css b/stylesheets/style.css index 80b124f8..5ae23cd6 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -13,7 +13,7 @@ a,a:visited { color: #34345C; } -a:hover,p.intro a.post_no:hover { +a:hover,.intro a.post_no:hover { color: #ff0000; } @@ -23,27 +23,27 @@ a.post_no { padding: 0; } -p.intro a.post_no { +.intro a.post_no { color: inherit; } -p.intro a.post_no,p.intro a.email,p.intro a.post_anchor { +.intro a.post_no,p.intro a.email,p.intro a.post_anchor { margin: 0; } -p.intro a.email span.name { +.intro a.email span.name { color: #34345C; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #ff0000; } -p.intro label { +.intro label { display: inline; } -p.intro time,p.intro a.ip-link,p.intro a.capcode { +.intro time,p.intro a.ip-link,p.intro a.capcode { direction: ltr; unicode-bidi: embed; } @@ -219,7 +219,7 @@ div.post.op hr { border-color: #D9BFB7; } -p.intro { +.intro { margin: 0.5em 0; padding: 0; padding-bottom: 0.2em; @@ -230,22 +230,22 @@ input.delete { margin: 1px 6px 0 0; } -p.intro span.subject { +.intro span.subject { color: #0F0C5D; font-weight: bold; } -p.intro span.name { +.intro span.name { color: #117743; font-weight: bold; } -p.intro span.capcode,p.intro a.capcode,p.intro a.nametag { +.intro span.capcode,p.intro a.capcode,p.intro a.nametag { color: #F00000; margin-left: 0; } -p.intro a { +.intro a { margin-left: 8px; } @@ -604,7 +604,7 @@ table.mod.config-editor input[type="text"] { background-color: rgba(100%,100%,100%,0.2); } -p.intro.thread-hidden { +.intro.thread-hidden { margin: 0; padding: 0; } @@ -931,7 +931,7 @@ span.pln { @media screen and (min-width: 768px) { - p.intro { + .intro { clear: none; } @@ -1051,3 +1051,12 @@ span.pln { margin-left: 10px; margin-right: 10px; } + +/* Fileboard */ +table.fileboard th, table.fileboard td { + padding: 2px; + text-align: center; +} +table.fileboard .intro a { + margin-left: 0px; +} diff --git a/stylesheets/szalet.css b/stylesheets/szalet.css index e4deb8ee..77a216a6 100644 --- a/stylesheets/szalet.css +++ b/stylesheets/szalet.css @@ -20,7 +20,7 @@ background-repeat: repeat; background-color: #200000; } -p.intro span.capcode, p.intro a.capcode, p.intro a.nametag { +.intro span.capcode, p.intro a.capcode, p.intro a.nametag { color: #26899C; } @@ -154,7 +154,7 @@ div.banner, .replymode, .catalogmode { font-weight:800; } -p.intro span.subject { +.intro span.subject { color: #771018; font-weight: bold; } diff --git a/stylesheets/terminal2.css b/stylesheets/terminal2.css index f7463553..a951bc16 100644 --- a/stylesheets/terminal2.css +++ b/stylesheets/terminal2.css @@ -16,7 +16,7 @@ div.title, h1 { div.title p { font-size: 10px; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { color: #00FF00; text-decoration: underline; font-family: sans-serif; @@ -50,21 +50,21 @@ div.post.reply div.body a:link, div.post.reply div.body a:visited { div.post.reply div.body a:link:hover, div.post.reply div.body a:visited:hover { color: #00FF00; } -p.intro span.subject { +.intro span.subject { font-size: 12px; font-family: sans-serif; color: #446655; font-weight: 800; } -p.intro span.name { +.intro span.name { color: #00FF00; font-weight: 800; } -p.intro a.capcode, p.intro a.nametag { +.intro a.capcode, p.intro a.nametag { color: #00FF00; margin-left: 0; } -p.intro a.email, p.intro a.email span.name, p.intro a.email:hover, p.intro a.email:hover span.name { +.intro a.email, p.intro a.email span.name, p.intro a.email:hover, p.intro a.email:hover span.name { color: #00FF00; } input[type="text"], textarea, select { diff --git a/stylesheets/testorange.css b/stylesheets/testorange.css index cd2161b6..44ebd697 100644 --- a/stylesheets/testorange.css +++ b/stylesheets/testorange.css @@ -202,7 +202,7 @@ div.boardlist.bottom { background-color: rgba(0%, 0%, 0%, 0.45); } -p.intro span.subject { +.intro span.subject { color:#ee8100; } diff --git a/stylesheets/v8ch.css b/stylesheets/v8ch.css index bd8e68ab..eafed531 100644 --- a/stylesheets/v8ch.css +++ b/stylesheets/v8ch.css @@ -136,7 +136,7 @@ form table tr th{ background: #fec !important; } -p.intro.thread-hidden{ +.intro.thread-hidden{ padding-bottom: 1em !important; } diff --git a/stylesheets/wasabi.css b/stylesheets/wasabi.css index f898d731..87a81bdd 100644 --- a/stylesheets/wasabi.css +++ b/stylesheets/wasabi.css @@ -27,16 +27,16 @@ a.post_no { margin: 0; padding: 0; } -p.intro a.post_no, p.intro a.email { +.intro a.post_no, p.intro a.email { margin: 0; } -p.intro a.email span.name { +.intro a.email span.name { color: #34345C; } -p.intro a.email:hover span.name { +.intro a.email:hover span.name { color: #ff0000; } -p.intro label { +.intro label { display: inline; } h2 { @@ -155,7 +155,7 @@ div.post.op { div.post.op hr { border-color: #D9BFB7; } -p.intro { +.intro { margin: 0.5em 0; padding: 0; padding-bottom: 0.2em; @@ -164,19 +164,19 @@ input.delete { float: left; margin: 1px 6px 0 0; } -p.intro span.subject { +.intro span.subject { color: #0F0C5D; font-weight: bold; } -p.intro span.name { +.intro span.name { color: #117743; font-weight: bold; } -p.intro a.capcode, p.intro a.nametag { +.intro a.capcode, p.intro a.nametag { color: #F00000; margin-left: 0; } -p.intro a { +.intro a { margin-left: 8px; } div.delete { diff --git a/stylesheets/yotsuba.css b/stylesheets/yotsuba.css index 8997b696..5324d1a7 100644 --- a/stylesheets/yotsuba.css +++ b/stylesheets/yotsuba.css @@ -2,7 +2,7 @@ body { background: #ffe url('img/fade-yotsuba.png') repeat-x 50% 0%; color: #800000; } -a:link, a:visited, p.intro a.email span.name { +a:link, a:visited, .intro a.email span.name { color: #0000ff; } a:link:hover { @@ -22,7 +22,7 @@ div.post.reply.highlighted { div.post.reply div.body a { color: navy; } -p.intro span.subject { +.intro span.subject { color: #d00; } form table tr th { diff --git a/templates/fileboard.html b/templates/fileboard.html new file mode 100644 index 00000000..a970cecb --- /dev/null +++ b/templates/fileboard.html @@ -0,0 +1,15 @@ + + + + {{ body }} +
  + {% trans %}No.{% endtrans %} + {% trans %}Name{% endtrans %} + {% trans %}File{% endtrans %} + {% trans %}Tag{% endtrans %} + {% trans %}Subject{% endtrans %} + {% trans %}Size{% endtrans %} + {% trans %}Date{% endtrans %} + {% trans %}Replies{% endtrans %} +   +
diff --git a/templates/post_form.html b/templates/post_form.html index d2e644b3..ea3ac765 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -92,6 +92,18 @@ {% endif %} + {% if config.allowed_tags and not id %} + + {% trans %}Tag{% endtrans %} + + + + + {% endif %} {% trans %}File{% endtrans %} diff --git a/templates/post_thread_fileboard.html b/templates/post_thread_fileboard.html new file mode 100644 index 00000000..983bfe17 --- /dev/null +++ b/templates/post_thread_fileboard.html @@ -0,0 +1,42 @@ +{% filter remove_whitespace %} +{# tabs and new lines will be ignored #} + +{# we are intentionally breaking the thread_ID convention: the jses need to handle this case differently #} + + + +{{ post.id }} +{% include 'post/name.html' %} + {% include 'post/flag.html' %} +[{{ post.files[0].filename|e|bidi_cleanup }}] +{% if post.modifiers['tag'] %}[{{ post.modifiers['tag'] }}]{% endif %} +{% include 'post/subject.html' %} + {% if post.sticky %} + {% if config.font_awesome %} + + {% else %} + Sticky + {% endif %} + {% endif %} + {% if post.locked %} + {% if config.font_awesome %} + + {% else %} + Locked + {% endif %} + {% endif %} + {% if post.bumplocked and (config.mod.view_bumplock < 0 or (post.mod and post.mod|hasPermission(config.mod.view_bumplock, board.uri))) %} + {% if config.font_awesome %} + + {% else %} + Bumplocked + {% endif %} + {% endif %} +{{ post.files[0].size|filesize }} +{% include 'post/time.html' %} +{{ post.omitted }} +{% include 'post/post_controls.html' %} + [{% trans %}Reply{% endtrans %}] + + +{% endfilter %} -- cgit v1.3