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 @@ *
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 } }