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