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