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 9use dokuwiki\ChangeLog\MediaChangeLog; 10use dokuwiki\ChangeLog\PageChangeLog; 11use dokuwiki\Extension\AuthPlugin; 12use dokuwiki\Extension\Event; 13 14if (!defined('SEC_EDIT_PATTERN')) { 15 define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#'); 16} 17 18 19/** 20 * Convenience function to quickly build a wikilink 21 * 22 * @author Andreas Gohr <andi@splitbrain.org> 23 * @param string $id id of the target page 24 * @param string $name the name of the link, i.e. the text that is displayed 25 * @param string|array $search search string(s) that shall be highlighted in the target page 26 * @return string the HTML code of the link 27 */ 28function html_wikilink($id, $name = null, $search = '') { 29 /** @var Doku_Renderer_xhtml $xhtml_renderer */ 30 static $xhtml_renderer = null; 31 if (is_null($xhtml_renderer)) { 32 $xhtml_renderer = p_get_renderer('xhtml'); 33 } 34 35 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); 36} 37 38/** 39 * The loginform 40 * 41 * @author Andreas Gohr <andi@splitbrain.org> 42 * 43 * @param bool $svg Whether to show svg icons in the register and resendpwd links or not 44 * @deprecated 2020-07-18 45 */ 46function html_login($svg = false) { 47 dbg_deprecated(\dokuwiki\Ui\Login::class .'::show()'); 48 (new dokuwiki\Ui\Login($svg))->show(); 49} 50 51 52/** 53 * Denied page content 54 * 55 * @return string html 56 * @deprecated 2020-07-18 not called anymore, see inc/Action/Denied::tplContent() 57 */ 58function html_denied() { 59 dbg_deprecated(\dokuwiki\Action\Denied::class .'::showBanner()'); 60 (new dokuwiki\Action\Denied())->showBanner(); 61} 62 63/** 64 * inserts section edit buttons if wanted or removes the markers 65 * 66 * @author Andreas Gohr <andi@splitbrain.org> 67 * 68 * @param string $text 69 * @param bool $show show section edit buttons? 70 * @return string 71 */ 72function html_secedit($text, $show = true) { 73 global $INFO; 74 75 if ((isset($INFO) && !$INFO['writable']) || !$show || (isset($INFO) && $INFO['rev'])) { 76 return preg_replace(SEC_EDIT_PATTERN,'',$text); 77 } 78 79 return preg_replace_callback(SEC_EDIT_PATTERN, 80 'html_secedit_button', $text); 81} 82 83/** 84 * prepares section edit button data for event triggering 85 * used as a callback in html_secedit 86 * 87 * @author Andreas Gohr <andi@splitbrain.org> 88 * 89 * @param array $matches matches with regexp 90 * @return string 91 * @triggers HTML_SECEDIT_BUTTON 92 */ 93function html_secedit_button($matches){ 94 $json = htmlspecialchars_decode($matches[1], ENT_QUOTES); 95 $data = json_decode($json, true); 96 if ($data == NULL) { 97 return; 98 } 99 $data ['target'] = strtolower($data['target']); 100 $data ['hid'] = strtolower($data['hid']); 101 102 return Event::createAndTrigger('HTML_SECEDIT_BUTTON', $data, 103 'html_secedit_get_button'); 104} 105 106/** 107 * prints a section editing button 108 * used as default action form HTML_SECEDIT_BUTTON 109 * 110 * @author Adrian Lang <lang@cosmocode.de> 111 * 112 * @param array $data name, section id and target 113 * @return string html 114 */ 115function html_secedit_get_button($data) { 116 global $ID; 117 global $INFO; 118 119 if (!isset($data['name']) || $data['name'] === '') return ''; 120 121 $name = $data['name']; 122 unset($data['name']); 123 124 $secid = $data['secid']; 125 unset($data['secid']); 126 127 $params = array_merge( 128 array('do' => 'edit', 'rev' => $INFO['lastmod'], 'summary' => '['.$name.'] '), 129 $data 130 ); 131 132 $html = '<div class="secedit editbutton_'.$data['target'] .' editbutton_'.$secid .'">'; 133 $html.= html_btn('secedit', $ID, '', $params, 'post', $name); 134 $html.= '</div>'; 135 return $html; 136} 137 138/** 139 * Just the back to top button (in its own form) 140 * 141 * @author Andreas Gohr <andi@splitbrain.org> 142 * 143 * @return string html 144 */ 145function html_topbtn() { 146 global $lang; 147 148 $html = '<a class="nolink" href="#dokuwiki__top">' 149 .'<button class="button" onclick="window.scrollTo(0, 0)" title="'. $lang['btn_top'] .'">' 150 . $lang['btn_top'] 151 .'</button></a>'; 152 return $html; 153} 154 155/** 156 * Displays a button (using its own form) 157 * If tooltip exists, the access key tooltip is replaced. 158 * 159 * @author Andreas Gohr <andi@splitbrain.org> 160 * 161 * @param string $name 162 * @param string $id 163 * @param string $akey access key 164 * @param string[] $params key-value pairs added as hidden inputs 165 * @param string $method 166 * @param string $tooltip 167 * @param bool|string $label label text, false: lookup btn_$name in localization 168 * @param string $svg (optional) svg code, inserted into the button 169 * @return string 170 */ 171function html_btn($name, $id, $akey, $params, $method = 'get', $tooltip = '', $label = false, $svg = null) { 172 global $conf; 173 global $lang; 174 175 if (!$label) 176 $label = $lang['btn_'.$name]; 177 178 //filter id (without urlencoding) 179 $id = idfilter($id,false); 180 181 //make nice URLs even for buttons 182 if ($conf['userewrite'] == 2) { 183 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 184 } elseif ($conf['userewrite']) { 185 $script = DOKU_BASE.$id; 186 } else { 187 $script = DOKU_BASE.DOKU_SCRIPT; 188 $params['id'] = $id; 189 } 190 191 $html = '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 192 193 if (is_array($params)) { 194 foreach ($params as $key => $val) { 195 $html .= '<input type="hidden" name="'.$key.'" value="'.hsc($val).'" />'; 196 } 197 } 198 199 $tip = empty($tooltip) ? hsc($label) : hsc($tooltip); 200 201 $html .= '<button type="submit" '; 202 if ($akey) { 203 $tip .= ' ['.strtoupper($akey).']'; 204 $html .= 'accesskey="'.$akey.'" '; 205 } 206 $html .= 'title="'.$tip.'">'; 207 if ($svg) { 208 $html .= '<span>'. hsc($label) .'</span>'. inlineSVG($svg); 209 } else { 210 $html .= hsc($label); 211 } 212 $html .= '</button>'; 213 $html .= '</div></form>'; 214 215 return $html; 216} 217/** 218 * show a revision warning 219 * 220 * @author Szymon Olewniczak <dokuwiki@imz.re> 221 * @deprecated 2020-07-18 222 */ 223function html_showrev() { 224 dbg_deprecated(\dokuwiki\Ui\PageView::class .'::showrev()'); 225} 226 227/** 228 * Show a wiki page 229 * 230 * @author Andreas Gohr <andi@splitbrain.org> 231 * 232 * @param null|string $txt wiki text or null for showing $ID 233 * @deprecated 2020-07-18 234 */ 235function html_show($txt=null) { 236 dbg_deprecated(\dokuwiki\Ui\PageView::class .'::show()'); 237 (new dokuwiki\Ui\PageView($txt))->show(); 238} 239 240/** 241 * ask the user about how to handle an exisiting draft 242 * 243 * @author Andreas Gohr <andi@splitbrain.org> 244 * @deprecated 2020-07-18 245 */ 246function html_draft() { 247 dbg_deprecated(\dokuwiki\Ui\Draft::class .'::show()'); 248 (new dokuwiki\Ui\Draft)->show(); 249} 250 251/** 252 * Highlights searchqueries in HTML code 253 * 254 * @author Andreas Gohr <andi@splitbrain.org> 255 * @author Harry Fuecks <hfuecks@gmail.com> 256 * 257 * @param string $html 258 * @param array|string $phrases 259 * @return string html 260 */ 261function html_hilight($html, $phrases) { 262 $phrases = (array) $phrases; 263 $phrases = array_map('preg_quote_cb', $phrases); 264 $phrases = array_map('ft_snippet_re_preprocess', $phrases); 265 $phrases = array_filter($phrases); 266 $regex = join('|',$phrases); 267 268 if ($regex === '') return $html; 269 if (!\dokuwiki\Utf8\Clean::isUtf8($regex)) return $html; 270 271 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui", function ($match) { 272 $hlight = unslash($match[0]); 273 if (!isset($match[2])) { 274 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 275 } 276 return $hlight; 277 }, $html); 278 return $html; 279} 280 281/** 282 * Display error on locked pages 283 * 284 * @author Andreas Gohr <andi@splitbrain.org> 285 * @deprecated 2020-07-18 not called anymore, see inc/Action/Locked::tplContent() 286 */ 287function html_locked() { 288 dbg_deprecated(\dokuwiki\Action\Locked::class .'::showBanner()'); 289 (new dokuwiki\Action\Locked())->showBanner(); 290} 291 292/** 293 * list old revisions 294 * 295 * @author Andreas Gohr <andi@splitbrain.org> 296 * @author Ben Coburn <btcoburn@silicodon.net> 297 * @author Kate Arzamastseva <pshns@ukr.net> 298 * 299 * @param int $first skip the first n changelog lines 300 * @param string $media_id id of media, or empty for current page 301 * @deprecated 2020-07-18 302 */ 303function html_revisions($first = 0, $media_id = '') { 304 dbg_deprecated(\dokuwiki\Ui\PageRevisions::class .'::show()'); 305 if ($media_id) { 306 (new dokuwiki\Ui\MediaRevisions($media_id))->show($first); 307 } else { 308 global $INFO; 309 (new dokuwiki\Ui\PageRevisions($INFO['id']))->show($first); 310 } 311} 312 313/** 314 * display recent changes 315 * 316 * @author Andreas Gohr <andi@splitbrain.org> 317 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 318 * @author Ben Coburn <btcoburn@silicodon.net> 319 * @author Kate Arzamastseva <pshns@ukr.net> 320 * 321 * @param int $first 322 * @param string $show_changes 323 * @deprecated 2020-07-18 324 */ 325function html_recent($first = 0, $show_changes = 'both') { 326 dbg_deprecated(\dokuwiki\Ui\Recent::class .'::show()'); 327 (new dokuwiki\Ui\Recent($first, $show_changes))->show(); 328} 329 330/** 331 * Display page index 332 * 333 * @author Andreas Gohr <andi@splitbrain.org> 334 * 335 * @param string $ns 336 * @deprecated 2020-07-18 337 */ 338function html_index($ns) { 339 dbg_deprecated(\dokuwiki\Ui\Index::class .'::show()'); 340 (new dokuwiki\Ui\Index($ns))->show(); 341} 342 343/** 344 * Index tree item formatter for html_buildlist() 345 * 346 * User function for html_buildlist() 347 * 348 * @author Andreas Gohr <andi@splitbrain.org> 349 * 350 * @param array $item 351 * @return string 352 * @deprecated 2020-07-18 353 */ 354function html_list_index($item) { 355 dbg_deprecated(\dokuwiki\Ui\Index::class .'::formatListItem()'); 356 return (new dokuwiki\Ui\Index)->formatListItem($item); 357} 358 359/** 360 * Index list item formatter for html_buildlist() 361 * 362 * This user function is used in html_buildlist to build the 363 * <li> tags for namespaces when displaying the page index 364 * it gives different classes to opened or closed "folders" 365 * 366 * @author Andreas Gohr <andi@splitbrain.org> 367 * 368 * @param array $item 369 * @return string html 370 * @deprecated 2020-07-18 371 */ 372function html_li_index($item) { 373 dbg_deprecated(\dokuwiki\Ui\Index::class .'::tagListItem()'); 374 return (new dokuwiki\Ui\Index)->tagListItem($item); 375} 376 377/** 378 * Default list item formatter for html_buildlist() 379 * 380 * @author Andreas Gohr <andi@splitbrain.org> 381 * 382 * @param array $item 383 * @return string html 384 * @deprecated 2020-07-18 385 */ 386function html_li_default($item){ 387 return '<li class="level'.$item['level'].'">'; 388} 389 390/** 391 * Build an unordered list 392 * 393 * Build an unordered list from the given $data array 394 * Each item in the array has to have a 'level' property 395 * the item itself gets printed by the given $func user 396 * function. The second and optional function is used to 397 * print the <li> tag. Both user function need to accept 398 * a single item. 399 * 400 * Both user functions can be given as array to point to 401 * a member of an object. 402 * 403 * @author Andreas Gohr <andi@splitbrain.org> 404 * 405 * @param array $data array with item arrays 406 * @param string $class class of ul wrapper 407 * @param callable $func callback to print an list item 408 * @param callable $lifunc (optional) callback to the opening li tag 409 * @param bool $forcewrapper (optional) Trigger building a wrapper ul if the first level is 410 * 0 (we have a root object) or 1 (just the root content) 411 * @return string html of an unordered list 412 */ 413function html_buildlist($data, $class, $func, $lifunc = null, $forcewrapper = false) { 414 if (count($data) === 0) { 415 return ''; 416 } 417 418 $firstElement = reset($data); 419 $start_level = $firstElement['level']; 420 $level = $start_level; 421 $html = ''; 422 $open = 0; 423 424 // set callback function to build the <li> tag, formerly defined as html_li_default() 425 if (!is_callable($lifunc)) { 426 $lifunc = function ($item) { 427 return '<li class="level'.$item['level'].'">'; 428 }; 429 } 430 431 foreach ($data as $item) { 432 if ($item['level'] > $level) { 433 //open new list 434 for ($i = 0; $i < ($item['level'] - $level); $i++) { 435 if ($i) $html .= '<li class="clear">'; 436 $html .= "\n".'<ul class="'.$class.'">'."\n"; 437 $open++; 438 } 439 $level = $item['level']; 440 441 } elseif ($item['level'] < $level) { 442 //close last item 443 $html .= '</li>'."\n"; 444 while ($level > $item['level'] && $open > 0 ) { 445 //close higher lists 446 $html .= '</ul>'."\n".'</li>'."\n"; 447 $level--; 448 $open--; 449 } 450 } elseif ($html !== '') { 451 //close previous item 452 $html .= '</li>'."\n"; 453 } 454 455 //print item 456 $html .= call_user_func($lifunc, $item); 457 $html .= '<div class="li">'; 458 459 $html .= call_user_func($func, $item); 460 $html .= '</div>'; 461 } 462 463 //close remaining items and lists 464 $html .= '</li>'."\n"; 465 while ($open-- > 0) { 466 $html .= '</ul></li>'."\n"; 467 } 468 469 if ($forcewrapper || $start_level < 2) { 470 // Trigger building a wrapper ul if the first level is 471 // 0 (we have a root object) or 1 (just the root content) 472 $html = "\n".'<ul class="'.$class.'">'."\n".$html.'</ul>'."\n"; 473 } 474 475 return $html; 476} 477 478/** 479 * display backlinks 480 * 481 * @author Andreas Gohr <andi@splitbrain.org> 482 * @author Michael Klier <chi@chimeric.de> 483 * @deprecated 2020-07-18 484 */ 485function html_backlinks() { 486 dbg_deprecated(\dokuwiki\Ui\Backlinks::class .'::show()'); 487 (new dokuwiki\Ui\Backlinks)->show(); 488} 489 490/** 491 * Get header of diff HTML 492 * 493 * @param string $l_rev Left revisions 494 * @param string $r_rev Right revision 495 * @param string $id Page id, if null $ID is used 496 * @param bool $media If it is for media files 497 * @param bool $inline Return the header on a single line 498 * @return string[] HTML snippets for diff header 499 * @deprecated 2020-07-18 500 */ 501function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) { 502 dbg_deprecated('see '. \dokuwiki\Ui\PageDiff::class .'::buildDiffHead()'); 503} 504 505/** 506 * Show diff 507 * between current page version and provided $text 508 * or between the revisions provided via GET or POST 509 * 510 * @author Andreas Gohr <andi@splitbrain.org> 511 * @param string $text when non-empty: compare with this text with most current version 512 * @param bool $intro display the intro text 513 * @param string $type type of the diff (inline or sidebyside) 514 * @deprecated 2020-07-18 515 */ 516function html_diff($text = '', $intro = true, $type = null) { 517 dbg_deprecated(\dokuwiki\Ui\PageDiff::class .'::show()'); 518 global $INFO; 519 (new dokuwiki\Ui\PageDiff($INFO['id']))->compareWith($text)->preference([ 520 'showIntro' => $intro, 521 'difftype' => $type, 522 ])->show(); 523} 524 525/** 526 * Create html for revision navigation 527 * 528 * @param PageChangeLog $pagelog changelog object of current page 529 * @param string $type inline vs sidebyside 530 * @param int $l_rev left revision timestamp 531 * @param int $r_rev right revision timestamp 532 * @return string[] html of left and right navigation elements 533 * @deprecated 2020-07-18 534 */ 535function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) { 536 dbg_deprecated('see '. \dokuwiki\Ui\PageDiff::class .'::buildRevisionsNavigation()'); 537} 538 539/** 540 * Create html link to a diff defined by two revisions 541 * 542 * @param string $difftype display type 543 * @param string $linktype 544 * @param int $lrev oldest revision 545 * @param int $rrev newest revision or null for diff with current revision 546 * @return string html of link to a diff 547 * @deprecated 2020-07-18 548 */ 549function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) { 550 dbg_deprecated('see '. \dokuwiki\Ui\PageDiff::class .'::diffViewlink()'); 551} 552 553/** 554 * Insert soft breaks in diff html 555 * 556 * @param string $diffhtml 557 * @return string 558 * @deprecated 2020-07-18 559 */ 560function html_insert_softbreaks($diffhtml) { 561 dbg_deprecated(\dokuwiki\Ui\PageDiff::class .'::insertSoftbreaks()'); 562 return (new dokuwiki\Ui\PageDiff)->insertSoftbreaks($diffhtml); 563} 564 565/** 566 * show warning on conflict detection 567 * 568 * @author Andreas Gohr <andi@splitbrain.org> 569 * 570 * @param string $text 571 * @param string $summary 572 * @deprecated 2020-07-18 573 */ 574function html_conflict($text, $summary) { 575 dbg_deprecated(\dokuwiki\Ui\PageConflict::class .'::show()'); 576 (new dokuwiki\Ui\PageConflict($text, $summary))->show(); 577} 578 579/** 580 * Prints the global message array 581 * 582 * @author Andreas Gohr <andi@splitbrain.org> 583 */ 584function html_msgarea() { 585 global $MSG, $MSG_shown; 586 /** @var array $MSG */ 587 // store if the global $MSG has already been shown and thus HTML output has been started 588 $MSG_shown = true; 589 590 if (!isset($MSG)) return; 591 592 $shown = array(); 593 foreach ($MSG as $msg) { 594 $hash = md5($msg['msg']); 595 if (isset($shown[$hash])) continue; // skip double messages 596 if (info_msg_allowed($msg)) { 597 print '<div class="'.$msg['lvl'].'">'; 598 print $msg['msg']; 599 print '</div>'; 600 } 601 $shown[$hash] = 1; 602 } 603 604 unset($GLOBALS['MSG']); 605} 606 607/** 608 * Prints the registration form 609 * 610 * @author Andreas Gohr <andi@splitbrain.org> 611 * @deprecated 2020-07-18 612 */ 613function html_register() { 614 dbg_deprecated(\dokuwiki\Ui\UserRegister::class .'::show()'); 615 (new dokuwiki\Ui\UserRegister)->show(); 616} 617 618/** 619 * Print the update profile form 620 * 621 * @author Christopher Smith <chris@jalakai.co.uk> 622 * @author Andreas Gohr <andi@splitbrain.org> 623 * @deprecated 2020-07-18 624 */ 625function html_updateprofile() { 626 dbg_deprecated(\dokuwiki\Ui\UserProfile::class .'::show()'); 627 (new dokuwiki\Ui\UserProfile)->show(); 628} 629 630/** 631 * Preprocess edit form data 632 * 633 * @author Andreas Gohr <andi@splitbrain.org> 634 * 635 * @deprecated 2020-07-18 636 */ 637function html_edit() { 638 dbg_deprecated(\dokuwiki\Ui\Editor::class .'::show()'); 639 (new dokuwiki\Ui\Editor)->show(); 640} 641 642/** 643 * Display the default edit form 644 * 645 * Is the default action for HTML_EDIT_FORMSELECTION. 646 * 647 * @param mixed[] $param 648 * @deprecated 2020-07-18 649 */ 650function html_edit_form($param) { 651 dbg_deprecated(\dokuwiki\Ui\Editor::class .'::addTextarea()'); 652 return (new dokuwiki\Ui\Editor)->addTextarea($param); 653} 654 655/** 656 * prints some debug info 657 * 658 * @author Andreas Gohr <andi@splitbrain.org> 659 */ 660function html_debug() { 661 global $conf; 662 global $lang; 663 /** @var AuthPlugin $auth */ 664 global $auth; 665 global $INFO; 666 667 //remove sensitive data 668 $cnf = $conf; 669 debug_guard($cnf); 670 $nfo = $INFO; 671 debug_guard($nfo); 672 $ses = $_SESSION; 673 debug_guard($ses); 674 675 print '<html><body>'; 676 677 print '<p>When reporting bugs please send all the following '; 678 print 'output as a mail to andi@splitbrain.org '; 679 print 'The best way to do this is to save this page in your browser</p>'; 680 681 print '<b>$INFO:</b><pre>'; 682 print_r($nfo); 683 print '</pre>'; 684 685 print '<b>$_SERVER:</b><pre>'; 686 print_r($_SERVER); 687 print '</pre>'; 688 689 print '<b>$conf:</b><pre>'; 690 print_r($cnf); 691 print '</pre>'; 692 693 print '<b>DOKU_BASE:</b><pre>'; 694 print DOKU_BASE; 695 print '</pre>'; 696 697 print '<b>abs DOKU_BASE:</b><pre>'; 698 print DOKU_URL; 699 print '</pre>'; 700 701 print '<b>rel DOKU_BASE:</b><pre>'; 702 print dirname($_SERVER['PHP_SELF']).'/'; 703 print '</pre>'; 704 705 print '<b>PHP Version:</b><pre>'; 706 print phpversion(); 707 print '</pre>'; 708 709 print '<b>locale:</b><pre>'; 710 print setlocale(LC_ALL,0); 711 print '</pre>'; 712 713 print '<b>encoding:</b><pre>'; 714 print $lang['encoding']; 715 print '</pre>'; 716 717 if ($auth) { 718 print '<b>Auth backend capabilities:</b><pre>'; 719 foreach ($auth->getCapabilities() as $cando) { 720 print ' '.str_pad($cando,16) .' => '. (int)$auth->canDo($cando) . DOKU_LF; 721 } 722 print '</pre>'; 723 } 724 725 print '<b>$_SESSION:</b><pre>'; 726 print_r($ses); 727 print '</pre>'; 728 729 print '<b>Environment:</b><pre>'; 730 print_r($_ENV); 731 print '</pre>'; 732 733 print '<b>PHP settings:</b><pre>'; 734 $inis = ini_get_all(); 735 print_r($inis); 736 print '</pre>'; 737 738 if (function_exists('apache_get_version')) { 739 $apache = array(); 740 $apache['version'] = apache_get_version(); 741 742 if (function_exists('apache_get_modules')) { 743 $apache['modules'] = apache_get_modules(); 744 } 745 print '<b>Apache</b><pre>'; 746 print_r($apache); 747 print '</pre>'; 748 } 749 750 print '</body></html>'; 751} 752 753/** 754 * Form to request a new password for an existing account 755 * 756 * @author Benoit Chesneau <benoit@bchesneau.info> 757 * @author Andreas Gohr <gohr@cosmocode.de> 758 * @deprecated 2020-07-18 759 */ 760function html_resendpwd() { 761 dbg_deprecated(\dokuwiki\Ui\UserResendPwd::class .'::show()'); 762 (new dokuwiki\Ui\UserResendPwd)->show(); 763} 764 765/** 766 * Return the TOC rendered to XHTML 767 * 768 * @author Andreas Gohr <andi@splitbrain.org> 769 * 770 * @param array $toc 771 * @return string html 772 */ 773function html_TOC($toc) { 774 if (!count($toc)) return ''; 775 global $lang; 776 $out = '<!-- TOC START -->'.DOKU_LF; 777 $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF; 778 $out .= '<h3 class="toggle">'; 779 $out .= $lang['toc']; 780 $out .= '</h3>'.DOKU_LF; 781 $out .= '<div>'.DOKU_LF; 782 $out .= html_buildlist($toc, 'toc', 'html_list_toc', null, true); 783 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 784 $out .= '<!-- TOC END -->'.DOKU_LF; 785 return $out; 786} 787 788/** 789 * Callback for html_buildlist 790 * 791 * @param array $item 792 * @return string html 793 */ 794function html_list_toc($item) { 795 if (isset($item['hid'])){ 796 $link = '#'.$item['hid']; 797 } else { 798 $link = $item['link']; 799 } 800 801 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 802} 803 804/** 805 * Helper function to build TOC items 806 * 807 * Returns an array ready to be added to a TOC array 808 * 809 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 810 * @param string $text - what to display in the TOC 811 * @param int $level - nesting level 812 * @param string $hash - is prepended to the given $link, set blank if you want full links 813 * @return array the toc item 814 */ 815function html_mktocitem($link, $text, $level, $hash='#') { 816 return array( 817 'link' => $hash.$link, 818 'title' => $text, 819 'type' => 'ul', 820 'level' => $level 821 ); 822} 823 824/** 825 * Output a Doku_Form object. 826 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 827 * 828 * @author Tom N Harris <tnharris@whoopdedo.org> 829 * 830 * @param string $name The name of the form 831 * @param Doku_Form $form The form 832 * @return void 833 * @deprecated 2020-07-18 834 */ 835function html_form($name, $form) { 836 dbg_deprecated('use dokuwiki\Form\Form instead of Doku_Form'); 837 // Safety check in case the caller forgets. 838 $form->endFieldset(); 839 Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 840} 841 842/** 843 * Form print function. 844 * Just calls printForm() on the form object. 845 * 846 * @param Doku_Form $form The form 847 * @return void 848 * @deprecated 2020-07-18 849 */ 850function html_form_output($form) { 851 dbg_deprecated('use dokuwiki\Form\Form::toHTML()'); 852 $form->printForm(); 853} 854 855/** 856 * Embed a flash object in HTML 857 * 858 * This will create the needed HTML to embed a flash movie in a cross browser 859 * compatble way using valid XHTML 860 * 861 * The parameters $params, $flashvars and $atts need to be associative arrays. 862 * No escaping needs to be done for them. The alternative content *has* to be 863 * escaped because it is used as is. If no alternative content is given 864 * $lang['noflash'] is used. 865 * 866 * @author Andreas Gohr <andi@splitbrain.org> 867 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 868 * 869 * @param string $swf - the SWF movie to embed 870 * @param int $width - width of the flash movie in pixels 871 * @param int $height - height of the flash movie in pixels 872 * @param array $params - additional parameters (<param>) 873 * @param array $flashvars - parameters to be passed in the flashvar parameter 874 * @param array $atts - additional attributes for the <object> tag 875 * @param string $alt - alternative content (is NOT automatically escaped!) 876 * @return string - the XHTML markup 877 */ 878function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 879 global $lang; 880 881 $out = ''; 882 883 // prepare the object attributes 884 if(is_null($atts)) $atts = array(); 885 $atts['width'] = (int) $width; 886 $atts['height'] = (int) $height; 887 if(!$atts['width']) $atts['width'] = 425; 888 if(!$atts['height']) $atts['height'] = 350; 889 890 // add object attributes for standard compliant browsers 891 $std = $atts; 892 $std['type'] = 'application/x-shockwave-flash'; 893 $std['data'] = $swf; 894 895 // add object attributes for IE 896 $ie = $atts; 897 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 898 899 // open object (with conditional comments) 900 $out .= '<!--[if !IE]> -->'.NL; 901 $out .= '<object '.buildAttributes($std).'>'.NL; 902 $out .= '<!-- <![endif]-->'.NL; 903 $out .= '<!--[if IE]>'.NL; 904 $out .= '<object '.buildAttributes($ie).'>'.NL; 905 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 906 $out .= '<!--><!-- -->'.NL; 907 908 // print params 909 if(is_array($params)) foreach($params as $key => $val){ 910 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 911 } 912 913 // add flashvars 914 if(is_array($flashvars)){ 915 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 916 } 917 918 // alternative content 919 if($alt){ 920 $out .= $alt.NL; 921 }else{ 922 $out .= $lang['noflash'].NL; 923 } 924 925 // finish 926 $out .= '</object>'.NL; 927 $out .= '<!-- <![endif]-->'.NL; 928 929 return $out; 930} 931 932/** 933 * Prints HTML code for the given tab structure 934 * 935 * @param array $tabs tab structure 936 * @param string $current_tab the current tab id 937 * @return void 938 */ 939function html_tabs($tabs, $current_tab = null) { 940 echo '<ul class="tabs">'.NL; 941 942 foreach ($tabs as $id => $tab) { 943 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 944 } 945 946 echo '</ul>'.NL; 947} 948 949/** 950 * Prints a single tab 951 * 952 * @author Kate Arzamastseva <pshns@ukr.net> 953 * @author Adrian Lang <mail@adrianlang.de> 954 * 955 * @param string $href - tab href 956 * @param string $caption - tab caption 957 * @param boolean $selected - is tab selected 958 * @return void 959 */ 960 961function html_tab($href, $caption, $selected = false) { 962 $tab = '<li>'; 963 if ($selected) { 964 $tab .= '<strong>'; 965 } else { 966 $tab .= '<a href="' . hsc($href) . '">'; 967 } 968 $tab .= hsc($caption) 969 . '</' . ($selected ? 'strong' : 'a') . '>' 970 . '</li>'.NL; 971 echo $tab; 972} 973 974/** 975 * Display size change 976 * 977 * @param int $sizechange - size of change in Bytes 978 * @param Doku_Form $form - (optional) form to add elements to 979 * @return void|string 980 */ 981function html_sizechange($sizechange, $form = null) { 982 if (isset($sizechange)) { 983 $class = 'sizechange'; 984 $value = filesize_h(abs($sizechange)); 985 if ($sizechange > 0) { 986 $class .= ' positive'; 987 $value = '+' . $value; 988 } elseif ($sizechange < 0) { 989 $class .= ' negative'; 990 $value = '-' . $value; 991 } else { 992 $value = '±' . $value; 993 } 994 if (!isset($form)) { 995 return '<span class="'.$class.'">'.$value.'</span>'; 996 } else { // Doku_Form 997 $form->addElement(form_makeOpenTag('span', array('class' => $class))); 998 $form->addElement($value); 999 $form->addElement(form_makeCloseTag('span')); 1000 } 1001 } 1002} 1003