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