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