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_INC.'conf/dokuwiki.php'); 11 12/** 13 * Wrapper around htmlspecialchars() 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 * @see htmlspecialchars() 17 */ 18function hsc($string){ 19 return htmlspecialchars($string); 20} 21 22/** 23 * print a newline terminated string 24 * 25 * You can give an indention as optional parameter 26 * 27 * @author Andreas Gohr <andi@splitbrain.org> 28 */ 29function ptln($string,$intend=0){ 30 for($i=0; $i<$intend; $i++) print ' '; 31 print"$string\n"; 32} 33 34/** 35 * Print the content 36 * 37 * This function is used for printing all the usual content 38 * (defined by the global $ACT var) by calling the appropriate 39 * outputfunction(s) from html.php 40 * 41 * Everything that doesn't use the default template isn't 42 * handled by this function. ACL stuff is not done either. 43 * 44 * @author Andreas Gohr <andi@splitbrain.org> 45 */ 46function tpl_content(){ 47 global $ACT; 48 global $TEXT; 49 global $PRE; 50 global $SUF; 51 global $SUM; 52 global $IDX; 53 54 switch($ACT){ 55 case 'show': 56 html_show(); 57 break; 58 case 'preview': 59 html_edit($TEXT); 60 html_show($TEXT); 61 break; 62 case 'edit': 63 html_edit(); 64 break; 65 case 'wordblock': 66 html_edit($TEXT,'wordblock'); 67 break; 68 case 'search': 69 html_search(); 70 break; 71 case 'revisions': 72 html_revisions(); 73 break; 74 case 'diff': 75 html_diff(); 76 break; 77 case 'recent': 78 $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; 79 html_recent($first); 80 break; 81 case 'index': 82 html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 83 break; 84 case 'backlink': 85 html_backlinks(); 86 break; 87 case 'conflict': 88 html_conflict(con($PRE,$TEXT,$SUF),$SUM); 89 html_diff(con($PRE,$TEXT,$SUF),false); 90 break; 91 case 'locked': 92 html_locked(); 93 break; 94 case 'login': 95 html_login(); 96 break; 97 case 'register': 98 html_register(); 99 break; 100 case 'denied': 101 print p_locale_xhtml('denied'); 102 break; 103 case 'admin': 104 tpl_admin(); 105 break; 106 default: 107 msg("Failed to handle command: ".hsc($ACT),-1); 108 } 109} 110 111/** 112 * Handle the admin page contents 113 * 114 * @author Andreas Gohr <andi@splitbrain.org> 115 */ 116function tpl_admin(){ 117 switch($_REQUEST['page']){ 118 case 'acl': 119 admin_acl_html(); 120 break; 121 default: 122 html_admin(); 123 } 124} 125 126/** 127 * Print the correct HTML meta headers 128 * 129 * This has to go into the head section of your template. 130 * 131 * @author Andreas Gohr <andi@splitbrain.org> 132 */ 133function tpl_metaheaders(){ 134 global $ID; 135 global $INFO; 136 global $ACT; 137 global $lang; 138 $it=2; 139 140 // the usual stuff 141 ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 142 ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 143 ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 144 ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 145 ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 146 ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it); 147 ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it); 148 ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'style.css" />',$it); 149 150 // setup robot tags apropriate for different modes 151 if( ($ACT=='show' || $ACT=='export_html') && !$REV){ 152 if($INFO['exists']){ 153 ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 154 //delay indexing: 155 if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 156 ptln('<meta name="robots" content="index,follow" />',$it); 157 }else{ 158 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 159 } 160 }else{ 161 ptln('<meta name="robots" content="noindex,follow" />',$it); 162 } 163 }else{ 164 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 165 } 166 167 // include some JavaScript language strings 168 ptln('<script language="JavaScript" type="text/javascript">',$it); 169 ptln(" var alertText = '".$lang['qb_alert']."'",$it); 170 ptln(" var notSavedYet = '".$lang['notsavedyet']."'",$it); 171 ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it); 172 ptln('</script>',$it); 173 174 // load the default JavaScript files 175 ptln('<script language="JavaScript" type="text/javascript" src="'.DOKU_BASE.'script.js"></script>',$it); 176 ptln('<script language="JavaScript" type="text/javascript" src="'.DOKU_BASE.'tw-sack.js"></script>',$it); 177 ptln('<script language="JavaScript" type="text/javascript" src="'.DOKU_BASE.'ajax.js"></script>',$it); 178 179 //FIXME include some default CSS ? IE FIX? 180} 181 182/** 183 * Print a link 184 * 185 * Just builds a link but adds additional JavaScript needed for 186 * the unsaved data check needed in the edit form. 187 * 188 * @author Andreas Gohr <andi@splitbrain.org> 189 */ 190function tpl_link($url,$name,$more=''){ 191 print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; 192 if ($more) print ' '.$more; 193 print ">$name</a>"; 194} 195 196/** 197 * get the parent page 198 * 199 * Tries to find out which page is parent. 200 * returns false if none is available 201 * 202 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 203 */ 204function tpl_getparent($ID){ 205 global $conf; 206 207 if ($ID != $conf['start']) { 208 $idparts = explode(':', $ID); 209 $pn = array_pop($idparts); // get the page name 210 211 for ($n=0; $n < 2; $n++) { 212 if (count($idparts) == 0) { 213 $ID = $conf['start']; // go to topmost page 214 break; 215 }else{ 216 $ns = array_pop($idparts); // get the last part of namespace 217 if ($pn != $ns) { // are we already home? 218 array_push($idparts, $ns, $ns); // no, then add a page with same name 219 $ID = implode (':', $idparts); // as the namespace and recombine $ID 220 break; 221 } 222 } 223 } 224 225 if (@file_exists(wikiFN($ID))) { 226 return $ID; 227 } 228 } 229 return false; 230} 231 232/** 233 * Print one of the buttons 234 * 235 * Available Buttons are 236 * 237 * edit - edit/create/show button 238 * history - old revisions 239 * recent - recent changes 240 * login - login/logout button - if ACL enabled 241 * index - The index 242 * admin - admin page - if enough rights 243 * top - a back to top button 244 * back - a back to parent button - if available 245 * 246 * @author Andreas Gohr <andi@splitbrain.org> 247 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 248 */ 249function tpl_button($type){ 250 global $ID; 251 global $INFO; 252 global $conf; 253 254 switch($type){ 255 case 'edit': 256 print html_editbutton(); 257 break; 258 case 'history': 259 print html_btn(revs,$ID,'o',array('do' => 'revisions')); 260 break; 261 case 'recent': 262 print html_btn(recent,'','r',array('do' => 'recent')); 263 break; 264 case 'index': 265 print html_btn(index,$ID,'x',array('do' => 'index')); 266 break; 267 case 'back': 268 if ($ID = tpl_getparent($ID)) { 269 print html_btn(back,$ID,'b',array('do' => 'show')); 270 } 271 break; 272 case 'top': 273 print html_topbtn(); 274 break; 275 case 'login': 276 if($conf['useacl']){ 277 if($_SERVER['REMOTE_USER']){ 278 print html_btn('logout',$ID,'',array('do' => 'logout',)); 279 }else{ 280 print html_btn('login',$ID,'',array('do' => 'login')); 281 } 282 } 283 break; 284 case 'admin': 285 if($INFO['perm'] == AUTH_ADMIN) 286 print html_btn(admin,$ID,'',array('do' => 'admin')); 287 break; 288 default: 289 print '[unknown button type]'; 290 } 291} 292 293/** 294 * Like the action buttons but links 295 * 296 * Available links are 297 * 298 * edit - edit/create/show button 299 * history - old revisions 300 * recent - recent changes 301 * login - login/logout button - if ACL enabled 302 * index - The index 303 * admin - admin page - if enough rights 304 * top - a back to top button 305 * back - a back to parent button - if available 306 * 307 * @author Andreas Gohr <andi@splitbrain.org> 308 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 309 * @see tpl_button 310 */ 311function tpl_actionlink($type,$pre='',$suf=''){ 312 global $ID; 313 global $INFO; 314 global $REV; 315 global $ACT; 316 global $conf; 317 global $lang; 318 319 switch($type){ 320 case 'edit': 321 #most complicated type - we need to decide on current action 322 if($ACT == 'show' || $ACT == 'search'){ 323 if($INFO['writable']){ 324 if($INFO['exists']){ 325 tpl_link(wl($ID,'do=edit&rev='.$REV), 326 $pre.$lang['btn_edit'].$suf, 327 'class="action" accesskey="e" rel="nofollow"'); 328 }else{ 329 tpl_link(wl($ID,'do=edit&rev='.$REV), 330 $pre.$lang['btn_create'].$suf, 331 'class="action" accesskey="e" rel="nofollow"'); 332 } 333 }else{ 334 tpl_link(wl($ID,'do=edit&rev='.$REV), 335 $pre.$lang['btn_source'].$suf, 336 'class="action" accesskey="v" rel="nofollow"'); 337 } 338 }else{ 339 tpl_link(wl($ID,'do=show'), 340 $pre.$lang['btn_show'].$suf, 341 'class="action" accesskey="v" rel="nofollow"'); 342 } 343 break; 344 case 'history': 345 tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action" accesskey="o"'); 346 break; 347 case 'recent': 348 tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action" accesskey="r"'); 349 break; 350 case 'index': 351 tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action" accesskey="x"'); 352 break; 353 case 'top': 354 print '<a href="#top" class="action" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 355 break; 356 case 'back': 357 if ($ID = tpl_getparent($ID)) { 358 tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action" accesskey="b"'); 359 } 360 break; 361 case 'login': 362 if($conf['useacl']){ 363 if($_SERVER['REMOTE_USER']){ 364 tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action"'); 365 }else{ 366 tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action"'); 367 } 368 } 369 break; 370 case 'admin': 371 if($INFO['perm'] == AUTH_ADMIN) 372 tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action"'); 373 break; 374 default: 375 print '[unknown link type]'; 376 } 377} 378 379/** 380 * Print the search form 381 * 382 * @author Andreas Gohr <andi@splitbrain.org> 383 */ 384function tpl_searchform(){ 385 global $lang; 386 print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search" onsubmit="return svchk()">'; 387 print '<input type="hidden" name="do" value="search" />'; 388 print '<input type="text" id="qsearch_in" accesskey="f" name="id" class="edit" onkeyup="ajax_qsearch.call(\'qsearch_in\',\'qsearch_out\')" />'; 389 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 390 print '<div id="qsearch_out" class="ajax_qsearch" onclick="this.style.display=\'none\'"></div>'; 391 print '</form>'; 392} 393 394/** 395 * Print the breadcrumbs trace 396 * 397 * @author Andreas Gohr <andi@splitbrain.org> 398 */ 399function tpl_breadcrumbs(){ 400 global $lang; 401 global $conf; 402 403 //check if enabled 404 if(!$conf['breadcrumbs']) return; 405 406 $crumbs = breadcrumbs(); //setup crumb trace 407 408 //reverse crumborder in right-to-left mode 409 if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 410 411 //render crumbs, highlight the last one 412 print $lang['breadcrumb'].':'; 413 $last = count($crumbs); 414 $i = 0; 415 foreach ($crumbs as $id => $name){ 416 $i++; 417 print ' <span class="bcsep">»</span> '; 418 if ($i == $last) print '<span class="curid">'; 419 tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 420 if ($i == $last) print '</span>'; 421 } 422} 423 424/** 425 * Hierarchical breadcrumbs 426 * 427 * This code was suggested as replacement for the usual breadcrumbs 428 * trail in the Wiki and was modified by me. 429 * It only makes sense with a deep site structure. 430 * 431 * @author Andreas Gohr <andi@splitbrain.org> 432 * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 433 * @todo May behave starngely in RTL languages 434 */ 435function tpl_youarehere(){ 436 global $conf; 437 global $ID; 438 global $lang; 439 440 441 $parts = explode(':', $ID); 442 443 print $lang['breadcrumb'].': '; 444 445 //always print the startpage 446 if( $a_part[0] != $conf['start'] ) 447 tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"'); 448 449 $page = ''; 450 foreach ($parts as $part){ 451 print ' » '; 452 $page .= $part; 453 454 if(file_exists(wikiFN($page))){ 455 tpl_link(wl($page),$part,'title="'.$page.'"'); 456 }else{ 457 print $page; 458 } 459 460 $page .= ':'; 461 } 462} 463 464/** 465 * Print info if the user is logged in 466 * and show full name in that case 467 * 468 * Could be enhanced with a profile link in future? 469 * 470 * @author Andreas Gohr <andi@splitbrain.org> 471 */ 472function tpl_userinfo(){ 473 global $lang; 474 global $INFO; 475 if($_SERVER['REMOTE_USER']) 476 print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 477} 478 479/** 480 * Print some info about the current page 481 * 482 * @author Andreas Gohr <andi@splitbrain.org> 483 */ 484function tpl_pageinfo(){ 485 global $conf; 486 global $lang; 487 global $INFO; 488 global $REV; 489 490 // prepare date and path 491 $fn = $INFO['filepath']; 492 if(!$conf['fullpath']){ 493 if($REV){ 494 $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 495 }else{ 496 $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 497 } 498 } 499 $fn = utf8_decodeFN($fn); 500 $date = date($conf['dformat'],$INFO['lastmod']); 501 502 // print it 503 if($INFO['exists']){ 504 print $fn; 505 print ' · '; 506 print $lang['lastmod']; 507 print ': '; 508 print $date; 509 if($INFO['editor']){ 510 print ' '.$lang['by'].' '; 511 print $INFO['editor']; 512 } 513 if($INFO['locked']){ 514 print ' · '; 515 print $lang['lockedby']; 516 print ': '; 517 print $INFO['locked']; 518 } 519 } 520} 521 522/** 523 * Print a list of namespaces containing media files 524 * 525 * @author Andreas Gohr <andi@splitbrain.org> 526 */ 527function tpl_medianamespaces(){ 528 global $conf; 529 530 $data = array(); 531 search($data,$conf['mediadir'],'search_namespaces',array()); 532 print html_buildlist($data,'idx',media_html_list_namespaces); 533} 534 535/** 536 * Print a list of mediafiles in the current namespace 537 * 538 * @author Andreas Gohr <andi@splitbrain.org> 539 */ 540function tpl_mediafilelist(){ 541 global $conf; 542 global $lang; 543 global $NS; 544 $dir = utf8_encodeFN(str_replace(':','/',$NS)); 545 546 $data = array(); 547 search($data,$conf['mediadir'],'search_media',array(),$dir); 548 549 if(!count($data)){ 550 ptln('<div class="nothing">'.$lang['nothingfound'].'<div>'); 551 return; 552 } 553 554 ptln('<ul>',2); 555 foreach($data as $item){ 556 ptln('<li>',4); 557 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'. 558 utf8_decodeFN($item['file']). 559 '</a>',6); 560 if($item['isimg']){ 561 $w = $item['info'][0]; 562 $h = $item['info'][1]; 563 564 ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')<br />',6); 565 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'); 566 567 if($w>120){ 568 print '<img src="'.DOKU_BASE.'fetch.php?w=120&media='.urlencode($item['id']).'" width="120" />'; 569 }else{ 570 print '<img src="'.DOKU_BASE.'fetch.php?media='.urlencode($item['id']).'" width="'.$w.'" height="'.$h.'" />'; 571 } 572 print '</a>'; 573 574 }else{ 575 ptln ('('.filesize_h($item['size']).')',6); 576 } 577 ptln('</li>',4); 578 } 579 ptln('</ul>',2); 580} 581 582/** 583 * Print the media upload form if permissions are correct 584 * 585 * @author Andreas Gohr <andi@splitbrain.org> 586 */ 587function tpl_mediauploadform(){ 588 global $NS; 589 global $UPLOADOK; 590 global $lang; 591 592 if(!$UPLOADOK) return; 593 594 ptln('<form action="'.$_SERVER['PHP_SELF'].'" name="upload"'. 595 ' method="post" enctype="multipart/form-data">',2); 596 ptln($lang['txt_upload'].':<br />',4); 597 ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 598 ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 599 ptln($lang['txt_filename'].'<br />',4); 600 ptln('<input type="text" name="id" class="edit" />',4); 601 ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 602 ptln('</form>',2); 603} 604 605 606//Setup VIM: ex: et ts=2 enc=utf-8 : 607