3 * DokuWiki template functions
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
9 if(!defined('DOKU_INC')) die('meh.');
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>
21 function template($file) {
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;
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
39 function tpl_incdir($tpl='') {
41 if(!$tpl) $tpl = $conf['template'];
42 return DOKU_INC
.'lib/tpl/'.$tpl.'/';
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
54 function tpl_basedir($tpl='') {
56 if(!$tpl) $tpl = $conf['template'];
57 return DOKU_BASE
.'lib/tpl/'.$tpl.'/';
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) {
80 $INFO['prependTOC'] = $prependTOC;
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);
91 * Default Action of TPL_ACT_RENDER
95 function tpl_content_core() {
96 $router = \dokuwiki\ActionRouter
::getInstance();
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);
108 * Places the TOC where the function is called
110 * If you use this you most probably want to call tpl_content with
113 * @author Andreas Gohr <andi@splitbrain.org>
115 * @param bool $return Should the TOC be returned instead to be printed?
118 function tpl_toc($return = false) {
129 // if a TOC was prepared in global scope, always use it
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'];
139 $toc = isset($meta['description']['tableofcontents']) ?
$meta['description']['tableofcontents'] : null;
140 if(!$tocok ||
!is_array($toc) ||
!$conf['tocminheads'] ||
count($toc) < $conf['tocminheads']) {
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;
160 * Handle the admin page contents
162 * @author Andreas Gohr <andi@splitbrain.org>
166 function tpl_admin() {
172 $class = $INPUT->str('page');
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();
188 $admin = new dokuwiki\Ui\
Admin();
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?
205 function tpl_metaheaders($alt = true) {
214 global $updateVersion;
215 /** @var Input $INPUT */
218 // prepare the 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);
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__']);
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(
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']) {
303 if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
304 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
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);
314 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
316 } elseif(defined('DOKU_MEDIADETAIL')) {
317 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
319 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
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']));
328 $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
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()."';";
343 $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
344 $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
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);
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>
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[*/".
393 echo '>', $attr['_data'], '</', $tag, '>';
399 if($tag == 'script') {
400 echo "<!--<![endif]-->\n";
408 * Just builds a link.
410 * @author Andreas Gohr <andi@splitbrain.org>
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;
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;
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);
461 $pos = strrpos(getNS($id), ':');
462 $parent = substr($parent, 0, $pos).':';
463 resolve_pageid('', $parent, $exists);
464 if($parent == $id) return false;
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) {
485 } elseif(!is_array($data)) {
486 $out = sprintf($data, 'button');
489 * @var string $accesskey
491 * @var string $method
495 if($id === '#dokuwiki__top') {
496 $out = html_topbtn();
498 $out = html_btn($type, $id, $accesskey, $params, $method);
501 if($return) return $out;
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');
523 $data = tpl_get_action($type);
524 if($data === false) {
526 } elseif(!is_array($data)) {
527 $out = sprintf($data, 'link');
530 * @var string $accesskey
532 * @var string $method
533 * @var bool $nofollow
535 * @var string $replacement
538 if(strpos($id, '#') === 0) {
541 $linktarget = wl($id, $params);
543 $caption = $lang['btn_'.$type];
544 if(strpos($caption, '%s')){
545 $caption = sprintf($caption, $replacement);
547 $akey = $addTitle = '';
549 $akey = 'accesskey="'.$accesskey.'" ';
550 $addTitle = ' ['.strtoupper($accesskey).']';
552 $rel = $nofollow ?
'rel="nofollow" ' : '';
554 $linktarget, $pre.(($inner) ?
$inner : $caption).$suf,
555 'class="action '.$type.'" '.
557 'title="'.hsc($caption).$addTitle.'"', true
560 if($return) return $out;
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)) {
585 /** @var \dokuwiki\Menu\Item\AbstractItem $item */
587 $data = $item->getLegacyData();
589 } catch(\RuntimeException
$ignored) {
599 'params' => array('do' => $type),
606 $evt = new Doku_Event('TPL_ACTION_GET', $data);
607 if($evt->advise_before()) {
608 //handle unknown types
610 $data = '[unknown %s type]';
613 $evt->advise_after();
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');
638 $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
640 $out .= tpl_button($type, true);
642 if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
644 if($return) return $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>
662 * @param bool $autocomplete
665 function tpl_searchform($ajax = true, $autocomplete = true) {
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([
679 'id' => 'dw__search',
681 $searchForm->addTagOpen('div')->addClass('no');
682 $searchForm->setHiddenField('do', 'search');
683 $searchForm->setHiddenField('id', $ID);
684 $searchForm->addTextInput('q')
689 'placeholder' => $lang['btn_search'],
690 'autocomplete' => $autocomplete ?
'on' : 'off',
693 ->val($ACT === 'search' ?
$QUERY : '')
696 $searchForm->addButton('', $lang['btn_search'])->attrs([
698 'title' => $lang['btn_search'],
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();
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) {
726 if(!$conf['breadcrumbs']) return false;
729 if(is_null($sep)) $sep = '•';
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);
741 foreach($crumbs as $id => $name) {
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;
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) {
775 if(!$conf['youarehere']) return false;
778 if(is_null($sep)) $sep = ' » ';
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
792 for($i = 0; $i < $count - 1; $i++
) {
793 $part .= $parts[$i].':';
795 if($page == $conf['start']) continue; // Skip startpage
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;
808 $page = $part.$parts[$i];
809 if($page == $conf['start']) {
810 if($return) return $out;
815 $out .= tpl_pagelink($page, null, true);
816 if($return) return $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>
831 function tpl_userinfo() {
833 /** @var Input $INPUT */
836 if($INPUT->server
->str('REMOTE_USER')) {
837 print $lang['loggedinas'].' '.userlink();
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) {
857 // return if we are not allowed to view the page
858 if(!auth_quickaclcheck($ID)) {
862 // prepare date and path
863 $fn = $INFO['filepath'];
864 if(!$conf['fullpath']) {
866 $fn = str_replace($conf['olddir'].'/', '', $fn);
868 $fn = str_replace($conf['datadir'].'/', '', $fn);
871 $fn = utf8_decodeFN($fn);
872 $date = dformat($INFO['lastmod']);
875 if($INFO['exists']) {
877 $out .= '<bdi>'.$fn.'</bdi>';
879 $out .= $lang['lastmod'];
882 if($INFO['editor']) {
883 $out .= ' '.$lang['by'].' ';
884 $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
886 $out .= ' ('.$lang['external_edit'].')';
888 if($INFO['locked']) {
890 $out .= $lang['lockedby'];
892 $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
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;
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
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();
948 $page_title = $lang['btn_'.$ACT];
954 $page_title = $lang['btn_'.$ACT];
959 $page_title = "✎ ".$name;
963 $page_title = $name . ' - ' . $lang['btn_revs'];
969 $page_title = $name . ' - ' . $lang['btn_'.$ACT];
972 default : // SHOW and anything else not included
977 return hsc($page_title);
979 print hsc($page_title);
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
1003 function tpl_img_getTag($tags, $alt = '', $src = null) {
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;
1018 * Returns a description list of the metatags of the current image
1020 * @return string html of description list
1022 function tpl_img_meta() {
1025 $tags = tpl_get_img_meta();
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']);
1036 echo hsc($tag['value']);
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 */
1062 foreach($fields as $tag){
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);
1072 $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
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) {
1092 /** @var Input $INPUT */
1095 $w = (int) tpl_img_getTag('File.Width');
1096 $h = (int) tpl_img_getTag('File.Height');
1098 //resize to given max values
1101 if($maxwidth && $w >= $maxwidth) {
1102 $ratio = $maxwidth / $w;
1103 } elseif($maxheight && $h > $maxheight) {
1104 $ratio = $maxheight / $h;
1107 if($maxheight && $h >= $maxheight) {
1108 $ratio = $maxheight / $h;
1109 } elseif($maxwidth && $w > $maxwidth) {
1110 $ratio = $maxwidth / $w;
1114 $w = floor($ratio * $w);
1115 $h = floor($ratio * $h);
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)) {
1129 if($w) $p['width'] = $w;
1130 if($h) $p['height'] = $h;
1131 $p['class'] = 'img_detail';
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
1150 function _tpl_img_action($data) {
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>';
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
1168 function tpl_indexerWebBug() {
1172 $p['src'] = DOKU_BASE
.'lib/exe/taskrunner.php?id='.rawurlencode($ID).
1174 $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers...
1177 $att = buildAttributes($p);
1178 print "<img $att />";
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
1191 function tpl_getConf($id, $notset=false) {
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];
1218 * reads all template configuration variables
1219 * this function is automatically called by tpl_getConf()
1223 function tpl_loadConfig() {
1225 $file = tpl_incdir().'/conf/default.php';
1228 if(!file_exists($file)) return false;
1230 // load default config file
1240 * use this function to access template language variables
1242 * @param string $id key of language 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/';
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');
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/';
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';
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') {
1327 /** @var Input $INPUT */
1330 $do = $INPUT->extract('do')->str('do');
1331 if(in_array($do, array('save', 'cancel'))) $do = '';
1334 if($INPUT->bool('edit')) {
1336 } elseif(is_array($INUSE)) {
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()) {
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);
1356 msg('Unknown action '.hsc($do), -1);
1359 $evt->advise_after();
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() {
1377 /** @var Input $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
;
1390 $tabTitle = ($NS) ?
$NS : '['.$lang['mediaroot'].']';
1391 printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
1393 if($opened_tab === 'search' ||
$opened_tab === 'files') {
1394 media_tab_files_options();
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);
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 */
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));
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);
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() {
1486 ptln('<div id="media__tree">');
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 = '>') {
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"?
1518 function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
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'].'"' : '';
1528 if($wrap) $out .= '<div class="license">';
1530 $src = license_img($img);
1532 $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
1533 $out .= '><img src="'.DOKU_BASE
.$src.'" alt="'.$lic['name'].'" /></a>';
1534 if(!$imgonly) $out .= ' ';
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;
1550 * Includes the rendered HTML of a given page
1552 * This function is useful to populate sidebars or similar features in a
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) {
1563 $pageid = page_findnearest($pageid, $useacl);
1564 } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE
) {
1567 if(!$pageid) return false;
1571 $html = p_wiki_xhtml($pageid, '', false);
1574 if($print) echo $html;
1579 * Display the subscribe form
1581 * @author Adrian Lang <lang@cosmocode.de>
1583 function tpl_subscribe() {
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>';
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>';
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(
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'].
1625 // Add new subscription form
1626 echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
1627 echo '<div class="level2">';
1628 $ns = getNS($ID).':';
1630 $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
1631 $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
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);
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() {
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()
1676 * @author Andreas Gohr <andi@splitbrain.org>
1678 function tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1682 // loop through candidates until a match was found:
1683 foreach($search as $img) {
1684 if(substr($img, 0, 1) == ':') {
1685 $file = mediaFN($img);
1688 $file = tpl_incdir().$img;
1692 if(file_exists($file)) break;
1695 // fetch image data if requested
1696 if(!is_null($imginfo)) {
1697 $imginfo = getimagesize($file);
1702 $url = ml($img, '', true, '', $abs);
1704 $url = tpl_basedir().$img;
1705 if($abs) $url = DOKU_URL
.substr($url, strlen(DOKU_REL
));
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,
1721 * Note: no escaping or sanity checking is done here. Never pass user input
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");
1742 // still here? try the template dir
1743 $file = tpl_incdir().$file;
1744 if(file_exists($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)
1757 function tpl_favicon($types = array('favicon')) {
1761 foreach($types as $type) {
1764 $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1765 $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL
;
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
;
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
;
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;
1790 require_once DOKU_INC
.'lib/exe/mediamanager.php';
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
;
1802 echo '<div class="panel namespaces">'.NL
;
1803 echo '<h2>'.$lang['namespaces'].'</h2>'.NL
;
1804 echo '<div class="panelHeader">';
1805 echo $lang['media_namespaces'];
1808 echo '<div class="panelContent" id="media__tree">'.NL
;
1813 echo '<div class="panel filelist">'.NL
;
1814 tpl_mediaFileList();
1817 echo '<div class="panel file">'.NL
;
1818 echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL
;
1819 tpl_mediaFileDetails($image, $rev);
1826 * Return useful layout classes
1828 * @author Anika Henke <anika@selfthinker.org>
1832 function tpl_classes() {
1833 global $ACT, $conf, $ID, $INFO;
1834 /** @var Input $INPUT */
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');
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 :