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