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 9if(!defined('DOKU_INC')) die('meh.'); 10 11/** 12 * Returns the path to the given template, uses 13 * default one if the custom version doesn't exist. 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 */ 17function template($tpl){ 18 global $conf; 19 20 if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) 21 return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; 22 23 return DOKU_INC.'lib/tpl/default/'.$tpl; 24} 25 26/** 27 * Print the content 28 * 29 * This function is used for printing all the usual content 30 * (defined by the global $ACT var) by calling the appropriate 31 * outputfunction(s) from html.php 32 * 33 * Everything that doesn't use the main template file isn't 34 * handled by this function. ACL stuff is not done here either. 35 * 36 * @author Andreas Gohr <andi@splitbrain.org> 37 */ 38function tpl_content($prependTOC=true) { 39 global $ACT; 40 global $INFO; 41 $INFO['prependTOC'] = $prependTOC; 42 43 ob_start(); 44 trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core'); 45 $html_output = ob_get_clean(); 46 trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln'); 47 48 return !empty($html_output); 49} 50 51function tpl_content_core(){ 52 global $ACT; 53 global $TEXT; 54 global $PRE; 55 global $SUF; 56 global $SUM; 57 global $IDX; 58 59 switch($ACT){ 60 case 'show': 61 html_show(); 62 break; 63 case 'preview': 64 html_edit($TEXT); 65 html_show($TEXT); 66 break; 67 case 'recover': 68 html_edit($TEXT); 69 break; 70 case 'edit': 71 html_edit(); 72 break; 73 case 'draft': 74 html_draft(); 75 break; 76 case 'wordblock': 77 html_edit($TEXT,'wordblock'); 78 break; 79 case 'search': 80 html_search(); 81 break; 82 case 'revisions': 83 $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; 84 html_revisions($first); 85 break; 86 case 'diff': 87 html_diff(); 88 break; 89 case 'recent': 90 if (is_array($_REQUEST['first'])) { 91 $_REQUEST['first'] = array_keys($_REQUEST['first']); 92 $_REQUEST['first'] = $_REQUEST['first'][0]; 93 } 94 $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; 95 html_recent($first); 96 break; 97 case 'index': 98 html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 99 break; 100 case 'backlink': 101 html_backlinks(); 102 break; 103 case 'conflict': 104 html_conflict(con($PRE,$TEXT,$SUF),$SUM); 105 html_diff(con($PRE,$TEXT,$SUF),false); 106 break; 107 case 'locked': 108 html_locked(); 109 html_edit(); 110 break; 111 case 'login': 112 html_login(); 113 break; 114 case 'register': 115 html_register(); 116 break; 117 case 'resendpwd': 118 html_resendpwd(); 119 break; 120 case 'denied': 121 print p_locale_xhtml('denied'); 122 break; 123 case 'profile' : 124 html_updateprofile(); 125 break; 126 case 'admin': 127 tpl_admin(); 128 break; 129 default: 130 $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); 131 if ($evt->advise_before()) 132 msg("Failed to handle command: ".hsc($ACT),-1); 133 $evt->advise_after(); 134 unset($evt); 135 return false; 136 } 137 return true; 138} 139 140/** 141 * Places the TOC where the function is called 142 * 143 * If you use this you most probably want to call tpl_content with 144 * a false argument 145 * 146 * @author Andreas Gohr <andi@splitbrain.org> 147 */ 148function tpl_toc($return=false){ 149 global $TOC; 150 global $ACT; 151 global $ID; 152 global $REV; 153 global $INFO; 154 global $conf; 155 $toc = array(); 156 157 if(is_array($TOC)){ 158 // if a TOC was prepared in global scope, always use it 159 $toc = $TOC; 160 }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){ 161 // get TOC from metadata, render if neccessary 162 $meta = p_get_metadata($ID, false, true); 163 if(isset($meta['internal']['toc'])){ 164 $tocok = $meta['internal']['toc']; 165 }else{ 166 $tocok = true; 167 } 168 $toc = $meta['description']['tableofcontents']; 169 if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){ 170 $toc = array(); 171 } 172 }elseif($ACT == 'admin'){ 173 // try to load admin plugin TOC FIXME: duplicates code from tpl_admin 174 $plugin = null; 175 if (!empty($_REQUEST['page'])) { 176 $pluginlist = plugin_list('admin'); 177 if (in_array($_REQUEST['page'], $pluginlist)) { 178 // attempt to load the plugin 179 $plugin =& plugin_load('admin',$_REQUEST['page']); 180 } 181 } 182 if ( ($plugin !== null) && 183 (!$plugin->forAdminOnly() || $INFO['isadmin']) ){ 184 $toc = $plugin->getTOC(); 185 $TOC = $toc; // avoid later rebuild 186 } 187 } 188 189 trigger_event('TPL_TOC_RENDER', $toc, NULL, false); 190 $html = html_TOC($toc); 191 if($return) return $html; 192 echo $html; 193} 194 195/** 196 * Handle the admin page contents 197 * 198 * @author Andreas Gohr <andi@splitbrain.org> 199 */ 200function tpl_admin(){ 201 global $INFO; 202 global $TOC; 203 204 $plugin = null; 205 if (!empty($_REQUEST['page'])) { 206 $pluginlist = plugin_list('admin'); 207 208 if (in_array($_REQUEST['page'], $pluginlist)) { 209 210 // attempt to load the plugin 211 $plugin =& plugin_load('admin',$_REQUEST['page']); 212 } 213 } 214 215 if ($plugin !== null){ 216 if($plugin->forAdminOnly() && !$INFO['isadmin']){ 217 msg('For admins only',-1); 218 html_admin(); 219 }else{ 220 if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 221 if($INFO['prependTOC']) tpl_toc(); 222 $plugin->html(); 223 } 224 }else{ 225 html_admin(); 226 } 227 return true; 228} 229 230/** 231 * Print the correct HTML meta headers 232 * 233 * This has to go into the head section of your template. 234 * 235 * @triggers TPL_METAHEADER_OUTPUT 236 * @param boolean $alt Should feeds and alternative format links be added? 237 * @author Andreas Gohr <andi@splitbrain.org> 238 */ 239function tpl_metaheaders($alt=true){ 240 global $ID; 241 global $REV; 242 global $INFO; 243 global $ACT; 244 global $QUERY; 245 global $lang; 246 global $conf; 247 $it=2; 248 249 // prepare the head array 250 $head = array(); 251 252 253 // the usual stuff 254 $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() ); 255 $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml', 256 'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] ); 257 $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE ); 258 if(actionOK('index')){ 259 $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'), 260 'title'=>$lang['btn_index'] ); 261 } 262 263 if($alt){ 264 $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', 265 'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php'); 266 $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', 267 'title'=>'Current Namespace', 268 'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']); 269 if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){ 270 $head['link'][] = array( 'rel'=>'edit', 271 'title'=>$lang['btn_edit'], 272 'href'=> wl($ID,'do=edit',false,'&')); 273 } 274 275 if($ACT == 'search'){ 276 $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', 277 'title'=>'Search Result', 278 'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY); 279 } 280 281 if(actionOK('export_xhtml')){ 282 $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML', 283 'href'=>exportlink($ID, 'xhtml', '', false, '&')); 284 } 285 286 if(actionOK('export_raw')){ 287 $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup', 288 'href'=>exportlink($ID, 'raw', '', false, '&')); 289 } 290 } 291 292 // setup robot tags apropriate for different modes 293 if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ 294 if($INFO['exists']){ 295 //delay indexing: 296 if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 297 $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); 298 }else{ 299 $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); 300 } 301 $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') ); 302 }else{ 303 $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow'); 304 } 305 }elseif(defined('DOKU_MEDIADETAIL')){ 306 $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); 307 }else{ 308 $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); 309 } 310 311 // set metadata 312 if($ACT == 'show' || $ACT=='export_xhtml'){ 313 // date of modification 314 if($REV){ 315 $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV)); 316 }else{ 317 $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod'])); 318 } 319 320 // keywords (explicit or implicit) 321 if(!empty($INFO['meta']['subject'])){ 322 $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject'])); 323 }else{ 324 $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID)); 325 } 326 } 327 328 // load stylesheets 329 $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css', 330 'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template']); 331 $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css', 332 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template']); 333 $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css', 334 'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template']); 335 336 // make $INFO available to JavaScripts 337 require_once(DOKU_INC.'inc/JSON.php'); 338 $json = new JSON(); 339 $infocpy = $INFO; 340 $infocpy['userinfo']['login'] = $_SERVER['REMOTE_USER']; 341 $infocpy['userinfo']['pass'] = ''; 342 $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=> 'var INFO = '.$json->encode($infocpy).';'); 343 344 345 // load javascript 346 $js_edit = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0; 347 $js_write = ($INFO['writable']) ? 1 : 0; 348 if(defined('DOKU_MEDIAMANAGER')){ 349 $js_edit = 1; 350 $js_write = 0; 351 } 352 if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){ 353 $script = "NS='".$INFO['namespace']."';"; 354 if($conf['useacl'] && $_SERVER['REMOTE_USER']){ 355 require_once(DOKU_INC.'inc/toolbar.php'); 356 $script .= "SIG='".toolbar_signature()."';"; 357 } 358 $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', 359 '_data'=> $script); 360 } 361 $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'', 362 'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write); 363 364 365 // trigger event here 366 trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); 367 return true; 368} 369 370/** 371 * prints the array build by tpl_metaheaders 372 * 373 * $data is an array of different header tags. Each tag can have multiple 374 * instances. Attributes are given as key value pairs. Values will be HTML 375 * encoded automatically so they should be provided as is in the $data array. 376 * 377 * For tags having a body attribute specify the the body data in the special 378 * attribute '_data'. This field will NOT BE ESCAPED automatically. 379 * 380 * @author Andreas Gohr <andi@splitbrain.org> 381 */ 382function _tpl_metaheaders_action($data){ 383 foreach($data as $tag => $inst){ 384 foreach($inst as $attr){ 385 echo '<',$tag,' ',buildAttributes($attr); 386 if(isset($attr['_data']) || $tag == 'script'){ 387 if($tag == 'script' && $attr['_data']) 388 $attr['_data'] = "<!--//--><![CDATA[//><!--\n". 389 $attr['_data']. 390 "\n//--><!]]>"; 391 392 echo '>',$attr['_data'],'</',$tag,'>'; 393 }else{ 394 echo '/>'; 395 } 396 echo "\n"; 397 } 398 } 399} 400 401/** 402 * Print a link 403 * 404 * Just builds a link. 405 * 406 * @author Andreas Gohr <andi@splitbrain.org> 407 */ 408function tpl_link($url,$name,$more='',$return=false){ 409 $out = '<a href="'.$url.'" '; 410 if ($more) $out .= ' '.$more; 411 $out .= ">$name</a>"; 412 if ($return) return $out; 413 print $out; 414 return true; 415} 416 417/** 418 * Prints a link to a WikiPage 419 * 420 * Wrapper around html_wikilink 421 * 422 * @author Andreas Gohr <andi@splitbrain.org> 423 */ 424function tpl_pagelink($id,$name=NULL){ 425 print html_wikilink($id,$name); 426 return true; 427} 428 429/** 430 * get the parent page 431 * 432 * Tries to find out which page is parent. 433 * returns false if none is available 434 * 435 * @author Andreas Gohr <andi@splitbrain.org> 436 */ 437function tpl_getparent($id){ 438 global $conf; 439 $parent = getNS($id).':'; 440 resolve_pageid('',$parent,$exists); 441 if($parent == $id) { 442 $pos = strrpos (getNS($id),':'); 443 $parent = substr($parent,0,$pos).':'; 444 resolve_pageid('',$parent,$exists); 445 if($parent == $id) return false; 446 } 447 return $parent; 448} 449 450/** 451 * Print one of the buttons 452 * 453 * Available Buttons are 454 * 455 * edit - edit/create/show/draft button 456 * history - old revisions 457 * recent - recent changes 458 * login - login/logout button - if ACL enabled 459 * profile - user profile button (if logged in) 460 * index - The index 461 * admin - admin page - if enough rights 462 * top - a back to top button 463 * back - a back to parent button - if available 464 * backlink - links to the list of backlinks 465 * subscription- subscribe/unsubscribe button 466 * 467 * @author Andreas Gohr <andi@splitbrain.org> 468 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 469 */ 470function tpl_button($type,$return=false){ 471 global $ACT; 472 global $ID; 473 global $REV; 474 global $NS; 475 global $INFO; 476 global $conf; 477 global $auth; 478 479 // check disabled actions and fix the badly named ones 480 $ctype = $type; 481 if($type == 'history') $ctype='revisions'; 482 if(!actionOK($ctype)) return false; 483 484 $out = ''; 485 switch($type){ 486 case 'edit': 487 #most complicated type - we need to decide on current action 488 if($ACT == 'show' || $ACT == 'search'){ 489 if($INFO['writable']){ 490 if(!empty($INFO['draft'])){ 491 $out .= html_btn('draft',$ID,'e',array('do' => 'draft'),'post'); 492 }else{ 493 if($INFO['exists']){ 494 $out .= html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); 495 }else{ 496 $out .= html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); 497 } 498 } 499 }else{ 500 if(!actionOK('source')) return false; //pseudo action 501 $out .= html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post'); 502 } 503 }else{ 504 $out .= html_btn('show',$ID,'v',array('do' => 'show')); 505 } 506 break; 507 case 'history': 508 if(actionOK('revisions')) 509 $out .= html_btn('revs',$ID,'o',array('do' => 'revisions')); 510 break; 511 case 'recent': 512 if(actionOK('recent')) 513 $out .= html_btn('recent',$ID,'r',array('do' => 'recent')); 514 break; 515 case 'index': 516 if(actionOK('index')) 517 $out .= html_btn('index',$ID,'x',array('do' => 'index')); 518 break; 519 case 'back': 520 if ($parent = tpl_getparent($ID)) { 521 $out .= html_btn('back',$parent,'b',array('do' => 'show')); 522 } 523 break; 524 case 'top': 525 $out .= html_topbtn(); 526 break; 527 case 'login': 528 if($conf['useacl'] && $auth){ 529 if($_SERVER['REMOTE_USER']){ 530 $out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken())); 531 }else{ 532 $out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken())); 533 } 534 } 535 break; 536 case 'admin': 537 if($INFO['ismanager']){ 538 $out .= html_btn('admin',$ID,'',array('do' => 'admin')); 539 } 540 break; 541 case 'revert': 542 if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ 543 $out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())); 544 } 545 break; 546 case 'subscribe': 547 case 'subscription': 548 if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){ 549 if($_SERVER['REMOTE_USER']){ 550 if($INFO['subscribed']){ 551 if(actionOK('unsubscribe')) 552 $out .= html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',)); 553 } else { 554 if(actionOK('subscribe')) 555 $out .= html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); 556 } 557 } 558 } 559 if($type == 'subscribe') break; 560 // else: fall through for backward compatibility 561 case 'subscribens': 562 if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){ 563 if($_SERVER['REMOTE_USER']){ 564 if($INFO['subscribedns']){ 565 if(actionOK('unsubscribens')) 566 $out .= html_btn('unsubscribens',$ID,'',array('do' => 'unsubscribens',)); 567 } else { 568 if(actionOK('subscribens')) 569 $out .= html_btn('subscribens',$ID,'',array('do' => 'subscribens',)); 570 } 571 } 572 } 573 break; 574 case 'backlink': 575 if(actionOK('backlink')) 576 $out .= html_btn('backlink',$ID,'',array('do' => 'backlink')); 577 break; 578 case 'profile': 579 if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth && 580 $auth->canDo('Profile') && ($ACT!='profile')){ 581 $out .= html_btn('profile',$ID,'',array('do' => 'profile')); 582 } 583 break; 584 default: 585 $out .= '[unknown button type]'; 586 break; 587 } 588 if ($return) return $out; 589 print $out; 590 return $out ? true : false; 591} 592 593/** 594 * Like the action buttons but links 595 * 596 * Available links are 597 * 598 * edit - edit/create/show link 599 * history - old revisions 600 * recent - recent changes 601 * login - login/logout link - if ACL enabled 602 * profile - user profile link (if logged in) 603 * index - The index 604 * admin - admin page - if enough rights 605 * top - a back to top link 606 * back - a back to parent link - if available 607 * backlink - links to the list of backlinks 608 * subscribe/subscription - subscribe/unsubscribe link 609 * 610 * @author Andreas Gohr <andi@splitbrain.org> 611 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 612 * @see tpl_button 613 */ 614function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){ 615 global $ID; 616 global $INFO; 617 global $REV; 618 global $ACT; 619 global $conf; 620 global $lang; 621 global $auth; 622 623 // check disabled actions and fix the badly named ones 624 $ctype = $type; 625 if($type == 'history') $ctype='revisions'; 626 if(!actionOK($ctype)) return false; 627 628 $out = ''; 629 switch($type){ 630 case 'edit': 631 #most complicated type - we need to decide on current action 632 if($ACT == 'show' || $ACT == 'search'){ 633 if($INFO['writable']){ 634 if(!empty($INFO['draft'])) { 635 $out .= tpl_link(wl($ID,'do=draft'), 636 $pre.(($inner)?$inner:$lang['btn_draft']).$suf, 637 'class="action edit" accesskey="e" rel="nofollow"',1); 638 } else { 639 if($INFO['exists']){ 640 $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), 641 $pre.(($inner)?$inner:$lang['btn_edit']).$suf, 642 'class="action edit" accesskey="e" rel="nofollow"',1); 643 }else{ 644 $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), 645 $pre.(($inner)?$inner:$lang['btn_create']).$suf, 646 'class="action create" accesskey="e" rel="nofollow"',1); 647 } 648 } 649 }else{ 650 if(actionOK('source')) //pseudo action 651 $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), 652 $pre.(($inner)?$inner:$lang['btn_source']).$suf, 653 'class="action source" accesskey="v" rel="nofollow"',1); 654 } 655 }else{ 656 $out .= tpl_link(wl($ID,'do=show'), 657 $pre.(($inner)?$inner:$lang['btn_show']).$suf, 658 'class="action show" accesskey="v" rel="nofollow"',1); 659 } 660 break; 661 case 'history': 662 if(actionOK('revisions')) 663 $out .= tpl_link(wl($ID,'do=revisions'), 664 $pre.(($inner)?$inner:$lang['btn_revs']).$suf, 665 'class="action revisions" accesskey="o" rel="nofollow"',1); 666 break; 667 case 'recent': 668 if(actionOK('recent')) 669 $out .= tpl_link(wl($ID,'do=recent'), 670 $pre.(($inner)?$inner:$lang['btn_recent']).$suf, 671 'class="action recent" accesskey="r" rel="nofollow"',1); 672 break; 673 case 'index': 674 if(actionOK('index')) 675 $out .= tpl_link(wl($ID,'do=index'), 676 $pre.(($inner)?$inner:$lang['btn_index']).$suf, 677 'class="action index" accesskey="x" rel="nofollow"',1); 678 break; 679 case 'top': 680 $out .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'. 681 $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>'; 682 break; 683 case 'back': 684 if ($parent = tpl_getparent($ID)) { 685 $out .= tpl_link(wl($parent,'do=show'), 686 $pre.(($inner)?$inner:$lang['btn_back']).$suf, 687 'class="action back" accesskey="b" rel="nofollow"',1); 688 } 689 break; 690 case 'login': 691 if($conf['useacl'] && $auth){ 692 if($_SERVER['REMOTE_USER']){ 693 $out .= tpl_link(wl($ID,'do=logout&sectok='.getSecurityToken()), 694 $pre.(($inner)?$inner:$lang['btn_logout']).$suf, 695 'class="action logout" rel="nofollow"',1); 696 }else{ 697 $out .= tpl_link(wl($ID,'do=login&sectok='.getSecurityToken()), 698 $pre.(($inner)?$inner:$lang['btn_login']).$suf, 699 'class="action login" rel="nofollow"',1); 700 } 701 } 702 break; 703 case 'admin': 704 if($INFO['ismanager']){ 705 $out .= tpl_link(wl($ID,'do=admin'), 706 $pre.(($inner)?$inner:$lang['btn_admin']).$suf, 707 'class="action admin" rel="nofollow"',1); 708 } 709 break; 710 case 'revert': 711 if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ 712 $out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())), 713 $pre.(($inner)?$inner:$lang['btn_revert']).$suf, 714 'class="action revert" rel="nofollow"',1); 715 } 716 break; 717 case 'subscribe': 718 case 'subscription': 719 if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){ 720 if($_SERVER['REMOTE_USER']){ 721 if($INFO['subscribed']) { 722 if(actionOK('unsubscribe')) 723 $out .= tpl_link(wl($ID,'do=unsubscribe'), 724 $pre.(($inner)?$inner:$lang['btn_unsubscribe']).$suf, 725 'class="action unsubscribe" rel="nofollow"',1); 726 } else { 727 if(actionOK('subscribe')) 728 $out .= tpl_link(wl($ID,'do=subscribe'), 729 $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf, 730 'class="action subscribe" rel="nofollow"',1); 731 } 732 } 733 } 734 if($type == 'subscribe') break; 735 // else: fall through for backward compatibility 736 case 'subscribens': 737 if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){ 738 if($_SERVER['REMOTE_USER']){ 739 if($INFO['subscribedns']) { 740 if(actionOK('unsubscribens')) 741 $out .= tpl_link(wl($ID,'do=unsubscribens'), 742 $pre.(($inner)?$inner:$lang['btn_unsubscribens']).$suf, 743 'class="action unsubscribens" rel="nofollow"',1); 744 } else { 745 if(actionOK('subscribens')) 746 $out .= tpl_link(wl($ID,'do=subscribens'), 747 $pre.(($inner)?$inner:$lang['btn_subscribens']).$suf, 748 'class="action subscribens" rel="nofollow"',1); 749 } 750 } 751 } 752 break; 753 case 'backlink': 754 if(actionOK('backlink')) 755 $out .= tpl_link(wl($ID,'do=backlink'), 756 $pre.(($inner)?$inner:$lang['btn_backlink']).$suf, 757 'class="action backlink" rel="nofollow"',1); 758 break; 759 case 'profile': 760 if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] && 761 $auth->canDo('Profile') && ($ACT!='profile')){ 762 $out .= tpl_link(wl($ID,'do=profile'), 763 $pre.(($inner)?$inner:$lang['btn_profile']).$suf, 764 'class="action profile" rel="nofollow"',1); 765 } 766 break; 767 default: 768 $out .= '[unknown link type]'; 769 break; 770 } 771 if ($return) return $out; 772 print $out; 773 return $out ? true : false; 774} 775 776/** 777 * Wrapper around tpl_button() and tpl_actionlink() 778 * 779 * @author Anika Henke <anika@selfthinker.org> 780 */ 781function tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') { 782 $out = ''; 783 if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1); 784 else $out .= tpl_button($type,1); 785 if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 786 787 if ($return) return $out; 788 print $out; 789 return $out ? true : false; 790} 791 792/** 793 * Print the search form 794 * 795 * If the first parameter is given a div with the ID 'qsearch_out' will 796 * be added which instructs the ajax pagequicksearch to kick in and place 797 * its output into this div. The second parameter controls the propritary 798 * attribute autocomplete. If set to false this attribute will be set with an 799 * value of "off" to instruct the browser to disable it's own built in 800 * autocompletion feature (MSIE and Firefox) 801 * 802 * @author Andreas Gohr <andi@splitbrain.org> 803 */ 804function tpl_searchform($ajax=true,$autocomplete=true){ 805 global $lang; 806 global $ACT; 807 global $QUERY; 808 809 // don't print the search form if search action has been disabled 810 if (!actionOk('search')) return false; 811 812 print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">'; 813 print '<input type="hidden" name="do" value="search" />'; 814 print '<input type="text" '; 815 if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 816 if(!$autocomplete) print 'autocomplete="off" '; 817 print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 818 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; 819 if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 820 print '</div></form>'; 821 return true; 822} 823 824/** 825 * Print the breadcrumbs trace 826 * 827 * @author Andreas Gohr <andi@splitbrain.org> 828 */ 829function tpl_breadcrumbs($sep='»'){ 830 global $lang; 831 global $conf; 832 833 //check if enabled 834 if(!$conf['breadcrumbs']) return false; 835 836 $crumbs = breadcrumbs(); //setup crumb trace 837 838 //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups 839 if($lang['direction'] == 'rtl') { 840 $crumbs = array_reverse($crumbs,true); 841 $crumbs_sep = ' ‏<span class="bcsep">'.$sep.'</span>‏ '; 842 } else { 843 $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 844 } 845 846 //render crumbs, highlight the last one 847 print '<span class="bchead">'.$lang['breadcrumb'].':</span>'; 848 $last = count($crumbs); 849 $i = 0; 850 foreach ($crumbs as $id => $name){ 851 $i++; 852 echo $crumbs_sep; 853 if ($i == $last) print '<span class="curid">'; 854 tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"'); 855 if ($i == $last) print '</span>'; 856 } 857 return true; 858} 859 860/** 861 * Hierarchical breadcrumbs 862 * 863 * This code was suggested as replacement for the usual breadcrumbs. 864 * It only makes sense with a deep site structure. 865 * 866 * @author Andreas Gohr <andi@splitbrain.org> 867 * @author Nigel McNie <oracle.shinoda@gmail.com> 868 * @author Sean Coates <sean@caedmon.net> 869 * @author <fredrik@averpil.com> 870 * @todo May behave strangely in RTL languages 871 */ 872function tpl_youarehere($sep=' » '){ 873 global $conf; 874 global $ID; 875 global $lang; 876 877 // check if enabled 878 if(!$conf['youarehere']) return false; 879 880 $parts = explode(':', $ID); 881 $count = count($parts); 882 883 if($GLOBALS['ACT'] == 'search') 884 { 885 $parts = array($conf['start']); 886 $count = 1; 887 } 888 889 echo '<span class="bchead">'.$lang['youarehere'].': </span>'; 890 891 // always print the startpage 892 $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start']; 893 if(!$title) $title = $conf['start']; 894 tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"'); 895 896 // print intermediate namespace links 897 $part = ''; 898 for($i=0; $i<$count - 1; $i++){ 899 $part .= $parts[$i].':'; 900 $page = $part; 901 resolve_pageid('',$page,$exists); 902 if ($page == $conf['start']) continue; // Skip startpage 903 904 // output 905 echo $sep; 906 if($exists){ 907 $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; 908 tpl_link(wl($page),hsc($title),'title="'.$page.'"'); 909 }else{ 910 tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); 911 } 912 } 913 914 // print current page, skipping start page, skipping for namespace index 915 if(isset($page) && $page==$part.$parts[$i]) return; 916 $page = $part.$parts[$i]; 917 if($page == $conf['start']) return; 918 echo $sep; 919 if(page_exists($page)){ 920 $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; 921 tpl_link(wl($page),hsc($title),'title="'.$page.'"'); 922 }else{ 923 tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); 924 } 925 return true; 926} 927 928/** 929 * Print info if the user is logged in 930 * and show full name in that case 931 * 932 * Could be enhanced with a profile link in future? 933 * 934 * @author Andreas Gohr <andi@splitbrain.org> 935 */ 936function tpl_userinfo(){ 937 global $lang; 938 global $INFO; 939 if($_SERVER['REMOTE_USER']){ 940 print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')'; 941 return true; 942 } 943 return false; 944} 945 946/** 947 * Print some info about the current page 948 * 949 * @author Andreas Gohr <andi@splitbrain.org> 950 */ 951function tpl_pageinfo($ret=false){ 952 global $conf; 953 global $lang; 954 global $INFO; 955 global $ID; 956 957 // return if we are not allowed to view the page 958 if (!auth_quickaclcheck($ID)) { return false; } 959 960 // prepare date and path 961 $fn = $INFO['filepath']; 962 if(!$conf['fullpath']){ 963 if($INFO['rev']){ 964 $fn = str_replace(fullpath($conf['olddir']).'/','',$fn); 965 }else{ 966 $fn = str_replace(fullpath($conf['datadir']).'/','',$fn); 967 } 968 } 969 $fn = utf8_decodeFN($fn); 970 $date = dformat($INFO['lastmod']); 971 972 // print it 973 if($INFO['exists']){ 974 $out = ''; 975 $out .= $fn; 976 $out .= ' · '; 977 $out .= $lang['lastmod']; 978 $out .= ': '; 979 $out .= $date; 980 if($INFO['editor']){ 981 $out .= ' '.$lang['by'].' '; 982 $out .= editorinfo($INFO['editor']); 983 }else{ 984 $out .= ' ('.$lang['external_edit'].')'; 985 } 986 if($INFO['locked']){ 987 $out .= ' · '; 988 $out .= $lang['lockedby']; 989 $out .= ': '; 990 $out .= editorinfo($INFO['locked']); 991 } 992 if($ret){ 993 return $out; 994 }else{ 995 echo $out; 996 return true; 997 } 998 } 999 return false; 1000} 1001 1002/** 1003 * Prints or returns the name of the given page (current one if none given). 1004 * 1005 * If useheading is enabled this will use the first headline else 1006 * the given ID is used. 1007 * 1008 * @author Andreas Gohr <andi@splitbrain.org> 1009 */ 1010function tpl_pagetitle($id=null, $ret=false){ 1011 global $conf; 1012 if(is_null($id)){ 1013 global $ID; 1014 $id = $ID; 1015 } 1016 1017 $name = $id; 1018 if (useHeading('navigation')) { 1019 $title = p_get_first_heading($id); 1020 if ($title) $name = $title; 1021 } 1022 1023 if ($ret) { 1024 return hsc($name); 1025 } else { 1026 print hsc($name); 1027 return true; 1028 } 1029} 1030 1031/** 1032 * Returns the requested EXIF/IPTC tag from the current image 1033 * 1034 * If $tags is an array all given tags are tried until a 1035 * value is found. If no value is found $alt is returned. 1036 * 1037 * Which texts are known is defined in the functions _exifTagNames 1038 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 1039 * to the names of the latter one) 1040 * 1041 * Only allowed in: detail.php 1042 * 1043 * @author Andreas Gohr <andi@splitbrain.org> 1044 */ 1045function tpl_img_getTag($tags,$alt='',$src=null){ 1046 // Init Exif Reader 1047 global $SRC; 1048 1049 if(is_null($src)) $src = $SRC; 1050 1051 static $meta = null; 1052 if(is_null($meta)) $meta = new JpegMeta($src); 1053 if($meta === false) return $alt; 1054 $info = $meta->getField($tags); 1055 if($info == false) return $alt; 1056 return $info; 1057} 1058 1059/** 1060 * Prints the image with a link to the full sized version 1061 * 1062 * Only allowed in: detail.php 1063 */ 1064function tpl_img($maxwidth=0,$maxheight=0){ 1065 global $IMG; 1066 $w = tpl_img_getTag('File.Width'); 1067 $h = tpl_img_getTag('File.Height'); 1068 1069 //resize to given max values 1070 $ratio = 1; 1071 if($w >= $h){ 1072 if($maxwidth && $w >= $maxwidth){ 1073 $ratio = $maxwidth/$w; 1074 }elseif($maxheight && $h > $maxheight){ 1075 $ratio = $maxheight/$h; 1076 } 1077 }else{ 1078 if($maxheight && $h >= $maxheight){ 1079 $ratio = $maxheight/$h; 1080 }elseif($maxwidth && $w > $maxwidth){ 1081 $ratio = $maxwidth/$w; 1082 } 1083 } 1084 if($ratio){ 1085 $w = floor($ratio*$w); 1086 $h = floor($ratio*$h); 1087 } 1088 1089 //prepare URLs 1090 $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); 1091 $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); 1092 1093 //prepare attributes 1094 $alt=tpl_img_getTag('Simple.Title'); 1095 $p = array(); 1096 if($w) $p['width'] = $w; 1097 if($h) $p['height'] = $h; 1098 $p['class'] = 'img_detail'; 1099 if($alt){ 1100 $p['alt'] = $alt; 1101 $p['title'] = $alt; 1102 }else{ 1103 $p['alt'] = ''; 1104 } 1105 $p = buildAttributes($p); 1106 1107 print '<a href="'.$url.'">'; 1108 print '<img src="'.$src.'" '.$p.'/>'; 1109 print '</a>'; 1110 return true; 1111} 1112 1113/** 1114 * This function inserts a 1x1 pixel gif which in reality 1115 * is the inexer function. 1116 * 1117 * Should be called somewhere at the very end of the main.php 1118 * template 1119 */ 1120function tpl_indexerWebBug(){ 1121 global $ID; 1122 global $INFO; 1123 if(!$INFO['exists']) return false; 1124 1125 if(isHiddenPage($ID)) return false; //no need to index hidden pages 1126 1127 $p = array(); 1128 $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1129 '&'.time(); 1130 $p['width'] = 1; 1131 $p['height'] = 1; 1132 $p['alt'] = ''; 1133 $att = buildAttributes($p); 1134 print "<img $att />"; 1135 return true; 1136} 1137 1138// configuration methods 1139/** 1140 * tpl_getConf($id) 1141 * 1142 * use this function to access template configuration variables 1143 */ 1144function tpl_getConf($id){ 1145 global $conf; 1146 global $tpl_configloaded; 1147 1148 $tpl = $conf['template']; 1149 1150 if (!$tpl_configloaded){ 1151 $tconf = tpl_loadConfig(); 1152 if ($tconf !== false){ 1153 foreach ($tconf as $key => $value){ 1154 if (isset($conf['tpl'][$tpl][$key])) continue; 1155 $conf['tpl'][$tpl][$key] = $value; 1156 } 1157 $tpl_configloaded = true; 1158 } 1159 } 1160 1161 return $conf['tpl'][$tpl][$id]; 1162} 1163 1164/** 1165 * tpl_loadConfig() 1166 * reads all template configuration variables 1167 * this function is automatically called by tpl_getConf() 1168 */ 1169function tpl_loadConfig(){ 1170 1171 $file = DOKU_TPLINC.'/conf/default.php'; 1172 $conf = array(); 1173 1174 if (!@file_exists($file)) return false; 1175 1176 // load default config file 1177 include($file); 1178 1179 return $conf; 1180} 1181 1182/** 1183 * prints the "main content" in the mediamanger popup 1184 * 1185 * Depending on the user's actions this may be a list of 1186 * files in a namespace, the meta editing dialog or 1187 * a message of referencing pages 1188 * 1189 * Only allowed in mediamanager.php 1190 * 1191 * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1192 * @param bool $fromajax - set true when calling this function via ajax 1193 * @author Andreas Gohr <andi@splitbrain.org> 1194 */ 1195function tpl_mediaContent($fromajax=false){ 1196 global $IMG; 1197 global $AUTH; 1198 global $INUSE; 1199 global $NS; 1200 global $JUMPTO; 1201 1202 if(is_array($_REQUEST['do'])){ 1203 $do = array_shift(array_keys($_REQUEST['do'])); 1204 }else{ 1205 $do = $_REQUEST['do']; 1206 } 1207 if(in_array($do,array('save','cancel'))) $do = ''; 1208 1209 if(!$do){ 1210 if($_REQUEST['edit']){ 1211 $do = 'metaform'; 1212 }elseif(is_array($INUSE)){ 1213 $do = 'filesinuse'; 1214 }else{ 1215 $do = 'filelist'; 1216 } 1217 } 1218 1219 // output the content pane, wrapped in an event. 1220 if(!$fromajax) ptln('<div id="media__content">'); 1221 $data = array( 'do' => $do); 1222 $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1223 if ($evt->advise_before()) { 1224 $do = $data['do']; 1225 if($do == 'metaform'){ 1226 media_metaform($IMG,$AUTH); 1227 }elseif($do == 'filesinuse'){ 1228 media_filesinuse($INUSE,$IMG); 1229 }elseif($do == 'filelist'){ 1230 media_filelist($NS,$AUTH,$JUMPTO); 1231 }elseif($do == 'searchlist'){ 1232 media_searchlist($_REQUEST['q'],$NS,$AUTH); 1233 }else{ 1234 msg('Unknown action '.hsc($do),-1); 1235 } 1236 } 1237 $evt->advise_after(); 1238 unset($evt); 1239 if(!$fromajax) ptln('</div>'); 1240 1241} 1242 1243/** 1244 * prints the namespace tree in the mediamanger popup 1245 * 1246 * Only allowed in mediamanager.php 1247 * 1248 * @author Andreas Gohr <andi@splitbrain.org> 1249 */ 1250function tpl_mediaTree(){ 1251 global $NS; 1252 1253 ptln('<div id="media__tree">'); 1254 media_nstree($NS); 1255 ptln('</div>'); 1256} 1257 1258 1259/** 1260 * Print a dropdown menu with all DokuWiki actions 1261 * 1262 * Note: this will not use any pretty URLs 1263 * 1264 * @author Andreas Gohr <andi@splitbrain.org> 1265 */ 1266function tpl_actiondropdown($empty='',$button='>'){ 1267 global $ID; 1268 global $INFO; 1269 global $REV; 1270 global $ACT; 1271 global $conf; 1272 global $lang; 1273 global $auth; 1274 1275 1276 echo '<form method="post" accept-charset="utf-8">'; #FIXME action 1277 echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1278 if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 1279 echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 1280 1281 echo '<select name="do" id="action__selector" class="edit">'; 1282 echo '<option value="">'.$empty.'</option>'; 1283 1284 echo '<optgroup label=" — ">'; 1285 // 'edit' - most complicated type, we need to decide on current action 1286 if($ACT == 'show' || $ACT == 'search'){ 1287 if($INFO['writable']){ 1288 if(!empty($INFO['draft'])) { 1289 echo '<option value="edit">'.$lang['btn_draft'].'</option>'; 1290 } else { 1291 if($INFO['exists']){ 1292 echo '<option value="edit">'.$lang['btn_edit'].'</option>'; 1293 }else{ 1294 echo '<option value="edit">'.$lang['btn_create'].'</option>'; 1295 } 1296 } 1297 }else if(actionOK('source')) { //pseudo action 1298 echo '<option value="edit">'.$lang['btn_source'].'</option>'; 1299 } 1300 }else{ 1301 echo '<option value="show">'.$lang['btn_show'].'</option>'; 1302 } 1303 1304 echo '<option value="revisions">'.$lang['btn_revs'].'</option>'; 1305 if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ 1306 echo '<option value="revert">'.$lang['btn_revert'].'</option>'; 1307 } 1308 echo '<option value="backlink">'.$lang['btn_backlink'].'</option>'; 1309 echo '</optgroup>'; 1310 1311 echo '<optgroup label=" — ">'; 1312 echo '<option value="recent">'.$lang['btn_recent'].'</option>'; 1313 echo '<option value="index">'.$lang['btn_index'].'</option>'; 1314 echo '</optgroup>'; 1315 1316 echo '<optgroup label=" — ">'; 1317 if($conf['useacl'] && $auth){ 1318 if($_SERVER['REMOTE_USER']){ 1319 echo '<option value="logout">'.$lang['btn_logout'].'</option>'; 1320 }else{ 1321 echo '<option value="login">'.$lang['btn_login'].'</option>'; 1322 } 1323 } 1324 1325 if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] && 1326 $auth->canDo('Profile') && ($ACT!='profile')){ 1327 echo '<option value="profile">'.$lang['btn_profile'].'</option>'; 1328 } 1329 1330 if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){ 1331 if($_SERVER['REMOTE_USER']){ 1332 if($INFO['subscribed']) { 1333 echo '<option value="unsubscribe">'.$lang['btn_unsubscribe'].'</option>'; 1334 } else { 1335 echo '<option value="subscribe">'.$lang['btn_subscribe'].'</option>'; 1336 } 1337 } 1338 } 1339 1340 if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){ 1341 if($_SERVER['REMOTE_USER']){ 1342 if($INFO['subscribedns']) { 1343 echo '<option value="unsubscribens">'.$lang['btn_unsubscribens'].'</option>'; 1344 } else { 1345 echo '<option value="subscribens">'.$lang['btn_subscribens'].'</option>'; 1346 } 1347 } 1348 } 1349 1350 if($INFO['ismanager']){ 1351 echo '<option value="admin">'.$lang['btn_admin'].'</option>'; 1352 } 1353 echo '</optgroup>'; 1354 1355 echo '</select>'; 1356 echo '<input type="submit" value="'.$button.'" id="action__selectorbtn" />'; 1357 echo '</form>'; 1358} 1359 1360/** 1361 * Print a informational line about the used license 1362 * 1363 * @author Andreas Gohr <andi@splitbrain.org> 1364 * @param string $img - print image? (|button|badge) 1365 * @param bool $return - when true don't print, but return HTML 1366 */ 1367function tpl_license($img='badge',$imgonly=false,$return=false){ 1368 global $license; 1369 global $conf; 1370 global $lang; 1371 if(!$conf['license']) return ''; 1372 if(!is_array($license[$conf['license']])) return ''; 1373 $lic = $license[$conf['license']]; 1374 1375 $out = '<div class="license">'; 1376 if($img){ 1377 $src = license_img($img); 1378 if($src){ 1379 $out .= '<a href="'.$lic['url'].'" rel="license"'; 1380 if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"'; 1381 $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> '; 1382 } 1383 } 1384 if(!$imgonly) { 1385 $out .= $lang['license']; 1386 $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"'; 1387 if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"'; 1388 $out .= '>'.$lic['name'].'</a>'; 1389 } 1390 $out .= '</div>'; 1391 1392 if($return) return $out; 1393 echo $out; 1394} 1395 1396 1397/** 1398 * Includes the rendered XHTML of a given page 1399 * 1400 * This function is useful to populate sidebars or similar features in a 1401 * template 1402 */ 1403function tpl_include_page($pageid,$print=true){ 1404 global $ID; 1405 $oldid = $ID; 1406 $html = p_wiki_xhtml($pageid,'',false); 1407 $ID = $oldid; 1408 1409 if(!$print) return $html; 1410 echo $html; 1411} 1412 1413//Setup VIM: ex: et ts=4 enc=utf-8 : 1414 1415