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