1<?php 2/** 3 * HTML output 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 11 require_once(DOKU_INC.'inc/parserutils.php'); 12 13/** 14 * Convenience function to quickly build a wikilink 15 * 16 * @author Andreas Gohr <andi@splitbrain.org> 17 */ 18function html_wikilink($id,$name=NULL,$search=''){ 19 require_once(DOKU_INC.'inc/parser/xhtml.php'); 20 static $xhtml_renderer = NULL; 21 if(is_null($xhtml_renderer)){ 22 $xhtml_renderer = new Doku_Renderer_xhtml(); 23 } 24 25 return $xhtml_renderer->internallink($id,$name,$search,true); 26} 27 28/** 29 * Helps building long attribute lists 30 * 31 * @author Andreas Gohr <andi@splitbrain.org> 32 */ 33function html_attbuild($attributes){ 34 $ret = ''; 35 foreach ( $attributes as $key => $value ) { 36 $ret .= $key.'="'.formtext($value).'" '; 37 } 38 return trim($ret); 39} 40 41/** 42 * The loginform 43 * 44 * @author Andreas Gohr <andi@splitbrain.org> 45 */ 46function html_login(){ 47 global $lang; 48 global $conf; 49 global $ID; 50 51 print p_locale_xhtml('login'); 52 ?> 53 <div align="center"> 54 <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" method="post"> 55 <fieldset> 56 <legend><?php echo $lang['btn_login']?></legend> 57 <input type="hidden" name="id" value="<?php echo $ID?>" /> 58 <input type="hidden" name="do" value="login" /> 59 <label> 60 <span><?php echo $lang['user']?></span> 61 <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>" class="edit" /> 62 </label><br /> 63 <label> 64 <span><?php echo $lang['pass']?></span> 65 <input type="password" name="p" class="edit" /> 66 </label><br /> 67 <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" /> 68 <label for="remember" class="simple"> 69 <input type="checkbox" name="r" id="remember" value="1" /> 70 <span><?php echo $lang['remember']?></span> 71 </label> 72 </fieldset> 73 </form> 74 <?php 75 if($conf['openregister']){ 76 print '<p>'; 77 print $lang['reghere']; 78 print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>'; 79 print '</p>'; 80 } 81 ?> 82 </div> 83 <?php 84/* 85 FIXME provide new hook 86 if(@file_exists('includes/login.txt')){ 87 print io_cacheParse('includes/login.txt'); 88 } 89*/ 90} 91 92/** 93 * shows the edit/source/show button dependent on current mode 94 * 95 * @author Andreas Gohr <andi@splitbrain.org> 96 */ 97function html_editbutton(){ 98 global $ID; 99 global $REV; 100 global $ACT; 101 global $INFO; 102 103 if($ACT == 'show' || $ACT == 'search'){ 104 if($INFO['writable']){ 105 if($INFO['exists']){ 106 $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); 107 }else{ 108 $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); 109 } 110 }else{ 111 $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post'); 112 } 113 }else{ 114 $r = html_btn('show',$ID,'v',array('do' => 'show')); 115 } 116 return $r; 117} 118 119/** 120 * prints a section editing button 121 * 122 * @author Andreas Gohr <andi@splitbrain.org> 123 */ 124function html_secedit_button($section,$p){ 125 global $ID; 126 global $lang; 127 $secedit = ''; 128# if($p) $secedit .= "</p>\n"; 129 $secedit .= '<div class="secedit">'; 130 $secedit .= html_btn('secedit',$ID,'', 131 array('do' => 'edit', 132 'lines' => "$section"), 133 'post'); 134 $secedit .= '</div>'; 135# if($p) $secedit .= "\n<p>"; 136 return $secedit; 137} 138 139/** 140 * inserts section edit buttons if wanted or removes the markers 141 * 142 * @author Andreas Gohr <andi@splitbrain.org> 143 */ 144function html_secedit($text,$show=true){ 145 global $INFO; 146 if($INFO['writable'] && $show && !$INFO['rev']){ 147 $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e', 148 "html_secedit_button('\\1',true)", 149 $text); 150 $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e', 151 "html_secedit_button('\\1',false)", 152 $text); 153 }else{ 154 $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text); 155 } 156 return $text; 157} 158 159/** 160 * Just the back to top button (in its own form) 161 * 162 * @author Andreas Gohr <andi@splitbrain.org> 163 */ 164function html_topbtn(){ 165 global $lang; 166 167 $ret = ''; 168 $ret = '<a href="#top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" /></a>'; 169 170 return $ret; 171} 172 173/** 174 * Just the back to media window button in its own form 175 * 176 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 177 */ 178function html_backtomedia_button($params,$akey=''){ 179 global $conf; 180 global $lang; 181 182 $ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/media.php">'; 183 184 reset($params); 185 while (list($key, $val) = each($params)) { 186 $ret .= '<input type="hidden" name="'.$key.'" '; 187 $ret .= 'value="'.htmlspecialchars($val).'" />'; 188 } 189 190 $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" '; 191 if($akey){ 192 $ret .= 'title="ALT+'.strtoupper($akey).'" '; 193 $ret .= 'accesskey="'.$akey.'" '; 194 } 195 $ret .= '/>'; 196 $ret .= '</form>'; 197 198 return $ret; 199} 200 201/** 202 * Displays a button (using its own form) 203 * 204 * @author Andreas Gohr <andi@splitbrain.org> 205 */ 206function html_btn($name,$id,$akey,$params,$method='get'){ 207 global $conf; 208 global $lang; 209 210 $label = $lang['btn_'.$name]; 211 212 $ret = ''; 213 214 //filter id (without urlencoding) 215 $id = idfilter($id,false); 216 217 //make nice URLs even for buttons 218 if($conf['userewrite'] == 2){ 219 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 220 }elseif($conf['userewrite']){ 221 $script = DOKU_BASE.$id; 222 }else{ 223 $script = DOKU_BASE.DOKU_SCRIPT; 224 $params['id'] = $id; 225 } 226 227 $ret .= '<form class="button" method="'.$method.'" action="'.$script.'" onsubmit="return svchk()">'; 228 229 reset($params); 230 while (list($key, $val) = each($params)) { 231 $ret .= '<input type="hidden" name="'.$key.'" '; 232 $ret .= 'value="'.htmlspecialchars($val).'" />'; 233 } 234 235 $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" '; 236 if($akey){ 237 $ret .= 'title="ALT+'.strtoupper($akey).'" '; 238 $ret .= 'accesskey="'.$akey.'" '; 239 } 240 $ret .= '/>'; 241 $ret .= '</form>'; 242 243 return $ret; 244} 245 246/** 247 * show a wiki page 248 * 249 * @author Andreas Gohr <andi@splitbrain.org> 250 */ 251function html_show($txt=''){ 252 global $ID; 253 global $REV; 254 global $HIGH; 255 //disable section editing for old revisions or in preview 256 if($txt || $REV){ 257 $secedit = false; 258 }else{ 259 $secedit = true; 260 } 261 262 if ($txt){ 263 //PreviewHeader 264 print p_locale_xhtml('preview'); 265 print '<div class="preview">'; 266 print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 267 print '</div>'; 268 269 }else{ 270 if ($REV) print p_locale_xhtml('showrev'); 271 $html = p_wiki_xhtml($ID,$REV,true); 272 $html = html_secedit($html,$secedit); 273 print html_hilight($html,$HIGH); 274 } 275} 276 277/** 278 * Highlights searchqueries in HTML code 279 * 280 * @author Andreas Gohr <andi@splitbrain.org> 281 */ 282function html_hilight($html,$query){ 283 $queries = preg_split ("/\s/",$query,-1,PREG_SPLIT_NO_EMPTY); 284 foreach ($queries as $q){ 285 $q = preg_quote($q,'/'); 286 $html = preg_replace("/((<[^>]*)|$q)/ie", '"\2"=="\1"? unslash("\1"):"<span class=\"search_hit\">".unslash("\1")."</span>"', $html); 287 } 288 return $html; 289} 290 291/** 292 * Run a search and display the result 293 * 294 * @author Andreas Gohr <andi@splitbrain.org> 295 */ 296function html_search(){ 297 require_once(DOKU_INC.'inc/search.php'); 298 require_once(DOKU_INC.'inc/fulltext.php'); 299 global $conf; 300 global $QUERY; 301 global $ID; 302 global $lang; 303 304 print p_locale_xhtml('searchpage'); 305 flush(); 306 307 //show progressbar 308 print '<div align="center">'; 309 print '<script language="javascript" type="text/javascript" charset="utf-8">'; 310 print 'showLoadBar();'; 311 print '</script>'; 312 print '<br /></div>'; 313 314 //do quick pagesearch 315 $data = array(); 316 $data = ft_pageLookup(cleanID($QUERY)); 317 if(count($data)){ 318 sort($data); 319 print '<div class="search_quickresult">'; 320 print '<b>'.$lang[quickhits].':</b><br />'; 321 foreach($data as $id){ 322 print '<div class="search_quickhits">'; 323 print html_wikilink(':'.$id,$conf['useheading']?NULL:$id); 324 print '</div> '; 325 } 326 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 327 print '<div class="clearer"> </div>'; 328 print '</div>'; 329 } 330 flush(); 331 332 //do fulltext search 333 $data = ft_pageSearch($QUERY,$poswords); 334 if(count($data)){ 335 $num = 1; 336 foreach($data as $id => $cnt){ 337 print '<div class="search_result">'; 338 print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords); 339 print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />'; 340 if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ? 341 print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>'; 342 } 343 print '</div>'; 344 flush(); 345 $num++; 346 } 347 }else{ 348 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 349 } 350 351 //hide progressbar 352 print '<script language="javascript" type="text/javascript" charset="utf-8">'; 353 print 'hideLoadBar();'; 354 print '</script>'; 355} 356 357/** 358 * Display error on locked pages 359 * 360 * @author Andreas Gohr <andi@splitbrain.org> 361 */ 362function html_locked(){ 363 global $ID; 364 global $conf; 365 global $lang; 366 global $INFO; 367 368 $locktime = filemtime(wikiFN($ID).'.lock'); 369 $expire = @date($conf['dformat'], $locktime + $conf['locktime'] ); 370 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 371 372 print p_locale_xhtml('locked'); 373 print '<ul>'; 374 print '<li><b>'.$lang['lockedby'].':</b> '.$INFO['locked'].'</li>'; 375 print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>'; 376 print '</ul>'; 377} 378 379/** 380 * list old revisions 381 * 382 * @author Andreas Gohr <andi@splitbrain.org> 383 */ 384function html_revisions(){ 385 global $ID; 386 global $INFO; 387 global $conf; 388 global $lang; 389 $revisions = getRevisions($ID); 390 $date = @date($conf['dformat'],$INFO['lastmod']); 391 392 print p_locale_xhtml('revisions'); 393 print '<ul>'; 394 if($INFO['exists']){ 395 print '<li>'; 396 397 print $date; 398 399 print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" border="0" width="15" height="11" alt="" /> '; 400 401 print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> '; 402 403 print $INFO['sum']; 404 print ' <span class="user">'; 405 print $INFO['editor']; 406 print '</span> '; 407 408 print '('.$lang['current'].')'; 409 print '</li>'; 410 } 411 412 foreach($revisions as $rev){ 413 $date = date($conf['dformat'],$rev); 414 $info = getRevisionInfo($ID,$rev); 415 416 print '<li>'; 417 418 print $date; 419 420 print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">'; 421 $p = array(); 422 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 423 $p['border'] = 0; 424 $p['width'] = 15; 425 $p['height'] = 11; 426 $p['title'] = $lang['diff']; 427 $p['alt'] = $lang['diff']; 428 $att = buildAttributes($p); 429 print "<img $att />"; 430 print '</a> '; 431 432 print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> '; 433 434 print htmlspecialchars($info['sum']); 435 print ' <span class="user">'; 436 if($info['user']){ 437 print $info['user']; 438 }else{ 439 print $info['ip']; 440 } 441 print '</span>'; 442 443 print '</li>'; 444 } 445 print '</ul>'; 446} 447 448/** 449 * display recent changes 450 * 451 * @author Andreas Gohr <andi@splitbrain.org> 452 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 453 */ 454function html_recent($first=0){ 455 global $conf; 456 global $lang; 457 global $ID; 458 /* we need to get one additionally log entry to be able to 459 * decide if this is the last page or is there another one. 460 * This is the cheapest solution to get this information. 461 */ 462 $recents = getRecents($first,$conf['recent'] + 1,true,getNS($ID)); 463 if(count($recents) == 0 && $first != 0){ 464 $first=0; 465 $recents = getRecents(0,$conf['recent'] + 1,true,getNS($ID)); 466 } 467 $cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent']; 468 469 print p_locale_xhtml('recent'); 470 print '<ul>'; 471 472 $keys = array_keys($recents); 473 for ($n=0; $n < $cnt; $n++){ 474 $id = $keys[$n]; 475 $date = date($conf['dformat'],$recents[$id]['date']); 476 print '<li>'; 477 478 print $date.' '; 479 480 print '<a href="'.wl($id,"do=diff").'">'; 481 $p = array(); 482 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 483 $p['border'] = 0; 484 $p['width'] = 15; 485 $p['height'] = 11; 486 $p['title'] = $lang['diff']; 487 $p['alt'] = $lang['diff']; 488 $att = buildAttributes($p); 489 print "<img $att />"; 490 print '</a> '; 491 492 print '<a href="'.wl($id,"do=revisions").'">'; 493 $p = array(); 494 $p['src'] = DOKU_BASE.'lib/images/history.png'; 495 $p['border'] = 0; 496 $p['width'] = 12; 497 $p['height'] = 14; 498 $p['title'] = $lang['btn_revs']; 499 $p['alt'] = $lang['btn_revs']; 500 $att = buildAttributes($p); 501 print "<img $att />"; 502 print '</a> '; 503 504 print html_wikilink(":$id",$conf['useheading']?NULL:$id); 505 506 print ' '.htmlspecialchars($recents[$id]['sum']); 507 print ' <span class="user">'; 508 if($recents[$id]['user']){ 509 print $recents[$id]['user']; 510 }else{ 511 print $recents[$id]['ip']; 512 } 513 print '</span>'; 514 515 print '</li>'; 516 } 517 print '</ul>'; 518 519 print '<div class="pagenav">'; 520 $last = $first + $conf['recent']; 521 if ($first > 0) { 522 $first -= $conf['recent']; 523 if ($first < 0) $first = 0; 524 print '<div class="pagenav-prev">'; 525 print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first)); 526 print '</div>'; 527 } 528 if ($conf['recent'] < count($recents)) { 529 print '<div class="pagenav-next">'; 530 print html_btn('older','',"n",array('do' => 'recent', 'first' => $last)); 531 print '</div>'; 532 } 533 print '</div>'; 534} 535 536/** 537 * Display page index 538 * 539 * @author Andreas Gohr <andi@splitbrain.org> 540 */ 541function html_index($ns){ 542 require_once(DOKU_INC.'inc/search.php'); 543 global $conf; 544 global $ID; 545 $dir = $conf['datadir']; 546 $ns = cleanID($ns); 547 #fixme use appropriate function 548 if(empty($ns)){ 549 $ns = dirname(str_replace(':','/',$ID)); 550 if($ns == '.') $ns =''; 551 } 552 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 553 554 print p_locale_xhtml('index'); 555 556 $data = array(); 557 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 558 print html_buildlist($data,'idx','html_list_index','html_li_index'); 559} 560 561/** 562 * Index item formatter 563 * 564 * User function for html_buildlist() 565 * 566 * @author Andreas Gohr <andi@splitbrain.org> 567 */ 568function html_list_index($item){ 569 $ret = ''; 570 $base = ':'.$item['id']; 571 $base = substr($base,strrpos($base,':')+1); 572 if($item['type']=='d'){ 573 $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">'; 574 $ret .= $base; 575 $ret .= '</a>'; 576 }else{ 577 $ret .= html_wikilink(':'.$item['id']); 578 } 579 return $ret; 580} 581 582/** 583 * Index List item 584 * 585 * This user function is used in html_build_lidt to build the 586 * <li> tags for namespaces when displaying the page index 587 * it gives different classes to opened or closed "folders" 588 * 589 * @author Andreas Gohr <andi@splitbrain.org> 590 */ 591function html_li_index($item){ 592 if($item['type'] == "f"){ 593 return '<li class="level'.$item['level'].'">'; 594 }elseif($item['open']){ 595 return '<li class="open">'; 596 }else{ 597 return '<li class="closed">'; 598 } 599} 600 601/** 602 * Default List item 603 * 604 * @author Andreas Gohr <andi@splitbrain.org> 605 */ 606function html_li_default($item){ 607 return '<li class="level'.$item['level'].'">'; 608} 609 610/** 611 * Build an unordered list 612 * 613 * Build an unordered list from the given $data array 614 * Each item in the array has to have a 'level' property 615 * the item itself gets printed by the given $func user 616 * function. The second and optional function is used to 617 * print the <li> tag. Both user function need to accept 618 * a single item. 619 * 620 * @author Andreas Gohr <andi@splitbrain.org> 621 */ 622function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 623 $level = 0; 624 $opens = 0; 625 $ret = ''; 626 627 foreach ($data as $item){ 628 629 if( $item['level'] > $level ){ 630 //open new list 631 for($i=0; $i<($item['level'] - $level); $i++){ 632 if ($i) $ret .= "<li class=\"clear\">\n"; 633 $ret .= "\n<ul class=\"$class\">\n"; 634 } 635 }elseif( $item['level'] < $level ){ 636 //close last item 637 $ret .= "</li>\n"; 638 for ($i=0; $i<($level - $item['level']); $i++){ 639 //close higher lists 640 $ret .= "</ul>\n</li>\n"; 641 } 642 }else{ 643 //close last item 644 $ret .= "</li>\n"; 645 } 646 647 //remember current level 648 $level = $item['level']; 649 650 //print item 651 $ret .= $lifunc($item); //user function 652 $ret .= '<span class="li">'; 653 $ret .= $func($item); //user function 654 $ret .= '</span>'; 655 } 656 657 //close remaining items and lists 658 for ($i=0; $i < $level; $i++){ 659 $ret .= "</li></ul>\n"; 660 } 661 662 return $ret; 663} 664 665/** 666 * display backlinks 667 * 668 * @author Andreas Gohr <andi@splitbrain.org> 669 */ 670function html_backlinks(){ 671 require_once(DOKU_INC.'inc/fulltext.php'); 672 global $ID; 673 global $conf; 674 675 print p_locale_xhtml('backlinks'); 676 677 $data = ft_backlinks($ID); 678 679 print '<ul class="idx">'; 680 foreach($data as $blink){ 681 print '<li>'; 682 print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink); 683 print '</li>'; 684 } 685 print '</ul>'; 686} 687 688/** 689 * show diff 690 * 691 * @author Andreas Gohr <andi@splitbrain.org> 692 */ 693function html_diff($text='',$intro=true){ 694 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 695 global $ID; 696 global $REV; 697 global $lang; 698 global $conf; 699 if($text){ 700 $df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))), 701 split("\n",htmlspecialchars(cleanText($text)))); 702 $left = '<a class="wikilink1" href="'.wl($ID).'">'. 703 $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'. 704 $lang['current']; 705 $right = $lang['yours']; 706 }else{ 707 if($REV){ 708 $r = $REV; 709 }else{ 710 //use last revision if none given 711 $revs = getRevisions($ID); 712 $r = $revs[0]; 713 } 714 715 $df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))), 716 split("\n",htmlspecialchars(rawWiki($ID,'')))); 717 $left = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'. 718 $ID.' '.date($conf['dformat'],$r).'</a>'; 719 $right = '<a class="wikilink1" href="'.wl($ID).'">'. 720 $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '. 721 $lang['current']; 722 } 723 $tdf = new TableDiffFormatter(); 724 if($intro) print p_locale_xhtml('diff'); 725 ?> 726 <table class="diff" width="100%"> 727 <tr> 728 <td colspan="2" width="50%" class="diff-header"> 729 <?php echo $left?> 730 </td> 731 <td colspan="2" width="50%" class="diff-header"> 732 <?php echo $right?> 733 </td> 734 </tr> 735 <?php echo $tdf->format($df)?> 736 </table> 737 <?php 738} 739 740/** 741 * show warning on conflict detection 742 * 743 * @author Andreas Gohr <andi@splitbrain.org> 744 */ 745function html_conflict($text,$summary){ 746 global $ID; 747 global $lang; 748 749 print p_locale_xhtml('conflict'); 750 ?> 751 <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"> 752 <input type="hidden" name="id" value="<?php echo $ID?>" /> 753 <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" /> 754 <input type="hidden" name="summary" value="<?php echo formText($summary)?>" /> 755 756 <div align="center"> 757 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" /> 758 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" /> 759 </div> 760 </form> 761 <br /><br /><br /><br /> 762 <?php 763} 764 765/** 766 * Prints the global message array 767 * 768 * @author Andreas Gohr <andi@splitbrain.org> 769 */ 770function html_msgarea(){ 771 global $MSG; 772 773 if(!isset($MSG)) return; 774 775 foreach($MSG as $msg){ 776 print '<div class="'.$msg['lvl'].'">'; 777 print $msg['msg']; 778 print '</div>'; 779 } 780} 781 782/** 783 * Prints the registration form 784 * 785 * @author Andreas Gohr <andi@splitbrain.org> 786 */ 787function html_register(){ 788 global $lang; 789 global $conf; 790 global $ID; 791 792 print p_locale_xhtml('register'); 793?> 794 <div align="center"> 795 <form name="register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>"> 796 <input type="hidden" name="do" value="register" /> 797 <input type="hidden" name="save" value="1" /> 798 <fieldset> 799 <legend><?php echo $lang['register']?></legend> 800 <label> 801 <?php echo $lang['user']?> 802 <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" /> 803 </label><br /> 804 805 <?php 806 if (!$conf['autopasswd']) { 807 ?> 808 <label> 809 <?php echo $lang['pass']?> 810 <input type="password" name="pass" class="edit" size="50" /> 811 </label><br /> 812 <label> 813 <?php echo $lang['passchk']?> 814 <input type="password" name="passchk" class="edit" size="50" /> 815 </label><br /> 816 <?php 817 } 818 ?> 819 820 <label> 821 <?php echo $lang['fullname']?> 822 <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" /> 823 </label><br /> 824 <label> 825 <?php echo $lang['email']?> 826 <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" /> 827 </label><br /> 828 <input type="submit" class="button" value="<?php echo $lang['register']?>" /> 829 </fieldset> 830 </form> 831 </div> 832<?php 833} 834 835/** 836 * This displays the edit form (lots of logic included) 837 * 838 * @fixme this is a huge lump of code and should be modularized 839 * @author Andreas Gohr <andi@splitbrain.org> 840 */ 841function html_edit($text=null,$include='edit'){ //FIXME: include needed? 842 global $ID; 843 global $REV; 844 global $DATE; 845 global $RANGE; 846 global $PRE; 847 global $SUF; 848 global $INFO; 849 global $SUM; 850 global $lang; 851 global $conf; 852 853 //set summary default 854 if(!$SUM){ 855 if($REV){ 856 $SUM = $lang['restored']; 857 }elseif(!$INFO['exists']){ 858 $SUM = $lang['created']; 859 } 860 } 861 862 //no text? Load it! 863 if(!isset($text)){ 864 $pr = false; //no preview mode 865 if($INFO['exists']){ 866 if($RANGE){ 867 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); 868 }else{ 869 $text = rawWiki($ID,$REV); 870 } 871 }else{ 872 //try to load a pagetemplate 873 $text = pageTemplate($ID); 874 } 875 }else{ 876 $pr = true; //preview mode 877 } 878 879 $wr = $INFO['writable']; 880 if($wr){ 881 if ($REV) print p_locale_xhtml('editrev'); 882 print p_locale_xhtml($include); 883 }else{ 884 print p_locale_xhtml('read'); 885 $ro='readonly="readonly"'; 886 } 887 if(!$DATE) $DATE = $INFO['lastmod']; 888 889 890?> 891 <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" onsubmit="return svchk()"> 892 <input type="hidden" name="id" value="<?php echo $ID?>" /> 893 <input type="hidden" name="rev" value="<?php echo $REV?>" /> 894 <input type="hidden" name="date" value="<?php echo $DATE?>" /> 895 <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" /> 896 <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" /> 897 <table style="width:99%"> 898 <tr> 899 <td class="toolbar" colspan="2"> 900 <?php if($wr){?> 901 <script language="javascript" type="text/javascript" charset="utf-8"> 902 <?php /* sets changed to true when previewed */?> 903 textChanged = <?php ($pr) ? print 'true' : print 'false' ?>; 904 905 formatButton('bold.png','<?php echo $lang['qb_bold']?>','**','**','<?php echo $lang['qb_bold']?>','b'); 906 formatButton('italic.png','<?php echo $lang['qb_italic']?>',"\/\/","\/\/",'<?php echo $lang['qb_italic']?>','i'); 907 formatButton('underline.png','<?php echo $lang['qb_underl']?>','__','__','<?php echo $lang['qb_underl']?>','u'); 908 formatButton('code.png','<?php echo $lang['qb_code']?>','\'\'','\'\'','<?php echo $lang['qb_code']?>','c'); 909 formatButton('strike.png','<?php echo $lang['qb_strike']?>','<del>','<\/del>','<?php echo $lang['qb_strike']?>','d'); 910 911 formatButton('fonth1.png','<?php echo $lang['qb_h1']?>','====== ',' ======\n','<?php echo $lang['qb_h1']?>','1'); 912 formatButton('fonth2.png','<?php echo $lang['qb_h2']?>','===== ',' =====\n','<?php echo $lang['qb_h2']?>','2'); 913 formatButton('fonth3.png','<?php echo $lang['qb_h3']?>','==== ',' ====\n','<?php echo $lang['qb_h3']?>','3'); 914 formatButton('fonth4.png','<?php echo $lang['qb_h4']?>','=== ',' ===\n','<?php echo $lang['qb_h4']?>','4'); 915 formatButton('fonth5.png','<?php echo $lang['qb_h5']?>','== ',' ==\n','<?php echo $lang['qb_h5']?>','5'); 916 917 formatButton('link.png','<?php echo $lang['qb_link']?>','[[',']]','<?php echo $lang['qb_link']?>','l'); 918 formatButton('extlink.png','<?php echo $lang['qb_extlink']?>','[[',']]','http://www.example.com|<?php echo $lang['qb_extlink']?>'); 919 920 formatButton('list.png','<?php echo $lang['qb_ol']?>',' - ','\n','<?php echo $lang['qb_ol']?>'); 921 formatButton('list_ul.png','<?php echo $lang['qb_ul']?>',' * ','\n','<?php echo $lang['qb_ul']?>'); 922 923 insertButton('rule.png','<?php echo $lang['qb_hr']?>','----\n'); 924 mediaButton('image.png','<?php echo $lang['qb_media']?>','m','<?php echo $INFO['namespace']?>'); 925 926 <?php 927 if($conf['useacl'] && $_SERVER['REMOTE_USER']){ 928 echo "insertButton('sig.png','".$lang['qb_sig']."','".html_signature()."','y');"; 929 } 930 ?> 931 </script> 932 <span id="spell_action"></span> 933 <?php } ?> 934 </td> 935 <td> 936 <div id="spell_suggest"></div> 937 </td> 938 </tr> 939 <tr> 940 <td colspan="3"> 941 <div id="spell_result"></div> 942 <textarea name="wikitext" id="wikitext" <?php echo $ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" onkeyup="summaryCheck();" tabindex="1"><?php echo "\n".formText($text)?></textarea> 943 </td> 944 </tr> 945 <tr id="wikieditbar"> 946 <td> 947 <?php if($wr){?> 948 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" /> 949 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" /> 950 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="5" /> 951 <?php } ?> 952 </td> 953 <td> 954 <?php if($wr){ ?> 955 <?php echo $lang['summary']?>: 956 <input type="text" class="edit" name="summary" id="summary" size="50" onkeyup="summaryCheck();" value="<?php echo formText($SUM)?>" tabindex="2" /> 957 <?php }?> 958 </td> 959 <td align="right"> 960 <script language="javascript" type="text/javascript" charset="utf-8"> 961 showSizeCtl(); 962 <?php if($wr){ ?> 963 init_locktimer(<?php echo $conf['locktime']-60?>,'<?php echo $lang['willexpire']?>'); 964 965 //initialize spellchecker 966 <?php if($conf['spellchecker']){ ?> 967 ajax_spell.init('<?php echo $lang['spell_start']?>','<?php echo $lang['spell_stop']?>','<?php echo $lang['spell_wait']?>','<?php echo $lang['spell_noerr']?>','<?php echo $lang['spell_nosug']?>','<?php echo $lang['spell_change']?>'); 968 <?php } ?> 969 970 document.editform.wikitext.focus(); 971 <?php } ?> 972 </script> 973 </td> 974 </tr> 975 </table> 976 </form> 977<?php 978} 979 980/** 981 * prepares the signature string as configured in the config 982 * 983 * @author Andreas Gohr <andi@splitbrain.org> 984 */ 985function html_signature(){ 986 global $conf; 987 global $INFO; 988 989 $sig = $conf['signature']; 990 $sig = strftime($sig); 991 $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig); 992 $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig); 993 $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig); 994 $sig = str_replace('@DATE@',date($conf['dformat']),$sig); 995 return addslashes($sig); 996} 997 998/** 999 * prints some debug info 1000 * 1001 * @author Andreas Gohr <andi@splitbrain.org> 1002 */ 1003function html_debug(){ 1004 global $conf; 1005 global $lang; 1006 //remove sensitive data 1007 $cnf = $conf; 1008 $cnf['auth']='***'; 1009 $cnf['notify']='***'; 1010 $cnf['ftp']='***'; 1011 1012 print '<html><body>'; 1013 1014 print '<p>When reporting bugs please send all the following '; 1015 print 'output as a mail to andi@splitbrain.org '; 1016 print 'The best way to do this is to save this page in your browser</p>'; 1017 1018 print '<b>$_SERVER:</b><pre>'; 1019 print_r($_SERVER); 1020 print '</pre>'; 1021 1022 print '<b>$conf:</b><pre>'; 1023 print_r($cnf); 1024 print '</pre>'; 1025 1026 print '<b>DOKU_BASE:</b><pre>'; 1027 print DOKU_BASE; 1028 print '</pre>'; 1029 1030 print '<b>abs DOKU_BASE:</b><pre>'; 1031 print DOKU_URL; 1032 print '</pre>'; 1033 1034 print '<b>rel DOKU_BASE:</b><pre>'; 1035 print dirname($_SERVER['PHP_SELF']).'/'; 1036 print '</pre>'; 1037 1038 print '<b>PHP Version:</b><pre>'; 1039 print phpversion(); 1040 print '</pre>'; 1041 1042 print '<b>locale:</b><pre>'; 1043 print setlocale(LC_ALL,0); 1044 print '</pre>'; 1045 1046 print '<b>encoding:</b><pre>'; 1047 print $lang['encoding']; 1048 print '</pre>'; 1049 1050 print '<b>Environment:</b><pre>'; 1051 print_r($_ENV); 1052 print '</pre>'; 1053 1054 print '<b>PHP settings:</b><pre>'; 1055 $inis = ini_get_all(); 1056 print_r($inis); 1057 print '</pre>'; 1058 1059 print '</body></html>'; 1060} 1061 1062function html_admin(){ 1063 global $ID; 1064 global $lang; 1065 global $conf; 1066 1067 print p_locale_xhtml('admin'); 1068 1069 // build menu of admin functions from the plugins that handle them 1070 $pluginlist = plugin_list('admin'); 1071 $menu = array(); 1072 foreach ($pluginlist as $p) { 1073 if($obj =& plugin_load('admin',$p) === NULL) continue; 1074 $menu[] = array('plugin' => $p, 1075 'prompt' => $obj->getMenuText($conf['lang']), 1076 'sort' => $obj->getMenuSort() 1077 ); 1078 } 1079 1080 usort($menu, p_sort_modes); 1081 1082 // output the menu 1083 ptln('<ul>'); 1084 1085 foreach ($menu as $item) { 1086 if (!$item['prompt']) continue; 1087 ptln(' <li><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></li>'); 1088 } 1089 1090 // add in non-plugin functions 1091 if (!$conf['openregister']){ 1092 ptln('<li><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></li>'); 1093 } 1094 1095 ptln('</ul>'); 1096 1097/* 1098 ptln('<ul>'); ptln('<ul class="admin">'); 1099 1100 // currently ACL only - more to come 1101 ptln('<li><a href="'.wl($ID,'do=admin&page=acl').'">'.$lang['admin_acl'].'</a></li>'); 1102 if (!$conf['openregister']){ 1103 ptln('<li><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></li>'); 1104 } 1105 1106 ptln('</ul>'); 1107*/ 1108} 1109 1110 1111//Setup VIM: ex: et ts=2 enc=utf-8 : 1112