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