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