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 if(empty($id)) { 309 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 310 flush(); 311 return; 312 } 313 } else { 314 $id = cleanID($QUERY); 315 } 316 317 //show progressbar 318 print '<div class="centeralign" id="dw__loading">'.NL; 319 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 320 print 'showLoadBar();'.NL; 321 print '//--><!]]></script>'.NL; 322 print '<br /></div>'.NL; 323 flush(); 324 325 //do quick pagesearch 326 $data = array(); 327 328 $data = ft_pageLookup($id); 329 if(count($data)){ 330 print '<div class="search_quickresult">'; 331 print '<h3>'.$lang['quickhits'].':</h3>'; 332 print '<ul class="search_quickhits">'; 333 foreach($data as $id){ 334 print '<li> '; 335 $ns = getNS($id); 336 if($ns){ 337 $name = shorten(noNS($id), ' ('.$ns.')',30); 338 }else{ 339 $name = $id; 340 } 341 print html_wikilink(':'.$id,$name); 342 print '</li> '; 343 } 344 print '</ul> '; 345 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 346 print '<div class="clearer"> </div>'; 347 print '</div>'; 348 } 349 flush(); 350 351 //do fulltext search 352 $data = ft_pageSearch($QUERY,$regex); 353 if(count($data)){ 354 $num = 1; 355 foreach($data as $id => $cnt){ 356 print '<div class="search_result">'; 357 print html_wikilink(':'.$id,useHeading('navigation')?NULL:$id,$regex); 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 print '</div>'; 363 flush(); 364 $num++; 365 } 366 }else{ 367 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 368 } 369 370 //hide progressbar 371 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 372 print 'hideLoadBar("dw__loading");'.NL; 373 print '//--><!]]></script>'.NL; 374 flush(); 375} 376 377/** 378 * Display error on locked pages 379 * 380 * @author Andreas Gohr <andi@splitbrain.org> 381 */ 382function html_locked(){ 383 global $ID; 384 global $conf; 385 global $lang; 386 global $INFO; 387 388 $locktime = filemtime(wikiLockFN($ID)); 389 $expire = @strftime($conf['dformat'], $locktime + $conf['locktime'] ); 390 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 391 392 print p_locale_xhtml('locked'); 393 print '<ul>'; 394 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</div></li>'; 395 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 396 print '</ul>'; 397} 398 399/** 400 * list old revisions 401 * 402 * @author Andreas Gohr <andi@splitbrain.org> 403 * @author Ben Coburn <btcoburn@silicodon.net> 404 */ 405function html_revisions($first=0){ 406 global $ID; 407 global $INFO; 408 global $conf; 409 global $lang; 410 /* we need to get one additionally log entry to be able to 411 * decide if this is the last page or is there another one. 412 * see html_recent() 413 */ 414 $revisions = getRevisions($ID, $first, $conf['recent']+1); 415 if(count($revisions)==0 && $first!=0){ 416 $first=0; 417 $revisions = getRevisions($ID, $first, $conf['recent']+1);; 418 } 419 $hasNext = false; 420 if (count($revisions)>$conf['recent']) { 421 $hasNext = true; 422 array_pop($revisions); // remove extra log entry 423 } 424 425 $date = @strftime($conf['dformat'],$INFO['lastmod']); 426 427 print p_locale_xhtml('revisions'); 428 429 $form = new Doku_Form('page__revisions', wl($ID)); 430 $form->addElement(form_makeOpenTag('ul')); 431 if($INFO['exists'] && $first==0){ 432 if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 433 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 434 else 435 $form->addElement(form_makeOpenTag('li')); 436 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 437 $form->addElement(form_makeTag('input', array( 438 'type' => 'checkbox', 439 'name' => 'rev2[]', 440 'value' => 'current'))); 441 442 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 443 $form->addElement($date); 444 $form->addElement(form_makeCloseTag('span')); 445 446 $form->addElement(form_makeTag('img', array( 447 'src' => DOKU_BASE.'lib/images/blank.gif', 448 'width' => '15', 449 'height' => '11', 450 'alt' => ''))); 451 452 $form->addElement(form_makeOpenTag('a', array( 453 'class' => 'wikilink1', 454 'href' => wl($ID)))); 455 $form->addElement($ID); 456 $form->addElement(form_makeCloseTag('a')); 457 458 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 459 $form->addElement(' – '); 460 $form->addElement(htmlspecialchars($INFO['sum'])); 461 $form->addElement(form_makeCloseTag('span')); 462 463 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 464 $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor'])); 465 $form->addElement(form_makeCloseTag('span')); 466 467 $form->addElement('('.$lang['current'].')'); 468 $form->addElement(form_makeCloseTag('div')); 469 $form->addElement(form_makeCloseTag('li')); 470 } 471 472 foreach($revisions as $rev){ 473 $date = strftime($conf['dformat'],$rev); 474 $info = getRevisionInfo($ID,$rev,true); 475 $exists = page_exists($ID,$rev); 476 477 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 478 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 479 else 480 $form->addElement(form_makeOpenTag('li')); 481 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 482 if($exists){ 483 $form->addElement(form_makeTag('input', array( 484 'type' => 'checkbox', 485 'name' => 'rev2[]', 486 'value' => $rev))); 487 }else{ 488 $form->addElement(form_makeTag('img', array( 489 'src' => DOKU_BASE.'lib/images/blank.gif', 490 'width' => 14, 491 'height' => 11, 492 'alt' => ''))); 493 } 494 495 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 496 $form->addElement($date); 497 $form->addElement(form_makeCloseTag('span')); 498 499 if($exists){ 500 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link'))); 501 $form->addElement(form_makeTag('img', array( 502 'src' => DOKU_BASE.'lib/images/diff.png', 503 'width' => 15, 504 'height' => 11, 505 'title' => $lang['diff'], 506 'alt' => $lang['diff']))); 507 $form->addElement(form_makeCloseTag('a')); 508 509 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1'))); 510 $form->addElement($ID); 511 $form->addElement(form_makeCloseTag('a')); 512 }else{ 513 $form->addElement(form_makeTag('img', array( 514 'src' => DOKU_BASE.'lib/images/blank.gif', 515 'width' => '15', 516 'height' => '11', 517 'alt' => ''))); 518 $form->addElement($ID); 519 } 520 521 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 522 $form->addElement(' – '); 523 $form->addElement(htmlspecialchars($info['sum'])); 524 $form->addElement(form_makeCloseTag('span')); 525 526 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 527 if($info['user']){ 528 $form->addElement(editorinfo($info['user'])); 529 if(auth_ismanager()){ 530 $form->addElement(' ('.$info['ip'].')'); 531 } 532 }else{ 533 $form->addElement($info['ip']); 534 } 535 $form->addElement(form_makeCloseTag('span')); 536 537 $form->addElement(form_makeCloseTag('div')); 538 $form->addElement(form_makeCloseTag('li')); 539 } 540 $form->addElement(form_makeCloseTag('ul')); 541 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 542 html_form('revisions', $form); 543 544 print '<div class="pagenav">'; 545 $last = $first + $conf['recent']; 546 if ($first > 0) { 547 $first -= $conf['recent']; 548 if ($first < 0) $first = 0; 549 print '<div class="pagenav-prev">'; 550 print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first)); 551 print '</div>'; 552 } 553 if ($hasNext) { 554 print '<div class="pagenav-next">'; 555 print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last)); 556 print '</div>'; 557 } 558 print '</div>'; 559 560} 561 562/** 563 * display recent changes 564 * 565 * @author Andreas Gohr <andi@splitbrain.org> 566 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 567 * @author Ben Coburn <btcoburn@silicodon.net> 568 */ 569function html_recent($first=0){ 570 global $conf; 571 global $lang; 572 global $ID; 573 /* we need to get one additionally log entry to be able to 574 * decide if this is the last page or is there another one. 575 * This is the cheapest solution to get this information. 576 */ 577 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 578 if(count($recents) == 0 && $first != 0){ 579 $first=0; 580 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 581 } 582 $hasNext = false; 583 if (count($recents)>$conf['recent']) { 584 $hasNext = true; 585 array_pop($recents); // remove extra log entry 586 } 587 588 print p_locale_xhtml('recent'); 589 590 if (getNS($ID) != '') 591 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 592 593 $form = new Doku_Form('dw__recent', script(), 'get'); 594 $form->addHidden('sectok', null); 595 $form->addHidden('do', 'recent'); 596 $form->addHidden('id', $ID); 597 $form->addElement(form_makeOpenTag('ul')); 598 599 foreach($recents as $recent){ 600 $date = strftime($conf['dformat'],$recent['date']); 601 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 602 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 603 else 604 $form->addElement(form_makeOpenTag('li')); 605 606 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 607 608 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 609 $form->addElement($date); 610 $form->addElement(form_makeCloseTag('span')); 611 612 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&')))); 613 $form->addElement(form_makeTag('img', array( 614 'src' => DOKU_BASE.'lib/images/diff.png', 615 'width' => 15, 616 'height'=> 11, 617 'title' => $lang['diff'], 618 'alt' => $lang['diff'] 619 ))); 620 $form->addElement(form_makeCloseTag('a')); 621 622 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&')))); 623 $form->addElement(form_makeTag('img', array( 624 'src' => DOKU_BASE.'lib/images/history.png', 625 'width' => 12, 626 'height'=> 14, 627 'title' => $lang['btn_revs'], 628 'alt' => $lang['btn_revs'] 629 ))); 630 $form->addElement(form_makeCloseTag('a')); 631 632 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?NULL:$recent['id'])); 633 634 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 635 $form->addElement(' – '.htmlspecialchars($recent['sum'])); 636 $form->addElement(form_makeCloseTag('span')); 637 638 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 639 if($recent['user']){ 640 $form->addElement(editorinfo($recent['user'])); 641 if(auth_ismanager()){ 642 $form->addElement(' ('.$recent['ip'].')'); 643 } 644 }else{ 645 $form->addElement($recent['ip']); 646 } 647 $form->addElement(form_makeCloseTag('span')); 648 649 $form->addElement(form_makeCloseTag('div')); 650 $form->addElement(form_makeCloseTag('li')); 651 } 652 $form->addElement(form_makeCloseTag('ul')); 653 654 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 655 $last = $first + $conf['recent']; 656 if ($first > 0) { 657 $first -= $conf['recent']; 658 if ($first < 0) $first = 0; 659 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 660 $form->addElement(form_makeTag('input', array( 661 'type' => 'submit', 662 'name' => 'first['.$first.']', 663 'value' => $lang['btn_newer'], 664 'accesskey' => 'n', 665 'title' => $lang['btn_newer'].' [N]', 666 'class' => 'button' 667 ))); 668 $form->addElement(form_makeCloseTag('div')); 669 } 670 if ($hasNext) { 671 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 672 $form->addElement(form_makeTag('input', array( 673 'type' => 'submit', 674 'name' => 'first['.$last.']', 675 'value' => $lang['btn_older'], 676 'accesskey' => 'p', 677 'title' => $lang['btn_older'].' [P]', 678 'class' => 'button' 679 ))); 680 $form->addElement(form_makeCloseTag('div')); 681 } 682 $form->addElement(form_makeCloseTag('div')); 683 html_form('recent', $form); 684} 685 686/** 687 * Display page index 688 * 689 * @author Andreas Gohr <andi@splitbrain.org> 690 */ 691function html_index($ns){ 692 require_once(DOKU_INC.'inc/search.php'); 693 global $conf; 694 global $ID; 695 $dir = $conf['datadir']; 696 $ns = cleanID($ns); 697 #fixme use appropriate function 698 if(empty($ns)){ 699 $ns = dirname(str_replace(':','/',$ID)); 700 if($ns == '.') $ns =''; 701 } 702 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 703 704 echo p_locale_xhtml('index'); 705 echo '<div id="index__tree">'; 706 707 $data = array(); 708 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 709 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 710 711 echo '</div>'; 712} 713 714/** 715 * Index item formatter 716 * 717 * User function for html_buildlist() 718 * 719 * @author Andreas Gohr <andi@splitbrain.org> 720 */ 721function html_list_index($item){ 722 global $ID; 723 $ret = ''; 724 $base = ':'.$item['id']; 725 $base = substr($base,strrpos($base,':')+1); 726 if($item['type']=='d'){ 727 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>'; 728 $ret .= $base; 729 $ret .= '</strong></a>'; 730 }else{ 731 $ret .= html_wikilink(':'.$item['id']); 732 } 733 return $ret; 734} 735 736/** 737 * Index List item 738 * 739 * This user function is used in html_build_lidt to build the 740 * <li> tags for namespaces when displaying the page index 741 * it gives different classes to opened or closed "folders" 742 * 743 * @author Andreas Gohr <andi@splitbrain.org> 744 */ 745function html_li_index($item){ 746 if($item['type'] == "f"){ 747 return '<li class="level'.$item['level'].'">'; 748 }elseif($item['open']){ 749 return '<li class="open">'; 750 }else{ 751 return '<li class="closed">'; 752 } 753} 754 755/** 756 * Default List item 757 * 758 * @author Andreas Gohr <andi@splitbrain.org> 759 */ 760function html_li_default($item){ 761 return '<li class="level'.$item['level'].'">'; 762} 763 764/** 765 * Build an unordered list 766 * 767 * Build an unordered list from the given $data array 768 * Each item in the array has to have a 'level' property 769 * the item itself gets printed by the given $func user 770 * function. The second and optional function is used to 771 * print the <li> tag. Both user function need to accept 772 * a single item. 773 * 774 * Both user functions can be given as array to point to 775 * a member of an object. 776 * 777 * @author Andreas Gohr <andi@splitbrain.org> 778 */ 779function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 780 $level = 0; 781 $opens = 0; 782 $ret = ''; 783 784 foreach ($data as $item){ 785 786 if( $item['level'] > $level ){ 787 //open new list 788 for($i=0; $i<($item['level'] - $level); $i++){ 789 if ($i) $ret .= "<li class=\"clear\">\n"; 790 $ret .= "\n<ul class=\"$class\">\n"; 791 } 792 }elseif( $item['level'] < $level ){ 793 //close last item 794 $ret .= "</li>\n"; 795 for ($i=0; $i<($level - $item['level']); $i++){ 796 //close higher lists 797 $ret .= "</ul>\n</li>\n"; 798 } 799 }else{ 800 //close last item 801 $ret .= "</li>\n"; 802 } 803 804 //remember current level 805 $level = $item['level']; 806 807 //print item 808 $ret .= call_user_func($lifunc,$item); 809 $ret .= '<div class="li">'; 810 811 $ret .= call_user_func($func,$item); 812 $ret .= '</div>'; 813 } 814 815 //close remaining items and lists 816 for ($i=0; $i < $level; $i++){ 817 $ret .= "</li></ul>\n"; 818 } 819 820 return $ret; 821} 822 823/** 824 * display backlinks 825 * 826 * @author Andreas Gohr <andi@splitbrain.org> 827 * @author Michael Klier <chi@chimeric.de> 828 */ 829function html_backlinks(){ 830 require_once(DOKU_INC.'inc/fulltext.php'); 831 global $ID; 832 global $conf; 833 global $lang; 834 835 print p_locale_xhtml('backlinks'); 836 837 $data = ft_backlinks($ID); 838 839 if(!empty($data)) { 840 print '<ul class="idx">'; 841 foreach($data as $blink){ 842 print '<li><div class="li">'; 843 print html_wikilink(':'.$blink,useHeading('navigation')?NULL:$blink); 844 print '</div></li>'; 845 } 846 print '</ul>'; 847 } else { 848 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 849 } 850} 851 852/** 853 * show diff 854 * 855 * @author Andreas Gohr <andi@splitbrain.org> 856 */ 857function html_diff($text='',$intro=true){ 858 require_once(DOKU_INC.'inc/DifferenceEngine.php'); 859 global $ID; 860 global $REV; 861 global $lang; 862 global $conf; 863 864 // we're trying to be clever here, revisions to compare can be either 865 // given as rev and rev2 parameters, with rev2 being optional. Or in an 866 // array in rev2. 867 $rev1 = $REV; 868 869 if(is_array($_REQUEST['rev2'])){ 870 $rev1 = (int) $_REQUEST['rev2'][0]; 871 $rev2 = (int) $_REQUEST['rev2'][1]; 872 873 if(!$rev1){ 874 $rev1 = $rev2; 875 unset($rev2); 876 } 877 }else{ 878 $rev2 = (int) $_REQUEST['rev2']; 879 } 880 881 if($text){ // compare text to the most current revision 882 $l_rev = ''; 883 $l_text = rawWiki($ID,''); 884 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 885 $ID.' '.strftime($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '. 886 $lang['current']; 887 888 $r_rev = ''; 889 $r_text = cleanText($text); 890 $r_head = $lang['yours']; 891 }else{ 892 if($rev1 && $rev2){ // two specific revisions wanted 893 // make sure order is correct (older on the left) 894 if($rev1 < $rev2){ 895 $l_rev = $rev1; 896 $r_rev = $rev2; 897 }else{ 898 $l_rev = $rev2; 899 $r_rev = $rev1; 900 } 901 }elseif($rev1){ // single revision given, compare to current 902 $r_rev = ''; 903 $l_rev = $rev1; 904 }else{ // no revision was given, compare previous to current 905 $r_rev = ''; 906 $revs = getRevisions($ID, 0, 1); 907 $l_rev = $revs[0]; 908 } 909 910 // when both revisions are empty then the page was created just now 911 if(!$l_rev && !$r_rev){ 912 $l_text = ''; 913 }else{ 914 $l_text = rawWiki($ID,$l_rev); 915 } 916 $r_text = rawWiki($ID,$r_rev); 917 918 919 if(!$l_rev){ 920 $l_head = '—'; 921 }else{ 922 $l_info = getRevisionInfo($ID,$l_rev,true); 923 if($l_info['user']){ $l_user = editorinfo($l_info['user']); 924 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')'; 925 } else { $l_user = $l_info['ip']; } 926 $l_user = '<span class="user">'.$l_user.'</span>'; 927 $l_sum = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : ''; 928 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 929 930 $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'. 931 $ID.' ['.strftime($conf['dformat'],$l_rev).']</a>'. 932 '<br />'.$l_user.' '.$l_sum; 933 } 934 935 if($r_rev){ 936 $r_info = getRevisionInfo($ID,$r_rev,true); 937 if($r_info['user']){ $r_user = editorinfo($r_info['user']); 938 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')'; 939 } else { $r_user = $r_info['ip']; } 940 $r_user = '<span class="user">'.$r_user.'</span>'; 941 $r_sum = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : ''; 942 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 943 944 $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'. 945 $ID.' ['.strftime($conf['dformat'],$r_rev).']</a>'. 946 '<br />'.$r_user.' '.$r_sum; 947 }elseif($_rev = @filemtime(wikiFN($ID))){ 948 $_info = getRevisionInfo($ID,$_rev,true); 949 if($_info['user']){ $_user = editorinfo($_info['user']); 950 if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')'; 951 } else { $_user = $_info['ip']; } 952 $_user = '<span class="user">'.$_user.'</span>'; 953 $_sum = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : ''; 954 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 955 956 $r_head = '<a class="wikilink1" href="'.wl($ID).'">'. 957 $ID.' ['.strftime($conf['dformat'],$_rev).']</a> '. 958 '('.$lang['current'].')'. 959 '<br />'.$_user.' '.$_sum; 960 }else{ 961 $r_head = '— ('.$lang['current'].')'; 962 } 963 } 964 965 $df = new Diff(explode("\n",htmlspecialchars($l_text)), 966 explode("\n",htmlspecialchars($r_text))); 967 968 $tdf = new TableDiffFormatter(); 969 if($intro) print p_locale_xhtml('diff'); 970 ?> 971 <table class="diff"> 972 <tr> 973 <th colspan="2" <?php echo $l_minor?>> 974 <?php echo $l_head?> 975 </th> 976 <th colspan="2" <?php echo $r_minor?>> 977 <?php echo $r_head?> 978 </th> 979 </tr> 980 <?php echo $tdf->format($df)?> 981 </table> 982 <?php 983} 984 985/** 986 * show warning on conflict detection 987 * 988 * @author Andreas Gohr <andi@splitbrain.org> 989 */ 990function html_conflict($text,$summary){ 991 global $ID; 992 global $lang; 993 994 print p_locale_xhtml('conflict'); 995 $form = new Doku_Form('dw__editform'); 996 $form->addHidden('id', $ID); 997 $form->addHidden('wikitext', $text); 998 $form->addHidden('summary', $summary); 999 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1000 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1001 html_form('conflict', $form); 1002 print '<br /><br /><br /><br />'.NL; 1003} 1004 1005/** 1006 * Prints the global message array 1007 * 1008 * @author Andreas Gohr <andi@splitbrain.org> 1009 */ 1010function html_msgarea(){ 1011 global $MSG; 1012 if(!isset($MSG)) return; 1013 1014 $shown = array(); 1015 foreach($MSG as $msg){ 1016 $hash = md5($msg['msg']); 1017 if(isset($shown[$hash])) continue; // skip double messages 1018 print '<div class="'.$msg['lvl'].'">'; 1019 print $msg['msg']; 1020 print '</div>'; 1021 $shown[$hash] = 1; 1022 } 1023} 1024 1025/** 1026 * Prints the registration form 1027 * 1028 * @author Andreas Gohr <andi@splitbrain.org> 1029 */ 1030function html_register(){ 1031 global $lang; 1032 global $conf; 1033 global $ID; 1034 1035 print p_locale_xhtml('register'); 1036 print '<div class="centeralign">'.NL; 1037 $form = new Doku_Form('dw__register', wl($ID)); 1038 $form->startFieldset($lang['register']); 1039 $form->addHidden('do', 'register'); 1040 $form->addHidden('save', '1'); 1041 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50'))); 1042 if (!$conf['autopasswd']) { 1043 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1044 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1045 } 1046 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50'))); 1047 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50'))); 1048 $form->addElement(form_makeButton('submit', '', $lang['register'])); 1049 $form->endFieldset(); 1050 html_form('register', $form); 1051 1052 print '</div>'.NL; 1053} 1054 1055/** 1056 * Print the update profile form 1057 * 1058 * @author Christopher Smith <chris@jalakai.co.uk> 1059 * @author Andreas Gohr <andi@splitbrain.org> 1060 */ 1061function html_updateprofile(){ 1062 global $lang; 1063 global $conf; 1064 global $ID; 1065 global $INFO; 1066 global $auth; 1067 1068 print p_locale_xhtml('updateprofile'); 1069 1070 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; 1071 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; 1072 print '<div class="centeralign">'.NL; 1073 $form = new Doku_Form('dw__register', wl($ID)); 1074 $form->startFieldset($lang['profile']); 1075 $form->addHidden('do', 'profile'); 1076 $form->addHidden('save', '1'); 1077 $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1078 $attr = array('size'=>'50'); 1079 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1080 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr)); 1081 $attr = array('size'=>'50'); 1082 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1083 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr)); 1084 $form->addElement(form_makeTag('br')); 1085 if ($auth->canDo('modPass')) { 1086 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1087 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1088 } 1089 if ($conf['profileconfirm']) { 1090 $form->addElement(form_makeTag('br')); 1091 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); 1092 } 1093 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1094 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1095 $form->endFieldset(); 1096 html_form('updateprofile', $form); 1097 print '</div>'.NL; 1098} 1099 1100/** 1101 * This displays the edit form (lots of logic included) 1102 * 1103 * @fixme this is a huge lump of code and should be modularized 1104 * @triggers HTML_PAGE_FROMTEMPLATE 1105 * @triggers HTML_EDITFORM_INJECTION 1106 * @author Andreas Gohr <andi@splitbrain.org> 1107 */ 1108function html_edit($text=null,$include='edit'){ //FIXME: include needed? 1109 global $ID; 1110 global $REV; 1111 global $DATE; 1112 global $RANGE; 1113 global $PRE; 1114 global $SUF; 1115 global $INFO; 1116 global $SUM; 1117 global $lang; 1118 global $conf; 1119 global $license; 1120 1121 //set summary default 1122 if(!$SUM){ 1123 if($REV){ 1124 $SUM = $lang['restored']; 1125 }elseif(!$INFO['exists']){ 1126 $SUM = $lang['created']; 1127 } 1128 } 1129 1130 //no text? Load it! 1131 if(!isset($text)){ 1132 $pr = false; //no preview mode 1133 if($INFO['exists']){ 1134 if($RANGE){ 1135 list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); 1136 }else{ 1137 $text = rawWiki($ID,$REV); 1138 } 1139 $check = md5($text); 1140 $mod = false; 1141 }else{ 1142 //try to load a pagetemplate 1143 $data = array($ID); 1144 $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); 1145 $check = md5(''); 1146 $mod = $text!==''; 1147 } 1148 }else{ 1149 $pr = true; //preview mode 1150 if (isset($_REQUEST['changecheck'])) { 1151 $check = $_REQUEST['changecheck']; 1152 $mod = md5($text)!==$check; 1153 } else { 1154 // Why? Assume default text is unmodified. 1155 $check = md5($text); 1156 $mod = false; 1157 } 1158 } 1159 1160 $wr = $INFO['writable'] && !$INFO['locked']; 1161 if($wr){ 1162 if ($REV) print p_locale_xhtml('editrev'); 1163 print p_locale_xhtml($include); 1164 }else{ 1165 // check pseudo action 'source' 1166 if(!actionOK('source')){ 1167 msg('Command disabled: source',-1); 1168 return; 1169 } 1170 print p_locale_xhtml('read'); 1171 } 1172 if(!$DATE) $DATE = $INFO['lastmod']; 1173 1174 1175?> 1176 <div style="width:99%;"> 1177 1178 <div class="toolbar"> 1179 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div> 1180 <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1181 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1182 1183 <?php if($wr){?> 1184 <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!-- 1185 <?php /* sets changed to true when previewed */?> 1186 textChanged = <?php ($mod) ? print 'true' : print 'false' ?>; 1187 //--><!]]></script> 1188 <span id="spell__action"></span> 1189 <div id="spell__suggest"></div> 1190 <?php } ?> 1191 </div> 1192 <div id="spell__result"></div> 1193<?php 1194 $form = new Doku_Form('dw__editform'); 1195 $form->addHidden('id', $ID); 1196 $form->addHidden('rev', $REV); 1197 $form->addHidden('date', $DATE); 1198 $form->addHidden('prefix', $PRE); 1199 $form->addHidden('suffix', $SUF); 1200 $form->addHidden('changecheck', $check); 1201 $attr = array('tabindex'=>'1'); 1202 if (!$wr) $attr['readonly'] = 'readonly'; 1203 $form->addElement(form_makeWikiText($text, $attr)); 1204 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); 1205 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1206 $form->addElement(form_makeCloseTag('div')); 1207 if ($wr) { 1208 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1209 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1210 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1211 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1212 $form->addElement(form_makeCloseTag('div')); 1213 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1214 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1215 $elem = html_minoredit(); 1216 if ($elem) $form->addElement($elem); 1217 $form->addElement(form_makeCloseTag('div')); 1218 } 1219 $form->addElement(form_makeCloseTag('div')); 1220 if($conf['license']){ 1221 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1222 $out = $lang['licenseok']; 1223 $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1224 if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"'; 1225 $out .= '> '.$license[$conf['license']]['name'].'</a>'; 1226 $form->addElement($out); 1227 $form->addElement(form_makeCloseTag('div')); 1228 } 1229 html_form('edit', $form); 1230 print '</div>'.NL; 1231} 1232 1233/** 1234 * Adds a checkbox for minor edits for logged in users 1235 * 1236 * @author Andrea Gohr <andi@splitbrain.org> 1237 */ 1238function html_minoredit(){ 1239 global $conf; 1240 global $lang; 1241 // minor edits are for logged in users only 1242 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1243 return false; 1244 } 1245 1246 $p = array(); 1247 $p['tabindex'] = 3; 1248 if(!empty($_REQUEST['minor'])) $p['checked']='checked'; 1249 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1250} 1251 1252/** 1253 * prints some debug info 1254 * 1255 * @author Andreas Gohr <andi@splitbrain.org> 1256 */ 1257function html_debug(){ 1258 global $conf; 1259 global $lang; 1260 global $auth; 1261 global $INFO; 1262 1263 //remove sensitive data 1264 $cnf = $conf; 1265 debug_guard($cnf); 1266 $nfo = $INFO; 1267 debug_guard($nfo); 1268 $ses = $_SESSION; 1269 debug_guard($ses); 1270 1271 print '<html><body>'; 1272 1273 print '<p>When reporting bugs please send all the following '; 1274 print 'output as a mail to andi@splitbrain.org '; 1275 print 'The best way to do this is to save this page in your browser</p>'; 1276 1277 print '<b>$INFO:</b><pre>'; 1278 print_r($nfo); 1279 print '</pre>'; 1280 1281 print '<b>$_SERVER:</b><pre>'; 1282 print_r($_SERVER); 1283 print '</pre>'; 1284 1285 print '<b>$conf:</b><pre>'; 1286 print_r($cnf); 1287 print '</pre>'; 1288 1289 print '<b>DOKU_BASE:</b><pre>'; 1290 print DOKU_BASE; 1291 print '</pre>'; 1292 1293 print '<b>abs DOKU_BASE:</b><pre>'; 1294 print DOKU_URL; 1295 print '</pre>'; 1296 1297 print '<b>rel DOKU_BASE:</b><pre>'; 1298 print dirname($_SERVER['PHP_SELF']).'/'; 1299 print '</pre>'; 1300 1301 print '<b>PHP Version:</b><pre>'; 1302 print phpversion(); 1303 print '</pre>'; 1304 1305 print '<b>locale:</b><pre>'; 1306 print setlocale(LC_ALL,0); 1307 print '</pre>'; 1308 1309 print '<b>encoding:</b><pre>'; 1310 print $lang['encoding']; 1311 print '</pre>'; 1312 1313 if($auth){ 1314 print '<b>Auth backend capabilities:</b><pre>'; 1315 print_r($auth->cando); 1316 print '</pre>'; 1317 } 1318 1319 print '<b>$_SESSION:</b><pre>'; 1320 print_r($ses); 1321 print '</pre>'; 1322 1323 print '<b>Environment:</b><pre>'; 1324 print_r($_ENV); 1325 print '</pre>'; 1326 1327 print '<b>PHP settings:</b><pre>'; 1328 $inis = ini_get_all(); 1329 print_r($inis); 1330 print '</pre>'; 1331 1332 print '</body></html>'; 1333} 1334 1335function html_admin(){ 1336 global $ID; 1337 global $INFO; 1338 global $lang; 1339 global $conf; 1340 1341 print p_locale_xhtml('admin'); 1342 1343 // build menu of admin functions from the plugins that handle them 1344 $pluginlist = plugin_list('admin'); 1345 $menu = array(); 1346 foreach ($pluginlist as $p) { 1347 if($obj =& plugin_load('admin',$p) === NULL) continue; 1348 1349 // check permissions 1350 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1351 1352 $menu[] = array('plugin' => $p, 1353 'prompt' => $obj->getMenuText($conf['lang']), 1354 'sort' => $obj->getMenuSort() 1355 ); 1356 } 1357 1358 usort($menu, 'p_sort_modes'); 1359 1360 // output the menu 1361 ptln('<ul>'); 1362 1363 foreach ($menu as $item) { 1364 if (!$item['prompt']) continue; 1365 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1366 } 1367 1368 ptln('</ul>'); 1369} 1370 1371/** 1372 * Form to request a new password for an existing account 1373 * 1374 * @author Benoit Chesneau <benoit@bchesneau.info> 1375 */ 1376function html_resendpwd() { 1377 global $lang; 1378 global $conf; 1379 global $ID; 1380 1381 print p_locale_xhtml('resendpwd'); 1382 print '<div class="centeralign">'.NL; 1383 $form = new Doku_Form('dw__resendpwd', wl($ID)); 1384 $form->startFieldset($lang['resendpwd']); 1385 $form->addHidden('do', 'resendpwd'); 1386 $form->addHidden('save', '1'); 1387 $form->addElement(form_makeTag('br')); 1388 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block')); 1389 $form->addElement(form_makeTag('br')); 1390 $form->addElement(form_makeTag('br')); 1391 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1392 $form->endFieldset(); 1393 html_form('resendpwd', $form); 1394 print '</div>'.NL; 1395} 1396 1397/** 1398 * Return the TOC rendered to XHTML 1399 * 1400 * @author Andreas Gohr <andi@splitbrain.org> 1401 */ 1402function html_TOC($toc){ 1403 if(!count($toc)) return ''; 1404 global $lang; 1405 $out = '<!-- TOC START -->'.DOKU_LF; 1406 $out .= '<div class="toc">'.DOKU_LF; 1407 $out .= '<div class="tocheader toctoggle" id="toc__header">'; 1408 $out .= $lang['toc']; 1409 $out .= '</div>'.DOKU_LF; 1410 $out .= '<div id="toc__inside">'.DOKU_LF; 1411 $out .= html_buildlist($toc,'toc','html_list_toc'); 1412 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1413 $out .= '<!-- TOC END -->'.DOKU_LF; 1414 return $out; } 1415 1416/** 1417 * Callback for html_buildlist 1418 */ 1419function html_list_toc($item){ 1420 if($item['hid']){ 1421 $link = '#'.$item['hid']; 1422 }else{ 1423 $link = $item['link']; 1424 } 1425 1426 return '<span class="li"><a href="'.$link.'" class="toc">'. 1427 hsc($item['title']).'</a></span>'; 1428} 1429 1430/** 1431 * Helper function to build TOC items 1432 * 1433 * Returns an array ready to be added to a TOC array 1434 * 1435 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1436 * @param string $text - what to display in the TOC 1437 * @param int $level - nesting level 1438 * @param string $hash - is prepended to the given $link, set blank if you want full links 1439 */ 1440function html_mktocitem($link, $text, $level, $hash='#'){ 1441 global $conf; 1442 return array( 'link' => $hash.$link, 1443 'title' => $text, 1444 'type' => 'ul', 1445 'level' => $level); 1446} 1447 1448/** 1449 * Output a Doku_Form object. 1450 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1451 * 1452 * @author Tom N Harris <tnharris@whoopdedo.org> 1453 */ 1454function html_form($name, &$form) { 1455 // Safety check in case the caller forgets. 1456 $form->endFieldset(); 1457 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1458} 1459 1460/** 1461 * Form print function. 1462 * Just calls printForm() on the data object. 1463 */ 1464function html_form_output($data) { 1465 $data->printForm(); 1466} 1467 1468/** 1469 * Embed a flash object in HTML 1470 * 1471 * This will create the needed HTML to embed a flash movie in a cross browser 1472 * compatble way using valid XHTML 1473 * 1474 * The parameters $params, $flashvars and $atts need to be associative arrays. 1475 * No escaping needs to be done for them. The alternative content *has* to be 1476 * escaped because it is used as is. If no alternative content is given 1477 * $lang['noflash'] is used. 1478 * 1479 * @author Andreas Gohr <andi@splitbrain.org> 1480 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 1481 * 1482 * @param string $swf - the SWF movie to embed 1483 * @param int $width - width of the flash movie in pixels 1484 * @param int $height - height of the flash movie in pixels 1485 * @param array $params - additional parameters (<param>) 1486 * @param array $flashvars - parameters to be passed in the flashvar parameter 1487 * @param array $atts - additional attributes for the <object> tag 1488 * @param string $alt - alternative content (is NOT automatically escaped!) 1489 * @returns string - the XHTML markup 1490 */ 1491function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 1492 global $lang; 1493 1494 $out = ''; 1495 1496 // prepare the object attributes 1497 if(is_null($atts)) $atts = array(); 1498 $atts['width'] = (int) $width; 1499 $atts['height'] = (int) $height; 1500 if(!$atts['width']) $atts['width'] = 425; 1501 if(!$atts['height']) $atts['height'] = 350; 1502 1503 // add object attributes for standard compliant browsers 1504 $std = $atts; 1505 $std['type'] = 'application/x-shockwave-flash'; 1506 $std['data'] = $swf; 1507 1508 // add object attributes for IE 1509 $ie = $atts; 1510 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 1511 1512 // open object (with conditional comments) 1513 $out .= '<!--[if !IE]> -->'.NL; 1514 $out .= '<object '.buildAttributes($std).'>'.NL; 1515 $out .= '<!-- <![endif]-->'.NL; 1516 $out .= '<!--[if IE]>'.NL; 1517 $out .= '<object '.buildAttributes($ie).'>'.NL; 1518 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 1519 $out .= '<!--><!-- -->'.NL; 1520 1521 // print params 1522 if(is_array($params)) foreach($params as $key => $val){ 1523 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 1524 } 1525 1526 // add flashvars 1527 if(is_array($flashvars)){ 1528 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 1529 } 1530 1531 // alternative content 1532 if($alt){ 1533 $out .= $alt.NL; 1534 }else{ 1535 $out .= $lang['noflash'].NL; 1536 } 1537 1538 // finish 1539 $out .= '</object>'.NL; 1540 $out .= '<!-- <![endif]-->'.NL; 1541 1542 return $out; 1543} 1544 1545//Setup VIM: ex: et ts=2 enc=utf-8 : 1546