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