From fea7d0d0ac57ce46a8212b9e2a24be9794ae58f3 Mon Sep 17 00:00:00 2001 From: Simon DELAGE Date: Sun, 14 Jun 2015 03:06:52 +0200 Subject: [PATCH] Major change (from helper to event) --- action.php | 66 ++++++++++++++++++++++++++++++++++---------- conf/default.php | 2 +- conf/metadata.php | 2 +- helper.php | 58 -------------------------------------- lang/en/lang.php | 2 +- lang/en/settings.php | 6 ++-- lang/fr/lang.php | 2 +- lang/fr/settings.php | 2 +- plugin.info.txt | 2 +- 9 files changed, 61 insertions(+), 81 deletions(-) delete mode 100644 helper.php diff --git a/action.php b/action.php index a3e8995..72f7380 100644 --- a/action.php +++ b/action.php @@ -17,6 +17,7 @@ class action_plugin_tagalerts extends DokuWiki_Action_Plugin{ function register(&$controller) { $controller->register_hook('TPL_METAHEADER_OUTPUT', 'AFTER', $this, 'init', array()); $controller->register_hook('TPL_TOC_RENDER', 'AFTER', $this, 'alert', array()); + $controller->register_hook('PLUGIN_TAG_LINK', 'AFTER', $this, 'link', array()); $controller->register_hook('CONFMANAGER_CONFIGFILES_REGISTER', 'BEFORE', $this, 'addConfigFile', array()); } @@ -39,7 +40,7 @@ class action_plugin_tagalerts extends DokuWiki_Action_Plugin{ $this->pagetags = explode(',', $meta['content']); } } - // Load special messages from ...tagalerts/conf/tagalerts.conf to global conf (so they can be used even by the helper) + // Load special messages from ...tagalerts/conf/tagalerts.conf to global conf $specAlertsFile = dirname(__FILE__).'/conf/tagalerts.conf'; if (@file_exists($specAlertsFile)) { $conf['plugin']['tagalerts']['specAlerts'] = confToHash($specAlertsFile); @@ -47,25 +48,27 @@ class action_plugin_tagalerts extends DokuWiki_Action_Plugin{ } function alert(&$event, $param) { - global $ID; global $conf; + global $ACT; - // Get an array of notification triggers from 'notify' option (make sure the list is well formated: no blanks between triggers and no '_' in triggers) - $errorTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('error')))); - $infoTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('info')))); - $successTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('success')))); - $notifyTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('notify')))); - // Get matches between page tags and triggers (don't preserve keys) - $tagalerts = array(); - $tagalerts['error'] = array_values((array_intersect($this->pagetags, $errorTriggers))); - $tagalerts['info'] = array_values((array_intersect($this->pagetags, $infoTriggers))); - $tagalerts['success'] = array_values((array_intersect($this->pagetags, $successTriggers))); - $tagalerts['notify'] = array_values((array_intersect($this->pagetags, $notifyTriggers))); - if ($this->getConf('inline') != '1') { + if (($this->getConf('action') == "messages") & ($ACT == "show")) { + // Get an array of notification triggers from 'notify' option (make sure the list is well formated: no blanks between triggers and no '_' in triggers) + $errorTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('error')))); + $infoTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('info')))); + $successTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('success')))); + $notifyTriggers = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('notify')))); + // Get matches between page tags and triggers (don't preserve keys) + $tagalerts = array(); + $tagalerts['error'] = array_values((array_intersect($this->pagetags, $errorTriggers))); + $tagalerts['info'] = array_values((array_intersect($this->pagetags, $infoTriggers))); + $tagalerts['success'] = array_values((array_intersect($this->pagetags, $successTriggers))); + $tagalerts['notify'] = array_values((array_intersect($this->pagetags, $notifyTriggers))); foreach($tagalerts as $type=>$tag) { if (isset($tag[0])) { + // Alert from conf file if (isset($conf['plugin']['tagalerts']['specAlerts'][$tag[0]])) { $msg = $conf['plugin']['tagalerts']['specAlerts'][$tag[0]]; + // Or from localized $conf } else { $msg = $this->getLang('tagalerts').$tag[0]."."; } @@ -75,6 +78,41 @@ class action_plugin_tagalerts extends DokuWiki_Action_Plugin{ } } + function link(&$event) { + global $conf; + global $ACT; + + if (($this->getConf('action') == "inline") & ($ACT == "show")) { + $href = $event->data['href']; + $class = $event->data['class']; + $tooltip = $event->data['tooltip']; + $title = $event->data['title']; + // CLASS + // Get an array of notification triggers from 'notify' option (make sure the list is well formated: no blanks between triggers and no '_' in triggers) + $triggers = array(); + $triggers['error'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('error')))); + $triggers['info'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('info')))); + $triggers['success'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('success')))); + $triggers['notify'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('notify')))); + foreach($triggers as $type=>$val) { + if (in_array($title, $val)) { + $class = $class.' tag'.$type; + } + } + // TOOLTIP + if (isset($conf['plugin']['tagalerts']['specAlerts'][$title])) { + $tooltip = $conf['plugin']['tagalerts']['specAlerts'][$title]." (".$tooltip.")"; + } + // RESULT + $event->data = array( + 'href' => $href, + 'class' => $class, + 'tooltip' => $tooltip, + 'title' => $title + ); + } + } + // Register the plugin conf file in ConfManager Plugin public function addConfigFile(Doku_Event $event, $params) { if (class_exists('ConfigManagerTwoLine')) { diff --git a/conf/default.php b/conf/default.php index e7ab17c..8102f4f 100644 --- a/conf/default.php +++ b/conf/default.php @@ -6,7 +6,7 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$conf['inline'] = '0'; +$meta['action'] = 'inline'; $conf['error'] = ''; //comma separated list of tags for wich a "tag error" should be thrown $conf['info'] = ''; //comma separated list of tags for wich a "tag info" should be thrown $conf['success'] = ''; //comma separated list of tags for wich a "tag success" should be thrown diff --git a/conf/metadata.php b/conf/metadata.php index b103b79..eaa7deb 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -6,7 +6,7 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$meta['inline'] = array('multichoice','_choices'=>array('0','1')); +$meta['action'] = array('multichoice','_choices'=>array('messages','inline')); $meta['error'] = array('string'); $meta['info'] = array('string'); $meta['success'] = array('string'); diff --git a/helper.php b/helper.php deleted file mode 100644 index 936e197..0000000 --- a/helper.php +++ /dev/null @@ -1,58 +0,0 @@ - - * @license: CC Attribution-Share Alike 3.0 Unported - */ - -// must be run within Dokuwiki -if (!defined('DOKU_INC')) die(); - -if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); -if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); - -/** - * Helper part of the tag plugin, allows to query and print tags - */ -class helper_plugin_tagalerts extends DokuWiki_Plugin { - - /** - * Returns the links for given tags - * - * @param array $tags an array of tags - * @return string HTML link tags - */ - function extraClass($tag, $class) { - global $ID; - global $conf; - - if ($this->getConf('inline')) { - // Get an array of notification triggers from 'notify' option (make sure the list is well formated: no blanks between triggers and no '_' in triggers) - $triggers = array(); - $triggers['error'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('error')))); - $triggers['info'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('info')))); - $triggers['success'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('success')))); - $triggers['notify'] = explode(',',str_replace('_', ' ', str_replace(', ', ',', $this->getConf('notify')))); - foreach($triggers as $type=>$val) { - if (in_array($tag, $val)) { - $class = $class.' tag'.$type; - } - } - return $class; - } - } - - function tooltip($tag, $tooltip) { - global $ID; - global $conf; - - if (isset($conf['plugin']['tagalerts']['specAlerts'][$tag])) { - $tooltip = $conf['plugin']['tagalerts']['specAlerts'][$tag]." (".$tooltip.")"; - } - return $tooltip; - } - -} -// vim:ts=4:sw=4:et: diff --git a/lang/en/lang.php b/lang/en/lang.php index 98e9fb9..8f881b2 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -6,6 +6,6 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$lang['description'] = 'This plugin is made to show alerts when some specified tags are detected. Use this file to define tags\' specific messages (one tag and one message per line).'; +$lang['confdescription'] = 'This plugin is made to show alerts when some specified tags are detected. Use this file to define tags\' specific messages (one tag and one message per line).'; $lang['tagalerts'] = 'This page has been marked as '; $lang['tag_required'] = 'The Tag plugin is required for Tag Alerts to be of any use (https://www.dokuwiki.org/plugin:tag).'; diff --git a/lang/en/settings.php b/lang/en/settings.php index 4397ec6..463940e 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -6,9 +6,9 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$lang['inline'] = 'Tagalerts type'; -$lang['inline_o_0'] = 'messages'; -$lang['inline_o_1'] = 'inline'; +$lang['action'] = 'Tagalerts type [default: inline]'; +$lang['action_o_messages'] = 'messages'; +$lang['action_o_inline'] = 'inline'; $lang['error'] = 'Comma separated list of tags that will trigger an alert based on system error message.'; $lang['info'] = 'Comma separated list of tags that will trigger an alert based on system information message.'; $lang['success'] = 'Comma separated list of tags that will trigger an alert based on system success message.'; diff --git a/lang/fr/lang.php b/lang/fr/lang.php index 4a62ee6..b5c61c3 100644 --- a/lang/fr/lang.php +++ b/lang/fr/lang.php @@ -6,6 +6,6 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$lang['description'] = 'Ce plugin est fait pour afficher des alertes lorsque certains tags définis sont détectés. Utilisez ce fichier pour définir des message spécifiques pour certains tags (un tag et un message par ligne).'; +$lang['confdescription'] = 'Ce plugin permet d\'afficher des alertes lorsque certains tags définis sont détectés. Utilisez ce fichier pour définir des message spécifiques pour certains tags (un tag et un message par ligne).'; $lang['tagalerts'] = 'Cette page a été marquée comme '; $lang['tag_required'] = 'Le plugin Tag est requis pour que Tag Alerts soit d\'une quelconque utilité (https://www.dokuwiki.org/plugin:tag).'; diff --git a/lang/fr/settings.php b/lang/fr/settings.php index 2e8ae3a..47d722a 100644 --- a/lang/fr/settings.php +++ b/lang/fr/settings.php @@ -6,7 +6,7 @@ * @license: CC Attribution-Share Alike 3.0 Unported */ -$lang['inline'] = 'Type d\'alertes [défaut: messages]'; +$lang['action'] = 'Type d\'alertes [défaut: inline]'; $lang['error'] = 'Liste de tags séparés par une virgule qui déclencheront une alerte basée sur les messages système d\'erreur.'; $lang['info'] = 'Liste de tags séparés par une virgule qui déclencheront une alerte basée sur les messages système d\'information.'; $lang['success'] = 'Liste de tags séparés par une virgule qui déclencheront une alerte basée sur les messages système de succès.'; diff --git a/plugin.info.txt b/plugin.info.txt index 715bf3b..58af621 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base tagalerts author Simon Delage email simon.geekitude@gmail.com -date 2015-06-13 +date 2015-06-14 name Tag Alerts desc Throw alerts when some tags are detected (based on Dokuwiki system messages) or just styling tag list links url https://www.dokuwiki.org/plugin:tagalerts