1<?php 2/** 3 * Plugin HEAT: Creates highlighted link for HEAT numbers 4 * 5 * Syntax: Heat #01234567 or HEAT #1234567 - will be highlighted 6 * 7 * @license CC BY-SA http://creativecommons.org/licenses/by-sa/3.0/nz/ 8 * @author Jo Booth <jo-heat_plugin@mesh.net.nz> 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 15/** 16 * All DokuWiki plugins to extend the parser/rendering mechanism 17 * need to inherit from this class 18 */ 19class syntax_plugin_heat extends DokuWiki_Syntax_Plugin { 20 21 /** 22 * Get an associative array with plugin info. 23 * 24 * <p> 25 * The returned array holds the following fields: 26 * <dl> 27 * <dt>author</dt><dd>Author of the plugin</dd> 28 * <dt>email</dt><dd>Email address to contact the author</dd> 29 * <dt>date</dt><dd>Last modified date of the plugin in 30 * <tt>YYYY-MM-DD</tt> format</dd> 31 * <dt>name</dt><dd>Name of the plugin</dd> 32 * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd> 33 * <dt>url</dt><dd>Website with more information on the plugin 34 * (eg. syntax description)</dd> 35 * </dl> 36 * @param none 37 * @return Array Information about this plugin class. 38 * @public 39 * @static 40 */ 41 function getInfo(){ 42 return array( 43 'author' => 'Jo Booth', 44 'email' => 'jo.booth@intergraph.com', 45 'date' => '2012-11-26', 46 'name' => 'HEAT Plugin', 47 'desc' => 'Highlights HEAT numbers in wiki', 48 'url' => 'http://www.dokuwiki.org/plugin:heat', 49 ); 50 } 51 52 /** 53 * Get the type of syntax this plugin defines. 54 * 55 * @param none 56 * @return String <tt>'substition'</tt> (i.e. 'substitution'). 57 * @public 58 * @static 59 */ 60 function getType(){ 61 return 'substition'; 62 } 63 64 /** 65 * What kind of syntax do we allow (optional) 66 */ 67// function getAllowedTypes() { 68// return array(); 69// } 70 71 /** 72 * Define how this plugin is handled regarding paragraphs. 73 * 74 * <p> 75 * This method is important for correct XHTML nesting. It returns 76 * one of the following values: 77 * </p> 78 * <dl> 79 * <dt>normal</dt><dd>The plugin can be used inside paragraphs.</dd> 80 * <dt>block</dt><dd>Open paragraphs need to be closed before 81 * plugin output.</dd> 82 * <dt>stack</dt><dd>Special case: Plugin wraps other paragraphs.</dd> 83 * </dl> 84 * @param none 85 * @return String <tt>'block'</tt>. 86 * @public 87 * @static 88 */ 89// function getPType(){ 90// return 'normal'; 91// } 92 93 /** 94 * Where to sort in? 95 * 96 * @param none 97 * @return Integer <tt>6</tt>. 98 * @public 99 * @static 100 */ 101 function getSort(){ 102 return 999; 103 } 104 105 106 /** 107 * Connect lookup pattern to lexer. 108 * 109 * @param $aMode String The desired rendermode. 110 * @return none 111 * @public 112 * @see render() 113 */ 114 function connectTo($mode) { 115 $this->Lexer->addSpecialPattern('HEAT #',$mode,'plugin_heat'); 116 $this->Lexer->addSpecialPattern('Heat #',$mode,'plugin_heat'); 117 $this->Lexer->addSpecialPattern('heat #',$mode,'plugin_heat'); 118// $this->Lexer->addEntryPattern('<TEST>',$mode,'plugin_test'); 119 } 120 121// function postConnect() { 122// $this->Lexer->addExitPattern('</TEST>','plugin_test'); 123// } 124 125 126 /** 127 * Handler to prepare matched data for the rendering process. 128 * 129 * <p> 130 * The <tt>$aState</tt> parameter gives the type of pattern 131 * which triggered the call to this method: 132 * </p> 133 * <dl> 134 * <dt>DOKU_LEXER_ENTER</dt> 135 * <dd>a pattern set by <tt>addEntryPattern()</tt></dd> 136 * <dt>DOKU_LEXER_MATCHED</dt> 137 * <dd>a pattern set by <tt>addPattern()</tt></dd> 138 * <dt>DOKU_LEXER_EXIT</dt> 139 * <dd> a pattern set by <tt>addExitPattern()</tt></dd> 140 * <dt>DOKU_LEXER_SPECIAL</dt> 141 * <dd>a pattern set by <tt>addSpecialPattern()</tt></dd> 142 * <dt>DOKU_LEXER_UNMATCHED</dt> 143 * <dd>ordinary text encountered within the plugin's syntax mode 144 * which doesn't match any pattern.</dd> 145 * </dl> 146 * @param $aMatch String The text matched by the patterns. 147 * @param $aState Integer The lexer state for the match. 148 * @param $aPos Integer The character position of the matched text. 149 * @param $aHandler Object Reference to the Doku_Handler object. 150 * @return Integer The current lexer state for the match. 151 * @public 152 * @see render() 153 * @static 154 */ 155 function handle($match, $state, $pos, &$handler){ 156 switch ($state) { 157 case DOKU_LEXER_ENTER : 158 break; 159 case DOKU_LEXER_MATCHED : 160 break; 161 case DOKU_LEXER_UNMATCHED : 162 break; 163 case DOKU_LEXER_EXIT : 164 break; 165 case DOKU_LEXER_SPECIAL : 166 break; 167 } 168 return array(); 169 } 170 171 /** 172 * Handle the actual output creation. 173 * 174 * <p> 175 * The method checks for the given <tt>$aFormat</tt> and returns 176 * <tt>FALSE</tt> when a format isn't supported. <tt>$aRenderer</tt> 177 * contains a reference to the renderer object which is currently 178 * handling the rendering. The contents of <tt>$aData</tt> is the 179 * return value of the <tt>handle()</tt> method. 180 * </p> 181 * @param $aFormat String The output format to generate. 182 * @param $aRenderer Object A reference to the renderer object. 183 * @param $aData Array The data created by the <tt>handle()</tt> 184 * method. 185 * @return Boolean <tt>TRUE</tt> if rendered successfully, or 186 * <tt>FALSE</tt> otherwise. 187 * @public 188 * @see handle() 189 */ 190 function render($mode, &$renderer, $data) { 191 if($mode == 'xhtml'){ 192 $renderer->doc .= "<strong>Heat #</strong>"; // ptype = 'normal' 193// $renderer->doc .= "<p>Hello World!</p>"; // ptype = 'block' 194 return true; 195 } 196 return false; 197 } 198} 199 200//Setup VIM: ex: et ts=4 enc=utf-8 : 201?>