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