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