xref: /dokuwiki/inc/html.php (revision b0702bc0721b4ab46dd01cad67f23fa0766c97e9)
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,'r',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" 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,'r',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      $ret .= "\n<ul class=\"$class\">\n";
766    }elseif( $item['level'] < $level ){
767      //close last item
768      $ret .= "</li>\n";
769      for ($i=0; $i<($level - $item['level']); $i++){
770        //close higher lists
771        $ret .= "</ul>\n</li>\n";
772      }
773    }else{
774      //close last item
775      $ret .= "</li>\n";
776    }
777
778    //remember current level
779    $level = $item['level'];
780
781    //print item
782    $ret .= $lifunc($item); //user function
783    $ret .= '<span class="li">';
784    $ret .= $func($item); //user function
785    $ret .= '</span>';
786  }
787
788  //close remaining items and lists
789  for ($i=0; $i < $level; $i++){
790    $ret .= "</li></ul>\n";
791  }
792
793  return $ret;
794}
795
796/**
797 * display backlinks
798 *
799 * @author Andreas Gohr <andi@splitbrain.org>
800 */
801function html_backlinks(){
802  require_once("inc/search.php");
803  global $ID;
804  global $conf;
805
806  if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
807    $opts['ns']   = $matches[1];
808    $opts['name'] = $matches[2];
809  }else{
810    $opts['ns']   = '';
811    $opts['name'] = $ID;
812  }
813
814  print parsedLocale('backlinks');
815
816  $data = array();
817  search($data,$conf['datadir'],'search_backlinks',$opts);
818  sort($data);
819
820  print '<ul class="idx">';
821  foreach($data as $row){
822    print '<li>';
823    print html_wikilink(':'.$row['id'],$row['id']);
824    print '</li>';
825  }
826  print '</ul>';
827}
828
829/**
830 * show diff
831 *
832 * @author Andreas Gohr <andi@splitbrain.org>
833 */
834function html_diff($text='',$intro=true){
835  require_once("inc/DifferenceEngine.php");
836  global $ID;
837  global $REV;
838  global $lang;
839  global $conf;
840  if($text){
841    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
842                    split("\n",htmlspecialchars(cleanText($text))));
843    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
844              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
845              $lang['current'];
846    $right = $lang['yours'];
847  }else{
848    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$REV))),
849                    split("\n",htmlspecialchars(rawWiki($ID,''))));
850    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$REV").'">'.
851              $ID.' '.date($conf['dformat'],$REV).'</a>';
852    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
853              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
854              $lang['current'];
855  }
856  $tdf = new TableDiffFormatter();
857  if($intro) print parsedLocale('diff');
858  ?>
859    <table class="diff" width="100%">
860      <tr>
861        <td colspan="2" width="50%" class="diff-header">
862          <?=$left?>
863        </td>
864        <td colspan="2" width="50%" class="diff-header">
865          <?=$right?>
866        </td>
867      </tr>
868      <?=$tdf->format($df)?>
869    </table>
870  <?
871}
872
873/**
874 * show warning on conflict detection
875 *
876 * @author Andreas Gohr <andi@splitbrain.org>
877 */
878function html_conflict($text,$summary){
879  global $ID;
880  global $lang;
881
882  print parsedLocale('conflict');
883  ?>
884  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
885  <input type="hidden" name="id" value="<?=$ID?>" />
886  <input type="hidden" name="wikitext" value="<?=formText($text)?>" />
887  <input type="hidden" name="summary" value="<?=formText($summary)?>" />
888
889  <div align="center">
890    <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
891    <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" />
892  </div>
893  </form>
894  <br /><br /><br /><br />
895  <?
896}
897
898/**
899 * Prints the global message array
900 *
901 * @author Andreas Gohr <andi@splitbrain.org>
902 */
903function html_msgarea(){
904  global $MSG;
905
906  if(!isset($MSG)) return;
907
908  foreach($MSG as $msg){
909    print '<div class="'.$msg['lvl'].'">';
910    print $msg['msg'];
911    print '</div>';
912  }
913}
914
915/**
916 * Prints the registration form
917 *
918 * @author Andreas Gohr <andi@splitbrain.org>
919 */
920function html_register(){
921  global $lang;
922  global $ID;
923
924  print parsedLocale('register');
925?>
926  <div align="center">
927  <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
928  <input type="hidden" name="do" value="register" />
929  <input type="hidden" name="save" value="1" />
930  <fieldset>
931    <legend><?=$lang['register']?></legend>
932    <label>
933      <?=$lang['user']?>
934      <input type="text" name="login" class="edit" size="50" value="<?=formText($_POST['login'])?>" />
935    </label><br />
936    <label>
937      <?=$lang['fullname']?>
938      <input type="text" name="fullname" class="edit" size="50" value="<?=formText($_POST['fullname'])?>" />
939    </label><br />
940    <label>
941      <?=$lang['email']?>
942      <input type="text" name="email" class="edit" size="50" value="<?=formText($_POST['email'])?>" />
943    </label><br />
944    <input type="submit" class="button" value="<?=$lang['register']?>" />
945  </fieldset>
946  </form>
947  </div>
948<?
949}
950
951/**
952 * This displays the edit form (lots of logic included)
953 *
954 * @author Andreas Gohr <andi@splitbrain.org>
955 */
956function html_edit($text=null,$include='edit'){ //FIXME: include needed?
957  global $ID;
958  global $REV;
959  global $DATE;
960  global $RANGE;
961  global $PRE;
962  global $SUF;
963  global $INFO;
964  global $SUM;
965  global $lang;
966  global $conf;
967
968  //check for create permissions first
969  if(!$INFO['exists'] && !html_acl(AUTH_CREATE)) return;
970
971  //set summary default
972  if(!$SUM){
973    if($REV){
974      $SUM = $lang['restored'];
975    }elseif(!$INFO['exists']){
976      $SUM = $lang['created'];
977    }
978  }
979
980  //no text? Load it!
981  if(!isset($text)){
982    $pr = false; //no preview mode
983    if($RANGE){
984      list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
985    }else{
986      $text = rawWiki($ID,$REV);
987    }
988  }else{
989    $pr = true; //preview mode
990  }
991
992  $wr = $INFO['writable'];
993  if($wr){
994    if ($REV) print parsedLocale('editrev');
995    print parsedLocale($include);
996  }else{
997    print parsedLocale('read');
998    $ro='readonly="readonly"';
999  }
1000  if(!$DATE) $DATE = $INFO['lastmod'];
1001?>
1002  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" onsubmit="return svchk()">
1003  <input type="hidden" name="id"   value="<?=$ID?>" />
1004  <input type="hidden" name="rev"  value="<?=$REV?>" />
1005  <input type="hidden" name="date" value="<?=$DATE?>" />
1006  <input type="hidden" name="prefix" value="<?=formText($PRE)?>" />
1007  <input type="hidden" name="suffix" value="<?=formText($SUF)?>" />
1008  <table style="width:99%">
1009    <tr>
1010      <td class="toolbar" colspan="3">
1011        <?if($wr){?>
1012        <script language="JavaScript" type="text/javascript">
1013          <?/* sets changed to true when previewed */?>
1014          textChanged = <? ($pr) ? print 'true' : print 'false' ?>;
1015
1016          formatButton('images/bold.png','<?=$lang['qb_bold']?>','**','**','<?=$lang['qb_bold']?>','b');
1017          formatButton('images/italic.png','<?=$lang['qb_italic']?>',"\/\/","\/\/",'<?=$lang['qb_italic']?>','i');
1018          formatButton('images/underline.png','<?=$lang['qb_underl']?>','__','__','<?=$lang['qb_underl']?>','u');
1019          formatButton('images/code.png','<?=$lang['qb_code']?>','\'\'','\'\'','<?=$lang['qb_code']?>','c');
1020
1021          formatButton('images/fonth1.png','<?=$lang['qb_h1']?>','====== ',' ======\n','<?=$lang['qb_h1']?>','1');
1022          formatButton('images/fonth2.png','<?=$lang['qb_h2']?>','===== ',' =====\n','<?=$lang['qb_h2']?>','2');
1023          formatButton('images/fonth3.png','<?=$lang['qb_h3']?>','==== ',' ====\n','<?=$lang['qb_h3']?>','3');
1024          formatButton('images/fonth4.png','<?=$lang['qb_h4']?>','=== ',' ===\n','<?=$lang['qb_h4']?>','4');
1025          formatButton('images/fonth5.png','<?=$lang['qb_h5']?>','== ',' ==\n','<?=$lang['qb_h5']?>','5');
1026
1027          formatButton('images/link.png','<?=$lang['qb_link']?>','[[',']]','<?=$lang['qb_link']?>','l');
1028          formatButton('images/extlink.png','<?=$lang['qb_extlink']?>','[[',']]','http://www.example.com|<?=$lang['qb_extlink']?>');
1029
1030          formatButton('images/list.png','<?=$lang['qb_ol']?>','  - ','\n','<?=$lang['qb_ol']?>');
1031          formatButton('images/list_ul.png','<?=$lang['qb_ul']?>','  * ','\n','<?=$lang['qb_ul']?>');
1032
1033          insertButton('images/rule.png','<?=$lang['qb_hr']?>','----\n');
1034          mediaButton('images/image.png','<?=$lang['qb_media']?>','m','<?=$INFO['namespace']?>');
1035
1036          <?
1037          if($conf['useacl'] && $_SERVER['REMOTE_USER']){
1038            echo "insertButton('images/sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
1039          }
1040          ?>
1041        </script>
1042        <?}?>
1043      </td>
1044    </tr>
1045    <tr>
1046      <td colspan="3">
1047        <textarea name="wikitext" id="wikitext" <?=$ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" tabindex="1"><?="\n".formText($text)?></textarea>
1048      </td>
1049    </tr>
1050    <tr>
1051      <td>
1052      <?if($wr){?>
1053        <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" />
1054        <input class="button" type="submit" name="do" value="<?=$lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" />
1055        <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" tabindex="5" />
1056      <?}?>
1057      </td>
1058      <td>
1059      <?if($wr){?>
1060        <?=$lang['summary']?>:
1061        <input type="text" class="edit" name="summary" size="50" value="<?=formText($SUM)?>" tabindex="2" />
1062      <?}?>
1063      </td>
1064      <td align="right">
1065        <script type="text/javascript">
1066          showSizeCtl();
1067          <?if($wr){?>
1068            init_locktimer(<?=$conf['locktime']-60?>,'<?=$lang['willexpire']?>');
1069            document.editform.wikitext.focus();
1070          <?}?>
1071        </script>
1072      </td>
1073    </tr>
1074  </table>
1075  </form>
1076<?
1077}
1078
1079/**
1080 * prepares the signature string as configured in the config
1081 *
1082 * @author Andreas Gohr <andi@splitbrain.org>
1083 */
1084function html_signature(){
1085  global $conf;
1086  global $INFO;
1087
1088  $sig = $conf['signature'];
1089  $sig = strftime($sig);
1090  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
1091  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
1092  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
1093  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
1094  return $sig;
1095}
1096
1097/**
1098 * prints some debug info
1099 *
1100 * @author Andreas Gohr <andi@splitbrain.org>
1101 */
1102function html_debug(){
1103  global $conf;
1104  global $lang;
1105  //remove sensitive data
1106  $cnf = $conf;
1107  $cnf['auth']='***';
1108  $cnf['notify']='***';
1109
1110  print '<html><body>';
1111
1112  print '<p>When reporting bugs please send all the following ';
1113  print 'output as a mail to andi@splitbrain.org ';
1114  print 'The best way to do this is to save this page in your browser</p>';
1115
1116  print '<b>$_SERVER:</b><pre>';
1117  print_r($_SERVER);
1118  print '</pre>';
1119
1120  print '<b>$conf:</b><pre>';
1121  print_r($cnf);
1122  print '</pre>';
1123
1124  print '<b>abs baseURL:</b><pre>';
1125  print getBaseURL(true);
1126  print '</pre>';
1127
1128  print '<b>rel baseURL:</b><pre>';
1129  print dirname($_SERVER['PHP_SELF']).'/';
1130  print '</pre>';
1131
1132  print '<b>PHP Version:</b><pre>';
1133  print phpversion();
1134  print '</pre>';
1135
1136  print '<b>locale:</b><pre>';
1137  print setlocale(LC_ALL,0);
1138  print '</pre>';
1139
1140  print '<b>encoding:</b><pre>';
1141  print $lang['encoding'];
1142  print '</pre>';
1143
1144  print '<b>Environment:</b><pre>';
1145  print_r($_ENV);
1146  print '</pre>';
1147
1148  print '<b>PHP settings:</b><pre>';
1149  $inis = ini_get_all();
1150  print_r($inis);
1151  print '</pre>';
1152
1153  print '</body></html>';
1154}
1155
1156?>
1157