diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php
index 869e7de6..c9a2ce4a 100644
--- a/core/imageboard.pack.php
+++ b/core/imageboard.pack.php
@@ -476,11 +476,11 @@ class Image {
$this->delete_tags_from_image();
// insert each new tags
foreach($tags as $tag) {
- if(preg_match("/^source=(.*)$/i", $tag, $matches)) {
+ if(preg_match("/^source[=|:](.*)$/i", $tag, $matches)) {
$this->set_source($matches[1]);
continue;
}
- if(preg_match("/^pool=(.*)$/i", $tag, $matches)) {
+ if(preg_match("/^pool[=|:](.*)$/i", $tag, $matches)) {
if(class_exists("Pools")) {
$pls = new Pools();
$pls->add_post_from_tag($matches[1], $this->id);
diff --git a/ext/danbooru_api/main.php b/ext/danbooru_api/main.php
index f5d8773e..2ba1b82d 100644
--- a/ext/danbooru_api/main.php
+++ b/ext/danbooru_api/main.php
@@ -54,14 +54,6 @@ class DanbooruApi extends Extension {
}
}
- public function onSearchTermParse(SearchTermParseEvent $event) {
- $matches = array();
- if(preg_match("/^md5:([0-9a-fA-F]*)$/i", $event->term, $matches)) {
- $hash = strtolower($matches[1]);
- $event->add_querylet(new Querylet("images.hash = '$hash'")); // :-O
- }
- }
-
// Danbooru API
private function api_danbooru(PageRequestEvent $event)
{
diff --git a/ext/favorites/main.php b/ext/favorites/main.php
index aee35d6a..6517377e 100644
--- a/ext/favorites/main.php
+++ b/ext/favorites/main.php
@@ -117,12 +117,12 @@ class Favorites extends Extension {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
- if(preg_match("/favorites(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
- $cmp = $matches[1];
+ if(preg_match("/^favorites([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$favorites = $matches[2];
$event->add_querylet(new Querylet("images.id IN (SELECT id FROM images WHERE favorites $cmp $favorites)"));
}
- else if(preg_match("/favorited_by=(.*)/i", $event->term, $matches)) {
+ else if(preg_match("/^favorited_by[=|:](.*)$/i", $event->term, $matches)) {
global $database;
$user = User::by_name($matches[1]);
if(!is_null($user)) {
@@ -134,7 +134,7 @@ class Favorites extends Extension {
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM user_favorites WHERE user_id = $user_id)"));
}
- else if(preg_match("/favorited_by_userno=([0-9]+)/i", $event->term, $matches)) {
+ else if(preg_match("/^favorited_by_userno[=|:](\d+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM user_favorites WHERE user_id = $user_id)"));
}
diff --git a/ext/index/main.php b/ext/index/main.php
index f851bde7..4acc663c 100644
--- a/ext/index/main.php
+++ b/ext/index/main.php
@@ -38,36 +38,53 @@
*
id<20 -- search only the first few images
* id>=500 -- search later images
*
- * user=Username, eg
+ * user=Username & poster=Username, eg
*
* - user=Shish -- find all of Shish's posts
+ *
- poster=Shish -- same as above
*
- * hash=md5sum, eg
+ * user_id=userID & poster_id=userID, eg
+ *
+ * - user_id=2 -- find all posts by user id 2
+ *
- poster_id=2 -- same as above
+ *
+ * hash=md5sum & md5=md5sum, eg
*
* - hash=bf5b59173f16b6937a4021713dbfaa72 -- find the "Taiga want up!" image
+ *
- md5=bf5b59173f16b6937a4021713dbfaa72 -- same as above
*
- * filetype=type, eg
+ * filetype=type & ext=type, eg
*
* - filetype=png -- find all PNG images
+ *
- ext=png -- same as above
*
- * filename=blah, eg
+ * filename=blah & name=blah, eg
*
* - filename=kitten -- find all images with "kitten" in the original filename
+ *
- name=kitten -- same as above
*
* posted (=, <, >, <=, >=) date, eg
*
* - posted>=2009-12-25 posted<=2010-01-01 -- find images posted between christmas and new year
*
+ * tags (=, <, >, <=, >=) count, eg
+ *
+ * - tags=1 -- search for images with only 1 tag
+ *
- tags>=10 -- search for images with 10 or more tags
+ *
- tags<25 -- search for images with less than 25 tags
+ *
+ * source=url, eg
+ *
+ * - source=http://example.com -- find all images with "http://example.com" in the source
+ *
*
* 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
* match it.
+ *
Metatags can be followed by ":" rather than "=" if you prefer.
+ *
I.E: "posted:2014-01-01", "id:>=500" etc.
*
Some search methods provided by extensions:
*
- * - Danbooru API
- *
- * - md5:[hash] -- same as "hash=", but the API calls it by a different name
- *
* - Numeric Score
*
* - score (=, <, >, <=, >=) number -- seach by score
@@ -81,11 +98,14 @@
*
- Favorites
*
* - favorites (=, <, >, <=, >=) number -- search for images favourited a certain number of times
- *
- favourited_by=Username -- search for a user's choices
+ *
- favourited_by=Username -- search for a user's choices by username
+ *
- favorited_by_userno=UserID -- search for a user's choice by userID
*
* - Notes
*
* - notes (=, <, >, <=, >=) number -- search by the number of notes an image has
+ *
- notes_by=Username -- search for a notes created by username
+ *
- notes_by_userno=UserID -- search for a notes created by userID
*
*
*/
@@ -240,45 +260,45 @@ class Index extends Extension {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
// check for tags first as tag based searches are more common.
- if(preg_match("/tags(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
- $cmp = $matches[1];
+ if(preg_match("/^tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$tags = $matches[2];
$event->add_querylet(new Querylet('images.id IN (SELECT DISTINCT image_id FROM image_tags GROUP BY image_id HAVING count(image_id) '.$cmp.' '.$tags.')'));
}
- else if(preg_match("/^ratio(<|>|<=|>=|=)(\d+):(\d+)$/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^ratio([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+):(\d+)$/", $event->term, $matches)) {
+ $cmp = preg_replace('/^:/', '=', $matches[1]);
$args = array("width{$this->stpen}"=>int_escape($matches[2]), "height{$this->stpen}"=>int_escape($matches[3]));
$event->add_querylet(new Querylet("width / height $cmp :width{$this->stpen} / :height{$this->stpen}", $args));
}
- else if(preg_match("/^(filesize|id)(<|>|<=|>=|=)(\d+[kmg]?b?)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(filesize|id)([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+[kmg]?b?)$/i", $event->term, $matches)) {
$col = $matches[1];
- $cmp = $matches[2];
+ $cmp = ltrim($matches[2], ":") ?: "=";
$val = parse_shorthand_int($matches[3]);
$event->add_querylet(new Querylet("images.$col $cmp :val{$this->stpen}", array("val{$this->stpen}"=>$val)));
}
- else if(preg_match("/^(hash|md5)=([0-9a-fA-F]*)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(hash|md5)[=|:]([0-9a-fA-F]*)$/i", $event->term, $matches)) {
$hash = strtolower($matches[2]);
$event->add_querylet(new Querylet('images.hash = :hash', array("hash" => $hash)));
}
- else if(preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(filetype|ext)[=|:]([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
$ext = strtolower($matches[2]);
$event->add_querylet(new Querylet('images.ext = :ext', array("ext" => $ext)));
}
- else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(filename|name)[=|:]([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
$filename = strtolower($matches[2]);
$event->add_querylet(new Querylet("images.filename LIKE :filename{$this->stpen}", array("filename{$this->stpen}"=>"%$filename%")));
}
- else if(preg_match("/^(source)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
- $filename = strtolower($matches[2]);
- $event->add_querylet(new Querylet('images.source LIKE :src', array("src"=>"%$filename%")));
+ else if(preg_match("/^(source)[=|:]([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
+ $source = strtolower($matches[2]);
+ $event->add_querylet(new Querylet('images.source LIKE :src', array("src"=>"%$source%")));
}
- else if(preg_match("/^posted(<|>|<=|>=|=)([0-9-]*)$/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^posted([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9-]*)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$val = $matches[2];
$event->add_querylet(new Querylet("images.posted $cmp :posted{$this->stpen}", array("posted{$this->stpen}"=>$val)));
}
- else if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^size([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)x(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$args = array("width{$this->stpen}"=>int_escape($matches[2]), "height{$this->stpen}"=>int_escape($matches[3]));
$event->add_querylet(new Querylet("width $cmp :width{$this->stpen} AND height $cmp :height{$this->stpen}", $args));
}
diff --git a/ext/notes/main.php b/ext/notes/main.php
index 5bc09ef6..f29a22e9 100644
--- a/ext/notes/main.php
+++ b/ext/notes/main.php
@@ -210,16 +210,16 @@ class Notes extends Extension {
*/
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
- if(preg_match("/note=(.*)/i", $event->term, $matches)) {
+ if(preg_match("/^note[=|:](.*)$/i", $event->term, $matches)) {
$notes = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM notes WHERE note = $notes)"));
}
- else if(preg_match("/notes(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^notes([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)%/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$notes = $matches[2];
$event->add_querylet(new Querylet("images.id IN (SELECT id FROM images WHERE notes $cmp $notes)"));
}
- else if(preg_match("/notes_by=(.*)/i", $event->term, $matches)) {
+ else if(preg_match("/^notes_by[=|:](.*)$/i", $event->term, $matches)) {
global $database;
$user = User::by_name($matches[1]);
if(!is_null($user)) {
@@ -231,7 +231,7 @@ class Notes extends Extension {
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM notes WHERE user_id = $user_id)"));
}
- else if(preg_match("/notes_by_userno=([0-9]+)/i", $event->term, $matches)) {
+ else if(preg_match("/^notes_by_userno[=|:](\d+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM notes WHERE user_id = $user_id)"));
}
diff --git a/ext/rating/main.php b/ext/rating/main.php
index be54cdb4..1b41b89f 100644
--- a/ext/rating/main.php
+++ b/ext/rating/main.php
@@ -116,7 +116,7 @@ class Ratings extends Extension {
$set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
$event->add_querylet(new Querylet("rating IN ($set)"));
}
- if(preg_match("/^rating=(?:([sqeu]+)|(safe|questionable|explicit|unknown))$/D", strtolower($event->term), $matches)) {
+ if(preg_match("/^rating[=|:](?:([sqeu]+)|(safe|questionable|explicit|unknown))$/D", strtolower($event->term), $matches)) {
$ratings = $matches[1] ? $matches[1] : array($matches[2][0]);
$ratings = array_intersect(str_split($ratings), str_split(Ratings::get_user_privs($user)));
$set = "'" . join("', '", $ratings) . "'";
@@ -199,7 +199,7 @@ class Ratings extends Extension {
private function no_rating_query($context) {
foreach($context as $term) {
- if(preg_match("/^rating=/", $term)) {
+ if(preg_match("/^rating[=|:]/", $term)) {
return false;
}
}
diff --git a/ext/user/main.php b/ext/user/main.php
index 5a4058ca..67755004 100644
--- a/ext/user/main.php
+++ b/ext/user/main.php
@@ -309,7 +309,7 @@ class UserPage extends Extension {
global $user;
$matches = array();
- if(preg_match("/^(poster|user)=(.*)$/i", $event->term, $matches)) {
+ if(preg_match("/^(poster|user)[=|:](.*)$/i", $event->term, $matches)) {
$duser = User::by_name($matches[2]);
if(!is_null($duser)) {
$user_id = $duser->id;
@@ -319,11 +319,11 @@ class UserPage extends Extension {
}
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
- else if(preg_match("/^(poster|user)_id=([0-9]+)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(poster|user)_id[=|:]([0-9]+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[2]);
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
- else if($user->can("view_ip") && preg_match("/^(poster|user)_ip=([0-9\.]+)$/i", $event->term, $matches)) {
+ else if($user->can("view_ip") && preg_match("/^(poster|user)_ip[=|:]([0-9\.]+)$/i", $event->term, $matches)) {
$user_ip = $matches[2]; // FIXME: ip_escape?
$event->add_querylet(new Querylet("images.owner_ip = '$user_ip'"));
}