1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* DokuWiki template functions |
4
|
|
|
* |
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
6
|
|
|
* @author Andreas Gohr <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use dokuwiki\Extension\AdminPlugin; |
10
|
|
|
use dokuwiki\Extension\Event; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Access a template file |
14
|
|
|
* |
15
|
|
|
* Returns the path to the given file inside the current template, uses |
16
|
|
|
* default template if the custom version doesn't exist. |
17
|
|
|
* |
18
|
|
|
* @author Andreas Gohr <[email protected]> |
19
|
|
|
* @param string $file |
20
|
|
|
* @return string |
21
|
|
|
*/ |
22
|
|
|
function template($file) { |
23
|
|
|
global $conf; |
24
|
|
|
|
25
|
|
|
if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) |
26
|
|
|
return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; |
27
|
|
|
|
28
|
|
|
return DOKU_INC.'lib/tpl/dokuwiki/'.$file; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Convenience function to access template dir from local FS |
33
|
|
|
* |
34
|
|
|
* This replaces the deprecated DOKU_TPLINC constant |
35
|
|
|
* |
36
|
|
|
* @author Andreas Gohr <[email protected]> |
37
|
|
|
* @param string $tpl The template to use, default to current one |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
function tpl_incdir($tpl='') { |
41
|
|
|
global $conf; |
42
|
|
|
if(!$tpl) $tpl = $conf['template']; |
43
|
|
|
return DOKU_INC.'lib/tpl/'.$tpl.'/'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Convenience function to access template dir from web |
48
|
|
|
* |
49
|
|
|
* This replaces the deprecated DOKU_TPL constant |
50
|
|
|
* |
51
|
|
|
* @author Andreas Gohr <[email protected]> |
52
|
|
|
* @param string $tpl The template to use, default to current one |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
function tpl_basedir($tpl='') { |
56
|
|
|
global $conf; |
57
|
|
|
if(!$tpl) $tpl = $conf['template']; |
58
|
|
|
return DOKU_BASE.'lib/tpl/'.$tpl.'/'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Print the content |
63
|
|
|
* |
64
|
|
|
* This function is used for printing all the usual content |
65
|
|
|
* (defined by the global $ACT var) by calling the appropriate |
66
|
|
|
* outputfunction(s) from html.php |
67
|
|
|
* |
68
|
|
|
* Everything that doesn't use the main template file isn't |
69
|
|
|
* handled by this function. ACL stuff is not done here either. |
70
|
|
|
* |
71
|
|
|
* @author Andreas Gohr <[email protected]> |
72
|
|
|
* |
73
|
|
|
* @triggers TPL_ACT_RENDER |
74
|
|
|
* @triggers TPL_CONTENT_DISPLAY |
75
|
|
|
* @param bool $prependTOC should the TOC be displayed here? |
76
|
|
|
* @return bool true if any output |
77
|
|
|
*/ |
78
|
|
|
function tpl_content($prependTOC = true) { |
79
|
|
|
global $ACT; |
80
|
|
|
global $INFO; |
81
|
|
|
$INFO['prependTOC'] = $prependTOC; |
82
|
|
|
|
83
|
|
|
ob_start(); |
84
|
|
|
Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); |
85
|
|
|
$html_output = ob_get_clean(); |
86
|
|
|
Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); |
87
|
|
|
|
88
|
|
|
return !empty($html_output); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Default Action of TPL_ACT_RENDER |
93
|
|
|
* |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
function tpl_content_core() { |
97
|
|
|
$router = \dokuwiki\ActionRouter::getInstance(); |
98
|
|
|
try { |
99
|
|
|
$router->getAction()->tplContent(); |
100
|
|
|
} catch(\dokuwiki\Action\Exception\FatalException $e) { |
101
|
|
|
// there was no content for the action |
102
|
|
|
msg(hsc($e->getMessage()), -1); |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
return true; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Places the TOC where the function is called |
110
|
|
|
* |
111
|
|
|
* If you use this you most probably want to call tpl_content with |
112
|
|
|
* a false argument |
113
|
|
|
* |
114
|
|
|
* @author Andreas Gohr <[email protected]> |
115
|
|
|
* |
116
|
|
|
* @param bool $return Should the TOC be returned instead to be printed? |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
function tpl_toc($return = false) { |
120
|
|
|
global $TOC; |
121
|
|
|
global $ACT; |
122
|
|
|
global $ID; |
123
|
|
|
global $REV; |
124
|
|
|
global $INFO; |
125
|
|
|
global $conf; |
126
|
|
|
global $INPUT; |
127
|
|
|
$toc = array(); |
128
|
|
|
|
129
|
|
|
if(is_array($TOC)) { |
130
|
|
|
// if a TOC was prepared in global scope, always use it |
131
|
|
|
$toc = $TOC; |
132
|
|
|
} elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { |
133
|
|
|
// get TOC from metadata, render if neccessary |
134
|
|
|
$meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); |
135
|
|
|
if(isset($meta['internal']['toc'])) { |
136
|
|
|
$tocok = $meta['internal']['toc']; |
137
|
|
|
} else { |
138
|
|
|
$tocok = true; |
139
|
|
|
} |
140
|
|
|
$toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; |
141
|
|
|
if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { |
142
|
|
|
$toc = array(); |
143
|
|
|
} |
144
|
|
|
} elseif($ACT == 'admin') { |
145
|
|
|
// try to load admin plugin TOC |
146
|
|
|
/** @var $plugin AdminPlugin */ |
147
|
|
|
if ($plugin = plugin_getRequestAdminPlugin()) { |
148
|
|
|
$toc = $plugin->getTOC(); |
149
|
|
|
$TOC = $toc; // avoid later rebuild |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false); |
154
|
|
|
$html = html_TOC($toc); |
155
|
|
|
if($return) return $html; |
156
|
|
|
echo $html; |
157
|
|
|
return ''; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Handle the admin page contents |
162
|
|
|
* |
163
|
|
|
* @author Andreas Gohr <[email protected]> |
164
|
|
|
* |
165
|
|
|
* @return bool |
166
|
|
|
*/ |
167
|
|
|
function tpl_admin() { |
168
|
|
|
global $INFO; |
169
|
|
|
global $TOC; |
170
|
|
|
global $INPUT; |
171
|
|
|
|
172
|
|
|
$plugin = null; |
173
|
|
|
$class = $INPUT->str('page'); |
174
|
|
|
if(!empty($class)) { |
175
|
|
|
$pluginlist = plugin_list('admin'); |
176
|
|
|
|
177
|
|
|
if(in_array($class, $pluginlist)) { |
178
|
|
|
// attempt to load the plugin |
179
|
|
|
/** @var $plugin AdminPlugin */ |
180
|
|
|
$plugin = plugin_load('admin', $class); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
if($plugin !== null) { |
185
|
|
|
if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet |
186
|
|
|
if($INFO['prependTOC']) tpl_toc(); |
187
|
|
|
$plugin->html(); |
188
|
|
|
} else { |
189
|
|
|
$admin = new dokuwiki\Ui\Admin(); |
190
|
|
|
$admin->show(); |
191
|
|
|
} |
192
|
|
|
return true; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Print the correct HTML meta headers |
197
|
|
|
* |
198
|
|
|
* This has to go into the head section of your template. |
199
|
|
|
* |
200
|
|
|
* @author Andreas Gohr <[email protected]> |
201
|
|
|
* |
202
|
|
|
* @triggers TPL_METAHEADER_OUTPUT |
203
|
|
|
* @param bool $alt Should feeds and alternative format links be added? |
204
|
|
|
* @return bool |
205
|
|
|
*/ |
206
|
|
|
function tpl_metaheaders($alt = true) { |
207
|
|
|
global $ID; |
208
|
|
|
global $REV; |
209
|
|
|
global $INFO; |
210
|
|
|
global $JSINFO; |
211
|
|
|
global $ACT; |
212
|
|
|
global $QUERY; |
213
|
|
|
global $lang; |
214
|
|
|
global $conf; |
215
|
|
|
global $updateVersion; |
216
|
|
|
/** @var Input $INPUT */ |
217
|
|
|
global $INPUT; |
218
|
|
|
|
219
|
|
|
// prepare the head array |
220
|
|
|
$head = array(); |
221
|
|
|
|
222
|
|
|
// prepare seed for js and css |
223
|
|
|
$tseed = $updateVersion; |
224
|
|
|
$depends = getConfigFiles('main'); |
225
|
|
|
$depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini"; |
226
|
|
|
foreach($depends as $f) $tseed .= @filemtime($f); |
227
|
|
|
$tseed = md5($tseed); |
228
|
|
|
|
229
|
|
|
// the usual stuff |
230
|
|
|
$head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); |
231
|
|
|
if(actionOK('search')) { |
232
|
|
|
$head['link'][] = array( |
233
|
|
|
'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', |
234
|
|
|
'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] |
235
|
|
|
); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); |
239
|
|
|
if(actionOK('index')) { |
240
|
|
|
$head['link'][] = array( |
241
|
|
|
'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), |
242
|
|
|
'title'=> $lang['btn_index'] |
243
|
|
|
); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
if (actionOK('manifest')) { |
247
|
|
|
$head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php'); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
$styleUtil = new \dokuwiki\StyleUtils(); |
251
|
|
|
$styleIni = $styleUtil->cssStyleini(); |
252
|
|
|
$replacements = $styleIni['replacements']; |
253
|
|
|
if (!empty($replacements['__theme_color__'])) { |
254
|
|
|
$head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
if($alt) { |
258
|
|
|
if(actionOK('rss')) { |
259
|
|
|
$head['link'][] = array( |
260
|
|
|
'rel' => 'alternate', 'type'=> 'application/rss+xml', |
261
|
|
|
'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' |
262
|
|
|
); |
263
|
|
|
$head['link'][] = array( |
264
|
|
|
'rel' => 'alternate', 'type'=> 'application/rss+xml', |
265
|
|
|
'title'=> $lang['currentns'], |
266
|
|
|
'href' => DOKU_BASE.'feed.php?mode=list&ns='.(isset($INFO) ? $INFO['namespace'] : '') |
267
|
|
|
); |
268
|
|
|
} |
269
|
|
|
if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { |
270
|
|
|
$head['link'][] = array( |
271
|
|
|
'rel' => 'edit', |
272
|
|
|
'title'=> $lang['btn_edit'], |
273
|
|
|
'href' => wl($ID, 'do=edit', false, '&') |
274
|
|
|
); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
if(actionOK('rss') && $ACT == 'search') { |
278
|
|
|
$head['link'][] = array( |
279
|
|
|
'rel' => 'alternate', 'type'=> 'application/rss+xml', |
280
|
|
|
'title'=> $lang['searchresult'], |
281
|
|
|
'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY |
282
|
|
|
); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
if(actionOK('export_xhtml')) { |
286
|
|
|
$head['link'][] = array( |
287
|
|
|
'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], |
288
|
|
|
'href'=> exportlink($ID, 'xhtml', '', false, '&') |
289
|
|
|
); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
if(actionOK('export_raw')) { |
293
|
|
|
$head['link'][] = array( |
294
|
|
|
'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], |
295
|
|
|
'href'=> exportlink($ID, 'raw', '', false, '&') |
296
|
|
|
); |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
// setup robot tags appropriate for different modes |
301
|
|
|
if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { |
302
|
|
|
if($INFO['exists']) { |
303
|
|
|
//delay indexing: |
304
|
|
|
if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) { |
305
|
|
|
$head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); |
306
|
|
|
} else { |
307
|
|
|
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); |
308
|
|
|
} |
309
|
|
|
$canonicalUrl = wl($ID, '', true, '&'); |
310
|
|
|
if ($ID == $conf['start']) { |
311
|
|
|
$canonicalUrl = DOKU_URL; |
312
|
|
|
} |
313
|
|
|
$head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); |
314
|
|
|
} else { |
315
|
|
|
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); |
316
|
|
|
} |
317
|
|
|
} elseif(defined('DOKU_MEDIADETAIL')) { |
318
|
|
|
$head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); |
319
|
|
|
} else { |
320
|
|
|
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
// set metadata |
324
|
|
|
if($ACT == 'show' || $ACT == 'export_xhtml') { |
325
|
|
|
// keywords (explicit or implicit) |
326
|
|
|
if(!empty($INFO['meta']['subject'])) { |
327
|
|
|
$head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); |
328
|
|
|
} else { |
329
|
|
|
$head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
// load stylesheets |
334
|
|
|
$head['link'][] = array( |
335
|
|
|
'rel' => 'stylesheet', |
336
|
|
|
'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed |
337
|
|
|
); |
338
|
|
|
|
339
|
|
|
$script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';"; |
340
|
|
|
if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { |
341
|
|
|
$script .= "var SIG=".toolbar_signature().";"; |
342
|
|
|
} |
343
|
|
|
jsinfo(); |
344
|
|
|
$script .= 'var JSINFO = ' . json_encode($JSINFO).';'; |
345
|
|
|
$head['script'][] = array('_data'=> $script); |
346
|
|
|
|
347
|
|
|
// load jquery |
348
|
|
|
$jquery = getCdnUrls(); |
349
|
|
|
foreach($jquery as $src) { |
350
|
|
|
$head['script'][] = array( |
351
|
|
|
'_data' => '', |
352
|
|
|
'src' => $src, |
353
|
|
|
) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
// load our javascript dispatcher |
357
|
|
|
$head['script'][] = array( |
358
|
|
|
'_data'=> '', |
359
|
|
|
'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed, |
360
|
|
|
) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); |
361
|
|
|
|
362
|
|
|
// trigger event here |
363
|
|
|
Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); |
364
|
|
|
return true; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* prints the array build by tpl_metaheaders |
369
|
|
|
* |
370
|
|
|
* $data is an array of different header tags. Each tag can have multiple |
371
|
|
|
* instances. Attributes are given as key value pairs. Values will be HTML |
372
|
|
|
* encoded automatically so they should be provided as is in the $data array. |
373
|
|
|
* |
374
|
|
|
* For tags having a body attribute specify the body data in the special |
375
|
|
|
* attribute '_data'. This field will NOT BE ESCAPED automatically. |
376
|
|
|
* |
377
|
|
|
* @author Andreas Gohr <[email protected]> |
378
|
|
|
* |
379
|
|
|
* @param array $data |
380
|
|
|
*/ |
381
|
|
|
function _tpl_metaheaders_action($data) { |
382
|
|
|
foreach($data as $tag => $inst) { |
383
|
|
|
if($tag == 'script') { |
384
|
|
|
echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE |
385
|
|
|
} |
386
|
|
|
foreach($inst as $attr) { |
387
|
|
|
if ( empty($attr) ) { continue; } |
388
|
|
|
echo '<', $tag, ' ', buildAttributes($attr); |
389
|
|
|
if(isset($attr['_data']) || $tag == 'script') { |
390
|
|
|
if($tag == 'script' && $attr['_data']) |
391
|
|
|
$attr['_data'] = "/*<![CDATA[*/". |
392
|
|
|
$attr['_data']. |
393
|
|
|
"\n/*!]]>*/"; |
394
|
|
|
|
395
|
|
|
echo '>', $attr['_data'], '</', $tag, '>'; |
396
|
|
|
} else { |
397
|
|
|
echo '/>'; |
398
|
|
|
} |
399
|
|
|
echo "\n"; |
400
|
|
|
} |
401
|
|
|
if($tag == 'script') { |
402
|
|
|
echo "<!--<![endif]-->\n"; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Print a link |
409
|
|
|
* |
410
|
|
|
* Just builds a link. |
411
|
|
|
* |
412
|
|
|
* @author Andreas Gohr <[email protected]> |
413
|
|
|
* |
414
|
|
|
* @param string $url |
415
|
|
|
* @param string $name |
416
|
|
|
* @param string $more |
417
|
|
|
* @param bool $return if true return the link html, otherwise print |
418
|
|
|
* @return bool|string html of the link, or true if printed |
419
|
|
|
*/ |
420
|
|
|
function tpl_link($url, $name, $more = '', $return = false) { |
421
|
|
|
$out = '<a href="'.$url.'" '; |
422
|
|
|
if($more) $out .= ' '.$more; |
423
|
|
|
$out .= ">$name</a>"; |
424
|
|
|
if($return) return $out; |
425
|
|
|
print $out; |
426
|
|
|
return true; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* Prints a link to a WikiPage |
431
|
|
|
* |
432
|
|
|
* Wrapper around html_wikilink |
433
|
|
|
* |
434
|
|
|
* @author Andreas Gohr <[email protected]> |
435
|
|
|
* |
436
|
|
|
* @param string $id page id |
437
|
|
|
* @param string|null $name the name of the link |
438
|
|
|
* @param bool $return |
439
|
|
|
* @return true|string |
440
|
|
|
*/ |
441
|
|
|
function tpl_pagelink($id, $name = null, $return = false) { |
442
|
|
|
$out = '<bdi>'.html_wikilink($id, $name).'</bdi>'; |
443
|
|
|
if($return) return $out; |
444
|
|
|
print $out; |
445
|
|
|
return true; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* get the parent page |
450
|
|
|
* |
451
|
|
|
* Tries to find out which page is parent. |
452
|
|
|
* returns false if none is available |
453
|
|
|
* |
454
|
|
|
* @author Andreas Gohr <[email protected]> |
455
|
|
|
* |
456
|
|
|
* @param string $id page id |
457
|
|
|
* @return false|string |
458
|
|
|
*/ |
459
|
|
|
function tpl_getparent($id) { |
460
|
|
|
$parent = getNS($id).':'; |
461
|
|
|
resolve_pageid('', $parent, $exists); |
462
|
|
|
if($parent == $id) { |
463
|
|
|
$pos = strrpos(getNS($id), ':'); |
464
|
|
|
$parent = substr($parent, 0, $pos).':'; |
465
|
|
|
resolve_pageid('', $parent, $exists); |
466
|
|
|
if($parent == $id) return false; |
467
|
|
|
} |
468
|
|
|
return $parent; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Print one of the buttons |
473
|
|
|
* |
474
|
|
|
* @author Adrian Lang <[email protected]> |
475
|
|
|
* @see tpl_get_action |
476
|
|
|
* |
477
|
|
|
* @param string $type |
478
|
|
|
* @param bool $return |
479
|
|
|
* @return bool|string html, or false if no data, true if printed |
480
|
|
|
* @deprecated 2017-09-01 see devel:menus |
481
|
|
|
*/ |
482
|
|
|
function tpl_button($type, $return = false) { |
483
|
|
|
dbg_deprecated('see devel:menus'); |
484
|
|
|
$data = tpl_get_action($type); |
485
|
|
|
if($data === false) { |
486
|
|
|
return false; |
487
|
|
|
} elseif(!is_array($data)) { |
488
|
|
|
$out = sprintf($data, 'button'); |
489
|
|
|
} else { |
490
|
|
|
/** |
491
|
|
|
* @var string $accesskey |
492
|
|
|
* @var string $id |
493
|
|
|
* @var string $method |
494
|
|
|
* @var array $params |
495
|
|
|
*/ |
496
|
|
|
extract($data); |
497
|
|
|
if($id === '#dokuwiki__top') { |
498
|
|
|
$out = html_topbtn(); |
499
|
|
|
} else { |
500
|
|
|
$out = html_btn($type, $id, $accesskey, $params, $method); |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
if($return) return $out; |
504
|
|
|
echo $out; |
505
|
|
|
return true; |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* Like the action buttons but links |
510
|
|
|
* |
511
|
|
|
* @author Adrian Lang <[email protected]> |
512
|
|
|
* @see tpl_get_action |
513
|
|
|
* |
514
|
|
|
* @param string $type action command |
515
|
|
|
* @param string $pre prefix of link |
516
|
|
|
* @param string $suf suffix of link |
517
|
|
|
* @param string $inner innerHML of link |
518
|
|
|
* @param bool $return if true it returns html, otherwise prints |
519
|
|
|
* @return bool|string html or false if no data, true if printed |
520
|
|
|
* @deprecated 2017-09-01 see devel:menus |
521
|
|
|
*/ |
522
|
|
|
function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { |
523
|
|
|
dbg_deprecated('see devel:menus'); |
524
|
|
|
global $lang; |
525
|
|
|
$data = tpl_get_action($type); |
526
|
|
|
if($data === false) { |
527
|
|
|
return false; |
528
|
|
|
} elseif(!is_array($data)) { |
529
|
|
|
$out = sprintf($data, 'link'); |
530
|
|
|
} else { |
531
|
|
|
/** |
532
|
|
|
* @var string $accesskey |
533
|
|
|
* @var string $id |
534
|
|
|
* @var string $method |
535
|
|
|
* @var bool $nofollow |
536
|
|
|
* @var array $params |
537
|
|
|
* @var string $replacement |
538
|
|
|
*/ |
539
|
|
|
extract($data); |
540
|
|
|
if(strpos($id, '#') === 0) { |
541
|
|
|
$linktarget = $id; |
542
|
|
|
} else { |
543
|
|
|
$linktarget = wl($id, $params); |
544
|
|
|
} |
545
|
|
|
$caption = $lang['btn_'.$type]; |
546
|
|
|
if(strpos($caption, '%s')){ |
547
|
|
|
$caption = sprintf($caption, $replacement); |
548
|
|
|
} |
549
|
|
|
$akey = $addTitle = ''; |
550
|
|
|
if($accesskey) { |
551
|
|
|
$akey = 'accesskey="'.$accesskey.'" '; |
552
|
|
|
$addTitle = ' ['.strtoupper($accesskey).']'; |
553
|
|
|
} |
554
|
|
|
$rel = $nofollow ? 'rel="nofollow" ' : ''; |
555
|
|
|
$out = tpl_link( |
556
|
|
|
$linktarget, $pre.(($inner) ? $inner : $caption).$suf, |
557
|
|
|
'class="action '.$type.'" '. |
558
|
|
|
$akey.$rel. |
559
|
|
|
'title="'.hsc($caption).$addTitle.'"', true |
560
|
|
|
); |
561
|
|
|
} |
562
|
|
|
if($return) return $out; |
563
|
|
|
echo $out; |
564
|
|
|
return true; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Check the actions and get data for buttons and links |
569
|
|
|
* |
570
|
|
|
* @author Andreas Gohr <[email protected]> |
571
|
|
|
* @author Matthias Grimm <[email protected]> |
572
|
|
|
* @author Adrian Lang <[email protected]> |
573
|
|
|
* |
574
|
|
|
* @param string $type |
575
|
|
|
* @return array|bool|string |
576
|
|
|
* @deprecated 2017-09-01 see devel:menus |
577
|
|
|
*/ |
578
|
|
|
function tpl_get_action($type) { |
579
|
|
|
dbg_deprecated('see devel:menus'); |
580
|
|
|
if($type == 'history') $type = 'revisions'; |
581
|
|
|
if($type == 'subscription') $type = 'subscribe'; |
582
|
|
|
if($type == 'img_backto') $type = 'imgBackto'; |
583
|
|
|
|
584
|
|
|
$class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); |
585
|
|
|
if(class_exists($class)) { |
586
|
|
|
try { |
587
|
|
|
/** @var \dokuwiki\Menu\Item\AbstractItem $item */ |
588
|
|
|
$item = new $class; |
589
|
|
|
$data = $item->getLegacyData(); |
590
|
|
|
$unknown = false; |
591
|
|
|
} catch(\RuntimeException $ignored) { |
592
|
|
|
return false; |
593
|
|
|
} |
594
|
|
|
} else { |
595
|
|
|
global $ID; |
596
|
|
|
$data = array( |
597
|
|
|
'accesskey' => null, |
598
|
|
|
'type' => $type, |
599
|
|
|
'id' => $ID, |
600
|
|
|
'method' => 'get', |
601
|
|
|
'params' => array('do' => $type), |
602
|
|
|
'nofollow' => true, |
603
|
|
|
'replacement' => '', |
604
|
|
|
); |
605
|
|
|
$unknown = true; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
$evt = new Event('TPL_ACTION_GET', $data); |
609
|
|
|
if($evt->advise_before()) { |
610
|
|
|
//handle unknown types |
611
|
|
|
if($unknown) { |
612
|
|
|
$data = '[unknown %s type]'; |
613
|
|
|
} |
614
|
|
|
} |
615
|
|
|
$evt->advise_after(); |
616
|
|
|
unset($evt); |
617
|
|
|
|
618
|
|
|
return $data; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* Wrapper around tpl_button() and tpl_actionlink() |
623
|
|
|
* |
624
|
|
|
* @author Anika Henke <[email protected]> |
625
|
|
|
* |
626
|
|
|
* @param string $type action command |
627
|
|
|
* @param bool $link link or form button? |
628
|
|
|
* @param string|bool $wrapper HTML element wrapper |
629
|
|
|
* @param bool $return return or print |
630
|
|
|
* @param string $pre prefix for links |
631
|
|
|
* @param string $suf suffix for links |
632
|
|
|
* @param string $inner inner HTML for links |
633
|
|
|
* @return bool|string |
634
|
|
|
* @deprecated 2017-09-01 see devel:menus |
635
|
|
|
*/ |
636
|
|
|
function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { |
637
|
|
|
dbg_deprecated('see devel:menus'); |
638
|
|
|
$out = ''; |
639
|
|
|
if($link) { |
640
|
|
|
$out .= tpl_actionlink($type, $pre, $suf, $inner, true); |
641
|
|
|
} else { |
642
|
|
|
$out .= tpl_button($type, true); |
643
|
|
|
} |
644
|
|
|
if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; |
645
|
|
|
|
646
|
|
|
if($return) return $out; |
647
|
|
|
print $out; |
648
|
|
|
return $out ? true : false; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* Print the search form |
653
|
|
|
* |
654
|
|
|
* If the first parameter is given a div with the ID 'qsearch_out' will |
655
|
|
|
* be added which instructs the ajax pagequicksearch to kick in and place |
656
|
|
|
* its output into this div. The second parameter controls the propritary |
657
|
|
|
* attribute autocomplete. If set to false this attribute will be set with an |
658
|
|
|
* value of "off" to instruct the browser to disable it's own built in |
659
|
|
|
* autocompletion feature (MSIE and Firefox) |
660
|
|
|
* |
661
|
|
|
* @author Andreas Gohr <[email protected]> |
662
|
|
|
* |
663
|
|
|
* @param bool $ajax |
664
|
|
|
* @param bool $autocomplete |
665
|
|
|
* @return bool |
666
|
|
|
*/ |
667
|
|
|
function tpl_searchform($ajax = true, $autocomplete = true) { |
668
|
|
|
global $lang; |
669
|
|
|
global $ACT; |
670
|
|
|
global $QUERY; |
671
|
|
|
global $ID; |
672
|
|
|
|
673
|
|
|
// don't print the search form if search action has been disabled |
674
|
|
|
if(!actionOK('search')) return false; |
675
|
|
|
|
676
|
|
|
$searchForm = new dokuwiki\Form\Form([ |
677
|
|
|
'action' => wl(), |
678
|
|
|
'method' => 'get', |
679
|
|
|
'role' => 'search', |
680
|
|
|
'class' => 'search', |
681
|
|
|
'id' => 'dw__search', |
682
|
|
|
], true); |
683
|
|
|
$searchForm->addTagOpen('div')->addClass('no'); |
684
|
|
|
$searchForm->setHiddenField('do', 'search'); |
685
|
|
|
$searchForm->setHiddenField('id', $ID); |
686
|
|
|
$searchForm->addTextInput('q') |
687
|
|
|
->addClass('edit') |
688
|
|
|
->attrs([ |
689
|
|
|
'title' => '[F]', |
690
|
|
|
'accesskey' => 'f', |
691
|
|
|
'placeholder' => $lang['btn_search'], |
692
|
|
|
'autocomplete' => $autocomplete ? 'on' : 'off', |
693
|
|
|
]) |
694
|
|
|
->id('qsearch__in') |
695
|
|
|
->val($ACT === 'search' ? $QUERY : '') |
696
|
|
|
->useInput(false) |
697
|
|
|
; |
698
|
|
|
$searchForm->addButton('', $lang['btn_search'])->attrs([ |
699
|
|
|
'type' => 'submit', |
700
|
|
|
'title' => $lang['btn_search'], |
701
|
|
|
]); |
702
|
|
|
if ($ajax) { |
703
|
|
|
$searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup'); |
704
|
|
|
$searchForm->addTagClose('div'); |
705
|
|
|
} |
706
|
|
|
$searchForm->addTagClose('div'); |
707
|
|
|
|
708
|
|
|
echo $searchForm->toHTML('QuickSearch'); |
709
|
|
|
|
710
|
|
|
return true; |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
/** |
714
|
|
|
* Print the breadcrumbs trace |
715
|
|
|
* |
716
|
|
|
* @author Andreas Gohr <[email protected]> |
717
|
|
|
* |
718
|
|
|
* @param string $sep Separator between entries |
719
|
|
|
* @param bool $return return or print |
720
|
|
|
* @return bool|string |
721
|
|
|
*/ |
722
|
|
|
function tpl_breadcrumbs($sep = null, $return = false) { |
723
|
|
|
global $lang; |
724
|
|
|
global $conf; |
725
|
|
|
|
726
|
|
|
//check if enabled |
727
|
|
|
if(!$conf['breadcrumbs']) return false; |
728
|
|
|
|
729
|
|
|
//set default |
730
|
|
|
if(is_null($sep)) $sep = '•'; |
731
|
|
|
|
732
|
|
|
$out=''; |
733
|
|
|
|
734
|
|
|
$crumbs = breadcrumbs(); //setup crumb trace |
735
|
|
|
|
736
|
|
|
$crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; |
737
|
|
|
|
738
|
|
|
//render crumbs, highlight the last one |
739
|
|
|
$out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>'; |
740
|
|
|
$last = count($crumbs); |
741
|
|
|
$i = 0; |
742
|
|
|
foreach($crumbs as $id => $name) { |
743
|
|
|
$i++; |
744
|
|
|
$out .= $crumbs_sep; |
745
|
|
|
if($i == $last) $out .= '<span class="curid">'; |
746
|
|
|
$out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) . '</bdi>'; |
747
|
|
|
if($i == $last) $out .= '</span>'; |
748
|
|
|
} |
749
|
|
|
if($return) return $out; |
750
|
|
|
print $out; |
751
|
|
|
return $out ? true : false; |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
/** |
755
|
|
|
* Hierarchical breadcrumbs |
756
|
|
|
* |
757
|
|
|
* This code was suggested as replacement for the usual breadcrumbs. |
758
|
|
|
* It only makes sense with a deep site structure. |
759
|
|
|
* |
760
|
|
|
* @author Andreas Gohr <[email protected]> |
761
|
|
|
* @author Nigel McNie <[email protected]> |
762
|
|
|
* @author Sean Coates <[email protected]> |
763
|
|
|
* @author <[email protected]> |
764
|
|
|
* @todo May behave strangely in RTL languages |
765
|
|
|
* |
766
|
|
|
* @param string $sep Separator between entries |
767
|
|
|
* @param bool $return return or print |
768
|
|
|
* @return bool|string |
769
|
|
|
*/ |
770
|
|
|
function tpl_youarehere($sep = null, $return = false) { |
771
|
|
|
global $conf; |
772
|
|
|
global $ID; |
773
|
|
|
global $lang; |
774
|
|
|
|
775
|
|
|
// check if enabled |
776
|
|
|
if(!$conf['youarehere']) return false; |
777
|
|
|
|
778
|
|
|
//set default |
779
|
|
|
if(is_null($sep)) $sep = ' » '; |
780
|
|
|
|
781
|
|
|
$out = ''; |
782
|
|
|
|
783
|
|
|
$parts = explode(':', $ID); |
784
|
|
|
$count = count($parts); |
785
|
|
|
|
786
|
|
|
$out .= '<span class="bchead">'.$lang['youarehere'].' </span>'; |
787
|
|
|
|
788
|
|
|
// always print the startpage |
789
|
|
|
$out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>'; |
790
|
|
|
|
791
|
|
|
// print intermediate namespace links |
792
|
|
|
$part = ''; |
793
|
|
|
for($i = 0; $i < $count - 1; $i++) { |
794
|
|
|
$part .= $parts[$i].':'; |
795
|
|
|
$page = $part; |
796
|
|
|
if($page == $conf['start']) continue; // Skip startpage |
797
|
|
|
|
798
|
|
|
// output |
799
|
|
|
$out .= $sep . tpl_pagelink($page, null, true); |
800
|
|
|
} |
801
|
|
|
|
802
|
|
|
// print current page, skipping start page, skipping for namespace index |
803
|
|
|
resolve_pageid('', $page, $exists); |
804
|
|
|
if (isset($page) && $page == $part.$parts[$i]) { |
805
|
|
|
if($return) return $out; |
806
|
|
|
print $out; |
807
|
|
|
return true; |
808
|
|
|
} |
809
|
|
|
$page = $part.$parts[$i]; |
810
|
|
|
if($page == $conf['start']) { |
811
|
|
|
if($return) return $out; |
812
|
|
|
print $out; |
813
|
|
|
return true; |
814
|
|
|
} |
815
|
|
|
$out .= $sep; |
816
|
|
|
$out .= tpl_pagelink($page, null, true); |
817
|
|
|
if($return) return $out; |
818
|
|
|
print $out; |
819
|
|
|
return $out ? true : false; |
820
|
|
|
} |
821
|
|
|
|
822
|
|
|
/** |
823
|
|
|
* Print info if the user is logged in |
824
|
|
|
* and show full name in that case |
825
|
|
|
* |
826
|
|
|
* Could be enhanced with a profile link in future? |
827
|
|
|
* |
828
|
|
|
* @author Andreas Gohr <[email protected]> |
829
|
|
|
* |
830
|
|
|
* @return bool |
831
|
|
|
*/ |
832
|
|
|
function tpl_userinfo() { |
833
|
|
|
global $lang; |
834
|
|
|
/** @var Input $INPUT */ |
835
|
|
|
global $INPUT; |
836
|
|
|
|
837
|
|
|
if($INPUT->server->str('REMOTE_USER')) { |
838
|
|
|
print $lang['loggedinas'].' '.userlink(); |
839
|
|
|
return true; |
840
|
|
|
} |
841
|
|
|
return false; |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* Print some info about the current page |
846
|
|
|
* |
847
|
|
|
* @author Andreas Gohr <[email protected]> |
848
|
|
|
* |
849
|
|
|
* @param bool $ret return content instead of printing it |
850
|
|
|
* @return bool|string |
851
|
|
|
*/ |
852
|
|
|
function tpl_pageinfo($ret = false) { |
853
|
|
|
global $conf; |
854
|
|
|
global $lang; |
855
|
|
|
global $INFO; |
856
|
|
|
global $ID; |
857
|
|
|
|
858
|
|
|
// return if we are not allowed to view the page |
859
|
|
|
if(!auth_quickaclcheck($ID)) { |
860
|
|
|
return false; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
// prepare date and path |
864
|
|
|
$fn = $INFO['filepath']; |
865
|
|
|
if(!$conf['fullpath']) { |
866
|
|
|
if($INFO['rev']) { |
867
|
|
|
$fn = str_replace($conf['olddir'].'/', '', $fn); |
868
|
|
|
} else { |
869
|
|
|
$fn = str_replace($conf['datadir'].'/', '', $fn); |
870
|
|
|
} |
871
|
|
|
} |
872
|
|
|
$fn = utf8_decodeFN($fn); |
873
|
|
|
$date = dformat($INFO['lastmod']); |
874
|
|
|
|
875
|
|
|
// print it |
876
|
|
|
if($INFO['exists']) { |
877
|
|
|
$out = ''; |
878
|
|
|
$out .= '<bdi>'.$fn.'</bdi>'; |
879
|
|
|
$out .= ' · '; |
880
|
|
|
$out .= $lang['lastmod']; |
881
|
|
|
$out .= ' '; |
882
|
|
|
$out .= $date; |
883
|
|
|
if($INFO['editor']) { |
884
|
|
|
$out .= ' '.$lang['by'].' '; |
885
|
|
|
$out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; |
886
|
|
|
} else { |
887
|
|
|
$out .= ' ('.$lang['external_edit'].')'; |
888
|
|
|
} |
889
|
|
|
if($INFO['locked']) { |
890
|
|
|
$out .= ' · '; |
891
|
|
|
$out .= $lang['lockedby']; |
892
|
|
|
$out .= ' '; |
893
|
|
|
$out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; |
894
|
|
|
} |
895
|
|
|
if($ret) { |
896
|
|
|
return $out; |
897
|
|
|
} else { |
898
|
|
|
echo $out; |
899
|
|
|
return true; |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
return false; |
903
|
|
|
} |
904
|
|
|
|
905
|
|
|
/** |
906
|
|
|
* Prints or returns the name of the given page (current one if none given). |
907
|
|
|
* |
908
|
|
|
* If useheading is enabled this will use the first headline else |
909
|
|
|
* the given ID is used. |
910
|
|
|
* |
911
|
|
|
* @author Andreas Gohr <[email protected]> |
912
|
|
|
* |
913
|
|
|
* @param string $id page id |
914
|
|
|
* @param bool $ret return content instead of printing |
915
|
|
|
* @return bool|string |
916
|
|
|
*/ |
917
|
|
|
function tpl_pagetitle($id = null, $ret = false) { |
918
|
|
|
global $ACT, $INPUT, $conf, $lang; |
919
|
|
|
|
920
|
|
|
if(is_null($id)) { |
921
|
|
|
global $ID; |
922
|
|
|
$id = $ID; |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
$name = $id; |
926
|
|
|
if(useHeading('navigation')) { |
927
|
|
|
$first_heading = p_get_first_heading($id); |
928
|
|
|
if($first_heading) $name = $first_heading; |
|
|
|
|
929
|
|
|
} |
930
|
|
|
|
931
|
|
|
// default page title is the page name, modify with the current action |
932
|
|
|
switch ($ACT) { |
933
|
|
|
// admin functions |
934
|
|
|
case 'admin' : |
935
|
|
|
$page_title = $lang['btn_admin']; |
936
|
|
|
// try to get the plugin name |
937
|
|
|
/** @var $plugin AdminPlugin */ |
938
|
|
|
if ($plugin = plugin_getRequestAdminPlugin()){ |
939
|
|
|
$plugin_title = $plugin->getMenuText($conf['lang']); |
940
|
|
|
$page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); |
941
|
|
|
} |
942
|
|
|
break; |
943
|
|
|
|
944
|
|
|
// user functions |
945
|
|
|
case 'login' : |
946
|
|
|
case 'profile' : |
947
|
|
|
case 'register' : |
948
|
|
|
case 'resendpwd' : |
949
|
|
|
$page_title = $lang['btn_'.$ACT]; |
950
|
|
|
break; |
951
|
|
|
|
952
|
|
|
// wiki functions |
953
|
|
|
case 'search' : |
954
|
|
|
case 'index' : |
955
|
|
|
$page_title = $lang['btn_'.$ACT]; |
956
|
|
|
break; |
957
|
|
|
|
958
|
|
|
// page functions |
959
|
|
|
case 'edit' : |
960
|
|
|
case 'preview' : |
961
|
|
|
$page_title = "✎ ".$name; |
962
|
|
|
break; |
963
|
|
|
|
964
|
|
|
case 'revisions' : |
965
|
|
|
$page_title = $name . ' - ' . $lang['btn_revs']; |
966
|
|
|
break; |
967
|
|
|
|
968
|
|
|
case 'backlink' : |
969
|
|
|
case 'recent' : |
970
|
|
|
case 'subscribe' : |
971
|
|
|
$page_title = $name . ' - ' . $lang['btn_'.$ACT]; |
972
|
|
|
break; |
973
|
|
|
|
974
|
|
|
default : // SHOW and anything else not included |
975
|
|
|
$page_title = $name; |
976
|
|
|
} |
977
|
|
|
|
978
|
|
|
if($ret) { |
979
|
|
|
return hsc($page_title); |
980
|
|
|
} else { |
981
|
|
|
print hsc($page_title); |
982
|
|
|
return true; |
983
|
|
|
} |
984
|
|
|
} |
985
|
|
|
|
986
|
|
|
/** |
987
|
|
|
* Returns the requested EXIF/IPTC tag from the current image |
988
|
|
|
* |
989
|
|
|
* If $tags is an array all given tags are tried until a |
990
|
|
|
* value is found. If no value is found $alt is returned. |
991
|
|
|
* |
992
|
|
|
* Which texts are known is defined in the functions _exifTagNames |
993
|
|
|
* and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC |
994
|
|
|
* to the names of the latter one) |
995
|
|
|
* |
996
|
|
|
* Only allowed in: detail.php |
997
|
|
|
* |
998
|
|
|
* @author Andreas Gohr <[email protected]> |
999
|
|
|
* |
1000
|
|
|
* @param array|string $tags tag or array of tags to try |
1001
|
|
|
* @param string $alt alternative output if no data was found |
1002
|
|
|
* @param null|string $src the image src, uses global $SRC if not given |
1003
|
|
|
* @return string |
1004
|
|
|
*/ |
1005
|
|
|
function tpl_img_getTag($tags, $alt = '', $src = null) { |
1006
|
|
|
// Init Exif Reader |
1007
|
|
|
global $SRC; |
1008
|
|
|
|
1009
|
|
|
if(is_null($src)) $src = $SRC; |
1010
|
|
|
if(is_null($src)) return $alt; |
1011
|
|
|
|
1012
|
|
|
static $meta = null; |
1013
|
|
|
if(is_null($meta)) $meta = new JpegMeta($src); |
1014
|
|
|
if($meta === false) return $alt; |
1015
|
|
|
$info = cleanText($meta->getField($tags)); |
1016
|
|
|
$meta = null; // garbage collect and close any file handles. See #3404 |
1017
|
|
|
if($info == false) return $alt; |
1018
|
|
|
return $info; |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
/** |
1022
|
|
|
* Returns a description list of the metatags of the current image |
1023
|
|
|
* |
1024
|
|
|
* @return string html of description list |
1025
|
|
|
*/ |
1026
|
|
|
function tpl_img_meta() { |
1027
|
|
|
global $lang; |
1028
|
|
|
|
1029
|
|
|
$tags = tpl_get_img_meta(); |
1030
|
|
|
|
1031
|
|
|
echo '<dl>'; |
1032
|
|
|
foreach($tags as $tag) { |
1033
|
|
|
$label = $lang[$tag['langkey']]; |
1034
|
|
|
if(!$label) $label = $tag['langkey'] . ':'; |
1035
|
|
|
|
1036
|
|
|
echo '<dt>'.$label.'</dt><dd>'; |
1037
|
|
|
if ($tag['type'] == 'date') { |
1038
|
|
|
echo dformat($tag['value']); |
1039
|
|
|
} else { |
1040
|
|
|
echo hsc($tag['value']); |
1041
|
|
|
} |
1042
|
|
|
echo '</dd>'; |
1043
|
|
|
} |
1044
|
|
|
echo '</dl>'; |
1045
|
|
|
} |
1046
|
|
|
|
1047
|
|
|
/** |
1048
|
|
|
* Returns metadata as configured in mediameta config file, ready for creating html |
1049
|
|
|
* |
1050
|
|
|
* @return array with arrays containing the entries: |
1051
|
|
|
* - string langkey key to lookup in the $lang var, if not found printed as is |
1052
|
|
|
* - string type type of value |
1053
|
|
|
* - string value tag value (unescaped) |
1054
|
|
|
*/ |
1055
|
|
|
function tpl_get_img_meta() { |
1056
|
|
|
|
1057
|
|
|
$config_files = getConfigFiles('mediameta'); |
1058
|
|
|
foreach ($config_files as $config_file) { |
1059
|
|
|
if(file_exists($config_file)) { |
1060
|
|
|
include($config_file); |
1061
|
|
|
} |
1062
|
|
|
} |
1063
|
|
|
/** @var array $fields the included array with metadata */ |
1064
|
|
|
|
1065
|
|
|
$tags = array(); |
1066
|
|
|
foreach($fields as $tag){ |
1067
|
|
|
$t = array(); |
1068
|
|
|
if (!empty($tag[0])) { |
1069
|
|
|
$t = array($tag[0]); |
1070
|
|
|
} |
1071
|
|
|
if(isset($tag[3]) && is_array($tag[3])) { |
1072
|
|
|
$t = array_merge($t,$tag[3]); |
1073
|
|
|
} |
1074
|
|
|
$value = tpl_img_getTag($t); |
1075
|
|
|
if ($value) { |
1076
|
|
|
$tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); |
1077
|
|
|
} |
1078
|
|
|
} |
1079
|
|
|
return $tags; |
1080
|
|
|
} |
1081
|
|
|
|
1082
|
|
|
/** |
1083
|
|
|
* Prints the image with a link to the full sized version |
1084
|
|
|
* |
1085
|
|
|
* Only allowed in: detail.php |
1086
|
|
|
* |
1087
|
|
|
* @triggers TPL_IMG_DISPLAY |
1088
|
|
|
* @param $maxwidth int - maximal width of the image |
1089
|
|
|
* @param $maxheight int - maximal height of the image |
1090
|
|
|
* @param $link bool - link to the orginal size? |
1091
|
|
|
* @param $params array - additional image attributes |
1092
|
|
|
* @return bool Result of TPL_IMG_DISPLAY |
1093
|
|
|
*/ |
1094
|
|
|
function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { |
1095
|
|
|
global $IMG; |
1096
|
|
|
/** @var Input $INPUT */ |
1097
|
|
|
global $INPUT; |
1098
|
|
|
global $REV; |
1099
|
|
|
$w = (int) tpl_img_getTag('File.Width'); |
1100
|
|
|
$h = (int) tpl_img_getTag('File.Height'); |
1101
|
|
|
|
1102
|
|
|
//resize to given max values |
1103
|
|
|
$ratio = 1; |
1104
|
|
|
if($w >= $h) { |
1105
|
|
|
if($maxwidth && $w >= $maxwidth) { |
1106
|
|
|
$ratio = $maxwidth / $w; |
1107
|
|
|
} elseif($maxheight && $h > $maxheight) { |
1108
|
|
|
$ratio = $maxheight / $h; |
1109
|
|
|
} |
1110
|
|
|
} else { |
1111
|
|
|
if($maxheight && $h >= $maxheight) { |
1112
|
|
|
$ratio = $maxheight / $h; |
1113
|
|
|
} elseif($maxwidth && $w > $maxwidth) { |
1114
|
|
|
$ratio = $maxwidth / $w; |
1115
|
|
|
} |
1116
|
|
|
} |
1117
|
|
|
if($ratio) { |
1118
|
|
|
$w = floor($ratio * $w); |
1119
|
|
|
$h = floor($ratio * $h); |
1120
|
|
|
} |
1121
|
|
|
|
1122
|
|
|
//prepare URLs |
1123
|
|
|
$url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); |
1124
|
|
|
$src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); |
1125
|
|
|
|
1126
|
|
|
//prepare attributes |
1127
|
|
|
$alt = tpl_img_getTag('Simple.Title'); |
1128
|
|
|
if(is_null($params)) { |
1129
|
|
|
$p = array(); |
1130
|
|
|
} else { |
1131
|
|
|
$p = $params; |
1132
|
|
|
} |
1133
|
|
|
if($w) $p['width'] = $w; |
1134
|
|
|
if($h) $p['height'] = $h; |
1135
|
|
|
$p['class'] = 'img_detail'; |
1136
|
|
|
if($alt) { |
1137
|
|
|
$p['alt'] = $alt; |
1138
|
|
|
$p['title'] = $alt; |
1139
|
|
|
} else { |
1140
|
|
|
$p['alt'] = ''; |
1141
|
|
|
} |
1142
|
|
|
$p['src'] = $src; |
1143
|
|
|
|
1144
|
|
|
$data = array('url'=> ($link ? $url : null), 'params'=> $p); |
1145
|
|
|
return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); |
1146
|
|
|
} |
1147
|
|
|
|
1148
|
|
|
/** |
1149
|
|
|
* Default action for TPL_IMG_DISPLAY |
1150
|
|
|
* |
1151
|
|
|
* @param array $data |
1152
|
|
|
* @return bool |
1153
|
|
|
*/ |
1154
|
|
|
function _tpl_img_action($data) { |
1155
|
|
|
global $lang; |
1156
|
|
|
$p = buildAttributes($data['params']); |
1157
|
|
|
|
1158
|
|
|
if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; |
1159
|
|
|
print '<img '.$p.'/>'; |
1160
|
|
|
if($data['url']) print '</a>'; |
1161
|
|
|
return true; |
1162
|
|
|
} |
1163
|
|
|
|
1164
|
|
|
/** |
1165
|
|
|
* This function inserts a small gif which in reality is the indexer function. |
1166
|
|
|
* |
1167
|
|
|
* Should be called somewhere at the very end of the main.php |
1168
|
|
|
* template |
1169
|
|
|
* |
1170
|
|
|
* @return bool |
1171
|
|
|
*/ |
1172
|
|
|
function tpl_indexerWebBug() { |
1173
|
|
|
global $ID; |
1174
|
|
|
|
1175
|
|
|
$p = array(); |
1176
|
|
|
$p['src'] = DOKU_BASE.'lib/exe/taskrunner.php?id='.rawurlencode($ID). |
1177
|
|
|
'&'.time(); |
1178
|
|
|
$p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... |
1179
|
|
|
$p['height'] = 1; |
1180
|
|
|
$p['alt'] = ''; |
1181
|
|
|
$att = buildAttributes($p); |
1182
|
|
|
print "<img $att />"; |
1183
|
|
|
return true; |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
/** |
1187
|
|
|
* tpl_getConf($id) |
1188
|
|
|
* |
1189
|
|
|
* use this function to access template configuration variables |
1190
|
|
|
* |
1191
|
|
|
* @param string $id name of the value to access |
1192
|
|
|
* @param mixed $notset what to return if the setting is not available |
1193
|
|
|
* @return mixed |
1194
|
|
|
*/ |
1195
|
|
|
function tpl_getConf($id, $notset=false) { |
1196
|
|
|
global $conf; |
1197
|
|
|
static $tpl_configloaded = false; |
1198
|
|
|
|
1199
|
|
|
$tpl = $conf['template']; |
1200
|
|
|
|
1201
|
|
|
if(!$tpl_configloaded) { |
1202
|
|
|
$tconf = tpl_loadConfig(); |
1203
|
|
|
if($tconf !== false) { |
1204
|
|
|
foreach($tconf as $key => $value) { |
1205
|
|
|
if(isset($conf['tpl'][$tpl][$key])) continue; |
1206
|
|
|
$conf['tpl'][$tpl][$key] = $value; |
1207
|
|
|
} |
1208
|
|
|
$tpl_configloaded = true; |
1209
|
|
|
} |
1210
|
|
|
} |
1211
|
|
|
|
1212
|
|
|
if(isset($conf['tpl'][$tpl][$id])){ |
1213
|
|
|
return $conf['tpl'][$tpl][$id]; |
1214
|
|
|
} |
1215
|
|
|
|
1216
|
|
|
return $notset; |
1217
|
|
|
} |
1218
|
|
|
|
1219
|
|
|
/** |
1220
|
|
|
* tpl_loadConfig() |
1221
|
|
|
* |
1222
|
|
|
* reads all template configuration variables |
1223
|
|
|
* this function is automatically called by tpl_getConf() |
1224
|
|
|
* |
1225
|
|
|
* @return array |
1226
|
|
|
*/ |
1227
|
|
|
function tpl_loadConfig() { |
1228
|
|
|
|
1229
|
|
|
$file = tpl_incdir().'/conf/default.php'; |
1230
|
|
|
$conf = array(); |
1231
|
|
|
|
1232
|
|
|
if(!file_exists($file)) return false; |
1233
|
|
|
|
1234
|
|
|
// load default config file |
1235
|
|
|
include($file); |
1236
|
|
|
|
1237
|
|
|
return $conf; |
1238
|
|
|
} |
1239
|
|
|
|
1240
|
|
|
// language methods |
1241
|
|
|
/** |
1242
|
|
|
* tpl_getLang($id) |
1243
|
|
|
* |
1244
|
|
|
* use this function to access template language variables |
1245
|
|
|
* |
1246
|
|
|
* @param string $id key of language string |
1247
|
|
|
* @return string |
1248
|
|
|
*/ |
1249
|
|
|
function tpl_getLang($id) { |
1250
|
|
|
static $lang = array(); |
1251
|
|
|
|
1252
|
|
|
if(count($lang) === 0) { |
1253
|
|
|
global $conf, $config_cascade; // definitely don't invoke "global $lang" |
1254
|
|
|
|
1255
|
|
|
$path = tpl_incdir() . 'lang/'; |
1256
|
|
|
|
1257
|
|
|
$lang = array(); |
1258
|
|
|
|
1259
|
|
|
// don't include once |
1260
|
|
|
@include($path . 'en/lang.php'); |
1261
|
|
|
foreach($config_cascade['lang']['template'] as $config_file) { |
1262
|
|
|
if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { |
1263
|
|
|
include($config_file . $conf['template'] . '/en/lang.php'); |
1264
|
|
|
} |
1265
|
|
|
} |
1266
|
|
|
|
1267
|
|
|
if($conf['lang'] != 'en') { |
1268
|
|
|
@include($path . $conf['lang'] . '/lang.php'); |
1269
|
|
|
foreach($config_cascade['lang']['template'] as $config_file) { |
1270
|
|
|
if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { |
1271
|
|
|
include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); |
1272
|
|
|
} |
1273
|
|
|
} |
1274
|
|
|
} |
1275
|
|
|
} |
1276
|
|
|
return isset($lang[$id]) ? $lang[$id] : ''; |
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
/** |
1280
|
|
|
* Retrieve a language dependent file and pass to xhtml renderer for display |
1281
|
|
|
* template equivalent of p_locale_xhtml() |
1282
|
|
|
* |
1283
|
|
|
* @param string $id id of language dependent wiki page |
1284
|
|
|
* @return string parsed contents of the wiki page in xhtml format |
1285
|
|
|
*/ |
1286
|
|
|
function tpl_locale_xhtml($id) { |
1287
|
|
|
return p_cached_output(tpl_localeFN($id)); |
1288
|
|
|
} |
1289
|
|
|
|
1290
|
|
|
/** |
1291
|
|
|
* Prepends appropriate path for a language dependent filename |
1292
|
|
|
* |
1293
|
|
|
* @param string $id id of localized text |
1294
|
|
|
* @return string wiki text |
1295
|
|
|
*/ |
1296
|
|
|
function tpl_localeFN($id) { |
1297
|
|
|
$path = tpl_incdir().'lang/'; |
1298
|
|
|
global $conf; |
1299
|
|
|
$file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; |
1300
|
|
|
if (!file_exists($file)){ |
1301
|
|
|
$file = $path.$conf['lang'].'/'.$id.'.txt'; |
1302
|
|
|
if(!file_exists($file)){ |
1303
|
|
|
//fall back to english |
1304
|
|
|
$file = $path.'en/'.$id.'.txt'; |
1305
|
|
|
} |
1306
|
|
|
} |
1307
|
|
|
return $file; |
1308
|
|
|
} |
1309
|
|
|
|
1310
|
|
|
/** |
1311
|
|
|
* prints the "main content" in the mediamanager popup |
1312
|
|
|
* |
1313
|
|
|
* Depending on the user's actions this may be a list of |
1314
|
|
|
* files in a namespace, the meta editing dialog or |
1315
|
|
|
* a message of referencing pages |
1316
|
|
|
* |
1317
|
|
|
* Only allowed in mediamanager.php |
1318
|
|
|
* |
1319
|
|
|
* @triggers MEDIAMANAGER_CONTENT_OUTPUT |
1320
|
|
|
* @param bool $fromajax - set true when calling this function via ajax |
1321
|
|
|
* @param string $sort |
1322
|
|
|
* |
1323
|
|
|
* @author Andreas Gohr <[email protected]> |
1324
|
|
|
*/ |
1325
|
|
|
function tpl_mediaContent($fromajax = false, $sort='natural') { |
1326
|
|
|
global $IMG; |
1327
|
|
|
global $AUTH; |
1328
|
|
|
global $INUSE; |
1329
|
|
|
global $NS; |
1330
|
|
|
global $JUMPTO; |
1331
|
|
|
/** @var Input $INPUT */ |
1332
|
|
|
global $INPUT; |
1333
|
|
|
|
1334
|
|
|
$do = $INPUT->extract('do')->str('do'); |
1335
|
|
|
if(in_array($do, array('save', 'cancel'))) $do = ''; |
1336
|
|
|
|
1337
|
|
|
if(!$do) { |
1338
|
|
|
if($INPUT->bool('edit')) { |
1339
|
|
|
$do = 'metaform'; |
1340
|
|
|
} elseif(is_array($INUSE)) { |
1341
|
|
|
$do = 'filesinuse'; |
1342
|
|
|
} else { |
1343
|
|
|
$do = 'filelist'; |
1344
|
|
|
} |
1345
|
|
|
} |
1346
|
|
|
|
1347
|
|
|
// output the content pane, wrapped in an event. |
1348
|
|
|
if(!$fromajax) ptln('<div id="media__content">'); |
1349
|
|
|
$data = array('do' => $do); |
1350
|
|
|
$evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); |
1351
|
|
|
if($evt->advise_before()) { |
1352
|
|
|
$do = $data['do']; |
1353
|
|
|
if($do == 'filesinuse') { |
1354
|
|
|
media_filesinuse($INUSE, $IMG); |
1355
|
|
|
} elseif($do == 'filelist') { |
1356
|
|
|
media_filelist($NS, $AUTH, $JUMPTO,false,$sort); |
1357
|
|
|
} elseif($do == 'searchlist') { |
1358
|
|
|
media_searchlist($INPUT->str('q'), $NS, $AUTH); |
1359
|
|
|
} else { |
1360
|
|
|
msg('Unknown action '.hsc($do), -1); |
1361
|
|
|
} |
1362
|
|
|
} |
1363
|
|
|
$evt->advise_after(); |
1364
|
|
|
unset($evt); |
1365
|
|
|
if(!$fromajax) ptln('</div>'); |
1366
|
|
|
|
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
/** |
1370
|
|
|
* Prints the central column in full-screen media manager |
1371
|
|
|
* Depending on the opened tab this may be a list of |
1372
|
|
|
* files in a namespace, upload form or search form |
1373
|
|
|
* |
1374
|
|
|
* @author Kate Arzamastseva <[email protected]> |
1375
|
|
|
*/ |
1376
|
|
|
function tpl_mediaFileList() { |
1377
|
|
|
global $AUTH; |
1378
|
|
|
global $NS; |
1379
|
|
|
global $JUMPTO; |
1380
|
|
|
global $lang; |
1381
|
|
|
/** @var Input $INPUT */ |
1382
|
|
|
global $INPUT; |
1383
|
|
|
|
1384
|
|
|
$opened_tab = $INPUT->str('tab_files'); |
1385
|
|
|
if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; |
1386
|
|
|
if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; |
1387
|
|
|
|
1388
|
|
|
echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; |
1389
|
|
|
|
1390
|
|
|
media_tabs_files($opened_tab); |
1391
|
|
|
|
1392
|
|
|
echo '<div class="panelHeader">'.NL; |
1393
|
|
|
echo '<h3>'; |
1394
|
|
|
$tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; |
1395
|
|
|
printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); |
1396
|
|
|
echo '</h3>'.NL; |
1397
|
|
|
if($opened_tab === 'search' || $opened_tab === 'files') { |
1398
|
|
|
media_tab_files_options(); |
1399
|
|
|
} |
1400
|
|
|
echo '</div>'.NL; |
1401
|
|
|
|
1402
|
|
|
echo '<div class="panelContent">'.NL; |
1403
|
|
|
if($opened_tab == 'files') { |
1404
|
|
|
media_tab_files($NS, $AUTH, $JUMPTO); |
1405
|
|
|
} elseif($opened_tab == 'upload') { |
1406
|
|
|
media_tab_upload($NS, $AUTH, $JUMPTO); |
1407
|
|
|
} elseif($opened_tab == 'search') { |
1408
|
|
|
media_tab_search($NS, $AUTH); |
1409
|
|
|
} |
1410
|
|
|
echo '</div>'.NL; |
1411
|
|
|
} |
1412
|
|
|
|
1413
|
|
|
/** |
1414
|
|
|
* Prints the third column in full-screen media manager |
1415
|
|
|
* Depending on the opened tab this may be details of the |
1416
|
|
|
* selected file, the meta editing dialog or |
1417
|
|
|
* list of file revisions |
1418
|
|
|
* |
1419
|
|
|
* @author Kate Arzamastseva <[email protected]> |
1420
|
|
|
* |
1421
|
|
|
* @param string $image |
1422
|
|
|
* @param boolean $rev |
1423
|
|
|
*/ |
1424
|
|
|
function tpl_mediaFileDetails($image, $rev) { |
1425
|
|
|
global $conf, $DEL, $lang; |
1426
|
|
|
/** @var Input $INPUT */ |
1427
|
|
|
global $INPUT; |
1428
|
|
|
|
1429
|
|
|
$removed = ( |
1430
|
|
|
!file_exists(mediaFN($image)) && |
1431
|
|
|
file_exists(mediaMetaFN($image, '.changes')) && |
1432
|
|
|
$conf['mediarevisions'] |
1433
|
|
|
); |
1434
|
|
|
if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; |
1435
|
|
|
if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; |
1436
|
|
|
$ns = getNS($image); |
1437
|
|
|
$do = $INPUT->str('mediado'); |
1438
|
|
|
|
1439
|
|
|
$opened_tab = $INPUT->str('tab_details'); |
1440
|
|
|
|
1441
|
|
|
$tab_array = array('view'); |
1442
|
|
|
list(, $mime) = mimetype($image); |
1443
|
|
|
if($mime == 'image/jpeg') { |
1444
|
|
|
$tab_array[] = 'edit'; |
1445
|
|
|
} |
1446
|
|
|
if($conf['mediarevisions']) { |
1447
|
|
|
$tab_array[] = 'history'; |
1448
|
|
|
} |
1449
|
|
|
|
1450
|
|
|
if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; |
1451
|
|
|
if($INPUT->bool('edit')) $opened_tab = 'edit'; |
1452
|
|
|
if($do == 'restore') $opened_tab = 'view'; |
1453
|
|
|
|
1454
|
|
|
media_tabs_details($image, $opened_tab); |
1455
|
|
|
|
1456
|
|
|
echo '<div class="panelHeader"><h3>'; |
1457
|
|
|
list($ext) = mimetype($image, false); |
1458
|
|
|
$class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); |
1459
|
|
|
$class = 'select mediafile mf_'.$class; |
1460
|
|
|
$attributes = $rev ? ['rev' => $rev] : []; |
1461
|
|
|
$tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'. |
1462
|
|
|
$image.'</a>'.'</strong>'; |
1463
|
|
|
if($opened_tab === 'view' && $rev) { |
1464
|
|
|
printf($lang['media_viewold'], $tabTitle, dformat($rev)); |
1465
|
|
|
} else { |
1466
|
|
|
printf($lang['media_'.$opened_tab], $tabTitle); |
1467
|
|
|
} |
1468
|
|
|
|
1469
|
|
|
echo '</h3></div>'.NL; |
1470
|
|
|
|
1471
|
|
|
echo '<div class="panelContent">'.NL; |
1472
|
|
|
|
1473
|
|
|
if($opened_tab == 'view') { |
1474
|
|
|
media_tab_view($image, $ns, null, $rev); |
1475
|
|
|
|
1476
|
|
|
} elseif($opened_tab == 'edit' && !$removed) { |
1477
|
|
|
media_tab_edit($image, $ns); |
1478
|
|
|
|
1479
|
|
|
} elseif($opened_tab == 'history' && $conf['mediarevisions']) { |
1480
|
|
|
media_tab_history($image, $ns); |
1481
|
|
|
} |
1482
|
|
|
|
1483
|
|
|
echo '</div>'.NL; |
1484
|
|
|
} |
1485
|
|
|
|
1486
|
|
|
/** |
1487
|
|
|
* prints the namespace tree in the mediamanager popup |
1488
|
|
|
* |
1489
|
|
|
* Only allowed in mediamanager.php |
1490
|
|
|
* |
1491
|
|
|
* @author Andreas Gohr <[email protected]> |
1492
|
|
|
*/ |
1493
|
|
|
function tpl_mediaTree() { |
1494
|
|
|
global $NS; |
1495
|
|
|
ptln('<div id="media__tree">'); |
1496
|
|
|
media_nstree($NS); |
1497
|
|
|
ptln('</div>'); |
1498
|
|
|
} |
1499
|
|
|
|
1500
|
|
|
/** |
1501
|
|
|
* Print a dropdown menu with all DokuWiki actions |
1502
|
|
|
* |
1503
|
|
|
* Note: this will not use any pretty URLs |
1504
|
|
|
* |
1505
|
|
|
* @author Andreas Gohr <[email protected]> |
1506
|
|
|
* |
1507
|
|
|
* @param string $empty empty option label |
1508
|
|
|
* @param string $button submit button label |
1509
|
|
|
* @deprecated 2017-09-01 see devel:menus |
1510
|
|
|
*/ |
1511
|
|
|
function tpl_actiondropdown($empty = '', $button = '>') { |
1512
|
|
|
dbg_deprecated('see devel:menus'); |
1513
|
|
|
$menu = new \dokuwiki\Menu\MobileMenu(); |
1514
|
|
|
echo $menu->getDropdown($empty, $button); |
1515
|
|
|
} |
1516
|
|
|
|
1517
|
|
|
/** |
1518
|
|
|
* Print a informational line about the used license |
1519
|
|
|
* |
1520
|
|
|
* @author Andreas Gohr <[email protected]> |
1521
|
|
|
* @param string $img print image? (|button|badge) |
1522
|
|
|
* @param bool $imgonly skip the textual description? |
1523
|
|
|
* @param bool $return when true don't print, but return HTML |
1524
|
|
|
* @param bool $wrap wrap in div with class="license"? |
1525
|
|
|
* @return string |
1526
|
|
|
*/ |
1527
|
|
|
function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { |
1528
|
|
|
global $license; |
1529
|
|
|
global $conf; |
1530
|
|
|
global $lang; |
1531
|
|
|
if(!$conf['license']) return ''; |
1532
|
|
|
if(!is_array($license[$conf['license']])) return ''; |
1533
|
|
|
$lic = $license[$conf['license']]; |
1534
|
|
|
$target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; |
1535
|
|
|
|
1536
|
|
|
$out = ''; |
1537
|
|
|
if($wrap) $out .= '<div class="license">'; |
1538
|
|
|
if($img) { |
1539
|
|
|
$src = license_img($img); |
1540
|
|
|
if($src) { |
1541
|
|
|
$out .= '<a href="'.$lic['url'].'" rel="license"'.$target; |
1542
|
|
|
$out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; |
1543
|
|
|
if(!$imgonly) $out .= ' '; |
1544
|
|
|
} |
1545
|
|
|
} |
1546
|
|
|
if(!$imgonly) { |
1547
|
|
|
$out .= $lang['license'].' '; |
1548
|
|
|
$out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; |
1549
|
|
|
$out .= '>'.$lic['name'].'</a></bdi>'; |
1550
|
|
|
} |
1551
|
|
|
if($wrap) $out .= '</div>'; |
1552
|
|
|
|
1553
|
|
|
if($return) return $out; |
1554
|
|
|
echo $out; |
1555
|
|
|
return ''; |
1556
|
|
|
} |
1557
|
|
|
|
1558
|
|
|
/** |
1559
|
|
|
* Includes the rendered HTML of a given page |
1560
|
|
|
* |
1561
|
|
|
* This function is useful to populate sidebars or similar features in a |
1562
|
|
|
* template |
1563
|
|
|
* |
1564
|
|
|
* @param string $pageid The page name you want to include |
1565
|
|
|
* @param bool $print Should the content be printed or returned only |
1566
|
|
|
* @param bool $propagate Search higher namespaces, too? |
1567
|
|
|
* @param bool $useacl Include the page only if the ACLs check out? |
1568
|
|
|
* @return bool|null|string |
1569
|
|
|
*/ |
1570
|
|
|
function tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) { |
1571
|
|
|
if($propagate) { |
1572
|
|
|
$pageid = page_findnearest($pageid, $useacl); |
1573
|
|
|
} elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { |
1574
|
|
|
return false; |
1575
|
|
|
} |
1576
|
|
|
if(!$pageid) return false; |
1577
|
|
|
|
1578
|
|
|
global $TOC; |
1579
|
|
|
$oldtoc = $TOC; |
1580
|
|
|
$html = p_wiki_xhtml($pageid, '', false); |
1581
|
|
|
$TOC = $oldtoc; |
1582
|
|
|
|
1583
|
|
|
if($print) echo $html; |
1584
|
|
|
return $html; |
1585
|
|
|
} |
1586
|
|
|
|
1587
|
|
|
/** |
1588
|
|
|
* Display the subscribe form |
1589
|
|
|
* |
1590
|
|
|
* @author Adrian Lang <[email protected]> |
1591
|
|
|
* @deprecated 2020-07-23 |
1592
|
|
|
*/ |
1593
|
|
|
function tpl_subscribe() { |
1594
|
|
|
dbg_deprecated(\dokuwiki\Ui\Subscribe::class .'::show()'); |
1595
|
|
|
(new \dokuwiki\Ui\Subscribe)->show(); |
1596
|
|
|
} |
1597
|
|
|
|
1598
|
|
|
/** |
1599
|
|
|
* Tries to send already created content right to the browser |
1600
|
|
|
* |
1601
|
|
|
* Wraps around ob_flush() and flush() |
1602
|
|
|
* |
1603
|
|
|
* @author Andreas Gohr <[email protected]> |
1604
|
|
|
*/ |
1605
|
|
|
function tpl_flush() { |
1606
|
|
|
if( ob_get_level() > 0 ) ob_flush(); |
1607
|
|
|
flush(); |
1608
|
|
|
} |
1609
|
|
|
|
1610
|
|
|
/** |
1611
|
|
|
* Tries to find a ressource file in the given locations. |
1612
|
|
|
* |
1613
|
|
|
* If a given location starts with a colon it is assumed to be a media |
1614
|
|
|
* file, otherwise it is assumed to be relative to the current template |
1615
|
|
|
* |
1616
|
|
|
* @param string[] $search locations to look at |
1617
|
|
|
* @param bool $abs if to use absolute URL |
1618
|
|
|
* @param array &$imginfo filled with getimagesize() |
1619
|
|
|
* @param bool $fallback use fallback image if target isn't found or return 'false' if potential |
1620
|
|
|
* false result is required |
1621
|
|
|
* @return string |
1622
|
|
|
* |
1623
|
|
|
* @author Andreas Gohr <[email protected]> |
1624
|
|
|
*/ |
1625
|
|
|
function tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true) { |
1626
|
|
|
$img = ''; |
1627
|
|
|
$file = ''; |
1628
|
|
|
$ismedia = false; |
1629
|
|
|
// loop through candidates until a match was found: |
1630
|
|
|
foreach($search as $img) { |
1631
|
|
|
if(substr($img, 0, 1) == ':') { |
1632
|
|
|
$file = mediaFN($img); |
1633
|
|
|
$ismedia = true; |
1634
|
|
|
} else { |
1635
|
|
|
$file = tpl_incdir().$img; |
1636
|
|
|
$ismedia = false; |
1637
|
|
|
} |
1638
|
|
|
|
1639
|
|
|
if(file_exists($file)) break; |
1640
|
|
|
} |
1641
|
|
|
|
1642
|
|
|
// manage non existing target |
1643
|
|
|
if (!file_exists($file)) { |
1644
|
|
|
// give result for fallback image |
1645
|
|
|
if ($fallback === true) { |
1646
|
|
|
$file = DOKU_INC . 'lib/images/blank.gif'; |
1647
|
|
|
// stop process if false result is required (if $fallback is false) |
1648
|
|
|
} else { |
1649
|
|
|
return false; |
1650
|
|
|
} |
1651
|
|
|
} |
1652
|
|
|
|
1653
|
|
|
// fetch image data if requested |
1654
|
|
|
if(!is_null($imginfo)) { |
1655
|
|
|
$imginfo = getimagesize($file); |
1656
|
|
|
} |
1657
|
|
|
|
1658
|
|
|
// build URL |
1659
|
|
|
if($ismedia) { |
1660
|
|
|
$url = ml($img, '', true, '', $abs); |
1661
|
|
|
} else { |
1662
|
|
|
$url = tpl_basedir().$img; |
1663
|
|
|
if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); |
1664
|
|
|
} |
1665
|
|
|
|
1666
|
|
|
return $url; |
1667
|
|
|
} |
1668
|
|
|
|
1669
|
|
|
/** |
1670
|
|
|
* PHP include a file |
1671
|
|
|
* |
1672
|
|
|
* either from the conf directory if it exists, otherwise use |
1673
|
|
|
* file in the template's root directory. |
1674
|
|
|
* |
1675
|
|
|
* The function honours config cascade settings and looks for the given |
1676
|
|
|
* file next to the ´main´ config files, in the order protected, local, |
1677
|
|
|
* default. |
1678
|
|
|
* |
1679
|
|
|
* Note: no escaping or sanity checking is done here. Never pass user input |
1680
|
|
|
* to this function! |
1681
|
|
|
* |
1682
|
|
|
* @author Anika Henke <[email protected]> |
1683
|
|
|
* @author Andreas Gohr <[email protected]> |
1684
|
|
|
* |
1685
|
|
|
* @param string $file |
1686
|
|
|
*/ |
1687
|
|
|
function tpl_includeFile($file) { |
1688
|
|
|
global $config_cascade; |
1689
|
|
|
foreach(array('protected', 'local', 'default') as $config_group) { |
1690
|
|
|
if(empty($config_cascade['main'][$config_group])) continue; |
1691
|
|
|
foreach($config_cascade['main'][$config_group] as $conf_file) { |
1692
|
|
|
$dir = dirname($conf_file); |
1693
|
|
|
if(file_exists("$dir/$file")) { |
1694
|
|
|
include("$dir/$file"); |
1695
|
|
|
return; |
1696
|
|
|
} |
1697
|
|
|
} |
1698
|
|
|
} |
1699
|
|
|
|
1700
|
|
|
// still here? try the template dir |
1701
|
|
|
$file = tpl_incdir().$file; |
1702
|
|
|
if(file_exists($file)) { |
1703
|
|
|
include($file); |
1704
|
|
|
} |
1705
|
|
|
} |
1706
|
|
|
|
1707
|
|
|
/** |
1708
|
|
|
* Returns <link> tag for various icon types (favicon|mobile|generic) |
1709
|
|
|
* |
1710
|
|
|
* @author Anika Henke <[email protected]> |
1711
|
|
|
* |
1712
|
|
|
* @param array $types - list of icon types to display (favicon|mobile|generic) |
1713
|
|
|
* @return string |
1714
|
|
|
*/ |
1715
|
|
|
function tpl_favicon($types = array('favicon')) { |
1716
|
|
|
|
1717
|
|
|
$return = ''; |
1718
|
|
|
|
1719
|
|
|
foreach($types as $type) { |
1720
|
|
|
switch($type) { |
1721
|
|
|
case 'favicon': |
1722
|
|
|
$look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); |
1723
|
|
|
$return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; |
1724
|
|
|
break; |
1725
|
|
|
case 'mobile': |
1726
|
|
|
$look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); |
1727
|
|
|
$return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; |
1728
|
|
|
break; |
1729
|
|
|
case 'generic': |
1730
|
|
|
// ideal world solution, which doesn't work in any browser yet |
1731
|
|
|
$look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); |
1732
|
|
|
$return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; |
1733
|
|
|
break; |
1734
|
|
|
} |
1735
|
|
|
} |
1736
|
|
|
|
1737
|
|
|
return $return; |
1738
|
|
|
} |
1739
|
|
|
|
1740
|
|
|
/** |
1741
|
|
|
* Prints full-screen media manager |
1742
|
|
|
* |
1743
|
|
|
* @author Kate Arzamastseva <[email protected]> |
1744
|
|
|
*/ |
1745
|
|
|
function tpl_media() { |
1746
|
|
|
global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; |
1747
|
|
|
$fullscreen = true; |
1748
|
|
|
require_once DOKU_INC.'lib/exe/mediamanager.php'; |
1749
|
|
|
|
1750
|
|
|
$rev = ''; |
1751
|
|
|
$image = cleanID($INPUT->str('image')); |
1752
|
|
|
if(isset($IMG)) $image = $IMG; |
1753
|
|
|
if(isset($JUMPTO)) $image = $JUMPTO; |
1754
|
|
|
if(isset($REV) && !$JUMPTO) $rev = $REV; |
1755
|
|
|
|
1756
|
|
|
echo '<div id="mediamanager__page">'.NL; |
1757
|
|
|
echo '<h1>'.$lang['btn_media'].'</h1>'.NL; |
1758
|
|
|
html_msgarea(); |
1759
|
|
|
|
1760
|
|
|
echo '<div class="panel namespaces">'.NL; |
1761
|
|
|
echo '<h2>'.$lang['namespaces'].'</h2>'.NL; |
1762
|
|
|
echo '<div class="panelHeader">'; |
1763
|
|
|
echo $lang['media_namespaces']; |
1764
|
|
|
echo '</div>'.NL; |
1765
|
|
|
|
1766
|
|
|
echo '<div class="panelContent" id="media__tree">'.NL; |
1767
|
|
|
media_nstree($NS); |
1768
|
|
|
echo '</div>'.NL; |
1769
|
|
|
echo '</div>'.NL; |
1770
|
|
|
|
1771
|
|
|
echo '<div class="panel filelist">'.NL; |
1772
|
|
|
tpl_mediaFileList(); |
1773
|
|
|
echo '</div>'.NL; |
1774
|
|
|
|
1775
|
|
|
echo '<div class="panel file">'.NL; |
1776
|
|
|
echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; |
1777
|
|
|
tpl_mediaFileDetails($image, $rev); |
1778
|
|
|
echo '</div>'.NL; |
1779
|
|
|
|
1780
|
|
|
echo '</div>'.NL; |
1781
|
|
|
} |
1782
|
|
|
|
1783
|
|
|
/** |
1784
|
|
|
* Return useful layout classes |
1785
|
|
|
* |
1786
|
|
|
* @author Anika Henke <[email protected]> |
1787
|
|
|
* |
1788
|
|
|
* @return string |
1789
|
|
|
*/ |
1790
|
|
|
function tpl_classes() { |
1791
|
|
|
global $ACT, $conf, $ID, $INFO; |
1792
|
|
|
/** @var Input $INPUT */ |
1793
|
|
|
global $INPUT; |
1794
|
|
|
|
1795
|
|
|
$classes = array( |
1796
|
|
|
'dokuwiki', |
1797
|
|
|
'mode_'.$ACT, |
1798
|
|
|
'tpl_'.$conf['template'], |
1799
|
|
|
$INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', |
1800
|
|
|
(isset($INFO) && $INFO['exists']) ? '' : 'notFound', |
1801
|
|
|
($ID == $conf['start']) ? 'home' : '', |
1802
|
|
|
); |
1803
|
|
|
return join(' ', $classes); |
1804
|
|
|
} |
1805
|
|
|
|
1806
|
|
|
/** |
1807
|
|
|
* Create event for tools menues |
1808
|
|
|
* |
1809
|
|
|
* @author Anika Henke <[email protected]> |
1810
|
|
|
* @param string $toolsname name of menu |
1811
|
|
|
* @param array $items |
1812
|
|
|
* @param string $view e.g. 'main', 'detail', ... |
1813
|
|
|
* @deprecated 2017-09-01 see devel:menus |
1814
|
|
|
*/ |
1815
|
|
|
function tpl_toolsevent($toolsname, $items, $view = 'main') { |
1816
|
|
|
dbg_deprecated('see devel:menus'); |
1817
|
|
|
$data = array( |
1818
|
|
|
'view' => $view, |
1819
|
|
|
'items' => $items |
1820
|
|
|
); |
1821
|
|
|
|
1822
|
|
|
$hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; |
1823
|
|
|
$evt = new Event($hook, $data); |
1824
|
|
|
if($evt->advise_before()) { |
1825
|
|
|
foreach($evt->data['items'] as $k => $html) echo $html; |
1826
|
|
|
} |
1827
|
|
|
$evt->advise_after(); |
1828
|
|
|
} |
1829
|
|
|
|
1830
|
|
|
//Setup VIM: ex: et ts=4 : |
1831
|
|
|
|
1832
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: