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