-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaction.php
89 lines (80 loc) · 2.48 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* DokuWiki Plugin custombuttons (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Constantinos Xanthopoulos <[email protected]>
*/
class action_plugin_custombuttons extends DokuWiki_Action_Plugin {
/**
* Registers a callback function for a given event
*/
public function register(Doku_Event_Handler $controller) {
if ($this->loadCBData())
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insert_button', array());
}
/**
* Read config
*
* @return bool|mixed
*/
protected function loadCBData() {
$file = @file_get_contents(DOKU_PLUGIN . "custombuttons/config.json");
if(!$file) return false;
return json_decode($file, true);
}
/**
* Build list of buttons
*
* @return array
*/
protected function makelist() {
$conf = $this->loadCBData();
$buttonlist = array();
foreach ($conf as $button) {
$ico = '../../plugins/custombuttons/';
if (!$button['icon']) {
$ico .= 'genpng.php?text='. $button['label'];
} else {
$ico .= 'ico/'. $button['icon'];
}
if ($button['type'] == 1) {
$buttonlist[] = array(
'type' => 'format',
'title' => $button['label'],
'icon' => $ico,
'open' => $button['pretag'],
'close' => $button['posttag']
);
} else {
$buttonlist[] = array(
'type' => 'insert',
'title' => $button['label'],
'icon' => $ico,
'insert' => $button['code'],
'block' => true
);
}
}
return $buttonlist;
}
/**
* Add list with buttons to toolbar
*
* @param Doku_Event $event
* @param $param
*/
public function insert_button(Doku_Event $event, $param) {
$buttonlist = $this->makelist();
if ($this->getConf('usepicker')) {
$event->data[] = array(
'type' => 'picker',
'title' => $this->getLang('picker'),
'icon' => '../../plugins/custombuttons/custom.png',
'list' => $buttonlist
);
} else {
$event->data = array_merge($event->data, $buttonlist);
}
}
}