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