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