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