xref: /dokuwiki/inc/html.php (revision 8b829d43781cf602c3152baa57853dc31da3f395)
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')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10if(!defined('NL')) define('NL',"\n");
11require_once(DOKU_INC.'inc/parserutils.php');
12
13/**
14 * Convenience function to quickly build a wikilink
15 *
16 * @author Andreas Gohr <andi@splitbrain.org>
17 */
18function html_wikilink($id,$name=NULL,$search=''){
19  static $xhtml_renderer = NULL;
20  if(is_null($xhtml_renderer)){
21    require_once(DOKU_INC.'inc/parser/xhtml.php');
22    $xhtml_renderer = new Doku_Renderer_xhtml();
23  }
24
25  return $xhtml_renderer->internallink($id,$name,$search,true);
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 * @triggers HTML_LOGINFORM_INJECTION
46 */
47function html_login(){
48  global $lang;
49  global $conf;
50  global $ID;
51  global $auth;
52
53  print p_locale_xhtml('login');
54  ?>
55    <div class="centeralign">
56    <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"
57          method="post" id="dw__login">
58      <fieldset>
59        <legend><?php echo $lang['btn_login']?></legend>
60        <input type="hidden" name="id" value="<?php echo $ID?>" />
61        <input type="hidden" name="do" value="login" />
62        <label class="block">
63          <span><?php echo $lang['user']?></span>
64          <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>"
65                 class="edit" id="focus__this" />
66        </label><br />
67        <label class="block">
68          <span><?php echo $lang['pass']?></span>
69          <input type="password" name="p" class="edit" />
70        </label><br />
71
72        <?php //bad and dirty event insert hook
73        $evdata = array();
74        trigger_event('HTML_LOGINFORM_INJECTION', $evdata);
75        ?>
76
77        <label for="remember__me" class="simple">
78          <input type="checkbox" name="r" id="remember__me" value="1" />
79          <span><?php echo $lang['remember']?></span>
80        </label>
81        <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
82      </fieldset>
83    </form>
84  <?php
85    if($auth && $auth->canDo('addUser') && actionOK('register')){
86      print '<p>';
87      print $lang['reghere'];
88      print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
89      print '</p>';
90    }
91
92    if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
93      print '<p>';
94      print $lang['pwdforget'];
95      print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
96      print '</p>';
97    }
98  ?>
99    </div>
100  <?php
101/*
102 FIXME provide new hook
103  if(@file_exists('includes/login.txt')){
104    print io_cacheParse('includes/login.txt');
105  }
106*/
107}
108
109/**
110 * prints a section editing button
111 * used as a callback in html_secedit
112 *
113 * @author Andreas Gohr <andi@splitbrain.org>
114 */
115function html_secedit_button($matches){
116  global $ID;
117  global $INFO;
118
119  $section = $matches[2];
120  $name = $matches[1];
121
122  $secedit  = '';
123  $secedit .= '<div class="secedit">';
124  $secedit .= html_btn('secedit',$ID,'',
125                        array('do'      => 'edit',
126                              'lines'   => "$section",
127                              'rev' => $INFO['lastmod']),
128                              'post', $name);
129  $secedit .= '</div>';
130  return $secedit;
131}
132
133/**
134 * inserts section edit buttons if wanted or removes the markers
135 *
136 * @author Andreas Gohr <andi@splitbrain.org>
137 */
138function html_secedit($text,$show=true){
139  global $INFO;
140
141  if($INFO['writable'] && $show && !$INFO['rev']){
142    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
143                         'html_secedit_button', $text);
144  }else{
145    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
146  }
147
148  return $text;
149}
150
151/**
152 * Just the back to top button (in its own form)
153 *
154 * @author Andreas Gohr <andi@splitbrain.org>
155 */
156function html_topbtn(){
157  global $lang;
158
159  $ret  = '';
160  $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>';
161
162  return $ret;
163}
164
165/**
166 * Displays a button (using its own form)
167 * If tooltip exists, the access key tooltip is replaced.
168 *
169 * @author Andreas Gohr <andi@splitbrain.org>
170 */
171function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
172  global $conf;
173  global $lang;
174
175  $label = $lang['btn_'.$name];
176
177  $ret = '';
178  $tip = '';
179
180  //filter id (without urlencoding)
181  $id = idfilter($id,false);
182
183  //make nice URLs even for buttons
184  if($conf['userewrite'] == 2){
185    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
186  }elseif($conf['userewrite']){
187    $script = DOKU_BASE.$id;
188  }else{
189    $script = DOKU_BASE.DOKU_SCRIPT;
190    $params['id'] = $id;
191  }
192
193  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">';
194
195  if(is_array($params)){
196    reset($params);
197    while (list($key, $val) = each($params)) {
198      $ret .= '<input type="hidden" name="'.$key.'" ';
199      $ret .= 'value="'.htmlspecialchars($val).'" />';
200    }
201  }
202
203  if ($tooltip!='') {
204      $tip = htmlspecialchars($tooltip);
205  }else{
206      $tip = htmlspecialchars($label);
207  }
208
209  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
210  if($akey){
211    $tip .= ' [ALT+'.strtoupper($akey).']';
212    $ret .= 'accesskey="'.$akey.'" ';
213  }
214  $ret .= 'title="'.$tip.'" ';
215  $ret .= '/>';
216  $ret .= '</div></form>';
217
218  return $ret;
219}
220
221/**
222 * show a wiki page
223 *
224 * @author Andreas Gohr <andi@splitbrain.org>
225 */
226function html_show($txt=''){
227  global $ID;
228  global $REV;
229  global $HIGH;
230  //disable section editing for old revisions or in preview
231  if($txt || $REV){
232    $secedit = false;
233  }else{
234    $secedit = true;
235  }
236
237  if ($txt){
238    //PreviewHeader
239    print '<br id="scroll__here" />';
240    print p_locale_xhtml('preview');
241    print '<div class="preview">';
242    print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
243    print '<div class="clearer"></div>';
244    print '</div>';
245
246  }else{
247    if ($REV) print p_locale_xhtml('showrev');
248    $html = p_wiki_xhtml($ID,$REV,true);
249    $html = html_secedit($html,$secedit);
250    print html_hilight($html,$HIGH);
251  }
252}
253
254/**
255 * ask the user about how to handle an exisiting draft
256 *
257 * @author Andreas Gohr <andi@splitbrain.org>
258 */
259function html_draft(){
260  global $INFO;
261  global $ID;
262  global $lang;
263  global $conf;
264  $draft = unserialize(io_readFile($INFO['draft'],false));
265  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
266
267  echo p_locale_xhtml('draft');
268  ?>
269  <form id="dw__editform" method="post" action="<?php echo script()?>"
270   accept-charset="<?php echo $lang['encoding']?>"><div class="no">
271    <input type="hidden" name="id"   value="<?php echo $ID?>" />
272    <input type="hidden" name="date" value="<?php echo $draft['date']?>" /></div>
273    <textarea name="wikitext" id="wiki__text" readonly="readonly" cols="80" rows="10" class="edit"><?php echo "\n".formText($text)?></textarea>
274
275    <div id="draft__status"><?php echo $lang['draftdate'].' '.date($conf['dformat'],filemtime($INFO['draft']))?></div>
276
277    <input class="button" type="submit" name="do[recover]" value="<?php echo $lang['btn_recover']?>" tabindex="1" />
278    <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_draftdel']?>" tabindex="2" />
279    <input class="button" type="submit" name="do[show]" value="<?php echo $lang['btn_cancel']?>" tabindex="3" />
280  </form>
281  <?php
282}
283
284/**
285 * Highlights searchqueries in HTML code
286 *
287 * @author Andreas Gohr <andi@splitbrain.org>
288 * @author Harry Fuecks <hfuecks@gmail.com>
289 */
290function html_hilight($html,$query){
291  //split at common delimiters
292  $queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY);
293  foreach ($queries as $q){
294     $q = preg_quote($q,'/');
295     $html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html);
296  }
297  return $html;
298}
299
300/**
301 * Callback used by html_hilight()
302 *
303 * @author Harry Fuecks <hfuecks@gmail.com>
304 */
305function html_hilight_callback($m) {
306  $hlight = unslash($m[0]);
307  if ( !isset($m[2])) {
308    $hlight = '<span class="search_hit">'.$hlight.'</span>';
309  }
310  return $hlight;
311}
312
313/**
314 * Run a search and display the result
315 *
316 * @author Andreas Gohr <andi@splitbrain.org>
317 */
318function html_search(){
319  require_once(DOKU_INC.'inc/search.php');
320  require_once(DOKU_INC.'inc/fulltext.php');
321  global $conf;
322  global $QUERY;
323  global $ID;
324  global $lang;
325
326  print p_locale_xhtml('searchpage');
327  flush();
328
329  //check if search is restricted to namespace
330  if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) {
331      $id = cleanID($match[1]);
332      if(empty($id)) {
333        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
334        flush();
335        return;
336      }
337  } else {
338      $id = cleanID($QUERY);
339  }
340
341  //show progressbar
342  print '<div class="centeralign" id="dw__loading">'.NL;
343  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
344  print 'showLoadBar();'.NL;
345  print '//--><!]]></script>'.NL;
346  print '<br /></div>'.NL;
347  flush();
348
349  //do quick pagesearch
350  $data = array();
351
352  $data = ft_pageLookup($id);
353  if(count($data)){
354    sort($data);
355    print '<div class="search_quickresult">';
356    print '<h3>'.$lang['quickhits'].':</h3>';
357    print '<ul class="search_quickhits">';
358    foreach($data as $id){
359      print '<li> ';
360      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id);
361      print '</li> ';
362    }
363    print '</ul> ';
364    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
365    print '<div class="clearer">&nbsp;</div>';
366    print '</div>';
367  }
368  flush();
369
370  //do fulltext search
371  $data = ft_pageSearch($QUERY,$poswords);
372  if(count($data)){
373    $num = 1;
374    foreach($data as $id => $cnt){
375      print '<div class="search_result">';
376      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
377      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
378      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
379        print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
380      }
381      print '</div>';
382      flush();
383      $num++;
384    }
385  }else{
386    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
387  }
388
389  //hide progressbar
390  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
391  print 'hideLoadBar("dw__loading");'.NL;
392  print '//--><!]]></script>'.NL;
393  flush();
394}
395
396/**
397 * Display error on locked pages
398 *
399 * @author Andreas Gohr <andi@splitbrain.org>
400 */
401function html_locked(){
402  global $ID;
403  global $conf;
404  global $lang;
405  global $INFO;
406
407  $locktime = filemtime(wikiLockFN($ID));
408  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
409  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
410
411  print p_locale_xhtml('locked');
412  print '<ul>';
413  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
414  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
415  print '</ul>';
416}
417
418/**
419 * list old revisions
420 *
421 * @author Andreas Gohr <andi@splitbrain.org>
422 * @author Ben Coburn <btcoburn@silicodon.net>
423 */
424function html_revisions($first=0){
425  global $ID;
426  global $INFO;
427  global $conf;
428  global $lang;
429  /* we need to get one additionally log entry to be able to
430   * decide if this is the last page or is there another one.
431   * see html_recent()
432   */
433  $revisions = getRevisions($ID, $first, $conf['recent']+1);
434  if(count($revisions)==0 && $first!=0){
435    $first=0;
436    $revisions = getRevisions($ID, $first, $conf['recent']+1);;
437  }
438  $hasNext = false;
439  if (count($revisions)>$conf['recent']) {
440    $hasNext = true;
441    array_pop($revisions); // remove extra log entry
442  }
443
444  $date = @date($conf['dformat'],$INFO['lastmod']);
445
446  print p_locale_xhtml('revisions');
447  print '<form action="'.wl($ID).'" method="post" id="page__revisions">';
448  print '<ul>';
449  if($INFO['exists'] && $first==0){
450    print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
451    print '<div class="li">';
452    print '<input type="checkbox" name="rev2[]" value="current" /> ';
453
454    print $date;
455
456    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
457
458    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
459
460    print ' &ndash; ';
461    print $INFO['sum'];
462    print ' <span class="user">';
463    print (empty($INFO['editor']))?('('.$lang['external_edit'].')'):$INFO['editor'];
464    print '</span> ';
465
466    print '('.$lang['current'].')';
467    print '</div>';
468    print '</li>';
469  }
470
471  foreach($revisions as $rev){
472    $date   = date($conf['dformat'],$rev);
473    $info   = getRevisionInfo($ID,$rev,true);
474    $exists = @file_exists(wikiFN($ID,$rev));
475
476
477
478    print ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
479    print '<div class="li">';
480    if($exists){
481      print '<input type="checkbox" name="rev2[]" value="'.$rev.'" /> ';
482    }else{
483      print '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="14" height="11" alt="" /> ';
484    }
485    print $date;
486
487    if($exists){
488      print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
489      $p = array();
490      $p['src']    = DOKU_BASE.'lib/images/diff.png';
491      $p['width']  = 15;
492      $p['height'] = 11;
493      $p['title']  = $lang['diff'];
494      $p['alt']    = $lang['diff'];
495      $att = buildAttributes($p);
496      print "<img $att />";
497      print '</a> ';
498
499      print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>';
500    }else{
501      print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
502      print $ID;
503    }
504
505    print ' &ndash; ';
506    print htmlspecialchars($info['sum']);
507    print ' <span class="user">';
508    if($info['user']){
509      print $info['user'];
510    }else{
511      print $info['ip'];
512    }
513    print '</span>';
514
515    print '</div>';
516    print '</li>';
517  }
518  print '</ul>';
519  print '<input name="do[diff]" type="submit" value="'.$lang['diff2'].'" class="button" />';
520  print '</form>';
521
522  print '<div class="pagenav">';
523  $last = $first + $conf['recent'];
524  if ($first > 0) {
525    $first -= $conf['recent'];
526    if ($first < 0) $first = 0;
527    print '<div class="pagenav-prev">';
528    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
529    print '</div>';
530  }
531  if ($hasNext) {
532    print '<div class="pagenav-next">';
533    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
534    print '</div>';
535  }
536  print '</div>';
537
538}
539
540/**
541 * display recent changes
542 *
543 * @author Andreas Gohr <andi@splitbrain.org>
544 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
545 * @author Ben Coburn <btcoburn@silicodon.net>
546 */
547function html_recent($first=0){
548  global $conf;
549  global $lang;
550  global $ID;
551  /* we need to get one additionally log entry to be able to
552   * decide if this is the last page or is there another one.
553   * This is the cheapest solution to get this information.
554   */
555  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
556  if(count($recents) == 0 && $first != 0){
557    $first=0;
558    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
559  }
560  $hasNext = false;
561  if (count($recents)>$conf['recent']) {
562    $hasNext = true;
563    array_pop($recents); // remove extra log entry
564  }
565
566  print p_locale_xhtml('recent');
567  print '<ul>';
568
569  foreach($recents as $recent){
570    $date = date($conf['dformat'],$recent['date']);
571    print ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
572    print '<div class="li">';
573
574    print $date.' ';
575
576    print '<a href="'.wl($recent['id'],"do=diff").'">';
577    $p = array();
578    $p['src']    = DOKU_BASE.'lib/images/diff.png';
579    $p['width']  = 15;
580    $p['height'] = 11;
581    $p['title']  = $lang['diff'];
582    $p['alt']    = $lang['diff'];
583    $att = buildAttributes($p);
584    print "<img $att />";
585    print '</a> ';
586
587    print '<a href="'.wl($recent['id'],"do=revisions").'">';
588    $p = array();
589    $p['src']    = DOKU_BASE.'lib/images/history.png';
590    $p['width']  = 12;
591    $p['height'] = 14;
592    $p['title']  = $lang['btn_revs'];
593    $p['alt']    = $lang['btn_revs'];
594    $att = buildAttributes($p);
595    print "<img $att />";
596    print '</a> ';
597
598    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
599    print ' &ndash; '.htmlspecialchars($recent['sum']);
600
601    print ' <span class="user">';
602    if($recent['user']){
603      print $recent['user'];
604    }else{
605      print $recent['ip'];
606    }
607    print '</span>';
608
609    print '</div>';
610    print '</li>';
611  }
612  print '</ul>';
613
614  print '<div class="pagenav">';
615  $last = $first + $conf['recent'];
616  if ($first > 0) {
617    $first -= $conf['recent'];
618    if ($first < 0) $first = 0;
619    print '<div class="pagenav-prev">';
620    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
621    print '</div>';
622  }
623  if ($hasNext) {
624    print '<div class="pagenav-next">';
625    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
626    print '</div>';
627  }
628  print '</div>';
629}
630
631/**
632 * Display page index
633 *
634 * @author Andreas Gohr <andi@splitbrain.org>
635 */
636function html_index($ns){
637  require_once(DOKU_INC.'inc/search.php');
638  global $conf;
639  global $ID;
640  $dir = $conf['datadir'];
641  $ns  = cleanID($ns);
642  #fixme use appropriate function
643  if(empty($ns)){
644    $ns = dirname(str_replace(':','/',$ID));
645    if($ns == '.') $ns ='';
646  }
647  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
648
649  echo p_locale_xhtml('index');
650  echo '<div id="index__tree">';
651
652  $data = array();
653  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
654  echo html_buildlist($data,'idx','html_list_index','html_li_index');
655
656  echo '</div>';
657}
658
659/**
660 * Index item formatter
661 *
662 * User function for html_buildlist()
663 *
664 * @author Andreas Gohr <andi@splitbrain.org>
665 */
666function html_list_index($item){
667  global $ID;
668  $ret = '';
669  $base = ':'.$item['id'];
670  $base = substr($base,strrpos($base,':')+1);
671  if($item['type']=='d'){
672    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir"><strong>';
673    $ret .= $base;
674    $ret .= '</strong></a>';
675  }else{
676    $ret .= html_wikilink(':'.$item['id']);
677  }
678  return $ret;
679}
680
681/**
682 * Index List item
683 *
684 * This user function is used in html_build_lidt to build the
685 * <li> tags for namespaces when displaying the page index
686 * it gives different classes to opened or closed "folders"
687 *
688 * @author Andreas Gohr <andi@splitbrain.org>
689 */
690function html_li_index($item){
691  if($item['type'] == "f"){
692    return '<li class="level'.$item['level'].'">';
693  }elseif($item['open']){
694    return '<li class="open">';
695  }else{
696    return '<li class="closed">';
697  }
698}
699
700/**
701 * Default List item
702 *
703 * @author Andreas Gohr <andi@splitbrain.org>
704 */
705function html_li_default($item){
706  return '<li class="level'.$item['level'].'">';
707}
708
709/**
710 * Build an unordered list
711 *
712 * Build an unordered list from the given $data array
713 * Each item in the array has to have a 'level' property
714 * the item itself gets printed by the given $func user
715 * function. The second and optional function is used to
716 * print the <li> tag. Both user function need to accept
717 * a single item.
718 *
719 * Both user functions can be given as array to point to
720 * a member of an object.
721 *
722 * @author Andreas Gohr <andi@splitbrain.org>
723 */
724function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
725  $level = 0;
726  $opens = 0;
727  $ret   = '';
728
729  foreach ($data as $item){
730
731    if( $item['level'] > $level ){
732      //open new list
733      for($i=0; $i<($item['level'] - $level); $i++){
734        if ($i) $ret .= "<li class=\"clear\">\n";
735        $ret .= "\n<ul class=\"$class\">\n";
736      }
737    }elseif( $item['level'] < $level ){
738      //close last item
739      $ret .= "</li>\n";
740      for ($i=0; $i<($level - $item['level']); $i++){
741        //close higher lists
742        $ret .= "</ul>\n</li>\n";
743      }
744    }else{
745      //close last item
746      $ret .= "</li>\n";
747    }
748
749    //remember current level
750    $level = $item['level'];
751
752    //print item
753    $ret .= call_user_func($lifunc,$item);
754    $ret .= '<div class="li">';
755
756    $ret .= call_user_func($func,$item);
757    $ret .= '</div>';
758  }
759
760  //close remaining items and lists
761  for ($i=0; $i < $level; $i++){
762    $ret .= "</li></ul>\n";
763  }
764
765  return $ret;
766}
767
768/**
769 * display backlinks
770 *
771 * @author Andreas Gohr <andi@splitbrain.org>
772 */
773function html_backlinks(){
774  require_once(DOKU_INC.'inc/fulltext.php');
775  global $ID;
776  global $conf;
777
778  print p_locale_xhtml('backlinks');
779
780  $data = ft_backlinks($ID);
781
782  print '<ul class="idx">';
783  foreach($data as $blink){
784    print '<li><div class="li">';
785    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
786    print '</div></li>';
787  }
788  print '</ul>';
789}
790
791/**
792 * show diff
793 *
794 * @author Andreas Gohr <andi@splitbrain.org>
795 */
796function html_diff($text='',$intro=true){
797  require_once(DOKU_INC.'inc/DifferenceEngine.php');
798  global $ID;
799  global $REV;
800  global $lang;
801  global $conf;
802
803  // we're trying to be clever here, revisions to compare can be either
804  // given as rev and rev2 parameters, with rev2 being optional. Or in an
805  // array in rev2.
806  $rev1 = $REV;
807  if(is_array($_REQUEST['rev2'])){
808    $rev1 = (int) $_REQUEST['rev2'][0];
809    $rev2 = (int) $_REQUEST['rev2'][1];
810  }else{
811    $rev2 = (int) $_REQUEST['rev2'];
812  }
813
814  if($text){                      // compare text to the most current revision
815    $l_rev   = '';
816    $l_text  = rawWiki($ID,'');
817    $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
818               $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
819               $lang['current'];
820
821    $r_rev   = '';
822    $r_text  = cleanText($text);
823    $r_head  = $lang['yours'];
824  }else{
825    if($rev1 && $rev2){            // two specific revisions wanted
826      // make sure order is correct (older on the right)
827      if($rev1 < $rev2){
828        $l_rev = $rev1;
829        $r_rev = $rev2;
830      }else{
831        $l_rev = $rev2;
832        $r_rev = $rev1;
833      }
834    }elseif($rev1){                // single revision given, compare to current
835      $r_rev = '';
836      $l_rev = $rev1;
837    }else{                        // no revision was given, compare previous to current
838      $r_rev = '';
839      $revs = getRevisions($ID, 0, 1);
840      $l_rev = $revs[0];
841    }
842
843    $l_text = rawWiki($ID,$l_rev);
844    $r_text = rawWiki($ID,$r_rev);
845
846    $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
847              $ID.' '.date($conf['dformat'],$l_rev).'</a>';
848
849    if($r_rev){
850      $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
851                $ID.' '.date($conf['dformat'],$r_rev).'</a>';
852    }else{
853      $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
854               $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
855               $lang['current'];
856    }
857  }
858
859  $df = new Diff(explode("\n",htmlspecialchars($l_text)),
860                 explode("\n",htmlspecialchars($r_text)));
861
862  $tdf = new TableDiffFormatter();
863  if($intro) print p_locale_xhtml('diff');
864  ?>
865    <table class="diff">
866      <tr>
867        <th colspan="2">
868          <?php echo $l_head?>
869        </th>
870        <th colspan="2">
871          <?php echo $r_head?>
872        </th>
873      </tr>
874      <?php echo $tdf->format($df)?>
875    </table>
876  <?php
877}
878
879/**
880 * show warning on conflict detection
881 *
882 * @author Andreas Gohr <andi@splitbrain.org>
883 */
884function html_conflict($text,$summary){
885  global $ID;
886  global $lang;
887
888  print p_locale_xhtml('conflict');
889  ?>
890  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
891  <div class="centeralign">
892    <input type="hidden" name="id" value="<?php echo $ID?>" />
893    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
894    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
895
896    <input class="button" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" />
897    <input class="button" type="submit" name="do[cancel]" value="<?php echo $lang['btn_cancel']?>" />
898  </div>
899  </form>
900  <br /><br /><br /><br />
901  <?php
902}
903
904/**
905 * Prints the global message array
906 *
907 * @author Andreas Gohr <andi@splitbrain.org>
908 */
909function html_msgarea(){
910  global $MSG;
911
912  if(!isset($MSG)) return;
913
914  foreach($MSG as $msg){
915    print '<div class="'.$msg['lvl'].'">';
916    print $msg['msg'];
917    print '</div>';
918  }
919}
920
921/**
922 * Prints the registration form
923 *
924 * @author Andreas Gohr <andi@splitbrain.org>
925 * @triggers HTML_REGISTERFORM_INJECTION
926 */
927function html_register(){
928  global $lang;
929  global $conf;
930  global $ID;
931
932  print p_locale_xhtml('register');
933?>
934  <div class="centeralign">
935  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
936  <fieldset>
937    <input type="hidden" name="do" value="register" />
938    <input type="hidden" name="save" value="1" />
939
940    <legend><?php echo $lang['register']?></legend>
941    <label class="block">
942      <?php echo $lang['user']?>
943      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
944    </label><br />
945
946    <?php
947      if (!$conf['autopasswd']) {
948    ?>
949      <label class="block">
950        <?php echo $lang['pass']?>
951        <input type="password" name="pass" class="edit" size="50" />
952      </label><br />
953      <label class="block">
954        <?php echo $lang['passchk']?>
955        <input type="password" name="passchk" class="edit" size="50" />
956      </label><br />
957    <?php
958      }
959    ?>
960
961    <label class="block">
962      <?php echo $lang['fullname']?>
963      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
964    </label><br />
965    <label class="block">
966      <?php echo $lang['email']?>
967      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
968    </label><br />
969    <?php //bad and dirty event insert hook
970    $evdata = array();
971    trigger_event('HTML_REGISTERFORM_INJECTION', $evdata);
972    ?>
973    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
974  </fieldset>
975  </form>
976  </div>
977<?php
978}
979
980/**
981 * Print the update profile form
982 *
983 * @author Christopher Smith <chris@jalakai.co.uk>
984 * @author Andreas Gohr <andi@splitbrain.org>
985 */
986function html_updateprofile(){
987  global $lang;
988  global $conf;
989  global $ID;
990  global $INFO;
991  global $auth;
992
993  print p_locale_xhtml('updateprofile');
994
995  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
996  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
997?>
998  <div class="centeralign">
999  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
1000  <fieldset style="width: 80%;">
1001    <input type="hidden" name="do" value="profile" />
1002    <input type="hidden" name="save" value="1" />
1003
1004    <legend><?php echo $lang['profile']?></legend>
1005    <label class="block">
1006      <?php echo $lang['user']?>
1007      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
1008    </label><br />
1009    <label class="block">
1010      <?php echo $lang['fullname']?>
1011      <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
1012    </label><br />
1013    <label class="block">
1014      <?php echo $lang['email']?>
1015      <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
1016    </label><br /><br />
1017
1018    <?php if($auth->canDo('modPass')) { ?>
1019    <label class="block">
1020      <?php echo $lang['newpass']?>
1021      <input type="password" name="newpass" class="edit" size="50" />
1022    </label><br />
1023    <label class="block">
1024      <?php echo $lang['passchk']?>
1025      <input type="password" name="passchk" class="edit" size="50" />
1026    </label><br />
1027    <?php } ?>
1028
1029    <?php if ($conf['profileconfirm']) { ?>
1030      <br />
1031      <label class="block">
1032      <?php echo $lang['oldpass']?>
1033      <input type="password" name="oldpass" class="edit" size="50" />
1034    </label><br />
1035    <?php } ?>
1036    <?php //bad and dirty event insert hook
1037    $evdata = array();
1038    trigger_event('HTML_PROFILEFORM_INJECTION', $evdata);
1039    ?>
1040    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
1041    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
1042  </fieldset>
1043  </form>
1044  </div>
1045<?php
1046}
1047
1048/**
1049 * This displays the edit form (lots of logic included)
1050 *
1051 * @fixme    this is a huge lump of code and should be modularized
1052 * @triggers HTML_PAGE_FROMTEMPLATE
1053 * @triggers HTML_EDITFORM_INJECTION
1054 * @author   Andreas Gohr <andi@splitbrain.org>
1055 */
1056function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1057  global $ID;
1058  global $REV;
1059  global $DATE;
1060  global $RANGE;
1061  global $PRE;
1062  global $SUF;
1063  global $INFO;
1064  global $SUM;
1065  global $lang;
1066  global $conf;
1067
1068  //set summary default
1069  if(!$SUM){
1070    if($REV){
1071      $SUM = $lang['restored'];
1072    }elseif(!$INFO['exists']){
1073      $SUM = $lang['created'];
1074    }
1075  }
1076
1077  //no text? Load it!
1078  if(!isset($text)){
1079    $pr = false; //no preview mode
1080    if($INFO['exists']){
1081      if($RANGE){
1082        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1083      }else{
1084        $text = rawWiki($ID,$REV);
1085      }
1086      $check = md5($text);
1087      $mod = false;
1088    }else{
1089      //try to load a pagetemplate
1090      $data = array($ID);
1091      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1092      $check = md5('');
1093      $mod = $text!=='';
1094    }
1095  }else{
1096    $pr = true; //preview mode
1097    if (isset($_REQUEST['changecheck'])) {
1098      $check = $_REQUEST['changecheck'];
1099      $mod = md5($text)!==$check;
1100    } else {
1101      // Why? Assume default text is unmodified.
1102      $check = md5($text);
1103      $mod = false;
1104    }
1105  }
1106
1107  $wr = $INFO['writable'];
1108  if($wr){
1109    if ($REV) print p_locale_xhtml('editrev');
1110    print p_locale_xhtml($include);
1111    $ro=false;
1112  }else{
1113    // check pseudo action 'source'
1114    if(!actionOK('source')){
1115      msg('Command disabled: source',-1);
1116      return;
1117    }
1118    print p_locale_xhtml('read');
1119    $ro='readonly="readonly"';
1120  }
1121  if(!$DATE) $DATE = $INFO['lastmod'];
1122
1123
1124?>
1125  <div style="width:99%;">
1126
1127   <div class="toolbar">
1128      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.date($conf['dformat']);?></div>
1129      <div id="tool__bar"><?php if(!$ro){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1130      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1131
1132      <?php if($wr){?>
1133      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1134        <?php /* sets changed to true when previewed */?>
1135        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1136      //--><!]]></script>
1137      <span id="spell__action"></span>
1138      <div id="spell__suggest"></div>
1139      <?php } ?>
1140   </div>
1141   <div id="spell__result"></div>
1142
1143
1144   <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">
1145      <input type="hidden" name="id"   value="<?php echo $ID?>" />
1146      <input type="hidden" name="rev"  value="<?php echo $REV?>" />
1147      <input type="hidden" name="date" value="<?php echo $DATE?>" />
1148      <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
1149      <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
1150      <input type="hidden" name="changecheck" value="<?php echo $check?>" />
1151    </div>
1152
1153    <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
1154
1155    <?php //bad and dirty event insert hook
1156    $evdata = array('writable' => $wr);
1157    trigger_event('HTML_EDITFORM_INJECTION', $evdata);
1158    ?>
1159
1160    <div id="wiki__editbar">
1161      <div id="size__ctl"></div>
1162      <?php if($wr){?>
1163         <div class="editButtons">
1164            <input class="button" id="edbtn__save" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" tabindex="4" />
1165            <input class="button" id="edbtn__preview" type="submit" name="do[preview]" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="<?php echo $lang['btn_preview']?> [ALT+P]" tabindex="5" />
1166            <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="6" />
1167         </div>
1168      <?php } ?>
1169      <?php if($wr){ ?>
1170        <div class="summary">
1171           <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label>
1172           <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1173           <?php html_minoredit()?>
1174        </div>
1175      <?php }?>
1176    </div>
1177  </form>
1178  </div>
1179<?php
1180}
1181
1182/**
1183 * Adds a checkbox for minor edits for logged in users
1184 *
1185 * @author Andrea Gohr <andi@splitbrain.org>
1186 */
1187function html_minoredit(){
1188  global $conf;
1189  global $lang;
1190  // minor edits are for logged in users only
1191  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1192    return;
1193  }
1194
1195  $p = array();
1196  $p['name']     = 'minor';
1197  $p['type']     = 'checkbox';
1198  $p['id']       = 'minoredit';
1199  $p['tabindex'] = 3;
1200  $p['value']    = '1';
1201  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1202  $att = buildAttributes($p);
1203
1204  print '<span class="nowrap">';
1205  print "<input $att />";
1206  print '<label for="minoredit">';
1207  print $lang['minoredit'];
1208  print '</label>';
1209  print '</span>';
1210}
1211
1212/**
1213 * prints some debug info
1214 *
1215 * @author Andreas Gohr <andi@splitbrain.org>
1216 */
1217function html_debug(){
1218  global $conf;
1219  global $lang;
1220  global $auth;
1221  global $INFO;
1222
1223  //remove sensitive data
1224  $cnf = $conf;
1225  $cnf['auth']='***';
1226  $cnf['notify']='***';
1227  $cnf['ftp']='***';
1228  $nfo = $INFO;
1229  $nfo['userinfo'] = '***';
1230  $ses = $_SESSION;
1231  $ses[$conf['title']]['auth'] = '***';
1232
1233  print '<html><body>';
1234
1235  print '<p>When reporting bugs please send all the following ';
1236  print 'output as a mail to andi@splitbrain.org ';
1237  print 'The best way to do this is to save this page in your browser</p>';
1238
1239  print '<b>$INFO:</b><pre>';
1240  print_r($nfo);
1241  print '</pre>';
1242
1243  print '<b>$_SERVER:</b><pre>';
1244  print_r($_SERVER);
1245  print '</pre>';
1246
1247  print '<b>$conf:</b><pre>';
1248  print_r($cnf);
1249  print '</pre>';
1250
1251  print '<b>DOKU_BASE:</b><pre>';
1252  print DOKU_BASE;
1253  print '</pre>';
1254
1255  print '<b>abs DOKU_BASE:</b><pre>';
1256  print DOKU_URL;
1257  print '</pre>';
1258
1259  print '<b>rel DOKU_BASE:</b><pre>';
1260  print dirname($_SERVER['PHP_SELF']).'/';
1261  print '</pre>';
1262
1263  print '<b>PHP Version:</b><pre>';
1264  print phpversion();
1265  print '</pre>';
1266
1267  print '<b>locale:</b><pre>';
1268  print setlocale(LC_ALL,0);
1269  print '</pre>';
1270
1271  print '<b>encoding:</b><pre>';
1272  print $lang['encoding'];
1273  print '</pre>';
1274
1275  if($auth){
1276    print '<b>Auth backend capabilities:</b><pre>';
1277    print_r($auth->cando);
1278    print '</pre>';
1279  }
1280
1281  print '<b>$_SESSION:</b><pre>';
1282  print_r($ses);
1283  print '</pre>';
1284
1285  print '<b>Environment:</b><pre>';
1286  print_r($_ENV);
1287  print '</pre>';
1288
1289  print '<b>PHP settings:</b><pre>';
1290  $inis = ini_get_all();
1291  print_r($inis);
1292  print '</pre>';
1293
1294  print '</body></html>';
1295}
1296
1297function html_admin(){
1298  global $ID;
1299  global $INFO;
1300  global $lang;
1301  global $conf;
1302
1303  print p_locale_xhtml('admin');
1304
1305  // build menu of admin functions from the plugins that handle them
1306  $pluginlist = plugin_list('admin');
1307  $menu = array();
1308  foreach ($pluginlist as $p) {
1309    if($obj =& plugin_load('admin',$p) === NULL) continue;
1310
1311    // check permissions
1312    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1313
1314    $menu[] = array('plugin' => $p,
1315                    'prompt' => $obj->getMenuText($conf['lang']),
1316                    'sort' => $obj->getMenuSort()
1317                   );
1318  }
1319
1320  usort($menu, 'p_sort_modes');
1321
1322  // output the menu
1323  ptln('<ul>');
1324
1325  foreach ($menu as $item) {
1326    if (!$item['prompt']) continue;
1327    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1328  }
1329
1330  ptln('</ul>');
1331}
1332
1333/**
1334 * Form to request a new password for an existing account
1335 *
1336 * @author Benoit Chesneau <benoit@bchesneau.info>
1337 */
1338function html_resendpwd() {
1339  global $lang;
1340  global $conf;
1341  global $ID;
1342
1343  print p_locale_xhtml('resendpwd');
1344?>
1345  <div class="centeralign">
1346  <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
1347    <fieldset>
1348      <br />
1349      <legend><?php echo $lang['resendpwd']?></legend>
1350      <input type="hidden" name="do" value="resendpwd" />
1351      <input type="hidden" name="save" value="1" />
1352      <label class="block">
1353        <span><?php echo $lang['user']?></span>
1354        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
1355      </label><br />
1356      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
1357    </fieldset>
1358  </form>
1359  </div>
1360<?php
1361}
1362
1363//Setup VIM: ex: et ts=2 enc=utf-8 :
1364