xref: /dokuwiki/inc/html.php (revision 672f99ce23ac7ec217f954a568d9b380f3c8f2a2)
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')) die('meh.');
10if(!defined('NL')) define('NL',"\n");
11require_once(DOKU_INC.'inc/parserutils.php');
12require_once(DOKU_INC.'inc/form.php');
13
14/**
15 * Convenience function to quickly build a wikilink
16 *
17 * @author Andreas Gohr <andi@splitbrain.org>
18 */
19function html_wikilink($id,$name=NULL,$search=''){
20  static $xhtml_renderer = NULL;
21  if(is_null($xhtml_renderer)){
22    require_once(DOKU_INC.'inc/parser/xhtml.php');
23    $xhtml_renderer = new Doku_Renderer_xhtml();
24  }
25
26  return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
27}
28
29/**
30 * Helps building long attribute lists
31 *
32 * @author Andreas Gohr <andi@splitbrain.org>
33 */
34function html_attbuild($attributes){
35  $ret = '';
36  foreach ( $attributes as $key => $value ) {
37    $ret .= $key.'="'.formtext($value).'" ';
38  }
39  return trim($ret);
40}
41
42/**
43 * The loginform
44 *
45 * @author   Andreas Gohr <andi@splitbrain.org>
46 */
47function html_login(){
48  global $lang;
49  global $conf;
50  global $ID;
51  global $auth;
52
53  print p_locale_xhtml('login');
54  print '<div class="centeralign">'.NL;
55  $form = new Doku_Form('dw__login');
56  $form->startFieldset($lang['btn_login']);
57  $form->addHidden('id', $ID);
58  $form->addHidden('do', 'login');
59  $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
60  $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
61  if($conf['rememberme']) {
62      $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
63  }
64  $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
65  $form->endFieldset();
66  html_form('login', $form);
67
68  if($auth && $auth->canDo('addUser') && actionOK('register')){
69    print '<p>';
70    print $lang['reghere'];
71    print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
72    print '</p>';
73  }
74
75  if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
76    print '<p>';
77    print $lang['pwdforget'];
78    print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
79    print '</p>';
80  }
81  print '</div>'.NL;
82}
83
84/**
85 * prints a section editing button
86 * used as a callback in html_secedit
87 *
88 * @author Andreas Gohr <andi@splitbrain.org>
89 */
90function html_secedit_button($matches){
91  global $ID;
92  global $INFO;
93
94  $section = $matches[2];
95  $name = $matches[1];
96
97  $secedit  = '';
98  $secedit .= '<div class="secedit">';
99  $secedit .= html_btn('secedit',$ID,'',
100                        array('do'      => 'edit',
101                              'lines'   => "$section",
102                              'rev' => $INFO['lastmod']),
103                              'post', $name);
104  $secedit .= '</div>';
105  return $secedit;
106}
107
108/**
109 * inserts section edit buttons if wanted or removes the markers
110 *
111 * @author Andreas Gohr <andi@splitbrain.org>
112 */
113function html_secedit($text,$show=true){
114  global $INFO;
115
116  if($INFO['writable'] && $show && !$INFO['rev']){
117    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
118                         'html_secedit_button', $text);
119  }else{
120    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
121  }
122
123  return $text;
124}
125
126/**
127 * Just the back to top button (in its own form)
128 *
129 * @author Andreas Gohr <andi@splitbrain.org>
130 */
131function html_topbtn(){
132  global $lang;
133
134  $ret  = '';
135  $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>';
136
137  return $ret;
138}
139
140/**
141 * Displays a button (using its own form)
142 * If tooltip exists, the access key tooltip is replaced.
143 *
144 * @author Andreas Gohr <andi@splitbrain.org>
145 */
146function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
147  global $conf;
148  global $lang;
149
150  $label = $lang['btn_'.$name];
151
152  $ret = '';
153  $tip = '';
154
155  //filter id (without urlencoding)
156  $id = idfilter($id,false);
157
158  //make nice URLs even for buttons
159  if($conf['userewrite'] == 2){
160    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
161  }elseif($conf['userewrite']){
162    $script = DOKU_BASE.$id;
163  }else{
164    $script = DOKU_BASE.DOKU_SCRIPT;
165    $params['id'] = $id;
166  }
167
168  $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
169
170  if(is_array($params)){
171    reset($params);
172    while (list($key, $val) = each($params)) {
173      $ret .= '<input type="hidden" name="'.$key.'" ';
174      $ret .= 'value="'.htmlspecialchars($val).'" />';
175    }
176  }
177
178  if ($tooltip!='') {
179      $tip = htmlspecialchars($tooltip);
180  }else{
181      $tip = htmlspecialchars($label);
182  }
183
184  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
185  if($akey){
186    $tip .= ' ['.strtoupper($akey).']';
187    $ret .= 'accesskey="'.$akey.'" ';
188  }
189  $ret .= 'title="'.$tip.'" ';
190  $ret .= '/>';
191  $ret .= '</div></form>';
192
193  return $ret;
194}
195
196/**
197 * show a wiki page
198 *
199 * @author Andreas Gohr <andi@splitbrain.org>
200 */
201function html_show($txt=''){
202  global $ID;
203  global $REV;
204  global $HIGH;
205  global $INFO;
206  //disable section editing for old revisions or in preview
207  if($txt || $REV){
208    $secedit = false;
209  }else{
210    $secedit = true;
211  }
212
213  if ($txt){
214    //PreviewHeader
215    echo '<br id="scroll__here" />';
216    echo p_locale_xhtml('preview');
217    echo '<div class="preview">';
218    $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
219    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
220    echo $html;
221    echo '<div class="clearer"></div>';
222    echo '</div>';
223
224  }else{
225    if ($REV) print p_locale_xhtml('showrev');
226    $html = p_wiki_xhtml($ID,$REV,true);
227    $html = html_secedit($html,$secedit);
228    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
229    $html = html_hilight($html,$HIGH);
230    echo $html;
231  }
232}
233
234/**
235 * ask the user about how to handle an exisiting draft
236 *
237 * @author Andreas Gohr <andi@splitbrain.org>
238 */
239function html_draft(){
240  global $INFO;
241  global $ID;
242  global $lang;
243  global $conf;
244  $draft = unserialize(io_readFile($INFO['draft'],false));
245  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
246
247  print p_locale_xhtml('draft');
248  $form = new Doku_Form('dw__editform');
249  $form->addHidden('id', $ID);
250  $form->addHidden('date', $draft['date']);
251  $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
252  $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
253  $form->addElement($lang['draftdate'].' '. strftime($conf['dformat'],filemtime($INFO['draft'])));
254  $form->addElement(form_makeCloseTag('div'));
255  $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
256  $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
257  $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
258  html_form('draft', $form);
259}
260
261/**
262 * Highlights searchqueries in HTML code
263 *
264 * @author Andreas Gohr <andi@splitbrain.org>
265 * @author Harry Fuecks <hfuecks@gmail.com>
266 */
267function html_hilight($html,$phrases){
268  $regex = join('|',array_map('preg_quote_cb',array_filter((array) $phrases)));
269
270  if ($regex === '') return $html;
271  $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
272  return $html;
273}
274
275/**
276 * Callback used by html_hilight()
277 *
278 * @author Harry Fuecks <hfuecks@gmail.com>
279 */
280function html_hilight_callback($m) {
281  $hlight = unslash($m[0]);
282  if ( !isset($m[2])) {
283    $hlight = '<span class="search_hit">'.$hlight.'</span>';
284  }
285  return $hlight;
286}
287
288/**
289 * Run a search and display the result
290 *
291 * @author Andreas Gohr <andi@splitbrain.org>
292 */
293function html_search(){
294  require_once(DOKU_INC.'inc/search.php');
295  require_once(DOKU_INC.'inc/fulltext.php');
296  global $conf;
297  global $QUERY;
298  global $ID;
299  global $lang;
300
301  print p_locale_xhtml('searchpage');
302  flush();
303
304  //check if search is restricted to namespace
305  if(preg_match('/@([^@]*)/',$QUERY,$match)) {
306      $id = cleanID($match[1]);
307      if(empty($id)) {
308        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
309        flush();
310        return;
311      }
312  } else {
313      $id = cleanID($QUERY);
314  }
315
316  //show progressbar
317  print '<div class="centeralign" id="dw__loading">'.NL;
318  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
319  print 'showLoadBar();'.NL;
320  print '//--><!]]></script>'.NL;
321  print '<br /></div>'.NL;
322  flush();
323
324  //do quick pagesearch
325  $data = array();
326
327  $data = ft_pageLookup($id);
328  if(count($data)){
329    print '<div class="search_quickresult">';
330    print '<h3>'.$lang['quickhits'].':</h3>';
331    print '<ul class="search_quickhits">';
332    foreach($data as $id){
333      print '<li> ';
334      $ns = getNS($id);
335      if($ns){
336        $name = shorten(noNS($id), ' ('.$ns.')',30);
337      }else{
338        $name = $id;
339      }
340      print html_wikilink(':'.$id,$name);
341      print '</li> ';
342    }
343    print '</ul> ';
344    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
345    print '<div class="clearer">&nbsp;</div>';
346    print '</div>';
347  }
348  flush();
349
350  //do fulltext search
351  $data = ft_pageSearch($QUERY,$regex);
352  if(count($data)){
353    $num = 1;
354    foreach($data as $id => $cnt){
355      print '<div class="search_result">';
356      print html_wikilink(':'.$id,useHeading('navigation')?NULL:$id,$regex);
357      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
358      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
359        print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
360      }
361      print '</div>';
362      flush();
363      $num++;
364    }
365  }else{
366    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
367  }
368
369  //hide progressbar
370  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
371  print 'hideLoadBar("dw__loading");'.NL;
372  print '//--><!]]></script>'.NL;
373  flush();
374}
375
376/**
377 * Display error on locked pages
378 *
379 * @author Andreas Gohr <andi@splitbrain.org>
380 */
381function html_locked(){
382  global $ID;
383  global $conf;
384  global $lang;
385  global $INFO;
386
387  $locktime = filemtime(wikiLockFN($ID));
388  $expire = @strftime($conf['dformat'], $locktime + $conf['locktime'] );
389  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
390
391  print p_locale_xhtml('locked');
392  print '<ul>';
393  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</div></li>';
394  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
395  print '</ul>';
396}
397
398/**
399 * list old revisions
400 *
401 * @author Andreas Gohr <andi@splitbrain.org>
402 * @author Ben Coburn <btcoburn@silicodon.net>
403 */
404function html_revisions($first=0){
405  global $ID;
406  global $INFO;
407  global $conf;
408  global $lang;
409  /* we need to get one additionally log entry to be able to
410   * decide if this is the last page or is there another one.
411   * see html_recent()
412   */
413  $revisions = getRevisions($ID, $first, $conf['recent']+1);
414  if(count($revisions)==0 && $first!=0){
415    $first=0;
416    $revisions = getRevisions($ID, $first, $conf['recent']+1);;
417  }
418  $hasNext = false;
419  if (count($revisions)>$conf['recent']) {
420    $hasNext = true;
421    array_pop($revisions); // remove extra log entry
422  }
423
424  $date = @strftime($conf['dformat'],$INFO['lastmod']);
425
426  print p_locale_xhtml('revisions');
427
428  $form = new Doku_Form('page__revisions', wl($ID));
429  $form->addElement(form_makeOpenTag('ul'));
430  if($INFO['exists'] && $first==0){
431    if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
432      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
433    else
434      $form->addElement(form_makeOpenTag('li'));
435    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
436    $form->addElement(form_makeTag('input', array(
437      'type' => 'checkbox',
438      'name' => 'rev2[]',
439      'value' => 'current')));
440
441    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
442    $form->addElement($date);
443    $form->addElement(form_makeCloseTag('span'));
444
445    $form->addElement(form_makeTag('img', array(
446      'src' =>  DOKU_BASE.'lib/images/blank.gif',
447      'width' => '15',
448      'height' => '11',
449      'alt'    => '')));
450
451    $form->addElement(form_makeOpenTag('a', array(
452      'class' => 'wikilink1',
453      'href'  => wl($ID))));
454    $form->addElement($ID);
455    $form->addElement(form_makeCloseTag('a'));
456
457    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
458    $form->addElement(' &ndash; ');
459    $form->addElement(htmlspecialchars($INFO['sum']));
460    $form->addElement(form_makeCloseTag('span'));
461
462    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
463    $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
464    $form->addElement(form_makeCloseTag('span'));
465
466    $form->addElement('('.$lang['current'].')');
467    $form->addElement(form_makeCloseTag('div'));
468    $form->addElement(form_makeCloseTag('li'));
469  }
470
471  foreach($revisions as $rev){
472    $date   = strftime($conf['dformat'],$rev);
473    $info   = getRevisionInfo($ID,$rev,true);
474    $exists = page_exists($ID,$rev);
475
476    if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
477      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
478    else
479      $form->addElement(form_makeOpenTag('li'));
480    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
481    if($exists){
482      $form->addElement(form_makeTag('input', array(
483        'type' => 'checkbox',
484        'name' => 'rev2[]',
485        'value' => $rev)));
486    }else{
487      $form->addElement(form_makeTag('img', array(
488        'src' => DOKU_BASE.'lib/images/blank.gif',
489        'width' => 14,
490        'height' => 11,
491        'alt' => '')));
492    }
493
494    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
495    $form->addElement($date);
496    $form->addElement(form_makeCloseTag('span'));
497
498    if($exists){
499      $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
500      $form->addElement(form_makeTag('img', array(
501        'src'    => DOKU_BASE.'lib/images/diff.png',
502        'width'  => 15,
503        'height' => 11,
504        'title'  => $lang['diff'],
505        'alt'    => $lang['diff'])));
506      $form->addElement(form_makeCloseTag('a'));
507
508      $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
509      $form->addElement($ID);
510      $form->addElement(form_makeCloseTag('a'));
511    }else{
512      $form->addElement(form_makeTag('img', array(
513        'src' => DOKU_BASE.'lib/images/blank.gif',
514        'width' => '15',
515        'height' => '11',
516        'alt'   => '')));
517      $form->addElement($ID);
518    }
519
520    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
521    $form->addElement(' &ndash; ');
522    $form->addElement(htmlspecialchars($info['sum']));
523    $form->addElement(form_makeCloseTag('span'));
524
525    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
526    if($info['user']){
527      $form->addElement(editorinfo($info['user']));
528      if(auth_ismanager()){
529        $form->addElement(' ('.$info['ip'].')');
530      }
531    }else{
532      $form->addElement($info['ip']);
533    }
534    $form->addElement(form_makeCloseTag('span'));
535
536    $form->addElement(form_makeCloseTag('div'));
537    $form->addElement(form_makeCloseTag('li'));
538  }
539  $form->addElement(form_makeCloseTag('ul'));
540  $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
541  html_form('revisions', $form);
542
543  print '<div class="pagenav">';
544  $last = $first + $conf['recent'];
545  if ($first > 0) {
546    $first -= $conf['recent'];
547    if ($first < 0) $first = 0;
548    print '<div class="pagenav-prev">';
549    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
550    print '</div>';
551  }
552  if ($hasNext) {
553    print '<div class="pagenav-next">';
554    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
555    print '</div>';
556  }
557  print '</div>';
558
559}
560
561/**
562 * display recent changes
563 *
564 * @author Andreas Gohr <andi@splitbrain.org>
565 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
566 * @author Ben Coburn <btcoburn@silicodon.net>
567 */
568function html_recent($first=0){
569  global $conf;
570  global $lang;
571  global $ID;
572  /* we need to get one additionally log entry to be able to
573   * decide if this is the last page or is there another one.
574   * This is the cheapest solution to get this information.
575   */
576  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
577  if(count($recents) == 0 && $first != 0){
578    $first=0;
579    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
580  }
581  $hasNext = false;
582  if (count($recents)>$conf['recent']) {
583    $hasNext = true;
584    array_pop($recents); // remove extra log entry
585  }
586
587  print p_locale_xhtml('recent');
588
589  if (getNS($ID) != '')
590    print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
591
592  $form = new Doku_Form('dw__recent', script(), 'get');
593  $form->addHidden('sectok', null);
594  $form->addHidden('do', 'recent');
595  $form->addHidden('id', $ID);
596  $form->addElement(form_makeOpenTag('ul'));
597
598  foreach($recents as $recent){
599    $date = strftime($conf['dformat'],$recent['date']);
600    if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
601      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
602    else
603      $form->addElement(form_makeOpenTag('li'));
604
605    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
606
607    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
608    $form->addElement($date);
609    $form->addElement(form_makeCloseTag('span'));
610
611    $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
612    $form->addElement(form_makeTag('img', array(
613      'src'   => DOKU_BASE.'lib/images/diff.png',
614      'width' => 15,
615      'height'=> 11,
616      'title' => $lang['diff'],
617      'alt'   => $lang['diff']
618    )));
619    $form->addElement(form_makeCloseTag('a'));
620
621    $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
622    $form->addElement(form_makeTag('img', array(
623      'src'   => DOKU_BASE.'lib/images/history.png',
624      'width' => 12,
625      'height'=> 14,
626      'title' => $lang['btn_revs'],
627      'alt'   => $lang['btn_revs']
628    )));
629    $form->addElement(form_makeCloseTag('a'));
630
631    $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?NULL:$recent['id']));
632
633    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
634    $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
635    $form->addElement(form_makeCloseTag('span'));
636
637    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
638    if($recent['user']){
639      $form->addElement(editorinfo($recent['user']));
640      if(auth_ismanager()){
641        $form->addElement(' ('.$recent['ip'].')');
642      }
643    }else{
644      $form->addElement($recent['ip']);
645    }
646    $form->addElement(form_makeCloseTag('span'));
647
648    $form->addElement(form_makeCloseTag('div'));
649    $form->addElement(form_makeCloseTag('li'));
650  }
651  $form->addElement(form_makeCloseTag('ul'));
652
653  $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
654  $last = $first + $conf['recent'];
655  if ($first > 0) {
656    $first -= $conf['recent'];
657    if ($first < 0) $first = 0;
658    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
659    $form->addElement(form_makeTag('input', array(
660      'type'  => 'submit',
661      'name'  => 'first['.$first.']',
662      'value' => $lang['btn_newer'],
663      'accesskey' => 'n',
664      'title' => $lang['btn_newer'].' [N]',
665      'class' => 'button'
666    )));
667    $form->addElement(form_makeCloseTag('div'));
668  }
669  if ($hasNext) {
670    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
671    $form->addElement(form_makeTag('input', array(
672      'type'  => 'submit',
673      'name'  => 'first['.$last.']',
674      'value' => $lang['btn_older'],
675      'accesskey' => 'p',
676      'title' => $lang['btn_older'].' [P]',
677      'class' => 'button'
678    )));
679    $form->addElement(form_makeCloseTag('div'));
680  }
681  $form->addElement(form_makeCloseTag('div'));
682  html_form('recent', $form);
683}
684
685/**
686 * Display page index
687 *
688 * @author Andreas Gohr <andi@splitbrain.org>
689 */
690function html_index($ns){
691  require_once(DOKU_INC.'inc/search.php');
692  global $conf;
693  global $ID;
694  $dir = $conf['datadir'];
695  $ns  = cleanID($ns);
696  #fixme use appropriate function
697  if(empty($ns)){
698    $ns = dirname(str_replace(':','/',$ID));
699    if($ns == '.') $ns ='';
700  }
701  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
702
703  echo p_locale_xhtml('index');
704  echo '<div id="index__tree">';
705
706  $data = array();
707  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
708  echo html_buildlist($data,'idx','html_list_index','html_li_index');
709
710  echo '</div>';
711}
712
713/**
714 * Index item formatter
715 *
716 * User function for html_buildlist()
717 *
718 * @author Andreas Gohr <andi@splitbrain.org>
719 */
720function html_list_index($item){
721  global $ID;
722  $ret = '';
723  $base = ':'.$item['id'];
724  $base = substr($base,strrpos($base,':')+1);
725  if($item['type']=='d'){
726    $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
727    $ret .= $base;
728    $ret .= '</strong></a>';
729  }else{
730    $ret .= html_wikilink(':'.$item['id']);
731  }
732  return $ret;
733}
734
735/**
736 * Index List item
737 *
738 * This user function is used in html_build_lidt to build the
739 * <li> tags for namespaces when displaying the page index
740 * it gives different classes to opened or closed "folders"
741 *
742 * @author Andreas Gohr <andi@splitbrain.org>
743 */
744function html_li_index($item){
745  if($item['type'] == "f"){
746    return '<li class="level'.$item['level'].'">';
747  }elseif($item['open']){
748    return '<li class="open">';
749  }else{
750    return '<li class="closed">';
751  }
752}
753
754/**
755 * Default List item
756 *
757 * @author Andreas Gohr <andi@splitbrain.org>
758 */
759function html_li_default($item){
760  return '<li class="level'.$item['level'].'">';
761}
762
763/**
764 * Build an unordered list
765 *
766 * Build an unordered list from the given $data array
767 * Each item in the array has to have a 'level' property
768 * the item itself gets printed by the given $func user
769 * function. The second and optional function is used to
770 * print the <li> tag. Both user function need to accept
771 * a single item.
772 *
773 * Both user functions can be given as array to point to
774 * a member of an object.
775 *
776 * @author Andreas Gohr <andi@splitbrain.org>
777 */
778function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
779  $level = 0;
780  $opens = 0;
781  $ret   = '';
782
783  foreach ($data as $item){
784
785    if( $item['level'] > $level ){
786      //open new list
787      for($i=0; $i<($item['level'] - $level); $i++){
788        if ($i) $ret .= "<li class=\"clear\">\n";
789        $ret .= "\n<ul class=\"$class\">\n";
790      }
791    }elseif( $item['level'] < $level ){
792      //close last item
793      $ret .= "</li>\n";
794      for ($i=0; $i<($level - $item['level']); $i++){
795        //close higher lists
796        $ret .= "</ul>\n</li>\n";
797      }
798    }else{
799      //close last item
800      $ret .= "</li>\n";
801    }
802
803    //remember current level
804    $level = $item['level'];
805
806    //print item
807    $ret .= call_user_func($lifunc,$item);
808    $ret .= '<div class="li">';
809
810    $ret .= call_user_func($func,$item);
811    $ret .= '</div>';
812  }
813
814  //close remaining items and lists
815  for ($i=0; $i < $level; $i++){
816    $ret .= "</li></ul>\n";
817  }
818
819  return $ret;
820}
821
822/**
823 * display backlinks
824 *
825 * @author Andreas Gohr <andi@splitbrain.org>
826 * @author Michael Klier <chi@chimeric.de>
827 */
828function html_backlinks(){
829  require_once(DOKU_INC.'inc/fulltext.php');
830  global $ID;
831  global $conf;
832  global $lang;
833
834  print p_locale_xhtml('backlinks');
835
836  $data = ft_backlinks($ID);
837
838  if(!empty($data)) {
839      print '<ul class="idx">';
840      foreach($data as $blink){
841        print '<li><div class="li">';
842        print html_wikilink(':'.$blink,useHeading('navigation')?NULL:$blink);
843        print '</div></li>';
844      }
845      print '</ul>';
846  } else {
847      print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
848  }
849}
850
851/**
852 * show diff
853 *
854 * @author Andreas Gohr <andi@splitbrain.org>
855 */
856function html_diff($text='',$intro=true){
857  require_once(DOKU_INC.'inc/DifferenceEngine.php');
858  global $ID;
859  global $REV;
860  global $lang;
861  global $conf;
862
863  // we're trying to be clever here, revisions to compare can be either
864  // given as rev and rev2 parameters, with rev2 being optional. Or in an
865  // array in rev2.
866  $rev1 = $REV;
867
868  if(is_array($_REQUEST['rev2'])){
869    $rev1 = (int) $_REQUEST['rev2'][0];
870    $rev2 = (int) $_REQUEST['rev2'][1];
871
872    if(!$rev1){
873        $rev1 = $rev2;
874        unset($rev2);
875    }
876  }else{
877    $rev2 = (int) $_REQUEST['rev2'];
878  }
879
880  if($text){                      // compare text to the most current revision
881    $l_rev   = '';
882    $l_text  = rawWiki($ID,'');
883    $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
884               $ID.' '.strftime($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
885               $lang['current'];
886
887    $r_rev   = '';
888    $r_text  = cleanText($text);
889    $r_head  = $lang['yours'];
890  }else{
891    if($rev1 && $rev2){            // two specific revisions wanted
892      // make sure order is correct (older on the left)
893      if($rev1 < $rev2){
894        $l_rev = $rev1;
895        $r_rev = $rev2;
896      }else{
897        $l_rev = $rev2;
898        $r_rev = $rev1;
899      }
900    }elseif($rev1){                // single revision given, compare to current
901      $r_rev = '';
902      $l_rev = $rev1;
903    }else{                        // no revision was given, compare previous to current
904      $r_rev = '';
905      $revs = getRevisions($ID, 0, 1);
906      $l_rev = $revs[0];
907    }
908
909    // when both revisions are empty then the page was created just now
910    if(!$l_rev && !$r_rev){
911      $l_text = '';
912    }else{
913      $l_text = rawWiki($ID,$l_rev);
914    }
915    $r_text = rawWiki($ID,$r_rev);
916
917
918    if(!$l_rev){
919      $l_head = '&mdash;';
920    }else{
921      $l_info   = getRevisionInfo($ID,$l_rev,true);
922      if($l_info['user']){ $l_user = editorinfo($l_info['user']);
923        if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
924      } else { $l_user = $l_info['ip']; }
925      $l_user  = '<span class="user">'.$l_user.'</span>';
926      $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
927      if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
928
929      $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
930                $ID.' ['.strftime($conf['dformat'],$l_rev).']</a>'.
931                '<br />'.$l_user.' '.$l_sum;
932    }
933
934    if($r_rev){
935      $r_info   = getRevisionInfo($ID,$r_rev,true);
936      if($r_info['user']){ $r_user = editorinfo($r_info['user']);
937        if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
938      } else { $r_user = $r_info['ip']; }
939      $r_user = '<span class="user">'.$r_user.'</span>';
940      $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
941      if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
942
943      $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
944                $ID.' ['.strftime($conf['dformat'],$r_rev).']</a>'.
945                '<br />'.$r_user.' '.$r_sum;
946    }elseif($_rev = @filemtime(wikiFN($ID))){
947      $_info   = getRevisionInfo($ID,$_rev,true);
948      if($_info['user']){ $_user = editorinfo($_info['user']);
949        if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
950      } else { $_user = $_info['ip']; }
951      $_user = '<span class="user">'.$_user.'</span>';
952      $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
953      if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
954
955      $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
956               $ID.' ['.strftime($conf['dformat'],$_rev).']</a> '.
957               '('.$lang['current'].')'.
958                '<br />'.$_user.' '.$_sum;
959    }else{
960      $r_head = '&mdash; ('.$lang['current'].')';
961    }
962  }
963
964  $df = new Diff(explode("\n",htmlspecialchars($l_text)),
965                 explode("\n",htmlspecialchars($r_text)));
966
967  $tdf = new TableDiffFormatter();
968  if($intro) print p_locale_xhtml('diff');
969  ?>
970    <table class="diff">
971      <tr>
972        <th colspan="2" <?php echo $l_minor?>>
973          <?php echo $l_head?>
974        </th>
975        <th colspan="2" <?php echo $r_minor?>>
976          <?php echo $r_head?>
977        </th>
978      </tr>
979      <?php echo $tdf->format($df)?>
980    </table>
981  <?php
982}
983
984/**
985 * show warning on conflict detection
986 *
987 * @author Andreas Gohr <andi@splitbrain.org>
988 */
989function html_conflict($text,$summary){
990  global $ID;
991  global $lang;
992
993  print p_locale_xhtml('conflict');
994  $form = new Doku_Form('dw__editform');
995  $form->addHidden('id', $ID);
996  $form->addHidden('wikitext', $text);
997  $form->addHidden('summary', $summary);
998  $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
999  $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1000  html_form('conflict', $form);
1001  print '<br /><br /><br /><br />'.NL;
1002}
1003
1004/**
1005 * Prints the global message array
1006 *
1007 * @author Andreas Gohr <andi@splitbrain.org>
1008 */
1009function html_msgarea(){
1010    global $MSG;
1011    if(!isset($MSG)) return;
1012
1013    $shown = array();
1014    foreach($MSG as $msg){
1015        $hash = md5($msg['msg']);
1016        if(isset($shown[$hash])) continue; // skip double messages
1017        print '<div class="'.$msg['lvl'].'">';
1018        print $msg['msg'];
1019        print '</div>';
1020        $shown[$hash] = 1;
1021    }
1022}
1023
1024/**
1025 * Prints the registration form
1026 *
1027 * @author Andreas Gohr <andi@splitbrain.org>
1028 */
1029function html_register(){
1030  global $lang;
1031  global $conf;
1032  global $ID;
1033
1034  print p_locale_xhtml('register');
1035  print '<div class="centeralign">'.NL;
1036  $form = new Doku_Form('dw__register', wl($ID));
1037  $form->startFieldset($lang['register']);
1038  $form->addHidden('do', 'register');
1039  $form->addHidden('save', '1');
1040  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1041  if (!$conf['autopasswd']) {
1042    $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1043    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1044  }
1045  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1046  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1047  $form->addElement(form_makeButton('submit', '', $lang['register']));
1048  $form->endFieldset();
1049  html_form('register', $form);
1050
1051  print '</div>'.NL;
1052}
1053
1054/**
1055 * Print the update profile form
1056 *
1057 * @author Christopher Smith <chris@jalakai.co.uk>
1058 * @author Andreas Gohr <andi@splitbrain.org>
1059 */
1060function html_updateprofile(){
1061  global $lang;
1062  global $conf;
1063  global $ID;
1064  global $INFO;
1065  global $auth;
1066
1067  print p_locale_xhtml('updateprofile');
1068
1069  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1070  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1071  print '<div class="centeralign">'.NL;
1072  $form = new Doku_Form('dw__register', wl($ID));
1073  $form->startFieldset($lang['profile']);
1074  $form->addHidden('do', 'profile');
1075  $form->addHidden('save', '1');
1076  $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1077  $attr = array('size'=>'50');
1078  if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1079  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1080  $attr = array('size'=>'50');
1081  if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1082  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1083  $form->addElement(form_makeTag('br'));
1084  if ($auth->canDo('modPass')) {
1085    $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1086    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1087  }
1088  if ($conf['profileconfirm']) {
1089    $form->addElement(form_makeTag('br'));
1090    $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1091  }
1092  $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1093  $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1094  $form->endFieldset();
1095  html_form('updateprofile', $form);
1096  print '</div>'.NL;
1097}
1098
1099/**
1100 * This displays the edit form (lots of logic included)
1101 *
1102 * @fixme    this is a huge lump of code and should be modularized
1103 * @triggers HTML_PAGE_FROMTEMPLATE
1104 * @triggers HTML_EDITFORM_INJECTION
1105 * @author   Andreas Gohr <andi@splitbrain.org>
1106 */
1107function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1108  global $ID;
1109  global $REV;
1110  global $DATE;
1111  global $RANGE;
1112  global $PRE;
1113  global $SUF;
1114  global $INFO;
1115  global $SUM;
1116  global $lang;
1117  global $conf;
1118  global $license;
1119
1120  //set summary default
1121  if(!$SUM){
1122    if($REV){
1123      $SUM = $lang['restored'];
1124    }elseif(!$INFO['exists']){
1125      $SUM = $lang['created'];
1126    }
1127  }
1128
1129  //no text? Load it!
1130  if(!isset($text)){
1131    $pr = false; //no preview mode
1132    if($INFO['exists']){
1133      if($RANGE){
1134        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1135      }else{
1136        $text = rawWiki($ID,$REV);
1137      }
1138      $check = md5($text);
1139      $mod = false;
1140    }else{
1141      //try to load a pagetemplate
1142      $data = array($ID);
1143      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1144      $check = md5('');
1145      $mod = $text!=='';
1146    }
1147  }else{
1148    $pr = true; //preview mode
1149    if (isset($_REQUEST['changecheck'])) {
1150      $check = $_REQUEST['changecheck'];
1151      $mod = md5($text)!==$check;
1152    } else {
1153      // Why? Assume default text is unmodified.
1154      $check = md5($text);
1155      $mod = false;
1156    }
1157  }
1158
1159  $wr = $INFO['writable'] && !$INFO['locked'];
1160  if($wr){
1161    if ($REV) print p_locale_xhtml('editrev');
1162    print p_locale_xhtml($include);
1163  }else{
1164    // check pseudo action 'source'
1165    if(!actionOK('source')){
1166      msg('Command disabled: source',-1);
1167      return;
1168    }
1169    print p_locale_xhtml('read');
1170  }
1171  if(!$DATE) $DATE = $INFO['lastmod'];
1172
1173
1174?>
1175  <div style="width:99%;">
1176
1177   <div class="toolbar">
1178      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div>
1179      <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1180      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1181
1182      <?php if($wr){?>
1183      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1184        <?php /* sets changed to true when previewed */?>
1185        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1186      //--><!]]></script>
1187      <span id="spell__action"></span>
1188      <div id="spell__suggest"></div>
1189      <?php } ?>
1190   </div>
1191   <div id="spell__result"></div>
1192<?php
1193  $form = new Doku_Form('dw__editform');
1194  $form->addHidden('id', $ID);
1195  $form->addHidden('rev', $REV);
1196  $form->addHidden('date', $DATE);
1197  $form->addHidden('prefix', $PRE);
1198  $form->addHidden('suffix', $SUF);
1199  $form->addHidden('changecheck', $check);
1200  $attr = array('tabindex'=>'1');
1201  if (!$wr) $attr['readonly'] = 'readonly';
1202  $form->addElement(form_makeWikiText($text, $attr));
1203  $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1204  $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1205  $form->addElement(form_makeCloseTag('div'));
1206  if ($wr) {
1207    $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1208    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1209    $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1210    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1211    $form->addElement(form_makeCloseTag('div'));
1212    $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1213    $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1214    $elem = html_minoredit();
1215    if ($elem) $form->addElement($elem);
1216    $form->addElement(form_makeCloseTag('div'));
1217  }
1218  $form->addElement(form_makeCloseTag('div'));
1219  if($conf['license']){
1220    $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1221    $out  = $lang['licenseok'];
1222    $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1223    if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
1224    $out .= '> '.$license[$conf['license']]['name'].'</a>';
1225    $form->addElement($out);
1226    $form->addElement(form_makeCloseTag('div'));
1227  }
1228  html_form('edit', $form);
1229  print '</div>'.NL;
1230}
1231
1232/**
1233 * Adds a checkbox for minor edits for logged in users
1234 *
1235 * @author Andrea Gohr <andi@splitbrain.org>
1236 */
1237function html_minoredit(){
1238  global $conf;
1239  global $lang;
1240  // minor edits are for logged in users only
1241  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1242    return false;
1243  }
1244
1245  $p = array();
1246  $p['tabindex'] = 3;
1247  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1248  return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1249}
1250
1251/**
1252 * prints some debug info
1253 *
1254 * @author Andreas Gohr <andi@splitbrain.org>
1255 */
1256function html_debug(){
1257  global $conf;
1258  global $lang;
1259  global $auth;
1260  global $INFO;
1261
1262  //remove sensitive data
1263  $cnf = $conf;
1264  debug_guard($cnf);
1265  $nfo = $INFO;
1266  debug_guard($nfo);
1267  $ses = $_SESSION;
1268  debug_guard($ses);
1269
1270  print '<html><body>';
1271
1272  print '<p>When reporting bugs please send all the following ';
1273  print 'output as a mail to andi@splitbrain.org ';
1274  print 'The best way to do this is to save this page in your browser</p>';
1275
1276  print '<b>$INFO:</b><pre>';
1277  print_r($nfo);
1278  print '</pre>';
1279
1280  print '<b>$_SERVER:</b><pre>';
1281  print_r($_SERVER);
1282  print '</pre>';
1283
1284  print '<b>$conf:</b><pre>';
1285  print_r($cnf);
1286  print '</pre>';
1287
1288  print '<b>DOKU_BASE:</b><pre>';
1289  print DOKU_BASE;
1290  print '</pre>';
1291
1292  print '<b>abs DOKU_BASE:</b><pre>';
1293  print DOKU_URL;
1294  print '</pre>';
1295
1296  print '<b>rel DOKU_BASE:</b><pre>';
1297  print dirname($_SERVER['PHP_SELF']).'/';
1298  print '</pre>';
1299
1300  print '<b>PHP Version:</b><pre>';
1301  print phpversion();
1302  print '</pre>';
1303
1304  print '<b>locale:</b><pre>';
1305  print setlocale(LC_ALL,0);
1306  print '</pre>';
1307
1308  print '<b>encoding:</b><pre>';
1309  print $lang['encoding'];
1310  print '</pre>';
1311
1312  if($auth){
1313    print '<b>Auth backend capabilities:</b><pre>';
1314    print_r($auth->cando);
1315    print '</pre>';
1316  }
1317
1318  print '<b>$_SESSION:</b><pre>';
1319  print_r($ses);
1320  print '</pre>';
1321
1322  print '<b>Environment:</b><pre>';
1323  print_r($_ENV);
1324  print '</pre>';
1325
1326  print '<b>PHP settings:</b><pre>';
1327  $inis = ini_get_all();
1328  print_r($inis);
1329  print '</pre>';
1330
1331  print '</body></html>';
1332}
1333
1334function html_admin(){
1335  global $ID;
1336  global $INFO;
1337  global $lang;
1338  global $conf;
1339
1340  print p_locale_xhtml('admin');
1341
1342  // build menu of admin functions from the plugins that handle them
1343  $pluginlist = plugin_list('admin');
1344  $menu = array();
1345  foreach ($pluginlist as $p) {
1346    if($obj =& plugin_load('admin',$p) === NULL) continue;
1347
1348    // check permissions
1349    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1350
1351    $menu[] = array('plugin' => $p,
1352                    'prompt' => $obj->getMenuText($conf['lang']),
1353                    'sort' => $obj->getMenuSort()
1354                   );
1355  }
1356
1357  usort($menu, 'p_sort_modes');
1358
1359  // output the menu
1360  ptln('<ul>');
1361
1362  foreach ($menu as $item) {
1363    if (!$item['prompt']) continue;
1364    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1365  }
1366
1367  ptln('</ul>');
1368}
1369
1370/**
1371 * Form to request a new password for an existing account
1372 *
1373 * @author Benoit Chesneau <benoit@bchesneau.info>
1374 */
1375function html_resendpwd() {
1376  global $lang;
1377  global $conf;
1378  global $ID;
1379
1380  print p_locale_xhtml('resendpwd');
1381  print '<div class="centeralign">'.NL;
1382  $form = new Doku_Form('dw__resendpwd', wl($ID));
1383  $form->startFieldset($lang['resendpwd']);
1384  $form->addHidden('do', 'resendpwd');
1385  $form->addHidden('save', '1');
1386  $form->addElement(form_makeTag('br'));
1387  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1388  $form->addElement(form_makeTag('br'));
1389  $form->addElement(form_makeTag('br'));
1390  $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1391  $form->endFieldset();
1392  html_form('resendpwd', $form);
1393  print '</div>'.NL;
1394}
1395
1396/**
1397 * Return the TOC rendered to XHTML
1398 *
1399 * @author Andreas Gohr <andi@splitbrain.org>
1400 */
1401function html_TOC($toc){
1402    if(!count($toc)) return '';
1403    global $lang;
1404    $out  = '<!-- TOC START -->'.DOKU_LF;
1405    $out .= '<div class="toc">'.DOKU_LF;
1406    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1407    $out .= $lang['toc'];
1408    $out .= '</div>'.DOKU_LF;
1409    $out .= '<div id="toc__inside">'.DOKU_LF;
1410    $out .= html_buildlist($toc,'toc','html_list_toc');
1411    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1412    $out .= '<!-- TOC END -->'.DOKU_LF;
1413    return $out;                                                                                                }
1414
1415/**
1416 * Callback for html_buildlist
1417 */
1418function html_list_toc($item){
1419    if($item['hid']){
1420        $link = '#'.$item['hid'];
1421    }else{
1422        $link = $item['link'];
1423    }
1424
1425    return '<span class="li"><a href="'.$link.'" class="toc">'.
1426           hsc($item['title']).'</a></span>';
1427}
1428
1429/**
1430 * Helper function to build TOC items
1431 *
1432 * Returns an array ready to be added to a TOC array
1433 *
1434 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1435 * @param string $text  - what to display in the TOC
1436 * @param int    $level - nesting level
1437 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1438 */
1439function html_mktocitem($link, $text, $level, $hash='#'){
1440    global $conf;
1441    return  array( 'link'  => $hash.$link,
1442                   'title' => $text,
1443                   'type'  => 'ul',
1444                   'level' => $level);
1445}
1446
1447/**
1448 * Output a Doku_Form object.
1449 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1450 *
1451 * @author Tom N Harris <tnharris@whoopdedo.org>
1452 */
1453function html_form($name, &$form) {
1454  // Safety check in case the caller forgets.
1455  $form->endFieldset();
1456  trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1457}
1458
1459/**
1460 * Form print function.
1461 * Just calls printForm() on the data object.
1462 */
1463function html_form_output($data) {
1464  $data->printForm();
1465}
1466
1467/**
1468 * Embed a flash object in HTML
1469 *
1470 * This will create the needed HTML to embed a flash movie in a cross browser
1471 * compatble way using valid XHTML
1472 *
1473 * The parameters $params, $flashvars and $atts need to be associative arrays.
1474 * No escaping needs to be done for them. The alternative content *has* to be
1475 * escaped because it is used as is. If no alternative content is given
1476 * $lang['noflash'] is used.
1477 *
1478 * @author Andreas Gohr <andi@splitbrain.org>
1479 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1480 *
1481 * @param string $swf      - the SWF movie to embed
1482 * @param int $width       - width of the flash movie in pixels
1483 * @param int $height      - height of the flash movie in pixels
1484 * @param array $params    - additional parameters (<param>)
1485 * @param array $flashvars - parameters to be passed in the flashvar parameter
1486 * @param array $atts      - additional attributes for the <object> tag
1487 * @param string $alt      - alternative content (is NOT automatically escaped!)
1488 * @returns string         - the XHTML markup
1489 */
1490function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1491    global $lang;
1492
1493    $out = '';
1494
1495    // prepare the object attributes
1496    if(is_null($atts)) $atts = array();
1497    $atts['width']  = (int) $width;
1498    $atts['height'] = (int) $height;
1499    if(!$atts['width'])  $atts['width']  = 425;
1500    if(!$atts['height']) $atts['height'] = 350;
1501
1502    // add object attributes for standard compliant browsers
1503    $std = $atts;
1504    $std['type'] = 'application/x-shockwave-flash';
1505    $std['data'] = $swf;
1506
1507    // add object attributes for IE
1508    $ie  = $atts;
1509    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1510
1511    // open object (with conditional comments)
1512    $out .= '<!--[if !IE]> -->'.NL;
1513    $out .= '<object '.buildAttributes($std).'>'.NL;
1514    $out .= '<!-- <![endif]-->'.NL;
1515    $out .= '<!--[if IE]>'.NL;
1516    $out .= '<object '.buildAttributes($ie).'>'.NL;
1517    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1518    $out .= '<!--><!-- -->'.NL;
1519
1520    // print params
1521    if(is_array($params)) foreach($params as $key => $val){
1522        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1523    }
1524
1525    // add flashvars
1526    if(is_array($flashvars)){
1527        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1528    }
1529
1530    // alternative content
1531    if($alt){
1532        $out .= $alt.NL;
1533    }else{
1534        $out .= $lang['noflash'].NL;
1535    }
1536
1537    // finish
1538    $out .= '</object>'.NL;
1539    $out .= '<!-- <![endif]-->'.NL;
1540
1541    return $out;
1542}
1543
1544//Setup VIM: ex: et ts=2 enc=utf-8 :
1545