From 6ff80ab2c8985e5f9bdaaeed5ce8fd694e3638c0 Mon Sep 17 00:00:00 2001 From: Daku Date: Thu, 8 Oct 2015 18:22:20 +0100 Subject: [PATCH] move tag sanitization, alias checking & tag parsing to TagSetEvent --- core/imageboard.pack.php | 9 --------- ext/tag_edit/main.php | 27 ++++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index dc92b145..9d24d881 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -576,9 +576,6 @@ class Image { assert('is_array($tags) && count($tags) > 0', var_export($tags, true)); global $database; - $tags = array_map(array('Tag', 'sanitise'), $tags); - $tags = Tag::resolve_aliases($tags); - if(count($tags) <= 0) { throw new SCoreException('Tried to set zero tags'); } @@ -588,12 +585,6 @@ class Image { $this->delete_tags_from_image(); // insert each new tags foreach($tags as $tag) { - $ttpe = new TagTermParseEvent($tag, $this->id); - send_event($ttpe); - if($ttpe->is_metatag()) { - continue; - } - if(mb_strlen($tag, 'UTF-8') > 255){ flash_message("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n"); continue; diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 1dfa025e..09d86ba1 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -95,11 +95,32 @@ class SourceSetEvent extends Event { class TagSetEvent extends Event { /** @var \Image */ public $image; - var $tags; + public $tags; + public $metatags; public function __construct(Image $image, $tags) { - $this->image = $image; - $this->tags = Tag::explode($tags); + $this->image = $image; + + $this->tags = array(); + $this->metatags = array(); + + //tags need to be sanitised, alias checked & have metatags removed before being passed to onTagSet + $tag_array = Tag::explode($tags); + $tag_array = array_map(array('Tag', 'sanitise'), $tag_array); + $tag_array = Tag::resolve_aliases($tag_array); + + foreach($tag_array as $tag) { + //TODO: Parsing metatags BEFORE set_tags is sent seems like a bad idea? + $ttpe = new TagTermParseEvent($tag, $image->id); + send_event($ttpe); + + //seperate tags from metatags + if(!$ttpe->is_metatag()) { + array_push($this->tags, $tag); + }else{ + array_push($this->metatags, $tag); + } + } } }