1<?php 2/** 3 * HTML output functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9if(!defined('DOKU_INC')) die('meh.'); 10if(!defined('NL')) define('NL',"\n"); 11 12/** 13 * Convenience function to quickly build a wikilink 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 */ 17function html_wikilink($id,$name=null,$search=''){ 18 static $xhtml_renderer = null; 19 if(is_null($xhtml_renderer)){ 20 $xhtml_renderer = p_get_renderer('xhtml'); 21 } 22 23 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); 24} 25 26/** 27 * Helps building long attribute lists 28 * 29 * @author Andreas Gohr <andi@splitbrain.org> 30 */ 31function html_attbuild($attributes){ 32 $ret = ''; 33 foreach ( $attributes as $key => $value ) { 34 $ret .= $key.'="'.formText($value).'" '; 35 } 36 return trim($ret); 37} 38 39/** 40 * The loginform 41 * 42 * @author Andreas Gohr <andi@splitbrain.org> 43 */ 44function html_login(){ 45 global $lang; 46 global $conf; 47 global $ID; 48 global $auth; 49 50 print p_locale_xhtml('login'); 51 print '<div class="centeralign">'.NL; 52 $form = new Doku_Form(array('id' => 'dw__login')); 53 $form->startFieldset($lang['btn_login']); 54 $form->addHidden('id', $ID); 55 $form->addHidden('do', 'login'); 56 $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block')); 57 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); 58 if($conf['rememberme']) { 59 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); 60 } 61 $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); 62 $form->endFieldset(); 63 64 if($auth && $auth->canDo('addUser') && actionOK('register')){ 65 $form->addElement('<p>' 66 . $lang['reghere'] 67 . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>' 68 . '</p>'); 69 } 70 71 if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) { 72 $form->addElement('<p>' 73 . $lang['pwdforget'] 74 . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>' 75 . '</p>'); 76 } 77 78 html_form('login', $form); 79 print '</div>'.NL; 80} 81 82/** 83 * prints a section editing button 84 * used as a callback in html_secedit 85 * 86 * @author Andreas Gohr <andi@splitbrain.org> 87 */ 88function html_secedit_button($matches){ 89 global $ID; 90 global $INFO; 91 92 $edittarget = ($matches[1] === 'SECTION') ? 'plain' : 93 strtolower($matches[1]); 94 95 $section = $matches[3]; 96 $name = $matches[2]; 97 98 $secedit = ''; 99 $secedit .= '<div class="secedit editbutton_' . $edittarget . '">'; 100 $secedit .= html_btn('secedit',$ID,'', 101 array('do' => 'edit', 102 'lines' => $section, 103 'edittarget' => $edittarget, 104 'rev' => $INFO['lastmod']), 105 'post', $name); 106 $secedit .= '</div>'; 107 return $secedit; 108} 109 110/** 111 * inserts section edit buttons if wanted or removes the markers 112 * 113 * @author Andreas Gohr <andi@splitbrain.org> 114 */ 115function html_secedit($text,$show=true){ 116 global $INFO; 117 118 $regexp = '#<!-- ([A-Z]+) (?:"(.*)" )?\[(\d+-\d*)\] -->#'; 119 120 if($INFO['writable'] && $show && !$INFO['rev']){ 121 $text = preg_replace_callback($regexp, 122 'html_secedit_button', $text); 123 }else{ 124 $text = preg_replace($regexp,'',$text); 125 } 126 127 return $text; 128} 129 130/** 131 * Just the back to top button (in its own form) 132 * 133 * @author Andreas Gohr <andi@splitbrain.org> 134 */ 135function html_topbtn(){ 136 global $lang; 137 138 $ret = ''; 139 $ret = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>'; 140 141 return $ret; 142} 143 144/** 145 * Displays a button (using its own form) 146 * If tooltip exists, the access key tooltip is replaced. 147 * 148 * @author Andreas Gohr <andi@splitbrain.org> 149 */ 150function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){ 151 global $conf; 152 global $lang; 153 154 $label = $lang['btn_'.$name]; 155 156 $ret = ''; 157 $tip = ''; 158 159 //filter id (without urlencoding) 160 $id = idfilter($id,false); 161 162 //make nice URLs even for buttons 163 if($conf['userewrite'] == 2){ 164 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 165 }elseif($conf['userewrite']){ 166 $script = DOKU_BASE.$id; 167 }else{ 168 $script = DOKU_BASE.DOKU_SCRIPT; 169 $params['id'] = $id; 170 } 171 172 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 173 174 if(is_array($params)){ 175 reset($params); 176 while (list($key, $val) = each($params)) { 177 $ret .= '<input type="hidden" name="'.$key.'" '; 178 $ret .= 'value="'.htmlspecialchars($val).'" />'; 179 } 180 } 181 182 if ($tooltip!='') { 183 $tip = htmlspecialchars($tooltip); 184 }else{ 185 $tip = htmlspecialchars($label); 186 } 187 188 $ret .= '<input type="submit" value="'.hsc($label).'" class="button" '; 189 if($akey){ 190 $tip .= ' ['.strtoupper($akey).']'; 191 $ret .= 'accesskey="'.$akey.'" '; 192 } 193 $ret .= 'title="'.$tip.'" '; 194 $ret .= '/>'; 195 $ret .= '</div></form>'; 196 197 return $ret; 198} 199 200/** 201 * show a wiki page 202 * 203 * @author Andreas Gohr <andi@splitbrain.org> 204 */ 205function html_show($txt=''){ 206 global $ID; 207 global $REV; 208 global $HIGH; 209 global $INFO; 210 //disable section editing for old revisions or in preview 211 if($txt || $REV){ 212 $secedit = false; 213 }else{ 214 $secedit = true; 215 } 216 217 if ($txt){ 218 //PreviewHeader 219 echo '<br id="scroll__here" />'; 220 echo p_locale_xhtml('preview'); 221 echo '<div class="preview">'; 222 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 223 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 224 echo $html; 225 echo '<div class="clearer"></div>'; 226 echo '</div>'; 227 228 }else{ 229 if ($REV) print p_locale_xhtml('showrev'); 230 $html = p_wiki_xhtml($ID,$REV,true); 231 $html = html_secedit($html,$secedit); 232 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 233 $html = html_hilight($html,$HIGH); 234 echo $html; 235 } 236} 237 238/** 239 * ask the user about how to handle an exisiting draft 240 * 241 * @author Andreas Gohr <andi@splitbrain.org> 242 */ 243function html_draft(){ 244 global $INFO; 245 global $ID; 246 global $lang; 247 global $conf; 248 $draft = unserialize(io_readFile($INFO['draft'],false)); 249 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 250 251 print p_locale_xhtml('draft'); 252 $form = new Doku_Form(array('id' => 'dw__editform')); 253 $form->addHidden('id', $ID); 254 $form->addHidden('date', $draft['date']); 255 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); 256 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 257 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft']))); 258 $form->addElement(form_makeCloseTag('div')); 259 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 260 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 261 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 262 html_form('draft', $form); 263} 264 265/** 266 * Highlights searchqueries in HTML code 267 * 268 * @author Andreas Gohr <andi@splitbrain.org> 269 * @author Harry Fuecks <hfuecks@gmail.com> 270 */ 271function html_hilight($html,$phrases){ 272 $phrases = array_filter((array) $phrases); 273 $regex = join('|',array_map('preg_quote_cb',$phrases)); 274 275 if ($regex === '') return $html; 276 $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 277 return $html; 278} 279 280/** 281 * Callback used by html_hilight() 282 * 283 * @author Harry Fuecks <hfuecks@gmail.com> 284 */ 285function html_hilight_callback($m) { 286 $hlight = unslash($m[0]); 287 if ( !isset($m[2])) { 288 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 289 } 290 return $hlight; 291} 292 293/** 294 * Run a search and display the result 295 * 296 * @author Andreas Gohr <andi@splitbrain.org> 297 */ 298function html_search(){ 299 require_once(DOKU_INC.'inc/search.php'); 300 require_once(DOKU_INC.'inc/fulltext.php'); 301 global $conf; 302 global $QUERY; 303 global $ID; 304 global $lang; 305 306 print p_locale_xhtml('searchpage'); 307 flush(); 308 309 //check if search is restricted to namespace 310 if(preg_match('/@([^@]*)/',$QUERY,$match)) { 311 $id = cleanID($match[1]); 312 } else { 313 $id = cleanID($QUERY); 314 } 315 316 //show progressbar 317 print '<div class="centeralign" id="dw__loading">'.NL; 318 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 319 print 'showLoadBar();'.NL; 320 print '//--><!]]></script>'.NL; 321 print '<br /></div>'.NL; 322 flush(); 323 324 //do quick pagesearch 325 $data = array(); 326 327 if($id) $data = ft_pageLookup($id); 328 if(count($data)){ 329 print '<div class="search_quickresult">'; 330 print '<h3>'.$lang['quickhits'].':</h3>'; 331 print '<ul class="search_quickhits">'; 332 foreach($data as $id){ 333 print '<li> '; 334 $ns = getNS($id); 335 if($ns){ 336 $name = shorten(noNS($id), ' ('.$ns.')',30); 337 }else{ 338 $name = $id; 339 } 340 print html_wikilink(':'.$id,$name); 341 print '</li> '; 342 } 343 print '</ul> '; 344 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 345 print '<div class="clearer"> </div>'; 346 print '</div>'; 347 } 348 flush(); 349 350 //do fulltext search 351 $data = ft_pageSearch($QUERY,$regex); 352 if(count($data)){ 353 $num = 1; 354 foreach($data as $id => $cnt){ 355 print '<div class="search_result">'; 356 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex); 357 if($cnt !== 0){ 358 print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />'; 359 if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ? 360 print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>'; 361 } 362 $num++; 363 } 364 print '</div>'; 365 flush(); 366 } 367 }else{ 368 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 369 } 370 371 //hide progressbar 372 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 373 print 'hideLoadBar("dw__loading");'.NL; 374 print '//--><!]]></script>'.NL; 375 flush(); 376} 377 378/** 379 * Display error on locked pages 380 * 381 * @author Andreas Gohr <andi@splitbrain.org> 382 */ 383function html_locked(){ 384 global $ID; 385 global $conf; 386 global $lang; 387 global $INFO; 388 389 $locktime = filemtime(wikiLockFN($ID)); 390 $expire = dformat($locktime + $conf['locktime']); 391 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 392 393 print p_locale_xhtml('locked'); 394 print '<ul>'; 395 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>'; 396 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 397 print '</ul>'; 398} 399 400/** 401 * list old revisions 402 * 403 * @author Andreas Gohr <andi@splitbrain.org> 404 * @author Ben Coburn <btcoburn@silicodon.net> 405 */ 406function html_revisions($first=0){ 407 global $ID; 408 global $INFO; 409 global $conf; 410 global $lang; 411 /* we need to get one additionally log entry to be able to 412 * decide if this is the last page or is there another one. 413 * see html_recent() 414 */ 415 $revisions = getRevisions($ID, $first, $conf['recent']+1); 416 if(count($revisions)==0 && $first!=0){ 417 $first=0; 418 $revisions = getRevisions($ID, $first, $conf['recent']+1);; 419 } 420 $hasNext = false; 421 if (count($revisions)>$conf['recent']) { 422 $hasNext = true; 423 array_pop($revisions); // remove extra log entry 424 } 425 426 $date = dformat($INFO['lastmod']); 427 428 print p_locale_xhtml('revisions'); 429 430 $form = new Doku_Form(array('id' => 'page__revisions')); 431 $form->addElement(form_makeOpenTag('ul')); 432 if($INFO['exists'] && $first==0){ 433 if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 434 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 435 else 436 $form->addElement(form_makeOpenTag('li')); 437 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 438 $form->addElement(form_makeTag('input', array( 439 'type' => 'checkbox', 440 'name' => 'rev2[]', 441 'value' => 'current'))); 442 443 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 444 $form->addElement($date); 445 $form->addElement(form_makeCloseTag('span')); 446 447 $form->addElement(form_makeTag('img', array( 448 'src' => DOKU_BASE.'lib/images/blank.gif', 449 'width' => '15', 450 'height' => '11', 451 'alt' => ''))); 452 453 $form->addElement(form_makeOpenTag('a', array( 454 'class' => 'wikilink1', 455 'href' => wl($ID)))); 456 $form->addElement($ID); 457 $form->addElement(form_makeCloseTag('a')); 458 459 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 460 $form->addElement(' – '); 461 $form->addElement(htmlspecialchars($INFO['sum'])); 462 $form->addElement(form_makeCloseTag('span')); 463 464 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 465 $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor'])); 466 $form->addElement(form_makeCloseTag('span')); 467 468 $form->addElement('('.$lang['current'].')'); 469 $form->addElement(form_makeCloseTag('div')); 470 $form->addElement(form_makeCloseTag('li')); 471 } 472 473 foreach($revisions as $rev){ 474 $date = dformat($rev); 475 $info = getRevisionInfo($ID,$rev,true); 476 $exists = page_exists($ID,$rev); 477 478 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 479 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 480 else 481 $form->addElement(form_makeOpenTag('li')); 482 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 483 if($exists){ 484 $form->addElement(form_makeTag('input', array( 485 'type' => 'checkbox', 486 'name' => 'rev2[]', 487 'value' => $rev))); 488 }else{ 489 $form->addElement(form_makeTag('img', array( 490 'src' => DOKU_BASE.'lib/images/blank.gif', 491 'width' => 14, 492 'height' => 11, 493 'alt' => ''))); 494 } 495 496 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 497 $form->addElement($date); 498 $form->addElement(form_makeCloseTag('span')); 499 500 if($exists){ 501 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link'))); 502 $form->addElement(form_makeTag('img', array( 503 'src' => DOKU_BASE.'lib/images/diff.png', 504 'width' => 15, 505 'height' => 11, 506 'title' => $lang['diff'], 507 'alt' => $lang['diff']))); 508 $form->addElement(form_makeCloseTag('a')); 509 510 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1'))); 511 $form->addElement($ID); 512 $form->addElement(form_makeCloseTag('a')); 513 }else{ 514 $form->addElement(form_makeTag('img', array( 515 'src' => DOKU_BASE.'lib/images/blank.gif', 516 'width' => '15', 517 'height' => '11', 518 'alt' => ''))); 519 $form->addElement($ID); 520 } 521 522 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 523 $form->addElement(' – '); 524 $form->addElement(htmlspecialchars($info['sum'])); 525 $form->addElement(form_makeCloseTag('span')); 526 527 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 528 if($info['user']){ 529 $form->addElement(editorinfo($info['user'])); 530 if(auth_ismanager()){ 531 $form->addElement(' ('.$info['ip'].')'); 532 } 533 }else{ 534 $form->addElement($info['ip']); 535 } 536 $form->addElement(form_makeCloseTag('span')); 537 538 $form->addElement(form_makeCloseTag('div')); 539 $form->addElement(form_makeCloseTag('li')); 540 } 541 $form->addElement(form_makeCloseTag('ul')); 542 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 543 html_form('revisions', $form); 544 545 print '<div class="pagenav">'; 546 $last = $first + $conf['recent']; 547 if ($first > 0) { 548 $first -= $conf['recent']; 549 if ($first < 0) $first = 0; 550 print '<div class="pagenav-prev">'; 551 print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first)); 552 print '</div>'; 553 } 554 if ($hasNext) { 555 print '<div class="pagenav-next">'; 556 print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last)); 557 print '</div>'; 558 } 559 print '</div>'; 560 561} 562 563/** 564 * display recent changes 565 * 566 * @author Andreas Gohr <andi@splitbrain.org> 567 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 568 * @author Ben Coburn <btcoburn@silicodon.net> 569 */ 570function html_recent($first=0){ 571 global $conf; 572 global $lang; 573 global $ID; 574 /* we need to get one additionally log entry to be able to 575 * decide if this is the last page or is there another one. 576 * This is the cheapest solution to get this information. 577 */ 578 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 579 if(count($recents) == 0 && $first != 0){ 580 $first=0; 581 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 582 } 583 $hasNext = false; 584 if (count($recents)>$conf['recent']) { 585 $hasNext = true; 586 array_pop($recents); // remove extra log entry 587 } 588 589 print p_locale_xhtml('recent'); 590 591 if (getNS($ID) != '') 592 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 593 594 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET')); 595 $form->addHidden('sectok', null); 596 $form->addHidden('do', 'recent'); 597 $form->addHidden('id', $ID); 598 $form->addElement(form_makeOpenTag('ul')); 599 600 foreach($recents as $recent){ 601 $date = dformat($recent['date']); 602 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 603 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 604 else 605 $form->addElement(form_makeOpenTag('li')); 606 607 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 608 609 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 610 $form->addElement($date); 611 $form->addElement(form_makeCloseTag('span')); 612 613 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&')))); 614 $form->addElement(form_makeTag('img', array( 615 'src' => DOKU_BASE.'lib/images/diff.png', 616 'width' => 15, 617 'height'=> 11, 618 'title' => $lang['diff'], 619 'alt' => $lang['diff'] 620 ))); 621 $form->addElement(form_makeCloseTag('a')); 622 623 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&')))); 624 $form->addElement(form_makeTag('img', array( 625 'src' => DOKU_BASE.'lib/images/history.png', 626 'width' => 12, 627 'height'=> 14, 628 'title' => $lang['btn_revs'], 629 'alt' => $lang['btn_revs'] 630 ))); 631 $form->addElement(form_makeCloseTag('a')); 632 633 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id'])); 634 635 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 636 $form->addElement(' – '.htmlspecialchars($recent['sum'])); 637 $form->addElement(form_makeCloseTag('span')); 638 639 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 640 if($recent['user']){ 641 $form->addElement(editorinfo($recent['user'])); 642 if(auth_ismanager()){ 643 $form->addElement(' ('.$recent['ip'].')'); 644 } 645 }else{ 646 $form->addElement($recent['ip']); 647 } 648 $form->addElement(form_makeCloseTag('span')); 649 650 $form->addElement(form_makeCloseTag('div')); 651 $form->addElement(form_makeCloseTag('li')); 652 } 653 $form->addElement(form_makeCloseTag('ul')); 654 655 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 656 $last = $first + $conf['recent']; 657 if ($first > 0) { 658 $first -= $conf['recent']; 659 if ($first < 0) $first = 0; 660 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 661 $form->addElement(form_makeTag('input', array( 662 'type' => 'submit', 663 'name' => 'first['.$first.']', 664 'value' => $lang['btn_newer'], 665 'accesskey' => 'n', 666 'title' => $lang['btn_newer'].' [N]', 667 'class' => 'button' 668 ))); 669 $form->addElement(form_makeCloseTag('div')); 670 } 671 if ($hasNext) { 672 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 673 $form->addElement(form_makeTag('input', array( 674 'type' => 'submit', 675 'name' => 'first['.$last.']', 676 'value' => $lang['btn_older'], 677 'accesskey' => 'p', 678 'title' => $lang['btn_older'].' [P]', 679 'class' => 'button' 680 ))); 681 $form->addElement(form_makeCloseTag('div')); 682 } 683 $form->addElement(form_makeCloseTag('div')); 684 html_form('recent', $form); 685} 686 687/** 688 * Display page index 689 * 690 * @author Andreas Gohr <andi@splitbrain.org> 691 */ 692function html_index($ns){ 693 require_once(DOKU_INC.'inc/search.php'); 694 global $conf; 695 global $ID; 696 $dir = $conf['datadir']; 697 $ns = cleanID($ns); 698 #fixme use appropriate function 699 if(empty($ns)){ 700 $ns = dirname(str_replace(':','/',$ID)); 701 if($ns == '.') $ns =''; 702 } 703 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 704 705 echo p_locale_xhtml('index'); 706 echo '<div id="index__tree">'; 707 708 $data = array(); 709 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 710 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 711 712 echo '</div>'; 713} 714 715/** 716 * Index item formatter 717 * 718 * User function for html_buildlist() 719 * 720 * @author Andreas Gohr <andi@splitbrain.org> 721 */ 722function html_list_index($item){ 723 global $ID; 724 $ret = ''; 725 $base = ':'.$item['id']; 726 $base = substr($base,strrpos($base,':')+1); 727 if($item['type']=='d'){ 728 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>'; 729 $ret .= $base; 730 $ret .= '</strong></a>'; 731 }else{ 732 $ret .= html_wikilink(':'.$item['id']); 733 } 734 return $ret; 735} 736 737/** 738 * Index List item 739 * 740 * This user function is used in html_build_lidt to build the 741 * <li> tags for namespaces when displaying the page index 742 * it gives different classes to opened or closed "folders" 743 * 744 * @author Andreas Gohr <andi@splitbrain.org> 745 */ 746function html_li_index($item){ 747 if($item['type'] == "f"){ 748 return '<li class="level'.$item['level'].'">'; 749 }elseif($item['open']){ 750 return '<li class="open">'; 751 }else{ 752 return '<li class="closed">'; 753 } 754} 755 756/** 757 * Default List item 758 * 759 * @author Andreas Gohr <andi@splitbrain.org> 760 */ 761function html_li_default($item){ 762 return '<li class="level'.$item['level'].'">'; 763} 764 765/** 766 * Build an unordered list 767 * 768 * Build an unordered list from the given $data array 769 * Each item in the array has to have a 'level' property 770 * the item itself gets printed by the given $func user 771 * function. The second and optional function is used to 772 * print the <li> tag. Both user function need to accept 773 * a single item. 774 * 775 * Both user functions can be given as array to point to 776 * a member of an object. 777 * 778 * @author Andreas Gohr <andi@splitbrain.org> 779 */ 780function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 781 $level = 0; 782 $opens = 0; 783 $ret = ''; 784 785 foreach ($data as $item){ 786 787 if( $item['level'] > $level ){ 788 //open new list 789 for($i=0; $i<($item['level'] - $level); $i++){ 790 if ($i) $ret .= "<li class=\"clear\">\n"; 791 $ret .= "\n<ul class=\"$class\">\n"; 792 } 793 }elseif( $item['level'] < $level ){ 794 //close last item 795 $ret .= "</li>\n"; 796 for ($i=0; $i<($level - $item['level']); $i++){ 797 //close higher lists 798 $ret .= "</ul>\n</li>\n"; 799 } 800 }else{ 801 //close last item 802 $ret .= "</li>\n"; 803 } 804 805 //remember current level 806 $level = $item['level']; 807 808 //print item 809 $ret .= call_user_func($lifunc,$item); 810 $ret .= '<div class="li">'; 811 812 $ret .= call_user_func($func,$item); 813 $ret .= '</div>'; 814 } 815 816 //close remaining items and lists 817 for ($i=0; $i < $level; $i++){ 818 $ret .= "</li></ul>\n"; 819 } 820 821 return $ret; 822} 823 824/** 825 * display backlinks 826 * 827 * @author Andreas Gohr <andi@splitbrain.org> 828 * @author Michael Klier <chi@chimeric.de> 829 */ 830function html_backlinks(){ 831 require_once(DOKU_INC.'inc/fulltext.php'); 832 global $ID; 833 global $conf; 834 global $lang; 835 836 print p_locale_xhtml('backlinks'); 837 838 $data = ft_backlinks($ID); 839 840 if(!empty($data)) { 841 print '<ul class="idx">'; 842 foreach($data as $blink){ 843 print '<li><div class="li">'; 844 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 845 print '</div></li>'; 846 } 847 print '</ul>'; 848 } else { 849 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 850 } 851} 852 853/** 854 * show diff 855 * 856 * @author Andreas Gohr <andi@splitbrain.org> 857 */ 858function html_diff($text='',$intro=true){ 859 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 860 global $ID; 861 global $REV; 862 global $lang; 863 global $conf; 864 865 // we're trying to be clever here, revisions to compare can be either 866 // given as rev and rev2 parameters, with rev2 being optional. Or in an 867 // array in rev2. 868 $rev1 = $REV; 869 870 if(is_array($_REQUEST['rev2'])){ 871 $rev1 = (int) $_REQUEST['rev2'][0]; 872 $rev2 = (int) $_REQUEST['rev2'][1]; 873 874 if(!$rev1){ 875 $rev1 = $rev2; 876 unset($rev2); 877 } 878 }else{ 879 $rev2 = (int) $_REQUEST['rev2']; 880 } 881 882 if($text){ // compare text to the most current revision 883 $l_rev = ''; 884 $l_text = rawWiki($ID,''); 885 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 886 $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '. 887 $lang['current']; 888 889 $r_rev = ''; 890 $r_text = cleanText($text); 891 $r_head = $lang['yours']; 892 }else{ 893 if($rev1 && $rev2){ // two specific revisions wanted 894 // make sure order is correct (older on the left) 895 if($rev1 < $rev2){ 896 $l_rev = $rev1; 897 $r_rev = $rev2; 898 }else{ 899 $l_rev = $rev2; 900 $r_rev = $rev1; 901 } 902 }elseif($rev1){ // single revision given, compare to current 903 $r_rev = ''; 904 $l_rev = $rev1; 905 }else{ // no revision was given, compare previous to current 906 $r_rev = ''; 907 $revs = getRevisions($ID, 0, 1); 908 $l_rev = $revs[0]; 909 $REV = $l_rev; // store revision back in $REV 910 } 911 912 // when both revisions are empty then the page was created just now 913 if(!$l_rev && !$r_rev){ 914 $l_text = ''; 915 }else{ 916 $l_text = rawWiki($ID,$l_rev); 917 } 918 $r_text = rawWiki($ID,$r_rev); 919 920 if(!$l_rev){ 921 $l_head = '—'; 922 }else{ 923 $l_info = getRevisionInfo($ID,$l_rev,true); 924 if($l_info['user']){ 925 $l_user = editorinfo($l_info['user']); 926 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')'; 927 } else { 928 $l_user = $l_info['ip']; 929 } 930 $l_user = '<span class="user">'.$l_user.'</span>'; 931 $l_sum = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : ''; 932 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 933 934 $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'. 935 $ID.' ['.dformat($l_rev).']</a>'. 936 '<br />'.$l_user.' '.$l_sum; 937 } 938 939 if($r_rev){ 940 $r_info = getRevisionInfo($ID,$r_rev,true); 941 if($r_info['user']){ 942 $r_user = editorinfo($r_info['user']); 943 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')'; 944 } else { 945 $r_user = $r_info['ip']; 946 } 947 $r_user = '<span class="user">'.$r_user.'</span>'; 948 $r_sum = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : ''; 949 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 950 951 $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'. 952 $ID.' ['.dformat($r_rev).']</a>'. 953 '<br />'.$r_user.' '.$r_sum; 954 }elseif($_rev = @filemtime(wikiFN($ID))){ 955 $_info = getRevisionInfo($ID,$_rev,true); 956 if($_info['user']){ 957 $_user = editorinfo($_info['user']); 958 if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')'; 959 } else { 960 $_user = $_info['ip']; 961 } 962 $_user = '<span class="user">'.$_user.'</span>'; 963 $_sum = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : ''; 964 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 965 966 $r_head = '<a class="wikilink1" href="'.wl($ID).'">'. 967 $ID.' ['.dformat($_rev).']</a> '. 968 '('.$lang['current'].')'. 969 '<br />'.$_user.' '.$_sum; 970 }else{ 971 $r_head = '— ('.$lang['current'].')'; 972 } 973 } 974 975 $df = new Diff(explode("\n",htmlspecialchars($l_text)), 976 explode("\n",htmlspecialchars($r_text))); 977 978 $tdf = new TableDiffFormatter(); 979 if($intro) print p_locale_xhtml('diff'); 980 ?> 981 <table class="diff"> 982 <tr> 983 <th colspan="2" <?php echo $l_minor?>> 984 <?php echo $l_head?> 985 </th> 986 <th colspan="2" <?php echo $r_minor?>> 987 <?php echo $r_head?> 988 </th> 989 </tr> 990 <?php echo $tdf->format($df)?> 991 </table> 992 <?php 993} 994 995/** 996 * show warning on conflict detection 997 * 998 * @author Andreas Gohr <andi@splitbrain.org> 999 */ 1000function html_conflict($text,$summary){ 1001 global $ID; 1002 global $lang; 1003 1004 print p_locale_xhtml('conflict'); 1005 $form = new Doku_Form(array('id' => 'dw__editform')); 1006 $form->addHidden('id', $ID); 1007 $form->addHidden('wikitext', $text); 1008 $form->addHidden('summary', $summary); 1009 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1010 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1011 html_form('conflict', $form); 1012 print '<br /><br /><br /><br />'.NL; 1013} 1014 1015/** 1016 * Prints the global message array 1017 * 1018 * @author Andreas Gohr <andi@splitbrain.org> 1019 */ 1020function html_msgarea(){ 1021 global $MSG; 1022 if(!isset($MSG)) return; 1023 1024 $shown = array(); 1025 foreach($MSG as $msg){ 1026 $hash = md5($msg['msg']); 1027 if(isset($shown[$hash])) continue; // skip double messages 1028 print '<div class="'.$msg['lvl'].'">'; 1029 print $msg['msg']; 1030 print '</div>'; 1031 $shown[$hash] = 1; 1032 } 1033} 1034 1035/** 1036 * Prints the registration form 1037 * 1038 * @author Andreas Gohr <andi@splitbrain.org> 1039 */ 1040function html_register(){ 1041 global $lang; 1042 global $conf; 1043 global $ID; 1044 1045 print p_locale_xhtml('register'); 1046 print '<div class="centeralign">'.NL; 1047 $form = new Doku_Form(array('id' => 'dw__register')); 1048 $form->startFieldset($lang['register']); 1049 $form->addHidden('do', 'register'); 1050 $form->addHidden('save', '1'); 1051 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50'))); 1052 if (!$conf['autopasswd']) { 1053 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1054 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1055 } 1056 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50'))); 1057 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50'))); 1058 $form->addElement(form_makeButton('submit', '', $lang['register'])); 1059 $form->endFieldset(); 1060 html_form('register', $form); 1061 1062 print '</div>'.NL; 1063} 1064 1065/** 1066 * Print the update profile form 1067 * 1068 * @author Christopher Smith <chris@jalakai.co.uk> 1069 * @author Andreas Gohr <andi@splitbrain.org> 1070 */ 1071function html_updateprofile(){ 1072 global $lang; 1073 global $conf; 1074 global $ID; 1075 global $INFO; 1076 global $auth; 1077 1078 print p_locale_xhtml('updateprofile'); 1079 1080 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; 1081 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; 1082 print '<div class="centeralign">'.NL; 1083 $form = new Doku_Form(array('id' => 'dw__register')); 1084 $form->startFieldset($lang['profile']); 1085 $form->addHidden('do', 'profile'); 1086 $form->addHidden('save', '1'); 1087 $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1088 $attr = array('size'=>'50'); 1089 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1090 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr)); 1091 $attr = array('size'=>'50'); 1092 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1093 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr)); 1094 $form->addElement(form_makeTag('br')); 1095 if ($auth->canDo('modPass')) { 1096 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1097 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1098 } 1099 if ($conf['profileconfirm']) { 1100 $form->addElement(form_makeTag('br')); 1101 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); 1102 } 1103 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1104 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1105 $form->endFieldset(); 1106 html_form('updateprofile', $form); 1107 print '</div>'.NL; 1108} 1109 1110/** 1111 * Preprocess edit form data 1112 * 1113 * @triggers HTML_PAGE_FROMTEMPLATE 1114 * @author Andreas Gohr <andi@splitbrain.org> 1115 */ 1116function html_edit($text=null,$include='edit'){ //FIXME: include needed? 1117 global $ID; 1118 global $REV; 1119 global $DATE; 1120 global $RANGE; 1121 global $PRE; 1122 global $SUF; 1123 global $INFO; 1124 global $SUM; 1125 global $lang; 1126 global $conf; 1127 1128 //set summary default 1129 if(!$SUM){ 1130 if($REV){ 1131 $SUM = $lang['restored']; 1132 }elseif(!$INFO['exists']){ 1133 $SUM = $lang['created']; 1134 } 1135 } 1136 1137 //no text? Load it! 1138 if(!isset($text)){ 1139 $pr = false; //no preview mode 1140 if($INFO['exists']){ 1141 if($RANGE){ 1142 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); 1143 }else{ 1144 $text = rawWiki($ID,$REV); 1145 } 1146 $check = md5($text); 1147 $mod = false; 1148 }else{ 1149 //try to load a pagetemplate 1150 $data = array($ID); 1151 $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); 1152 $check = md5(''); 1153 $mod = $text!==''; 1154 } 1155 }else{ 1156 $pr = true; //preview mode 1157 if (isset($_REQUEST['changecheck'])) { 1158 $check = $_REQUEST['changecheck']; 1159 $mod = md5($text)!==$check; 1160 } else { 1161 // Why? Assume default text is unmodified. 1162 $check = md5($text); 1163 $mod = false; 1164 } 1165 } 1166 1167 $wr = $INFO['writable'] && !$INFO['locked']; 1168 if($wr){ 1169 if ($REV) print p_locale_xhtml('editrev'); 1170 print p_locale_xhtml($include); 1171 }else{ 1172 // check pseudo action 'source' 1173 if(!actionOK('source')){ 1174 msg('Command disabled: source',-1); 1175 return; 1176 } 1177 print p_locale_xhtml('read'); 1178 } 1179 if(!$DATE) $DATE = $INFO['lastmod']; 1180 1181 $data = compact('wr', 'text', 'mod', 'check'); 1182 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1183} 1184 1185/** 1186 * Display the default edit form 1187 * 1188 * Is the default action for HTML_EDIT_FORMSELECTION. 1189 * 1190 * @triggers HTML_EDITFORM_OUTPUT 1191 */ 1192function html_edit_form($param) { 1193 extract($param); 1194 global $conf; 1195 global $license; 1196 global $lang; 1197 global $REV; 1198 global $DATE; 1199 global $PRE; 1200 global $SUF; 1201 global $INFO; 1202 global $SUM; 1203 global $ID; 1204 ?> 1205 <?php if($wr){?> 1206 <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!-- 1207 <?php /* sets changed to true when previewed */?> 1208 textChanged = <?php ($mod) ? print 'true' : print 'false' ?>; 1209 //--><!]]></script> 1210 <?php } ?> 1211 <div style="width:99%;"> 1212 1213 <div class="toolbar"> 1214 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1215 <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1216 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1217 1218 </div> 1219 <?php 1220 $form = new Doku_Form(array('id' => 'dw__editform')); 1221 $form->addHidden('id', $ID); 1222 $form->addHidden('rev', $REV); 1223 $form->addHidden('date', $DATE); 1224 $form->addHidden('prefix', $PRE); 1225 $form->addHidden('suffix', $SUF); 1226 $form->addHidden('changecheck', $check); 1227 $attr = array('tabindex'=>'1'); 1228 if (!$wr) $attr['readonly'] = 'readonly'; 1229 $form->addElement(form_makeWikiText($text, $attr)); 1230 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); 1231 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1232 $form->addElement(form_makeCloseTag('div')); 1233 if ($wr) { 1234 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1235 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1236 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1237 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1238 $form->addElement(form_makeCloseTag('div')); 1239 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1240 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1241 $elem = html_minoredit(); 1242 if ($elem) $form->addElement($elem); 1243 $form->addElement(form_makeCloseTag('div')); 1244 } 1245 $form->addElement(form_makeCloseTag('div')); 1246 if($wr && $conf['license']){ 1247 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1248 $out = $lang['licenseok']; 1249 $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1250 if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"'; 1251 $out .= '> '.$license[$conf['license']]['name'].'</a>'; 1252 $form->addElement($out); 1253 $form->addElement(form_makeCloseTag('div')); 1254 } 1255 html_form('edit', $form); 1256 print '</div>'.NL; 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