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