xref: /dokuwiki/inc/html.php (revision 54041c77c7e08db6205a57148735b3266b711756)
1ed7b5f09Sandi<?php
215fae107Sandi/**
315fae107Sandi * HTML output functions
415fae107Sandi *
515fae107Sandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
615fae107Sandi * @author     Andreas Gohr <andi@splitbrain.org>
715fae107Sandi */
815fae107Sandi
900976812SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
10e226efe1SAndreas Gohrif(!defined('NL')) define('NL',"\n");
116bbae538Sandirequire_once(DOKU_INC.'inc/parserutils.php');
12fdb8d77bSTom N Harrisrequire_once(DOKU_INC.'inc/form.php');
136bbae538Sandi
14f3f0262cSandi/**
15f3f0262cSandi * Convenience function to quickly build a wikilink
1615fae107Sandi *
1715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
18f3f0262cSandi */
1930f1737dSandifunction html_wikilink($id,$name=NULL,$search=''){
20723d78dbSandi  static $xhtml_renderer = NULL;
21723d78dbSandi  if(is_null($xhtml_renderer)){
22fdf3dcb9SMatthias Urlichs    require_once(DOKU_INC.'inc/parser/xhtml.php');
23723d78dbSandi    $xhtml_renderer = new Doku_Renderer_xhtml();
24f3f0262cSandi  }
25f3f0262cSandi
26cffcc403Sandi  return $xhtml_renderer->internallink($id,$name,$search,true);
27f3f0262cSandi}
28f3f0262cSandi
29f3f0262cSandi/**
30c19fe9c0Sandi * Helps building long attribute lists
31c19fe9c0Sandi *
32c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
33c19fe9c0Sandi */
34c19fe9c0Sandifunction html_attbuild($attributes){
35c19fe9c0Sandi  $ret = '';
36c19fe9c0Sandi  foreach ( $attributes as $key => $value ) {
37c19fe9c0Sandi    $ret .= $key.'="'.formtext($value).'" ';
38c19fe9c0Sandi  }
39c19fe9c0Sandi  return trim($ret);
40c19fe9c0Sandi}
41c19fe9c0Sandi
42c19fe9c0Sandi/**
43f3f0262cSandi * The loginform
4415fae107Sandi *
4515fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
46f3f0262cSandi */
47f3f0262cSandifunction html_login(){
48f3f0262cSandi  global $lang;
49f3f0262cSandi  global $conf;
50f3f0262cSandi  global $ID;
51cd52f92dSchris  global $auth;
52f3f0262cSandi
53c112d578Sandi  print p_locale_xhtml('login');
54fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
55fdb8d77bSTom N Harris  $form = new Doku_Form('dw__login');
56fdb8d77bSTom N Harris  $form->startFieldset($lang['btn_login']);
57fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
58fdb8d77bSTom N Harris  $form->addHidden('do', 'login');
59fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('u', $_REQUEST['u'], $lang['user'], 'focus__this', 'block'));
60fdb8d77bSTom N Harris  $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
61fdb8d77bSTom N Harris  $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
62fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
63fdb8d77bSTom N Harris  $form->endFieldset();
64fdb8d77bSTom N Harris  html_form('login', $form);
655b62573aSAndreas Gohr
666957b2eaSAndreas Gohr  if($auth && $auth->canDo('addUser') && actionOK('register')){
67f3f0262cSandi    print '<p>';
68f3f0262cSandi    print $lang['reghere'];
691d5856cfSAndreas Gohr    print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
70f3f0262cSandi    print '</p>';
71f3f0262cSandi  }
728b06d178Schris
736957b2eaSAndreas Gohr  if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
748b06d178Schris    print '<p>';
758b06d178Schris    print $lang['pwdforget'];
761d5856cfSAndreas Gohr    print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
778b06d178Schris    print '</p>';
788b06d178Schris  }
79fdb8d77bSTom N Harris  print '</div>'.NL;
80f3f0262cSandi}
81f3f0262cSandi
82f3f0262cSandi/**
8315fae107Sandi * prints a section editing button
8435dae8b0SBen Coburn * used as a callback in html_secedit
8515fae107Sandi *
8615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8715fae107Sandi */
8835dae8b0SBen Coburnfunction html_secedit_button($matches){
89f3f0262cSandi  global $ID;
90041d7a86SBen Coburn  global $INFO;
91041d7a86SBen Coburn
92041d7a86SBen Coburn  $section = $matches[2];
93041d7a86SBen Coburn  $name = $matches[1];
94041d7a86SBen Coburn
95f3f0262cSandi  $secedit  = '';
96f3f0262cSandi  $secedit .= '<div class="secedit">';
97f3f0262cSandi  $secedit .= html_btn('secedit',$ID,'',
98f3f0262cSandi                        array('do'      => 'edit',
99306b2c85SDenis Simakov                              'lines'   => "$section",
100306b2c85SDenis Simakov                              'rev' => $INFO['lastmod']),
10135dae8b0SBen Coburn                              'post', $name);
102f3f0262cSandi  $secedit .= '</div>';
103f3f0262cSandi  return $secedit;
104f3f0262cSandi}
105f3f0262cSandi
10615fae107Sandi/**
10715fae107Sandi * inserts section edit buttons if wanted or removes the markers
10815fae107Sandi *
10915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
11015fae107Sandi */
111f3f0262cSandifunction html_secedit($text,$show=true){
112f3f0262cSandi  global $INFO;
11335dae8b0SBen Coburn
114c112d578Sandi  if($INFO['writable'] && $show && !$INFO['rev']){
11535dae8b0SBen Coburn    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
11635dae8b0SBen Coburn                         'html_secedit_button', $text);
117f3f0262cSandi  }else{
11835dae8b0SBen Coburn    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
119f3f0262cSandi  }
12035dae8b0SBen Coburn
121f3f0262cSandi  return $text;
122f3f0262cSandi}
123f3f0262cSandi
124f3f0262cSandi/**
125d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1266b13307fSandi *
1276b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1286b13307fSandi */
1296b13307fSandifunction html_topbtn(){
1306b13307fSandi  global $lang;
1316b13307fSandi
1326b13307fSandi  $ret  = '';
13311ea018fSAndreas Gohr  $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>';
134df7b6005Sandi
1356b13307fSandi  return $ret;
1366b13307fSandi}
1376b13307fSandi
1386b13307fSandi/**
139d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
14035dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
14115fae107Sandi *
14215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
143f3f0262cSandi */
14435dae8b0SBen Coburnfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
145f3f0262cSandi  global $conf;
146f3f0262cSandi  global $lang;
147f3f0262cSandi
148f3f0262cSandi  $label = $lang['btn_'.$name];
149f3f0262cSandi
150f3f0262cSandi  $ret = '';
15135dae8b0SBen Coburn  $tip = '';
152f3f0262cSandi
15349c713a3Sandi  //filter id (without urlencoding)
15449c713a3Sandi  $id = idfilter($id,false);
155f3f0262cSandi
156f3f0262cSandi  //make nice URLs even for buttons
1576c7843b5Sandi  if($conf['userewrite'] == 2){
1586c7843b5Sandi    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1596c7843b5Sandi  }elseif($conf['userewrite']){
1606c7843b5Sandi    $script = DOKU_BASE.$id;
1616c7843b5Sandi  }else{
1628b00ebcfSandi    $script = DOKU_BASE.DOKU_SCRIPT;
163f3f0262cSandi    $params['id'] = $id;
164f3f0262cSandi  }
165f3f0262cSandi
166b278f2deSAndreas Gohr  $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
167f3f0262cSandi
16806a4bf8fSAndreas Gohr  if(is_array($params)){
169f3f0262cSandi    reset($params);
170f3f0262cSandi    while (list($key, $val) = each($params)) {
171f3f0262cSandi      $ret .= '<input type="hidden" name="'.$key.'" ';
172f3f0262cSandi      $ret .= 'value="'.htmlspecialchars($val).'" />';
173f3f0262cSandi    }
17406a4bf8fSAndreas Gohr  }
175f3f0262cSandi
17635dae8b0SBen Coburn  if ($tooltip!='') {
17735dae8b0SBen Coburn      $tip = htmlspecialchars($tooltip);
17811ea018fSAndreas Gohr  }else{
17911ea018fSAndreas Gohr      $tip = htmlspecialchars($label);
18011ea018fSAndreas Gohr  }
18111ea018fSAndreas Gohr
18211ea018fSAndreas Gohr  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
18311ea018fSAndreas Gohr  if($akey){
18411ea018fSAndreas Gohr    $tip .= ' [ALT+'.strtoupper($akey).']';
18511ea018fSAndreas Gohr    $ret .= 'accesskey="'.$akey.'" ';
18635dae8b0SBen Coburn  }
18735dae8b0SBen Coburn  $ret .= 'title="'.$tip.'" ';
188f3f0262cSandi  $ret .= '/>';
1894beabca9SAnika Henke  $ret .= '</div></form>';
190f3f0262cSandi
191f3f0262cSandi  return $ret;
192f3f0262cSandi}
193f3f0262cSandi
194f3f0262cSandi/**
19515fae107Sandi * show a wiki page
19615fae107Sandi *
19715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
19815fae107Sandi */
1996bbae538Sandifunction html_show($txt=''){
200f3f0262cSandi  global $ID;
201f3f0262cSandi  global $REV;
202f3f0262cSandi  global $HIGH;
203b8595a66SAndreas Gohr  global $INFO;
204f3f0262cSandi  //disable section editing for old revisions or in preview
2055400331dSandi  if($txt || $REV){
2066bbae538Sandi    $secedit = false;
2076bbae538Sandi  }else{
2086bbae538Sandi    $secedit = true;
209f3f0262cSandi  }
210f3f0262cSandi
2116bbae538Sandi  if ($txt){
212f3f0262cSandi    //PreviewHeader
213b8595a66SAndreas Gohr    echo '<br id="scroll__here" />';
214b8595a66SAndreas Gohr    echo p_locale_xhtml('preview');
215b8595a66SAndreas Gohr    echo '<div class="preview">';
216b8595a66SAndreas Gohr    $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
217b8595a66SAndreas Gohr    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
218b8595a66SAndreas Gohr    echo $html;
219b8595a66SAndreas Gohr    echo '<div class="clearer"></div>';
220b8595a66SAndreas Gohr    echo '</div>';
2216bbae538Sandi
222f3f0262cSandi  }else{
223c112d578Sandi    if ($REV) print p_locale_xhtml('showrev');
224c112d578Sandi    $html = p_wiki_xhtml($ID,$REV,true);
2256bbae538Sandi    $html = html_secedit($html,$secedit);
226b8595a66SAndreas Gohr    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
227b8595a66SAndreas Gohr    $html = html_hilight($html,$HIGH);
228b8595a66SAndreas Gohr    echo $html;
229f3f0262cSandi  }
230f3f0262cSandi}
231f3f0262cSandi
232f3f0262cSandi/**
233ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
234ee4c4a1bSAndreas Gohr *
235ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
236ee4c4a1bSAndreas Gohr */
237ee4c4a1bSAndreas Gohrfunction html_draft(){
238ee4c4a1bSAndreas Gohr  global $INFO;
239ee4c4a1bSAndreas Gohr  global $ID;
240ee4c4a1bSAndreas Gohr  global $lang;
241ee4c4a1bSAndreas Gohr  global $conf;
242ee4c4a1bSAndreas Gohr  $draft = unserialize(io_readFile($INFO['draft'],false));
243ee4c4a1bSAndreas Gohr  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
244ee4c4a1bSAndreas Gohr
245fdb8d77bSTom N Harris  print p_locale_xhtml('draft');
246fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
247fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
248fdb8d77bSTom N Harris  $form->addHidden('date', $draft['date']);
249fdb8d77bSTom N Harris  $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
250fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
251e656dcd4SAndreas Gohr  $form->addElement($lang['draftdate'].' '. strftime($conf['dformat'],filemtime($INFO['draft'])));
252fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
253fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
254fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
255fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
256fdb8d77bSTom N Harris  html_form('draft', $form);
257ee4c4a1bSAndreas Gohr}
258ee4c4a1bSAndreas Gohr
259ee4c4a1bSAndreas Gohr/**
260f3f0262cSandi * Highlights searchqueries in HTML code
26115fae107Sandi *
26215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2637209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
264f3f0262cSandi */
265546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
266546d3a99SAndreas Gohr  $regex = join('|',array_map('preg_quote_cb',array_filter((array) $phrases)));
26760c15d7dSAndreas Gohr
26860c15d7dSAndreas Gohr  if ($regex === '') return $html;
2691db218e9SAndreas Gohr  $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
270f3f0262cSandi  return $html;
271f3f0262cSandi}
272f3f0262cSandi
273f3f0262cSandi/**
2747209be23SAndreas Gohr * Callback used by html_hilight()
2757209be23SAndreas Gohr *
2767209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2777209be23SAndreas Gohr */
2787209be23SAndreas Gohrfunction html_hilight_callback($m) {
2797209be23SAndreas Gohr  $hlight = unslash($m[0]);
2807209be23SAndreas Gohr  if ( !isset($m[2])) {
281688774a0SAnika Henke    $hlight = '<span class="search_hit">'.$hlight.'</span>';
2827209be23SAndreas Gohr  }
2837209be23SAndreas Gohr  return $hlight;
2847209be23SAndreas Gohr}
2857209be23SAndreas Gohr
2867209be23SAndreas Gohr/**
28715fae107Sandi * Run a search and display the result
28815fae107Sandi *
28915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
290f3f0262cSandi */
291f3f0262cSandifunction html_search(){
292ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
293506fa893SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
294f3f0262cSandi  global $conf;
295f3f0262cSandi  global $QUERY;
296f3f0262cSandi  global $ID;
297f3f0262cSandi  global $lang;
298f3f0262cSandi
299c112d578Sandi  print p_locale_xhtml('searchpage');
300f3f0262cSandi  flush();
301f3f0262cSandi
302d0ab54f6SMichael Klier chi@chimeric.de  //check if search is restricted to namespace
303d0ab54f6SMichael Klier chi@chimeric.de  if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) {
304d0ab54f6SMichael Klier chi@chimeric.de      $id = cleanID($match[1]);
305d0ab54f6SMichael Klier chi@chimeric.de      if(empty($id)) {
306d0ab54f6SMichael Klier chi@chimeric.de        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
307d0ab54f6SMichael Klier chi@chimeric.de        flush();
308d0ab54f6SMichael Klier chi@chimeric.de        return;
309d0ab54f6SMichael Klier chi@chimeric.de      }
310d0ab54f6SMichael Klier chi@chimeric.de  } else {
311d0ab54f6SMichael Klier chi@chimeric.de      $id = cleanID($QUERY);
312d0ab54f6SMichael Klier chi@chimeric.de  }
313d0ab54f6SMichael Klier chi@chimeric.de
3144d9ff3d5Sandi  //show progressbar
315e226efe1SAndreas Gohr  print '<div class="centeralign" id="dw__loading">'.NL;
316e226efe1SAndreas Gohr  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
317e226efe1SAndreas Gohr  print 'showLoadBar();'.NL;
318e226efe1SAndreas Gohr  print '//--><!]]></script>'.NL;
319e226efe1SAndreas Gohr  print '<br /></div>'.NL;
3209edac8a8SAndreas Gohr  flush();
3214d9ff3d5Sandi
322f3f0262cSandi  //do quick pagesearch
323f3f0262cSandi  $data = array();
324d0ab54f6SMichael Klier chi@chimeric.de
325d0ab54f6SMichael Klier chi@chimeric.de  $data = ft_pageLookup($id);
326f3f0262cSandi  if(count($data)){
327f3f0262cSandi    sort($data);
328f3f0262cSandi    print '<div class="search_quickresult">';
329746855cfSBen Coburn    print '<h3>'.$lang['quickhits'].':</h3>';
3304f732f0eSAnika Henke    print '<ul class="search_quickhits">';
331140c93f3SAnika Henke    foreach($data as $id){
3324f732f0eSAnika Henke      print '<li> ';
333ebbb1c49SAndreas Gohr      print html_wikilink(':'.$id,noNS($id));
3344f732f0eSAnika Henke      print '</li> ';
335f3f0262cSandi    }
336140c93f3SAnika Henke    print '</ul> ';
337f3f0262cSandi    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
338f3f0262cSandi    print '<div class="clearer">&nbsp;</div>';
339f3f0262cSandi    print '</div>';
340f3f0262cSandi  }
341f3f0262cSandi  flush();
342f3f0262cSandi
343f3f0262cSandi  //do fulltext search
34460c15d7dSAndreas Gohr  $data = ft_pageSearch($QUERY,$regex);
345f3f0262cSandi  if(count($data)){
346506fa893SAndreas Gohr    $num = 1;
347506fa893SAndreas Gohr    foreach($data as $id => $cnt){
348f3f0262cSandi      print '<div class="search_result">';
34960c15d7dSAndreas Gohr      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$regex);
350506fa893SAndreas Gohr      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
351506fa893SAndreas Gohr      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
35260c15d7dSAndreas Gohr        print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
353506fa893SAndreas Gohr      }
354f3f0262cSandi      print '</div>';
355506fa893SAndreas Gohr      flush();
356506fa893SAndreas Gohr      $num++;
357f3f0262cSandi    }
358f3f0262cSandi  }else{
359820fa24bSandi    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
360f3f0262cSandi  }
3614d9ff3d5Sandi
3624d9ff3d5Sandi  //hide progressbar
363e226efe1SAndreas Gohr  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
364e226efe1SAndreas Gohr  print 'hideLoadBar("dw__loading");'.NL;
365e226efe1SAndreas Gohr  print '//--><!]]></script>'.NL;
3669edac8a8SAndreas Gohr  flush();
367f3f0262cSandi}
368f3f0262cSandi
36915fae107Sandi/**
37015fae107Sandi * Display error on locked pages
37115fae107Sandi *
37215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
37315fae107Sandi */
374ee20e7d1Sandifunction html_locked(){
375f3f0262cSandi  global $ID;
376f3f0262cSandi  global $conf;
377f3f0262cSandi  global $lang;
37888f522e9Sandi  global $INFO;
379f3f0262cSandi
380c9b4bd1eSBen Coburn  $locktime = filemtime(wikiLockFN($ID));
381e656dcd4SAndreas Gohr  $expire = @strftime($conf['dformat'], $locktime + $conf['locktime'] );
382f3f0262cSandi  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
383f3f0262cSandi
384c112d578Sandi  print p_locale_xhtml('locked');
385f3f0262cSandi  print '<ul>';
3860c6b58a8SAndreas Gohr  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
3870c6b58a8SAndreas Gohr  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
388f3f0262cSandi  print '</ul>';
389f3f0262cSandi}
390f3f0262cSandi
39115fae107Sandi/**
39215fae107Sandi * list old revisions
39315fae107Sandi *
39415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
39571726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
39615fae107Sandi */
39771726d78SBen Coburnfunction html_revisions($first=0){
398f3f0262cSandi  global $ID;
399f3f0262cSandi  global $INFO;
400f3f0262cSandi  global $conf;
401f3f0262cSandi  global $lang;
40271726d78SBen Coburn  /* we need to get one additionally log entry to be able to
40371726d78SBen Coburn   * decide if this is the last page or is there another one.
40471726d78SBen Coburn   * see html_recent()
40571726d78SBen Coburn   */
40671726d78SBen Coburn  $revisions = getRevisions($ID, $first, $conf['recent']+1);
40771726d78SBen Coburn  if(count($revisions)==0 && $first!=0){
40871726d78SBen Coburn    $first=0;
40971726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);;
41071726d78SBen Coburn  }
41171726d78SBen Coburn  $hasNext = false;
41271726d78SBen Coburn  if (count($revisions)>$conf['recent']) {
41371726d78SBen Coburn    $hasNext = true;
41471726d78SBen Coburn    array_pop($revisions); // remove extra log entry
41571726d78SBen Coburn  }
41671726d78SBen Coburn
417e656dcd4SAndreas Gohr  $date = @strftime($conf['dformat'],$INFO['lastmod']);
418f3f0262cSandi
419c112d578Sandi  print p_locale_xhtml('revisions');
42077707b04SAndreas Gohr  print '<form action="'.wl($ID).'" method="post" id="page__revisions">';
421f3f0262cSandi  print '<ul>';
42271726d78SBen Coburn  if($INFO['exists'] && $first==0){
423ebf1501fSBen Coburn    print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
4240c6b58a8SAndreas Gohr    print '<div class="li">';
42577707b04SAndreas Gohr    print '<input type="checkbox" name="rev2[]" value="current" /> ';
426f9b2fe70Sandi
427f9b2fe70Sandi    print $date;
428f9b2fe70Sandi
42902e51121SAnika Henke    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
430cffcc403Sandi
431f9b2fe70Sandi    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
432652610a2Sandi
43341396b71SAndreas Gohr    print ' &ndash; ';
434652610a2Sandi    print $INFO['sum'];
43588f522e9Sandi    print ' <span class="user">';
4365aa52fafSBen Coburn    print (empty($INFO['editor']))?('('.$lang['external_edit'].')'):$INFO['editor'];
43788f522e9Sandi    print '</span> ';
438652610a2Sandi
439652610a2Sandi    print '('.$lang['current'].')';
4400c6b58a8SAndreas Gohr    print '</div>';
441652610a2Sandi    print '</li>';
442f3f0262cSandi  }
443f3f0262cSandi
444f3f0262cSandi  foreach($revisions as $rev){
445e656dcd4SAndreas Gohr    $date   = strftime($conf['dformat'],$rev);
446fb53bfe2SBen Coburn    $info   = getRevisionInfo($ID,$rev,true);
447103c256aSChris Smith    $exists = page_exists($ID,$rev);
448652610a2Sandi
449ebf1501fSBen Coburn    print ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
4500c6b58a8SAndreas Gohr    print '<div class="li">';
45177707b04SAndreas Gohr    if($exists){
45277707b04SAndreas Gohr      print '<input type="checkbox" name="rev2[]" value="'.$rev.'" /> ';
45377707b04SAndreas Gohr    }else{
45477707b04SAndreas Gohr      print '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="14" height="11" alt="" /> ';
45577707b04SAndreas Gohr    }
456f9b2fe70Sandi    print $date;
457f9b2fe70Sandi
45877707b04SAndreas Gohr    if($exists){
459cffcc403Sandi      print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
460d94f4568SAndreas Gohr      $p = array();
461d94f4568SAndreas Gohr      $p['src']    = DOKU_BASE.'lib/images/diff.png';
462d94f4568SAndreas Gohr      $p['width']  = 15;
463d94f4568SAndreas Gohr      $p['height'] = 11;
464d94f4568SAndreas Gohr      $p['title']  = $lang['diff'];
465d94f4568SAndreas Gohr      $p['alt']    = $lang['diff'];
466d94f4568SAndreas Gohr      $att = buildAttributes($p);
467d94f4568SAndreas Gohr      print "<img $att />";
468cffcc403Sandi      print '</a> ';
469cffcc403Sandi
470f9b2fe70Sandi      print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>';
47141396b71SAndreas Gohr    }else{
47241396b71SAndreas Gohr      print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
47341396b71SAndreas Gohr      print $ID;
47441396b71SAndreas Gohr    }
475f9b2fe70Sandi
47641396b71SAndreas Gohr    print ' &ndash; ';
477f243a77fSandi    print htmlspecialchars($info['sum']);
47888f522e9Sandi    print ' <span class="user">';
47988f522e9Sandi    if($info['user']){
48088f522e9Sandi      print $info['user'];
48188f522e9Sandi    }else{
482652610a2Sandi      print $info['ip'];
48388f522e9Sandi    }
48488f522e9Sandi    print '</span>';
485652610a2Sandi
4860c6b58a8SAndreas Gohr    print '</div>';
487f3f0262cSandi    print '</li>';
488f3f0262cSandi  }
489f3f0262cSandi  print '</ul>';
49077707b04SAndreas Gohr  print '<input name="do[diff]" type="submit" value="'.$lang['diff2'].'" class="button" />';
49177707b04SAndreas Gohr  print '</form>';
49271726d78SBen Coburn
49371726d78SBen Coburn  print '<div class="pagenav">';
49471726d78SBen Coburn  $last = $first + $conf['recent'];
49571726d78SBen Coburn  if ($first > 0) {
49671726d78SBen Coburn    $first -= $conf['recent'];
49771726d78SBen Coburn    if ($first < 0) $first = 0;
49871726d78SBen Coburn    print '<div class="pagenav-prev">';
499eeb83e57SBen Coburn    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
50071726d78SBen Coburn    print '</div>';
50171726d78SBen Coburn  }
50271726d78SBen Coburn  if ($hasNext) {
50371726d78SBen Coburn    print '<div class="pagenav-next">';
504eeb83e57SBen Coburn    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
50571726d78SBen Coburn    print '</div>';
50671726d78SBen Coburn  }
50771726d78SBen Coburn  print '</div>';
50871726d78SBen Coburn
509f3f0262cSandi}
510f3f0262cSandi
51115fae107Sandi/**
51215fae107Sandi * display recent changes
51315fae107Sandi *
51415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5155749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
51671726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
51715fae107Sandi */
518a39955b0Smatthiasgrimmfunction html_recent($first=0){
519f3f0262cSandi  global $conf;
520cffcc403Sandi  global $lang;
521dbb00abcSEsther Brunner  global $ID;
5225749f1ceSmatthiasgrimm  /* we need to get one additionally log entry to be able to
5235749f1ceSmatthiasgrimm   * decide if this is the last page or is there another one.
5245749f1ceSmatthiasgrimm   * This is the cheapest solution to get this information.
5255749f1ceSmatthiasgrimm   */
526b6912aeaSAndreas Gohr  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5275749f1ceSmatthiasgrimm  if(count($recents) == 0 && $first != 0){
5285749f1ceSmatthiasgrimm    $first=0;
52971726d78SBen Coburn    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5305749f1ceSmatthiasgrimm  }
53171726d78SBen Coburn  $hasNext = false;
53271726d78SBen Coburn  if (count($recents)>$conf['recent']) {
53371726d78SBen Coburn    $hasNext = true;
53471726d78SBen Coburn    array_pop($recents); // remove extra log entry
53571726d78SBen Coburn  }
536f3f0262cSandi
537c112d578Sandi  print p_locale_xhtml('recent');
538f3f0262cSandi  print '<ul>';
539a39955b0Smatthiasgrimm
540d437bcc4SAndreas Gohr  foreach($recents as $recent){
541e656dcd4SAndreas Gohr    $date = strftime($conf['dformat'],$recent['date']);
542ebf1501fSBen Coburn    print ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
5430c6b58a8SAndreas Gohr    print '<div class="li">';
544cffcc403Sandi
545f9b2fe70Sandi    print $date.' ';
546f9b2fe70Sandi
547d437bcc4SAndreas Gohr    print '<a href="'.wl($recent['id'],"do=diff").'">';
548d94f4568SAndreas Gohr    $p = array();
549d94f4568SAndreas Gohr    $p['src']    = DOKU_BASE.'lib/images/diff.png';
550d94f4568SAndreas Gohr    $p['width']  = 15;
551d94f4568SAndreas Gohr    $p['height'] = 11;
552d94f4568SAndreas Gohr    $p['title']  = $lang['diff'];
553d94f4568SAndreas Gohr    $p['alt']    = $lang['diff'];
554d94f4568SAndreas Gohr    $att = buildAttributes($p);
555d94f4568SAndreas Gohr    print "<img $att />";
556cffcc403Sandi    print '</a> ';
557cffcc403Sandi
558d437bcc4SAndreas Gohr    print '<a href="'.wl($recent['id'],"do=revisions").'">';
559d94f4568SAndreas Gohr    $p = array();
560d94f4568SAndreas Gohr    $p['src']    = DOKU_BASE.'lib/images/history.png';
561d94f4568SAndreas Gohr    $p['width']  = 12;
562d94f4568SAndreas Gohr    $p['height'] = 14;
563d94f4568SAndreas Gohr    $p['title']  = $lang['btn_revs'];
564d94f4568SAndreas Gohr    $p['alt']    = $lang['btn_revs'];
565d94f4568SAndreas Gohr    $att = buildAttributes($p);
566d94f4568SAndreas Gohr    print "<img $att />";
567cffcc403Sandi    print '</a> ';
568cffcc403Sandi
569d437bcc4SAndreas Gohr    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
57041396b71SAndreas Gohr    print ' &ndash; '.htmlspecialchars($recent['sum']);
571b6912aeaSAndreas Gohr
57288f522e9Sandi    print ' <span class="user">';
573d437bcc4SAndreas Gohr    if($recent['user']){
574d437bcc4SAndreas Gohr      print $recent['user'];
57588f522e9Sandi    }else{
576d437bcc4SAndreas Gohr      print $recent['ip'];
57788f522e9Sandi    }
57888f522e9Sandi    print '</span>';
579cffcc403Sandi
5800c6b58a8SAndreas Gohr    print '</div>';
581f3f0262cSandi    print '</li>';
582f3f0262cSandi  }
583f3f0262cSandi  print '</ul>';
584a39955b0Smatthiasgrimm
585a39955b0Smatthiasgrimm  print '<div class="pagenav">';
5865749f1ceSmatthiasgrimm  $last = $first + $conf['recent'];
587a39955b0Smatthiasgrimm  if ($first > 0) {
588a39955b0Smatthiasgrimm    $first -= $conf['recent'];
589a39955b0Smatthiasgrimm    if ($first < 0) $first = 0;
590a39955b0Smatthiasgrimm    print '<div class="pagenav-prev">';
5915749f1ceSmatthiasgrimm    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
592a39955b0Smatthiasgrimm    print '</div>';
593a39955b0Smatthiasgrimm  }
59471726d78SBen Coburn  if ($hasNext) {
595a39955b0Smatthiasgrimm    print '<div class="pagenav-next">';
5965749f1ceSmatthiasgrimm    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
597a39955b0Smatthiasgrimm    print '</div>';
598a39955b0Smatthiasgrimm  }
599a39955b0Smatthiasgrimm  print '</div>';
600f3f0262cSandi}
601f3f0262cSandi
60215fae107Sandi/**
60315fae107Sandi * Display page index
60415fae107Sandi *
60515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
60615fae107Sandi */
607f3f0262cSandifunction html_index($ns){
608ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
609f3f0262cSandi  global $conf;
610f3f0262cSandi  global $ID;
611f3f0262cSandi  $dir = $conf['datadir'];
612f3f0262cSandi  $ns  = cleanID($ns);
61330f1737dSandi  #fixme use appropriate function
614f3f0262cSandi  if(empty($ns)){
615f3f0262cSandi    $ns = dirname(str_replace(':','/',$ID));
616f3f0262cSandi    if($ns == '.') $ns ='';
617f3f0262cSandi  }
61888d3a917Sandi  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
619f3f0262cSandi
620a06884abSAndreas Gohr  echo p_locale_xhtml('index');
621a06884abSAndreas Gohr  echo '<div id="index__tree">';
622f3f0262cSandi
623f3f0262cSandi  $data = array();
624f3f0262cSandi  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
625a06884abSAndreas Gohr  echo html_buildlist($data,'idx','html_list_index','html_li_index');
626a06884abSAndreas Gohr
627a06884abSAndreas Gohr  echo '</div>';
628f3f0262cSandi}
629f3f0262cSandi
630f3f0262cSandi/**
63115fae107Sandi * Index item formatter
63215fae107Sandi *
633f3f0262cSandi * User function for html_buildlist()
63415fae107Sandi *
63515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
636f3f0262cSandi */
637f3f0262cSandifunction html_list_index($item){
638d98d4540SBen Coburn  global $ID;
639f3f0262cSandi  $ret = '';
640f3f0262cSandi  $base = ':'.$item['id'];
641f3f0262cSandi  $base = substr($base,strrpos($base,':')+1);
642f3f0262cSandi  if($item['type']=='d'){
6434a119027SAndreas Gohr    $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
644f3f0262cSandi    $ret .= $base;
645ed7ecb79SAnika Henke    $ret .= '</strong></a>';
646f3f0262cSandi  }else{
647f3f0262cSandi    $ret .= html_wikilink(':'.$item['id']);
648f3f0262cSandi  }
649f3f0262cSandi  return $ret;
650f3f0262cSandi}
651f3f0262cSandi
652f3f0262cSandi/**
653cb70c441Sandi * Index List item
654cb70c441Sandi *
655cb70c441Sandi * This user function is used in html_build_lidt to build the
656cb70c441Sandi * <li> tags for namespaces when displaying the page index
657cb70c441Sandi * it gives different classes to opened or closed "folders"
658cb70c441Sandi *
659cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
660cb70c441Sandi */
661cb70c441Sandifunction html_li_index($item){
662cb70c441Sandi  if($item['type'] == "f"){
663cb70c441Sandi    return '<li class="level'.$item['level'].'">';
664cb70c441Sandi  }elseif($item['open']){
665cb70c441Sandi    return '<li class="open">';
666cb70c441Sandi  }else{
667cb70c441Sandi    return '<li class="closed">';
668cb70c441Sandi  }
669cb70c441Sandi}
670cb70c441Sandi
671cb70c441Sandi/**
672cb70c441Sandi * Default List item
673cb70c441Sandi *
674cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
675cb70c441Sandi */
676cb70c441Sandifunction html_li_default($item){
677cb70c441Sandi  return '<li class="level'.$item['level'].'">';
678cb70c441Sandi}
679cb70c441Sandi
680cb70c441Sandi/**
68115fae107Sandi * Build an unordered list
68215fae107Sandi *
683f3f0262cSandi * Build an unordered list from the given $data array
684f3f0262cSandi * Each item in the array has to have a 'level' property
685f3f0262cSandi * the item itself gets printed by the given $func user
686cb70c441Sandi * function. The second and optional function is used to
687cb70c441Sandi * print the <li> tag. Both user function need to accept
688cb70c441Sandi * a single item.
68915fae107Sandi *
690c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
691c5a8fd96SAndreas Gohr * a member of an object.
692c5a8fd96SAndreas Gohr *
69315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
694f3f0262cSandi */
695cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
696f3f0262cSandi  $level = 0;
697f3f0262cSandi  $opens = 0;
698f3f0262cSandi  $ret   = '';
699f3f0262cSandi
700f3f0262cSandi  foreach ($data as $item){
701f3f0262cSandi
702f3f0262cSandi    if( $item['level'] > $level ){
703f3f0262cSandi      //open new list
704df52d0feSandi      for($i=0; $i<($item['level'] - $level); $i++){
705df52d0feSandi        if ($i) $ret .= "<li class=\"clear\">\n";
706f3f0262cSandi        $ret .= "\n<ul class=\"$class\">\n";
707df52d0feSandi      }
708f3f0262cSandi    }elseif( $item['level'] < $level ){
709f3f0262cSandi      //close last item
710f3f0262cSandi      $ret .= "</li>\n";
711f3f0262cSandi      for ($i=0; $i<($level - $item['level']); $i++){
712f3f0262cSandi        //close higher lists
713f3f0262cSandi        $ret .= "</ul>\n</li>\n";
714f3f0262cSandi      }
715f3f0262cSandi    }else{
716f3f0262cSandi      //close last item
717f3f0262cSandi      $ret .= "</li>\n";
718f3f0262cSandi    }
719f3f0262cSandi
720f3f0262cSandi    //remember current level
721f3f0262cSandi    $level = $item['level'];
722f3f0262cSandi
723f3f0262cSandi    //print item
72434dbe711Schris    $ret .= call_user_func($lifunc,$item);
7250c6b58a8SAndreas Gohr    $ret .= '<div class="li">';
72634dbe711Schris
72734dbe711Schris    $ret .= call_user_func($func,$item);
7280c6b58a8SAndreas Gohr    $ret .= '</div>';
729f3f0262cSandi  }
730f3f0262cSandi
731f3f0262cSandi  //close remaining items and lists
732f3f0262cSandi  for ($i=0; $i < $level; $i++){
733f3f0262cSandi    $ret .= "</li></ul>\n";
734f3f0262cSandi  }
735f3f0262cSandi
736f3f0262cSandi  return $ret;
737f3f0262cSandi}
738f3f0262cSandi
73915fae107Sandi/**
74015fae107Sandi * display backlinks
74115fae107Sandi *
74215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
74311df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
74415fae107Sandi */
745f3f0262cSandifunction html_backlinks(){
74654f4c056SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
747f3f0262cSandi  global $ID;
748f3f0262cSandi  global $conf;
74911df47ecSMichael Klier  global $lang;
750f3f0262cSandi
751c112d578Sandi  print p_locale_xhtml('backlinks');
752f3f0262cSandi
75354f4c056SAndreas Gohr  $data = ft_backlinks($ID);
754f3f0262cSandi
75511df47ecSMichael Klier  if(!empty($data)) {
756f3f0262cSandi      print '<ul class="idx">';
75754f4c056SAndreas Gohr      foreach($data as $blink){
7580c6b58a8SAndreas Gohr        print '<li><div class="li">';
75954f4c056SAndreas Gohr        print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
7600c6b58a8SAndreas Gohr        print '</div></li>';
761f3f0262cSandi      }
762f3f0262cSandi      print '</ul>';
76311df47ecSMichael Klier  } else {
76411df47ecSMichael Klier      print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
76511df47ecSMichael Klier  }
766f3f0262cSandi}
767f3f0262cSandi
76815fae107Sandi/**
76915fae107Sandi * show diff
77015fae107Sandi *
77115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
77215fae107Sandi */
773f3f0262cSandifunction html_diff($text='',$intro=true){
774ed7b5f09Sandi  require_once(DOKU_INC.'inc/DifferenceEngine.php');
775f3f0262cSandi  global $ID;
776f3f0262cSandi  global $REV;
777f3f0262cSandi  global $lang;
778f3f0262cSandi  global $conf;
779e1bd90ffSAndreas Gohr
78077707b04SAndreas Gohr  // we're trying to be clever here, revisions to compare can be either
78177707b04SAndreas Gohr  // given as rev and rev2 parameters, with rev2 being optional. Or in an
78277707b04SAndreas Gohr  // array in rev2.
78377707b04SAndreas Gohr  $rev1 = $REV;
7847b3f8b16SAndreas Gohr
78577707b04SAndreas Gohr  if(is_array($_REQUEST['rev2'])){
78677707b04SAndreas Gohr    $rev1 = (int) $_REQUEST['rev2'][0];
78777707b04SAndreas Gohr    $rev2 = (int) $_REQUEST['rev2'][1];
788*54041c77SAndreas Gohr
789*54041c77SAndreas Gohr    if(!$rev1){
790*54041c77SAndreas Gohr        $rev1 = $rev2;
791*54041c77SAndreas Gohr        unset($rev2);
792*54041c77SAndreas Gohr    }
793f3f0262cSandi  }else{
79477707b04SAndreas Gohr    $rev2 = (int) $_REQUEST['rev2'];
7954d58bd99Sandi  }
7964d58bd99Sandi
79777707b04SAndreas Gohr  if($text){                      // compare text to the most current revision
79877707b04SAndreas Gohr    $l_rev   = '';
79977707b04SAndreas Gohr    $l_text  = rawWiki($ID,'');
80077707b04SAndreas Gohr    $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
801e656dcd4SAndreas Gohr               $ID.' '.strftime($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
80277707b04SAndreas Gohr               $lang['current'];
80377707b04SAndreas Gohr
80477707b04SAndreas Gohr    $r_rev   = '';
80577707b04SAndreas Gohr    $r_text  = cleanText($text);
80677707b04SAndreas Gohr    $r_head  = $lang['yours'];
807e1bd90ffSAndreas Gohr  }else{
80877707b04SAndreas Gohr    if($rev1 && $rev2){            // two specific revisions wanted
809*54041c77SAndreas Gohr      // make sure order is correct (older on the left)
81077707b04SAndreas Gohr      if($rev1 < $rev2){
81177707b04SAndreas Gohr        $l_rev = $rev1;
81277707b04SAndreas Gohr        $r_rev = $rev2;
81377707b04SAndreas Gohr      }else{
81477707b04SAndreas Gohr        $l_rev = $rev2;
81577707b04SAndreas Gohr        $r_rev = $rev1;
816e1bd90ffSAndreas Gohr      }
81777707b04SAndreas Gohr    }elseif($rev1){                // single revision given, compare to current
81877707b04SAndreas Gohr      $r_rev = '';
81977707b04SAndreas Gohr      $l_rev = $rev1;
82077707b04SAndreas Gohr    }else{                        // no revision was given, compare previous to current
82177707b04SAndreas Gohr      $r_rev = '';
82277707b04SAndreas Gohr      $revs = getRevisions($ID, 0, 1);
82377707b04SAndreas Gohr      $l_rev = $revs[0];
82477707b04SAndreas Gohr    }
82577707b04SAndreas Gohr
8267b3f8b16SAndreas Gohr    // when both revisions are empty then the page was created just now
8277b3f8b16SAndreas Gohr    if(!$l_rev && !$r_rev){
8287b3f8b16SAndreas Gohr      $l_text = '';
8297b3f8b16SAndreas Gohr    }else{
83077707b04SAndreas Gohr      $l_text = rawWiki($ID,$l_rev);
8317b3f8b16SAndreas Gohr    }
83277707b04SAndreas Gohr    $r_text = rawWiki($ID,$r_rev);
83377707b04SAndreas Gohr
8347b3f8b16SAndreas Gohr
8357b3f8b16SAndreas Gohr    if(!$l_rev){
8367b3f8b16SAndreas Gohr      $l_head = '&mdash;';
8377b3f8b16SAndreas Gohr    }else{
83877707b04SAndreas Gohr      $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
839e656dcd4SAndreas Gohr                $ID.' '.strftime($conf['dformat'],$l_rev).'</a>';
8407b3f8b16SAndreas Gohr    }
84177707b04SAndreas Gohr
84277707b04SAndreas Gohr    if($r_rev){
84377707b04SAndreas Gohr      $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
844e656dcd4SAndreas Gohr                $ID.' '.strftime($conf['dformat'],$r_rev).'</a>';
8457b3f8b16SAndreas Gohr    }elseif($_rev = @filemtime(wikiFN($ID))){
84677707b04SAndreas Gohr      $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
8477b3f8b16SAndreas Gohr               $ID.' '.strftime($conf['dformat'],$_rev).'</a> '.
848f3f0262cSandi               $lang['current'];
8497b3f8b16SAndreas Gohr    }else{
8507b3f8b16SAndreas Gohr      $r_head = '&mdash; '.$lang['current'];
851f3f0262cSandi    }
85277707b04SAndreas Gohr  }
85377707b04SAndreas Gohr
85477707b04SAndreas Gohr  $df = new Diff(explode("\n",htmlspecialchars($l_text)),
85577707b04SAndreas Gohr                 explode("\n",htmlspecialchars($r_text)));
85677707b04SAndreas Gohr
857f3f0262cSandi  $tdf = new TableDiffFormatter();
858c112d578Sandi  if($intro) print p_locale_xhtml('diff');
859f3f0262cSandi  ?>
860daf4ca4eSAnika Henke    <table class="diff">
861f3f0262cSandi      <tr>
862daf4ca4eSAnika Henke        <th colspan="2">
86377707b04SAndreas Gohr          <?php echo $l_head?>
864daf4ca4eSAnika Henke        </th>
865daf4ca4eSAnika Henke        <th colspan="2">
86677707b04SAndreas Gohr          <?php echo $r_head?>
867daf4ca4eSAnika Henke        </th>
868f3f0262cSandi      </tr>
8694da078a3Smatthiasgrimm      <?php echo $tdf->format($df)?>
870f3f0262cSandi    </table>
8714da078a3Smatthiasgrimm  <?php
872f3f0262cSandi}
873f3f0262cSandi
87415fae107Sandi/**
87515fae107Sandi * show warning on conflict detection
87615fae107Sandi *
87715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
87815fae107Sandi */
879f3f0262cSandifunction html_conflict($text,$summary){
880f3f0262cSandi  global $ID;
881f3f0262cSandi  global $lang;
882f3f0262cSandi
883c112d578Sandi  print p_locale_xhtml('conflict');
884fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
885fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
886fdb8d77bSTom N Harris  $form->addHidden('wikitext', $text);
887fdb8d77bSTom N Harris  $form->addHidden('summary', $summary);
888fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
889fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
890fdb8d77bSTom N Harris  html_form('conflict', $form);
891fdb8d77bSTom N Harris  print '<br /><br /><br /><br />'.NL;
892f3f0262cSandi}
893f3f0262cSandi
894f3f0262cSandi/**
89515fae107Sandi * Prints the global message array
89615fae107Sandi *
89715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
898f3f0262cSandi */
899f3f0262cSandifunction html_msgarea(){
900f3f0262cSandi  global $MSG;
901f3f0262cSandi
902f3f0262cSandi  if(!isset($MSG)) return;
903f3f0262cSandi
904f3f0262cSandi  foreach($MSG as $msg){
905f3f0262cSandi    print '<div class="'.$msg['lvl'].'">';
906f3f0262cSandi    print $msg['msg'];
907f3f0262cSandi    print '</div>';
908f3f0262cSandi  }
909f3f0262cSandi}
910f3f0262cSandi
911f3f0262cSandi/**
912f3f0262cSandi * Prints the registration form
91315fae107Sandi *
91415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
915f3f0262cSandi */
916f3f0262cSandifunction html_register(){
917f3f0262cSandi  global $lang;
918cab2716aSmatthias.grimm  global $conf;
919f3f0262cSandi  global $ID;
920f3f0262cSandi
921c112d578Sandi  print p_locale_xhtml('register');
922fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
923fdb8d77bSTom N Harris  $form = new Doku_Form('dw__register', wl($ID));
924fdb8d77bSTom N Harris  $form->startFieldset($lang['register']);
925fdb8d77bSTom N Harris  $form->addHidden('do', 'register');
926fdb8d77bSTom N Harris  $form->addHidden('save', '1');
927fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
928cab2716aSmatthias.grimm  if (!$conf['autopasswd']) {
929fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
930fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
931cab2716aSmatthias.grimm  }
932fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
933fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
934fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['register']));
935fdb8d77bSTom N Harris  $form->endFieldset();
936fdb8d77bSTom N Harris  html_form('register', $form);
937cab2716aSmatthias.grimm
938fdb8d77bSTom N Harris  print '</div>'.NL;
939f3f0262cSandi}
940f3f0262cSandi
941f3f0262cSandi/**
9428b06d178Schris * Print the update profile form
9438b06d178Schris *
9448b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
9458b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
9468b06d178Schris */
9478b06d178Schrisfunction html_updateprofile(){
9488b06d178Schris  global $lang;
9498b06d178Schris  global $conf;
9508b06d178Schris  global $ID;
9518b06d178Schris  global $INFO;
95282fd59b6SAndreas Gohr  global $auth;
9538b06d178Schris
9548b06d178Schris  print p_locale_xhtml('updateprofile');
9558b06d178Schris
9568b06d178Schris  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
9578b06d178Schris  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
958fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
959fdb8d77bSTom N Harris  $form = new Doku_Form('dw__register', wl($ID));
960fdb8d77bSTom N Harris  $form->startFieldset($lang['profile']);
961fdb8d77bSTom N Harris  $form->addHidden('do', 'profile');
962fdb8d77bSTom N Harris  $form->addHidden('save', '1');
963fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
964fdb8d77bSTom N Harris  $attr = array('size'=>'50');
965fdb8d77bSTom N Harris  if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
966fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
96739ba8890SAndreas Gohr  $attr = array('size'=>'50');
96839ba8890SAndreas Gohr  if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
969fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
970fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
971fdb8d77bSTom N Harris  if ($auth->canDo('modPass')) {
972fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
973fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
974fdb8d77bSTom N Harris  }
975fdb8d77bSTom N Harris  if ($conf['profileconfirm']) {
976fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
977fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
978fdb8d77bSTom N Harris  }
979fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
980fdb8d77bSTom N Harris  $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
981fdb8d77bSTom N Harris  $form->endFieldset();
982fdb8d77bSTom N Harris  html_form('updateprofile', $form);
983fdb8d77bSTom N Harris  print '</div>'.NL;
9848b06d178Schris}
9858b06d178Schris
9868b06d178Schris/**
987f3f0262cSandi * This displays the edit form (lots of logic included)
98815fae107Sandi *
9897146cee2SAndreas Gohr * @fixme    this is a huge lump of code and should be modularized
990016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
991c9570649SAndreas Gohr * @triggers HTML_EDITFORM_INJECTION
99215fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
993f3f0262cSandi */
994f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
995f3f0262cSandi  global $ID;
996f3f0262cSandi  global $REV;
997f3f0262cSandi  global $DATE;
998f3f0262cSandi  global $RANGE;
999f3f0262cSandi  global $PRE;
1000f3f0262cSandi  global $SUF;
1001f3f0262cSandi  global $INFO;
1002f3f0262cSandi  global $SUM;
1003f3f0262cSandi  global $lang;
1004f3f0262cSandi  global $conf;
1005f3f0262cSandi
1006f3f0262cSandi  //set summary default
1007f3f0262cSandi  if(!$SUM){
1008f3f0262cSandi    if($REV){
1009f3f0262cSandi      $SUM = $lang['restored'];
1010f3f0262cSandi    }elseif(!$INFO['exists']){
1011f3f0262cSandi      $SUM = $lang['created'];
1012f3f0262cSandi    }
1013f3f0262cSandi  }
1014f3f0262cSandi
1015f3f0262cSandi  //no text? Load it!
1016f3f0262cSandi  if(!isset($text)){
1017f3f0262cSandi    $pr = false; //no preview mode
10187146cee2SAndreas Gohr    if($INFO['exists']){
1019f3f0262cSandi      if($RANGE){
1020f3f0262cSandi        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1021f3f0262cSandi      }else{
1022f3f0262cSandi        $text = rawWiki($ID,$REV);
1023f3f0262cSandi      }
10248fe3bb00STom N Harris      $check = md5($text);
10258fe3bb00STom N Harris      $mod = false;
1026f3f0262cSandi    }else{
10277146cee2SAndreas Gohr      //try to load a pagetemplate
1028b7d5a5f0SAndreas Gohr      $data = array($ID);
1029016b6153SAndreas Gohr      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
10308fe3bb00STom N Harris      $check = md5('');
10318fe3bb00STom N Harris      $mod = $text!=='';
10327146cee2SAndreas Gohr    }
10337146cee2SAndreas Gohr  }else{
1034f3f0262cSandi    $pr = true; //preview mode
10358fe3bb00STom N Harris    if (isset($_REQUEST['changecheck'])) {
10368fe3bb00STom N Harris      $check = $_REQUEST['changecheck'];
10378fe3bb00STom N Harris      $mod = md5($text)!==$check;
10388fe3bb00STom N Harris    } else {
10398fe3bb00STom N Harris      // Why? Assume default text is unmodified.
10408fe3bb00STom N Harris      $check = md5($text);
10418fe3bb00STom N Harris      $mod = false;
10428fe3bb00STom N Harris    }
1043f3f0262cSandi  }
1044f3f0262cSandi
1045f3f0262cSandi  $wr = $INFO['writable'];
1046f3f0262cSandi  if($wr){
1047c112d578Sandi    if ($REV) print p_locale_xhtml('editrev');
1048c112d578Sandi    print p_locale_xhtml($include);
1049f3f0262cSandi  }else{
1050409d7af7SAndreas Gohr    // check pseudo action 'source'
1051409d7af7SAndreas Gohr    if(!actionOK('source')){
1052409d7af7SAndreas Gohr      msg('Command disabled: source',-1);
1053409d7af7SAndreas Gohr      return;
1054409d7af7SAndreas Gohr    }
1055c112d578Sandi    print p_locale_xhtml('read');
1056f3f0262cSandi  }
1057f3f0262cSandi  if(!$DATE) $DATE = $INFO['lastmod'];
1058dc57ef04Sandi
1059dc57ef04Sandi
1060f3f0262cSandi?>
106163afe2a6SAnika Henke  <div style="width:99%;">
106242c7abd6SAndreas Gohr
106363afe2a6SAnika Henke   <div class="toolbar">
1064e656dcd4SAndreas Gohr      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div>
1065fdb8d77bSTom N Harris      <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1066409d7af7SAndreas Gohr      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
106720d062caSAndreas Gohr
10684da078a3Smatthiasgrimm      <?php if($wr){?>
1069e226efe1SAndreas Gohr      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
10704da078a3Smatthiasgrimm        <?php /* sets changed to true when previewed */?>
10718fe3bb00STom N Harris        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1072e226efe1SAndreas Gohr      //--><!]]></script>
107324a33b42SAndreas Gohr      <span id="spell__action"></span>
107424a33b42SAndreas Gohr      <div id="spell__suggest"></div>
1075ee4c4a1bSAndreas Gohr      <?php } ?>
107663afe2a6SAnika Henke   </div>
107724a33b42SAndreas Gohr   <div id="spell__result"></div>
10784da078a3Smatthiasgrimm<?php
1079fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
1080fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
1081fdb8d77bSTom N Harris  $form->addHidden('rev', $REV);
1082fdb8d77bSTom N Harris  $form->addHidden('date', $DATE);
1083fdb8d77bSTom N Harris  $form->addHidden('prefix', $PRE);
1084fdb8d77bSTom N Harris  $form->addHidden('suffix', $SUF);
1085fdb8d77bSTom N Harris  $form->addHidden('changecheck', $check);
1086fdb8d77bSTom N Harris  $attr = array('tabindex'=>'1');
1087fdb8d77bSTom N Harris  if (!$wr) $attr['readonly'] = 'readonly';
1088fdb8d77bSTom N Harris  $form->addElement(form_makeWikiText($text, $attr));
1089fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1090fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1091fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
1092fdb8d77bSTom N Harris  if ($wr) {
1093fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1094fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1095fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1096fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1097fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1098fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1099fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1100fdb8d77bSTom N Harris    $elem = html_minoredit();
1101fdb8d77bSTom N Harris    if ($elem) $form->addElement($elem);
1102fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1103fdb8d77bSTom N Harris  }
1104fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
1105fdb8d77bSTom N Harris  html_form('edit', $form);
1106fdb8d77bSTom N Harris  print '</div>'.NL;
1107f3f0262cSandi}
1108f3f0262cSandi
1109f3f0262cSandi/**
1110b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1111b6912aeaSAndreas Gohr *
1112b6912aeaSAndreas Gohr * @author Andrea Gohr <andi@splitbrain.org>
1113b6912aeaSAndreas Gohr */
1114b6912aeaSAndreas Gohrfunction html_minoredit(){
1115b6912aeaSAndreas Gohr  global $conf;
1116b6912aeaSAndreas Gohr  global $lang;
1117b6912aeaSAndreas Gohr  // minor edits are for logged in users only
1118b6912aeaSAndreas Gohr  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1119fdb8d77bSTom N Harris    return false;
1120b6912aeaSAndreas Gohr  }
1121b6912aeaSAndreas Gohr
1122b6912aeaSAndreas Gohr  $p = array();
1123b6912aeaSAndreas Gohr  $p['tabindex'] = 3;
1124bb4866bdSchris  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1125fdb8d77bSTom N Harris  return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1126b6912aeaSAndreas Gohr}
1127b6912aeaSAndreas Gohr
1128b6912aeaSAndreas Gohr/**
1129f3f0262cSandi * prints some debug info
113015fae107Sandi *
113115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1132f3f0262cSandi */
1133f3f0262cSandifunction html_debug(){
1134f3f0262cSandi  global $conf;
1135d16a4edaSandi  global $lang;
11365298a619SAndreas Gohr  global $auth;
1137100a97e3SAndreas Gohr  global $INFO;
1138100a97e3SAndreas Gohr
113928fb55ffSandi  //remove sensitive data
114028fb55ffSandi  $cnf = $conf;
114128fb55ffSandi  $cnf['auth']='***';
114228fb55ffSandi  $cnf['notify']='***';
11433dc3a5f1Sandi  $cnf['ftp']='***';
1144100a97e3SAndreas Gohr  $nfo = $INFO;
1145100a97e3SAndreas Gohr  $nfo['userinfo'] = '***';
1146100a97e3SAndreas Gohr  $ses = $_SESSION;
1147100a97e3SAndreas Gohr  $ses[$conf['title']]['auth'] = '***';
1148f3f0262cSandi
1149f3f0262cSandi  print '<html><body>';
1150f3f0262cSandi
1151f3f0262cSandi  print '<p>When reporting bugs please send all the following ';
1152f3f0262cSandi  print 'output as a mail to andi@splitbrain.org ';
1153f3f0262cSandi  print 'The best way to do this is to save this page in your browser</p>';
1154f3f0262cSandi
1155100a97e3SAndreas Gohr  print '<b>$INFO:</b><pre>';
1156100a97e3SAndreas Gohr  print_r($nfo);
1157100a97e3SAndreas Gohr  print '</pre>';
1158100a97e3SAndreas Gohr
1159f3f0262cSandi  print '<b>$_SERVER:</b><pre>';
1160f3f0262cSandi  print_r($_SERVER);
1161f3f0262cSandi  print '</pre>';
1162f3f0262cSandi
1163f3f0262cSandi  print '<b>$conf:</b><pre>';
116428fb55ffSandi  print_r($cnf);
1165f3f0262cSandi  print '</pre>';
1166f3f0262cSandi
1167ed7b5f09Sandi  print '<b>DOKU_BASE:</b><pre>';
1168ed7b5f09Sandi  print DOKU_BASE;
1169f3f0262cSandi  print '</pre>';
1170f3f0262cSandi
1171ed7b5f09Sandi  print '<b>abs DOKU_BASE:</b><pre>';
1172ed7b5f09Sandi  print DOKU_URL;
1173ed7b5f09Sandi  print '</pre>';
1174ed7b5f09Sandi
1175ed7b5f09Sandi  print '<b>rel DOKU_BASE:</b><pre>';
1176f3f0262cSandi  print dirname($_SERVER['PHP_SELF']).'/';
1177f3f0262cSandi  print '</pre>';
1178f3f0262cSandi
1179f3f0262cSandi  print '<b>PHP Version:</b><pre>';
1180f3f0262cSandi  print phpversion();
1181f3f0262cSandi  print '</pre>';
1182f3f0262cSandi
1183f3f0262cSandi  print '<b>locale:</b><pre>';
1184f3f0262cSandi  print setlocale(LC_ALL,0);
1185f3f0262cSandi  print '</pre>';
1186f3f0262cSandi
1187d16a4edaSandi  print '<b>encoding:</b><pre>';
1188d16a4edaSandi  print $lang['encoding'];
1189d16a4edaSandi  print '</pre>';
1190d16a4edaSandi
11915298a619SAndreas Gohr  if($auth){
11925298a619SAndreas Gohr    print '<b>Auth backend capabilities:</b><pre>';
11935298a619SAndreas Gohr    print_r($auth->cando);
11945298a619SAndreas Gohr    print '</pre>';
11955298a619SAndreas Gohr  }
11965298a619SAndreas Gohr
11973aa54d7cSAndreas Gohr  print '<b>$_SESSION:</b><pre>';
1198100a97e3SAndreas Gohr  print_r($ses);
11993aa54d7cSAndreas Gohr  print '</pre>';
12003aa54d7cSAndreas Gohr
1201f3f0262cSandi  print '<b>Environment:</b><pre>';
1202f3f0262cSandi  print_r($_ENV);
1203f3f0262cSandi  print '</pre>';
1204f3f0262cSandi
1205f3f0262cSandi  print '<b>PHP settings:</b><pre>';
1206f3f0262cSandi  $inis = ini_get_all();
1207f3f0262cSandi  print_r($inis);
1208f3f0262cSandi  print '</pre>';
1209f3f0262cSandi
1210f3f0262cSandi  print '</body></html>';
1211f3f0262cSandi}
1212f3f0262cSandi
1213c19fe9c0Sandifunction html_admin(){
1214c19fe9c0Sandi  global $ID;
1215f8cc712eSAndreas Gohr  global $INFO;
1216c19fe9c0Sandi  global $lang;
1217ca3a6df1SMatthias Grimm  global $conf;
1218c19fe9c0Sandi
1219c112d578Sandi  print p_locale_xhtml('admin');
1220c19fe9c0Sandi
122111e2ce22Schris  // build menu of admin functions from the plugins that handle them
122211e2ce22Schris  $pluginlist = plugin_list('admin');
122311e2ce22Schris  $menu = array();
122411e2ce22Schris  foreach ($pluginlist as $p) {
122511e2ce22Schris    if($obj =& plugin_load('admin',$p) === NULL) continue;
1226f8cc712eSAndreas Gohr
1227f8cc712eSAndreas Gohr    // check permissions
1228f8cc712eSAndreas Gohr    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1229f8cc712eSAndreas Gohr
123011e2ce22Schris    $menu[] = array('plugin' => $p,
123111e2ce22Schris                    'prompt' => $obj->getMenuText($conf['lang']),
123211e2ce22Schris                    'sort' => $obj->getMenuSort()
123311e2ce22Schris                   );
123411e2ce22Schris  }
123511e2ce22Schris
1236746855cfSBen Coburn  usort($menu, 'p_sort_modes');
123711e2ce22Schris
123811e2ce22Schris  // output the menu
123911e2ce22Schris  ptln('<ul>');
124011e2ce22Schris
124111e2ce22Schris  foreach ($menu as $item) {
124211e2ce22Schris    if (!$item['prompt']) continue;
12430c6b58a8SAndreas Gohr    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
124411e2ce22Schris  }
124511e2ce22Schris
124611e2ce22Schris  ptln('</ul>');
1247ca3a6df1SMatthias Grimm}
1248c19fe9c0Sandi
12498b06d178Schris/**
12508b06d178Schris * Form to request a new password for an existing account
12518b06d178Schris *
12528b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
125311e2ce22Schris */
12548b06d178Schrisfunction html_resendpwd() {
12558b06d178Schris  global $lang;
12568b06d178Schris  global $conf;
12578b06d178Schris  global $ID;
1258c19fe9c0Sandi
12598b06d178Schris  print p_locale_xhtml('resendpwd');
1260fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
1261fdb8d77bSTom N Harris  $form = new Doku_Form('dw__resendpwd', wl($ID));
1262fdb8d77bSTom N Harris  $form->startFieldset($lang['resendpwd']);
1263fdb8d77bSTom N Harris  $form->addHidden('do', 'resendpwd');
1264fdb8d77bSTom N Harris  $form->addHidden('save', '1');
1265fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1266fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1267fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1268fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1269fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1270fdb8d77bSTom N Harris  $form->endFieldset();
1271fdb8d77bSTom N Harris  html_form('resendpwd', $form);
1272fdb8d77bSTom N Harris  print '</div>'.NL;
1273fdb8d77bSTom N Harris}
1274fdb8d77bSTom N Harris
1275fdb8d77bSTom N Harris/**
1276b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1277b8595a66SAndreas Gohr *
1278b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1279b8595a66SAndreas Gohr */
1280b8595a66SAndreas Gohrfunction html_TOC($toc){
1281b8595a66SAndreas Gohr    if(!count($toc)) return '';
1282b8595a66SAndreas Gohr    global $lang;
1283b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1284b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1285b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1286b8595a66SAndreas Gohr    $out .= $lang['toc'];
1287b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1288b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1289b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1290b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1291b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1292b8595a66SAndreas Gohr    return $out;                                                                                                }
1293b8595a66SAndreas Gohr
1294b8595a66SAndreas Gohr/**
1295b8595a66SAndreas Gohr * Callback for html_buildlist
1296b8595a66SAndreas Gohr */
1297b8595a66SAndreas Gohrfunction html_list_toc($item){
12987d91652aSAndreas Gohr    if($item['hid']){
12997d91652aSAndreas Gohr        $link = '#'.$item['hid'];
13007d91652aSAndreas Gohr    }else{
13017d91652aSAndreas Gohr        $link = $item['link'];
13027d91652aSAndreas Gohr    }
13037d91652aSAndreas Gohr
13047d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1305b8595a66SAndreas Gohr           hsc($item['title']).'</a></span>';
1306b8595a66SAndreas Gohr}
1307b8595a66SAndreas Gohr
1308b8595a66SAndreas Gohr/**
1309b8595a66SAndreas Gohr * Helper function to build TOC items
1310b8595a66SAndreas Gohr *
1311b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1312b8595a66SAndreas Gohr *
1313b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1314b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1315b8595a66SAndreas Gohr * @param int    $level - nesting level
1316b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1317b8595a66SAndreas Gohr */
1318b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1319b8595a66SAndreas Gohr    global $conf;
1320b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1321b8595a66SAndreas Gohr                   'title' => $text,
1322b8595a66SAndreas Gohr                   'type'  => 'ul',
13232bb0d541Schris                   'level' => $level);
1324b8595a66SAndreas Gohr}
1325b8595a66SAndreas Gohr
1326b8595a66SAndreas Gohr/**
1327fdb8d77bSTom N Harris * Output a Doku_Form object.
1328fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1329fdb8d77bSTom N Harris *
1330fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1331fdb8d77bSTom N Harris */
1332fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1333fdb8d77bSTom N Harris  // Safety check in case the caller forgets.
1334fdb8d77bSTom N Harris  $form->endFieldset();
1335fdb8d77bSTom N Harris  trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1336fdb8d77bSTom N Harris}
1337fdb8d77bSTom N Harris
1338fdb8d77bSTom N Harris/**
1339fdb8d77bSTom N Harris * Form print function.
1340fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1341fdb8d77bSTom N Harris */
1342fdb8d77bSTom N Harrisfunction html_form_output($data) {
1343fdb8d77bSTom N Harris  $data->printForm();
13448b06d178Schris}
1345340756e4Sandi
1346340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1347