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