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') 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') 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 58b60f0aa4ef14589315a66fcf58d749928483c7 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:46:34 +0100 Subject: ... --- inc/mod/pages.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 79d1bf51..2b7de134 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1224,7 +1224,10 @@ function mod_move($originBoard, $postID) { // create the new thread $newID = post($post); - + + $op = $post; + $op['id'] = $newID; + if ($post['has_file']) { // copy image foreach ($post['files'] as $i => &$file) { @@ -1357,14 +1360,14 @@ function mod_move($originBoard, $postID) { buildIndex(); - header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($post, false, $newboard) . + header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($op, false, $newboard) . '#' . $botID, true, $config['redirect_http']); } else { deletePost($postID); buildIndex(); openBoard($targetBoard); - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post, false, $newboard), true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($op, false, $newboard), true, $config['redirect_http']); } } -- cgit v1.3 From 2f7aeec53128b08e000e89bc031f25c0501565f3 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:48:33 +0100 Subject: ... --- inc/mod/pages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 2b7de134..be713f57 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1360,14 +1360,14 @@ function mod_move($originBoard, $postID) { buildIndex(); - header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($op, false, $newboard) . + header('Location: ?/' . sprintf($config['board_path'], $newboard['uri']) . $config['dir']['res'] . link_for($op, false, $newboard) . '#' . $botID, true, $config['redirect_http']); } else { deletePost($postID); buildIndex(); openBoard($targetBoard); - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($op, false, $newboard), true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $newboard['uri']) . $config['dir']['res'] . link_for($op, false, $newboard), true, $config['redirect_http']); } } -- 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') 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 50b80e9e2452cfffadeb6918150736a4dde7834a Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 14:06:44 +0100 Subject: ... (slug api) --- inc/api.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc') diff --git a/inc/api.php b/inc/api.php index c9608f06..351943a3 100644 --- a/inc/api.php +++ b/inc/api.php @@ -33,6 +33,7 @@ class Api { 'sticky' => 'sticky', 'locked' => 'locked', 'bump' => 'last_modified', + 'slug' => 'semantic_url', ); $this->threadsPageFields = array( -- 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') 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') 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 6c4d3941fa729558f4a5313081c85b0a06202e54 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 14:22:29 +0100 Subject: api fix --- inc/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/api.php b/inc/api.php index c9608f06..661ee109 100644 --- a/inc/api.php +++ b/inc/api.php @@ -109,7 +109,7 @@ class Api { if (isset($post->files) && $post->files && !$threadsPage) { $file = $post->files[0]; $this->translateFields($this->fileFields, $file, $apiPost); - $apiPost['filename'] = substr($file->name, 0, strrpos($file->name, '.')); + $apiPost['filename'] = isset($file->name) ? substr($file->name, 0, strrpos($file->name, '.')) : ""; $dotPos = strrpos($file->file, '.'); $apiPost['ext'] = substr($file->file, $dotPos); $apiPost['tim'] = substr($file->file, 0, $dotPos); -- cgit v1.3 From 10a82199656aa5a9f5b81afda1a2f3512f46efe2 Mon Sep 17 00:00:00 2001 From: Marcin Łabanowski Date: Thu, 12 Mar 2015 00:00:59 +0100 Subject: enable a `basic` cache by default; notify me if it breaks your chan --- inc/config.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/config.php b/inc/config.php index ac4acaa4..42e1c32b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -115,7 +115,7 @@ * http://tinyboard.org/docs/index.php?p=Config/Cache */ - $config['cache']['enabled'] = false; + $config['cache']['enabled'] = 'php'; // $config['cache']['enabled'] = 'xcache'; // $config['cache']['enabled'] = 'apc'; // $config['cache']['enabled'] = 'memcached'; @@ -570,6 +570,9 @@ // Use semantic URLs for threads, like /b/res/12345/daily-programming-thread.html $config['slugify'] = false; + // Max size for slugs + $config['slug_max_size'] = 80; + /* * ==================== * Ban settings -- 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') 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') 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') 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 300e9e7e71bb9a3e095dca425e944e2fbf6e5117 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 31 Mar 2015 05:20:00 +0200 Subject: fix some png images being discarded --- inc/image.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/image.php b/inc/image.php index 7a68605d..291f3e2a 100644 --- a/inc/image.php +++ b/inc/image.php @@ -363,9 +363,10 @@ class ImageConvert extends ImageBase { $this->height, escapeshellarg($this->temp)))) || !file_exists($this->temp)) { - if (strpos($error, "known incorrect sRGB profile") === false) { + if (strpos($error, "known incorrect sRGB profile") === false && + strpos($error, "iCCP: Not recognizing known sRGB profile that has been edited") === false) { $this->destroy(); - error('Failed to resize image!', null, array('convert_error' => $error)); + error(_('Failed to resize image!')." "._('Details: ').nl2br(htmlspecialchars($error)), null, array('convert_error' => $error)); } if (!file_exists($this->temp)) { $this->destroy(); -- cgit v1.3 From 4a22ee9245b81e9a94bcc18128cf9ad10d19d901 Mon Sep 17 00:00:00 2001 From: 8chan Date: Thu, 30 Oct 2014 05:33:01 -0700 Subject: Extra files and IDs in API Conflicts: inc/api.php --- inc/api.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/api.php b/inc/api.php index ac3b1325..eb99d3fb 100644 --- a/inc/api.php +++ b/inc/api.php @@ -86,11 +86,22 @@ class Api { } } + private function translateFile($file, $post, &$apiPost) { + $this->translateFields($this->fileFields, $file, $apiPost); + $apiPost['filename'] = @substr($file->name, 0, strrpos($file->name, '.')); + $dotPos = strrpos($file->file, '.'); + $apiPost['ext'] = substr($file->file, $dotPos); + $apiPost['tim'] = substr($file->file, 0, $dotPos); + $apiPost['md5'] = base64_encode(hex2bin($post->filehash)); + } + private function translatePost($post, $threadsPage = false) { + global $config, $board; $apiPost = array(); $fields = $threadsPage ? $this->threadsPageFields : $this->postFields; $this->translateFields($fields, $post, $apiPost); + if (isset($config['poster_ids'])) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']); if ($threadsPage) return $apiPost; // Handle country field @@ -109,12 +120,19 @@ class Api { // Note: 4chan only supports one file, so only the first file is taken into account for 4chan-compatible API. if (isset($post->files) && $post->files && !$threadsPage) { $file = $post->files[0]; - $this->translateFields($this->fileFields, $file, $apiPost); - $apiPost['filename'] = isset($file->name) ? substr($file->name, 0, strrpos($file->name, '.')) : ""; - $dotPos = strrpos($file->file, '.'); - $apiPost['ext'] = substr($file->file, $dotPos); - $apiPost['tim'] = substr($file->file, 0, $dotPos); - $apiPost['md5'] = base64_encode(hex2bin($post->filehash)); + $this->translateFile($file, $post, $apiPost); + if (sizeof($post->files) > 1) { + $extra_files = array(); + foreach ($post->files as $i => $f) { + if ($i == 0) continue; + + $extra_file = array(); + $this->translateFile($f, $post, $extra_file); + + $extra_files[] = $extra_file; + } + $apiPost['extra_files'] = $extra_files; + } } return $apiPost; -- cgit v1.3 From e35d261ff48e38ea109e29feeed7f8edaaf82b4a Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 31 Mar 2015 05:32:38 +0200 Subject: enable embed field for api --- inc/api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/api.php b/inc/api.php index eb99d3fb..f8f2a71c 100644 --- a/inc/api.php +++ b/inc/api.php @@ -1,4 +1,4 @@ - 'sticky', 'locked' => 'locked', 'bump' => 'last_modified', + 'embed' => 'embed', 'slug' => 'semantic_url', ); -- cgit v1.3 From 5a9af83ba64fcc5547f3c5206121cff3992a3663 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 31 Mar 2015 05:50:52 +0200 Subject: better slugify support for api --- inc/api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/api.php b/inc/api.php index f8f2a71c..a057f4ed 100644 --- a/inc/api.php +++ b/inc/api.php @@ -34,7 +34,6 @@ class Api { 'locked' => 'locked', 'bump' => 'last_modified', 'embed' => 'embed', - 'slug' => 'semantic_url', ); $this->threadsPageFields = array( @@ -117,6 +116,10 @@ class Api { } } + if ($config['slugify'] && !$post->thread) { + $apiPost['semantic_url'] = $post->slug; + } + // Handle files // Note: 4chan only supports one file, so only the first file is taken into account for 4chan-compatible API. if (isset($post->files) && $post->files && !$threadsPage) { -- 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') 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') 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') 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 e4e01e45733488a756f457f0681dc90b28f6fa1b Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 1 Apr 2015 17:16:30 +0200 Subject: smart build: define configuration variables --- inc/config.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/config.php b/inc/config.php index 0ba1952b..be1bb8e1 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1181,9 +1181,20 @@ // Website favicon. // $config['url_favicon'] = '/favicon.gif'; - // EXPERIMENTAL: Try not to build pages when we shouldn't have to. + // Try not to build pages when we shouldn't have to. $config['try_smarter'] = true; + // EXPERIMENTAL: Defer static HTML building to a moment, when a given file is actually accessed. + // Warning: This option won't run out of the box. You need to tell your webserver, that a file + // for serving 403 and 404 pages is /smart_build.php. Also, you need to turn off indexes. + $config['smart_build'] = false; + + // Smart build related: when a file doesn't exist, where should we redirect? + $config['page_404'] = '/404.html'; + + // Smart build related: extra entrypoints. + $config['smart_build_entrypoints'] = array(); + /* * ==================== * Mod settings -- 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') 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') 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') 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') 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') 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') 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') 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') 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 8cf28682e74baf592df8b0949e76922fa76de08e Mon Sep 17 00:00:00 2001 From: Jason Puglisi Date: Fri, 3 Apr 2015 08:03:15 -0400 Subject: Removed tab at start of api.php to fix ban list and possibly other stuff --- inc/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/api.php b/inc/api.php index a057f4ed..b77fa3f8 100644 --- a/inc/api.php +++ b/inc/api.php @@ -1,4 +1,4 @@ - 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') 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') 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') 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') 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') 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 b78b3db0105c832f3e5b1f5cca019bb41a137662 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:59:04 +0200 Subject: uncache themes on settings change --- inc/mod/pages.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index be713f57..969c570e 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2501,10 +2501,14 @@ function mod_theme_configure($theme_name) { $query->bindValue(':value', $_POST[$conf['name']]); $query->execute() or error(db_error($query)); } - + $query = prepare("INSERT INTO ``theme_settings`` VALUES(:theme, NULL, NULL)"); $query->bindValue(':theme', $theme_name); $query->execute() or error(db_error($query)); + + // Clean cache + Cache::delete("themes"); + Cache::delete("theme_settings_".$theme); $result = true; $message = false; @@ -2552,11 +2556,15 @@ function mod_theme_uninstall($theme_name) { if (!hasPermission($config['mod']['themes'])) error($config['error']['noaccess']); - + $query = prepare("DELETE FROM ``theme_settings`` WHERE `theme` = :theme"); $query->bindValue(':theme', $theme_name); $query->execute() or error(db_error($query)); + // Clean cache + Cache::delete("themes"); + Cache::delete("theme_settings_".$theme); + header('Location: ?/themes', true, $config['redirect_http']); } -- cgit v1.3 From 1d28b4be4daac42164cf52c262f923856fbeeb28 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 17:13:55 +0200 Subject: cache.php: fs cache --- inc/cache.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'inc') diff --git a/inc/cache.php b/inc/cache.php index d1200919..d6bc9211 100644 --- a/inc/cache.php +++ b/inc/cache.php @@ -50,6 +50,17 @@ class Cache { case 'php': $data = isset(self::$cache[$key]) ? self::$cache[$key] : false; break; + case 'fs': + $key = str_replace('/', '::', $key); + $key = str_replace("\0", '', $key); + if (!file_exists('tmp/cache/'.$key)) { + $data = false; + } + else { + $data = file_get_contents('tmp/cache/'.$key); + $data = json_decode($data, true); + } + break; case 'redis': if (!self::$cache) self::init(); @@ -87,6 +98,11 @@ class Cache { case 'xcache': xcache_set($key, $value, $expires); break; + case 'fs': + $key = str_replace('/', '::', $key); + $key = str_replace("\0", '', $key); + file_put_contents('tmp/cache/'.$key, json_encode($value)); + break; case 'php': self::$cache[$key] = $value; break; @@ -113,6 +129,11 @@ class Cache { case 'xcache': xcache_unset($key); break; + case 'fs': + $key = str_replace('/', '::', $key); + $key = str_replace("\0", '', $key); + unlink('tmp/cache/'.$key); + break; case 'php': unset(self::$cache[$key]); break; @@ -134,6 +155,12 @@ class Cache { case 'php': self::$cache = array(); break; + case 'fs': + $files = glob('tmp/cache/*'); + foreach ($files as $file) { + unlink($file); + } + break; case 'redis': if (!self::$cache) self::init(); -- 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') 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') 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') 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') 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') 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') 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 11dfc8bbdc6c1c3888632c3cd96bcec4a313fc01 Mon Sep 17 00:00:00 2001 From: czaks Date: Mon, 6 Apr 2015 22:51:02 +0200 Subject: fs cache backend: silence the error --- inc/cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/cache.php b/inc/cache.php index d6bc9211..852aefa2 100644 --- a/inc/cache.php +++ b/inc/cache.php @@ -132,7 +132,7 @@ class Cache { case 'fs': $key = str_replace('/', '::', $key); $key = str_replace("\0", '', $key); - unlink('tmp/cache/'.$key); + @unlink('tmp/cache/'.$key); break; case 'php': unset(self::$cache[$key]); -- cgit v1.3 From f2848f2242a3135277474293347ab47c12782728 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 28 Mar 2015 19:37:57 -0700 Subject: Update GeoIP database --- inc/lib/geoip/GeoIPv6.dat | Bin 1127489 -> 1429913 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'inc') diff --git a/inc/lib/geoip/GeoIPv6.dat b/inc/lib/geoip/GeoIPv6.dat index 1c2658c5..c2f3f11b 100644 Binary files a/inc/lib/geoip/GeoIPv6.dat and b/inc/lib/geoip/GeoIPv6.dat differ -- 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') 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 1b16e97f67853e37641dee3ca1e7d9022a786f2b Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 12 Apr 2015 03:08:40 +0200 Subject: [code] fix regexps --- inc/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/config.php b/inc/config.php index b7c60125..f11ee5f1 100644 --- a/inc/config.php +++ b/inc/config.php @@ -625,8 +625,8 @@ $config['markup'][] = array("/^[ |\t]*==(.+?)==[ |\t]*$/m", "\$1"); // 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" + // "/\[code\](.*?)\[\/code\]/is" + // "/```([a-z0-9-]{0,20})\n(.*?)\n?```\n?/s" $config['markup_code'] = false; // Repair markup with HTML Tidy. This may be slower, but it solves nesting mistakes. Tinyboad, at the -- 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') 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 From 4c1d2f924c60b1b33d6ab96b2ad26e48d6bd68b4 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 23 Apr 2015 07:57:52 +0200 Subject: fix error while installing themes; thanks xixi --- inc/mod/pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 969c570e..804c1e43 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2508,7 +2508,7 @@ function mod_theme_configure($theme_name) { // Clean cache Cache::delete("themes"); - Cache::delete("theme_settings_".$theme); + Cache::delete("theme_settings_".$theme_name); $result = true; $message = false; -- cgit v1.3 From 2d9214ac63b34ea1066efa2dbc759258f2ca661a Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 23 Apr 2015 08:18:36 +0200 Subject: version check should point at engine.vichan.net and not tinyboard.org actually --- inc/mod/pages.php | 4 ++-- templates/mod/dashboard.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'inc') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 804c1e43..2c679b20 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -111,7 +111,7 @@ function mod_dashboard() { $latest = unserialize($_COOKIE['update']); } else { $ctx = stream_context_create(array('http' => array('timeout' => 5))); - if ($code = @file_get_contents('http://tinyboard.org/version.txt', 0, $ctx)) { + if ($code = @file_get_contents('http://engine.vichan.net/version.txt', 0, $ctx)) { $ver = strtok($code, "\n"); if (preg_match('@^// v(\d+)\.(\d+)\.(\d+)\s*?$@', $ver, $matches)) { @@ -120,7 +120,7 @@ function mod_dashboard() { 'major' => $matches[2], 'minor' => $matches[3] ); - if (preg_match('/v(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $matches)) { + if (preg_match('/(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $matches)) { $current = array( 'massive' => (int) $matches[1], 'major' => (int) $matches[2], diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 2c370a11..7e25555b 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -155,9 +155,9 @@ Update
  • - A newer version of Tinyboard + A newer version of vichan (v{{ newer_release.massive }}.{{ newer_release.major }}.{{ newer_release.minor }}) is available! - See http://tinyboard.org/ for upgrade instructions. + See https://engine.vichan.net/ for upgrade instructions.
-- cgit v1.3 From 3f29bdfac92cfff13b234f3abc9d92bd5b9a2a37 Mon Sep 17 00:00:00 2001 From: Anonke Date: Sat, 30 May 2015 20:46:43 +0200 Subject: the poster IDs were showing in API despite being disabled --- inc/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/api.php b/inc/api.php index b77fa3f8..57e4d367 100644 --- a/inc/api.php +++ b/inc/api.php @@ -101,7 +101,7 @@ class Api { $fields = $threadsPage ? $this->threadsPageFields : $this->postFields; $this->translateFields($fields, $post, $apiPost); - if (isset($config['poster_ids'])) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']); + if (isset($config['poster_ids']) && $config['poster_ids']) $apiPost['id'] = poster_id($post->ip, $post->thread, $board['uri']); if ($threadsPage) return $apiPost; // Handle country field -- cgit v1.3 From d3d167affb7f2ac7708e8fe54658df594b6f672c Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 8 Jul 2015 16:26:58 +0200 Subject: SECURITY: XSS fix for youtube.js/metacafe embed --- inc/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/config.php b/inc/config.php index 32308bd4..75506645 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1022,7 +1022,7 @@ '' ), array( - '/^https?:\/\/(\w+\.)?metacafe\.com\/watch\/(\d+)\/([a-zA-Z0-9_\-.]+)\/(\?.+)?$/i', + '/^https?:\/\/(\w+\.)?metacafe\.com\/watch\/(\d+)\/([a-zA-Z0-9_\-.]+)\/(\?[^\'"<>]+)?$/i', '
' ), array( @@ -1665,6 +1665,6 @@ // Youtube.js embed HTML code $config['youtube_js_html'] = ''; -- cgit v1.3 From 601c8cebc9eaaa7cf5254350c32f9741d2dd05d6 Mon Sep 17 00:00:00 2001 From: 27chan Date: Mon, 10 Aug 2015 22:13:42 -0300 Subject: Add extension mp4 --- inc/lib/webm/ffmpeg.php | 53 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'inc') diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php index edd2c73a..faf90608 100644 --- a/inc/lib/webm/ffmpeg.php +++ b/inc/lib/webm/ffmpeg.php @@ -3,60 +3,61 @@ * ffmpeg.php * A barebones ffmpeg based webm implementation for vichan. */ - function get_webm_info($filename) { global $board, $config; - $filename = escapeshellarg($filename); $ffprobe = $config['webm']['ffprobe_path']; $ffprobe_out = array(); $webminfo = array(); - exec("$ffprobe -v quiet -print_format json -show_format -show_streams $filename", $ffprobe_out); $ffprobe_out = json_decode(implode("\n", $ffprobe_out), 1); $webminfo['error'] = is_valid_webm($ffprobe_out); - if(empty($webminfo['error'])) { $webminfo['width'] = $ffprobe_out['streams'][0]['width']; $webminfo['height'] = $ffprobe_out['streams'][0]['height']; + $webminfo['duration'] = $ffprobe_out['format']['duration']; } - return $webminfo; } - function is_valid_webm($ffprobe_out) { global $board, $config; - if (empty($ffprobe_out)) return array('code' => 1, 'msg' => $config['error']['genwebmerror']); - - if ($ffprobe_out['format']['format_name'] != 'matroska,webm') - return array('code' => 2, 'msg' => $config['error']['invalidwebm']); - + $extension = pathinfo($ffprobe_out['format']['filename'], PATHINFO_EXTENSION); + if ($extension === 'webm') { + if ($ffprobe_out['format']['format_name'] != 'matroska,webm') + return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + } elseif ($extension === 'mp4') { + if ($ffprobe_out['streams'][0]['codec_name'] != 'h264' && $ffprobe_out['streams'][1]['codec_name'] != 'aac') + return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + } else { + return array('code' => 1, 'msg' => $config['error']['genwebmerror']); + } if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio'])) return array('code' => 3, 'msg' => $config['error']['webmhasaudio']); - - if ($ffprobe_out['streams'][0]['codec_name'] != 'vp8') - return array('code' => 2, 'msg' => $config['error']['invalidwebm']); - if (empty($ffprobe_out['streams'][0]['width']) || (empty($ffprobe_out['streams'][0]['height']))) return array('code' => 2, 'msg' => $config['error']['invalidwebm']); - if ($ffprobe_out['format']['duration'] > $config['webm']['max_length']) - return array('code' => 4, 'msg' => $config['error']['webmtoolong']); + return array('code' => 4, 'msg' => sprintf($config['error']['webmtoolong'], $config['webm']['max_length'])); } - -function make_webm_thumbnail($filename, $thumbnail, $width, $height) { +function make_webm_thumbnail($filename, $thumbnail, $width, $height, $duration) { global $board, $config; - $filename = escapeshellarg($filename); - $thumbnail = escapeshellarg($thumbnail); // Should be safe by default but you + $thumbnailfc = escapeshellarg($thumbnail); // Should be safe by default but you // can never be too safe. - $ffmpeg = $config['webm']['ffmpeg_path']; + $ret = 0; $ffmpeg_out = array(); - - exec("$ffmpeg -i $filename -v quiet -ss 00:00:00 -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnail 2>&1"); - - return count($ffmpeg_out); + exec("$ffmpeg -strict -2 -ss " . floor($duration / 2) . " -i $filename -v quiet -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnailfc 2>&1", $ffmpeg_out, $ret); + // Work around for https://trac.ffmpeg.org/ticket/4362 + if (filesize($thumbnail) === 0) { + // try again with first frame + exec("$ffmpeg -y -strict -2 -ss 0 -i $filename -v quiet -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnailfc 2>&1", $ffmpeg_out, $ret); + clearstatcache(); + // failed if no thumbnail size even if ret code 0, ffmpeg is buggy + if (filesize($thumbnail) === 0) { + $ret = 1; + } + } + return $ret; } -- cgit v1.3 From f1cbbbc15a745b36018e7f7b065cd84057a599e1 Mon Sep 17 00:00:00 2001 From: 27chan Date: Mon, 10 Aug 2015 22:15:21 -0300 Subject: Add extension mp4 --- inc/lib/webm/posthandler.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'inc') diff --git a/inc/lib/webm/posthandler.php b/inc/lib/webm/posthandler.php index a5b7429b..15c6600d 100644 --- a/inc/lib/webm/posthandler.php +++ b/inc/lib/webm/posthandler.php @@ -1,27 +1,22 @@ has_file) foreach ($post->files as &$file) if ($file->extension == 'webm') { + if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm' || $file->extension == 'mp4') { if ($config['webm']['use_ffmpeg']) { require_once dirname(__FILE__) . '/ffmpeg.php'; $webminfo = get_webm_info($file->file_path); - if (empty($webminfo['error'])) { $file->width = $webminfo['width']; $file->height = $webminfo['height']; - if ($config['spoiler_images'] && isset($_POST['spoiler'])) { $file = webm_set_spoiler($file); } else { $file = set_thumbnail_dimensions($post, $file); $tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg'; - - if(false == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight)) { + if(0 == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight, $webminfo['duration'])) { $file->thumb = $file->file_id . '.jpg'; } else { @@ -37,7 +32,6 @@ function postHandler($post) { require_once dirname(__FILE__) . '/videodata.php'; $videoDetails = videoData($file->file_path); if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file"; - // Set thumbnail $thumbName = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.webm'; if ($config['spoiler_images'] && isset($_POST['spoiler'])) { @@ -53,12 +47,10 @@ function postHandler($post) { $file->thumb = 'file'; } unset($videoDetails['frame']); - // Set width and height if (isset($videoDetails['width']) && isset($videoDetails['height'])) { $file->width = $videoDetails['width']; $file->height = $videoDetails['height']; - if ($file->thumb != 'file' && $file->thumb != 'spoiler') { $file = set_thumbnail_dimensions($post, $file); } @@ -66,14 +58,11 @@ function postHandler($post) { } } } - function set_thumbnail_dimensions($post,$file) { global $board, $config; - $tn_dimensions = array(); $tn_maxw = $post->op ? $config['thumb_op_width'] : $config['thumb_width']; $tn_maxh = $post->op ? $config['thumb_op_height'] : $config['thumb_height']; - if ($file->width > $tn_maxw || $file->height > $tn_maxh) { $file->thumbwidth = min($tn_maxw, intval(round($file->width * $tn_maxh / $file->height))); $file->thumbheight = min($tn_maxh, intval(round($file->height * $tn_maxw / $file->width))); @@ -81,17 +70,13 @@ function set_thumbnail_dimensions($post,$file) { $file->thumbwidth = $file->width; $file->thumbheight = $file->height; } - return $file; } - function webm_set_spoiler($file) { global $board, $config; - $file->thumb = 'spoiler'; $size = @getimagesize($config['spoiler_image']); $file->thumbwidth = $size[0]; $file->thumbheight = $size[1]; - return $file; } -- cgit v1.3 From 219c1987a90d828b3e0c38b66509617ad78b91ab Mon Sep 17 00:00:00 2001 From: 27chan Date: Mon, 10 Aug 2015 22:25:09 -0300 Subject: Add extension mp4 --- inc/config.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc') diff --git a/inc/config.php b/inc/config.php index 75506645..69b4bd3a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -754,6 +754,7 @@ $config['file_icons']['default'] = 'file.png'; $config['file_icons']['zip'] = 'zip.png'; $config['file_icons']['webm'] = 'video.png'; + $config['file_icons']['mp4'] = 'video.png'; // Example: Custom thumbnail for certain file extension. // $config['file_icons']['extension'] = 'some_file.png'; -- cgit v1.3 From ccd00c497c7465f14f7b259469ad287524e6b33a Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 11 Aug 2015 03:46:02 +0200 Subject: a stricter check for webm processing --- inc/lib/webm/ffmpeg.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc') diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php index faf90608..0747b420 100644 --- a/inc/lib/webm/ffmpeg.php +++ b/inc/lib/webm/ffmpeg.php @@ -45,6 +45,8 @@ function make_webm_thumbnail($filename, $thumbnail, $width, $height, $duration) $filename = escapeshellarg($filename); $thumbnailfc = escapeshellarg($thumbnail); // Should be safe by default but you // can never be too safe. + $width = escapeshellarg($width); + $height = escapeshellarg($height); // Same as above. $ffmpeg = $config['webm']['ffmpeg_path']; $ret = 0; $ffmpeg_out = array(); -- cgit v1.3 From 1136cc0e44e5094362cf46e9416a143f594482b0 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 11 Aug 2015 03:47:44 +0200 Subject: reflect in readme, that we support .mp4 files as well now --- inc/lib/webm/README.md | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'inc') diff --git a/inc/lib/webm/README.md b/inc/lib/webm/README.md index dc3394c9..d1c2a52a 100644 --- a/inc/lib/webm/README.md +++ b/inc/lib/webm/README.md @@ -30,6 +30,13 @@ If you have an [FFmpeg](https://www.ffmpeg.org/) binary on your server and you w $config['webm']['ffmpeg_path'] = '/path/to/ffmeg'; $config['webm']['ffprobe_path'] = '/path/to/ffprobe'; +MP4 support +----------- + +MP4 support is available only if you use FFmpeg thumbnailing (see above). + + $config['allowed_ext_files'][] = 'mp4'; + License ------- -- cgit v1.3 From 706feeddff55ecafc397137dbc005890fdef963d Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 11 Aug 2015 04:51:27 +0200 Subject: fix cache_config: webms were thumbnailed twice and with the latest addition, they couldn`t resize at all --- inc/functions.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/functions.php b/inc/functions.php index aa91133f..515e3e55 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -249,9 +249,9 @@ function loadConfig() { if ($config['allow_roll']) event_handler('post', 'diceRoller'); - if (is_array($config['anonymous'])) - $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; - + if (in_array('webm', $config['allowed_ext_files']) || + in_array('mp4', $config['allowed_ext_files'])) + event_handler('post', 'postHandler'); } // Effectful config processing below: @@ -287,10 +287,9 @@ function loadConfig() { if ($config['cache']['enabled']) require_once 'inc/cache.php'; - if (in_array('webm', $config['allowed_ext_files'])) { + if (in_array('webm', $config['allowed_ext_files']) || + in_array('mp4', $config['allowed_ext_files'])) require_once 'inc/lib/webm/posthandler.php'; - event_handler('post', 'postHandler'); - } event('load-config'); @@ -308,6 +307,9 @@ function loadConfig() { Cache::set('config_'.$boardsuffix, $config); Cache::set('events_'.$boardsuffix, $events); } + + if (is_array($config['anonymous'])) + $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; if ($config['debug']) { if (!isset($debug)) { -- cgit v1.3 From 6d4e75624063fe6077a654378af9763e32a1c0e8 Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 11 Sep 2015 12:49:30 +0200 Subject: fix a bug for some bad database state. thanks Seisatsu for testing --- inc/display.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/display.php b/inc/display.php index e7fb9320..90cf3434 100644 --- a/inc/display.php +++ b/inc/display.php @@ -354,7 +354,7 @@ class Post { } if (isset($this->files) && $this->files) - $this->files = json_decode($this->files); + $this->files = @json_decode($this->files); $this->subject = utf8tohtml($this->subject); $this->name = utf8tohtml($this->name); @@ -404,7 +404,7 @@ class Thread { } if (isset($this->files)) - $this->files = json_decode($this->files); + $this->files = @json_decode($this->files); $this->subject = utf8tohtml($this->subject); $this->name = utf8tohtml($this->name); -- cgit v1.3 From d2de4419bddbb7b0e09ced1f01d3ccb45aecc50f Mon Sep 17 00:00:00 2001 From: Matthieu Date: Thu, 14 Jan 2016 21:05:24 +0100 Subject: Added: config option to hide email in post. (prevent emailfag but let the possibility to sage and noko) --- inc/config.php | 3 +++ templates/post/name.html | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/config.php b/inc/config.php index 69b4bd3a..d5bdbfe5 100644 --- a/inc/config.php +++ b/inc/config.php @@ -550,6 +550,9 @@ // When true, the sage won't be displayed $config['hide_sage'] = false; + // Don't display user's email when it's not "sage" + $config['hide_email'] = false; + // Attach country flags to posts. $config['country_flags'] = false; diff --git a/templates/post/name.html b/templates/post/name.html index 13c676c7..e7f85f8b 100644 --- a/templates/post/name.html +++ b/templates/post/name.html @@ -1,5 +1,5 @@ {% set capcode = post.capcode|capcode %} -{% if post.email|length > 0 and (config.hide_sage!=true or post.email!='sage') %} +{% if post.email|length > 0 and (config.hide_sage!=true or post.email!='sage') and config.hide_email!=true %} {# start email #} {% endif %} -- cgit v1.3