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