Merge pull request #523 from DakuTree/patch-tagevent

Move tag sanitization, alias resolving & tag parsing from set_tags > TagSetEvent
This commit is contained in:
Shish
2015-10-26 19:22:08 +00:00
5 changed files with 68 additions and 31 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;
@@ -632,6 +623,19 @@ class Image {
}
}
/**
* Send list of metatags to be parsed.
*
* @param [] $metatags
* @param int $image_id
*/
public function parse_metatags($metatags, $image_id) {
foreach($metatags as $tag) {
$ttpe = new TagTermParseEvent($tag, $image_id, TRUE);
send_event($ttpe);
}
}
/**
* Delete this image from the database and disk
*/
@@ -1156,6 +1160,8 @@ class Tag {
$tag_array = array("tagme");
}
$tag_array = array_iunique($tag_array); //remove duplicate tags
sort($tag_array);
return $tag_array;
@@ -1254,7 +1260,7 @@ class Tag {
$i = 0;
$tag_count = count($tags);
while($i<$tag_count) {
$aliases = explode(' ', Tag::resolve_alias($tags[$i]));
$aliases = Tag::explode(Tag::resolve_alias($tags[$i]), FALSE);
foreach($aliases as $alias){
if(!in_array($alias, $new)){
if($tags[$i] == $alias){