-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsyntax.php
157 lines (147 loc) · 4.89 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Variable Plugin: allows to insert dynamic variables
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Esther Brunner <[email protected]>
*/
class syntax_plugin_var extends DokuWiki_Syntax_Plugin {
protected $aliasSeps = '._-';
/// Added in 2015-06 release to implement
static $wikiVERSION;
function getType() { return 'substition'; }
function getSort() { return 99; }
function connectTo($mode) { $this->Lexer->addSpecialPattern('@\w{2,6}['.$this->aliasSeps.']?@', $mode, 'plugin_var'); }
function handle($match, $state, $pos, Doku_Handler $handler) {
$match = substr($match, 1, -1); // strip markup
return array($match);
}
function wikiLink($id, $namespace = false)
{
if ($namespace)
$id = getNS($id);
$link = wl($id, '', true);
if ($namespace)
$link .= '/';
return $link;
}
function render($mode, Doku_Renderer $renderer, $data) {
global $ID;
global $INFO;
global $conf;
$meta = $data[0];
$length = strlen($meta);
$aliasSep = '.';
$part = substr($meta, 0, -1);
if ($part == 'ALIAS' && strpos ($this->aliasSeps, $meta[$length-1]) !== false) {
$aliasSep = $meta[$length-1];
$meta = $part;
}
$metadata = $mode == 'metadata';
$nocache = false;
switch ($meta) {
case 'ID':
$xhtml = $ID;
$meta = $xhtml;
break;
case 'NS':
$xhtml = getNS($ID);
$meta = $xhtml;
break;
case 'NSL':
$meta = $this->wikiLink($ID, true);
$nocache = true;
if (!$metadata)
$renderer->externallink($meta);
break;
case 'PAGE':
$xhtml = strtr(noNS($ID),'_',' ');
$meta = $xhtml;
break;
case 'PAGEL':
$meta = $this->wikiLink($ID);
$nocache = true;
if (!$metadata)
$renderer->externallink($meta);
break;
case 'USER':
$xhtml = $_SERVER['REMOTE_USER'];
$nocache = true;
break;
case 'ALIAS':
$xhtml = ($_SERVER['REMOTE_USER'] ? str_replace(' ', $aliasSep, $INFO['userinfo']['name']) : $_SERVER['REMOTE_USER']);
$nocache = true;
break;
case 'NAME':
$xhtml = ($_SERVER['REMOTE_USER'] ? $INFO['userinfo']['name'] : clientIP());
$nocache = true;
break;
case 'MAIL':
$xhtml = ($_SERVER['REMOTE_USER'] ? $INFO['userinfo']['mail'] : '');
$nocache = true;
break;
case 'DATE':
$xhtml = strftime($conf['dformat']);
$nocache = true;
break;
case 'YEAR':
$xhtml = date('Y');
break;
case 'MONTH':
$xhtml = date('m');
$nocache = true;
break;
case 'SMONTH':
$xhtml = date('n');
$nocache = true;
break;
case 'DAY':
$xhtml = date('d');
$nocache = true;
break;
case 'SDAY':
$xhtml = date('j');
$nocache = true;
break;
case 'WIKI':
$xhtml = $conf['title'];
break;
case 'TITLE':
$xhtml = ($INFO['meta']['title']) ? $INFO['meta']['title'] : $meta;
$nocache = true;
break;
case 'SERVER':
$xhtml = ($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $meta;
$nocache = true;
break;
case 'VER':
$xhtml = self::$wikiVERSION;
break;
case 'VERR':
list($vrel,$vdate,$vname) = explode(' ', self::$wikiVERSION);
$xhtml = trim($vdate);
break;
case 'VERN':
list($vrel,$vdate,$vname) = explode(' ', self::$wikiVERSION);
$xhtml = trim(substr($vname, 1, -1));
break;
default:
// for unknown match render original
$xhtml = "@{$meta}@";
break;
}
if ($metadata) {
$renderer->cdata($meta);
} else {
if ($xhtml != null) {
$renderer->cdata($xhtml);
}
if ($nocache) {
$renderer->nocache();
}
}
return true;
}
}
syntax_plugin_var::$wikiVERSION = getVersion();
// vim:ts=4:sw=4:et:enc=utf-8: