[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
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 9 use dokuwiki\Extension\AdminPlugin; 10 use dokuwiki\Extension\Event; 11 use dokuwiki\File\PageResolver; 12 13 /** 14 * Access a template file 15 * 16 * Returns the path to the given file inside the current template, uses 17 * default template if the custom version doesn't exist. 18 * 19 * @author Andreas Gohr <andi@splitbrain.org> 20 * @param string $file 21 * @return string 22 */ 23 function template($file) { 24 global $conf; 25 26 if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) 27 return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; 28 29 return DOKU_INC.'lib/tpl/dokuwiki/'.$file; 30 } 31 32 /** 33 * Convenience function to access template dir from local FS 34 * 35 * This replaces the deprecated DOKU_TPLINC constant 36 * 37 * @author Andreas Gohr <andi@splitbrain.org> 38 * @param string $tpl The template to use, default to current one 39 * @return string 40 */ 41 function tpl_incdir($tpl='') { 42 global $conf; 43 if(!$tpl) $tpl = $conf['template']; 44 return DOKU_INC.'lib/tpl/'.$tpl.'/'; 45 } 46 47 /** 48 * Convenience function to access template dir from web 49 * 50 * This replaces the deprecated DOKU_TPL constant 51 * 52 * @author Andreas Gohr <andi@splitbrain.org> 53 * @param string $tpl The template to use, default to current one 54 * @return string 55 */ 56 function tpl_basedir($tpl='') { 57 global $conf; 58 if(!$tpl) $tpl = $conf['template']; 59 return DOKU_BASE.'lib/tpl/'.$tpl.'/'; 60 } 61 62 /** 63 * Print the content 64 * 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 68 * 69 * Everything that doesn't use the main template file isn't 70 * handled by this function. ACL stuff is not done here either. 71 * 72 * @author Andreas Gohr <andi@splitbrain.org> 73 * 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 78 */ 79 function tpl_content($prependTOC = true) { 80 global $ACT; 81 global $INFO; 82 $INFO['prependTOC'] = $prependTOC; 83 84 ob_start(); 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'); 88 89 return !empty($html_output); 90 } 91 92 /** 93 * Default Action of TPL_ACT_RENDER 94 * 95 * @return bool 96 */ 97 function tpl_content_core() { 98 $router = \dokuwiki\ActionRouter::getInstance(); 99 try { 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); 104 return false; 105 } 106 return true; 107 } 108 109 /** 110 * Places the TOC where the function is called 111 * 112 * If you use this you most probably want to call tpl_content with 113 * a false argument 114 * 115 * @author Andreas Gohr <andi@splitbrain.org> 116 * 117 * @param bool $return Should the TOC be returned instead to be printed? 118 * @return string 119 */ 120 function tpl_toc($return = false) { 121 global $TOC; 122 global $ACT; 123 global $ID; 124 global $REV; 125 global $INFO; 126 global $conf; 127 global $INPUT; 128 $toc = array(); 129 130 if(is_array($TOC)) { 131 // if a TOC was prepared in global scope, always use it 132 $toc = $TOC; 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']; 138 } else { 139 $tocok = true; 140 } 141 $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 142 if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 143 $toc = array(); 144 } 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 151 } 152 } 153 154 Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false); 155 $html = html_TOC($toc); 156 if($return) return $html; 157 echo $html; 158 return ''; 159 } 160 161 /** 162 * Handle the admin page contents 163 * 164 * @author Andreas Gohr <andi@splitbrain.org> 165 * 166 * @return bool 167 */ 168 function tpl_admin() { 169 global $INFO; 170 global $TOC; 171 global $INPUT; 172 173 $plugin = null; 174 $class = $INPUT->str('page'); 175 if(!empty($class)) { 176 $pluginlist = plugin_list('admin'); 177 178 if(in_array($class, $pluginlist)) { 179 // attempt to load the plugin 180 /** @var $plugin AdminPlugin */ 181 $plugin = plugin_load('admin', $class); 182 } 183 } 184 185 if($plugin !== null) { 186 if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 187 if($INFO['prependTOC']) tpl_toc(); 188 $plugin->html(); 189 } else { 190 $admin = new dokuwiki\Ui\Admin(); 191 $admin->show(); 192 } 193 return true; 194 } 195 196 /** 197 * Print the correct HTML meta headers 198 * 199 * This has to go into the head section of your template. 200 * 201 * @author Andreas Gohr <andi@splitbrain.org> 202 * 203 * @triggers TPL_METAHEADER_OUTPUT 204 * @param bool $alt Should feeds and alternative format links be added? 205 * @return bool 206 */ 207 function tpl_metaheaders($alt = true) { 208 global $ID; 209 global $REV; 210 global $INFO; 211 global $JSINFO; 212 global $ACT; 213 global $QUERY; 214 global $lang; 215 global $conf; 216 global $updateVersion; 217 /** @var Input $INPUT */ 218 global $INPUT; 219 220 // prepare the head array 221 $head = array(); 222 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); 229 230 // the usual stuff 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'] 236 ); 237 } 238 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'] 244 ); 245 } 246 247 if (actionOK('manifest')) { 248 $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php'); 249 } 250 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__']); 256 } 257 258 if($alt) { 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' 263 ); 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'] : '') 268 ); 269 } 270 if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 271 $head['link'][] = array( 272 'rel' => 'edit', 273 'title'=> $lang['btn_edit'], 274 'href' => wl($ID, 'do=edit', false, '&') 275 ); 276 } 277 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 283 ); 284 } 285 286 if(actionOK('export_xhtml')) { 287 $head['link'][] = array( 288 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 289 'href'=> exportlink($ID, 'xhtml', '', false, '&') 290 ); 291 } 292 293 if(actionOK('export_raw')) { 294 $head['link'][] = array( 295 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 296 'href'=> exportlink($ID, 'raw', '', false, '&') 297 ); 298 } 299 } 300 301 // setup robot tags appropriate for different modes 302 if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 303 if($INFO['exists']) { 304 //delay indexing: 305 if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) { 306 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 307 } else { 308 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 309 } 310 $canonicalUrl = wl($ID, '', true, '&'); 311 if ($ID == $conf['start']) { 312 $canonicalUrl = DOKU_URL; 313 } 314 $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 315 } else { 316 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 317 } 318 } elseif(defined('DOKU_MEDIADETAIL')) { 319 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 320 } else { 321 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 322 } 323 324 // set metadata 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'])); 329 } else { 330 $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 331 } 332 } 333 334 // load stylesheets 335 $head['link'][] = array( 336 'rel' => 'stylesheet', 337 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed 338 ); 339 340 $script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';"; 341 if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 342 $script .= "var SIG=".toolbar_signature().";"; 343 } 344 jsinfo(); 345 $script .= 'var JSINFO = ' . json_encode($JSINFO).';'; 346 $head['script'][] = array('_data'=> $script); 347 348 // load jquery 349 $jquery = getCdnUrls(); 350 foreach($jquery as $src) { 351 $head['script'][] = array( 352 '_data' => '', 353 'src' => $src, 354 ) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); 355 } 356 357 // load our javascript dispatcher 358 $head['script'][] = array( 359 '_data'=> '', 360 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed, 361 ) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); 362 363 // trigger event here 364 Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 365 return true; 366 } 367 368 /** 369 * prints the array build by tpl_metaheaders 370 * 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. 374 * 375 * For tags having a body attribute specify the body data in the special 376 * attribute '_data'. This field will NOT BE ESCAPED automatically. 377 * 378 * @author Andreas Gohr <andi@splitbrain.org> 379 * 380 * @param array $data 381 */ 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 386 } 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[*/". 393 $attr['_data']. 394 "\n/*!]]>*/"; 395 396 echo '>', isset($attr['_data']) ? $attr['_data'] : '', '</', $tag, '>'; 397 } else { 398 echo '/>'; 399 } 400 echo "\n"; 401 } 402 if($tag == 'script') { 403 echo "<!--<![endif]-->\n"; 404 } 405 } 406 } 407 408 /** 409 * Print a link 410 * 411 * Just builds a link. 412 * 413 * @author Andreas Gohr <andi@splitbrain.org> 414 * 415 * @param string $url 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 420 */ 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; 426 print $out; 427 return true; 428 } 429 430 /** 431 * Prints a link to a WikiPage 432 * 433 * Wrapper around html_wikilink 434 * 435 * @author Andreas Gohr <andi@splitbrain.org> 436 * 437 * @param string $id page id 438 * @param string|null $name the name of the link 439 * @param bool $return 440 * @return true|string 441 */ 442 function tpl_pagelink($id, $name = null, $return = false) { 443 $out = '<bdi>'.html_wikilink($id, $name).'</bdi>'; 444 if($return) return $out; 445 print $out; 446 return true; 447 } 448 449 /** 450 * get the parent page 451 * 452 * Tries to find out which page is parent. 453 * returns false if none is available 454 * 455 * @author Andreas Gohr <andi@splitbrain.org> 456 * 457 * @param string $id page id 458 * @return false|string 459 */ 460 function tpl_getparent($id) { 461 $resolver = new PageResolver('root'); 462 463 $parent = getNS($id).':'; 464 $parent = $resolver->resolveId($parent); 465 if($parent == $id) { 466 $pos = strrpos(getNS($id), ':'); 467 $parent = substr($parent, 0, $pos).':'; 468 $parent = $resolver->resolveId($parent); 469 if($parent == $id) return false; 470 } 471 return $parent; 472 } 473 474 /** 475 * Print one of the buttons 476 * 477 * @author Adrian Lang <mail@adrianlang.de> 478 * @see tpl_get_action 479 * 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 484 */ 485 function tpl_button($type, $return = false) { 486 dbg_deprecated('see devel:menus'); 487 $data = tpl_get_action($type); 488 if($data === false) { 489 return false; 490 } elseif(!is_array($data)) { 491 $out = sprintf($data, 'button'); 492 } else { 493 /** 494 * @var string $accesskey 495 * @var string $id 496 * @var string $method 497 * @var array $params 498 */ 499 extract($data); 500 if($id === '#dokuwiki__top') { 501 $out = html_topbtn(); 502 } else { 503 $out = html_btn($type, $id, $accesskey, $params, $method); 504 } 505 } 506 if($return) return $out; 507 echo $out; 508 return true; 509 } 510 511 /** 512 * Like the action buttons but links 513 * 514 * @author Adrian Lang <mail@adrianlang.de> 515 * @see tpl_get_action 516 * 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 524 */ 525 function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 526 dbg_deprecated('see devel:menus'); 527 global $lang; 528 $data = tpl_get_action($type); 529 if($data === false) { 530 return false; 531 } elseif(!is_array($data)) { 532 $out = sprintf($data, 'link'); 533 } else { 534 /** 535 * @var string $accesskey 536 * @var string $id 537 * @var string $method 538 * @var bool $nofollow 539 * @var array $params 540 * @var string $replacement 541 */ 542 extract($data); 543 if(strpos($id, '#') === 0) { 544 $linktarget = $id; 545 } else { 546 $linktarget = wl($id, $params); 547 } 548 $caption = $lang['btn_'.$type]; 549 if(strpos($caption, '%s')){ 550 $caption = sprintf($caption, $replacement); 551 } 552 $akey = $addTitle = ''; 553 if($accesskey) { 554 $akey = 'accesskey="'.$accesskey.'" '; 555 $addTitle = ' ['.strtoupper($accesskey).']'; 556 } 557 $rel = $nofollow ? 'rel="nofollow" ' : ''; 558 $out = tpl_link( 559 $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 560 'class="action '.$type.'" '. 561 $akey.$rel. 562 'title="'.hsc($caption).$addTitle.'"', true 563 ); 564 } 565 if($return) return $out; 566 echo $out; 567 return true; 568 } 569 570 /** 571 * Check the actions and get data for buttons and links 572 * 573 * @author Andreas Gohr <andi@splitbrain.org> 574 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 575 * @author Adrian Lang <mail@adrianlang.de> 576 * 577 * @param string $type 578 * @return array|bool|string 579 * @deprecated 2017-09-01 see devel:menus 580 */ 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'; 586 587 $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 588 if(class_exists($class)) { 589 try { 590 /** @var \dokuwiki\Menu\Item\AbstractItem $item */ 591 $item = new $class; 592 $data = $item->getLegacyData(); 593 $unknown = false; 594 } catch(\RuntimeException $ignored) { 595 return false; 596 } 597 } else { 598 global $ID; 599 $data = array( 600 'accesskey' => null, 601 'type' => $type, 602 'id' => $ID, 603 'method' => 'get', 604 'params' => array('do' => $type), 605 'nofollow' => true, 606 'replacement' => '', 607 ); 608 $unknown = true; 609 } 610 611 $evt = new Event('TPL_ACTION_GET', $data); 612 if($evt->advise_before()) { 613 //handle unknown types 614 if($unknown) { 615 $data = '[unknown %s type]'; 616 } 617 } 618 $evt->advise_after(); 619 unset($evt); 620 621 return $data; 622 } 623 624 /** 625 * Wrapper around tpl_button() and tpl_actionlink() 626 * 627 * @author Anika Henke <anika@selfthinker.org> 628 * 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 638 */ 639 function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 640 dbg_deprecated('see devel:menus'); 641 $out = ''; 642 if($link) { 643 $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 644 } else { 645 $out .= tpl_button($type, true); 646 } 647 if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 648 649 if($return) return $out; 650 print $out; 651 return $out ? true : false; 652 } 653 654 /** 655 * Print the search form 656 * 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) 663 * 664 * @author Andreas Gohr <andi@splitbrain.org> 665 * 666 * @param bool $ajax 667 * @param bool $autocomplete 668 * @return bool 669 */ 670 function tpl_searchform($ajax = true, $autocomplete = true) { 671 global $lang; 672 global $ACT; 673 global $QUERY; 674 global $ID; 675 676 // don't print the search form if search action has been disabled 677 if(!actionOK('search')) return false; 678 679 $searchForm = new dokuwiki\Form\Form([ 680 'action' => wl(), 681 'method' => 'get', 682 'role' => 'search', 683 'class' => 'search', 684 'id' => 'dw__search', 685 ], true); 686 $searchForm->addTagOpen('div')->addClass('no'); 687 $searchForm->setHiddenField('do', 'search'); 688 $searchForm->setHiddenField('id', $ID); 689 $searchForm->addTextInput('q') 690 ->addClass('edit') 691 ->attrs([ 692 'title' => '[F]', 693 'accesskey' => 'f', 694 'placeholder' => $lang['btn_search'], 695 'autocomplete' => $autocomplete ? 'on' : 'off', 696 ]) 697 ->id('qsearch__in') 698 ->val($ACT === 'search' ? $QUERY : '') 699 ->useInput(false) 700 ; 701 $searchForm->addButton('', $lang['btn_search'])->attrs([ 702 'type' => 'submit', 703 'title' => $lang['btn_search'], 704 ]); 705 if ($ajax) { 706 $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup'); 707 $searchForm->addTagClose('div'); 708 } 709 $searchForm->addTagClose('div'); 710 711 echo $searchForm->toHTML('QuickSearch'); 712 713 return true; 714 } 715 716 /** 717 * Print the breadcrumbs trace 718 * 719 * @author Andreas Gohr <andi@splitbrain.org> 720 * 721 * @param string $sep Separator between entries 722 * @param bool $return return or print 723 * @return bool|string 724 */ 725 function tpl_breadcrumbs($sep = null, $return = false) { 726 global $lang; 727 global $conf; 728 729 //check if enabled 730 if(!$conf['breadcrumbs']) return false; 731 732 //set default 733 if(is_null($sep)) $sep = '•'; 734 735 $out=''; 736 737 $crumbs = breadcrumbs(); //setup crumb trace 738 739 $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 740 741 //render crumbs, highlight the last one 742 $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 743 $last = count($crumbs); 744 $i = 0; 745 foreach($crumbs as $id => $name) { 746 $i++; 747 $out .= $crumbs_sep; 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>'; 751 } 752 if($return) return $out; 753 print $out; 754 return $out ? true : false; 755 } 756 757 /** 758 * Hierarchical breadcrumbs 759 * 760 * This code was suggested as replacement for the usual breadcrumbs. 761 * It only makes sense with a deep site structure. 762 * 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 768 * 769 * @param string $sep Separator between entries 770 * @param bool $return return or print 771 * @return bool|string 772 */ 773 function tpl_youarehere($sep = null, $return = false) { 774 global $conf; 775 global $ID; 776 global $lang; 777 778 // check if enabled 779 if(!$conf['youarehere']) return false; 780 781 //set default 782 if(is_null($sep)) $sep = ' » '; 783 784 $out = ''; 785 786 $parts = explode(':', $ID); 787 $count = count($parts); 788 789 $out .= '<span class="bchead">'.$lang['youarehere'].' </span>'; 790 791 // always print the startpage 792 $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>'; 793 794 // print intermediate namespace links 795 $part = ''; 796 for($i = 0; $i < $count - 1; $i++) { 797 $part .= $parts[$i].':'; 798 $page = $part; 799 if($page == $conf['start']) continue; // Skip startpage 800 801 // output 802 $out .= $sep . tpl_pagelink($page, null, true); 803 } 804 805 // print current page, skipping start page, skipping for namespace index 806 if (isset($page)) { 807 $page = (new PageResolver('root'))->resolveId($page); 808 if ($page == $part . $parts[$i]) { 809 if ($return) return $out; 810 print $out; 811 return true; 812 } 813 } 814 $page = $part.$parts[$i]; 815 if($page == $conf['start']) { 816 if($return) return $out; 817 print $out; 818 return true; 819 } 820 $out .= $sep; 821 $out .= tpl_pagelink($page, null, true); 822 if($return) return $out; 823 print $out; 824 return $out ? true : false; 825 } 826 827 /** 828 * Print info if the user is logged in 829 * and show full name in that case 830 * 831 * Could be enhanced with a profile link in future? 832 * 833 * @author Andreas Gohr <andi@splitbrain.org> 834 * 835 * @return bool 836 */ 837 function tpl_userinfo() { 838 global $lang; 839 /** @var Input $INPUT */ 840 global $INPUT; 841 842 if($INPUT->server->str('REMOTE_USER')) { 843 print $lang['loggedinas'].' '.userlink(); 844 return true; 845 } 846 return false; 847 } 848 849 /** 850 * Print some info about the current page 851 * 852 * @author Andreas Gohr <andi@splitbrain.org> 853 * 854 * @param bool $ret return content instead of printing it 855 * @return bool|string 856 */ 857 function tpl_pageinfo($ret = false) { 858 global $conf; 859 global $lang; 860 global $INFO; 861 global $ID; 862 863 // return if we are not allowed to view the page 864 if(!auth_quickaclcheck($ID)) { 865 return false; 866 } 867 868 // prepare date and path 869 $fn = $INFO['filepath']; 870 if(!$conf['fullpath']) { 871 if($INFO['rev']) { 872 $fn = str_replace($conf['olddir'].'/', '', $fn); 873 } else { 874 $fn = str_replace($conf['datadir'].'/', '', $fn); 875 } 876 } 877 $fn = utf8_decodeFN($fn); 878 $date = dformat($INFO['lastmod']); 879 880 // print it 881 if($INFO['exists']) { 882 $out = ''; 883 $out .= '<bdi>'.$fn.'</bdi>'; 884 $out .= ' · '; 885 $out .= $lang['lastmod']; 886 $out .= ' '; 887 $out .= $date; 888 if($INFO['editor']) { 889 $out .= ' '.$lang['by'].' '; 890 $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 891 } else { 892 $out .= ' ('.$lang['external_edit'].')'; 893 } 894 if($INFO['locked']) { 895 $out .= ' · '; 896 $out .= $lang['lockedby']; 897 $out .= ' '; 898 $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 899 } 900 if($ret) { 901 return $out; 902 } else { 903 echo $out; 904 return true; 905 } 906 } 907 return false; 908 } 909 910 /** 911 * Prints or returns the name of the given page (current one if none given). 912 * 913 * If useheading is enabled this will use the first headline else 914 * the given ID is used. 915 * 916 * @author Andreas Gohr <andi@splitbrain.org> 917 * 918 * @param string $id page id 919 * @param bool $ret return content instead of printing 920 * @return bool|string 921 */ 922 function tpl_pagetitle($id = null, $ret = false) { 923 global $ACT, $INPUT, $conf, $lang; 924 925 if(is_null($id)) { 926 global $ID; 927 $id = $ID; 928 } 929 930 $name = $id; 931 if(useHeading('navigation')) { 932 $first_heading = p_get_first_heading($id); 933 if($first_heading) $name = $first_heading; 934 } 935 936 // default page title is the page name, modify with the current action 937 switch ($ACT) { 938 // admin functions 939 case 'admin' : 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(); 946 } 947 break; 948 949 // user functions 950 case 'login' : 951 case 'profile' : 952 case 'register' : 953 case 'resendpwd' : 954 $page_title = $lang['btn_'.$ACT]; 955 break; 956 957 // wiki functions 958 case 'search' : 959 case 'index' : 960 $page_title = $lang['btn_'.$ACT]; 961 break; 962 963 // page functions 964 case 'edit' : 965 case 'preview' : 966 $page_title = "✎ ".$name; 967 break; 968 969 case 'revisions' : 970 $page_title = $name . ' - ' . $lang['btn_revs']; 971 break; 972 973 case 'backlink' : 974 case 'recent' : 975 case 'subscribe' : 976 $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 977 break; 978 979 default : // SHOW and anything else not included 980 $page_title = $name; 981 } 982 983 if($ret) { 984 return hsc($page_title); 985 } else { 986 print hsc($page_title); 987 return true; 988 } 989 } 990 991 /** 992 * Returns the requested EXIF/IPTC tag from the current image 993 * 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. 996 * 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) 1000 * 1001 * Only allowed in: detail.php 1002 * 1003 * @author Andreas Gohr <andi@splitbrain.org> 1004 * 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 1008 * @return string 1009 */ 1010 function tpl_img_getTag($tags, $alt = '', $src = null) { 1011 // Init Exif Reader 1012 global $SRC, $imgMeta; 1013 1014 if(is_null($src)) $src = $SRC; 1015 if(is_null($src)) return $alt; 1016 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; 1021 return $info; 1022 } 1023 1024 1025 /** 1026 * Garbage collects up the open JpegMeta object. 1027 */ 1028 function tpl_img_close(){ 1029 global $imgMeta; 1030 $imgMeta = null; 1031 } 1032 1033 /** 1034 * Returns a description list of the metatags of the current image 1035 * 1036 * @return string html of description list 1037 */ 1038 function tpl_img_meta() { 1039 global $lang; 1040 1041 $tags = tpl_get_img_meta(); 1042 1043 echo '<dl>'; 1044 foreach($tags as $tag) { 1045 $label = $lang[$tag['langkey']]; 1046 if(!$label) $label = $tag['langkey'] . ':'; 1047 1048 echo '<dt>'.$label.'</dt><dd>'; 1049 if ($tag['type'] == 'date') { 1050 echo dformat($tag['value']); 1051 } else { 1052 echo hsc($tag['value']); 1053 } 1054 echo '</dd>'; 1055 } 1056 echo '</dl>'; 1057 } 1058 1059 /** 1060 * Returns metadata as configured in mediameta config file, ready for creating html 1061 * 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) 1066 */ 1067 function tpl_get_img_meta() { 1068 1069 $config_files = getConfigFiles('mediameta'); 1070 foreach ($config_files as $config_file) { 1071 if(file_exists($config_file)) { 1072 include($config_file); 1073 } 1074 } 1075 /** @var array $fields the included array with metadata */ 1076 1077 $tags = array(); 1078 foreach($fields as $tag){ 1079 $t = array(); 1080 if (!empty($tag[0])) { 1081 $t = array($tag[0]); 1082 } 1083 if(isset($tag[3]) && is_array($tag[3])) { 1084 $t = array_merge($t,$tag[3]); 1085 } 1086 $value = tpl_img_getTag($t); 1087 if ($value) { 1088 $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1089 } 1090 } 1091 return $tags; 1092 } 1093 1094 /** 1095 * Prints the image with a link to the full sized version 1096 * 1097 * Only allowed in: detail.php 1098 * 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 1105 */ 1106 function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 1107 global $IMG; 1108 /** @var Input $INPUT */ 1109 global $INPUT; 1110 global $REV; 1111 $w = (int) tpl_img_getTag('File.Width'); 1112 $h = (int) tpl_img_getTag('File.Height'); 1113 1114 //resize to given max values 1115 $ratio = 1; 1116 if($w >= $h) { 1117 if($maxwidth && $w >= $maxwidth) { 1118 $ratio = $maxwidth / $w; 1119 } elseif($maxheight && $h > $maxheight) { 1120 $ratio = $maxheight / $h; 1121 } 1122 } else { 1123 if($maxheight && $h >= $maxheight) { 1124 $ratio = $maxheight / $h; 1125 } elseif($maxwidth && $w > $maxwidth) { 1126 $ratio = $maxwidth / $w; 1127 } 1128 } 1129 if($ratio) { 1130 $w = floor($ratio * $w); 1131 $h = floor($ratio * $h); 1132 } 1133 1134 //prepare URLs 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, '&'); 1137 1138 //prepare attributes 1139 $alt = tpl_img_getTag('Simple.Title'); 1140 if(is_null($params)) { 1141 $p = array(); 1142 } else { 1143 $p = $params; 1144 } 1145 if($w) $p['width'] = $w; 1146 if($h) $p['height'] = $h; 1147 $p['class'] = 'img_detail'; 1148 if($alt) { 1149 $p['alt'] = $alt; 1150 $p['title'] = $alt; 1151 } else { 1152 $p['alt'] = ''; 1153 } 1154 $p['src'] = $src; 1155 1156 $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1157 return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1158 } 1159 1160 /** 1161 * Default action for TPL_IMG_DISPLAY 1162 * 1163 * @param array $data 1164 * @return bool 1165 */ 1166 function _tpl_img_action($data) { 1167 global $lang; 1168 $p = buildAttributes($data['params']); 1169 1170 if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1171 print '<img '.$p.'/>'; 1172 if($data['url']) print '</a>'; 1173 return true; 1174 } 1175 1176 /** 1177 * This function inserts a small gif which in reality is the indexer function. 1178 * 1179 * Should be called somewhere at the very end of the main.php 1180 * template 1181 * 1182 * @return bool 1183 */ 1184 function tpl_indexerWebBug() { 1185 global $ID; 1186 1187 $p = array(); 1188 $p['src'] = DOKU_BASE.'lib/exe/taskrunner.php?id='.rawurlencode($ID). 1189 '&'.time(); 1190 $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 1191 $p['height'] = 1; 1192 $p['alt'] = ''; 1193 $att = buildAttributes($p); 1194 print "<img $att />"; 1195 return true; 1196 } 1197 1198 /** 1199 * tpl_getConf($id) 1200 * 1201 * use this function to access template configuration variables 1202 * 1203 * @param string $id name of the value to access 1204 * @param mixed $notset what to return if the setting is not available 1205 * @return mixed 1206 */ 1207 function tpl_getConf($id, $notset=false) { 1208 global $conf; 1209 static $tpl_configloaded = false; 1210 1211 $tpl = $conf['template']; 1212 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; 1219 } 1220 $tpl_configloaded = true; 1221 } 1222 } 1223 1224 if(isset($conf['tpl'][$tpl][$id])){ 1225 return $conf['tpl'][$tpl][$id]; 1226 } 1227 1228 return $notset; 1229 } 1230 1231 /** 1232 * tpl_loadConfig() 1233 * 1234 * reads all template configuration variables 1235 * this function is automatically called by tpl_getConf() 1236 * 1237 * @return array 1238 */ 1239 function tpl_loadConfig() { 1240 1241 $file = tpl_incdir().'/conf/default.php'; 1242 $conf = array(); 1243 1244 if(!file_exists($file)) return false; 1245 1246 // load default config file 1247 include($file); 1248 1249 return $conf; 1250 } 1251 1252 // language methods 1253 /** 1254 * tpl_getLang($id) 1255 * 1256 * use this function to access template language variables 1257 * 1258 * @param string $id key of language string 1259 * @return string 1260 */ 1261 function tpl_getLang($id) { 1262 static $lang = array(); 1263 1264 if(count($lang) === 0) { 1265 global $conf, $config_cascade; // definitely don't invoke "global $lang" 1266 1267 $path = tpl_incdir() . 'lang/'; 1268 1269 $lang = array(); 1270 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'); 1276 } 1277 } 1278 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'); 1284 } 1285 } 1286 } 1287 } 1288 return isset($lang[$id]) ? $lang[$id] : ''; 1289 } 1290 1291 /** 1292 * Retrieve a language dependent file and pass to xhtml renderer for display 1293 * template equivalent of p_locale_xhtml() 1294 * 1295 * @param string $id id of language dependent wiki page 1296 * @return string parsed contents of the wiki page in xhtml format 1297 */ 1298 function tpl_locale_xhtml($id) { 1299 return p_cached_output(tpl_localeFN($id)); 1300 } 1301 1302 /** 1303 * Prepends appropriate path for a language dependent filename 1304 * 1305 * @param string $id id of localized text 1306 * @return string wiki text 1307 */ 1308 function tpl_localeFN($id) { 1309 $path = tpl_incdir().'lang/'; 1310 global $conf; 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'; 1317 } 1318 } 1319 return $file; 1320 } 1321 1322 /** 1323 * prints the "main content" in the mediamanager popup 1324 * 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 1328 * 1329 * Only allowed in mediamanager.php 1330 * 1331 * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1332 * @param bool $fromajax - set true when calling this function via ajax 1333 * @param string $sort 1334 * 1335 * @author Andreas Gohr <andi@splitbrain.org> 1336 */ 1337 function tpl_mediaContent($fromajax = false, $sort='natural') { 1338 global $IMG; 1339 global $AUTH; 1340 global $INUSE; 1341 global $NS; 1342 global $JUMPTO; 1343 /** @var Input $INPUT */ 1344 global $INPUT; 1345 1346 $do = $INPUT->extract('do')->str('do'); 1347 if(in_array($do, array('save', 'cancel'))) $do = ''; 1348 1349 if(!$do) { 1350 if($INPUT->bool('edit')) { 1351 $do = 'metaform'; 1352 } elseif(is_array($INUSE)) { 1353 $do = 'filesinuse'; 1354 } else { 1355 $do = 'filelist'; 1356 } 1357 } 1358 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()) { 1364 $do = $data['do']; 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); 1371 } else { 1372 msg('Unknown action '.hsc($do), -1); 1373 } 1374 } 1375 $evt->advise_after(); 1376 unset($evt); 1377 if(!$fromajax) ptln('</div>'); 1378 1379 } 1380 1381 /** 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 1385 * 1386 * @author Kate Arzamastseva <pshns@ukr.net> 1387 */ 1388 function tpl_mediaFileList() { 1389 global $AUTH; 1390 global $NS; 1391 global $JUMPTO; 1392 global $lang; 1393 /** @var Input $INPUT */ 1394 global $INPUT; 1395 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'; 1399 1400 echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 1401 1402 media_tabs_files($opened_tab); 1403 1404 echo '<div class="panelHeader">'.NL; 1405 echo '<h3>'; 1406 $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1407 printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 1408 echo '</h3>'.NL; 1409 if($opened_tab === 'search' || $opened_tab === 'files') { 1410 media_tab_files_options(); 1411 } 1412 echo '</div>'.NL; 1413 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); 1421 } 1422 echo '</div>'.NL; 1423 } 1424 1425 /** 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 1430 * 1431 * @author Kate Arzamastseva <pshns@ukr.net> 1432 * 1433 * @param string $image 1434 * @param boolean $rev 1435 */ 1436 function tpl_mediaFileDetails($image, $rev) { 1437 global $conf, $DEL, $lang; 1438 /** @var Input $INPUT */ 1439 global $INPUT; 1440 1441 $removed = ( 1442 !file_exists(mediaFN($image)) && 1443 file_exists(mediaMetaFN($image, '.changes')) && 1444 $conf['mediarevisions'] 1445 ); 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'); 1450 1451 $opened_tab = $INPUT->str('tab_details'); 1452 1453 $tab_array = array('view'); 1454 list(, $mime) = mimetype($image); 1455 if($mime == 'image/jpeg') { 1456 $tab_array[] = 'edit'; 1457 } 1458 if($conf['mediarevisions']) { 1459 $tab_array[] = 'history'; 1460 } 1461 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'; 1465 1466 media_tabs_details($image, $opened_tab); 1467 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)); 1477 } else { 1478 printf($lang['media_'.$opened_tab], $tabTitle); 1479 } 1480 1481 echo '</h3></div>'.NL; 1482 1483 echo '<div class="panelContent">'.NL; 1484 1485 if($opened_tab == 'view') { 1486 media_tab_view($image, $ns, null, $rev); 1487 1488 } elseif($opened_tab == 'edit' && !$removed) { 1489 media_tab_edit($image, $ns); 1490 1491 } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1492 media_tab_history($image, $ns); 1493 } 1494 1495 echo '</div>'.NL; 1496 } 1497 1498 /** 1499 * prints the namespace tree in the mediamanager popup 1500 * 1501 * Only allowed in mediamanager.php 1502 * 1503 * @author Andreas Gohr <andi@splitbrain.org> 1504 */ 1505 function tpl_mediaTree() { 1506 global $NS; 1507 ptln('<div id="media__tree">'); 1508 media_nstree($NS); 1509 ptln('</div>'); 1510 } 1511 1512 /** 1513 * Print a dropdown menu with all DokuWiki actions 1514 * 1515 * Note: this will not use any pretty URLs 1516 * 1517 * @author Andreas Gohr <andi@splitbrain.org> 1518 * 1519 * @param string $empty empty option label 1520 * @param string $button submit button label 1521 * @deprecated 2017-09-01 see devel:menus 1522 */ 1523 function tpl_actiondropdown($empty = '', $button = '>') { 1524 dbg_deprecated('see devel:menus'); 1525 $menu = new \dokuwiki\Menu\MobileMenu(); 1526 echo $menu->getDropdown($empty, $button); 1527 } 1528 1529 /** 1530 * Print a informational line about the used license 1531 * 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"? 1537 * @return string 1538 */ 1539 function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1540 global $license; 1541 global $conf; 1542 global $lang; 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'].'"' : ''; 1547 1548 $out = ''; 1549 if($wrap) $out .= '<div class="license">'; 1550 if($img) { 1551 $src = license_img($img); 1552 if($src) { 1553 $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 1554 $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 1555 if(!$imgonly) $out .= ' '; 1556 } 1557 } 1558 if(!$imgonly) { 1559 $out .= $lang['license'].' '; 1560 $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1561 $out .= '>'.$lic['name'].'</a></bdi>'; 1562 } 1563 if($wrap) $out .= '</div>'; 1564 1565 if($return) return $out; 1566 echo $out; 1567 return ''; 1568 } 1569 1570 /** 1571 * Includes the rendered HTML of a given page 1572 * 1573 * This function is useful to populate sidebars or similar features in a 1574 * template 1575 * 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 1581 */ 1582 function tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) { 1583 if($propagate) { 1584 $pageid = page_findnearest($pageid, $useacl); 1585 } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 1586 return false; 1587 } 1588 if(!$pageid) return false; 1589 1590 global $TOC; 1591 $oldtoc = $TOC; 1592 $html = p_wiki_xhtml($pageid, '', false); 1593 $TOC = $oldtoc; 1594 1595 if($print) echo $html; 1596 return $html; 1597 } 1598 1599 /** 1600 * Display the subscribe form 1601 * 1602 * @author Adrian Lang <lang@cosmocode.de> 1603 * @deprecated 2020-07-23 1604 */ 1605 function tpl_subscribe() { 1606 dbg_deprecated(\dokuwiki\Ui\Subscribe::class .'::show()'); 1607 (new \dokuwiki\Ui\Subscribe)->show(); 1608 } 1609 1610 /** 1611 * Tries to send already created content right to the browser 1612 * 1613 * Wraps around ob_flush() and flush() 1614 * 1615 * @author Andreas Gohr <andi@splitbrain.org> 1616 */ 1617 function tpl_flush() { 1618 if( ob_get_level() > 0 ) ob_flush(); 1619 flush(); 1620 } 1621 1622 /** 1623 * Tries to find a ressource file in the given locations. 1624 * 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 1627 * 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 1633 * @return string 1634 * 1635 * @author Andreas Gohr <andi@splitbrain.org> 1636 */ 1637 function tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true) { 1638 $img = ''; 1639 $file = ''; 1640 $ismedia = false; 1641 // loop through candidates until a match was found: 1642 foreach($search as $img) { 1643 if(substr($img, 0, 1) == ':') { 1644 $file = mediaFN($img); 1645 $ismedia = true; 1646 } else { 1647 $file = tpl_incdir().$img; 1648 $ismedia = false; 1649 } 1650 1651 if(file_exists($file)) break; 1652 } 1653 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) 1660 } else { 1661 return false; 1662 } 1663 } 1664 1665 // fetch image data if requested 1666 if(!is_null($imginfo)) { 1667 $imginfo = getimagesize($file); 1668 } 1669 1670 // build URL 1671 if($ismedia) { 1672 $url = ml($img, '', true, '', $abs); 1673 } else { 1674 $url = tpl_basedir().$img; 1675 if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1676 } 1677 1678 return $url; 1679 } 1680 1681 /** 1682 * PHP include a file 1683 * 1684 * either from the conf directory if it exists, otherwise use 1685 * file in the template's root directory. 1686 * 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, 1689 * default. 1690 * 1691 * Note: no escaping or sanity checking is done here. Never pass user input 1692 * to this function! 1693 * 1694 * @author Anika Henke <anika@selfthinker.org> 1695 * @author Andreas Gohr <andi@splitbrain.org> 1696 * 1697 * @param string $file 1698 */ 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"); 1707 return; 1708 } 1709 } 1710 } 1711 1712 // still here? try the template dir 1713 $file = tpl_incdir().$file; 1714 if(file_exists($file)) { 1715 include($file); 1716 } 1717 } 1718 1719 /** 1720 * Returns <link> tag for various icon types (favicon|mobile|generic) 1721 * 1722 * @author Anika Henke <anika@selfthinker.org> 1723 * 1724 * @param array $types - list of icon types to display (favicon|mobile|generic) 1725 * @return string 1726 */ 1727 function tpl_favicon($types = array('favicon')) { 1728 1729 $return = ''; 1730 1731 foreach($types as $type) { 1732 switch($type) { 1733 case 'favicon': 1734 $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1735 $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1736 break; 1737 case 'mobile': 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; 1740 break; 1741 case 'generic': 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; 1745 break; 1746 } 1747 } 1748 1749 return $return; 1750 } 1751 1752 /** 1753 * Prints full-screen media manager 1754 * 1755 * @author Kate Arzamastseva <pshns@ukr.net> 1756 */ 1757 function tpl_media() { 1758 global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 1759 $fullscreen = true; 1760 require_once DOKU_INC.'lib/exe/mediamanager.php'; 1761 1762 $rev = ''; 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; 1767 1768 echo '<div id="mediamanager__page">'.NL; 1769 echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1770 html_msgarea(); 1771 1772 echo '<div class="panel namespaces">'.NL; 1773 echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 1774 echo '<div class="panelHeader">'; 1775 echo $lang['media_namespaces']; 1776 echo '</div>'.NL; 1777 1778 echo '<div class="panelContent" id="media__tree">'.NL; 1779 media_nstree($NS); 1780 echo '</div>'.NL; 1781 echo '</div>'.NL; 1782 1783 echo '<div class="panel filelist">'.NL; 1784 tpl_mediaFileList(); 1785 echo '</div>'.NL; 1786 1787 echo '<div class="panel file">'.NL; 1788 echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1789 tpl_mediaFileDetails($image, $rev); 1790 echo '</div>'.NL; 1791 1792 echo '</div>'.NL; 1793 } 1794 1795 /** 1796 * Return useful layout classes 1797 * 1798 * @author Anika Henke <anika@selfthinker.org> 1799 * 1800 * @return string 1801 */ 1802 function tpl_classes() { 1803 global $ACT, $conf, $ID, $INFO; 1804 /** @var Input $INPUT */ 1805 global $INPUT; 1806 1807 $classes = array( 1808 'dokuwiki', 1809 'mode_'.$ACT, 1810 'tpl_'.$conf['template'], 1811 $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 1812 (isset($INFO['exists']) && $INFO['exists']) ? '' : 'notFound', 1813 ($ID == $conf['start']) ? 'home' : '', 1814 ); 1815 return join(' ', $classes); 1816 } 1817 1818 /** 1819 * Create event for tools menues 1820 * 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 1826 */ 1827 function tpl_toolsevent($toolsname, $items, $view = 'main') { 1828 dbg_deprecated('see devel:menus'); 1829 $data = array( 1830 'view' => $view, 1831 'items' => $items 1832 ); 1833 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; 1838 } 1839 $evt->advise_after(); 1840 } 1841 1842 //Setup VIM: ex: et ts=4 : 1843
title
Description
Body
title
Description
Body
title
Description
Body
title
Body