Merge pull request #2515 from Innovailable/master
[dokuwiki.git] / inc / template.php
blob03c7bf96fe951720f0d7541eaa1576a446524d56
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 if(!defined('DOKU_INC')) die('meh.');
11 /**
12 * Access a template file
14 * Returns the path to the given file inside the current template, uses
15 * default template if the custom version doesn't exist.
17 * @author Andreas Gohr <andi@splitbrain.org>
18 * @param string $file
19 * @return string
21 function template($file) {
22 global $conf;
24 if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
25 return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
27 return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
30 /**
31 * Convenience function to access template dir from local FS
33 * This replaces the deprecated DOKU_TPLINC constant
35 * @author Andreas Gohr <andi@splitbrain.org>
36 * @param string $tpl The template to use, default to current one
37 * @return string
39 function tpl_incdir($tpl='') {
40 global $conf;
41 if(!$tpl) $tpl = $conf['template'];
42 return DOKU_INC.'lib/tpl/'.$tpl.'/';
45 /**
46 * Convenience function to access template dir from web
48 * This replaces the deprecated DOKU_TPL constant
50 * @author Andreas Gohr <andi@splitbrain.org>
51 * @param string $tpl The template to use, default to current one
52 * @return string
54 function tpl_basedir($tpl='') {
55 global $conf;
56 if(!$tpl) $tpl = $conf['template'];
57 return DOKU_BASE.'lib/tpl/'.$tpl.'/';
60 /**
61 * Print the content
63 * This function is used for printing all the usual content
64 * (defined by the global $ACT var) by calling the appropriate
65 * outputfunction(s) from html.php
67 * Everything that doesn't use the main template file isn't
68 * handled by this function. ACL stuff is not done here either.
70 * @author Andreas Gohr <andi@splitbrain.org>
72 * @triggers TPL_ACT_RENDER
73 * @triggers TPL_CONTENT_DISPLAY
74 * @param bool $prependTOC should the TOC be displayed here?
75 * @return bool true if any output
77 function tpl_content($prependTOC = true) {
78 global $ACT;
79 global $INFO;
80 $INFO['prependTOC'] = $prependTOC;
82 ob_start();
83 trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
84 $html_output = ob_get_clean();
85 trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
87 return !empty($html_output);
90 /**
91 * Default Action of TPL_ACT_RENDER
93 * @return bool
95 function tpl_content_core() {
96 $router = \dokuwiki\ActionRouter::getInstance();
97 try {
98 $router->getAction()->tplContent();
99 } catch(\dokuwiki\Action\Exception\FatalException $e) {
100 // there was no content for the action
101 msg(hsc($e->getMessage()), -1);
102 return false;
104 return true;
108 * Places the TOC where the function is called
110 * If you use this you most probably want to call tpl_content with
111 * a false argument
113 * @author Andreas Gohr <andi@splitbrain.org>
115 * @param bool $return Should the TOC be returned instead to be printed?
116 * @return string
118 function tpl_toc($return = false) {
119 global $TOC;
120 global $ACT;
121 global $ID;
122 global $REV;
123 global $INFO;
124 global $conf;
125 global $INPUT;
126 $toc = array();
128 if(is_array($TOC)) {
129 // if a TOC was prepared in global scope, always use it
130 $toc = $TOC;
131 } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
132 // get TOC from metadata, render if neccessary
133 $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
134 if(isset($meta['internal']['toc'])) {
135 $tocok = $meta['internal']['toc'];
136 } else {
137 $tocok = true;
139 $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
140 if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
141 $toc = array();
143 } elseif($ACT == 'admin') {
144 // try to load admin plugin TOC
145 /** @var $plugin DokuWiki_Admin_Plugin */
146 if ($plugin = plugin_getRequestAdminPlugin()) {
147 $toc = $plugin->getTOC();
148 $TOC = $toc; // avoid later rebuild
152 trigger_event('TPL_TOC_RENDER', $toc, null, false);
153 $html = html_TOC($toc);
154 if($return) return $html;
155 echo $html;
156 return '';
160 * Handle the admin page contents
162 * @author Andreas Gohr <andi@splitbrain.org>
164 * @return bool
166 function tpl_admin() {
167 global $INFO;
168 global $TOC;
169 global $INPUT;
171 $plugin = null;
172 $class = $INPUT->str('page');
173 if(!empty($class)) {
174 $pluginlist = plugin_list('admin');
176 if(in_array($class, $pluginlist)) {
177 // attempt to load the plugin
178 /** @var $plugin DokuWiki_Admin_Plugin */
179 $plugin = plugin_load('admin', $class);
183 if($plugin !== null) {
184 if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
185 if($INFO['prependTOC']) tpl_toc();
186 $plugin->html();
187 } else {
188 $admin = new dokuwiki\Ui\Admin();
189 $admin->show();
191 return true;
195 * Print the correct HTML meta headers
197 * This has to go into the head section of your template.
199 * @author Andreas Gohr <andi@splitbrain.org>
201 * @triggers TPL_METAHEADER_OUTPUT
202 * @param bool $alt Should feeds and alternative format links be added?
203 * @return bool
205 function tpl_metaheaders($alt = true) {
206 global $ID;
207 global $REV;
208 global $INFO;
209 global $JSINFO;
210 global $ACT;
211 global $QUERY;
212 global $lang;
213 global $conf;
214 global $updateVersion;
215 /** @var Input $INPUT */
216 global $INPUT;
218 // prepare the head array
219 $head = array();
221 // prepare seed for js and css
222 $tseed = $updateVersion;
223 $depends = getConfigFiles('main');
224 $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
225 foreach($depends as $f) $tseed .= @filemtime($f);
226 $tseed = md5($tseed);
228 // the usual stuff
229 $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
230 if(actionOK('search')) {
231 $head['link'][] = array(
232 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
233 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
237 $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
238 if(actionOK('index')) {
239 $head['link'][] = array(
240 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
241 'title'=> $lang['btn_index']
245 if (actionOK('manifest')) {
246 $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
249 $styleUtil = new \dokuwiki\StyleUtils();
250 $styleIni = $styleUtil->cssStyleini($conf['template']);
251 $replacements = $styleIni['replacements'];
252 if (!empty($replacements['__theme_color__'])) {
253 $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']);
256 if($alt) {
257 if(actionOK('rss')) {
258 $head['link'][] = array(
259 'rel' => 'alternate', 'type'=> 'application/rss+xml',
260 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
262 $head['link'][] = array(
263 'rel' => 'alternate', 'type'=> 'application/rss+xml',
264 'title'=> $lang['currentns'],
265 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
268 if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
269 $head['link'][] = array(
270 'rel' => 'edit',
271 'title'=> $lang['btn_edit'],
272 'href' => wl($ID, 'do=edit', false, '&')
276 if(actionOK('rss') && $ACT == 'search') {
277 $head['link'][] = array(
278 'rel' => 'alternate', 'type'=> 'application/rss+xml',
279 'title'=> $lang['searchresult'],
280 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
284 if(actionOK('export_xhtml')) {
285 $head['link'][] = array(
286 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
287 'href'=> exportlink($ID, 'xhtml', '', false, '&')
291 if(actionOK('export_raw')) {
292 $head['link'][] = array(
293 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
294 'href'=> exportlink($ID, 'raw', '', false, '&')
299 // setup robot tags apropriate for different modes
300 if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
301 if($INFO['exists']) {
302 //delay indexing:
303 if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
304 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
305 } else {
306 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
308 $canonicalUrl = wl($ID, '', true, '&');
309 if ($ID == $conf['start']) {
310 $canonicalUrl = DOKU_URL;
312 $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
313 } else {
314 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
316 } elseif(defined('DOKU_MEDIADETAIL')) {
317 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
318 } else {
319 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
322 // set metadata
323 if($ACT == 'show' || $ACT == 'export_xhtml') {
324 // keywords (explicit or implicit)
325 if(!empty($INFO['meta']['subject'])) {
326 $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
327 } else {
328 $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
332 // load stylesheets
333 $head['link'][] = array(
334 'rel' => 'stylesheet', 'type'=> 'text/css',
335 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
338 $script = "var NS='".$INFO['namespace']."';";
339 if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
340 $script .= "var SIG='".toolbar_signature()."';";
342 jsinfo();
343 $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
344 $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
346 // load jquery
347 $jquery = getCdnUrls();
348 foreach($jquery as $src) {
349 $head['script'][] = array(
350 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src
354 // load our javascript dispatcher
355 $head['script'][] = array(
356 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
357 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed
360 // trigger event here
361 trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
362 return true;
366 * prints the array build by tpl_metaheaders
368 * $data is an array of different header tags. Each tag can have multiple
369 * instances. Attributes are given as key value pairs. Values will be HTML
370 * encoded automatically so they should be provided as is in the $data array.
372 * For tags having a body attribute specify the body data in the special
373 * attribute '_data'. This field will NOT BE ESCAPED automatically.
375 * @author Andreas Gohr <andi@splitbrain.org>
377 * @param array $data
379 function _tpl_metaheaders_action($data) {
380 foreach($data as $tag => $inst) {
381 if($tag == 'script') {
382 echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
384 foreach($inst as $attr) {
385 if ( empty($attr) ) { continue; }
386 echo '<', $tag, ' ', buildAttributes($attr);
387 if(isset($attr['_data']) || $tag == 'script') {
388 if($tag == 'script' && $attr['_data'])
389 $attr['_data'] = "/*<![CDATA[*/".
390 $attr['_data'].
391 "\n/*!]]>*/";
393 echo '>', $attr['_data'], '</', $tag, '>';
394 } else {
395 echo '/>';
397 echo "\n";
399 if($tag == 'script') {
400 echo "<!--<![endif]-->\n";
406 * Print a link
408 * Just builds a link.
410 * @author Andreas Gohr <andi@splitbrain.org>
412 * @param string $url
413 * @param string $name
414 * @param string $more
415 * @param bool $return if true return the link html, otherwise print
416 * @return bool|string html of the link, or true if printed
418 function tpl_link($url, $name, $more = '', $return = false) {
419 $out = '<a href="'.$url.'" ';
420 if($more) $out .= ' '.$more;
421 $out .= ">$name</a>";
422 if($return) return $out;
423 print $out;
424 return true;
428 * Prints a link to a WikiPage
430 * Wrapper around html_wikilink
432 * @author Andreas Gohr <andi@splitbrain.org>
434 * @param string $id page id
435 * @param string|null $name the name of the link
436 * @param bool $return
437 * @return true|string
439 function tpl_pagelink($id, $name = null, $return = false) {
440 $out = '<bdi>'.html_wikilink($id, $name).'</bdi>';
441 if($return) return $out;
442 print $out;
443 return true;
447 * get the parent page
449 * Tries to find out which page is parent.
450 * returns false if none is available
452 * @author Andreas Gohr <andi@splitbrain.org>
454 * @param string $id page id
455 * @return false|string
457 function tpl_getparent($id) {
458 $parent = getNS($id).':';
459 resolve_pageid('', $parent, $exists);
460 if($parent == $id) {
461 $pos = strrpos(getNS($id), ':');
462 $parent = substr($parent, 0, $pos).':';
463 resolve_pageid('', $parent, $exists);
464 if($parent == $id) return false;
466 return $parent;
470 * Print one of the buttons
472 * @author Adrian Lang <mail@adrianlang.de>
473 * @see tpl_get_action
475 * @param string $type
476 * @param bool $return
477 * @return bool|string html, or false if no data, true if printed
478 * @deprecated 2017-09-01 see devel:menus
480 function tpl_button($type, $return = false) {
481 dbg_deprecated('see devel:menus');
482 $data = tpl_get_action($type);
483 if($data === false) {
484 return false;
485 } elseif(!is_array($data)) {
486 $out = sprintf($data, 'button');
487 } else {
489 * @var string $accesskey
490 * @var string $id
491 * @var string $method
492 * @var array $params
494 extract($data);
495 if($id === '#dokuwiki__top') {
496 $out = html_topbtn();
497 } else {
498 $out = html_btn($type, $id, $accesskey, $params, $method);
501 if($return) return $out;
502 echo $out;
503 return true;
507 * Like the action buttons but links
509 * @author Adrian Lang <mail@adrianlang.de>
510 * @see tpl_get_action
512 * @param string $type action command
513 * @param string $pre prefix of link
514 * @param string $suf suffix of link
515 * @param string $inner innerHML of link
516 * @param bool $return if true it returns html, otherwise prints
517 * @return bool|string html or false if no data, true if printed
518 * @deprecated 2017-09-01 see devel:menus
520 function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
521 dbg_deprecated('see devel:menus');
522 global $lang;
523 $data = tpl_get_action($type);
524 if($data === false) {
525 return false;
526 } elseif(!is_array($data)) {
527 $out = sprintf($data, 'link');
528 } else {
530 * @var string $accesskey
531 * @var string $id
532 * @var string $method
533 * @var bool $nofollow
534 * @var array $params
535 * @var string $replacement
537 extract($data);
538 if(strpos($id, '#') === 0) {
539 $linktarget = $id;
540 } else {
541 $linktarget = wl($id, $params);
543 $caption = $lang['btn_'.$type];
544 if(strpos($caption, '%s')){
545 $caption = sprintf($caption, $replacement);
547 $akey = $addTitle = '';
548 if($accesskey) {
549 $akey = 'accesskey="'.$accesskey.'" ';
550 $addTitle = ' ['.strtoupper($accesskey).']';
552 $rel = $nofollow ? 'rel="nofollow" ' : '';
553 $out = tpl_link(
554 $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
555 'class="action '.$type.'" '.
556 $akey.$rel.
557 'title="'.hsc($caption).$addTitle.'"', true
560 if($return) return $out;
561 echo $out;
562 return true;
566 * Check the actions and get data for buttons and links
568 * @author Andreas Gohr <andi@splitbrain.org>
569 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
570 * @author Adrian Lang <mail@adrianlang.de>
572 * @param string $type
573 * @return array|bool|string
574 * @deprecated 2017-09-01 see devel:menus
576 function tpl_get_action($type) {
577 dbg_deprecated('see devel:menus');
578 if($type == 'history') $type = 'revisions';
579 if($type == 'subscription') $type = 'subscribe';
580 if($type == 'img_backto') $type = 'imgBackto';
582 $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
583 if(class_exists($class)) {
584 try {
585 /** @var \dokuwiki\Menu\Item\AbstractItem $item */
586 $item = new $class;
587 $data = $item->getLegacyData();
588 $unknown = false;
589 } catch(\RuntimeException $ignored) {
590 return false;
592 } else {
593 global $ID;
594 $data = array(
595 'accesskey' => null,
596 'type' => $type,
597 'id' => $ID,
598 'method' => 'get',
599 'params' => array('do' => $type),
600 'nofollow' => true,
601 'replacement' => '',
603 $unknown = true;
606 $evt = new Doku_Event('TPL_ACTION_GET', $data);
607 if($evt->advise_before()) {
608 //handle unknown types
609 if($unknown) {
610 $data = '[unknown %s type]';
613 $evt->advise_after();
614 unset($evt);
616 return $data;
620 * Wrapper around tpl_button() and tpl_actionlink()
622 * @author Anika Henke <anika@selfthinker.org>
624 * @param string $type action command
625 * @param bool $link link or form button?
626 * @param string|bool $wrapper HTML element wrapper
627 * @param bool $return return or print
628 * @param string $pre prefix for links
629 * @param string $suf suffix for links
630 * @param string $inner inner HTML for links
631 * @return bool|string
632 * @deprecated 2017-09-01 see devel:menus
634 function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
635 dbg_deprecated('see devel:menus');
636 $out = '';
637 if($link) {
638 $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
639 } else {
640 $out .= tpl_button($type, true);
642 if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
644 if($return) return $out;
645 print $out;
646 return $out ? true : false;
650 * Print the search form
652 * If the first parameter is given a div with the ID 'qsearch_out' will
653 * be added which instructs the ajax pagequicksearch to kick in and place
654 * its output into this div. The second parameter controls the propritary
655 * attribute autocomplete. If set to false this attribute will be set with an
656 * value of "off" to instruct the browser to disable it's own built in
657 * autocompletion feature (MSIE and Firefox)
659 * @author Andreas Gohr <andi@splitbrain.org>
661 * @param bool $ajax
662 * @param bool $autocomplete
663 * @return bool
665 function tpl_searchform($ajax = true, $autocomplete = true) {
666 global $lang;
667 global $ACT;
668 global $QUERY;
669 global $ID;
671 // don't print the search form if search action has been disabled
672 if(!actionOK('search')) return false;
674 $searchForm = new dokuwiki\Form\Form([
675 'action' => wl(),
676 'method' => 'get',
677 'role' => 'search',
678 'class' => 'search',
679 'id' => 'dw__search',
680 ], true);
681 $searchForm->addTagOpen('div')->addClass('no');
682 $searchForm->setHiddenField('do', 'search');
683 $searchForm->setHiddenField('id', $ID);
684 $searchForm->addTextInput('q')
685 ->addClass('edit')
686 ->attrs([
687 'title' => '[F]',
688 'accesskey' => 'f',
689 'placeholder' => $lang['btn_search'],
690 'autocomplete' => $autocomplete ? 'on' : 'off',
692 ->id('qsearch__in')
693 ->val($ACT === 'search' ? $QUERY : '')
694 ->useInput(false)
696 $searchForm->addButton('', $lang['btn_search'])->attrs([
697 'type' => 'submit',
698 'title' => $lang['btn_search'],
700 if ($ajax) {
701 $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
702 $searchForm->addTagClose('div');
704 $searchForm->addTagClose('div');
705 trigger_event('FORM_QUICKSEARCH_OUTPUT', $searchForm);
707 echo $searchForm->toHTML();
709 return true;
713 * Print the breadcrumbs trace
715 * @author Andreas Gohr <andi@splitbrain.org>
717 * @param string $sep Separator between entries
718 * @param bool $return return or print
719 * @return bool|string
721 function tpl_breadcrumbs($sep = null, $return = false) {
722 global $lang;
723 global $conf;
725 //check if enabled
726 if(!$conf['breadcrumbs']) return false;
728 //set default
729 if(is_null($sep)) $sep = '•';
731 $out='';
733 $crumbs = breadcrumbs(); //setup crumb trace
735 $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
737 //render crumbs, highlight the last one
738 $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>';
739 $last = count($crumbs);
740 $i = 0;
741 foreach($crumbs as $id => $name) {
742 $i++;
743 $out .= $crumbs_sep;
744 if($i == $last) $out .= '<span class="curid">';
745 $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) . '</bdi>';
746 if($i == $last) $out .= '</span>';
748 if($return) return $out;
749 print $out;
750 return $out ? true : false;
754 * Hierarchical breadcrumbs
756 * This code was suggested as replacement for the usual breadcrumbs.
757 * It only makes sense with a deep site structure.
759 * @author Andreas Gohr <andi@splitbrain.org>
760 * @author Nigel McNie <oracle.shinoda@gmail.com>
761 * @author Sean Coates <sean@caedmon.net>
762 * @author <fredrik@averpil.com>
763 * @todo May behave strangely in RTL languages
765 * @param string $sep Separator between entries
766 * @param bool $return return or print
767 * @return bool|string
769 function tpl_youarehere($sep = null, $return = false) {
770 global $conf;
771 global $ID;
772 global $lang;
774 // check if enabled
775 if(!$conf['youarehere']) return false;
777 //set default
778 if(is_null($sep)) $sep = ' » ';
780 $out = '';
782 $parts = explode(':', $ID);
783 $count = count($parts);
785 $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
787 // always print the startpage
788 $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
790 // print intermediate namespace links
791 $part = '';
792 for($i = 0; $i < $count - 1; $i++) {
793 $part .= $parts[$i].':';
794 $page = $part;
795 if($page == $conf['start']) continue; // Skip startpage
797 // output
798 $out .= $sep . tpl_pagelink($page, null, true);
801 // print current page, skipping start page, skipping for namespace index
802 resolve_pageid('', $page, $exists);
803 if (isset($page) && $page == $part.$parts[$i]) {
804 if($return) return $out;
805 print $out;
806 return true;
808 $page = $part.$parts[$i];
809 if($page == $conf['start']) {
810 if($return) return $out;
811 print $out;
812 return true;
814 $out .= $sep;
815 $out .= tpl_pagelink($page, null, true);
816 if($return) return $out;
817 print $out;
818 return $out ? true : false;
822 * Print info if the user is logged in
823 * and show full name in that case
825 * Could be enhanced with a profile link in future?
827 * @author Andreas Gohr <andi@splitbrain.org>
829 * @return bool
831 function tpl_userinfo() {
832 global $lang;
833 /** @var Input $INPUT */
834 global $INPUT;
836 if($INPUT->server->str('REMOTE_USER')) {
837 print $lang['loggedinas'].' '.userlink();
838 return true;
840 return false;
844 * Print some info about the current page
846 * @author Andreas Gohr <andi@splitbrain.org>
848 * @param bool $ret return content instead of printing it
849 * @return bool|string
851 function tpl_pageinfo($ret = false) {
852 global $conf;
853 global $lang;
854 global $INFO;
855 global $ID;
857 // return if we are not allowed to view the page
858 if(!auth_quickaclcheck($ID)) {
859 return false;
862 // prepare date and path
863 $fn = $INFO['filepath'];
864 if(!$conf['fullpath']) {
865 if($INFO['rev']) {
866 $fn = str_replace($conf['olddir'].'/', '', $fn);
867 } else {
868 $fn = str_replace($conf['datadir'].'/', '', $fn);
871 $fn = utf8_decodeFN($fn);
872 $date = dformat($INFO['lastmod']);
874 // print it
875 if($INFO['exists']) {
876 $out = '';
877 $out .= '<bdi>'.$fn.'</bdi>';
878 $out .= ' · ';
879 $out .= $lang['lastmod'];
880 $out .= ' ';
881 $out .= $date;
882 if($INFO['editor']) {
883 $out .= ' '.$lang['by'].' ';
884 $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
885 } else {
886 $out .= ' ('.$lang['external_edit'].')';
888 if($INFO['locked']) {
889 $out .= ' · ';
890 $out .= $lang['lockedby'];
891 $out .= ' ';
892 $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
894 if($ret) {
895 return $out;
896 } else {
897 echo $out;
898 return true;
901 return false;
905 * Prints or returns the name of the given page (current one if none given).
907 * If useheading is enabled this will use the first headline else
908 * the given ID is used.
910 * @author Andreas Gohr <andi@splitbrain.org>
912 * @param string $id page id
913 * @param bool $ret return content instead of printing
914 * @return bool|string
916 function tpl_pagetitle($id = null, $ret = false) {
917 global $ACT, $INPUT, $conf, $lang;
919 if(is_null($id)) {
920 global $ID;
921 $id = $ID;
924 $name = $id;
925 if(useHeading('navigation')) {
926 $first_heading = p_get_first_heading($id);
927 if($first_heading) $name = $first_heading;
930 // default page title is the page name, modify with the current action
931 switch ($ACT) {
932 // admin functions
933 case 'admin' :
934 $page_title = $lang['btn_admin'];
935 // try to get the plugin name
936 /** @var $plugin DokuWiki_Admin_Plugin */
937 if ($plugin = plugin_getRequestAdminPlugin()){
938 $plugin_title = $plugin->getMenuText($conf['lang']);
939 $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
941 break;
943 // user functions
944 case 'login' :
945 case 'profile' :
946 case 'register' :
947 case 'resendpwd' :
948 $page_title = $lang['btn_'.$ACT];
949 break;
951 // wiki functions
952 case 'search' :
953 case 'index' :
954 $page_title = $lang['btn_'.$ACT];
955 break;
957 // page functions
958 case 'edit' :
959 $page_title = "✎ ".$name;
960 break;
962 case 'revisions' :
963 $page_title = $name . ' - ' . $lang['btn_revs'];
964 break;
966 case 'backlink' :
967 case 'recent' :
968 case 'subscribe' :
969 $page_title = $name . ' - ' . $lang['btn_'.$ACT];
970 break;
972 default : // SHOW and anything else not included
973 $page_title = $name;
976 if($ret) {
977 return hsc($page_title);
978 } else {
979 print hsc($page_title);
980 return true;
985 * Returns the requested EXIF/IPTC tag from the current image
987 * If $tags is an array all given tags are tried until a
988 * value is found. If no value is found $alt is returned.
990 * Which texts are known is defined in the functions _exifTagNames
991 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
992 * to the names of the latter one)
994 * Only allowed in: detail.php
996 * @author Andreas Gohr <andi@splitbrain.org>
998 * @param array|string $tags tag or array of tags to try
999 * @param string $alt alternative output if no data was found
1000 * @param null|string $src the image src, uses global $SRC if not given
1001 * @return string
1003 function tpl_img_getTag($tags, $alt = '', $src = null) {
1004 // Init Exif Reader
1005 global $SRC;
1007 if(is_null($src)) $src = $SRC;
1009 static $meta = null;
1010 if(is_null($meta)) $meta = new JpegMeta($src);
1011 if($meta === false) return $alt;
1012 $info = cleanText($meta->getField($tags));
1013 if($info == false) return $alt;
1014 return $info;
1018 * Returns a description list of the metatags of the current image
1020 * @return string html of description list
1022 function tpl_img_meta() {
1023 global $lang;
1025 $tags = tpl_get_img_meta();
1027 echo '<dl>';
1028 foreach($tags as $tag) {
1029 $label = $lang[$tag['langkey']];
1030 if(!$label) $label = $tag['langkey'] . ':';
1032 echo '<dt>'.$label.'</dt><dd>';
1033 if ($tag['type'] == 'date') {
1034 echo dformat($tag['value']);
1035 } else {
1036 echo hsc($tag['value']);
1038 echo '</dd>';
1040 echo '</dl>';
1044 * Returns metadata as configured in mediameta config file, ready for creating html
1046 * @return array with arrays containing the entries:
1047 * - string langkey key to lookup in the $lang var, if not found printed as is
1048 * - string type type of value
1049 * - string value tag value (unescaped)
1051 function tpl_get_img_meta() {
1053 $config_files = getConfigFiles('mediameta');
1054 foreach ($config_files as $config_file) {
1055 if(file_exists($config_file)) {
1056 include($config_file);
1059 /** @var array $fields the included array with metadata */
1061 $tags = array();
1062 foreach($fields as $tag){
1063 $t = array();
1064 if (!empty($tag[0])) {
1065 $t = array($tag[0]);
1067 if(is_array($tag[3])) {
1068 $t = array_merge($t,$tag[3]);
1070 $value = tpl_img_getTag($t);
1071 if ($value) {
1072 $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1075 return $tags;
1079 * Prints the image with a link to the full sized version
1081 * Only allowed in: detail.php
1083 * @triggers TPL_IMG_DISPLAY
1084 * @param $maxwidth int - maximal width of the image
1085 * @param $maxheight int - maximal height of the image
1086 * @param $link bool - link to the orginal size?
1087 * @param $params array - additional image attributes
1088 * @return bool Result of TPL_IMG_DISPLAY
1090 function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
1091 global $IMG;
1092 /** @var Input $INPUT */
1093 global $INPUT;
1094 global $REV;
1095 $w = (int) tpl_img_getTag('File.Width');
1096 $h = (int) tpl_img_getTag('File.Height');
1098 //resize to given max values
1099 $ratio = 1;
1100 if($w >= $h) {
1101 if($maxwidth && $w >= $maxwidth) {
1102 $ratio = $maxwidth / $w;
1103 } elseif($maxheight && $h > $maxheight) {
1104 $ratio = $maxheight / $h;
1106 } else {
1107 if($maxheight && $h >= $maxheight) {
1108 $ratio = $maxheight / $h;
1109 } elseif($maxwidth && $w > $maxwidth) {
1110 $ratio = $maxwidth / $w;
1113 if($ratio) {
1114 $w = floor($ratio * $w);
1115 $h = floor($ratio * $h);
1118 //prepare URLs
1119 $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
1120 $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
1122 //prepare attributes
1123 $alt = tpl_img_getTag('Simple.Title');
1124 if(is_null($params)) {
1125 $p = array();
1126 } else {
1127 $p = $params;
1129 if($w) $p['width'] = $w;
1130 if($h) $p['height'] = $h;
1131 $p['class'] = 'img_detail';
1132 if($alt) {
1133 $p['alt'] = $alt;
1134 $p['title'] = $alt;
1135 } else {
1136 $p['alt'] = '';
1138 $p['src'] = $src;
1140 $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1141 return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1145 * Default action for TPL_IMG_DISPLAY
1147 * @param array $data
1148 * @return bool
1150 function _tpl_img_action($data) {
1151 global $lang;
1152 $p = buildAttributes($data['params']);
1154 if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1155 print '<img '.$p.'/>';
1156 if($data['url']) print '</a>';
1157 return true;
1161 * This function inserts a small gif which in reality is the indexer function.
1163 * Should be called somewhere at the very end of the main.php
1164 * template
1166 * @return bool
1168 function tpl_indexerWebBug() {
1169 global $ID;
1171 $p = array();
1172 $p['src'] = DOKU_BASE.'lib/exe/taskrunner.php?id='.rawurlencode($ID).
1173 '&'.time();
1174 $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers...
1175 $p['height'] = 1;
1176 $p['alt'] = '';
1177 $att = buildAttributes($p);
1178 print "<img $att />";
1179 return true;
1183 * tpl_getConf($id)
1185 * use this function to access template configuration variables
1187 * @param string $id name of the value to access
1188 * @param mixed $notset what to return if the setting is not available
1189 * @return mixed
1191 function tpl_getConf($id, $notset=false) {
1192 global $conf;
1193 static $tpl_configloaded = false;
1195 $tpl = $conf['template'];
1197 if(!$tpl_configloaded) {
1198 $tconf = tpl_loadConfig();
1199 if($tconf !== false) {
1200 foreach($tconf as $key => $value) {
1201 if(isset($conf['tpl'][$tpl][$key])) continue;
1202 $conf['tpl'][$tpl][$key] = $value;
1204 $tpl_configloaded = true;
1208 if(isset($conf['tpl'][$tpl][$id])){
1209 return $conf['tpl'][$tpl][$id];
1212 return $notset;
1216 * tpl_loadConfig()
1218 * reads all template configuration variables
1219 * this function is automatically called by tpl_getConf()
1221 * @return array
1223 function tpl_loadConfig() {
1225 $file = tpl_incdir().'/conf/default.php';
1226 $conf = array();
1228 if(!file_exists($file)) return false;
1230 // load default config file
1231 include($file);
1233 return $conf;
1236 // language methods
1238 * tpl_getLang($id)
1240 * use this function to access template language variables
1242 * @param string $id key of language string
1243 * @return string
1245 function tpl_getLang($id) {
1246 static $lang = array();
1248 if(count($lang) === 0) {
1249 global $conf, $config_cascade; // definitely don't invoke "global $lang"
1251 $path = tpl_incdir() . 'lang/';
1253 $lang = array();
1255 // don't include once
1256 @include($path . 'en/lang.php');
1257 foreach($config_cascade['lang']['template'] as $config_file) {
1258 if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1259 include($config_file . $conf['template'] . '/en/lang.php');
1263 if($conf['lang'] != 'en') {
1264 @include($path . $conf['lang'] . '/lang.php');
1265 foreach($config_cascade['lang']['template'] as $config_file) {
1266 if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1267 include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1272 return $lang[$id];
1276 * Retrieve a language dependent file and pass to xhtml renderer for display
1277 * template equivalent of p_locale_xhtml()
1279 * @param string $id id of language dependent wiki page
1280 * @return string parsed contents of the wiki page in xhtml format
1282 function tpl_locale_xhtml($id) {
1283 return p_cached_output(tpl_localeFN($id));
1287 * Prepends appropriate path for a language dependent filename
1289 * @param string $id id of localized text
1290 * @return string wiki text
1292 function tpl_localeFN($id) {
1293 $path = tpl_incdir().'lang/';
1294 global $conf;
1295 $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
1296 if (!file_exists($file)){
1297 $file = $path.$conf['lang'].'/'.$id.'.txt';
1298 if(!file_exists($file)){
1299 //fall back to english
1300 $file = $path.'en/'.$id.'.txt';
1303 return $file;
1307 * prints the "main content" in the mediamanager popup
1309 * Depending on the user's actions this may be a list of
1310 * files in a namespace, the meta editing dialog or
1311 * a message of referencing pages
1313 * Only allowed in mediamanager.php
1315 * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1316 * @param bool $fromajax - set true when calling this function via ajax
1317 * @param string $sort
1319 * @author Andreas Gohr <andi@splitbrain.org>
1321 function tpl_mediaContent($fromajax = false, $sort='natural') {
1322 global $IMG;
1323 global $AUTH;
1324 global $INUSE;
1325 global $NS;
1326 global $JUMPTO;
1327 /** @var Input $INPUT */
1328 global $INPUT;
1330 $do = $INPUT->extract('do')->str('do');
1331 if(in_array($do, array('save', 'cancel'))) $do = '';
1333 if(!$do) {
1334 if($INPUT->bool('edit')) {
1335 $do = 'metaform';
1336 } elseif(is_array($INUSE)) {
1337 $do = 'filesinuse';
1338 } else {
1339 $do = 'filelist';
1343 // output the content pane, wrapped in an event.
1344 if(!$fromajax) ptln('<div id="media__content">');
1345 $data = array('do' => $do);
1346 $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1347 if($evt->advise_before()) {
1348 $do = $data['do'];
1349 if($do == 'filesinuse') {
1350 media_filesinuse($INUSE, $IMG);
1351 } elseif($do == 'filelist') {
1352 media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1353 } elseif($do == 'searchlist') {
1354 media_searchlist($INPUT->str('q'), $NS, $AUTH);
1355 } else {
1356 msg('Unknown action '.hsc($do), -1);
1359 $evt->advise_after();
1360 unset($evt);
1361 if(!$fromajax) ptln('</div>');
1366 * Prints the central column in full-screen media manager
1367 * Depending on the opened tab this may be a list of
1368 * files in a namespace, upload form or search form
1370 * @author Kate Arzamastseva <pshns@ukr.net>
1372 function tpl_mediaFileList() {
1373 global $AUTH;
1374 global $NS;
1375 global $JUMPTO;
1376 global $lang;
1377 /** @var Input $INPUT */
1378 global $INPUT;
1380 $opened_tab = $INPUT->str('tab_files');
1381 if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1382 if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1384 echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
1386 media_tabs_files($opened_tab);
1388 echo '<div class="panelHeader">'.NL;
1389 echo '<h3>';
1390 $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1391 printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
1392 echo '</h3>'.NL;
1393 if($opened_tab === 'search' || $opened_tab === 'files') {
1394 media_tab_files_options();
1396 echo '</div>'.NL;
1398 echo '<div class="panelContent">'.NL;
1399 if($opened_tab == 'files') {
1400 media_tab_files($NS, $AUTH, $JUMPTO);
1401 } elseif($opened_tab == 'upload') {
1402 media_tab_upload($NS, $AUTH, $JUMPTO);
1403 } elseif($opened_tab == 'search') {
1404 media_tab_search($NS, $AUTH);
1406 echo '</div>'.NL;
1410 * Prints the third column in full-screen media manager
1411 * Depending on the opened tab this may be details of the
1412 * selected file, the meta editing dialog or
1413 * list of file revisions
1415 * @author Kate Arzamastseva <pshns@ukr.net>
1417 * @param string $image
1418 * @param boolean $rev
1420 function tpl_mediaFileDetails($image, $rev) {
1421 global $conf, $DEL, $lang;
1422 /** @var Input $INPUT */
1423 global $INPUT;
1425 $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1426 if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
1427 if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1428 $ns = getNS($image);
1429 $do = $INPUT->str('mediado');
1431 $opened_tab = $INPUT->str('tab_details');
1433 $tab_array = array('view');
1434 list(, $mime) = mimetype($image);
1435 if($mime == 'image/jpeg') {
1436 $tab_array[] = 'edit';
1438 if($conf['mediarevisions']) {
1439 $tab_array[] = 'history';
1442 if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1443 if($INPUT->bool('edit')) $opened_tab = 'edit';
1444 if($do == 'restore') $opened_tab = 'view';
1446 media_tabs_details($image, $opened_tab);
1448 echo '<div class="panelHeader"><h3>';
1449 list($ext) = mimetype($image, false);
1450 $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
1451 $class = 'select mediafile mf_'.$class;
1452 $attributes = $rev ? ['rev' => $rev] : [];
1453 $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
1454 if($opened_tab === 'view' && $rev) {
1455 printf($lang['media_viewold'], $tabTitle, dformat($rev));
1456 } else {
1457 printf($lang['media_'.$opened_tab], $tabTitle);
1460 echo '</h3></div>'.NL;
1462 echo '<div class="panelContent">'.NL;
1464 if($opened_tab == 'view') {
1465 media_tab_view($image, $ns, null, $rev);
1467 } elseif($opened_tab == 'edit' && !$removed) {
1468 media_tab_edit($image, $ns);
1470 } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1471 media_tab_history($image, $ns);
1474 echo '</div>'.NL;
1478 * prints the namespace tree in the mediamanager popup
1480 * Only allowed in mediamanager.php
1482 * @author Andreas Gohr <andi@splitbrain.org>
1484 function tpl_mediaTree() {
1485 global $NS;
1486 ptln('<div id="media__tree">');
1487 media_nstree($NS);
1488 ptln('</div>');
1492 * Print a dropdown menu with all DokuWiki actions
1494 * Note: this will not use any pretty URLs
1496 * @author Andreas Gohr <andi@splitbrain.org>
1498 * @param string $empty empty option label
1499 * @param string $button submit button label
1500 * @deprecated 2017-09-01 see devel:menus
1502 function tpl_actiondropdown($empty = '', $button = '&gt;') {
1503 dbg_deprecated('see devel:menus');
1504 $menu = new \dokuwiki\Menu\MobileMenu();
1505 echo $menu->getDropdown($empty, $button);
1509 * Print a informational line about the used license
1511 * @author Andreas Gohr <andi@splitbrain.org>
1512 * @param string $img print image? (|button|badge)
1513 * @param bool $imgonly skip the textual description?
1514 * @param bool $return when true don't print, but return HTML
1515 * @param bool $wrap wrap in div with class="license"?
1516 * @return string
1518 function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1519 global $license;
1520 global $conf;
1521 global $lang;
1522 if(!$conf['license']) return '';
1523 if(!is_array($license[$conf['license']])) return '';
1524 $lic = $license[$conf['license']];
1525 $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1527 $out = '';
1528 if($wrap) $out .= '<div class="license">';
1529 if($img) {
1530 $src = license_img($img);
1531 if($src) {
1532 $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
1533 $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
1534 if(!$imgonly) $out .= ' ';
1537 if(!$imgonly) {
1538 $out .= $lang['license'].' ';
1539 $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1540 $out .= '>'.$lic['name'].'</a></bdi>';
1542 if($wrap) $out .= '</div>';
1544 if($return) return $out;
1545 echo $out;
1546 return '';
1550 * Includes the rendered HTML of a given page
1552 * This function is useful to populate sidebars or similar features in a
1553 * template
1555 * @param string $pageid The page name you want to include
1556 * @param bool $print Should the content be printed or returned only
1557 * @param bool $propagate Search higher namespaces, too?
1558 * @param bool $useacl Include the page only if the ACLs check out?
1559 * @return bool|null|string
1561 function tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
1562 if($propagate) {
1563 $pageid = page_findnearest($pageid, $useacl);
1564 } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
1565 return false;
1567 if(!$pageid) return false;
1569 global $TOC;
1570 $oldtoc = $TOC;
1571 $html = p_wiki_xhtml($pageid, '', false);
1572 $TOC = $oldtoc;
1574 if($print) echo $html;
1575 return $html;
1579 * Display the subscribe form
1581 * @author Adrian Lang <lang@cosmocode.de>
1583 function tpl_subscribe() {
1584 global $INFO;
1585 global $ID;
1586 global $lang;
1587 global $conf;
1588 $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
1590 echo p_locale_xhtml('subscr_form');
1591 echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
1592 echo '<div class="level2">';
1593 if($INFO['subscribed'] === false) {
1594 echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
1595 } else {
1596 echo '<ul>';
1597 foreach($INFO['subscribed'] as $sub) {
1598 echo '<li><div class="li">';
1599 if($sub['target'] !== $ID) {
1600 echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
1601 } else {
1602 echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
1604 $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
1605 if(!$sstl) $sstl = hsc($sub['style']);
1606 echo ' ('.$sstl.') ';
1608 echo '<a href="'.wl(
1609 $ID,
1610 array(
1611 'do' => 'subscribe',
1612 'sub_target'=> $sub['target'],
1613 'sub_style' => $sub['style'],
1614 'sub_action'=> 'unsubscribe',
1615 'sectok' => getSecurityToken()
1618 '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
1619 '</a></div></li>';
1621 echo '</ul>';
1623 echo '</div>';
1625 // Add new subscription form
1626 echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
1627 echo '<div class="level2">';
1628 $ns = getNS($ID).':';
1629 $targets = array(
1630 $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
1631 $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
1633 $styles = array(
1634 'every' => $lang['subscr_style_every'],
1635 'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
1636 'list' => sprintf($lang['subscr_style_list'], $stime_days),
1639 $form = new Doku_Form(array('id' => 'subscribe__form'));
1640 $form->startFieldset($lang['subscr_m_subscribe']);
1641 $form->addRadioSet('sub_target', $targets);
1642 $form->startFieldset($lang['subscr_m_receive']);
1643 $form->addRadioSet('sub_style', $styles);
1644 $form->addHidden('sub_action', 'subscribe');
1645 $form->addHidden('do', 'subscribe');
1646 $form->addHidden('id', $ID);
1647 $form->endFieldset();
1648 $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
1649 html_form('SUBSCRIBE', $form);
1650 echo '</div>';
1654 * Tries to send already created content right to the browser
1656 * Wraps around ob_flush() and flush()
1658 * @author Andreas Gohr <andi@splitbrain.org>
1660 function tpl_flush() {
1661 ob_flush();
1662 flush();
1666 * Tries to find a ressource file in the given locations.
1668 * If a given location starts with a colon it is assumed to be a media
1669 * file, otherwise it is assumed to be relative to the current template
1671 * @param string[] $search locations to look at
1672 * @param bool $abs if to use absolute URL
1673 * @param array &$imginfo filled with getimagesize()
1674 * @return string
1676 * @author Andreas Gohr <andi@splitbrain.org>
1678 function tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1679 $img = '';
1680 $file = '';
1681 $ismedia = false;
1682 // loop through candidates until a match was found:
1683 foreach($search as $img) {
1684 if(substr($img, 0, 1) == ':') {
1685 $file = mediaFN($img);
1686 $ismedia = true;
1687 } else {
1688 $file = tpl_incdir().$img;
1689 $ismedia = false;
1692 if(file_exists($file)) break;
1695 // fetch image data if requested
1696 if(!is_null($imginfo)) {
1697 $imginfo = getimagesize($file);
1700 // build URL
1701 if($ismedia) {
1702 $url = ml($img, '', true, '', $abs);
1703 } else {
1704 $url = tpl_basedir().$img;
1705 if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1708 return $url;
1712 * PHP include a file
1714 * either from the conf directory if it exists, otherwise use
1715 * file in the template's root directory.
1717 * The function honours config cascade settings and looks for the given
1718 * file next to the ´main´ config files, in the order protected, local,
1719 * default.
1721 * Note: no escaping or sanity checking is done here. Never pass user input
1722 * to this function!
1724 * @author Anika Henke <anika@selfthinker.org>
1725 * @author Andreas Gohr <andi@splitbrain.org>
1727 * @param string $file
1729 function tpl_includeFile($file) {
1730 global $config_cascade;
1731 foreach(array('protected', 'local', 'default') as $config_group) {
1732 if(empty($config_cascade['main'][$config_group])) continue;
1733 foreach($config_cascade['main'][$config_group] as $conf_file) {
1734 $dir = dirname($conf_file);
1735 if(file_exists("$dir/$file")) {
1736 include("$dir/$file");
1737 return;
1742 // still here? try the template dir
1743 $file = tpl_incdir().$file;
1744 if(file_exists($file)) {
1745 include($file);
1750 * Returns <link> tag for various icon types (favicon|mobile|generic)
1752 * @author Anika Henke <anika@selfthinker.org>
1754 * @param array $types - list of icon types to display (favicon|mobile|generic)
1755 * @return string
1757 function tpl_favicon($types = array('favicon')) {
1759 $return = '';
1761 foreach($types as $type) {
1762 switch($type) {
1763 case 'favicon':
1764 $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1765 $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1766 break;
1767 case 'mobile':
1768 $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1769 $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1770 break;
1771 case 'generic':
1772 // ideal world solution, which doesn't work in any browser yet
1773 $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1774 $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1775 break;
1779 return $return;
1783 * Prints full-screen media manager
1785 * @author Kate Arzamastseva <pshns@ukr.net>
1787 function tpl_media() {
1788 global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
1789 $fullscreen = true;
1790 require_once DOKU_INC.'lib/exe/mediamanager.php';
1792 $rev = '';
1793 $image = cleanID($INPUT->str('image'));
1794 if(isset($IMG)) $image = $IMG;
1795 if(isset($JUMPTO)) $image = $JUMPTO;
1796 if(isset($REV) && !$JUMPTO) $rev = $REV;
1798 echo '<div id="mediamanager__page">'.NL;
1799 echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1800 html_msgarea();
1802 echo '<div class="panel namespaces">'.NL;
1803 echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
1804 echo '<div class="panelHeader">';
1805 echo $lang['media_namespaces'];
1806 echo '</div>'.NL;
1808 echo '<div class="panelContent" id="media__tree">'.NL;
1809 media_nstree($NS);
1810 echo '</div>'.NL;
1811 echo '</div>'.NL;
1813 echo '<div class="panel filelist">'.NL;
1814 tpl_mediaFileList();
1815 echo '</div>'.NL;
1817 echo '<div class="panel file">'.NL;
1818 echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1819 tpl_mediaFileDetails($image, $rev);
1820 echo '</div>'.NL;
1822 echo '</div>'.NL;
1826 * Return useful layout classes
1828 * @author Anika Henke <anika@selfthinker.org>
1830 * @return string
1832 function tpl_classes() {
1833 global $ACT, $conf, $ID, $INFO;
1834 /** @var Input $INPUT */
1835 global $INPUT;
1837 $classes = array(
1838 'dokuwiki',
1839 'mode_'.$ACT,
1840 'tpl_'.$conf['template'],
1841 $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
1842 $INFO['exists'] ? '' : 'notFound',
1843 ($ID == $conf['start']) ? 'home' : '',
1845 return join(' ', $classes);
1849 * Create event for tools menues
1851 * @author Anika Henke <anika@selfthinker.org>
1852 * @param string $toolsname name of menu
1853 * @param array $items
1854 * @param string $view e.g. 'main', 'detail', ...
1855 * @deprecated 2017-09-01 see devel:menus
1857 function tpl_toolsevent($toolsname, $items, $view = 'main') {
1858 dbg_deprecated('see devel:menus');
1859 $data = array(
1860 'view' => $view,
1861 'items' => $items
1864 $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
1865 $evt = new Doku_Event($hook, $data);
1866 if($evt->advise_before()) {
1867 foreach($evt->data['items'] as $k => $html) echo $html;
1869 $evt->advise_after();
1872 //Setup VIM: ex: et ts=4 :