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