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