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