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