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