First release

This commit is contained in:
Simon DELAGE 2015-06-13 01:49:18 +02:00
parent 81073ada2d
commit b1d0adcff4
14 changed files with 285 additions and 0 deletions

85
action.php Normal file
View file

@ -0,0 +1,85 @@
<?php
/**
* Tag Alerts plugin main file
*
* @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_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 '<div class="tag'.$type.'">'.hsc($msg).'</div>';
}
}
}
}
// 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;
}
}
}

13
conf/default.php Normal file
View file

@ -0,0 +1,13 @@
<?php
/**
* Configuration defaults file for Tag Alert plugin
*
* @author: Simon Delage <simon.geekitude@gmail.com>
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$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

13
conf/metadata.php Normal file
View file

@ -0,0 +1,13 @@
<?php
/**
* Configuration metadata file for Tag Alert plugin
*
* @author: Simon Delage <simon.geekitude@gmail.com>
* @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['error'] = array('string');
$meta['info'] = array('string');
$meta['success'] = array('string');
$meta['notify'] = array('string');

6
conf/tagalerts.conf Normal file
View file

@ -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.

58
helper.php Normal file
View file

@ -0,0 +1,58 @@
<?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:

BIN
images/error.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
images/info.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/notify.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/success.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/tag.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

10
lang/en/lang.php Normal file
View file

@ -0,0 +1,10 @@
<?php
/**
* English language file for Tag Alerts plugin
*
* @author: Simon Delage <simon.geekitude@gmail.com>
* @license: CC Attribution-Share Alike 3.0 Unported <http://creativecommons.org/licenses/by-sa/3.0/>
*/
$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).';

15
lang/en/settings.php Normal file
View file

@ -0,0 +1,15 @@
<?php
/**
* English settings file for Tag Alerts plugin
*
* @author: Simon Delage <simon.geekitude@gmail.com>
* @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['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.';

7
plugin.info.txt Normal file
View file

@ -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

78
style.css Normal file
View file

@ -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);
}