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