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