xref: /dokuwiki/inc/html.php (revision 2709b4569c04bc8a1cb7933e1a5d726a7afc5be0)
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('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('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('page__revisions', wl($ID));
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('dw__recent', script(), '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
916    if(!$l_rev){
917      $l_head = '&mdash;';
918    }else{
919      $l_info   = getRevisionInfo($ID,$l_rev,true);
920      if($l_info['user']){ $l_user = editorinfo($l_info['user']);
921        if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
922      } else { $l_user = $l_info['ip']; }
923      $l_user  = '<span class="user">'.$l_user.'</span>';
924      $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
925      if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
926
927      $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
928                $ID.' ['.dformat($l_rev).']</a>'.
929                '<br />'.$l_user.' '.$l_sum;
930    }
931
932    if($r_rev){
933      $r_info   = getRevisionInfo($ID,$r_rev,true);
934      if($r_info['user']){ $r_user = editorinfo($r_info['user']);
935        if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
936      } else { $r_user = $r_info['ip']; }
937      $r_user = '<span class="user">'.$r_user.'</span>';
938      $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
939      if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
940
941      $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
942                $ID.' ['.dformat($r_rev).']</a>'.
943                '<br />'.$r_user.' '.$r_sum;
944    }elseif($_rev = @filemtime(wikiFN($ID))){
945      $_info   = getRevisionInfo($ID,$_rev,true);
946      if($_info['user']){ $_user = editorinfo($_info['user']);
947        if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
948      } else { $_user = $_info['ip']; }
949      $_user = '<span class="user">'.$_user.'</span>';
950      $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
951      if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
952
953      $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
954               $ID.' ['.dformat($_rev).']</a> '.
955               '('.$lang['current'].')'.
956                '<br />'.$_user.' '.$_sum;
957    }else{
958      $r_head = '&mdash; ('.$lang['current'].')';
959    }
960  }
961
962  $df = new Diff(explode("\n",htmlspecialchars($l_text)),
963                 explode("\n",htmlspecialchars($r_text)));
964
965  $tdf = new TableDiffFormatter();
966  if($intro) print p_locale_xhtml('diff');
967  ?>
968    <table class="diff">
969      <tr>
970        <th colspan="2" <?php echo $l_minor?>>
971          <?php echo $l_head?>
972        </th>
973        <th colspan="2" <?php echo $r_minor?>>
974          <?php echo $r_head?>
975        </th>
976      </tr>
977      <?php echo $tdf->format($df)?>
978    </table>
979  <?php
980}
981
982/**
983 * show warning on conflict detection
984 *
985 * @author Andreas Gohr <andi@splitbrain.org>
986 */
987function html_conflict($text,$summary){
988  global $ID;
989  global $lang;
990
991  print p_locale_xhtml('conflict');
992  $form = new Doku_Form('dw__editform');
993  $form->addHidden('id', $ID);
994  $form->addHidden('wikitext', $text);
995  $form->addHidden('summary', $summary);
996  $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
997  $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
998  html_form('conflict', $form);
999  print '<br /><br /><br /><br />'.NL;
1000}
1001
1002/**
1003 * Prints the global message array
1004 *
1005 * @author Andreas Gohr <andi@splitbrain.org>
1006 */
1007function html_msgarea(){
1008    global $MSG;
1009    if(!isset($MSG)) return;
1010
1011    $shown = array();
1012    foreach($MSG as $msg){
1013        $hash = md5($msg['msg']);
1014        if(isset($shown[$hash])) continue; // skip double messages
1015        print '<div class="'.$msg['lvl'].'">';
1016        print $msg['msg'];
1017        print '</div>';
1018        $shown[$hash] = 1;
1019    }
1020}
1021
1022/**
1023 * Prints the registration form
1024 *
1025 * @author Andreas Gohr <andi@splitbrain.org>
1026 */
1027function html_register(){
1028  global $lang;
1029  global $conf;
1030  global $ID;
1031
1032  print p_locale_xhtml('register');
1033  print '<div class="centeralign">'.NL;
1034  $form = new Doku_Form('dw__register', wl($ID));
1035  $form->startFieldset($lang['register']);
1036  $form->addHidden('do', 'register');
1037  $form->addHidden('save', '1');
1038  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1039  if (!$conf['autopasswd']) {
1040    $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1041    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1042  }
1043  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1044  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1045  $form->addElement(form_makeButton('submit', '', $lang['register']));
1046  $form->endFieldset();
1047  html_form('register', $form);
1048
1049  print '</div>'.NL;
1050}
1051
1052/**
1053 * Print the update profile form
1054 *
1055 * @author Christopher Smith <chris@jalakai.co.uk>
1056 * @author Andreas Gohr <andi@splitbrain.org>
1057 */
1058function html_updateprofile(){
1059  global $lang;
1060  global $conf;
1061  global $ID;
1062  global $INFO;
1063  global $auth;
1064
1065  print p_locale_xhtml('updateprofile');
1066
1067  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1068  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1069  print '<div class="centeralign">'.NL;
1070  $form = new Doku_Form('dw__register', wl($ID));
1071  $form->startFieldset($lang['profile']);
1072  $form->addHidden('do', 'profile');
1073  $form->addHidden('save', '1');
1074  $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1075  $attr = array('size'=>'50');
1076  if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1077  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1078  $attr = array('size'=>'50');
1079  if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1080  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1081  $form->addElement(form_makeTag('br'));
1082  if ($auth->canDo('modPass')) {
1083    $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1084    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1085  }
1086  if ($conf['profileconfirm']) {
1087    $form->addElement(form_makeTag('br'));
1088    $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1089  }
1090  $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1091  $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1092  $form->endFieldset();
1093  html_form('updateprofile', $form);
1094  print '</div>'.NL;
1095}
1096
1097/**
1098 * This displays the edit form (lots of logic included)
1099 *
1100 * @fixme    this is a huge lump of code and should be modularized
1101 * @triggers HTML_PAGE_FROMTEMPLATE
1102 * @triggers HTML_EDITFORM_INJECTION
1103 * @author   Andreas Gohr <andi@splitbrain.org>
1104 */
1105function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1106  global $ID;
1107  global $REV;
1108  global $DATE;
1109  global $RANGE;
1110  global $PRE;
1111  global $SUF;
1112  global $INFO;
1113  global $SUM;
1114  global $lang;
1115  global $conf;
1116  global $license;
1117
1118  //set summary default
1119  if(!$SUM){
1120    if($REV){
1121      $SUM = $lang['restored'];
1122    }elseif(!$INFO['exists']){
1123      $SUM = $lang['created'];
1124    }
1125  }
1126
1127  //no text? Load it!
1128  if(!isset($text)){
1129    $pr = false; //no preview mode
1130    if($INFO['exists']){
1131      if($RANGE){
1132        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1133      }else{
1134        $text = rawWiki($ID,$REV);
1135      }
1136      $check = md5($text);
1137      $mod = false;
1138    }else{
1139      //try to load a pagetemplate
1140      $data = array($ID);
1141      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1142      $check = md5('');
1143      $mod = $text!=='';
1144    }
1145  }else{
1146    $pr = true; //preview mode
1147    if (isset($_REQUEST['changecheck'])) {
1148      $check = $_REQUEST['changecheck'];
1149      $mod = md5($text)!==$check;
1150    } else {
1151      // Why? Assume default text is unmodified.
1152      $check = md5($text);
1153      $mod = false;
1154    }
1155  }
1156
1157  $wr = $INFO['writable'] && !$INFO['locked'];
1158  if($wr){
1159    if ($REV) print p_locale_xhtml('editrev');
1160    print p_locale_xhtml($include);
1161  }else{
1162    // check pseudo action 'source'
1163    if(!actionOK('source')){
1164      msg('Command disabled: source',-1);
1165      return;
1166    }
1167    print p_locale_xhtml('read');
1168  }
1169  if(!$DATE) $DATE = $INFO['lastmod'];
1170
1171
1172?>
1173  <div style="width:99%;">
1174
1175   <div class="toolbar">
1176      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1177      <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1178      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1179
1180      <?php if($wr){?>
1181      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1182        <?php /* sets changed to true when previewed */?>
1183        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1184      //--><!]]></script>
1185      <span id="spell__action"></span>
1186      <div id="spell__suggest"></div>
1187      <?php } ?>
1188   </div>
1189   <div id="spell__result"></div>
1190<?php
1191  $form = new Doku_Form('dw__editform');
1192  $form->addHidden('id', $ID);
1193  $form->addHidden('rev', $REV);
1194  $form->addHidden('date', $DATE);
1195  $form->addHidden('prefix', $PRE);
1196  $form->addHidden('suffix', $SUF);
1197  $form->addHidden('changecheck', $check);
1198  $attr = array('tabindex'=>'1');
1199  if (!$wr) $attr['readonly'] = 'readonly';
1200  $form->addElement(form_makeWikiText($text, $attr));
1201  $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1202  $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1203  $form->addElement(form_makeCloseTag('div'));
1204  if ($wr) {
1205    $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1206    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1207    $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1208    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1209    $form->addElement(form_makeCloseTag('div'));
1210    $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1211    $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1212    $elem = html_minoredit();
1213    if ($elem) $form->addElement($elem);
1214    $form->addElement(form_makeCloseTag('div'));
1215  }
1216  $form->addElement(form_makeCloseTag('div'));
1217  if($conf['license']){
1218    $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1219    $out  = $lang['licenseok'];
1220    $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1221    if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
1222    $out .= '> '.$license[$conf['license']]['name'].'</a>';
1223    $form->addElement($out);
1224    $form->addElement(form_makeCloseTag('div'));
1225  }
1226  html_form('edit', $form);
1227  print '</div>'.NL;
1228}
1229
1230/**
1231 * Adds a checkbox for minor edits for logged in users
1232 *
1233 * @author Andrea Gohr <andi@splitbrain.org>
1234 */
1235function html_minoredit(){
1236  global $conf;
1237  global $lang;
1238  // minor edits are for logged in users only
1239  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1240    return false;
1241  }
1242
1243  $p = array();
1244  $p['tabindex'] = 3;
1245  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1246  return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1247}
1248
1249/**
1250 * prints some debug info
1251 *
1252 * @author Andreas Gohr <andi@splitbrain.org>
1253 */
1254function html_debug(){
1255  global $conf;
1256  global $lang;
1257  global $auth;
1258  global $INFO;
1259
1260  //remove sensitive data
1261  $cnf = $conf;
1262  debug_guard($cnf);
1263  $nfo = $INFO;
1264  debug_guard($nfo);
1265  $ses = $_SESSION;
1266  debug_guard($ses);
1267
1268  print '<html><body>';
1269
1270  print '<p>When reporting bugs please send all the following ';
1271  print 'output as a mail to andi@splitbrain.org ';
1272  print 'The best way to do this is to save this page in your browser</p>';
1273
1274  print '<b>$INFO:</b><pre>';
1275  print_r($nfo);
1276  print '</pre>';
1277
1278  print '<b>$_SERVER:</b><pre>';
1279  print_r($_SERVER);
1280  print '</pre>';
1281
1282  print '<b>$conf:</b><pre>';
1283  print_r($cnf);
1284  print '</pre>';
1285
1286  print '<b>DOKU_BASE:</b><pre>';
1287  print DOKU_BASE;
1288  print '</pre>';
1289
1290  print '<b>abs DOKU_BASE:</b><pre>';
1291  print DOKU_URL;
1292  print '</pre>';
1293
1294  print '<b>rel DOKU_BASE:</b><pre>';
1295  print dirname($_SERVER['PHP_SELF']).'/';
1296  print '</pre>';
1297
1298  print '<b>PHP Version:</b><pre>';
1299  print phpversion();
1300  print '</pre>';
1301
1302  print '<b>locale:</b><pre>';
1303  print setlocale(LC_ALL,0);
1304  print '</pre>';
1305
1306  print '<b>encoding:</b><pre>';
1307  print $lang['encoding'];
1308  print '</pre>';
1309
1310  if($auth){
1311    print '<b>Auth backend capabilities:</b><pre>';
1312    print_r($auth->cando);
1313    print '</pre>';
1314  }
1315
1316  print '<b>$_SESSION:</b><pre>';
1317  print_r($ses);
1318  print '</pre>';
1319
1320  print '<b>Environment:</b><pre>';
1321  print_r($_ENV);
1322  print '</pre>';
1323
1324  print '<b>PHP settings:</b><pre>';
1325  $inis = ini_get_all();
1326  print_r($inis);
1327  print '</pre>';
1328
1329  print '</body></html>';
1330}
1331
1332/**
1333 * List available Administration Tasks
1334 *
1335 * @author Andreas Gohr <andi@splitbrain.org>
1336 * @author Håkan Sandell <hakan.sandell@home.se>
1337 */
1338function html_admin(){
1339    global $ID;
1340    global $INFO;
1341    global $lang;
1342    global $conf;
1343    global $auth;
1344
1345    // build menu of admin functions from the plugins that handle them
1346    $pluginlist = plugin_list('admin');
1347    $menu = array();
1348    foreach ($pluginlist as $p) {
1349        if($obj =& plugin_load('admin',$p) === NULL) continue;
1350
1351        // check permissions
1352        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1353
1354        $menu[$p] = array('plugin' => $p,
1355                          'prompt' => $obj->getMenuText($conf['lang']),
1356                          'sort' => $obj->getMenuSort()
1357                         );
1358    }
1359
1360    print p_locale_xhtml('admin');
1361
1362    // Admin Tasks
1363    if($INFO['isadmin']){
1364        ptln('<ul class="admin_tasks">');
1365
1366        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1367            ptln('  <li class="admin_usermanager"><div class="li">'.
1368                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1369                    $menu['usermanager']['prompt'].'</a></div></li>');
1370        }
1371        unset($menu['usermanager']);
1372
1373        if($menu['acl']){
1374            ptln('  <li class="admin_acl"><div class="li">'.
1375                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1376                    $menu['acl']['prompt'].'</a></div></li>');
1377        }
1378        unset($menu['acl']);
1379
1380        if($menu['plugin']){
1381            ptln('  <li class="admin_plugin"><div class="li">'.
1382                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
1383                    $menu['plugin']['prompt'].'</a></div></li>');
1384        }
1385        unset($menu['plugin']);
1386
1387        if($menu['config']){
1388            ptln('  <li class="admin_config"><div class="li">'.
1389                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1390                    $menu['config']['prompt'].'</a></div></li>');
1391        }
1392        unset($menu['config']);
1393    }
1394    ptln('</ul>');
1395
1396    // Manager Tasks
1397    ptln('<ul class="admin_tasks">');
1398
1399    if($menu['revert']){
1400        ptln('  <li class="admin_revert"><div class="li">'.
1401                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1402                $menu['revert']['prompt'].'</a></div></li>');
1403    }
1404    unset($menu['revert']);
1405
1406    if($menu['popularity']){
1407        ptln('  <li class="admin_popularity"><div class="li">'.
1408                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1409                $menu['popularity']['prompt'].'</a></div></li>');
1410    }
1411    unset($menu['popularity']);
1412
1413    ptln('</ul>');
1414
1415
1416    // print the rest as sorted list
1417    if(count($menu)){
1418        usort($menu, 'p_sort_modes');
1419        // output the menu
1420        ptln('<div class="clearer"></div>');
1421        print p_locale_xhtml('adminplugins');
1422        ptln('<ul>');
1423        foreach ($menu as $item) {
1424            if (!$item['prompt']) continue;
1425            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1426        }
1427        ptln('</ul>');
1428    }
1429}
1430
1431/**
1432 * Form to request a new password for an existing account
1433 *
1434 * @author Benoit Chesneau <benoit@bchesneau.info>
1435 */
1436function html_resendpwd() {
1437  global $lang;
1438  global $conf;
1439  global $ID;
1440
1441  print p_locale_xhtml('resendpwd');
1442  print '<div class="centeralign">'.NL;
1443  $form = new Doku_Form('dw__resendpwd', wl($ID));
1444  $form->startFieldset($lang['resendpwd']);
1445  $form->addHidden('do', 'resendpwd');
1446  $form->addHidden('save', '1');
1447  $form->addElement(form_makeTag('br'));
1448  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1449  $form->addElement(form_makeTag('br'));
1450  $form->addElement(form_makeTag('br'));
1451  $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1452  $form->endFieldset();
1453  html_form('resendpwd', $form);
1454  print '</div>'.NL;
1455}
1456
1457/**
1458 * Return the TOC rendered to XHTML
1459 *
1460 * @author Andreas Gohr <andi@splitbrain.org>
1461 */
1462function html_TOC($toc){
1463    if(!count($toc)) return '';
1464    global $lang;
1465    $out  = '<!-- TOC START -->'.DOKU_LF;
1466    $out .= '<div class="toc">'.DOKU_LF;
1467    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1468    $out .= $lang['toc'];
1469    $out .= '</div>'.DOKU_LF;
1470    $out .= '<div id="toc__inside">'.DOKU_LF;
1471    $out .= html_buildlist($toc,'toc','html_list_toc');
1472    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1473    $out .= '<!-- TOC END -->'.DOKU_LF;
1474    return $out;                                                                                                }
1475
1476/**
1477 * Callback for html_buildlist
1478 */
1479function html_list_toc($item){
1480    if($item['hid']){
1481        $link = '#'.$item['hid'];
1482    }else{
1483        $link = $item['link'];
1484    }
1485
1486    return '<span class="li"><a href="'.$link.'" class="toc">'.
1487           hsc($item['title']).'</a></span>';
1488}
1489
1490/**
1491 * Helper function to build TOC items
1492 *
1493 * Returns an array ready to be added to a TOC array
1494 *
1495 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1496 * @param string $text  - what to display in the TOC
1497 * @param int    $level - nesting level
1498 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1499 */
1500function html_mktocitem($link, $text, $level, $hash='#'){
1501    global $conf;
1502    return  array( 'link'  => $hash.$link,
1503                   'title' => $text,
1504                   'type'  => 'ul',
1505                   'level' => $level);
1506}
1507
1508/**
1509 * Output a Doku_Form object.
1510 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1511 *
1512 * @author Tom N Harris <tnharris@whoopdedo.org>
1513 */
1514function html_form($name, &$form) {
1515  // Safety check in case the caller forgets.
1516  $form->endFieldset();
1517  trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1518}
1519
1520/**
1521 * Form print function.
1522 * Just calls printForm() on the data object.
1523 */
1524function html_form_output($data) {
1525  $data->printForm();
1526}
1527
1528/**
1529 * Embed a flash object in HTML
1530 *
1531 * This will create the needed HTML to embed a flash movie in a cross browser
1532 * compatble way using valid XHTML
1533 *
1534 * The parameters $params, $flashvars and $atts need to be associative arrays.
1535 * No escaping needs to be done for them. The alternative content *has* to be
1536 * escaped because it is used as is. If no alternative content is given
1537 * $lang['noflash'] is used.
1538 *
1539 * @author Andreas Gohr <andi@splitbrain.org>
1540 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1541 *
1542 * @param string $swf      - the SWF movie to embed
1543 * @param int $width       - width of the flash movie in pixels
1544 * @param int $height      - height of the flash movie in pixels
1545 * @param array $params    - additional parameters (<param>)
1546 * @param array $flashvars - parameters to be passed in the flashvar parameter
1547 * @param array $atts      - additional attributes for the <object> tag
1548 * @param string $alt      - alternative content (is NOT automatically escaped!)
1549 * @returns string         - the XHTML markup
1550 */
1551function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1552    global $lang;
1553
1554    $out = '';
1555
1556    // prepare the object attributes
1557    if(is_null($atts)) $atts = array();
1558    $atts['width']  = (int) $width;
1559    $atts['height'] = (int) $height;
1560    if(!$atts['width'])  $atts['width']  = 425;
1561    if(!$atts['height']) $atts['height'] = 350;
1562
1563    // add object attributes for standard compliant browsers
1564    $std = $atts;
1565    $std['type'] = 'application/x-shockwave-flash';
1566    $std['data'] = $swf;
1567
1568    // add object attributes for IE
1569    $ie  = $atts;
1570    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1571
1572    // open object (with conditional comments)
1573    $out .= '<!--[if !IE]> -->'.NL;
1574    $out .= '<object '.buildAttributes($std).'>'.NL;
1575    $out .= '<!-- <![endif]-->'.NL;
1576    $out .= '<!--[if IE]>'.NL;
1577    $out .= '<object '.buildAttributes($ie).'>'.NL;
1578    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1579    $out .= '<!--><!-- -->'.NL;
1580
1581    // print params
1582    if(is_array($params)) foreach($params as $key => $val){
1583        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1584    }
1585
1586    // add flashvars
1587    if(is_array($flashvars)){
1588        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1589    }
1590
1591    // alternative content
1592    if($alt){
1593        $out .= $alt.NL;
1594    }else{
1595        $out .= $lang['noflash'].NL;
1596    }
1597
1598    // finish
1599    $out .= '</object>'.NL;
1600    $out .= '<!-- <![endif]-->'.NL;
1601
1602    return $out;
1603}
1604
1605//Setup VIM: ex: et ts=2 enc=utf-8 :
1606