From c208a3715c82ac4e6f5d56577c31ae5df1c9c7cd Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 10 Mar 2017 16:14:56 +0000 Subject: [PATCH 01/40] mark static functions as static --- core/imageboard.pack.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 0827b411..5f0253fc 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -175,7 +175,7 @@ class Image { return $images; } - public function validate_accel($tags) { + public static function validate_accel($tags) { $yays = 0; $nays = 0; foreach($tags as $tag) { @@ -195,7 +195,7 @@ class Image { * @return null|PDOStatement * @throws SCoreException */ - public function get_accelerated_result($tags, $offset, $limit) { + public static function get_accelerated_result($tags, $offset, $limit) { global $database; if(!Image::validate_accel($tags)) { From 10863d4c4bb14eface0bb62adc6cfb8bd6bf7ee1 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 10 Mar 2017 16:15:31 +0000 Subject: [PATCH 02/40] import imageboard to avoid warnings --- core/_bootstrap.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/_bootstrap.inc.php b/core/_bootstrap.inc.php index df92da94..e8d6559a 100644 --- a/core/_bootstrap.inc.php +++ b/core/_bootstrap.inc.php @@ -10,6 +10,7 @@ require_once "core/sys_config.inc.php"; require_once "core/util.inc.php"; require_once "lib/context.php"; require_once "vendor/autoload.php"; +require_once "core/imageboard.pack.php"; // set up and purify the environment _version_check(); From 277d80c4df41918a4b664ecdd88fa1a0b4f0be35 Mon Sep 17 00:00:00 2001 From: jgen Date: Thu, 23 Mar 2017 00:35:18 -0700 Subject: [PATCH 03/40] Bump the version number --- core/sys_config.inc.php | 2 +- install.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sys_config.inc.php b/core/sys_config.inc.php index abc00766..12d71c5e 100644 --- a/core/sys_config.inc.php +++ b/core/sys_config.inc.php @@ -36,7 +36,7 @@ _d("COMPILE_ELS", false); // boolean pre-build the list of event listeners _d("NICE_URLS", false); // boolean force niceurl mode _d("SEARCH_ACCEL", false); // boolean use search accelerator _d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse -_d("VERSION", '2.5.5+'); // string shimmie version +_d("VERSION", '2.6.0+'); // string shimmie version _d("TIMEZONE", null); // string timezone _d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,comment,tag_list,index,tag_edit,alias_editor"); // extensions to always enable _d("EXTRA_EXTS", ""); // string optional extra extensions diff --git a/install.php b/install.php index 1efe82ac..ec2c5f1e 100644 --- a/install.php +++ b/install.php @@ -3,7 +3,7 @@ * Shimmie Installer * * @package Shimmie - * @copyright Copyright (c) 2007-2015, Shish et al. + * @copyright Copyright (c) 2007-2017, Shish et al. * @author Shish [webmaster at shishnet.org], jgen [jeffgenovy at gmail.com] * @link http://code.shishnet.org/shimmie2/ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 From 8ff24eb1c6ab7b12ea47e393dd9849702a0b7d2e Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 24 Mar 2017 23:21:48 -0700 Subject: [PATCH 04/40] Revert "Bump the version number" This reverts commit 277d80c4df41918a4b664ecdd88fa1a0b4f0be35. --- core/sys_config.inc.php | 2 +- install.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sys_config.inc.php b/core/sys_config.inc.php index 12d71c5e..abc00766 100644 --- a/core/sys_config.inc.php +++ b/core/sys_config.inc.php @@ -36,7 +36,7 @@ _d("COMPILE_ELS", false); // boolean pre-build the list of event listeners _d("NICE_URLS", false); // boolean force niceurl mode _d("SEARCH_ACCEL", false); // boolean use search accelerator _d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse -_d("VERSION", '2.6.0+'); // string shimmie version +_d("VERSION", '2.5.5+'); // string shimmie version _d("TIMEZONE", null); // string timezone _d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,comment,tag_list,index,tag_edit,alias_editor"); // extensions to always enable _d("EXTRA_EXTS", ""); // string optional extra extensions diff --git a/install.php b/install.php index ec2c5f1e..1efe82ac 100644 --- a/install.php +++ b/install.php @@ -3,7 +3,7 @@ * Shimmie Installer * * @package Shimmie - * @copyright Copyright (c) 2007-2017, Shish et al. + * @copyright Copyright (c) 2007-2015, Shish et al. * @author Shish [webmaster at shishnet.org], jgen [jeffgenovy at gmail.com] * @link http://code.shishnet.org/shimmie2/ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 From 8ef13db69cfa67956b3d66ad2748fc47386a5c5b Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 27 Mar 2017 18:15:16 +0100 Subject: [PATCH 05/40] bump develop --- core/sys_config.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sys_config.inc.php b/core/sys_config.inc.php index a47051ef..12d71c5e 100644 --- a/core/sys_config.inc.php +++ b/core/sys_config.inc.php @@ -36,7 +36,7 @@ _d("COMPILE_ELS", false); // boolean pre-build the list of event listeners _d("NICE_URLS", false); // boolean force niceurl mode _d("SEARCH_ACCEL", false); // boolean use search accelerator _d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse -_d("VERSION", '2.6.0'); // string shimmie version +_d("VERSION", '2.6.0+'); // string shimmie version _d("TIMEZONE", null); // string timezone _d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,comment,tag_list,index,tag_edit,alias_editor"); // extensions to always enable _d("EXTRA_EXTS", ""); // string optional extra extensions From f934baa207fba32bcbd571db1e6e5c3013618b7f Mon Sep 17 00:00:00 2001 From: John Brooks Date: Sun, 23 Apr 2017 02:17:49 +0000 Subject: [PATCH 06/40] bulk_add_csv: Run Tag::explode() on the tags before passing them to handlers Fixes #575 --- ext/bulk_add_csv/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/bulk_add_csv/main.php b/ext/bulk_add_csv/main.php index 34645e91..2e7cf6d7 100644 --- a/ext/bulk_add_csv/main.php +++ b/ext/bulk_add_csv/main.php @@ -126,7 +126,7 @@ class BulkAddCSV extends Extension { $list .= "
".html_escape("$shortpath (".str_replace(" ", ", ", $tags).")... "); if (file_exists($csvdata[0]) && is_file($csvdata[0])) { try{ - $this->add_image($fullpath, $pathinfo["basename"], $tags, $source, $rating, $thumbfile); + $this->add_image($fullpath, $pathinfo["basename"], Tag::explode($tags), $source, $rating, $thumbfile); $list .= "ok\n"; } catch(Exception $ex) { From 1625bd68e3773e25e9b34f40cc0d5b3d0b71df1f Mon Sep 17 00:00:00 2001 From: Thomas Hori Date: Tue, 25 Apr 2017 17:48:34 +0100 Subject: [PATCH 07/40] Fix error upon bulk add. Fixes "PHP Fatal error: Uncaught TypeError: Argument 2 passed to TagSetEvent::__construct() must be of the type array, string given" upon bulk add. --- core/imageboard.pack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 755de669..5a2dacab 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -1219,7 +1219,7 @@ function add_dir($base) { $short_path = str_replace($base, "", $full_path); $filename = basename($full_path); - $tags = path_to_tags($short_path); + $tags = Tag::explode(path_to_tags($short_path)); $result = "$short_path (".str_replace(" ", ", ", $tags).")... "; try { add_image($full_path, $filename, $tags); From d1306cfb2d0293af639f724e259866e4d613e394 Mon Sep 17 00:00:00 2001 From: Thomas Hori Date: Wed, 26 Apr 2017 14:08:06 +0100 Subject: [PATCH 08/40] Move Tag::explode call into add_image call so that $result is unaffected. --- core/imageboard.pack.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 5a2dacab..9e20b33e 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -1219,10 +1219,10 @@ function add_dir($base) { $short_path = str_replace($base, "", $full_path); $filename = basename($full_path); - $tags = Tag::explode(path_to_tags($short_path)); + $tags = path_to_tags($short_path); $result = "$short_path (".str_replace(" ", ", ", $tags).")... "; try { - add_image($full_path, $filename, $tags); + add_image($full_path, $filename, Tag::explode($tags)); $result .= "ok"; } catch(UploadException $ex) { From c0e87ae2aec0c6a37187b73b3e2e2c39f7e042a5 Mon Sep 17 00:00:00 2001 From: jgen Date: Thu, 11 May 2017 23:43:10 -0700 Subject: [PATCH 09/40] Fix issue with archive handler if no add_status method. --- ext/handle_archive/main.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/handle_archive/main.php b/ext/handle_archive/main.php index 1fe56ca6..ad43c4ac 100644 --- a/ext/handle_archive/main.php +++ b/ext/handle_archive/main.php @@ -35,8 +35,10 @@ class ArchiveFileHandler extends Extension { exec($cmd); $results = add_dir($tmpdir); if(count($results) > 0) { - // FIXME no theme? - $this->theme->add_status("Adding files", $results); + // Not all themes have the add_status() method, so need to check before calling. + if (method_exists($this->theme, "add_status")) { + $this->theme->add_status("Adding files", $results); + } } deltree($tmpdir); $event->image_id = -2; // default -1 = upload wasn't handled From f492c6c2c37e7efc8a7a7b6d57ce49580d14ac9e Mon Sep 17 00:00:00 2001 From: jgen Date: Fri, 12 May 2017 00:57:50 -0700 Subject: [PATCH 10/40] Ensure that the Image object tag_array and the metadata array tags are always arrays. --- core/imageboard.pack.php | 6 +++--- ext/bulk_add_csv/main.php | 4 ++-- ext/cron_uploader/main.php | 6 +++++- ext/handle_flash/main.php | 2 +- ext/handle_ico/main.php | 2 +- ext/handle_mp3/main.php | 2 +- ext/handle_pixel/main.php | 2 +- ext/handle_svg/main.php | 2 +- ext/handle_video/main.php | 2 +- ext/oekaki/main.php | 2 +- ext/ouroboros_api/main.php | 2 +- tests/bootstrap.php | 2 +- 12 files changed, 19 insertions(+), 15 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 9e20b33e..81c84c51 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -1210,7 +1210,7 @@ function move_upload_to_archive(DataUploadEvent $event) { * Add a directory full of images * * @param $base string - * @return array + * @return array|string[] */ function add_dir($base) { $results = array(); @@ -1222,7 +1222,7 @@ function add_dir($base) { $tags = path_to_tags($short_path); $result = "$short_path (".str_replace(" ", ", ", $tags).")... "; try { - add_image($full_path, $filename, Tag::explode($tags)); + add_image($full_path, $filename, $tags); $result .= "ok"; } catch(UploadException $ex) { @@ -1250,7 +1250,7 @@ function add_image($tmpname, $filename, $tags) { $metadata = array(); $metadata['filename'] = $pathinfo['basename']; $metadata['extension'] = $pathinfo['extension']; - $metadata['tags'] = $tags; + $metadata['tags'] = Tag::explode($tags); $metadata['source'] = null; $event = new DataUploadEvent($tmpname, $metadata); send_event($event); diff --git a/ext/bulk_add_csv/main.php b/ext/bulk_add_csv/main.php index 2e7cf6d7..a5b999e7 100644 --- a/ext/bulk_add_csv/main.php +++ b/ext/bulk_add_csv/main.php @@ -73,7 +73,7 @@ class BulkAddCSV extends Extension { $metadata = array(); $metadata['filename'] = $pathinfo['basename']; $metadata['extension'] = $pathinfo['extension']; - $metadata['tags'] = $tags; + $metadata['tags'] = Tag::explode($tags); $metadata['source'] = $source; $event = new DataUploadEvent($tmpname, $metadata); send_event($event); @@ -126,7 +126,7 @@ class BulkAddCSV extends Extension { $list .= "
".html_escape("$shortpath (".str_replace(" ", ", ", $tags).")... "); if (file_exists($csvdata[0]) && is_file($csvdata[0])) { try{ - $this->add_image($fullpath, $pathinfo["basename"], Tag::explode($tags), $source, $rating, $thumbfile); + $this->add_image($fullpath, $pathinfo["basename"], $tags, $source, $rating, $thumbfile); $list .= "ok\n"; } catch(Exception $ex) { diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index 182a1848..202ee14c 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -304,6 +304,10 @@ class CronUploader extends Extension { /** * Generate the necessary DataUploadEvent for a given image and tags. + * + * @param string $tmpname + * @param string $filename + * @param string $tags */ private function add_image($tmpname, $filename, $tags) { assert ( file_exists ( $tmpname ) ); @@ -315,7 +319,7 @@ class CronUploader extends Extension { $metadata = array(); $metadata ['filename'] = $pathinfo ['basename']; $metadata ['extension'] = $pathinfo ['extension']; - $metadata ['tags'] = ""; // = $tags; doesn't work when not logged in here + $metadata ['tags'] = array(""); // = $tags; doesn't work when not logged in here $metadata ['source'] = null; $event = new DataUploadEvent ( $tmpname, $metadata ); send_event ( $event ); diff --git a/ext/handle_flash/main.php b/ext/handle_flash/main.php index 6122cb46..719648d4 100644 --- a/ext/handle_flash/main.php +++ b/ext/handle_flash/main.php @@ -37,7 +37,7 @@ class FlashFileHandler extends DataHandlerExtension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; $info = getimagesize($filename); diff --git a/ext/handle_ico/main.php b/ext/handle_ico/main.php index beda9596..31d5e337 100644 --- a/ext/handle_ico/main.php +++ b/ext/handle_ico/main.php @@ -67,7 +67,7 @@ class IcoFileHandler extends Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_mp3/main.php b/ext/handle_mp3/main.php index 9bbbe55a..4f0eae9e 100644 --- a/ext/handle_mp3/main.php +++ b/ext/handle_mp3/main.php @@ -43,7 +43,7 @@ class MP3FileHandler extends DataHandlerExtension { $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 38ba6b3d..149677eb 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -35,7 +35,7 @@ class PixelFileHandler extends DataHandlerExtension { $image->hash = $metadata['hash']; $image->filename = (($pos = strpos($metadata['filename'],'?')) !== false) ? substr($metadata['filename'],0,$pos) : $metadata['filename']; $image->ext = (($pos = strpos($metadata['extension'],'?')) !== false) ? substr($metadata['extension'],0,$pos) : $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_svg/main.php b/ext/handle_svg/main.php index c932f6ba..2e58dbd3 100644 --- a/ext/handle_svg/main.php +++ b/ext/handle_svg/main.php @@ -75,7 +75,7 @@ class SVGFileHandler extends Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index 4edbcc32..a31ac781 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -170,7 +170,7 @@ class VideoFileHandler extends DataHandlerExtension { $image->filesize = $metadata['size']; $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/oekaki/main.php b/ext/oekaki/main.php index bf4c804d..c26c1019 100644 --- a/ext/oekaki/main.php +++ b/ext/oekaki/main.php @@ -31,7 +31,7 @@ class Oekaki extends Extension { $metadata = array(); $metadata['filename'] = 'oekaki.png'; $metadata['extension'] = $pathinfo['extension']; - $metadata['tags'] = 'oekaki tagme'; + $metadata['tags'] = Tag::explode('oekaki tagme'); $metadata['source'] = null; $duev = new DataUploadEvent($tmpname, $metadata); send_event($duev); diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php index 95a69d97..966e8bc9 100644 --- a/ext/ouroboros_api/main.php +++ b/ext/ouroboros_api/main.php @@ -500,7 +500,7 @@ class OuroborosAPI extends Extension } } $meta = array(); - $meta['tags'] = $post->tags; + $meta['tags'] = Tag::explode($post->tags); $meta['source'] = $post->source; if (defined('ENABLED_EXTS')) { if (strstr(ENABLED_EXTS, 'rating') !== false) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d17b242a..961c0c0b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -132,7 +132,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit_Framework_TestCase { // post things /** * @param string $filename - * @param string|string[] $tags + * @param string $tags * @return int */ protected function post_image($filename, $tags) { From 7ebe301ffd45f0ccf0cbaa6549976934909c7cd5 Mon Sep 17 00:00:00 2001 From: jgen Date: Sat, 13 May 2017 18:01:31 -0700 Subject: [PATCH 11/40] Check if already an array before exploding. --- ext/ouroboros_api/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php index 966e8bc9..f58190b2 100644 --- a/ext/ouroboros_api/main.php +++ b/ext/ouroboros_api/main.php @@ -500,7 +500,7 @@ class OuroborosAPI extends Extension } } $meta = array(); - $meta['tags'] = Tag::explode($post->tags); + $meta['tags'] = is_array($post->tags) ? $post->tags : Tag::explode($post->tags); $meta['source'] = $post->source; if (defined('ENABLED_EXTS')) { if (strstr(ENABLED_EXTS, 'rating') !== false) { From 3ffb2da91cd1deef07ec92f62f639ce840df18cc Mon Sep 17 00:00:00 2001 From: jgen Date: Sat, 13 May 2017 23:18:47 -0700 Subject: [PATCH 12/40] More checking to ensure tags is an array. --- ext/ouroboros_api/main.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php index f58190b2..963832a2 100644 --- a/ext/ouroboros_api/main.php +++ b/ext/ouroboros_api/main.php @@ -536,7 +536,8 @@ class OuroborosAPI extends Extension if (!is_null($img)) { $handler = $config->get_string("upload_collision_handler"); if($handler == "merge") { - $merged = array_merge(Tag::explode($post->tags), $img->get_tag_array()); + $postTags = is_array($post->tags) ? $post->tags : Tag::explode($post->tags); + $merged = array_merge($postTags, $img->get_tag_array()); send_event(new TagSetEvent($img, $merged)); // This is really the only thing besides tags we should care From cf5aacaddffd841754ed4c23b572e1b3bb3be913 Mon Sep 17 00:00:00 2001 From: jgen Date: Sun, 14 May 2017 14:00:20 -0700 Subject: [PATCH 13/40] Use empty array instead of array with empty string. (Thanks Shish!) --- ext/cron_uploader/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index 202ee14c..046dd9b9 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -319,7 +319,7 @@ class CronUploader extends Extension { $metadata = array(); $metadata ['filename'] = $pathinfo ['basename']; $metadata ['extension'] = $pathinfo ['extension']; - $metadata ['tags'] = array(""); // = $tags; doesn't work when not logged in here + $metadata ['tags'] = array(); // = $tags; doesn't work when not logged in here $metadata ['source'] = null; $event = new DataUploadEvent ( $tmpname, $metadata ); send_event ( $event ); From fc7d96b530f176e7e93c4b3b01e39ab40089a2a1 Mon Sep 17 00:00:00 2001 From: jgen Date: Sun, 14 May 2017 22:18:44 -0700 Subject: [PATCH 14/40] Another location where $tags should be an array instead of a string. --- ext/cron_uploader/main.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index 046dd9b9..a9b05650 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -311,6 +311,7 @@ class CronUploader extends Extension { */ private function add_image($tmpname, $filename, $tags) { assert ( file_exists ( $tmpname ) ); + assert('is_string($tags)'); $pathinfo = pathinfo ( $filename ); if (! array_key_exists ( 'extension', $pathinfo )) { @@ -333,7 +334,7 @@ class CronUploader extends Extension { // Set tags $img = Image::by_id($event->image_id); - $img->set_tags($tags); + $img->set_tags(Tag::explode($tags)); } private function generate_image_queue($base = "", $subdir = "") { From 684efedcfdf654cf83853b4db65a316229579293 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 29 May 2017 10:16:32 +0100 Subject: [PATCH 15/40] Log what URL query caused invalid search queries --- core/imageboard.pack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 5f0253fc..46424643 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -953,7 +953,7 @@ class Image { } } - assert('$positive_tag_id_array || $negative_tag_id_array'); + assert('$positive_tag_id_array || $negative_tag_id_array', @$_GET['q']); $wheres = array(); if (!empty($positive_tag_id_array)) { $positive_tag_id_list = join(', ', $positive_tag_id_array); From 51e165aecfd09d3a5db5e13c6a59881ac18f4f6f Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 29 May 2017 10:18:11 +0100 Subject: [PATCH 16/40] Add separate memcached cache --- core/database.class.php | 114 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 9 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index 27037ab1..f2995251 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -291,13 +291,8 @@ class MemcacheCache implements CacheEngine { */ public function __construct($args) { $hp = explode(":", $args); - if(class_exists("Memcache")) { - $this->memcache = new Memcache; - @$this->memcache->pconnect($hp[0], $hp[1]); - } - else { - print "no memcache"; exit; - } + $this->memcache = new Memcache; + @$this->memcache->pconnect($hp[0], $hp[1]); } /** @@ -355,6 +350,92 @@ class MemcacheCache implements CacheEngine { */ public function get_misses() {return $this->misses;} } +class MemcachedCache implements CacheEngine { + /** @var \Memcached|null */ + public $memcache=null; + /** @var int */ + private $hits=0; + /** @var int */ + private $misses=0; + + /** + * @param string $args + */ + public function __construct($args) { + $hp = explode(":", $args); + $this->memcache = new Memcached; + #$this->memcache->setOption(Memcached::OPT_COMPRESSION, False); + #$this->memcache->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP); + #$this->memcache->setOption(Memcached::OPT_PREFIX_KEY, phpversion()); + $this->memcache->addServer($hp[0], $hp[1]); + } + + /** + * @param string $key + * @return array|bool|string + */ + public function get($key) { + assert('!is_null($key)'); + $key = "d-" . $key; + + $val = $this->memcache->get($key); + $res = $this->memcache->getResultCode(); + + if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { + $hit = $res == Memcached::RES_SUCCESS ? "miss" : "hit"; + file_put_contents("data/cache.log", "Cache $hit: $key\n", FILE_APPEND); + } + if($res == Memcached::RES_SUCCESS) { + $this->hits++; + return $val; + } + else if($res == Memcached::RES_NOTFOUND) { + $this->misses++; + return false; + } + else { + error_log("Memcached error: $res"); + } + } + + /** + * @param string $key + * @param mixed $val + * @param int $time + */ + public function set($key, $val, $time=0) { + assert('!is_null($key)'); + $key = "d-" . $key; + + $this->memcache->set($key, $val, $time); + if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { + file_put_contents("data/cache.log", "Cache set: $key ($time)\n", FILE_APPEND); + } + } + + /** + * @param string $key + */ + public function delete($key) { + assert('!is_null($key)'); + $key = "d-" . $key; + + $this->memcache->delete($key); + if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { + file_put_contents("data/cache.log", "Cache delete: $key\n", FILE_APPEND); + } + } + + /** + * @return int + */ + public function get_hits() {return $this->hits;} + + /** + * @return int + */ + public function get_misses() {return $this->misses;} +} class APCCache implements CacheEngine { public $hits=0, $misses=0; @@ -439,9 +520,24 @@ class Database { private function connect_cache() { $matches = array(); - if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) { + if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|memcached|apc)://(.*)#", CACHE_DSN, $matches)) { if($matches[1] == "memcache") { - $this->cache = new MemcacheCache($matches[2]); + if(class_exists("Memcache")) { + $this->cache = new MemcacheCache($matches[2]); + } + else { + #error_log("no memcache module - caching disabled"); + $this->cache = new NoCache(); + } + } + else if($matches[1] == "memcached") { + if(class_exists("Memcached")) { + $this->cache = new MemcachedCache($matches[2]); + } + else { + #error_log("no memcached module - caching disabled"); + $this->cache = new NoCache(); + } } else if($matches[1] == "apc") { $this->cache = new APCCache($matches[2]); From 8828fdfd05aa43ef50b1ab6c64415880923f593c Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 29 May 2017 10:19:11 +0100 Subject: [PATCH 17/40] log SQL query times in DEBUG_SQL mode --- core/database.class.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index f2995251..6f3325b6 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -682,6 +682,17 @@ class Database { else $this->query_count++; } + private function count_time($method, $start) { + if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { + $fp = @fopen("data/sql.log", "a"); + if($fp) { + fwrite($fp, $method.":".(microtime(true) - $start)."\n"); + fclose($fp); + } + } + $this->dbtime += microtime(true) - $start; + } + /** * Execute an SQL query and return an PDO result-set. * @@ -726,7 +737,7 @@ class Database { public function get_all($query, $args=array()) { $_start = microtime(true); $data = $this->execute($query, $args)->fetchAll(); - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_all", $_start); return $data; } @@ -740,7 +751,7 @@ class Database { public function get_row($query, $args=array()) { $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_row", $_start); return $row ? $row : null; } @@ -758,7 +769,7 @@ class Database { foreach($stmt as $row) { $res[] = $row[0]; } - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_col", $_start); return $res; } @@ -776,7 +787,7 @@ class Database { foreach($stmt as $row) { $res[$row[0]] = $row[1]; } - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_pairs", $_start); return $res; } @@ -790,7 +801,7 @@ class Database { public function get_one($query, $args=array()) { $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_one", $_start); return $row[0]; } From 4e5af700939b99e72a287fb65bc0bcee68ed3658 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 29 May 2017 11:09:28 +0100 Subject: [PATCH 18/40] re-stub mb_strlen (see #615) --- core/util.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/util.inc.php b/core/util.inc.php index 81582cdf..842918dd 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -958,6 +958,13 @@ function data_path($filename) { return $filename; } +if (!function_exists('mb_strlen')) { + // TODO: we should warn the admin that they are missing multibyte support + function mb_strlen($str, $encoding) { + return strlen($str); + } +} + /** * @param string $url * @param string $mfile From 2f557326df1d904f2df9c2177dc3196f7a854477 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 30 May 2017 02:13:11 +0100 Subject: [PATCH 19/40] die if caching modules are missing, don't silently fall back to NoCache --- core/database.class.php | 43 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index 78b33ea8..2ab4230e 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -399,7 +399,6 @@ class MemcachedCache implements CacheEngine { */ public function get($key) { assert('!is_null($key)'); - $key = "d-" . $key; $val = $this->memcache->get($key); $res = $this->memcache->getResultCode(); @@ -428,7 +427,6 @@ class MemcachedCache implements CacheEngine { */ public function set($key, $val, $time=0) { assert('!is_null($key)'); - $key = "d-" . $key; $this->memcache->set($key, $val, $time); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { @@ -441,7 +439,6 @@ class MemcachedCache implements CacheEngine { */ public function delete($key) { assert('!is_null($key)'); - $key = "d-" . $key; $this->memcache->delete($key); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { @@ -549,22 +546,10 @@ class Database { $matches = array(); if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|memcached|apc)://(.*)#", CACHE_DSN, $matches)) { if($matches[1] == "memcache") { - if(class_exists("Memcache")) { - $this->cache = new MemcacheCache($matches[2]); - } - else { - #error_log("no memcache module - caching disabled"); - $this->cache = new NoCache(); - } + $this->cache = new MemcacheCache($matches[2]); } else if($matches[1] == "memcached") { - if(class_exists("Memcached")) { - $this->cache = new MemcachedCache($matches[2]); - } - else { - #error_log("no memcached module - caching disabled"); - $this->cache = new NoCache(); - } + $this->cache = new MemcachedCache($matches[2]); } else if($matches[1] == "apc") { $this->cache = new APCCache($matches[2]); @@ -695,17 +680,14 @@ class Database { */ private function count_execs($db, $sql, $inputarray) { if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { - $fp = @fopen("data/sql.log", "a"); - if($fp) { - $sql = trim(preg_replace('/\s+/msi', ' ', $sql)); - if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { - fwrite($fp, $sql." -- ".join(", ", $inputarray)."\n"); - } - else { - fwrite($fp, $sql."\n"); - } - fclose($fp); + $sql = trim(preg_replace('/\s+/msi', ' ', $sql)); + if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { + $text = $sql." -- ".join(", ", $inputarray)."\n"; } + else { + $text = $sql."\n"; + } + file_put_contents("data/sql.log", $text, FILE_APPEND); } if(!is_array($inputarray)) $this->query_count++; # handle 2-dimensional input arrays @@ -715,11 +697,8 @@ class Database { private function count_time($method, $start) { if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { - $fp = @fopen("data/sql.log", "a"); - if($fp) { - fwrite($fp, $method.":".(microtime(true) - $start)."\n"); - fclose($fp); - } + $text = $method.":".(microtime(true) - $start)."\n"; + file_put_contents("data/sql.log", $text, FILE_APPEND); } $this->dbtime += microtime(true) - $start; } From 2666d83579104f0b180c191de9e77e575a4a918f Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 1 Jun 2017 20:44:02 +0100 Subject: [PATCH 20/40] fix URL for video fallback flash player --- ext/handle_video/theme.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php index 9cc28fa5..83d14104 100644 --- a/ext/handle_video/theme.php +++ b/ext/handle_video/theme.php @@ -9,6 +9,7 @@ class VideoFileHandlerTheme extends Themelet { $full_url = make_http($ilink); $autoplay = $config->get_bool("video_playback_autoplay"); $loop = $config->get_bool("video_playback_loop"); + $player = make_link('lib/vendor/swf/flashmediaelement.swf'); $html = "Video not playing? Click here to download the file.
"; @@ -22,8 +23,8 @@ class VideoFileHandlerTheme extends Themelet { } $html_fallback = " - - + + From 53c6f6df3086ab77b5a9ecf8d861a9fd51790b5f Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 1 Jun 2017 20:44:17 +0100 Subject: [PATCH 21/40] bulk thumb regen --- ext/regen_thumb/main.php | 22 ++++++++++++++++++++-- ext/regen_thumb/theme.php | 12 +++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ext/regen_thumb/main.php b/ext/regen_thumb/main.php index ec48c649..16a00f7a 100644 --- a/ext/regen_thumb/main.php +++ b/ext/regen_thumb/main.php @@ -15,13 +15,24 @@ class RegenThumb extends Extension { public function onPageRequest(PageRequestEvent $event) { - global $page, $user; + global $database, $page, $user; - if($event->page_matches("regen_thumb") && $user->can("delete_image") && isset($_POST['image_id'])) { + if($event->page_matches("regen_thumb/one") && $user->can("delete_image") && isset($_POST['image_id'])) { $image = Image::by_id(int_escape($_POST['image_id'])); send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true)); $this->theme->display_results($page, $image); } + if($event->page_matches("regen_thumb/mass") && $user->can("delete_image") && isset($_POST['tags'])) { + $tags = Tag::explode(strtolower($_POST['tags']), false); + $images = Image::find_images(0, 10000, $tags); + + foreach($images as $image) { + send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true)); + } + + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); + } } public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { @@ -30,5 +41,12 @@ class RegenThumb extends Extension { $event->add_part($this->theme->get_buttons_html($event->image->id)); } } + + public function onPostListBuilding(PostListBuildingEvent $event) { + global $user; + if($user->can("delete_image") && !empty($event->search_terms)) { + $event->add_control($this->theme->mtr_html(implode(" ", $event->search_terms))); + } + } } diff --git a/ext/regen_thumb/theme.php b/ext/regen_thumb/theme.php index e7de3afb..aec02c9d 100644 --- a/ext/regen_thumb/theme.php +++ b/ext/regen_thumb/theme.php @@ -9,7 +9,7 @@ class RegenThumbTheme extends Themelet { */ public function get_buttons_html($image_id) { return " - ".make_form(make_link("regen_thumb"))." + ".make_form(make_link("regen_thumb/one"))." @@ -29,5 +29,15 @@ class RegenThumbTheme extends Themelet { $page->add_block(new NavBlock()); $page->add_block(new Block("Thumbnail", $this->build_thumb_html($image))); } + + public function mtr_html($terms) { + $h_terms = html_escape($terms); + $html = make_form(make_link("regen_thumb/mass"), "POST") . " + + + + "; + return $html; + } } From 9f4caaddea85c7a05d1e645c26a9989dc5037771 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 1 Jun 2017 20:44:26 +0100 Subject: [PATCH 22/40] remove some unused variables --- ext/view/theme.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/view/theme.php b/ext/view/theme.php index 64bd1a57..17b96694 100644 --- a/ext/view/theme.php +++ b/ext/view/theme.php @@ -30,11 +30,9 @@ class ViewImageTheme extends Themelet { protected function build_pin(Image $image) { if(isset($_GET['search'])) { - $search_terms = explode(' ', $_GET['search']); $query = "search=".url_escape($_GET['search']); } else { - $search_terms = array(); $query = null; } From d105644d1b4ee2154dd54d023342b0ca627d6561 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 8 Jun 2017 09:36:59 +0100 Subject: [PATCH 23/40] use php sorting for alphabetic tag list, as utf8 sort ignores punctuation --- ext/tag_list/main.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index c97ebac4..c7804e69 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -269,7 +269,7 @@ class TagList extends Extension { $cache_key = data_path("cache/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html"); if(file_exists($cache_key)) {return file_get_contents($cache_key);} - $tag_data = $database->get_all($database->scoreql_to_sql(" + $tag_data = $database->get_pairs($database->scoreql_to_sql(" SELECT tag, count FROM tags WHERE count >= :tags_min @@ -296,8 +296,10 @@ class TagList extends Extension { mb_internal_encoding('UTF-8'); $lastLetter = ""; - foreach($tag_data as $row) { - $tag = $row['tag']; + # postres utf8 string sort ignores punctuation, so we get "aza, a-zb, azc" + # which breaks down into "az, a-, az" :( + ksort($tag_data, SORT_STRING | SORT_FLAG_CASE); + foreach($tag_data as $tag => $count) { if($lastLetter != mb_strtolower(substr($tag, 0, count($starts_with)+1))) { $lastLetter = mb_strtolower(substr($tag, 0, count($starts_with)+1)); $h_lastLetter = html_escape($lastLetter); @@ -305,7 +307,6 @@ class TagList extends Extension { } $link = $this->tag_link($tag); $h_tag = html_escape($tag); - $count = $row['count']; $html .= "$h_tag ($count)\n"; } From 94ec37029a054f371e91a034d029737739d42ea1 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 8 Jun 2017 09:37:21 +0100 Subject: [PATCH 24/40] stub more mb_ functions --- core/util.inc.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/util.inc.php b/core/util.inc.php index 842918dd..0ad31d44 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -963,6 +963,10 @@ if (!function_exists('mb_strlen')) { function mb_strlen($str, $encoding) { return strlen($str); } + function mb_internal_encoding($encoding) {} + function mb_strtolower($str) { + return strtolower($str); + } } /** From 2f083f76081b935d3561a6ed4f20263b01a4b2c8 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 8 Jun 2017 09:37:38 +0100 Subject: [PATCH 25/40] more useful memcached error messages --- core/database.class.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/database.class.php b/core/database.class.php index 2ab4230e..b63d3d1d 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -399,6 +399,7 @@ class MemcachedCache implements CacheEngine { */ public function get($key) { assert('!is_null($key)'); + $key = urlencode($key); $val = $this->memcache->get($key); $res = $this->memcache->getResultCode(); @@ -416,7 +417,7 @@ class MemcachedCache implements CacheEngine { return false; } else { - error_log("Memcached error: $res"); + error_log("Memcached error during get($key): $res"); } } @@ -427,11 +428,16 @@ class MemcachedCache implements CacheEngine { */ public function set($key, $val, $time=0) { assert('!is_null($key)'); + $key = urlencode($key); $this->memcache->set($key, $val, $time); + $res = $this->memcache->getResultCode(); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { file_put_contents("data/cache.log", "Cache set: $key ($time)\n", FILE_APPEND); } + if($res != Memcached::RES_SUCCESS) { + error_log("Memcached error during set($key): $res"); + } } /** @@ -439,11 +445,16 @@ class MemcachedCache implements CacheEngine { */ public function delete($key) { assert('!is_null($key)'); + $key = urlencode($key); $this->memcache->delete($key); + $res = $this->memcache->getResultCode(); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { file_put_contents("data/cache.log", "Cache delete: $key\n", FILE_APPEND); } + if($res != Memcached::RES_SUCCESS && $res != Memcached::RES_NOTFOUND) { + error_log("Memcached error during delete($key): $res"); + } } /** From 8fcf721045af4ef1dc7ec607d510404ce9852c6f Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 20 Jul 2017 23:28:55 +0100 Subject: [PATCH 26/40] use image link for video --- ext/handle_video/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php index 83d14104..21d4ac61 100644 --- a/ext/handle_video/theme.php +++ b/ext/handle_video/theme.php @@ -11,7 +11,7 @@ class VideoFileHandlerTheme extends Themelet { $loop = $config->get_bool("video_playback_loop"); $player = make_link('lib/vendor/swf/flashmediaelement.swf'); - $html = "Video not playing? Click here to download the file.
"; + $html = "Video not playing? Click here to download the file.
"; //Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats $supportedExts = ['mp4' => 'video/mp4', 'm4v' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm', 'flv' => 'video/flv']; From 3c3529a4ccc43808367cf875e070c0f61b8611ef Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 20 Jul 2017 23:29:17 +0100 Subject: [PATCH 27/40] don't respond to autocomplete requests for blank string --- ext/tag_list/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index c7804e69..8649a18a 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -46,7 +46,7 @@ class TagList extends Extension { $this->theme->display_page($page); } else if($event->page_matches("api/internal/tag_list/complete")) { - if(!isset($_GET["s"])) return; + if(!isset($_GET["s"]) || $_GET["s"] == "" || $_GET["s"] == "_") return; //$limit = 0; $cache_key = "autocomplete-" . strtolower($_GET["s"]); From 5a6728209a6f1f281637f4091d6bf845afeb13ab Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 22 Aug 2017 01:04:33 +0100 Subject: [PATCH 28/40] improve cache logging --- core/database.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/database.class.php b/core/database.class.php index b63d3d1d..ec1a7ce2 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -405,7 +405,7 @@ class MemcachedCache implements CacheEngine { $res = $this->memcache->getResultCode(); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { - $hit = $res == Memcached::RES_SUCCESS ? "miss" : "hit"; + $hit = $res == Memcached::RES_SUCCESS ? "hit" : "miss"; file_put_contents("data/cache.log", "Cache $hit: $key\n", FILE_APPEND); } if($res == Memcached::RES_SUCCESS) { @@ -690,7 +690,7 @@ class Database { * @param string $sql */ private function count_execs($db, $sql, $inputarray) { - if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { + if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { $sql = trim(preg_replace('/\s+/msi', ' ', $sql)); if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { $text = $sql." -- ".join(", ", $inputarray)."\n"; @@ -707,7 +707,7 @@ class Database { } private function count_time($method, $start) { - if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { + if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { $text = $method.":".(microtime(true) - $start)."\n"; file_put_contents("data/sql.log", $text, FILE_APPEND); } From d875ab66a1d46225343ad395f05f3f93991dda72 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 22 Aug 2017 01:05:18 +0100 Subject: [PATCH 29/40] 60 second post-list cache --- ext/index/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/index/main.php b/ext/index/main.php index 49e53781..29d225ea 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -265,7 +265,7 @@ class Index extends Extension { $images = $database->cache->get("post-list:$page_number"); if(!$images) { $images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms); - $database->cache->set("post-list:$page_number", $images, 600); + $database->cache->set("post-list:$page_number", $images, 60); } } else { From 35bd51e5138bbd29adc7b365e62c63b043796192 Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 23 Aug 2017 00:42:19 +0100 Subject: [PATCH 30/40] use 'count()' + result->get_one() to count images, rather than 'select *' + result->rowcount()... --- core/imageboard.pack.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 4975c050..0ee89a09 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -282,8 +282,7 @@ class Image { } else { $querylet = Image::build_search_querylet($tags); - $result = $database->execute($querylet->sql, $querylet->variables); - return $result->rowCount(); + return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables); } } From 473c0f0bcb7507561fd300bf71a17f1eed652946 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 24 Aug 2017 10:17:24 +0100 Subject: [PATCH 31/40] explicitly mark some block types as ignored when calculating 404ness --- core/block.class.php | 8 ++++++++ ext/blocks/main.php | 4 +++- ext/chatbox/main.php | 1 + ext/handle_404/main.php | 5 +---- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/block.class.php b/core/block.class.php index 1fbe0e3f..8fe1bfbc 100644 --- a/core/block.class.php +++ b/core/block.class.php @@ -44,6 +44,14 @@ class Block { */ public $id; + /** + * Should this block count as content for the sake of + * the 404 handler + * + * @var boolean + */ + public $is_content = true; + /** * Construct a block. * diff --git a/ext/blocks/main.php b/ext/blocks/main.php index 43043370..d1f0f6cf 100644 --- a/ext/blocks/main.php +++ b/ext/blocks/main.php @@ -42,7 +42,9 @@ class Blocks extends Extension { foreach($blocks as $block) { $path = implode("/", $event->args); if(strlen($path) < 4000 && fnmatch($block['pages'], $path)) { - $page->add_block(new Block($block['title'], $block['content'], $block['area'], $block['priority'])); + $b = new Block($block['title'], $block['content'], $block['area'], $block['priority']); + $b->is_content = false; + $page->add_block($b); } } diff --git a/ext/chatbox/main.php b/ext/chatbox/main.php index 1ac474c4..80081d46 100644 --- a/ext/chatbox/main.php +++ b/ext/chatbox/main.php @@ -30,6 +30,7 @@ class Chatbox extends Extension { // loads the chatbox at the set location $html = "
"; $chatblock = new Block("Chatbox", $html, "main", 97); + $chatblock->is_content = false; $page->add_block($chatblock); } } diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php index b7996848..a17e80f7 100644 --- a/ext/handle_404/main.php +++ b/ext/handle_404/main.php @@ -43,10 +43,7 @@ class Handle404 extends Extension { private function count_main($blocks) { $n = 0; foreach($blocks as $block) { - if($block->section == "main") $n++; // more hax. - } - if(ext_is_live("Chatbox")) { - $n--; // even more hax. + if($block->section == "main" && $block->is_content) $n++; // more hax. } return $n; } From abe473ffd68ee0eb6370b613f34635413e689414 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 24 Aug 2017 10:17:39 +0100 Subject: [PATCH 32/40] count blank header as null --- core/block.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/block.class.php b/core/block.class.php index 8fe1bfbc..0fffb41f 100644 --- a/core/block.class.php +++ b/core/block.class.php @@ -66,7 +66,11 @@ class Block { $this->body = $body; $this->section = $section; $this->position = $position; - $this->id = preg_replace('/[^\w]/', '',str_replace(' ', '_', is_null($id) ? (is_null($header) ? md5($body) : $header) . $section : $id)); + + if(is_null($id)) { + $id = (empty($header) ? md5($body) : $header) . $section; + } + $this->id = preg_replace('/[^\w]/', '',str_replace(' ', '_', $id)); } /** From cdbb4e8c7b24f21ce4cd0c7b513f08bde215af1a Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 17 Sep 2017 15:09:25 +0100 Subject: [PATCH 33/40] add resize/script.js --- ext/resize/script.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ext/resize/script.js diff --git a/ext/resize/script.js b/ext/resize/script.js new file mode 100644 index 00000000..21edb03d --- /dev/null +++ b/ext/resize/script.js @@ -0,0 +1,19 @@ +$(function() { + var original_width = $("#original_width").val(); + var original_height = $("#original_height").val(); + + $("#resize_width").change(function() { + if($("#resize_aspect").prop("checked")) { + $("#resize_height").val( + Math.round($("#resize_width").val() / original_width * original_height) + ); + } + }); + $("#resize_height").change(function() { + if($("#resize_aspect").prop("checked")) { + $("#resize_width").val( + Math.round($("#resize_height").val() / original_height * original_width) + ); + } + }); +}); From e1d6ff0f4ee4006a904c0ee2122e45bce88719eb Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 17 Sep 2017 17:08:08 +0100 Subject: [PATCH 34/40] composer update --- composer.lock | 250 ++++++++++++++++++--------------------------- tests/test-deep.sh | 2 +- 2 files changed, 100 insertions(+), 152 deletions(-) diff --git a/composer.lock b/composer.lock index 4eed5ce6..bd153b0b 100644 --- a/composer.lock +++ b/composer.lock @@ -18,23 +18,11 @@ "type": "zip", "url": "https://api.github.com/repos/jquery/jquery-dist/zipball/3a43d7e563314bf32970b773dd31ecf2b90813dd", "reference": "3a43d7e563314bf32970b773dd31ecf2b90813dd", - "shasum": "" - }, - "type": "bower-asset-library", - "extra": { - "bower-asset-main": "dist/jquery.js", - "bower-asset-ignore": [ - "package.json" - ] + "shasum": null }, + "type": "bower-asset", "license": [ "MIT" - ], - "keywords": [ - "browser", - "javascript", - "jquery", - "library" ] }, { @@ -49,19 +37,12 @@ "type": "zip", "url": "https://api.github.com/repos/rmm5t/jquery-timeago/zipball/67c11951ae9b6020341c1056a42b5406162db40c", "reference": "67c11951ae9b6020341c1056a42b5406162db40c", - "shasum": "" + "shasum": null }, "require": { "bower-asset/jquery": ">=1.4" }, - "type": "bower-asset-library", - "extra": { - "bower-asset-main": "jquery.timeago.js", - "bower-asset-ignore": [ - "test", - "vendor" - ] - }, + "type": "bower-asset", "license": [ "MIT" ] @@ -78,25 +59,9 @@ "type": "zip", "url": "https://api.github.com/repos/js-cookie/js-cookie/zipball/5c830fb71a2bd3acce9cb733d692e13316991891", "reference": "5c830fb71a2bd3acce9cb733d692e13316991891", - "shasum": "" - }, - "type": "bower-asset-library", - "extra": { - "bower-asset-main": [ - "src/js.cookie.js" - ], - "bower-asset-ignore": [ - "travis.sh", - "test", - "Gruntfile.js", - "package.json", - ".gitignore", - ".jshintignore", - ".jshintrc", - ".tm_properties", - ".travis.yml" - ] + "shasum": null }, + "type": "bower-asset", "license": [ "MIT" ] @@ -106,38 +71,18 @@ "version": "2.21.1", "source": { "type": "git", - "url": "https://github.com/johndyer/mediaelement.git", + "url": "https://github.com/mediaelement/mediaelement.git", "reference": "6e80b260172f4ddc3b0bbee046775d2ba4c6f9b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/johndyer/mediaelement/zipball/6e80b260172f4ddc3b0bbee046775d2ba4c6f9b7", + "url": "https://api.github.com/repos/mediaelement/mediaelement/zipball/6e80b260172f4ddc3b0bbee046775d2ba4c6f9b7", "reference": "6e80b260172f4ddc3b0bbee046775d2ba4c6f9b7", - "shasum": "" - }, - "type": "bower-asset-library", - "extra": { - "bower-asset-main": [ - "./build/mediaelement-and-player.js", - "./build/mediaelementplayer.css" - ], - "bower-asset-ignore": [ - "**", - "!/build/**", - "!/bower.json", - "!/README*", - "!/changelog*" - ] + "shasum": null }, + "type": "bower-asset", "license": [ "MIT" - ], - "description": "HTML5