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