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