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