xref: /dokuwiki/inc/html.php (revision 729c3d2ed88cf36d2ade93acc5695e81427b43c9)
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" id="dw__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[recover]" value="<?php echo $lang['btn_recover']?>" tabindex="1" />
301    <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_draftdel']?>" tabindex="2" />
302    <input class="button" type="submit" name="do[show]" 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
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    if($REV){
827      $r = $REV;
828    }else{
829      //use last revision if none given
830      $revs = getRevisions($ID, 0, 1);
831      $r = $revs[0];
832    }
833
834    if($r){
835      $df  = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,$r))),
836                      explode("\n",htmlspecialchars(rawWiki($ID,''))));
837      $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
838                $ID.' '.date($conf['dformat'],$r).'</a>';
839    }else{
840      $df  = new Diff(array(''),
841                      explode("\n",htmlspecialchars(rawWiki($ID,''))));
842      $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
843                $ID.'</a>';
844    }
845    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
846              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
847              $lang['current'];
848  }
849  $tdf = new TableDiffFormatter();
850  if($intro) print p_locale_xhtml('diff');
851  ?>
852    <table class="diff">
853      <tr>
854        <th colspan="2">
855          <?php echo $left?>
856        </th>
857        <th colspan="2">
858          <?php echo $right?>
859        </th>
860      </tr>
861      <?php echo $tdf->format($df)?>
862    </table>
863  <?php
864}
865
866/**
867 * show warning on conflict detection
868 *
869 * @author Andreas Gohr <andi@splitbrain.org>
870 */
871function html_conflict($text,$summary){
872  global $ID;
873  global $lang;
874
875  print p_locale_xhtml('conflict');
876  ?>
877  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
878  <div class="centeralign">
879    <input type="hidden" name="id" value="<?php echo $ID?>" />
880    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
881    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
882
883    <input class="button" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" />
884    <input class="button" type="submit" name="do[cancel]" value="<?php echo $lang['btn_cancel']?>" />
885  </div>
886  </form>
887  <br /><br /><br /><br />
888  <?php
889}
890
891/**
892 * Prints the global message array
893 *
894 * @author Andreas Gohr <andi@splitbrain.org>
895 */
896function html_msgarea(){
897  global $MSG;
898
899  if(!isset($MSG)) return;
900
901  foreach($MSG as $msg){
902    print '<div class="'.$msg['lvl'].'">';
903    print $msg['msg'];
904    print '</div>';
905  }
906}
907
908/**
909 * Prints the registration form
910 *
911 * @author Andreas Gohr <andi@splitbrain.org>
912 */
913function html_register(){
914  global $lang;
915  global $conf;
916  global $ID;
917
918  print p_locale_xhtml('register');
919?>
920  <div class="centeralign">
921  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
922  <fieldset>
923    <input type="hidden" name="do" value="register" />
924    <input type="hidden" name="save" value="1" />
925
926    <legend><?php echo $lang['register']?></legend>
927    <label class="block">
928      <?php echo $lang['user']?>
929      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
930    </label><br />
931
932    <?php
933      if (!$conf['autopasswd']) {
934    ?>
935      <label class="block">
936        <?php echo $lang['pass']?>
937        <input type="password" name="pass" class="edit" size="50" />
938      </label><br />
939      <label class="block">
940        <?php echo $lang['passchk']?>
941        <input type="password" name="passchk" class="edit" size="50" />
942      </label><br />
943    <?php
944      }
945    ?>
946
947    <label class="block">
948      <?php echo $lang['fullname']?>
949      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
950    </label><br />
951    <label class="block">
952      <?php echo $lang['email']?>
953      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
954    </label><br />
955    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
956  </fieldset>
957  </form>
958  </div>
959<?php
960}
961
962/**
963 * Print the update profile form
964 *
965 * @author Christopher Smith <chris@jalakai.co.uk>
966 * @author Andreas Gohr <andi@splitbrain.org>
967 */
968function html_updateprofile(){
969  global $lang;
970  global $conf;
971  global $ID;
972  global $INFO;
973  global $auth;
974
975  print p_locale_xhtml('updateprofile');
976
977  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
978  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
979?>
980  <div class="centeralign">
981  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
982  <fieldset style="width: 80%;">
983    <input type="hidden" name="do" value="profile" />
984    <input type="hidden" name="save" value="1" />
985
986    <legend><?php echo $lang['profile']?></legend>
987    <label class="block">
988      <?php echo $lang['user']?>
989      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
990    </label><br />
991    <label class="block">
992      <?php echo $lang['fullname']?>
993      <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
994    </label><br />
995    <label class="block">
996      <?php echo $lang['email']?>
997      <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
998    </label><br /><br />
999
1000    <?php if($auth->canDo('modPass')) { ?>
1001    <label class="block">
1002      <?php echo $lang['newpass']?>
1003      <input type="password" name="newpass" class="edit" size="50" />
1004    </label><br />
1005    <label class="block">
1006      <?php echo $lang['passchk']?>
1007      <input type="password" name="passchk" class="edit" size="50" />
1008    </label><br />
1009    <?php } ?>
1010
1011    <?php if ($conf['profileconfirm']) { ?>
1012      <br />
1013      <label class="block">
1014      <?php echo $lang['oldpass']?>
1015      <input type="password" name="oldpass" class="edit" size="50" />
1016    </label><br />
1017    <?php } ?>
1018
1019    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
1020    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
1021  </fieldset>
1022  </form>
1023  </div>
1024<?php
1025}
1026
1027/**
1028 * This displays the edit form (lots of logic included)
1029 *
1030 * @fixme    this is a huge lump of code and should be modularized
1031 * @triggers HTML_PAGE_FROMTEMPLATE
1032 * @author   Andreas Gohr <andi@splitbrain.org>
1033 */
1034function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1035  global $ID;
1036  global $REV;
1037  global $DATE;
1038  global $RANGE;
1039  global $PRE;
1040  global $SUF;
1041  global $INFO;
1042  global $SUM;
1043  global $lang;
1044  global $conf;
1045
1046  //set summary default
1047  if(!$SUM){
1048    if($REV){
1049      $SUM = $lang['restored'];
1050    }elseif(!$INFO['exists']){
1051      $SUM = $lang['created'];
1052    }
1053  }
1054
1055  //no text? Load it!
1056  if(!isset($text)){
1057    $pr = false; //no preview mode
1058    if($INFO['exists']){
1059      if($RANGE){
1060        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1061      }else{
1062        $text = rawWiki($ID,$REV);
1063      }
1064    }else{
1065      //try to load a pagetemplate
1066      $data = array($ID);
1067      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1068    }
1069  }else{
1070    $pr = true; //preview mode
1071  }
1072
1073  $wr = $INFO['writable'];
1074  if($wr){
1075    if ($REV) print p_locale_xhtml('editrev');
1076    print p_locale_xhtml($include);
1077    $ro=false;
1078  }else{
1079    // check pseudo action 'source'
1080    if(!actionOK('source')){
1081      msg('Command disabled: source',-1);
1082      return;
1083    }
1084    print p_locale_xhtml('read');
1085    $ro='readonly="readonly"';
1086  }
1087  if(!$DATE) $DATE = $INFO['lastmod'];
1088
1089
1090?>
1091  <div style="width:99%;">
1092
1093   <div class="toolbar">
1094      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.date($conf['dformat']);?></div>
1095      <div id="tool__bar"><?php if(!$ro){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1096      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1097
1098      <?php if($wr){?>
1099      <script type="text/javascript" charset="utf-8">
1100        <?php /* sets changed to true when previewed */?>
1101        textChanged = <?php ($pr) ? print 'true' : print 'false' ?>;
1102      </script>
1103      <span id="spell__action"></span>
1104      <div id="spell__suggest"></div>
1105      <?php } ?>
1106   </div>
1107   <div id="spell__result"></div>
1108
1109
1110   <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">
1111      <input type="hidden" name="id"   value="<?php echo $ID?>" />
1112      <input type="hidden" name="rev"  value="<?php echo $REV?>" />
1113      <input type="hidden" name="date" value="<?php echo $DATE?>" />
1114      <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
1115      <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
1116    </div>
1117
1118    <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
1119
1120    <div id="wiki__editbar">
1121      <div id="size__ctl"></div>
1122      <?php if($wr){?>
1123         <div class="editButtons">
1124            <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" />
1125            <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" />
1126            <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="6" />
1127         </div>
1128      <?php } ?>
1129      <?php if($wr){ ?>
1130        <div class="summary">
1131           <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label>
1132           <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1133           <?php html_minoredit()?>
1134        </div>
1135      <?php }?>
1136    </div>
1137  </form>
1138  </div>
1139<?php
1140}
1141
1142/**
1143 * Adds a checkbox for minor edits for logged in users
1144 *
1145 * @author Andrea Gohr <andi@splitbrain.org>
1146 */
1147function html_minoredit(){
1148  global $conf;
1149  global $lang;
1150  // minor edits are for logged in users only
1151  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1152    return;
1153  }
1154
1155  $p = array();
1156  $p['name']     = 'minor';
1157  $p['type']     = 'checkbox';
1158  $p['id']       = 'minoredit';
1159  $p['tabindex'] = 3;
1160  $p['value']    = '1';
1161  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1162  $att = buildAttributes($p);
1163
1164  print '<span class="nowrap">';
1165  print "<input $att />";
1166  print '<label for="minoredit">';
1167  print $lang['minoredit'];
1168  print '</label>';
1169  print '</span>';
1170}
1171
1172/**
1173 * prints some debug info
1174 *
1175 * @author Andreas Gohr <andi@splitbrain.org>
1176 */
1177function html_debug(){
1178  global $conf;
1179  global $lang;
1180  global $auth;
1181  global $INFO;
1182
1183  //remove sensitive data
1184  $cnf = $conf;
1185  $cnf['auth']='***';
1186  $cnf['notify']='***';
1187  $cnf['ftp']='***';
1188  $nfo = $INFO;
1189  $nfo['userinfo'] = '***';
1190  $ses = $_SESSION;
1191  $ses[$conf['title']]['auth'] = '***';
1192
1193  print '<html><body>';
1194
1195  print '<p>When reporting bugs please send all the following ';
1196  print 'output as a mail to andi@splitbrain.org ';
1197  print 'The best way to do this is to save this page in your browser</p>';
1198
1199  print '<b>$INFO:</b><pre>';
1200  print_r($nfo);
1201  print '</pre>';
1202
1203  print '<b>$_SERVER:</b><pre>';
1204  print_r($_SERVER);
1205  print '</pre>';
1206
1207  print '<b>$conf:</b><pre>';
1208  print_r($cnf);
1209  print '</pre>';
1210
1211  print '<b>DOKU_BASE:</b><pre>';
1212  print DOKU_BASE;
1213  print '</pre>';
1214
1215  print '<b>abs DOKU_BASE:</b><pre>';
1216  print DOKU_URL;
1217  print '</pre>';
1218
1219  print '<b>rel DOKU_BASE:</b><pre>';
1220  print dirname($_SERVER['PHP_SELF']).'/';
1221  print '</pre>';
1222
1223  print '<b>PHP Version:</b><pre>';
1224  print phpversion();
1225  print '</pre>';
1226
1227  print '<b>locale:</b><pre>';
1228  print setlocale(LC_ALL,0);
1229  print '</pre>';
1230
1231  print '<b>encoding:</b><pre>';
1232  print $lang['encoding'];
1233  print '</pre>';
1234
1235  if($auth){
1236    print '<b>Auth backend capabilities:</b><pre>';
1237    print_r($auth->cando);
1238    print '</pre>';
1239  }
1240
1241  print '<b>$_SESSION:</b><pre>';
1242  print_r($ses);
1243  print '</pre>';
1244
1245  print '<b>Environment:</b><pre>';
1246  print_r($_ENV);
1247  print '</pre>';
1248
1249  print '<b>PHP settings:</b><pre>';
1250  $inis = ini_get_all();
1251  print_r($inis);
1252  print '</pre>';
1253
1254  print '</body></html>';
1255}
1256
1257function html_admin(){
1258  global $ID;
1259  global $lang;
1260  global $conf;
1261
1262  print p_locale_xhtml('admin');
1263
1264  // build menu of admin functions from the plugins that handle them
1265  $pluginlist = plugin_list('admin');
1266  $menu = array();
1267  foreach ($pluginlist as $p) {
1268    if($obj =& plugin_load('admin',$p) === NULL) continue;
1269    $menu[] = array('plugin' => $p,
1270                    'prompt' => $obj->getMenuText($conf['lang']),
1271                    'sort' => $obj->getMenuSort()
1272                   );
1273  }
1274
1275  usort($menu, 'p_sort_modes');
1276
1277  // output the menu
1278  ptln('<ul>');
1279
1280  foreach ($menu as $item) {
1281    if (!$item['prompt']) continue;
1282    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1283  }
1284
1285  ptln('</ul>');
1286}
1287
1288/**
1289 * Form to request a new password for an existing account
1290 *
1291 * @author Benoit Chesneau <benoit@bchesneau.info>
1292 */
1293function html_resendpwd() {
1294  global $lang;
1295  global $conf;
1296  global $ID;
1297
1298  print p_locale_xhtml('resendpwd');
1299?>
1300  <div class="centeralign">
1301  <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
1302    <fieldset>
1303      <br />
1304      <legend><?php echo $lang['resendpwd']?></legend>
1305      <input type="hidden" name="do" value="resendpwd" />
1306      <input type="hidden" name="save" value="1" />
1307      <label class="block">
1308        <span><?php echo $lang['user']?></span>
1309        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
1310      </label><br />
1311      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
1312    </fieldset>
1313  </form>
1314  </div>
1315<?php
1316}
1317
1318//Setup VIM: ex: et ts=2 enc=utf-8 :
1319