-
Notifications
You must be signed in to change notification settings - Fork 18
/
tpl.php
186 lines (164 loc) · 6.73 KB
/
tpl.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
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
<?php
namespace dokuwiki\template\sprintdoc;
/**
* Class tpl
*
* Provides additional template functions for the dokuwiki template
* @package dokuwiki\tpl\dokuwiki
*/
class tpl {
static $icons = array(
'default' => '00-default_checkbox-blank-circle-outline.svg',
'edit' => '01-edit_pencil.svg',
'create' => '02-create_pencil.svg',
'draft' => '03-draft_android-studio.svg',
'show' => '04-show_file-document.svg',
'source' => '05-source_file-xml.svg',
'revert' => '06-revert_replay.svg',
'revs' => '07-revisions_history.svg',
'backlink' => '08-backlink_link-variant.svg',
'subscribe' => '09-subscribe_email-outline.svg',
'top' => '10-top_arrow-up.svg',
'mediaManager' => '11-mediamanager_folder-image.svg',
'img_backto' => '12-back_arrow-left.svg',
);
/**
* Return the HTML for one of the default actions
*
* Reimplements parts of tpl_actionlink
*
* @param string $action
* @return string
*/
static public function pageToolAction($action) {
$data = tpl_get_action($action);
if(!is_array($data)) return '';
global $lang;
if($data['id'][0] == '#') {
$linktarget = $data['id'];
} else {
$linktarget = wl($data['id'], $data['params'], false, '&');
}
$caption = $lang['btn_' . $data['type']];
if(strpos($caption, '%s') !== false) {
$caption = sprintf($caption, $data['replacement']);
}
$svg = __DIR__ . '/images/tools/' . self::$icons[$data['type']];
return self::pageToolItem(
$linktarget,
$caption,
$svg,
array('accesskey' => $data['accesskey'])
);
}
/**
* Return the HTML for a page action
*
* Plugins may use this in TEMPLATE_PAGETOOLS_DISPLAY
*
* @param string $link The link
* @param string $caption The label of the action
* @param string $svg The icon to show
* @param string[] $args HTML attributes for the item
* @return string
*/
static public function pageToolItem($link, $caption, $svg, $args = array()) {
if(blank($args['title'])) {
$args['title'] = $caption;
}
if(!blank($args['accesskey'])) {
$args['title'] .= ' [' . strtoupper($args['accesskey']) . ']';
}
if(blank($args['rel'])) {
$args['rel'] = 'nofollow';
}
$args['href'] = $link ?: '#';
$svg = inlineSVG($svg);
if(!$svg) $svg = inlineSVG(__DIR__ . '/images/tools/' . self::$icons['default']);
$attributes = buildAttributes($args, true);
$out = "<a $attributes>";
$out .= '<span>' . hsc($caption) . '</span>';
$out .= $svg;
$out .= '</a>';
return $out;
}
/**
* Assemble the tools for the current page
*
* It also includes the tools for some plugins, if they are installed and enabled. This does currently not trigger
* any events, but should be adjusted to the standard dokuwiki template, once that has svg-functionality implemented.
*
* @return array
*/
static public function assemblePageTools() {
$data = array(
'view' => 'main-svg',
'items' => array(
'edit' => static::pageToolAction('edit'),
'revert' => static::pageToolAction('revert'),
'revisions' => static::pageToolAction('revisions'),
'backlink' => static::pageToolAction('backlink'),
'subscribe' => static::pageToolAction('subscribe'),
)
);
$data['items'] = array_map(function ($elem) {
return '<li>' . $elem . '</li>';
},array_filter($data['items']));
/**
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Begin shims as a temporary solution until the svg-approach is mainlined and the plugins have adapted
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
global $ACT;
if (act_clean($ACT) === 'show') {
/** @var \action_plugin_move_rename $move */
$move = plugin_load('action', 'move_rename');
if ($move && $move->getConf('pagetools_integration')) {
$attr = array(
'style' => 'background-image: none;',
);
$item = \dokuwiki\template\sprintdoc\tpl::pageToolItem('', $move->getLang('renamepage'), __DIR__ . '/images/tools/41-format-paint.svg', $attr);
$data['items'][] = '<li class="plugin_move_page">' . $item . '</li>';
}
/** @var \action_plugin_odt_export $odt */
$odt = plugin_load('action', 'odt_export');
if ($odt && $odt->getConf('showexportbutton')) {
global $ID, $REV;
$params = array('do' => 'export_odt');
if ($REV) {
$params['rev'] = $REV;
}
$attr = array(
'class' => 'action export_pdf',
'style' => 'background-image: none;',
);
$svg = __DIR__ . '/images/tools/43-file-delimeted.svg';
$item = \dokuwiki\template\sprintdoc\tpl::pageToolItem(wl($ID, $params, false, '&'), $odt->getLang('export_odt_button'), $svg, $attr);
$data['items'][] = '<li>' . $item . '</li>';
}
/** @var \action_plugin_dw2pdf $dw2pdf */
$dw2pdf = plugin_load('action', 'dw2pdf');
if ($dw2pdf && $dw2pdf->getConf('showexportbutton')) {
global $ID, $REV;
$params = array('do' => 'export_pdf');
if ($REV) {
$params['rev'] = $REV;
}
$attr = array(
'class' => 'action export_pdf',
'style' => 'background-image: none;',
);
$svg = __DIR__ . '/images/tools/40-pdf-file.svg';
$item = \dokuwiki\template\sprintdoc\tpl::pageToolItem(wl($ID, $params, false, '&'), $dw2pdf->getLang('export_pdf_button'), $svg, $attr);
$data['items'][] = '<li>' . $item . '</li>';
}
}
/**
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* End of shims
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
$data['items']['top'] = '<li>' . static::pageToolAction('top') . '</li>';
return $data;
}
}