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