xref: /dokuwiki/inc/html.php (revision 825ec23293e024eec12550b41e87d006e9419248)
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['locked']){
384      print ' &middot; ';
385      print $lang['lockedby'];
386      print ': ';
387      print $INFO['locked'];
388    }
389  }
390  print '</div>';
391}
392
393/**
394 * Diplay the overall footer
395 *
396 * @author Andreas Gohr <andi@splitbrain.org>
397 */
398function html_footer(){
399  global $ID;
400  global $REV;
401  global $INFO;
402  global $lang;
403  global $conf;
404?>
405  <!-- wikipage stop -->
406  </div>
407  <div class="clearer">&nbsp;</div>
408  <div class="stylefoot">
409    <?
410      flush();
411      @include("includes/pagefooter.html");
412      html_metainfo();
413    ?>
414    <div class="bar" id="bar_bottom">
415      <div class="bar-left" id="bar_bottomleft">
416        <?=html_editbutton()?>
417        <?=html_btn(revs,$ID,'r',array('do' => 'revisions'))?>
418      </div>
419
420      <div class="bar-right" id="bar_bottomright">
421        <?
422          if($conf['useacl']){
423            if($_SERVER['REMOTE_USER']){
424              print html_btn('logout',$ID,'',array('do' => 'logout',));
425            }else{
426              print html_btn('login',$ID,'',array('do' => 'login'));
427            }
428          }
429        ?>
430        <?=html_btn(index,$ID,'x',array('do' => 'index'))?>
431        <a href="#top"><input type="button" class="button" value="<?=$lang['btn_top']?>" /></a>&nbsp;
432      </div>
433    </div>
434  </div>
435  <?@include("includes/footer.html")?>
436  </div>
437  </body>
438  </html>
439<?
440}
441
442/**
443 * Print the table of contents
444 *
445 * @author Andreas Gohr <andi@splitbrain.org>
446 */
447function html_toc($toc){
448  global $lang;
449  $ret  = '';
450  $ret .= '<div class="toc">';
451  $ret .=   '<div class="tocheader">';
452  $ret .=      $lang['toc'];
453  $ret .=     ' <script type="text/javascript">';
454  $ret .=     'showTocToggle("+","-")';
455  $ret .=     '</script>';
456  $ret .=   '</div>';
457  $ret .=   '<div id="tocinside">';
458  $ret .=   html_buildlist($toc,'toc','html_list_toc');
459  $ret .=   '</div>';
460  $ret .= '</div>';
461  return $ret;
462}
463
464/**
465 * TOC item formatter
466 *
467 * User function for html_buildlist()
468 *
469 * @author Andreas Gohr <andi@splitbrain.org>
470 */
471function html_list_toc($item){
472  $ret  = '';
473  $ret .= '<a href="#'.$item['id'].'" class="toc">';
474  $ret .= $item['name'];
475  $ret .= '</a>';
476  return $ret;
477}
478
479/**
480 * show a wiki page
481 *
482 * @author Andreas Gohr <andi@splitbrain.org>
483 */
484function html_show($text=''){
485  global $ID;
486  global $REV;
487  global $HIGH;
488  //disable section editing for old revisions or in preview
489  if($text || $REV){
490    global $parser;
491    $parser['secedit'] = false;
492  }
493
494  if ($text){
495    //PreviewHeader
496    print parsedLocale('preview');
497    print '<div class="preview">';
498    print html_secedit(parse($text),false);
499    print '</div>';
500  }else{
501    if ($REV) print parsedLocale('showrev');
502    $html = parsedWiki($ID,$REV,true);
503    $html = html_secedit($html);
504    print html_hilight($html,$HIGH);
505  }
506}
507
508/**
509 * Highlights searchqueries in HTML code
510 *
511 * @author Andreas Gohr <andi@splitbrain.org>
512 */
513function html_hilight($html,$query){
514  $queries = preg_split ("/\s/",$query,-1,PREG_SPLIT_NO_EMPTY);
515  foreach ($queries as $q){
516    $q = preg_quote($q,'/');
517    $html = preg_replace("/((<[^>]*)|$q)/ie", '"\2"=="\1"? "\1":"<span class=\"search_hit\">\1</span>"', $html);
518  }
519  return $html;
520}
521
522/**
523 * Run a search and display the result
524 *
525 * @author Andreas Gohr <andi@splitbrain.org>
526 */
527function html_search(){
528  require_once("inc/search.php");
529  global $conf;
530  global $QUERY;
531  global $ID;
532  global $lang;
533
534  print parsedLocale('searchpage');
535  flush();
536
537  //do quick pagesearch
538  $data = array();
539  search($data,$conf['datadir'],'search_pagename',array(query => cleanID($QUERY)));
540  if(count($data)){
541    sort($data);
542    print '<div class="search_quickresult">';
543    print '<b>'.$lang[quickhits].':</b><br />';
544    foreach($data as $row){
545      print '<div class="search_quickhits">';
546      print html_wikilink(':'.$row['id'],$row['id']);
547      print '</div> ';
548    }
549    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
550    print '<div class="clearer">&nbsp;</div>';
551    print '</div>';
552  }
553  flush();
554
555  //do fulltext search
556  $data = array();
557  search($data,$conf['datadir'],'search_fulltext',array(query => utf8_strtolower($QUERY)));
558  if(count($data)){
559    usort($data,'sort_search_fulltext');
560    foreach($data as $row){
561      print '<div class="search_result">';
562      print html_wikilink(':'.$row['id'],$row['id'],$QUERY);
563      print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
564      print '<div class="search_snippet">'.$row['snippet'].'</div>';
565      print '</div>';
566    }
567  }else{
568    print '<div align="center">'.$lang['nothingfound'].'</div>';
569  }
570}
571
572/**
573 * Display error on locked pages
574 *
575 * @author Andreas Gohr <andi@splitbrain.org>
576 */
577function html_locked($ip){
578  global $ID;
579  global $conf;
580  global $lang;
581
582  $locktime = filemtime(wikiFN($ID).'.lock');
583  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
584  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
585
586  print parsedLocale('locked');
587  print '<ul>';
588  print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>';
589  print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>';
590  print '</ul>';
591}
592
593/**
594 * list old revisions
595 *
596 * @author Andreas Gohr <andi@splitbrain.org>
597 */
598function html_revisions(){
599  global $ID;
600  global $INFO;
601  global $conf;
602  global $lang;
603  $revisions = getRevisions($ID);
604  $date = @date($conf['dformat'],$INFO['lastmod']);
605
606  print parsedLocale('revisions');
607  print '<ul>';
608  if($INFO['exists']){
609    print '<li>'.$date.' <a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ('.$lang['current'].')</li>';
610  }
611
612  foreach($revisions as $rev){
613    $date = date($conf['dformat'],$rev);
614    print '<li>';
615    print $date.' <a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
616    print '<a href="'.wl($ID,"rev=$rev,do=diff").'">['.$lang['diff'].']</a>';
617    print '</li>';
618  }
619  print '</ul>';
620}
621
622/**
623 * display recent changes
624 *
625 * @author Andreas Gohr <andi@splitbrain.org>
626 */
627function html_recent(){
628  global $conf;
629  $recents = getRecents(0,true);
630
631  print parsedLocale('recent');
632  print '<ul>';
633  foreach(array_keys($recents) as $id){
634    $date = date($conf['dformat'],$recents[$id]['date']);
635    print '<li>';
636    print $date.' '.html_wikilink($id,$id);
637    print ' '.htmlspecialchars($recents[$id]['sum']);
638    print ' <span class="user">(';
639    print $recents[$id]['ip'];
640    if($recents[$id]['user']) print ' '.$recents[$id]['user'];
641    print ')</span>';
642    print '</li>';
643  }
644  print '</ul>';
645}
646
647/**
648 * Display page index
649 *
650 * @author Andreas Gohr <andi@splitbrain.org>
651 */
652function html_index($ns){
653  require_once("inc/search.php");
654  global $conf;
655  global $ID;
656  $dir = $conf['datadir'];
657  $ns  = cleanID($ns);
658  if(empty($ns)){
659    $ns = dirname(str_replace(':','/',$ID));
660    if($ns == '.') $ns ='';
661  }
662  $ns  = str_replace(':','/',$ns);
663
664  print parsedLocale('index');
665
666  $data = array();
667  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
668  print html_buildlist($data,'idx','html_list_index','html_li_index');
669}
670
671/**
672 * Index item formatter
673 *
674 * User function for html_buildlist()
675 *
676 * @author Andreas Gohr <andi@splitbrain.org>
677 */
678function html_list_index($item){
679  $ret = '';
680  $base = ':'.$item['id'];
681  $base = substr($base,strrpos($base,':')+1);
682  if($item['type']=='d'){
683    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
684    $ret .= $base;
685    $ret .= '</a>';
686  }else{
687    $ret .= html_wikilink(':'.$item['id']);
688  }
689  return $ret;
690}
691
692/**
693 * Index List item
694 *
695 * This user function is used in html_build_lidt to build the
696 * <li> tags for namespaces when displaying the page index
697 * it gives different classes to opened or closed "folders"
698 *
699 * @author Andreas Gohr <andi@splitbrain.org>
700 */
701function html_li_index($item){
702  if($item['type'] == "f"){
703    return '<li class="level'.$item['level'].'">';
704  }elseif($item['open']){
705    return '<li class="open">';
706  }else{
707    return '<li class="closed">';
708  }
709}
710
711/**
712 * Default List item
713 *
714 * @author Andreas Gohr <andi@splitbrain.org>
715 */
716function html_li_default($item){
717  return '<li class="level'.$item['level'].'">';
718}
719
720/**
721 * Build an unordered list
722 *
723 * Build an unordered list from the given $data array
724 * Each item in the array has to have a 'level' property
725 * the item itself gets printed by the given $func user
726 * function. The second and optional function is used to
727 * print the <li> tag. Both user function need to accept
728 * a single item.
729 *
730 * @author Andreas Gohr <andi@splitbrain.org>
731 */
732function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
733  $level = 0;
734  $opens = 0;
735  $ret   = '';
736
737  foreach ($data as $item){
738
739    if( $item['level'] > $level ){
740      //open new list
741      $ret .= "\n<ul class=\"$class\">\n";
742    }elseif( $item['level'] < $level ){
743      //close last item
744      $ret .= "</li>\n";
745      for ($i=0; $i<($level - $item['level']); $i++){
746        //close higher lists
747        $ret .= "</ul>\n</li>\n";
748      }
749    }else{
750      //close last item
751      $ret .= "</li>\n";
752    }
753
754    //remember current level
755    $level = $item['level'];
756
757    //print item
758    $ret .= $lifunc($item); //user function
759    $ret .= '<span class="li">';
760    $ret .= $func($item); //user function
761    $ret .= '</span>';
762  }
763
764  //close remaining items and lists
765  for ($i=0; $i < $level; $i++){
766    $ret .= "</li></ul>\n";
767  }
768
769  return $ret;
770}
771
772/**
773 * display backlinks
774 *
775 * @author Andreas Gohr <andi@splitbrain.org>
776 */
777function html_backlinks(){
778  require_once("inc/search.php");
779  global $ID;
780  global $conf;
781
782  if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
783    $opts['ns']   = $matches[1];
784    $opts['name'] = $matches[2];
785  }else{
786    $opts['ns']   = '';
787    $opts['name'] = $ID;
788  }
789
790  print parsedLocale('backlinks');
791
792  $data = array();
793  search($data,$conf['datadir'],'search_backlinks',$opts);
794  sort($data);
795
796  print '<ul class="idx">';
797  foreach($data as $row){
798    print '<li>';
799    print html_wikilink(':'.$row['id'],$row['id']);
800    print '</li>';
801  }
802  print '</ul>';
803}
804
805/**
806 * show diff
807 *
808 * @author Andreas Gohr <andi@splitbrain.org>
809 */
810function html_diff($text='',$intro=true){
811  require_once("inc/DifferenceEngine.php");
812  global $ID;
813  global $REV;
814  global $lang;
815  global $conf;
816  if($text){
817    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
818                    split("\n",htmlspecialchars(cleanText($text))));
819    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
820              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
821              $lang['current'];
822    $right = $lang['yours'];
823  }else{
824    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$REV))),
825                    split("\n",htmlspecialchars(rawWiki($ID,''))));
826    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$REV").'">'.
827              $ID.' '.date($conf['dformat'],$REV).'</a>';
828    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
829              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
830              $lang['current'];
831  }
832  $tdf = new TableDiffFormatter();
833  if($intro) print parsedLocale('diff');
834  ?>
835    <table class="diff" width="100%">
836      <tr>
837        <td colspan="2" width="50%" class="diff-header">
838          <?=$left?>
839        </td>
840        <td colspan="2" width="50%" class="diff-header">
841          <?=$right?>
842        </td>
843      </tr>
844      <?=$tdf->format($df)?>
845    </table>
846  <?
847}
848
849/**
850 * show warning on conflict detection
851 *
852 * @author Andreas Gohr <andi@splitbrain.org>
853 */
854function html_conflict($text,$summary){
855  global $ID;
856  global $lang;
857
858  print parsedLocale('conflict');
859  ?>
860  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
861  <input type="hidden" name="id" value="<?=$ID?>" />
862  <input type="hidden" name="wikitext" value="<?=formText($text)?>" />
863  <input type="hidden" name="summary" value="<?=formText($summary)?>" />
864
865  <div align="center">
866    <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
867    <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" />
868  </div>
869  </form>
870  <br /><br /><br /><br />
871  <?
872}
873
874/**
875 * Prints the global message array
876 *
877 * @author Andreas Gohr <andi@splitbrain.org>
878 */
879function html_msgarea(){
880  global $MSG;
881
882  if(!isset($MSG)) return;
883
884  foreach($MSG as $msg){
885    print '<div class="'.$msg['lvl'].'">';
886    print $msg['msg'];
887    print '</div>';
888  }
889}
890
891/**
892 * Prints the registration form
893 *
894 * @author Andreas Gohr <andi@splitbrain.org>
895 */
896function html_register(){
897  global $lang;
898  global $ID;
899
900  print parsedLocale('register');
901?>
902  <div align="center">
903  <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
904  <input type="hidden" name="do" value="register" />
905  <input type="hidden" name="save" value="1" />
906  <fieldset>
907    <legend><?=$lang['register']?></legend>
908    <label>
909      <?=$lang['user']?>
910      <input type="text" name="login" class="edit" size="50" value="<?=formText($_POST['login'])?>" />
911    </label><br />
912    <label>
913      <?=$lang['fullname']?>
914      <input type="text" name="fullname" class="edit" size="50" value="<?=formText($_POST['fullname'])?>" />
915    </label><br />
916    <label>
917      <?=$lang['email']?>
918      <input type="text" name="email" class="edit" size="50" value="<?=formText($_POST['email'])?>" />
919    </label><br />
920    <input type="submit" class="button" value="<?=$lang['register']?>" />
921  </fieldset>
922  </form>
923  </div>
924<?
925}
926
927/**
928 * This displays the edit form (lots of logic included)
929 *
930 * @author Andreas Gohr <andi@splitbrain.org>
931 */
932function html_edit($text=null,$include='edit'){ //FIXME: include needed?
933  global $ID;
934  global $REV;
935  global $DATE;
936  global $RANGE;
937  global $PRE;
938  global $SUF;
939  global $INFO;
940  global $SUM;
941  global $lang;
942  global $conf;
943
944  //check for create permissions first
945  if(!$INFO['exists'] && !html_acl(AUTH_CREATE)) return;
946
947  //set summary default
948  if(!$SUM){
949    if($REV){
950      $SUM = $lang['restored'];
951    }elseif(!$INFO['exists']){
952      $SUM = $lang['created'];
953    }
954  }
955
956  //no text? Load it!
957  if(!isset($text)){
958    $pr = false; //no preview mode
959    if($RANGE){
960      list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
961    }else{
962      $text = rawWiki($ID,$REV);
963    }
964  }else{
965    $pr = true; //preview mode
966  }
967
968  $wr = $INFO['writable'];
969  if($wr){
970    if ($REV) print parsedLocale('editrev');
971    print parsedLocale($include);
972  }else{
973    print parsedLocale('read');
974    $ro='readonly="readonly"';
975  }
976  if(!$DATE) $DATE = $INFO['lastmod'];
977?>
978  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" onsubmit="return svchk()">
979  <input type="hidden" name="id"   value="<?=$ID?>" />
980  <input type="hidden" name="rev"  value="<?=$REV?>" />
981  <input type="hidden" name="date" value="<?=$DATE?>" />
982  <input type="hidden" name="prefix" value="<?=formText($PRE)?>" />
983  <input type="hidden" name="suffix" value="<?=formText($SUF)?>" />
984  <table style="width:99%">
985    <tr>
986      <td class="toolbar" colspan="3">
987        <?if($wr){?>
988        <script language="JavaScript" type="text/javascript">
989          <?/* sets changed to true when previewed */?>
990          textChanged = <? ($pr) ? print 'true' : print 'false' ?>;
991
992          formatButton('images/bold.png','<?=$lang['qb_bold']?>','**','**','<?=$lang['qb_bold']?>','b');
993          formatButton('images/italic.png','<?=$lang['qb_italic']?>',"\/\/","\/\/",'<?=$lang['qb_italic']?>','i');
994          formatButton('images/underline.png','<?=$lang['qb_underl']?>','__','__','<?=$lang['qb_underl']?>','u');
995          formatButton('images/code.png','<?=$lang['qb_code']?>','\'\'','\'\'','<?=$lang['qb_code']?>','c');
996
997          formatButton('images/fonth1.png','<?=$lang['qb_h1']?>','====== ',' ======\n','<?=$lang['qb_h1']?>','1');
998          formatButton('images/fonth2.png','<?=$lang['qb_h2']?>','===== ',' =====\n','<?=$lang['qb_h2']?>','2');
999          formatButton('images/fonth3.png','<?=$lang['qb_h3']?>','==== ',' ====\n','<?=$lang['qb_h3']?>','3');
1000          formatButton('images/fonth4.png','<?=$lang['qb_h4']?>','=== ',' ===\n','<?=$lang['qb_h4']?>','4');
1001          formatButton('images/fonth5.png','<?=$lang['qb_h5']?>','== ',' ==\n','<?=$lang['qb_h5']?>','5');
1002
1003          formatButton('images/link.png','<?=$lang['qb_link']?>','[[',']]','<?=$lang['qb_link']?>','l');
1004          formatButton('images/extlink.png','<?=$lang['qb_extlink']?>','[[',']]','http://www.example.com|<?=$lang['qb_extlink']?>');
1005
1006          formatButton('images/list.png','<?=$lang['qb_ol']?>','  - ','\n','<?=$lang['qb_ol']?>');
1007          formatButton('images/list_ul.png','<?=$lang['qb_ul']?>','  * ','\n','<?=$lang['qb_ul']?>');
1008
1009          insertButton('images/rule.png','<?=$lang['qb_hr']?>','----\n');
1010          mediaButton('images/image.png','<?=$lang['qb_media']?>','m','<?=$INFO['namespace']?>');
1011
1012          <?
1013          if($conf['useacl'] && $_SERVER['REMOTE_USER']){
1014            echo "insertButton('images/sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
1015          }
1016          ?>
1017        </script>
1018        <?}?>
1019      </td>
1020    </tr>
1021    <tr>
1022      <td colspan="3">
1023        <textarea name="wikitext" id="wikitext" <?=$ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" tabindex="1"><?="\n".formText($text)?></textarea>
1024      </td>
1025    </tr>
1026    <tr>
1027      <td>
1028      <?if($wr){?>
1029        <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" />
1030        <input class="button" type="submit" name="do" value="<?=$lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" />
1031        <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" tabindex="5" />
1032      <?}?>
1033      </td>
1034      <td>
1035      <?if($wr){?>
1036        <?=$lang['summary']?>:
1037        <input type="text" class="edit" name="summary" size="50" value="<?=formText($SUM)?>" tabindex="2" />
1038      <?}?>
1039      </td>
1040      <td align="right">
1041        <script type="text/javascript">
1042          showSizeCtl();
1043          <?if($wr){?>
1044            init_locktimer(<?=$conf['locktime']-60?>,'<?=$lang['willexpire']?>');
1045            document.editform.wikitext.focus();
1046          <?}?>
1047        </script>
1048      </td>
1049    </tr>
1050  </table>
1051  </form>
1052<?
1053}
1054
1055/**
1056 * prepares the signature string as configured in the config
1057 *
1058 * @author Andreas Gohr <andi@splitbrain.org>
1059 */
1060function html_signature(){
1061  global $conf;
1062  global $INFO;
1063
1064  $sig = $conf['signature'];
1065  $sig = strftime($sig);
1066  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
1067  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
1068  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
1069  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
1070  return $sig;
1071}
1072
1073/**
1074 * prints some debug info
1075 *
1076 * @author Andreas Gohr <andi@splitbrain.org>
1077 */
1078function html_debug(){
1079  global $conf;
1080  global $lang;
1081  //remove sensitive data
1082  $cnf = $conf;
1083  $cnf['auth']='***';
1084  $cnf['notify']='***';
1085
1086  print '<html><body>';
1087
1088  print '<p>When reporting bugs please send all the following ';
1089  print 'output as a mail to andi@splitbrain.org ';
1090  print 'The best way to do this is to save this page in your browser</p>';
1091
1092  print '<b>$_SERVER:</b><pre>';
1093  print_r($_SERVER);
1094  print '</pre>';
1095
1096  print '<b>$conf:</b><pre>';
1097  print_r($cnf);
1098  print '</pre>';
1099
1100  print '<b>abs baseURL:</b><pre>';
1101  print getBaseURL(true);
1102  print '</pre>';
1103
1104  print '<b>rel baseURL:</b><pre>';
1105  print dirname($_SERVER['PHP_SELF']).'/';
1106  print '</pre>';
1107
1108  print '<b>PHP Version:</b><pre>';
1109  print phpversion();
1110  print '</pre>';
1111
1112  print '<b>locale:</b><pre>';
1113  print setlocale(LC_ALL,0);
1114  print '</pre>';
1115
1116  print '<b>encoding:</b><pre>';
1117  print $lang['encoding'];
1118  print '</pre>';
1119
1120  print '<b>Environment:</b><pre>';
1121  print_r($_ENV);
1122  print '</pre>';
1123
1124  print '<b>PHP settings:</b><pre>';
1125  $inis = ini_get_all();
1126  print_r($inis);
1127  print '</pre>';
1128
1129  print '</body></html>';
1130}
1131
1132?>
1133