move tag sanitization, alias checking & tag parsing to TagSetEvent

This commit is contained in:
Daku 2015-10-08 18:22:20 +01:00
parent 23b9d7d8da
commit 6ff80ab2c8
2 changed files with 24 additions and 12 deletions

View File

@ -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;

View File

@ -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);
}
}
}
}