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