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 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_INC.'inc/parser/parser.php'); 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { 18 19 var $allowedModesSetup = false; 20 21 /** 22 * General Info 23 * 24 * Needs to return a associative array with the following values: 25 * 26 * author - Author of the plugin 27 * email - Email address to contact the author 28 * date - Last modified date of the plugin in YYYY-MM-DD format 29 * name - Name of the plugin 30 * desc - Short description of the plugin (Text only) 31 * url - Website with more information on the plugin (eg. syntax description) 32 */ 33 function getInfo(){ 34 trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING); 35 } 36 37 /** 38 * Syntax Type 39 * 40 * Needs to return one of the mode types defined in $PARSER_MODES in parser.php 41 */ 42 function getType(){ 43 trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING); 44 } 45 46 /** 47 * Allowed Mode Types 48 * 49 * Defines the mode types for other dokuwiki markup that maybe nested within the 50 * plugin's own markup. Needs to return an array of one or more of the mode types 51 * defined in $PARSER_MODES in parser.php 52 */ 53 function getAllowedTypes() { 54 return array(); 55 } 56 57 /** 58 * Paragraph Type 59 * 60 * Defines how this syntax is handled regarding paragraphs. This is important 61 * for correct XHTML nesting. Should return one of the following: 62 * 63 * 'normal' - The plugin can be used inside paragraphs 64 * 'block' - Open paragraphs need to be closed before plugin output 65 * 'stack' - Special case. Plugin wraps other paragraphs. 66 * 67 * @see Doku_Handler_Block 68 */ 69 function getPType(){ 70 return 'normal'; 71 } 72 73 /** 74 * Handler to prepare matched data for the rendering process 75 * 76 * This function can only pass data to render() via its return value - render() 77 * may be not be run during the object's current life. 78 * 79 * Usually you should only need the $match param. 80 * 81 * @param $match string The text matched by the patterns 82 * @param $state int The lexer state for the match 83 * @param $pos int The character position of the matched text 84 * @param $handler ref Reference to the Doku_Handler object 85 * @return array Return an array with all data you want to use in render 86 */ 87 function handle($match, $state, $pos, &$handler){ 88 trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); 89 } 90 91 /** 92 * Handles the actual output creation. 93 * 94 * The function must not assume any other of the classes methods have been run 95 * during the object's current life. The only reliable data it receives are its 96 * parameters. 97 * 98 * The function should always check for the given mode and return false 99 * when a mode isn't supported. 100 * 101 * $renderer contains a reference to the renderer object which is 102 * currently handling the rendering. You need to use it for writing 103 * the output. How this is done depends on the renderer used (specified 104 * by $mode 105 * 106 * The contents of the $data array depends on what the handler() function above 107 * created 108 * 109 * @param $mode string current Rendermode 110 * @param $renderer ref reference to the current renderer object 111 * @param $data array data created by handler() 112 * @return boolean rendered correctly? 113 */ 114 function render($mode, &$renderer, $data) { 115 trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); 116 117 } 118 119 /** 120 * There should be no need to override this function 121 */ 122 function accepts($mode) { 123 124 if (!$this->allowedModesSetup) { 125 global $PARSER_MODES; 126 127 $allowedModeTypes = $this->getAllowedTypes(); 128 foreach($allowedModeTypes as $mt) { 129 $this->allowedModes = array_merge($this->allowedModes, $PARSER_MODES[$mt]); 130 } 131 132 unset($this->allowedModes[array_search(substr(get_class($this), 7), $this->allowedModes)]); 133 $this->allowedModesSetup = true; 134 } 135 136 return parent::accepts($mode); 137 } 138 139} 140//Setup VIM: ex: et ts=4 enc=utf-8 : 141