1<?php 2/** 3 * Syntax Plugin Prototype 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8// must be run within Dokuwiki 9if(!defined('DOKU_INC')) die(); 10 11/** 12 * All DokuWiki plugins to extend the parser/rendering mechanism 13 * need to inherit from this class 14 */ 15class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { 16 17 var $allowedModesSetup = false; 18 19 /** 20 * Syntax Type 21 * 22 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 23 */ 24 function getType(){ 25 trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING); 26 } 27 28 /** 29 * Allowed Mode Types 30 * 31 * Defines the mode types for other dokuwiki markup that maybe nested within the 32 * plugin's own markup. Needs to return an array of one or more of the mode types 33 * defined in $PARSER_MODES in parser.php 34 */ 35 function getAllowedTypes() { 36 return array(); 37 } 38 39 /** 40 * Paragraph Type 41 * 42 * Defines how this syntax is handled regarding paragraphs. This is important 43 * for correct XHTML nesting. Should return one of the following: 44 * 45 * 'normal' - The plugin can be used inside paragraphs 46 * 'block' - Open paragraphs need to be closed before plugin output 47 * 'stack' - Special case. Plugin wraps other paragraphs. 48 * 49 * @see Doku_Handler_Block 50 */ 51 function getPType(){ 52 return 'normal'; 53 } 54 55 /** 56 * Handler to prepare matched data for the rendering process 57 * 58 * This function can only pass data to render() via its return value - render() 59 * may be not be run during the object's current life. 60 * 61 * Usually you should only need the $match param. 62 * 63 * @param string $match The text matched by the patterns 64 * @param int $state The lexer state for the match 65 * @param int $pos The character position of the matched text 66 * @param Doku_Handler $handler Reference to the Doku_Handler object 67 * @return array Return an array with all data you want to use in render 68 */ 69 function handle($match, $state, $pos, Doku_Handler &$handler){ 70 trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); 71 } 72 73 /** 74 * Handles the actual output creation. 75 * 76 * The function must not assume any other of the classes methods have been run 77 * during the object's current life. The only reliable data it receives are its 78 * parameters. 79 * 80 * The function should always check for the given output format and return false 81 * when a format isn't supported. 82 * 83 * $renderer contains a reference to the renderer object which is 84 * currently handling the rendering. You need to use it for writing 85 * the output. How this is done depends on the renderer used (specified 86 * by $format 87 * 88 * The contents of the $data array depends on what the handler() function above 89 * created 90 * 91 * @param $format string output format being rendered 92 * @param $renderer Doku_Renderer reference to the current renderer object 93 * @param $data array data created by handler() 94 * @return boolean rendered correctly? 95 */ 96 function render($format, Doku_Renderer &$renderer, $data) { 97 trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); 98 99 } 100 101 /** 102 * There should be no need to override these functions 103 */ 104 function accepts($mode) { 105 106 if (!$this->allowedModesSetup) { 107 global $PARSER_MODES; 108 109 $allowedModeTypes = $this->getAllowedTypes(); 110 foreach($allowedModeTypes as $mt) { 111 $this->allowedModes = array_merge($this->allowedModes, $PARSER_MODES[$mt]); 112 } 113 114 $idx = array_search(substr(get_class($this), 7), (array) $this->allowedModes); 115 if ($idx !== false) { 116 unset($this->allowedModes[$idx]); 117 } 118 $this->allowedModesSetup = true; 119 } 120 121 return parent::accepts($mode); 122 } 123} 124//Setup VIM: ex: et ts=4 : 125