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 global $conf; 139 $it=2; 140 141 // the usual stuff 142 ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 143 ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 144 ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 145 ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 146 ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 147 ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it); 148 ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it); 149 ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/styles/style.css" />',$it); 150 151 // setup robot tags apropriate for different modes 152 if( ($ACT=='show' || $ACT=='export_html') && !$REV){ 153 if($INFO['exists']){ 154 ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 155 //delay indexing: 156 if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 157 ptln('<meta name="robots" content="index,follow" />',$it); 158 }else{ 159 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 160 } 161 }else{ 162 ptln('<meta name="robots" content="noindex,follow" />',$it); 163 } 164 }else{ 165 ptln('<meta name="robots" content="noindex,nofollow" />',$it); 166 } 167 168 // include some JavaScript language strings 169 ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it); 170 ptln(" var alertText = '".$lang['qb_alert']."'",$it); 171 ptln(" var notSavedYet = '".$lang['notsavedyet']."'",$it); 172 ptln(" var DOKU_BASE = '".DOKU_BASE."'",$it); 173 ptln('</script>',$it); 174 175 // load the default JavaScript files 176 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 177 DOKU_BASE.'lib/scripts/script.js"></script>',$it); 178 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 179 DOKU_BASE.'lib/scripts/tw-sack.js"></script>',$it); 180 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 181 DOKU_BASE.'lib/scripts/ajax.js"></script>',$it); 182 183 // load spellchecker script if wanted 184 if($conf['spellchecker'] && ($ACT=='edit' || $ACT=='preview')){ 185 ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'. 186 DOKU_BASE.'lib/scripts/spellcheck.js"></script>',$it); 187 } 188 189 //FIXME include some default CSS ? IE FIX? 190} 191 192/** 193 * Print a link 194 * 195 * Just builds a link but adds additional JavaScript needed for 196 * the unsaved data check needed in the edit form. 197 * 198 * @author Andreas Gohr <andi@splitbrain.org> 199 */ 200function tpl_link($url,$name,$more=''){ 201 print '<a href="'.$url.'" onclick="return svchk()" onkeypress="return svchk()"'; 202 if ($more) print ' '.$more; 203 print ">$name</a>"; 204} 205 206/** 207 * get the parent page 208 * 209 * Tries to find out which page is parent. 210 * returns false if none is available 211 * 212 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 213 */ 214function tpl_getparent($ID){ 215 global $conf; 216 217 if ($ID != $conf['start']) { 218 $idparts = explode(':', $ID); 219 $pn = array_pop($idparts); // get the page name 220 221 for ($n=0; $n < 2; $n++) { 222 if (count($idparts) == 0) { 223 $ID = $conf['start']; // go to topmost page 224 break; 225 }else{ 226 $ns = array_pop($idparts); // get the last part of namespace 227 if ($pn != $ns) { // are we already home? 228 array_push($idparts, $ns, $ns); // no, then add a page with same name 229 $ID = implode (':', $idparts); // as the namespace and recombine $ID 230 break; 231 } 232 } 233 } 234 235 if (@file_exists(wikiFN($ID))) { 236 return $ID; 237 } 238 } 239 return false; 240} 241 242/** 243 * Print one of the buttons 244 * 245 * Available Buttons are 246 * 247 * edit - edit/create/show button 248 * history - old revisions 249 * recent - recent changes 250 * login - login/logout button - if ACL enabled 251 * index - The index 252 * admin - admin page - if enough rights 253 * top - a back to top button 254 * back - a back to parent button - if available 255 * 256 * @author Andreas Gohr <andi@splitbrain.org> 257 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 258 */ 259function tpl_button($type){ 260 global $ID; 261 global $INFO; 262 global $conf; 263 264 switch($type){ 265 case 'edit': 266 print html_editbutton(); 267 break; 268 case 'history': 269 print html_btn(revs,$ID,'o',array('do' => 'revisions')); 270 break; 271 case 'recent': 272 print html_btn(recent,'','r',array('do' => 'recent')); 273 break; 274 case 'index': 275 print html_btn(index,$ID,'x',array('do' => 'index')); 276 break; 277 case 'back': 278 if ($ID = tpl_getparent($ID)) { 279 print html_btn(back,$ID,'b',array('do' => 'show')); 280 } 281 break; 282 case 'top': 283 print html_topbtn(); 284 break; 285 case 'login': 286 if($conf['useacl']){ 287 if($_SERVER['REMOTE_USER']){ 288 print html_btn('logout',$ID,'',array('do' => 'logout',)); 289 }else{ 290 print html_btn('login',$ID,'',array('do' => 'login')); 291 } 292 } 293 break; 294 case 'admin': 295 if($INFO['perm'] == AUTH_ADMIN) 296 print html_btn(admin,$ID,'',array('do' => 'admin')); 297 break; 298 default: 299 print '[unknown button type]'; 300 } 301} 302 303/** 304 * Like the action buttons but links 305 * 306 * Available links are 307 * 308 * edit - edit/create/show button 309 * history - old revisions 310 * recent - recent changes 311 * login - login/logout button - if ACL enabled 312 * index - The index 313 * admin - admin page - if enough rights 314 * top - a back to top button 315 * back - a back to parent button - if available 316 * 317 * @author Andreas Gohr <andi@splitbrain.org> 318 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 319 * @see tpl_button 320 */ 321function tpl_actionlink($type,$pre='',$suf=''){ 322 global $ID; 323 global $INFO; 324 global $REV; 325 global $ACT; 326 global $conf; 327 global $lang; 328 329 switch($type){ 330 case 'edit': 331 #most complicated type - we need to decide on current action 332 if($ACT == 'show' || $ACT == 'search'){ 333 if($INFO['writable']){ 334 if($INFO['exists']){ 335 tpl_link(wl($ID,'do=edit&rev='.$REV), 336 $pre.$lang['btn_edit'].$suf, 337 'class="action" accesskey="e" rel="nofollow"'); 338 }else{ 339 tpl_link(wl($ID,'do=edit&rev='.$REV), 340 $pre.$lang['btn_create'].$suf, 341 'class="action" accesskey="e" rel="nofollow"'); 342 } 343 }else{ 344 tpl_link(wl($ID,'do=edit&rev='.$REV), 345 $pre.$lang['btn_source'].$suf, 346 'class="action" accesskey="v" rel="nofollow"'); 347 } 348 }else{ 349 tpl_link(wl($ID,'do=show'), 350 $pre.$lang['btn_show'].$suf, 351 'class="action" accesskey="v" rel="nofollow"'); 352 } 353 break; 354 case 'history': 355 tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action" accesskey="o"'); 356 break; 357 case 'recent': 358 tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action" accesskey="r"'); 359 break; 360 case 'index': 361 tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action" accesskey="x"'); 362 break; 363 case 'top': 364 print '<a href="#top" class="action" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 365 break; 366 case 'back': 367 if ($ID = tpl_getparent($ID)) { 368 tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action" accesskey="b"'); 369 } 370 break; 371 case 'login': 372 if($conf['useacl']){ 373 if($_SERVER['REMOTE_USER']){ 374 tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action"'); 375 }else{ 376 tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action"'); 377 } 378 } 379 break; 380 case 'admin': 381 if($INFO['perm'] == AUTH_ADMIN) 382 tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action"'); 383 break; 384 default: 385 print '[unknown link type]'; 386 } 387} 388 389/** 390 * Print the search form 391 * 392 * @author Andreas Gohr <andi@splitbrain.org> 393 */ 394function tpl_searchform(){ 395 global $lang; 396 global $ACT; 397 398 print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search" onsubmit="return svchk()">'; 399 print '<input type="hidden" name="do" value="search" />'; 400 print '<input type="text" '; 401 402 if ($ACT == 'search') 403 print 'value="'.$_REQUEST['id'].'" '; /* keep search input as long as user stays on search page */ 404 405 print 'id="qsearch_in" accesskey="f" name="id" class="edit" onkeyup="ajax_qsearch.call(\'qsearch_in\',\'qsearch_out\')" />'; 406 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 407 print '<div id="qsearch_out" class="ajax_qsearch" onclick="this.style.display=\'none\'"></div>'; 408 print '</form>'; 409} 410 411/** 412 * Print the breadcrumbs trace 413 * 414 * @author Andreas Gohr <andi@splitbrain.org> 415 */ 416function tpl_breadcrumbs(){ 417 global $lang; 418 global $conf; 419 420 //check if enabled 421 if(!$conf['breadcrumbs']) return; 422 423 $crumbs = breadcrumbs(); //setup crumb trace 424 425 //reverse crumborder in right-to-left mode 426 if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 427 428 //render crumbs, highlight the last one 429 print $lang['breadcrumb'].':'; 430 $last = count($crumbs); 431 $i = 0; 432 foreach ($crumbs as $id => $name){ 433 $i++; 434 print ' <span class="bcsep">»</span> '; 435 if ($i == $last) print '<span class="curid">'; 436 tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 437 if ($i == $last) print '</span>'; 438 } 439} 440 441/** 442 * Hierarchical breadcrumbs 443 * 444 * This code was suggested as replacement for the usual breadcrumbs 445 * trail in the Wiki and was modified by me. 446 * It only makes sense with a deep site structure. 447 * 448 * @author Andreas Gohr <andi@splitbrain.org> 449 * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 450 * @todo May behave starngely in RTL languages 451 */ 452function tpl_youarehere(){ 453 global $conf; 454 global $ID; 455 global $lang; 456 457 458 $parts = explode(':', $ID); 459 460 print $lang['breadcrumb'].': '; 461 462 //always print the startpage 463 if( $a_part[0] != $conf['start'] ) 464 tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"'); 465 466 $page = ''; 467 foreach ($parts as $part){ 468 print ' » '; 469 $page .= $part; 470 471 if(file_exists(wikiFN($page))){ 472 tpl_link(wl($page),$part,'title="'.$page.'"'); 473 }else{ 474 print $page; 475 } 476 477 $page .= ':'; 478 } 479} 480 481/** 482 * Print info if the user is logged in 483 * and show full name in that case 484 * 485 * Could be enhanced with a profile link in future? 486 * 487 * @author Andreas Gohr <andi@splitbrain.org> 488 */ 489function tpl_userinfo(){ 490 global $lang; 491 global $INFO; 492 if($_SERVER['REMOTE_USER']) 493 print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 494} 495 496/** 497 * Print some info about the current page 498 * 499 * @author Andreas Gohr <andi@splitbrain.org> 500 */ 501function tpl_pageinfo(){ 502 global $conf; 503 global $lang; 504 global $INFO; 505 global $REV; 506 507 // prepare date and path 508 $fn = $INFO['filepath']; 509 if(!$conf['fullpath']){ 510 if($REV){ 511 $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 512 }else{ 513 $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 514 } 515 } 516 $fn = utf8_decodeFN($fn); 517 $date = date($conf['dformat'],$INFO['lastmod']); 518 519 // print it 520 if($INFO['exists']){ 521 print $fn; 522 print ' · '; 523 print $lang['lastmod']; 524 print ': '; 525 print $date; 526 if($INFO['editor']){ 527 print ' '.$lang['by'].' '; 528 print $INFO['editor']; 529 } 530 if($INFO['locked']){ 531 print ' · '; 532 print $lang['lockedby']; 533 print ': '; 534 print $INFO['locked']; 535 } 536 } 537} 538 539/** 540 * Print a list of namespaces containing media files 541 * 542 * @author Andreas Gohr <andi@splitbrain.org> 543 */ 544function tpl_medianamespaces(){ 545 global $conf; 546 547 $data = array(); 548 search($data,$conf['mediadir'],'search_namespaces',array()); 549 print html_buildlist($data,'idx',media_html_list_namespaces); 550} 551 552/** 553 * Print a list of mediafiles in the current namespace 554 * 555 * @author Andreas Gohr <andi@splitbrain.org> 556 */ 557function tpl_mediafilelist(){ 558 global $conf; 559 global $lang; 560 global $NS; 561 global $AUTH; 562 $dir = utf8_encodeFN(str_replace(':','/',$NS)); 563 564 $data = array(); 565 search($data,$conf['mediadir'],'search_media',array(),$dir); 566 567 if(!count($data)){ 568 ptln('<div class="nothing">'.$lang['nothingfound'].'<div>'); 569 return; 570 } 571 572 ptln('<ul>',2); 573 foreach($data as $item){ 574 ptln('<li>',4); 575 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'. 576 utf8_decodeFN($item['file']). 577 '</a>',6); 578 579 //prepare deletion button 580 if($AUTH >= AUTH_DELETE){ 581 $ask = $lang['del_confirm'].'\\n'; 582 $ask .= $item['id']; 583 584 $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.urlencode($item['id']).'" '. 585 'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'. 586 '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '. 587 'align="bottom" title="'.$lang['btn_delete'].'" /></a>'; 588 }else{ 589 $del = ''; 590 } 591 592 593 if($item['isimg']){ 594 $w = $item['info'][0]; 595 $h = $item['info'][1]; 596 597 ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')',6); 598 ptln($del.'<br />',6); 599 ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">'); 600 601 if($w>120){ 602 print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?w=120&media='.urlencode($item['id']).'" width="120" />'; 603 }else{ 604 print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?media='.urlencode($item['id']).'" width="'.$w.'" height="'.$h.'" />'; 605 } 606 print '</a>'; 607 608 }else{ 609 ptln ('('.filesize_h($item['size']).')',6); 610 ptln($del,6); 611 } 612 ptln('</li>',4); 613 } 614 ptln('</ul>',2); 615} 616 617/** 618 * Print the media upload form if permissions are correct 619 * 620 * @author Andreas Gohr <andi@splitbrain.org> 621 */ 622function tpl_mediauploadform(){ 623 global $NS; 624 global $UPLOADOK; 625 global $AUTH; 626 global $lang; 627 628 if(!$UPLOADOK) return; 629 630 ptln('<form action="'.$_SERVER['PHP_SELF'].'" name="upload"'. 631 ' method="post" enctype="multipart/form-data">',2); 632 ptln($lang['txt_upload'].':<br />',4); 633 ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 634 ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 635 ptln($lang['txt_filename'].'<br />',4); 636 ptln('<input type="text" name="id" class="edit" />',4); 637 ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 638 if($AUTH >= AUTH_DELETE){ 639 ptln('<label for="ow" class="simple"><input type="checkbox" name="ow" value="1" id="ow">'.$lang['txt_overwrt'].'</label>',4); 640 } 641 ptln('</form>',2); 642} 643 644 645//Setup VIM: ex: et ts=2 enc=utf-8 : 646