move tag sanitization, alias checking & tag parsing to TagSetEvent
This commit is contained in:
parent
23b9d7d8da
commit
6ff80ab2c8
@ -576,9 +576,6 @@ class Image {
|
|||||||
assert('is_array($tags) && count($tags) > 0', var_export($tags, true));
|
assert('is_array($tags) && count($tags) > 0', var_export($tags, true));
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$tags = array_map(array('Tag', 'sanitise'), $tags);
|
|
||||||
$tags = Tag::resolve_aliases($tags);
|
|
||||||
|
|
||||||
if(count($tags) <= 0) {
|
if(count($tags) <= 0) {
|
||||||
throw new SCoreException('Tried to set zero tags');
|
throw new SCoreException('Tried to set zero tags');
|
||||||
}
|
}
|
||||||
@ -588,12 +585,6 @@ class Image {
|
|||||||
$this->delete_tags_from_image();
|
$this->delete_tags_from_image();
|
||||||
// insert each new tags
|
// insert each new tags
|
||||||
foreach($tags as $tag) {
|
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){
|
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");
|
flash_message("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n");
|
||||||
continue;
|
continue;
|
||||||
|
@ -95,11 +95,32 @@ class SourceSetEvent extends Event {
|
|||||||
class TagSetEvent extends Event {
|
class TagSetEvent extends Event {
|
||||||
/** @var \Image */
|
/** @var \Image */
|
||||||
public $image;
|
public $image;
|
||||||
var $tags;
|
public $tags;
|
||||||
|
public $metatags;
|
||||||
|
|
||||||
public function __construct(Image $image, $tags) {
|
public function __construct(Image $image, $tags) {
|
||||||
$this->image = $image;
|
$this->image = $image;
|
||||||
$this->tags = Tag::explode($tags);
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user