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