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 133 $plugin = NULL; 134 if ($_REQUEST['page']) { 135 $pluginlist = plugin_list('admin'); 136 137 if (in_array($_REQUEST['page'], $pluginlist)) { 138 139 // attempt to load the plugin 140 $plugin =& plugin_load('admin',$_REQUEST['page']); 141 } 142 } 143 144 if ($plugin !== NULL) 145 $plugin->html(); 146 else 147 html_admin(); 148/* 149 switch($_REQUEST['page']){ 150 case 'acl': 151 admin_acl_html(); 152 break; 153 case 'plugin': 154 require_once(DOKU_INC.'inc/admin_plugin.php'); 155 admin_plugin_html(); 156 break; 157 default: 158 html_admin(); 159 } 160*/ 161} 162 163/** 164 * Print the correct HTML meta headers 165 * 166 * This has to go into the head section of your template. 167 * 168 * @author Andreas Gohr <andi@splitbrain.org> 169 */ 170function tpl_metaheaders(){ 171 global $ID; 172 global $INFO; 173 global $ACT; 174 global $lang; 175 global $conf; 176 $it=2; 177 178 // the usual stuff 179 ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 180 ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 181 ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 182 ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 183 ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 184 ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it); 185 ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it); 186 ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/styles/style.css" />',$it); 187 188 // setup robot tags apropriate for different modes 189 if( ($ACT=='show' || $ACT=='export_html') && !$REV){ 190 if($INFO['exists']){ 191 ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 192 //delay indexing: 193 if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 194 ptln('<meta name="robots" content="index,follow" />',$it); 195 }else{ 196 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 197 } 198 }else{ 199 ptln('<meta name="robots" content="noindex,follow" />',$it); 200 } 201 }else{ 202 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 203 } 204 205 // include some JavaScript language strings 206 ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it); 207 ptln(" var alertText = '".str_replace('\\\\n','\\n',addslashes($lang['qb_alert']))."'",$it); 208 ptln(" var notSavedYet = '".str_replace('\\\\n','\\n',addslashes($lang['notsavedyet']))."'",$it); 209 ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it); 210 ptln('</script>',$it); 211 212 // load the default JavaScript files 213 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 214 DOKU_BASE.'lib/scripts/script.js"></script>',$it); 215 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 216 DOKU_BASE.'lib/scripts/tw-sack.js"></script>',$it); 217 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 218 DOKU_BASE.'lib/scripts/ajax.js"></script>',$it); 219 220 // load spellchecker script if wanted 221 if($conf['spellchecker'] && ($ACT=='edit' || $ACT=='preview')){ 222 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 223 DOKU_BASE.'lib/scripts/spellcheck.js"></script>',$it); 224 } 225 226 // dom tool tip library, for insitu footnotes 227 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 228 DOKU_BASE.'lib/scripts/domLib.js"></script>',$it); 229 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 230 DOKU_BASE.'lib/scripts/domTT.js"></script>',$it); 231 232 // plugin stylesheets and Scripts 233 plugin_printCSSJS(); 234} 235 236/** 237 * Print a link 238 * 239 * Just builds a link but adds additional JavaScript needed for 240 * the unsaved data check needed in the edit form. 241 * 242 * @author Andreas Gohr <andi@splitbrain.org> 243 */ 244function tpl_link($url,$name,$more=''){ 245 print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; 246 if ($more) print ' '.$more; 247 print ">$name</a>"; 248} 249 250/** 251 * Prints a link to a WikiPage 252 * 253 * Wrapper around html_wikilink 254 * 255 * @author Andreas Gohr <andi@splitbrain.org> 256 */ 257function tpl_pagelink($id,$name=NULL){ 258 print html_wikilink($id,$name); 259} 260 261/** 262 * get the parent page 263 * 264 * Tries to find out which page is parent. 265 * returns false if none is available 266 * 267 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 268 */ 269function tpl_getparent($ID){ 270 global $conf; 271 272 if ($ID != $conf['start']) { 273 $idparts = explode(':', $ID); 274 $pn = array_pop($idparts); // get the page name 275 276 for ($n=0; $n < 2; $n++) { 277 if (count($idparts) == 0) { 278 $ID = $conf['start']; // go to topmost page 279 break; 280 }else{ 281 $ns = array_pop($idparts); // get the last part of namespace 282 if ($pn != $ns) { // are we already home? 283 array_push($idparts, $ns, $ns); // no, then add a page with same name 284 $ID = implode (':', $idparts); // as the namespace and recombine $ID 285 break; 286 } 287 } 288 } 289 290 if (@file_exists(wikiFN($ID))) { 291 return $ID; 292 } 293 } 294 return false; 295} 296 297/** 298 * Print one of the buttons 299 * 300 * Available Buttons are 301 * 302 * edit - edit/create/show button 303 * history - old revisions 304 * recent - recent changes 305 * login - login/logout button - if ACL enabled 306 * index - The index 307 * admin - admin page - if enough rights 308 * top - a back to top button 309 * back - a back to parent button - if available 310 * backtomedia - returns to the mediafile upload dialog 311 * after references have been displayed 312 * backlink - links to the list of backlinks 313 * 314 * @author Andreas Gohr <andi@splitbrain.org> 315 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 316 */ 317function tpl_button($type){ 318 global $ACT; 319 global $ID; 320 global $NS; 321 global $INFO; 322 global $conf; 323 324 switch($type){ 325 case 'edit': 326 print html_editbutton(); 327 break; 328 case 'history': 329 print html_btn('revs',$ID,'o',array('do' => 'revisions')); 330 break; 331 case 'recent': 332 print html_btn('recent','','r',array('do' => 'recent')); 333 break; 334 case 'index': 335 print html_btn('index',$ID,'x',array('do' => 'index')); 336 break; 337 case 'back': 338 if ($ID = tpl_getparent($ID)) { 339 print html_btn('back',$ID,'b',array('do' => 'show')); 340 } 341 break; 342 case 'top': 343 print html_topbtn(); 344 break; 345 case 'login': 346 if($conf['useacl']){ 347 if($_SERVER['REMOTE_USER']){ 348 print html_btn('logout',$ID,'',array('do' => 'logout',)); 349 }else{ 350 print html_btn('login',$ID,'',array('do' => 'login')); 351 } 352 } 353 break; 354 case 'admin': 355 if($INFO['perm'] == AUTH_ADMIN) 356 print html_btn('admin',$ID,'',array('do' => 'admin')); 357 break; 358 case 'backtomedia': 359 print html_backtomedia_button(array('ns' => $NS),'b'); 360 break; 361 case 'subscription': 362 if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 363 if($_SERVER['REMOTE_USER']){ 364 if($INFO['subscribed']){ 365 print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',)); 366 } else { 367 print html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); 368 } 369 } 370 } 371 break; 372 case 'backlink': 373 print html_btn('backlink',$ID,'',array('do' => 'backlink')); 374 break; 375 default: 376 print '[unknown button type]'; 377 } 378} 379 380/** 381 * Like the action buttons but links 382 * 383 * Available links are 384 * 385 * edit - edit/create/show button 386 * history - old revisions 387 * recent - recent changes 388 * login - login/logout button - if ACL enabled 389 * index - The index 390 * admin - admin page - if enough rights 391 * top - a back to top button 392 * back - a back to parent button - if available 393 * backlink - links to the list of backlinks 394 * 395 * @author Andreas Gohr <andi@splitbrain.org> 396 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 397 * @see tpl_button 398 */ 399function tpl_actionlink($type,$pre='',$suf=''){ 400 global $ID; 401 global $INFO; 402 global $REV; 403 global $ACT; 404 global $conf; 405 global $lang; 406 407 switch($type){ 408 case 'edit': 409 #most complicated type - we need to decide on current action 410 if($ACT == 'show' || $ACT == 'search'){ 411 if($INFO['writable']){ 412 if($INFO['exists']){ 413 tpl_link(wl($ID,'do=edit&rev='.$REV), 414 $pre.$lang['btn_edit'].$suf, 415 'class="action edit" accesskey="e" rel="nofollow"'); 416 }else{ 417 tpl_link(wl($ID,'do=edit&rev='.$REV), 418 $pre.$lang['btn_create'].$suf, 419 'class="action create" accesskey="e" rel="nofollow"'); 420 } 421 }else{ 422 tpl_link(wl($ID,'do=edit&rev='.$REV), 423 $pre.$lang['btn_source'].$suf, 424 'class="action source" accesskey="v" rel="nofollow"'); 425 } 426 }else{ 427 tpl_link(wl($ID,'do=show'), 428 $pre.$lang['btn_show'].$suf, 429 'class="action show" accesskey="v" rel="nofollow"'); 430 } 431 break; 432 case 'history': 433 tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"'); 434 break; 435 case 'recent': 436 tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"'); 437 break; 438 case 'index': 439 tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"'); 440 break; 441 case 'top': 442 print '<a href="#top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 443 break; 444 case 'back': 445 if ($ID = tpl_getparent($ID)) { 446 tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"'); 447 } 448 break; 449 case 'login': 450 if($conf['useacl']){ 451 if($_SERVER['REMOTE_USER']){ 452 tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"'); 453 }else{ 454 tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"'); 455 } 456 } 457 break; 458 case 'admin': 459 if($INFO['perm'] == AUTH_ADMIN) 460 tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"'); 461 break; 462 case 'subscribe': 463 case 'subscription': 464 if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 465 if($_SERVER['REMOTE_USER']){ 466 if($INFO['subscribed']) { 467 tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"'); 468 } else { 469 tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"'); 470 } 471 } 472 } 473 break; 474 case 'backlink': 475 tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"'); 476 break; 477 default: 478 print '[unknown link type]'; 479 } 480} 481 482/** 483 * Print the search form 484 * 485 * @author Andreas Gohr <andi@splitbrain.org> 486 */ 487function tpl_searchform(){ 488 global $lang; 489 global $ACT; 490 491 print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search" onsubmit="return svchk()">'; 492 print '<input type="hidden" name="do" value="search" />'; 493 print '<input type="text" '; 494 495 if ($ACT == 'search') 496 print 'value="'.$_REQUEST['id'].'" '; /* keep search input as long as user stays on search page */ 497 498 print 'id="qsearch_in" accesskey="f" name="id" class="edit" onkeyup="ajax_qsearch.call(\'qsearch_in\',\'qsearch_out\')" />'; 499 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 500 print '<div id="qsearch_out" class="ajax_qsearch" onclick="this.style.display=\'none\'"></div>'; 501 print '</form>'; 502} 503 504/** 505 * Print the breadcrumbs trace 506 * 507 * @author Andreas Gohr <andi@splitbrain.org> 508 */ 509function tpl_breadcrumbs(){ 510 global $lang; 511 global $conf; 512 513 //check if enabled 514 if(!$conf['breadcrumbs']) return; 515 516 $crumbs = breadcrumbs(); //setup crumb trace 517 518 //reverse crumborder in right-to-left mode 519 if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 520 521 //render crumbs, highlight the last one 522 print $lang['breadcrumb'].':'; 523 $last = count($crumbs); 524 $i = 0; 525 foreach ($crumbs as $id => $name){ 526 $i++; 527 print ' <span class="bcsep">»</span> '; 528 if ($i == $last) print '<span class="curid">'; 529 tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 530 if ($i == $last) print '</span>'; 531 } 532} 533 534/** 535 * Hierarchical breadcrumbs 536 * 537 * This code was suggested as replacement for the usual breadcrumbs 538 * trail in the Wiki and was modified by me. 539 * It only makes sense with a deep site structure. 540 * 541 * @author Andreas Gohr <andi@splitbrain.org> 542 * @author Nigel McNie <oracle.shinoda@gmail.com> 543 * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 544 * @todo May behave strangely in RTL languages 545 */ 546function tpl_youarehere(){ 547 global $conf; 548 global $ID; 549 global $lang; 550 551 552 $parts = explode(':', $ID); 553 554 // Perhaps a $lang['tree'] could be defined? "Trace" isn't too appropriate 555 //print $lang['tree'].': '; 556 print $lang['breadcrumb'].': '; 557 558 //always print the startpage 559 if( $a_part[0] != $conf['start'] ) 560 tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"'); 561 562 $page = ''; 563 foreach ($parts as $part){ 564 // Skip startpage if already done 565 if ($part == $conf['start']) continue; 566 567 print ' » '; 568 $page .= $part; 569 570 if(file_exists(wikiFN($page))){ 571 tpl_link(wl($page),$part,'title="'.$page.'"'); 572 }else{ 573 // Print the link, but mark as not-existing, as for other non-existing links 574 tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"'); 575 //print $page; 576 } 577 578 $page .= ':'; 579 } 580} 581 582/** 583 * Print info if the user is logged in 584 * and show full name in that case 585 * 586 * Could be enhanced with a profile link in future? 587 * 588 * @author Andreas Gohr <andi@splitbrain.org> 589 */ 590function tpl_userinfo(){ 591 global $lang; 592 global $INFO; 593 if($_SERVER['REMOTE_USER']) 594 print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 595} 596 597/** 598 * Print some info about the current page 599 * 600 * @author Andreas Gohr <andi@splitbrain.org> 601 */ 602function tpl_pageinfo(){ 603 global $conf; 604 global $lang; 605 global $INFO; 606 global $REV; 607 608 // prepare date and path 609 $fn = $INFO['filepath']; 610 if(!$conf['fullpath']){ 611 if($REV){ 612 $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 613 }else{ 614 $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 615 } 616 } 617 $fn = utf8_decodeFN($fn); 618 $date = date($conf['dformat'],$INFO['lastmod']); 619 620 // print it 621 if($INFO['exists']){ 622 print $fn; 623 print ' · '; 624 print $lang['lastmod']; 625 print ': '; 626 print $date; 627 if($INFO['editor']){ 628 print ' '.$lang['by'].' '; 629 print $INFO['editor']; 630 } 631 if($INFO['locked']){ 632 print ' · '; 633 print $lang['lockedby']; 634 print ': '; 635 print $INFO['locked']; 636 } 637 } 638} 639 640/** 641 * Print a list of namespaces containing media files 642 * 643 * @author Andreas Gohr <andi@splitbrain.org> 644 */ 645function tpl_medianamespaces(){ 646 global $conf; 647 648 $data = array(); 649 search($data,$conf['mediadir'],'search_namespaces',array()); 650 print html_buildlist($data,'idx',media_html_list_namespaces); 651} 652 653/** 654 * Print a list of mediafiles in the current namespace 655 * 656 * @author Andreas Gohr <andi@splitbrain.org> 657 */ 658function tpl_mediafilelist(){ 659 global $conf; 660 global $lang; 661 global $NS; 662 global $AUTH; 663 $dir = utf8_encodeFN(str_replace(':','/',$NS)); 664 665 $data = array(); 666 search($data,$conf['mediadir'],'search_media',array(),$dir); 667 668 if(!count($data)){ 669 ptln('<div class="nothing">'.$lang['nothingfound'].'</div>'); 670 return; 671 } 672 673 ptln('<ul>',2); 674 foreach($data as $item){ 675 ptln('<li>',4); 676 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'. 677 utf8_decodeFN($item['file']). 678 '</a>',6); 679 680 //prepare deletion button 681 if($AUTH >= AUTH_DELETE){ 682 $ask = $lang['del_confirm'].'\\n'; 683 $ask .= $item['id']; 684 685 $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.urlencode($item['id']).'" '. 686 'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'. 687 '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '. 688 'align="bottom" title="'.$lang['btn_delete'].'" /></a>'; 689 }else{ 690 $del = ''; 691 } 692 693 if($item['isimg']){ 694 $w = $item['meta']->getField('File.Width'); 695 $h = $item['meta']->getField('File.Height'); 696 697 ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')',6); 698 ptln($del.'<br />',6); 699 ptln('<div class="imagemeta">',6); 700 701 //build thumbnail 702 print '<a href="javascript:mediaSelect(\''.$item['id'].'\')">'; 703 704 if($w>120 || $h>120){ 705 $ratio = $item['meta']->getResizeRatio(120); 706 $w = floor($w * $ratio); 707 $h = floor($h * $ratio); 708 } 709 710 $src = ml($item['id'],array('w'=>$w,'h'=>$h)); 711 712 $p = array(); 713 $p['width'] = $w; 714 $p['height'] = $h; 715 $p['alt'] = $item['id']; 716 $p['class'] = 'thumb'; 717 $att = buildAttributes($p); 718 719 print '<img src="'.$src.'" '.$att.' />'; 720 print '</a>'; 721 722 //read EXIF/IPTC data 723 $t = $item['meta']->getField('IPTC.Headline'); 724 if($t) print '<b>'.$t.'</b><br />'; 725 726 $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment', 727 'EXIF.TIFFImageDescription', 728 'EXIF.TIFFUserComment')); 729 if($t) print $t.'<br />'; 730 731 $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category')); 732 if($t) print '<i>'.$t.'</i><br />'; 733 734 //add edit button 735 if($AUTH >= AUTH_UPLOAD && $item['meta']->getField('File.Mime') == 'image/jpeg'){ 736 print '<a href="'.DOKU_BASE.'lib/exe/media.php?edit='.urlencode($item['id']).'">'; 737 print '<img src="'.DOKU_BASE.'lib/images/edit.gif" alt="'.$lang['metaedit'].'" title="'.$lang['metaedit'].'" />'; 738 print '</a>'; 739 } 740 741 ptln('</div>',6); 742 }else{ 743 ptln ('('.filesize_h($item['size']).')',6); 744 ptln($del,6); 745 } 746 ptln('</li>',4); 747 } 748 ptln('</ul>',2); 749} 750 751/** 752 * show references to a media file 753 * References uses the same visual as search results and share 754 * their CSS tags except pagenames won't be links. 755 * 756 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 757 */ 758function tpl_showreferences(&$data){ 759 global $lang; 760 761 $hidden=0; //count of hits without read permission 762 763 if(count($data)){ 764 usort($data,'sort_search_fulltext'); 765 foreach($data as $row){ 766 if(auth_quickaclcheck($row['id']) >= AUTH_READ){ 767 print '<div class="search_result">'; 768 print '<span class="mediaref_ref">'.$row['id'].'</span>'; 769 print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />'; 770 print '<div class="search_snippet">'.$row['snippet'].'</div>'; 771 print '</div>'; 772 }else 773 $hidden++; 774 } 775 if ($hidden){ 776 print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>'; 777 } 778 } 779} 780 781/** 782 * Print the media upload form if permissions are correct 783 * 784 * @author Andreas Gohr <andi@splitbrain.org> 785 */ 786function tpl_mediauploadform(){ 787 global $NS; 788 global $UPLOADOK; 789 global $AUTH; 790 global $lang; 791 792 if(!$UPLOADOK) return; 793 794 ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" name="upload"'. 795 ' method="post" enctype="multipart/form-data">',2); 796 ptln($lang['txt_upload'].':<br />',4); 797 ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 798 ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 799 ptln($lang['txt_filename'].'<br />',4); 800 ptln('<input type="text" name="id" class="edit" />',4); 801 ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 802 if($AUTH >= AUTH_DELETE){ 803 ptln('<label for="ow"><input type="checkbox" name="ow" value="1" id="ow">'.$lang['txt_overwrt'].'</label>',4); 804 } 805 ptln('</form>',2); 806} 807 808/** 809 * Prints the name of the given page (current one if none given). 810 * 811 * If useheading is enabled this will use the first headline else 812 * the given ID is printed. 813 * 814 * @author Andreas Gohr <andi@splitbrain.org> 815 */ 816function tpl_pagetitle($id=null){ 817 global $conf; 818 if(is_null($id)){ 819 global $ID; 820 $id = $ID; 821 } 822 823 $name = $id; 824 if ($conf['useheading']) { 825 $title = p_get_first_heading($id); 826 if ($title) $name = $title; 827 } 828 print hsc($name); 829} 830 831/** 832 * Returns the requested EXIF/IPTC tag from the current image 833 * 834 * If $tags is an array all given tags are tried until a 835 * value is found. If no value is found $alt is returned. 836 * 837 * Which texts are known is defined in the functions _exifTagNames 838 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 839 * to the names of the latter one) 840 * 841 * Only allowed in: detail.php, mediaedit.php 842 * 843 * @author Andreas Gohr <andi@splitbrain.org> 844 */ 845function tpl_img_getTag($tags,$alt=''){ 846 // Init Exif Reader 847 global $SRC; 848 static $meta = null; 849 if(is_null($meta)) $meta = new JpegMeta($SRC); 850 if($meta === false) return $alt; 851 $info = $meta->getField($tags); 852 if($info == false) return $alt; 853 return $info; 854} 855 856/** 857 * Prints the image with a link to the full sized version 858 * 859 * Only allowed in: detail.php 860 */ 861function tpl_img($maxwidth=0,$maxheight=0){ 862 global $IMG; 863 $w = tpl_img_getTag('File.Width'); 864 $h = tpl_img_getTag('File.Height'); 865 866 //resize to given max values 867 $ratio = 1; 868 if($w >= $h){ 869 if($maxwidth && $w >= $maxwidth){ 870 $ratio = $maxwidth/$w; 871 }elseif($maxheight && $h > $maxheight){ 872 $ratio = $maxheight/$h; 873 } 874 }else{ 875 if($maxheight && $h >= $maxheight){ 876 $ratio = $maxheight/$h; 877 }elseif($maxwidth && $w > $maxwidth){ 878 $ratio = $maxwidth/$w; 879 } 880 } 881 if($ratio){ 882 $w = floor($ratio*$w); 883 $h = floor($ratio*$h); 884 } 885 886 //prepare URLs 887 $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); 888 $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); 889 890 //prepare attributes 891 $alt=tpl_img_getTag('Simple.Title'); 892 $p = array(); 893 if($w) $p['width'] = $w; 894 if($h) $p['height'] = $h; 895 $p['class'] = 'img_detail'; 896 if($alt){ 897 $p['alt'] = $alt; 898 $p['title'] = $alt; 899 }else{ 900 $p['alt'] = ''; 901 } 902 $p = buildAttributes($p); 903 904 print '<a href="'.$url.'">'; 905 print '<img src="'.$src.'" '.$p.'/>'; 906 print '</a>'; 907} 908 909/** 910 * This function inserts a 1x1 pixel gif which in reality 911 * is the inexer function. 912 * 913 * Should be called somewhere at the very end of the main.php 914 * template 915 */ 916function tpl_indexerWebBug(){ 917 global $ID; 918 global $INFO; 919 if(!$INFO['exists']) return; 920 921 $p = array(); 922 $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.urlencode($ID). 923 '&'.time(); 924 $p['width'] = 1; 925 $p['height'] = 1; 926 $p['alt'] = ''; 927 $att = buildAttributes($p); 928 print "<img $att />"; 929} 930 931//Setup VIM: ex: et ts=2 enc=utf-8 : 932