xref: /dokuwiki/inc/html.php (revision 3cd36d102e7362d0d548681f21154df643c1157a)
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
1012  if(!isset($MSG)) return;
1013
1014  $MSG = array_unique($MSG); // no double messages
1015
1016  foreach($MSG as $msg){
1017    print '<div class="'.$msg['lvl'].'">';
1018    print $msg['msg'];
1019    print '</div>';
1020  }
1021}
1022
1023/**
1024 * Prints the registration form
1025 *
1026 * @author Andreas Gohr <andi@splitbrain.org>
1027 */
1028function html_register(){
1029  global $lang;
1030  global $conf;
1031  global $ID;
1032
1033  print p_locale_xhtml('register');
1034  print '<div class="centeralign">'.NL;
1035  $form = new Doku_Form('dw__register', wl($ID));
1036  $form->startFieldset($lang['register']);
1037  $form->addHidden('do', 'register');
1038  $form->addHidden('save', '1');
1039  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1040  if (!$conf['autopasswd']) {
1041    $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1042    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1043  }
1044  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1045  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1046  $form->addElement(form_makeButton('submit', '', $lang['register']));
1047  $form->endFieldset();
1048  html_form('register', $form);
1049
1050  print '</div>'.NL;
1051}
1052
1053/**
1054 * Print the update profile form
1055 *
1056 * @author Christopher Smith <chris@jalakai.co.uk>
1057 * @author Andreas Gohr <andi@splitbrain.org>
1058 */
1059function html_updateprofile(){
1060  global $lang;
1061  global $conf;
1062  global $ID;
1063  global $INFO;
1064  global $auth;
1065
1066  print p_locale_xhtml('updateprofile');
1067
1068  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1069  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1070  print '<div class="centeralign">'.NL;
1071  $form = new Doku_Form('dw__register', wl($ID));
1072  $form->startFieldset($lang['profile']);
1073  $form->addHidden('do', 'profile');
1074  $form->addHidden('save', '1');
1075  $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1076  $attr = array('size'=>'50');
1077  if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1078  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1079  $attr = array('size'=>'50');
1080  if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1081  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1082  $form->addElement(form_makeTag('br'));
1083  if ($auth->canDo('modPass')) {
1084    $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1085    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1086  }
1087  if ($conf['profileconfirm']) {
1088    $form->addElement(form_makeTag('br'));
1089    $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1090  }
1091  $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1092  $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1093  $form->endFieldset();
1094  html_form('updateprofile', $form);
1095  print '</div>'.NL;
1096}
1097
1098/**
1099 * This displays the edit form (lots of logic included)
1100 *
1101 * @fixme    this is a huge lump of code and should be modularized
1102 * @triggers HTML_PAGE_FROMTEMPLATE
1103 * @triggers HTML_EDITFORM_INJECTION
1104 * @author   Andreas Gohr <andi@splitbrain.org>
1105 */
1106function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1107  global $ID;
1108  global $REV;
1109  global $DATE;
1110  global $RANGE;
1111  global $PRE;
1112  global $SUF;
1113  global $INFO;
1114  global $SUM;
1115  global $lang;
1116  global $conf;
1117  global $license;
1118
1119  //set summary default
1120  if(!$SUM){
1121    if($REV){
1122      $SUM = $lang['restored'];
1123    }elseif(!$INFO['exists']){
1124      $SUM = $lang['created'];
1125    }
1126  }
1127
1128  //no text? Load it!
1129  if(!isset($text)){
1130    $pr = false; //no preview mode
1131    if($INFO['exists']){
1132      if($RANGE){
1133        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1134      }else{
1135        $text = rawWiki($ID,$REV);
1136      }
1137      $check = md5($text);
1138      $mod = false;
1139    }else{
1140      //try to load a pagetemplate
1141      $data = array($ID);
1142      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1143      $check = md5('');
1144      $mod = $text!=='';
1145    }
1146  }else{
1147    $pr = true; //preview mode
1148    if (isset($_REQUEST['changecheck'])) {
1149      $check = $_REQUEST['changecheck'];
1150      $mod = md5($text)!==$check;
1151    } else {
1152      // Why? Assume default text is unmodified.
1153      $check = md5($text);
1154      $mod = false;
1155    }
1156  }
1157
1158  $wr = $INFO['writable'] && !$INFO['locked'];
1159  if($wr){
1160    if ($REV) print p_locale_xhtml('editrev');
1161    print p_locale_xhtml($include);
1162  }else{
1163    // check pseudo action 'source'
1164    if(!actionOK('source')){
1165      msg('Command disabled: source',-1);
1166      return;
1167    }
1168    print p_locale_xhtml('read');
1169  }
1170  if(!$DATE) $DATE = $INFO['lastmod'];
1171
1172
1173?>
1174  <div style="width:99%;">
1175
1176   <div class="toolbar">
1177      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div>
1178      <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1179      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1180
1181      <?php if($wr){?>
1182      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1183        <?php /* sets changed to true when previewed */?>
1184        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1185      //--><!]]></script>
1186      <span id="spell__action"></span>
1187      <div id="spell__suggest"></div>
1188      <?php } ?>
1189   </div>
1190   <div id="spell__result"></div>
1191<?php
1192  $form = new Doku_Form('dw__editform');
1193  $form->addHidden('id', $ID);
1194  $form->addHidden('rev', $REV);
1195  $form->addHidden('date', $DATE);
1196  $form->addHidden('prefix', $PRE);
1197  $form->addHidden('suffix', $SUF);
1198  $form->addHidden('changecheck', $check);
1199  $attr = array('tabindex'=>'1');
1200  if (!$wr) $attr['readonly'] = 'readonly';
1201  $form->addElement(form_makeWikiText($text, $attr));
1202  $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1203  $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1204  $form->addElement(form_makeCloseTag('div'));
1205  if ($wr) {
1206    $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1207    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1208    $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1209    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1210    $form->addElement(form_makeCloseTag('div'));
1211    $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1212    $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1213    $elem = html_minoredit();
1214    if ($elem) $form->addElement($elem);
1215    $form->addElement(form_makeCloseTag('div'));
1216  }
1217  $form->addElement(form_makeCloseTag('div'));
1218  if($conf['license']){
1219    $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1220    $out  = $lang['licenseok'];
1221    $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1222    if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
1223    $out .= '> '.$license[$conf['license']]['name'].'</a>';
1224    $form->addElement($out);
1225    $form->addElement(form_makeCloseTag('div'));
1226  }
1227  html_form('edit', $form);
1228  print '</div>'.NL;
1229}
1230
1231/**
1232 * Adds a checkbox for minor edits for logged in users
1233 *
1234 * @author Andrea Gohr <andi@splitbrain.org>
1235 */
1236function html_minoredit(){
1237  global $conf;
1238  global $lang;
1239  // minor edits are for logged in users only
1240  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1241    return false;
1242  }
1243
1244  $p = array();
1245  $p['tabindex'] = 3;
1246  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1247  return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1248}
1249
1250/**
1251 * prints some debug info
1252 *
1253 * @author Andreas Gohr <andi@splitbrain.org>
1254 */
1255function html_debug(){
1256  global $conf;
1257  global $lang;
1258  global $auth;
1259  global $INFO;
1260
1261  //remove sensitive data
1262  $cnf = $conf;
1263  debug_guard($cnf);
1264  $nfo = $INFO;
1265  debug_guard($nfo);
1266  $ses = $_SESSION;
1267  debug_guard($ses);
1268
1269  print '<html><body>';
1270
1271  print '<p>When reporting bugs please send all the following ';
1272  print 'output as a mail to andi@splitbrain.org ';
1273  print 'The best way to do this is to save this page in your browser</p>';
1274
1275  print '<b>$INFO:</b><pre>';
1276  print_r($nfo);
1277  print '</pre>';
1278
1279  print '<b>$_SERVER:</b><pre>';
1280  print_r($_SERVER);
1281  print '</pre>';
1282
1283  print '<b>$conf:</b><pre>';
1284  print_r($cnf);
1285  print '</pre>';
1286
1287  print '<b>DOKU_BASE:</b><pre>';
1288  print DOKU_BASE;
1289  print '</pre>';
1290
1291  print '<b>abs DOKU_BASE:</b><pre>';
1292  print DOKU_URL;
1293  print '</pre>';
1294
1295  print '<b>rel DOKU_BASE:</b><pre>';
1296  print dirname($_SERVER['PHP_SELF']).'/';
1297  print '</pre>';
1298
1299  print '<b>PHP Version:</b><pre>';
1300  print phpversion();
1301  print '</pre>';
1302
1303  print '<b>locale:</b><pre>';
1304  print setlocale(LC_ALL,0);
1305  print '</pre>';
1306
1307  print '<b>encoding:</b><pre>';
1308  print $lang['encoding'];
1309  print '</pre>';
1310
1311  if($auth){
1312    print '<b>Auth backend capabilities:</b><pre>';
1313    print_r($auth->cando);
1314    print '</pre>';
1315  }
1316
1317  print '<b>$_SESSION:</b><pre>';
1318  print_r($ses);
1319  print '</pre>';
1320
1321  print '<b>Environment:</b><pre>';
1322  print_r($_ENV);
1323  print '</pre>';
1324
1325  print '<b>PHP settings:</b><pre>';
1326  $inis = ini_get_all();
1327  print_r($inis);
1328  print '</pre>';
1329
1330  print '</body></html>';
1331}
1332
1333function html_admin(){
1334  global $ID;
1335  global $INFO;
1336  global $lang;
1337  global $conf;
1338
1339  print p_locale_xhtml('admin');
1340
1341  // build menu of admin functions from the plugins that handle them
1342  $pluginlist = plugin_list('admin');
1343  $menu = array();
1344  foreach ($pluginlist as $p) {
1345    if($obj =& plugin_load('admin',$p) === NULL) continue;
1346
1347    // check permissions
1348    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1349
1350    $menu[] = array('plugin' => $p,
1351                    'prompt' => $obj->getMenuText($conf['lang']),
1352                    'sort' => $obj->getMenuSort()
1353                   );
1354  }
1355
1356  usort($menu, 'p_sort_modes');
1357
1358  // output the menu
1359  ptln('<ul>');
1360
1361  foreach ($menu as $item) {
1362    if (!$item['prompt']) continue;
1363    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1364  }
1365
1366  ptln('</ul>');
1367}
1368
1369/**
1370 * Form to request a new password for an existing account
1371 *
1372 * @author Benoit Chesneau <benoit@bchesneau.info>
1373 */
1374function html_resendpwd() {
1375  global $lang;
1376  global $conf;
1377  global $ID;
1378
1379  print p_locale_xhtml('resendpwd');
1380  print '<div class="centeralign">'.NL;
1381  $form = new Doku_Form('dw__resendpwd', wl($ID));
1382  $form->startFieldset($lang['resendpwd']);
1383  $form->addHidden('do', 'resendpwd');
1384  $form->addHidden('save', '1');
1385  $form->addElement(form_makeTag('br'));
1386  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1387  $form->addElement(form_makeTag('br'));
1388  $form->addElement(form_makeTag('br'));
1389  $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1390  $form->endFieldset();
1391  html_form('resendpwd', $form);
1392  print '</div>'.NL;
1393}
1394
1395/**
1396 * Return the TOC rendered to XHTML
1397 *
1398 * @author Andreas Gohr <andi@splitbrain.org>
1399 */
1400function html_TOC($toc){
1401    if(!count($toc)) return '';
1402    global $lang;
1403    $out  = '<!-- TOC START -->'.DOKU_LF;
1404    $out .= '<div class="toc">'.DOKU_LF;
1405    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1406    $out .= $lang['toc'];
1407    $out .= '</div>'.DOKU_LF;
1408    $out .= '<div id="toc__inside">'.DOKU_LF;
1409    $out .= html_buildlist($toc,'toc','html_list_toc');
1410    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1411    $out .= '<!-- TOC END -->'.DOKU_LF;
1412    return $out;                                                                                                }
1413
1414/**
1415 * Callback for html_buildlist
1416 */
1417function html_list_toc($item){
1418    if($item['hid']){
1419        $link = '#'.$item['hid'];
1420    }else{
1421        $link = $item['link'];
1422    }
1423
1424    return '<span class="li"><a href="'.$link.'" class="toc">'.
1425           hsc($item['title']).'</a></span>';
1426}
1427
1428/**
1429 * Helper function to build TOC items
1430 *
1431 * Returns an array ready to be added to a TOC array
1432 *
1433 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1434 * @param string $text  - what to display in the TOC
1435 * @param int    $level - nesting level
1436 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1437 */
1438function html_mktocitem($link, $text, $level, $hash='#'){
1439    global $conf;
1440    return  array( 'link'  => $hash.$link,
1441                   'title' => $text,
1442                   'type'  => 'ul',
1443                   'level' => $level);
1444}
1445
1446/**
1447 * Output a Doku_Form object.
1448 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1449 *
1450 * @author Tom N Harris <tnharris@whoopdedo.org>
1451 */
1452function html_form($name, &$form) {
1453  // Safety check in case the caller forgets.
1454  $form->endFieldset();
1455  trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1456}
1457
1458/**
1459 * Form print function.
1460 * Just calls printForm() on the data object.
1461 */
1462function html_form_output($data) {
1463  $data->printForm();
1464}
1465
1466/**
1467 * Embed a flash object in HTML
1468 *
1469 * This will create the needed HTML to embed a flash movie in a cross browser
1470 * compatble way using valid XHTML
1471 *
1472 * The parameters $params, $flashvars and $atts need to be associative arrays.
1473 * No escaping needs to be done for them. The alternative content *has* to be
1474 * escaped because it is used as is. If no alternative content is given
1475 * $lang['noflash'] is used.
1476 *
1477 * @author Andreas Gohr <andi@splitbrain.org>
1478 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1479 *
1480 * @param string $swf      - the SWF movie to embed
1481 * @param int $width       - width of the flash movie in pixels
1482 * @param int $height      - height of the flash movie in pixels
1483 * @param array $params    - additional parameters (<param>)
1484 * @param array $flashvars - parameters to be passed in the flashvar parameter
1485 * @param array $atts      - additional attributes for the <object> tag
1486 * @param string $alt      - alternative content (is NOT automatically escaped!)
1487 * @returns string         - the XHTML markup
1488 */
1489function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1490    global $lang;
1491
1492    $out = '';
1493
1494    // prepare the object attributes
1495    if(is_null($atts)) $atts = array();
1496    $atts['width']  = (int) $width;
1497    $atts['height'] = (int) $height;
1498    if(!$atts['width'])  $atts['width']  = 425;
1499    if(!$atts['height']) $atts['height'] = 350;
1500
1501    // add object attributes for standard compliant browsers
1502    $std = $atts;
1503    $std['type'] = 'application/x-shockwave-flash';
1504    $std['data'] = $swf;
1505
1506    // add object attributes for IE
1507    $ie  = $atts;
1508    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1509
1510    // open object (with conditional comments)
1511    $out .= '<!--[if !IE]> -->'.NL;
1512    $out .= '<object '.buildAttributes($std).'>'.NL;
1513    $out .= '<!-- <![endif]-->'.NL;
1514    $out .= '<!--[if IE]>'.NL;
1515    $out .= '<object '.buildAttributes($ie).'>'.NL;
1516    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1517    $out .= '<!--><!-- -->'.NL;
1518
1519    // print params
1520    if(is_array($params)) foreach($params as $key => $val){
1521        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1522    }
1523
1524    // add flashvars
1525    if(is_array($flashvars)){
1526        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1527    }
1528
1529    // alternative content
1530    if($alt){
1531        $out .= $alt.NL;
1532    }else{
1533        $out .= $lang['noflash'].NL;
1534    }
1535
1536    // finish
1537    $out .= '</object>'.NL;
1538    $out .= '<!-- <![endif]-->'.NL;
1539
1540    return $out;
1541}
1542
1543//Setup VIM: ex: et ts=2 enc=utf-8 :
1544