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