1<?php 2/** 3 * DokuWiki Plugin namespacemessage (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Christoph Ziehr <info@einsatzleiterwiki.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class action_plugin_namespacemessage extends DokuWiki_Action_Plugin { 13 14 15 public function register(Doku_Event_Handler $controller) { 16 17 $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'handle_tpl_act_render'); 18 19 } 20 21 22 public function handle_tpl_act_render(Doku_Event &$event, $param) { 23 24 // make the global DokuWiki-variables usable in this function 25 global $ACT; 26 global $INFO; 27 28 // Only show the message when the page is displayed, but not in admin for example 29 if ($ACT !== 'show') { 30 return; 31 } 32 33 // Save the first-level-namespace in the variable $actual_ns 34 $actual_ns = strtok ( $INFO["namespace"] , (':') ); 35 36 // Fetch the namespaces in which the message shouldn't shown from the configuration and save them in an array 37 $not_in_namespaces_array = explode(" ", $this->getConf('not_in_namespaces')); 38 39 // Compare each namespace from the array with the actual first-level-namespace of the page 40 foreach ($not_in_namespaces_array as $ns_to_compare) { 41 // Replace "rootns" from configuration for the root namespace with "nothing" to make it comparable 42 $ns_to_compare = str_replace("rootns", "", $ns_to_compare); 43 // If the actual namespace matches the configured, finish the function without displaying the message 44 if($actual_ns == $ns_to_compare) { 45 return; 46 } 47 } 48 // Display the message 49 echo $this->getConf('message'); 50 } 51 52} 53 54// vim:ts=4:sw=4:et: 55