3 * DokuWiki template functions
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
9 use dokuwiki\Extension\AdminPlugin
;
10 use dokuwiki\Extension\Event
;
11 use dokuwiki\File\PageResolver
;
14 * Access a template file
16 * Returns the path to the given file inside the current template, uses
17 * default template if the custom version doesn't exist.
19 * @author Andreas Gohr <andi@splitbrain.org>
23 function template($file) {
26 if(@is_readable
(DOKU_INC
.'lib/tpl/'.$conf['template'].'/'.$file))
27 return DOKU_INC
.'lib/tpl/'.$conf['template'].'/'.$file;
29 return DOKU_INC
.'lib/tpl/dokuwiki/'.$file;
33 * Convenience function to access template dir from local FS
35 * This replaces the deprecated DOKU_TPLINC constant
37 * @author Andreas Gohr <andi@splitbrain.org>
38 * @param string $tpl The template to use, default to current one
41 function tpl_incdir($tpl='') {
43 if(!$tpl) $tpl = $conf['template'];
44 return DOKU_INC
.'lib/tpl/'.$tpl.'/';
48 * Convenience function to access template dir from web
50 * This replaces the deprecated DOKU_TPL constant
52 * @author Andreas Gohr <andi@splitbrain.org>
53 * @param string $tpl The template to use, default to current one
56 function tpl_basedir($tpl='') {
58 if(!$tpl) $tpl = $conf['template'];
59 return DOKU_BASE
.'lib/tpl/'.$tpl.'/';
65 * This function is used for printing all the usual content
66 * (defined by the global $ACT var) by calling the appropriate
67 * outputfunction(s) from html.php
69 * Everything that doesn't use the main template file isn't
70 * handled by this function. ACL stuff is not done here either.
72 * @author Andreas Gohr <andi@splitbrain.org>
74 * @triggers TPL_ACT_RENDER
75 * @triggers TPL_CONTENT_DISPLAY
76 * @param bool $prependTOC should the TOC be displayed here?
77 * @return bool true if any output
79 function tpl_content($prependTOC = true) {
82 $INFO['prependTOC'] = $prependTOC;
85 Event
::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
86 $html_output = ob_get_clean();
87 Event
::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
89 return !empty($html_output);
93 * Default Action of TPL_ACT_RENDER
97 function tpl_content_core() {
98 $router = \dokuwiki\ActionRouter
::getInstance();
100 $router->getAction()->tplContent();
101 } catch(\dokuwiki\Action\Exception\FatalException
$e) {
102 // there was no content for the action
103 msg(hsc($e->getMessage()), -1);
110 * Places the TOC where the function is called
112 * If you use this you most probably want to call tpl_content with
115 * @author Andreas Gohr <andi@splitbrain.org>
117 * @param bool $return Should the TOC be returned instead to be printed?
120 function tpl_toc($return = false) {
131 // if a TOC was prepared in global scope, always use it
133 } elseif(($ACT == 'show' ||
substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
134 // get TOC from metadata, render if neccessary
135 $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE
);
136 if(isset($meta['internal']['toc'])) {
137 $tocok = $meta['internal']['toc'];
141 $toc = isset($meta['description']['tableofcontents']) ?
$meta['description']['tableofcontents'] : null;
142 if(!$tocok ||
!is_array($toc) ||
!$conf['tocminheads'] ||
count($toc) < $conf['tocminheads']) {
145 } elseif($ACT == 'admin') {
146 // try to load admin plugin TOC
147 /** @var $plugin AdminPlugin */
148 if ($plugin = plugin_getRequestAdminPlugin()) {
149 $toc = $plugin->getTOC();
150 $TOC = $toc; // avoid later rebuild
154 Event
::createAndTrigger('TPL_TOC_RENDER', $toc, null, false);
155 $html = html_TOC($toc);
156 if($return) return $html;
162 * Handle the admin page contents
164 * @author Andreas Gohr <andi@splitbrain.org>
168 function tpl_admin() {
174 $class = $INPUT->str('page');
176 $pluginlist = plugin_list('admin');
178 if(in_array($class, $pluginlist)) {
179 // attempt to load the plugin
180 /** @var $plugin AdminPlugin */
181 $plugin = plugin_load('admin', $class);
185 if($plugin !== null) {
186 if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
187 if($INFO['prependTOC']) tpl_toc();
190 $admin = new dokuwiki\Ui\
Admin();
197 * Print the correct HTML meta headers
199 * This has to go into the head section of your template.
201 * @author Andreas Gohr <andi@splitbrain.org>
203 * @triggers TPL_METAHEADER_OUTPUT
204 * @param bool $alt Should feeds and alternative format links be added?
207 function tpl_metaheaders($alt = true) {
216 global $updateVersion;
217 /** @var Input $INPUT */
220 // prepare the head array
223 // prepare seed for js and css
224 $tseed = $updateVersion;
225 $depends = getConfigFiles('main');
226 $depends[] = DOKU_CONF
."tpl/".$conf['template']."/style.ini";
227 foreach($depends as $f) $tseed .= @filemtime
($f);
228 $tseed = md5($tseed);
231 $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
232 if(actionOK('search')) {
233 $head['link'][] = array(
234 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
235 'href'=> DOKU_BASE
.'lib/exe/opensearch.php', 'title'=> $conf['title']
239 $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE
);
240 if(actionOK('index')) {
241 $head['link'][] = array(
242 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
243 'title'=> $lang['btn_index']
247 if (actionOK('manifest')) {
248 $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE
.'lib/exe/manifest.php');
251 $styleUtil = new \dokuwiki\
StyleUtils();
252 $styleIni = $styleUtil->cssStyleini();
253 $replacements = $styleIni['replacements'];
254 if (!empty($replacements['__theme_color__'])) {
255 $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']);
259 if(actionOK('rss')) {
260 $head['link'][] = array(
261 'rel' => 'alternate', 'type'=> 'application/rss+xml',
262 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE
.'feed.php'
264 $head['link'][] = array(
265 'rel' => 'alternate', 'type'=> 'application/rss+xml',
266 'title'=> $lang['currentns'],
267 'href' => DOKU_BASE
.'feed.php?mode=list&ns='.(isset($INFO) ?
$INFO['namespace'] : '')
270 if(($ACT == 'show' ||
$ACT == 'search') && $INFO['writable']) {
271 $head['link'][] = array(
273 'title'=> $lang['btn_edit'],
274 'href' => wl($ID, 'do=edit', false, '&')
278 if(actionOK('rss') && $ACT == 'search') {
279 $head['link'][] = array(
280 'rel' => 'alternate', 'type'=> 'application/rss+xml',
281 'title'=> $lang['searchresult'],
282 'href' => DOKU_BASE
.'feed.php?mode=search&q='.$QUERY
286 if(actionOK('export_xhtml')) {
287 $head['link'][] = array(
288 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
289 'href'=> exportlink($ID, 'xhtml', '', false, '&')
293 if(actionOK('export_raw')) {
294 $head['link'][] = array(
295 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
296 'href'=> exportlink($ID, 'raw', '', false, '&')
301 // setup robot tags appropriate for different modes
302 if(($ACT == 'show' ||
$ACT == 'export_xhtml') && !$REV) {
303 if($INFO['exists']) {
305 if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
306 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
308 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
310 $canonicalUrl = wl($ID, '', true, '&');
311 if ($ID == $conf['start']) {
312 $canonicalUrl = DOKU_URL
;
314 $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
316 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
318 } elseif(defined('DOKU_MEDIADETAIL')) {
319 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
321 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
325 if($ACT == 'show' ||
$ACT == 'export_xhtml') {
326 // keywords (explicit or implicit)
327 if(!empty($INFO['meta']['subject'])) {
328 $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
330 $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
335 $head['link'][] = array(
336 'rel' => 'stylesheet',
337 'href'=> DOKU_BASE
.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
340 $script = "var NS='".(isset($INFO)?
$INFO['namespace']:'')."';";
341 if($conf['useacl'] && $INPUT->server
->str('REMOTE_USER')) {
342 $script .= "var SIG=".toolbar_signature().";";
345 $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
346 $head['script'][] = array('_data'=> $script);
349 $jquery = getCdnUrls();
350 foreach($jquery as $src) {
351 $head['script'][] = array(
354 ) +
($conf['defer_js'] ?
[ 'defer' => 'defer'] : []);
357 // load our javascript dispatcher
358 $head['script'][] = array(
360 'src' => DOKU_BASE
.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed,
361 ) +
($conf['defer_js'] ?
[ 'defer' => 'defer'] : []);
363 // trigger event here
364 Event
::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
369 * prints the array build by tpl_metaheaders
371 * $data is an array of different header tags. Each tag can have multiple
372 * instances. Attributes are given as key value pairs. Values will be HTML
373 * encoded automatically so they should be provided as is in the $data array.
375 * For tags having a body attribute specify the body data in the special
376 * attribute '_data'. This field will NOT BE ESCAPED automatically.
378 * @author Andreas Gohr <andi@splitbrain.org>
382 function _tpl_metaheaders_action($data) {
383 foreach($data as $tag => $inst) {
384 if($tag == 'script') {
385 echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
387 foreach($inst as $attr) {
388 if ( empty($attr) ) { continue; }
389 echo '<', $tag, ' ', buildAttributes($attr);
390 if(isset($attr['_data']) ||
$tag == 'script') {
391 if($tag == 'script' && isset($attr['_data']))
392 $attr['_data'] = "/*<![CDATA[*/".
396 echo '>', isset($attr['_data']) ?
$attr['_data'] : '', '</', $tag, '>';
402 if($tag == 'script') {
403 echo "<!--<![endif]-->\n";
411 * Just builds a link.
413 * @author Andreas Gohr <andi@splitbrain.org>
416 * @param string $name
417 * @param string $more
418 * @param bool $return if true return the link html, otherwise print
419 * @return bool|string html of the link, or true if printed
421 function tpl_link($url, $name, $more = '', $return = false) {
422 $out = '<a href="'.$url.'" ';
423 if($more) $out .= ' '.$more;
424 $out .= ">$name</a>";
425 if($return) return $out;
431 * Prints a link to a WikiPage
433 * Wrapper around html_wikilink
435 * @author Andreas Gohr <andi@splitbrain.org>
437 * @param string $id page id
438 * @param string|null $name the name of the link
439 * @param bool $return
440 * @return true|string
442 function tpl_pagelink($id, $name = null, $return = false) {
443 $out = '<bdi>'.html_wikilink($id, $name).'</bdi>';
444 if($return) return $out;
450 * get the parent page
452 * Tries to find out which page is parent.
453 * returns false if none is available
455 * @author Andreas Gohr <andi@splitbrain.org>
457 * @param string $id page id
458 * @return false|string
460 function tpl_getparent($id) {
461 $resolver = new PageResolver('root');
463 $parent = getNS($id).':';
464 $parent = $resolver->resolveId($parent);
466 $pos = strrpos(getNS($id), ':');
467 $parent = substr($parent, 0, $pos).':';
468 $parent = $resolver->resolveId($parent);
469 if($parent == $id) return false;
475 * Print one of the buttons
477 * @author Adrian Lang <mail@adrianlang.de>
478 * @see tpl_get_action
480 * @param string $type
481 * @param bool $return
482 * @return bool|string html, or false if no data, true if printed
483 * @deprecated 2017-09-01 see devel:menus
485 function tpl_button($type, $return = false) {
486 dbg_deprecated('see devel:menus');
487 $data = tpl_get_action($type);
488 if($data === false) {
490 } elseif(!is_array($data)) {
491 $out = sprintf($data, 'button');
494 * @var string $accesskey
496 * @var string $method
500 if($id === '#dokuwiki__top') {
501 $out = html_topbtn();
503 $out = html_btn($type, $id, $accesskey, $params, $method);
506 if($return) return $out;
512 * Like the action buttons but links
514 * @author Adrian Lang <mail@adrianlang.de>
515 * @see tpl_get_action
517 * @param string $type action command
518 * @param string $pre prefix of link
519 * @param string $suf suffix of link
520 * @param string $inner innerHML of link
521 * @param bool $return if true it returns html, otherwise prints
522 * @return bool|string html or false if no data, true if printed
523 * @deprecated 2017-09-01 see devel:menus
525 function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
526 dbg_deprecated('see devel:menus');
528 $data = tpl_get_action($type);
529 if($data === false) {
531 } elseif(!is_array($data)) {
532 $out = sprintf($data, 'link');
535 * @var string $accesskey
537 * @var string $method
538 * @var bool $nofollow
540 * @var string $replacement
543 if(strpos($id, '#') === 0) {
546 $linktarget = wl($id, $params);
548 $caption = $lang['btn_'.$type];
549 if(strpos($caption, '%s')){
550 $caption = sprintf($caption, $replacement);
552 $akey = $addTitle = '';
554 $akey = 'accesskey="'.$accesskey.'" ';
555 $addTitle = ' ['.strtoupper($accesskey).']';
557 $rel = $nofollow ?
'rel="nofollow" ' : '';
559 $linktarget, $pre.(($inner) ?
$inner : $caption).$suf,
560 'class="action '.$type.'" '.
562 'title="'.hsc($caption).$addTitle.'"', true
565 if($return) return $out;
571 * Check the actions and get data for buttons and links
573 * @author Andreas Gohr <andi@splitbrain.org>
574 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
575 * @author Adrian Lang <mail@adrianlang.de>
577 * @param string $type
578 * @return array|bool|string
579 * @deprecated 2017-09-01 see devel:menus
581 function tpl_get_action($type) {
582 dbg_deprecated('see devel:menus');
583 if($type == 'history') $type = 'revisions';
584 if($type == 'subscription') $type = 'subscribe';
585 if($type == 'img_backto') $type = 'imgBackto';
587 $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
588 if(class_exists($class)) {
590 /** @var \dokuwiki\Menu\Item\AbstractItem $item */
592 $data = $item->getLegacyData();
594 } catch(\RuntimeException
$ignored) {
604 'params' => array('do' => $type),
611 $evt = new Event('TPL_ACTION_GET', $data);
612 if($evt->advise_before()) {
613 //handle unknown types
615 $data = '[unknown %s type]';
618 $evt->advise_after();
625 * Wrapper around tpl_button() and tpl_actionlink()
627 * @author Anika Henke <anika@selfthinker.org>
629 * @param string $type action command
630 * @param bool $link link or form button?
631 * @param string|bool $wrapper HTML element wrapper
632 * @param bool $return return or print
633 * @param string $pre prefix for links
634 * @param string $suf suffix for links
635 * @param string $inner inner HTML for links
636 * @return bool|string
637 * @deprecated 2017-09-01 see devel:menus
639 function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
640 dbg_deprecated('see devel:menus');
643 $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
645 $out .= tpl_button($type, true);
647 if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
649 if($return) return $out;
651 return $out ?
true : false;
655 * Print the search form
657 * If the first parameter is given a div with the ID 'qsearch_out' will
658 * be added which instructs the ajax pagequicksearch to kick in and place
659 * its output into this div. The second parameter controls the propritary
660 * attribute autocomplete. If set to false this attribute will be set with an
661 * value of "off" to instruct the browser to disable it's own built in
662 * autocompletion feature (MSIE and Firefox)
664 * @author Andreas Gohr <andi@splitbrain.org>
667 * @param bool $autocomplete
670 function tpl_searchform($ajax = true, $autocomplete = true) {
676 // don't print the search form if search action has been disabled
677 if(!actionOK('search')) return false;
679 $searchForm = new dokuwiki\Form\
Form([
684 'id' => 'dw__search',
686 $searchForm->addTagOpen('div')->addClass('no');
687 $searchForm->setHiddenField('do', 'search');
688 $searchForm->setHiddenField('id', $ID);
689 $searchForm->addTextInput('q')
694 'placeholder' => $lang['btn_search'],
695 'autocomplete' => $autocomplete ?
'on' : 'off',
698 ->val($ACT === 'search' ?
$QUERY : '')
701 $searchForm->addButton('', $lang['btn_search'])->attrs([
703 'title' => $lang['btn_search'],
706 $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
707 $searchForm->addTagClose('div');
709 $searchForm->addTagClose('div');
711 echo $searchForm->toHTML('QuickSearch');
717 * Print the breadcrumbs trace
719 * @author Andreas Gohr <andi@splitbrain.org>
721 * @param string $sep Separator between entries
722 * @param bool $return return or print
723 * @return bool|string
725 function tpl_breadcrumbs($sep = null, $return = false) {
730 if(!$conf['breadcrumbs']) return false;
733 if(is_null($sep)) $sep = '•';
737 $crumbs = breadcrumbs(); //setup crumb trace
739 $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
741 //render crumbs, highlight the last one
742 $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>';
743 $last = count($crumbs);
745 foreach($crumbs as $id => $name) {
748 if($i == $last) $out .= '<span class="curid">';
749 $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) . '</bdi>';
750 if($i == $last) $out .= '</span>';
752 if($return) return $out;
754 return $out ?
true : false;
758 * Hierarchical breadcrumbs
760 * This code was suggested as replacement for the usual breadcrumbs.
761 * It only makes sense with a deep site structure.
763 * @author Andreas Gohr <andi@splitbrain.org>
764 * @author Nigel McNie <oracle.shinoda@gmail.com>
765 * @author Sean Coates <sean@caedmon.net>
766 * @author <fredrik@averpil.com>
767 * @todo May behave strangely in RTL languages
769 * @param string $sep Separator between entries
770 * @param bool $return return or print
771 * @return bool|string
773 function tpl_youarehere($sep = null, $return = false) {
779 if(!$conf['youarehere']) return false;
782 if(is_null($sep)) $sep = ' » ';
786 $parts = explode(':', $ID);
787 $count = count($parts);
789 $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
791 // always print the startpage
792 $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
794 // print intermediate namespace links
796 for($i = 0; $i < $count - 1; $i++
) {
797 $part .= $parts[$i].':';
799 if($page == $conf['start']) continue; // Skip startpage
802 $out .= $sep . tpl_pagelink($page, null, true);
805 // print current page, skipping start page, skipping for namespace index
807 $page = (new PageResolver('root'))->resolveId($page);
808 if ($page == $part . $parts[$i]) {
809 if ($return) return $out;
814 $page = $part.$parts[$i];
815 if($page == $conf['start']) {
816 if($return) return $out;
821 $out .= tpl_pagelink($page, null, true);
822 if($return) return $out;
824 return $out ?
true : false;
828 * Print info if the user is logged in
829 * and show full name in that case
831 * Could be enhanced with a profile link in future?
833 * @author Andreas Gohr <andi@splitbrain.org>
837 function tpl_userinfo() {
839 /** @var Input $INPUT */
842 if($INPUT->server
->str('REMOTE_USER')) {
843 print $lang['loggedinas'].' '.userlink();
850 * Print some info about the current page
852 * @author Andreas Gohr <andi@splitbrain.org>
854 * @param bool $ret return content instead of printing it
855 * @return bool|string
857 function tpl_pageinfo($ret = false) {
863 // return if we are not allowed to view the page
864 if(!auth_quickaclcheck($ID)) {
868 // prepare date and path
869 $fn = $INFO['filepath'];
870 if(!$conf['fullpath']) {
872 $fn = str_replace($conf['olddir'].'/', '', $fn);
874 $fn = str_replace($conf['datadir'].'/', '', $fn);
877 $fn = utf8_decodeFN($fn);
878 $date = dformat($INFO['lastmod']);
881 if($INFO['exists']) {
883 $out .= '<bdi>'.$fn.'</bdi>';
885 $out .= $lang['lastmod'];
888 if($INFO['editor']) {
889 $out .= ' '.$lang['by'].' ';
890 $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
892 $out .= ' ('.$lang['external_edit'].')';
894 if($INFO['locked']) {
896 $out .= $lang['lockedby'];
898 $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
911 * Prints or returns the name of the given page (current one if none given).
913 * If useheading is enabled this will use the first headline else
914 * the given ID is used.
916 * @author Andreas Gohr <andi@splitbrain.org>
918 * @param string $id page id
919 * @param bool $ret return content instead of printing
920 * @return bool|string
922 function tpl_pagetitle($id = null, $ret = false) {
923 global $ACT, $INPUT, $conf, $lang;
931 if(useHeading('navigation')) {
932 $first_heading = p_get_first_heading($id);
933 if($first_heading) $name = $first_heading;
936 // default page title is the page name, modify with the current action
940 $page_title = $lang['btn_admin'];
941 // try to get the plugin name
942 /** @var $plugin AdminPlugin */
943 if ($plugin = plugin_getRequestAdminPlugin()){
944 $plugin_title = $plugin->getMenuText($conf['lang']);
945 $page_title = $plugin_title ?
$plugin_title : $plugin->getPluginName();
954 $page_title = $lang['btn_'.$ACT];
960 $page_title = $lang['btn_'.$ACT];
966 $page_title = "✎ ".$name;
970 $page_title = $name . ' - ' . $lang['btn_revs'];
976 $page_title = $name . ' - ' . $lang['btn_'.$ACT];
979 default : // SHOW and anything else not included
984 return hsc($page_title);
986 print hsc($page_title);
992 * Returns the requested EXIF/IPTC tag from the current image
994 * If $tags is an array all given tags are tried until a
995 * value is found. If no value is found $alt is returned.
997 * Which texts are known is defined in the functions _exifTagNames
998 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
999 * to the names of the latter one)
1001 * Only allowed in: detail.php
1003 * @author Andreas Gohr <andi@splitbrain.org>
1005 * @param array|string $tags tag or array of tags to try
1006 * @param string $alt alternative output if no data was found
1007 * @param null|string $src the image src, uses global $SRC if not given
1010 function tpl_img_getTag($tags, $alt = '', $src = null) {
1012 global $SRC, $imgMeta;
1014 if(is_null($src)) $src = $SRC;
1015 if(is_null($src)) return $alt;
1017 if(!isset($imgMeta) ||
$imgMeta === null) $imgMeta = new JpegMeta($src);
1018 if($imgMeta === false) return $alt;
1019 $info = cleanText($imgMeta->getField($tags));
1020 if($info == false) return $alt;
1026 * Garbage collects up the open JpegMeta object.
1028 function tpl_img_close(){
1034 * Returns a description list of the metatags of the current image
1036 * @return string html of description list
1038 function tpl_img_meta() {
1041 $tags = tpl_get_img_meta();
1044 foreach($tags as $tag) {
1045 $label = $lang[$tag['langkey']];
1046 if(!$label) $label = $tag['langkey'] . ':';
1048 echo '<dt>'.$label.'</dt><dd>';
1049 if ($tag['type'] == 'date') {
1050 echo dformat($tag['value']);
1052 echo hsc($tag['value']);
1060 * Returns metadata as configured in mediameta config file, ready for creating html
1062 * @return array with arrays containing the entries:
1063 * - string langkey key to lookup in the $lang var, if not found printed as is
1064 * - string type type of value
1065 * - string value tag value (unescaped)
1067 function tpl_get_img_meta() {
1069 $config_files = getConfigFiles('mediameta');
1070 foreach ($config_files as $config_file) {
1071 if(file_exists($config_file)) {
1072 include($config_file);
1075 /** @var array $fields the included array with metadata */
1078 foreach($fields as $tag){
1080 if (!empty($tag[0])) {
1081 $t = array($tag[0]);
1083 if(isset($tag[3]) && is_array($tag[3])) {
1084 $t = array_merge($t,$tag[3]);
1086 $value = tpl_img_getTag($t);
1088 $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1095 * Prints the image with a link to the full sized version
1097 * Only allowed in: detail.php
1099 * @triggers TPL_IMG_DISPLAY
1100 * @param $maxwidth int - maximal width of the image
1101 * @param $maxheight int - maximal height of the image
1102 * @param $link bool - link to the orginal size?
1103 * @param $params array - additional image attributes
1104 * @return bool Result of TPL_IMG_DISPLAY
1106 function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
1108 /** @var Input $INPUT */
1111 $w = (int) tpl_img_getTag('File.Width');
1112 $h = (int) tpl_img_getTag('File.Height');
1114 //resize to given max values
1117 if($maxwidth && $w >= $maxwidth) {
1118 $ratio = $maxwidth / $w;
1119 } elseif($maxheight && $h > $maxheight) {
1120 $ratio = $maxheight / $h;
1123 if($maxheight && $h >= $maxheight) {
1124 $ratio = $maxheight / $h;
1125 } elseif($maxwidth && $w > $maxwidth) {
1126 $ratio = $maxwidth / $w;
1130 $w = floor($ratio * $w);
1131 $h = floor($ratio * $h);
1135 $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
1136 $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
1138 //prepare attributes
1139 $alt = tpl_img_getTag('Simple.Title');
1140 if(is_null($params)) {
1145 if($w) $p['width'] = $w;
1146 if($h) $p['height'] = $h;
1147 $p['class'] = 'img_detail';
1156 $data = array('url'=> ($link ?
$url : null), 'params'=> $p);
1157 return Event
::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1161 * Default action for TPL_IMG_DISPLAY
1163 * @param array $data
1166 function _tpl_img_action($data) {
1168 $p = buildAttributes($data['params']);
1170 if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1171 print '<img '.$p.'/>';
1172 if($data['url']) print '</a>';
1177 * This function inserts a small gif which in reality is the indexer function.
1179 * Should be called somewhere at the very end of the main.php
1184 function tpl_indexerWebBug() {
1188 $p['src'] = DOKU_BASE
.'lib/exe/taskrunner.php?id='.rawurlencode($ID).
1190 $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers...
1193 $att = buildAttributes($p);
1194 print "<img $att />";
1201 * use this function to access template configuration variables
1203 * @param string $id name of the value to access
1204 * @param mixed $notset what to return if the setting is not available
1207 function tpl_getConf($id, $notset=false) {
1209 static $tpl_configloaded = false;
1211 $tpl = $conf['template'];
1213 if(!$tpl_configloaded) {
1214 $tconf = tpl_loadConfig();
1215 if($tconf !== false) {
1216 foreach($tconf as $key => $value) {
1217 if(isset($conf['tpl'][$tpl][$key])) continue;
1218 $conf['tpl'][$tpl][$key] = $value;
1220 $tpl_configloaded = true;
1224 if(isset($conf['tpl'][$tpl][$id])){
1225 return $conf['tpl'][$tpl][$id];
1234 * reads all template configuration variables
1235 * this function is automatically called by tpl_getConf()
1239 function tpl_loadConfig() {
1241 $file = tpl_incdir().'/conf/default.php';
1244 if(!file_exists($file)) return false;
1246 // load default config file
1256 * use this function to access template language variables
1258 * @param string $id key of language string
1261 function tpl_getLang($id) {
1262 static $lang = array();
1264 if(count($lang) === 0) {
1265 global $conf, $config_cascade; // definitely don't invoke "global $lang"
1267 $path = tpl_incdir() . 'lang/';
1271 // don't include once
1272 @include
($path . 'en/lang.php');
1273 foreach($config_cascade['lang']['template'] as $config_file) {
1274 if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1275 include($config_file . $conf['template'] . '/en/lang.php');
1279 if($conf['lang'] != 'en') {
1280 @include
($path . $conf['lang'] . '/lang.php');
1281 foreach($config_cascade['lang']['template'] as $config_file) {
1282 if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1283 include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1288 return isset($lang[$id]) ?
$lang[$id] : '';
1292 * Retrieve a language dependent file and pass to xhtml renderer for display
1293 * template equivalent of p_locale_xhtml()
1295 * @param string $id id of language dependent wiki page
1296 * @return string parsed contents of the wiki page in xhtml format
1298 function tpl_locale_xhtml($id) {
1299 return p_cached_output(tpl_localeFN($id));
1303 * Prepends appropriate path for a language dependent filename
1305 * @param string $id id of localized text
1306 * @return string wiki text
1308 function tpl_localeFN($id) {
1309 $path = tpl_incdir().'lang/';
1311 $file = DOKU_CONF
.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
1312 if (!file_exists($file)){
1313 $file = $path.$conf['lang'].'/'.$id.'.txt';
1314 if(!file_exists($file)){
1315 //fall back to english
1316 $file = $path.'en/'.$id.'.txt';
1323 * prints the "main content" in the mediamanager popup
1325 * Depending on the user's actions this may be a list of
1326 * files in a namespace, the meta editing dialog or
1327 * a message of referencing pages
1329 * Only allowed in mediamanager.php
1331 * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1332 * @param bool $fromajax - set true when calling this function via ajax
1333 * @param string $sort
1335 * @author Andreas Gohr <andi@splitbrain.org>
1337 function tpl_mediaContent($fromajax = false, $sort='natural') {
1343 /** @var Input $INPUT */
1346 $do = $INPUT->extract('do')->str('do');
1347 if(in_array($do, array('save', 'cancel'))) $do = '';
1350 if($INPUT->bool('edit')) {
1352 } elseif(is_array($INUSE)) {
1359 // output the content pane, wrapped in an event.
1360 if(!$fromajax) ptln('<div id="media__content">');
1361 $data = array('do' => $do);
1362 $evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1363 if($evt->advise_before()) {
1365 if($do == 'filesinuse') {
1366 media_filesinuse($INUSE, $IMG);
1367 } elseif($do == 'filelist') {
1368 media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1369 } elseif($do == 'searchlist') {
1370 media_searchlist($INPUT->str('q'), $NS, $AUTH);
1372 msg('Unknown action '.hsc($do), -1);
1375 $evt->advise_after();
1377 if(!$fromajax) ptln('</div>');
1382 * Prints the central column in full-screen media manager
1383 * Depending on the opened tab this may be a list of
1384 * files in a namespace, upload form or search form
1386 * @author Kate Arzamastseva <pshns@ukr.net>
1388 function tpl_mediaFileList() {
1393 /** @var Input $INPUT */
1396 $opened_tab = $INPUT->str('tab_files');
1397 if(!$opened_tab ||
!in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1398 if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1400 echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL
;
1402 media_tabs_files($opened_tab);
1404 echo '<div class="panelHeader">'.NL
;
1406 $tabTitle = ($NS) ?
$NS : '['.$lang['mediaroot'].']';
1407 printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
1409 if($opened_tab === 'search' ||
$opened_tab === 'files') {
1410 media_tab_files_options();
1414 echo '<div class="panelContent">'.NL
;
1415 if($opened_tab == 'files') {
1416 media_tab_files($NS, $AUTH, $JUMPTO);
1417 } elseif($opened_tab == 'upload') {
1418 media_tab_upload($NS, $AUTH, $JUMPTO);
1419 } elseif($opened_tab == 'search') {
1420 media_tab_search($NS, $AUTH);
1426 * Prints the third column in full-screen media manager
1427 * Depending on the opened tab this may be details of the
1428 * selected file, the meta editing dialog or
1429 * list of file revisions
1431 * @author Kate Arzamastseva <pshns@ukr.net>
1433 * @param string $image
1434 * @param boolean $rev
1436 function tpl_mediaFileDetails($image, $rev) {
1437 global $conf, $DEL, $lang;
1438 /** @var Input $INPUT */
1442 !file_exists(mediaFN($image)) &&
1443 file_exists(mediaMetaFN($image, '.changes')) &&
1444 $conf['mediarevisions']
1446 if(!$image ||
(!file_exists(mediaFN($image)) && !$removed) ||
$DEL) return;
1447 if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1448 $ns = getNS($image);
1449 $do = $INPUT->str('mediado');
1451 $opened_tab = $INPUT->str('tab_details');
1453 $tab_array = array('view');
1454 list(, $mime) = mimetype($image);
1455 if($mime == 'image/jpeg') {
1456 $tab_array[] = 'edit';
1458 if($conf['mediarevisions']) {
1459 $tab_array[] = 'history';
1462 if(!$opened_tab ||
!in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1463 if($INPUT->bool('edit')) $opened_tab = 'edit';
1464 if($do == 'restore') $opened_tab = 'view';
1466 media_tabs_details($image, $opened_tab);
1468 echo '<div class="panelHeader"><h3>';
1469 list($ext) = mimetype($image, false);
1470 $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
1471 $class = 'select mediafile mf_'.$class;
1472 $attributes = $rev ?
['rev' => $rev] : [];
1473 $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.
1474 $image.'</a>'.'</strong>';
1475 if($opened_tab === 'view' && $rev) {
1476 printf($lang['media_viewold'], $tabTitle, dformat($rev));
1478 printf($lang['media_'.$opened_tab], $tabTitle);
1481 echo '</h3></div>'.NL
;
1483 echo '<div class="panelContent">'.NL
;
1485 if($opened_tab == 'view') {
1486 media_tab_view($image, $ns, null, $rev);
1488 } elseif($opened_tab == 'edit' && !$removed) {
1489 media_tab_edit($image, $ns);
1491 } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1492 media_tab_history($image, $ns);
1499 * prints the namespace tree in the mediamanager popup
1501 * Only allowed in mediamanager.php
1503 * @author Andreas Gohr <andi@splitbrain.org>
1505 function tpl_mediaTree() {
1507 ptln('<div id="media__tree">');
1513 * Print a dropdown menu with all DokuWiki actions
1515 * Note: this will not use any pretty URLs
1517 * @author Andreas Gohr <andi@splitbrain.org>
1519 * @param string $empty empty option label
1520 * @param string $button submit button label
1521 * @deprecated 2017-09-01 see devel:menus
1523 function tpl_actiondropdown($empty = '', $button = '>') {
1524 dbg_deprecated('see devel:menus');
1525 $menu = new \dokuwiki\Menu\
MobileMenu();
1526 echo $menu->getDropdown($empty, $button);
1530 * Print a informational line about the used license
1532 * @author Andreas Gohr <andi@splitbrain.org>
1533 * @param string $img print image? (|button|badge)
1534 * @param bool $imgonly skip the textual description?
1535 * @param bool $return when true don't print, but return HTML
1536 * @param bool $wrap wrap in div with class="license"?
1539 function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1543 if(!$conf['license']) return '';
1544 if(!is_array($license[$conf['license']])) return '';
1545 $lic = $license[$conf['license']];
1546 $target = ($conf['target']['extern']) ?
' target="'.$conf['target']['extern'].'"' : '';
1549 if($wrap) $out .= '<div class="license">';
1551 $src = license_img($img);
1553 $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
1554 $out .= '><img src="'.DOKU_BASE
.$src.'" alt="'.$lic['name'].'" /></a>';
1555 if(!$imgonly) $out .= ' ';
1559 $out .= $lang['license'].' ';
1560 $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1561 $out .= '>'.$lic['name'].'</a></bdi>';
1563 if($wrap) $out .= '</div>';
1565 if($return) return $out;
1571 * Includes the rendered HTML of a given page
1573 * This function is useful to populate sidebars or similar features in a
1576 * @param string $pageid The page name you want to include
1577 * @param bool $print Should the content be printed or returned only
1578 * @param bool $propagate Search higher namespaces, too?
1579 * @param bool $useacl Include the page only if the ACLs check out?
1580 * @return bool|null|string
1582 function tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
1584 $pageid = page_findnearest($pageid, $useacl);
1585 } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE
) {
1588 if(!$pageid) return false;
1592 $html = p_wiki_xhtml($pageid, '', false);
1595 if($print) echo $html;
1600 * Display the subscribe form
1602 * @author Adrian Lang <lang@cosmocode.de>
1603 * @deprecated 2020-07-23
1605 function tpl_subscribe() {
1606 dbg_deprecated(\dokuwiki\Ui\Subscribe
::class .'::show()');
1607 (new \dokuwiki\Ui\Subscribe
)->show();
1611 * Tries to send already created content right to the browser
1613 * Wraps around ob_flush() and flush()
1615 * @author Andreas Gohr <andi@splitbrain.org>
1617 function tpl_flush() {
1618 if( ob_get_level() > 0 ) ob_flush();
1623 * Tries to find a ressource file in the given locations.
1625 * If a given location starts with a colon it is assumed to be a media
1626 * file, otherwise it is assumed to be relative to the current template
1628 * @param string[] $search locations to look at
1629 * @param bool $abs if to use absolute URL
1630 * @param array &$imginfo filled with getimagesize()
1631 * @param bool $fallback use fallback image if target isn't found or return 'false' if potential
1632 * false result is required
1635 * @author Andreas Gohr <andi@splitbrain.org>
1637 function tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true) {
1641 // loop through candidates until a match was found:
1642 foreach($search as $img) {
1643 if(substr($img, 0, 1) == ':') {
1644 $file = mediaFN($img);
1647 $file = tpl_incdir().$img;
1651 if(file_exists($file)) break;
1654 // manage non existing target
1655 if (!file_exists($file)) {
1656 // give result for fallback image
1657 if ($fallback === true) {
1658 $file = DOKU_INC
. 'lib/images/blank.gif';
1659 // stop process if false result is required (if $fallback is false)
1665 // fetch image data if requested
1666 if(!is_null($imginfo)) {
1667 $imginfo = getimagesize($file);
1672 $url = ml($img, '', true, '', $abs);
1674 $url = tpl_basedir().$img;
1675 if($abs) $url = DOKU_URL
.substr($url, strlen(DOKU_REL
));
1682 * PHP include a file
1684 * either from the conf directory if it exists, otherwise use
1685 * file in the template's root directory.
1687 * The function honours config cascade settings and looks for the given
1688 * file next to the ´main´ config files, in the order protected, local,
1691 * Note: no escaping or sanity checking is done here. Never pass user input
1694 * @author Anika Henke <anika@selfthinker.org>
1695 * @author Andreas Gohr <andi@splitbrain.org>
1697 * @param string $file
1699 function tpl_includeFile($file) {
1700 global $config_cascade;
1701 foreach(array('protected', 'local', 'default') as $config_group) {
1702 if(empty($config_cascade['main'][$config_group])) continue;
1703 foreach($config_cascade['main'][$config_group] as $conf_file) {
1704 $dir = dirname($conf_file);
1705 if(file_exists("$dir/$file")) {
1706 include("$dir/$file");
1712 // still here? try the template dir
1713 $file = tpl_incdir().$file;
1714 if(file_exists($file)) {
1720 * Returns <link> tag for various icon types (favicon|mobile|generic)
1722 * @author Anika Henke <anika@selfthinker.org>
1724 * @param array $types - list of icon types to display (favicon|mobile|generic)
1727 function tpl_favicon($types = array('favicon')) {
1731 foreach($types as $type) {
1734 $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1735 $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL
;
1738 $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1739 $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL
;
1742 // ideal world solution, which doesn't work in any browser yet
1743 $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1744 $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL
;
1753 * Prints full-screen media manager
1755 * @author Kate Arzamastseva <pshns@ukr.net>
1757 function tpl_media() {
1758 global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
1760 require_once DOKU_INC
.'lib/exe/mediamanager.php';
1763 $image = cleanID($INPUT->str('image'));
1764 if(isset($IMG)) $image = $IMG;
1765 if(isset($JUMPTO)) $image = $JUMPTO;
1766 if(isset($REV) && !$JUMPTO) $rev = $REV;
1768 echo '<div id="mediamanager__page">'.NL
;
1769 echo '<h1>'.$lang['btn_media'].'</h1>'.NL
;
1772 echo '<div class="panel namespaces">'.NL
;
1773 echo '<h2>'.$lang['namespaces'].'</h2>'.NL
;
1774 echo '<div class="panelHeader">';
1775 echo $lang['media_namespaces'];
1778 echo '<div class="panelContent" id="media__tree">'.NL
;
1783 echo '<div class="panel filelist">'.NL
;
1784 tpl_mediaFileList();
1787 echo '<div class="panel file">'.NL
;
1788 echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL
;
1789 tpl_mediaFileDetails($image, $rev);
1796 * Return useful layout classes
1798 * @author Anika Henke <anika@selfthinker.org>
1802 function tpl_classes() {
1803 global $ACT, $conf, $ID, $INFO;
1804 /** @var Input $INPUT */
1810 'tpl_'.$conf['template'],
1811 $INPUT->server
->bool('REMOTE_USER') ?
'loggedIn' : '',
1812 (isset($INFO['exists']) && $INFO['exists']) ?
'' : 'notFound',
1813 ($ID == $conf['start']) ?
'home' : '',
1815 return join(' ', $classes);
1819 * Create event for tools menues
1821 * @author Anika Henke <anika@selfthinker.org>
1822 * @param string $toolsname name of menu
1823 * @param array $items
1824 * @param string $view e.g. 'main', 'detail', ...
1825 * @deprecated 2017-09-01 see devel:menus
1827 function tpl_toolsevent($toolsname, $items, $view = 'main') {
1828 dbg_deprecated('see devel:menus');
1834 $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
1835 $evt = new Event($hook, $data);
1836 if($evt->advise_before()) {
1837 foreach($evt->data
['items'] as $k => $html) echo $html;
1839 $evt->advise_after();
1842 //Setup VIM: ex: et ts=4 :