From 25c286b71faf23231fea2346e6c5dcef1a39df15 Mon Sep 17 00:00:00 2001 From: Daku Date: Thu, 2 Jan 2014 14:00:24 +0000 Subject: [PATCH] add support for using : as a metatag seperator + updated docs --- core/imageboard.pack.php | 4 +-- ext/danbooru_api/main.php | 8 ----- ext/favorites/main.php | 8 ++--- ext/index/main.php | 70 +++++++++++++++++++++++++-------------- ext/notes/main.php | 10 +++--- ext/rating/main.php | 4 +-- ext/user/main.php | 6 ++-- 7 files changed, 61 insertions(+), 49 deletions(-) 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 * - *
  • hash=md5sum, eg + *
  • user_id=userID & poster_id=userID, eg + * + *
  • hash=md5sum & md5=md5sum, eg * - *
  • filetype=type, eg + *
  • filetype=type & ext=type, eg * - *
  • filename=blah, eg + *
  • filename=blah & name=blah, eg * *
  • posted (=, <, >, <=, >=) date, eg * + *
  • tags (=, <, >, <=, >=) count, eg + * + *
  • source=url, eg + * * *

    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: *