From cc95eb5deb89b06e71911f4116a3d1d79f53fe4a Mon Sep 17 00:00:00 2001 From: jgen Date: Mon, 13 May 2013 20:40:01 -0400 Subject: [PATCH 1/5] Some more small speed tweaks. --- core/event.class.php | 6 ++++-- core/imageboard.pack.php | 13 ++++++++----- ext/wiki/main.php | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/event.class.php b/core/event.class.php index 2f3b84dd..f68a1336 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -39,7 +39,7 @@ class PageRequestEvent extends Event { } // if path is not specified, use the default front page - if(strlen($path) === 0) { + if(empty($path)) { /* empty is faster than strlen */ $path = $config->get_string('front_page'); } @@ -147,7 +147,9 @@ class CommandEvent extends Event { $opts = array(); $log_level = SCORE_LOG_WARNING; - for($i=1; $icache->get("image-count"); if(!$total) { $total = $database->get_one("SELECT COUNT(*) FROM images"); @@ -156,7 +158,7 @@ class Image { } return $total; } - else if(count($tags) == 1 && !preg_match("/[:=><\*\?]/", $tags[0])) { + else if($tag_count == 1 && !preg_match("/[:=><\*\?]/", $tags[0])) { $term = Tag::resolve_alias($tags[0]); return $database->get_one( $database->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"), @@ -578,13 +580,14 @@ class Image { $_flexihash = new Flexihash(); foreach(explode(",", $opts) as $opt) { $parts = explode("=", $opt); + $parts_count = count($parts); $opt_val = ""; $opt_weight = 0; - if(count($parts) == 2) { + if($parts_count == 2) { $opt_val = $parts[0]; $opt_weight = $parts[1]; } - elseif(count($parts) == 1) { + elseif($parts_count == 1) { $opt_val = $parts[0]; $opt_weight = 1; } @@ -652,7 +655,7 @@ class Image { $positive = false; $term = substr($term, 1); } - if(strlen($term) == 0) { + if(strlen($term) === 0) { continue; } diff --git a/ext/wiki/main.php b/ext/wiki/main.php index bb2f4837..4026c2bd 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -83,7 +83,7 @@ class Wiki extends Extension { public function onPageRequest(PageRequestEvent $event) { global $config, $page, $user; if($event->page_matches("wiki")) { - if(is_null($event->get_arg(0)) || strlen(trim($event->get_arg(0))) == 0) { + if(is_null($event->get_arg(0)) || strlen(trim($event->get_arg(0))) === 0) { $title = "Index"; } else { From 234b8c4f51fa323c8e062b80eff51f967198e0de Mon Sep 17 00:00:00 2001 From: jgen Date: Thu, 3 Oct 2013 21:08:13 -0400 Subject: [PATCH 2/5] Removing this line as this file does not exist and simply causes 404 errors. --- themes/danbooru2/layout.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/themes/danbooru2/layout.class.php b/themes/danbooru2/layout.class.php index e39c6623..a56315ea 100644 --- a/themes/danbooru2/layout.class.php +++ b/themes/danbooru2/layout.class.php @@ -233,7 +233,6 @@ class Layout { {$page->title} $header_html - From 2d041d468f83bfcdb9609a744404ad034430bea2 Mon Sep 17 00:00:00 2001 From: jgen Date: Thu, 3 Oct 2013 21:09:41 -0400 Subject: [PATCH 3/5] Adding ability to specify the 'date' in the image thumbnail title (when you hover over the thumbnail). --- core/imageboard.pack.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index a657212f..32e50efc 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -563,6 +563,7 @@ class Image { $tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl); $tmpl = str_replace('$filename', $_escape($base_fname), $tmpl); $tmpl = str_replace('$title', $_escape($config->get_string("title")), $tmpl); + $tmpl = str_replace('$date', $_escape(autodate($this->posted)), $tmpl); // nothing seems to use this, sending the event out to 50 exts is a lot of overhead if(!SPEED_HAX) { From 393a9e60df0b282ddd130b08c2c5012749fc6d7e Mon Sep 17 00:00:00 2001 From: jgen Date: Thu, 3 Oct 2013 21:17:15 -0400 Subject: [PATCH 4/5] No need to have HTML in the image thumb title. Derp. --- 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 32e50efc..04c79164 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -563,7 +563,7 @@ class Image { $tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl); $tmpl = str_replace('$filename', $_escape($base_fname), $tmpl); $tmpl = str_replace('$title', $_escape($config->get_string("title")), $tmpl); - $tmpl = str_replace('$date', $_escape(autodate($this->posted)), $tmpl); + $tmpl = str_replace('$date', $_escape(autodate($this->posted), false), $tmpl); // nothing seems to use this, sending the event out to 50 exts is a lot of overhead if(!SPEED_HAX) { From 70428b2b5d72bb898440bd5ac4939551304f9038 Mon Sep 17 00:00:00 2001 From: jgen Date: Thu, 3 Oct 2013 21:19:19 -0400 Subject: [PATCH 5/5] Its better to pass to the right function. (Side note, this is why you always test your code) --- 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 04c79164..eed9b604 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -563,7 +563,7 @@ class Image { $tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl); $tmpl = str_replace('$filename', $_escape($base_fname), $tmpl); $tmpl = str_replace('$title', $_escape($config->get_string("title")), $tmpl); - $tmpl = str_replace('$date', $_escape(autodate($this->posted), false), $tmpl); + $tmpl = str_replace('$date', $_escape(autodate($this->posted, false)), $tmpl); // nothing seems to use this, sending the event out to 50 exts is a lot of overhead if(!SPEED_HAX) {