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