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