1<?php 2/** 3 * Plugin noprint: Disables printing section of pages 4 * 5 * Syntax: <noprint>...</noprint> encloses the hidden part of the page when printed 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author Dennis Ploeger (<develop@dieploegers.de>) 9 */ 10 11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13require_once(DOKU_PLUGIN.'syntax.php'); 14 15class syntax_plugin_noprint extends DokuWiki_Syntax_Plugin { 16 17 /** 18 * Get the type of syntax this plugin defines. 19 * 20 * @param none 21 * @return String 22 * @public 23 * @static 24 */ 25 function getType(){ 26 return 'substition'; 27 } 28 29 /** 30 * What modes are allowed within our mode? 31 */ 32 function getAllowedTypes() { 33 return array('substition','protected','disabled','formatting'); 34 } 35 36 /** 37 * Define how this plugin is handled regarding paragraphs. 38 * 39 * @param none 40 * @return String <tt>'block'</tt>. 41 * @public 42 * @static 43 */ 44 function getPType(){ 45 return 'block'; 46 } 47 48 /** 49 * Where to sort in? 50 * 51 * @param none 52 * @return Integer <tt>6</tt>. 53 * @public 54 * @static 55 */ 56 function getSort(){ 57 return 999; 58 } 59 60 61 /** 62 * Connect lookup pattern to lexer. 63 * 64 * @param $aMode String The desired rendermode. 65 * @return none 66 * @public 67 * @see render() 68 */ 69 function connectTo($mode) { 70 71 $this->Lexer->addSpecialPattern('<noprint>',$mode,'plugin_noprint'); 72 $this->Lexer->addSpecialPattern('</noprint>',$mode,'plugin_noprint'); 73 74 } 75 76 /** 77 * Handler to prepare matched data for the rendering process. 78 * 79 * @param $aMatch String The text matched by the patterns. 80 * @param $aState Integer The lexer state for the match. 81 * @param $aPos Integer The character position of the matched text. 82 * @param $aHandler Object Reference to the Doku_Handler object. 83 * @return Integer The current lexer state for the match. 84 * @public 85 * @see render() 86 * @static 87 */ 88 function handle($match, $state, $pos, Doku_Handler $handler){ 89 90 return array($match, $state); 91 92 } 93 94 /** 95 * Handle the actual output creation. 96 * 97 * @param $aFormat String The output format to generate. 98 * @param $aRenderer Object A reference to the renderer object. 99 * @param $aData Array The data created by the <tt>handle()</tt> 100 * method. 101 * @return Boolean <tt>TRUE</tt> if rendered successfully, or 102 * <tt>FALSE</tt> otherwise. 103 * @public 104 * @see handle() 105 */ 106 function render($mode, Doku_Renderer $renderer, $data) { 107 108 if ($mode == 'xhtml'){ 109 110 $open = true; 111 112 if (preg_match("/<\//", $data[0])) { 113 114 $open = false; 115 116 } 117 118 switch ($open) { 119 case true: 120 $renderer->doc .= "<span id=\"noprint\">"; 121 break; 122 case false: 123 $renderer->doc .= "</span>"; 124 break; 125 } 126 return true; 127 } 128 return false; 129 } 130} 131 132//Setup VIM: ex: et ts=4 enc=utf-8 : 133?> 134