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