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