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