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 }else{ 765 print ' ('.$lang['external_edit'].')'; 766 } 767 if($INFO['locked']){ 768 print ' · '; 769 print $lang['lockedby']; 770 print ': '; 771 print $INFO['locked']; 772 } 773 } 774} 775 776/** 777 * Prints or returns the name of the given page (current one if none given). 778 * 779 * If useheading is enabled this will use the first headline else 780 * the given ID is used. 781 * 782 * @author Andreas Gohr <andi@splitbrain.org> 783 */ 784function tpl_pagetitle($id=null, $ret=false){ 785 global $conf; 786 if(is_null($id)){ 787 global $ID; 788 $id = $ID; 789 } 790 791 $name = $id; 792 if ($conf['useheading']) { 793 $title = p_get_first_heading($id); 794 if ($title) $name = $title; 795 } 796 797 if ($ret) { 798 return hsc($name); 799 } else { 800 print hsc($name); 801 } 802} 803 804/** 805 * Returns the requested EXIF/IPTC tag from the current image 806 * 807 * If $tags is an array all given tags are tried until a 808 * value is found. If no value is found $alt is returned. 809 * 810 * Which texts are known is defined in the functions _exifTagNames 811 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 812 * to the names of the latter one) 813 * 814 * Only allowed in: detail.php 815 * 816 * @author Andreas Gohr <andi@splitbrain.org> 817 */ 818function tpl_img_getTag($tags,$alt='',$src=null){ 819 // Init Exif Reader 820 global $SRC; 821 822 if(is_null($src)) $src = $SRC; 823 824 static $meta = null; 825 if(is_null($meta)) $meta = new JpegMeta($src); 826 if($meta === false) return $alt; 827 $info = $meta->getField($tags); 828 if($info == false) return $alt; 829 return $info; 830} 831 832/** 833 * Prints the image with a link to the full sized version 834 * 835 * Only allowed in: detail.php 836 */ 837function tpl_img($maxwidth=0,$maxheight=0){ 838 global $IMG; 839 $w = tpl_img_getTag('File.Width'); 840 $h = tpl_img_getTag('File.Height'); 841 842 //resize to given max values 843 $ratio = 1; 844 if($w >= $h){ 845 if($maxwidth && $w >= $maxwidth){ 846 $ratio = $maxwidth/$w; 847 }elseif($maxheight && $h > $maxheight){ 848 $ratio = $maxheight/$h; 849 } 850 }else{ 851 if($maxheight && $h >= $maxheight){ 852 $ratio = $maxheight/$h; 853 }elseif($maxwidth && $w > $maxwidth){ 854 $ratio = $maxwidth/$w; 855 } 856 } 857 if($ratio){ 858 $w = floor($ratio*$w); 859 $h = floor($ratio*$h); 860 } 861 862 //prepare URLs 863 $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); 864 $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); 865 866 //prepare attributes 867 $alt=tpl_img_getTag('Simple.Title'); 868 $p = array(); 869 if($w) $p['width'] = $w; 870 if($h) $p['height'] = $h; 871 $p['class'] = 'img_detail'; 872 if($alt){ 873 $p['alt'] = $alt; 874 $p['title'] = $alt; 875 }else{ 876 $p['alt'] = ''; 877 } 878 $p = buildAttributes($p); 879 880 print '<a href="'.$url.'">'; 881 print '<img src="'.$src.'" '.$p.'/>'; 882 print '</a>'; 883} 884 885/** 886 * This function inserts a 1x1 pixel gif which in reality 887 * is the inexer function. 888 * 889 * Should be called somewhere at the very end of the main.php 890 * template 891 */ 892function tpl_indexerWebBug(){ 893 global $ID; 894 global $INFO; 895 if(!$INFO['exists']) return; 896 897 if(isHiddenPage($ID)) return; //no need to index hidden pages 898 899 $p = array(); 900 $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 901 '&'.time(); 902 $p['width'] = 1; 903 $p['height'] = 1; 904 $p['alt'] = ''; 905 $att = buildAttributes($p); 906 print "<img $att />"; 907} 908 909// configuration methods 910/** 911 * tpl_getConf($id) 912 * 913 * use this function to access template configuration variables 914 */ 915function tpl_getConf($id){ 916 global $conf; 917 global $tpl_configloaded; 918 919 $tpl = $conf['template']; 920 921 if (!$tpl_configloaded){ 922 $tconf = tpl_loadConfig(); 923 if ($tconf !== false){ 924 foreach ($tconf as $key => $value){ 925 if (isset($conf['tpl'][$tpl][$key])) continue; 926 $conf['tpl'][$tpl][$key] = $value; 927 } 928 $tpl_configloaded = true; 929 } 930 } 931 932 return $conf['tpl'][$tpl][$id]; 933} 934 935/** 936 * tpl_loadConfig() 937 * reads all template configuration variables 938 * this function is automatically called by tpl_getConf() 939 */ 940function tpl_loadConfig(){ 941 942 $file = DOKU_TPLINC.'/conf/default.php'; 943 $conf = array(); 944 945 if (!@file_exists($file)) return false; 946 947 // load default config file 948 include($file); 949 950 return $conf; 951} 952 953/** 954 * prints the "main content" in the mediamanger popup 955 * 956 * Depending on the user's actions this may be a list of 957 * files in a namespace, the meta editing dialog or 958 * a message of referencing pages 959 * 960 * Only allowed in mediamanager.php 961 * 962 * @author Andreas Gohr <andi@splitbrain.org> 963 */ 964function tpl_mediaContent(){ 965 global $IMG; 966 global $AUTH; 967 global $INUSE; 968 global $NS; 969 global $JUMPTO; 970 971 ptln('<div id="media__content">'); 972 if($_REQUEST['edit']){ 973 media_metaform($IMG,$AUTH); 974 }elseif(is_array($INUSE)){ 975 media_filesinuse($INUSE,$IMG); 976 }else{ 977 media_filelist($NS,$AUTH,$JUMPTO); 978 } 979 ptln('</div>'); 980} 981 982/** 983 * prints the namespace tree in the mediamanger popup 984 * 985 * Only allowed in mediamanager.php 986 * 987 * @author Andreas Gohr <andi@splitbrain.org> 988 */ 989function tpl_mediaTree(){ 990 global $NS; 991 992 ptln('<div id="media__tree">'); 993 media_nstree($NS); 994 ptln('</div>'); 995} 996 997//Setup VIM: ex: et ts=2 enc=utf-8 : 998