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