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