Merge pull request #3467 from dokuwiki-translate/lang_update_291_1617824346
[dokuwiki.git] / inc / template.php
blob9b7dfa5ab0d262237297435476dbce2e796e3cee
1 <?php
2 /**
3 * DokuWiki template functions
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
9 use dokuwiki\Extension\AdminPlugin;
10 use dokuwiki\Extension\Event;
12 /**
13 * Access a template file
15 * Returns the path to the given file inside the current template, uses
16 * default template if the custom version doesn't exist.
18 * @author Andreas Gohr <andi@splitbrain.org>
19 * @param string $file
20 * @return string
22 function template($file) {
23 global $conf;
25 if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
26 return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
28 return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
31 /**
32 * Convenience function to access template dir from local FS
34 * This replaces the deprecated DOKU_TPLINC constant
36 * @author Andreas Gohr <andi@splitbrain.org>
37 * @param string $tpl The template to use, default to current one
38 * @return string
40 function tpl_incdir($tpl='') {
41 global $conf;
42 if(!$tpl) $tpl = $conf['template'];
43 return DOKU_INC.'lib/tpl/'.$tpl.'/';
46 /**
47 * Convenience function to access template dir from web
49 * This replaces the deprecated DOKU_TPL constant
51 * @author Andreas Gohr <andi@splitbrain.org>
52 * @param string $tpl The template to use, default to current one
53 * @return string
55 function tpl_basedir($tpl='') {
56 global $conf;
57 if(!$tpl) $tpl = $conf['template'];
58 return DOKU_BASE.'lib/tpl/'.$tpl.'/';
61 /**
62 * Print the content
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
68 * Everything that doesn't use the main template file isn't
69 * handled by this function. ACL stuff is not done here either.
71 * @author Andreas Gohr <andi@splitbrain.org>
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
78 function tpl_content($prependTOC = true) {
79 global $ACT;
80 global $INFO;
81 $INFO['prependTOC'] = $prependTOC;
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');
88 return !empty($html_output);
91 /**
92 * Default Action of TPL_ACT_RENDER
94 * @return bool
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;
105 return true;
109 * Places the TOC where the function is called
111 * If you use this you most probably want to call tpl_content with
112 * a false argument
114 * @author Andreas Gohr <andi@splitbrain.org>
116 * @param bool $return Should the TOC be returned instead to be printed?
117 * @return string
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();
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;
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();
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
153 Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false);
154 $html = html_TOC($toc);
155 if($return) return $html;
156 echo $html;
157 return '';
161 * Handle the admin page contents
163 * @author Andreas Gohr <andi@splitbrain.org>
165 * @return bool
167 function tpl_admin() {
168 global $INFO;
169 global $TOC;
170 global $INPUT;
172 $plugin = null;
173 $class = $INPUT->str('page');
174 if(!empty($class)) {
175 $pluginlist = plugin_list('admin');
177 if(in_array($class, $pluginlist)) {
178 // attempt to load the plugin
179 /** @var $plugin AdminPlugin */
180 $plugin = plugin_load('admin', $class);
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();
192 return true;
196 * Print the correct HTML meta headers
198 * This has to go into the head section of your template.
200 * @author Andreas Gohr <andi@splitbrain.org>
202 * @triggers TPL_METAHEADER_OUTPUT
203 * @param bool $alt Should feeds and alternative format links be added?
204 * @return bool
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;
219 // prepare the head array
220 $head = array();
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);
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']
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']
246 if (actionOK('manifest')) {
247 $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
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__']);
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'
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'] : '')
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, '&')
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
285 if(actionOK('export_xhtml')) {
286 $head['link'][] = array(
287 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
288 'href'=> exportlink($ID, 'xhtml', '', false, '&')
292 if(actionOK('export_raw')) {
293 $head['link'][] = array(
294 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
295 'href'=> exportlink($ID, 'raw', '', false, '&')
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');
309 $canonicalUrl = wl($ID, '', true, '&');
310 if ($ID == $conf['start']) {
311 $canonicalUrl = DOKU_URL;
313 $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
314 } else {
315 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
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');
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));
333 // load stylesheets
334 $head['link'][] = array(
335 'rel' => 'stylesheet',
336 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
339 $script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';";
340 if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
341 $script .= "var SIG=".toolbar_signature().";";
343 jsinfo();
344 $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
345 $head['script'][] = array('_data'=> $script);
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'] : []);
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'] : []);
362 // trigger event here
363 Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
364 return true;
368 * prints the array build by tpl_metaheaders
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.
374 * For tags having a body attribute specify the body data in the special
375 * attribute '_data'. This field will NOT BE ESCAPED automatically.
377 * @author Andreas Gohr <andi@splitbrain.org>
379 * @param array $data
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
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/*!]]>*/";
395 echo '>', $attr['_data'], '</', $tag, '>';
396 } else {
397 echo '/>';
399 echo "\n";
401 if($tag == 'script') {
402 echo "<!--<![endif]-->\n";
408 * Print a link
410 * Just builds a link.
412 * @author Andreas Gohr <andi@splitbrain.org>
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
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;
430 * Prints a link to a WikiPage
432 * Wrapper around html_wikilink
434 * @author Andreas Gohr <andi@splitbrain.org>
436 * @param string $id page id
437 * @param string|null $name the name of the link
438 * @param bool $return
439 * @return true|string
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;
449 * get the parent page
451 * Tries to find out which page is parent.
452 * returns false if none is available
454 * @author Andreas Gohr <andi@splitbrain.org>
456 * @param string $id page id
457 * @return false|string
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;
468 return $parent;
472 * Print one of the buttons
474 * @author Adrian Lang <mail@adrianlang.de>
475 * @see tpl_get_action
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
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 {
491 * @var string $accesskey
492 * @var string $id
493 * @var string $method
494 * @var array $params
496 extract($data);
497 if($id === '#dokuwiki__top') {
498 $out = html_topbtn();
499 } else {
500 $out = html_btn($type, $id, $accesskey, $params, $method);
503 if($return) return $out;
504 echo $out;
505 return true;
509 * Like the action buttons but links
511 * @author Adrian Lang <mail@adrianlang.de>
512 * @see tpl_get_action
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
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 {
532 * @var string $accesskey
533 * @var string $id
534 * @var string $method
535 * @var bool $nofollow
536 * @var array $params
537 * @var string $replacement
539 extract($data);
540 if(strpos($id, '#') === 0) {
541 $linktarget = $id;
542 } else {
543 $linktarget = wl($id, $params);
545 $caption = $lang['btn_'.$type];
546 if(strpos($caption, '%s')){
547 $caption = sprintf($caption, $replacement);
549 $akey = $addTitle = '';
550 if($accesskey) {
551 $akey = 'accesskey="'.$accesskey.'" ';
552 $addTitle = ' ['.strtoupper($accesskey).']';
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
562 if($return) return $out;
563 echo $out;
564 return true;
568 * Check the actions and get data for buttons and links
570 * @author Andreas Gohr <andi@splitbrain.org>
571 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
572 * @author Adrian Lang <mail@adrianlang.de>
574 * @param string $type
575 * @return array|bool|string
576 * @deprecated 2017-09-01 see devel:menus
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';
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;
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' => '',
605 $unknown = true;
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]';
615 $evt->advise_after();
616 unset($evt);
618 return $data;
622 * Wrapper around tpl_button() and tpl_actionlink()
624 * @author Anika Henke <anika@selfthinker.org>
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
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);
644 if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
646 if($return) return $out;
647 print $out;
648 return $out ? true : false;
652 * Print the search form
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)
661 * @author Andreas Gohr <andi@splitbrain.org>
663 * @param bool $ajax
664 * @param bool $autocomplete
665 * @return bool
667 function tpl_searchform($ajax = true, $autocomplete = true) {
668 global $lang;
669 global $ACT;
670 global $QUERY;
671 global $ID;
673 // don't print the search form if search action has been disabled
674 if(!actionOK('search')) return false;
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',
694 ->id('qsearch__in')
695 ->val($ACT === 'search' ? $QUERY : '')
696 ->useInput(false)
698 $searchForm->addButton('', $lang['btn_search'])->attrs([
699 'type' => 'submit',
700 'title' => $lang['btn_search'],
702 if ($ajax) {
703 $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
704 $searchForm->addTagClose('div');
706 $searchForm->addTagClose('div');
708 echo $searchForm->toHTML('QuickSearch');
710 return true;
714 * Print the breadcrumbs trace
716 * @author Andreas Gohr <andi@splitbrain.org>
718 * @param string $sep Separator between entries
719 * @param bool $return return or print
720 * @return bool|string
722 function tpl_breadcrumbs($sep = null, $return = false) {
723 global $lang;
724 global $conf;
726 //check if enabled
727 if(!$conf['breadcrumbs']) return false;
729 //set default
730 if(is_null($sep)) $sep = '•';
732 $out='';
734 $crumbs = breadcrumbs(); //setup crumb trace
736 $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
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>';
749 if($return) return $out;
750 print $out;
751 return $out ? true : false;
755 * Hierarchical breadcrumbs
757 * This code was suggested as replacement for the usual breadcrumbs.
758 * It only makes sense with a deep site structure.
760 * @author Andreas Gohr <andi@splitbrain.org>
761 * @author Nigel McNie <oracle.shinoda@gmail.com>
762 * @author Sean Coates <sean@caedmon.net>
763 * @author <fredrik@averpil.com>
764 * @todo May behave strangely in RTL languages
766 * @param string $sep Separator between entries
767 * @param bool $return return or print
768 * @return bool|string
770 function tpl_youarehere($sep = null, $return = false) {
771 global $conf;
772 global $ID;
773 global $lang;
775 // check if enabled
776 if(!$conf['youarehere']) return false;
778 //set default
779 if(is_null($sep)) $sep = ' » ';
781 $out = '';
783 $parts = explode(':', $ID);
784 $count = count($parts);
786 $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
788 // always print the startpage
789 $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
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
798 // output
799 $out .= $sep . tpl_pagelink($page, null, true);
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;
809 $page = $part.$parts[$i];
810 if($page == $conf['start']) {
811 if($return) return $out;
812 print $out;
813 return true;
815 $out .= $sep;
816 $out .= tpl_pagelink($page, null, true);
817 if($return) return $out;
818 print $out;
819 return $out ? true : false;
823 * Print info if the user is logged in
824 * and show full name in that case
826 * Could be enhanced with a profile link in future?
828 * @author Andreas Gohr <andi@splitbrain.org>
830 * @return bool
832 function tpl_userinfo() {
833 global $lang;
834 /** @var Input $INPUT */
835 global $INPUT;
837 if($INPUT->server->str('REMOTE_USER')) {
838 print $lang['loggedinas'].' '.userlink();
839 return true;
841 return false;
845 * Print some info about the current page
847 * @author Andreas Gohr <andi@splitbrain.org>
849 * @param bool $ret return content instead of printing it
850 * @return bool|string
852 function tpl_pageinfo($ret = false) {
853 global $conf;
854 global $lang;
855 global $INFO;
856 global $ID;
858 // return if we are not allowed to view the page
859 if(!auth_quickaclcheck($ID)) {
860 return false;
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);
872 $fn = utf8_decodeFN($fn);
873 $date = dformat($INFO['lastmod']);
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'].')';
889 if($INFO['locked']) {
890 $out .= ' · ';
891 $out .= $lang['lockedby'];
892 $out .= ' ';
893 $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
895 if($ret) {
896 return $out;
897 } else {
898 echo $out;
899 return true;
902 return false;
906 * Prints or returns the name of the given page (current one if none given).
908 * If useheading is enabled this will use the first headline else
909 * the given ID is used.
911 * @author Andreas Gohr <andi@splitbrain.org>
913 * @param string $id page id
914 * @param bool $ret return content instead of printing
915 * @return bool|string
917 function tpl_pagetitle($id = null, $ret = false) {
918 global $ACT, $INPUT, $conf, $lang;
920 if(is_null($id)) {
921 global $ID;
922 $id = $ID;
925 $name = $id;
926 if(useHeading('navigation')) {
927 $first_heading = p_get_first_heading($id);
928 if($first_heading) $name = $first_heading;
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();
942 break;
944 // user functions
945 case 'login' :
946 case 'profile' :
947 case 'register' :
948 case 'resendpwd' :
949 $page_title = $lang['btn_'.$ACT];
950 break;
952 // wiki functions
953 case 'search' :
954 case 'index' :
955 $page_title = $lang['btn_'.$ACT];
956 break;
958 // page functions
959 case 'edit' :
960 case 'preview' :
961 $page_title = "✎ ".$name;
962 break;
964 case 'revisions' :
965 $page_title = $name . ' - ' . $lang['btn_revs'];
966 break;
968 case 'backlink' :
969 case 'recent' :
970 case 'subscribe' :
971 $page_title = $name . ' - ' . $lang['btn_'.$ACT];
972 break;
974 default : // SHOW and anything else not included
975 $page_title = $name;
978 if($ret) {
979 return hsc($page_title);
980 } else {
981 print hsc($page_title);
982 return true;
987 * Returns the requested EXIF/IPTC tag from the current image
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.
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)
996 * Only allowed in: detail.php
998 * @author Andreas Gohr <andi@splitbrain.org>
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
1005 function tpl_img_getTag($tags, $alt = '', $src = null) {
1006 // Init Exif Reader
1007 global $SRC;
1009 if(is_null($src)) $src = $SRC;
1010 if(is_null($src)) return $alt;
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;
1022 * Returns a description list of the metatags of the current image
1024 * @return string html of description list
1026 function tpl_img_meta() {
1027 global $lang;
1029 $tags = tpl_get_img_meta();
1031 echo '<dl>';
1032 foreach($tags as $tag) {
1033 $label = $lang[$tag['langkey']];
1034 if(!$label) $label = $tag['langkey'] . ':';
1036 echo '<dt>'.$label.'</dt><dd>';
1037 if ($tag['type'] == 'date') {
1038 echo dformat($tag['value']);
1039 } else {
1040 echo hsc($tag['value']);
1042 echo '</dd>';
1044 echo '</dl>';
1048 * Returns metadata as configured in mediameta config file, ready for creating html
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)
1055 function tpl_get_img_meta() {
1057 $config_files = getConfigFiles('mediameta');
1058 foreach ($config_files as $config_file) {
1059 if(file_exists($config_file)) {
1060 include($config_file);
1063 /** @var array $fields the included array with metadata */
1065 $tags = array();
1066 foreach($fields as $tag){
1067 $t = array();
1068 if (!empty($tag[0])) {
1069 $t = array($tag[0]);
1071 if(isset($tag[3]) && is_array($tag[3])) {
1072 $t = array_merge($t,$tag[3]);
1074 $value = tpl_img_getTag($t);
1075 if ($value) {
1076 $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1079 return $tags;
1083 * Prints the image with a link to the full sized version
1085 * Only allowed in: detail.php
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
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');
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;
1110 } else {
1111 if($maxheight && $h >= $maxheight) {
1112 $ratio = $maxheight / $h;
1113 } elseif($maxwidth && $w > $maxwidth) {
1114 $ratio = $maxwidth / $w;
1117 if($ratio) {
1118 $w = floor($ratio * $w);
1119 $h = floor($ratio * $h);
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, '&');
1126 //prepare attributes
1127 $alt = tpl_img_getTag('Simple.Title');
1128 if(is_null($params)) {
1129 $p = array();
1130 } else {
1131 $p = $params;
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'] = '';
1142 $p['src'] = $src;
1144 $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1145 return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1149 * Default action for TPL_IMG_DISPLAY
1151 * @param array $data
1152 * @return bool
1154 function _tpl_img_action($data) {
1155 global $lang;
1156 $p = buildAttributes($data['params']);
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;
1165 * This function inserts a small gif which in reality is the indexer function.
1167 * Should be called somewhere at the very end of the main.php
1168 * template
1170 * @return bool
1172 function tpl_indexerWebBug() {
1173 global $ID;
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;
1187 * tpl_getConf($id)
1189 * use this function to access template configuration variables
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
1195 function tpl_getConf($id, $notset=false) {
1196 global $conf;
1197 static $tpl_configloaded = false;
1199 $tpl = $conf['template'];
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;
1208 $tpl_configloaded = true;
1212 if(isset($conf['tpl'][$tpl][$id])){
1213 return $conf['tpl'][$tpl][$id];
1216 return $notset;
1220 * tpl_loadConfig()
1222 * reads all template configuration variables
1223 * this function is automatically called by tpl_getConf()
1225 * @return array
1227 function tpl_loadConfig() {
1229 $file = tpl_incdir().'/conf/default.php';
1230 $conf = array();
1232 if(!file_exists($file)) return false;
1234 // load default config file
1235 include($file);
1237 return $conf;
1240 // language methods
1242 * tpl_getLang($id)
1244 * use this function to access template language variables
1246 * @param string $id key of language string
1247 * @return string
1249 function tpl_getLang($id) {
1250 static $lang = array();
1252 if(count($lang) === 0) {
1253 global $conf, $config_cascade; // definitely don't invoke "global $lang"
1255 $path = tpl_incdir() . 'lang/';
1257 $lang = array();
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');
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');
1276 return isset($lang[$id]) ? $lang[$id] : '';
1280 * Retrieve a language dependent file and pass to xhtml renderer for display
1281 * template equivalent of p_locale_xhtml()
1283 * @param string $id id of language dependent wiki page
1284 * @return string parsed contents of the wiki page in xhtml format
1286 function tpl_locale_xhtml($id) {
1287 return p_cached_output(tpl_localeFN($id));
1291 * Prepends appropriate path for a language dependent filename
1293 * @param string $id id of localized text
1294 * @return string wiki text
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';
1307 return $file;
1311 * prints the "main content" in the mediamanager popup
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
1317 * Only allowed in mediamanager.php
1319 * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1320 * @param bool $fromajax - set true when calling this function via ajax
1321 * @param string $sort
1323 * @author Andreas Gohr <andi@splitbrain.org>
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;
1334 $do = $INPUT->extract('do')->str('do');
1335 if(in_array($do, array('save', 'cancel'))) $do = '';
1337 if(!$do) {
1338 if($INPUT->bool('edit')) {
1339 $do = 'metaform';
1340 } elseif(is_array($INUSE)) {
1341 $do = 'filesinuse';
1342 } else {
1343 $do = 'filelist';
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);
1363 $evt->advise_after();
1364 unset($evt);
1365 if(!$fromajax) ptln('</div>');
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
1374 * @author Kate Arzamastseva <pshns@ukr.net>
1376 function tpl_mediaFileList() {
1377 global $AUTH;
1378 global $NS;
1379 global $JUMPTO;
1380 global $lang;
1381 /** @var Input $INPUT */
1382 global $INPUT;
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';
1388 echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
1390 media_tabs_files($opened_tab);
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();
1400 echo '</div>'.NL;
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);
1410 echo '</div>'.NL;
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
1419 * @author Kate Arzamastseva <pshns@ukr.net>
1421 * @param string $image
1422 * @param boolean $rev
1424 function tpl_mediaFileDetails($image, $rev) {
1425 global $conf, $DEL, $lang;
1426 /** @var Input $INPUT */
1427 global $INPUT;
1429 $removed = (
1430 !file_exists(mediaFN($image)) &&
1431 file_exists(mediaMetaFN($image, '.changes')) &&
1432 $conf['mediarevisions']
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');
1439 $opened_tab = $INPUT->str('tab_details');
1441 $tab_array = array('view');
1442 list(, $mime) = mimetype($image);
1443 if($mime == 'image/jpeg') {
1444 $tab_array[] = 'edit';
1446 if($conf['mediarevisions']) {
1447 $tab_array[] = 'history';
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';
1454 media_tabs_details($image, $opened_tab);
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);
1469 echo '</h3></div>'.NL;
1471 echo '<div class="panelContent">'.NL;
1473 if($opened_tab == 'view') {
1474 media_tab_view($image, $ns, null, $rev);
1476 } elseif($opened_tab == 'edit' && !$removed) {
1477 media_tab_edit($image, $ns);
1479 } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1480 media_tab_history($image, $ns);
1483 echo '</div>'.NL;
1487 * prints the namespace tree in the mediamanager popup
1489 * Only allowed in mediamanager.php
1491 * @author Andreas Gohr <andi@splitbrain.org>
1493 function tpl_mediaTree() {
1494 global $NS;
1495 ptln('<div id="media__tree">');
1496 media_nstree($NS);
1497 ptln('</div>');
1501 * Print a dropdown menu with all DokuWiki actions
1503 * Note: this will not use any pretty URLs
1505 * @author Andreas Gohr <andi@splitbrain.org>
1507 * @param string $empty empty option label
1508 * @param string $button submit button label
1509 * @deprecated 2017-09-01 see devel:menus
1511 function tpl_actiondropdown($empty = '', $button = '&gt;') {
1512 dbg_deprecated('see devel:menus');
1513 $menu = new \dokuwiki\Menu\MobileMenu();
1514 echo $menu->getDropdown($empty, $button);
1518 * Print a informational line about the used license
1520 * @author Andreas Gohr <andi@splitbrain.org>
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
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'].'"' : '';
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 .= ' ';
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>';
1551 if($wrap) $out .= '</div>';
1553 if($return) return $out;
1554 echo $out;
1555 return '';
1559 * Includes the rendered HTML of a given page
1561 * This function is useful to populate sidebars or similar features in a
1562 * template
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
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;
1576 if(!$pageid) return false;
1578 global $TOC;
1579 $oldtoc = $TOC;
1580 $html = p_wiki_xhtml($pageid, '', false);
1581 $TOC = $oldtoc;
1583 if($print) echo $html;
1584 return $html;
1588 * Display the subscribe form
1590 * @author Adrian Lang <lang@cosmocode.de>
1591 * @deprecated 2020-07-23
1593 function tpl_subscribe() {
1594 dbg_deprecated(\dokuwiki\Ui\Subscribe::class .'::show()');
1595 (new \dokuwiki\Ui\Subscribe)->show();
1599 * Tries to send already created content right to the browser
1601 * Wraps around ob_flush() and flush()
1603 * @author Andreas Gohr <andi@splitbrain.org>
1605 function tpl_flush() {
1606 if( ob_get_level() > 0 ) ob_flush();
1607 flush();
1611 * Tries to find a ressource file in the given locations.
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
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
1623 * @author Andreas Gohr <andi@splitbrain.org>
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;
1639 if(file_exists($file)) break;
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;
1653 // fetch image data if requested
1654 if(!is_null($imginfo)) {
1655 $imginfo = getimagesize($file);
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));
1666 return $url;
1670 * PHP include a file
1672 * either from the conf directory if it exists, otherwise use
1673 * file in the template's root directory.
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.
1679 * Note: no escaping or sanity checking is done here. Never pass user input
1680 * to this function!
1682 * @author Anika Henke <anika@selfthinker.org>
1683 * @author Andreas Gohr <andi@splitbrain.org>
1685 * @param string $file
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;
1700 // still here? try the template dir
1701 $file = tpl_incdir().$file;
1702 if(file_exists($file)) {
1703 include($file);
1708 * Returns <link> tag for various icon types (favicon|mobile|generic)
1710 * @author Anika Henke <anika@selfthinker.org>
1712 * @param array $types - list of icon types to display (favicon|mobile|generic)
1713 * @return string
1715 function tpl_favicon($types = array('favicon')) {
1717 $return = '';
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;
1737 return $return;
1741 * Prints full-screen media manager
1743 * @author Kate Arzamastseva <pshns@ukr.net>
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';
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;
1756 echo '<div id="mediamanager__page">'.NL;
1757 echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1758 html_msgarea();
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;
1766 echo '<div class="panelContent" id="media__tree">'.NL;
1767 media_nstree($NS);
1768 echo '</div>'.NL;
1769 echo '</div>'.NL;
1771 echo '<div class="panel filelist">'.NL;
1772 tpl_mediaFileList();
1773 echo '</div>'.NL;
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;
1780 echo '</div>'.NL;
1784 * Return useful layout classes
1786 * @author Anika Henke <anika@selfthinker.org>
1788 * @return string
1790 function tpl_classes() {
1791 global $ACT, $conf, $ID, $INFO;
1792 /** @var Input $INPUT */
1793 global $INPUT;
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' : '',
1803 return join(' ', $classes);
1807 * Create event for tools menues
1809 * @author Anika Henke <anika@selfthinker.org>
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
1815 function tpl_toolsevent($toolsname, $items, $view = 'main') {
1816 dbg_deprecated('see devel:menus');
1817 $data = array(
1818 'view' => $view,
1819 'items' => $items
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;
1827 $evt->advise_after();
1830 //Setup VIM: ex: et ts=4 :