forked from tstaerk/mediasyntax
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.php
More file actions
248 lines (224 loc) · 8.09 KB
/
action.php
File metadata and controls
248 lines (224 loc) · 8.09 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Thorsten Staerk <dokuwiki@staerk.de>, Esther Brunner <wikidesign@gmail.com>
*/
class action_plugin_mediasyntax extends DokuWiki_Action_Plugin
{
public $supportedModes = array('xhtml', 'i');
public $helper = null;
function __construct()
{
$this->helper = plugin_load('helper', 'mediasyntax');
}
/**
* register the eventhandlers
*/
function register(Doku_Event_Handler $controller)
{
$controller->register_hook('TOOLBAR_DEFINE',
'AFTER',
$this,
'define_toolbar',
array());
$controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare');
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_form');
$controller->register_hook('HTML_CONFLICTFORM_OUTPUT', 'BEFORE', $this, 'handle_form');
$controller->register_hook('HTML_DRAFTFORM_OUTPUT', 'BEFORE', $this, 'handle_form');
$controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'handle_redirect');
$controller->register_hook('PARSER_HANDLER_DONE', 'BEFORE', $this, 'handle_parser');
$controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'handle_metadata');
}
/**
* Used for debugging purposes only
*/
function handle_metadata(Doku_Event $event, $param)
{
dbglog("entering function ".__FUNCTION__);
//$event->data contains things like creator, last change etc.
}
/**
* Supplies the current section level to the include syntax plugin
*
* @author Michael Klier <chi@chimeric.de>
*/
function handle_parser(Doku_Event $event, $param)
{
global $ID;
// check for stored toplevel ID in helper plugin
// if it's missing lets see if we have to do anything at all
if(!isset($this->helper->toplevel_id))
{
$ins =& $event->data->calls;
$num = count($ins);
for($i=0; $i<$num; $i++)
{
if(($ins[$i][0] == 'plugin'))
{
switch($ins[$i][1][0])
{
case 'mediasyntax_include':
if(!isset($this->helper->toplevel_id))
{
$this->helper->toplevel_id = $ID;
}
$this->helper->parse_instructions($ID, $ins);
break;
// some plugins already close open sections
// so we need to make sure we don't close them twice
case 'box':
$this->helper->sec_close = false;
break;
}
}
}
}
}
/**
* Add a hidden input to the form to preserve the redirect_id
*/
function handle_form(Doku_Event $event, $param)
{
if (array_key_exists('redirect_id', $_REQUEST))
{
$event->data->addHidden('redirect_id', cleanID($_REQUEST['redirect_id']));
}
}
/**
* Modify the data for the redirect when there is a redirect_id set
*/
function handle_redirect(Doku_Event $event, $param)
{
if (array_key_exists('redirect_id', $_REQUEST))
{
$event->data['id'] = cleanID($_REQUEST['redirect_id']);
$event->data['title'] = '';
}
}
/**
* prepare the cache object for default _useCache action
*/
function _cache_prepare(Doku_Event $event, $param)
{
global $ID;
global $INFO;
global $conf;
$cache =& $event->data;
// we're only interested in instructions of the current page
// without the ID check we'd get the cache objects for included pages as well
if(!isset($cache->page) || ($cache->page != $ID)) return;
if(!isset($cache->mode) || !in_array($cache->mode, $this->supportedModes)) return;
if(!empty($INFO['userinfo']))
{
$include_key = $INFO['userinfo']['name'] . '|' . implode('|', $INFO['userinfo']['grps']);
}
else
{
$include_key = '@ALL';
}
$depends = p_get_metadata($ID, 'plugin_mediasyntax');
if($conf['allowdebug'])
{
dbglog('---- PLUGIN INCLUDE INCLUDE KEY START ----');
dbglog($include_key);
dbglog('---- PLUGIN INCLUDE INCLUDE KEY END ----');
dbglog('---- PLUGIN INCLUDE CACHE DEPENDS START ----');
dbglog($depends);
dbglog('---- PLUGIN INCLUDE CACHE DEPENDS END ----');
}
$cache->depends['purge'] = true; // kill some performance
if(is_array($depends))
{
$pages = array();
if(!isset($depends['keys'][$include_key]))
{
$cache->depends['purge'] = true; // include key not set - request purge
}
else
{
$pages = $depends['pages'];
}
}
else
{
// nothing to do for us
return;
}
// add plugin.info.txt to depends for nicer upgrades
$cache->depends['files'][] = dirname(__FILE__) . '/plugin.info.txt';
$key = '';
foreach($pages as $page)
{
$page = cleanID($this->helper->_apply_macro($page));
resolve_pageid(getNS($ID), $page, $exists);
$file = wikiFN($page);
if(!in_array($cache->depends['files'], array($file)) && @file_exists($file))
{
$cache->depends['files'][] = $file;
$key .= '#' . $page . '|ACL' . auth_quickaclcheck($page);
}
}
// empty $key implies no includes, so nothing to do
if(empty($key)) return;
// mark the cache as being modified by the include plugin
$cache->include = true;
// set new cache key & cache name
// now also dependent on included page ids and their ACL_READ status
$cache->key .= $key;
$cache->cache = getCacheName($cache->key, $cache->ext);
}
/**
* modifiy the toolbar JS defines
*
* @author Esther Brunner <wikidesign@gmail.com>
*/
function define_toolbar(Doku_Event $event, $param)
{
dbglog("entering function ".__FUNCTION__);
dbglog("event->data follows");
dbglog($event->data);
dbglog("event->data ends");
array_splice($event->data, 5,3);
$c = count($event->data);
for ($i = 0; $i <= $c; $i++)
{
if ($event->data[$i]['icon'] == 'ol.png')
{
$event->data[$i]['open'] = "# ";
}
elseif ($event->data[$i]['icon'] == 'h.png')
{
$event->data[$i]['list'][0]['open'] = "= ";
$event->data[$i]['list'][0]['close'] = " =\\n";
$event->data[$i]['list'][1]['open'] = "== ";
$event->data[$i]['list'][1]['close'] = " ==\\n";
}
elseif ($event->data[$i]['icon'] == 'ul.png')
{
$event->data[$i]['open'] = "* ";
}
elseif ($event->data[$i]['icon'] == 'ol.png')
{
$event->data[$i]['open'] = "# ";
}
elseif ($event->data[$i]['icon'] == 'italic.png')
{
$event->data[$i]['open'] = "''";
$event->data[$i]['close'] = "''";
}
elseif ($event->data[$i]['icon'] == 'mono.png')
{
$event->data[$i]['open'] = "<tt>";
$event->data[$i]['close'] = "</tt>";
$event->data[$i]['block'] = 1;
}
elseif ($event->data[$i]['icon'] == 'bold.png')
{
$event->data[$i]['open'] = "'''";
$event->data[$i]['close'] = "'''";
}
}
return true;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :