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