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_INC.'conf/dokuwiki.php'); 11 12/** 13 * Wrapper around htmlspecialchars() 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 * @see htmlspecialchars() 17 */ 18function hsc($string){ 19 return htmlspecialchars($string); 20} 21 22/** 23 * print a newline terminated string 24 * 25 * You can give an indention as optional parameter 26 * 27 * @author Andreas Gohr <andi@splitbrain.org> 28 */ 29function ptln($string,$intend=0){ 30 for($i=0; $i<$intend; $i++) print ' '; 31 print"$string\n"; 32} 33 34/** 35 * Print the content 36 * 37 * This function is used for printing all the usual content 38 * (defined by the global $ACT var) by calling the appropriate 39 * outputfunction(s) from html.php 40 * 41 * Everything that doesn't use the default template isn't 42 * handled by this function. ACL stuff is not done either. 43 * 44 * @author Andreas Gohr <andi@splitbrain.org> 45 */ 46function tpl_content(){ 47 global $ACT; 48 global $TEXT; 49 global $PRE; 50 global $SUF; 51 global $SUM; 52 global $IDX; 53 54 switch($ACT){ 55 case 'show': 56 html_show(); 57 break; 58 case 'preview': 59 html_edit($TEXT); 60 html_show($TEXT); 61 break; 62 case 'edit': 63 html_edit(); 64 break; 65 case 'wordblock': 66 html_edit($TEXT,'wordblock'); 67 break; 68 case 'search': 69 html_search(); 70 break; 71 case 'revisions': 72 html_revisions(); 73 break; 74 case 'diff': 75 html_diff(); 76 break; 77 case 'recent': 78 $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; 79 html_recent($first); 80 break; 81 case 'index': 82 html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 83 break; 84 case 'backlink': 85 html_backlinks(); 86 break; 87 case 'conflict': 88 html_conflict(con($PRE,$TEXT,$SUF),$SUM); 89 html_diff(con($PRE,$TEXT,$SUF),false); 90 break; 91 case 'locked': 92 html_locked(); 93 break; 94 case 'login': 95 html_login(); 96 break; 97 case 'register': 98 html_register(); 99 break; 100 case 'denied': 101 print p_locale_xhtml('denied'); 102 break; 103 case 'admin': 104 tpl_admin(); 105 break; 106 default: 107 msg("Failed to handle command: ".hsc($ACT),-1); 108 } 109} 110 111/** 112 * Handle the admin page contents 113 * 114 * @author Andreas Gohr <andi@splitbrain.org> 115 */ 116function tpl_admin(){ 117 switch($_REQUEST['page']){ 118 case 'acl': 119 admin_acl_html(); 120 break; 121 default: 122 html_admin(); 123 } 124} 125 126/** 127 * Print the correct HTML meta headers 128 * 129 * This has to go into the head section of your template. 130 * 131 * @author Andreas Gohr <andi@splitbrain.org> 132 */ 133function tpl_metaheaders(){ 134 global $ID; 135 global $INFO; 136 global $ACT; 137 global $lang; 138 global $conf; 139 $it=2; 140 141 // the usual stuff 142 ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 143 ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 144 ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 145 ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 146 ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 147 ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it); 148 ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it); 149 ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/styles/style.css" />',$it); 150 151 // setup robot tags apropriate for different modes 152 if( ($ACT=='show' || $ACT=='export_html') && !$REV){ 153 if($INFO['exists']){ 154 ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 155 //delay indexing: 156 if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 157 ptln('<meta name="robots" content="index,follow" />',$it); 158 }else{ 159 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 160 } 161 }else{ 162 ptln('<meta name="robots" content="noindex,follow" />',$it); 163 } 164 }else{ 165 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 166 } 167 168 // include some JavaScript language strings 169 ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it); 170 ptln(" var alertText = '".$lang['qb_alert']."'",$it); 171 ptln(" var notSavedYet = '".$lang['notsavedyet']."'",$it); 172 ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it); 173 ptln('</script>',$it); 174 175 // load the default JavaScript files 176 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 177 DOKU_BASE.'lib/scripts/script.js"></script>',$it); 178 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 179 DOKU_BASE.'lib/scripts/tw-sack.js"></script>',$it); 180 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 181 DOKU_BASE.'lib/scripts/ajax.js"></script>',$it); 182 183 // load spellchecker script if wanted 184 if($conf['spellchecker'] && ($ACT=='edit' || $ACT=='preview')){ 185 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 186 DOKU_BASE.'lib/scripts/spellcheck.js"></script>',$it); 187 } 188 189 // dom tool tip library, for insitu footnotes 190 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 191 DOKU_BASE.'lib/scripts/domLib.js"></script>',$it); 192 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 193 DOKU_BASE.'lib/scripts/domTT.js"></script>',$it); 194 195 //FIXME include some default CSS ? IE FIX? 196} 197 198/** 199 * Print a link 200 * 201 * Just builds a link but adds additional JavaScript needed for 202 * the unsaved data check needed in the edit form. 203 * 204 * @author Andreas Gohr <andi@splitbrain.org> 205 */ 206function tpl_link($url,$name,$more=''){ 207 print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; 208 if ($more) print ' '.$more; 209 print ">$name</a>"; 210} 211 212/** 213 * Prints a link to a WikiPage 214 * 215 * Wrapper around html_wikilink 216 * 217 * @author Andreas Gohr <andi@splitbrain.org> 218 */ 219function tpl_pagelink($id,$name=NULL){ 220 print html_wikilink($id,$name); 221} 222 223/** 224 * get the parent page 225 * 226 * Tries to find out which page is parent. 227 * returns false if none is available 228 * 229 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 230 */ 231function tpl_getparent($ID){ 232 global $conf; 233 234 if ($ID != $conf['start']) { 235 $idparts = explode(':', $ID); 236 $pn = array_pop($idparts); // get the page name 237 238 for ($n=0; $n < 2; $n++) { 239 if (count($idparts) == 0) { 240 $ID = $conf['start']; // go to topmost page 241 break; 242 }else{ 243 $ns = array_pop($idparts); // get the last part of namespace 244 if ($pn != $ns) { // are we already home? 245 array_push($idparts, $ns, $ns); // no, then add a page with same name 246 $ID = implode (':', $idparts); // as the namespace and recombine $ID 247 break; 248 } 249 } 250 } 251 252 if (@file_exists(wikiFN($ID))) { 253 return $ID; 254 } 255 } 256 return false; 257} 258 259/** 260 * Print one of the buttons 261 * 262 * Available Buttons are 263 * 264 * edit - edit/create/show button 265 * history - old revisions 266 * recent - recent changes 267 * login - login/logout button - if ACL enabled 268 * index - The index 269 * admin - admin page - if enough rights 270 * top - a back to top button 271 * back - a back to parent button - if available 272 * backtomedia - returns to the mediafile upload dialog 273 * after references have been displayed 274 * 275 * @author Andreas Gohr <andi@splitbrain.org> 276 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 277 */ 278function tpl_button($type){ 279 global $ID; 280 global $NS; 281 global $INFO; 282 global $conf; 283 284 switch($type){ 285 case 'edit': 286 print html_editbutton(); 287 break; 288 case 'history': 289 print html_btn('revs',$ID,'o',array('do' => 'revisions')); 290 break; 291 case 'recent': 292 print html_btn('recent','','r',array('do' => 'recent')); 293 break; 294 case 'index': 295 print html_btn('index',$ID,'x',array('do' => 'index')); 296 break; 297 case 'back': 298 if ($ID = tpl_getparent($ID)) { 299 print html_btn('back',$ID,'b',array('do' => 'show')); 300 } 301 break; 302 case 'top': 303 print html_topbtn(); 304 break; 305 case 'login': 306 if($conf['useacl']){ 307 if($_SERVER['REMOTE_USER']){ 308 print html_btn('logout',$ID,'',array('do' => 'logout',)); 309 }else{ 310 print html_btn('login',$ID,'',array('do' => 'login')); 311 } 312 } 313 break; 314 case 'admin': 315 if($INFO['perm'] == AUTH_ADMIN) 316 print html_btn('admin',$ID,'',array('do' => 'admin')); 317 break; 318 case 'backtomedia': 319 print html_backtomedia_button(array('ns' => $NS),'b'); 320 break; 321 default: 322 print '[unknown button type]'; 323 } 324} 325 326/** 327 * Like the action buttons but links 328 * 329 * Available links are 330 * 331 * edit - edit/create/show button 332 * history - old revisions 333 * recent - recent changes 334 * login - login/logout button - if ACL enabled 335 * index - The index 336 * admin - admin page - if enough rights 337 * top - a back to top button 338 * back - a back to parent button - if available 339 * 340 * @author Andreas Gohr <andi@splitbrain.org> 341 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 342 * @see tpl_button 343 */ 344function tpl_actionlink($type,$pre='',$suf=''){ 345 global $ID; 346 global $INFO; 347 global $REV; 348 global $ACT; 349 global $conf; 350 global $lang; 351 352 switch($type){ 353 case 'edit': 354 #most complicated type - we need to decide on current action 355 if($ACT == 'show' || $ACT == 'search'){ 356 if($INFO['writable']){ 357 if($INFO['exists']){ 358 tpl_link(wl($ID,'do=edit&rev='.$REV), 359 $pre.$lang['btn_edit'].$suf, 360 'class="action" accesskey="e" rel="nofollow"'); 361 }else{ 362 tpl_link(wl($ID,'do=edit&rev='.$REV), 363 $pre.$lang['btn_create'].$suf, 364 'class="action" accesskey="e" rel="nofollow"'); 365 } 366 }else{ 367 tpl_link(wl($ID,'do=edit&rev='.$REV), 368 $pre.$lang['btn_source'].$suf, 369 'class="action" accesskey="v" rel="nofollow"'); 370 } 371 }else{ 372 tpl_link(wl($ID,'do=show'), 373 $pre.$lang['btn_show'].$suf, 374 'class="action" accesskey="v" rel="nofollow"'); 375 } 376 break; 377 case 'history': 378 tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action" accesskey="o"'); 379 break; 380 case 'recent': 381 tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action" accesskey="r"'); 382 break; 383 case 'index': 384 tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action" accesskey="x"'); 385 break; 386 case 'top': 387 print '<a href="#top" class="action" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 388 break; 389 case 'back': 390 if ($ID = tpl_getparent($ID)) { 391 tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action" accesskey="b"'); 392 } 393 break; 394 case 'login': 395 if($conf['useacl']){ 396 if($_SERVER['REMOTE_USER']){ 397 tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action"'); 398 }else{ 399 tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action"'); 400 } 401 } 402 break; 403 case 'admin': 404 if($INFO['perm'] == AUTH_ADMIN) 405 tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action"'); 406 break; 407 default: 408 print '[unknown link type]'; 409 } 410} 411 412/** 413 * Print the search form 414 * 415 * @author Andreas Gohr <andi@splitbrain.org> 416 */ 417function tpl_searchform(){ 418 global $lang; 419 global $ACT; 420 421 print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search" onsubmit="return svchk()">'; 422 print '<input type="hidden" name="do" value="search" />'; 423 print '<input type="text" '; 424 425 if ($ACT == 'search') 426 print 'value="'.$_REQUEST['id'].'" '; /* keep search input as long as user stays on search page */ 427 428 print 'id="qsearch_in" accesskey="f" name="id" class="edit" onkeyup="ajax_qsearch.call(\'qsearch_in\',\'qsearch_out\')" />'; 429 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 430 print '<div id="qsearch_out" class="ajax_qsearch" onclick="this.style.display=\'none\'"></div>'; 431 print '</form>'; 432} 433 434/** 435 * Print the breadcrumbs trace 436 * 437 * @author Andreas Gohr <andi@splitbrain.org> 438 */ 439function tpl_breadcrumbs(){ 440 global $lang; 441 global $conf; 442 443 //check if enabled 444 if(!$conf['breadcrumbs']) return; 445 446 $crumbs = breadcrumbs(); //setup crumb trace 447 448 //reverse crumborder in right-to-left mode 449 if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 450 451 //render crumbs, highlight the last one 452 print $lang['breadcrumb'].':'; 453 $last = count($crumbs); 454 $i = 0; 455 foreach ($crumbs as $id => $name){ 456 $i++; 457 print ' <span class="bcsep">»</span> '; 458 if ($i == $last) print '<span class="curid">'; 459 tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 460 if ($i == $last) print '</span>'; 461 } 462} 463 464/** 465 * Hierarchical breadcrumbs 466 * 467 * This code was suggested as replacement for the usual breadcrumbs 468 * trail in the Wiki and was modified by me. 469 * It only makes sense with a deep site structure. 470 * 471 * @author Andreas Gohr <andi@splitbrain.org> 472 * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 473 * @todo May behave starngely in RTL languages 474 */ 475function tpl_youarehere(){ 476 global $conf; 477 global $ID; 478 global $lang; 479 480 481 $parts = explode(':', $ID); 482 483 print $lang['breadcrumb'].': '; 484 485 //always print the startpage 486 if( $a_part[0] != $conf['start'] ) 487 tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"'); 488 489 $page = ''; 490 foreach ($parts as $part){ 491 print ' » '; 492 $page .= $part; 493 494 if(file_exists(wikiFN($page))){ 495 tpl_link(wl($page),$part,'title="'.$page.'"'); 496 }else{ 497 print $page; 498 } 499 500 $page .= ':'; 501 } 502} 503 504/** 505 * Print info if the user is logged in 506 * and show full name in that case 507 * 508 * Could be enhanced with a profile link in future? 509 * 510 * @author Andreas Gohr <andi@splitbrain.org> 511 */ 512function tpl_userinfo(){ 513 global $lang; 514 global $INFO; 515 if($_SERVER['REMOTE_USER']) 516 print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 517} 518 519/** 520 * Print some info about the current page 521 * 522 * @author Andreas Gohr <andi@splitbrain.org> 523 */ 524function tpl_pageinfo(){ 525 global $conf; 526 global $lang; 527 global $INFO; 528 global $REV; 529 530 // prepare date and path 531 $fn = $INFO['filepath']; 532 if(!$conf['fullpath']){ 533 if($REV){ 534 $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 535 }else{ 536 $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 537 } 538 } 539 $fn = utf8_decodeFN($fn); 540 $date = date($conf['dformat'],$INFO['lastmod']); 541 542 // print it 543 if($INFO['exists']){ 544 print $fn; 545 print ' · '; 546 print $lang['lastmod']; 547 print ': '; 548 print $date; 549 if($INFO['editor']){ 550 print ' '.$lang['by'].' '; 551 print $INFO['editor']; 552 } 553 if($INFO['locked']){ 554 print ' · '; 555 print $lang['lockedby']; 556 print ': '; 557 print $INFO['locked']; 558 } 559 } 560} 561 562/** 563 * Print a list of namespaces containing media files 564 * 565 * @author Andreas Gohr <andi@splitbrain.org> 566 */ 567function tpl_medianamespaces(){ 568 global $conf; 569 570 $data = array(); 571 search($data,$conf['mediadir'],'search_namespaces',array()); 572 print html_buildlist($data,'idx',media_html_list_namespaces); 573} 574 575/** 576 * Print a list of mediafiles in the current namespace 577 * 578 * @author Andreas Gohr <andi@splitbrain.org> 579 */ 580function tpl_mediafilelist(){ 581 global $conf; 582 global $lang; 583 global $NS; 584 global $AUTH; 585 $dir = utf8_encodeFN(str_replace(':','/',$NS)); 586 587 $data = array(); 588 search($data,$conf['mediadir'],'search_media',array(),$dir); 589 590 if(!count($data)){ 591 ptln('<div class="nothing">'.$lang['nothingfound'].'<div>'); 592 return; 593 } 594 595 ptln('<ul>',2); 596 foreach($data as $item){ 597 ptln('<li>',4); 598 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'. 599 utf8_decodeFN($item['file']). 600 '</a>',6); 601 602 //prepare deletion button 603 if($AUTH >= AUTH_DELETE){ 604 $ask = $lang['del_confirm'].'\\n'; 605 $ask .= $item['id']; 606 607 $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.urlencode($item['id']).'" '. 608 'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'. 609 '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '. 610 'align="bottom" title="'.$lang['btn_delete'].'" /></a>'; 611 }else{ 612 $del = ''; 613 } 614 615 if($item['isimg']){ 616 $w = $item['info'][0]; 617 $h = $item['info'][1]; 618 619 ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')',6); 620 ptln($del.'<br />',6); 621 ptln('<div class="meta">',6); 622 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'); 623 624 if($w>120){ 625 print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?w=120&media='.urlencode($item['id']).'" width="120" class="thumb" />'; 626 }else{ 627 print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?media='.urlencode($item['id']).'" width="'.$w.'" height="'.$h.'" class="thumb" />'; 628 } 629 print '</a>'; 630 631 //read EXIF/IPTC data 632 $meta = new JpegMeta(mediaFN($item['id'])); 633 $t = $meta->getField('IPTC.Headline'); 634 if($t) print '<b>'.$t.'</b><br />'; 635 636 $t = $meta->getField(array('IPTC.Caption','EXIF.UserComment','EXIF.TIFFImageDescription','EXIF.TIFFUserComment')); 637 if($t) print $t.'<br />'; 638 639 $t = $meta->getField(array('IPTC.Keywords','IPTC.Category')); 640 if($t) print '<i>'.$t.'</i><br />'; 641 642 ptln('</div>',6); 643 }else{ 644 ptln ('('.filesize_h($item['size']).')',6); 645 ptln($del,6); 646 } 647 ptln('</li>',4); 648 } 649 ptln('</ul>',2); 650} 651 652/** 653 * show references to a media file 654 * References uses the same visual as search results and share 655 * their CSS tags except pagenames won't be links. 656 * 657 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 658 */ 659function tpl_showreferences(&$data){ 660 global $lang; 661 662 $hidden=0; //count of hits without read permission 663 664 if(count($data)){ 665 usort($data,'sort_search_fulltext'); 666 foreach($data as $row){ 667 if(auth_quickaclcheck($row['id']) >= AUTH_READ){ 668 print '<div class="search_result">'; 669 print '<span class="mediaref_ref">'.$row['id'].'</span>'; 670 print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />'; 671 print '<div class="search_snippet">'.$row['snippet'].'</div>'; 672 print '</div>'; 673 }else 674 $hidden++; 675 } 676 if ($hidden){ 677 print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>'; 678 } 679 } 680} 681 682/** 683 * Print the media upload form if permissions are correct 684 * 685 * @author Andreas Gohr <andi@splitbrain.org> 686 */ 687function tpl_mediauploadform(){ 688 global $NS; 689 global $UPLOADOK; 690 global $AUTH; 691 global $lang; 692 693 if(!$UPLOADOK) return; 694 695 ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" name="upload"'. 696 ' method="post" enctype="multipart/form-data">',2); 697 ptln($lang['txt_upload'].':<br />',4); 698 ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 699 ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 700 ptln($lang['txt_filename'].'<br />',4); 701 ptln('<input type="text" name="id" class="edit" />',4); 702 ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 703 if($AUTH >= AUTH_DELETE){ 704 ptln('<label for="ow" class="simple"><input type="checkbox" name="ow" value="1" id="ow">'.$lang['txt_overwrt'].'</label>',4); 705 } 706 ptln('</form>',2); 707} 708 709/** 710 * Prints the name of the given page (current one if none given). 711 * 712 * If useheading is enabled this will use the first headline else 713 * the given ID is printed. 714 * 715 * @author Andreas Gohr <andi@splitbrain.org> 716 */ 717function tpl_pagetitle($id=null){ 718 global $conf; 719 if(is_null($id)){ 720 global $ID; 721 $id = $ID; 722 } 723 724 $name = $id; 725 if ($conf['useheading']) { 726 $title = p_get_first_heading($id); 727 if ($title) $name = $title; 728 } 729 print hsc($name); 730} 731 732/** 733 * Returns the requested EXIF/IPTC tag from the current image 734 * 735 * If $tags is an array all given tags are tried until a 736 * value is found. If no value is found $alt is returned. 737 * 738 * Which texts are known is defined in the functions _exifTagNames 739 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 740 * to the names of the latter one) 741 * 742 * Only allowed in: detail.php 743 * 744 * @author Andreas Gohr <andi@splitbrain.org> 745 */ 746function tpl_img_getTag($tags,$alt=''){ 747 // Init Exif Reader 748 global $SRC; 749 static $meta = null; 750 if(is_null($meta)) $meta = new JpegMeta($SRC); 751 if($meta === false) return $alt; 752 $info = $meta->getField($tags); 753 if($info == false) return $alt; 754 return $info; 755} 756 757/** 758 * Prints the image with a link to the full sized version 759 * 760 * Only allowed in: detail.php 761 */ 762function tpl_img($maxwidth=900,$maxheight=700){ 763 global $IMG; 764 $w = tpl_img_getTag('File.Width'); 765 $h = tpl_img_getTag('File.Height'); 766 767 //resize to given max values 768 $ratio = 0; 769 if($w > $h){ 770 if($w > $maxwidth){ 771 $ratio = $maxwidth/$w; 772 }elseif($h > $maxheight){ 773 $ratio = $maxheight/$h; 774 } 775 }else{ 776 if($h > $maxheight){ 777 $ratio = $maxheight/$h; 778 }elseif($w > $maxwidth){ 779 $ratio = $maxwidth/$w; 780 } 781 } 782 if($ratio){ 783 $w = floor($ratio*$w); 784 $h = floor($ratio*$h); 785 } 786 787 //prepare URL 788 $p = array(); 789 $p['cache'] = $_REQUEST['cache']; 790 $p['media'] = $IMG; 791 $p = buildURLparams($p); 792 $url=DOKU_BASE.'lib/exe/fetch.php?'.$p; 793 794 //prepare attributes 795 $alt=tpl_img_getTag('Simple.Title'); 796 $p = array(); 797 if($w) $p['width'] = $w; 798 if($h) $p['height'] = $h; 799 $p['class'] = 'img_detail'; 800 if($alt){ 801 $p['alt'] = $alt; 802 $p['title'] = $alt; 803 }else{ 804 $p['alt'] = ''; 805 } 806 $p = buildAttributes($p); 807 808 print '<a href="'.$url.'">'; 809 print '<img src="'.$url.'&w='.$w.'&h='.$w.'" '.$p.'/>'; 810 print '</a>'; 811} 812 813//Setup VIM: ex: et ts=2 enc=utf-8 : 814