forked from flammy/imagebox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.php
69 lines (56 loc) · 2.1 KB
/
action.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
<?php
/**
* ImageBox's action component for supporting Move plugin.
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author FFTiger <[email protected]>, myst6re <[email protected]>
*/
class action_plugin_imagebox extends DokuWiki_Action_Plugin {
function register(Doku_Event_handler $controller) {
$controller->register_hook('PLUGIN_MOVE_HANDLERS_REGISTER', 'BEFORE', $this, 'handle_move_register');
}
public function handle_move_register(Doku_Event $event, $params) {
$event->data['handlers']['imagebox'] = array($this, 'rewrite_imagebox');
}
public function rewrite_imagebox($match, $state, $pos, $plugin, helper_plugin_move_handler $handler) {
// Only work on enter pattern. (Do not change description and exit pattern.)
if (substr($match, 0, 3) != '[{{') return $match;
// Get pure syntax without markup.
if (substr($match, -1) == '|') {
$syntax = substr($match, 3, -1);
} else {
$syntax = substr($match, 3);
}
$left_blank = false;
$right_blank = false;
if (substr($syntax, 0, 1) == ' ') {
$left_blank = true;
$syntax = substr($syntax, 1);
}
if (substr($syntax, -1) == ' ') {
$right_blank = true;
$syntax = substr($syntax, 0, -1);
}
list($src, $option) = array_pad(explode('?', $syntax, 2), 2, '');
// Resolve new source.
if (method_exists($handler, 'adaptRelativeId')) {
$new_src = $handler->adaptRelativeId($src);
} else {
$new_src = $handler->resolveMoves($src, 'media');
$new_src = $handler->relativeLink($src, $new_src, 'media');
}
if ($src == $new_src) {
return $match;
} else {
// Construct result.
$result = '[{{';
if ($left_blank) $result .= ' ';
$result .= $new_src;
if ($option) $result .= "?".$option;
if ($right_blank) $result .= ' ';
$result .= "|";
return $result;
}
}
}
?>