xref: /dokuwiki/inc/html.php (revision 37a1dc12655862a2f6e02b06145bd31a2f8b5489)
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');
59aab557e9SGina Haeussge  $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
60fdb8d77bSTom N Harris  $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
6117f89d7eSMichael Klier  if($conf['rememberme']) {
62fdb8d77bSTom N Harris      $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6317f89d7eSMichael Klier  }
64fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
65fdb8d77bSTom N Harris  $form->endFieldset();
66fdb8d77bSTom N Harris  html_form('login', $form);
675b62573aSAndreas Gohr
686957b2eaSAndreas Gohr  if($auth && $auth->canDo('addUser') && actionOK('register')){
69f3f0262cSandi    print '<p>';
70f3f0262cSandi    print $lang['reghere'];
711d5856cfSAndreas Gohr    print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
72f3f0262cSandi    print '</p>';
73f3f0262cSandi  }
748b06d178Schris
756957b2eaSAndreas Gohr  if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
768b06d178Schris    print '<p>';
778b06d178Schris    print $lang['pwdforget'];
781d5856cfSAndreas Gohr    print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
798b06d178Schris    print '</p>';
808b06d178Schris  }
81fdb8d77bSTom N Harris  print '</div>'.NL;
82f3f0262cSandi}
83f3f0262cSandi
84f3f0262cSandi/**
8515fae107Sandi * prints a section editing button
8635dae8b0SBen Coburn * used as a callback in html_secedit
8715fae107Sandi *
8815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8915fae107Sandi */
9035dae8b0SBen Coburnfunction html_secedit_button($matches){
91f3f0262cSandi  global $ID;
92041d7a86SBen Coburn  global $INFO;
93041d7a86SBen Coburn
94041d7a86SBen Coburn  $section = $matches[2];
95041d7a86SBen Coburn  $name = $matches[1];
96041d7a86SBen Coburn
97f3f0262cSandi  $secedit  = '';
98f3f0262cSandi  $secedit .= '<div class="secedit">';
99f3f0262cSandi  $secedit .= html_btn('secedit',$ID,'',
100f3f0262cSandi                        array('do'      => 'edit',
101306b2c85SDenis Simakov                              'lines'   => "$section",
102306b2c85SDenis Simakov                              'rev' => $INFO['lastmod']),
10335dae8b0SBen Coburn                              'post', $name);
104f3f0262cSandi  $secedit .= '</div>';
105f3f0262cSandi  return $secedit;
106f3f0262cSandi}
107f3f0262cSandi
10815fae107Sandi/**
10915fae107Sandi * inserts section edit buttons if wanted or removes the markers
11015fae107Sandi *
11115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
11215fae107Sandi */
113f3f0262cSandifunction html_secedit($text,$show=true){
114f3f0262cSandi  global $INFO;
11535dae8b0SBen Coburn
116c112d578Sandi  if($INFO['writable'] && $show && !$INFO['rev']){
11735dae8b0SBen Coburn    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
11835dae8b0SBen Coburn                         'html_secedit_button', $text);
119f3f0262cSandi  }else{
12035dae8b0SBen Coburn    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
121f3f0262cSandi  }
12235dae8b0SBen Coburn
123f3f0262cSandi  return $text;
124f3f0262cSandi}
125f3f0262cSandi
126f3f0262cSandi/**
127d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1286b13307fSandi *
1296b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1306b13307fSandi */
1316b13307fSandifunction html_topbtn(){
1326b13307fSandi  global $lang;
1336b13307fSandi
1346b13307fSandi  $ret  = '';
13511ea018fSAndreas 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>';
136df7b6005Sandi
1376b13307fSandi  return $ret;
1386b13307fSandi}
1396b13307fSandi
1406b13307fSandi/**
141d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
14235dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
14315fae107Sandi *
14415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
145f3f0262cSandi */
14635dae8b0SBen Coburnfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
147f3f0262cSandi  global $conf;
148f3f0262cSandi  global $lang;
149f3f0262cSandi
150f3f0262cSandi  $label = $lang['btn_'.$name];
151f3f0262cSandi
152f3f0262cSandi  $ret = '';
15335dae8b0SBen Coburn  $tip = '';
154f3f0262cSandi
15549c713a3Sandi  //filter id (without urlencoding)
15649c713a3Sandi  $id = idfilter($id,false);
157f3f0262cSandi
158f3f0262cSandi  //make nice URLs even for buttons
1596c7843b5Sandi  if($conf['userewrite'] == 2){
1606c7843b5Sandi    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1616c7843b5Sandi  }elseif($conf['userewrite']){
1626c7843b5Sandi    $script = DOKU_BASE.$id;
1636c7843b5Sandi  }else{
1648b00ebcfSandi    $script = DOKU_BASE.DOKU_SCRIPT;
165f3f0262cSandi    $params['id'] = $id;
166f3f0262cSandi  }
167f3f0262cSandi
168b278f2deSAndreas Gohr  $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
169f3f0262cSandi
17006a4bf8fSAndreas Gohr  if(is_array($params)){
171f3f0262cSandi    reset($params);
172f3f0262cSandi    while (list($key, $val) = each($params)) {
173f3f0262cSandi      $ret .= '<input type="hidden" name="'.$key.'" ';
174f3f0262cSandi      $ret .= 'value="'.htmlspecialchars($val).'" />';
175f3f0262cSandi    }
17606a4bf8fSAndreas Gohr  }
177f3f0262cSandi
17835dae8b0SBen Coburn  if ($tooltip!='') {
17935dae8b0SBen Coburn      $tip = htmlspecialchars($tooltip);
18011ea018fSAndreas Gohr  }else{
18111ea018fSAndreas Gohr      $tip = htmlspecialchars($label);
18211ea018fSAndreas Gohr  }
18311ea018fSAndreas Gohr
18411ea018fSAndreas Gohr  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
18511ea018fSAndreas Gohr  if($akey){
18607493d05SAnika Henke    $tip .= ' ['.strtoupper($akey).']';
18707493d05SAnika Henke    $ret .= 'accesskey="'.htmlspecialchars($label).' '.$akey.'" ';
18835dae8b0SBen Coburn  }
18935dae8b0SBen Coburn  $ret .= 'title="'.$tip.'" ';
190f3f0262cSandi  $ret .= '/>';
1914beabca9SAnika Henke  $ret .= '</div></form>';
192f3f0262cSandi
193f3f0262cSandi  return $ret;
194f3f0262cSandi}
195f3f0262cSandi
196f3f0262cSandi/**
19715fae107Sandi * show a wiki page
19815fae107Sandi *
19915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
20015fae107Sandi */
2016bbae538Sandifunction html_show($txt=''){
202f3f0262cSandi  global $ID;
203f3f0262cSandi  global $REV;
204f3f0262cSandi  global $HIGH;
205b8595a66SAndreas Gohr  global $INFO;
206f3f0262cSandi  //disable section editing for old revisions or in preview
2075400331dSandi  if($txt || $REV){
2086bbae538Sandi    $secedit = false;
2096bbae538Sandi  }else{
2106bbae538Sandi    $secedit = true;
211f3f0262cSandi  }
212f3f0262cSandi
2136bbae538Sandi  if ($txt){
214f3f0262cSandi    //PreviewHeader
215b8595a66SAndreas Gohr    echo '<br id="scroll__here" />';
216b8595a66SAndreas Gohr    echo p_locale_xhtml('preview');
217b8595a66SAndreas Gohr    echo '<div class="preview">';
218b8595a66SAndreas Gohr    $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
219b8595a66SAndreas Gohr    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
220b8595a66SAndreas Gohr    echo $html;
221b8595a66SAndreas Gohr    echo '<div class="clearer"></div>';
222b8595a66SAndreas Gohr    echo '</div>';
2236bbae538Sandi
224f3f0262cSandi  }else{
225c112d578Sandi    if ($REV) print p_locale_xhtml('showrev');
226c112d578Sandi    $html = p_wiki_xhtml($ID,$REV,true);
2276bbae538Sandi    $html = html_secedit($html,$secedit);
228b8595a66SAndreas Gohr    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
229b8595a66SAndreas Gohr    $html = html_hilight($html,$HIGH);
230b8595a66SAndreas Gohr    echo $html;
231f3f0262cSandi  }
232f3f0262cSandi}
233f3f0262cSandi
234f3f0262cSandi/**
235ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
236ee4c4a1bSAndreas Gohr *
237ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
238ee4c4a1bSAndreas Gohr */
239ee4c4a1bSAndreas Gohrfunction html_draft(){
240ee4c4a1bSAndreas Gohr  global $INFO;
241ee4c4a1bSAndreas Gohr  global $ID;
242ee4c4a1bSAndreas Gohr  global $lang;
243ee4c4a1bSAndreas Gohr  global $conf;
244ee4c4a1bSAndreas Gohr  $draft = unserialize(io_readFile($INFO['draft'],false));
245ee4c4a1bSAndreas Gohr  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
246ee4c4a1bSAndreas Gohr
247fdb8d77bSTom N Harris  print p_locale_xhtml('draft');
248fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
249fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
250fdb8d77bSTom N Harris  $form->addHidden('date', $draft['date']);
251fdb8d77bSTom N Harris  $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
252fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
253e656dcd4SAndreas Gohr  $form->addElement($lang['draftdate'].' '. strftime($conf['dformat'],filemtime($INFO['draft'])));
254fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
255fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
256fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
257fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
258fdb8d77bSTom N Harris  html_form('draft', $form);
259ee4c4a1bSAndreas Gohr}
260ee4c4a1bSAndreas Gohr
261ee4c4a1bSAndreas Gohr/**
262f3f0262cSandi * Highlights searchqueries in HTML code
26315fae107Sandi *
26415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2657209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
266f3f0262cSandi */
267546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
268546d3a99SAndreas Gohr  $regex = join('|',array_map('preg_quote_cb',array_filter((array) $phrases)));
26960c15d7dSAndreas Gohr
27060c15d7dSAndreas Gohr  if ($regex === '') return $html;
2711db218e9SAndreas Gohr  $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
272f3f0262cSandi  return $html;
273f3f0262cSandi}
274f3f0262cSandi
275f3f0262cSandi/**
2767209be23SAndreas Gohr * Callback used by html_hilight()
2777209be23SAndreas Gohr *
2787209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2797209be23SAndreas Gohr */
2807209be23SAndreas Gohrfunction html_hilight_callback($m) {
2817209be23SAndreas Gohr  $hlight = unslash($m[0]);
2827209be23SAndreas Gohr  if ( !isset($m[2])) {
283688774a0SAnika Henke    $hlight = '<span class="search_hit">'.$hlight.'</span>';
2847209be23SAndreas Gohr  }
2857209be23SAndreas Gohr  return $hlight;
2867209be23SAndreas Gohr}
2877209be23SAndreas Gohr
2887209be23SAndreas Gohr/**
28915fae107Sandi * Run a search and display the result
29015fae107Sandi *
29115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
292f3f0262cSandi */
293f3f0262cSandifunction html_search(){
294ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
295506fa893SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
296f3f0262cSandi  global $conf;
297f3f0262cSandi  global $QUERY;
298f3f0262cSandi  global $ID;
299f3f0262cSandi  global $lang;
300f3f0262cSandi
301c112d578Sandi  print p_locale_xhtml('searchpage');
302f3f0262cSandi  flush();
303f3f0262cSandi
304d0ab54f6SMichael Klier chi@chimeric.de  //check if search is restricted to namespace
305d0ab54f6SMichael Klier chi@chimeric.de  if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) {
306d0ab54f6SMichael Klier chi@chimeric.de      $id = cleanID($match[1]);
307d0ab54f6SMichael Klier chi@chimeric.de      if(empty($id)) {
308d0ab54f6SMichael Klier chi@chimeric.de        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
309d0ab54f6SMichael Klier chi@chimeric.de        flush();
310d0ab54f6SMichael Klier chi@chimeric.de        return;
311d0ab54f6SMichael Klier chi@chimeric.de      }
312d0ab54f6SMichael Klier chi@chimeric.de  } else {
313d0ab54f6SMichael Klier chi@chimeric.de      $id = cleanID($QUERY);
314d0ab54f6SMichael Klier chi@chimeric.de  }
315d0ab54f6SMichael Klier chi@chimeric.de
3164d9ff3d5Sandi  //show progressbar
317e226efe1SAndreas Gohr  print '<div class="centeralign" id="dw__loading">'.NL;
318e226efe1SAndreas Gohr  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
319e226efe1SAndreas Gohr  print 'showLoadBar();'.NL;
320e226efe1SAndreas Gohr  print '//--><!]]></script>'.NL;
321e226efe1SAndreas Gohr  print '<br /></div>'.NL;
3229edac8a8SAndreas Gohr  flush();
3234d9ff3d5Sandi
324f3f0262cSandi  //do quick pagesearch
325f3f0262cSandi  $data = array();
326d0ab54f6SMichael Klier chi@chimeric.de
327d0ab54f6SMichael Klier chi@chimeric.de  $data = ft_pageLookup($id);
328f3f0262cSandi  if(count($data)){
329f3f0262cSandi    print '<div class="search_quickresult">';
330746855cfSBen Coburn    print '<h3>'.$lang['quickhits'].':</h3>';
3314f732f0eSAnika Henke    print '<ul class="search_quickhits">';
332140c93f3SAnika Henke    foreach($data as $id){
3334f732f0eSAnika Henke      print '<li> ';
334bd2f6c2fSAndreas Gohr      $ns = getNS($id);
335bd2f6c2fSAndreas Gohr      if($ns){
336bd2f6c2fSAndreas Gohr        $name = shorten(noNS($id), ' ('.$ns.')',30);
337bd2f6c2fSAndreas Gohr      }else{
338bd2f6c2fSAndreas Gohr        $name = $id;
339bd2f6c2fSAndreas Gohr      }
340bd2f6c2fSAndreas Gohr      print html_wikilink(':'.$id,$name);
3414f732f0eSAnika Henke      print '</li> ';
342f3f0262cSandi    }
343140c93f3SAnika Henke    print '</ul> ';
344f3f0262cSandi    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
345f3f0262cSandi    print '<div class="clearer">&nbsp;</div>';
346f3f0262cSandi    print '</div>';
347f3f0262cSandi  }
348f3f0262cSandi  flush();
349f3f0262cSandi
350f3f0262cSandi  //do fulltext search
35160c15d7dSAndreas Gohr  $data = ft_pageSearch($QUERY,$regex);
352f3f0262cSandi  if(count($data)){
353506fa893SAndreas Gohr    $num = 1;
354506fa893SAndreas Gohr    foreach($data as $id => $cnt){
355f3f0262cSandi      print '<div class="search_result">';
35660c15d7dSAndreas Gohr      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$regex);
357506fa893SAndreas Gohr      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
358506fa893SAndreas Gohr      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
35960c15d7dSAndreas Gohr        print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
360506fa893SAndreas Gohr      }
361f3f0262cSandi      print '</div>';
362506fa893SAndreas Gohr      flush();
363506fa893SAndreas Gohr      $num++;
364f3f0262cSandi    }
365f3f0262cSandi  }else{
366820fa24bSandi    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
367f3f0262cSandi  }
3684d9ff3d5Sandi
3694d9ff3d5Sandi  //hide progressbar
370e226efe1SAndreas Gohr  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
371e226efe1SAndreas Gohr  print 'hideLoadBar("dw__loading");'.NL;
372e226efe1SAndreas Gohr  print '//--><!]]></script>'.NL;
3739edac8a8SAndreas Gohr  flush();
374f3f0262cSandi}
375f3f0262cSandi
37615fae107Sandi/**
37715fae107Sandi * Display error on locked pages
37815fae107Sandi *
37915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
38015fae107Sandi */
381ee20e7d1Sandifunction html_locked(){
382f3f0262cSandi  global $ID;
383f3f0262cSandi  global $conf;
384f3f0262cSandi  global $lang;
38588f522e9Sandi  global $INFO;
386f3f0262cSandi
387c9b4bd1eSBen Coburn  $locktime = filemtime(wikiLockFN($ID));
388e656dcd4SAndreas Gohr  $expire = @strftime($conf['dformat'], $locktime + $conf['locktime'] );
389f3f0262cSandi  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
390f3f0262cSandi
391c112d578Sandi  print p_locale_xhtml('locked');
392f3f0262cSandi  print '<ul>';
393f7c7911aSGina Haeussge  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</div></li>';
3940c6b58a8SAndreas Gohr  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
395f3f0262cSandi  print '</ul>';
396f3f0262cSandi}
397f3f0262cSandi
39815fae107Sandi/**
39915fae107Sandi * list old revisions
40015fae107Sandi *
40115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40271726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
40315fae107Sandi */
40471726d78SBen Coburnfunction html_revisions($first=0){
405f3f0262cSandi  global $ID;
406f3f0262cSandi  global $INFO;
407f3f0262cSandi  global $conf;
408f3f0262cSandi  global $lang;
40971726d78SBen Coburn  /* we need to get one additionally log entry to be able to
41071726d78SBen Coburn   * decide if this is the last page or is there another one.
41171726d78SBen Coburn   * see html_recent()
41271726d78SBen Coburn   */
41371726d78SBen Coburn  $revisions = getRevisions($ID, $first, $conf['recent']+1);
41471726d78SBen Coburn  if(count($revisions)==0 && $first!=0){
41571726d78SBen Coburn    $first=0;
41671726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);;
41771726d78SBen Coburn  }
41871726d78SBen Coburn  $hasNext = false;
41971726d78SBen Coburn  if (count($revisions)>$conf['recent']) {
42071726d78SBen Coburn    $hasNext = true;
42171726d78SBen Coburn    array_pop($revisions); // remove extra log entry
42271726d78SBen Coburn  }
42371726d78SBen Coburn
424e656dcd4SAndreas Gohr  $date = @strftime($conf['dformat'],$INFO['lastmod']);
425f3f0262cSandi
426c112d578Sandi  print p_locale_xhtml('revisions');
427*37a1dc12Smichael
428*37a1dc12Smichael  $form = new Doku_Form('page__revisions', wl($ID));
429*37a1dc12Smichael  $form->addElement(form_makeOpenTag('ul'));
43071726d78SBen Coburn  if($INFO['exists'] && $first==0){
431*37a1dc12Smichael    if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
432*37a1dc12Smichael      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
433*37a1dc12Smichael    else
434*37a1dc12Smichael      $form->addElement(form_makeOpenTag('li'));
435*37a1dc12Smichael    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
436*37a1dc12Smichael    $form->addElement(form_makeTag('input', array(
437*37a1dc12Smichael      'type' => 'checkbox',
438*37a1dc12Smichael      'name' => 'rev2[]',
439*37a1dc12Smichael      'value' => 'current')));
440f9b2fe70Sandi
441*37a1dc12Smichael    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
442*37a1dc12Smichael    $form->addElement($date);
443*37a1dc12Smichael    $form->addElement(form_makeCloseTag('span'));
444f9b2fe70Sandi
445*37a1dc12Smichael    $form->addElement(form_makeTag('img', array(
446*37a1dc12Smichael      'src' =>  DOKU_BASE.'lib/images/blank.gif',
447*37a1dc12Smichael      'width' => '15',
448*37a1dc12Smichael      'height' => '11',
449*37a1dc12Smichael      'alt'    => '')));
450cffcc403Sandi
451*37a1dc12Smichael    $form->addElement(form_makeOpenTag('a', array(
452*37a1dc12Smichael      'class' => 'wikilink1',
453*37a1dc12Smichael      'href'  => wl($ID))));
454*37a1dc12Smichael    $form->addElement($ID);
455*37a1dc12Smichael    $form->addElement(form_makeCloseTag('a'));
456652610a2Sandi
457*37a1dc12Smichael    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
458*37a1dc12Smichael    $form->addElement(' &ndash; ');
459*37a1dc12Smichael    $form->addElement(htmlspecialchars($INFO['sum']));
460*37a1dc12Smichael    $form->addElement(form_makeCloseTag('span'));
461652610a2Sandi
462*37a1dc12Smichael    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
463*37a1dc12Smichael    $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
464*37a1dc12Smichael    $form->addElement(form_makeCloseTag('span'));
465*37a1dc12Smichael
466*37a1dc12Smichael    $form->addElement('('.$lang['current'].')');
467*37a1dc12Smichael    $form->addElement(form_makeCloseTag('div'));
468*37a1dc12Smichael    $form->addElement(form_makeCloseTag('li'));
469f3f0262cSandi  }
470f3f0262cSandi
471f3f0262cSandi  foreach($revisions as $rev){
472e656dcd4SAndreas Gohr    $date   = strftime($conf['dformat'],$rev);
473fb53bfe2SBen Coburn    $info   = getRevisionInfo($ID,$rev,true);
474103c256aSChris Smith    $exists = page_exists($ID,$rev);
475652610a2Sandi
476*37a1dc12Smichael    if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
477*37a1dc12Smichael      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
478*37a1dc12Smichael    else
479*37a1dc12Smichael      $form->addElement(form_makeOpenTag('li'));
480*37a1dc12Smichael    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
48177707b04SAndreas Gohr    if($exists){
482*37a1dc12Smichael      $form->addElement(form_makeTag('input', array(
483*37a1dc12Smichael        'type' => 'checkbox',
484*37a1dc12Smichael        'name' => 'rev2[]',
485*37a1dc12Smichael        'value' => $rev)));
48677707b04SAndreas Gohr    }else{
487*37a1dc12Smichael      $form->addElement(form_makeTag('img', array(
488*37a1dc12Smichael        'src' => DOKU_BASE.'lib/images/blank.gif',
489*37a1dc12Smichael        'width' => 14,
490*37a1dc12Smichael        'height' => 11,
491*37a1dc12Smichael        'alt' => '')));
49241396b71SAndreas Gohr    }
493f9b2fe70Sandi
494*37a1dc12Smichael    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
495*37a1dc12Smichael    $form->addElement($date);
496*37a1dc12Smichael    $form->addElement(form_makeCloseTag('span'));
497*37a1dc12Smichael
498*37a1dc12Smichael    if($exists){
499*37a1dc12Smichael      $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
500*37a1dc12Smichael      $form->addElement(form_makeTag('img', array(
501*37a1dc12Smichael        'src'    => DOKU_BASE.'lib/images/diff.png',
502*37a1dc12Smichael        'width'  => 15,
503*37a1dc12Smichael        'height' => 11,
504*37a1dc12Smichael        'title'  => $lang['diff'],
505*37a1dc12Smichael        'alt'    => $lang['diff'])));
506*37a1dc12Smichael      $form->addElement(form_makeCloseTag('a'));
507*37a1dc12Smichael
508*37a1dc12Smichael      $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
509*37a1dc12Smichael      $form->addElement($ID);
510*37a1dc12Smichael      $form->addElement(form_makeCloseTag('a'));
511*37a1dc12Smichael    }else{
512*37a1dc12Smichael      $form->addElement(form_makeTag('img', array(
513*37a1dc12Smichael        'src' => DOKU_BASE.'lib/images/blank.gif',
514*37a1dc12Smichael        'width' => '15',
515*37a1dc12Smichael        'height' => '11',
516*37a1dc12Smichael        'alt'   => '')));
517*37a1dc12Smichael      $form->addElement($ID);
518*37a1dc12Smichael    }
519*37a1dc12Smichael
520*37a1dc12Smichael    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
521*37a1dc12Smichael    $form->addElement(' &ndash; ');
522*37a1dc12Smichael    $form->addElement(htmlspecialchars($info['sum']));
523*37a1dc12Smichael    $form->addElement(form_makeCloseTag('span'));
524*37a1dc12Smichael
525*37a1dc12Smichael    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
52688f522e9Sandi    if($info['user']){
527*37a1dc12Smichael      $form->addElement(editorinfo($info['user']));
52888f522e9Sandi    }else{
529*37a1dc12Smichael      $form->addElement($info['ip']);
53088f522e9Sandi    }
531*37a1dc12Smichael    $form->addElement(form_makeCloseTag('span'));
532652610a2Sandi
533*37a1dc12Smichael    $form->addElement(form_makeCloseTag('div'));
534*37a1dc12Smichael    $form->addElement(form_makeCloseTag('li'));
535f3f0262cSandi  }
536*37a1dc12Smichael  $form->addElement(form_makeCloseTag('ul'));
537*37a1dc12Smichael  $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
538*37a1dc12Smichael  html_form('revisions', $form);
53971726d78SBen Coburn
54071726d78SBen Coburn  print '<div class="pagenav">';
54171726d78SBen Coburn  $last = $first + $conf['recent'];
54271726d78SBen Coburn  if ($first > 0) {
54371726d78SBen Coburn    $first -= $conf['recent'];
54471726d78SBen Coburn    if ($first < 0) $first = 0;
54571726d78SBen Coburn    print '<div class="pagenav-prev">';
546eeb83e57SBen Coburn    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
54771726d78SBen Coburn    print '</div>';
54871726d78SBen Coburn  }
54971726d78SBen Coburn  if ($hasNext) {
55071726d78SBen Coburn    print '<div class="pagenav-next">';
551eeb83e57SBen Coburn    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
55271726d78SBen Coburn    print '</div>';
55371726d78SBen Coburn  }
55471726d78SBen Coburn  print '</div>';
55571726d78SBen Coburn
556f3f0262cSandi}
557f3f0262cSandi
55815fae107Sandi/**
55915fae107Sandi * display recent changes
56015fae107Sandi *
56115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5625749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
56371726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
56415fae107Sandi */
565a39955b0Smatthiasgrimmfunction html_recent($first=0){
566f3f0262cSandi  global $conf;
567cffcc403Sandi  global $lang;
568dbb00abcSEsther Brunner  global $ID;
5695749f1ceSmatthiasgrimm  /* we need to get one additionally log entry to be able to
5705749f1ceSmatthiasgrimm   * decide if this is the last page or is there another one.
5715749f1ceSmatthiasgrimm   * This is the cheapest solution to get this information.
5725749f1ceSmatthiasgrimm   */
573b6912aeaSAndreas Gohr  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5745749f1ceSmatthiasgrimm  if(count($recents) == 0 && $first != 0){
5755749f1ceSmatthiasgrimm    $first=0;
57671726d78SBen Coburn    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5775749f1ceSmatthiasgrimm  }
57871726d78SBen Coburn  $hasNext = false;
57971726d78SBen Coburn  if (count($recents)>$conf['recent']) {
58071726d78SBen Coburn    $hasNext = true;
58171726d78SBen Coburn    array_pop($recents); // remove extra log entry
58271726d78SBen Coburn  }
583f3f0262cSandi
584c112d578Sandi  print p_locale_xhtml('recent');
585e83cef14SGina Haeussge
586e83cef14SGina Haeussge  if (getNS($ID) != '')
5879e561443SAndreas Gohr    print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
588e83cef14SGina Haeussge
589abdcc39fSmichael  $form = new Doku_Form('dw__recent', script(), 'get');
590abdcc39fSmichael  $form->addHidden('sectok', null);
591abdcc39fSmichael  $form->addHidden('do', 'recent');
592abdcc39fSmichael  $form->addHidden('id', $ID);
593abdcc39fSmichael  $form->addElement(form_makeOpenTag('ul'));
594a39955b0Smatthiasgrimm
595d437bcc4SAndreas Gohr  foreach($recents as $recent){
596e656dcd4SAndreas Gohr    $date = strftime($conf['dformat'],$recent['date']);
597abdcc39fSmichael    if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
598abdcc39fSmichael      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
599abdcc39fSmichael    else
600abdcc39fSmichael      $form->addElement(form_makeOpenTag('li'));
601cffcc403Sandi
602abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
603f9b2fe70Sandi
604abdcc39fSmichael    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
605abdcc39fSmichael    $form->addElement($date);
606abdcc39fSmichael    $form->addElement(form_makeCloseTag('span'));
607cffcc403Sandi
608cddd152cSmichael    $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
609abdcc39fSmichael    $form->addElement(form_makeTag('img', array(
610abdcc39fSmichael      'src'   => DOKU_BASE.'lib/images/diff.png',
611abdcc39fSmichael      'width' => 15,
612abdcc39fSmichael      'height'=> 11,
613abdcc39fSmichael      'title' => $lang['diff'],
614abdcc39fSmichael      'alt'   => $lang['diff']
615abdcc39fSmichael    )));
616abdcc39fSmichael    $form->addElement(form_makeCloseTag('a'));
617cffcc403Sandi
618cddd152cSmichael    $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
619abdcc39fSmichael    $form->addElement(form_makeTag('img', array(
620abdcc39fSmichael      'src'   => DOKU_BASE.'lib/images/history.png',
621abdcc39fSmichael      'width' => 12,
622abdcc39fSmichael      'height'=> 14,
623abdcc39fSmichael      'title' => $lang['btn_revs'],
624abdcc39fSmichael      'alt'   => $lang['btn_revs']
625abdcc39fSmichael    )));
626abdcc39fSmichael    $form->addElement(form_makeCloseTag('a'));
627b6912aeaSAndreas Gohr
628abdcc39fSmichael    $form->addElement(html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']));
629abdcc39fSmichael
630abdcc39fSmichael    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
631abdcc39fSmichael    $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
632abdcc39fSmichael    $form->addElement(form_makeCloseTag('span'));
633abdcc39fSmichael
634abdcc39fSmichael    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
635d437bcc4SAndreas Gohr    if($recent['user']){
636abdcc39fSmichael      $form->addElement(editorinfo($recent['user']));
63788f522e9Sandi    }else{
638abdcc39fSmichael      $form->addElement($recent['ip']);
63988f522e9Sandi    }
640abdcc39fSmichael    $form->addElement(form_makeCloseTag('span'));
641cffcc403Sandi
642abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
643abdcc39fSmichael    $form->addElement(form_makeCloseTag('li'));
644f3f0262cSandi  }
645abdcc39fSmichael  $form->addElement(form_makeCloseTag('ul'));
646a39955b0Smatthiasgrimm
647abdcc39fSmichael  $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6485749f1ceSmatthiasgrimm  $last = $first + $conf['recent'];
649a39955b0Smatthiasgrimm  if ($first > 0) {
650a39955b0Smatthiasgrimm    $first -= $conf['recent'];
651a39955b0Smatthiasgrimm    if ($first < 0) $first = 0;
652abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
653abdcc39fSmichael    $form->addElement(form_makeTag('input', array(
654abdcc39fSmichael      'type'  => 'submit',
655abdcc39fSmichael      'name'  => 'first['.$first.']',
656cddd152cSmichael      'value' => $lang['btn_newer'],
657cddd152cSmichael      'accesskey' => 'n',
658cddd152cSmichael      'title' => '[ALT+N]'
659abdcc39fSmichael    )));
660abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
661a39955b0Smatthiasgrimm  }
66271726d78SBen Coburn  if ($hasNext) {
663abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
664abdcc39fSmichael    $form->addElement(form_makeTag('input', array(
665abdcc39fSmichael      'type'  => 'submit',
666abdcc39fSmichael      'name'  => 'first['.$last.']',
667cddd152cSmichael      'value' => $lang['btn_older'],
668cddd152cSmichael      'accesskey' => 'p',
669cddd152cSmichael      'title'  => '[ALT+P]'
670abdcc39fSmichael    )));
671abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
672a39955b0Smatthiasgrimm  }
673abdcc39fSmichael  $form->addElement(form_makeCloseTag('div'));
674abdcc39fSmichael  html_form('recent', $form);
675f3f0262cSandi}
676f3f0262cSandi
67715fae107Sandi/**
67815fae107Sandi * Display page index
67915fae107Sandi *
68015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
68115fae107Sandi */
682f3f0262cSandifunction html_index($ns){
683ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
684f3f0262cSandi  global $conf;
685f3f0262cSandi  global $ID;
686f3f0262cSandi  $dir = $conf['datadir'];
687f3f0262cSandi  $ns  = cleanID($ns);
68830f1737dSandi  #fixme use appropriate function
689f3f0262cSandi  if(empty($ns)){
690f3f0262cSandi    $ns = dirname(str_replace(':','/',$ID));
691f3f0262cSandi    if($ns == '.') $ns ='';
692f3f0262cSandi  }
69388d3a917Sandi  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
694f3f0262cSandi
695a06884abSAndreas Gohr  echo p_locale_xhtml('index');
696a06884abSAndreas Gohr  echo '<div id="index__tree">';
697f3f0262cSandi
698f3f0262cSandi  $data = array();
699f3f0262cSandi  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
700a06884abSAndreas Gohr  echo html_buildlist($data,'idx','html_list_index','html_li_index');
701a06884abSAndreas Gohr
702a06884abSAndreas Gohr  echo '</div>';
703f3f0262cSandi}
704f3f0262cSandi
705f3f0262cSandi/**
70615fae107Sandi * Index item formatter
70715fae107Sandi *
708f3f0262cSandi * User function for html_buildlist()
70915fae107Sandi *
71015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
711f3f0262cSandi */
712f3f0262cSandifunction html_list_index($item){
713d98d4540SBen Coburn  global $ID;
714f3f0262cSandi  $ret = '';
715f3f0262cSandi  $base = ':'.$item['id'];
716f3f0262cSandi  $base = substr($base,strrpos($base,':')+1);
717f3f0262cSandi  if($item['type']=='d'){
7184a119027SAndreas Gohr    $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
719f3f0262cSandi    $ret .= $base;
720ed7ecb79SAnika Henke    $ret .= '</strong></a>';
721f3f0262cSandi  }else{
722f3f0262cSandi    $ret .= html_wikilink(':'.$item['id']);
723f3f0262cSandi  }
724f3f0262cSandi  return $ret;
725f3f0262cSandi}
726f3f0262cSandi
727f3f0262cSandi/**
728cb70c441Sandi * Index List item
729cb70c441Sandi *
730cb70c441Sandi * This user function is used in html_build_lidt to build the
731cb70c441Sandi * <li> tags for namespaces when displaying the page index
732cb70c441Sandi * it gives different classes to opened or closed "folders"
733cb70c441Sandi *
734cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
735cb70c441Sandi */
736cb70c441Sandifunction html_li_index($item){
737cb70c441Sandi  if($item['type'] == "f"){
738cb70c441Sandi    return '<li class="level'.$item['level'].'">';
739cb70c441Sandi  }elseif($item['open']){
740cb70c441Sandi    return '<li class="open">';
741cb70c441Sandi  }else{
742cb70c441Sandi    return '<li class="closed">';
743cb70c441Sandi  }
744cb70c441Sandi}
745cb70c441Sandi
746cb70c441Sandi/**
747cb70c441Sandi * Default List item
748cb70c441Sandi *
749cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
750cb70c441Sandi */
751cb70c441Sandifunction html_li_default($item){
752cb70c441Sandi  return '<li class="level'.$item['level'].'">';
753cb70c441Sandi}
754cb70c441Sandi
755cb70c441Sandi/**
75615fae107Sandi * Build an unordered list
75715fae107Sandi *
758f3f0262cSandi * Build an unordered list from the given $data array
759f3f0262cSandi * Each item in the array has to have a 'level' property
760f3f0262cSandi * the item itself gets printed by the given $func user
761cb70c441Sandi * function. The second and optional function is used to
762cb70c441Sandi * print the <li> tag. Both user function need to accept
763cb70c441Sandi * a single item.
76415fae107Sandi *
765c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
766c5a8fd96SAndreas Gohr * a member of an object.
767c5a8fd96SAndreas Gohr *
76815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
769f3f0262cSandi */
770cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
771f3f0262cSandi  $level = 0;
772f3f0262cSandi  $opens = 0;
773f3f0262cSandi  $ret   = '';
774f3f0262cSandi
775f3f0262cSandi  foreach ($data as $item){
776f3f0262cSandi
777f3f0262cSandi    if( $item['level'] > $level ){
778f3f0262cSandi      //open new list
779df52d0feSandi      for($i=0; $i<($item['level'] - $level); $i++){
780df52d0feSandi        if ($i) $ret .= "<li class=\"clear\">\n";
781f3f0262cSandi        $ret .= "\n<ul class=\"$class\">\n";
782df52d0feSandi      }
783f3f0262cSandi    }elseif( $item['level'] < $level ){
784f3f0262cSandi      //close last item
785f3f0262cSandi      $ret .= "</li>\n";
786f3f0262cSandi      for ($i=0; $i<($level - $item['level']); $i++){
787f3f0262cSandi        //close higher lists
788f3f0262cSandi        $ret .= "</ul>\n</li>\n";
789f3f0262cSandi      }
790f3f0262cSandi    }else{
791f3f0262cSandi      //close last item
792f3f0262cSandi      $ret .= "</li>\n";
793f3f0262cSandi    }
794f3f0262cSandi
795f3f0262cSandi    //remember current level
796f3f0262cSandi    $level = $item['level'];
797f3f0262cSandi
798f3f0262cSandi    //print item
79934dbe711Schris    $ret .= call_user_func($lifunc,$item);
8000c6b58a8SAndreas Gohr    $ret .= '<div class="li">';
80134dbe711Schris
80234dbe711Schris    $ret .= call_user_func($func,$item);
8030c6b58a8SAndreas Gohr    $ret .= '</div>';
804f3f0262cSandi  }
805f3f0262cSandi
806f3f0262cSandi  //close remaining items and lists
807f3f0262cSandi  for ($i=0; $i < $level; $i++){
808f3f0262cSandi    $ret .= "</li></ul>\n";
809f3f0262cSandi  }
810f3f0262cSandi
811f3f0262cSandi  return $ret;
812f3f0262cSandi}
813f3f0262cSandi
81415fae107Sandi/**
81515fae107Sandi * display backlinks
81615fae107Sandi *
81715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
81811df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
81915fae107Sandi */
820f3f0262cSandifunction html_backlinks(){
82154f4c056SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
822f3f0262cSandi  global $ID;
823f3f0262cSandi  global $conf;
82411df47ecSMichael Klier  global $lang;
825f3f0262cSandi
826c112d578Sandi  print p_locale_xhtml('backlinks');
827f3f0262cSandi
82854f4c056SAndreas Gohr  $data = ft_backlinks($ID);
829f3f0262cSandi
83011df47ecSMichael Klier  if(!empty($data)) {
831f3f0262cSandi      print '<ul class="idx">';
83254f4c056SAndreas Gohr      foreach($data as $blink){
8330c6b58a8SAndreas Gohr        print '<li><div class="li">';
83454f4c056SAndreas Gohr        print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
8350c6b58a8SAndreas Gohr        print '</div></li>';
836f3f0262cSandi      }
837f3f0262cSandi      print '</ul>';
83811df47ecSMichael Klier  } else {
83911df47ecSMichael Klier      print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
84011df47ecSMichael Klier  }
841f3f0262cSandi}
842f3f0262cSandi
84315fae107Sandi/**
84415fae107Sandi * show diff
84515fae107Sandi *
84615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
84715fae107Sandi */
848f3f0262cSandifunction html_diff($text='',$intro=true){
849ed7b5f09Sandi  require_once(DOKU_INC.'inc/DifferenceEngine.php');
850f3f0262cSandi  global $ID;
851f3f0262cSandi  global $REV;
852f3f0262cSandi  global $lang;
853f3f0262cSandi  global $conf;
854e1bd90ffSAndreas Gohr
85577707b04SAndreas Gohr  // we're trying to be clever here, revisions to compare can be either
85677707b04SAndreas Gohr  // given as rev and rev2 parameters, with rev2 being optional. Or in an
85777707b04SAndreas Gohr  // array in rev2.
85877707b04SAndreas Gohr  $rev1 = $REV;
8597b3f8b16SAndreas Gohr
86077707b04SAndreas Gohr  if(is_array($_REQUEST['rev2'])){
86177707b04SAndreas Gohr    $rev1 = (int) $_REQUEST['rev2'][0];
86277707b04SAndreas Gohr    $rev2 = (int) $_REQUEST['rev2'][1];
86354041c77SAndreas Gohr
86454041c77SAndreas Gohr    if(!$rev1){
86554041c77SAndreas Gohr        $rev1 = $rev2;
86654041c77SAndreas Gohr        unset($rev2);
86754041c77SAndreas Gohr    }
868f3f0262cSandi  }else{
86977707b04SAndreas Gohr    $rev2 = (int) $_REQUEST['rev2'];
8704d58bd99Sandi  }
8714d58bd99Sandi
87277707b04SAndreas Gohr  if($text){                      // compare text to the most current revision
87377707b04SAndreas Gohr    $l_rev   = '';
87477707b04SAndreas Gohr    $l_text  = rawWiki($ID,'');
87577707b04SAndreas Gohr    $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
876e656dcd4SAndreas Gohr               $ID.' '.strftime($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
87777707b04SAndreas Gohr               $lang['current'];
87877707b04SAndreas Gohr
87977707b04SAndreas Gohr    $r_rev   = '';
88077707b04SAndreas Gohr    $r_text  = cleanText($text);
88177707b04SAndreas Gohr    $r_head  = $lang['yours'];
882e1bd90ffSAndreas Gohr  }else{
88377707b04SAndreas Gohr    if($rev1 && $rev2){            // two specific revisions wanted
88454041c77SAndreas Gohr      // make sure order is correct (older on the left)
88577707b04SAndreas Gohr      if($rev1 < $rev2){
88677707b04SAndreas Gohr        $l_rev = $rev1;
88777707b04SAndreas Gohr        $r_rev = $rev2;
88877707b04SAndreas Gohr      }else{
88977707b04SAndreas Gohr        $l_rev = $rev2;
89077707b04SAndreas Gohr        $r_rev = $rev1;
891e1bd90ffSAndreas Gohr      }
89277707b04SAndreas Gohr    }elseif($rev1){                // single revision given, compare to current
89377707b04SAndreas Gohr      $r_rev = '';
89477707b04SAndreas Gohr      $l_rev = $rev1;
89577707b04SAndreas Gohr    }else{                        // no revision was given, compare previous to current
89677707b04SAndreas Gohr      $r_rev = '';
89777707b04SAndreas Gohr      $revs = getRevisions($ID, 0, 1);
89877707b04SAndreas Gohr      $l_rev = $revs[0];
89977707b04SAndreas Gohr    }
90077707b04SAndreas Gohr
9017b3f8b16SAndreas Gohr    // when both revisions are empty then the page was created just now
9027b3f8b16SAndreas Gohr    if(!$l_rev && !$r_rev){
9037b3f8b16SAndreas Gohr      $l_text = '';
9047b3f8b16SAndreas Gohr    }else{
90577707b04SAndreas Gohr      $l_text = rawWiki($ID,$l_rev);
9067b3f8b16SAndreas Gohr    }
90777707b04SAndreas Gohr    $r_text = rawWiki($ID,$r_rev);
90877707b04SAndreas Gohr
9097b3f8b16SAndreas Gohr
9107b3f8b16SAndreas Gohr    if(!$l_rev){
9117b3f8b16SAndreas Gohr      $l_head = '&mdash;';
9127b3f8b16SAndreas Gohr    }else{
91377707b04SAndreas Gohr      $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
914e656dcd4SAndreas Gohr                $ID.' '.strftime($conf['dformat'],$l_rev).'</a>';
9157b3f8b16SAndreas Gohr    }
91677707b04SAndreas Gohr
91777707b04SAndreas Gohr    if($r_rev){
91877707b04SAndreas Gohr      $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
919e656dcd4SAndreas Gohr                $ID.' '.strftime($conf['dformat'],$r_rev).'</a>';
9207b3f8b16SAndreas Gohr    }elseif($_rev = @filemtime(wikiFN($ID))){
92177707b04SAndreas Gohr      $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
9227b3f8b16SAndreas Gohr               $ID.' '.strftime($conf['dformat'],$_rev).'</a> '.
923f3f0262cSandi               $lang['current'];
9247b3f8b16SAndreas Gohr    }else{
9257b3f8b16SAndreas Gohr      $r_head = '&mdash; '.$lang['current'];
926f3f0262cSandi    }
92777707b04SAndreas Gohr  }
92877707b04SAndreas Gohr
92977707b04SAndreas Gohr  $df = new Diff(explode("\n",htmlspecialchars($l_text)),
93077707b04SAndreas Gohr                 explode("\n",htmlspecialchars($r_text)));
93177707b04SAndreas Gohr
932f3f0262cSandi  $tdf = new TableDiffFormatter();
933c112d578Sandi  if($intro) print p_locale_xhtml('diff');
934f3f0262cSandi  ?>
935daf4ca4eSAnika Henke    <table class="diff">
936f3f0262cSandi      <tr>
937daf4ca4eSAnika Henke        <th colspan="2">
93877707b04SAndreas Gohr          <?php echo $l_head?>
939daf4ca4eSAnika Henke        </th>
940daf4ca4eSAnika Henke        <th colspan="2">
94177707b04SAndreas Gohr          <?php echo $r_head?>
942daf4ca4eSAnika Henke        </th>
943f3f0262cSandi      </tr>
9444da078a3Smatthiasgrimm      <?php echo $tdf->format($df)?>
945f3f0262cSandi    </table>
9464da078a3Smatthiasgrimm  <?php
947f3f0262cSandi}
948f3f0262cSandi
94915fae107Sandi/**
95015fae107Sandi * show warning on conflict detection
95115fae107Sandi *
95215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
95315fae107Sandi */
954f3f0262cSandifunction html_conflict($text,$summary){
955f3f0262cSandi  global $ID;
956f3f0262cSandi  global $lang;
957f3f0262cSandi
958c112d578Sandi  print p_locale_xhtml('conflict');
959fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
960fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
961fdb8d77bSTom N Harris  $form->addHidden('wikitext', $text);
962fdb8d77bSTom N Harris  $form->addHidden('summary', $summary);
963fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
964fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
965fdb8d77bSTom N Harris  html_form('conflict', $form);
966fdb8d77bSTom N Harris  print '<br /><br /><br /><br />'.NL;
967f3f0262cSandi}
968f3f0262cSandi
969f3f0262cSandi/**
97015fae107Sandi * Prints the global message array
97115fae107Sandi *
97215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
973f3f0262cSandi */
974f3f0262cSandifunction html_msgarea(){
975f3f0262cSandi  global $MSG;
976f3f0262cSandi
977f3f0262cSandi  if(!isset($MSG)) return;
978f3f0262cSandi
979f3f0262cSandi  foreach($MSG as $msg){
980f3f0262cSandi    print '<div class="'.$msg['lvl'].'">';
981f3f0262cSandi    print $msg['msg'];
982f3f0262cSandi    print '</div>';
983f3f0262cSandi  }
984f3f0262cSandi}
985f3f0262cSandi
986f3f0262cSandi/**
987f3f0262cSandi * Prints the registration form
98815fae107Sandi *
98915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
990f3f0262cSandi */
991f3f0262cSandifunction html_register(){
992f3f0262cSandi  global $lang;
993cab2716aSmatthias.grimm  global $conf;
994f3f0262cSandi  global $ID;
995f3f0262cSandi
996c112d578Sandi  print p_locale_xhtml('register');
997fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
998fdb8d77bSTom N Harris  $form = new Doku_Form('dw__register', wl($ID));
999fdb8d77bSTom N Harris  $form->startFieldset($lang['register']);
1000fdb8d77bSTom N Harris  $form->addHidden('do', 'register');
1001fdb8d77bSTom N Harris  $form->addHidden('save', '1');
1002fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1003cab2716aSmatthias.grimm  if (!$conf['autopasswd']) {
1004fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1005fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1006cab2716aSmatthias.grimm  }
1007fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1008fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1009fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['register']));
1010fdb8d77bSTom N Harris  $form->endFieldset();
1011fdb8d77bSTom N Harris  html_form('register', $form);
1012cab2716aSmatthias.grimm
1013fdb8d77bSTom N Harris  print '</div>'.NL;
1014f3f0262cSandi}
1015f3f0262cSandi
1016f3f0262cSandi/**
10178b06d178Schris * Print the update profile form
10188b06d178Schris *
10198b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10208b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10218b06d178Schris */
10228b06d178Schrisfunction html_updateprofile(){
10238b06d178Schris  global $lang;
10248b06d178Schris  global $conf;
10258b06d178Schris  global $ID;
10268b06d178Schris  global $INFO;
102782fd59b6SAndreas Gohr  global $auth;
10288b06d178Schris
10298b06d178Schris  print p_locale_xhtml('updateprofile');
10308b06d178Schris
10318b06d178Schris  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
10328b06d178Schris  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1033fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
1034fdb8d77bSTom N Harris  $form = new Doku_Form('dw__register', wl($ID));
1035fdb8d77bSTom N Harris  $form->startFieldset($lang['profile']);
1036fdb8d77bSTom N Harris  $form->addHidden('do', 'profile');
1037fdb8d77bSTom N Harris  $form->addHidden('save', '1');
1038fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1039fdb8d77bSTom N Harris  $attr = array('size'=>'50');
1040fdb8d77bSTom N Harris  if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1041fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
104239ba8890SAndreas Gohr  $attr = array('size'=>'50');
104339ba8890SAndreas Gohr  if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1044fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1045fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1046fdb8d77bSTom N Harris  if ($auth->canDo('modPass')) {
1047fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1048fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1049fdb8d77bSTom N Harris  }
1050fdb8d77bSTom N Harris  if ($conf['profileconfirm']) {
1051fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1052fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1053fdb8d77bSTom N Harris  }
1054fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1055fdb8d77bSTom N Harris  $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1056fdb8d77bSTom N Harris  $form->endFieldset();
1057fdb8d77bSTom N Harris  html_form('updateprofile', $form);
1058fdb8d77bSTom N Harris  print '</div>'.NL;
10598b06d178Schris}
10608b06d178Schris
10618b06d178Schris/**
1062f3f0262cSandi * This displays the edit form (lots of logic included)
106315fae107Sandi *
10647146cee2SAndreas Gohr * @fixme    this is a huge lump of code and should be modularized
1065016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
1066c9570649SAndreas Gohr * @triggers HTML_EDITFORM_INJECTION
106715fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
1068f3f0262cSandi */
1069f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
1070f3f0262cSandi  global $ID;
1071f3f0262cSandi  global $REV;
1072f3f0262cSandi  global $DATE;
1073f3f0262cSandi  global $RANGE;
1074f3f0262cSandi  global $PRE;
1075f3f0262cSandi  global $SUF;
1076f3f0262cSandi  global $INFO;
1077f3f0262cSandi  global $SUM;
1078f3f0262cSandi  global $lang;
1079f3f0262cSandi  global $conf;
1080066fee30SAndreas Gohr  global $license;
1081f3f0262cSandi
1082f3f0262cSandi  //set summary default
1083f3f0262cSandi  if(!$SUM){
1084f3f0262cSandi    if($REV){
1085f3f0262cSandi      $SUM = $lang['restored'];
1086f3f0262cSandi    }elseif(!$INFO['exists']){
1087f3f0262cSandi      $SUM = $lang['created'];
1088f3f0262cSandi    }
1089f3f0262cSandi  }
1090f3f0262cSandi
1091f3f0262cSandi  //no text? Load it!
1092f3f0262cSandi  if(!isset($text)){
1093f3f0262cSandi    $pr = false; //no preview mode
10947146cee2SAndreas Gohr    if($INFO['exists']){
1095f3f0262cSandi      if($RANGE){
1096f3f0262cSandi        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1097f3f0262cSandi      }else{
1098f3f0262cSandi        $text = rawWiki($ID,$REV);
1099f3f0262cSandi      }
11008fe3bb00STom N Harris      $check = md5($text);
11018fe3bb00STom N Harris      $mod = false;
1102f3f0262cSandi    }else{
11037146cee2SAndreas Gohr      //try to load a pagetemplate
1104b7d5a5f0SAndreas Gohr      $data = array($ID);
1105016b6153SAndreas Gohr      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
11068fe3bb00STom N Harris      $check = md5('');
11078fe3bb00STom N Harris      $mod = $text!=='';
11087146cee2SAndreas Gohr    }
11097146cee2SAndreas Gohr  }else{
1110f3f0262cSandi    $pr = true; //preview mode
11118fe3bb00STom N Harris    if (isset($_REQUEST['changecheck'])) {
11128fe3bb00STom N Harris      $check = $_REQUEST['changecheck'];
11138fe3bb00STom N Harris      $mod = md5($text)!==$check;
11148fe3bb00STom N Harris    } else {
11158fe3bb00STom N Harris      // Why? Assume default text is unmodified.
11168fe3bb00STom N Harris      $check = md5($text);
11178fe3bb00STom N Harris      $mod = false;
11188fe3bb00STom N Harris    }
1119f3f0262cSandi  }
1120f3f0262cSandi
112127eb9321SAnika Henke  $wr = $INFO['writable'] && !$INFO['locked'];
1122f3f0262cSandi  if($wr){
1123c112d578Sandi    if ($REV) print p_locale_xhtml('editrev');
1124c112d578Sandi    print p_locale_xhtml($include);
1125f3f0262cSandi  }else{
1126409d7af7SAndreas Gohr    // check pseudo action 'source'
1127409d7af7SAndreas Gohr    if(!actionOK('source')){
1128409d7af7SAndreas Gohr      msg('Command disabled: source',-1);
1129409d7af7SAndreas Gohr      return;
1130409d7af7SAndreas Gohr    }
1131c112d578Sandi    print p_locale_xhtml('read');
1132f3f0262cSandi  }
1133f3f0262cSandi  if(!$DATE) $DATE = $INFO['lastmod'];
1134dc57ef04Sandi
1135dc57ef04Sandi
1136f3f0262cSandi?>
113763afe2a6SAnika Henke  <div style="width:99%;">
113842c7abd6SAndreas Gohr
113963afe2a6SAnika Henke   <div class="toolbar">
1140e656dcd4SAndreas Gohr      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div>
1141fdb8d77bSTom N Harris      <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1142409d7af7SAndreas Gohr      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
114320d062caSAndreas Gohr
11444da078a3Smatthiasgrimm      <?php if($wr){?>
1145e226efe1SAndreas Gohr      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
11464da078a3Smatthiasgrimm        <?php /* sets changed to true when previewed */?>
11478fe3bb00STom N Harris        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1148e226efe1SAndreas Gohr      //--><!]]></script>
114924a33b42SAndreas Gohr      <span id="spell__action"></span>
115024a33b42SAndreas Gohr      <div id="spell__suggest"></div>
1151ee4c4a1bSAndreas Gohr      <?php } ?>
115263afe2a6SAnika Henke   </div>
115324a33b42SAndreas Gohr   <div id="spell__result"></div>
11544da078a3Smatthiasgrimm<?php
1155fdb8d77bSTom N Harris  $form = new Doku_Form('dw__editform');
1156fdb8d77bSTom N Harris  $form->addHidden('id', $ID);
1157fdb8d77bSTom N Harris  $form->addHidden('rev', $REV);
1158fdb8d77bSTom N Harris  $form->addHidden('date', $DATE);
1159fdb8d77bSTom N Harris  $form->addHidden('prefix', $PRE);
1160fdb8d77bSTom N Harris  $form->addHidden('suffix', $SUF);
1161fdb8d77bSTom N Harris  $form->addHidden('changecheck', $check);
1162fdb8d77bSTom N Harris  $attr = array('tabindex'=>'1');
1163fdb8d77bSTom N Harris  if (!$wr) $attr['readonly'] = 'readonly';
1164fdb8d77bSTom N Harris  $form->addElement(form_makeWikiText($text, $attr));
1165fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1166fdb8d77bSTom N Harris  $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1167fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
1168fdb8d77bSTom N Harris  if ($wr) {
1169fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1170fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1171fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1172fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1173fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1174fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1175fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1176fdb8d77bSTom N Harris    $elem = html_minoredit();
1177fdb8d77bSTom N Harris    if ($elem) $form->addElement($elem);
1178fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1179fdb8d77bSTom N Harris  }
1180fdb8d77bSTom N Harris  $form->addElement(form_makeCloseTag('div'));
1181066fee30SAndreas Gohr  if($conf['license']){
1182066fee30SAndreas Gohr    $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1183066fee30SAndreas Gohr    $out  = $lang['licenseok'];
1184066fee30SAndreas Gohr    $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1185066fee30SAndreas Gohr    if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
1186066fee30SAndreas Gohr    $out .= '> '.$license[$conf['license']]['name'].'</a>';
1187066fee30SAndreas Gohr    $form->addElement($out);
1188066fee30SAndreas Gohr    $form->addElement(form_makeCloseTag('div'));
1189066fee30SAndreas Gohr  }
1190fdb8d77bSTom N Harris  html_form('edit', $form);
1191fdb8d77bSTom N Harris  print '</div>'.NL;
1192f3f0262cSandi}
1193f3f0262cSandi
1194f3f0262cSandi/**
1195b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1196b6912aeaSAndreas Gohr *
1197b6912aeaSAndreas Gohr * @author Andrea Gohr <andi@splitbrain.org>
1198b6912aeaSAndreas Gohr */
1199b6912aeaSAndreas Gohrfunction html_minoredit(){
1200b6912aeaSAndreas Gohr  global $conf;
1201b6912aeaSAndreas Gohr  global $lang;
1202b6912aeaSAndreas Gohr  // minor edits are for logged in users only
1203b6912aeaSAndreas Gohr  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1204fdb8d77bSTom N Harris    return false;
1205b6912aeaSAndreas Gohr  }
1206b6912aeaSAndreas Gohr
1207b6912aeaSAndreas Gohr  $p = array();
1208b6912aeaSAndreas Gohr  $p['tabindex'] = 3;
1209bb4866bdSchris  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1210fdb8d77bSTom N Harris  return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1211b6912aeaSAndreas Gohr}
1212b6912aeaSAndreas Gohr
1213b6912aeaSAndreas Gohr/**
1214f3f0262cSandi * prints some debug info
121515fae107Sandi *
121615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1217f3f0262cSandi */
1218f3f0262cSandifunction html_debug(){
1219f3f0262cSandi  global $conf;
1220d16a4edaSandi  global $lang;
12215298a619SAndreas Gohr  global $auth;
1222100a97e3SAndreas Gohr  global $INFO;
1223100a97e3SAndreas Gohr
122428fb55ffSandi  //remove sensitive data
122528fb55ffSandi  $cnf = $conf;
122624297a69SAndreas Gohr  debug_guard($cnf);
1227100a97e3SAndreas Gohr  $nfo = $INFO;
122824297a69SAndreas Gohr  debug_guard($nfo);
1229100a97e3SAndreas Gohr  $ses = $_SESSION;
123024297a69SAndreas Gohr  debug_guard($ses);
1231f3f0262cSandi
1232f3f0262cSandi  print '<html><body>';
1233f3f0262cSandi
1234f3f0262cSandi  print '<p>When reporting bugs please send all the following ';
1235f3f0262cSandi  print 'output as a mail to andi@splitbrain.org ';
1236f3f0262cSandi  print 'The best way to do this is to save this page in your browser</p>';
1237f3f0262cSandi
1238100a97e3SAndreas Gohr  print '<b>$INFO:</b><pre>';
1239100a97e3SAndreas Gohr  print_r($nfo);
1240100a97e3SAndreas Gohr  print '</pre>';
1241100a97e3SAndreas Gohr
1242f3f0262cSandi  print '<b>$_SERVER:</b><pre>';
1243f3f0262cSandi  print_r($_SERVER);
1244f3f0262cSandi  print '</pre>';
1245f3f0262cSandi
1246f3f0262cSandi  print '<b>$conf:</b><pre>';
124728fb55ffSandi  print_r($cnf);
1248f3f0262cSandi  print '</pre>';
1249f3f0262cSandi
1250ed7b5f09Sandi  print '<b>DOKU_BASE:</b><pre>';
1251ed7b5f09Sandi  print DOKU_BASE;
1252f3f0262cSandi  print '</pre>';
1253f3f0262cSandi
1254ed7b5f09Sandi  print '<b>abs DOKU_BASE:</b><pre>';
1255ed7b5f09Sandi  print DOKU_URL;
1256ed7b5f09Sandi  print '</pre>';
1257ed7b5f09Sandi
1258ed7b5f09Sandi  print '<b>rel DOKU_BASE:</b><pre>';
1259f3f0262cSandi  print dirname($_SERVER['PHP_SELF']).'/';
1260f3f0262cSandi  print '</pre>';
1261f3f0262cSandi
1262f3f0262cSandi  print '<b>PHP Version:</b><pre>';
1263f3f0262cSandi  print phpversion();
1264f3f0262cSandi  print '</pre>';
1265f3f0262cSandi
1266f3f0262cSandi  print '<b>locale:</b><pre>';
1267f3f0262cSandi  print setlocale(LC_ALL,0);
1268f3f0262cSandi  print '</pre>';
1269f3f0262cSandi
1270d16a4edaSandi  print '<b>encoding:</b><pre>';
1271d16a4edaSandi  print $lang['encoding'];
1272d16a4edaSandi  print '</pre>';
1273d16a4edaSandi
12745298a619SAndreas Gohr  if($auth){
12755298a619SAndreas Gohr    print '<b>Auth backend capabilities:</b><pre>';
12765298a619SAndreas Gohr    print_r($auth->cando);
12775298a619SAndreas Gohr    print '</pre>';
12785298a619SAndreas Gohr  }
12795298a619SAndreas Gohr
12803aa54d7cSAndreas Gohr  print '<b>$_SESSION:</b><pre>';
1281100a97e3SAndreas Gohr  print_r($ses);
12823aa54d7cSAndreas Gohr  print '</pre>';
12833aa54d7cSAndreas Gohr
1284f3f0262cSandi  print '<b>Environment:</b><pre>';
1285f3f0262cSandi  print_r($_ENV);
1286f3f0262cSandi  print '</pre>';
1287f3f0262cSandi
1288f3f0262cSandi  print '<b>PHP settings:</b><pre>';
1289f3f0262cSandi  $inis = ini_get_all();
1290f3f0262cSandi  print_r($inis);
1291f3f0262cSandi  print '</pre>';
1292f3f0262cSandi
1293f3f0262cSandi  print '</body></html>';
1294f3f0262cSandi}
1295f3f0262cSandi
1296c19fe9c0Sandifunction html_admin(){
1297c19fe9c0Sandi  global $ID;
1298f8cc712eSAndreas Gohr  global $INFO;
1299c19fe9c0Sandi  global $lang;
1300ca3a6df1SMatthias Grimm  global $conf;
1301c19fe9c0Sandi
1302c112d578Sandi  print p_locale_xhtml('admin');
1303c19fe9c0Sandi
130411e2ce22Schris  // build menu of admin functions from the plugins that handle them
130511e2ce22Schris  $pluginlist = plugin_list('admin');
130611e2ce22Schris  $menu = array();
130711e2ce22Schris  foreach ($pluginlist as $p) {
130811e2ce22Schris    if($obj =& plugin_load('admin',$p) === NULL) continue;
1309f8cc712eSAndreas Gohr
1310f8cc712eSAndreas Gohr    // check permissions
1311f8cc712eSAndreas Gohr    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1312f8cc712eSAndreas Gohr
131311e2ce22Schris    $menu[] = array('plugin' => $p,
131411e2ce22Schris                    'prompt' => $obj->getMenuText($conf['lang']),
131511e2ce22Schris                    'sort' => $obj->getMenuSort()
131611e2ce22Schris                   );
131711e2ce22Schris  }
131811e2ce22Schris
1319746855cfSBen Coburn  usort($menu, 'p_sort_modes');
132011e2ce22Schris
132111e2ce22Schris  // output the menu
132211e2ce22Schris  ptln('<ul>');
132311e2ce22Schris
132411e2ce22Schris  foreach ($menu as $item) {
132511e2ce22Schris    if (!$item['prompt']) continue;
13260c6b58a8SAndreas Gohr    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
132711e2ce22Schris  }
132811e2ce22Schris
132911e2ce22Schris  ptln('</ul>');
1330ca3a6df1SMatthias Grimm}
1331c19fe9c0Sandi
13328b06d178Schris/**
13338b06d178Schris * Form to request a new password for an existing account
13348b06d178Schris *
13358b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
133611e2ce22Schris */
13378b06d178Schrisfunction html_resendpwd() {
13388b06d178Schris  global $lang;
13398b06d178Schris  global $conf;
13408b06d178Schris  global $ID;
1341c19fe9c0Sandi
13428b06d178Schris  print p_locale_xhtml('resendpwd');
1343fdb8d77bSTom N Harris  print '<div class="centeralign">'.NL;
1344fdb8d77bSTom N Harris  $form = new Doku_Form('dw__resendpwd', wl($ID));
1345fdb8d77bSTom N Harris  $form->startFieldset($lang['resendpwd']);
1346fdb8d77bSTom N Harris  $form->addHidden('do', 'resendpwd');
1347fdb8d77bSTom N Harris  $form->addHidden('save', '1');
1348fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1349fdb8d77bSTom N Harris  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1350fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1351fdb8d77bSTom N Harris  $form->addElement(form_makeTag('br'));
1352fdb8d77bSTom N Harris  $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1353fdb8d77bSTom N Harris  $form->endFieldset();
1354fdb8d77bSTom N Harris  html_form('resendpwd', $form);
1355fdb8d77bSTom N Harris  print '</div>'.NL;
1356fdb8d77bSTom N Harris}
1357fdb8d77bSTom N Harris
1358fdb8d77bSTom N Harris/**
1359b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1360b8595a66SAndreas Gohr *
1361b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1362b8595a66SAndreas Gohr */
1363b8595a66SAndreas Gohrfunction html_TOC($toc){
1364b8595a66SAndreas Gohr    if(!count($toc)) return '';
1365b8595a66SAndreas Gohr    global $lang;
1366b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1367b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1368b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1369b8595a66SAndreas Gohr    $out .= $lang['toc'];
1370b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1371b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1372b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1373b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1374b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1375b8595a66SAndreas Gohr    return $out;                                                                                                }
1376b8595a66SAndreas Gohr
1377b8595a66SAndreas Gohr/**
1378b8595a66SAndreas Gohr * Callback for html_buildlist
1379b8595a66SAndreas Gohr */
1380b8595a66SAndreas Gohrfunction html_list_toc($item){
13817d91652aSAndreas Gohr    if($item['hid']){
13827d91652aSAndreas Gohr        $link = '#'.$item['hid'];
13837d91652aSAndreas Gohr    }else{
13847d91652aSAndreas Gohr        $link = $item['link'];
13857d91652aSAndreas Gohr    }
13867d91652aSAndreas Gohr
13877d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1388b8595a66SAndreas Gohr           hsc($item['title']).'</a></span>';
1389b8595a66SAndreas Gohr}
1390b8595a66SAndreas Gohr
1391b8595a66SAndreas Gohr/**
1392b8595a66SAndreas Gohr * Helper function to build TOC items
1393b8595a66SAndreas Gohr *
1394b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1395b8595a66SAndreas Gohr *
1396b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1397b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1398b8595a66SAndreas Gohr * @param int    $level - nesting level
1399b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1400b8595a66SAndreas Gohr */
1401b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1402b8595a66SAndreas Gohr    global $conf;
1403b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1404b8595a66SAndreas Gohr                   'title' => $text,
1405b8595a66SAndreas Gohr                   'type'  => 'ul',
14062bb0d541Schris                   'level' => $level);
1407b8595a66SAndreas Gohr}
1408b8595a66SAndreas Gohr
1409b8595a66SAndreas Gohr/**
1410fdb8d77bSTom N Harris * Output a Doku_Form object.
1411fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1412fdb8d77bSTom N Harris *
1413fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1414fdb8d77bSTom N Harris */
1415fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1416fdb8d77bSTom N Harris  // Safety check in case the caller forgets.
1417fdb8d77bSTom N Harris  $form->endFieldset();
1418fdb8d77bSTom N Harris  trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1419fdb8d77bSTom N Harris}
1420fdb8d77bSTom N Harris
1421fdb8d77bSTom N Harris/**
1422fdb8d77bSTom N Harris * Form print function.
1423fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1424fdb8d77bSTom N Harris */
1425fdb8d77bSTom N Harrisfunction html_form_output($data) {
1426fdb8d77bSTom N Harris  $data->printForm();
14278b06d178Schris}
1428340756e4Sandi
1429340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1430