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 static $xhtml_renderer = NULL; 20 if(is_null($xhtml_renderer)){ 21 require_once(DOKU_INC.'inc/parser/xhtml.php'); 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 global $auth; 51 52 print p_locale_xhtml('login'); 53 ?> 54 <div class="centeralign"> 55 <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" 56 method="post" name="login"> 57 <fieldset> 58 <legend><?php echo $lang['btn_login']?></legend> 59 <input type="hidden" name="id" value="<?php echo $ID?>" /> 60 <input type="hidden" name="do" value="login" /> 61 <label class="block"> 62 <span><?php echo $lang['user']?></span> 63 <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>" 64 class="edit" id="focus__this" /> 65 </label><br /> 66 <label class="block"> 67 <span><?php echo $lang['pass']?></span> 68 <input type="password" name="p" class="edit" /> 69 </label><br /> 70 <label for="remember__me" class="simple"> 71 <input type="checkbox" name="r" id="remember__me" value="1" /> 72 <span><?php echo $lang['remember']?></span> 73 </label> 74 <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" /> 75 </fieldset> 76 </form> 77 <?php 78 if($auth->canDo('addUser') && $conf['openregister']){ 79 print '<p>'; 80 print $lang['reghere']; 81 print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>'; 82 print '</p>'; 83 } 84 85 if ($auth->canDo('modPass') && $conf['resendpasswd']) { 86 print '<p>'; 87 print $lang['pwdforget']; 88 print ': <a href="'.wl($ID,'do=resendpwd').'" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'; 89 print '</p>'; 90 } 91 ?> 92 </div> 93 <?php 94/* 95 FIXME provide new hook 96 if(@file_exists('includes/login.txt')){ 97 print io_cacheParse('includes/login.txt'); 98 } 99*/ 100} 101 102/** 103 * shows the edit/source/show/draft button dependent on current mode 104 * 105 * @author Andreas Gohr <andi@splitbrain.org> 106 */ 107function html_editbutton(){ 108 global $ID; 109 global $REV; 110 global $ACT; 111 global $INFO; 112 113 if($ACT == 'show' || $ACT == 'search'){ 114 if($INFO['writable']){ 115 if($INFO['draft']){ 116 $r = html_btn('draft',$ID,'e',array('do' => 'draft'),'post'); 117 }else{ 118 if($INFO['exists']){ 119 $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); 120 }else{ 121 $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); 122 } 123 } 124 }else{ 125 $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post'); 126 } 127 }else{ 128 $r = html_btn('show',$ID,'v',array('do' => 'show')); 129 } 130 return $r; 131} 132 133/** 134 * prints a section editing button 135 * used as a callback in html_secedit 136 * 137 * @author Andreas Gohr <andi@splitbrain.org> 138 */ 139function html_secedit_button($matches){ 140 global $ID; 141 global $INFO; 142 143 $section = $matches[2]; 144 $name = $matches[1]; 145 146 $secedit = ''; 147 $secedit .= '<div class="secedit">'; 148 $secedit .= html_btn('secedit',$ID,'', 149 array('do' => 'edit', 150 'lines' => "$section", 151 'rev' => $INFO['lastmod']), 152 'post', $name); 153 $secedit .= '</div>'; 154 return $secedit; 155} 156 157/** 158 * inserts section edit buttons if wanted or removes the markers 159 * 160 * @author Andreas Gohr <andi@splitbrain.org> 161 */ 162function html_secedit($text,$show=true){ 163 global $INFO; 164 165 if($INFO['writable'] && $show && !$INFO['rev']){ 166 $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#', 167 'html_secedit_button', $text); 168 }else{ 169 $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text); 170 } 171 172 return $text; 173} 174 175/** 176 * Just the back to top button (in its own form) 177 * 178 * @author Andreas Gohr <andi@splitbrain.org> 179 */ 180function html_topbtn(){ 181 global $lang; 182 183 $ret = ''; 184 $ret = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" /></a>'; 185 186 return $ret; 187} 188 189/** 190 * Just the back to media window button in its own form 191 * 192 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 193 */ 194function html_backtomedia_button($params,$akey=''){ 195 global $conf; 196 global $lang; 197 198 $ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/mediamanager.php"><div class="no">'; 199 200 reset($params); 201 while (list($key, $val) = each($params)) { 202 $ret .= '<input type="hidden" name="'.$key.'" '; 203 $ret .= 'value="'.htmlspecialchars($val).'" />'; 204 } 205 206 $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" '; 207 if($akey){ 208 $ret .= 'title="ALT+'.strtoupper($akey).'" '; 209 $ret .= 'accesskey="'.$akey.'" '; 210 } 211 $ret .= '/>'; 212 $ret .= '</div></form>'; 213 214 return $ret; 215} 216 217/** 218 * Displays a button (using its own form) 219 * If tooltip exists, the access key tooltip is replaced. 220 * 221 * @author Andreas Gohr <andi@splitbrain.org> 222 */ 223function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){ 224 global $conf; 225 global $lang; 226 227 $label = $lang['btn_'.$name]; 228 229 $ret = ''; 230 $tip = ''; 231 232 //filter id (without urlencoding) 233 $id = idfilter($id,false); 234 235 //make nice URLs even for buttons 236 if($conf['userewrite'] == 2){ 237 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 238 }elseif($conf['userewrite']){ 239 $script = DOKU_BASE.$id; 240 }else{ 241 $script = DOKU_BASE.DOKU_SCRIPT; 242 $params['id'] = $id; 243 } 244 245 $ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">'; 246 247 if(is_array($params)){ 248 reset($params); 249 while (list($key, $val) = each($params)) { 250 $ret .= '<input type="hidden" name="'.$key.'" '; 251 $ret .= 'value="'.htmlspecialchars($val).'" />'; 252 } 253 } 254 255 $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" '; 256 if($akey){ 257 $tip = '[ALT+'.strtoupper($akey).']'; 258 $ret .= 'accesskey="'.$akey.'" '; 259 } 260 if ($tooltip!='') { 261 $tip = htmlspecialchars($tooltip); 262 } 263 $ret .= 'title="'.$tip.'" '; 264 $ret .= '/>'; 265 $ret .= '</div></form>'; 266 267 return $ret; 268} 269 270/** 271 * show a wiki page 272 * 273 * @author Andreas Gohr <andi@splitbrain.org> 274 */ 275function html_show($txt=''){ 276 global $ID; 277 global $REV; 278 global $HIGH; 279 //disable section editing for old revisions or in preview 280 if($txt || $REV){ 281 $secedit = false; 282 }else{ 283 $secedit = true; 284 } 285 286 if ($txt){ 287 //PreviewHeader 288 print '<br id="scroll__here" />'; 289 print p_locale_xhtml('preview'); 290 print '<div class="preview">'; 291 print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 292 print '<div class="clearer"></div>'; 293 print '</div>'; 294 295 }else{ 296 if ($REV) print p_locale_xhtml('showrev'); 297 $html = p_wiki_xhtml($ID,$REV,true); 298 $html = html_secedit($html,$secedit); 299 print html_hilight($html,$HIGH); 300 } 301} 302 303/** 304 * ask the user about how to handle an exisiting draft 305 * 306 * @author Andreas Gohr <andi@splitbrain.org> 307 */ 308function html_draft(){ 309 global $INFO; 310 global $ID; 311 global $lang; 312 global $conf; 313 $draft = unserialize(io_readFile($INFO['draft'],false)); 314 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 315 316 echo p_locale_xhtml('draft'); 317 ?> 318 <form id="dw__editform" method="post" action="<?php echo script()?>" 319 accept-charset="<?php echo $lang['encoding']?>"><div class="no"> 320 <input type="hidden" name="id" value="<?php echo $ID?>" /> 321 <input type="hidden" name="date" value="<?php echo $draft['date']?>" /></div> 322 <textarea name="wikitext" id="wiki__text" readonly="readonly" cols="80" rows="10" class="edit"><?php echo "\n".formText($text)?></textarea> 323 324 <div id="draft__status"><?php echo $lang['draftdate'].' '.date($conf['dformat'],filemtime($INFO['draft']))?></div> 325 326 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_recover']?>" tabindex="1" /> 327 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_draftdel']?>" tabindex="2" /> 328 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="3" /> 329 </form> 330 <?php 331} 332 333/** 334 * Highlights searchqueries in HTML code 335 * 336 * @author Andreas Gohr <andi@splitbrain.org> 337 * @author Harry Fuecks <hfuecks@gmail.com> 338 */ 339function html_hilight($html,$query){ 340 //split at common delimiters 341 $queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY); 342 foreach ($queries as $q){ 343 $q = preg_quote($q,'/'); 344 $html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html); 345 } 346 return $html; 347} 348 349/** 350 * Callback used by html_hilight() 351 * 352 * @author Harry Fuecks <hfuecks@gmail.com> 353 */ 354function html_hilight_callback($m) { 355 $hlight = unslash($m[0]); 356 if ( !isset($m[2])) { 357 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 358 } 359 return $hlight; 360} 361 362/** 363 * Run a search and display the result 364 * 365 * @author Andreas Gohr <andi@splitbrain.org> 366 */ 367function html_search(){ 368 require_once(DOKU_INC.'inc/search.php'); 369 require_once(DOKU_INC.'inc/fulltext.php'); 370 global $conf; 371 global $QUERY; 372 global $ID; 373 global $lang; 374 375 print p_locale_xhtml('searchpage'); 376 flush(); 377 378 //check if search is restricted to namespace 379 if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) { 380 $id = cleanID($match[1]); 381 if(empty($id)) { 382 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 383 flush(); 384 return; 385 } 386 } else { 387 $id = cleanID($QUERY); 388 } 389 390 //show progressbar 391 print '<div class="centeralign" id="dw__loading">'; 392 print '<br /></div>'; 393 print '<script type="text/javascript" charset="utf-8">'; 394 print 'showLoadBar("dw__loading");'; 395 print '</script>'; 396 flush(); 397 398 //do quick pagesearch 399 $data = array(); 400 401 $data = ft_pageLookup($id); 402 if(count($data)){ 403 sort($data); 404 print '<div class="search_quickresult">'; 405 print '<h3>'.$lang[quickhits].':</h3>'; 406 print '<ul class="search_quickhits">'; 407 foreach($data as $id){ 408 print '<li> '; 409 print html_wikilink(':'.$id,$conf['useheading']?NULL:$id); 410 print '</li> '; 411 } 412 print '</ul> '; 413 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 414 print '<div class="clearer"> </div>'; 415 print '</div>'; 416 } 417 flush(); 418 419 //do fulltext search 420 $data = ft_pageSearch($QUERY,$poswords); 421 if(count($data)){ 422 $num = 1; 423 foreach($data as $id => $cnt){ 424 print '<div class="search_result">'; 425 print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords); 426 print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />'; 427 if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ? 428 print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>'; 429 } 430 print '</div>'; 431 flush(); 432 $num++; 433 } 434 }else{ 435 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 436 } 437 438 //hide progressbar 439 print '<script type="text/javascript" charset="utf-8">'; 440 print 'hideLoadBar("dw__loading");'; 441 print '</script>'; 442 flush(); 443} 444 445/** 446 * Display error on locked pages 447 * 448 * @author Andreas Gohr <andi@splitbrain.org> 449 */ 450function html_locked(){ 451 global $ID; 452 global $conf; 453 global $lang; 454 global $INFO; 455 456 $locktime = filemtime(wikiFN($ID).'.lock'); 457 $expire = @date($conf['dformat'], $locktime + $conf['locktime'] ); 458 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 459 460 print p_locale_xhtml('locked'); 461 print '<ul>'; 462 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>'; 463 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 464 print '</ul>'; 465} 466 467/** 468 * list old revisions 469 * 470 * @author Andreas Gohr <andi@splitbrain.org> 471 */ 472function html_revisions(){ 473 global $ID; 474 global $INFO; 475 global $conf; 476 global $lang; 477 $revisions = getRevisions($ID); 478 $date = @date($conf['dformat'],$INFO['lastmod']); 479 480 print p_locale_xhtml('revisions'); 481 print '<ul>'; 482 if($INFO['exists']){ 483 print ($INFO['minor']) ? '<li class="minor">' : '<li>'; 484 print '<div class="li">'; 485 486 print $date; 487 488 print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> '; 489 490 print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> '; 491 492 print $INFO['sum']; 493 print ' <span class="user">'; 494 print $INFO['editor']; 495 print '</span> '; 496 497 print '('.$lang['current'].')'; 498 print '</div>'; 499 print '</li>'; 500 } 501 502 foreach($revisions as $rev){ 503 $date = date($conf['dformat'],$rev); 504 $info = getRevisionInfo($ID,$rev,true); 505 506 print ($info['minor']) ? '<li class="minor">' : '<li>'; 507 print '<div class="li">'; 508 print $date; 509 510 print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">'; 511 $p = array(); 512 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 513 $p['width'] = 15; 514 $p['height'] = 11; 515 $p['title'] = $lang['diff']; 516 $p['alt'] = $lang['diff']; 517 $att = buildAttributes($p); 518 print "<img $att />"; 519 print '</a> '; 520 521 print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> '; 522 523 print htmlspecialchars($info['sum']); 524 print ' <span class="user">'; 525 if($info['user']){ 526 print $info['user']; 527 }else{ 528 print $info['ip']; 529 } 530 print '</span>'; 531 532 print '</div>'; 533 print '</li>'; 534 } 535 print '</ul>'; 536} 537 538/** 539 * display recent changes 540 * 541 * @author Andreas Gohr <andi@splitbrain.org> 542 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 543 */ 544function html_recent($first=0){ 545 global $conf; 546 global $lang; 547 global $ID; 548 /* we need to get one additionally log entry to be able to 549 * decide if this is the last page or is there another one. 550 * This is the cheapest solution to get this information. 551 */ 552 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 553 if(count($recents) == 0 && $first != 0){ 554 $first=0; 555 $recents = getRecents(0,$conf['recent'] + 1,getNS($ID)); 556 } 557 $cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent']; 558 559 print p_locale_xhtml('recent'); 560 print '<ul>'; 561 562 foreach($recents as $recent){ 563 $date = date($conf['dformat'],$recent['date']); 564 print ($recent['minor']) ? '<li class="minor">' : '<li>'; 565 print '<div class="li">'; 566 567 print $date.' '; 568 569 print '<a href="'.wl($recent['id'],"do=diff").'">'; 570 $p = array(); 571 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 572 $p['width'] = 15; 573 $p['height'] = 11; 574 $p['title'] = $lang['diff']; 575 $p['alt'] = $lang['diff']; 576 $att = buildAttributes($p); 577 print "<img $att />"; 578 print '</a> '; 579 580 print '<a href="'.wl($recent['id'],"do=revisions").'">'; 581 $p = array(); 582 $p['src'] = DOKU_BASE.'lib/images/history.png'; 583 $p['width'] = 12; 584 $p['height'] = 14; 585 $p['title'] = $lang['btn_revs']; 586 $p['alt'] = $lang['btn_revs']; 587 $att = buildAttributes($p); 588 print "<img $att />"; 589 print '</a> '; 590 591 print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']); 592 print ' '.htmlspecialchars($recent['sum']); 593 594 print ' <span class="user">'; 595 if($recent['user']){ 596 print $recent['user']; 597 }else{ 598 print $recent['ip']; 599 } 600 print '</span>'; 601 602 print '</div>'; 603 print '</li>'; 604 } 605 print '</ul>'; 606 607 print '<div class="pagenav">'; 608 $last = $first + $conf['recent']; 609 if ($first > 0) { 610 $first -= $conf['recent']; 611 if ($first < 0) $first = 0; 612 print '<div class="pagenav-prev">'; 613 print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first)); 614 print '</div>'; 615 } 616 if ($conf['recent'] < count($recents)) { 617 print '<div class="pagenav-next">'; 618 print html_btn('older','',"n",array('do' => 'recent', 'first' => $last)); 619 print '</div>'; 620 } 621 print '</div>'; 622} 623 624/** 625 * Display page index 626 * 627 * @author Andreas Gohr <andi@splitbrain.org> 628 */ 629function html_index($ns){ 630 require_once(DOKU_INC.'inc/search.php'); 631 global $conf; 632 global $ID; 633 $dir = $conf['datadir']; 634 $ns = cleanID($ns); 635 #fixme use appropriate function 636 if(empty($ns)){ 637 $ns = dirname(str_replace(':','/',$ID)); 638 if($ns == '.') $ns =''; 639 } 640 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 641 642 print p_locale_xhtml('index'); 643 644 $data = array(); 645 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 646 print html_buildlist($data,'idx','html_list_index','html_li_index'); 647} 648 649/** 650 * Index item formatter 651 * 652 * User function for html_buildlist() 653 * 654 * @author Andreas Gohr <andi@splitbrain.org> 655 */ 656function html_list_index($item){ 657 $ret = ''; 658 $base = ':'.$item['id']; 659 $base = substr($base,strrpos($base,':')+1); 660 if($item['type']=='d'){ 661 $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">'; 662 $ret .= $base; 663 $ret .= '</a>'; 664 }else{ 665 $ret .= html_wikilink(':'.$item['id']); 666 } 667 return $ret; 668} 669 670/** 671 * Index List item 672 * 673 * This user function is used in html_build_lidt to build the 674 * <li> tags for namespaces when displaying the page index 675 * it gives different classes to opened or closed "folders" 676 * 677 * @author Andreas Gohr <andi@splitbrain.org> 678 */ 679function html_li_index($item){ 680 if($item['type'] == "f"){ 681 return '<li class="level'.$item['level'].'">'; 682 }elseif($item['open']){ 683 return '<li class="open">'; 684 }else{ 685 return '<li class="closed">'; 686 } 687} 688 689/** 690 * Default List item 691 * 692 * @author Andreas Gohr <andi@splitbrain.org> 693 */ 694function html_li_default($item){ 695 return '<li class="level'.$item['level'].'">'; 696} 697 698/** 699 * Build an unordered list 700 * 701 * Build an unordered list from the given $data array 702 * Each item in the array has to have a 'level' property 703 * the item itself gets printed by the given $func user 704 * function. The second and optional function is used to 705 * print the <li> tag. Both user function need to accept 706 * a single item. 707 * 708 * Both user functions can be given as array to point to 709 * a member of an object. 710 * 711 * @author Andreas Gohr <andi@splitbrain.org> 712 */ 713function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 714 $level = 0; 715 $opens = 0; 716 $ret = ''; 717 718 foreach ($data as $item){ 719 720 if( $item['level'] > $level ){ 721 //open new list 722 for($i=0; $i<($item['level'] - $level); $i++){ 723 if ($i) $ret .= "<li class=\"clear\">\n"; 724 $ret .= "\n<ul class=\"$class\">\n"; 725 } 726 }elseif( $item['level'] < $level ){ 727 //close last item 728 $ret .= "</li>\n"; 729 for ($i=0; $i<($level - $item['level']); $i++){ 730 //close higher lists 731 $ret .= "</ul>\n</li>\n"; 732 } 733 }else{ 734 //close last item 735 $ret .= "</li>\n"; 736 } 737 738 //remember current level 739 $level = $item['level']; 740 741 //print item 742 if(is_array($lifunc)){ 743 $ret .= $lifunc[0]->$lifunc[1]($item); //user object method 744 }else{ 745 $ret .= $lifunc($item); //user function 746 } 747 $ret .= '<div class="li">'; 748 if(is_array($func)){ 749 $ret .= $func[0]->$func[1]($item); //user object method 750 }else{ 751 $ret .= $func($item); //user function 752 } 753 $ret .= '</div>'; 754 } 755 756 //close remaining items and lists 757 for ($i=0; $i < $level; $i++){ 758 $ret .= "</li></ul>\n"; 759 } 760 761 return $ret; 762} 763 764/** 765 * display backlinks 766 * 767 * @author Andreas Gohr <andi@splitbrain.org> 768 */ 769function html_backlinks(){ 770 require_once(DOKU_INC.'inc/fulltext.php'); 771 global $ID; 772 global $conf; 773 774 print p_locale_xhtml('backlinks'); 775 776 $data = ft_backlinks($ID); 777 778 print '<ul class="idx">'; 779 foreach($data as $blink){ 780 print '<li><div class="li">'; 781 print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink); 782 print '</div></li>'; 783 } 784 print '</ul>'; 785} 786 787/** 788 * show diff 789 * 790 * @author Andreas Gohr <andi@splitbrain.org> 791 */ 792function html_diff($text='',$intro=true){ 793 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 794 global $ID; 795 global $REV; 796 global $lang; 797 global $conf; 798 if($text){ 799 $df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))), 800 split("\n",htmlspecialchars(cleanText($text)))); 801 $left = '<a class="wikilink1" href="'.wl($ID).'">'. 802 $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'. 803 $lang['current']; 804 $right = $lang['yours']; 805 }else{ 806 if($REV){ 807 $r = $REV; 808 }else{ 809 //use last revision if none given 810 $revs = getRevisions($ID); 811 $r = $revs[0]; 812 } 813 814 $df = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))), 815 split("\n",htmlspecialchars(rawWiki($ID,'')))); 816 $left = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'. 817 $ID.' '.date($conf['dformat'],$r).'</a>'; 818 $right = '<a class="wikilink1" href="'.wl($ID).'">'. 819 $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '. 820 $lang['current']; 821 } 822 $tdf = new TableDiffFormatter(); 823 if($intro) print p_locale_xhtml('diff'); 824 ?> 825 <table class="diff"> 826 <tr> 827 <th colspan="2"> 828 <?php echo $left?> 829 </th> 830 <th colspan="2"> 831 <?php echo $right?> 832 </th> 833 </tr> 834 <?php echo $tdf->format($df)?> 835 </table> 836 <?php 837} 838 839/** 840 * show warning on conflict detection 841 * 842 * @author Andreas Gohr <andi@splitbrain.org> 843 */ 844function html_conflict($text,$summary){ 845 global $ID; 846 global $lang; 847 848 print p_locale_xhtml('conflict'); 849 ?> 850 <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"> 851 <div class="centeralign"> 852 <input type="hidden" name="id" value="<?php echo $ID?>" /> 853 <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" /> 854 <input type="hidden" name="summary" value="<?php echo formText($summary)?>" /> 855 856 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" /> 857 <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" /> 858 </div> 859 </form> 860 <br /><br /><br /><br /> 861 <?php 862} 863 864/** 865 * Prints the global message array 866 * 867 * @author Andreas Gohr <andi@splitbrain.org> 868 */ 869function html_msgarea(){ 870 global $MSG; 871 872 if(!isset($MSG)) return; 873 874 foreach($MSG as $msg){ 875 print '<div class="'.$msg['lvl'].'">'; 876 print $msg['msg']; 877 print '</div>'; 878 } 879} 880 881/** 882 * Prints the registration form 883 * 884 * @author Andreas Gohr <andi@splitbrain.org> 885 */ 886function html_register(){ 887 global $lang; 888 global $conf; 889 global $ID; 890 891 print p_locale_xhtml('register'); 892?> 893 <div class="centeralign"> 894 <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>"> 895 <fieldset> 896 <input type="hidden" name="do" value="register" /> 897 <input type="hidden" name="save" value="1" /> 898 899 <legend><?php echo $lang['register']?></legend> 900 <label class="block"> 901 <?php echo $lang['user']?> 902 <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" /> 903 </label><br /> 904 905 <?php 906 if (!$conf['autopasswd']) { 907 ?> 908 <label class="block"> 909 <?php echo $lang['pass']?> 910 <input type="password" name="pass" class="edit" size="50" /> 911 </label><br /> 912 <label class="block"> 913 <?php echo $lang['passchk']?> 914 <input type="password" name="passchk" class="edit" size="50" /> 915 </label><br /> 916 <?php 917 } 918 ?> 919 920 <label class="block"> 921 <?php echo $lang['fullname']?> 922 <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" /> 923 </label><br /> 924 <label class="block"> 925 <?php echo $lang['email']?> 926 <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" /> 927 </label><br /> 928 <input type="submit" class="button" value="<?php echo $lang['register']?>" /> 929 </fieldset> 930 </form> 931 </div> 932<?php 933} 934 935/** 936 * Print the update profile form 937 * 938 * @author Christopher Smith <chris@jalakai.co.uk> 939 * @author Andreas Gohr <andi@splitbrain.org> 940 */ 941function html_updateprofile(){ 942 global $lang; 943 global $conf; 944 global $ID; 945 global $INFO; 946 global $auth; 947 948 print p_locale_xhtml('updateprofile'); 949 950 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; 951 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; 952?> 953 <div class="centeralign"> 954 <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>"> 955 <fieldset style="width: 80%;"> 956 <input type="hidden" name="do" value="profile" /> 957 <input type="hidden" name="save" value="1" /> 958 959 <legend><?php echo $lang['profile']?></legend> 960 <label class="block"> 961 <?php echo $lang['user']?> 962 <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" /> 963 </label><br /> 964 <label class="block"> 965 <?php echo $lang['fullname']?> 966 <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" /> 967 </label><br /> 968 <label class="block"> 969 <?php echo $lang['email']?> 970 <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" /> 971 </label><br /><br /> 972 973 <?php if($auth->canDo('modPass')) { ?> 974 <label class="block"> 975 <?php echo $lang['newpass']?> 976 <input type="password" name="newpass" class="edit" size="50" /> 977 </label><br /> 978 <label class="block"> 979 <?php echo $lang['passchk']?> 980 <input type="password" name="passchk" class="edit" size="50" /> 981 </label><br /> 982 <?php } ?> 983 984 <?php if ($conf['profileconfirm']) { ?> 985 <br /> 986 <label class="block"> 987 <?php echo $lang['oldpass']?> 988 <input type="password" name="oldpass" class="edit" size="50" /> 989 </label><br /> 990 <?php } ?> 991 992 <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" /> 993 <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" /> 994 </fieldset> 995 </form> 996 </div> 997<?php 998} 999 1000/** 1001 * This displays the edit form (lots of logic included) 1002 * 1003 * @fixme this is a huge lump of code and should be modularized 1004 * @author Andreas Gohr <andi@splitbrain.org> 1005 */ 1006function html_edit($text=null,$include='edit'){ //FIXME: include needed? 1007 global $ID; 1008 global $REV; 1009 global $DATE; 1010 global $RANGE; 1011 global $PRE; 1012 global $SUF; 1013 global $INFO; 1014 global $SUM; 1015 global $lang; 1016 global $conf; 1017 1018 //set summary default 1019 if(!$SUM){ 1020 if($REV){ 1021 $SUM = $lang['restored']; 1022 }elseif(!$INFO['exists']){ 1023 $SUM = $lang['created']; 1024 } 1025 } 1026 1027 //no text? Load it! 1028 if(!isset($text)){ 1029 $pr = false; //no preview mode 1030 if($INFO['exists']){ 1031 if($RANGE){ 1032 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); 1033 }else{ 1034 $text = rawWiki($ID,$REV); 1035 } 1036 }else{ 1037 //try to load a pagetemplate 1038 $text = pageTemplate($ID); 1039 } 1040 }else{ 1041 $pr = true; //preview mode 1042 } 1043 1044 $wr = $INFO['writable']; 1045 if($wr){ 1046 if ($REV) print p_locale_xhtml('editrev'); 1047 print p_locale_xhtml($include); 1048 }else{ 1049 print p_locale_xhtml('read'); 1050 $ro='readonly="readonly"'; 1051 } 1052 if(!$DATE) $DATE = $INFO['lastmod']; 1053 1054 1055?> 1056 <div style="width:99%;"> 1057 1058 <div class="toolbar"> 1059 <div id="draft__status"><?php if($INFO['draft']) echo $lang['draftdate'].' '.date($conf['dformat']);?></div> 1060 <div id="tool__bar"><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1061 target="_blank"><?php echo $lang['mediaselect'] ?></a></div> 1062 1063 <?php if($wr){?> 1064 <script type="text/javascript" charset="utf-8"> 1065 <?php /* sets changed to true when previewed */?> 1066 textChanged = <?php ($pr) ? print 'true' : print 'false' ?>; 1067 </script> 1068 <span id="spell__action"></span> 1069 <div id="spell__suggest"></div> 1070 <?php } ?> 1071 </div> 1072 <div id="spell__result"></div> 1073 1074 1075 <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no"> 1076 <input type="hidden" name="id" value="<?php echo $ID?>" /> 1077 <input type="hidden" name="rev" value="<?php echo $REV?>" /> 1078 <input type="hidden" name="date" value="<?php echo $DATE?>" /> 1079 <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" /> 1080 <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" /> 1081 </div> 1082 1083 <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea> 1084 1085 <div id="wiki__editbar"> 1086 <div id="size__ctl"></div> 1087 <?php if($wr){?> 1088 <div class="editButtons"> 1089 <input class="button" id="edbtn__save" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" tabindex="4" /> 1090 <input class="button" id="edbtn__preview" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" tabindex="5" /> 1091 <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="6" /> 1092 </div> 1093 <?php } ?> 1094 <?php if($wr){ ?> 1095 <div class="summary"> 1096 <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label> 1097 <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" /> 1098 <?php html_minoredit()?> 1099 </div> 1100 <?php }?> 1101 </div> 1102 </form> 1103 </div> 1104<?php 1105} 1106 1107/** 1108 * Adds a checkbox for minor edits for logged in users 1109 * 1110 * @author Andrea Gohr <andi@splitbrain.org> 1111 */ 1112function html_minoredit(){ 1113 global $conf; 1114 global $lang; 1115 // minor edits are for logged in users only 1116 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1117 return; 1118 } 1119 1120 $p = array(); 1121 $p['name'] = 'minor'; 1122 $p['type'] = 'checkbox'; 1123 $p['id'] = 'minoredit'; 1124 $p['tabindex'] = 3; 1125 $p['value'] = '1'; 1126 if($_REQUEST['minor']) $p['checked']='checked'; 1127 $att = buildAttributes($p); 1128 1129 print '<span class="nowrap">'; 1130 print "<input $att />"; 1131 print '<label for="minoredit">'; 1132 print $lang['minoredit']; 1133 print '</label>'; 1134 print '</span>'; 1135} 1136 1137/** 1138 * prints some debug info 1139 * 1140 * @author Andreas Gohr <andi@splitbrain.org> 1141 */ 1142function html_debug(){ 1143 global $conf; 1144 global $lang; 1145 global $auth; 1146 //remove sensitive data 1147 $cnf = $conf; 1148 $cnf['auth']='***'; 1149 $cnf['notify']='***'; 1150 $cnf['ftp']='***'; 1151 1152 print '<html><body>'; 1153 1154 print '<p>When reporting bugs please send all the following '; 1155 print 'output as a mail to andi@splitbrain.org '; 1156 print 'The best way to do this is to save this page in your browser</p>'; 1157 1158 print '<b>$_SERVER:</b><pre>'; 1159 print_r($_SERVER); 1160 print '</pre>'; 1161 1162 print '<b>$conf:</b><pre>'; 1163 print_r($cnf); 1164 print '</pre>'; 1165 1166 print '<b>DOKU_BASE:</b><pre>'; 1167 print DOKU_BASE; 1168 print '</pre>'; 1169 1170 print '<b>abs DOKU_BASE:</b><pre>'; 1171 print DOKU_URL; 1172 print '</pre>'; 1173 1174 print '<b>rel DOKU_BASE:</b><pre>'; 1175 print dirname($_SERVER['PHP_SELF']).'/'; 1176 print '</pre>'; 1177 1178 print '<b>PHP Version:</b><pre>'; 1179 print phpversion(); 1180 print '</pre>'; 1181 1182 print '<b>locale:</b><pre>'; 1183 print setlocale(LC_ALL,0); 1184 print '</pre>'; 1185 1186 print '<b>encoding:</b><pre>'; 1187 print $lang['encoding']; 1188 print '</pre>'; 1189 1190 if($auth){ 1191 print '<b>Auth backend capabilities:</b><pre>'; 1192 print_r($auth->cando); 1193 print '</pre>'; 1194 } 1195 1196 print '<b>$_SESSION:</b><pre>'; 1197 print_r($_SESSION); 1198 print '</pre>'; 1199 1200 print '<b>Environment:</b><pre>'; 1201 print_r($_ENV); 1202 print '</pre>'; 1203 1204 print '<b>PHP settings:</b><pre>'; 1205 $inis = ini_get_all(); 1206 print_r($inis); 1207 print '</pre>'; 1208 1209 print '</body></html>'; 1210} 1211 1212function html_admin(){ 1213 global $ID; 1214 global $lang; 1215 global $conf; 1216 1217 print p_locale_xhtml('admin'); 1218 1219 // build menu of admin functions from the plugins that handle them 1220 $pluginlist = plugin_list('admin'); 1221 $menu = array(); 1222 foreach ($pluginlist as $p) { 1223 if($obj =& plugin_load('admin',$p) === NULL) continue; 1224 $menu[] = array('plugin' => $p, 1225 'prompt' => $obj->getMenuText($conf['lang']), 1226 'sort' => $obj->getMenuSort() 1227 ); 1228 } 1229 1230 usort($menu, p_sort_modes); 1231 1232 // output the menu 1233 ptln('<ul>'); 1234 1235 foreach ($menu as $item) { 1236 if (!$item['prompt']) continue; 1237 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1238 } 1239 1240 // add in non-plugin functions 1241 if (!$conf['openregister']){ 1242 ptln('<li><div class="li"><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></div></li>'); 1243 } 1244 1245 ptln('</ul>'); 1246} 1247 1248/** 1249 * Form to request a new password for an existing account 1250 * 1251 * @author Benoit Chesneau <benoit@bchesneau.info> 1252 */ 1253function html_resendpwd() { 1254 global $lang; 1255 global $conf; 1256 global $ID; 1257 1258 print p_locale_xhtml('resendpwd'); 1259?> 1260 <div class="centeralign"> 1261 <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post"> 1262 <fieldset> 1263 <br /> 1264 <legend><?php echo $lang['resendpwd']?></legend> 1265 <input type="hidden" name="do" value="resendpwd" /> 1266 <input type="hidden" name="save" value="1" /> 1267 <label class="block"> 1268 <span><?php echo $lang['user']?></span> 1269 <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br /> 1270 </label><br /> 1271 <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" /> 1272 </fieldset> 1273 </form> 1274 </div> 1275<?php 1276} 1277 1278//Setup VIM: ex: et ts=2 enc=utf-8 : 1279