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