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