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