1<?php 2/** 3 * HTML output functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9if(!defined('DOKU_INC')) die('meh.'); 10if(!defined('NL')) define('NL',"\n"); 11 12/** 13 * Convenience function to quickly build a wikilink 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 * @param string $id id of the target page 17 * @param string $name the name of the link, i.e. the text that is displayed 18 * @param string|array $search search string(s) that shall be highlighted in the target page 19 * @return string the HTML code of the link 20 */ 21function html_wikilink($id,$name=null,$search=''){ 22 static $xhtml_renderer = null; 23 if(is_null($xhtml_renderer)){ 24 $xhtml_renderer = p_get_renderer('xhtml'); 25 } 26 27 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); 28} 29 30/** 31 * The loginform 32 * 33 * @author Andreas Gohr <andi@splitbrain.org> 34 */ 35function html_login(){ 36 global $lang; 37 global $conf; 38 global $ID; 39 global $INPUT; 40 41 print p_locale_xhtml('login'); 42 print '<div class="centeralign">'.NL; 43 $form = new Doku_Form(array('id' => 'dw__login')); 44 $form->startFieldset($lang['btn_login']); 45 $form->addHidden('id', $ID); 46 $form->addHidden('do', 'login'); 47 $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block')); 48 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); 49 if($conf['rememberme']) { 50 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); 51 } 52 $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); 53 $form->endFieldset(); 54 55 if(actionOK('register')){ 56 $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>'); 57 } 58 59 if (actionOK('resendpwd')) { 60 $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>'); 61 } 62 63 html_form('login', $form); 64 print '</div>'.NL; 65} 66 67 68/** 69 * Denied page content 70 * 71 * @return string html 72 */ 73function html_denied() { 74 global $lang; 75 $denied = p_locale_xhtml('denied'); 76 $notloggedin = isset($_SERVER['REMOTE_USER']) ? '' : $lang['notloggedin']; 77 78 $denied = str_replace( 79 array('@NOTLOGGEDIN@'), 80 array($notloggedin), 81 $denied 82 ); 83 print $denied; 84} 85 86/** 87 * inserts section edit buttons if wanted or removes the markers 88 * 89 * @author Andreas Gohr <andi@splitbrain.org> 90 */ 91function html_secedit($text,$show=true){ 92 global $INFO; 93 94 $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; 95 96 if(!$INFO['writable'] || !$show || $INFO['rev']){ 97 return preg_replace($regexp,'',$text); 98 } 99 100 return preg_replace_callback($regexp, 101 'html_secedit_button', $text); 102} 103 104/** 105 * prepares section edit button data for event triggering 106 * used as a callback in html_secedit 107 * 108 * @triggers HTML_SECEDIT_BUTTON 109 * @author Andreas Gohr <andi@splitbrain.org> 110 */ 111function html_secedit_button($matches){ 112 $data = array('secid' => $matches[1], 113 'target' => strtolower($matches[2]), 114 'range' => $matches[count($matches) - 1]); 115 if (count($matches) === 5) { 116 $data['name'] = $matches[3]; 117 } 118 119 return trigger_event('HTML_SECEDIT_BUTTON', $data, 120 'html_secedit_get_button'); 121} 122 123/** 124 * prints a section editing button 125 * used as default action form HTML_SECEDIT_BUTTON 126 * 127 * @author Adrian Lang <lang@cosmocode.de> 128 */ 129function html_secedit_get_button($data) { 130 global $ID; 131 global $INFO; 132 133 if (!isset($data['name']) || $data['name'] === '') return ''; 134 135 $name = $data['name']; 136 unset($data['name']); 137 138 $secid = $data['secid']; 139 unset($data['secid']); 140 141 return "<div class='secedit editbutton_" . $data['target'] . 142 " editbutton_" . $secid . "'>" . 143 html_btn('secedit', $ID, '', 144 array_merge(array('do' => 'edit', 145 'rev' => $INFO['lastmod'], 146 'summary' => '['.$name.'] '), $data), 147 'post', $name) . '</div>'; 148} 149 150/** 151 * Just the back to top button (in its own form) 152 * 153 * @author Andreas Gohr <andi@splitbrain.org> 154 */ 155function html_topbtn(){ 156 global $lang; 157 158 $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>'; 159 160 return $ret; 161} 162 163/** 164 * Displays a button (using its own form) 165 * If tooltip exists, the access key tooltip is replaced. 166 * 167 * @author Andreas Gohr <andi@splitbrain.org> 168 */ 169function html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){ 170 global $conf; 171 global $lang; 172 173 if (!$label) 174 $label = $lang['btn_'.$name]; 175 176 $ret = ''; 177 178 //filter id (without urlencoding) 179 $id = idfilter($id,false); 180 181 //make nice URLs even for buttons 182 if($conf['userewrite'] == 2){ 183 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 184 }elseif($conf['userewrite']){ 185 $script = DOKU_BASE.$id; 186 }else{ 187 $script = DOKU_BASE.DOKU_SCRIPT; 188 $params['id'] = $id; 189 } 190 191 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 192 193 if(is_array($params)){ 194 reset($params); 195 while (list($key, $val) = each($params)) { 196 $ret .= '<input type="hidden" name="'.$key.'" '; 197 $ret .= 'value="'.htmlspecialchars($val).'" />'; 198 } 199 } 200 201 if ($tooltip!='') { 202 $tip = htmlspecialchars($tooltip); 203 }else{ 204 $tip = htmlspecialchars($label); 205 } 206 207 $ret .= '<input type="submit" value="'.hsc($label).'" class="button" '; 208 if($akey){ 209 $tip .= ' ['.strtoupper($akey).']'; 210 $ret .= 'accesskey="'.$akey.'" '; 211 } 212 $ret .= 'title="'.$tip.'" '; 213 $ret .= '/>'; 214 $ret .= '</div></form>'; 215 216 return $ret; 217} 218 219/** 220 * show a wiki page 221 * 222 * @author Andreas Gohr <andi@splitbrain.org> 223 */ 224function html_show($txt=null){ 225 global $ID; 226 global $REV; 227 global $HIGH; 228 global $INFO; 229 //disable section editing for old revisions or in preview 230 if($txt || $REV){ 231 $secedit = false; 232 }else{ 233 $secedit = true; 234 } 235 236 if (!is_null($txt)){ 237 //PreviewHeader 238 echo '<br id="scroll__here" />'; 239 echo p_locale_xhtml('preview'); 240 echo '<div class="preview"><div class="pad">'; 241 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 242 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 243 echo $html; 244 echo '<div class="clearer"></div>'; 245 echo '</div></div>'; 246 247 }else{ 248 if ($REV) print p_locale_xhtml('showrev'); 249 $html = p_wiki_xhtml($ID,$REV,true); 250 $html = html_secedit($html,$secedit); 251 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 252 $html = html_hilight($html,$HIGH); 253 echo $html; 254 } 255} 256 257/** 258 * ask the user about how to handle an exisiting draft 259 * 260 * @author Andreas Gohr <andi@splitbrain.org> 261 */ 262function html_draft(){ 263 global $INFO; 264 global $ID; 265 global $lang; 266 $draft = unserialize(io_readFile($INFO['draft'],false)); 267 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 268 269 print p_locale_xhtml('draft'); 270 $form = new Doku_Form(array('id' => 'dw__editform')); 271 $form->addHidden('id', $ID); 272 $form->addHidden('date', $draft['date']); 273 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); 274 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 275 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft']))); 276 $form->addElement(form_makeCloseTag('div')); 277 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 278 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 279 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 280 html_form('draft', $form); 281} 282 283/** 284 * Highlights searchqueries in HTML code 285 * 286 * @author Andreas Gohr <andi@splitbrain.org> 287 * @author Harry Fuecks <hfuecks@gmail.com> 288 */ 289function html_hilight($html,$phrases){ 290 $phrases = (array) $phrases; 291 $phrases = array_map('preg_quote_cb', $phrases); 292 $phrases = array_map('ft_snippet_re_preprocess', $phrases); 293 $phrases = array_filter($phrases); 294 $regex = join('|',$phrases); 295 296 if ($regex === '') return $html; 297 if (!utf8_check($regex)) return $html; 298 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 299 return $html; 300} 301 302/** 303 * Callback used by html_hilight() 304 * 305 * @author Harry Fuecks <hfuecks@gmail.com> 306 */ 307function html_hilight_callback($m) { 308 $hlight = unslash($m[0]); 309 if ( !isset($m[2])) { 310 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 311 } 312 return $hlight; 313} 314 315/** 316 * Run a search and display the result 317 * 318 * @author Andreas Gohr <andi@splitbrain.org> 319 */ 320function html_search(){ 321 global $QUERY; 322 global $lang; 323 324 $intro = p_locale_xhtml('searchpage'); 325 // allow use of placeholder in search intro 326 $intro = str_replace( 327 array('@QUERY@','@SEARCH@'), 328 array(hsc(rawurlencode($QUERY)),hsc($QUERY)), 329 $intro); 330 echo $intro; 331 flush(); 332 333 //show progressbar 334 print '<div id="dw__loading">'.NL; 335 print '<script type="text/javascript">/*<![CDATA[*/'.NL; 336 print 'showLoadBar();'.NL; 337 print '/*!]]>*/</script>'.NL; 338 print '</div>'.NL; 339 flush(); 340 341 //do quick pagesearch 342 $data = ft_pageLookup($QUERY,true,useHeading('navigation')); 343 if(count($data)){ 344 print '<div class="search_quickresult">'; 345 print '<h3>'.$lang['quickhits'].':</h3>'; 346 print '<ul class="search_quickhits">'; 347 foreach($data as $id => $title){ 348 print '<li> '; 349 if (useHeading('navigation')) { 350 $name = $title; 351 }else{ 352 $ns = getNS($id); 353 if($ns){ 354 $name = shorten(noNS($id), ' ('.$ns.')',30); 355 }else{ 356 $name = $id; 357 } 358 } 359 print html_wikilink(':'.$id,$name); 360 print '</li> '; 361 } 362 print '</ul> '; 363 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 364 print '<div class="clearer"></div>'; 365 print '</div>'; 366 } 367 flush(); 368 369 //do fulltext search 370 $data = ft_pageSearch($QUERY,$regex); 371 if(count($data)){ 372 print '<dl class="search_results">'; 373 $num = 1; 374 foreach($data as $id => $cnt){ 375 print '<dt>'; 376 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex); 377 if($cnt !== 0){ 378 print ': '.$cnt.' '.$lang['hits'].''; 379 } 380 print '</dt>'; 381 if($cnt !== 0){ 382 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only 383 print '<dd>'.ft_snippet($id,$regex).'</dd>'; 384 } 385 $num++; 386 } 387 flush(); 388 } 389 print '</dl>'; 390 }else{ 391 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 392 } 393 394 //hide progressbar 395 print '<script type="text/javascript">/*<![CDATA[*/'.NL; 396 print 'hideLoadBar("dw__loading");'.NL; 397 print '/*!]]>*/</script>'.NL; 398 flush(); 399} 400 401/** 402 * Display error on locked pages 403 * 404 * @author Andreas Gohr <andi@splitbrain.org> 405 */ 406function html_locked(){ 407 global $ID; 408 global $conf; 409 global $lang; 410 global $INFO; 411 412 $locktime = filemtime(wikiLockFN($ID)); 413 $expire = dformat($locktime + $conf['locktime']); 414 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 415 416 print p_locale_xhtml('locked'); 417 print '<ul>'; 418 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>'; 419 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 420 print '</ul>'; 421} 422 423/** 424 * list old revisions 425 * 426 * @author Andreas Gohr <andi@splitbrain.org> 427 * @author Ben Coburn <btcoburn@silicodon.net> 428 * @author Kate Arzamastseva <pshns@ukr.net> 429 */ 430function html_revisions($first=0, $media_id = false){ 431 global $ID; 432 global $INFO; 433 global $conf; 434 global $lang; 435 $id = $ID; 436 /* we need to get one additional log entry to be able to 437 * decide if this is the last page or is there another one. 438 * see html_recent() 439 */ 440 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); 441 else { 442 $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); 443 $id = $media_id; 444 } 445 446 if(count($revisions)==0 && $first!=0){ 447 $first=0; 448 if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); 449 else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); 450 } 451 $hasNext = false; 452 if (count($revisions)>$conf['recent']) { 453 $hasNext = true; 454 array_pop($revisions); // remove extra log entry 455 } 456 457 if (!$media_id) $date = dformat($INFO['lastmod']); 458 else $date = dformat(@filemtime(mediaFN($id))); 459 460 if (!$media_id) print p_locale_xhtml('revisions'); 461 462 $params = array('id' => 'page__revisions', 'class' => 'changes'); 463 if ($media_id) $params['action'] = media_managerURL(array('image' => $media_id), '&'); 464 465 $form = new Doku_Form($params); 466 $form->addElement(form_makeOpenTag('ul')); 467 468 if (!$media_id) $exists = $INFO['exists']; 469 else $exists = @file_exists(mediaFN($id)); 470 471 $display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id; 472 if (!$display_name) $display_name = $id; 473 474 if($exists && $first==0){ 475 if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 476 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 477 else 478 $form->addElement(form_makeOpenTag('li')); 479 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 480 $form->addElement(form_makeTag('input', array( 481 'type' => 'checkbox', 482 'name' => 'rev2[]', 483 'value' => 'current'))); 484 485 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 486 $form->addElement($date); 487 $form->addElement(form_makeCloseTag('span')); 488 489 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 490 491 if (!$media_id) $href = wl($id); 492 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); 493 $form->addElement(form_makeOpenTag('a', array( 494 'class' => 'wikilink1', 495 'href' => $href))); 496 $form->addElement($display_name); 497 $form->addElement(form_makeCloseTag('a')); 498 499 if ($media_id) $form->addElement(form_makeOpenTag('div')); 500 501 if (!$media_id) { 502 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 503 $form->addElement(' – '); 504 $form->addElement(htmlspecialchars($INFO['sum'])); 505 $form->addElement(form_makeCloseTag('span')); 506 } 507 508 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 509 if (!$media_id) $editor = $INFO['editor']; 510 else { 511 $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true); 512 if($revinfo['user']){ 513 $editor = $revinfo['user']; 514 }else{ 515 $editor = $revinfo['ip']; 516 } 517 } 518 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor)); 519 $form->addElement(form_makeCloseTag('span')); 520 521 $form->addElement('('.$lang['current'].')'); 522 523 if ($media_id) $form->addElement(form_makeCloseTag('div')); 524 525 $form->addElement(form_makeCloseTag('div')); 526 $form->addElement(form_makeCloseTag('li')); 527 } 528 529 foreach($revisions as $rev){ 530 $date = dformat($rev); 531 if (!$media_id) { 532 $info = getRevisionInfo($id,$rev,true); 533 $exists = page_exists($id,$rev); 534 } else { 535 $info = getRevisionInfo($id,$rev,true,true); 536 $exists = @file_exists(mediaFN($id,$rev)); 537 } 538 539 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 540 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 541 else 542 $form->addElement(form_makeOpenTag('li')); 543 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 544 if($exists){ 545 $form->addElement(form_makeTag('input', array( 546 'type' => 'checkbox', 547 'name' => 'rev2[]', 548 'value' => $rev))); 549 }else{ 550 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 551 } 552 553 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 554 $form->addElement($date); 555 $form->addElement(form_makeCloseTag('span')); 556 557 if($exists){ 558 if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&'); 559 else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); 560 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link'))); 561 $form->addElement(form_makeTag('img', array( 562 'src' => DOKU_BASE.'lib/images/diff.png', 563 'width' => 15, 564 'height' => 11, 565 'title' => $lang['diff'], 566 'alt' => $lang['diff']))); 567 $form->addElement(form_makeCloseTag('a')); 568 if (!$media_id) $href = wl($id,"rev=$rev",false,'&'); 569 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); 570 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1'))); 571 $form->addElement($display_name); 572 $form->addElement(form_makeCloseTag('a')); 573 }else{ 574 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 575 $form->addElement($display_name); 576 } 577 578 if ($media_id) $form->addElement(form_makeOpenTag('div')); 579 580 if ($info['sum']) { 581 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 582 if (!$media_id) $form->addElement(' – '); 583 $form->addElement('<bdi>'.htmlspecialchars($info['sum']).'</bdi>'); 584 $form->addElement(form_makeCloseTag('span')); 585 } 586 587 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 588 if($info['user']){ 589 $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>'); 590 if(auth_ismanager()){ 591 $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>'); 592 } 593 }else{ 594 $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>'); 595 } 596 $form->addElement(form_makeCloseTag('span')); 597 598 if ($media_id) $form->addElement(form_makeCloseTag('div')); 599 600 $form->addElement(form_makeCloseTag('div')); 601 $form->addElement(form_makeCloseTag('li')); 602 } 603 $form->addElement(form_makeCloseTag('ul')); 604 if (!$media_id) { 605 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 606 } else { 607 $form->addHidden('mediado', 'diff'); 608 $form->addElement(form_makeButton('submit', '', $lang['diff2'])); 609 } 610 html_form('revisions', $form); 611 612 print '<div class="pagenav">'; 613 $last = $first + $conf['recent']; 614 if ($first > 0) { 615 $first -= $conf['recent']; 616 if ($first < 0) $first = 0; 617 print '<div class="pagenav-prev">'; 618 if ($media_id) { 619 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&', false, true)); 620 } else { 621 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first)); 622 } 623 print '</div>'; 624 } 625 if ($hasNext) { 626 print '<div class="pagenav-next">'; 627 if ($media_id) { 628 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&', false, true)); 629 } else { 630 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last)); 631 } 632 print '</div>'; 633 } 634 print '</div>'; 635 636} 637 638/** 639 * display recent changes 640 * 641 * @author Andreas Gohr <andi@splitbrain.org> 642 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 643 * @author Ben Coburn <btcoburn@silicodon.net> 644 * @author Kate Arzamastseva <pshns@ukr.net> 645 */ 646function html_recent($first=0, $show_changes='both'){ 647 global $conf; 648 global $lang; 649 global $ID; 650 /* we need to get one additionally log entry to be able to 651 * decide if this is the last page or is there another one. 652 * This is the cheapest solution to get this information. 653 */ 654 $flags = 0; 655 if ($show_changes == 'mediafiles' && $conf['mediarevisions']) { 656 $flags = RECENTS_MEDIA_CHANGES; 657 } elseif ($show_changes == 'pages') { 658 $flags = 0; 659 } elseif ($conf['mediarevisions']) { 660 $show_changes = 'both'; 661 $flags = RECENTS_MEDIA_PAGES_MIXED; 662 } 663 664 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 665 if(count($recents) == 0 && $first != 0){ 666 $first=0; 667 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 668 } 669 $hasNext = false; 670 if (count($recents)>$conf['recent']) { 671 $hasNext = true; 672 array_pop($recents); // remove extra log entry 673 } 674 675 print p_locale_xhtml('recent'); 676 677 if (getNS($ID) != '') 678 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 679 680 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes')); 681 $form->addHidden('sectok', null); 682 $form->addHidden('do', 'recent'); 683 $form->addHidden('id', $ID); 684 685 if ($conf['mediarevisions']) { 686 $form->addElement('<div class="changeType">'); 687 $form->addElement(form_makeListboxField( 688 'show_changes', 689 array( 690 'pages' => $lang['pages_changes'], 691 'mediafiles' => $lang['media_changes'], 692 'both' => $lang['both_changes']), 693 $show_changes, 694 $lang['changes_type'], 695 '','', 696 array('class'=>'quickselect'))); 697 698 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply'])); 699 $form->addElement('</div>'); 700 } 701 702 $form->addElement(form_makeOpenTag('ul')); 703 704 foreach($recents as $recent){ 705 $date = dformat($recent['date']); 706 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 707 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 708 else 709 $form->addElement(form_makeOpenTag('li')); 710 711 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 712 713 if ($recent['media']) { 714 $form->addElement(media_printicon($recent['id'])); 715 } else { 716 $icon = DOKU_BASE.'lib/images/fileicons/file.png'; 717 $form->addElement('<img src="'.$icon.'" alt="'.$recent['id'].'" class="icon" />'); 718 } 719 720 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 721 $form->addElement($date); 722 $form->addElement(form_makeCloseTag('span')); 723 724 $diff = false; 725 $href = ''; 726 727 if ($recent['media']) { 728 $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id']))); 729 if ($diff) { 730 $href = media_managerURL(array('tab_details' => 'history', 731 'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 732 } 733 } else { 734 $href = wl($recent['id'],"do=diff", false, '&'); 735 } 736 737 if ($recent['media'] && !$diff) { 738 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 739 } else { 740 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href))); 741 $form->addElement(form_makeTag('img', array( 742 'src' => DOKU_BASE.'lib/images/diff.png', 743 'width' => 15, 744 'height'=> 11, 745 'title' => $lang['diff'], 746 'alt' => $lang['diff'] 747 ))); 748 $form->addElement(form_makeCloseTag('a')); 749 } 750 751 if ($recent['media']) { 752 $href = media_managerURL(array('tab_details' => 'history', 753 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 754 } else { 755 $href = wl($recent['id'],"do=revisions",false,'&'); 756 } 757 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => $href))); 758 $form->addElement(form_makeTag('img', array( 759 'src' => DOKU_BASE.'lib/images/history.png', 760 'width' => 12, 761 'height'=> 14, 762 'title' => $lang['btn_revs'], 763 'alt' => $lang['btn_revs'] 764 ))); 765 $form->addElement(form_makeCloseTag('a')); 766 767 if ($recent['media']) { 768 $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 769 $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2'; 770 $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href))); 771 $form->addElement($recent['id']); 772 $form->addElement(form_makeCloseTag('a')); 773 } else { 774 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id'])); 775 } 776 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 777 $form->addElement(' – '.htmlspecialchars($recent['sum'])); 778 $form->addElement(form_makeCloseTag('span')); 779 780 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 781 if($recent['user']){ 782 $form->addElement('<bdi>'.editorinfo($recent['user']).'</bdi>'); 783 if(auth_ismanager()){ 784 $form->addElement(' <bdo dir="ltr">('.$recent['ip'].')</bdo>'); 785 } 786 }else{ 787 $form->addElement('<bdo dir="ltr">'.$recent['ip'].'</bdo>'); 788 } 789 $form->addElement(form_makeCloseTag('span')); 790 791 $form->addElement(form_makeCloseTag('div')); 792 $form->addElement(form_makeCloseTag('li')); 793 } 794 $form->addElement(form_makeCloseTag('ul')); 795 796 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 797 $last = $first + $conf['recent']; 798 if ($first > 0) { 799 $first -= $conf['recent']; 800 if ($first < 0) $first = 0; 801 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 802 $form->addElement(form_makeTag('input', array( 803 'type' => 'submit', 804 'name' => 'first['.$first.']', 805 'value' => $lang['btn_newer'], 806 'accesskey' => 'n', 807 'title' => $lang['btn_newer'].' [N]', 808 'class' => 'button show' 809 ))); 810 $form->addElement(form_makeCloseTag('div')); 811 } 812 if ($hasNext) { 813 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 814 $form->addElement(form_makeTag('input', array( 815 'type' => 'submit', 816 'name' => 'first['.$last.']', 817 'value' => $lang['btn_older'], 818 'accesskey' => 'p', 819 'title' => $lang['btn_older'].' [P]', 820 'class' => 'button show' 821 ))); 822 $form->addElement(form_makeCloseTag('div')); 823 } 824 $form->addElement(form_makeCloseTag('div')); 825 html_form('recent', $form); 826} 827 828/** 829 * Display page index 830 * 831 * @author Andreas Gohr <andi@splitbrain.org> 832 */ 833function html_index($ns){ 834 global $conf; 835 global $ID; 836 $ns = cleanID($ns); 837 #fixme use appropriate function 838 if(empty($ns)){ 839 $ns = dirname(str_replace(':','/',$ID)); 840 if($ns == '.') $ns =''; 841 } 842 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 843 844 echo p_locale_xhtml('index'); 845 echo '<div id="index__tree">'; 846 847 $data = array(); 848 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 849 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 850 851 echo '</div>'; 852} 853 854/** 855 * Index item formatter 856 * 857 * User function for html_buildlist() 858 * 859 * @author Andreas Gohr <andi@splitbrain.org> 860 */ 861function html_list_index($item){ 862 global $ID, $conf; 863 864 // prevent searchbots needlessly following links 865 $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : ''; 866 867 $ret = ''; 868 $base = ':'.$item['id']; 869 $base = substr($base,strrpos($base,':')+1); 870 if($item['type']=='d'){ 871 // FS#2766, no need for search bots to follow namespace links in the index 872 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>'; 873 $ret .= $base; 874 $ret .= '</strong></a>'; 875 }else{ 876 // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605 877 $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id'])); 878 } 879 return $ret; 880} 881 882/** 883 * Index List item 884 * 885 * This user function is used in html_buildlist to build the 886 * <li> tags for namespaces when displaying the page index 887 * it gives different classes to opened or closed "folders" 888 * 889 * @author Andreas Gohr <andi@splitbrain.org> 890 */ 891function html_li_index($item){ 892 if($item['type'] == "f"){ 893 return '<li class="level'.$item['level'].'">'; 894 }elseif($item['open']){ 895 return '<li class="open">'; 896 }else{ 897 return '<li class="closed">'; 898 } 899} 900 901/** 902 * Default List item 903 * 904 * @author Andreas Gohr <andi@splitbrain.org> 905 */ 906function html_li_default($item){ 907 return '<li class="level'.$item['level'].'">'; 908} 909 910/** 911 * Build an unordered list 912 * 913 * Build an unordered list from the given $data array 914 * Each item in the array has to have a 'level' property 915 * the item itself gets printed by the given $func user 916 * function. The second and optional function is used to 917 * print the <li> tag. Both user function need to accept 918 * a single item. 919 * 920 * Both user functions can be given as array to point to 921 * a member of an object. 922 * 923 * @author Andreas Gohr <andi@splitbrain.org> 924 */ 925function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){ 926 if (count($data) === 0) { 927 return ''; 928 } 929 930 $start_level = $data[0]['level']; 931 $level = $start_level; 932 $ret = ''; 933 $open = 0; 934 935 foreach ($data as $item){ 936 937 if( $item['level'] > $level ){ 938 //open new list 939 for($i=0; $i<($item['level'] - $level); $i++){ 940 if ($i) $ret .= "<li class=\"clear\">"; 941 $ret .= "\n<ul class=\"$class\">\n"; 942 $open++; 943 } 944 $level = $item['level']; 945 946 }elseif( $item['level'] < $level ){ 947 //close last item 948 $ret .= "</li>\n"; 949 while( $level > $item['level'] && $open > 0 ){ 950 //close higher lists 951 $ret .= "</ul>\n</li>\n"; 952 $level--; 953 $open--; 954 } 955 } elseif ($ret !== '') { 956 //close previous item 957 $ret .= "</li>\n"; 958 } 959 960 //print item 961 $ret .= call_user_func($lifunc,$item); 962 $ret .= '<div class="li">'; 963 964 $ret .= call_user_func($func,$item); 965 $ret .= '</div>'; 966 } 967 968 //close remaining items and lists 969 $ret .= "</li>\n"; 970 while($open-- > 0) { 971 $ret .= "</ul></li>\n"; 972 } 973 974 if ($forcewrapper || $start_level < 2) { 975 // Trigger building a wrapper ul if the first level is 976 // 0 (we have a root object) or 1 (just the root content) 977 $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n"; 978 } 979 980 return $ret; 981} 982 983/** 984 * display backlinks 985 * 986 * @author Andreas Gohr <andi@splitbrain.org> 987 * @author Michael Klier <chi@chimeric.de> 988 */ 989function html_backlinks(){ 990 global $ID; 991 global $lang; 992 993 print p_locale_xhtml('backlinks'); 994 995 $data = ft_backlinks($ID); 996 997 if(!empty($data)) { 998 print '<ul class="idx">'; 999 foreach($data as $blink){ 1000 print '<li><div class="li">'; 1001 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 1002 print '</div></li>'; 1003 } 1004 print '</ul>'; 1005 } else { 1006 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 1007 } 1008} 1009 1010/** 1011 * Get header of diff HTML 1012 * @param string $l_rev Left revisions 1013 * @param string $r_rev Right revision 1014 * @param string $id Page id, if null $ID is used 1015 * @param bool $media If it is for media files 1016 * @param bool $inline Return the header on a single line 1017 * @return array HTML snippets for diff header 1018 */ 1019function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) { 1020 global $lang; 1021 if ($id === null) { 1022 global $ID; 1023 $id = $ID; 1024 } 1025 $head_separator = $inline ? ' ' : '<br />'; 1026 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN'; 1027 $ml_or_wl = $media ? 'ml' : 'wl'; 1028 $l_minor = $r_minor = ''; 1029 1030 if(!$l_rev){ 1031 $l_head = '—'; 1032 }else{ 1033 $l_info = getRevisionInfo($id,$l_rev,true, $media); 1034 if($l_info['user']){ 1035 $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>'; 1036 if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>'; 1037 } else { 1038 $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>'; 1039 } 1040 $l_user = '<span class="user">'.$l_user.'</span>'; 1041 $l_sum = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : ''; 1042 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 1043 1044 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']'; 1045 $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'. 1046 $l_head_title.'</a></bdi>'. 1047 $head_separator.$l_user.' '.$l_sum; 1048 } 1049 1050 if($r_rev){ 1051 $r_info = getRevisionInfo($id,$r_rev,true, $media); 1052 if($r_info['user']){ 1053 $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>'; 1054 if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>'; 1055 } else { 1056 $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>'; 1057 } 1058 $r_user = '<span class="user">'.$r_user.'</span>'; 1059 $r_sum = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : ''; 1060 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1061 1062 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']'; 1063 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'. 1064 $r_head_title.'</a></bdi>'. 1065 $head_separator.$r_user.' '.$r_sum; 1066 }elseif($_rev = @filemtime($media_or_wikiFN($id))){ 1067 $_info = getRevisionInfo($id,$_rev,true, $media); 1068 if($_info['user']){ 1069 $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>'; 1070 if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>'; 1071 } else { 1072 $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>'; 1073 } 1074 $_user = '<span class="user">'.$_user.'</span>'; 1075 $_sum = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : ''; 1076 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1077 1078 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']'; 1079 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'. 1080 $r_head_title.'</a></bdi> '. 1081 '('.$lang['current'].')'. 1082 $head_separator.$_user.' '.$_sum; 1083 }else{ 1084 $r_head = '— ('.$lang['current'].')'; 1085 } 1086 1087 return array($l_head, $r_head, $l_minor, $r_minor); 1088} 1089 1090/** 1091 * show diff 1092 * 1093 * @author Andreas Gohr <andi@splitbrain.org> 1094 * @param string $text - compare with this text with most current version 1095 * @param bool $intro - display the intro text 1096 * @param string $type type of the diff (inline or sidebyside) 1097 */ 1098function html_diff($text='',$intro=true,$type=null){ 1099 global $ID; 1100 global $REV; 1101 global $lang; 1102 global $INPUT; 1103 global $INFO; 1104 1105 if(!$type) { 1106 $type = $INPUT->str('difftype'); 1107 if (empty($type)) { 1108 $type = get_doku_pref('difftype', $type); 1109 if (empty($type) && $INFO['ismobile']) { 1110 $type = 'inline'; 1111 } 1112 } 1113 } 1114 if($type != 'inline') $type = 'sidebyside'; 1115 1116 // we're trying to be clever here, revisions to compare can be either 1117 // given as rev and rev2 parameters, with rev2 being optional. Or in an 1118 // array in rev2. 1119 $rev1 = $REV; 1120 1121 $rev2 = $INPUT->ref('rev2'); 1122 if(is_array($rev2)){ 1123 $rev1 = (int) $rev2[0]; 1124 $rev2 = (int) $rev2[1]; 1125 1126 if(!$rev1){ 1127 $rev1 = $rev2; 1128 unset($rev2); 1129 } 1130 }else{ 1131 $rev2 = $INPUT->int('rev2'); 1132 } 1133 1134 $r_minor = ''; 1135 $l_minor = ''; 1136 1137 if($text){ // compare text to the most current revision 1138 $l_rev = ''; 1139 $l_text = rawWiki($ID,''); 1140 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 1141 $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '. 1142 $lang['current']; 1143 1144 $r_rev = ''; 1145 $r_text = cleanText($text); 1146 $r_head = $lang['yours']; 1147 }else{ 1148 if($rev1 && isset($rev2) && $rev2){ // two specific revisions wanted 1149 // make sure order is correct (older on the left) 1150 if($rev1 < $rev2){ 1151 $l_rev = $rev1; 1152 $r_rev = $rev2; 1153 }else{ 1154 $l_rev = $rev2; 1155 $r_rev = $rev1; 1156 } 1157 }elseif($rev1){ // single revision given, compare to current 1158 $r_rev = ''; 1159 $l_rev = $rev1; 1160 }else{ // no revision was given, compare previous to current 1161 $r_rev = ''; 1162 $revs = getRevisions($ID, 0, 1); 1163 $l_rev = $revs[0]; 1164 $REV = $l_rev; // store revision back in $REV 1165 } 1166 1167 // when both revisions are empty then the page was created just now 1168 if(!$l_rev && !$r_rev){ 1169 $l_text = ''; 1170 }else{ 1171 $l_text = rawWiki($ID,$l_rev); 1172 } 1173 $r_text = rawWiki($ID,$r_rev); 1174 1175 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline'); 1176 } 1177 1178 $df = new Diff(explode("\n",$l_text),explode("\n",$r_text)); 1179 1180 if($type == 'inline'){ 1181 $tdf = new InlineDiffFormatter(); 1182 } else { 1183 $tdf = new TableDiffFormatter(); 1184 } 1185 1186 if($intro) print p_locale_xhtml('diff'); 1187 1188 if (!$text) { 1189 ptln('<div class="diffoptions">'); 1190 1191 $form = new Doku_Form(array('action'=>wl())); 1192 $form->addHidden('id',$ID); 1193 $form->addHidden('rev2[0]',$l_rev); 1194 $form->addHidden('rev2[1]',$r_rev); 1195 $form->addHidden('do','diff'); 1196 $form->addElement(form_makeListboxField( 1197 'difftype', 1198 array( 1199 'sidebyside' => $lang['diff_side'], 1200 'inline' => $lang['diff_inline']), 1201 $type, 1202 $lang['diff_type'], 1203 '','', 1204 array('class'=>'quickselect'))); 1205 $form->addElement(form_makeButton('submit', 'diff','Go')); 1206 $form->printForm(); 1207 1208 $diffurl = wl($ID, array( 1209 'do' => 'diff', 1210 'rev2[0]' => $l_rev, 1211 'rev2[1]' => $r_rev ? $r_rev : $INFO['currentrev'], // link to exactly this view FS#2835 1212 'difftype' => $type, 1213 )); 1214 ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>'); 1215 ptln('</div>'); 1216 } 1217 ?> 1218 <div class="table"> 1219 <table class="diff diff_<?php echo $type?>"> 1220 <?php if ($type == 'inline') { ?> 1221 <tr> 1222 <th class="diff-lineheader">-</th><th <?php echo $l_minor?>> 1223 <?php echo $l_head?> 1224 </th> 1225 </tr> 1226 <tr> 1227 <th class="diff-lineheader">+</th><th <?php echo $r_minor?>> 1228 <?php echo $r_head?> 1229 </th> 1230 </tr> 1231 <?php } else { ?> 1232 <tr> 1233 <th colspan="2" <?php echo $l_minor?>> 1234 <?php echo $l_head?> 1235 </th> 1236 <th colspan="2" <?php echo $r_minor?>> 1237 <?php echo $r_head?> 1238 </th> 1239 </tr> 1240 <?php } 1241 echo html_insert_softbreaks($tdf->format($df)); ?> 1242 </table> 1243 </div> 1244 <?php 1245} 1246 1247function html_insert_softbreaks($diffhtml) { 1248 // search the diff html string for both: 1249 // - html tags, so these can be ignored 1250 // - long strings of characters without breaking characters 1251 return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml); 1252} 1253 1254function html_softbreak_callback($match){ 1255 // if match is an html tag, return it intact 1256 if ($match[0]{0} == '<') return $match[0]; 1257 1258 // its a long string without a breaking character, 1259 // make certain characters into breaking characters by inserting a 1260 // breaking character (zero length space, U+200B / #8203) in front them. 1261 $regex = <<< REGEX 1262(?(?= # start a conditional expression with a positive look ahead ... 1263&\#?\\w{1,6};) # ... for html entities - we don't want to split them (ok to catch some invalid combinations) 1264&\#?\\w{1,6}; # yes pattern - a quicker match for the html entity, since we know we have one 1265| 1266[?/,&\#;:] # no pattern - any other group of 'special' characters to insert a breaking character after 1267)+ # end conditional expression 1268REGEX; 1269 1270 return preg_replace('<'.$regex.'>xu','\0​',$match[0]); 1271} 1272 1273/** 1274 * show warning on conflict detection 1275 * 1276 * @author Andreas Gohr <andi@splitbrain.org> 1277 */ 1278function html_conflict($text,$summary){ 1279 global $ID; 1280 global $lang; 1281 1282 print p_locale_xhtml('conflict'); 1283 $form = new Doku_Form(array('id' => 'dw__editform')); 1284 $form->addHidden('id', $ID); 1285 $form->addHidden('wikitext', $text); 1286 $form->addHidden('summary', $summary); 1287 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1288 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1289 html_form('conflict', $form); 1290 print '<br /><br /><br /><br />'.NL; 1291} 1292 1293/** 1294 * Prints the global message array 1295 * 1296 * @author Andreas Gohr <andi@splitbrain.org> 1297 */ 1298function html_msgarea(){ 1299 global $MSG, $MSG_shown; 1300 /** @var array $MSG */ 1301 // store if the global $MSG has already been shown and thus HTML output has been started 1302 $MSG_shown = true; 1303 1304 if(!isset($MSG)) return; 1305 1306 $shown = array(); 1307 foreach($MSG as $msg){ 1308 $hash = md5($msg['msg']); 1309 if(isset($shown[$hash])) continue; // skip double messages 1310 if(info_msg_allowed($msg)){ 1311 print '<div class="'.$msg['lvl'].'">'; 1312 print $msg['msg']; 1313 print '</div>'; 1314 } 1315 $shown[$hash] = 1; 1316 } 1317 1318 unset($GLOBALS['MSG']); 1319} 1320 1321/** 1322 * Prints the registration form 1323 * 1324 * @author Andreas Gohr <andi@splitbrain.org> 1325 */ 1326function html_register(){ 1327 global $lang; 1328 global $conf; 1329 global $INPUT; 1330 1331 $base_attrs = array('size'=>50,'required'=>'required'); 1332 $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit'); 1333 1334 print p_locale_xhtml('register'); 1335 print '<div class="centeralign">'.NL; 1336 $form = new Doku_Form(array('id' => 'dw__register')); 1337 $form->startFieldset($lang['btn_register']); 1338 $form->addHidden('do', 'register'); 1339 $form->addHidden('save', '1'); 1340 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs)); 1341 if (!$conf['autopasswd']) { 1342 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs)); 1343 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs)); 1344 } 1345 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs)); 1346 $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs)); 1347 $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); 1348 $form->endFieldset(); 1349 html_form('register', $form); 1350 1351 print '</div>'.NL; 1352} 1353 1354/** 1355 * Print the update profile form 1356 * 1357 * @author Christopher Smith <chris@jalakai.co.uk> 1358 * @author Andreas Gohr <andi@splitbrain.org> 1359 */ 1360function html_updateprofile(){ 1361 global $lang; 1362 global $conf; 1363 global $INPUT; 1364 global $INFO; 1365 /** @var auth_basic $auth */ 1366 global $auth; 1367 1368 print p_locale_xhtml('updateprofile'); 1369 print '<div class="centeralign">'.NL; 1370 1371 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true); 1372 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true); 1373 $form = new Doku_Form(array('id' => 'dw__register')); 1374 $form->startFieldset($lang['profile']); 1375 $form->addHidden('do', 'profile'); 1376 $form->addHidden('save', '1'); 1377 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1378 $attr = array('size'=>'50'); 1379 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1380 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr)); 1381 $attr = array('size'=>'50', 'class'=>'edit'); 1382 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1383 $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr)); 1384 $form->addElement(form_makeTag('br')); 1385 if ($auth->canDo('modPass')) { 1386 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1387 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1388 } 1389 if ($conf['profileconfirm']) { 1390 $form->addElement(form_makeTag('br')); 1391 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required'))); 1392 } 1393 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1394 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1395 1396 $form->endFieldset(); 1397 html_form('updateprofile', $form); 1398 1399 if ($auth->canDo('delUser') && actionOK('profile_delete')) { 1400 $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete')); 1401 $form_profiledelete->startFieldset($lang['profdeleteuser']); 1402 $form_profiledelete->addHidden('do', 'profile_delete'); 1403 $form_profiledelete->addHidden('delete', '1'); 1404 $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required'))); 1405 if ($conf['profileconfirm']) { 1406 $form_profiledelete->addElement(form_makeTag('br')); 1407 $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required'))); 1408 } 1409 $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser'])); 1410 $form_profiledelete->endFieldset(); 1411 1412 html_form('profiledelete', $form_profiledelete); 1413 } 1414 1415 print '</div>'.NL; 1416} 1417 1418/** 1419 * Preprocess edit form data 1420 * 1421 * @author Andreas Gohr <andi@splitbrain.org> 1422 * 1423 * @triggers HTML_EDITFORM_OUTPUT 1424 */ 1425function html_edit(){ 1426 global $INPUT; 1427 global $ID; 1428 global $REV; 1429 global $DATE; 1430 global $PRE; 1431 global $SUF; 1432 global $INFO; 1433 global $SUM; 1434 global $lang; 1435 global $conf; 1436 global $TEXT; 1437 global $RANGE; 1438 1439 if ($INPUT->has('changecheck')) { 1440 $check = $INPUT->str('changecheck'); 1441 } elseif(!$INFO['exists']){ 1442 // $TEXT has been loaded from page template 1443 $check = md5(''); 1444 } else { 1445 $check = md5($TEXT); 1446 } 1447 $mod = md5($TEXT) !== $check; 1448 1449 $wr = $INFO['writable'] && !$INFO['locked']; 1450 $include = 'edit'; 1451 if($wr){ 1452 if ($REV) $include = 'editrev'; 1453 }else{ 1454 // check pseudo action 'source' 1455 if(!actionOK('source')){ 1456 msg('Command disabled: source',-1); 1457 return; 1458 } 1459 $include = 'read'; 1460 } 1461 1462 global $license; 1463 1464 $form = new Doku_Form(array('id' => 'dw__editform')); 1465 $form->addHidden('id', $ID); 1466 $form->addHidden('rev', $REV); 1467 $form->addHidden('date', $DATE); 1468 $form->addHidden('prefix', $PRE . '.'); 1469 $form->addHidden('suffix', $SUF); 1470 $form->addHidden('changecheck', $check); 1471 1472 $data = array('form' => $form, 1473 'wr' => $wr, 1474 'media_manager' => true, 1475 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section', 1476 'intro_locale' => $include); 1477 1478 if ($data['target'] !== 'section') { 1479 // Only emit event if page is writable, section edit data is valid and 1480 // edit target is not section. 1481 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1482 } else { 1483 html_edit_form($data); 1484 } 1485 if (isset($data['intro_locale'])) { 1486 echo p_locale_xhtml($data['intro_locale']); 1487 } 1488 1489 $form->addHidden('target', $data['target']); 1490 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar'))); 1491 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1492 $form->addElement(form_makeCloseTag('div')); 1493 if ($wr) { 1494 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1495 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1496 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1497 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1498 $form->addElement(form_makeCloseTag('div')); 1499 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1500 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1501 $elem = html_minoredit(); 1502 if ($elem) $form->addElement($elem); 1503 $form->addElement(form_makeCloseTag('div')); 1504 } 1505 $form->addElement(form_makeCloseTag('div')); 1506 if($wr && $conf['license']){ 1507 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1508 $out = $lang['licenseok']; 1509 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1510 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; 1511 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 1512 $form->addElement($out); 1513 $form->addElement(form_makeCloseTag('div')); 1514 } 1515 1516 if ($wr) { 1517 // sets changed to true when previewed 1518 echo '<script type="text/javascript">/*<![CDATA[*/'. NL; 1519 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1520 echo '/*!]]>*/</script>' . NL; 1521 } ?> 1522 <div class="editBox" role="application"> 1523 1524 <div class="toolbar group"> 1525 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1526 <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1527 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1528 </div> 1529 <?php 1530 1531 html_form('edit', $form); 1532 print '</div>'.NL; 1533} 1534 1535/** 1536 * Display the default edit form 1537 * 1538 * Is the default action for HTML_EDIT_FORMSELECTION. 1539 */ 1540function html_edit_form($param) { 1541 global $TEXT; 1542 1543 if ($param['target'] !== 'section') { 1544 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1); 1545 } 1546 1547 $attr = array('tabindex'=>'1'); 1548 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1549 1550 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1551} 1552 1553/** 1554 * Adds a checkbox for minor edits for logged in users 1555 * 1556 * @author Andreas Gohr <andi@splitbrain.org> 1557 */ 1558function html_minoredit(){ 1559 global $conf; 1560 global $lang; 1561 global $INPUT; 1562 // minor edits are for logged in users only 1563 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1564 return false; 1565 } 1566 1567 $p = array(); 1568 $p['tabindex'] = 3; 1569 if($INPUT->bool('minor')) $p['checked']='checked'; 1570 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1571} 1572 1573/** 1574 * prints some debug info 1575 * 1576 * @author Andreas Gohr <andi@splitbrain.org> 1577 */ 1578function html_debug(){ 1579 global $conf; 1580 global $lang; 1581 /** @var auth_basic $auth */ 1582 global $auth; 1583 global $INFO; 1584 1585 //remove sensitive data 1586 $cnf = $conf; 1587 debug_guard($cnf); 1588 $nfo = $INFO; 1589 debug_guard($nfo); 1590 $ses = $_SESSION; 1591 debug_guard($ses); 1592 1593 print '<html><body>'; 1594 1595 print '<p>When reporting bugs please send all the following '; 1596 print 'output as a mail to andi@splitbrain.org '; 1597 print 'The best way to do this is to save this page in your browser</p>'; 1598 1599 print '<b>$INFO:</b><pre>'; 1600 print_r($nfo); 1601 print '</pre>'; 1602 1603 print '<b>$_SERVER:</b><pre>'; 1604 print_r($_SERVER); 1605 print '</pre>'; 1606 1607 print '<b>$conf:</b><pre>'; 1608 print_r($cnf); 1609 print '</pre>'; 1610 1611 print '<b>DOKU_BASE:</b><pre>'; 1612 print DOKU_BASE; 1613 print '</pre>'; 1614 1615 print '<b>abs DOKU_BASE:</b><pre>'; 1616 print DOKU_URL; 1617 print '</pre>'; 1618 1619 print '<b>rel DOKU_BASE:</b><pre>'; 1620 print dirname($_SERVER['PHP_SELF']).'/'; 1621 print '</pre>'; 1622 1623 print '<b>PHP Version:</b><pre>'; 1624 print phpversion(); 1625 print '</pre>'; 1626 1627 print '<b>locale:</b><pre>'; 1628 print setlocale(LC_ALL,0); 1629 print '</pre>'; 1630 1631 print '<b>encoding:</b><pre>'; 1632 print $lang['encoding']; 1633 print '</pre>'; 1634 1635 if($auth){ 1636 print '<b>Auth backend capabilities:</b><pre>'; 1637 foreach ($auth->getCapabilities() as $cando){ 1638 print ' '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL; 1639 } 1640 print '</pre>'; 1641 } 1642 1643 print '<b>$_SESSION:</b><pre>'; 1644 print_r($ses); 1645 print '</pre>'; 1646 1647 print '<b>Environment:</b><pre>'; 1648 print_r($_ENV); 1649 print '</pre>'; 1650 1651 print '<b>PHP settings:</b><pre>'; 1652 $inis = ini_get_all(); 1653 print_r($inis); 1654 print '</pre>'; 1655 1656 if (function_exists('apache_get_version')) { 1657 $apache['version'] = apache_get_version(); 1658 1659 if (function_exists('apache_get_modules')) { 1660 $apache['modules'] = apache_get_modules(); 1661 } 1662 print '<b>Apache</b><pre>'; 1663 print_r($apache); 1664 print '</pre>'; 1665 } 1666 1667 print '</body></html>'; 1668} 1669 1670/** 1671 * List available Administration Tasks 1672 * 1673 * @author Andreas Gohr <andi@splitbrain.org> 1674 * @author Håkan Sandell <hakan.sandell@home.se> 1675 */ 1676function html_admin(){ 1677 global $ID; 1678 global $INFO; 1679 global $conf; 1680 /** @var DokuWiki_Auth_Plugin $auth */ 1681 global $auth; 1682 1683 // build menu of admin functions from the plugins that handle them 1684 $pluginlist = plugin_list('admin'); 1685 $menu = array(); 1686 foreach ($pluginlist as $p) { 1687 /** @var DokuWiki_Admin_Plugin $obj */ 1688 if(($obj = plugin_load('admin',$p)) === null) continue; 1689 1690 // check permissions 1691 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1692 1693 $menu[$p] = array('plugin' => $p, 1694 'prompt' => $obj->getMenuText($conf['lang']), 1695 'sort' => $obj->getMenuSort() 1696 ); 1697 } 1698 1699 // data security check 1700 // simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 1701 // it verifies either: 1702 // 'savedir' has been moved elsewhere, or 1703 // has protection to prevent the webserver serving files from it 1704 if (substr($conf['savedir'],0,2) == './'){ 1705 echo '<a style="border:none; float:right;" 1706 href="http://www.dokuwiki.org/security#web_access_security"> 1707 <img src="'.DOKU_URL.$conf['savedir'].'/security.png" alt="Your data directory seems to be protected properly." 1708 onerror="this.parentNode.style.display=\'none\'" /></a>'; 1709 } 1710 1711 print p_locale_xhtml('admin'); 1712 1713 // Admin Tasks 1714 if($INFO['isadmin']){ 1715 ptln('<ul class="admin_tasks">'); 1716 1717 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 1718 ptln(' <li class="admin_usermanager"><div class="li">'. 1719 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 1720 $menu['usermanager']['prompt'].'</a></div></li>'); 1721 } 1722 unset($menu['usermanager']); 1723 1724 if($menu['acl']){ 1725 ptln(' <li class="admin_acl"><div class="li">'. 1726 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 1727 $menu['acl']['prompt'].'</a></div></li>'); 1728 } 1729 unset($menu['acl']); 1730 1731 if($menu['extension']){ 1732 ptln(' <li class="admin_plugin"><div class="li">'. 1733 '<a href="'.wl($ID, array('do' => 'admin','page' => 'extension')).'">'. 1734 $menu['extension']['prompt'].'</a></div></li>'); 1735 } 1736 unset($menu['extension']); 1737 1738 if($menu['config']){ 1739 ptln(' <li class="admin_config"><div class="li">'. 1740 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 1741 $menu['config']['prompt'].'</a></div></li>'); 1742 } 1743 unset($menu['config']); 1744 } 1745 ptln('</ul>'); 1746 1747 // Manager Tasks 1748 ptln('<ul class="admin_tasks">'); 1749 1750 if($menu['revert']){ 1751 ptln(' <li class="admin_revert"><div class="li">'. 1752 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 1753 $menu['revert']['prompt'].'</a></div></li>'); 1754 } 1755 unset($menu['revert']); 1756 1757 if($menu['popularity']){ 1758 ptln(' <li class="admin_popularity"><div class="li">'. 1759 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 1760 $menu['popularity']['prompt'].'</a></div></li>'); 1761 } 1762 unset($menu['popularity']); 1763 1764 // print DokuWiki version: 1765 ptln('</ul>'); 1766 echo '<div id="admin__version">'; 1767 echo getVersion(); 1768 echo '</div>'; 1769 1770 // print the rest as sorted list 1771 if(count($menu)){ 1772 usort($menu, 'p_sort_modes'); 1773 // output the menu 1774 ptln('<div class="clearer"></div>'); 1775 print p_locale_xhtml('adminplugins'); 1776 ptln('<ul>'); 1777 foreach ($menu as $item) { 1778 if (!$item['prompt']) continue; 1779 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1780 } 1781 ptln('</ul>'); 1782 } 1783} 1784 1785/** 1786 * Form to request a new password for an existing account 1787 * 1788 * @author Benoit Chesneau <benoit@bchesneau.info> 1789 * @author Andreas Gohr <gohr@cosmocode.de> 1790 */ 1791function html_resendpwd() { 1792 global $lang; 1793 global $conf; 1794 global $INPUT; 1795 1796 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth')); 1797 1798 if(!$conf['autopasswd'] && $token){ 1799 print p_locale_xhtml('resetpwd'); 1800 print '<div class="centeralign">'.NL; 1801 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1802 $form->startFieldset($lang['btn_resendpwd']); 1803 $form->addHidden('token', $token); 1804 $form->addHidden('do', 'resendpwd'); 1805 1806 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1807 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1808 1809 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1810 $form->endFieldset(); 1811 html_form('resendpwd', $form); 1812 print '</div>'.NL; 1813 }else{ 1814 print p_locale_xhtml('resendpwd'); 1815 print '<div class="centeralign">'.NL; 1816 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1817 $form->startFieldset($lang['resendpwd']); 1818 $form->addHidden('do', 'resendpwd'); 1819 $form->addHidden('save', '1'); 1820 $form->addElement(form_makeTag('br')); 1821 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block')); 1822 $form->addElement(form_makeTag('br')); 1823 $form->addElement(form_makeTag('br')); 1824 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1825 $form->endFieldset(); 1826 html_form('resendpwd', $form); 1827 print '</div>'.NL; 1828 } 1829} 1830 1831/** 1832 * Return the TOC rendered to XHTML 1833 * 1834 * @author Andreas Gohr <andi@splitbrain.org> 1835 */ 1836function html_TOC($toc){ 1837 if(!count($toc)) return ''; 1838 global $lang; 1839 $out = '<!-- TOC START -->'.DOKU_LF; 1840 $out .= '<div id="dw__toc">'.DOKU_LF; 1841 $out .= '<h3 class="toggle">'; 1842 $out .= $lang['toc']; 1843 $out .= '</h3>'.DOKU_LF; 1844 $out .= '<div>'.DOKU_LF; 1845 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); 1846 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1847 $out .= '<!-- TOC END -->'.DOKU_LF; 1848 return $out; 1849} 1850 1851/** 1852 * Callback for html_buildlist 1853 */ 1854function html_list_toc($item){ 1855 if(isset($item['hid'])){ 1856 $link = '#'.$item['hid']; 1857 }else{ 1858 $link = $item['link']; 1859 } 1860 1861 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 1862} 1863 1864/** 1865 * Helper function to build TOC items 1866 * 1867 * Returns an array ready to be added to a TOC array 1868 * 1869 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1870 * @param string $text - what to display in the TOC 1871 * @param int $level - nesting level 1872 * @param string $hash - is prepended to the given $link, set blank if you want full links 1873 * @return array the toc item 1874 */ 1875function html_mktocitem($link, $text, $level, $hash='#'){ 1876 return array( 'link' => $hash.$link, 1877 'title' => $text, 1878 'type' => 'ul', 1879 'level' => $level); 1880} 1881 1882/** 1883 * Output a Doku_Form object. 1884 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1885 * 1886 * @author Tom N Harris <tnharris@whoopdedo.org> 1887 * @param string $name The name of the form 1888 * @param Doku_Form $form The form 1889 */ 1890function html_form($name, &$form) { 1891 // Safety check in case the caller forgets. 1892 $form->endFieldset(); 1893 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1894} 1895 1896/** 1897 * Form print function. 1898 * Just calls printForm() on the data object. 1899 * @param Doku_Form $data The form 1900 */ 1901function html_form_output($data) { 1902 $data->printForm(); 1903} 1904 1905/** 1906 * Embed a flash object in HTML 1907 * 1908 * This will create the needed HTML to embed a flash movie in a cross browser 1909 * compatble way using valid XHTML 1910 * 1911 * The parameters $params, $flashvars and $atts need to be associative arrays. 1912 * No escaping needs to be done for them. The alternative content *has* to be 1913 * escaped because it is used as is. If no alternative content is given 1914 * $lang['noflash'] is used. 1915 * 1916 * @author Andreas Gohr <andi@splitbrain.org> 1917 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 1918 * 1919 * @param string $swf - the SWF movie to embed 1920 * @param int $width - width of the flash movie in pixels 1921 * @param int $height - height of the flash movie in pixels 1922 * @param array $params - additional parameters (<param>) 1923 * @param array $flashvars - parameters to be passed in the flashvar parameter 1924 * @param array $atts - additional attributes for the <object> tag 1925 * @param string $alt - alternative content (is NOT automatically escaped!) 1926 * @return string - the XHTML markup 1927 */ 1928function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 1929 global $lang; 1930 1931 $out = ''; 1932 1933 // prepare the object attributes 1934 if(is_null($atts)) $atts = array(); 1935 $atts['width'] = (int) $width; 1936 $atts['height'] = (int) $height; 1937 if(!$atts['width']) $atts['width'] = 425; 1938 if(!$atts['height']) $atts['height'] = 350; 1939 1940 // add object attributes for standard compliant browsers 1941 $std = $atts; 1942 $std['type'] = 'application/x-shockwave-flash'; 1943 $std['data'] = $swf; 1944 1945 // add object attributes for IE 1946 $ie = $atts; 1947 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 1948 1949 // open object (with conditional comments) 1950 $out .= '<!--[if !IE]> -->'.NL; 1951 $out .= '<object '.buildAttributes($std).'>'.NL; 1952 $out .= '<!-- <![endif]-->'.NL; 1953 $out .= '<!--[if IE]>'.NL; 1954 $out .= '<object '.buildAttributes($ie).'>'.NL; 1955 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 1956 $out .= '<!--><!-- -->'.NL; 1957 1958 // print params 1959 if(is_array($params)) foreach($params as $key => $val){ 1960 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 1961 } 1962 1963 // add flashvars 1964 if(is_array($flashvars)){ 1965 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 1966 } 1967 1968 // alternative content 1969 if($alt){ 1970 $out .= $alt.NL; 1971 }else{ 1972 $out .= $lang['noflash'].NL; 1973 } 1974 1975 // finish 1976 $out .= '</object>'.NL; 1977 $out .= '<!-- <![endif]-->'.NL; 1978 1979 return $out; 1980} 1981 1982/** 1983 * Prints HTML code for the given tab structure 1984 * 1985 * @param array $tabs tab structure 1986 * @param string $current_tab the current tab id 1987 */ 1988function html_tabs($tabs, $current_tab = null) { 1989 echo '<ul class="tabs">'.NL; 1990 1991 foreach($tabs as $id => $tab) { 1992 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 1993 } 1994 1995 echo '</ul>'.NL; 1996} 1997/** 1998 * Prints a single tab 1999 * 2000 * @author Kate Arzamastseva <pshns@ukr.net> 2001 * @author Adrian Lang <mail@adrianlang.de> 2002 * 2003 * @param string $href - tab href 2004 * @param string $caption - tab caption 2005 * @param boolean $selected - is tab selected 2006 */ 2007 2008function html_tab($href, $caption, $selected=false) { 2009 $tab = '<li>'; 2010 if ($selected) { 2011 $tab .= '<strong>'; 2012 } else { 2013 $tab .= '<a href="' . hsc($href) . '">'; 2014 } 2015 $tab .= hsc($caption) 2016 . '</' . ($selected ? 'strong' : 'a') . '>' 2017 . '</li>'.NL; 2018 echo $tab; 2019} 2020 2021