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