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 9 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10 require_once(DOKU_CONF.'dokuwiki.php'); 11 12/** 13 * Returns the path to the given template, uses 14 * default one if the custom version doesn't exist. 15 * Also enables gzip compression if configured. 16 * 17 * @author Andreas Gohr <andi@splitbrain.org> 18 */ 19function template($tpl){ 20 global $conf; 21 22 if ($conf['gzip_output'] && extension_loaded('zlib') && preg_match('/gzip|deflate/', $_SERVER['HTTP_ACCEPT_ENCODING'])) { 23 ob_start('ob_gzhandler'); 24 } 25 26 if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) 27 return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; 28 29 return DOKU_INC.'lib/tpl/default/'.$tpl; 30} 31 32/** 33 * Print the content 34 * 35 * This function is used for printing all the usual content 36 * (defined by the global $ACT var) by calling the appropriate 37 * outputfunction(s) from html.php 38 * 39 * Everything that doesn't use the main template file isn't 40 * handled by this function. ACL stuff is not done here either. 41 * 42 * @author Andreas Gohr <andi@splitbrain.org> 43 */ 44function tpl_content() { 45 global $ACT; 46 47 ob_start(); 48 49 trigger_event('TPL_ACT_RENDER',$ACT,tpl_content_core); 50 51 $html_output = ob_get_clean(); 52 53 trigger_event('TPL_CONTENT_DISPLAY',$html_output,ptln); 54} 55 56function tpl_content_core(){ 57 global $ACT; 58 global $TEXT; 59 global $PRE; 60 global $SUF; 61 global $SUM; 62 global $IDX; 63 64 switch($ACT){ 65 case 'show': 66 html_show(); 67 break; 68 case 'preview': 69 html_edit($TEXT); 70 html_show($TEXT); 71 break; 72 case 'recover': 73 html_edit($TEXT); 74 break; 75 case 'edit': 76 html_edit(); 77 break; 78 case 'draft': 79 html_draft(); 80 break; 81 case 'wordblock': 82 html_edit($TEXT,'wordblock'); 83 break; 84 case 'search': 85 html_search(); 86 break; 87 case 'revisions': 88 html_revisions(); 89 break; 90 case 'diff': 91 html_diff(); 92 break; 93 case 'recent': 94 $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; 95 html_recent($first); 96 break; 97 case 'index': 98 html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 99 break; 100 case 'backlink': 101 html_backlinks(); 102 break; 103 case 'conflict': 104 html_conflict(con($PRE,$TEXT,$SUF),$SUM); 105 html_diff(con($PRE,$TEXT,$SUF),false); 106 break; 107 case 'locked': 108 html_locked(); 109 break; 110 case 'login': 111 html_login(); 112 break; 113 case 'register': 114 html_register(); 115 break; 116 case 'resendpwd': 117 html_resendpwd(); 118 break; 119 case 'denied': 120 print p_locale_xhtml('denied'); 121 break; 122 case 'profile' : 123 html_updateprofile(); 124 break; 125 case 'admin': 126 tpl_admin(); 127 break; 128 default: 129 $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); 130 if ($evt->advise_before()) 131 msg("Failed to handle command: ".hsc($ACT),-1); 132 $evt->advise_after(); 133 unset($evt); 134 } 135} 136 137/** 138 * Handle the admin page contents 139 * 140 * @author Andreas Gohr <andi@splitbrain.org> 141 */ 142function tpl_admin(){ 143 144 $plugin = NULL; 145 if ($_REQUEST['page']) { 146 $pluginlist = plugin_list('admin'); 147 148 if (in_array($_REQUEST['page'], $pluginlist)) { 149 150 // attempt to load the plugin 151 $plugin =& plugin_load('admin',$_REQUEST['page']); 152 } 153 } 154 155 if ($plugin !== NULL) 156 $plugin->html(); 157 else 158 html_admin(); 159} 160 161/** 162 * Print the correct HTML meta headers 163 * 164 * This has to go into the head section of your template. 165 * 166 * @param boolean $alt Should feeds and alternative format links be added? 167 * @author Andreas Gohr <andi@splitbrain.org> 168 */ 169function tpl_metaheaders($alt=true){ 170 global $ID; 171 global $INFO; 172 global $ACT; 173 global $lang; 174 global $conf; 175 $it=2; 176 177 // the usual stuff 178 ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 179 ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 180 ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 181 182 if($alt){ 183 ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 184 ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 185 ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.exportlink($ID, 'xhtml').'" />',$it); 186 ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.exportlink($ID, 'raw').'" />',$it); 187 } 188 189 // setup robot tags apropriate for different modes 190 if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ 191 if($INFO['exists']){ 192 ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 193 //delay indexing: 194 if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 195 ptln('<meta name="robots" content="index,follow" />',$it); 196 }else{ 197 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 198 } 199 }else{ 200 ptln('<meta name="robots" content="noindex,follow" />',$it); 201 } 202 }else{ 203 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 204 } 205 206 // load stylesheets 207 ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php" />',$it); 208 ptln('<link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php?print=1" />',$it); 209 210 // load javascript 211 $js_edit = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover') ? 1 : 0; 212 $js_write = ($INFO['writable']) ? 1 : 0; 213 if(defined('DOKU_MEDIAMANAGER')){ 214 $js_edit = 1; 215 $js_write = 0; 216 } 217 if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){ 218 ptln('<script type="text/javascript" charset="utf-8">',$it); 219 ptln("NS='".$INFO['namespace']."';",$it+2); 220 if($conf['useacl'] && $_SERVER['REMOTE_USER']){ 221 require_once(DOKU_INC.'inc/toolbar.php'); 222 ptln("SIG='".toolbar_signature()."';",$it+2); 223 } 224 ptln('</script>',$it); 225 } 226 ptln('<script type="text/javascript" charset="utf-8" src="'. 227 DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write.'"></script>',$it); 228} 229 230/** 231 * Print a link 232 * 233 * Just builds a link. 234 * 235 * @author Andreas Gohr <andi@splitbrain.org> 236 */ 237function tpl_link($url,$name,$more=''){ 238 print '<a href="'.$url.'" '; 239 if ($more) print ' '.$more; 240 print ">$name</a>"; 241} 242 243/** 244 * Prints a link to a WikiPage 245 * 246 * Wrapper around html_wikilink 247 * 248 * @author Andreas Gohr <andi@splitbrain.org> 249 */ 250function tpl_pagelink($id,$name=NULL){ 251 print html_wikilink($id,$name); 252} 253 254/** 255 * get the parent page 256 * 257 * Tries to find out which page is parent. 258 * returns false if none is available 259 * 260 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 261 */ 262function tpl_getparent($ID){ 263 global $conf; 264 265 if ($ID != $conf['start']) { 266 $idparts = explode(':', $ID); 267 $pn = array_pop($idparts); // get the page name 268 269 for ($n=0; $n < 2; $n++) { 270 if (count($idparts) == 0) { 271 $ID = $conf['start']; // go to topmost page 272 break; 273 }else{ 274 $ns = array_pop($idparts); // get the last part of namespace 275 if ($pn != $ns) { // are we already home? 276 array_push($idparts, $ns, $ns); // no, then add a page with same name 277 $ID = implode (':', $idparts); // as the namespace and recombine $ID 278 break; 279 } 280 } 281 } 282 283 if (@file_exists(wikiFN($ID))) { 284 return $ID; 285 } 286 } 287 return false; 288} 289 290/** 291 * Print one of the buttons 292 * 293 * Available Buttons are 294 * 295 * edit - edit/create/show/draft button 296 * history - old revisions 297 * recent - recent changes 298 * login - login/logout button - if ACL enabled 299 * index - The index 300 * admin - admin page - if enough rights 301 * top - a back to top button 302 * back - a back to parent button - if available 303 * backtomedia - returns to the mediafile upload dialog 304 * after references have been displayed 305 * backlink - links to the list of backlinks 306 * 307 * @author Andreas Gohr <andi@splitbrain.org> 308 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 309 */ 310function tpl_button($type){ 311 global $ACT; 312 global $ID; 313 global $NS; 314 global $INFO; 315 global $conf; 316 global $auth; 317 318 switch($type){ 319 case 'edit': 320 print html_editbutton(); 321 break; 322 case 'history': 323 print html_btn('revs',$ID,'o',array('do' => 'revisions')); 324 break; 325 case 'recent': 326 print html_btn('recent','','r',array('do' => 'recent')); 327 break; 328 case 'index': 329 print html_btn('index',$ID,'x',array('do' => 'index')); 330 break; 331 case 'back': 332 if ($parent = tpl_getparent($ID)) { 333 print html_btn('back',$parent,'b',array('do' => 'show')); 334 } 335 break; 336 case 'top': 337 print html_topbtn(); 338 break; 339 case 'login': 340 if($conf['useacl']){ 341 if($_SERVER['REMOTE_USER']){ 342 print html_btn('logout',$ID,'',array('do' => 'logout',)); 343 }else{ 344 print html_btn('login',$ID,'',array('do' => 'login')); 345 } 346 } 347 break; 348 case 'admin': 349 if($INFO['perm'] == AUTH_ADMIN) 350 print html_btn('admin',$ID,'',array('do' => 'admin')); 351 break; 352 case 'backtomedia': 353 print html_backtomedia_button(array('ns' => $NS),'b'); 354 break; 355 case 'subscription': 356 if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 357 if($_SERVER['REMOTE_USER']){ 358 if($INFO['subscribed']){ 359 print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',)); 360 } else { 361 print html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); 362 } 363 } 364 } 365 break; 366 case 'backlink': 367 print html_btn('backlink',$ID,'',array('do' => 'backlink')); 368 break; 369 case 'profile': 370 if($conf['useacl'] && $_SERVER['REMOTE_USER'] && 371 $auth->canDo('Profile') && ($ACT!='profile')){ 372 print html_btn('profile',$ID,'',array('do' => 'profile')); 373 } 374 break; 375 default: 376 print '[unknown button type]'; 377 } 378} 379 380/** 381 * Like the action buttons but links 382 * 383 * Available links are 384 * 385 * edit - edit/create/show button 386 * history - old revisions 387 * recent - recent changes 388 * login - login/logout button - if ACL enabled 389 * index - The index 390 * admin - admin page - if enough rights 391 * top - a back to top button 392 * back - a back to parent button - if available 393 * backlink - links to the list of backlinks 394 * 395 * @author Andreas Gohr <andi@splitbrain.org> 396 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 397 * @see tpl_button 398 */ 399function tpl_actionlink($type,$pre='',$suf=''){ 400 global $ID; 401 global $INFO; 402 global $REV; 403 global $ACT; 404 global $conf; 405 global $lang; 406 global $auth; 407 408 switch($type){ 409 case 'edit': 410 #most complicated type - we need to decide on current action 411 if($ACT == 'show' || $ACT == 'search'){ 412 if($INFO['writable']){ 413 if($INFO['exists']){ 414 tpl_link(wl($ID,'do=edit&rev='.$REV), 415 $pre.$lang['btn_edit'].$suf, 416 'class="action edit" accesskey="e" rel="nofollow"'); 417 }else{ 418 tpl_link(wl($ID,'do=edit&rev='.$REV), 419 $pre.$lang['btn_create'].$suf, 420 'class="action create" accesskey="e" rel="nofollow"'); 421 } 422 }else{ 423 tpl_link(wl($ID,'do=edit&rev='.$REV), 424 $pre.$lang['btn_source'].$suf, 425 'class="action source" accesskey="v" rel="nofollow"'); 426 } 427 }else{ 428 tpl_link(wl($ID,'do=show'), 429 $pre.$lang['btn_show'].$suf, 430 'class="action show" accesskey="v" rel="nofollow"'); 431 } 432 return true; 433 case 'history': 434 tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"'); 435 return true; 436 case 'recent': 437 tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"'); 438 return true; 439 case 'index': 440 tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"'); 441 return true; 442 case 'top': 443 print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 444 return true; 445 case 'back': 446 if ($ID = tpl_getparent($ID)) { 447 tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"'); 448 return true; 449 } 450 return false; 451 case 'login': 452 if($conf['useacl']){ 453 if($_SERVER['REMOTE_USER']){ 454 tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"'); 455 }else{ 456 tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"'); 457 } 458 return true; 459 } 460 return false; 461 case 'admin': 462 if($INFO['perm'] == AUTH_ADMIN){ 463 tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"'); 464 return true; 465 } 466 return false; 467 case 'subscribe': 468 case 'subscription': 469 if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 470 if($_SERVER['REMOTE_USER']){ 471 if($INFO['subscribed']) { 472 tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"'); 473 } else { 474 tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"'); 475 } 476 return true; 477 } 478 } 479 return false; 480 case 'backlink': 481 tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"'); 482 return true; 483 case 'profile': 484 if($conf['useacl'] && $_SERVER['REMOTE_USER'] && 485 $auth->canDo('Profile') && ($ACT!='profile')){ 486 tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"'); 487 return true; 488 } 489 return false; 490 default: 491 print '[unknown link type]'; 492 return true; 493 } 494} 495 496/** 497 * Print the search form 498 * 499 * If the first parameter is given a div with the ID 'qsearch_out' will 500 * be added which instructs the ajax pagequicksearch to kick in and place 501 * its output into this div. The second parameter controls the propritary 502 * attribute autocomplete. If set to false this attribute will be set with an 503 * value of "off" to instruct the browser to disable it's own built in 504 * autocompletion feature (MSIE and Firefox) 505 * 506 * @author Andreas Gohr <andi@splitbrain.org> 507 */ 508function tpl_searchform($ajax=true,$autocomplete=true){ 509 global $lang; 510 global $ACT; 511 512 print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">'; 513 print '<input type="hidden" name="do" value="search" />'; 514 print '<input type="text" '; 515 if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" '; 516 if(!$autocomplete) print 'autocomplete="off" '; 517 print 'id="qsearch__in" accesskey="f" name="id" class="edit" />'; 518 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 519 if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 520 print '</div></form>'; 521} 522 523/** 524 * Print the breadcrumbs trace 525 * 526 * @author Andreas Gohr <andi@splitbrain.org> 527 */ 528function tpl_breadcrumbs(){ 529 global $lang; 530 global $conf; 531 532 //check if enabled 533 if(!$conf['breadcrumbs']) return; 534 535 $crumbs = breadcrumbs(); //setup crumb trace 536 537 //reverse crumborder in right-to-left mode 538 if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 539 540 //render crumbs, highlight the last one 541 print $lang['breadcrumb'].':'; 542 $last = count($crumbs); 543 $i = 0; 544 foreach ($crumbs as $id => $name){ 545 $i++; 546 print ' <span class="bcsep">»</span> '; 547 if ($i == $last) print '<span class="curid">'; 548 tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 549 if ($i == $last) print '</span>'; 550 } 551} 552 553/** 554 * Hierarchical breadcrumbs 555 * 556 * This code was suggested as replacement for the usual breadcrumbs. 557 * It only makes sense with a deep site structure. 558 * 559 * @author Andreas Gohr <andi@splitbrain.org> 560 * @author Nigel McNie <oracle.shinoda@gmail.com> 561 * @author Sean Coates <sean@caedmon.net> 562 * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 563 * @todo May behave strangely in RTL languages 564 */ 565function tpl_youarehere(){ 566 global $conf; 567 global $ID; 568 global $lang; 569 570 //check if enabled 571 if(!$conf['youarehere']) return; 572 573 $parts = explode(':', $ID); 574 575 print $lang['youarehere'].': '; 576 577 //always print the startpage 578 if( $a_part[0] != $conf['start']){ 579 if($conf['useheading']){ 580 $pageName = p_get_first_heading($conf['start']); 581 }else{ 582 $pageName = $conf['start']; 583 } 584 tpl_link(wl($conf['start']),$pageName,'title="'.$pageName.'"'); 585 } 586 587 $page = ''; 588 foreach ($parts as $part){ 589 // Skip startpage if already done 590 if ($part == $conf['start']) continue; 591 592 print ' » '; 593 $page .= $part; 594 595 if(file_exists(wikiFN($page))){ 596 if($conf['useheading']){ 597 $pageName = p_get_first_heading($page); 598 $partName = $pageName; 599 }else{ 600 $pageName = $page; 601 $partName = $part; 602 } 603 tpl_link(wl($page),$partName,'title="'.$pageName.'"'); 604 }else{ 605 // Print the link, but mark as not-existing, as for other non-existing links 606 tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"'); 607 //print $page; 608 } 609 610 $page .= ':'; 611 } 612} 613 614/** 615 * Print info if the user is logged in 616 * and show full name in that case 617 * 618 * Could be enhanced with a profile link in future? 619 * 620 * @author Andreas Gohr <andi@splitbrain.org> 621 */ 622function tpl_userinfo(){ 623 global $lang; 624 global $INFO; 625 if($_SERVER['REMOTE_USER']) 626 print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 627} 628 629/** 630 * Print some info about the current page 631 * 632 * @author Andreas Gohr <andi@splitbrain.org> 633 */ 634function tpl_pageinfo(){ 635 global $conf; 636 global $lang; 637 global $INFO; 638 global $REV; 639 640 // prepare date and path 641 $fn = $INFO['filepath']; 642 if(!$conf['fullpath']){ 643 if($REV){ 644 $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 645 }else{ 646 $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 647 } 648 } 649 $fn = utf8_decodeFN($fn); 650 $date = date($conf['dformat'],$INFO['lastmod']); 651 652 // print it 653 if($INFO['exists']){ 654 print $fn; 655 print ' · '; 656 print $lang['lastmod']; 657 print ': '; 658 print $date; 659 if($INFO['editor']){ 660 print ' '.$lang['by'].' '; 661 print $INFO['editor']; 662 } 663 if($INFO['locked']){ 664 print ' · '; 665 print $lang['lockedby']; 666 print ': '; 667 print $INFO['locked']; 668 } 669 } 670} 671 672/** 673 * Prints or returns the name of the given page (current one if none given). 674 * 675 * If useheading is enabled this will use the first headline else 676 * the given ID is used. 677 * 678 * @author Andreas Gohr <andi@splitbrain.org> 679 */ 680function tpl_pagetitle($id=null, $ret=false){ 681 global $conf; 682 if(is_null($id)){ 683 global $ID; 684 $id = $ID; 685 } 686 687 $name = $id; 688 if ($conf['useheading']) { 689 $title = p_get_first_heading($id); 690 if ($title) $name = $title; 691 } 692 693 if ($ret) { 694 return hsc($name); 695 } else { 696 print hsc($name); 697 } 698} 699 700/** 701 * Returns the requested EXIF/IPTC tag from the current image 702 * 703 * If $tags is an array all given tags are tried until a 704 * value is found. If no value is found $alt is returned. 705 * 706 * Which texts are known is defined in the functions _exifTagNames 707 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 708 * to the names of the latter one) 709 * 710 * Only allowed in: detail.php 711 * 712 * @author Andreas Gohr <andi@splitbrain.org> 713 */ 714function tpl_img_getTag($tags,$alt='',$src=null){ 715 // Init Exif Reader 716 global $SRC; 717 718 if(is_null($src)) $src = $SRC; 719 720 static $meta = null; 721 if(is_null($meta)) $meta = new JpegMeta($src); 722 if($meta === false) return $alt; 723 $info = $meta->getField($tags); 724 if($info == false) return $alt; 725 return $info; 726} 727 728/** 729 * Prints the image with a link to the full sized version 730 * 731 * Only allowed in: detail.php 732 */ 733function tpl_img($maxwidth=0,$maxheight=0){ 734 global $IMG; 735 $w = tpl_img_getTag('File.Width'); 736 $h = tpl_img_getTag('File.Height'); 737 738 //resize to given max values 739 $ratio = 1; 740 if($w >= $h){ 741 if($maxwidth && $w >= $maxwidth){ 742 $ratio = $maxwidth/$w; 743 }elseif($maxheight && $h > $maxheight){ 744 $ratio = $maxheight/$h; 745 } 746 }else{ 747 if($maxheight && $h >= $maxheight){ 748 $ratio = $maxheight/$h; 749 }elseif($maxwidth && $w > $maxwidth){ 750 $ratio = $maxwidth/$w; 751 } 752 } 753 if($ratio){ 754 $w = floor($ratio*$w); 755 $h = floor($ratio*$h); 756 } 757 758 //prepare URLs 759 $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); 760 $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); 761 762 //prepare attributes 763 $alt=tpl_img_getTag('Simple.Title'); 764 $p = array(); 765 if($w) $p['width'] = $w; 766 if($h) $p['height'] = $h; 767 $p['class'] = 'img_detail'; 768 if($alt){ 769 $p['alt'] = $alt; 770 $p['title'] = $alt; 771 }else{ 772 $p['alt'] = ''; 773 } 774 $p = buildAttributes($p); 775 776 print '<a href="'.$url.'">'; 777 print '<img src="'.$src.'" '.$p.'/>'; 778 print '</a>'; 779} 780 781/** 782 * This function inserts a 1x1 pixel gif which in reality 783 * is the inexer function. 784 * 785 * Should be called somewhere at the very end of the main.php 786 * template 787 */ 788function tpl_indexerWebBug(){ 789 global $ID; 790 global $INFO; 791 if(!$INFO['exists']) return; 792 793 if(isHiddenPage($ID)) return; //no need to index hidden pages 794 795 $p = array(); 796 $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 797 '&'.time(); 798 $p['width'] = 1; 799 $p['height'] = 1; 800 $p['alt'] = ''; 801 $att = buildAttributes($p); 802 print "<img $att />"; 803} 804 805// configuration methods 806/** 807 * tpl_getConf($id) 808 * 809 * use this function to access template configuration variables 810 */ 811function tpl_getConf($id){ 812 global $conf; 813 global $tpl_configloaded; 814 815 $tpl = $conf['template']; 816 817 if (!$tpl_configloaded){ 818 $tconf = tpl_loadConfig(); 819 if ($tconf !== false){ 820 foreach ($tconf as $key => $value){ 821 if (isset($conf['tpl'][$tpl][$key])) continue; 822 $conf['tpl'][$tpl][$key] = $value; 823 } 824 $tpl_configloaded = true; 825 } 826 } 827 828 return $conf['tpl'][$tpl][$id]; 829} 830 831/** 832 * tpl_loadConfig() 833 * reads all template configuration variables 834 * this function is automatically called by tpl_getConf() 835 */ 836function tpl_loadConfig(){ 837 838 $file = DOKU_TPLINC.'/conf/default.php'; 839 $conf = array(); 840 841 if (!@file_exists($file)) return false; 842 843 // load default config file 844 include($file); 845 846 return $conf; 847} 848 849/** 850 * prints the "main content" in the mediamanger popup 851 * 852 * Depending on the user's actions this may be a list of 853 * files in a namespace, the meta editing dialog or 854 * a message of referencing pages 855 * 856 * Only allowed in mediamanager.php 857 * 858 * @author Andreas Gohr <andi@splitbrain.org> 859 */ 860function tpl_mediaContent(){ 861 global $IMG; 862 global $AUTH; 863 global $INUSE; 864 global $NS; 865 global $JUMPTO; 866 867 ptln('<div id="media__content">'); 868 if($_REQUEST['edit']){ 869 media_metaform($IMG,$AUTH); 870 }elseif($INUSE){ 871 media_filesinuse($INUSE,$IMG); 872 }else{ 873 media_filelist($NS,$AUTH,$JUMPTO); 874 } 875 ptln('</div>'); 876} 877 878/** 879 * prints the namespace tree in the mediamanger popup 880 * 881 * Only allowed in mediamanager.php 882 * 883 * @author Andreas Gohr <andi@splitbrain.org> 884 */ 885function tpl_mediaTree(){ 886 global $NS; 887 888 ptln('<div id="media__tree">'); 889 media_nstree($NS); 890 ptln('</div>'); 891} 892 893//Setup VIM: ex: et ts=2 enc=utf-8 : 894