xref: /dokuwiki/inc/html.php (revision a06884abe180891c09730983f2b8d13662c3fd34)
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 '<ul>';
448  if($INFO['exists'] && $first==0){
449    print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
450    print '<div class="li">';
451
452    print $date;
453
454    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
455
456    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
457
458    print ' &ndash; ';
459    print $INFO['sum'];
460    print ' <span class="user">';
461    print (empty($INFO['editor']))?('('.$lang['external_edit'].')'):$INFO['editor'];
462    print '</span> ';
463
464    print '('.$lang['current'].')';
465    print '</div>';
466    print '</li>';
467  }
468
469  foreach($revisions as $rev){
470    $date = date($conf['dformat'],$rev);
471    $info = getRevisionInfo($ID,$rev,true);
472
473    print ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
474    print '<div class="li">';
475    print $date;
476
477    if(@file_exists(wikiFN($ID,$rev))){
478      print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
479      $p = array();
480      $p['src']    = DOKU_BASE.'lib/images/diff.png';
481      $p['width']  = 15;
482      $p['height'] = 11;
483      $p['title']  = $lang['diff'];
484      $p['alt']    = $lang['diff'];
485      $att = buildAttributes($p);
486      print "<img $att />";
487      print '</a> ';
488
489      print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>';
490    }else{
491      print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
492      print $ID;
493    }
494
495    print ' &ndash; ';
496    print htmlspecialchars($info['sum']);
497    print ' <span class="user">';
498    if($info['user']){
499      print $info['user'];
500    }else{
501      print $info['ip'];
502    }
503    print '</span>';
504
505    print '</div>';
506    print '</li>';
507  }
508  print '</ul>';
509
510  print '<div class="pagenav">';
511  $last = $first + $conf['recent'];
512  if ($first > 0) {
513    $first -= $conf['recent'];
514    if ($first < 0) $first = 0;
515    print '<div class="pagenav-prev">';
516    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
517    print '</div>';
518  }
519  if ($hasNext) {
520    print '<div class="pagenav-next">';
521    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
522    print '</div>';
523  }
524  print '</div>';
525
526}
527
528/**
529 * display recent changes
530 *
531 * @author Andreas Gohr <andi@splitbrain.org>
532 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
533 * @author Ben Coburn <btcoburn@silicodon.net>
534 */
535function html_recent($first=0){
536  global $conf;
537  global $lang;
538  global $ID;
539  /* we need to get one additionally log entry to be able to
540   * decide if this is the last page or is there another one.
541   * This is the cheapest solution to get this information.
542   */
543  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
544  if(count($recents) == 0 && $first != 0){
545    $first=0;
546    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
547  }
548  $hasNext = false;
549  if (count($recents)>$conf['recent']) {
550    $hasNext = true;
551    array_pop($recents); // remove extra log entry
552  }
553
554  print p_locale_xhtml('recent');
555  print '<ul>';
556
557  foreach($recents as $recent){
558    $date = date($conf['dformat'],$recent['date']);
559    print ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
560    print '<div class="li">';
561
562    print $date.' ';
563
564    print '<a href="'.wl($recent['id'],"do=diff").'">';
565    $p = array();
566    $p['src']    = DOKU_BASE.'lib/images/diff.png';
567    $p['width']  = 15;
568    $p['height'] = 11;
569    $p['title']  = $lang['diff'];
570    $p['alt']    = $lang['diff'];
571    $att = buildAttributes($p);
572    print "<img $att />";
573    print '</a> ';
574
575    print '<a href="'.wl($recent['id'],"do=revisions").'">';
576    $p = array();
577    $p['src']    = DOKU_BASE.'lib/images/history.png';
578    $p['width']  = 12;
579    $p['height'] = 14;
580    $p['title']  = $lang['btn_revs'];
581    $p['alt']    = $lang['btn_revs'];
582    $att = buildAttributes($p);
583    print "<img $att />";
584    print '</a> ';
585
586    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
587    print ' &ndash; '.htmlspecialchars($recent['sum']);
588
589    print ' <span class="user">';
590    if($recent['user']){
591      print $recent['user'];
592    }else{
593      print $recent['ip'];
594    }
595    print '</span>';
596
597    print '</div>';
598    print '</li>';
599  }
600  print '</ul>';
601
602  print '<div class="pagenav">';
603  $last = $first + $conf['recent'];
604  if ($first > 0) {
605    $first -= $conf['recent'];
606    if ($first < 0) $first = 0;
607    print '<div class="pagenav-prev">';
608    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
609    print '</div>';
610  }
611  if ($hasNext) {
612    print '<div class="pagenav-next">';
613    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
614    print '</div>';
615  }
616  print '</div>';
617}
618
619/**
620 * Display page index
621 *
622 * @author Andreas Gohr <andi@splitbrain.org>
623 */
624function html_index($ns){
625  require_once(DOKU_INC.'inc/search.php');
626  global $conf;
627  global $ID;
628  $dir = $conf['datadir'];
629  $ns  = cleanID($ns);
630  #fixme use appropriate function
631  if(empty($ns)){
632    $ns = dirname(str_replace(':','/',$ID));
633    if($ns == '.') $ns ='';
634  }
635  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
636
637  echo p_locale_xhtml('index');
638  echo '<div id="index__tree">';
639
640  $data = array();
641  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
642  echo html_buildlist($data,'idx','html_list_index','html_li_index');
643
644  echo '</div>';
645}
646
647/**
648 * Index item formatter
649 *
650 * User function for html_buildlist()
651 *
652 * @author Andreas Gohr <andi@splitbrain.org>
653 */
654function html_list_index($item){
655  global $ID;
656  $ret = '';
657  $base = ':'.$item['id'];
658  $base = substr($base,strrpos($base,':')+1);
659  if($item['type']=='d'){
660    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir"><strong>';
661    $ret .= $base;
662    $ret .= '</strong></a>';
663  }else{
664    $ret .= html_wikilink(':'.$item['id']);
665  }
666  return $ret;
667}
668
669/**
670 * Index List item
671 *
672 * This user function is used in html_build_lidt to build the
673 * <li> tags for namespaces when displaying the page index
674 * it gives different classes to opened or closed "folders"
675 *
676 * @author Andreas Gohr <andi@splitbrain.org>
677 */
678function html_li_index($item){
679  if($item['type'] == "f"){
680    return '<li class="level'.$item['level'].'">';
681  }elseif($item['open']){
682    return '<li class="open">';
683  }else{
684    return '<li class="closed">';
685  }
686}
687
688/**
689 * Default List item
690 *
691 * @author Andreas Gohr <andi@splitbrain.org>
692 */
693function html_li_default($item){
694  return '<li class="level'.$item['level'].'">';
695}
696
697/**
698 * Build an unordered list
699 *
700 * Build an unordered list from the given $data array
701 * Each item in the array has to have a 'level' property
702 * the item itself gets printed by the given $func user
703 * function. The second and optional function is used to
704 * print the <li> tag. Both user function need to accept
705 * a single item.
706 *
707 * Both user functions can be given as array to point to
708 * a member of an object.
709 *
710 * @author Andreas Gohr <andi@splitbrain.org>
711 */
712function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
713  $level = 0;
714  $opens = 0;
715  $ret   = '';
716
717  foreach ($data as $item){
718
719    if( $item['level'] > $level ){
720      //open new list
721      for($i=0; $i<($item['level'] - $level); $i++){
722        if ($i) $ret .= "<li class=\"clear\">\n";
723        $ret .= "\n<ul class=\"$class\">\n";
724      }
725    }elseif( $item['level'] < $level ){
726      //close last item
727      $ret .= "</li>\n";
728      for ($i=0; $i<($level - $item['level']); $i++){
729        //close higher lists
730        $ret .= "</ul>\n</li>\n";
731      }
732    }else{
733      //close last item
734      $ret .= "</li>\n";
735    }
736
737    //remember current level
738    $level = $item['level'];
739
740    //print item
741    $ret .= call_user_func($lifunc,$item);
742    $ret .= '<div class="li">';
743
744    $ret .= call_user_func($func,$item);
745    $ret .= '</div>';
746  }
747
748  //close remaining items and lists
749  for ($i=0; $i < $level; $i++){
750    $ret .= "</li></ul>\n";
751  }
752
753  return $ret;
754}
755
756/**
757 * display backlinks
758 *
759 * @author Andreas Gohr <andi@splitbrain.org>
760 */
761function html_backlinks(){
762  require_once(DOKU_INC.'inc/fulltext.php');
763  global $ID;
764  global $conf;
765
766  print p_locale_xhtml('backlinks');
767
768  $data = ft_backlinks($ID);
769
770  print '<ul class="idx">';
771  foreach($data as $blink){
772    print '<li><div class="li">';
773    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
774    print '</div></li>';
775  }
776  print '</ul>';
777}
778
779/**
780 * show diff
781 *
782 * @author Andreas Gohr <andi@splitbrain.org>
783 */
784function html_diff($text='',$intro=true){
785  require_once(DOKU_INC.'inc/DifferenceEngine.php');
786  global $ID;
787  global $REV;
788  global $lang;
789  global $conf;
790
791  if($text){
792    $df  = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,''))),
793                    explode("\n",htmlspecialchars(cleanText($text))));
794    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
795              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
796              $lang['current'];
797    $right = $lang['yours'];
798  }else{
799    //check if current revision exist
800    if(!@file_exists(wikiFN($ID))){
801      $revs = getRevisions($ID, 0, 2);
802      $rc = $revs[1];
803    }
804    if($REV){
805      $r = $REV;
806    }else{
807      if(empty($revs)){
808        //use last revision if none given
809        $revs = getRevisions($ID, 0, 1);
810      }
811      $r = $revs[0];
812    }
813
814    if($r){
815      $df  = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,$r))),
816                      explode("\n",htmlspecialchars(rawWiki($ID,''))));
817      $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
818                $ID.' '.date($conf['dformat'],(isset($rc) ? $rc : $r)).'</a>';
819    }else{
820      $df  = new Diff(array(''),
821                      explode("\n",htmlspecialchars(rawWiki($ID,''))));
822      $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
823                $ID.'</a>';
824    }
825    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
826              $ID.' '.date($conf['dformat'],(isset($rc) ? $r : @filemtime(wikiFN($ID)))).'</a> '.
827              $lang['current'];
828  }
829  $tdf = new TableDiffFormatter();
830  if($intro) print p_locale_xhtml('diff');
831  ?>
832    <table class="diff">
833      <tr>
834        <th colspan="2">
835          <?php echo $left?>
836        </th>
837        <th colspan="2">
838          <?php echo $right?>
839        </th>
840      </tr>
841      <?php echo $tdf->format($df)?>
842    </table>
843  <?php
844}
845
846/**
847 * show warning on conflict detection
848 *
849 * @author Andreas Gohr <andi@splitbrain.org>
850 */
851function html_conflict($text,$summary){
852  global $ID;
853  global $lang;
854
855  print p_locale_xhtml('conflict');
856  ?>
857  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
858  <div class="centeralign">
859    <input type="hidden" name="id" value="<?php echo $ID?>" />
860    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
861    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
862
863    <input class="button" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" />
864    <input class="button" type="submit" name="do[cancel]" value="<?php echo $lang['btn_cancel']?>" />
865  </div>
866  </form>
867  <br /><br /><br /><br />
868  <?php
869}
870
871/**
872 * Prints the global message array
873 *
874 * @author Andreas Gohr <andi@splitbrain.org>
875 */
876function html_msgarea(){
877  global $MSG;
878
879  if(!isset($MSG)) return;
880
881  foreach($MSG as $msg){
882    print '<div class="'.$msg['lvl'].'">';
883    print $msg['msg'];
884    print '</div>';
885  }
886}
887
888/**
889 * Prints the registration form
890 *
891 * @author Andreas Gohr <andi@splitbrain.org>
892 * @triggers HTML_REGISTERFORM_INJECTION
893 */
894function html_register(){
895  global $lang;
896  global $conf;
897  global $ID;
898
899  print p_locale_xhtml('register');
900?>
901  <div class="centeralign">
902  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
903  <fieldset>
904    <input type="hidden" name="do" value="register" />
905    <input type="hidden" name="save" value="1" />
906
907    <legend><?php echo $lang['register']?></legend>
908    <label class="block">
909      <?php echo $lang['user']?>
910      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
911    </label><br />
912
913    <?php
914      if (!$conf['autopasswd']) {
915    ?>
916      <label class="block">
917        <?php echo $lang['pass']?>
918        <input type="password" name="pass" class="edit" size="50" />
919      </label><br />
920      <label class="block">
921        <?php echo $lang['passchk']?>
922        <input type="password" name="passchk" class="edit" size="50" />
923      </label><br />
924    <?php
925      }
926    ?>
927
928    <label class="block">
929      <?php echo $lang['fullname']?>
930      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
931    </label><br />
932    <label class="block">
933      <?php echo $lang['email']?>
934      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
935    </label><br />
936    <?php //bad and dirty event insert hook
937    $evdata = array();
938    trigger_event('HTML_REGISTERFORM_INJECTION', $evdata);
939    ?>
940    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
941  </fieldset>
942  </form>
943  </div>
944<?php
945}
946
947/**
948 * Print the update profile form
949 *
950 * @author Christopher Smith <chris@jalakai.co.uk>
951 * @author Andreas Gohr <andi@splitbrain.org>
952 */
953function html_updateprofile(){
954  global $lang;
955  global $conf;
956  global $ID;
957  global $INFO;
958  global $auth;
959
960  print p_locale_xhtml('updateprofile');
961
962  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
963  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
964?>
965  <div class="centeralign">
966  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
967  <fieldset style="width: 80%;">
968    <input type="hidden" name="do" value="profile" />
969    <input type="hidden" name="save" value="1" />
970
971    <legend><?php echo $lang['profile']?></legend>
972    <label class="block">
973      <?php echo $lang['user']?>
974      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
975    </label><br />
976    <label class="block">
977      <?php echo $lang['fullname']?>
978      <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
979    </label><br />
980    <label class="block">
981      <?php echo $lang['email']?>
982      <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
983    </label><br /><br />
984
985    <?php if($auth->canDo('modPass')) { ?>
986    <label class="block">
987      <?php echo $lang['newpass']?>
988      <input type="password" name="newpass" class="edit" size="50" />
989    </label><br />
990    <label class="block">
991      <?php echo $lang['passchk']?>
992      <input type="password" name="passchk" class="edit" size="50" />
993    </label><br />
994    <?php } ?>
995
996    <?php if ($conf['profileconfirm']) { ?>
997      <br />
998      <label class="block">
999      <?php echo $lang['oldpass']?>
1000      <input type="password" name="oldpass" class="edit" size="50" />
1001    </label><br />
1002    <?php } ?>
1003    <?php //bad and dirty event insert hook
1004    $evdata = array();
1005    trigger_event('HTML_PROFILEFORM_INJECTION', $evdata);
1006    ?>
1007    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
1008    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
1009  </fieldset>
1010  </form>
1011  </div>
1012<?php
1013}
1014
1015/**
1016 * This displays the edit form (lots of logic included)
1017 *
1018 * @fixme    this is a huge lump of code and should be modularized
1019 * @triggers HTML_PAGE_FROMTEMPLATE
1020 * @triggers HTML_EDITFORM_INJECTION
1021 * @author   Andreas Gohr <andi@splitbrain.org>
1022 */
1023function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1024  global $ID;
1025  global $REV;
1026  global $DATE;
1027  global $RANGE;
1028  global $PRE;
1029  global $SUF;
1030  global $INFO;
1031  global $SUM;
1032  global $lang;
1033  global $conf;
1034
1035  //set summary default
1036  if(!$SUM){
1037    if($REV){
1038      $SUM = $lang['restored'];
1039    }elseif(!$INFO['exists']){
1040      $SUM = $lang['created'];
1041    }
1042  }
1043
1044  //no text? Load it!
1045  if(!isset($text)){
1046    $pr = false; //no preview mode
1047    if($INFO['exists']){
1048      if($RANGE){
1049        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1050      }else{
1051        $text = rawWiki($ID,$REV);
1052      }
1053      $check = md5($text);
1054      $mod = false;
1055    }else{
1056      //try to load a pagetemplate
1057      $data = array($ID);
1058      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1059      $check = md5('');
1060      $mod = $text!=='';
1061    }
1062  }else{
1063    $pr = true; //preview mode
1064    if (isset($_REQUEST['changecheck'])) {
1065      $check = $_REQUEST['changecheck'];
1066      $mod = md5($text)!==$check;
1067    } else {
1068      // Why? Assume default text is unmodified.
1069      $check = md5($text);
1070      $mod = false;
1071    }
1072  }
1073
1074  $wr = $INFO['writable'];
1075  if($wr){
1076    if ($REV) print p_locale_xhtml('editrev');
1077    print p_locale_xhtml($include);
1078    $ro=false;
1079  }else{
1080    // check pseudo action 'source'
1081    if(!actionOK('source')){
1082      msg('Command disabled: source',-1);
1083      return;
1084    }
1085    print p_locale_xhtml('read');
1086    $ro='readonly="readonly"';
1087  }
1088  if(!$DATE) $DATE = $INFO['lastmod'];
1089
1090
1091?>
1092  <div style="width:99%;">
1093
1094   <div class="toolbar">
1095      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.date($conf['dformat']);?></div>
1096      <div id="tool__bar"><?php if(!$ro){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1097      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1098
1099      <?php if($wr){?>
1100      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1101        <?php /* sets changed to true when previewed */?>
1102        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1103      //--><!]]></script>
1104      <span id="spell__action"></span>
1105      <div id="spell__suggest"></div>
1106      <?php } ?>
1107   </div>
1108   <div id="spell__result"></div>
1109
1110
1111   <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">
1112      <input type="hidden" name="id"   value="<?php echo $ID?>" />
1113      <input type="hidden" name="rev"  value="<?php echo $REV?>" />
1114      <input type="hidden" name="date" value="<?php echo $DATE?>" />
1115      <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
1116      <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
1117      <input type="hidden" name="changecheck" value="<?php echo $check?>" />
1118    </div>
1119
1120    <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
1121
1122    <?php //bad and dirty event insert hook
1123    $evdata = array('writable' => $wr);
1124    trigger_event('HTML_EDITFORM_INJECTION', $evdata);
1125    ?>
1126
1127    <div id="wiki__editbar">
1128      <div id="size__ctl"></div>
1129      <?php if($wr){?>
1130         <div class="editButtons">
1131            <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" />
1132            <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" />
1133            <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="6" />
1134         </div>
1135      <?php } ?>
1136      <?php if($wr){ ?>
1137        <div class="summary">
1138           <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label>
1139           <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1140           <?php html_minoredit()?>
1141        </div>
1142      <?php }?>
1143    </div>
1144  </form>
1145  </div>
1146<?php
1147}
1148
1149/**
1150 * Adds a checkbox for minor edits for logged in users
1151 *
1152 * @author Andrea Gohr <andi@splitbrain.org>
1153 */
1154function html_minoredit(){
1155  global $conf;
1156  global $lang;
1157  // minor edits are for logged in users only
1158  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1159    return;
1160  }
1161
1162  $p = array();
1163  $p['name']     = 'minor';
1164  $p['type']     = 'checkbox';
1165  $p['id']       = 'minoredit';
1166  $p['tabindex'] = 3;
1167  $p['value']    = '1';
1168  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1169  $att = buildAttributes($p);
1170
1171  print '<span class="nowrap">';
1172  print "<input $att />";
1173  print '<label for="minoredit">';
1174  print $lang['minoredit'];
1175  print '</label>';
1176  print '</span>';
1177}
1178
1179/**
1180 * prints some debug info
1181 *
1182 * @author Andreas Gohr <andi@splitbrain.org>
1183 */
1184function html_debug(){
1185  global $conf;
1186  global $lang;
1187  global $auth;
1188  global $INFO;
1189
1190  //remove sensitive data
1191  $cnf = $conf;
1192  $cnf['auth']='***';
1193  $cnf['notify']='***';
1194  $cnf['ftp']='***';
1195  $nfo = $INFO;
1196  $nfo['userinfo'] = '***';
1197  $ses = $_SESSION;
1198  $ses[$conf['title']]['auth'] = '***';
1199
1200  print '<html><body>';
1201
1202  print '<p>When reporting bugs please send all the following ';
1203  print 'output as a mail to andi@splitbrain.org ';
1204  print 'The best way to do this is to save this page in your browser</p>';
1205
1206  print '<b>$INFO:</b><pre>';
1207  print_r($nfo);
1208  print '</pre>';
1209
1210  print '<b>$_SERVER:</b><pre>';
1211  print_r($_SERVER);
1212  print '</pre>';
1213
1214  print '<b>$conf:</b><pre>';
1215  print_r($cnf);
1216  print '</pre>';
1217
1218  print '<b>DOKU_BASE:</b><pre>';
1219  print DOKU_BASE;
1220  print '</pre>';
1221
1222  print '<b>abs DOKU_BASE:</b><pre>';
1223  print DOKU_URL;
1224  print '</pre>';
1225
1226  print '<b>rel DOKU_BASE:</b><pre>';
1227  print dirname($_SERVER['PHP_SELF']).'/';
1228  print '</pre>';
1229
1230  print '<b>PHP Version:</b><pre>';
1231  print phpversion();
1232  print '</pre>';
1233
1234  print '<b>locale:</b><pre>';
1235  print setlocale(LC_ALL,0);
1236  print '</pre>';
1237
1238  print '<b>encoding:</b><pre>';
1239  print $lang['encoding'];
1240  print '</pre>';
1241
1242  if($auth){
1243    print '<b>Auth backend capabilities:</b><pre>';
1244    print_r($auth->cando);
1245    print '</pre>';
1246  }
1247
1248  print '<b>$_SESSION:</b><pre>';
1249  print_r($ses);
1250  print '</pre>';
1251
1252  print '<b>Environment:</b><pre>';
1253  print_r($_ENV);
1254  print '</pre>';
1255
1256  print '<b>PHP settings:</b><pre>';
1257  $inis = ini_get_all();
1258  print_r($inis);
1259  print '</pre>';
1260
1261  print '</body></html>';
1262}
1263
1264function html_admin(){
1265  global $ID;
1266  global $INFO;
1267  global $lang;
1268  global $conf;
1269
1270  print p_locale_xhtml('admin');
1271
1272  // build menu of admin functions from the plugins that handle them
1273  $pluginlist = plugin_list('admin');
1274  $menu = array();
1275  foreach ($pluginlist as $p) {
1276    if($obj =& plugin_load('admin',$p) === NULL) continue;
1277
1278    // check permissions
1279    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1280
1281    $menu[] = array('plugin' => $p,
1282                    'prompt' => $obj->getMenuText($conf['lang']),
1283                    'sort' => $obj->getMenuSort()
1284                   );
1285  }
1286
1287  usort($menu, 'p_sort_modes');
1288
1289  // output the menu
1290  ptln('<ul>');
1291
1292  foreach ($menu as $item) {
1293    if (!$item['prompt']) continue;
1294    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1295  }
1296
1297  ptln('</ul>');
1298}
1299
1300/**
1301 * Form to request a new password for an existing account
1302 *
1303 * @author Benoit Chesneau <benoit@bchesneau.info>
1304 */
1305function html_resendpwd() {
1306  global $lang;
1307  global $conf;
1308  global $ID;
1309
1310  print p_locale_xhtml('resendpwd');
1311?>
1312  <div class="centeralign">
1313  <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
1314    <fieldset>
1315      <br />
1316      <legend><?php echo $lang['resendpwd']?></legend>
1317      <input type="hidden" name="do" value="resendpwd" />
1318      <input type="hidden" name="save" value="1" />
1319      <label class="block">
1320        <span><?php echo $lang['user']?></span>
1321        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
1322      </label><br />
1323      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
1324    </fieldset>
1325  </form>
1326  </div>
1327<?php
1328}
1329
1330//Setup VIM: ex: et ts=2 enc=utf-8 :
1331