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 < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only 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) $include = 'editrev'; 1187 }else{ 1188 // check pseudo action 'source' 1189 if(!actionOK('source')){ 1190 msg('Command disabled: source',-1); 1191 return; 1192 } 1193 $include = 'read'; 1194 } 1195 if(!$DATE) $DATE = $INFO['lastmod']; 1196 1197 global $license; 1198 1199 $form = new Doku_Form(array('id' => 'dw__editform')); 1200 $form->addHidden('id', $ID); 1201 $form->addHidden('rev', $REV); 1202 $form->addHidden('date', $DATE); 1203 $form->addHidden('prefix', $PRE); 1204 $form->addHidden('suffix', $SUF); 1205 $form->addHidden('changecheck', $check); 1206 1207 $data = compact('wr', 'text', 'form'); 1208 $data['media_manager'] = true; 1209 $data['intro_locale'] = $include; 1210 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1211 if (isset($data['intro_locale'])) { 1212 echo p_locale_xhtml($data['intro_locale']); 1213 } 1214 1215 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); 1216 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1217 $form->addElement(form_makeCloseTag('div')); 1218 if ($wr) { 1219 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1220 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1221 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1222 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1223 $form->addElement(form_makeCloseTag('div')); 1224 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1225 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1226 $elem = html_minoredit(); 1227 if ($elem) $form->addElement($elem); 1228 $form->addElement(form_makeCloseTag('div')); 1229 } 1230 $form->addElement(form_makeCloseTag('div')); 1231 if($wr && $conf['license']){ 1232 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1233 $out = $lang['licenseok']; 1234 $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1235 if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"'; 1236 $out .= '> '.$license[$conf['license']]['name'].'</a>'; 1237 $form->addElement($out); 1238 $form->addElement(form_makeCloseTag('div')); 1239 } 1240 1241 if ($wr) { 1242 // sets changed to true when previewed 1243 echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'; 1244 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1245 echo '//--><!]]></script>'; 1246 } ?> 1247 <div style="width:99%;"> 1248 1249 <div class="toolbar"> 1250 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1251 <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']?>" 1252 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1253 1254 </div> 1255 <?php 1256 1257 html_form('edit', $form); 1258 print '</div>'.NL; 1259} 1260 1261/** 1262 * Display the default edit form 1263 * 1264 * Is the default action for HTML_EDIT_FORMSELECTION. 1265 * 1266 * @triggers HTML_EDITFORM_OUTPUT 1267 */ 1268function html_edit_form($param) { 1269 extract($param); 1270 $attr = array('tabindex'=>'1'); 1271 if (!$wr) $attr['readonly'] = 'readonly'; 1272 $form->addElement(form_makeWikiText($text, $attr)); 1273} 1274 1275/** 1276 * Adds a checkbox for minor edits for logged in users 1277 * 1278 * @author Andreas Gohr <andi@splitbrain.org> 1279 */ 1280function html_minoredit(){ 1281 global $conf; 1282 global $lang; 1283 // minor edits are for logged in users only 1284 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1285 return false; 1286 } 1287 1288 $p = array(); 1289 $p['tabindex'] = 3; 1290 if(!empty($_REQUEST['minor'])) $p['checked']='checked'; 1291 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1292} 1293 1294/** 1295 * prints some debug info 1296 * 1297 * @author Andreas Gohr <andi@splitbrain.org> 1298 */ 1299function html_debug(){ 1300 global $conf; 1301 global $lang; 1302 global $auth; 1303 global $INFO; 1304 1305 //remove sensitive data 1306 $cnf = $conf; 1307 debug_guard($cnf); 1308 $nfo = $INFO; 1309 debug_guard($nfo); 1310 $ses = $_SESSION; 1311 debug_guard($ses); 1312 1313 print '<html><body>'; 1314 1315 print '<p>When reporting bugs please send all the following '; 1316 print 'output as a mail to andi@splitbrain.org '; 1317 print 'The best way to do this is to save this page in your browser</p>'; 1318 1319 print '<b>$INFO:</b><pre>'; 1320 print_r($nfo); 1321 print '</pre>'; 1322 1323 print '<b>$_SERVER:</b><pre>'; 1324 print_r($_SERVER); 1325 print '</pre>'; 1326 1327 print '<b>$conf:</b><pre>'; 1328 print_r($cnf); 1329 print '</pre>'; 1330 1331 print '<b>DOKU_BASE:</b><pre>'; 1332 print DOKU_BASE; 1333 print '</pre>'; 1334 1335 print '<b>abs DOKU_BASE:</b><pre>'; 1336 print DOKU_URL; 1337 print '</pre>'; 1338 1339 print '<b>rel DOKU_BASE:</b><pre>'; 1340 print dirname($_SERVER['PHP_SELF']).'/'; 1341 print '</pre>'; 1342 1343 print '<b>PHP Version:</b><pre>'; 1344 print phpversion(); 1345 print '</pre>'; 1346 1347 print '<b>locale:</b><pre>'; 1348 print setlocale(LC_ALL,0); 1349 print '</pre>'; 1350 1351 print '<b>encoding:</b><pre>'; 1352 print $lang['encoding']; 1353 print '</pre>'; 1354 1355 if($auth){ 1356 print '<b>Auth backend capabilities:</b><pre>'; 1357 print_r($auth->cando); 1358 print '</pre>'; 1359 } 1360 1361 print '<b>$_SESSION:</b><pre>'; 1362 print_r($ses); 1363 print '</pre>'; 1364 1365 print '<b>Environment:</b><pre>'; 1366 print_r($_ENV); 1367 print '</pre>'; 1368 1369 print '<b>PHP settings:</b><pre>'; 1370 $inis = ini_get_all(); 1371 print_r($inis); 1372 print '</pre>'; 1373 1374 print '</body></html>'; 1375} 1376 1377/** 1378 * List available Administration Tasks 1379 * 1380 * @author Andreas Gohr <andi@splitbrain.org> 1381 * @author Håkan Sandell <hakan.sandell@home.se> 1382 */ 1383function html_admin(){ 1384 global $ID; 1385 global $INFO; 1386 global $lang; 1387 global $conf; 1388 global $auth; 1389 1390 // build menu of admin functions from the plugins that handle them 1391 $pluginlist = plugin_list('admin'); 1392 $menu = array(); 1393 foreach ($pluginlist as $p) { 1394 if($obj =& plugin_load('admin',$p) === null) continue; 1395 1396 // check permissions 1397 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1398 1399 $menu[$p] = array('plugin' => $p, 1400 'prompt' => $obj->getMenuText($conf['lang']), 1401 'sort' => $obj->getMenuSort() 1402 ); 1403 } 1404 1405 print p_locale_xhtml('admin'); 1406 1407 // Admin Tasks 1408 if($INFO['isadmin']){ 1409 ptln('<ul class="admin_tasks">'); 1410 1411 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 1412 ptln(' <li class="admin_usermanager"><div class="li">'. 1413 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 1414 $menu['usermanager']['prompt'].'</a></div></li>'); 1415 } 1416 unset($menu['usermanager']); 1417 1418 if($menu['acl']){ 1419 ptln(' <li class="admin_acl"><div class="li">'. 1420 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 1421 $menu['acl']['prompt'].'</a></div></li>'); 1422 } 1423 unset($menu['acl']); 1424 1425 if($menu['plugin']){ 1426 ptln(' <li class="admin_plugin"><div class="li">'. 1427 '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'. 1428 $menu['plugin']['prompt'].'</a></div></li>'); 1429 } 1430 unset($menu['plugin']); 1431 1432 if($menu['config']){ 1433 ptln(' <li class="admin_config"><div class="li">'. 1434 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 1435 $menu['config']['prompt'].'</a></div></li>'); 1436 } 1437 unset($menu['config']); 1438 } 1439 ptln('</ul>'); 1440 1441 // Manager Tasks 1442 ptln('<ul class="admin_tasks">'); 1443 1444 if($menu['revert']){ 1445 ptln(' <li class="admin_revert"><div class="li">'. 1446 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 1447 $menu['revert']['prompt'].'</a></div></li>'); 1448 } 1449 unset($menu['revert']); 1450 1451 if($menu['popularity']){ 1452 ptln(' <li class="admin_popularity"><div class="li">'. 1453 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 1454 $menu['popularity']['prompt'].'</a></div></li>'); 1455 } 1456 unset($menu['popularity']); 1457 1458 ptln('</ul>'); 1459 1460 // print the rest as sorted list 1461 if(count($menu)){ 1462 usort($menu, 'p_sort_modes'); 1463 // output the menu 1464 ptln('<div class="clearer"></div>'); 1465 print p_locale_xhtml('adminplugins'); 1466 ptln('<ul>'); 1467 foreach ($menu as $item) { 1468 if (!$item['prompt']) continue; 1469 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1470 } 1471 ptln('</ul>'); 1472 } 1473} 1474 1475/** 1476 * Form to request a new password for an existing account 1477 * 1478 * @author Benoit Chesneau <benoit@bchesneau.info> 1479 */ 1480function html_resendpwd() { 1481 global $lang; 1482 global $conf; 1483 global $ID; 1484 1485 print p_locale_xhtml('resendpwd'); 1486 print '<div class="centeralign">'.NL; 1487 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1488 $form->startFieldset($lang['resendpwd']); 1489 $form->addHidden('do', 'resendpwd'); 1490 $form->addHidden('save', '1'); 1491 $form->addElement(form_makeTag('br')); 1492 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block')); 1493 $form->addElement(form_makeTag('br')); 1494 $form->addElement(form_makeTag('br')); 1495 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1496 $form->endFieldset(); 1497 html_form('resendpwd', $form); 1498 print '</div>'.NL; 1499} 1500 1501/** 1502 * Return the TOC rendered to XHTML 1503 * 1504 * @author Andreas Gohr <andi@splitbrain.org> 1505 */ 1506function html_TOC($toc){ 1507 if(!count($toc)) return ''; 1508 global $lang; 1509 $out = '<!-- TOC START -->'.DOKU_LF; 1510 $out .= '<div class="toc">'.DOKU_LF; 1511 $out .= '<div class="tocheader toctoggle" id="toc__header">'; 1512 $out .= $lang['toc']; 1513 $out .= '</div>'.DOKU_LF; 1514 $out .= '<div id="toc__inside">'.DOKU_LF; 1515 $out .= html_buildlist($toc,'toc','html_list_toc'); 1516 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1517 $out .= '<!-- TOC END -->'.DOKU_LF; 1518 return $out; 1519} 1520 1521/** 1522 * Callback for html_buildlist 1523 */ 1524function html_list_toc($item){ 1525 if(isset($item['hid'])){ 1526 $link = '#'.$item['hid']; 1527 }else{ 1528 $link = $item['link']; 1529 } 1530 1531 return '<span class="li"><a href="'.$link.'" class="toc">'. 1532 hsc($item['title']).'</a></span>'; 1533} 1534 1535/** 1536 * Helper function to build TOC items 1537 * 1538 * Returns an array ready to be added to a TOC array 1539 * 1540 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1541 * @param string $text - what to display in the TOC 1542 * @param int $level - nesting level 1543 * @param string $hash - is prepended to the given $link, set blank if you want full links 1544 */ 1545function html_mktocitem($link, $text, $level, $hash='#'){ 1546 global $conf; 1547 return array( 'link' => $hash.$link, 1548 'title' => $text, 1549 'type' => 'ul', 1550 'level' => $level); 1551} 1552 1553/** 1554 * Output a Doku_Form object. 1555 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1556 * 1557 * @author Tom N Harris <tnharris@whoopdedo.org> 1558 */ 1559function html_form($name, &$form) { 1560 // Safety check in case the caller forgets. 1561 $form->endFieldset(); 1562 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1563} 1564 1565/** 1566 * Form print function. 1567 * Just calls printForm() on the data object. 1568 */ 1569function html_form_output($data) { 1570 $data->printForm(); 1571} 1572 1573/** 1574 * Embed a flash object in HTML 1575 * 1576 * This will create the needed HTML to embed a flash movie in a cross browser 1577 * compatble way using valid XHTML 1578 * 1579 * The parameters $params, $flashvars and $atts need to be associative arrays. 1580 * No escaping needs to be done for them. The alternative content *has* to be 1581 * escaped because it is used as is. If no alternative content is given 1582 * $lang['noflash'] is used. 1583 * 1584 * @author Andreas Gohr <andi@splitbrain.org> 1585 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 1586 * 1587 * @param string $swf - the SWF movie to embed 1588 * @param int $width - width of the flash movie in pixels 1589 * @param int $height - height of the flash movie in pixels 1590 * @param array $params - additional parameters (<param>) 1591 * @param array $flashvars - parameters to be passed in the flashvar parameter 1592 * @param array $atts - additional attributes for the <object> tag 1593 * @param string $alt - alternative content (is NOT automatically escaped!) 1594 * @returns string - the XHTML markup 1595 */ 1596function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 1597 global $lang; 1598 1599 $out = ''; 1600 1601 // prepare the object attributes 1602 if(is_null($atts)) $atts = array(); 1603 $atts['width'] = (int) $width; 1604 $atts['height'] = (int) $height; 1605 if(!$atts['width']) $atts['width'] = 425; 1606 if(!$atts['height']) $atts['height'] = 350; 1607 1608 // add object attributes for standard compliant browsers 1609 $std = $atts; 1610 $std['type'] = 'application/x-shockwave-flash'; 1611 $std['data'] = $swf; 1612 1613 // add object attributes for IE 1614 $ie = $atts; 1615 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 1616 1617 // open object (with conditional comments) 1618 $out .= '<!--[if !IE]> -->'.NL; 1619 $out .= '<object '.buildAttributes($std).'>'.NL; 1620 $out .= '<!-- <![endif]-->'.NL; 1621 $out .= '<!--[if IE]>'.NL; 1622 $out .= '<object '.buildAttributes($ie).'>'.NL; 1623 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 1624 $out .= '<!--><!-- -->'.NL; 1625 1626 // print params 1627 if(is_array($params)) foreach($params as $key => $val){ 1628 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 1629 } 1630 1631 // add flashvars 1632 if(is_array($flashvars)){ 1633 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 1634 } 1635 1636 // alternative content 1637 if($alt){ 1638 $out .= $alt.NL; 1639 }else{ 1640 $out .= $lang['noflash'].NL; 1641 } 1642 1643 // finish 1644 $out .= '</object>'.NL; 1645 $out .= '<!-- <![endif]-->'.NL; 1646 1647 return $out; 1648} 1649 1650