diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index c978c732..b8127e06 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -460,6 +460,8 @@ class Image { public function set_tags($tags) { global $database; + assert(is_array($tags)); + $tags = Tag::resolve_list($tags); assert(is_array($tags)); @@ -965,11 +967,11 @@ class Tag { /** * Turn any string or array into a valid tag array */ - public static function explode($tags) { + public static function explode($tags, $tagme=true) { assert(is_string($tags) || is_array($tags)); if(is_string($tags)) { - $tags = explode(' ', $tags); + $tags = explode(' ', trim($tags)); } //else if(is_array($tags)) { // do nothing @@ -983,7 +985,7 @@ class Tag { } } - if(count($tag_array) == 0) { + if(count($tag_array) == 0 && $tagme) { $tag_array = array("tagme"); } @@ -1053,8 +1055,8 @@ class Tag { * @return Array of tags */ public static function resolve_list($tags) { - $tags = Tag::explode($tags); - reset($tags); // rewind array to the first element. + assert(is_array($tags)); + $new = array(); foreach($tags as $tag) { $new_set = explode(' ', Tag::resolve_alias($tag)); @@ -1062,6 +1064,7 @@ class Tag { $new[] = $new_one; } } + $new = array_map(array('Tag', 'sanitise'), $new); $new = array_iunique($new); // remove any duplicate tags return $new; diff --git a/ext/index/main.php b/ext/index/main.php index 972be784..0b7ae1d0 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -147,7 +147,7 @@ class Index extends Extension { global $config, $database, $page, $user; if($event->page_matches("post/list")) { if(isset($_GET['search'])) { - $search = url_escape(implode(" ", Tag::resolve_list(trim($_GET['search'])))); + $search = url_escape(Tag::implode(Tag::resolve_list(Tag::explode($_GET['search'], false)))); if(empty($search)) { $page->set_mode("redirect"); $page->set_redirect(make_link("post/list/1")); diff --git a/ext/mass_tagger/main.php b/ext/mass_tagger/main.php index 31e6f21a..03a08c50 100644 --- a/ext/mass_tagger/main.php +++ b/ext/mass_tagger/main.php @@ -42,13 +42,13 @@ class MassTagger extends Extension { $_POST['setadd'] == 'set') { foreach($images as $image) { - $image->set_tags($tag); + $image->set_tags(Tag::explode($tag)); } } else { foreach($images as $image) { - $image->set_tags($tag . " " . $image->get_tag_list()); + $image->set_tags(Tag::explode($tag . " " . $image->get_tag_list())); } }