xref: /dokuwiki/inc/html.php (revision 10f8a4bf26b969e6347d78749bc170ea3f097482)
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    html_form('login', $form);
66
67    if($auth && $auth->canDo('addUser') && actionOK('register')){
68        print '<p>';
69        print $lang['reghere'];
70        print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
71        print '</p>';
72    }
73
74    if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
75        print '<p>';
76        print $lang['pwdforget'];
77        print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
78        print '</p>';
79    }
80    print '</div>'.NL;
81}
82
83/**
84 * prints a section editing button
85 * used as a callback in html_secedit
86 *
87 * @author Andreas Gohr <andi@splitbrain.org>
88 */
89function html_secedit_button($matches){
90    global $ID;
91    global $INFO;
92
93    $section = $matches[2];
94    $name = $matches[1];
95
96    $secedit  = '';
97    $secedit .= '<div class="secedit">';
98    $secedit .= html_btn('secedit',$ID,'',
99            array('do'      => 'edit',
100                'lines'   => "$section",
101                'rev' => $INFO['lastmod']),
102            'post', $name);
103    $secedit .= '</div>';
104    return $secedit;
105}
106
107/**
108 * inserts section edit buttons if wanted or removes the markers
109 *
110 * @author Andreas Gohr <andi@splitbrain.org>
111 */
112function html_secedit($text,$show=true){
113    global $INFO;
114
115    if($INFO['writable'] && $show && !$INFO['rev']){
116        $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
117                'html_secedit_button', $text);
118    }else{
119        $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
120    }
121
122    return $text;
123}
124
125/**
126 * Just the back to top button (in its own form)
127 *
128 * @author Andreas Gohr <andi@splitbrain.org>
129 */
130function html_topbtn(){
131    global $lang;
132
133    $ret  = '';
134    $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>';
135
136    return $ret;
137}
138
139/**
140 * Displays a button (using its own form)
141 * If tooltip exists, the access key tooltip is replaced.
142 *
143 * @author Andreas Gohr <andi@splitbrain.org>
144 */
145function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
146    global $conf;
147    global $lang;
148
149    $label = $lang['btn_'.$name];
150
151    $ret = '';
152    $tip = '';
153
154    //filter id (without urlencoding)
155    $id = idfilter($id,false);
156
157    //make nice URLs even for buttons
158    if($conf['userewrite'] == 2){
159        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
160    }elseif($conf['userewrite']){
161        $script = DOKU_BASE.$id;
162    }else{
163        $script = DOKU_BASE.DOKU_SCRIPT;
164        $params['id'] = $id;
165    }
166
167    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
168
169    if(is_array($params)){
170        reset($params);
171        while (list($key, $val) = each($params)) {
172            $ret .= '<input type="hidden" name="'.$key.'" ';
173            $ret .= 'value="'.htmlspecialchars($val).'" />';
174        }
175    }
176
177    if ($tooltip!='') {
178        $tip = htmlspecialchars($tooltip);
179    }else{
180        $tip = htmlspecialchars($label);
181    }
182
183    $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
184    if($akey){
185        $tip .= ' ['.strtoupper($akey).']';
186        $ret .= 'accesskey="'.$akey.'" ';
187    }
188    $ret .= 'title="'.$tip.'" ';
189    $ret .= '/>';
190    $ret .= '</div></form>';
191
192    return $ret;
193}
194
195/**
196 * show a wiki page
197 *
198 * @author Andreas Gohr <andi@splitbrain.org>
199 */
200function html_show($txt=''){
201    global $ID;
202    global $REV;
203    global $HIGH;
204    global $INFO;
205    //disable section editing for old revisions or in preview
206    if($txt || $REV){
207        $secedit = false;
208    }else{
209        $secedit = true;
210    }
211
212    if ($txt){
213        //PreviewHeader
214        echo '<br id="scroll__here" />';
215        echo p_locale_xhtml('preview');
216        echo '<div class="preview">';
217        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
218        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
219        echo $html;
220        echo '<div class="clearer"></div>';
221        echo '</div>';
222
223    }else{
224        if ($REV) print p_locale_xhtml('showrev');
225        $html = p_wiki_xhtml($ID,$REV,true);
226        $html = html_secedit($html,$secedit);
227        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
228        $html = html_hilight($html,$HIGH);
229        echo $html;
230    }
231}
232
233/**
234 * ask the user about how to handle an exisiting draft
235 *
236 * @author Andreas Gohr <andi@splitbrain.org>
237 */
238function html_draft(){
239    global $INFO;
240    global $ID;
241    global $lang;
242    global $conf;
243    $draft = unserialize(io_readFile($INFO['draft'],false));
244    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
245
246    print p_locale_xhtml('draft');
247    $form = new Doku_Form(array('id' => 'dw__editform'));
248    $form->addHidden('id', $ID);
249    $form->addHidden('date', $draft['date']);
250    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
251    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
252    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
253    $form->addElement(form_makeCloseTag('div'));
254    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
255    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
256    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
257    html_form('draft', $form);
258}
259
260/**
261 * Highlights searchqueries in HTML code
262 *
263 * @author Andreas Gohr <andi@splitbrain.org>
264 * @author Harry Fuecks <hfuecks@gmail.com>
265 */
266function html_hilight($html,$phrases){
267    $phrases = array_filter((array) $phrases);
268    $regex = join('|',array_map('preg_quote_cb',$phrases));
269
270    if ($regex === '') return $html;
271    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
272    return $html;
273}
274
275/**
276 * Callback used by html_hilight()
277 *
278 * @author Harry Fuecks <hfuecks@gmail.com>
279 */
280function html_hilight_callback($m) {
281    $hlight = unslash($m[0]);
282    if ( !isset($m[2])) {
283        $hlight = '<span class="search_hit">'.$hlight.'</span>';
284    }
285    return $hlight;
286}
287
288/**
289 * Run a search and display the result
290 *
291 * @author Andreas Gohr <andi@splitbrain.org>
292 */
293function html_search(){
294    require_once(DOKU_INC.'inc/search.php');
295    require_once(DOKU_INC.'inc/fulltext.php');
296    global $conf;
297    global $QUERY;
298    global $ID;
299    global $lang;
300
301    print p_locale_xhtml('searchpage');
302    flush();
303
304    //check if search is restricted to namespace
305    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
306        $id = cleanID($match[1]);
307    } else {
308        $id = cleanID($QUERY);
309    }
310
311    //show progressbar
312    print '<div class="centeralign" id="dw__loading">'.NL;
313    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
314    print 'showLoadBar();'.NL;
315    print '//--><!]]></script>'.NL;
316    print '<br /></div>'.NL;
317    flush();
318
319    //do quick pagesearch
320    $data = array();
321
322    if($id) $data = ft_pageLookup($id);
323    if(count($data)){
324        print '<div class="search_quickresult">';
325        print '<h3>'.$lang['quickhits'].':</h3>';
326        print '<ul class="search_quickhits">';
327        foreach($data as $id){
328            print '<li> ';
329            $ns = getNS($id);
330            if($ns){
331                $name = shorten(noNS($id), ' ('.$ns.')',30);
332            }else{
333                $name = $id;
334            }
335            print html_wikilink(':'.$id,$name);
336            print '</li> ';
337        }
338        print '</ul> ';
339        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
340        print '<div class="clearer">&nbsp;</div>';
341        print '</div>';
342    }
343    flush();
344
345    //do fulltext search
346    $data = ft_pageSearch($QUERY,$regex);
347    if(count($data)){
348        $num = 1;
349        foreach($data as $id => $cnt){
350            print '<div class="search_result">';
351            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
352            if($cnt !== 0){
353                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
354                if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
355                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
356                }
357                $num++;
358            }
359            print '</div>';
360            flush();
361        }
362    }else{
363        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
364    }
365
366    //hide progressbar
367    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
368    print 'hideLoadBar("dw__loading");'.NL;
369    print '//--><!]]></script>'.NL;
370    flush();
371}
372
373/**
374 * Display error on locked pages
375 *
376 * @author Andreas Gohr <andi@splitbrain.org>
377 */
378function html_locked(){
379    global $ID;
380    global $conf;
381    global $lang;
382    global $INFO;
383
384    $locktime = filemtime(wikiLockFN($ID));
385    $expire = dformat($locktime + $conf['locktime']);
386    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
387
388    print p_locale_xhtml('locked');
389    print '<ul>';
390    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
391    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
392    print '</ul>';
393}
394
395/**
396 * list old revisions
397 *
398 * @author Andreas Gohr <andi@splitbrain.org>
399 * @author Ben Coburn <btcoburn@silicodon.net>
400 */
401function html_revisions($first=0){
402    global $ID;
403    global $INFO;
404    global $conf;
405    global $lang;
406    /* we need to get one additionally log entry to be able to
407     * decide if this is the last page or is there another one.
408     * see html_recent()
409     */
410    $revisions = getRevisions($ID, $first, $conf['recent']+1);
411    if(count($revisions)==0 && $first!=0){
412        $first=0;
413        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
414    }
415    $hasNext = false;
416    if (count($revisions)>$conf['recent']) {
417        $hasNext = true;
418        array_pop($revisions); // remove extra log entry
419    }
420
421    $date = dformat($INFO['lastmod']);
422
423    print p_locale_xhtml('revisions');
424
425    $form = new Doku_Form(array('id' => 'page__revisions'));
426    $form->addElement(form_makeOpenTag('ul'));
427    if($INFO['exists'] && $first==0){
428        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
429            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
430        else
431            $form->addElement(form_makeOpenTag('li'));
432        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
433        $form->addElement(form_makeTag('input', array(
434                        'type' => 'checkbox',
435                        'name' => 'rev2[]',
436                        'value' => 'current')));
437
438        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
439        $form->addElement($date);
440        $form->addElement(form_makeCloseTag('span'));
441
442        $form->addElement(form_makeTag('img', array(
443                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
444                        'width' => '15',
445                        'height' => '11',
446                        'alt'    => '')));
447
448        $form->addElement(form_makeOpenTag('a', array(
449                        'class' => 'wikilink1',
450                        'href'  => wl($ID))));
451        $form->addElement($ID);
452        $form->addElement(form_makeCloseTag('a'));
453
454        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
455        $form->addElement(' &ndash; ');
456        $form->addElement(htmlspecialchars($INFO['sum']));
457        $form->addElement(form_makeCloseTag('span'));
458
459        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
460        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
461        $form->addElement(form_makeCloseTag('span'));
462
463        $form->addElement('('.$lang['current'].')');
464        $form->addElement(form_makeCloseTag('div'));
465        $form->addElement(form_makeCloseTag('li'));
466    }
467
468    foreach($revisions as $rev){
469        $date   = dformat($rev);
470        $info   = getRevisionInfo($ID,$rev,true);
471        $exists = page_exists($ID,$rev);
472
473        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
474            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
475        else
476            $form->addElement(form_makeOpenTag('li'));
477        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
478        if($exists){
479            $form->addElement(form_makeTag('input', array(
480                            'type' => 'checkbox',
481                            'name' => 'rev2[]',
482                            'value' => $rev)));
483        }else{
484            $form->addElement(form_makeTag('img', array(
485                            'src' => DOKU_BASE.'lib/images/blank.gif',
486                            'width' => 14,
487                            'height' => 11,
488                            'alt' => '')));
489        }
490
491        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
492        $form->addElement($date);
493        $form->addElement(form_makeCloseTag('span'));
494
495        if($exists){
496            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
497            $form->addElement(form_makeTag('img', array(
498                            'src'    => DOKU_BASE.'lib/images/diff.png',
499                            'width'  => 15,
500                            'height' => 11,
501                            'title'  => $lang['diff'],
502                            'alt'    => $lang['diff'])));
503            $form->addElement(form_makeCloseTag('a'));
504
505            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
506            $form->addElement($ID);
507            $form->addElement(form_makeCloseTag('a'));
508        }else{
509            $form->addElement(form_makeTag('img', array(
510                            'src' => DOKU_BASE.'lib/images/blank.gif',
511                            'width' => '15',
512                            'height' => '11',
513                            'alt'   => '')));
514            $form->addElement($ID);
515        }
516
517        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
518        $form->addElement(' &ndash; ');
519        $form->addElement(htmlspecialchars($info['sum']));
520        $form->addElement(form_makeCloseTag('span'));
521
522        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
523        if($info['user']){
524            $form->addElement(editorinfo($info['user']));
525            if(auth_ismanager()){
526                $form->addElement(' ('.$info['ip'].')');
527            }
528        }else{
529            $form->addElement($info['ip']);
530        }
531        $form->addElement(form_makeCloseTag('span'));
532
533        $form->addElement(form_makeCloseTag('div'));
534        $form->addElement(form_makeCloseTag('li'));
535    }
536    $form->addElement(form_makeCloseTag('ul'));
537    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
538    html_form('revisions', $form);
539
540    print '<div class="pagenav">';
541    $last = $first + $conf['recent'];
542    if ($first > 0) {
543        $first -= $conf['recent'];
544        if ($first < 0) $first = 0;
545        print '<div class="pagenav-prev">';
546        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
547        print '</div>';
548    }
549    if ($hasNext) {
550        print '<div class="pagenav-next">';
551        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
552        print '</div>';
553    }
554    print '</div>';
555
556}
557
558/**
559 * display recent changes
560 *
561 * @author Andreas Gohr <andi@splitbrain.org>
562 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
563 * @author Ben Coburn <btcoburn@silicodon.net>
564 */
565function html_recent($first=0){
566    global $conf;
567    global $lang;
568    global $ID;
569    /* we need to get one additionally log entry to be able to
570     * decide if this is the last page or is there another one.
571     * This is the cheapest solution to get this information.
572     */
573    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
574    if(count($recents) == 0 && $first != 0){
575        $first=0;
576        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
577    }
578    $hasNext = false;
579    if (count($recents)>$conf['recent']) {
580        $hasNext = true;
581        array_pop($recents); // remove extra log entry
582    }
583
584    print p_locale_xhtml('recent');
585
586    if (getNS($ID) != '')
587        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
588
589    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
590    $form->addHidden('sectok', null);
591    $form->addHidden('do', 'recent');
592    $form->addHidden('id', $ID);
593    $form->addElement(form_makeOpenTag('ul'));
594
595    foreach($recents as $recent){
596        $date = dformat($recent['date']);
597        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
598            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
599        else
600            $form->addElement(form_makeOpenTag('li'));
601
602        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
603
604        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
605        $form->addElement($date);
606        $form->addElement(form_makeCloseTag('span'));
607
608        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
609        $form->addElement(form_makeTag('img', array(
610                        'src'   => DOKU_BASE.'lib/images/diff.png',
611                        'width' => 15,
612                        'height'=> 11,
613                        'title' => $lang['diff'],
614                        'alt'   => $lang['diff']
615                        )));
616        $form->addElement(form_makeCloseTag('a'));
617
618        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
619        $form->addElement(form_makeTag('img', array(
620                        'src'   => DOKU_BASE.'lib/images/history.png',
621                        'width' => 12,
622                        'height'=> 14,
623                        'title' => $lang['btn_revs'],
624                        'alt'   => $lang['btn_revs']
625                        )));
626        $form->addElement(form_makeCloseTag('a'));
627
628        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
629
630        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
631        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
632        $form->addElement(form_makeCloseTag('span'));
633
634        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
635        if($recent['user']){
636            $form->addElement(editorinfo($recent['user']));
637            if(auth_ismanager()){
638                $form->addElement(' ('.$recent['ip'].')');
639            }
640        }else{
641            $form->addElement($recent['ip']);
642        }
643        $form->addElement(form_makeCloseTag('span'));
644
645        $form->addElement(form_makeCloseTag('div'));
646        $form->addElement(form_makeCloseTag('li'));
647    }
648    $form->addElement(form_makeCloseTag('ul'));
649
650    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
651    $last = $first + $conf['recent'];
652    if ($first > 0) {
653        $first -= $conf['recent'];
654        if ($first < 0) $first = 0;
655        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
656        $form->addElement(form_makeTag('input', array(
657                    'type'  => 'submit',
658                    'name'  => 'first['.$first.']',
659                    'value' => $lang['btn_newer'],
660                    'accesskey' => 'n',
661                    'title' => $lang['btn_newer'].' [N]',
662                    'class' => 'button'
663                    )));
664        $form->addElement(form_makeCloseTag('div'));
665    }
666    if ($hasNext) {
667        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
668        $form->addElement(form_makeTag('input', array(
669                        'type'  => 'submit',
670                        'name'  => 'first['.$last.']',
671                        'value' => $lang['btn_older'],
672                        'accesskey' => 'p',
673                        'title' => $lang['btn_older'].' [P]',
674                        'class' => 'button'
675                        )));
676        $form->addElement(form_makeCloseTag('div'));
677    }
678    $form->addElement(form_makeCloseTag('div'));
679    html_form('recent', $form);
680}
681
682/**
683 * Display page index
684 *
685 * @author Andreas Gohr <andi@splitbrain.org>
686 */
687function html_index($ns){
688    require_once(DOKU_INC.'inc/search.php');
689    global $conf;
690    global $ID;
691    $dir = $conf['datadir'];
692    $ns  = cleanID($ns);
693    #fixme use appropriate function
694    if(empty($ns)){
695        $ns = dirname(str_replace(':','/',$ID));
696        if($ns == '.') $ns ='';
697    }
698    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
699
700    echo p_locale_xhtml('index');
701    echo '<div id="index__tree">';
702
703    $data = array();
704    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
705    echo html_buildlist($data,'idx','html_list_index','html_li_index');
706
707    echo '</div>';
708}
709
710/**
711 * Index item formatter
712 *
713 * User function for html_buildlist()
714 *
715 * @author Andreas Gohr <andi@splitbrain.org>
716 */
717function html_list_index($item){
718    global $ID;
719    $ret = '';
720    $base = ':'.$item['id'];
721    $base = substr($base,strrpos($base,':')+1);
722    if($item['type']=='d'){
723        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
724        $ret .= $base;
725        $ret .= '</strong></a>';
726    }else{
727        $ret .= html_wikilink(':'.$item['id']);
728    }
729    return $ret;
730}
731
732/**
733 * Index List item
734 *
735 * This user function is used in html_build_lidt to build the
736 * <li> tags for namespaces when displaying the page index
737 * it gives different classes to opened or closed "folders"
738 *
739 * @author Andreas Gohr <andi@splitbrain.org>
740 */
741function html_li_index($item){
742    if($item['type'] == "f"){
743        return '<li class="level'.$item['level'].'">';
744    }elseif($item['open']){
745        return '<li class="open">';
746    }else{
747        return '<li class="closed">';
748    }
749}
750
751/**
752 * Default List item
753 *
754 * @author Andreas Gohr <andi@splitbrain.org>
755 */
756function html_li_default($item){
757    return '<li class="level'.$item['level'].'">';
758}
759
760/**
761 * Build an unordered list
762 *
763 * Build an unordered list from the given $data array
764 * Each item in the array has to have a 'level' property
765 * the item itself gets printed by the given $func user
766 * function. The second and optional function is used to
767 * print the <li> tag. Both user function need to accept
768 * a single item.
769 *
770 * Both user functions can be given as array to point to
771 * a member of an object.
772 *
773 * @author Andreas Gohr <andi@splitbrain.org>
774 */
775function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
776    $level = 0;
777    $opens = 0;
778    $ret   = '';
779
780    foreach ($data as $item){
781
782        if( $item['level'] > $level ){
783            //open new list
784            for($i=0; $i<($item['level'] - $level); $i++){
785                if ($i) $ret .= "<li class=\"clear\">\n";
786                $ret .= "\n<ul class=\"$class\">\n";
787            }
788        }elseif( $item['level'] < $level ){
789            //close last item
790            $ret .= "</li>\n";
791            for ($i=0; $i<($level - $item['level']); $i++){
792                //close higher lists
793                $ret .= "</ul>\n</li>\n";
794            }
795        }else{
796            //close last item
797            $ret .= "</li>\n";
798        }
799
800        //remember current level
801        $level = $item['level'];
802
803        //print item
804        $ret .= call_user_func($lifunc,$item);
805        $ret .= '<div class="li">';
806
807        $ret .= call_user_func($func,$item);
808        $ret .= '</div>';
809    }
810
811    //close remaining items and lists
812    for ($i=0; $i < $level; $i++){
813        $ret .= "</li></ul>\n";
814    }
815
816    return $ret;
817}
818
819/**
820 * display backlinks
821 *
822 * @author Andreas Gohr <andi@splitbrain.org>
823 * @author Michael Klier <chi@chimeric.de>
824 */
825function html_backlinks(){
826    require_once(DOKU_INC.'inc/fulltext.php');
827    global $ID;
828    global $conf;
829    global $lang;
830
831    print p_locale_xhtml('backlinks');
832
833    $data = ft_backlinks($ID);
834
835    if(!empty($data)) {
836        print '<ul class="idx">';
837        foreach($data as $blink){
838            print '<li><div class="li">';
839            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
840            print '</div></li>';
841        }
842        print '</ul>';
843    } else {
844        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
845    }
846}
847
848/**
849 * show diff
850 *
851 * @author Andreas Gohr <andi@splitbrain.org>
852 */
853function html_diff($text='',$intro=true){
854    require_once(DOKU_INC.'inc/DifferenceEngine.php');
855    global $ID;
856    global $REV;
857    global $lang;
858    global $conf;
859
860    // we're trying to be clever here, revisions to compare can be either
861    // given as rev and rev2 parameters, with rev2 being optional. Or in an
862    // array in rev2.
863    $rev1 = $REV;
864
865    if(is_array($_REQUEST['rev2'])){
866        $rev1 = (int) $_REQUEST['rev2'][0];
867        $rev2 = (int) $_REQUEST['rev2'][1];
868
869        if(!$rev1){
870            $rev1 = $rev2;
871            unset($rev2);
872        }
873    }else{
874        $rev2 = (int) $_REQUEST['rev2'];
875    }
876
877    if($text){                      // compare text to the most current revision
878        $l_rev   = '';
879        $l_text  = rawWiki($ID,'');
880        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
881            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
882            $lang['current'];
883
884        $r_rev   = '';
885        $r_text  = cleanText($text);
886        $r_head  = $lang['yours'];
887    }else{
888        if($rev1 && $rev2){            // two specific revisions wanted
889            // make sure order is correct (older on the left)
890            if($rev1 < $rev2){
891                $l_rev = $rev1;
892                $r_rev = $rev2;
893            }else{
894                $l_rev = $rev2;
895                $r_rev = $rev1;
896            }
897        }elseif($rev1){                // single revision given, compare to current
898            $r_rev = '';
899            $l_rev = $rev1;
900        }else{                        // no revision was given, compare previous to current
901            $r_rev = '';
902            $revs = getRevisions($ID, 0, 1);
903            $l_rev = $revs[0];
904            $REV = $l_rev; // store revision back in $REV
905        }
906
907        // when both revisions are empty then the page was created just now
908        if(!$l_rev && !$r_rev){
909            $l_text = '';
910        }else{
911            $l_text = rawWiki($ID,$l_rev);
912        }
913        $r_text = rawWiki($ID,$r_rev);
914
915        if(!$l_rev){
916            $l_head = '&mdash;';
917        }else{
918            $l_info   = getRevisionInfo($ID,$l_rev,true);
919            if($l_info['user']){
920                $l_user = editorinfo($l_info['user']);
921                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
922            } else {
923                $l_user = $l_info['ip'];
924            }
925            $l_user  = '<span class="user">'.$l_user.'</span>';
926            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
927            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
928
929            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
930            $ID.' ['.dformat($l_rev).']</a>'.
931            '<br />'.$l_user.' '.$l_sum;
932        }
933
934        if($r_rev){
935            $r_info   = getRevisionInfo($ID,$r_rev,true);
936            if($r_info['user']){
937                $r_user = editorinfo($r_info['user']);
938                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
939            } else {
940                $r_user = $r_info['ip'];
941            }
942            $r_user = '<span class="user">'.$r_user.'</span>';
943            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
944            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
945
946            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
947            $ID.' ['.dformat($r_rev).']</a>'.
948            '<br />'.$r_user.' '.$r_sum;
949        }elseif($_rev = @filemtime(wikiFN($ID))){
950            $_info   = getRevisionInfo($ID,$_rev,true);
951            if($_info['user']){
952                $_user = editorinfo($_info['user']);
953                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
954            } else {
955                $_user = $_info['ip'];
956            }
957            $_user = '<span class="user">'.$_user.'</span>';
958            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
959            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
960
961            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
962            $ID.' ['.dformat($_rev).']</a> '.
963            '('.$lang['current'].')'.
964            '<br />'.$_user.' '.$_sum;
965        }else{
966            $r_head = '&mdash; ('.$lang['current'].')';
967        }
968    }
969
970    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
971        explode("\n",htmlspecialchars($r_text)));
972
973    $tdf = new TableDiffFormatter();
974    if($intro) print p_locale_xhtml('diff');
975    ?>
976    <table class="diff">
977    <tr>
978    <th colspan="2" <?php echo $l_minor?>>
979    <?php echo $l_head?>
980    </th>
981    <th colspan="2" <?php echo $r_minor?>>
982    <?php echo $r_head?>
983    </th>
984    </tr>
985    <?php echo $tdf->format($df)?>
986    </table>
987    <?php
988}
989
990/**
991 * show warning on conflict detection
992 *
993 * @author Andreas Gohr <andi@splitbrain.org>
994 */
995function html_conflict($text,$summary){
996    global $ID;
997    global $lang;
998
999    print p_locale_xhtml('conflict');
1000    $form = new Doku_Form(array('id' => 'dw__editform'));
1001    $form->addHidden('id', $ID);
1002    $form->addHidden('wikitext', $text);
1003    $form->addHidden('summary', $summary);
1004    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1005    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1006    html_form('conflict', $form);
1007    print '<br /><br /><br /><br />'.NL;
1008}
1009
1010/**
1011 * Prints the global message array
1012 *
1013 * @author Andreas Gohr <andi@splitbrain.org>
1014 */
1015function html_msgarea(){
1016    global $MSG;
1017    if(!isset($MSG)) return;
1018
1019    $shown = array();
1020    foreach($MSG as $msg){
1021        $hash = md5($msg['msg']);
1022        if(isset($shown[$hash])) continue; // skip double messages
1023        print '<div class="'.$msg['lvl'].'">';
1024        print $msg['msg'];
1025        print '</div>';
1026        $shown[$hash] = 1;
1027    }
1028}
1029
1030/**
1031 * Prints the registration form
1032 *
1033 * @author Andreas Gohr <andi@splitbrain.org>
1034 */
1035function html_register(){
1036    global $lang;
1037    global $conf;
1038    global $ID;
1039
1040    print p_locale_xhtml('register');
1041    print '<div class="centeralign">'.NL;
1042    $form = new Doku_Form(array('id' => 'dw__register'));
1043    $form->startFieldset($lang['register']);
1044    $form->addHidden('do', 'register');
1045    $form->addHidden('save', '1');
1046    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1047    if (!$conf['autopasswd']) {
1048        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1049        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1050    }
1051    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1052    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1053    $form->addElement(form_makeButton('submit', '', $lang['register']));
1054    $form->endFieldset();
1055    html_form('register', $form);
1056
1057    print '</div>'.NL;
1058}
1059
1060/**
1061 * Print the update profile form
1062 *
1063 * @author Christopher Smith <chris@jalakai.co.uk>
1064 * @author Andreas Gohr <andi@splitbrain.org>
1065 */
1066function html_updateprofile(){
1067    global $lang;
1068    global $conf;
1069    global $ID;
1070    global $INFO;
1071    global $auth;
1072
1073    print p_locale_xhtml('updateprofile');
1074
1075    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1076    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1077    print '<div class="centeralign">'.NL;
1078    $form = new Doku_Form(array('id' => 'dw__register'));
1079    $form->startFieldset($lang['profile']);
1080    $form->addHidden('do', 'profile');
1081    $form->addHidden('save', '1');
1082    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1083    $attr = array('size'=>'50');
1084    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1085    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1086    $attr = array('size'=>'50');
1087    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1088    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1089    $form->addElement(form_makeTag('br'));
1090    if ($auth->canDo('modPass')) {
1091        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1092        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1093    }
1094    if ($conf['profileconfirm']) {
1095        $form->addElement(form_makeTag('br'));
1096        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1097    }
1098    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1099    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1100    $form->endFieldset();
1101    html_form('updateprofile', $form);
1102    print '</div>'.NL;
1103}
1104
1105/**
1106 * This displays the edit form (lots of logic included)
1107 *
1108 * @fixme    this is a huge lump of code and should be modularized
1109 * @triggers HTML_PAGE_FROMTEMPLATE
1110 * @triggers HTML_EDITFORM_INJECTION
1111 * @author   Andreas Gohr <andi@splitbrain.org>
1112 */
1113function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1114    global $ID;
1115    global $REV;
1116    global $DATE;
1117    global $RANGE;
1118    global $PRE;
1119    global $SUF;
1120    global $INFO;
1121    global $SUM;
1122    global $lang;
1123    global $conf;
1124    global $license;
1125
1126    //set summary default
1127    if(!$SUM){
1128        if($REV){
1129            $SUM = $lang['restored'];
1130        }elseif(!$INFO['exists']){
1131            $SUM = $lang['created'];
1132        }
1133    }
1134
1135    //no text? Load it!
1136    if(!isset($text)){
1137        $pr = false; //no preview mode
1138        if($INFO['exists']){
1139            if($RANGE){
1140                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1141            }else{
1142                $text = rawWiki($ID,$REV);
1143            }
1144            $check = md5($text);
1145            $mod = false;
1146        }else{
1147            //try to load a pagetemplate
1148            $data = array($ID);
1149            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1150            $check = md5('');
1151            $mod = $text!=='';
1152        }
1153    }else{
1154        $pr = true; //preview mode
1155        if (isset($_REQUEST['changecheck'])) {
1156            $check = $_REQUEST['changecheck'];
1157            $mod = md5($text)!==$check;
1158        } else {
1159            // Why? Assume default text is unmodified.
1160            $check = md5($text);
1161            $mod = false;
1162        }
1163    }
1164
1165    $wr = $INFO['writable'] && !$INFO['locked'];
1166    if($wr){
1167        if ($REV) print p_locale_xhtml('editrev');
1168        print p_locale_xhtml($include);
1169    }else{
1170        // check pseudo action 'source'
1171        if(!actionOK('source')){
1172            msg('Command disabled: source',-1);
1173            return;
1174        }
1175        print p_locale_xhtml('read');
1176    }
1177    if(!$DATE) $DATE = $INFO['lastmod'];
1178    ?>
1179        <div style="width:99%;">
1180
1181        <div class="toolbar">
1182        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1183        <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1184            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1185
1186            <?php if($wr){?>
1187                <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1188                    <?php /* sets changed to true when previewed */?>
1189                    textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1190                //--><!]]></script>
1191                <span id="spell__action"></span>
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($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 Andrea 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