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