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