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