diff --git a/action.php b/action.php new file mode 100644 index 0000000..5c40d1c --- /dev/null +++ b/action.php @@ -0,0 +1,85 @@ + + * @license: CC Attribution-Share Alike 3.0 Unported + */ + +// must be run within Dokuwiki +if (!defined('DOKU_INC')) die(); +if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); + +require_once (DOKU_PLUGIN . 'action.php'); + +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('CONFMANAGER_CONFIGFILES_REGISTER', 'BEFORE', $this, 'addConfigFile', array()); + } + + function init(&$event, $param) { + global $ID; + global $conf; + + $tags = plugin_load('helper', 'tag'); + if(is_null($tags)) { + msg($this->getLang('tag_required'), -1); + return false; + } + // Fetch tags for the page; stop proceeding when no tags specified + $tags = p_get_metadata($ID, 'subject', METADATA_DONT_RENDER); + if(is_null($tags)) true; + + foreach($event->data['meta'] as &$meta) { + if($meta['name'] == 'keywords') { + // Get an array of page's tags + $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) + $specAlertsFile = dirname(__FILE__).'/conf/tagalerts.conf'; + if (@file_exists($specAlertsFile)) { + $conf['plugin']['tagalerts']['specAlerts'] = confToHash($specAlertsFile); + } + } + + function alert(&$event, $param) { + global $ID; + global $conf; + + // 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') { + foreach($tagalerts as $type=>$tag) { + if (isset($tag[0])) { + if (isset($conf['plugin']['tagalerts']['specAlerts'][$tag[0]])) { + $msg = $conf['plugin']['tagalerts']['specAlerts'][$tag[0]]; + } else { + $msg = $this->getLang('tagalerts').$tag[0]."."; + } + echo '
'.hsc($msg).'
'; + } + } + } + } + + // Register the plugin conf file in ConfManager Plugin + public function addConfigFile(Doku_Event $event, $params) { + if (class_exists('ConfigManagerTwoLine')) { + $config = new ConfigManagerTwoLine('Tag Alerts', 'Description of my plugin', DOKU_PLUGIN . 'tagalerts/conf/tagalerts.conf'); + $event->data[] = $config; + } + } +} diff --git a/conf/default.php b/conf/default.php new file mode 100644 index 0000000..eae1944 --- /dev/null +++ b/conf/default.php @@ -0,0 +1,13 @@ + + * @license: CC Attribution-Share Alike 3.0 Unported + */ + +$conf['inline'] = '1'; +$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 +$conf['notify'] = ''; //comma separated list of tags for wich a "tag notification" should be thrown diff --git a/conf/metadata.php b/conf/metadata.php new file mode 100644 index 0000000..b103b79 --- /dev/null +++ b/conf/metadata.php @@ -0,0 +1,13 @@ + + * @license: CC Attribution-Share Alike 3.0 Unported + */ + +$meta['inline'] = array('multichoice','_choices'=>array('0','1')); +$meta['error'] = array('string'); +$meta['info'] = array('string'); +$meta['success'] = array('string'); +$meta['notify'] = array('string'); diff --git a/conf/tagalerts.conf b/conf/tagalerts.conf new file mode 100644 index 0000000..b39393d --- /dev/null +++ b/conf/tagalerts.conf @@ -0,0 +1,6 @@ +# Tagalerts config file to add specific messages depending on tag +# Add a tag (spaces replaced by _) and the corresponding message on same line (one tag and one message per line +# This file can be managed with Confmanager plugin (https://www.dokuwiki.org/plugin:confmanager) + +# Sample (remove the #): +#archive This page is marked as archived. It's content might be outdated. diff --git a/helper.php b/helper.php new file mode 100644 index 0000000..936e197 --- /dev/null +++ b/helper.php @@ -0,0 +1,58 @@ + + * @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/images/error.png b/images/error.png new file mode 100644 index 0000000..6929f52 Binary files /dev/null and b/images/error.png differ diff --git a/images/info.png b/images/info.png new file mode 100644 index 0000000..f3b48a2 Binary files /dev/null and b/images/info.png differ diff --git a/images/notify.png b/images/notify.png new file mode 100644 index 0000000..2503bbb Binary files /dev/null and b/images/notify.png differ diff --git a/images/success.png b/images/success.png new file mode 100644 index 0000000..90e066f Binary files /dev/null and b/images/success.png differ diff --git a/images/tag.png b/images/tag.png new file mode 100644 index 0000000..ead7e4b Binary files /dev/null and b/images/tag.png differ diff --git a/lang/en/lang.php b/lang/en/lang.php new file mode 100644 index 0000000..a77e43e --- /dev/null +++ b/lang/en/lang.php @@ -0,0 +1,10 @@ + + * @license: CC Attribution-Share Alike 3.0 Unported + */ + +$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 new file mode 100644 index 0000000..4397ec6 --- /dev/null +++ b/lang/en/settings.php @@ -0,0 +1,15 @@ + + * @license: CC Attribution-Share Alike 3.0 Unported + */ + +$lang['inline'] = 'Tagalerts type'; +$lang['inline_o_0'] = 'messages'; +$lang['inline_o_1'] = '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.'; +$lang['notify'] = 'Comma separated list of tags that will trigger an alert based on system notification message.'; diff --git a/plugin.info.txt b/plugin.info.txt new file mode 100644 index 0000000..715bf3b --- /dev/null +++ b/plugin.info.txt @@ -0,0 +1,7 @@ +base tagalerts +author Simon Delage +email simon.geekitude@gmail.com +date 2015-06-13 +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 diff --git a/style.css b/style.css new file mode 100644 index 0000000..6175f23 --- /dev/null +++ b/style.css @@ -0,0 +1,78 @@ +.dokuwiki .tagerror, +.dokuwiki .taginfo, +.dokuwiki .tagsuccess, +.dokuwiki .tagnotify { + border: 1px solid; + background-repeat: no-repeat; + font-size: 90%; + border-radius: 5px; +} + +.dokuwiki .tagerror { + background-color: #fcc !important; + border-color: #ebb; +} + +.dokuwiki .taginfo { + background-color: #ccf !important; + border-color: #bbe; +} + +.dokuwiki .tagsuccess { + background-color: #cfc !important; + border-color: #beb; +} + +.dokuwiki .tagnotify { + background-color: #ffc !important; + border-color: #eeb; +} + +.dokuwiki div.tagerror, +.dokuwiki div.taginfo, +.dokuwiki div.tagsuccess, +.dokuwiki div.tagnotify { + padding: 0 .5em 0 3em; + margin: -1.4em auto 1.8em auto; + background-position: 8px 50%; +} + +.dokuwiki div.tagerror { + background-image: url(images/error.png); +} + +.dokuwiki div.taginfo { + background-image: url(images/info.png); +} + +.dokuwiki div.tagsuccess { + background-image: url(images/success.png); +} + +.dokuwiki div.tagnotify { + background-image: url(images/notify.png); +} + +.dokuwiki a.tagerror, +.dokuwiki a.taginfo, +.dokuwiki a.tagsuccess, +.dokuwiki a.tagnotify { + padding: 0 3px 0 19px; + background-position: 1px 50%; +} + +.dokuwiki a.tagerror { + background-image: url(../../images/error.png); +} + +.dokuwiki a.taginfo { + background-image: url(../../images/info.png); +} + +.dokuwiki a.tagsuccess { + background-image: url(../../images/success.png); +} + +.dokuwiki a.tagnotify { + background-image: url(../../images/notify.png); +}