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