xref: /dokuwiki/inc/html.php (revision bab2b7f0bb724f0e6e184a1d777e778955f3b904)
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    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
276    return $html;
277}
278
279/**
280 * Callback used by html_hilight()
281 *
282 * @author Harry Fuecks <hfuecks@gmail.com>
283 *
284 * @param array $m matches
285 * @return string html
286 */
287function html_hilight_callback($m) { // FIXME should be closure in html_highlight()?
288    $hlight = unslash($m[0]);
289    if ( !isset($m[2])) {
290        $hlight = '<span class="search_hit">'.$hlight.'</span>';
291    }
292    return $hlight;
293}
294
295/**
296 * Display error on locked pages
297 *
298 * @author Andreas Gohr <andi@splitbrain.org>
299 */
300function html_locked(){
301    global $ID;
302    global $conf;
303    global $lang;
304    global $INFO;
305
306    $locktime = filemtime(wikiLockFN($ID));
307    $expire = dformat($locktime + $conf['locktime']);
308    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
309
310    print p_locale_xhtml('locked');
311    print '<ul>';
312    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
313    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
314    print '</ul>';
315}
316
317/**
318 * list old revisions
319 *
320 * @author Andreas Gohr <andi@splitbrain.org>
321 * @author Ben Coburn <btcoburn@silicodon.net>
322 * @author Kate Arzamastseva <pshns@ukr.net>
323 *
324 * @param int $first skip the first n changelog lines
325 * @param bool|string $media_id id of media, or false for current page
326 * @deprecated 2020-07-18
327 */
328function html_revisions($first=0, $media_id = false) {
329    (new dokuwiki\Ui\Revisions($first, $media_id))->show();
330}
331
332/**
333 * display recent changes
334 *
335 * @author Andreas Gohr <andi@splitbrain.org>
336 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
337 * @author Ben Coburn <btcoburn@silicodon.net>
338 * @author Kate Arzamastseva <pshns@ukr.net>
339 *
340 * @param int $first
341 * @param string $show_changes
342 * @deprecated 2020-07-18
343 */
344function html_recent($first = 0, $show_changes = 'both') {
345    (new dokuwiki\Ui\Recent($first, $show_changes))->show();
346}
347
348/**
349 * Display page index
350 *
351 * @author Andreas Gohr <andi@splitbrain.org>
352 *
353 * @param string $ns
354 * @deprecated 2020-07-18
355 */
356function html_index($ns) {
357    (new dokuwiki\Ui\Index($ns))->show();
358}
359
360/**
361 * Index item formatter
362 *
363 * User function for html_buildlist()
364 *
365 * @author Andreas Gohr <andi@splitbrain.org>
366 *
367 * @param array $item
368 * @return string
369 */
370function html_list_index($item) { // FIXME: also called from inc/Ajax.php
371    global $ID, $conf;
372
373    // prevent searchbots needlessly following links
374    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';
375
376    $ret = '';
377    $base = ':'.$item['id'];
378    $base = substr($base,strrpos($base,':')+1);
379    if($item['type']=='d'){
380        // FS#2766, no need for search bots to follow namespace links in the index
381        $link = wl($ID, 'idx=' . rawurlencode($item['id']));
382        $ret .= '<a href="' . $link . '" title="' . $item['id'] . '" class="idx_dir" ' . $nofollow . '><strong>';
383        $ret .= $base;
384        $ret .= '</strong></a>';
385    }else{
386        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
387        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
388    }
389    return $ret;
390}
391
392/**
393 * Index List item
394 *
395 * This user function is used in html_buildlist to build the
396 * <li> tags for namespaces when displaying the page index
397 * it gives different classes to opened or closed "folders"
398 *
399 * @author Andreas Gohr <andi@splitbrain.org>
400 *
401 * @param array $item
402 * @return string html
403 */
404function html_li_index($item) { // FIXME: also called from inc/Ajax.php
405    global $INFO;
406    global $ACT;
407
408    $class = '';
409    $id = '';
410
411    if($item['type'] == "f"){
412        // scroll to the current item
413        if(isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') {
414            $id = ' id="scroll__here"';
415            $class = ' bounce';
416        }
417        return '<li class="level'.$item['level'].$class.'" '.$id.'>';
418    }elseif($item['open']){
419        return '<li class="open">';
420    }else{
421        return '<li class="closed">';
422    }
423}
424
425/**
426 * Default List item
427 *
428 * @author Andreas Gohr <andi@splitbrain.org>
429 *
430 * @param array $item
431 * @return string html
432 */
433function html_li_default($item) { // FIXME: should be closure in html_buildlist()?
434    return '<li class="level'.$item['level'].'">';
435}
436
437/**
438 * Build an unordered list
439 *
440 * Build an unordered list from the given $data array
441 * Each item in the array has to have a 'level' property
442 * the item itself gets printed by the given $func user
443 * function. The second and optional function is used to
444 * print the <li> tag. Both user function need to accept
445 * a single item.
446 *
447 * Both user functions can be given as array to point to
448 * a member of an object.
449 *
450 * @author Andreas Gohr <andi@splitbrain.org>
451 *
452 * @param array    $data  array with item arrays
453 * @param string   $class class of ul wrapper
454 * @param callable $func  callback to print an list item
455 * @param callable $lifunc callback to the opening li tag
456 * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
457 *                               0 (we have a root object) or 1 (just the root content)
458 * @return string html of an unordered list
459 */
460function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
461    if (count($data) === 0) {
462        return '';
463    }
464
465    $firstElement = reset($data);
466    $start_level = $firstElement['level'];
467    $level = $start_level;
468    $ret   = '';
469    $open  = 0;
470
471    foreach ($data as $item){
472
473        if( $item['level'] > $level ){
474            //open new list
475            for($i=0; $i<($item['level'] - $level); $i++){
476                if ($i) $ret .= "<li class=\"clear\">";
477                $ret .= "\n<ul class=\"$class\">\n";
478                $open++;
479            }
480            $level = $item['level'];
481
482        }elseif( $item['level'] < $level ){
483            //close last item
484            $ret .= "</li>\n";
485            while( $level > $item['level'] && $open > 0 ){
486                //close higher lists
487                $ret .= "</ul>\n</li>\n";
488                $level--;
489                $open--;
490            }
491        } elseif ($ret !== '') {
492            //close previous item
493            $ret .= "</li>\n";
494        }
495
496        //print item
497        $ret .= call_user_func($lifunc,$item);
498        $ret .= '<div class="li">';
499
500        $ret .= call_user_func($func,$item);
501        $ret .= '</div>';
502    }
503
504    //close remaining items and lists
505    $ret .= "</li>\n";
506    while($open-- > 0) {
507        $ret .= "</ul></li>\n";
508    }
509
510    if ($forcewrapper || $start_level < 2) {
511        // Trigger building a wrapper ul if the first level is
512        // 0 (we have a root object) or 1 (just the root content)
513        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
514    }
515
516    return $ret;
517}
518
519/**
520 * display backlinks
521 *
522 * @author Andreas Gohr <andi@splitbrain.org>
523 * @author Michael Klier <chi@chimeric.de>
524 * @deprecated 2020-07-18
525 */
526function html_backlinks() {
527    (new dokuwiki\Ui\Backlinks)->show();
528}
529
530/**
531 * Show diff
532 * between current page version and provided $text
533 * or between the revisions provided via GET or POST
534 *
535 * @author Andreas Gohr <andi@splitbrain.org>
536 * @param  string $text  when non-empty: compare with this text with most current version
537 * @param  bool   $intro display the intro text
538 * @param  string $type  type of the diff (inline or sidebyside)
539 * @deprecated 2020-07-18
540 */
541function html_diff($text = '', $intro = true, $type = null) {
542    (new dokuwiki\Ui\Diff($text, $intro, $type))->show();
543}
544
545/**
546 * show warning on conflict detection
547 *
548 * @author Andreas Gohr <andi@splitbrain.org>
549 *
550 * @param string $text
551 * @param string $summary
552 * @deprecated 2020-07-18
553 */
554function html_conflict($text, $summary) {
555    (new dokuwiki\Ui\Conflict($text, $summary))->show();
556}
557
558/**
559 * Prints the global message array
560 *
561 * @author Andreas Gohr <andi@splitbrain.org>
562 */
563function html_msgarea(){
564    global $MSG, $MSG_shown;
565    /** @var array $MSG */
566    // store if the global $MSG has already been shown and thus HTML output has been started
567    $MSG_shown = true;
568
569    if(!isset($MSG)) return;
570
571    $shown = array();
572    foreach($MSG as $msg){
573        $hash = md5($msg['msg']);
574        if(isset($shown[$hash])) continue; // skip double messages
575        if(info_msg_allowed($msg)){
576            print '<div class="'.$msg['lvl'].'">';
577            print $msg['msg'];
578            print '</div>';
579        }
580        $shown[$hash] = 1;
581    }
582
583    unset($GLOBALS['MSG']);
584}
585
586/**
587 * Prints the registration form
588 *
589 * @author Andreas Gohr <andi@splitbrain.org>
590 * @deprecated 2020-07-18
591 */
592function html_register() {
593    (new dokuwiki\Ui\UserRegister)->show();
594}
595
596/**
597 * Print the update profile form
598 *
599 * @author Christopher Smith <chris@jalakai.co.uk>
600 * @author Andreas Gohr <andi@splitbrain.org>
601 * @deprecated 2020-07-18
602 */
603function html_updateprofile() {
604    (new dokuwiki\Ui\UserProfile)->show();
605}
606
607/**
608 * Preprocess edit form data
609 *
610 * @author   Andreas Gohr <andi@splitbrain.org>
611 *
612 * @triggers HTML_EDITFORM_OUTPUT
613 * @deprecated 2020-07-18
614 */
615function html_edit() {
616    (new dokuwiki\Ui\Editor)->show();
617}
618
619/**
620 * prints some debug info
621 *
622 * @author Andreas Gohr <andi@splitbrain.org>
623 */
624function html_debug(){
625    global $conf;
626    global $lang;
627    /** @var AuthPlugin $auth */
628    global $auth;
629    global $INFO;
630
631    //remove sensitive data
632    $cnf = $conf;
633    debug_guard($cnf);
634    $nfo = $INFO;
635    debug_guard($nfo);
636    $ses = $_SESSION;
637    debug_guard($ses);
638
639    print '<html><body>';
640
641    print '<p>When reporting bugs please send all the following ';
642    print 'output as a mail to andi@splitbrain.org ';
643    print 'The best way to do this is to save this page in your browser</p>';
644
645    print '<b>$INFO:</b><pre>';
646    print_r($nfo);
647    print '</pre>';
648
649    print '<b>$_SERVER:</b><pre>';
650    print_r($_SERVER);
651    print '</pre>';
652
653    print '<b>$conf:</b><pre>';
654    print_r($cnf);
655    print '</pre>';
656
657    print '<b>DOKU_BASE:</b><pre>';
658    print DOKU_BASE;
659    print '</pre>';
660
661    print '<b>abs DOKU_BASE:</b><pre>';
662    print DOKU_URL;
663    print '</pre>';
664
665    print '<b>rel DOKU_BASE:</b><pre>';
666    print dirname($_SERVER['PHP_SELF']).'/';
667    print '</pre>';
668
669    print '<b>PHP Version:</b><pre>';
670    print phpversion();
671    print '</pre>';
672
673    print '<b>locale:</b><pre>';
674    print setlocale(LC_ALL,0);
675    print '</pre>';
676
677    print '<b>encoding:</b><pre>';
678    print $lang['encoding'];
679    print '</pre>';
680
681    if($auth){
682        print '<b>Auth backend capabilities:</b><pre>';
683        foreach ($auth->getCapabilities() as $cando){
684            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
685        }
686        print '</pre>';
687    }
688
689    print '<b>$_SESSION:</b><pre>';
690    print_r($ses);
691    print '</pre>';
692
693    print '<b>Environment:</b><pre>';
694    print_r($_ENV);
695    print '</pre>';
696
697    print '<b>PHP settings:</b><pre>';
698    $inis = ini_get_all();
699    print_r($inis);
700    print '</pre>';
701
702    if (function_exists('apache_get_version')) {
703        $apache = array();
704        $apache['version'] = apache_get_version();
705
706        if (function_exists('apache_get_modules')) {
707            $apache['modules'] = apache_get_modules();
708        }
709        print '<b>Apache</b><pre>';
710        print_r($apache);
711        print '</pre>';
712    }
713
714    print '</body></html>';
715}
716
717/**
718 * Form to request a new password for an existing account
719 *
720 * @author Benoit Chesneau <benoit@bchesneau.info>
721 * @author Andreas Gohr <gohr@cosmocode.de>
722 * @deprecated 2020-07-18
723 */
724function html_resendpwd() {
725    (new dokuwiki\Ui\UserResendPwd)->show();
726}
727
728/**
729 * Return the TOC rendered to XHTML
730 *
731 * @author Andreas Gohr <andi@splitbrain.org>
732 *
733 * @param array $toc
734 * @return string html
735 */
736function html_TOC($toc){
737    if(!count($toc)) return '';
738    global $lang;
739    $out  = '<!-- TOC START -->'.DOKU_LF;
740    $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF;
741    $out .= '<h3 class="toggle">';
742    $out .= $lang['toc'];
743    $out .= '</h3>'.DOKU_LF;
744    $out .= '<div>'.DOKU_LF;
745    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
746    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
747    $out .= '<!-- TOC END -->'.DOKU_LF;
748    return $out;
749}
750
751/**
752 * Callback for html_buildlist
753 *
754 * @param array $item
755 * @return string html
756 */
757function html_list_toc($item){
758    if(isset($item['hid'])){
759        $link = '#'.$item['hid'];
760    }else{
761        $link = $item['link'];
762    }
763
764    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
765}
766
767/**
768 * Helper function to build TOC items
769 *
770 * Returns an array ready to be added to a TOC array
771 *
772 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
773 * @param string $text  - what to display in the TOC
774 * @param int    $level - nesting level
775 * @param string $hash  - is prepended to the given $link, set blank if you want full links
776 * @return array the toc item
777 */
778function html_mktocitem($link, $text, $level, $hash='#'){
779    return  array( 'link'  => $hash.$link,
780            'title' => $text,
781            'type'  => 'ul',
782            'level' => $level);
783}
784
785/**
786 * Output a Doku_Form object.
787 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
788 *
789 * @author Tom N Harris <tnharris@whoopdedo.org>
790 *
791 * @param string     $name The name of the form
792 * @param Doku_Form  $form The form
793 */
794function html_form($name, $form) {
795    // Safety check in case the caller forgets.
796    $form->endFieldset();
797    Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
798}
799
800/**
801 * Form print function.
802 * Just calls printForm() on the form object.
803 *
804 * @param Doku_Form $form The form
805 */
806function html_form_output($form) {
807    $form->printForm();
808}
809
810/**
811 * Embed a flash object in HTML
812 *
813 * This will create the needed HTML to embed a flash movie in a cross browser
814 * compatble way using valid XHTML
815 *
816 * The parameters $params, $flashvars and $atts need to be associative arrays.
817 * No escaping needs to be done for them. The alternative content *has* to be
818 * escaped because it is used as is. If no alternative content is given
819 * $lang['noflash'] is used.
820 *
821 * @author Andreas Gohr <andi@splitbrain.org>
822 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
823 *
824 * @param string $swf      - the SWF movie to embed
825 * @param int $width       - width of the flash movie in pixels
826 * @param int $height      - height of the flash movie in pixels
827 * @param array $params    - additional parameters (<param>)
828 * @param array $flashvars - parameters to be passed in the flashvar parameter
829 * @param array $atts      - additional attributes for the <object> tag
830 * @param string $alt      - alternative content (is NOT automatically escaped!)
831 * @return string         - the XHTML markup
832 */
833function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
834    global $lang;
835
836    $out = '';
837
838    // prepare the object attributes
839    if(is_null($atts)) $atts = array();
840    $atts['width']  = (int) $width;
841    $atts['height'] = (int) $height;
842    if(!$atts['width'])  $atts['width']  = 425;
843    if(!$atts['height']) $atts['height'] = 350;
844
845    // add object attributes for standard compliant browsers
846    $std = $atts;
847    $std['type'] = 'application/x-shockwave-flash';
848    $std['data'] = $swf;
849
850    // add object attributes for IE
851    $ie  = $atts;
852    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
853
854    // open object (with conditional comments)
855    $out .= '<!--[if !IE]> -->'.NL;
856    $out .= '<object '.buildAttributes($std).'>'.NL;
857    $out .= '<!-- <![endif]-->'.NL;
858    $out .= '<!--[if IE]>'.NL;
859    $out .= '<object '.buildAttributes($ie).'>'.NL;
860    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
861    $out .= '<!--><!-- -->'.NL;
862
863    // print params
864    if(is_array($params)) foreach($params as $key => $val){
865        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
866    }
867
868    // add flashvars
869    if(is_array($flashvars)){
870        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
871    }
872
873    // alternative content
874    if($alt){
875        $out .= $alt.NL;
876    }else{
877        $out .= $lang['noflash'].NL;
878    }
879
880    // finish
881    $out .= '</object>'.NL;
882    $out .= '<!-- <![endif]-->'.NL;
883
884    return $out;
885}
886
887/**
888 * Prints HTML code for the given tab structure
889 *
890 * @param array  $tabs        tab structure
891 * @param string $current_tab the current tab id
892 */
893function html_tabs($tabs, $current_tab = null) {
894    echo '<ul class="tabs">'.NL;
895
896    foreach($tabs as $id => $tab) {
897        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
898    }
899
900    echo '</ul>'.NL;
901}
902
903/**
904 * Prints a single tab
905 *
906 * @author Kate Arzamastseva <pshns@ukr.net>
907 * @author Adrian Lang <mail@adrianlang.de>
908 *
909 * @param string $href - tab href
910 * @param string $caption - tab caption
911 * @param boolean $selected - is tab selected
912 */
913
914function html_tab($href, $caption, $selected=false) {
915    $tab = '<li>';
916    if ($selected) {
917        $tab .= '<strong>';
918    } else {
919        $tab .= '<a href="' . hsc($href) . '">';
920    }
921    $tab .= hsc($caption)
922         .  '</' . ($selected ? 'strong' : 'a') . '>'
923         .  '</li>'.NL;
924    echo $tab;
925}
926
927/**
928 * Display size change
929 *
930 * @param int $sizechange - size of change in Bytes
931 * @param Doku_Form $form - (optional) form to add elements to
932 * @return void|string
933 */
934function html_sizechange($sizechange, $form = null) {
935    if (isset($sizechange)) {
936        $class = 'sizechange';
937        $value = filesize_h(abs($sizechange));
938        if ($sizechange > 0) {
939            $class .= ' positive';
940            $value = '+' . $value;
941        } elseif ($sizechange < 0) {
942            $class .= ' negative';
943            $value = '-' . $value;
944        } else {
945            $value = '±' . $value;
946        }
947        if (!isset($form)) {
948            return '<span class="'.$class.'">'.$value.'</span>';
949        } else { // Doku_Form
950            $form->addElement(form_makeOpenTag('span', array('class' => $class)));
951            $form->addElement($value);
952            $form->addElement(form_makeCloseTag('span'));
953        }
954    }
955}
956