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 foreach($recents as $recent){ 473 $date = date($conf['dformat'],$recent['date']); 474 print '<li>'; 475 476 print $date.' '; 477 478 print '<a href="'.wl($recent['id'],"do=diff").'">'; 479 $p = array(); 480 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 481 $p['border'] = 0; 482 $p['width'] = 15; 483 $p['height'] = 11; 484 $p['title'] = $lang['diff']; 485 $p['alt'] = $lang['diff']; 486 $att = buildAttributes($p); 487 print "<img $att />"; 488 print '</a> '; 489 490 print '<a href="'.wl($recent['id'],"do=revisions").'">'; 491 $p = array(); 492 $p['src'] = DOKU_BASE.'lib/images/history.png'; 493 $p['border'] = 0; 494 $p['width'] = 12; 495 $p['height'] = 14; 496 $p['title'] = $lang['btn_revs']; 497 $p['alt'] = $lang['btn_revs']; 498 $att = buildAttributes($p); 499 print "<img $att />"; 500 print '</a> '; 501 502 print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']); 503 504 print ' '.htmlspecialchars($recent['sum']); 505 print ' <span class="user">'; 506 if($recent['user']){ 507 print $recent['user']; 508 }else{ 509 print $recent['ip']; 510 } 511 print '</span>'; 512 513 print '</li>'; 514 } 515 print '</ul>'; 516 517 print '<div class="pagenav">'; 518 $last = $first + $conf['recent']; 519 if ($first > 0) { 520 $first -= $conf['recent']; 521 if ($first < 0) $first = 0; 522 print '<div class="pagenav-prev">'; 523 print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first)); 524 print '</div>'; 525 } 526 if ($conf['recent'] < count($recents)) { 527 print '<div class="pagenav-next">'; 528 print html_btn('older','',"n",array('do' => 'recent', 'first' => $last)); 529 print '</div>'; 530 } 531 print '</div>'; 532} 533 534/** 535 * Display page index 536 * 537 * @author Andreas Gohr <andi@splitbrain.org> 538 */ 539function html_index($ns){ 540 require_once(DOKU_INC.'inc/search.php'); 541 global $conf; 542 global $ID; 543 $dir = $conf['datadir']; 544 $ns = cleanID($ns); 545 #fixme use appropriate function 546 if(empty($ns)){ 547 $ns = dirname(str_replace(':','/',$ID)); 548 if($ns == '.') $ns =''; 549 } 550 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 551 552 print p_locale_xhtml('index'); 553 554 $data = array(); 555 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 556 print html_buildlist($data,'idx','html_list_index','html_li_index'); 557} 558 559/** 560 * Index item formatter 561 * 562 * User function for html_buildlist() 563 * 564 * @author Andreas Gohr <andi@splitbrain.org> 565 */ 566function html_list_index($item){ 567 $ret = ''; 568 $base = ':'.$item['id']; 569 $base = substr($base,strrpos($base,':')+1); 570 if($item['type']=='d'){ 571 $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">'; 572 $ret .= $base; 573 $ret .= '</a>'; 574 }else{ 575 $ret .= html_wikilink(':'.$item['id']); 576 } 577 return $ret; 578} 579 580/** 581 * Index List item 582 * 583 * This user function is used in html_build_lidt to build the 584 * <li> tags for namespaces when displaying the page index 585 * it gives different classes to opened or closed "folders" 586 * 587 * @author Andreas Gohr <andi@splitbrain.org> 588 */ 589function html_li_index($item){ 590 if($item['type'] == "f"){ 591 return '<li class="level'.$item['level'].'">'; 592 }elseif($item['open']){ 593 return '<li class="open">'; 594 }else{ 595 return '<li class="closed">'; 596 } 597} 598 599/** 600 * Default List item 601 * 602 * @author Andreas Gohr <andi@splitbrain.org> 603 */ 604function html_li_default($item){ 605 return '<li class="level'.$item['level'].'">'; 606} 607 608/** 609 * Build an unordered list 610 * 611 * Build an unordered list from the given $data array 612 * Each item in the array has to have a 'level' property 613 * the item itself gets printed by the given $func user 614 * function. The second and optional function is used to 615 * print the <li> tag. Both user function need to accept 616 * a single item. 617 * 618 * @author Andreas Gohr <andi@splitbrain.org> 619 */ 620function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 621 $level = 0; 622 $opens = 0; 623 $ret = ''; 624 625 foreach ($data as $item){ 626 627 if( $item['level'] > $level ){ 628 //open new list 629 for($i=0; $i<($item['level'] - $level); $i++){ 630 if ($i) $ret .= "<li class=\"clear\">\n"; 631 $ret .= "\n<ul class=\"$class\">\n"; 632 } 633 }elseif( $item['level'] < $level ){ 634 //close last item 635 $ret .= "</li>\n"; 636 for ($i=0; $i<($level - $item['level']); $i++){ 637 //close higher lists 638 $ret .= "</ul>\n</li>\n"; 639 } 640 }else{ 641 //close last item 642 $ret .= "</li>\n"; 643 } 644 645 //remember current level 646 $level = $item['level']; 647 648 //print item 649 $ret .= $lifunc($item); //user function 650 $ret .= '<span class="li">'; 651 $ret .= $func($item); //user function 652 $ret .= '</span>'; 653 } 654 655 //close remaining items and lists 656 for ($i=0; $i < $level; $i++){ 657 $ret .= "</li></ul>\n"; 658 } 659 660 return $ret; 661} 662 663/** 664 * display backlinks 665 * 666 * @author Andreas Gohr <andi@splitbrain.org> 667 */ 668function html_backlinks(){ 669 require_once(DOKU_INC.'inc/fulltext.php'); 670 global $ID; 671 global $conf; 672 673 print p_locale_xhtml('backlinks'); 674 675 $data = ft_backlinks($ID); 676 677 print '<ul class="idx">'; 678 foreach($data as $blink){ 679 print '<li>'; 680 print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink); 681 print '</li>'; 682 } 683 print '</ul>'; 684} 685 686/** 687 * show diff 688 * 689 * @author Andreas Gohr <andi@splitbrain.org> 690 */ 691function html_diff($text='',$intro=true){ 692 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 693 global $ID; 694 global $REV; 695 global $lang; 696 global $conf; 697 if($text){ 698 $df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))), 699 split("\n",htmlspecialchars(cleanText($text)))); 700 $left = '<a class="wikilink1" href="'.wl($ID).'">'. 701 $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'. 702 $lang['current']; 703 $right = $lang['yours']; 704 }else{ 705 if($REV){ 706 $r = $REV; 707 }else{ 708 //use last revision if none given 709 $revs = getRevisions($ID); 710 $r = $revs[0]; 711 } 712 713 $df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))), 714 split("\n",htmlspecialchars(rawWiki($ID,'')))); 715 $left = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'. 716 $ID.' '.date($conf['dformat'],$r).'</a>'; 717 $right = '<a class="wikilink1" href="'.wl($ID).'">'. 718 $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '. 719 $lang['current']; 720 } 721 $tdf = new TableDiffFormatter(); 722 if($intro) print p_locale_xhtml('diff'); 723 ?> 724 <table class="diff" width="100%"> 725 <tr> 726 <td colspan="2" width="50%" class="diff-header"> 727 <?php echo $left?> 728 </td> 729 <td colspan="2" width="50%" class="diff-header"> 730 <?php echo $right?> 731 </td> 732 </tr> 733 <?php echo $tdf->format($df)?> 734 </table> 735 <?php 736} 737 738/** 739 * show warning on conflict detection 740 * 741 * @author Andreas Gohr <andi@splitbrain.org> 742 */ 743function html_conflict($text,$summary){ 744 global $ID; 745 global $lang; 746 747 print p_locale_xhtml('conflict'); 748 ?> 749 <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"> 750 <input type="hidden" name="id" value="<?php echo $ID?>" /> 751 <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" /> 752 <input type="hidden" name="summary" value="<?php echo formText($summary)?>" /> 753 754 <div align="center"> 755 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" /> 756 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" /> 757 </div> 758 </form> 759 <br /><br /><br /><br /> 760 <?php 761} 762 763/** 764 * Prints the global message array 765 * 766 * @author Andreas Gohr <andi@splitbrain.org> 767 */ 768function html_msgarea(){ 769 global $MSG; 770 771 if(!isset($MSG)) return; 772 773 foreach($MSG as $msg){ 774 print '<div class="'.$msg['lvl'].'">'; 775 print $msg['msg']; 776 print '</div>'; 777 } 778} 779 780/** 781 * Prints the registration form 782 * 783 * @author Andreas Gohr <andi@splitbrain.org> 784 */ 785function html_register(){ 786 global $lang; 787 global $conf; 788 global $ID; 789 790 print p_locale_xhtml('register'); 791?> 792 <div align="center"> 793 <form name="register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>"> 794 <input type="hidden" name="do" value="register" /> 795 <input type="hidden" name="save" value="1" /> 796 <fieldset> 797 <legend><?php echo $lang['register']?></legend> 798 <label> 799 <?php echo $lang['user']?> 800 <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" /> 801 </label><br /> 802 803 <?php 804 if (!$conf['autopasswd']) { 805 ?> 806 <label> 807 <?php echo $lang['pass']?> 808 <input type="password" name="pass" class="edit" size="50" /> 809 </label><br /> 810 <label> 811 <?php echo $lang['passchk']?> 812 <input type="password" name="passchk" class="edit" size="50" /> 813 </label><br /> 814 <?php 815 } 816 ?> 817 818 <label> 819 <?php echo $lang['fullname']?> 820 <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" /> 821 </label><br /> 822 <label> 823 <?php echo $lang['email']?> 824 <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" /> 825 </label><br /> 826 <input type="submit" class="button" value="<?php echo $lang['register']?>" /> 827 </fieldset> 828 </form> 829 </div> 830<?php 831} 832 833/** 834 * This displays the edit form (lots of logic included) 835 * 836 * @fixme this is a huge lump of code and should be modularized 837 * @author Andreas Gohr <andi@splitbrain.org> 838 */ 839function html_edit($text=null,$include='edit'){ //FIXME: include needed? 840 global $ID; 841 global $REV; 842 global $DATE; 843 global $RANGE; 844 global $PRE; 845 global $SUF; 846 global $INFO; 847 global $SUM; 848 global $lang; 849 global $conf; 850 851 //set summary default 852 if(!$SUM){ 853 if($REV){ 854 $SUM = $lang['restored']; 855 }elseif(!$INFO['exists']){ 856 $SUM = $lang['created']; 857 } 858 } 859 860 //no text? Load it! 861 if(!isset($text)){ 862 $pr = false; //no preview mode 863 if($INFO['exists']){ 864 if($RANGE){ 865 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); 866 }else{ 867 $text = rawWiki($ID,$REV); 868 } 869 }else{ 870 //try to load a pagetemplate 871 $text = pageTemplate($ID); 872 } 873 }else{ 874 $pr = true; //preview mode 875 } 876 877 $wr = $INFO['writable']; 878 if($wr){ 879 if ($REV) print p_locale_xhtml('editrev'); 880 print p_locale_xhtml($include); 881 }else{ 882 print p_locale_xhtml('read'); 883 $ro='readonly="readonly"'; 884 } 885 if(!$DATE) $DATE = $INFO['lastmod']; 886 887 888?> 889 <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" onsubmit="return svchk()"> 890 <input type="hidden" name="id" value="<?php echo $ID?>" /> 891 <input type="hidden" name="rev" value="<?php echo $REV?>" /> 892 <input type="hidden" name="date" value="<?php echo $DATE?>" /> 893 <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" /> 894 <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" /> 895 <table style="width:99%"> 896 <tr> 897 <td class="toolbar" colspan="2"> 898 <?php if($wr){?> 899 <script language="javascript" type="text/javascript" charset="utf-8"> 900 <?php /* sets changed to true when previewed */?> 901 textChanged = <?php ($pr) ? print 'true' : print 'false' ?>; 902 903 formatButton('bold.png','<?php echo $lang['qb_bold']?>','**','**','<?php echo $lang['qb_bold']?>','b'); 904 formatButton('italic.png','<?php echo $lang['qb_italic']?>',"\/\/","\/\/",'<?php echo $lang['qb_italic']?>','i'); 905 formatButton('underline.png','<?php echo $lang['qb_underl']?>','__','__','<?php echo $lang['qb_underl']?>','u'); 906 formatButton('code.png','<?php echo $lang['qb_code']?>','\'\'','\'\'','<?php echo $lang['qb_code']?>','c'); 907 formatButton('strike.png','<?php echo $lang['qb_strike']?>','<del>','<\/del>','<?php echo $lang['qb_strike']?>','d'); 908 909 formatButton('fonth1.png','<?php echo $lang['qb_h1']?>','====== ',' ======\n','<?php echo $lang['qb_h1']?>','1'); 910 formatButton('fonth2.png','<?php echo $lang['qb_h2']?>','===== ',' =====\n','<?php echo $lang['qb_h2']?>','2'); 911 formatButton('fonth3.png','<?php echo $lang['qb_h3']?>','==== ',' ====\n','<?php echo $lang['qb_h3']?>','3'); 912 formatButton('fonth4.png','<?php echo $lang['qb_h4']?>','=== ',' ===\n','<?php echo $lang['qb_h4']?>','4'); 913 formatButton('fonth5.png','<?php echo $lang['qb_h5']?>','== ',' ==\n','<?php echo $lang['qb_h5']?>','5'); 914 915 formatButton('link.png','<?php echo $lang['qb_link']?>','[[',']]','<?php echo $lang['qb_link']?>','l'); 916 formatButton('extlink.png','<?php echo $lang['qb_extlink']?>','[[',']]','http://www.example.com|<?php echo $lang['qb_extlink']?>'); 917 918 formatButton('list.png','<?php echo $lang['qb_ol']?>',' - ','\n','<?php echo $lang['qb_ol']?>'); 919 formatButton('list_ul.png','<?php echo $lang['qb_ul']?>',' * ','\n','<?php echo $lang['qb_ul']?>'); 920 921 insertButton('rule.png','<?php echo $lang['qb_hr']?>','----\n'); 922 mediaButton('image.png','<?php echo $lang['qb_media']?>','m','<?php echo $INFO['namespace']?>'); 923 924 <?php 925 if($conf['useacl'] && $_SERVER['REMOTE_USER']){ 926 echo "insertButton('sig.png','".$lang['qb_sig']."','".html_signature()."','y');"; 927 } 928 ?> 929 </script> 930 <span id="spell_action"></span> 931 <?php } ?> 932 </td> 933 <td> 934 <div id="spell_suggest"></div> 935 </td> 936 </tr> 937 <tr> 938 <td colspan="3"> 939 <div id="spell_result"></div> 940 <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> 941 </td> 942 </tr> 943 <tr id="wikieditbar"> 944 <td> 945 <?php if($wr){?> 946 <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" /> 947 <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" /> 948 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="5" /> 949 <?php } ?> 950 </td> 951 <td> 952 <?php if($wr){ ?> 953 <?php echo $lang['summary']?>: 954 <input type="text" class="edit" name="summary" id="summary" size="50" onkeyup="summaryCheck();" value="<?php echo formText($SUM)?>" tabindex="2" /> 955 <?php }?> 956 </td> 957 <td align="right"> 958 <script language="javascript" type="text/javascript" charset="utf-8"> 959 showSizeCtl(); 960 <?php if($wr){ ?> 961 init_locktimer(<?php echo $conf['locktime']-60?>,'<?php echo $lang['willexpire']?>'); 962 963 //initialize spellchecker 964 <?php if($conf['spellchecker']){ ?> 965 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']?>'); 966 <?php } ?> 967 968 document.editform.wikitext.focus(); 969 <?php } ?> 970 </script> 971 </td> 972 </tr> 973 </table> 974 </form> 975<?php 976} 977 978/** 979 * prepares the signature string as configured in the config 980 * 981 * @author Andreas Gohr <andi@splitbrain.org> 982 */ 983function html_signature(){ 984 global $conf; 985 global $INFO; 986 987 $sig = $conf['signature']; 988 $sig = strftime($sig); 989 $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig); 990 $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig); 991 $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig); 992 $sig = str_replace('@DATE@',date($conf['dformat']),$sig); 993 return addslashes($sig); 994} 995 996/** 997 * prints some debug info 998 * 999 * @author Andreas Gohr <andi@splitbrain.org> 1000 */ 1001function html_debug(){ 1002 global $conf; 1003 global $lang; 1004 //remove sensitive data 1005 $cnf = $conf; 1006 $cnf['auth']='***'; 1007 $cnf['notify']='***'; 1008 $cnf['ftp']='***'; 1009 1010 print '<html><body>'; 1011 1012 print '<p>When reporting bugs please send all the following '; 1013 print 'output as a mail to andi@splitbrain.org '; 1014 print 'The best way to do this is to save this page in your browser</p>'; 1015 1016 print '<b>$_SERVER:</b><pre>'; 1017 print_r($_SERVER); 1018 print '</pre>'; 1019 1020 print '<b>$conf:</b><pre>'; 1021 print_r($cnf); 1022 print '</pre>'; 1023 1024 print '<b>DOKU_BASE:</b><pre>'; 1025 print DOKU_BASE; 1026 print '</pre>'; 1027 1028 print '<b>abs DOKU_BASE:</b><pre>'; 1029 print DOKU_URL; 1030 print '</pre>'; 1031 1032 print '<b>rel DOKU_BASE:</b><pre>'; 1033 print dirname($_SERVER['PHP_SELF']).'/'; 1034 print '</pre>'; 1035 1036 print '<b>PHP Version:</b><pre>'; 1037 print phpversion(); 1038 print '</pre>'; 1039 1040 print '<b>locale:</b><pre>'; 1041 print setlocale(LC_ALL,0); 1042 print '</pre>'; 1043 1044 print '<b>encoding:</b><pre>'; 1045 print $lang['encoding']; 1046 print '</pre>'; 1047 1048 print '<b>Environment:</b><pre>'; 1049 print_r($_ENV); 1050 print '</pre>'; 1051 1052 print '<b>PHP settings:</b><pre>'; 1053 $inis = ini_get_all(); 1054 print_r($inis); 1055 print '</pre>'; 1056 1057 print '</body></html>'; 1058} 1059 1060function html_admin(){ 1061 global $ID; 1062 global $lang; 1063 global $conf; 1064 1065 print p_locale_xhtml('admin'); 1066 1067 // build menu of admin functions from the plugins that handle them 1068 $pluginlist = plugin_list('admin'); 1069 $menu = array(); 1070 foreach ($pluginlist as $p) { 1071 if($obj =& plugin_load('admin',$p) === NULL) continue; 1072 $menu[] = array('plugin' => $p, 1073 'prompt' => $obj->getMenuText($conf['lang']), 1074 'sort' => $obj->getMenuSort() 1075 ); 1076 } 1077 1078 usort($menu, p_sort_modes); 1079 1080 // output the menu 1081 ptln('<ul>'); 1082 1083 foreach ($menu as $item) { 1084 if (!$item['prompt']) continue; 1085 ptln(' <li><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></li>'); 1086 } 1087 1088 // add in non-plugin functions 1089 if (!$conf['openregister']){ 1090 ptln('<li><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></li>'); 1091 } 1092 1093 ptln('</ul>'); 1094 1095/* 1096 ptln('<ul>'); ptln('<ul class="admin">'); 1097 1098 // currently ACL only - more to come 1099 ptln('<li><a href="'.wl($ID,'do=admin&page=acl').'">'.$lang['admin_acl'].'</a></li>'); 1100 if (!$conf['openregister']){ 1101 ptln('<li><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></li>'); 1102 } 1103 1104 ptln('</ul>'); 1105*/ 1106} 1107 1108 1109//Setup VIM: ex: et ts=2 enc=utf-8 : 1110