xref: /dokuwiki/inc/html.php (revision ee4c4a1b5a5840c1b9d2d8c74b3f4298dd52928b)
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
9ed7b5f09Sandi  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10f3f0262cSandi
116bbae538Sandi  require_once(DOKU_INC.'inc/parserutils.php');
126bbae538Sandi
13f3f0262cSandi/**
14f3f0262cSandi * Convenience function to quickly build a wikilink
1515fae107Sandi *
1615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
17f3f0262cSandi */
1830f1737dSandifunction html_wikilink($id,$name=NULL,$search=''){
19723d78dbSandi  static $xhtml_renderer = NULL;
20723d78dbSandi  if(is_null($xhtml_renderer)){
21fdf3dcb9SMatthias Urlichs    require_once(DOKU_INC.'inc/parser/xhtml.php');
22723d78dbSandi    $xhtml_renderer = new Doku_Renderer_xhtml();
23f3f0262cSandi  }
24f3f0262cSandi
25cffcc403Sandi  return $xhtml_renderer->internallink($id,$name,$search,true);
26f3f0262cSandi}
27f3f0262cSandi
28f3f0262cSandi/**
29c19fe9c0Sandi * Helps building long attribute lists
30c19fe9c0Sandi *
31c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
32c19fe9c0Sandi */
33c19fe9c0Sandifunction html_attbuild($attributes){
34c19fe9c0Sandi  $ret = '';
35c19fe9c0Sandi  foreach ( $attributes as $key => $value ) {
36c19fe9c0Sandi    $ret .= $key.'="'.formtext($value).'" ';
37c19fe9c0Sandi  }
38c19fe9c0Sandi  return trim($ret);
39c19fe9c0Sandi}
40c19fe9c0Sandi
41c19fe9c0Sandi/**
42f3f0262cSandi * The loginform
4315fae107Sandi *
4415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
45f3f0262cSandi */
46f3f0262cSandifunction html_login(){
47f3f0262cSandi  global $lang;
48f3f0262cSandi  global $conf;
49f3f0262cSandi  global $ID;
50cd52f92dSchris  global $auth;
51f3f0262cSandi
52c112d578Sandi  print p_locale_xhtml('login');
53f3f0262cSandi  ?>
5496331712SAnika Henke    <div class="centeralign">
554da078a3Smatthiasgrimm    <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
56f3f0262cSandi      <fieldset>
574da078a3Smatthiasgrimm        <legend><?php echo $lang['btn_login']?></legend>
584da078a3Smatthiasgrimm        <input type="hidden" name="id" value="<?php echo $ID?>" />
59f3f0262cSandi        <input type="hidden" name="do" value="login" />
60b6912aeaSAndreas Gohr        <label class="block">
614da078a3Smatthiasgrimm          <span><?php echo $lang['user']?></span>
624da078a3Smatthiasgrimm          <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>" class="edit" />
63f3f0262cSandi        </label><br />
64b6912aeaSAndreas Gohr        <label class="block">
654da078a3Smatthiasgrimm          <span><?php echo $lang['pass']?></span>
66f3f0262cSandi          <input type="password" name="p" class="edit" />
67f3f0262cSandi        </label><br />
684da078a3Smatthiasgrimm        <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
690c1887a0SAndreas Gohr        <label for="remember__me" class="simple">
704d6f545eSAndreas Gohr          <input type="checkbox" name="r" id="remember__me" value="1" />
714da078a3Smatthiasgrimm          <span><?php echo $lang['remember']?></span>
72132bdbfeSandi        </label>
73f3f0262cSandi      </fieldset>
74f3f0262cSandi    </form>
754da078a3Smatthiasgrimm  <?php
7682fd59b6SAndreas Gohr    if($auth->canDo('addUser') && $conf['openregister']){
77f3f0262cSandi      print '<p>';
78f3f0262cSandi      print $lang['reghere'];
79f3f0262cSandi      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
80f3f0262cSandi      print '</p>';
81f3f0262cSandi    }
828b06d178Schris
8382fd59b6SAndreas Gohr    if ($auth->canDo('modPass') && $conf['resendpasswd']) {
848b06d178Schris      print '<p>';
858b06d178Schris      print $lang['pwdforget'];
86753d5abfSMatthias Grimm      print ': <a href="'.wl($ID,'do=resendpwd').'" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
878b06d178Schris      print '</p>';
888b06d178Schris    }
89f3f0262cSandi  ?>
90f3f0262cSandi    </div>
914da078a3Smatthiasgrimm  <?php
926bbae538Sandi/*
936bbae538Sandi FIXME provide new hook
94f3f0262cSandi  if(@file_exists('includes/login.txt')){
95f3f0262cSandi    print io_cacheParse('includes/login.txt');
96f3f0262cSandi  }
976bbae538Sandi*/
98f3f0262cSandi}
99f3f0262cSandi
100f3f0262cSandi/**
101*ee4c4a1bSAndreas Gohr * shows the edit/source/show/draft button dependent on current mode
10215fae107Sandi *
10315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
104f3f0262cSandi */
105f3f0262cSandifunction html_editbutton(){
106f3f0262cSandi  global $ID;
107f3f0262cSandi  global $REV;
108f3f0262cSandi  global $ACT;
109f3f0262cSandi  global $INFO;
110f3f0262cSandi
111f3f0262cSandi  if($ACT == 'show' || $ACT == 'search'){
112f3f0262cSandi    if($INFO['writable']){
113*ee4c4a1bSAndreas Gohr      if($INFO['draft']){
114*ee4c4a1bSAndreas Gohr          $r = html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
115*ee4c4a1bSAndreas Gohr      }else{
116f3f0262cSandi        if($INFO['exists']){
117f3f0262cSandi          $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
118f3f0262cSandi        }else{
119f3f0262cSandi          $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
120f3f0262cSandi        }
121*ee4c4a1bSAndreas Gohr      }
122f3f0262cSandi    }else{
123f3f0262cSandi      $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
124f3f0262cSandi    }
125f3f0262cSandi  }else{
126f3f0262cSandi    $r = html_btn('show',$ID,'v',array('do' => 'show'));
127f3f0262cSandi  }
128f3f0262cSandi  return $r;
129f3f0262cSandi}
130f3f0262cSandi
13115fae107Sandi/**
13215fae107Sandi * prints a section editing button
13315fae107Sandi *
13415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
13515fae107Sandi */
136f3f0262cSandifunction html_secedit_button($section,$p){
137f3f0262cSandi  global $ID;
138f3f0262cSandi  global $lang;
139f3f0262cSandi  $secedit  = '';
140506ae684Sandi#  if($p) $secedit .= "</p>\n";
141f3f0262cSandi  $secedit .= '<div class="secedit">';
142f3f0262cSandi  $secedit .= html_btn('secedit',$ID,'',
143f3f0262cSandi                        array('do'      => 'edit',
144f3f0262cSandi                              'lines'   => "$section"),
145f3f0262cSandi                              'post');
146f3f0262cSandi  $secedit .= '</div>';
147506ae684Sandi#  if($p) $secedit .= "\n<p>";
148f3f0262cSandi  return $secedit;
149f3f0262cSandi}
150f3f0262cSandi
15115fae107Sandi/**
15215fae107Sandi * inserts section edit buttons if wanted or removes the markers
15315fae107Sandi *
15415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
15515fae107Sandi */
156f3f0262cSandifunction html_secedit($text,$show=true){
157f3f0262cSandi  global $INFO;
158c112d578Sandi  if($INFO['writable'] && $show && !$INFO['rev']){
159f3f0262cSandi    $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
160f3f0262cSandi                         "html_secedit_button('\\1',true)",
161f3f0262cSandi                         $text);
162f3f0262cSandi    $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
163f3f0262cSandi                         "html_secedit_button('\\1',false)",
164f3f0262cSandi                         $text);
165f3f0262cSandi  }else{
166f3f0262cSandi    $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
167f3f0262cSandi  }
168f3f0262cSandi  return $text;
169f3f0262cSandi}
170f3f0262cSandi
171f3f0262cSandi/**
172d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1736b13307fSandi *
1746b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1756b13307fSandi */
1766b13307fSandifunction html_topbtn(){
1776b13307fSandi  global $lang;
1786b13307fSandi
1796b13307fSandi  $ret  = '';
18021a15207SAnika Henke  $ret  = '<a href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" /></a>';
181df7b6005Sandi
1826b13307fSandi  return $ret;
1836b13307fSandi}
1846b13307fSandi
1856b13307fSandi/**
186d67ca2c0Smatthiasgrimm * Just the back to media window button in its own form
187d67ca2c0Smatthiasgrimm *
188d67ca2c0Smatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
189d67ca2c0Smatthiasgrimm */
190d67ca2c0Smatthiasgrimmfunction html_backtomedia_button($params,$akey=''){
191d67ca2c0Smatthiasgrimm  global $conf;
192d67ca2c0Smatthiasgrimm  global $lang;
193d67ca2c0Smatthiasgrimm
1944beabca9SAnika Henke  $ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/media.php"><div class="no">';
195d67ca2c0Smatthiasgrimm
196d67ca2c0Smatthiasgrimm  reset($params);
197d67ca2c0Smatthiasgrimm  while (list($key, $val) = each($params)) {
198d67ca2c0Smatthiasgrimm    $ret .= '<input type="hidden" name="'.$key.'" ';
199d67ca2c0Smatthiasgrimm    $ret .= 'value="'.htmlspecialchars($val).'" />';
200d67ca2c0Smatthiasgrimm  }
201d67ca2c0Smatthiasgrimm
202d67ca2c0Smatthiasgrimm  $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" ';
203d67ca2c0Smatthiasgrimm  if($akey){
204d67ca2c0Smatthiasgrimm    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
205d67ca2c0Smatthiasgrimm    $ret .= 'accesskey="'.$akey.'" ';
206d67ca2c0Smatthiasgrimm  }
207d67ca2c0Smatthiasgrimm  $ret .= '/>';
2084beabca9SAnika Henke  $ret .= '</div></form>';
209d67ca2c0Smatthiasgrimm
210d67ca2c0Smatthiasgrimm  return $ret;
211d67ca2c0Smatthiasgrimm}
212d67ca2c0Smatthiasgrimm
213d67ca2c0Smatthiasgrimm/**
214d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
21515fae107Sandi *
21615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
217f3f0262cSandi */
218f3f0262cSandifunction html_btn($name,$id,$akey,$params,$method='get'){
219f3f0262cSandi  global $conf;
220f3f0262cSandi  global $lang;
221f3f0262cSandi
222f3f0262cSandi  $label = $lang['btn_'.$name];
223f3f0262cSandi
224f3f0262cSandi  $ret = '';
225f3f0262cSandi
22649c713a3Sandi  //filter id (without urlencoding)
22749c713a3Sandi  $id = idfilter($id,false);
228f3f0262cSandi
229f3f0262cSandi  //make nice URLs even for buttons
2306c7843b5Sandi  if($conf['userewrite'] == 2){
2316c7843b5Sandi    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
2326c7843b5Sandi  }elseif($conf['userewrite']){
2336c7843b5Sandi    $script = DOKU_BASE.$id;
2346c7843b5Sandi  }else{
2358b00ebcfSandi    $script = DOKU_BASE.DOKU_SCRIPT;
236f3f0262cSandi    $params['id'] = $id;
237f3f0262cSandi  }
238f3f0262cSandi
2394beabca9SAnika Henke  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">';
240f3f0262cSandi
24106a4bf8fSAndreas Gohr  if(is_array($params)){
242f3f0262cSandi    reset($params);
243f3f0262cSandi    while (list($key, $val) = each($params)) {
244f3f0262cSandi      $ret .= '<input type="hidden" name="'.$key.'" ';
245f3f0262cSandi      $ret .= 'value="'.htmlspecialchars($val).'" />';
246f3f0262cSandi    }
24706a4bf8fSAndreas Gohr  }
248f3f0262cSandi
249f3f0262cSandi  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
250f3f0262cSandi  if($akey){
251f3f0262cSandi    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
252f3f0262cSandi    $ret .= 'accesskey="'.$akey.'" ';
253f3f0262cSandi  }
254f3f0262cSandi  $ret .= '/>';
2554beabca9SAnika Henke  $ret .= '</div></form>';
256f3f0262cSandi
257f3f0262cSandi  return $ret;
258f3f0262cSandi}
259f3f0262cSandi
260f3f0262cSandi/**
26115fae107Sandi * show a wiki page
26215fae107Sandi *
26315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
26415fae107Sandi */
2656bbae538Sandifunction html_show($txt=''){
266f3f0262cSandi  global $ID;
267f3f0262cSandi  global $REV;
268f3f0262cSandi  global $HIGH;
269f3f0262cSandi  //disable section editing for old revisions or in preview
2705400331dSandi  if($txt || $REV){
2716bbae538Sandi    $secedit = false;
2726bbae538Sandi  }else{
2736bbae538Sandi    $secedit = true;
274f3f0262cSandi  }
275f3f0262cSandi
2766bbae538Sandi  if ($txt){
277f3f0262cSandi    //PreviewHeader
27850835be7SAndreas Gohr    print '<br id="scroll__here" />';
279c112d578Sandi    print p_locale_xhtml('preview');
280f3f0262cSandi    print '<div class="preview">';
2819dc2c2afSandi    print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
28246723c19SAndreas Gohr    print '<div class="clearer"></div>';
283f3f0262cSandi    print '</div>';
2846bbae538Sandi
285f3f0262cSandi  }else{
286c112d578Sandi    if ($REV) print p_locale_xhtml('showrev');
287c112d578Sandi    $html = p_wiki_xhtml($ID,$REV,true);
2886bbae538Sandi    $html = html_secedit($html,$secedit);
289f3f0262cSandi    print html_hilight($html,$HIGH);
290f3f0262cSandi  }
291f3f0262cSandi}
292f3f0262cSandi
293f3f0262cSandi/**
294*ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
295*ee4c4a1bSAndreas Gohr *
296*ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
297*ee4c4a1bSAndreas Gohr */
298*ee4c4a1bSAndreas Gohrfunction html_draft(){
299*ee4c4a1bSAndreas Gohr  global $INFO;
300*ee4c4a1bSAndreas Gohr  global $ID;
301*ee4c4a1bSAndreas Gohr  global $lang;
302*ee4c4a1bSAndreas Gohr  global $conf;
303*ee4c4a1bSAndreas Gohr  $draft = unserialize(io_readFile($INFO['draft'],false));
304*ee4c4a1bSAndreas Gohr  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
305*ee4c4a1bSAndreas Gohr
306*ee4c4a1bSAndreas Gohr  echo p_locale_xhtml('draft');
307*ee4c4a1bSAndreas Gohr  ?>
308*ee4c4a1bSAndreas Gohr  <form id="dw__editform" method="post" action="<?php echo script()?>"
309*ee4c4a1bSAndreas Gohr   accept-charset="<?php echo $lang['encoding']?>"><div class="no">
310*ee4c4a1bSAndreas Gohr    <input type="hidden" name="id"   value="<?php echo $ID?>" />
311*ee4c4a1bSAndreas Gohr    <input type="hidden" name="date" value="<?php echo $draft['date']?>" /></div>
312*ee4c4a1bSAndreas Gohr    <textarea name="wikitext" id="wiki__text" readonly="readonly" cols="80" rows="10" class="edit"><?php echo "\n".formText($text)?></textarea>
313*ee4c4a1bSAndreas Gohr
314*ee4c4a1bSAndreas Gohr    <div id="draft__status"><?php echo $lang['draftdate'].' '.date($conf['dformat'],filemtime($INFO['draft']))?></div>
315*ee4c4a1bSAndreas Gohr
316*ee4c4a1bSAndreas Gohr    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_recover']?>" tabindex="1" />
317*ee4c4a1bSAndreas Gohr    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_draftdel']?>" tabindex="2" />
318*ee4c4a1bSAndreas Gohr    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="3" />
319*ee4c4a1bSAndreas Gohr  </form>
320*ee4c4a1bSAndreas Gohr  <?php
321*ee4c4a1bSAndreas Gohr}
322*ee4c4a1bSAndreas Gohr
323*ee4c4a1bSAndreas Gohr/**
324f3f0262cSandi * Highlights searchqueries in HTML code
32515fae107Sandi *
32615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
3277209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
328f3f0262cSandi */
329f3f0262cSandifunction html_hilight($html,$query){
3307209be23SAndreas Gohr  //split at common delimiters
3319d9c165eSAndreas Gohr  $queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY);
332f3f0262cSandi  foreach ($queries as $q){
333f3f0262cSandi     $q = preg_quote($q,'/');
3347209be23SAndreas Gohr     $html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html);
335f3f0262cSandi  }
336f3f0262cSandi  return $html;
337f3f0262cSandi}
338f3f0262cSandi
339f3f0262cSandi/**
3407209be23SAndreas Gohr * Callback used by html_hilight()
3417209be23SAndreas Gohr *
3427209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
3437209be23SAndreas Gohr */
3447209be23SAndreas Gohrfunction html_hilight_callback($m) {
3457209be23SAndreas Gohr  $hlight = unslash($m[0]);
3467209be23SAndreas Gohr  if ( !isset($m[2])) {
3477209be23SAndreas Gohr    $hlight = '<span class="search_hit">'.$hlight.'</span>';
3487209be23SAndreas Gohr  }
3497209be23SAndreas Gohr  return $hlight;
3507209be23SAndreas Gohr}
3517209be23SAndreas Gohr
3527209be23SAndreas Gohr/**
35315fae107Sandi * Run a search and display the result
35415fae107Sandi *
35515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
356f3f0262cSandi */
357f3f0262cSandifunction html_search(){
358ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
359506fa893SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
360f3f0262cSandi  global $conf;
361f3f0262cSandi  global $QUERY;
362f3f0262cSandi  global $ID;
363f3f0262cSandi  global $lang;
364f3f0262cSandi
365c112d578Sandi  print p_locale_xhtml('searchpage');
366f3f0262cSandi  flush();
367f3f0262cSandi
3684d9ff3d5Sandi  //show progressbar
3699edac8a8SAndreas Gohr  print '<div class="centeralign" id="dw__loading">';
3704d9ff3d5Sandi  print '<br /></div>';
3719edac8a8SAndreas Gohr  print '<script type="text/javascript" charset="utf-8">';
3729edac8a8SAndreas Gohr  print 'showLoadBar("dw__loading");';
3739edac8a8SAndreas Gohr  print '</script>';
3749edac8a8SAndreas Gohr  flush();
3754d9ff3d5Sandi
376f3f0262cSandi  //do quick pagesearch
377f3f0262cSandi  $data = array();
378506fa893SAndreas Gohr  $data = ft_pageLookup(cleanID($QUERY));
379f3f0262cSandi  if(count($data)){
380f3f0262cSandi    sort($data);
381f3f0262cSandi    print '<div class="search_quickresult">';
3824f732f0eSAnika Henke    print '<h3>'.$lang[quickhits].':</h3>';
3834f732f0eSAnika Henke    print '<ul class="search_quickhits">';
384140c93f3SAnika Henke    foreach($data as $id){
3854f732f0eSAnika Henke      print '<li> ';
386506fa893SAndreas Gohr      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id);
3874f732f0eSAnika Henke      print '</li> ';
388f3f0262cSandi    }
389140c93f3SAnika Henke    print '</ul> ';
390f3f0262cSandi    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
391f3f0262cSandi    print '<div class="clearer">&nbsp;</div>';
392f3f0262cSandi    print '</div>';
393f3f0262cSandi  }
394f3f0262cSandi  flush();
395f3f0262cSandi
396f3f0262cSandi  //do fulltext search
397506fa893SAndreas Gohr  $data = ft_pageSearch($QUERY,$poswords);
398f3f0262cSandi  if(count($data)){
399506fa893SAndreas Gohr    $num = 1;
400506fa893SAndreas Gohr    foreach($data as $id => $cnt){
401f3f0262cSandi      print '<div class="search_result">';
402506fa893SAndreas Gohr      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
403506fa893SAndreas Gohr      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
404506fa893SAndreas Gohr      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
405506fa893SAndreas Gohr        print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
406506fa893SAndreas Gohr      }
407f3f0262cSandi      print '</div>';
408506fa893SAndreas Gohr      flush();
409506fa893SAndreas Gohr      $num++;
410f3f0262cSandi    }
411f3f0262cSandi  }else{
412820fa24bSandi    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
413f3f0262cSandi  }
4144d9ff3d5Sandi
4154d9ff3d5Sandi  //hide progressbar
4164beabca9SAnika Henke  print '<script type="text/javascript" charset="utf-8">';
4179edac8a8SAndreas Gohr  print 'hideLoadBar("dw__loading");';
4184d9ff3d5Sandi  print '</script>';
4199edac8a8SAndreas Gohr  flush();
420f3f0262cSandi}
421f3f0262cSandi
42215fae107Sandi/**
42315fae107Sandi * Display error on locked pages
42415fae107Sandi *
42515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
42615fae107Sandi */
427ee20e7d1Sandifunction html_locked(){
428f3f0262cSandi  global $ID;
429f3f0262cSandi  global $conf;
430f3f0262cSandi  global $lang;
43188f522e9Sandi  global $INFO;
432f3f0262cSandi
433f3f0262cSandi  $locktime = filemtime(wikiFN($ID).'.lock');
434f3f0262cSandi  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
435f3f0262cSandi  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
436f3f0262cSandi
437c112d578Sandi  print p_locale_xhtml('locked');
438f3f0262cSandi  print '<ul>';
4390c6b58a8SAndreas Gohr  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
4400c6b58a8SAndreas Gohr  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
441f3f0262cSandi  print '</ul>';
442f3f0262cSandi}
443f3f0262cSandi
44415fae107Sandi/**
44515fae107Sandi * list old revisions
44615fae107Sandi *
44715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
44815fae107Sandi */
449f3f0262cSandifunction html_revisions(){
450f3f0262cSandi  global $ID;
451f3f0262cSandi  global $INFO;
452f3f0262cSandi  global $conf;
453f3f0262cSandi  global $lang;
454f3f0262cSandi  $revisions = getRevisions($ID);
455f3f0262cSandi  $date = @date($conf['dformat'],$INFO['lastmod']);
456f3f0262cSandi
457c112d578Sandi  print p_locale_xhtml('revisions');
458f3f0262cSandi  print '<ul>';
459f3f0262cSandi  if($INFO['exists']){
460b6912aeaSAndreas Gohr    print ($INFO['minor']) ? '<li class="minor">' : '<li>';
4610c6b58a8SAndreas Gohr    print '<div class="li">';
462f9b2fe70Sandi
463f9b2fe70Sandi    print $date;
464f9b2fe70Sandi
46502e51121SAnika Henke    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
466cffcc403Sandi
467f9b2fe70Sandi    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
468652610a2Sandi
469652610a2Sandi    print $INFO['sum'];
47088f522e9Sandi    print ' <span class="user">';
47188f522e9Sandi    print $INFO['editor'];
47288f522e9Sandi    print '</span> ';
473652610a2Sandi
474652610a2Sandi    print '('.$lang['current'].')';
4750c6b58a8SAndreas Gohr    print '</div>';
476652610a2Sandi    print '</li>';
477f3f0262cSandi  }
478f3f0262cSandi
479f3f0262cSandi  foreach($revisions as $rev){
480f3f0262cSandi    $date = date($conf['dformat'],$rev);
481652610a2Sandi    $info = getRevisionInfo($ID,$rev);
482652610a2Sandi
483b6912aeaSAndreas Gohr    print ($info['minor']) ? '<li class="minor">' : '<li>';
4840c6b58a8SAndreas Gohr    print '<div class="li">';
485f9b2fe70Sandi    print $date;
486f9b2fe70Sandi
487cffcc403Sandi    print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
488d94f4568SAndreas Gohr    $p = array();
489d94f4568SAndreas Gohr    $p['src']    = DOKU_BASE.'lib/images/diff.png';
490d94f4568SAndreas Gohr    $p['width']  = 15;
491d94f4568SAndreas Gohr    $p['height'] = 11;
492d94f4568SAndreas Gohr    $p['title']  = $lang['diff'];
493d94f4568SAndreas Gohr    $p['alt']    = $lang['diff'];
494d94f4568SAndreas Gohr    $att = buildAttributes($p);
495d94f4568SAndreas Gohr    print "<img $att />";
496cffcc403Sandi    print '</a> ';
497cffcc403Sandi
498f9b2fe70Sandi    print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
499f9b2fe70Sandi
500f243a77fSandi    print htmlspecialchars($info['sum']);
50188f522e9Sandi    print ' <span class="user">';
50288f522e9Sandi    if($info['user']){
50388f522e9Sandi      print $info['user'];
50488f522e9Sandi    }else{
505652610a2Sandi      print $info['ip'];
50688f522e9Sandi    }
50788f522e9Sandi    print '</span>';
508652610a2Sandi
5090c6b58a8SAndreas Gohr    print '</div>';
510f3f0262cSandi    print '</li>';
511f3f0262cSandi  }
512f3f0262cSandi  print '</ul>';
513f3f0262cSandi}
514f3f0262cSandi
51515fae107Sandi/**
51615fae107Sandi * display recent changes
51715fae107Sandi *
51815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5195749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
52015fae107Sandi */
521a39955b0Smatthiasgrimmfunction html_recent($first=0){
522f3f0262cSandi  global $conf;
523cffcc403Sandi  global $lang;
524dbb00abcSEsther Brunner  global $ID;
5255749f1ceSmatthiasgrimm  /* we need to get one additionally log entry to be able to
5265749f1ceSmatthiasgrimm   * decide if this is the last page or is there another one.
5275749f1ceSmatthiasgrimm   * This is the cheapest solution to get this information.
5285749f1ceSmatthiasgrimm   */
529b6912aeaSAndreas Gohr  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5305749f1ceSmatthiasgrimm  if(count($recents) == 0 && $first != 0){
5315749f1ceSmatthiasgrimm    $first=0;
532b6912aeaSAndreas Gohr    $recents = getRecents(0,$conf['recent'] + 1,getNS($ID));
5335749f1ceSmatthiasgrimm  }
5345749f1ceSmatthiasgrimm  $cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent'];
535f3f0262cSandi
536c112d578Sandi  print p_locale_xhtml('recent');
537f3f0262cSandi  print '<ul>';
538a39955b0Smatthiasgrimm
539d437bcc4SAndreas Gohr  foreach($recents as $recent){
540d437bcc4SAndreas Gohr    $date = date($conf['dformat'],$recent['date']);
541b6912aeaSAndreas Gohr    print ($recent['minor']) ? '<li class="minor">' : '<li>';
5420c6b58a8SAndreas Gohr    print '<div class="li">';
543cffcc403Sandi
544f9b2fe70Sandi    print $date.' ';
545f9b2fe70Sandi
546d437bcc4SAndreas Gohr    print '<a href="'.wl($recent['id'],"do=diff").'">';
547d94f4568SAndreas Gohr    $p = array();
548d94f4568SAndreas Gohr    $p['src']    = DOKU_BASE.'lib/images/diff.png';
549d94f4568SAndreas Gohr    $p['width']  = 15;
550d94f4568SAndreas Gohr    $p['height'] = 11;
551d94f4568SAndreas Gohr    $p['title']  = $lang['diff'];
552d94f4568SAndreas Gohr    $p['alt']    = $lang['diff'];
553d94f4568SAndreas Gohr    $att = buildAttributes($p);
554d94f4568SAndreas Gohr    print "<img $att />";
555cffcc403Sandi    print '</a> ';
556cffcc403Sandi
557d437bcc4SAndreas Gohr    print '<a href="'.wl($recent['id'],"do=revisions").'">';
558d94f4568SAndreas Gohr    $p = array();
559d94f4568SAndreas Gohr    $p['src']    = DOKU_BASE.'lib/images/history.png';
560d94f4568SAndreas Gohr    $p['width']  = 12;
561d94f4568SAndreas Gohr    $p['height'] = 14;
562d94f4568SAndreas Gohr    $p['title']  = $lang['btn_revs'];
563d94f4568SAndreas Gohr    $p['alt']    = $lang['btn_revs'];
564d94f4568SAndreas Gohr    $att = buildAttributes($p);
565d94f4568SAndreas Gohr    print "<img $att />";
566cffcc403Sandi    print '</a> ';
567cffcc403Sandi
568d437bcc4SAndreas Gohr    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
569d437bcc4SAndreas Gohr    print ' '.htmlspecialchars($recent['sum']);
570b6912aeaSAndreas Gohr
57188f522e9Sandi    print ' <span class="user">';
572d437bcc4SAndreas Gohr    if($recent['user']){
573d437bcc4SAndreas Gohr      print $recent['user'];
57488f522e9Sandi    }else{
575d437bcc4SAndreas Gohr      print $recent['ip'];
57688f522e9Sandi    }
57788f522e9Sandi    print '</span>';
578cffcc403Sandi
5790c6b58a8SAndreas Gohr    print '</div>';
580f3f0262cSandi    print '</li>';
581f3f0262cSandi  }
582f3f0262cSandi  print '</ul>';
583a39955b0Smatthiasgrimm
584a39955b0Smatthiasgrimm  print '<div class="pagenav">';
5855749f1ceSmatthiasgrimm  $last = $first + $conf['recent'];
586a39955b0Smatthiasgrimm  if ($first > 0) {
587a39955b0Smatthiasgrimm    $first -= $conf['recent'];
588a39955b0Smatthiasgrimm    if ($first < 0) $first = 0;
589a39955b0Smatthiasgrimm    print '<div class="pagenav-prev">';
5905749f1ceSmatthiasgrimm    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
591a39955b0Smatthiasgrimm    print '</div>';
592a39955b0Smatthiasgrimm  }
5935749f1ceSmatthiasgrimm  if ($conf['recent'] < count($recents)) {
594a39955b0Smatthiasgrimm    print '<div class="pagenav-next">';
5955749f1ceSmatthiasgrimm    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
596a39955b0Smatthiasgrimm    print '</div>';
597a39955b0Smatthiasgrimm  }
598a39955b0Smatthiasgrimm  print '</div>';
599f3f0262cSandi}
600f3f0262cSandi
60115fae107Sandi/**
60215fae107Sandi * Display page index
60315fae107Sandi *
60415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
60515fae107Sandi */
606f3f0262cSandifunction html_index($ns){
607ed7b5f09Sandi  require_once(DOKU_INC.'inc/search.php');
608f3f0262cSandi  global $conf;
609f3f0262cSandi  global $ID;
610f3f0262cSandi  $dir = $conf['datadir'];
611f3f0262cSandi  $ns  = cleanID($ns);
61230f1737dSandi  #fixme use appropriate function
613f3f0262cSandi  if(empty($ns)){
614f3f0262cSandi    $ns = dirname(str_replace(':','/',$ID));
615f3f0262cSandi    if($ns == '.') $ns ='';
616f3f0262cSandi  }
61788d3a917Sandi  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
618f3f0262cSandi
619c112d578Sandi  print p_locale_xhtml('index');
620f3f0262cSandi
621f3f0262cSandi  $data = array();
622f3f0262cSandi  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
623cb70c441Sandi  print html_buildlist($data,'idx','html_list_index','html_li_index');
624f3f0262cSandi}
625f3f0262cSandi
626f3f0262cSandi/**
62715fae107Sandi * Index item formatter
62815fae107Sandi *
629f3f0262cSandi * User function for html_buildlist()
63015fae107Sandi *
63115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
632f3f0262cSandi */
633f3f0262cSandifunction html_list_index($item){
634f3f0262cSandi  $ret = '';
635f3f0262cSandi  $base = ':'.$item['id'];
636f3f0262cSandi  $base = substr($base,strrpos($base,':')+1);
637f3f0262cSandi  if($item['type']=='d'){
638f3f0262cSandi    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
639f3f0262cSandi    $ret .= $base;
640f3f0262cSandi    $ret .= '</a>';
641f3f0262cSandi  }else{
642f3f0262cSandi    $ret .= html_wikilink(':'.$item['id']);
643f3f0262cSandi  }
644f3f0262cSandi  return $ret;
645f3f0262cSandi}
646f3f0262cSandi
647f3f0262cSandi/**
648cb70c441Sandi * Index List item
649cb70c441Sandi *
650cb70c441Sandi * This user function is used in html_build_lidt to build the
651cb70c441Sandi * <li> tags for namespaces when displaying the page index
652cb70c441Sandi * it gives different classes to opened or closed "folders"
653cb70c441Sandi *
654cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
655cb70c441Sandi */
656cb70c441Sandifunction html_li_index($item){
657cb70c441Sandi  if($item['type'] == "f"){
658cb70c441Sandi    return '<li class="level'.$item['level'].'">';
659cb70c441Sandi  }elseif($item['open']){
660cb70c441Sandi    return '<li class="open">';
661cb70c441Sandi  }else{
662cb70c441Sandi    return '<li class="closed">';
663cb70c441Sandi  }
664cb70c441Sandi}
665cb70c441Sandi
666cb70c441Sandi/**
667cb70c441Sandi * Default List item
668cb70c441Sandi *
669cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
670cb70c441Sandi */
671cb70c441Sandifunction html_li_default($item){
672cb70c441Sandi  return '<li class="level'.$item['level'].'">';
673cb70c441Sandi}
674cb70c441Sandi
675cb70c441Sandi/**
67615fae107Sandi * Build an unordered list
67715fae107Sandi *
678f3f0262cSandi * Build an unordered list from the given $data array
679f3f0262cSandi * Each item in the array has to have a 'level' property
680f3f0262cSandi * the item itself gets printed by the given $func user
681cb70c441Sandi * function. The second and optional function is used to
682cb70c441Sandi * print the <li> tag. Both user function need to accept
683cb70c441Sandi * a single item.
68415fae107Sandi *
685c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
686c5a8fd96SAndreas Gohr * a member of an object.
687c5a8fd96SAndreas Gohr *
68815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
689f3f0262cSandi */
690cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
691f3f0262cSandi  $level = 0;
692f3f0262cSandi  $opens = 0;
693f3f0262cSandi  $ret   = '';
694f3f0262cSandi
695f3f0262cSandi  foreach ($data as $item){
696f3f0262cSandi
697f3f0262cSandi    if( $item['level'] > $level ){
698f3f0262cSandi      //open new list
699df52d0feSandi      for($i=0; $i<($item['level'] - $level); $i++){
700df52d0feSandi        if ($i) $ret .= "<li class=\"clear\">\n";
701f3f0262cSandi        $ret .= "\n<ul class=\"$class\">\n";
702df52d0feSandi      }
703f3f0262cSandi    }elseif( $item['level'] < $level ){
704f3f0262cSandi      //close last item
705f3f0262cSandi      $ret .= "</li>\n";
706f3f0262cSandi      for ($i=0; $i<($level - $item['level']); $i++){
707f3f0262cSandi        //close higher lists
708f3f0262cSandi        $ret .= "</ul>\n</li>\n";
709f3f0262cSandi      }
710f3f0262cSandi    }else{
711f3f0262cSandi      //close last item
712f3f0262cSandi      $ret .= "</li>\n";
713f3f0262cSandi    }
714f3f0262cSandi
715f3f0262cSandi    //remember current level
716f3f0262cSandi    $level = $item['level'];
717f3f0262cSandi
718f3f0262cSandi    //print item
719c5a8fd96SAndreas Gohr    if(is_array($lifunc)){
720c5a8fd96SAndreas Gohr      $ret .= $lifunc[0]->$lifunc[1]($item); //user object method
721c5a8fd96SAndreas Gohr    }else{
722cb70c441Sandi      $ret .= $lifunc($item); //user function
723c5a8fd96SAndreas Gohr    }
7240c6b58a8SAndreas Gohr    $ret .= '<div class="li">';
725c5a8fd96SAndreas Gohr    if(is_array($func)){
726c5a8fd96SAndreas Gohr      $ret .= $func[0]->$func[1]($item); //user object method
727c5a8fd96SAndreas Gohr    }else{
728f3f0262cSandi    $ret .= $func($item); //user function
729c5a8fd96SAndreas Gohr    }
7300c6b58a8SAndreas Gohr    $ret .= '</div>';
731f3f0262cSandi  }
732f3f0262cSandi
733f3f0262cSandi  //close remaining items and lists
734f3f0262cSandi  for ($i=0; $i < $level; $i++){
735f3f0262cSandi    $ret .= "</li></ul>\n";
736f3f0262cSandi  }
737f3f0262cSandi
738f3f0262cSandi  return $ret;
739f3f0262cSandi}
740f3f0262cSandi
74115fae107Sandi/**
74215fae107Sandi * display backlinks
74315fae107Sandi *
74415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
74515fae107Sandi */
746f3f0262cSandifunction html_backlinks(){
74754f4c056SAndreas Gohr  require_once(DOKU_INC.'inc/fulltext.php');
748f3f0262cSandi  global $ID;
749f3f0262cSandi  global $conf;
750f3f0262cSandi
751c112d578Sandi  print p_locale_xhtml('backlinks');
752f3f0262cSandi
75354f4c056SAndreas Gohr  $data = ft_backlinks($ID);
754f3f0262cSandi
755f3f0262cSandi  print '<ul class="idx">';
75654f4c056SAndreas Gohr  foreach($data as $blink){
7570c6b58a8SAndreas Gohr    print '<li><div class="li">';
75854f4c056SAndreas Gohr    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
7590c6b58a8SAndreas Gohr    print '</div></li>';
760f3f0262cSandi  }
761f3f0262cSandi  print '</ul>';
762f3f0262cSandi}
763f3f0262cSandi
76415fae107Sandi/**
76515fae107Sandi * show diff
76615fae107Sandi *
76715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
76815fae107Sandi */
769f3f0262cSandifunction html_diff($text='',$intro=true){
770ed7b5f09Sandi  require_once(DOKU_INC.'inc/DifferenceEngine.php');
771f3f0262cSandi  global $ID;
772f3f0262cSandi  global $REV;
773f3f0262cSandi  global $lang;
774f3f0262cSandi  global $conf;
775f3f0262cSandi  if($text){
776f3f0262cSandi    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
777f3f0262cSandi                    split("\n",htmlspecialchars(cleanText($text))));
778f3f0262cSandi    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
779f3f0262cSandi              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
780f3f0262cSandi              $lang['current'];
781f3f0262cSandi    $right = $lang['yours'];
782f3f0262cSandi  }else{
7834d58bd99Sandi    if($REV){
7844d58bd99Sandi      $r = $REV;
7854d58bd99Sandi    }else{
7864d58bd99Sandi      //use last revision if none given
7874d58bd99Sandi      $revs = getRevisions($ID);
7884d58bd99Sandi      $r = $revs[0];
7894d58bd99Sandi    }
7904d58bd99Sandi
7914d58bd99Sandi    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))),
792f3f0262cSandi                    split("\n",htmlspecialchars(rawWiki($ID,''))));
7934d58bd99Sandi    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
7944d58bd99Sandi              $ID.' '.date($conf['dformat'],$r).'</a>';
795f3f0262cSandi    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
796f3f0262cSandi              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
797f3f0262cSandi              $lang['current'];
798f3f0262cSandi  }
799f3f0262cSandi  $tdf = new TableDiffFormatter();
800c112d578Sandi  if($intro) print p_locale_xhtml('diff');
801f3f0262cSandi  ?>
802daf4ca4eSAnika Henke    <table class="diff">
803f3f0262cSandi      <tr>
804daf4ca4eSAnika Henke        <th colspan="2">
8054da078a3Smatthiasgrimm          <?php echo $left?>
806daf4ca4eSAnika Henke        </th>
807daf4ca4eSAnika Henke        <th colspan="2">
8084da078a3Smatthiasgrimm          <?php echo $right?>
809daf4ca4eSAnika Henke        </th>
810f3f0262cSandi      </tr>
8114da078a3Smatthiasgrimm      <?php echo $tdf->format($df)?>
812f3f0262cSandi    </table>
8134da078a3Smatthiasgrimm  <?php
814f3f0262cSandi}
815f3f0262cSandi
81615fae107Sandi/**
81715fae107Sandi * show warning on conflict detection
81815fae107Sandi *
81915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
82015fae107Sandi */
821f3f0262cSandifunction html_conflict($text,$summary){
822f3f0262cSandi  global $ID;
823f3f0262cSandi  global $lang;
824f3f0262cSandi
825c112d578Sandi  print p_locale_xhtml('conflict');
826f3f0262cSandi  ?>
8271dd0c202SAnika Henke  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
82896331712SAnika Henke  <div class="centeralign">
8294da078a3Smatthiasgrimm    <input type="hidden" name="id" value="<?php echo $ID?>" />
8304da078a3Smatthiasgrimm    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
8314da078a3Smatthiasgrimm    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
832f3f0262cSandi
8334da078a3Smatthiasgrimm    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
8344da078a3Smatthiasgrimm    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" />
835f3f0262cSandi  </div>
836f3f0262cSandi  </form>
837f3f0262cSandi  <br /><br /><br /><br />
8384da078a3Smatthiasgrimm  <?php
839f3f0262cSandi}
840f3f0262cSandi
841f3f0262cSandi/**
84215fae107Sandi * Prints the global message array
84315fae107Sandi *
84415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
845f3f0262cSandi */
846f3f0262cSandifunction html_msgarea(){
847f3f0262cSandi  global $MSG;
848f3f0262cSandi
849f3f0262cSandi  if(!isset($MSG)) return;
850f3f0262cSandi
851f3f0262cSandi  foreach($MSG as $msg){
852f3f0262cSandi    print '<div class="'.$msg['lvl'].'">';
853f3f0262cSandi    print $msg['msg'];
854f3f0262cSandi    print '</div>';
855f3f0262cSandi  }
856f3f0262cSandi}
857f3f0262cSandi
858f3f0262cSandi/**
859f3f0262cSandi * Prints the registration form
86015fae107Sandi *
86115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
862f3f0262cSandi */
863f3f0262cSandifunction html_register(){
864f3f0262cSandi  global $lang;
865cab2716aSmatthias.grimm  global $conf;
866f3f0262cSandi  global $ID;
867f3f0262cSandi
868c112d578Sandi  print p_locale_xhtml('register');
869f3f0262cSandi?>
87096331712SAnika Henke  <div class="centeralign">
8711dd0c202SAnika Henke  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
87296331712SAnika Henke  <fieldset>
873f3f0262cSandi    <input type="hidden" name="do" value="register" />
874f3f0262cSandi    <input type="hidden" name="save" value="1" />
87596331712SAnika Henke
8764da078a3Smatthiasgrimm    <legend><?php echo $lang['register']?></legend>
877b6912aeaSAndreas Gohr    <label class="block">
8784da078a3Smatthiasgrimm      <?php echo $lang['user']?>
8794da078a3Smatthiasgrimm      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
880f3f0262cSandi    </label><br />
881cab2716aSmatthias.grimm
882cab2716aSmatthias.grimm    <?php
883cab2716aSmatthias.grimm      if (!$conf['autopasswd']) {
884cab2716aSmatthias.grimm    ?>
885b6912aeaSAndreas Gohr      <label class="block">
8864da078a3Smatthiasgrimm        <?php echo $lang['pass']?>
887cab2716aSmatthias.grimm        <input type="password" name="pass" class="edit" size="50" />
888cab2716aSmatthias.grimm      </label><br />
889b6912aeaSAndreas Gohr      <label class="block">
8904da078a3Smatthiasgrimm        <?php echo $lang['passchk']?>
891cab2716aSmatthias.grimm        <input type="password" name="passchk" class="edit" size="50" />
892cab2716aSmatthias.grimm      </label><br />
893cab2716aSmatthias.grimm    <?php
894cab2716aSmatthias.grimm      }
895cab2716aSmatthias.grimm    ?>
896cab2716aSmatthias.grimm
897b6912aeaSAndreas Gohr    <label class="block">
8984da078a3Smatthiasgrimm      <?php echo $lang['fullname']?>
8994da078a3Smatthiasgrimm      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
900f3f0262cSandi    </label><br />
901b6912aeaSAndreas Gohr    <label class="block">
9024da078a3Smatthiasgrimm      <?php echo $lang['email']?>
9034da078a3Smatthiasgrimm      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
904f3f0262cSandi    </label><br />
9054da078a3Smatthiasgrimm    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
906f3f0262cSandi  </fieldset>
907f3f0262cSandi  </form>
908f3f0262cSandi  </div>
9094da078a3Smatthiasgrimm<?php
910f3f0262cSandi}
911f3f0262cSandi
912f3f0262cSandi/**
9138b06d178Schris * Print the update profile form
9148b06d178Schris *
9158b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
9168b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
9178b06d178Schris */
9188b06d178Schrisfunction html_updateprofile(){
9198b06d178Schris  global $lang;
9208b06d178Schris  global $conf;
9218b06d178Schris  global $ID;
9228b06d178Schris  global $INFO;
92382fd59b6SAndreas Gohr  global $auth;
9248b06d178Schris
9258b06d178Schris  print p_locale_xhtml('updateprofile');
9268b06d178Schris
9278b06d178Schris  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
9288b06d178Schris  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
9298b06d178Schris?>
93096331712SAnika Henke  <div class="centeralign">
9311dd0c202SAnika Henke  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
93296331712SAnika Henke  <fieldset style="width: 80%;">
9338b06d178Schris    <input type="hidden" name="do" value="profile" />
9348b06d178Schris    <input type="hidden" name="save" value="1" />
93596331712SAnika Henke
9368b06d178Schris    <legend><?php echo $lang['profile']?></legend>
9378b06d178Schris    <label class="block">
9388b06d178Schris      <?php echo $lang['user']?>
9398b06d178Schris      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
9408b06d178Schris    </label><br />
9418b06d178Schris    <label class="block">
9428b06d178Schris      <?php echo $lang['fullname']?>
94382fd59b6SAndreas Gohr      <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
9448b06d178Schris    </label><br />
9458b06d178Schris    <label class="block">
9468b06d178Schris      <?php echo $lang['email']?>
94782fd59b6SAndreas Gohr      <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
9488b06d178Schris    </label><br /><br />
94982fd59b6SAndreas Gohr
95082fd59b6SAndreas Gohr    <?php if($auth->canDo('modPass')) { ?>
9518b06d178Schris    <label class="block">
9528b06d178Schris      <?php echo $lang['newpass']?>
9538b06d178Schris      <input type="password" name="newpass" class="edit" size="50" />
9548b06d178Schris    </label><br />
9558b06d178Schris    <label class="block">
9568b06d178Schris      <?php echo $lang['passchk']?>
9578b06d178Schris      <input type="password" name="passchk" class="edit" size="50" />
9588b06d178Schris    </label><br />
95982fd59b6SAndreas Gohr    <?php } ?>
9608b06d178Schris
9618b06d178Schris    <?php if ($conf['profileconfirm']) { ?>
9628b06d178Schris      <br />
9638b06d178Schris      <label class="block">
9648b06d178Schris      <?php echo $lang['oldpass']?>
9658b06d178Schris      <input type="password" name="oldpass" class="edit" size="50" />
9668b06d178Schris    </label><br />
9678b06d178Schris    <?php } ?>
9688b06d178Schris
9694cb79657SMatthias Grimm    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
9708b06d178Schris    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
9718b06d178Schris  </fieldset>
9728b06d178Schris  </form>
9738b06d178Schris  </div>
9748b06d178Schris<?php
9758b06d178Schris}
9768b06d178Schris
9778b06d178Schris/**
978f3f0262cSandi * This displays the edit form (lots of logic included)
97915fae107Sandi *
9807146cee2SAndreas Gohr * @fixme  this is a huge lump of code and should be modularized
98115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
982f3f0262cSandi */
983f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
984f3f0262cSandi  global $ID;
985f3f0262cSandi  global $REV;
986f3f0262cSandi  global $DATE;
987f3f0262cSandi  global $RANGE;
988f3f0262cSandi  global $PRE;
989f3f0262cSandi  global $SUF;
990f3f0262cSandi  global $INFO;
991f3f0262cSandi  global $SUM;
992f3f0262cSandi  global $lang;
993f3f0262cSandi  global $conf;
994f3f0262cSandi
995f3f0262cSandi  //set summary default
996f3f0262cSandi  if(!$SUM){
997f3f0262cSandi    if($REV){
998f3f0262cSandi      $SUM = $lang['restored'];
999f3f0262cSandi    }elseif(!$INFO['exists']){
1000f3f0262cSandi      $SUM = $lang['created'];
1001f3f0262cSandi    }
1002f3f0262cSandi  }
1003f3f0262cSandi
1004f3f0262cSandi  //no text? Load it!
1005f3f0262cSandi  if(!isset($text)){
1006f3f0262cSandi    $pr = false; //no preview mode
10077146cee2SAndreas Gohr    if($INFO['exists']){
1008f3f0262cSandi      if($RANGE){
1009f3f0262cSandi        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1010f3f0262cSandi      }else{
1011f3f0262cSandi        $text = rawWiki($ID,$REV);
1012f3f0262cSandi      }
1013f3f0262cSandi    }else{
10147146cee2SAndreas Gohr      //try to load a pagetemplate
10157146cee2SAndreas Gohr      $text = pageTemplate($ID);
10167146cee2SAndreas Gohr    }
10177146cee2SAndreas Gohr  }else{
1018f3f0262cSandi    $pr = true; //preview mode
1019f3f0262cSandi  }
1020f3f0262cSandi
1021f3f0262cSandi  $wr = $INFO['writable'];
1022f3f0262cSandi  if($wr){
1023c112d578Sandi    if ($REV) print p_locale_xhtml('editrev');
1024c112d578Sandi    print p_locale_xhtml($include);
1025f3f0262cSandi  }else{
1026c112d578Sandi    print p_locale_xhtml('read');
1027f3f0262cSandi    $ro='readonly="readonly"';
1028f3f0262cSandi  }
1029f3f0262cSandi  if(!$DATE) $DATE = $INFO['lastmod'];
1030dc57ef04Sandi
1031dc57ef04Sandi
1032f3f0262cSandi?>
103363afe2a6SAnika Henke  <div style="width:99%;">
103463afe2a6SAnika Henke  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">
103563afe2a6SAnika Henke     <div class="toolbar">
1036*ee4c4a1bSAndreas Gohr        <div id="draft__status"><?php if($INFO['draft']) echo $lang['draftdate'].' '.date($conf['dformat']);?></div>
103724a33b42SAndreas Gohr        <div id="tool__bar"></div>
10384da078a3Smatthiasgrimm        <input type="hidden" name="id"   value="<?php echo $ID?>" />
10394da078a3Smatthiasgrimm        <input type="hidden" name="rev"  value="<?php echo $REV?>" />
10404da078a3Smatthiasgrimm        <input type="hidden" name="date" value="<?php echo $DATE?>" />
10414da078a3Smatthiasgrimm        <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
10424da078a3Smatthiasgrimm        <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
104320d062caSAndreas Gohr
10444da078a3Smatthiasgrimm        <?php if($wr){?>
10454beabca9SAnika Henke        <script type="text/javascript" charset="utf-8">
10464da078a3Smatthiasgrimm          <?php /* sets changed to true when previewed */?>
10474da078a3Smatthiasgrimm          textChanged = <?php ($pr) ? print 'true' : print 'false' ?>;
1048f3f0262cSandi        </script>
104924a33b42SAndreas Gohr        <span id="spell__action"></span>
105024a33b42SAndreas Gohr        <div id="spell__suggest"></div>
1051*ee4c4a1bSAndreas Gohr        <?php } ?>
105263afe2a6SAnika Henke    </div>
105324a33b42SAndreas Gohr    <div id="spell__result"></div>
105463afe2a6SAnika Henke
105524a33b42SAndreas Gohr    <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
105663afe2a6SAnika Henke
105724a33b42SAndreas Gohr    <div id="wiki__editbar">
105824a33b42SAndreas Gohr      <div id="size__ctl"></div>
10594da078a3Smatthiasgrimm      <?php if($wr){?>
1060fa24fadbSAnika Henke         <div class="editButtons">
106124a33b42SAndreas Gohr            <input class="button" id="edbtn__save" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" tabindex="4" />
106224a33b42SAndreas Gohr            <input class="button" id="edbtn__preview" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" tabindex="5" />
1063*ee4c4a1bSAndreas Gohr            <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="5" />
1064fa24fadbSAnika Henke         </div>
10654da078a3Smatthiasgrimm      <?php } ?>
10664da078a3Smatthiasgrimm      <?php if($wr){ ?>
1067fa24fadbSAnika Henke        <div class="summary">
106824a33b42SAndreas Gohr           <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label>
106924a33b42SAndreas Gohr           <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1070b6912aeaSAndreas Gohr           <?php html_minoredit()?>
1071fa24fadbSAnika Henke        </div>
10724da078a3Smatthiasgrimm      <?php }?>
107363afe2a6SAnika Henke    </div>
107463afe2a6SAnika Henke  </div></form>
107563afe2a6SAnika Henke  </div>
10764da078a3Smatthiasgrimm<?php
1077f3f0262cSandi}
1078f3f0262cSandi
1079f3f0262cSandi/**
1080b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1081b6912aeaSAndreas Gohr *
1082b6912aeaSAndreas Gohr * @author Andrea Gohr <andi@splitbrain.org>
1083b6912aeaSAndreas Gohr */
1084b6912aeaSAndreas Gohrfunction html_minoredit(){
1085b6912aeaSAndreas Gohr  global $conf;
1086b6912aeaSAndreas Gohr  global $lang;
1087b6912aeaSAndreas Gohr  // minor edits are for logged in users only
1088b6912aeaSAndreas Gohr  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1089b6912aeaSAndreas Gohr    return;
1090b6912aeaSAndreas Gohr  }
1091b6912aeaSAndreas Gohr
1092b6912aeaSAndreas Gohr  $p = array();
1093b6912aeaSAndreas Gohr  $p['name']     = 'minor';
1094b6912aeaSAndreas Gohr  $p['type']     = 'checkbox';
1095b6912aeaSAndreas Gohr  $p['id']       = 'minoredit';
1096b6912aeaSAndreas Gohr  $p['tabindex'] = 3;
1097b6912aeaSAndreas Gohr  $p['value']    = '1';
1098b6912aeaSAndreas Gohr  if($_REQUEST['minor']) $p['checked']='checked';
1099b6912aeaSAndreas Gohr  $att = buildAttributes($p);
1100b6912aeaSAndreas Gohr
1101fa24fadbSAnika Henke  print '<span class="nowrap">';
1102b6912aeaSAndreas Gohr  print "<input $att />";
1103b6912aeaSAndreas Gohr  print '<label for="minoredit">';
1104b6912aeaSAndreas Gohr  print $lang['minoredit'];
1105b6912aeaSAndreas Gohr  print '</label>';
1106fa24fadbSAnika Henke  print '</span>';
1107b6912aeaSAndreas Gohr}
1108b6912aeaSAndreas Gohr
1109b6912aeaSAndreas Gohr/**
1110f3f0262cSandi * prints some debug info
111115fae107Sandi *
111215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1113f3f0262cSandi */
1114f3f0262cSandifunction html_debug(){
1115f3f0262cSandi  global $conf;
1116d16a4edaSandi  global $lang;
11175298a619SAndreas Gohr  global $auth;
111828fb55ffSandi  //remove sensitive data
111928fb55ffSandi  $cnf = $conf;
112028fb55ffSandi  $cnf['auth']='***';
112128fb55ffSandi  $cnf['notify']='***';
11223dc3a5f1Sandi  $cnf['ftp']='***';
1123f3f0262cSandi
1124f3f0262cSandi  print '<html><body>';
1125f3f0262cSandi
1126f3f0262cSandi  print '<p>When reporting bugs please send all the following ';
1127f3f0262cSandi  print 'output as a mail to andi@splitbrain.org ';
1128f3f0262cSandi  print 'The best way to do this is to save this page in your browser</p>';
1129f3f0262cSandi
1130f3f0262cSandi  print '<b>$_SERVER:</b><pre>';
1131f3f0262cSandi  print_r($_SERVER);
1132f3f0262cSandi  print '</pre>';
1133f3f0262cSandi
1134f3f0262cSandi  print '<b>$conf:</b><pre>';
113528fb55ffSandi  print_r($cnf);
1136f3f0262cSandi  print '</pre>';
1137f3f0262cSandi
1138ed7b5f09Sandi  print '<b>DOKU_BASE:</b><pre>';
1139ed7b5f09Sandi  print DOKU_BASE;
1140f3f0262cSandi  print '</pre>';
1141f3f0262cSandi
1142ed7b5f09Sandi  print '<b>abs DOKU_BASE:</b><pre>';
1143ed7b5f09Sandi  print DOKU_URL;
1144ed7b5f09Sandi  print '</pre>';
1145ed7b5f09Sandi
1146ed7b5f09Sandi  print '<b>rel DOKU_BASE:</b><pre>';
1147f3f0262cSandi  print dirname($_SERVER['PHP_SELF']).'/';
1148f3f0262cSandi  print '</pre>';
1149f3f0262cSandi
1150f3f0262cSandi  print '<b>PHP Version:</b><pre>';
1151f3f0262cSandi  print phpversion();
1152f3f0262cSandi  print '</pre>';
1153f3f0262cSandi
1154f3f0262cSandi  print '<b>locale:</b><pre>';
1155f3f0262cSandi  print setlocale(LC_ALL,0);
1156f3f0262cSandi  print '</pre>';
1157f3f0262cSandi
1158d16a4edaSandi  print '<b>encoding:</b><pre>';
1159d16a4edaSandi  print $lang['encoding'];
1160d16a4edaSandi  print '</pre>';
1161d16a4edaSandi
11625298a619SAndreas Gohr  if($auth){
11635298a619SAndreas Gohr    print '<b>Auth backend capabilities:</b><pre>';
11645298a619SAndreas Gohr    print_r($auth->cando);
11655298a619SAndreas Gohr    print '</pre>';
11665298a619SAndreas Gohr  }
11675298a619SAndreas Gohr
11683aa54d7cSAndreas Gohr  print '<b>$_SESSION:</b><pre>';
11693aa54d7cSAndreas Gohr  print_r($_SESSION);
11703aa54d7cSAndreas Gohr  print '</pre>';
11713aa54d7cSAndreas Gohr
1172f3f0262cSandi  print '<b>Environment:</b><pre>';
1173f3f0262cSandi  print_r($_ENV);
1174f3f0262cSandi  print '</pre>';
1175f3f0262cSandi
1176f3f0262cSandi  print '<b>PHP settings:</b><pre>';
1177f3f0262cSandi  $inis = ini_get_all();
1178f3f0262cSandi  print_r($inis);
1179f3f0262cSandi  print '</pre>';
1180f3f0262cSandi
1181f3f0262cSandi  print '</body></html>';
1182f3f0262cSandi}
1183f3f0262cSandi
1184c19fe9c0Sandifunction html_admin(){
1185c19fe9c0Sandi  global $ID;
1186c19fe9c0Sandi  global $lang;
1187ca3a6df1SMatthias Grimm  global $conf;
1188c19fe9c0Sandi
1189c112d578Sandi  print p_locale_xhtml('admin');
1190c19fe9c0Sandi
119111e2ce22Schris  // build menu of admin functions from the plugins that handle them
119211e2ce22Schris  $pluginlist = plugin_list('admin');
119311e2ce22Schris  $menu = array();
119411e2ce22Schris  foreach ($pluginlist as $p) {
119511e2ce22Schris    if($obj =& plugin_load('admin',$p) === NULL) continue;
119611e2ce22Schris    $menu[] = array('plugin' => $p,
119711e2ce22Schris                    'prompt' => $obj->getMenuText($conf['lang']),
119811e2ce22Schris                    'sort' => $obj->getMenuSort()
119911e2ce22Schris                   );
120011e2ce22Schris  }
120111e2ce22Schris
120211e2ce22Schris  usort($menu, p_sort_modes);
120311e2ce22Schris
120411e2ce22Schris  // output the menu
120511e2ce22Schris  ptln('<ul>');
120611e2ce22Schris
120711e2ce22Schris  foreach ($menu as $item) {
120811e2ce22Schris    if (!$item['prompt']) continue;
12090c6b58a8SAndreas Gohr    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
121011e2ce22Schris  }
121111e2ce22Schris
121211e2ce22Schris  // add in non-plugin functions
121311e2ce22Schris  if (!$conf['openregister']){
12140c6b58a8SAndreas Gohr    ptln('<li><div class="li"><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></div></li>');
121511e2ce22Schris  }
121611e2ce22Schris
121711e2ce22Schris  ptln('</ul>');
1218ca3a6df1SMatthias Grimm}
1219c19fe9c0Sandi
12208b06d178Schris/**
12218b06d178Schris * Form to request a new password for an existing account
12228b06d178Schris *
12238b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
122411e2ce22Schris */
12258b06d178Schrisfunction html_resendpwd() {
12268b06d178Schris  global $lang;
12278b06d178Schris  global $conf;
12288b06d178Schris  global $ID;
1229c19fe9c0Sandi
12308b06d178Schris  print p_locale_xhtml('resendpwd');
12318b06d178Schris?>
123296331712SAnika Henke  <div class="centeralign">
12331dd0c202SAnika Henke  <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
12348b06d178Schris    <fieldset>
12358b06d178Schris      <br />
1236753d5abfSMatthias Grimm      <legend><?php echo $lang['resendpwd']?></legend>
12378b06d178Schris      <input type="hidden" name="do" value="resendpwd" />
12388b06d178Schris      <input type="hidden" name="save" value="1" />
12398b06d178Schris      <label class="block">
12408b06d178Schris        <span><?php echo $lang['user']?></span>
12418b06d178Schris        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
12428b06d178Schris      </label><br />
12438b06d178Schris      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
12448b06d178Schris    </fieldset>
12458b06d178Schris  </form>
12468b06d178Schris  </div>
12478b06d178Schris<?php
12488b06d178Schris}
1249340756e4Sandi
1250340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1251