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