From b1d0adcff491177d59ca6c697dcb5da114b21e6d Mon Sep 17 00:00:00 2001 From: Simon DELAGE Date: Sat, 13 Jun 2015 01:49:18 +0200 Subject: [PATCH] First release --- action.php | 85 +++++++++++++++++++++++++++++++++++++++++++ conf/default.php | 13 +++++++ conf/metadata.php | 13 +++++++ conf/tagalerts.conf | 6 +++ helper.php | 58 +++++++++++++++++++++++++++++ images/error.png | Bin 0 -> 1166 bytes images/info.png | Bin 0 -> 1191 bytes images/notify.png | Bin 0 -> 1253 bytes images/success.png | Bin 0 -> 1211 bytes images/tag.png | Bin 0 -> 577 bytes lang/en/lang.php | 10 +++++ lang/en/settings.php | 15 ++++++++ plugin.info.txt | 7 ++++ style.css | 78 +++++++++++++++++++++++++++++++++++++++ 14 files changed, 285 insertions(+) create mode 100644 action.php create mode 100644 conf/default.php create mode 100644 conf/metadata.php create mode 100644 conf/tagalerts.conf create mode 100644 helper.php create mode 100644 images/error.png create mode 100644 images/info.png create mode 100644 images/notify.png create mode 100644 images/success.png create mode 100644 images/tag.png create mode 100644 lang/en/lang.php create mode 100644 lang/en/settings.php create mode 100644 plugin.info.txt create mode 100644 style.css 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 0000000000000000000000000000000000000000..6929f52d87144e7190709e157ff7840adca18d92 GIT binary patch literal 1166 zcmV;91abR`P)wWPGT*%^fb;fT5e>EM{+#0_ww>z8(y9H**Rav8yYW>q1 zYio+lwY3q51OMO;so0eHAMyiRJvK??2}} zJLfsi`8<2}1)i+Ev9Ymca&j`eTrN&ZN@ADG#k#KF0kHE)$>QO_`ebh!G4EiaY9ewG z5!|1jSk`r-%iQ14pdCGW6w8+{hoUGvI5^1Lwrx{P(>%h=b&o5cMmO^Z-}V!6*DRL2 zBGOkUswo*uloih{Y41IU3l}e{jakk=Zmr6pwd>d09S(;`Pfr(ax0`~&;0r`_6TtV6 zC5SY<ZQml2KRB}0$>EY0IVL8C zkAL+gGc$)mAucS)XDOvDDk_pvN?A})Aeot%nS;Tg)HIEwB#LEPV96khAg%i=nG)vc zFaV%3D+SxrR-$@O4bJxWBQ7ouMo%w%J|7IjKyh&~48wre>*Yu!0-w*PG&VNU1Bxp3 z{oJfwO8nD_>QV=+8#h4KgEr02!<-mLWOM{YD_wA^HthcNGi0TwVa>XAsHmtA0EFM~ z7p0}8Y#0Ur2t`qlmzO6J6BEr~Ft|mrOzVr8;R{gR$&e=9Cou_ed)~vcve!W-L0W{W z%oOY{d311aS~>qkaL1b`pZx(%tJem=C9+JJNGT-r>4M?k+5Yep4SMGYh$5zo7(j3>})G1Cr616S7l|TP!t8K zs&aL8HMO_5-vQte0C1_Q$WKxpbFRsAB&=SG@c1tXk6i&X!=91~drB&94*!U&XHU-( zQNZ){Xo0Tlb$xw(GB-C@eP}BA(4j+IUtfP)2(gKoCl&_${HvS&lIXCW=zjL8wHsk~ zCV&|T-@b+4&kx}CbicUv$Hc?US6&P;6NZ?c64;y1+Wpo)qk1Y zcUw255z!8kR81sZLhyjyc4d*z2+^Wx+P>D-Ryi~@#Ldmkq3F-?KWaOG gVE|nKRy=z6H;|1oiFHz!{Qv*}07*qoM6N<$f|TJKmH+?% literal 0 HcmV?d00001 diff --git a/images/info.png b/images/info.png new file mode 100644 index 0000000000000000000000000000000000000000..f3b48a2e49885ffc918fac958cb4fef0fee22cac GIT binary patch literal 1191 zcmV;Y1X%ltP)mD+p+>T1ARhk`Bx;PKbyU(=LJK=PJNbbR-q%}OTal5G0Zr5B!i5V|QBk3B&JPjMzK03e<_;AtBUPqlbuM?S zt)(kHi;A+`3ksJlTyQpi99OPfwi#>crZ+5wTC@6Dhs)(+xw*N_@As>CJYJ}jx&>h9 zp#Vak|=RD{EClpv8vVB*F!p3h&4^mNZ$tps4}>FE(= zWo33D#D9`#TbeGfu##3|X6ZUW9`Iq^Elzgn&{? z1_A-iFbsr3A$wC(Q_^m?M*&115a3Ge%uXZ!6Palk82c60tOaf=l&{Z3d4V5{F)+sN zgWep8XuZ9?v~Alq1%T@6>YS%fpO(6=H#5eX?-Q`3tS-#*;+LsE!8r$45>g3#IWUfs z1LK&PH8C>s0{}n~AruNC{!N^fmX;!sNT9g5m<+=}I2^V$G&JxBNH%@gf46IJg5Hf? zq_;jfPy3DzQ1nPY5fLdODz1KqQc_arSjTZ9A~FnvUJL|CN-0Z9N~Dxh1_A+j?>WWe zajEM%&5>x9X@L|$5MT)tN=hh27{2}+?j{BD^25l^4`a{nUFbh|4rys==Qc`gx1y7r3HgQba!{dX8U{VqtU3=(9pmE9Mxcn*qPx8EMM#b zlmY~yazhrLeEcz_I(6)?Tm#NI^44$03*qh9vwIf?2M5XFaKLW2!{hOwudk1VLLo>g z=f8e*bd&)&&kElBY6VPjc1v-tKYNi2-wjVdZ~-YLhzk%Y5D05mEyFEtqWz3QB_rCpKEBECNxchuIp4&Q=?+Bm;qq5HuQ1j&t!_%zwW#^Gj`L!#;5#PoSp(3 zBWN1KVy_#Up3BCxnMBWt-Wgv`(W|CuHdj|y+lPjR=0|oo9ME;0>g($%7K`0sjI9GO zIltiRU;eZTWHseHotarwm;>*^1po-sMiOVv{fP15u^WtO`-i&TJ~?NCPN(xwM@L7p zva-?%fNE=Nd0SiC9{|w2`MrA1!4bcq@p8x6)-J`r8V{}`_TxC)>Xz|wzT{sm#v4LM1ncs~FD002ovPDHLk FV1f~o7X$zR literal 0 HcmV?d00001 diff --git a/images/notify.png b/images/notify.png new file mode 100644 index 0000000000000000000000000000000000000000..2503bbb25c57fb9eda7fb1091a8ae9279fb6a615 GIT binary patch literal 1253 zcmVyGspj@b7s!- z{N{INo(H&h)+>slI~)#DRh81y(@9lTnxK|2AS?lZTk(!zcfiavo(TU~HJr7;icM;Ksy8*=5VR_wIOh%)4Kr!KQ*|5-| zV4ZDw{edHv`CZ-J($Da`#r!gB^4;@CjW$zL-Y* zg_N8aPeW()Cs5 z;CSF|8V^*_uV3fT@B6dqOk+O%*_clwhw`aoM<$gow2{SPq2oUtyJcdM$K&Bd#5GOh zoOAB+cz7fdAtIuhni|d+BLJ_6Yut&mxe=acO`3^FP)Gk61Cu-s!D~ZM5=2b5Tkx1F zAT80v+D#2`Wjc^ECl}@A6^^NgCF?z7Fl}?PRf7AW0Hz zHXGX7+L+tz2Iu_WukY#UVE{Ts`{QN!e)Oq^0<-1i@v(svC1p0q6p*AU5Fy~GzY9Ff z;mV9hLGBC;^hLhm9Xknu0i%6`_&X3mQmPEuVuduJk2STA?QLmkDJUr^;dZ-S z002pnAc`Vw+qR9iZ{HqdjLidZQ2>C>FJA&eMOPxpQZTF*YyO z{0_i>vv=bxF*-?`bsZa{28pEOHwL`<&c1;QQ=Y8=@Bx5x0Nw>KIJL(=RY_2&M^y&Y P00000NkvXXu0mjf?pi`2 literal 0 HcmV?d00001 diff --git a/images/success.png b/images/success.png new file mode 100644 index 0000000000000000000000000000000000000000..90e066f40970d4d53498e3d59f9c88bca04dbe0c GIT binary patch literal 1211 zcmV;s1VsCZP)xv|XWnm;mLWr78Ulh89%d%`>Zh7{j`SWmYpb6g$cH(YEgO<@i68ZW02$rr! zo+}TAVZby^>GSy%P16tv1gteRH7Tprx&y$D2Lz;{Z!8dno}&EuXc=fm%FvOKIt-~J zV`LzNfDqzOo{80KRx3?SOGGieNB^SS*Ip(o$-ghEOPEsjjZpA8=CM_}Iv& zT}Qe1;;Y=#`ZCq-Pk8;#74AN>jmeF4=%jRU1|ka?Oa5M!@;A+eshvarKsyVlgT81cOZ3L=NRE|I0Ilr(RChaxp@kn ztf{b>K>u(bsxQ2aZ*O12p|AJh`oJX!Q(!@P5kk-UuyxBew6(R-;c&oewZi3cp}DzP z1Ofp_DepafXJ@AXaM9v^BDd$3me}xcmMdqWXF2+kT^P;`qP_PF28I$)AYfN4SUIx{ zoH~TBzQ3j&dZ*Sod-iOjxVTsu%T`52g-{d)7K??Im6c{~ZS5d{fTg!#@b1J=Zg*>U zyxcQxoPEh7epnS7(wPz16&ngCK90HWMQFcy26dk`3_A-PFWzZM_BS*%ED41|vY?fb1&dC-kY-COtYqBYSH91#X*eEng|dW7*62xOJCwj zN7s)+5xctI?>#YAf=;LNKr|Xnty{Ow34oh7Z`SMU>xTd=1aRwKRg5w1tto|&d>#fW znWh^O5JDsX)I&$KJJQ?rm!1(KVzb$H96WeXUcP*p;c!?JLX?o~#{bB30OA0S11Pxv Z@>dgGL-jREWEcPd002ovPDHLkV1g@nG%f%D literal 0 HcmV?d00001 diff --git a/images/tag.png b/images/tag.png new file mode 100644 index 0000000000000000000000000000000000000000..ead7e4b0686a14751a93450b5749b4ebe9e13ac7 GIT binary patch literal 577 zcmV-H0>1r;P)0nSN8 zK~y-)jg!5O+CUVA?-c$kTzjNQ8@~sIEs){SE~>9yFlosCAL zU7=9GYPCWXMc8h)c^HPQ>pFxGjsF5%*M;YKAfmg;Wb%NswA*dgGz~=b^(H_{iS>Go z>2&&#BnhAOGXNNm$4b+*+a`|VAc~?>ODP3r&OFb{<2VKYv|6qGO%o|4Hk-`}z|2_? z1kB9r`#uB60bn>BW>-xt%lbW=&9bAm=Xp6ZbFo-FL5?QPX7g~(}AYcG|gatvsX_^868jS`EAwWbQ&rQAcIiE|)VR`b9+VuD%T+#5c>buv{*)OOyNidnTesA;kOFzDd(hr<2ucHTBk$FY|$jRz&pU+MWLbe1@)xYHQgT P00000NkvXXu0mjfH0t_b literal 0 HcmV?d00001 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); +}