From bdb3255116916a4a3e25c521ec307d2a2f91a05c Mon Sep 17 00:00:00 2001 From: Daku Date: Sun, 23 Feb 2014 22:27:52 +0000 Subject: [PATCH 01/15] speed: lowercase ext on image insert avoids having to lowercase every build_thumb_html call most extensions tend to match against their lowercase versions anyway --- core/basethemelet.class.php | 2 +- ext/image/main.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 06fadc20..445ada89 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -44,7 +44,7 @@ class BaseThemelet { $h_thumb_link = $image->get_thumb_link(); $h_tip = html_escape($image->get_tooltip()); $h_tags = strtolower($image->get_tag_list()); - $ext = strtolower($image->ext); + $ext = $image->ext; // If the file doesn't support thumbnail generation, show it at max size. if($ext === 'swf' || $ext === 'svg' || $ext === 'mp4' || $ext === 'ogv' || $ext === 'webm' || $ext === 'flv'){ diff --git a/ext/image/main.php b/ext/image/main.php index d2553606..4addd849 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -325,7 +325,7 @@ class ImageIO extends Extension { )", array( "owner_id"=>$user->id, "owner_ip"=>$_SERVER['REMOTE_ADDR'], "filename"=>substr($image->filename, 0, 60), "filesize"=>$image->filesize, - "hash"=>$image->hash, "ext"=>$image->ext, "width"=>$image->width, "height"=>$image->height, "source"=>$image->source + "hash"=>$image->hash, "ext"=>strtolower($image->ext), "width"=>$image->width, "height"=>$image->height, "source"=>$image->source ) ); $image->id = $database->get_last_insert_id('images_id_seq'); @@ -435,7 +435,7 @@ class ImageIO extends Extension { ", array( "filename"=>$image->filename, "filesize"=>$image->filesize, "hash"=>$image->hash, - "ext"=>$image->ext, "width"=>$image->width, "height"=>$image->height, "source"=>$image->source, + "ext"=>strtolower($image->ext), "width"=>$image->width, "height"=>$image->height, "source"=>$image->source, "id"=>$id ) ); From 58c5746e9bbed3de75a2c15957d0311be4e7ec46 Mon Sep 17 00:00:00 2001 From: Daku Date: Sun, 23 Feb 2014 22:32:15 +0000 Subject: [PATCH 02/15] speed: use isset rather than identical --- core/basethemelet.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 445ada89..94cfc159 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -39,19 +39,19 @@ class BaseThemelet { */ public function build_thumb_html(Image $image) { global $config; + $i_id = (int) $image->id; $h_view_link = make_link('post/view/'.$i_id); $h_thumb_link = $image->get_thumb_link(); $h_tip = html_escape($image->get_tooltip()); $h_tags = strtolower($image->get_tag_list()); - $ext = $image->ext; - - // If the file doesn't support thumbnail generation, show it at max size. - if($ext === 'swf' || $ext === 'svg' || $ext === 'mp4' || $ext === 'ogv' || $ext === 'webm' || $ext === 'flv'){ - $tsize = get_thumbnail_size($config->get_int('thumb_width'), $config->get_int('thumb_height')); - } - else{ + + $extArr = array_flip(array('swf', 'svg', 'mp4', 'ogv', 'webm', 'flv')); //List of thumbless filetypes + if(!isset($extArr[$image->ext])){ $tsize = get_thumbnail_size($image->width, $image->height); + }else{ + //Use max thumbnail size if using thumbless filetype + $tsize = get_thumbnail_size($config->get_int('thumb_width'), $config->get_int('thumb_height')); } $custom_classes = ""; From 790cb0d7a96fe00b5e5f755a6430a41838404407 Mon Sep 17 00:00:00 2001 From: Daku Date: Thu, 16 Jan 2014 08:31:34 +0000 Subject: [PATCH 03/15] [.+]tags metatag for tag_categories This is nowhere as near as fast as I'd like. Need to find a better query. --- ext/tag_categories/main.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php index 4a5dcffa..285a18e8 100644 --- a/ext/tag_categories/main.php +++ b/ext/tag_categories/main.php @@ -48,6 +48,30 @@ class TagCategories extends Extension { } } + public function onSearchTermParse(SearchTermParseEvent $event) { + $matches = array(); + + if(preg_match("/^(.+)tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]+)$/", $event->term, $matches)) { + global $database; + $type = $matches[1]; + $cmp = ltrim($matches[2], ":") ?: "="; + $count = $matches[3]; + + $types = $database->get_col('SELECT category FROM image_tag_categories'); + if(in_array($type, $types)) { + $event->add_querylet(new Querylet("images.id IN ( + SELECT * FROM ( + SELECT it.image_id + FROM image_tags it + LEFT JOIN tags t ON it.tag_id = t.id + GROUP BY image_id + HAVING SUM(CASE WHEN t.tag LIKE '$type:%' THEN 1 ELSE 0 END) $cmp $count + ) AS subquery + )")); + } + } + } + public function getDict() { global $database; From 320a92289b22833bd6814070294a91c6ae50f887 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 24 Feb 2014 01:50:31 +0000 Subject: [PATCH 04/15] have query use EXISTS rather than IN preferably we would have a table with image tag counts, but this works for now --- ext/tag_categories/main.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php index 285a18e8..80f62e88 100644 --- a/ext/tag_categories/main.php +++ b/ext/tag_categories/main.php @@ -51,7 +51,7 @@ class TagCategories extends Extension { public function onSearchTermParse(SearchTermParseEvent $event) { $matches = array(); - if(preg_match("/^(.+)tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]+)$/", $event->term, $matches)) { + if(preg_match("/^(.+)tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]+)$/i", $event->term, $matches)) { global $database; $type = $matches[1]; $cmp = ltrim($matches[2], ":") ?: "="; @@ -59,15 +59,15 @@ class TagCategories extends Extension { $types = $database->get_col('SELECT category FROM image_tag_categories'); if(in_array($type, $types)) { - $event->add_querylet(new Querylet("images.id IN ( - SELECT * FROM ( - SELECT it.image_id - FROM image_tags it - LEFT JOIN tags t ON it.tag_id = t.id - GROUP BY image_id - HAVING SUM(CASE WHEN t.tag LIKE '$type:%' THEN 1 ELSE 0 END) $cmp $count - ) AS subquery - )")); + $event->add_querylet( + new Querylet("EXISTS ( + SELECT 1 + FROM image_tags it + LEFT JOIN tags t ON it.tag_id = t.id + WHERE images.id = it.image_id + GROUP BY image_id + HAVING SUM(CASE WHEN t.tag LIKE '$type:%' THEN 1 ELSE 0 END) $cmp $count + )")); } } } From d67582717300391ac6ed03440a8b18fc10f6ae66 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 24 Feb 2014 19:54:15 +0000 Subject: [PATCH 05/15] order[=|:]random_#### metatag possible replacement for random_list ext? --- core/imageboard.pack.php | 2 +- ext/index/main.php | 14 +++++++++++++- ext/index/script.js | 12 ++++++++++++ ext/numeric_score/main.php | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index d87a6f4a..1c8b56a5 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -129,7 +129,7 @@ class Image { } $querylet = Image::build_search_querylet($tags); - $querylet->append(new Querylet(" ORDER BY images.".($order_sql ?: $config->get_string("index_order")))); + $querylet->append(new Querylet(" ORDER BY ".($order_sql ?: "images.".$config->get_string("index_order")))); $querylet->append(new Querylet(" LIMIT :limit OFFSET :offset", array("limit"=>$limit, "offset"=>$start))); #var_dump($querylet->sql); var_dump($querylet->variables); $result = $database->execute($querylet->sql, $querylet->variables); diff --git a/ext/index/main.php b/ext/index/main.php index a251f484..1ca555a7 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -94,6 +94,10 @@ *
  • order=width -- find all images sorted from highest > lowest width *
  • order=filesize_asc -- find all images sorted from lowest > highest filesize * + *
  • order=random_####, eg + *
      + *
    • order=random_8547 -- find all images sorted randomly using 8547 as a seed + *
    * *

    Search items can be combined to search for images which match both, * or you can stick "-" in front of an item to search for things that don't @@ -362,7 +366,15 @@ class Index extends Extension { $ord = strtolower($matches[1]); $default_order_for_column = preg_match("/^(id|filename)$/", $matches[1]) ? "ASC" : "DESC"; $sort = isset($matches[2]) ? strtoupper($matches[2]) : $default_order_for_column; - $order_sql = "$ord $sort"; + $order_sql = "images.$ord $sort"; + $event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag + } + else if(preg_match("/^order[=|:]random[_]([0-9]{1,4})$/i", $event->term, $matches)){ + global $order_sql; + //order[=|:]random requires a seed to avoid duplicates + //since the tag can't be changed during the parseevent, we instead generate the seed during submit using js + $seed = $matches[1]; + $order_sql = "RAND($seed)"; $event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag } diff --git a/ext/index/script.js b/ext/index/script.js index f90bc95e..d98c54d8 100644 --- a/ext/index/script.js +++ b/ext/index/script.js @@ -17,6 +17,18 @@ $(function() { function() {$('.shm-image-list').show();} ); } + + //Generate a random seed when using order:random + $('form[action="/shimmie/post/list"]').submit(function(e){ + var input = $('form[action="/shimmie/post/list"] input[name=search]'); + var tagArr = input.val().split(" "); + + var rand = (($.inArray("order:random", tagArr) + 1) || ($.inArray("order=random", tagArr) + 1)) - 1; + if(rand !== -1){ + tagArr[rand] = "order:random_"+Math.floor((Math.random()*9999)+1); + input.val(tagArr.join(" ")); + } + }); }); function select_blocked_tags() { diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php index 8f8cc980..1471fb70 100644 --- a/ext/numeric_score/main.php +++ b/ext/numeric_score/main.php @@ -237,7 +237,7 @@ class NumericScore extends Extension { global $order_sql; $default_order_for_column = "DESC"; $sort = isset($matches[3]) ? strtoupper($matches[3]) : $default_order_for_column; - $order_sql = "numeric_score $sort"; + $order_sql = "images.numeric_score $sort"; $event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag } } From df29537e747989a8d9623b53b376a19c4db983b4 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 24 Feb 2014 20:07:05 +0000 Subject: [PATCH 06/15] use default minchars again the tag list only returns a max of 10 results, and is only called once per autocomplete, making it harder to autocomplete longer tags --- lib/shimmie.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/shimmie.js b/lib/shimmie.js index 1814570b..f7731186 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -9,7 +9,7 @@ $(document).ready(function() { // Also use autocomplete in tag box? $('.autocomplete_tags').autocomplete(base_href + '/api/internal/tag_list/complete', { width: 320, - max: 15, + max: 10, highlight: false, multiple: true, multipleSeparator: ' ', @@ -17,8 +17,7 @@ $(document).ready(function() { scrollHeight: 300, selectFirst: false, queryParamName: 's', - delay: 150, - minChars: 1 + delay: 150 }); $("TABLE.sortable").tablesorter(); From 34e90c1cfcb7d56ae748884322d4518adb1d6cf1 Mon Sep 17 00:00:00 2001 From: Daku Date: Tue, 25 Feb 2014 17:40:07 +0000 Subject: [PATCH 07/15] updated date/links in footer --- themes/danbooru/layout.class.php | 4 ++-- themes/danbooru2/layout.class.php | 6 +++--- themes/default/layout.class.php | 4 ++-- themes/futaba/layout.class.php | 4 ++-- themes/lite/layout.class.php | 4 ++-- themes/warm/layout.class.php | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/themes/danbooru/layout.class.php b/themes/danbooru/layout.class.php index 611d8df6..4598f66b 100644 --- a/themes/danbooru/layout.class.php +++ b/themes/danbooru/layout.class.php @@ -231,8 +231,8 @@ $header_html Images © their respective owners, Shimmie © Shish & - The Team - 2007-2012, + The Team + 2007-2014, based on the Danbooru concept. $debug $contact diff --git a/themes/danbooru2/layout.class.php b/themes/danbooru2/layout.class.php index c0405e75..728af1cd 100644 --- a/themes/danbooru2/layout.class.php +++ b/themes/danbooru2/layout.class.php @@ -254,11 +254,11 @@ $header_html