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