1<?php 2/** 3 * @author Myron Turner <turnermm02@shaw.ca> 4 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 5*/ 6// must be run within Dokuwiki 7if(!defined('DOKU_INC')) die(); 8 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 9class action_plugin_nodisp extends DokuWiki_Action_Plugin { 10 public function register(Doku_Event_Handler $controller) { 11 $controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'handle_wiki_content'); 12 } 13 14 function __construct() { 15 16 if(file_exists(DOKU_PLUGIN . 'nodisp/syntax.php')) { 17 msg("Please remove syntax.php from lib/plugins/nodisp or remove the plugin and reinstall"); 18 } 19 20 } 21 22 function handle_wiki_content(Doku_Event $event, $param) { 23 global $ACT; 24 $act = act_clean($ACT); 25 if($act == 'source') { 26 $event->data = preg_replace_callback( 27 '|<nodisp (\d+)>.*?<\/nodisp>|ms', 28 function($matches) { 29 global $ID; 30 $acl = auth_quickaclcheck($ID); 31 if($acl < $matches[1]) { 32 return ""; 33 } 34 return $matches[0]; 35 },$event->data 36 ) ; 37 38 $event->data = preg_replace_callback( 39 '|\{nodisp (\d+)\}.*?\{\/nodisp\}|ms', 40 function($matches) { 41 global $ID; 42 $acl = auth_quickaclcheck($ID); 43 if($acl < $matches[1]) { 44 return ""; 45 } 46 return $matches[0]; 47 },$event->data 48 ) ; 49 50 $event->data = preg_replace_callback( 51 '|<nodisp\s+(\w+)>.*?<\/nodisp>|ms', 52 function($matches) { 53 global $ID; 54 $acl = auth_quickaclcheck($ID); 55 if($acl < $this->groupLevel($matches[1])) { 56 return ""; 57 } 58 return $matches[0]; 59 },$event->data 60 ) ; 61 62 $event->data = preg_replace_callback( 63 '|\{nodisp\s+(\w+)\}.*?\{\/nodisp\}|ms', 64 function($matches) { 65 global $ID; 66 $acl = auth_quickaclcheck($ID); 67 if($acl < $this->groupLevel($matches[1])) { 68 return ""; 69 } 70 return $matches[0]; 71 },$event->data 72 ) ; 73 return; 74 } 75 76 $event->data = preg_replace_callback( 77 '|<div class = "nodisp_([\w\d]+)"><!-- nodisp -->(.*?)<!-- nodisp -->.*?<\/div>|ms', 78 function($matches) { 79 global $ID; 80 $acl = auth_quickaclcheck($ID); 81 if($acl < $this->groupLevel($matches[1])) { 82 return ""; 83 } 84 return $matches[0]; 85 },$event->data 86 ) ; 87 } 88 89 function groupLevel($match) { 90 global $INFO; 91 92 if(is_numeric($match)) { 93 return $match; 94 } 95 $user_groups = $INFO['userinfo']['grps']; 96 if(empty($user_groups)) return "256"; 97 if(is_array($user_groups)) { 98 if(in_array($match,$user_groups)) { 99 return "1"; 100 } 101 } 102 return "256"; 103 104 } 105 } 106