1<?php 2 3 // must be run within DokuWiki 4 if(!defined('DOKU_INC')) die(); 5 6 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 7 require_once(DOKU_PLUGIN.'syntax.php'); 8 9 /** 10 * All DokuWiki plugins to extend the parser/rendering mechanism 11 * need to inherit from this class 12 */ 13 class syntax_plugin_nodisp_basic extends DokuWiki_Syntax_Plugin { 14 15 function getType(){ return 'container'; } 16 function getAllowedTypes() { return array('formatting', 'substition', 'disabled', 'protected', 'container', 'paragraphs' ); } 17 function getSort(){ return 168; } 18 19 /** 20 * Handle the match 21 */ 22 function handle($match, $state, $pos, Doku_Handler $handler){ 23/* 24 none 0 25 read 1 26 edit 2 27 create 4 28 upload 8 29 delete 16 30*/ 31 switch ($state) { 32 case DOKU_LEXER_ENTER : 33 if(preg_match("/nodisp\s+(\w+|\d+)(>|\})/",$match,$m) ){ 34 $level = "nodisp_" . $this->getLevel($m[1]); 35 return array($state,"<div class = \"$level\"><!-- nodisp -->\n"); 36 } 37 return array($state, "<div style='display:none'><!-- nodisp -->\n"); 38 39 case DOKU_LEXER_UNMATCHED : return array($state, $match); 40 case DOKU_LEXER_EXIT : return array($state, ''); 41 } 42 43 return array(); 44 } 45 46 /** 47 * Create output 48 */ 49 function render($mode, Doku_Renderer $renderer, $data) { 50 global $INFO; 51 if($mode == 'xhtml'){ 52 $renderer->nocache(); // disable caching 53 list($state, $match) = $data; 54 switch ($state) { 55 case DOKU_LEXER_ENTER : 56 if($INFO['isadmin'] || $INFO['ismanager'] ) break; 57 $renderer->doc .= $match; 58 break; 59 case DOKU_LEXER_UNMATCHED : $renderer->doc .= $renderer->_xmlEntities($match); break; 60 case DOKU_LEXER_EXIT : 61 if($INFO['isadmin'] || $INFO['ismanager'] ) break; 62 $renderer->doc .= "<!-- nodisp --></div>"; 63 break; 64 } 65 return true; 66 } 67 return false; 68 } 69 70 71 function getLevel($match) { 72 global $INFO; 73 if(is_numeric($match)) { 74 return $match; 75 } 76 77 $user_groups = $INFO['userinfo']['grps']; 78 if($user_groups && is_array($user_groups)) { 79 if(in_array($match,$user_groups)) { 80 return 16; 81 } 82 } 83 return $match; 84 } 85} 86