xref: /dokuwiki/inc/html.php (revision 6c6ee18ca085273a1bc16293583692c74ce47ef6)
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");
11require_once(DOKU_INC.'inc/parserutils.php');
12require_once(DOKU_INC.'inc/form.php');
13
14/**
15 * Convenience function to quickly build a wikilink
16 *
17 * @author Andreas Gohr <andi@splitbrain.org>
18 */
19function html_wikilink($id,$name=null,$search=''){
20    static $xhtml_renderer = null;
21    if(is_null($xhtml_renderer)){
22        $xhtml_renderer = p_get_renderer('xhtml');
23    }
24
25    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
26}
27
28/**
29 * Helps building long attribute lists
30 *
31 * @author Andreas Gohr <andi@splitbrain.org>
32 */
33function html_attbuild($attributes){
34    $ret = '';
35    foreach ( $attributes as $key => $value ) {
36        $ret .= $key.'="'.formText($value).'" ';
37    }
38    return trim($ret);
39}
40
41/**
42 * The loginform
43 *
44 * @author   Andreas Gohr <andi@splitbrain.org>
45 */
46function html_login(){
47    global $lang;
48    global $conf;
49    global $ID;
50    global $auth;
51
52    print p_locale_xhtml('login');
53    print '<div class="centeralign">'.NL;
54    $form = new Doku_Form(array('id' => 'dw__login'));
55    $form->startFieldset($lang['btn_login']);
56    $form->addHidden('id', $ID);
57    $form->addHidden('do', 'login');
58    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
59    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
60    if($conf['rememberme']) {
61        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
62    }
63    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
64    $form->endFieldset();
65
66    if($auth && $auth->canDo('addUser') && actionOK('register')){
67        $form->addElement('<p>'
68                          . $lang['reghere']
69                          . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'
70                          . '</p>');
71    }
72
73    if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
74        $form->addElement('<p>'
75                          . $lang['pwdforget']
76                          . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'
77                          . '</p>');
78    }
79
80    html_form('login', $form);
81    print '</div>'.NL;
82}
83
84/**
85 * prints a section editing button
86 * used as a callback in html_secedit
87 *
88 * @author Andreas Gohr <andi@splitbrain.org>
89 */
90function html_secedit_button($matches){
91    global $ID;
92    global $INFO;
93
94    $section = $matches[2];
95    $name = $matches[1];
96
97    $secedit  = '';
98    $secedit .= '<div class="secedit">';
99    $secedit .= html_btn('secedit',$ID,'',
100            array('do'      => 'edit',
101                'lines'   => "$section",
102                'rev' => $INFO['lastmod']),
103            'post', $name);
104    $secedit .= '</div>';
105    return $secedit;
106}
107
108/**
109 * inserts section edit buttons if wanted or removes the markers
110 *
111 * @author Andreas Gohr <andi@splitbrain.org>
112 */
113function html_secedit($text,$show=true){
114    global $INFO;
115
116    if($INFO['writable'] && $show && !$INFO['rev']){
117        $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
118                'html_secedit_button', $text);
119    }else{
120        $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
121    }
122
123    return $text;
124}
125
126/**
127 * Just the back to top button (in its own form)
128 *
129 * @author Andreas Gohr <andi@splitbrain.org>
130 */
131function html_topbtn(){
132    global $lang;
133
134    $ret  = '';
135    $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>';
136
137    return $ret;
138}
139
140/**
141 * Displays a button (using its own form)
142 * If tooltip exists, the access key tooltip is replaced.
143 *
144 * @author Andreas Gohr <andi@splitbrain.org>
145 */
146function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
147    global $conf;
148    global $lang;
149
150    $label = $lang['btn_'.$name];
151
152    $ret = '';
153    $tip = '';
154
155    //filter id (without urlencoding)
156    $id = idfilter($id,false);
157
158    //make nice URLs even for buttons
159    if($conf['userewrite'] == 2){
160        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
161    }elseif($conf['userewrite']){
162        $script = DOKU_BASE.$id;
163    }else{
164        $script = DOKU_BASE.DOKU_SCRIPT;
165        $params['id'] = $id;
166    }
167
168    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
169
170    if(is_array($params)){
171        reset($params);
172        while (list($key, $val) = each($params)) {
173            $ret .= '<input type="hidden" name="'.$key.'" ';
174            $ret .= 'value="'.htmlspecialchars($val).'" />';
175        }
176    }
177
178    if ($tooltip!='') {
179        $tip = htmlspecialchars($tooltip);
180    }else{
181        $tip = htmlspecialchars($label);
182    }
183
184    $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
185    if($akey){
186        $tip .= ' ['.strtoupper($akey).']';
187        $ret .= 'accesskey="'.$akey.'" ';
188    }
189    $ret .= 'title="'.$tip.'" ';
190    $ret .= '/>';
191    $ret .= '</div></form>';
192
193    return $ret;
194}
195
196/**
197 * show a wiki page
198 *
199 * @author Andreas Gohr <andi@splitbrain.org>
200 */
201function html_show($txt=''){
202    global $ID;
203    global $REV;
204    global $HIGH;
205    global $INFO;
206    //disable section editing for old revisions or in preview
207    if($txt || $REV){
208        $secedit = false;
209    }else{
210        $secedit = true;
211    }
212
213    if ($txt){
214        //PreviewHeader
215        echo '<br id="scroll__here" />';
216        echo p_locale_xhtml('preview');
217        echo '<div class="preview">';
218        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
219        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
220        echo $html;
221        echo '<div class="clearer"></div>';
222        echo '</div>';
223
224    }else{
225        if ($REV) print p_locale_xhtml('showrev');
226        $html = p_wiki_xhtml($ID,$REV,true);
227        $html = html_secedit($html,$secedit);
228        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
229        $html = html_hilight($html,$HIGH);
230        echo $html;
231    }
232}
233
234/**
235 * ask the user about how to handle an exisiting draft
236 *
237 * @author Andreas Gohr <andi@splitbrain.org>
238 */
239function html_draft(){
240    global $INFO;
241    global $ID;
242    global $lang;
243    global $conf;
244    $draft = unserialize(io_readFile($INFO['draft'],false));
245    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
246
247    print p_locale_xhtml('draft');
248    $form = new Doku_Form(array('id' => 'dw__editform'));
249    $form->addHidden('id', $ID);
250    $form->addHidden('date', $draft['date']);
251    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
252    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
253    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
254    $form->addElement(form_makeCloseTag('div'));
255    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
256    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
257    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
258    html_form('draft', $form);
259}
260
261/**
262 * Highlights searchqueries in HTML code
263 *
264 * @author Andreas Gohr <andi@splitbrain.org>
265 * @author Harry Fuecks <hfuecks@gmail.com>
266 */
267function html_hilight($html,$phrases){
268    $phrases = array_filter((array) $phrases);
269    $regex = join('|',array_map('preg_quote_cb',$phrases));
270
271    if ($regex === '') return $html;
272    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
273    return $html;
274}
275
276/**
277 * Callback used by html_hilight()
278 *
279 * @author Harry Fuecks <hfuecks@gmail.com>
280 */
281function html_hilight_callback($m) {
282    $hlight = unslash($m[0]);
283    if ( !isset($m[2])) {
284        $hlight = '<span class="search_hit">'.$hlight.'</span>';
285    }
286    return $hlight;
287}
288
289/**
290 * Run a search and display the result
291 *
292 * @author Andreas Gohr <andi@splitbrain.org>
293 */
294function html_search(){
295    require_once(DOKU_INC.'inc/search.php');
296    require_once(DOKU_INC.'inc/fulltext.php');
297    global $conf;
298    global $QUERY;
299    global $ID;
300    global $lang;
301
302    print p_locale_xhtml('searchpage');
303    flush();
304
305    //check if search is restricted to namespace
306    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
307        $id = cleanID($match[1]);
308    } else {
309        $id = cleanID($QUERY);
310    }
311
312    //show progressbar
313    print '<div class="centeralign" id="dw__loading">'.NL;
314    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
315    print 'showLoadBar();'.NL;
316    print '//--><!]]></script>'.NL;
317    print '<br /></div>'.NL;
318    flush();
319
320    //do quick pagesearch
321    $data = array();
322
323    if($id) $data = ft_pageLookup($id);
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){
329            print '<li> ';
330            $ns = getNS($id);
331            if($ns){
332                $name = shorten(noNS($id), ' ('.$ns.')',30);
333            }else{
334                $name = $id;
335            }
336            print html_wikilink(':'.$id,$name);
337            print '</li> ';
338        }
339        print '</ul> ';
340        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
341        print '<div class="clearer">&nbsp;</div>';
342        print '</div>';
343    }
344    flush();
345
346    //do fulltext search
347    $data = ft_pageSearch($QUERY,$regex);
348    if(count($data)){
349        $num = 1;
350        foreach($data as $id => $cnt){
351            print '<div class="search_result">';
352            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
353            if($cnt !== 0){
354                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
355                if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
356                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
357                }
358                $num++;
359            }
360            print '</div>';
361            flush();
362        }
363    }else{
364        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
365    }
366
367    //hide progressbar
368    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
369    print 'hideLoadBar("dw__loading");'.NL;
370    print '//--><!]]></script>'.NL;
371    flush();
372}
373
374/**
375 * Display error on locked pages
376 *
377 * @author Andreas Gohr <andi@splitbrain.org>
378 */
379function html_locked(){
380    global $ID;
381    global $conf;
382    global $lang;
383    global $INFO;
384
385    $locktime = filemtime(wikiLockFN($ID));
386    $expire = dformat($locktime + $conf['locktime']);
387    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
388
389    print p_locale_xhtml('locked');
390    print '<ul>';
391    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
392    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
393    print '</ul>';
394}
395
396/**
397 * list old revisions
398 *
399 * @author Andreas Gohr <andi@splitbrain.org>
400 * @author Ben Coburn <btcoburn@silicodon.net>
401 */
402function html_revisions($first=0){
403    global $ID;
404    global $INFO;
405    global $conf;
406    global $lang;
407    /* we need to get one additionally log entry to be able to
408     * decide if this is the last page or is there another one.
409     * see html_recent()
410     */
411    $revisions = getRevisions($ID, $first, $conf['recent']+1);
412    if(count($revisions)==0 && $first!=0){
413        $first=0;
414        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
415    }
416    $hasNext = false;
417    if (count($revisions)>$conf['recent']) {
418        $hasNext = true;
419        array_pop($revisions); // remove extra log entry
420    }
421
422    $date = dformat($INFO['lastmod']);
423
424    print p_locale_xhtml('revisions');
425
426    $form = new Doku_Form(array('id' => 'page__revisions'));
427    $form->addElement(form_makeOpenTag('ul'));
428    if($INFO['exists'] && $first==0){
429        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
430            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
431        else
432            $form->addElement(form_makeOpenTag('li'));
433        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
434        $form->addElement(form_makeTag('input', array(
435                        'type' => 'checkbox',
436                        'name' => 'rev2[]',
437                        'value' => 'current')));
438
439        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
440        $form->addElement($date);
441        $form->addElement(form_makeCloseTag('span'));
442
443        $form->addElement(form_makeTag('img', array(
444                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
445                        'width' => '15',
446                        'height' => '11',
447                        'alt'    => '')));
448
449        $form->addElement(form_makeOpenTag('a', array(
450                        'class' => 'wikilink1',
451                        'href'  => wl($ID))));
452        $form->addElement($ID);
453        $form->addElement(form_makeCloseTag('a'));
454
455        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
456        $form->addElement(' &ndash; ');
457        $form->addElement(htmlspecialchars($INFO['sum']));
458        $form->addElement(form_makeCloseTag('span'));
459
460        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
461        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
462        $form->addElement(form_makeCloseTag('span'));
463
464        $form->addElement('('.$lang['current'].')');
465        $form->addElement(form_makeCloseTag('div'));
466        $form->addElement(form_makeCloseTag('li'));
467    }
468
469    foreach($revisions as $rev){
470        $date   = dformat($rev);
471        $info   = getRevisionInfo($ID,$rev,true);
472        $exists = page_exists($ID,$rev);
473
474        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
475            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
476        else
477            $form->addElement(form_makeOpenTag('li'));
478        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
479        if($exists){
480            $form->addElement(form_makeTag('input', array(
481                            'type' => 'checkbox',
482                            'name' => 'rev2[]',
483                            'value' => $rev)));
484        }else{
485            $form->addElement(form_makeTag('img', array(
486                            'src' => DOKU_BASE.'lib/images/blank.gif',
487                            'width' => 14,
488                            'height' => 11,
489                            'alt' => '')));
490        }
491
492        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
493        $form->addElement($date);
494        $form->addElement(form_makeCloseTag('span'));
495
496        if($exists){
497            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
498            $form->addElement(form_makeTag('img', array(
499                            'src'    => DOKU_BASE.'lib/images/diff.png',
500                            'width'  => 15,
501                            'height' => 11,
502                            'title'  => $lang['diff'],
503                            'alt'    => $lang['diff'])));
504            $form->addElement(form_makeCloseTag('a'));
505
506            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
507            $form->addElement($ID);
508            $form->addElement(form_makeCloseTag('a'));
509        }else{
510            $form->addElement(form_makeTag('img', array(
511                            'src' => DOKU_BASE.'lib/images/blank.gif',
512                            'width' => '15',
513                            'height' => '11',
514                            'alt'   => '')));
515            $form->addElement($ID);
516        }
517
518        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
519        $form->addElement(' &ndash; ');
520        $form->addElement(htmlspecialchars($info['sum']));
521        $form->addElement(form_makeCloseTag('span'));
522
523        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
524        if($info['user']){
525            $form->addElement(editorinfo($info['user']));
526            if(auth_ismanager()){
527                $form->addElement(' ('.$info['ip'].')');
528            }
529        }else{
530            $form->addElement($info['ip']);
531        }
532        $form->addElement(form_makeCloseTag('span'));
533
534        $form->addElement(form_makeCloseTag('div'));
535        $form->addElement(form_makeCloseTag('li'));
536    }
537    $form->addElement(form_makeCloseTag('ul'));
538    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
539    html_form('revisions', $form);
540
541    print '<div class="pagenav">';
542    $last = $first + $conf['recent'];
543    if ($first > 0) {
544        $first -= $conf['recent'];
545        if ($first < 0) $first = 0;
546        print '<div class="pagenav-prev">';
547        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
548        print '</div>';
549    }
550    if ($hasNext) {
551        print '<div class="pagenav-next">';
552        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
553        print '</div>';
554    }
555    print '</div>';
556
557}
558
559/**
560 * display recent changes
561 *
562 * @author Andreas Gohr <andi@splitbrain.org>
563 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
564 * @author Ben Coburn <btcoburn@silicodon.net>
565 */
566function html_recent($first=0){
567    global $conf;
568    global $lang;
569    global $ID;
570    /* we need to get one additionally log entry to be able to
571     * decide if this is the last page or is there another one.
572     * This is the cheapest solution to get this information.
573     */
574    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
575    if(count($recents) == 0 && $first != 0){
576        $first=0;
577        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
578    }
579    $hasNext = false;
580    if (count($recents)>$conf['recent']) {
581        $hasNext = true;
582        array_pop($recents); // remove extra log entry
583    }
584
585    print p_locale_xhtml('recent');
586
587    if (getNS($ID) != '')
588        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
589
590    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
591    $form->addHidden('sectok', null);
592    $form->addHidden('do', 'recent');
593    $form->addHidden('id', $ID);
594    $form->addElement(form_makeOpenTag('ul'));
595
596    foreach($recents as $recent){
597        $date = dformat($recent['date']);
598        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
599            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
600        else
601            $form->addElement(form_makeOpenTag('li'));
602
603        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
604
605        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
606        $form->addElement($date);
607        $form->addElement(form_makeCloseTag('span'));
608
609        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
610        $form->addElement(form_makeTag('img', array(
611                        'src'   => DOKU_BASE.'lib/images/diff.png',
612                        'width' => 15,
613                        'height'=> 11,
614                        'title' => $lang['diff'],
615                        'alt'   => $lang['diff']
616                        )));
617        $form->addElement(form_makeCloseTag('a'));
618
619        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
620        $form->addElement(form_makeTag('img', array(
621                        'src'   => DOKU_BASE.'lib/images/history.png',
622                        'width' => 12,
623                        'height'=> 14,
624                        'title' => $lang['btn_revs'],
625                        'alt'   => $lang['btn_revs']
626                        )));
627        $form->addElement(form_makeCloseTag('a'));
628
629        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
630
631        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
632        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
633        $form->addElement(form_makeCloseTag('span'));
634
635        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
636        if($recent['user']){
637            $form->addElement(editorinfo($recent['user']));
638            if(auth_ismanager()){
639                $form->addElement(' ('.$recent['ip'].')');
640            }
641        }else{
642            $form->addElement($recent['ip']);
643        }
644        $form->addElement(form_makeCloseTag('span'));
645
646        $form->addElement(form_makeCloseTag('div'));
647        $form->addElement(form_makeCloseTag('li'));
648    }
649    $form->addElement(form_makeCloseTag('ul'));
650
651    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
652    $last = $first + $conf['recent'];
653    if ($first > 0) {
654        $first -= $conf['recent'];
655        if ($first < 0) $first = 0;
656        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
657        $form->addElement(form_makeTag('input', array(
658                    'type'  => 'submit',
659                    'name'  => 'first['.$first.']',
660                    'value' => $lang['btn_newer'],
661                    'accesskey' => 'n',
662                    'title' => $lang['btn_newer'].' [N]',
663                    'class' => 'button'
664                    )));
665        $form->addElement(form_makeCloseTag('div'));
666    }
667    if ($hasNext) {
668        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
669        $form->addElement(form_makeTag('input', array(
670                        'type'  => 'submit',
671                        'name'  => 'first['.$last.']',
672                        'value' => $lang['btn_older'],
673                        'accesskey' => 'p',
674                        'title' => $lang['btn_older'].' [P]',
675                        'class' => 'button'
676                        )));
677        $form->addElement(form_makeCloseTag('div'));
678    }
679    $form->addElement(form_makeCloseTag('div'));
680    html_form('recent', $form);
681}
682
683/**
684 * Display page index
685 *
686 * @author Andreas Gohr <andi@splitbrain.org>
687 */
688function html_index($ns){
689    require_once(DOKU_INC.'inc/search.php');
690    global $conf;
691    global $ID;
692    $dir = $conf['datadir'];
693    $ns  = cleanID($ns);
694    #fixme use appropriate function
695    if(empty($ns)){
696        $ns = dirname(str_replace(':','/',$ID));
697        if($ns == '.') $ns ='';
698    }
699    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
700
701    echo p_locale_xhtml('index');
702    echo '<div id="index__tree">';
703
704    $data = array();
705    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
706    echo html_buildlist($data,'idx','html_list_index','html_li_index');
707
708    echo '</div>';
709}
710
711/**
712 * Index item formatter
713 *
714 * User function for html_buildlist()
715 *
716 * @author Andreas Gohr <andi@splitbrain.org>
717 */
718function html_list_index($item){
719    global $ID;
720    $ret = '';
721    $base = ':'.$item['id'];
722    $base = substr($base,strrpos($base,':')+1);
723    if($item['type']=='d'){
724        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
725        $ret .= $base;
726        $ret .= '</strong></a>';
727    }else{
728        $ret .= html_wikilink(':'.$item['id']);
729    }
730    return $ret;
731}
732
733/**
734 * Index List item
735 *
736 * This user function is used in html_build_lidt to build the
737 * <li> tags for namespaces when displaying the page index
738 * it gives different classes to opened or closed "folders"
739 *
740 * @author Andreas Gohr <andi@splitbrain.org>
741 */
742function html_li_index($item){
743    if($item['type'] == "f"){
744        return '<li class="level'.$item['level'].'">';
745    }elseif($item['open']){
746        return '<li class="open">';
747    }else{
748        return '<li class="closed">';
749    }
750}
751
752/**
753 * Default List item
754 *
755 * @author Andreas Gohr <andi@splitbrain.org>
756 */
757function html_li_default($item){
758    return '<li class="level'.$item['level'].'">';
759}
760
761/**
762 * Build an unordered list
763 *
764 * Build an unordered list from the given $data array
765 * Each item in the array has to have a 'level' property
766 * the item itself gets printed by the given $func user
767 * function. The second and optional function is used to
768 * print the <li> tag. Both user function need to accept
769 * a single item.
770 *
771 * Both user functions can be given as array to point to
772 * a member of an object.
773 *
774 * @author Andreas Gohr <andi@splitbrain.org>
775 */
776function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
777    $level = 0;
778    $opens = 0;
779    $ret   = '';
780
781    foreach ($data as $item){
782
783        if( $item['level'] > $level ){
784            //open new list
785            for($i=0; $i<($item['level'] - $level); $i++){
786                if ($i) $ret .= "<li class=\"clear\">\n";
787                $ret .= "\n<ul class=\"$class\">\n";
788            }
789        }elseif( $item['level'] < $level ){
790            //close last item
791            $ret .= "</li>\n";
792            for ($i=0; $i<($level - $item['level']); $i++){
793                //close higher lists
794                $ret .= "</ul>\n</li>\n";
795            }
796        }else{
797            //close last item
798            $ret .= "</li>\n";
799        }
800
801        //remember current level
802        $level = $item['level'];
803
804        //print item
805        $ret .= call_user_func($lifunc,$item);
806        $ret .= '<div class="li">';
807
808        $ret .= call_user_func($func,$item);
809        $ret .= '</div>';
810    }
811
812    //close remaining items and lists
813    for ($i=0; $i < $level; $i++){
814        $ret .= "</li></ul>\n";
815    }
816
817    return $ret;
818}
819
820/**
821 * display backlinks
822 *
823 * @author Andreas Gohr <andi@splitbrain.org>
824 * @author Michael Klier <chi@chimeric.de>
825 */
826function html_backlinks(){
827    require_once(DOKU_INC.'inc/fulltext.php');
828    global $ID;
829    global $conf;
830    global $lang;
831
832    print p_locale_xhtml('backlinks');
833
834    $data = ft_backlinks($ID);
835
836    if(!empty($data)) {
837        print '<ul class="idx">';
838        foreach($data as $blink){
839            print '<li><div class="li">';
840            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
841            print '</div></li>';
842        }
843        print '</ul>';
844    } else {
845        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
846    }
847}
848
849/**
850 * show diff
851 *
852 * @author Andreas Gohr <andi@splitbrain.org>
853 */
854function html_diff($text='',$intro=true){
855    require_once(DOKU_INC.'inc/DifferenceEngine.php');
856    global $ID;
857    global $REV;
858    global $lang;
859    global $conf;
860
861    // we're trying to be clever here, revisions to compare can be either
862    // given as rev and rev2 parameters, with rev2 being optional. Or in an
863    // array in rev2.
864    $rev1 = $REV;
865
866    if(is_array($_REQUEST['rev2'])){
867        $rev1 = (int) $_REQUEST['rev2'][0];
868        $rev2 = (int) $_REQUEST['rev2'][1];
869
870        if(!$rev1){
871            $rev1 = $rev2;
872            unset($rev2);
873        }
874    }else{
875        $rev2 = (int) $_REQUEST['rev2'];
876    }
877
878    if($text){                      // compare text to the most current revision
879        $l_rev   = '';
880        $l_text  = rawWiki($ID,'');
881        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
882            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
883            $lang['current'];
884
885        $r_rev   = '';
886        $r_text  = cleanText($text);
887        $r_head  = $lang['yours'];
888    }else{
889        if($rev1 && $rev2){            // two specific revisions wanted
890            // make sure order is correct (older on the left)
891            if($rev1 < $rev2){
892                $l_rev = $rev1;
893                $r_rev = $rev2;
894            }else{
895                $l_rev = $rev2;
896                $r_rev = $rev1;
897            }
898        }elseif($rev1){                // single revision given, compare to current
899            $r_rev = '';
900            $l_rev = $rev1;
901        }else{                        // no revision was given, compare previous to current
902            $r_rev = '';
903            $revs = getRevisions($ID, 0, 1);
904            $l_rev = $revs[0];
905            $REV = $l_rev; // store revision back in $REV
906        }
907
908        // when both revisions are empty then the page was created just now
909        if(!$l_rev && !$r_rev){
910            $l_text = '';
911        }else{
912            $l_text = rawWiki($ID,$l_rev);
913        }
914        $r_text = rawWiki($ID,$r_rev);
915
916        if(!$l_rev){
917            $l_head = '&mdash;';
918        }else{
919            $l_info   = getRevisionInfo($ID,$l_rev,true);
920            if($l_info['user']){
921                $l_user = editorinfo($l_info['user']);
922                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
923            } else {
924                $l_user = $l_info['ip'];
925            }
926            $l_user  = '<span class="user">'.$l_user.'</span>';
927            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
928            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
929
930            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
931            $ID.' ['.dformat($l_rev).']</a>'.
932            '<br />'.$l_user.' '.$l_sum;
933        }
934
935        if($r_rev){
936            $r_info   = getRevisionInfo($ID,$r_rev,true);
937            if($r_info['user']){
938                $r_user = editorinfo($r_info['user']);
939                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
940            } else {
941                $r_user = $r_info['ip'];
942            }
943            $r_user = '<span class="user">'.$r_user.'</span>';
944            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
945            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
946
947            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
948            $ID.' ['.dformat($r_rev).']</a>'.
949            '<br />'.$r_user.' '.$r_sum;
950        }elseif($_rev = @filemtime(wikiFN($ID))){
951            $_info   = getRevisionInfo($ID,$_rev,true);
952            if($_info['user']){
953                $_user = editorinfo($_info['user']);
954                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
955            } else {
956                $_user = $_info['ip'];
957            }
958            $_user = '<span class="user">'.$_user.'</span>';
959            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
960            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
961
962            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
963            $ID.' ['.dformat($_rev).']</a> '.
964            '('.$lang['current'].')'.
965            '<br />'.$_user.' '.$_sum;
966        }else{
967            $r_head = '&mdash; ('.$lang['current'].')';
968        }
969    }
970
971    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
972        explode("\n",htmlspecialchars($r_text)));
973
974    $tdf = new TableDiffFormatter();
975    if($intro) print p_locale_xhtml('diff');
976    ?>
977    <table class="diff">
978    <tr>
979    <th colspan="2" <?php echo $l_minor?>>
980    <?php echo $l_head?>
981    </th>
982    <th colspan="2" <?php echo $r_minor?>>
983    <?php echo $r_head?>
984    </th>
985    </tr>
986    <?php echo $tdf->format($df)?>
987    </table>
988    <?php
989}
990
991/**
992 * show warning on conflict detection
993 *
994 * @author Andreas Gohr <andi@splitbrain.org>
995 */
996function html_conflict($text,$summary){
997    global $ID;
998    global $lang;
999
1000    print p_locale_xhtml('conflict');
1001    $form = new Doku_Form(array('id' => 'dw__editform'));
1002    $form->addHidden('id', $ID);
1003    $form->addHidden('wikitext', $text);
1004    $form->addHidden('summary', $summary);
1005    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1006    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1007    html_form('conflict', $form);
1008    print '<br /><br /><br /><br />'.NL;
1009}
1010
1011/**
1012 * Prints the global message array
1013 *
1014 * @author Andreas Gohr <andi@splitbrain.org>
1015 */
1016function html_msgarea(){
1017    global $MSG;
1018    if(!isset($MSG)) return;
1019
1020    $shown = array();
1021    foreach($MSG as $msg){
1022        $hash = md5($msg['msg']);
1023        if(isset($shown[$hash])) continue; // skip double messages
1024        print '<div class="'.$msg['lvl'].'">';
1025        print $msg['msg'];
1026        print '</div>';
1027        $shown[$hash] = 1;
1028    }
1029}
1030
1031/**
1032 * Prints the registration form
1033 *
1034 * @author Andreas Gohr <andi@splitbrain.org>
1035 */
1036function html_register(){
1037    global $lang;
1038    global $conf;
1039    global $ID;
1040
1041    print p_locale_xhtml('register');
1042    print '<div class="centeralign">'.NL;
1043    $form = new Doku_Form(array('id' => 'dw__register'));
1044    $form->startFieldset($lang['register']);
1045    $form->addHidden('do', 'register');
1046    $form->addHidden('save', '1');
1047    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1048    if (!$conf['autopasswd']) {
1049        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1050        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1051    }
1052    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1053    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1054    $form->addElement(form_makeButton('submit', '', $lang['register']));
1055    $form->endFieldset();
1056    html_form('register', $form);
1057
1058    print '</div>'.NL;
1059}
1060
1061/**
1062 * Print the update profile form
1063 *
1064 * @author Christopher Smith <chris@jalakai.co.uk>
1065 * @author Andreas Gohr <andi@splitbrain.org>
1066 */
1067function html_updateprofile(){
1068    global $lang;
1069    global $conf;
1070    global $ID;
1071    global $INFO;
1072    global $auth;
1073
1074    print p_locale_xhtml('updateprofile');
1075
1076    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1077    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1078    print '<div class="centeralign">'.NL;
1079    $form = new Doku_Form(array('id' => 'dw__register'));
1080    $form->startFieldset($lang['profile']);
1081    $form->addHidden('do', 'profile');
1082    $form->addHidden('save', '1');
1083    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1084    $attr = array('size'=>'50');
1085    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1086    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1087    $attr = array('size'=>'50');
1088    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1089    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1090    $form->addElement(form_makeTag('br'));
1091    if ($auth->canDo('modPass')) {
1092        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1093        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1094    }
1095    if ($conf['profileconfirm']) {
1096        $form->addElement(form_makeTag('br'));
1097        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1098    }
1099    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1100    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1101    $form->endFieldset();
1102    html_form('updateprofile', $form);
1103    print '</div>'.NL;
1104}
1105
1106/**
1107 * This displays the edit form (lots of logic included)
1108 *
1109 * @fixme    this is a huge lump of code and should be modularized
1110 * @triggers HTML_PAGE_FROMTEMPLATE
1111 * @triggers HTML_EDITFORM_INJECTION
1112 * @author   Andreas Gohr <andi@splitbrain.org>
1113 */
1114function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1115    global $ID;
1116    global $REV;
1117    global $DATE;
1118    global $RANGE;
1119    global $PRE;
1120    global $SUF;
1121    global $INFO;
1122    global $SUM;
1123    global $lang;
1124    global $conf;
1125    global $license;
1126
1127    //set summary default
1128    if(!$SUM){
1129        if($REV){
1130            $SUM = $lang['restored'];
1131        }elseif(!$INFO['exists']){
1132            $SUM = $lang['created'];
1133        }
1134    }
1135
1136    //no text? Load it!
1137    if(!isset($text)){
1138        $pr = false; //no preview mode
1139        if($INFO['exists']){
1140            if($RANGE){
1141                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1142            }else{
1143                $text = rawWiki($ID,$REV);
1144            }
1145            $check = md5($text);
1146            $mod = false;
1147        }else{
1148            //try to load a pagetemplate
1149            $data = array($ID);
1150            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1151            $check = md5('');
1152            $mod = $text!=='';
1153        }
1154    }else{
1155        $pr = true; //preview mode
1156        if (isset($_REQUEST['changecheck'])) {
1157            $check = $_REQUEST['changecheck'];
1158            $mod = md5($text)!==$check;
1159        } else {
1160            // Why? Assume default text is unmodified.
1161            $check = md5($text);
1162            $mod = false;
1163        }
1164    }
1165
1166    $wr = $INFO['writable'] && !$INFO['locked'];
1167    if($wr){
1168        if ($REV) print p_locale_xhtml('editrev');
1169        print p_locale_xhtml($include);
1170    }else{
1171        // check pseudo action 'source'
1172        if(!actionOK('source')){
1173            msg('Command disabled: source',-1);
1174            return;
1175        }
1176        print p_locale_xhtml('read');
1177    }
1178    if(!$DATE) $DATE = $INFO['lastmod'];
1179    ?>
1180        <div style="width:99%;">
1181
1182        <div class="toolbar">
1183        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1184        <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1185            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1186
1187            <?php if($wr){?>
1188                <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1189                    <?php /* sets changed to true when previewed */?>
1190                    textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1191                //--><!]]></script>
1192            <?php } ?>
1193        </div>
1194        <?php
1195        $form = new Doku_Form(array('id' => 'dw__editform'));
1196        $form->addHidden('id', $ID);
1197        $form->addHidden('rev', $REV);
1198        $form->addHidden('date', $DATE);
1199        $form->addHidden('prefix', $PRE);
1200        $form->addHidden('suffix', $SUF);
1201        $form->addHidden('changecheck', $check);
1202        $attr = array('tabindex'=>'1');
1203        if (!$wr) $attr['readonly'] = 'readonly';
1204        $form->addElement(form_makeWikiText($text, $attr));
1205        $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1206        $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1207        $form->addElement(form_makeCloseTag('div'));
1208        if ($wr) {
1209            $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1210            $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1211            $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1212            $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1213            $form->addElement(form_makeCloseTag('div'));
1214            $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1215            $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1216            $elem = html_minoredit();
1217            if ($elem) $form->addElement($elem);
1218            $form->addElement(form_makeCloseTag('div'));
1219        }
1220        $form->addElement(form_makeCloseTag('div'));
1221        if($wr && $conf['license']){
1222            $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1223            $out  = $lang['licenseok'];
1224            $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1225            if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
1226            $out .= '> '.$license[$conf['license']]['name'].'</a>';
1227            $form->addElement($out);
1228            $form->addElement(form_makeCloseTag('div'));
1229        }
1230        html_form('edit', $form);
1231        print '</div>'.NL;
1232}
1233
1234/**
1235 * Adds a checkbox for minor edits for logged in users
1236 *
1237 * @author Andreas Gohr <andi@splitbrain.org>
1238 */
1239function html_minoredit(){
1240    global $conf;
1241    global $lang;
1242    // minor edits are for logged in users only
1243    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1244        return false;
1245    }
1246
1247    $p = array();
1248    $p['tabindex'] = 3;
1249    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1250    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1251}
1252
1253/**
1254 * prints some debug info
1255 *
1256 * @author Andreas Gohr <andi@splitbrain.org>
1257 */
1258function html_debug(){
1259    global $conf;
1260    global $lang;
1261    global $auth;
1262    global $INFO;
1263
1264    //remove sensitive data
1265    $cnf = $conf;
1266    debug_guard($cnf);
1267    $nfo = $INFO;
1268    debug_guard($nfo);
1269    $ses = $_SESSION;
1270    debug_guard($ses);
1271
1272    print '<html><body>';
1273
1274    print '<p>When reporting bugs please send all the following ';
1275    print 'output as a mail to andi@splitbrain.org ';
1276    print 'The best way to do this is to save this page in your browser</p>';
1277
1278    print '<b>$INFO:</b><pre>';
1279    print_r($nfo);
1280    print '</pre>';
1281
1282    print '<b>$_SERVER:</b><pre>';
1283    print_r($_SERVER);
1284    print '</pre>';
1285
1286    print '<b>$conf:</b><pre>';
1287    print_r($cnf);
1288    print '</pre>';
1289
1290    print '<b>DOKU_BASE:</b><pre>';
1291    print DOKU_BASE;
1292    print '</pre>';
1293
1294    print '<b>abs DOKU_BASE:</b><pre>';
1295    print DOKU_URL;
1296    print '</pre>';
1297
1298    print '<b>rel DOKU_BASE:</b><pre>';
1299    print dirname($_SERVER['PHP_SELF']).'/';
1300    print '</pre>';
1301
1302    print '<b>PHP Version:</b><pre>';
1303    print phpversion();
1304    print '</pre>';
1305
1306    print '<b>locale:</b><pre>';
1307    print setlocale(LC_ALL,0);
1308    print '</pre>';
1309
1310    print '<b>encoding:</b><pre>';
1311    print $lang['encoding'];
1312    print '</pre>';
1313
1314    if($auth){
1315        print '<b>Auth backend capabilities:</b><pre>';
1316        print_r($auth->cando);
1317        print '</pre>';
1318    }
1319
1320    print '<b>$_SESSION:</b><pre>';
1321    print_r($ses);
1322    print '</pre>';
1323
1324    print '<b>Environment:</b><pre>';
1325    print_r($_ENV);
1326    print '</pre>';
1327
1328    print '<b>PHP settings:</b><pre>';
1329    $inis = ini_get_all();
1330    print_r($inis);
1331    print '</pre>';
1332
1333    print '</body></html>';
1334}
1335
1336/**
1337 * List available Administration Tasks
1338 *
1339 * @author Andreas Gohr <andi@splitbrain.org>
1340 * @author Håkan Sandell <hakan.sandell@home.se>
1341 */
1342function html_admin(){
1343    global $ID;
1344    global $INFO;
1345    global $lang;
1346    global $conf;
1347    global $auth;
1348
1349    // build menu of admin functions from the plugins that handle them
1350    $pluginlist = plugin_list('admin');
1351    $menu = array();
1352    foreach ($pluginlist as $p) {
1353        if($obj =& plugin_load('admin',$p) === null) continue;
1354
1355        // check permissions
1356        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1357
1358        $menu[$p] = array('plugin' => $p,
1359                'prompt' => $obj->getMenuText($conf['lang']),
1360                'sort' => $obj->getMenuSort()
1361                );
1362    }
1363
1364    print p_locale_xhtml('admin');
1365
1366    // Admin Tasks
1367    if($INFO['isadmin']){
1368        ptln('<ul class="admin_tasks">');
1369
1370        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1371            ptln('  <li class="admin_usermanager"><div class="li">'.
1372                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1373                    $menu['usermanager']['prompt'].'</a></div></li>');
1374        }
1375        unset($menu['usermanager']);
1376
1377        if($menu['acl']){
1378            ptln('  <li class="admin_acl"><div class="li">'.
1379                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1380                    $menu['acl']['prompt'].'</a></div></li>');
1381        }
1382        unset($menu['acl']);
1383
1384        if($menu['plugin']){
1385            ptln('  <li class="admin_plugin"><div class="li">'.
1386                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
1387                    $menu['plugin']['prompt'].'</a></div></li>');
1388        }
1389        unset($menu['plugin']);
1390
1391        if($menu['config']){
1392            ptln('  <li class="admin_config"><div class="li">'.
1393                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1394                    $menu['config']['prompt'].'</a></div></li>');
1395        }
1396        unset($menu['config']);
1397    }
1398    ptln('</ul>');
1399
1400    // Manager Tasks
1401    ptln('<ul class="admin_tasks">');
1402
1403    if($menu['revert']){
1404        ptln('  <li class="admin_revert"><div class="li">'.
1405                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1406                $menu['revert']['prompt'].'</a></div></li>');
1407    }
1408    unset($menu['revert']);
1409
1410    if($menu['popularity']){
1411        ptln('  <li class="admin_popularity"><div class="li">'.
1412                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1413                $menu['popularity']['prompt'].'</a></div></li>');
1414    }
1415    unset($menu['popularity']);
1416
1417    ptln('</ul>');
1418
1419    // print the rest as sorted list
1420    if(count($menu)){
1421        usort($menu, 'p_sort_modes');
1422        // output the menu
1423        ptln('<div class="clearer"></div>');
1424        print p_locale_xhtml('adminplugins');
1425        ptln('<ul>');
1426        foreach ($menu as $item) {
1427            if (!$item['prompt']) continue;
1428            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1429        }
1430        ptln('</ul>');
1431    }
1432}
1433
1434/**
1435 * Form to request a new password for an existing account
1436 *
1437 * @author Benoit Chesneau <benoit@bchesneau.info>
1438 */
1439function html_resendpwd() {
1440    global $lang;
1441    global $conf;
1442    global $ID;
1443
1444    print p_locale_xhtml('resendpwd');
1445    print '<div class="centeralign">'.NL;
1446    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1447    $form->startFieldset($lang['resendpwd']);
1448    $form->addHidden('do', 'resendpwd');
1449    $form->addHidden('save', '1');
1450    $form->addElement(form_makeTag('br'));
1451    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1452    $form->addElement(form_makeTag('br'));
1453    $form->addElement(form_makeTag('br'));
1454    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1455    $form->endFieldset();
1456    html_form('resendpwd', $form);
1457    print '</div>'.NL;
1458}
1459
1460/**
1461 * Return the TOC rendered to XHTML
1462 *
1463 * @author Andreas Gohr <andi@splitbrain.org>
1464 */
1465function html_TOC($toc){
1466    if(!count($toc)) return '';
1467    global $lang;
1468    $out  = '<!-- TOC START -->'.DOKU_LF;
1469    $out .= '<div class="toc">'.DOKU_LF;
1470    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1471    $out .= $lang['toc'];
1472    $out .= '</div>'.DOKU_LF;
1473    $out .= '<div id="toc__inside">'.DOKU_LF;
1474    $out .= html_buildlist($toc,'toc','html_list_toc');
1475    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1476    $out .= '<!-- TOC END -->'.DOKU_LF;
1477    return $out;
1478}
1479
1480/**
1481 * Callback for html_buildlist
1482 */
1483function html_list_toc($item){
1484    if(isset($item['hid'])){
1485        $link = '#'.$item['hid'];
1486    }else{
1487        $link = $item['link'];
1488    }
1489
1490    return '<span class="li"><a href="'.$link.'" class="toc">'.
1491        hsc($item['title']).'</a></span>';
1492}
1493
1494/**
1495 * Helper function to build TOC items
1496 *
1497 * Returns an array ready to be added to a TOC array
1498 *
1499 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1500 * @param string $text  - what to display in the TOC
1501 * @param int    $level - nesting level
1502 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1503 */
1504function html_mktocitem($link, $text, $level, $hash='#'){
1505    global $conf;
1506    return  array( 'link'  => $hash.$link,
1507            'title' => $text,
1508            'type'  => 'ul',
1509            'level' => $level);
1510}
1511
1512/**
1513 * Output a Doku_Form object.
1514 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1515 *
1516 * @author Tom N Harris <tnharris@whoopdedo.org>
1517 */
1518function html_form($name, &$form) {
1519    // Safety check in case the caller forgets.
1520    $form->endFieldset();
1521    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1522}
1523
1524/**
1525 * Form print function.
1526 * Just calls printForm() on the data object.
1527 */
1528function html_form_output($data) {
1529    $data->printForm();
1530}
1531
1532/**
1533 * Embed a flash object in HTML
1534 *
1535 * This will create the needed HTML to embed a flash movie in a cross browser
1536 * compatble way using valid XHTML
1537 *
1538 * The parameters $params, $flashvars and $atts need to be associative arrays.
1539 * No escaping needs to be done for them. The alternative content *has* to be
1540 * escaped because it is used as is. If no alternative content is given
1541 * $lang['noflash'] is used.
1542 *
1543 * @author Andreas Gohr <andi@splitbrain.org>
1544 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1545 *
1546 * @param string $swf      - the SWF movie to embed
1547 * @param int $width       - width of the flash movie in pixels
1548 * @param int $height      - height of the flash movie in pixels
1549 * @param array $params    - additional parameters (<param>)
1550 * @param array $flashvars - parameters to be passed in the flashvar parameter
1551 * @param array $atts      - additional attributes for the <object> tag
1552 * @param string $alt      - alternative content (is NOT automatically escaped!)
1553 * @returns string         - the XHTML markup
1554 */
1555function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1556    global $lang;
1557
1558    $out = '';
1559
1560    // prepare the object attributes
1561    if(is_null($atts)) $atts = array();
1562    $atts['width']  = (int) $width;
1563    $atts['height'] = (int) $height;
1564    if(!$atts['width'])  $atts['width']  = 425;
1565    if(!$atts['height']) $atts['height'] = 350;
1566
1567    // add object attributes for standard compliant browsers
1568    $std = $atts;
1569    $std['type'] = 'application/x-shockwave-flash';
1570    $std['data'] = $swf;
1571
1572    // add object attributes for IE
1573    $ie  = $atts;
1574    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1575
1576    // open object (with conditional comments)
1577    $out .= '<!--[if !IE]> -->'.NL;
1578    $out .= '<object '.buildAttributes($std).'>'.NL;
1579    $out .= '<!-- <![endif]-->'.NL;
1580    $out .= '<!--[if IE]>'.NL;
1581    $out .= '<object '.buildAttributes($ie).'>'.NL;
1582    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1583    $out .= '<!--><!-- -->'.NL;
1584
1585    // print params
1586    if(is_array($params)) foreach($params as $key => $val){
1587        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1588    }
1589
1590    // add flashvars
1591    if(is_array($flashvars)){
1592        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1593    }
1594
1595    // alternative content
1596    if($alt){
1597        $out .= $alt.NL;
1598    }else{
1599        $out .= $lang['noflash'].NL;
1600    }
1601
1602    // finish
1603    $out .= '</object>'.NL;
1604    $out .= '<!-- <![endif]-->'.NL;
1605
1606    return $out;
1607}
1608
1609