deprecate html_form()
[dokuwiki.git] / inc / html.php
blobe1469c1c802508cc3baad9babcc4ee446a4c0cd6
1 <?php
2 /**
3 * HTML output functions
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
9 use dokuwiki\ChangeLog\MediaChangeLog;
10 use dokuwiki\ChangeLog\PageChangeLog;
11 use dokuwiki\Extension\AuthPlugin;
12 use dokuwiki\Extension\Event;
14 if (!defined('SEC_EDIT_PATTERN')) {
15 define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#');
19 /**
20 * Convenience function to quickly build a wikilink
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
28 function 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');
35 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
38 /**
39 * The loginform
41 * @author Andreas Gohr <andi@splitbrain.org>
43 * @param bool $svg Whether to show svg icons in the register and resendpwd links or not
44 * @deprecated 2020-07-18
46 function html_login($svg = false) {
47 dbg_deprecated(\dokuwiki\Ui\Login::class .'::show()');
48 (new dokuwiki\Ui\Login($svg))->show();
52 /**
53 * Denied page content
55 * @return string html
56 * @deprecated 2020-07-18 not called anymore, see inc/Action/Denied::tplContent()
58 function html_denied() {
59 dbg_deprecated(\dokuwiki\Action\Denied::class .'::showBanner()');
60 (new dokuwiki\Action\Denied())->showBanner();
63 /**
64 * inserts section edit buttons if wanted or removes the markers
66 * @author Andreas Gohr <andi@splitbrain.org>
68 * @param string $text
69 * @param bool $show show section edit buttons?
70 * @return string
72 function html_secedit($text, $show = true) {
73 global $INFO;
75 if ((isset($INFO) && !$INFO['writable']) || !$show || (isset($INFO) && $INFO['rev'])) {
76 return preg_replace(SEC_EDIT_PATTERN,'',$text);
79 return preg_replace_callback(SEC_EDIT_PATTERN,
80 'html_secedit_button', $text);
83 /**
84 * prepares section edit button data for event triggering
85 * used as a callback in html_secedit
87 * @author Andreas Gohr <andi@splitbrain.org>
89 * @param array $matches matches with regexp
90 * @return string
91 * @triggers HTML_SECEDIT_BUTTON
93 function html_secedit_button($matches){
94 $json = htmlspecialchars_decode($matches[1], ENT_QUOTES);
95 $data = json_decode($json, true);
96 if ($data == NULL) {
97 return;
99 $data ['target'] = strtolower($data['target']);
100 $data ['hid'] = strtolower($data['hid']);
102 return Event::createAndTrigger('HTML_SECEDIT_BUTTON', $data,
103 'html_secedit_get_button');
107 * prints a section editing button
108 * used as default action form HTML_SECEDIT_BUTTON
110 * @author Adrian Lang <lang@cosmocode.de>
112 * @param array $data name, section id and target
113 * @return string html
115 function html_secedit_get_button($data) {
116 global $ID;
117 global $INFO;
119 if (!isset($data['name']) || $data['name'] === '') return '';
121 $name = $data['name'];
122 unset($data['name']);
124 $secid = $data['secid'];
125 unset($data['secid']);
127 $params = array_merge(
128 array('do' => 'edit', 'rev' => $INFO['lastmod'], 'summary' => '['.$name.'] '),
129 $data
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;
139 * Just the back to top button (in its own form)
141 * @author Andreas Gohr <andi@splitbrain.org>
143 * @return string html
145 function html_topbtn() {
146 global $lang;
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;
156 * Displays a button (using its own form)
157 * If tooltip exists, the access key tooltip is replaced.
159 * @author Andreas Gohr <andi@splitbrain.org>
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
171 function html_btn($name, $id, $akey, $params, $method = 'get', $tooltip = '', $label = false, $svg = null) {
172 global $conf;
173 global $lang;
175 if (!$label)
176 $label = $lang['btn_'.$name];
178 //filter id (without urlencoding)
179 $id = idfilter($id,false);
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;
191 $html = '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
193 if (is_array($params)) {
194 foreach ($params as $key => $val) {
195 $html .= '<input type="hidden" name="'.$key.'" value="'.hsc($val).'" />';
199 $tip = empty($tooltip) ? hsc($label) : hsc($tooltip);
201 $html .= '<button type="submit" ';
202 if ($akey) {
203 $tip .= ' ['.strtoupper($akey).']';
204 $html .= 'accesskey="'.$akey.'" ';
206 $html .= 'title="'.$tip.'">';
207 if ($svg) {
208 $html .= '<span>'. hsc($label) .'</span>'. inlineSVG($svg);
209 } else {
210 $html .= hsc($label);
212 $html .= '</button>';
213 $html .= '</div></form>';
215 return $html;
218 * show a revision warning
220 * @author Szymon Olewniczak <dokuwiki@imz.re>
221 * @deprecated 2020-07-18
223 function html_showrev() {
224 dbg_deprecated(\dokuwiki\Ui\PageView::class .'::showrev()');
228 * Show a wiki page
230 * @author Andreas Gohr <andi@splitbrain.org>
232 * @param null|string $txt wiki text or null for showing $ID
233 * @deprecated 2020-07-18
235 function html_show($txt=null) {
236 dbg_deprecated(\dokuwiki\Ui\PageView::class .'::show()');
237 (new dokuwiki\Ui\PageView($txt))->show();
241 * ask the user about how to handle an exisiting draft
243 * @author Andreas Gohr <andi@splitbrain.org>
244 * @deprecated 2020-07-18
246 function html_draft() {
247 dbg_deprecated(\dokuwiki\Ui\Draft::class .'::show()');
248 (new dokuwiki\Ui\Draft)->show();
252 * Highlights searchqueries in HTML code
254 * @author Andreas Gohr <andi@splitbrain.org>
255 * @author Harry Fuecks <hfuecks@gmail.com>
257 * @param string $html
258 * @param array|string $phrases
259 * @return string html
261 function 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);
268 if ($regex === '') return $html;
269 if (!\dokuwiki\Utf8\Clean::isUtf8($regex)) return $html;
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>';
276 return $hlight;
277 }, $html);
278 return $html;
282 * Display error on locked pages
284 * @author Andreas Gohr <andi@splitbrain.org>
285 * @deprecated 2020-07-18 not called anymore, see inc/Action/Locked::tplContent()
287 function html_locked() {
288 dbg_deprecated(\dokuwiki\Action\Locked::class .'::showBanner()');
289 (new dokuwiki\Action\Locked())->showBanner();
293 * list old revisions
295 * @author Andreas Gohr <andi@splitbrain.org>
296 * @author Ben Coburn <btcoburn@silicodon.net>
297 * @author Kate Arzamastseva <pshns@ukr.net>
299 * @param int $first skip the first n changelog lines
300 * @param bool|string $media_id id of media, or false for current page
301 * @deprecated 2020-07-18
303 function html_revisions($first=0, $media_id = false) {
304 dbg_deprecated(\dokuwiki\Ui\Revisions::class .'::show()');
305 (new dokuwiki\Ui\Revisions($first, $media_id))->show();
309 * display recent changes
311 * @author Andreas Gohr <andi@splitbrain.org>
312 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
313 * @author Ben Coburn <btcoburn@silicodon.net>
314 * @author Kate Arzamastseva <pshns@ukr.net>
316 * @param int $first
317 * @param string $show_changes
318 * @deprecated 2020-07-18
320 function html_recent($first = 0, $show_changes = 'both') {
321 dbg_deprecated(\dokuwiki\Ui\Recent::class .'::show()');
322 (new dokuwiki\Ui\Recent($first, $show_changes))->show();
326 * Display page index
328 * @author Andreas Gohr <andi@splitbrain.org>
330 * @param string $ns
331 * @deprecated 2020-07-18
333 function html_index($ns) {
334 dbg_deprecated(\dokuwiki\Ui\Index::class .'::show()');
335 (new dokuwiki\Ui\Index($ns))->show();
339 * Index tree item formatter for html_buildlist()
341 * User function for html_buildlist()
343 * @author Andreas Gohr <andi@splitbrain.org>
345 * @param array $item
346 * @return string
347 * @deprecated 2020-07-18
349 function html_list_index($item) {
350 dbg_deprecated(\dokuwiki\Ui\Index::class .'::formatListItem()');
351 return (new dokuwiki\Ui\Index)->formatListItem($item);
355 * Index list item formatter for html_buildlist()
357 * This user function is used in html_buildlist to build the
358 * <li> tags for namespaces when displaying the page index
359 * it gives different classes to opened or closed "folders"
361 * @author Andreas Gohr <andi@splitbrain.org>
363 * @param array $item
364 * @return string html
365 * @deprecated 2020-07-18
367 function html_li_index($item) {
368 dbg_deprecated(\dokuwiki\Ui\Index::class .'::tagListItem()');
369 return (new dokuwiki\Ui\Index)->tagListItem($item);
373 * Default list item formatter for html_buildlist()
375 * @author Andreas Gohr <andi@splitbrain.org>
377 * @param array $item
378 * @return string html
379 * @deprecated 2020-07-18
381 function html_li_default($item){
382 return '<li class="level'.$item['level'].'">';
386 * Build an unordered list
388 * Build an unordered list from the given $data array
389 * Each item in the array has to have a 'level' property
390 * the item itself gets printed by the given $func user
391 * function. The second and optional function is used to
392 * print the <li> tag. Both user function need to accept
393 * a single item.
395 * Both user functions can be given as array to point to
396 * a member of an object.
398 * @author Andreas Gohr <andi@splitbrain.org>
400 * @param array $data array with item arrays
401 * @param string $class class of ul wrapper
402 * @param callable $func callback to print an list item
403 * @param callable $lifunc (optional) callback to the opening li tag
404 * @param bool $forcewrapper (optional) Trigger building a wrapper ul if the first level is
405 * 0 (we have a root object) or 1 (just the root content)
406 * @return string html of an unordered list
408 function html_buildlist($data, $class, $func, $lifunc = null, $forcewrapper = false) {
409 if (count($data) === 0) {
410 return '';
413 $firstElement = reset($data);
414 $start_level = $firstElement['level'];
415 $level = $start_level;
416 $html = '';
417 $open = 0;
419 // set callback function to build the <li> tag, formerly defined as html_li_default()
420 if (!is_callable($lifunc)) {
421 $lifunc = function ($item) {
422 return '<li class="level'.$item['level'].'">';
426 foreach ($data as $item) {
427 if ($item['level'] > $level) {
428 //open new list
429 for ($i = 0; $i < ($item['level'] - $level); $i++) {
430 if ($i) $html .= '<li class="clear">';
431 $html .= "\n".'<ul class="'.$class.'">'."\n";
432 $open++;
434 $level = $item['level'];
436 } elseif ($item['level'] < $level) {
437 //close last item
438 $html .= '</li>'."\n";
439 while ($level > $item['level'] && $open > 0 ) {
440 //close higher lists
441 $html .= '</ul>'."\n".'</li>'."\n";
442 $level--;
443 $open--;
445 } elseif ($html !== '') {
446 //close previous item
447 $html .= '</li>'."\n";
450 //print item
451 $html .= call_user_func($lifunc, $item);
452 $html .= '<div class="li">';
454 $html .= call_user_func($func, $item);
455 $html .= '</div>';
458 //close remaining items and lists
459 $html .= '</li>'."\n";
460 while ($open-- > 0) {
461 $html .= '</ul></li>'."\n";
464 if ($forcewrapper || $start_level < 2) {
465 // Trigger building a wrapper ul if the first level is
466 // 0 (we have a root object) or 1 (just the root content)
467 $html = "\n".'<ul class="'.$class.'">'."\n".$html.'</ul>'."\n";
470 return $html;
474 * display backlinks
476 * @author Andreas Gohr <andi@splitbrain.org>
477 * @author Michael Klier <chi@chimeric.de>
478 * @deprecated 2020-07-18
480 function html_backlinks() {
481 dbg_deprecated(\dokuwiki\Ui\Backlinks::class .'::show()');
482 (new dokuwiki\Ui\Backlinks)->show();
486 * Get header of diff HTML
488 * @param string $l_rev Left revisions
489 * @param string $r_rev Right revision
490 * @param string $id Page id, if null $ID is used
491 * @param bool $media If it is for media files
492 * @param bool $inline Return the header on a single line
493 * @return string[] HTML snippets for diff header
494 * @deprecated 2020-07-18
496 function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
497 dbg_deprecated('see '. \dokuwiki\Ui\Diff::class .'::diffHead()');
501 * Show diff
502 * between current page version and provided $text
503 * or between the revisions provided via GET or POST
505 * @author Andreas Gohr <andi@splitbrain.org>
506 * @param string $text when non-empty: compare with this text with most current version
507 * @param bool $intro display the intro text
508 * @param string $type type of the diff (inline or sidebyside)
509 * @deprecated 2020-07-18
511 function html_diff($text = '', $intro = true, $type = null) {
512 dbg_deprecated(\dokuwiki\Ui\Diff::class .'::show()');
513 (new dokuwiki\Ui\Diff($text, $intro, $type))->show();
517 * Create html for revision navigation
519 * @param PageChangeLog $pagelog changelog object of current page
520 * @param string $type inline vs sidebyside
521 * @param int $l_rev left revision timestamp
522 * @param int $r_rev right revision timestamp
523 * @return string[] html of left and right navigation elements
524 * @deprecated 2020-07-18
526 function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
527 dbg_deprecated('see '. \dokuwiki\Ui\Diff::class .'::diffNavigation()');
531 * Create html link to a diff defined by two revisions
533 * @param string $difftype display type
534 * @param string $linktype
535 * @param int $lrev oldest revision
536 * @param int $rrev newest revision or null for diff with current revision
537 * @return string html of link to a diff
538 * @deprecated 2020-07-18
540 function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
541 dbg_deprecated('see '. \dokuwiki\Ui\Diff::class .'::diffViewlink()');
545 * Insert soft breaks in diff html
547 * @param string $diffhtml
548 * @return string
549 * @deprecated 2020-07-18
551 function html_insert_softbreaks($diffhtml) {
552 dbg_deprecated(\dokuwiki\Ui\Diff::class .'::insertSoftbreaks()');
553 return (new dokuwiki\Ui\Diff())->insertSoftbreaks($diffhtml);
557 * show warning on conflict detection
559 * @author Andreas Gohr <andi@splitbrain.org>
561 * @param string $text
562 * @param string $summary
563 * @deprecated 2020-07-18
565 function html_conflict($text, $summary) {
566 dbg_deprecated(\dokuwiki\Ui\Conflict::class .'::show()');
567 (new dokuwiki\Ui\Conflict($text, $summary))->show();
571 * Prints the global message array
573 * @author Andreas Gohr <andi@splitbrain.org>
575 function html_msgarea() {
576 global $MSG, $MSG_shown;
577 /** @var array $MSG */
578 // store if the global $MSG has already been shown and thus HTML output has been started
579 $MSG_shown = true;
581 if (!isset($MSG)) return;
583 $shown = array();
584 foreach ($MSG as $msg) {
585 $hash = md5($msg['msg']);
586 if (isset($shown[$hash])) continue; // skip double messages
587 if (info_msg_allowed($msg)) {
588 print '<div class="'.$msg['lvl'].'">';
589 print $msg['msg'];
590 print '</div>';
592 $shown[$hash] = 1;
595 unset($GLOBALS['MSG']);
599 * Prints the registration form
601 * @author Andreas Gohr <andi@splitbrain.org>
602 * @deprecated 2020-07-18
604 function html_register() {
605 dbg_deprecated(\dokuwiki\Ui\UserRegister::class .'::show()');
606 (new dokuwiki\Ui\UserRegister)->show();
610 * Print the update profile form
612 * @author Christopher Smith <chris@jalakai.co.uk>
613 * @author Andreas Gohr <andi@splitbrain.org>
614 * @deprecated 2020-07-18
616 function html_updateprofile() {
617 dbg_deprecated(\dokuwiki\Ui\UserProfile::class .'::show()');
618 (new dokuwiki\Ui\UserProfile)->show();
622 * Preprocess edit form data
624 * @author Andreas Gohr <andi@splitbrain.org>
626 * @deprecated 2020-07-18
628 function html_edit() {
629 dbg_deprecated(\dokuwiki\Ui\Editor::class .'::show()');
630 (new dokuwiki\Ui\Editor)->show();
634 * Display the default edit form
636 * Is the default action for HTML_EDIT_FORMSELECTION.
638 * @param mixed[] $param
639 * @deprecated 2020-07-18
641 function html_edit_form($param) {
642 dbg_deprecated(\dokuwiki\Ui\Editor::class .'::addTextarea()');
643 return (new dokuwiki\Ui\Editor)->addTextarea($param);
647 * prints some debug info
649 * @author Andreas Gohr <andi@splitbrain.org>
651 function html_debug() {
652 global $conf;
653 global $lang;
654 /** @var AuthPlugin $auth */
655 global $auth;
656 global $INFO;
658 //remove sensitive data
659 $cnf = $conf;
660 debug_guard($cnf);
661 $nfo = $INFO;
662 debug_guard($nfo);
663 $ses = $_SESSION;
664 debug_guard($ses);
666 print '<html><body>';
668 print '<p>When reporting bugs please send all the following ';
669 print 'output as a mail to andi@splitbrain.org ';
670 print 'The best way to do this is to save this page in your browser</p>';
672 print '<b>$INFO:</b><pre>';
673 print_r($nfo);
674 print '</pre>';
676 print '<b>$_SERVER:</b><pre>';
677 print_r($_SERVER);
678 print '</pre>';
680 print '<b>$conf:</b><pre>';
681 print_r($cnf);
682 print '</pre>';
684 print '<b>DOKU_BASE:</b><pre>';
685 print DOKU_BASE;
686 print '</pre>';
688 print '<b>abs DOKU_BASE:</b><pre>';
689 print DOKU_URL;
690 print '</pre>';
692 print '<b>rel DOKU_BASE:</b><pre>';
693 print dirname($_SERVER['PHP_SELF']).'/';
694 print '</pre>';
696 print '<b>PHP Version:</b><pre>';
697 print phpversion();
698 print '</pre>';
700 print '<b>locale:</b><pre>';
701 print setlocale(LC_ALL,0);
702 print '</pre>';
704 print '<b>encoding:</b><pre>';
705 print $lang['encoding'];
706 print '</pre>';
708 if ($auth) {
709 print '<b>Auth backend capabilities:</b><pre>';
710 foreach ($auth->getCapabilities() as $cando) {
711 print ' '.str_pad($cando,16) .' => '. (int)$auth->canDo($cando) . DOKU_LF;
713 print '</pre>';
716 print '<b>$_SESSION:</b><pre>';
717 print_r($ses);
718 print '</pre>';
720 print '<b>Environment:</b><pre>';
721 print_r($_ENV);
722 print '</pre>';
724 print '<b>PHP settings:</b><pre>';
725 $inis = ini_get_all();
726 print_r($inis);
727 print '</pre>';
729 if (function_exists('apache_get_version')) {
730 $apache = array();
731 $apache['version'] = apache_get_version();
733 if (function_exists('apache_get_modules')) {
734 $apache['modules'] = apache_get_modules();
736 print '<b>Apache</b><pre>';
737 print_r($apache);
738 print '</pre>';
741 print '</body></html>';
745 * Form to request a new password for an existing account
747 * @author Benoit Chesneau <benoit@bchesneau.info>
748 * @author Andreas Gohr <gohr@cosmocode.de>
749 * @deprecated 2020-07-18
751 function html_resendpwd() {
752 dbg_deprecated(\dokuwiki\Ui\UserResendPwd::class .'::show()');
753 (new dokuwiki\Ui\UserResendPwd)->show();
757 * Return the TOC rendered to XHTML
759 * @author Andreas Gohr <andi@splitbrain.org>
761 * @param array $toc
762 * @return string html
764 function html_TOC($toc) {
765 if (!count($toc)) return '';
766 global $lang;
767 $out = '<!-- TOC START -->'.DOKU_LF;
768 $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF;
769 $out .= '<h3 class="toggle">';
770 $out .= $lang['toc'];
771 $out .= '</h3>'.DOKU_LF;
772 $out .= '<div>'.DOKU_LF;
773 $out .= html_buildlist($toc, 'toc', 'html_list_toc', null, true);
774 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
775 $out .= '<!-- TOC END -->'.DOKU_LF;
776 return $out;
780 * Callback for html_buildlist
782 * @param array $item
783 * @return string html
785 function html_list_toc($item) {
786 if (isset($item['hid'])){
787 $link = '#'.$item['hid'];
788 } else {
789 $link = $item['link'];
792 return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
796 * Helper function to build TOC items
798 * Returns an array ready to be added to a TOC array
800 * @param string $link - where to link (if $hash set to '#' it's a local anchor)
801 * @param string $text - what to display in the TOC
802 * @param int $level - nesting level
803 * @param string $hash - is prepended to the given $link, set blank if you want full links
804 * @return array the toc item
806 function html_mktocitem($link, $text, $level, $hash='#') {
807 return array(
808 'link' => $hash.$link,
809 'title' => $text,
810 'type' => 'ul',
811 'level' => $level
816 * Output a Doku_Form object.
817 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
819 * @author Tom N Harris <tnharris@whoopdedo.org>
821 * @param string $name The name of the form
822 * @param Doku_Form $form The form
824 function html_form($name, $form) {
825 dbg_deprecated('use dokuwiki\Form\Form instead of Doku_Form');
826 // Safety check in case the caller forgets.
827 $form->endFieldset();
828 Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
832 * Form print function.
833 * Just calls printForm() on the form object.
835 * @param Doku_Form $form The form
837 function html_form_output($form) {
838 dbg_deprecated('use dokuwiki\Form\Form::toHTML()');
839 $form->printForm();
843 * Embed a flash object in HTML
845 * This will create the needed HTML to embed a flash movie in a cross browser
846 * compatble way using valid XHTML
848 * The parameters $params, $flashvars and $atts need to be associative arrays.
849 * No escaping needs to be done for them. The alternative content *has* to be
850 * escaped because it is used as is. If no alternative content is given
851 * $lang['noflash'] is used.
853 * @author Andreas Gohr <andi@splitbrain.org>
854 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
856 * @param string $swf - the SWF movie to embed
857 * @param int $width - width of the flash movie in pixels
858 * @param int $height - height of the flash movie in pixels
859 * @param array $params - additional parameters (<param>)
860 * @param array $flashvars - parameters to be passed in the flashvar parameter
861 * @param array $atts - additional attributes for the <object> tag
862 * @param string $alt - alternative content (is NOT automatically escaped!)
863 * @return string - the XHTML markup
865 function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
866 global $lang;
868 $out = '';
870 // prepare the object attributes
871 if(is_null($atts)) $atts = array();
872 $atts['width'] = (int) $width;
873 $atts['height'] = (int) $height;
874 if(!$atts['width']) $atts['width'] = 425;
875 if(!$atts['height']) $atts['height'] = 350;
877 // add object attributes for standard compliant browsers
878 $std = $atts;
879 $std['type'] = 'application/x-shockwave-flash';
880 $std['data'] = $swf;
882 // add object attributes for IE
883 $ie = $atts;
884 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
886 // open object (with conditional comments)
887 $out .= '<!--[if !IE]> -->'.NL;
888 $out .= '<object '.buildAttributes($std).'>'.NL;
889 $out .= '<!-- <![endif]-->'.NL;
890 $out .= '<!--[if IE]>'.NL;
891 $out .= '<object '.buildAttributes($ie).'>'.NL;
892 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL;
893 $out .= '<!--><!-- -->'.NL;
895 // print params
896 if(is_array($params)) foreach($params as $key => $val){
897 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
900 // add flashvars
901 if(is_array($flashvars)){
902 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
905 // alternative content
906 if($alt){
907 $out .= $alt.NL;
908 }else{
909 $out .= $lang['noflash'].NL;
912 // finish
913 $out .= '</object>'.NL;
914 $out .= '<!-- <![endif]-->'.NL;
916 return $out;
920 * Prints HTML code for the given tab structure
922 * @param array $tabs tab structure
923 * @param string $current_tab the current tab id
925 function html_tabs($tabs, $current_tab = null) {
926 echo '<ul class="tabs">'.NL;
928 foreach ($tabs as $id => $tab) {
929 html_tab($tab['href'], $tab['caption'], $id === $current_tab);
932 echo '</ul>'.NL;
936 * Prints a single tab
938 * @author Kate Arzamastseva <pshns@ukr.net>
939 * @author Adrian Lang <mail@adrianlang.de>
941 * @param string $href - tab href
942 * @param string $caption - tab caption
943 * @param boolean $selected - is tab selected
946 function html_tab($href, $caption, $selected = false) {
947 $tab = '<li>';
948 if ($selected) {
949 $tab .= '<strong>';
950 } else {
951 $tab .= '<a href="' . hsc($href) . '">';
953 $tab .= hsc($caption)
954 . '</' . ($selected ? 'strong' : 'a') . '>'
955 . '</li>'.NL;
956 echo $tab;
960 * Display size change
962 * @param int $sizechange - size of change in Bytes
963 * @param Doku_Form $form - (optional) form to add elements to
964 * @return void|string
966 function html_sizechange($sizechange, $form = null) {
967 if (isset($sizechange)) {
968 $class = 'sizechange';
969 $value = filesize_h(abs($sizechange));
970 if ($sizechange > 0) {
971 $class .= ' positive';
972 $value = '+' . $value;
973 } elseif ($sizechange < 0) {
974 $class .= ' negative';
975 $value = '-' . $value;
976 } else {
977 $value = '±' . $value;
979 if (!isset($form)) {
980 return '<span class="'.$class.'">'.$value.'</span>';
981 } else { // Doku_Form
982 $form->addElement(form_makeOpenTag('span', array('class' => $class)));
983 $form->addElement($value);
984 $form->addElement(form_makeCloseTag('span'));