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 //FIXME include some default CSS ? IE FIX? 190} 191 192/** 193 * Print a link 194 * 195 * Just builds a link but adds additional JavaScript needed for 196 * the unsaved data check needed in the edit form. 197 * 198 * @author Andreas Gohr <andi@splitbrain.org> 199 */ 200function tpl_link($url,$name,$more=''){ 201 print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; 202 if ($more) print ' '.$more; 203 print ">$name</a>"; 204} 205 206/** 207 * Prints a link to a WikiPage 208 * 209 * Wrapper around html_wikilink 210 * 211 * @author Andreas Gohr <andi@splitbrain.org> 212 */ 213function tpl_pagelink($id,$name=NULL){ 214 print html_wikilink($id,$name); 215} 216 217/** 218 * get the parent page 219 * 220 * Tries to find out which page is parent. 221 * returns false if none is available 222 * 223 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 224 */ 225function tpl_getparent($ID){ 226 global $conf; 227 228 if ($ID != $conf['start']) { 229 $idparts = explode(':', $ID); 230 $pn = array_pop($idparts); // get the page name 231 232 for ($n=0; $n < 2; $n++) { 233 if (count($idparts) == 0) { 234 $ID = $conf['start']; // go to topmost page 235 break; 236 }else{ 237 $ns = array_pop($idparts); // get the last part of namespace 238 if ($pn != $ns) { // are we already home? 239 array_push($idparts, $ns, $ns); // no, then add a page with same name 240 $ID = implode (':', $idparts); // as the namespace and recombine $ID 241 break; 242 } 243 } 244 } 245 246 if (@file_exists(wikiFN($ID))) { 247 return $ID; 248 } 249 } 250 return false; 251} 252 253/** 254 * Print one of the buttons 255 * 256 * Available Buttons are 257 * 258 * edit - edit/create/show button 259 * history - old revisions 260 * recent - recent changes 261 * login - login/logout button - if ACL enabled 262 * index - The index 263 * admin - admin page - if enough rights 264 * top - a back to top button 265 * back - a back to parent button - if available 266 * backtomedia - returns to the mediafile upload dialog 267 * after references have been displayed 268 * 269 * @author Andreas Gohr <andi@splitbrain.org> 270 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 271 */ 272function tpl_button($type){ 273 global $ID; 274 global $NS; 275 global $INFO; 276 global $conf; 277 278 switch($type){ 279 case 'edit': 280 print html_editbutton(); 281 break; 282 case 'history': 283 print html_btn('revs',$ID,'o',array('do' => 'revisions')); 284 break; 285 case 'recent': 286 print html_btn('recent','','r',array('do' => 'recent')); 287 break; 288 case 'index': 289 print html_btn('index',$ID,'x',array('do' => 'index')); 290 break; 291 case 'back': 292 if ($ID = tpl_getparent($ID)) { 293 print html_btn('back',$ID,'b',array('do' => 'show')); 294 } 295 break; 296 case 'top': 297 print html_topbtn(); 298 break; 299 case 'login': 300 if($conf['useacl']){ 301 if($_SERVER['REMOTE_USER']){ 302 print html_btn('logout',$ID,'',array('do' => 'logout',)); 303 }else{ 304 print html_btn('login',$ID,'',array('do' => 'login')); 305 } 306 } 307 break; 308 case 'admin': 309 if($INFO['perm'] == AUTH_ADMIN) 310 print html_btn('admin',$ID,'',array('do' => 'admin')); 311 break; 312 case 'backtomedia': 313 print html_backtomedia_button(array('ns' => $NS),'b'); 314 break; 315 default: 316 print '[unknown button type]'; 317 } 318} 319 320/** 321 * Like the action buttons but links 322 * 323 * Available links are 324 * 325 * edit - edit/create/show button 326 * history - old revisions 327 * recent - recent changes 328 * login - login/logout button - if ACL enabled 329 * index - The index 330 * admin - admin page - if enough rights 331 * top - a back to top button 332 * back - a back to parent button - if available 333 * 334 * @author Andreas Gohr <andi@splitbrain.org> 335 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 336 * @see tpl_button 337 */ 338function tpl_actionlink($type,$pre='',$suf=''){ 339 global $ID; 340 global $INFO; 341 global $REV; 342 global $ACT; 343 global $conf; 344 global $lang; 345 346 switch($type){ 347 case 'edit': 348 #most complicated type - we need to decide on current action 349 if($ACT == 'show' || $ACT == 'search'){ 350 if($INFO['writable']){ 351 if($INFO['exists']){ 352 tpl_link(wl($ID,'do=edit&rev='.$REV), 353 $pre.$lang['btn_edit'].$suf, 354 'class="action" accesskey="e" rel="nofollow"'); 355 }else{ 356 tpl_link(wl($ID,'do=edit&rev='.$REV), 357 $pre.$lang['btn_create'].$suf, 358 'class="action" accesskey="e" rel="nofollow"'); 359 } 360 }else{ 361 tpl_link(wl($ID,'do=edit&rev='.$REV), 362 $pre.$lang['btn_source'].$suf, 363 'class="action" accesskey="v" rel="nofollow"'); 364 } 365 }else{ 366 tpl_link(wl($ID,'do=show'), 367 $pre.$lang['btn_show'].$suf, 368 'class="action" accesskey="v" rel="nofollow"'); 369 } 370 break; 371 case 'history': 372 tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action" accesskey="o"'); 373 break; 374 case 'recent': 375 tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action" accesskey="r"'); 376 break; 377 case 'index': 378 tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action" accesskey="x"'); 379 break; 380 case 'top': 381 print '<a href="#top" class="action" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 382 break; 383 case 'back': 384 if ($ID = tpl_getparent($ID)) { 385 tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action" accesskey="b"'); 386 } 387 break; 388 case 'login': 389 if($conf['useacl']){ 390 if($_SERVER['REMOTE_USER']){ 391 tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action"'); 392 }else{ 393 tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action"'); 394 } 395 } 396 break; 397 case 'admin': 398 if($INFO['perm'] == AUTH_ADMIN) 399 tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action"'); 400 break; 401 default: 402 print '[unknown link type]'; 403 } 404} 405 406/** 407 * Print the search form 408 * 409 * @author Andreas Gohr <andi@splitbrain.org> 410 */ 411function tpl_searchform(){ 412 global $lang; 413 global $ACT; 414 415 print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search" onsubmit="return svchk()">'; 416 print '<input type="hidden" name="do" value="search" />'; 417 print '<input type="text" '; 418 419 if ($ACT == 'search') 420 print 'value="'.$_REQUEST['id'].'" '; /* keep search input as long as user stays on search page */ 421 422 print 'id="qsearch_in" accesskey="f" name="id" class="edit" onkeyup="ajax_qsearch.call(\'qsearch_in\',\'qsearch_out\')" />'; 423 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 424 print '<div id="qsearch_out" class="ajax_qsearch" onclick="this.style.display=\'none\'"></div>'; 425 print '</form>'; 426} 427 428/** 429 * Print the breadcrumbs trace 430 * 431 * @author Andreas Gohr <andi@splitbrain.org> 432 */ 433function tpl_breadcrumbs(){ 434 global $lang; 435 global $conf; 436 437 //check if enabled 438 if(!$conf['breadcrumbs']) return; 439 440 $crumbs = breadcrumbs(); //setup crumb trace 441 442 //reverse crumborder in right-to-left mode 443 if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 444 445 //render crumbs, highlight the last one 446 print $lang['breadcrumb'].':'; 447 $last = count($crumbs); 448 $i = 0; 449 foreach ($crumbs as $id => $name){ 450 $i++; 451 print ' <span class="bcsep">»</span> '; 452 if ($i == $last) print '<span class="curid">'; 453 tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 454 if ($i == $last) print '</span>'; 455 } 456} 457 458/** 459 * Hierarchical breadcrumbs 460 * 461 * This code was suggested as replacement for the usual breadcrumbs 462 * trail in the Wiki and was modified by me. 463 * It only makes sense with a deep site structure. 464 * 465 * @author Andreas Gohr <andi@splitbrain.org> 466 * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 467 * @todo May behave starngely in RTL languages 468 */ 469function tpl_youarehere(){ 470 global $conf; 471 global $ID; 472 global $lang; 473 474 475 $parts = explode(':', $ID); 476 477 print $lang['breadcrumb'].': '; 478 479 //always print the startpage 480 if( $a_part[0] != $conf['start'] ) 481 tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"'); 482 483 $page = ''; 484 foreach ($parts as $part){ 485 print ' » '; 486 $page .= $part; 487 488 if(file_exists(wikiFN($page))){ 489 tpl_link(wl($page),$part,'title="'.$page.'"'); 490 }else{ 491 print $page; 492 } 493 494 $page .= ':'; 495 } 496} 497 498/** 499 * Print info if the user is logged in 500 * and show full name in that case 501 * 502 * Could be enhanced with a profile link in future? 503 * 504 * @author Andreas Gohr <andi@splitbrain.org> 505 */ 506function tpl_userinfo(){ 507 global $lang; 508 global $INFO; 509 if($_SERVER['REMOTE_USER']) 510 print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 511} 512 513/** 514 * Print some info about the current page 515 * 516 * @author Andreas Gohr <andi@splitbrain.org> 517 */ 518function tpl_pageinfo(){ 519 global $conf; 520 global $lang; 521 global $INFO; 522 global $REV; 523 524 // prepare date and path 525 $fn = $INFO['filepath']; 526 if(!$conf['fullpath']){ 527 if($REV){ 528 $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 529 }else{ 530 $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 531 } 532 } 533 $fn = utf8_decodeFN($fn); 534 $date = date($conf['dformat'],$INFO['lastmod']); 535 536 // print it 537 if($INFO['exists']){ 538 print $fn; 539 print ' · '; 540 print $lang['lastmod']; 541 print ': '; 542 print $date; 543 if($INFO['editor']){ 544 print ' '.$lang['by'].' '; 545 print $INFO['editor']; 546 } 547 if($INFO['locked']){ 548 print ' · '; 549 print $lang['lockedby']; 550 print ': '; 551 print $INFO['locked']; 552 } 553 } 554} 555 556/** 557 * Print a list of namespaces containing media files 558 * 559 * @author Andreas Gohr <andi@splitbrain.org> 560 */ 561function tpl_medianamespaces(){ 562 global $conf; 563 564 $data = array(); 565 search($data,$conf['mediadir'],'search_namespaces',array()); 566 print html_buildlist($data,'idx',media_html_list_namespaces); 567} 568 569/** 570 * Print a list of mediafiles in the current namespace 571 * 572 * @author Andreas Gohr <andi@splitbrain.org> 573 */ 574function tpl_mediafilelist(){ 575 global $conf; 576 global $lang; 577 global $NS; 578 global $AUTH; 579 $dir = utf8_encodeFN(str_replace(':','/',$NS)); 580 581 $data = array(); 582 search($data,$conf['mediadir'],'search_media',array(),$dir); 583 584 if(!count($data)){ 585 ptln('<div class="nothing">'.$lang['nothingfound'].'<div>'); 586 return; 587 } 588 589 ptln('<ul>',2); 590 foreach($data as $item){ 591 ptln('<li>',4); 592 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'. 593 utf8_decodeFN($item['file']). 594 '</a>',6); 595 596 //prepare deletion button 597 if($AUTH >= AUTH_DELETE){ 598 $ask = $lang['del_confirm'].'\\n'; 599 $ask .= $item['id']; 600 601 $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.urlencode($item['id']).'" '. 602 'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'. 603 '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '. 604 'align="bottom" title="'.$lang['btn_delete'].'" /></a>'; 605 }else{ 606 $del = ''; 607 } 608 609 if($item['isimg']){ 610 $w = $item['info'][0]; 611 $h = $item['info'][1]; 612 613 ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')',6); 614 ptln($del.'<br />',6); 615 ptln('<div class="meta">',6); 616 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'); 617 618 if($w>120){ 619 print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?w=120&media='.urlencode($item['id']).'" width="120" class="thumb" />'; 620 }else{ 621 print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?media='.urlencode($item['id']).'" width="'.$w.'" height="'.$h.'" class="thumb" />'; 622 } 623 print '</a>'; 624 625 //read EXIF/IPTC data 626 $meta = new JpegMeta(mediaFN($item['id'])); 627 $t = $meta->getField('IPTC.Headline'); 628 if($t) print '<b>'.$t.'</b><br />'; 629 630 $t = $meta->getField(array('IPTC.Caption','EXIF.UserComment','EXIF.TIFFImageDescription','EXIF.TIFFUserComment')); 631 if($t) print $t.'<br />'; 632 633 $t = $meta->getField(array('IPTC.Keywords','IPTC.Category')); 634 if($t) print '<i>'.$t.'</i><br />'; 635 636 ptln('</div>',6); 637 }else{ 638 ptln ('('.filesize_h($item['size']).')',6); 639 ptln($del,6); 640 } 641 ptln('</li>',4); 642 } 643 ptln('</ul>',2); 644} 645 646/** 647 * show references to a media file 648 * References uses the same visual as search results and share 649 * their CSS tags except pagenames won't be links. 650 * 651 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 652 */ 653function tpl_showreferences(&$data){ 654 global $lang; 655 656 $hidden=0; //count of hits without read permission 657 658 if(count($data)){ 659 usort($data,'sort_search_fulltext'); 660 foreach($data as $row){ 661 if(auth_quickaclcheck($row['id']) >= AUTH_READ){ 662 print '<div class="search_result">'; 663 print '<span class="mediaref_ref">'.$row['id'].'</span>'; 664 print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />'; 665 print '<div class="search_snippet">'.$row['snippet'].'</div>'; 666 print '</div>'; 667 }else 668 $hidden++; 669 } 670 if ($hidden){ 671 print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>'; 672 } 673 } 674} 675 676/** 677 * Print the media upload form if permissions are correct 678 * 679 * @author Andreas Gohr <andi@splitbrain.org> 680 */ 681function tpl_mediauploadform(){ 682 global $NS; 683 global $UPLOADOK; 684 global $AUTH; 685 global $lang; 686 687 if(!$UPLOADOK) return; 688 689 ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" name="upload"'. 690 ' method="post" enctype="multipart/form-data">',2); 691 ptln($lang['txt_upload'].':<br />',4); 692 ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 693 ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 694 ptln($lang['txt_filename'].'<br />',4); 695 ptln('<input type="text" name="id" class="edit" />',4); 696 ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 697 if($AUTH >= AUTH_DELETE){ 698 ptln('<label for="ow" class="simple"><input type="checkbox" name="ow" value="1" id="ow">'.$lang['txt_overwrt'].'</label>',4); 699 } 700 ptln('</form>',2); 701} 702 703/** 704 * Prints the name of the given page (current one if none given). 705 * 706 * If useheading is enabled this will use the first headline else 707 * the given ID is printed. 708 * 709 * @author Andreas Gohr <andi@splitbrain.org> 710 */ 711function tpl_pagetitle($id=null){ 712 global $conf; 713 if(is_null($id)){ 714 global $ID; 715 $id = $ID; 716 } 717 718 $name = $id; 719 if ($conf['useheading']) { 720 $title = p_get_first_heading($id); 721 if ($title) $name = $title; 722 } 723 print hsc($name); 724} 725 726/** 727 * Returns the requested EXIF/IPTC tag from the current image 728 * 729 * If $tags is an array all given tags are tried until a 730 * value is found. If no value is found $alt is returned. 731 * 732 * Which texts are known is defined in the functions _exifTagNames 733 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 734 * to the names of the latter one) 735 * 736 * Only allowed in: detail.php 737 * 738 * @author Andreas Gohr <andi@splitbrain.org> 739 */ 740function tpl_img_getTag($tags,$alt=''){ 741 // Init Exif Reader 742 global $SRC; 743 static $meta = null; 744 if(is_null($meta)) $meta = new JpegMeta($SRC); 745 if($meta === false) return $alt; 746 $info = $meta->getField($tags); 747 if($info == false) return $alt; 748 return $info; 749} 750 751/** 752 * Prints the image with a link to the full sized version 753 * 754 * Only allowed in: detail.php 755 */ 756function tpl_img($maxwidth=900,$maxheight=700){ 757 global $IMG; 758 $w = tpl_img_getTag('File.Width'); 759 $h = tpl_img_getTag('File.Height'); 760 761 //resize to given max values 762 $ratio = 0; 763 if($w > $h){ 764 if($w > $maxwidth){ 765 $ratio = $maxwidth/$w; 766 }elseif($h > $maxheight){ 767 $ratio = $maxheight/$h; 768 } 769 }else{ 770 if($h > $maxheight){ 771 $ratio = $maxheight/$h; 772 }elseif($w > $maxwidth){ 773 $ratio = $maxwidth/$w; 774 } 775 } 776 if($ratio){ 777 $w = floor($ratio*$w); 778 $h = floor($ratio*$h); 779 } 780 781 //prepare URL 782 $p = array(); 783 $p['cache'] = $_REQUEST['cache']; 784 $p['media'] = $IMG; 785 $p = buildURLparams($p); 786 $url=DOKU_BASE.'lib/exe/fetch.php?'.$p; 787 788 //prepare attributes 789 $alt=tpl_img_getTag('Simple.Title'); 790 $p = array(); 791 if($w) $p['width'] = $w; 792 if($h) $p['height'] = $h; 793 $p['class'] = 'img_detail'; 794 if($alt){ 795 $p['alt'] = $alt; 796 $p['title'] = $alt; 797 }else{ 798 $p['alt'] = ''; 799 } 800 $p = buildAttributes($p); 801 802 print '<a href="'.$url.'">'; 803 print '<img src="'.$url.'&w='.$w.'&h='.$w.'" '.$p.'/>'; 804 print '</a>'; 805} 806 807//Setup VIM: ex: et ts=2 enc=utf-8 : 808