Major change (from helper to event)
This commit is contained in:
parent
3b2d6c9238
commit
fea7d0d0ac
9 changed files with 61 additions and 81 deletions
66
action.php
66
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')) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||
*/
|
||||
|
||||
$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
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||
*/
|
||||
|
||||
$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');
|
||||
|
|
58
helper.php
58
helper.php
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Tag Alerts plugin helper for tag plugin
|
||||
*
|
||||
* @author: Simon Delage <simon.geekitude@gmail.com>
|
||||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||
*/
|
||||
|
||||
// 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:
|
|
@ -6,6 +6,6 @@
|
|||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||
*/
|
||||
|
||||
$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).';
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||
*/
|
||||
|
||||
$lang['inline'] = 'Tagalerts type';
|
||||
$lang['inline_o_0'] = 'messages';
|
||||
$lang['inline_o_1'] = 'inline';
|
||||
$lang['action'] = 'Tagalerts type [default: <code>inline</code>]';
|
||||
$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.';
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||
*/
|
||||
|
||||
$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).';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
|
||||
*/
|
||||
|
||||
$lang['inline'] = 'Type d\'alertes [défaut: <code>messages</code>]';
|
||||
$lang['action'] = 'Type d\'alertes [défaut: <code>inline</code>]';
|
||||
$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.';
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue