From b7778b54c9a422b94fc0934932d081600a8ccd92 Mon Sep 17 00:00:00 2001 From: Daku Date: Wed, 29 Jan 2014 07:18:49 +0000 Subject: [PATCH] add TagTermParseEvent for parsing tags during tagging --- core/imageboard.pack.php | 12 +++--------- ext/pools/main.php | 10 ++++++++++ ext/tag_edit/main.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 6d5cd1cd..a65e9bc1 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -479,15 +479,9 @@ class Image { $this->delete_tags_from_image(); // insert each new tags foreach($tags as $tag) { - if(preg_match("/^source[=|:](.*)$/i", $tag, $matches)) { - $this->set_source($matches[1]); - continue; - } - if(preg_match("/^pool[=|:](.*)$/i", $tag, $matches)) { - if(class_exists("Pools")) { - $pls = new Pools(); - $pls->add_post_from_tag($matches[1], $this->id); - } + $ttpe = new TagTermParseEvent($tag, $this->id); + send_event($ttpe); + if($ttpe->is_metatag()) { continue; } diff --git a/ext/pools/main.php b/ext/pools/main.php index 6bcd8760..8ef17423 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -315,6 +315,16 @@ class Pools extends Extension { } } + public function onTagTermParse(TagTermParseEvent $event) { + $matches = array(); + + if(preg_match("/^pool[=|:](.*)$/i", $event->term, $matches)) { + $this->add_post_from_tag($matches[1], $event->id); + } + + if(!empty($matches)) $event->metatag = true; + } + public function add_post_from_tag(/*str*/ $poolTag, /*int*/ $imageID){ $poolTag = str_replace("_", " ", $poolTag); //First check if pool tag is a title diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 0f1655a1..2d0fd8b9 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -72,6 +72,25 @@ class LockSetEvent extends Event { } } +/* + * TagTermParseEvent: + * Signal that a tag term needs parsing + */ +class TagTermParseEvent extends Event { + var $term = null; + var $id = null; + var $metatag = false; + + public function TagTermParseEvent($term, $id) { + $this->term = $term; + $this->id = $id; + } + + public function is_metatag() { + return $this->metatag; + } +} + class TagEdit extends Extension { public function onPageRequest(PageRequestEvent $event) { global $user, $page; @@ -169,6 +188,15 @@ class TagEdit extends Extension { $event->add_part($this->theme->get_lock_editor_html($event->image), 42); } + public function onTagTermParse(TagTermParseEvent $event) { + $matches = array(); + + if(preg_match("/^source[=|:](.*)$/i", $event->term, $matches)) { + send_event(new SourceSetEvent(Image::by_id($event->id), $matches[1])); + } + + if(!empty($matches)) $event->metatag = true; + } private function can_tag(Image $image) { global $config, $user;