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