-
Notifications
You must be signed in to change notification settings - Fork 2
/
syntax.php.alternative.version
174 lines (142 loc) · 4.61 KB
/
syntax.php.alternative.version
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* This actually looks like the better implementation but I run into some caching issues on Angua with this. On Adora Belle it seemed ok.
* It is possible that the problems were spurious and only due to an unnatural situation when switching identities and rights in testing
* Test before adopting this code!
*/
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_showif extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Harald Ronge',
'email' => 'harald[at]turtur[.]nl',
'date' => '2013-10-15',
'name' => 'showif Plugin',
'desc' =>
'Shows text only if all of some conditions are true. Basic markup will be shown, but heading-markup is ignored.
Based on plugin nodisp from Myron Turner.
Admins and Managers will always see everything.
Syntax is <showif [condition1], [condition2], ...>[text]</showif>
Supported conditions are:
1. isloggedin
2. isnotloggedin
3. mayonlyread
4. mayatleastread
5. mayedit
6. isadmin
Administrators will always see everything except mayonlyread.
Not all combinations are useful ;-)
',
'url' => 'http://www.turtur.nl',
);
}
//new function
function accepts($mode){
return true;
}
function getType(){ return 'container'; } //was formatting
function getPType(){ return 'stack'; }
function getAllowedTypes() { return array(
'container',
'formatting',
'substition',
'protected',
'disabled',
'paragraphs',
'baseonly' //new
);
}
function getSort(){ return 196; } //was 168
function connectTo($mode) {
$this->Lexer->addEntryPattern('<showif.*?>(?=.*?</showif>)',$mode,'plugin_showif');
}
function postConnect() { $this->Lexer->addExitPattern('</showif>','plugin_showif'); }
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
switch ($state) {
case DOKU_LEXER_ENTER :
// remove <showif and >
$conditions = trim(substr($match, 8, -1));
// explode wanted auths
$this->conditions = explode(",",$conditions);
// FIXME remember conditions here
$ReWriter = new Doku_Handler_Nest($handler->CallWriter,'plugin_showif');
$handler->CallWriter = & $ReWriter;
// don't add any plugin instruction:
return false;
case DOKU_LEXER_UNMATCHED :
// unmatched data is cdata
$handler->_addCall('cdata', array($match), $pos);
// don't add any plugin instruction:
return false;
case DOKU_LEXER_EXIT :
// get all calls we intercepted
$calls = $handler->CallWriter->calls;
// switch back to the old call writer
$ReWriter = & $handler->CallWriter;
$handler->CallWriter = & $ReWriter->CallWriter;
// return a plugin instruction
return array($state, $calls, $this->conditions);
}
return false;
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
global $INFO;
if($mode == 'xhtml'){
$renderer->nocache(); // disable caching
list($state, $calls, $conditions) = $data;
if($state != DOKU_LEXER_EXIT) return true;
$show = FALSE;
//$i = 0;
// Loop through conditions
foreach($conditions as $val) {
// All conditions have to be true
if
(
(($val == "mayedit") && (auth_quickaclcheck($INFO['id'])) >= AUTH_EDIT)
||
//mayonlyread will be hidden for an administrator!
(($val == "mayonlyread") && (auth_quickaclcheck($INFO['id'])) == AUTH_READ)
||
(($val == "mayatleastread") && (auth_quickaclcheck($INFO['id'])) >= AUTH_READ)
||
($val == "isloggedin" && ($_SERVER['REMOTE_USER']))
||
($val == "isnotloggedin" && !($_SERVER['REMOTE_USER']))
||
(($val == "isadmin") && ($INFO['isadmin'] || $INFO['ismanager'] ))
) $show = TRUE;
else {$show = FALSE; break;}
}
if ($show) {
foreach($calls as $i){
if(method_exists($renderer,$i[0])){
call_user_func_array(array($renderer,$i[0]),$i[1]);
}
}
}
return true;
}
return false;
}
}
?>