xref: /dokuwiki/inc/html.php (revision 0e6682672bb6ed779e4d8585c07cdc0ed57d81e5)
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
9if(!defined('DOKU_INC')) die('meh.');
10if(!defined('NL')) define('NL',"\n");
11
12/**
13 * Convenience function to quickly build a wikilink
14 *
15 * @author Andreas Gohr <andi@splitbrain.org>
16 * @param string  $id      id of the target page
17 * @param string  $name    the name of the link, i.e. the text that is displayed
18 * @param string|array  $search  search string(s) that shall be highlighted in the target page
19 * @return string the HTML code of the link
20 */
21function html_wikilink($id,$name=null,$search=''){
22    static $xhtml_renderer = null;
23    if(is_null($xhtml_renderer)){
24        $xhtml_renderer = p_get_renderer('xhtml');
25    }
26
27    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
28}
29
30/**
31 * The loginform
32 *
33 * @author   Andreas Gohr <andi@splitbrain.org>
34 */
35function html_login(){
36    global $lang;
37    global $conf;
38    global $ID;
39    global $INPUT;
40
41    print p_locale_xhtml('login');
42    print '<div class="centeralign">'.NL;
43    $form = new Doku_Form(array('id' => 'dw__login'));
44    $form->startFieldset($lang['btn_login']);
45    $form->addHidden('id', $ID);
46    $form->addHidden('do', 'login');
47    $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block'));
48    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
49    if($conf['rememberme']) {
50        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
51    }
52    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
53    $form->endFieldset();
54
55    if(actionOK('register')){
56        $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>');
57    }
58
59    if (actionOK('resendpwd')) {
60        $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>');
61    }
62
63    html_form('login', $form);
64    print '</div>'.NL;
65}
66
67/**
68 * inserts section edit buttons if wanted or removes the markers
69 *
70 * @author Andreas Gohr <andi@splitbrain.org>
71 */
72function html_secedit($text,$show=true){
73    global $INFO;
74
75    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
76
77    if(!$INFO['writable'] || !$show || $INFO['rev']){
78        return preg_replace($regexp,'',$text);
79    }
80
81    return preg_replace_callback($regexp,
82                'html_secedit_button', $text);
83}
84
85/**
86 * prepares section edit button data for event triggering
87 * used as a callback in html_secedit
88 *
89 * @triggers HTML_SECEDIT_BUTTON
90 * @author Andreas Gohr <andi@splitbrain.org>
91 */
92function html_secedit_button($matches){
93    $data = array('secid'  => $matches[1],
94                  'target' => strtolower($matches[2]),
95                  'range'  => $matches[count($matches) - 1]);
96    if (count($matches) === 5) {
97        $data['name'] = $matches[3];
98    }
99
100    return trigger_event('HTML_SECEDIT_BUTTON', $data,
101                         'html_secedit_get_button');
102}
103
104/**
105 * prints a section editing button
106 * used as default action form HTML_SECEDIT_BUTTON
107 *
108 * @author Adrian Lang <lang@cosmocode.de>
109 */
110function html_secedit_get_button($data) {
111    global $ID;
112    global $INFO;
113
114    if (!isset($data['name']) || $data['name'] === '') return '';
115
116    $name = $data['name'];
117    unset($data['name']);
118
119    $secid = $data['secid'];
120    unset($data['secid']);
121
122    return "<div class='secedit editbutton_" . $data['target'] .
123                       " editbutton_" . $secid . "'>" .
124           html_btn('secedit', $ID, '',
125                    array_merge(array('do'  => 'edit',
126                                      'rev' => $INFO['lastmod'],
127                                      'summary' => '['.$name.'] '), $data),
128                    'post', $name) . '</div>';
129}
130
131/**
132 * Just the back to top button (in its own form)
133 *
134 * @author Andreas Gohr <andi@splitbrain.org>
135 */
136function html_topbtn(){
137    global $lang;
138
139    $ret  = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>';
140
141    return $ret;
142}
143
144/**
145 * Displays a button (using its own form)
146 * If tooltip exists, the access key tooltip is replaced.
147 *
148 * @author Andreas Gohr <andi@splitbrain.org>
149 */
150function html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){
151    global $conf;
152    global $lang;
153
154    if (!$label)
155        $label = $lang['btn_'.$name];
156
157    $ret = '';
158
159    //filter id (without urlencoding)
160    $id = idfilter($id,false);
161
162    //make nice URLs even for buttons
163    if($conf['userewrite'] == 2){
164        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
165    }elseif($conf['userewrite']){
166        $script = DOKU_BASE.$id;
167    }else{
168        $script = DOKU_BASE.DOKU_SCRIPT;
169        $params['id'] = $id;
170    }
171
172    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
173
174    if(is_array($params)){
175        reset($params);
176        while (list($key, $val) = each($params)) {
177            $ret .= '<input type="hidden" name="'.$key.'" ';
178            $ret .= 'value="'.htmlspecialchars($val).'" />';
179        }
180    }
181
182    if ($tooltip!='') {
183        $tip = htmlspecialchars($tooltip);
184    }else{
185        $tip = htmlspecialchars($label);
186    }
187
188    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
189    if($akey){
190        $tip .= ' ['.strtoupper($akey).']';
191        $ret .= 'accesskey="'.$akey.'" ';
192    }
193    $ret .= 'title="'.$tip.'" ';
194    $ret .= '/>';
195    $ret .= '</div></form>';
196
197    return $ret;
198}
199
200/**
201 * show a wiki page
202 *
203 * @author Andreas Gohr <andi@splitbrain.org>
204 */
205function html_show($txt=null){
206    global $ID;
207    global $REV;
208    global $HIGH;
209    global $INFO;
210    //disable section editing for old revisions or in preview
211    if($txt || $REV){
212        $secedit = false;
213    }else{
214        $secedit = true;
215    }
216
217    if (!is_null($txt)){
218        //PreviewHeader
219        echo '<br id="scroll__here" />';
220        echo p_locale_xhtml('preview');
221        echo '<div class="preview"><div class="pad">';
222        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
223        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
224        echo $html;
225        echo '<div class="clearer"></div>';
226        echo '</div></div>';
227
228    }else{
229        if ($REV) print p_locale_xhtml('showrev');
230        $html = p_wiki_xhtml($ID,$REV,true);
231        $html = html_secedit($html,$secedit);
232        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
233        $html = html_hilight($html,$HIGH);
234        echo $html;
235    }
236}
237
238/**
239 * ask the user about how to handle an exisiting draft
240 *
241 * @author Andreas Gohr <andi@splitbrain.org>
242 */
243function html_draft(){
244    global $INFO;
245    global $ID;
246    global $lang;
247    $draft = unserialize(io_readFile($INFO['draft'],false));
248    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
249
250    print p_locale_xhtml('draft');
251    $form = new Doku_Form(array('id' => 'dw__editform'));
252    $form->addHidden('id', $ID);
253    $form->addHidden('date', $draft['date']);
254    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
255    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
256    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
257    $form->addElement(form_makeCloseTag('div'));
258    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
259    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
260    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
261    html_form('draft', $form);
262}
263
264/**
265 * Highlights searchqueries in HTML code
266 *
267 * @author Andreas Gohr <andi@splitbrain.org>
268 * @author Harry Fuecks <hfuecks@gmail.com>
269 */
270function html_hilight($html,$phrases){
271    $phrases = (array) $phrases;
272    $phrases = array_map('preg_quote_cb', $phrases);
273    $phrases = array_map('ft_snippet_re_preprocess', $phrases);
274    $phrases = array_filter($phrases);
275    $regex = join('|',$phrases);
276
277    if ($regex === '') return $html;
278    if (!utf8_check($regex)) return $html;
279    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
280    return $html;
281}
282
283/**
284 * Callback used by html_hilight()
285 *
286 * @author Harry Fuecks <hfuecks@gmail.com>
287 */
288function html_hilight_callback($m) {
289    $hlight = unslash($m[0]);
290    if ( !isset($m[2])) {
291        $hlight = '<span class="search_hit">'.$hlight.'</span>';
292    }
293    return $hlight;
294}
295
296/**
297 * Run a search and display the result
298 *
299 * @author Andreas Gohr <andi@splitbrain.org>
300 */
301function html_search(){
302    global $QUERY;
303    global $lang;
304
305    $intro = p_locale_xhtml('searchpage');
306    // allow use of placeholder in search intro
307    $intro = str_replace(
308                array('@QUERY@','@SEARCH@'),
309                array(hsc(rawurlencode($QUERY)),hsc($QUERY)),
310                $intro);
311    echo $intro;
312    flush();
313
314    //show progressbar
315    print '<div id="dw__loading">'.NL;
316    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
317    print 'showLoadBar();'.NL;
318    print '/*!]]>*/</script>'.NL;
319    print '</div>'.NL;
320    flush();
321
322    //do quick pagesearch
323    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
324    if(count($data)){
325        print '<div class="search_quickresult">';
326        print '<h3>'.$lang['quickhits'].':</h3>';
327        print '<ul class="search_quickhits">';
328        foreach($data as $id => $title){
329            print '<li> ';
330            if (useHeading('navigation')) {
331                $name = $title;
332            }else{
333                $ns = getNS($id);
334                if($ns){
335                    $name = shorten(noNS($id), ' ('.$ns.')',30);
336                }else{
337                    $name = $id;
338                }
339            }
340            print html_wikilink(':'.$id,$name);
341            print '</li> ';
342        }
343        print '</ul> ';
344        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
345        print '<div class="clearer"></div>';
346        print '</div>';
347    }
348    flush();
349
350    //do fulltext search
351    $data = ft_pageSearch($QUERY,$regex);
352    if(count($data)){
353        print '<dl class="search_results">';
354        $num = 1;
355        foreach($data as $id => $cnt){
356            print '<dt>';
357            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
358            if($cnt !== 0){
359                print ': '.$cnt.' '.$lang['hits'].'';
360            }
361            print '</dt>';
362            if($cnt !== 0){
363                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
364                    print '<dd>'.ft_snippet($id,$regex).'</dd>';
365                }
366                $num++;
367            }
368            flush();
369        }
370        print '</dl>';
371    }else{
372        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
373    }
374
375    //hide progressbar
376    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
377    print 'hideLoadBar("dw__loading");'.NL;
378    print '/*!]]>*/</script>'.NL;
379    flush();
380}
381
382/**
383 * Display error on locked pages
384 *
385 * @author Andreas Gohr <andi@splitbrain.org>
386 */
387function html_locked(){
388    global $ID;
389    global $conf;
390    global $lang;
391    global $INFO;
392
393    $locktime = filemtime(wikiLockFN($ID));
394    $expire = dformat($locktime + $conf['locktime']);
395    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
396
397    print p_locale_xhtml('locked');
398    print '<ul>';
399    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
400    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
401    print '</ul>';
402}
403
404/**
405 * list old revisions
406 *
407 * @author Andreas Gohr <andi@splitbrain.org>
408 * @author Ben Coburn <btcoburn@silicodon.net>
409 * @author Kate Arzamastseva <pshns@ukr.net>
410 */
411function html_revisions($first=0, $media_id = false){
412    global $ID;
413    global $INFO;
414    global $conf;
415    global $lang;
416    $id = $ID;
417    /* we need to get one additional log entry to be able to
418     * decide if this is the last page or is there another one.
419     * see html_recent()
420     */
421    if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
422    else {
423        $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
424        $id = $media_id;
425    }
426
427    if(count($revisions)==0 && $first!=0){
428        $first=0;
429        if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
430        else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
431    }
432    $hasNext = false;
433    if (count($revisions)>$conf['recent']) {
434        $hasNext = true;
435        array_pop($revisions); // remove extra log entry
436    }
437
438    if (!$media_id) $date = dformat($INFO['lastmod']);
439    else $date = dformat(@filemtime(mediaFN($id)));
440
441    if (!$media_id) print p_locale_xhtml('revisions');
442
443    $params = array('id' => 'page__revisions', 'class' => 'changes');
444    if ($media_id) $params['action'] = media_managerURL(array('image' => $media_id), '&');
445
446    $form = new Doku_Form($params);
447    $form->addElement(form_makeOpenTag('ul'));
448
449    if (!$media_id) $exists = $INFO['exists'];
450    else $exists = @file_exists(mediaFN($id));
451
452    $display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id;
453    if (!$display_name) $display_name = $id;
454
455    if($exists && $first==0){
456        if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
457            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
458        else
459            $form->addElement(form_makeOpenTag('li'));
460        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
461        $form->addElement(form_makeTag('input', array(
462                        'type' => 'checkbox',
463                        'name' => 'rev2[]',
464                        'value' => 'current')));
465
466        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
467        $form->addElement($date);
468        $form->addElement(form_makeCloseTag('span'));
469
470        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
471
472        if (!$media_id) $href = wl($id);
473        else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
474        $form->addElement(form_makeOpenTag('a', array(
475                        'class' => 'wikilink1',
476                        'href'  => $href)));
477        $form->addElement($display_name);
478        $form->addElement(form_makeCloseTag('a'));
479
480        if ($media_id) $form->addElement(form_makeOpenTag('div'));
481
482        if (!$media_id) {
483            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
484            $form->addElement(' – ');
485            $form->addElement(htmlspecialchars($INFO['sum']));
486            $form->addElement(form_makeCloseTag('span'));
487        }
488
489        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
490        if (!$media_id) $editor = $INFO['editor'];
491        else {
492            $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true);
493            if($revinfo['user']){
494                $editor = $revinfo['user'];
495            }else{
496                $editor = $revinfo['ip'];
497            }
498        }
499        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor));
500        $form->addElement(form_makeCloseTag('span'));
501
502        $form->addElement('('.$lang['current'].')');
503
504        if ($media_id) $form->addElement(form_makeCloseTag('div'));
505
506        $form->addElement(form_makeCloseTag('div'));
507        $form->addElement(form_makeCloseTag('li'));
508    }
509
510    foreach($revisions as $rev){
511        $date = dformat($rev);
512        if (!$media_id) {
513            $info = getRevisionInfo($id,$rev,true);
514            $exists = page_exists($id,$rev);
515        }  else {
516            $info = getRevisionInfo($id,$rev,true,true);
517            $exists = @file_exists(mediaFN($id,$rev));
518        }
519
520        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
521            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
522        else
523            $form->addElement(form_makeOpenTag('li'));
524        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
525        if($exists){
526            $form->addElement(form_makeTag('input', array(
527                            'type' => 'checkbox',
528                            'name' => 'rev2[]',
529                            'value' => $rev)));
530        }else{
531            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
532        }
533
534        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
535        $form->addElement($date);
536        $form->addElement(form_makeCloseTag('span'));
537
538        if($exists){
539            if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&');
540            else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
541            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link')));
542            $form->addElement(form_makeTag('img', array(
543                            'src'    => DOKU_BASE.'lib/images/diff.png',
544                            'width'  => 15,
545                            'height' => 11,
546                            'title'  => $lang['diff'],
547                            'alt'    => $lang['diff'])));
548            $form->addElement(form_makeCloseTag('a'));
549            if (!$media_id) $href = wl($id,"rev=$rev",false,'&');
550            else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
551            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1')));
552            $form->addElement($display_name);
553            $form->addElement(form_makeCloseTag('a'));
554        }else{
555            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
556            $form->addElement($display_name);
557        }
558
559        if ($media_id) $form->addElement(form_makeOpenTag('div'));
560
561        if ($info['sum']) {
562            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
563            if (!$media_id) $form->addElement(' – ');
564            $form->addElement('<bdi>'.htmlspecialchars($info['sum']).'</bdi>');
565            $form->addElement(form_makeCloseTag('span'));
566        }
567
568        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
569        if($info['user']){
570            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
571            if(auth_ismanager()){
572                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
573            }
574        }else{
575            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
576        }
577        $form->addElement(form_makeCloseTag('span'));
578
579        if ($media_id) $form->addElement(form_makeCloseTag('div'));
580
581        $form->addElement(form_makeCloseTag('div'));
582        $form->addElement(form_makeCloseTag('li'));
583    }
584    $form->addElement(form_makeCloseTag('ul'));
585    if (!$media_id) {
586        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
587    } else {
588        $form->addHidden('mediado', 'diff');
589        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
590    }
591    html_form('revisions', $form);
592
593    print '<div class="pagenav">';
594    $last = $first + $conf['recent'];
595    if ($first > 0) {
596        $first -= $conf['recent'];
597        if ($first < 0) $first = 0;
598        print '<div class="pagenav-prev">';
599        if ($media_id) {
600            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
601        } else {
602            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
603        }
604        print '</div>';
605    }
606    if ($hasNext) {
607        print '<div class="pagenav-next">';
608        if ($media_id) {
609            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
610        } else {
611            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
612        }
613        print '</div>';
614    }
615    print '</div>';
616
617}
618
619/**
620 * display recent changes
621 *
622 * @author Andreas Gohr <andi@splitbrain.org>
623 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
624 * @author Ben Coburn <btcoburn@silicodon.net>
625 * @author Kate Arzamastseva <pshns@ukr.net>
626 */
627function html_recent($first=0, $show_changes='both'){
628    global $conf;
629    global $lang;
630    global $ID;
631    /* we need to get one additionally log entry to be able to
632     * decide if this is the last page or is there another one.
633     * This is the cheapest solution to get this information.
634     */
635    $flags = 0;
636    if ($show_changes == 'mediafiles' && $conf['mediarevisions']) {
637        $flags = RECENTS_MEDIA_CHANGES;
638    } elseif ($show_changes == 'pages') {
639        $flags = 0;
640    } elseif ($conf['mediarevisions']) {
641        $show_changes = 'both';
642        $flags = RECENTS_MEDIA_PAGES_MIXED;
643    }
644
645    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
646    if(count($recents) == 0 && $first != 0){
647        $first=0;
648        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
649    }
650    $hasNext = false;
651    if (count($recents)>$conf['recent']) {
652        $hasNext = true;
653        array_pop($recents); // remove extra log entry
654    }
655
656    print p_locale_xhtml('recent');
657
658    if (getNS($ID) != '')
659        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
660
661    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
662    $form->addHidden('sectok', null);
663    $form->addHidden('do', 'recent');
664    $form->addHidden('id', $ID);
665
666    if ($conf['mediarevisions']) {
667        $form->addElement('<div class="changeType">');
668        $form->addElement(form_makeListboxField(
669                    'show_changes',
670                    array(
671                        'pages'      => $lang['pages_changes'],
672                        'mediafiles' => $lang['media_changes'],
673                        'both'       => $lang['both_changes']),
674                    $show_changes,
675                    $lang['changes_type'],
676                    '','',
677                    array('class'=>'quickselect')));
678
679        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
680        $form->addElement('</div>');
681    }
682
683    $form->addElement(form_makeOpenTag('ul'));
684
685    foreach($recents as $recent){
686        $date = dformat($recent['date']);
687        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
688            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
689        else
690            $form->addElement(form_makeOpenTag('li'));
691
692        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
693
694        if ($recent['media']) {
695            $form->addElement(media_printicon($recent['id']));
696        } else {
697            $icon = DOKU_BASE.'lib/images/fileicons/file.png';
698            $form->addElement('<img src="'.$icon.'" alt="'.$recent['id'].'" class="icon" />');
699        }
700
701        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
702        $form->addElement($date);
703        $form->addElement(form_makeCloseTag('span'));
704
705        $diff = false;
706        $href = '';
707
708        if ($recent['media']) {
709            $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id'])));
710            if ($diff) {
711                $href = media_managerURL(array('tab_details' => 'history',
712                    'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
713            }
714        } else {
715            $href = wl($recent['id'],"do=diff", false, '&');
716        }
717
718        if ($recent['media'] && !$diff) {
719            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
720        } else {
721            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
722            $form->addElement(form_makeTag('img', array(
723                            'src'   => DOKU_BASE.'lib/images/diff.png',
724                            'width' => 15,
725                            'height'=> 11,
726                            'title' => $lang['diff'],
727                            'alt'   => $lang['diff']
728                            )));
729            $form->addElement(form_makeCloseTag('a'));
730        }
731
732        if ($recent['media']) {
733            $href = media_managerURL(array('tab_details' => 'history',
734                'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
735        } else {
736            $href = wl($recent['id'],"do=revisions",false,'&');
737        }
738        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => $href)));
739        $form->addElement(form_makeTag('img', array(
740                        'src'   => DOKU_BASE.'lib/images/history.png',
741                        'width' => 12,
742                        'height'=> 14,
743                        'title' => $lang['btn_revs'],
744                        'alt'   => $lang['btn_revs']
745                        )));
746        $form->addElement(form_makeCloseTag('a'));
747
748        if ($recent['media']) {
749            $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
750            $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2';
751            $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href)));
752            $form->addElement($recent['id']);
753            $form->addElement(form_makeCloseTag('a'));
754        } else {
755            $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
756        }
757        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
758        $form->addElement(' – '.htmlspecialchars($recent['sum']));
759        $form->addElement(form_makeCloseTag('span'));
760
761        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
762        if($recent['user']){
763            $form->addElement('<bdi>'.editorinfo($recent['user']).'</bdi>');
764            if(auth_ismanager()){
765                $form->addElement(' <bdo dir="ltr">('.$recent['ip'].')</bdo>');
766            }
767        }else{
768            $form->addElement('<bdo dir="ltr">'.$recent['ip'].'</bdo>');
769        }
770        $form->addElement(form_makeCloseTag('span'));
771
772        $form->addElement(form_makeCloseTag('div'));
773        $form->addElement(form_makeCloseTag('li'));
774    }
775    $form->addElement(form_makeCloseTag('ul'));
776
777    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
778    $last = $first + $conf['recent'];
779    if ($first > 0) {
780        $first -= $conf['recent'];
781        if ($first < 0) $first = 0;
782        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
783        $form->addElement(form_makeTag('input', array(
784                    'type'  => 'submit',
785                    'name'  => 'first['.$first.']',
786                    'value' => $lang['btn_newer'],
787                    'accesskey' => 'n',
788                    'title' => $lang['btn_newer'].' [N]',
789                    'class' => 'button show'
790                    )));
791        $form->addElement(form_makeCloseTag('div'));
792    }
793    if ($hasNext) {
794        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
795        $form->addElement(form_makeTag('input', array(
796                        'type'  => 'submit',
797                        'name'  => 'first['.$last.']',
798                        'value' => $lang['btn_older'],
799                        'accesskey' => 'p',
800                        'title' => $lang['btn_older'].' [P]',
801                        'class' => 'button show'
802                        )));
803        $form->addElement(form_makeCloseTag('div'));
804    }
805    $form->addElement(form_makeCloseTag('div'));
806    html_form('recent', $form);
807}
808
809/**
810 * Display page index
811 *
812 * @author Andreas Gohr <andi@splitbrain.org>
813 */
814function html_index($ns){
815    global $conf;
816    global $ID;
817    $ns  = cleanID($ns);
818    #fixme use appropriate function
819    if(empty($ns)){
820        $ns = dirname(str_replace(':','/',$ID));
821        if($ns == '.') $ns ='';
822    }
823    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
824
825    echo p_locale_xhtml('index');
826    echo '<div id="index__tree">';
827
828    $data = array();
829    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
830    echo html_buildlist($data,'idx','html_list_index','html_li_index');
831
832    echo '</div>';
833}
834
835/**
836 * Index item formatter
837 *
838 * User function for html_buildlist()
839 *
840 * @author Andreas Gohr <andi@splitbrain.org>
841 */
842function html_list_index($item){
843    global $ID, $conf;
844
845    // prevent searchbots needlessly following links
846    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : '';
847
848    $ret = '';
849    $base = ':'.$item['id'];
850    $base = substr($base,strrpos($base,':')+1);
851    if($item['type']=='d'){
852        // FS#2766, no need for search bots to follow namespace links in the index
853        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>';
854        $ret .= $base;
855        $ret .= '</strong></a>';
856    }else{
857        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
858        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
859    }
860    return $ret;
861}
862
863/**
864 * Index List item
865 *
866 * This user function is used in html_buildlist to build the
867 * <li> tags for namespaces when displaying the page index
868 * it gives different classes to opened or closed "folders"
869 *
870 * @author Andreas Gohr <andi@splitbrain.org>
871 */
872function html_li_index($item){
873    if($item['type'] == "f"){
874        return '<li class="level'.$item['level'].'">';
875    }elseif($item['open']){
876        return '<li class="open">';
877    }else{
878        return '<li class="closed">';
879    }
880}
881
882/**
883 * Default List item
884 *
885 * @author Andreas Gohr <andi@splitbrain.org>
886 */
887function html_li_default($item){
888    return '<li class="level'.$item['level'].'">';
889}
890
891/**
892 * Build an unordered list
893 *
894 * Build an unordered list from the given $data array
895 * Each item in the array has to have a 'level' property
896 * the item itself gets printed by the given $func user
897 * function. The second and optional function is used to
898 * print the <li> tag. Both user function need to accept
899 * a single item.
900 *
901 * Both user functions can be given as array to point to
902 * a member of an object.
903 *
904 * @author Andreas Gohr <andi@splitbrain.org>
905 */
906function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
907    if (count($data) === 0) {
908        return '';
909    }
910
911    $start_level = $data[0]['level'];
912    $level = $start_level;
913    $ret   = '';
914    $open  = 0;
915
916    foreach ($data as $item){
917
918        if( $item['level'] > $level ){
919            //open new list
920            for($i=0; $i<($item['level'] - $level); $i++){
921                if ($i) $ret .= "<li class=\"clear\">";
922                $ret .= "\n<ul class=\"$class\">\n";
923                $open++;
924            }
925            $level = $item['level'];
926
927        }elseif( $item['level'] < $level ){
928            //close last item
929            $ret .= "</li>\n";
930            while( $level > $item['level'] && $open > 0 ){
931                //close higher lists
932                $ret .= "</ul>\n</li>\n";
933                $level--;
934                $open--;
935            }
936        } elseif ($ret !== '') {
937            //close previous item
938            $ret .= "</li>\n";
939        }
940
941        //print item
942        $ret .= call_user_func($lifunc,$item);
943        $ret .= '<div class="li">';
944
945        $ret .= call_user_func($func,$item);
946        $ret .= '</div>';
947    }
948
949    //close remaining items and lists
950    $ret .= "</li>\n";
951    while($open-- > 0) {
952        $ret .= "</ul></li>\n";
953    }
954
955    if ($forcewrapper || $start_level < 2) {
956        // Trigger building a wrapper ul if the first level is
957        // 0 (we have a root object) or 1 (just the root content)
958        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
959    }
960
961    return $ret;
962}
963
964/**
965 * display backlinks
966 *
967 * @author Andreas Gohr <andi@splitbrain.org>
968 * @author Michael Klier <chi@chimeric.de>
969 */
970function html_backlinks(){
971    global $ID;
972    global $lang;
973
974    print p_locale_xhtml('backlinks');
975
976    $data = ft_backlinks($ID);
977
978    if(!empty($data)) {
979        print '<ul class="idx">';
980        foreach($data as $blink){
981            print '<li><div class="li">';
982            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
983            print '</div></li>';
984        }
985        print '</ul>';
986    } else {
987        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
988    }
989}
990
991/**
992 * Get header of diff HTML
993 * @param string $l_rev   Left revisions
994 * @param string $r_rev   Right revision
995 * @param string $id      Page id, if null $ID is used
996 * @param bool   $media   If it is for media files
997 * @param bool   $inline  Return the header on a single line
998 * @return array HTML snippets for diff header
999 */
1000function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1001    global $lang;
1002    if ($id === null) {
1003        global $ID;
1004        $id = $ID;
1005    }
1006    $head_separator = $inline ? ' ' : '<br />';
1007    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1008    $ml_or_wl = $media ? 'ml' : 'wl';
1009    $l_minor = $r_minor = '';
1010
1011    if(!$l_rev){
1012        $l_head = '&mdash;';
1013    }else{
1014        $l_info   = getRevisionInfo($id,$l_rev,true, $media);
1015        if($l_info['user']){
1016            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1017            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1018        } else {
1019            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1020        }
1021        $l_user  = '<span class="user">'.$l_user.'</span>';
1022        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1023        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1024
1025        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1026        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1027        $l_head_title.'</a></bdi>'.
1028        $head_separator.$l_user.' '.$l_sum;
1029    }
1030
1031    if($r_rev){
1032        $r_info   = getRevisionInfo($id,$r_rev,true, $media);
1033        if($r_info['user']){
1034            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1035            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1036        } else {
1037            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1038        }
1039        $r_user = '<span class="user">'.$r_user.'</span>';
1040        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1041        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1042
1043        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1044        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1045        $r_head_title.'</a></bdi>'.
1046        $head_separator.$r_user.' '.$r_sum;
1047    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1048        $_info   = getRevisionInfo($id,$_rev,true, $media);
1049        if($_info['user']){
1050            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1051            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1052        } else {
1053            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1054        }
1055        $_user = '<span class="user">'.$_user.'</span>';
1056        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1057        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1058
1059        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1060        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1061        $r_head_title.'</a></bdi> '.
1062        '('.$lang['current'].')'.
1063        $head_separator.$_user.' '.$_sum;
1064    }else{
1065        $r_head = '&mdash; ('.$lang['current'].')';
1066    }
1067
1068    return array($l_head, $r_head, $l_minor, $r_minor);
1069}
1070
1071/**
1072 * show diff
1073 *
1074 * @author Andreas Gohr <andi@splitbrain.org>
1075 * @param  string $text - compare with this text with most current version
1076 * @param  bool   $intro - display the intro text
1077 * @param  string $type type of the diff (inline or sidebyside)
1078 */
1079function html_diff($text='',$intro=true,$type=null){
1080    global $ID;
1081    global $REV;
1082    global $lang;
1083    global $INPUT;
1084    global $INFO;
1085
1086    if(!$type) {
1087        $type = $INPUT->str('difftype');
1088        if (empty($type)) {
1089            $type = get_doku_pref('difftype', $type);
1090            if (empty($type) && $INFO['ismobile']) {
1091                $type = 'inline';
1092            }
1093        }
1094    }
1095    if($type != 'inline') $type = 'sidebyside';
1096
1097    // we're trying to be clever here, revisions to compare can be either
1098    // given as rev and rev2 parameters, with rev2 being optional. Or in an
1099    // array in rev2.
1100    $rev1 = $REV;
1101
1102    $rev2 = $INPUT->ref('rev2');
1103    if(is_array($rev2)){
1104        $rev1 = (int) $rev2[0];
1105        $rev2 = (int) $rev2[1];
1106
1107        if(!$rev1){
1108            $rev1 = $rev2;
1109            unset($rev2);
1110        }
1111    }else{
1112        $rev2 = $INPUT->int('rev2');
1113    }
1114
1115    $r_minor = '';
1116    $l_minor = '';
1117
1118    if($text){                      // compare text to the most current revision
1119        $l_rev   = '';
1120        $l_text  = rawWiki($ID,'');
1121        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
1122            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
1123            $lang['current'];
1124
1125        $r_rev   = '';
1126        $r_text  = cleanText($text);
1127        $r_head  = $lang['yours'];
1128    }else{
1129        if($rev1 && isset($rev2) && $rev2){            // two specific revisions wanted
1130            // make sure order is correct (older on the left)
1131            if($rev1 < $rev2){
1132                $l_rev = $rev1;
1133                $r_rev = $rev2;
1134            }else{
1135                $l_rev = $rev2;
1136                $r_rev = $rev1;
1137            }
1138        }elseif($rev1){                // single revision given, compare to current
1139            $r_rev = '';
1140            $l_rev = $rev1;
1141        }else{                        // no revision was given, compare previous to current
1142            $r_rev = '';
1143            $revs = getRevisions($ID, 0, 1);
1144            $l_rev = $revs[0];
1145            $REV = $l_rev; // store revision back in $REV
1146        }
1147
1148        // when both revisions are empty then the page was created just now
1149        if(!$l_rev && !$r_rev){
1150            $l_text = '';
1151        }else{
1152            $l_text = rawWiki($ID,$l_rev);
1153        }
1154        $r_text = rawWiki($ID,$r_rev);
1155
1156        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1157    }
1158
1159    $df = new Diff(explode("\n",$l_text),explode("\n",$r_text));
1160
1161    if($type == 'inline'){
1162        $tdf = new InlineDiffFormatter();
1163    } else {
1164        $tdf = new TableDiffFormatter();
1165    }
1166
1167    if($intro) print p_locale_xhtml('diff');
1168
1169    if (!$text) {
1170        ptln('<div class="diffoptions">');
1171
1172        $form = new Doku_Form(array('action'=>wl()));
1173        $form->addHidden('id',$ID);
1174        $form->addHidden('rev2[0]',$l_rev);
1175        $form->addHidden('rev2[1]',$r_rev);
1176        $form->addHidden('do','diff');
1177        $form->addElement(form_makeListboxField(
1178                            'difftype',
1179                            array(
1180                                'sidebyside' => $lang['diff_side'],
1181                                'inline'     => $lang['diff_inline']),
1182                            $type,
1183                            $lang['diff_type'],
1184                            '','',
1185                            array('class'=>'quickselect')));
1186        $form->addElement(form_makeButton('submit', 'diff','Go'));
1187        $form->printForm();
1188
1189        $diffurl = wl($ID, array(
1190                        'do'       => 'diff',
1191                        'rev2[0]'  => $l_rev,
1192                        'rev2[1]'  => $r_rev ? $r_rev : $INFO['currentrev'], // link to exactly this view FS#2835
1193                        'difftype' => $type,
1194                      ));
1195        ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>');
1196        ptln('</div>');
1197    }
1198    ?>
1199    <div class="table">
1200    <table class="diff diff_<?php echo $type?>">
1201    <?php if ($type == 'inline') { ?>
1202    <tr>
1203    <th class="diff-lineheader">-</th><th <?php echo $l_minor?>>
1204    <?php echo $l_head?>
1205    </th>
1206    </tr>
1207    <tr>
1208    <th class="diff-lineheader">+</th><th <?php echo $r_minor?>>
1209    <?php echo $r_head?>
1210    </th>
1211    </tr>
1212    <?php } else { ?>
1213    <tr>
1214    <th colspan="2" <?php echo $l_minor?>>
1215    <?php echo $l_head?>
1216    </th>
1217    <th colspan="2" <?php echo $r_minor?>>
1218    <?php echo $r_head?>
1219    </th>
1220    </tr>
1221    <?php }
1222    echo html_insert_softbreaks($tdf->format($df)); ?>
1223    </table>
1224    </div>
1225    <?php
1226}
1227
1228function html_insert_softbreaks($diffhtml) {
1229    // search the diff html string for both:
1230    // - html tags, so these can be ignored
1231    // - long strings of characters without breaking characters
1232    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1233}
1234
1235function html_softbreak_callback($match){
1236    // if match is an html tag, return it intact
1237    if ($match[0]{0} == '<') return $match[0];
1238
1239    // its a long string without a breaking character,
1240    // make certain characters into breaking characters by inserting a
1241    // breaking character (zero length space, U+200B / #8203) in front them.
1242    $regex = <<< REGEX
1243(?(?=                                 # start a conditional expression with a positive look ahead ...
1244&\#?\\w{1,6};)                        # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1245&\#?\\w{1,6};                         # yes pattern - a quicker match for the html entity, since we know we have one
1246|
1247[?/,&\#;:]                            # no pattern - any other group of 'special' characters to insert a breaking character after
1248)+                                    # end conditional expression
1249REGEX;
1250
1251    return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1252}
1253
1254/**
1255 * show warning on conflict detection
1256 *
1257 * @author Andreas Gohr <andi@splitbrain.org>
1258 */
1259function html_conflict($text,$summary){
1260    global $ID;
1261    global $lang;
1262
1263    print p_locale_xhtml('conflict');
1264    $form = new Doku_Form(array('id' => 'dw__editform'));
1265    $form->addHidden('id', $ID);
1266    $form->addHidden('wikitext', $text);
1267    $form->addHidden('summary', $summary);
1268    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1269    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1270    html_form('conflict', $form);
1271    print '<br /><br /><br /><br />'.NL;
1272}
1273
1274/**
1275 * Prints the global message array
1276 *
1277 * @author Andreas Gohr <andi@splitbrain.org>
1278 */
1279function html_msgarea(){
1280    global $MSG, $MSG_shown;
1281    /** @var array $MSG */
1282    // store if the global $MSG has already been shown and thus HTML output has been started
1283    $MSG_shown = true;
1284
1285    if(!isset($MSG)) return;
1286
1287    $shown = array();
1288    foreach($MSG as $msg){
1289        $hash = md5($msg['msg']);
1290        if(isset($shown[$hash])) continue; // skip double messages
1291        if(info_msg_allowed($msg)){
1292            print '<div class="'.$msg['lvl'].'">';
1293            print $msg['msg'];
1294            print '</div>';
1295        }
1296        $shown[$hash] = 1;
1297    }
1298
1299    unset($GLOBALS['MSG']);
1300}
1301
1302/**
1303 * Prints the registration form
1304 *
1305 * @author Andreas Gohr <andi@splitbrain.org>
1306 */
1307function html_register(){
1308    global $lang;
1309    global $conf;
1310    global $INPUT;
1311
1312    $base_attrs = array('size'=>50,'required'=>'required');
1313    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1314
1315    print p_locale_xhtml('register');
1316    print '<div class="centeralign">'.NL;
1317    $form = new Doku_Form(array('id' => 'dw__register'));
1318    $form->startFieldset($lang['btn_register']);
1319    $form->addHidden('do', 'register');
1320    $form->addHidden('save', '1');
1321    $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1322    if (!$conf['autopasswd']) {
1323        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1324        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1325    }
1326    $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1327    $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1328    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1329    $form->endFieldset();
1330    html_form('register', $form);
1331
1332    print '</div>'.NL;
1333}
1334
1335/**
1336 * Print the update profile form
1337 *
1338 * @author Christopher Smith <chris@jalakai.co.uk>
1339 * @author Andreas Gohr <andi@splitbrain.org>
1340 */
1341function html_updateprofile(){
1342    global $lang;
1343    global $conf;
1344    global $INPUT;
1345    global $INFO;
1346    /** @var auth_basic $auth */
1347    global $auth;
1348
1349    print p_locale_xhtml('updateprofile');
1350    print '<div class="centeralign">'.NL;
1351
1352    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1353    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1354    $form = new Doku_Form(array('id' => 'dw__register'));
1355    $form->startFieldset($lang['profile']);
1356    $form->addHidden('do', 'profile');
1357    $form->addHidden('save', '1');
1358    $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1359    $attr = array('size'=>'50');
1360    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1361    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1362    $attr = array('size'=>'50', 'class'=>'edit');
1363    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1364    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1365    $form->addElement(form_makeTag('br'));
1366    if ($auth->canDo('modPass')) {
1367        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1368        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1369    }
1370    if ($conf['profileconfirm']) {
1371        $form->addElement(form_makeTag('br'));
1372        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1373    }
1374    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1375    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1376
1377    $form->endFieldset();
1378    html_form('updateprofile', $form);
1379
1380    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1381        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1382        $form_profiledelete->startFieldset($lang['profdeleteuser']);
1383        $form_profiledelete->addHidden('do', 'profile_delete');
1384        $form_profiledelete->addHidden('delete', '1');
1385        $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1386        if ($conf['profileconfirm']) {
1387            $form_profiledelete->addElement(form_makeTag('br'));
1388            $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1389        }
1390        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1391        $form_profiledelete->endFieldset();
1392
1393        html_form('profiledelete', $form_profiledelete);
1394    }
1395
1396    print '</div>'.NL;
1397}
1398
1399/**
1400 * Preprocess edit form data
1401 *
1402 * @author   Andreas Gohr <andi@splitbrain.org>
1403 *
1404 * @triggers HTML_EDITFORM_OUTPUT
1405 */
1406function html_edit(){
1407    global $INPUT;
1408    global $ID;
1409    global $REV;
1410    global $DATE;
1411    global $PRE;
1412    global $SUF;
1413    global $INFO;
1414    global $SUM;
1415    global $lang;
1416    global $conf;
1417    global $TEXT;
1418    global $RANGE;
1419
1420    if ($INPUT->has('changecheck')) {
1421        $check = $INPUT->str('changecheck');
1422    } elseif(!$INFO['exists']){
1423        // $TEXT has been loaded from page template
1424        $check = md5('');
1425    } else {
1426        $check = md5($TEXT);
1427    }
1428    $mod = md5($TEXT) !== $check;
1429
1430    $wr = $INFO['writable'] && !$INFO['locked'];
1431    $include = 'edit';
1432    if($wr){
1433        if ($REV) $include = 'editrev';
1434    }else{
1435        // check pseudo action 'source'
1436        if(!actionOK('source')){
1437            msg('Command disabled: source',-1);
1438            return;
1439        }
1440        $include = 'read';
1441    }
1442
1443    global $license;
1444
1445    $form = new Doku_Form(array('id' => 'dw__editform'));
1446    $form->addHidden('id', $ID);
1447    $form->addHidden('rev', $REV);
1448    $form->addHidden('date', $DATE);
1449    $form->addHidden('prefix', $PRE . '.');
1450    $form->addHidden('suffix', $SUF);
1451    $form->addHidden('changecheck', $check);
1452
1453    $data = array('form' => $form,
1454                  'wr'   => $wr,
1455                  'media_manager' => true,
1456                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1457                  'intro_locale' => $include);
1458
1459    if ($data['target'] !== 'section') {
1460        // Only emit event if page is writable, section edit data is valid and
1461        // edit target is not section.
1462        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1463    } else {
1464        html_edit_form($data);
1465    }
1466    if (isset($data['intro_locale'])) {
1467        echo p_locale_xhtml($data['intro_locale']);
1468    }
1469
1470    $form->addHidden('target', $data['target']);
1471    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1472    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1473    $form->addElement(form_makeCloseTag('div'));
1474    if ($wr) {
1475        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1476        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1477        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1478        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1479        $form->addElement(form_makeCloseTag('div'));
1480        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1481        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1482        $elem = html_minoredit();
1483        if ($elem) $form->addElement($elem);
1484        $form->addElement(form_makeCloseTag('div'));
1485    }
1486    $form->addElement(form_makeCloseTag('div'));
1487    if($wr && $conf['license']){
1488        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1489        $out  = $lang['licenseok'];
1490        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1491        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1492        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1493        $form->addElement($out);
1494        $form->addElement(form_makeCloseTag('div'));
1495    }
1496
1497    if ($wr) {
1498        // sets changed to true when previewed
1499        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1500        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1501        echo '/*!]]>*/</script>' . NL;
1502    } ?>
1503    <div class="editBox" role="application">
1504
1505    <div class="toolbar group">
1506        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1507        <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1508            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1509    </div>
1510    <?php
1511
1512    html_form('edit', $form);
1513    print '</div>'.NL;
1514}
1515
1516/**
1517 * Display the default edit form
1518 *
1519 * Is the default action for HTML_EDIT_FORMSELECTION.
1520 */
1521function html_edit_form($param) {
1522    global $TEXT;
1523
1524    if ($param['target'] !== 'section') {
1525        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1526    }
1527
1528    $attr = array('tabindex'=>'1');
1529    if (!$param['wr']) $attr['readonly'] = 'readonly';
1530
1531    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1532}
1533
1534/**
1535 * Adds a checkbox for minor edits for logged in users
1536 *
1537 * @author Andreas Gohr <andi@splitbrain.org>
1538 */
1539function html_minoredit(){
1540    global $conf;
1541    global $lang;
1542    global $INPUT;
1543    // minor edits are for logged in users only
1544    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1545        return false;
1546    }
1547
1548    $p = array();
1549    $p['tabindex'] = 3;
1550    if($INPUT->bool('minor')) $p['checked']='checked';
1551    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1552}
1553
1554/**
1555 * prints some debug info
1556 *
1557 * @author Andreas Gohr <andi@splitbrain.org>
1558 */
1559function html_debug(){
1560    global $conf;
1561    global $lang;
1562    /** @var auth_basic $auth */
1563    global $auth;
1564    global $INFO;
1565
1566    //remove sensitive data
1567    $cnf = $conf;
1568    debug_guard($cnf);
1569    $nfo = $INFO;
1570    debug_guard($nfo);
1571    $ses = $_SESSION;
1572    debug_guard($ses);
1573
1574    print '<html><body>';
1575
1576    print '<p>When reporting bugs please send all the following ';
1577    print 'output as a mail to andi@splitbrain.org ';
1578    print 'The best way to do this is to save this page in your browser</p>';
1579
1580    print '<b>$INFO:</b><pre>';
1581    print_r($nfo);
1582    print '</pre>';
1583
1584    print '<b>$_SERVER:</b><pre>';
1585    print_r($_SERVER);
1586    print '</pre>';
1587
1588    print '<b>$conf:</b><pre>';
1589    print_r($cnf);
1590    print '</pre>';
1591
1592    print '<b>DOKU_BASE:</b><pre>';
1593    print DOKU_BASE;
1594    print '</pre>';
1595
1596    print '<b>abs DOKU_BASE:</b><pre>';
1597    print DOKU_URL;
1598    print '</pre>';
1599
1600    print '<b>rel DOKU_BASE:</b><pre>';
1601    print dirname($_SERVER['PHP_SELF']).'/';
1602    print '</pre>';
1603
1604    print '<b>PHP Version:</b><pre>';
1605    print phpversion();
1606    print '</pre>';
1607
1608    print '<b>locale:</b><pre>';
1609    print setlocale(LC_ALL,0);
1610    print '</pre>';
1611
1612    print '<b>encoding:</b><pre>';
1613    print $lang['encoding'];
1614    print '</pre>';
1615
1616    if($auth){
1617        print '<b>Auth backend capabilities:</b><pre>';
1618        foreach ($auth->getCapabilities() as $cando){
1619            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
1620        }
1621        print '</pre>';
1622    }
1623
1624    print '<b>$_SESSION:</b><pre>';
1625    print_r($ses);
1626    print '</pre>';
1627
1628    print '<b>Environment:</b><pre>';
1629    print_r($_ENV);
1630    print '</pre>';
1631
1632    print '<b>PHP settings:</b><pre>';
1633    $inis = ini_get_all();
1634    print_r($inis);
1635    print '</pre>';
1636
1637    if (function_exists('apache_get_version')) {
1638        $apache['version'] = apache_get_version();
1639
1640        if (function_exists('apache_get_modules')) {
1641            $apache['modules'] = apache_get_modules();
1642        }
1643        print '<b>Apache</b><pre>';
1644        print_r($apache);
1645        print '</pre>';
1646    }
1647
1648    print '</body></html>';
1649}
1650
1651/**
1652 * List available Administration Tasks
1653 *
1654 * @author Andreas Gohr <andi@splitbrain.org>
1655 * @author Håkan Sandell <hakan.sandell@home.se>
1656 */
1657function html_admin(){
1658    global $ID;
1659    global $INFO;
1660    global $conf;
1661    /** @var DokuWiki_Auth_Plugin $auth */
1662    global $auth;
1663
1664    // build menu of admin functions from the plugins that handle them
1665    $pluginlist = plugin_list('admin');
1666    $menu = array();
1667    foreach ($pluginlist as $p) {
1668        /** @var DokuWiki_Admin_Plugin $obj */
1669        if(($obj = plugin_load('admin',$p)) === null) continue;
1670
1671        // check permissions
1672        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1673
1674        $menu[$p] = array('plugin' => $p,
1675                'prompt' => $obj->getMenuText($conf['lang']),
1676                'sort' => $obj->getMenuSort()
1677                );
1678    }
1679
1680    // data security check
1681    // simple check if the 'savedir' is relative and accessible when appended to DOKU_URL
1682    // it verifies either:
1683    //   'savedir' has been moved elsewhere, or
1684    //   has protection to prevent the webserver serving files from it
1685    if (substr($conf['savedir'],0,2) == './'){
1686        echo '<a style="border:none; float:right;"
1687                href="http://www.dokuwiki.org/security#web_access_security">
1688                <img src="'.DOKU_URL.$conf['savedir'].'/security.png" alt="Your data directory seems to be protected properly."
1689                onerror="this.parentNode.style.display=\'none\'" /></a>';
1690    }
1691
1692    print p_locale_xhtml('admin');
1693
1694    // Admin Tasks
1695    if($INFO['isadmin']){
1696        ptln('<ul class="admin_tasks">');
1697
1698        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1699            ptln('  <li class="admin_usermanager"><div class="li">'.
1700                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1701                    $menu['usermanager']['prompt'].'</a></div></li>');
1702        }
1703        unset($menu['usermanager']);
1704
1705        if($menu['acl']){
1706            ptln('  <li class="admin_acl"><div class="li">'.
1707                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1708                    $menu['acl']['prompt'].'</a></div></li>');
1709        }
1710        unset($menu['acl']);
1711
1712        if($menu['extension']){
1713            ptln('  <li class="admin_plugin"><div class="li">'.
1714                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'extension')).'">'.
1715                    $menu['extension']['prompt'].'</a></div></li>');
1716        }
1717        unset($menu['extension']);
1718
1719        if($menu['config']){
1720            ptln('  <li class="admin_config"><div class="li">'.
1721                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1722                    $menu['config']['prompt'].'</a></div></li>');
1723        }
1724        unset($menu['config']);
1725    }
1726    ptln('</ul>');
1727
1728    // Manager Tasks
1729    ptln('<ul class="admin_tasks">');
1730
1731    if($menu['revert']){
1732        ptln('  <li class="admin_revert"><div class="li">'.
1733                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1734                $menu['revert']['prompt'].'</a></div></li>');
1735    }
1736    unset($menu['revert']);
1737
1738    if($menu['popularity']){
1739        ptln('  <li class="admin_popularity"><div class="li">'.
1740                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1741                $menu['popularity']['prompt'].'</a></div></li>');
1742    }
1743    unset($menu['popularity']);
1744
1745    // print DokuWiki version:
1746    ptln('</ul>');
1747    echo '<div id="admin__version">';
1748    echo getVersion();
1749    echo '</div>';
1750
1751    // print the rest as sorted list
1752    if(count($menu)){
1753        usort($menu, 'p_sort_modes');
1754        // output the menu
1755        ptln('<div class="clearer"></div>');
1756        print p_locale_xhtml('adminplugins');
1757        ptln('<ul>');
1758        foreach ($menu as $item) {
1759            if (!$item['prompt']) continue;
1760            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1761        }
1762        ptln('</ul>');
1763    }
1764}
1765
1766/**
1767 * Form to request a new password for an existing account
1768 *
1769 * @author Benoit Chesneau <benoit@bchesneau.info>
1770 * @author Andreas Gohr <gohr@cosmocode.de>
1771 */
1772function html_resendpwd() {
1773    global $lang;
1774    global $conf;
1775    global $INPUT;
1776
1777    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
1778
1779    if(!$conf['autopasswd'] && $token){
1780        print p_locale_xhtml('resetpwd');
1781        print '<div class="centeralign">'.NL;
1782        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1783        $form->startFieldset($lang['btn_resendpwd']);
1784        $form->addHidden('token', $token);
1785        $form->addHidden('do', 'resendpwd');
1786
1787        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1788        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1789
1790        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1791        $form->endFieldset();
1792        html_form('resendpwd', $form);
1793        print '</div>'.NL;
1794    }else{
1795        print p_locale_xhtml('resendpwd');
1796        print '<div class="centeralign">'.NL;
1797        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1798        $form->startFieldset($lang['resendpwd']);
1799        $form->addHidden('do', 'resendpwd');
1800        $form->addHidden('save', '1');
1801        $form->addElement(form_makeTag('br'));
1802        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
1803        $form->addElement(form_makeTag('br'));
1804        $form->addElement(form_makeTag('br'));
1805        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1806        $form->endFieldset();
1807        html_form('resendpwd', $form);
1808        print '</div>'.NL;
1809    }
1810}
1811
1812/**
1813 * Return the TOC rendered to XHTML
1814 *
1815 * @author Andreas Gohr <andi@splitbrain.org>
1816 */
1817function html_TOC($toc){
1818    if(!count($toc)) return '';
1819    global $lang;
1820    $out  = '<!-- TOC START -->'.DOKU_LF;
1821    $out .= '<div id="dw__toc">'.DOKU_LF;
1822    $out .= '<h3 class="toggle">';
1823    $out .= $lang['toc'];
1824    $out .= '</h3>'.DOKU_LF;
1825    $out .= '<div>'.DOKU_LF;
1826    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
1827    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1828    $out .= '<!-- TOC END -->'.DOKU_LF;
1829    return $out;
1830}
1831
1832/**
1833 * Callback for html_buildlist
1834 */
1835function html_list_toc($item){
1836    if(isset($item['hid'])){
1837        $link = '#'.$item['hid'];
1838    }else{
1839        $link = $item['link'];
1840    }
1841
1842    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
1843}
1844
1845/**
1846 * Helper function to build TOC items
1847 *
1848 * Returns an array ready to be added to a TOC array
1849 *
1850 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1851 * @param string $text  - what to display in the TOC
1852 * @param int    $level - nesting level
1853 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1854 * @return array the toc item
1855 */
1856function html_mktocitem($link, $text, $level, $hash='#'){
1857    return  array( 'link'  => $hash.$link,
1858            'title' => $text,
1859            'type'  => 'ul',
1860            'level' => $level);
1861}
1862
1863/**
1864 * Output a Doku_Form object.
1865 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1866 *
1867 * @author Tom N Harris <tnharris@whoopdedo.org>
1868 * @param string     $name The name of the form
1869 * @param Doku_Form  $form The form
1870 */
1871function html_form($name, &$form) {
1872    // Safety check in case the caller forgets.
1873    $form->endFieldset();
1874    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1875}
1876
1877/**
1878 * Form print function.
1879 * Just calls printForm() on the data object.
1880 * @param Doku_Form $data The form
1881 */
1882function html_form_output($data) {
1883    $data->printForm();
1884}
1885
1886/**
1887 * Embed a flash object in HTML
1888 *
1889 * This will create the needed HTML to embed a flash movie in a cross browser
1890 * compatble way using valid XHTML
1891 *
1892 * The parameters $params, $flashvars and $atts need to be associative arrays.
1893 * No escaping needs to be done for them. The alternative content *has* to be
1894 * escaped because it is used as is. If no alternative content is given
1895 * $lang['noflash'] is used.
1896 *
1897 * @author Andreas Gohr <andi@splitbrain.org>
1898 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1899 *
1900 * @param string $swf      - the SWF movie to embed
1901 * @param int $width       - width of the flash movie in pixels
1902 * @param int $height      - height of the flash movie in pixels
1903 * @param array $params    - additional parameters (<param>)
1904 * @param array $flashvars - parameters to be passed in the flashvar parameter
1905 * @param array $atts      - additional attributes for the <object> tag
1906 * @param string $alt      - alternative content (is NOT automatically escaped!)
1907 * @return string         - the XHTML markup
1908 */
1909function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1910    global $lang;
1911
1912    $out = '';
1913
1914    // prepare the object attributes
1915    if(is_null($atts)) $atts = array();
1916    $atts['width']  = (int) $width;
1917    $atts['height'] = (int) $height;
1918    if(!$atts['width'])  $atts['width']  = 425;
1919    if(!$atts['height']) $atts['height'] = 350;
1920
1921    // add object attributes for standard compliant browsers
1922    $std = $atts;
1923    $std['type'] = 'application/x-shockwave-flash';
1924    $std['data'] = $swf;
1925
1926    // add object attributes for IE
1927    $ie  = $atts;
1928    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1929
1930    // open object (with conditional comments)
1931    $out .= '<!--[if !IE]> -->'.NL;
1932    $out .= '<object '.buildAttributes($std).'>'.NL;
1933    $out .= '<!-- <![endif]-->'.NL;
1934    $out .= '<!--[if IE]>'.NL;
1935    $out .= '<object '.buildAttributes($ie).'>'.NL;
1936    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1937    $out .= '<!--><!-- -->'.NL;
1938
1939    // print params
1940    if(is_array($params)) foreach($params as $key => $val){
1941        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1942    }
1943
1944    // add flashvars
1945    if(is_array($flashvars)){
1946        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1947    }
1948
1949    // alternative content
1950    if($alt){
1951        $out .= $alt.NL;
1952    }else{
1953        $out .= $lang['noflash'].NL;
1954    }
1955
1956    // finish
1957    $out .= '</object>'.NL;
1958    $out .= '<!-- <![endif]-->'.NL;
1959
1960    return $out;
1961}
1962
1963/**
1964 * Prints HTML code for the given tab structure
1965 *
1966 * @param array  $tabs        tab structure
1967 * @param string $current_tab the current tab id
1968 */
1969function html_tabs($tabs, $current_tab = null) {
1970    echo '<ul class="tabs">'.NL;
1971
1972    foreach($tabs as $id => $tab) {
1973        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
1974    }
1975
1976    echo '</ul>'.NL;
1977}
1978/**
1979 * Prints a single tab
1980 *
1981 * @author Kate Arzamastseva <pshns@ukr.net>
1982 * @author Adrian Lang <mail@adrianlang.de>
1983 *
1984 * @param string $href - tab href
1985 * @param string $caption - tab caption
1986 * @param boolean $selected - is tab selected
1987 */
1988
1989function html_tab($href, $caption, $selected=false) {
1990    $tab = '<li>';
1991    if ($selected) {
1992        $tab .= '<strong>';
1993    } else {
1994        $tab .= '<a href="' . hsc($href) . '">';
1995    }
1996    $tab .= hsc($caption)
1997         .  '</' . ($selected ? 'strong' : 'a') . '>'
1998         .  '</li>'.NL;
1999    echo $tab;
2000}
2001
2002