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