1<?php 2/** 3 * PHP Includes via Syntax 4 * 5 * Put your php files in /functions folder and add the path and function 6 * identifier to the /conf/default.php filr 7 * 8 * <function=functionId> 9 * 10 * The syntax includes the PHP file per include an puts the result into 11 * the wiki page. 12 * 13 * @license GNU_GPL_v2 14 * @author Markus Frosch <markus [at] lazyfrosch [dot] de> 15 * @author Tom Cafferty <tcafferty [at] glocalfocal [dot] com> 16 */ 17 18if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 19if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 20require_once(DOKU_PLUGIN.'syntax.php'); 21 22 23class syntax_plugin_function extends DokuWiki_Syntax_Plugin { 24 25 function getType(){ return 'substition'; } 26 function getPType(){ return 'normal'; } 27 function getAllowedTypes() { 28 return array('substition','protected','disabled'); 29 } 30 function getSort(){ return 195; } 31 32 function connectTo($mode) { 33 $this->Lexer->addSpecialPattern('<function=.*?>',$mode,'plugin_function'); 34 } 35 36 function handle($match, $state, $pos, &$handler){ 37 switch ($state) { 38 case DOKU_LEXER_SPECIAL : 39 return array($state, $match); 40 default: 41 return array($state); 42 } 43 } 44 45 function render($mode, &$renderer, $indata) { 46 global $conf; 47 if($mode == 'xhtml'){ 48 list($state, $data) = $indata; 49 50 switch ($state) { 51 case DOKU_LEXER_SPECIAL : 52 preg_match("#^<function=(.+)>$#", $data, $matches); 53 $func = $matches[1]; 54 $a = explode('?', $func); 55 $func = $a[0]; 56 if (!empty($a[1])) { parse_str($a[1], $params); } 57 else { $params[0] = ''; } 58 if(preg_match("#^[a-z0-9\-_ \./]+$#i", $func)) { 59 $renderer->info['cache'] = FALSE; 60 $filename = DOKU_PLUGIN . 'function/functions/' . $this->getConf($func); 61 include ($filename); 62 $renderer->doc .= $thisfunction($params); 63 } 64 else 65 $renderer->doc .= $renderer->_xmlEntities($data); 66 break; 67 68 } 69 return true; 70 } 71 72 // unsupported $mode 73 return false; 74 } 75} 76 77?>