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