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 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10if(!defined('NL')) define('NL',"\n"); 11require_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" id="dw__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[recover]" value="<?php echo $lang['btn_recover']?>" tabindex="1" /> 301 <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_draftdel']?>" tabindex="2" /> 302 <input class="button" type="submit" name="do[show]" 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">'.NL; 366 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 367 print 'showLoadBar();'.NL; 368 print '//--><!]]></script>'.NL; 369 print '<br /></div>'.NL; 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"><!--//--><![CDATA[//><!--'.NL; 414 print 'hideLoadBar("dw__loading");'.NL; 415 print '//--><!]]></script>'.NL; 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 ' – '; 482 print $INFO['sum']; 483 print ' <span class="user">'; 484 print $INFO['editor']; 485 print '</span> '; 486 487 print '('.$lang['current'].')'; 488 print '</div>'; 489 print '</li>'; 490 } 491 492 foreach($revisions as $rev){ 493 $date = date($conf['dformat'],$rev); 494 $info = getRevisionInfo($ID,$rev,true); 495 496 print ($info['type']==='e') ? '<li class="minor">' : '<li>'; 497 print '<div class="li">'; 498 print $date; 499 500 if(@file_exists(wikiFN($ID,$rev))){ 501 print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">'; 502 $p = array(); 503 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 504 $p['width'] = 15; 505 $p['height'] = 11; 506 $p['title'] = $lang['diff']; 507 $p['alt'] = $lang['diff']; 508 $att = buildAttributes($p); 509 print "<img $att />"; 510 print '</a> '; 511 512 print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>'; 513 }else{ 514 print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> '; 515 print $ID; 516 } 517 518 print ' – '; 519 print htmlspecialchars($info['sum']); 520 print ' <span class="user">'; 521 if($info['user']){ 522 print $info['user']; 523 }else{ 524 print $info['ip']; 525 } 526 print '</span>'; 527 528 print '</div>'; 529 print '</li>'; 530 } 531 print '</ul>'; 532 533 print '<div class="pagenav">'; 534 $last = $first + $conf['recent']; 535 if ($first > 0) { 536 $first -= $conf['recent']; 537 if ($first < 0) $first = 0; 538 print '<div class="pagenav-prev">'; 539 print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first)); 540 print '</div>'; 541 } 542 if ($hasNext) { 543 print '<div class="pagenav-next">'; 544 print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last)); 545 print '</div>'; 546 } 547 print '</div>'; 548 549} 550 551/** 552 * display recent changes 553 * 554 * @author Andreas Gohr <andi@splitbrain.org> 555 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 556 * @author Ben Coburn <btcoburn@silicodon.net> 557 */ 558function html_recent($first=0){ 559 global $conf; 560 global $lang; 561 global $ID; 562 /* we need to get one additionally log entry to be able to 563 * decide if this is the last page or is there another one. 564 * This is the cheapest solution to get this information. 565 */ 566 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 567 if(count($recents) == 0 && $first != 0){ 568 $first=0; 569 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 570 } 571 $hasNext = false; 572 if (count($recents)>$conf['recent']) { 573 $hasNext = true; 574 array_pop($recents); // remove extra log entry 575 } 576 577 print p_locale_xhtml('recent'); 578 print '<ul>'; 579 580 foreach($recents as $recent){ 581 $date = date($conf['dformat'],$recent['date']); 582 print ($recent['type']==='e') ? '<li class="minor">' : '<li>'; 583 print '<div class="li">'; 584 585 print $date.' '; 586 587 print '<a href="'.wl($recent['id'],"do=diff").'">'; 588 $p = array(); 589 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 590 $p['width'] = 15; 591 $p['height'] = 11; 592 $p['title'] = $lang['diff']; 593 $p['alt'] = $lang['diff']; 594 $att = buildAttributes($p); 595 print "<img $att />"; 596 print '</a> '; 597 598 print '<a href="'.wl($recent['id'],"do=revisions").'">'; 599 $p = array(); 600 $p['src'] = DOKU_BASE.'lib/images/history.png'; 601 $p['width'] = 12; 602 $p['height'] = 14; 603 $p['title'] = $lang['btn_revs']; 604 $p['alt'] = $lang['btn_revs']; 605 $att = buildAttributes($p); 606 print "<img $att />"; 607 print '</a> '; 608 609 print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']); 610 print ' – '.htmlspecialchars($recent['sum']); 611 612 print ' <span class="user">'; 613 if($recent['user']){ 614 print $recent['user']; 615 }else{ 616 print $recent['ip']; 617 } 618 print '</span>'; 619 620 print '</div>'; 621 print '</li>'; 622 } 623 print '</ul>'; 624 625 print '<div class="pagenav">'; 626 $last = $first + $conf['recent']; 627 if ($first > 0) { 628 $first -= $conf['recent']; 629 if ($first < 0) $first = 0; 630 print '<div class="pagenav-prev">'; 631 print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first)); 632 print '</div>'; 633 } 634 if ($hasNext) { 635 print '<div class="pagenav-next">'; 636 print html_btn('older','',"n",array('do' => 'recent', 'first' => $last)); 637 print '</div>'; 638 } 639 print '</div>'; 640} 641 642/** 643 * Display page index 644 * 645 * @author Andreas Gohr <andi@splitbrain.org> 646 */ 647function html_index($ns){ 648 require_once(DOKU_INC.'inc/search.php'); 649 global $conf; 650 global $ID; 651 $dir = $conf['datadir']; 652 $ns = cleanID($ns); 653 #fixme use appropriate function 654 if(empty($ns)){ 655 $ns = dirname(str_replace(':','/',$ID)); 656 if($ns == '.') $ns =''; 657 } 658 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 659 660 print p_locale_xhtml('index'); 661 662 $data = array(); 663 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 664 print html_buildlist($data,'idx','html_list_index','html_li_index'); 665} 666 667/** 668 * Index item formatter 669 * 670 * User function for html_buildlist() 671 * 672 * @author Andreas Gohr <andi@splitbrain.org> 673 */ 674function html_list_index($item){ 675 global $ID; 676 $ret = ''; 677 $base = ':'.$item['id']; 678 $base = substr($base,strrpos($base,':')+1); 679 if($item['type']=='d'){ 680 $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">'; 681 $ret .= $base; 682 $ret .= '</a>'; 683 }else{ 684 $ret .= html_wikilink(':'.$item['id']); 685 } 686 return $ret; 687} 688 689/** 690 * Index List item 691 * 692 * This user function is used in html_build_lidt to build the 693 * <li> tags for namespaces when displaying the page index 694 * it gives different classes to opened or closed "folders" 695 * 696 * @author Andreas Gohr <andi@splitbrain.org> 697 */ 698function html_li_index($item){ 699 if($item['type'] == "f"){ 700 return '<li class="level'.$item['level'].'">'; 701 }elseif($item['open']){ 702 return '<li class="open">'; 703 }else{ 704 return '<li class="closed">'; 705 } 706} 707 708/** 709 * Default List item 710 * 711 * @author Andreas Gohr <andi@splitbrain.org> 712 */ 713function html_li_default($item){ 714 return '<li class="level'.$item['level'].'">'; 715} 716 717/** 718 * Build an unordered list 719 * 720 * Build an unordered list from the given $data array 721 * Each item in the array has to have a 'level' property 722 * the item itself gets printed by the given $func user 723 * function. The second and optional function is used to 724 * print the <li> tag. Both user function need to accept 725 * a single item. 726 * 727 * Both user functions can be given as array to point to 728 * a member of an object. 729 * 730 * @author Andreas Gohr <andi@splitbrain.org> 731 */ 732function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 733 $level = 0; 734 $opens = 0; 735 $ret = ''; 736 737 foreach ($data as $item){ 738 739 if( $item['level'] > $level ){ 740 //open new list 741 for($i=0; $i<($item['level'] - $level); $i++){ 742 if ($i) $ret .= "<li class=\"clear\">\n"; 743 $ret .= "\n<ul class=\"$class\">\n"; 744 } 745 }elseif( $item['level'] < $level ){ 746 //close last item 747 $ret .= "</li>\n"; 748 for ($i=0; $i<($level - $item['level']); $i++){ 749 //close higher lists 750 $ret .= "</ul>\n</li>\n"; 751 } 752 }else{ 753 //close last item 754 $ret .= "</li>\n"; 755 } 756 757 //remember current level 758 $level = $item['level']; 759 760 //print item 761 if(is_array($lifunc)){ 762 $ret .= $lifunc[0]->$lifunc[1]($item); //user object method 763 }else{ 764 $ret .= $lifunc($item); //user function 765 } 766 $ret .= '<div class="li">'; 767 if(is_array($func)){ 768 $ret .= $func[0]->$func[1]($item); //user object method 769 }else{ 770 $ret .= $func($item); //user function 771 } 772 $ret .= '</div>'; 773 } 774 775 //close remaining items and lists 776 for ($i=0; $i < $level; $i++){ 777 $ret .= "</li></ul>\n"; 778 } 779 780 return $ret; 781} 782 783/** 784 * display backlinks 785 * 786 * @author Andreas Gohr <andi@splitbrain.org> 787 */ 788function html_backlinks(){ 789 require_once(DOKU_INC.'inc/fulltext.php'); 790 global $ID; 791 global $conf; 792 793 print p_locale_xhtml('backlinks'); 794 795 $data = ft_backlinks($ID); 796 797 print '<ul class="idx">'; 798 foreach($data as $blink){ 799 print '<li><div class="li">'; 800 print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink); 801 print '</div></li>'; 802 } 803 print '</ul>'; 804} 805 806/** 807 * show diff 808 * 809 * @author Andreas Gohr <andi@splitbrain.org> 810 */ 811function html_diff($text='',$intro=true){ 812 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 813 global $ID; 814 global $REV; 815 global $lang; 816 global $conf; 817 818 if($text){ 819 $df = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,''))), 820 explode("\n",htmlspecialchars(cleanText($text)))); 821 $left = '<a class="wikilink1" href="'.wl($ID).'">'. 822 $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'. 823 $lang['current']; 824 $right = $lang['yours']; 825 }else{ 826 //check if current revision exist 827 if(!@file_exists(wikiFN($ID))){ 828 $revs = getRevisions($ID, 0, 2); 829 $rc = $revs[1]; 830 } 831 if($REV){ 832 $r = $REV; 833 }else{ 834 if(empty($revs)){ 835 //use last revision if none given 836 $revs = getRevisions($ID, 0, 1); 837 } 838 $r = $revs[0]; 839 } 840 841 if($r){ 842 $df = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,$r))), 843 explode("\n",htmlspecialchars(rawWiki($ID,'')))); 844 $left = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'. 845 $ID.' '.date($conf['dformat'],(isset($rc) ? $rc : $r)).'</a>'; 846 }else{ 847 $df = new Diff(array(''), 848 explode("\n",htmlspecialchars(rawWiki($ID,'')))); 849 $left = '<a class="wikilink1" href="'.wl($ID).'">'. 850 $ID.'</a>'; 851 } 852 $right = '<a class="wikilink1" href="'.wl($ID).'">'. 853 $ID.' '.date($conf['dformat'],(isset($rc) ? $r : @filemtime(wikiFN($ID)))).'</a> '. 854 $lang['current']; 855 } 856 $tdf = new TableDiffFormatter(); 857 if($intro) print p_locale_xhtml('diff'); 858 ?> 859 <table class="diff"> 860 <tr> 861 <th colspan="2"> 862 <?php echo $left?> 863 </th> 864 <th colspan="2"> 865 <?php echo $right?> 866 </th> 867 </tr> 868 <?php echo $tdf->format($df)?> 869 </table> 870 <?php 871} 872 873/** 874 * show warning on conflict detection 875 * 876 * @author Andreas Gohr <andi@splitbrain.org> 877 */ 878function html_conflict($text,$summary){ 879 global $ID; 880 global $lang; 881 882 print p_locale_xhtml('conflict'); 883 ?> 884 <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"> 885 <div class="centeralign"> 886 <input type="hidden" name="id" value="<?php echo $ID?>" /> 887 <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" /> 888 <input type="hidden" name="summary" value="<?php echo formText($summary)?>" /> 889 890 <input class="button" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" /> 891 <input class="button" type="submit" name="do[cancel]" value="<?php echo $lang['btn_cancel']?>" /> 892 </div> 893 </form> 894 <br /><br /><br /><br /> 895 <?php 896} 897 898/** 899 * Prints the global message array 900 * 901 * @author Andreas Gohr <andi@splitbrain.org> 902 */ 903function html_msgarea(){ 904 global $MSG; 905 906 if(!isset($MSG)) return; 907 908 foreach($MSG as $msg){ 909 print '<div class="'.$msg['lvl'].'">'; 910 print $msg['msg']; 911 print '</div>'; 912 } 913} 914 915/** 916 * Prints the registration form 917 * 918 * @author Andreas Gohr <andi@splitbrain.org> 919 * @triggers HTML_REGISTERFORM_INJECTION 920 */ 921function html_register(){ 922 global $lang; 923 global $conf; 924 global $ID; 925 926 print p_locale_xhtml('register'); 927?> 928 <div class="centeralign"> 929 <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>"> 930 <fieldset> 931 <input type="hidden" name="do" value="register" /> 932 <input type="hidden" name="save" value="1" /> 933 934 <legend><?php echo $lang['register']?></legend> 935 <label class="block"> 936 <?php echo $lang['user']?> 937 <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" /> 938 </label><br /> 939 940 <?php 941 if (!$conf['autopasswd']) { 942 ?> 943 <label class="block"> 944 <?php echo $lang['pass']?> 945 <input type="password" name="pass" class="edit" size="50" /> 946 </label><br /> 947 <label class="block"> 948 <?php echo $lang['passchk']?> 949 <input type="password" name="passchk" class="edit" size="50" /> 950 </label><br /> 951 <?php 952 } 953 ?> 954 955 <label class="block"> 956 <?php echo $lang['fullname']?> 957 <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" /> 958 </label><br /> 959 <label class="block"> 960 <?php echo $lang['email']?> 961 <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" /> 962 </label><br /> 963 <?php //bad and dirty event insert hook 964 $evdata = array(); 965 trigger_event('HTML_REGISTERFORM_INJECTION', $evdata); 966 ?> 967 <input type="submit" class="button" value="<?php echo $lang['register']?>" /> 968 </fieldset> 969 </form> 970 </div> 971<?php 972} 973 974/** 975 * Print the update profile form 976 * 977 * @author Christopher Smith <chris@jalakai.co.uk> 978 * @author Andreas Gohr <andi@splitbrain.org> 979 */ 980function html_updateprofile(){ 981 global $lang; 982 global $conf; 983 global $ID; 984 global $INFO; 985 global $auth; 986 987 print p_locale_xhtml('updateprofile'); 988 989 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; 990 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; 991?> 992 <div class="centeralign"> 993 <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>"> 994 <fieldset style="width: 80%;"> 995 <input type="hidden" name="do" value="profile" /> 996 <input type="hidden" name="save" value="1" /> 997 998 <legend><?php echo $lang['profile']?></legend> 999 <label class="block"> 1000 <?php echo $lang['user']?> 1001 <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" /> 1002 </label><br /> 1003 <label class="block"> 1004 <?php echo $lang['fullname']?> 1005 <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" /> 1006 </label><br /> 1007 <label class="block"> 1008 <?php echo $lang['email']?> 1009 <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" /> 1010 </label><br /><br /> 1011 1012 <?php if($auth->canDo('modPass')) { ?> 1013 <label class="block"> 1014 <?php echo $lang['newpass']?> 1015 <input type="password" name="newpass" class="edit" size="50" /> 1016 </label><br /> 1017 <label class="block"> 1018 <?php echo $lang['passchk']?> 1019 <input type="password" name="passchk" class="edit" size="50" /> 1020 </label><br /> 1021 <?php } ?> 1022 1023 <?php if ($conf['profileconfirm']) { ?> 1024 <br /> 1025 <label class="block"> 1026 <?php echo $lang['oldpass']?> 1027 <input type="password" name="oldpass" class="edit" size="50" /> 1028 </label><br /> 1029 <?php } ?> 1030 1031 <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" /> 1032 <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" /> 1033 </fieldset> 1034 </form> 1035 </div> 1036<?php 1037} 1038 1039/** 1040 * This displays the edit form (lots of logic included) 1041 * 1042 * @fixme this is a huge lump of code and should be modularized 1043 * @triggers HTML_PAGE_FROMTEMPLATE 1044 * @triggers HTML_EDITFORM_INJECTION 1045 * @author Andreas Gohr <andi@splitbrain.org> 1046 */ 1047function html_edit($text=null,$include='edit'){ //FIXME: include needed? 1048 global $ID; 1049 global $REV; 1050 global $DATE; 1051 global $RANGE; 1052 global $PRE; 1053 global $SUF; 1054 global $INFO; 1055 global $SUM; 1056 global $lang; 1057 global $conf; 1058 1059 //set summary default 1060 if(!$SUM){ 1061 if($REV){ 1062 $SUM = $lang['restored']; 1063 }elseif(!$INFO['exists']){ 1064 $SUM = $lang['created']; 1065 } 1066 } 1067 1068 //no text? Load it! 1069 if(!isset($text)){ 1070 $pr = false; //no preview mode 1071 if($INFO['exists']){ 1072 if($RANGE){ 1073 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); 1074 }else{ 1075 $text = rawWiki($ID,$REV); 1076 } 1077 }else{ 1078 //try to load a pagetemplate 1079 $data = array($ID); 1080 $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); 1081 } 1082 }else{ 1083 $pr = true; //preview mode 1084 } 1085 1086 $wr = $INFO['writable']; 1087 if($wr){ 1088 if ($REV) print p_locale_xhtml('editrev'); 1089 print p_locale_xhtml($include); 1090 $ro=false; 1091 }else{ 1092 // check pseudo action 'source' 1093 if(!actionOK('source')){ 1094 msg('Command disabled: source',-1); 1095 return; 1096 } 1097 print p_locale_xhtml('read'); 1098 $ro='readonly="readonly"'; 1099 } 1100 if(!$DATE) $DATE = $INFO['lastmod']; 1101 1102 1103?> 1104 <div style="width:99%;"> 1105 1106 <div class="toolbar"> 1107 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.date($conf['dformat']);?></div> 1108 <div id="tool__bar"><?php if(!$ro){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1109 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1110 1111 <?php if($wr){?> 1112 <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!-- 1113 <?php /* sets changed to true when previewed */?> 1114 textChanged = <?php ($pr) ? print 'true' : print 'false' ?>; 1115 //--><!]]></script> 1116 <span id="spell__action"></span> 1117 <div id="spell__suggest"></div> 1118 <?php } ?> 1119 </div> 1120 <div id="spell__result"></div> 1121 1122 1123 <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no"> 1124 <input type="hidden" name="id" value="<?php echo $ID?>" /> 1125 <input type="hidden" name="rev" value="<?php echo $REV?>" /> 1126 <input type="hidden" name="date" value="<?php echo $DATE?>" /> 1127 <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" /> 1128 <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" /> 1129 </div> 1130 1131 <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea> 1132 1133 <?php //bad and dirty event insert hook 1134 $evdata = array('writable' => $wr); 1135 trigger_event('HTML_EDITFORM_INJECTION', $evdata); 1136 ?> 1137 1138 <div id="wiki__editbar"> 1139 <div id="size__ctl"></div> 1140 <?php if($wr){?> 1141 <div class="editButtons"> 1142 <input class="button" id="edbtn__save" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" tabindex="4" /> 1143 <input class="button" id="edbtn__preview" type="submit" name="do[preview]" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="<?php echo $lang['btn_preview']?> [ALT+P]" tabindex="5" /> 1144 <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="6" /> 1145 </div> 1146 <?php } ?> 1147 <?php if($wr){ ?> 1148 <div class="summary"> 1149 <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label> 1150 <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" /> 1151 <?php html_minoredit()?> 1152 </div> 1153 <?php }?> 1154 </div> 1155 </form> 1156 </div> 1157<?php 1158} 1159 1160/** 1161 * Adds a checkbox for minor edits for logged in users 1162 * 1163 * @author Andrea Gohr <andi@splitbrain.org> 1164 */ 1165function html_minoredit(){ 1166 global $conf; 1167 global $lang; 1168 // minor edits are for logged in users only 1169 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1170 return; 1171 } 1172 1173 $p = array(); 1174 $p['name'] = 'minor'; 1175 $p['type'] = 'checkbox'; 1176 $p['id'] = 'minoredit'; 1177 $p['tabindex'] = 3; 1178 $p['value'] = '1'; 1179 if(!empty($_REQUEST['minor'])) $p['checked']='checked'; 1180 $att = buildAttributes($p); 1181 1182 print '<span class="nowrap">'; 1183 print "<input $att />"; 1184 print '<label for="minoredit">'; 1185 print $lang['minoredit']; 1186 print '</label>'; 1187 print '</span>'; 1188} 1189 1190/** 1191 * prints some debug info 1192 * 1193 * @author Andreas Gohr <andi@splitbrain.org> 1194 */ 1195function html_debug(){ 1196 global $conf; 1197 global $lang; 1198 global $auth; 1199 global $INFO; 1200 1201 //remove sensitive data 1202 $cnf = $conf; 1203 $cnf['auth']='***'; 1204 $cnf['notify']='***'; 1205 $cnf['ftp']='***'; 1206 $nfo = $INFO; 1207 $nfo['userinfo'] = '***'; 1208 $ses = $_SESSION; 1209 $ses[$conf['title']]['auth'] = '***'; 1210 1211 print '<html><body>'; 1212 1213 print '<p>When reporting bugs please send all the following '; 1214 print 'output as a mail to andi@splitbrain.org '; 1215 print 'The best way to do this is to save this page in your browser</p>'; 1216 1217 print '<b>$INFO:</b><pre>'; 1218 print_r($nfo); 1219 print '</pre>'; 1220 1221 print '<b>$_SERVER:</b><pre>'; 1222 print_r($_SERVER); 1223 print '</pre>'; 1224 1225 print '<b>$conf:</b><pre>'; 1226 print_r($cnf); 1227 print '</pre>'; 1228 1229 print '<b>DOKU_BASE:</b><pre>'; 1230 print DOKU_BASE; 1231 print '</pre>'; 1232 1233 print '<b>abs DOKU_BASE:</b><pre>'; 1234 print DOKU_URL; 1235 print '</pre>'; 1236 1237 print '<b>rel DOKU_BASE:</b><pre>'; 1238 print dirname($_SERVER['PHP_SELF']).'/'; 1239 print '</pre>'; 1240 1241 print '<b>PHP Version:</b><pre>'; 1242 print phpversion(); 1243 print '</pre>'; 1244 1245 print '<b>locale:</b><pre>'; 1246 print setlocale(LC_ALL,0); 1247 print '</pre>'; 1248 1249 print '<b>encoding:</b><pre>'; 1250 print $lang['encoding']; 1251 print '</pre>'; 1252 1253 if($auth){ 1254 print '<b>Auth backend capabilities:</b><pre>'; 1255 print_r($auth->cando); 1256 print '</pre>'; 1257 } 1258 1259 print '<b>$_SESSION:</b><pre>'; 1260 print_r($ses); 1261 print '</pre>'; 1262 1263 print '<b>Environment:</b><pre>'; 1264 print_r($_ENV); 1265 print '</pre>'; 1266 1267 print '<b>PHP settings:</b><pre>'; 1268 $inis = ini_get_all(); 1269 print_r($inis); 1270 print '</pre>'; 1271 1272 print '</body></html>'; 1273} 1274 1275function html_admin(){ 1276 global $ID; 1277 global $INFO; 1278 global $lang; 1279 global $conf; 1280 1281 print p_locale_xhtml('admin'); 1282 1283 // build menu of admin functions from the plugins that handle them 1284 $pluginlist = plugin_list('admin'); 1285 $menu = array(); 1286 foreach ($pluginlist as $p) { 1287 if($obj =& plugin_load('admin',$p) === NULL) continue; 1288 1289 // check permissions 1290 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1291 1292 $menu[] = array('plugin' => $p, 1293 'prompt' => $obj->getMenuText($conf['lang']), 1294 'sort' => $obj->getMenuSort() 1295 ); 1296 } 1297 1298 usort($menu, 'p_sort_modes'); 1299 1300 // output the menu 1301 ptln('<ul>'); 1302 1303 foreach ($menu as $item) { 1304 if (!$item['prompt']) continue; 1305 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1306 } 1307 1308 ptln('</ul>'); 1309} 1310 1311/** 1312 * Form to request a new password for an existing account 1313 * 1314 * @author Benoit Chesneau <benoit@bchesneau.info> 1315 */ 1316function html_resendpwd() { 1317 global $lang; 1318 global $conf; 1319 global $ID; 1320 1321 print p_locale_xhtml('resendpwd'); 1322?> 1323 <div class="centeralign"> 1324 <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post"> 1325 <fieldset> 1326 <br /> 1327 <legend><?php echo $lang['resendpwd']?></legend> 1328 <input type="hidden" name="do" value="resendpwd" /> 1329 <input type="hidden" name="save" value="1" /> 1330 <label class="block"> 1331 <span><?php echo $lang['user']?></span> 1332 <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br /> 1333 </label><br /> 1334 <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" /> 1335 </fieldset> 1336 </form> 1337 </div> 1338<?php 1339} 1340 1341//Setup VIM: ex: et ts=2 enc=utf-8 : 1342