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 65 * 'block' - Open paragraphs need to be closed before plugin output 66 * 'stack' - Special case. Plugin wraps other paragraphs. 67 * 68 * @see Doku_Handler_Block 69 */ 70 function getPType(){ 71 return 'normal'; 72 } 73 74 /** 75 * Handler to prepare matched data for the rendering process 76 * This function is called statically - it may not reference any object properties 77 * 78 * Usually you should only need the $match param. 79 * 80 * @param $match string The text matched by the patterns 81 * @param $state int The lexer state for the match 82 * @param $pos int The character position of the matched text 83 * @param $handler ref Reference to the Doku_Handler object 84 * @return array Return an array with all data you want to use in render 85 */ 86 function handle($match, $state, $pos, &$handler){ 87 trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); 88 } 89 90 /** 91 * Handles the actual output creation. 92 * This function is called statically - it may not reference any object properties 93 * 94 * The function should always check for the given mode and return false 95 * when a mode isn't supported. 96 * 97 * $renderer contains a reference to the renderer object which is 98 * currently handling the rendering. You need to use it for writing 99 * the output. How this is done depends on the renderer used (specified 100 * by $mode 101 * 102 * The contents of the $data array depends on what the handler() function above 103 * created 104 * 105 * @param $mode string current Rendermode 106 * @param $renderer ref reference to the current renderer object 107 * @param $data array data created by handler() 108 * @return boolean rendered correctly? 109 */ 110 function render($mode, &$renderer, $data) { 111 trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); 112 } 113 114 /** 115 * There should be no need to override this function 116 */ 117 function accepts($mode) { 118 119 if (!$allowedModesSetup) { 120 global $PARSER_MODES; 121 122 $allowedModeTypes = $this->getAllowedTypes(); 123 foreach($allowedModeTypes as $mt) { 124 array_merge($this->allowedModes, $PARSER_MODES[$mt]); 125 } 126 127 unset($this->allowedModes[array_search(substr(get_class($this), 7), $this->allowedModes)]); 128 $allowedModesSetup = true; 129 } 130 131 return parent::accepts($mode); 132 } 133 134} 135 136//Setup VIM: ex: et ts=4 enc=utf-8 : 137