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