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