Skip to content
Snippets Groups Projects
html.php 25.5 KiB
Newer Older
andi's avatar
andi committed
/**
 * HTML output functions
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Andreas Gohr <andi@splitbrain.org>
 */

  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
andi's avatar
andi committed

andi's avatar
andi committed
  require_once(DOKU_INC.'inc/parserutils.php');

andi's avatar
andi committed
/**
 * Convenience function to quickly build a wikilink
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_wikilink($url,$name='',$search=''){
  global $conf;
  $link         = array();
  $link['url']  = $url;
  $link['name'] = $name;
  $link         = format_link_wiki($link);

  if($search){
    ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
    $link['url'] .= urlencode($search);
  }

  return format_link_build($link);
}

/**
 * Helps building long attribute lists
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function html_attbuild($attributes){
  $ret = '';
  foreach ( $attributes as $key => $value ) {
    $ret .= $key.'="'.formtext($value).'" ';
  }
  return trim($ret);
}

andi's avatar
andi committed
/**
 * The loginform
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_login(){
  global $lang;
  global $conf;
  global $ID;

  print p_locale_xhtml('login');
andi's avatar
andi committed
  ?>
    <div align="center">
    <form action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" method="post">
      <fieldset>
        <legend><?=$lang['btn_login']?></legend>
        <input type="hidden" name="id" value="<?=$ID?>" />
        <input type="hidden" name="do" value="login" />
        <label>
          <span><?=$lang['user']?></span>
          <input type="text" name="u" value="<?=formText($_REQUEST['u'])?>" class="edit" />
        </label><br />
        <label>
          <span><?=$lang['pass']?></span>
          <input type="password" name="p" class="edit" />
        </label><br />
        <input type="submit" value="<?=$lang['btn_login']?>" class="button" />
andi's avatar
andi committed
        <label for="remember" class="simple">
          <input type="checkbox" name="r" id="remember" value="1" />
          <span><?=$lang['remember']?></span>
        </label>
andi's avatar
andi committed
      </fieldset>
    </form>
  <?
    if($conf['openregister']){
      print '<p>';
      print $lang['reghere'];
      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
      print '</p>';
    }
  ?>
    </div>
  <?
andi's avatar
andi committed
/*
 FIXME provide new hook
andi's avatar
andi committed
  if(@file_exists('includes/login.txt')){
    print io_cacheParse('includes/login.txt');
  }
andi's avatar
andi committed
*/
andi's avatar
andi committed
}

/**
 * shows the edit/source/show button dependent on current mode
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_editbutton(){
  global $ID;
  global $REV;
  global $ACT;
  global $INFO;

  if($ACT == 'show' || $ACT == 'search'){
    if($INFO['writable']){
      if($INFO['exists']){
        $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
      }else{
        $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
      }
    }else{
      $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
    }
  }else{
    $r = html_btn('show',$ID,'v',array('do' => 'show'));
  }
  return $r;
}

andi's avatar
andi committed
/**
 * prints a section editing button
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_secedit_button($section,$p){
  global $ID;
  global $lang;
  $secedit  = '';
  if($p) $secedit .= "</p>\n";
  $secedit .= '<div class="secedit">';
  $secedit .= html_btn('secedit',$ID,'',
                        array('do'      => 'edit',
                              'lines'   => "$section"),
                              'post');
  $secedit .= '</div>';
  if($p) $secedit .= "\n<p>";
  return $secedit;
}

andi's avatar
andi committed
/**
 * inserts section edit buttons if wanted or removes the markers
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_secedit($text,$show=true){
  global $INFO;
  if($INFO['writable'] && $show && !$INFO['rev']){
andi's avatar
andi committed
    $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
                         "html_secedit_button('\\1',true)",
                         $text);
    $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
                         "html_secedit_button('\\1',false)",
                         $text);
  }else{
    $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
  }
  $text = preg_replace('@<p>\s*</p>@', '', $text);
andi's avatar
andi committed
  return $text;
}

/**
 * Just the back to top button (in it's own form)
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function html_topbtn(){
  global $lang;

  $ret  = '';
  $ret .= '<form class="button" method="get" action="#top" onsubmit="return svchk()">';
andi's avatar
andi committed
  $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_top']).'" class="button" />';
  $ret .= '</form>';
  return $ret;
}

andi's avatar
andi committed
/**
 * Displays a button (using it's own form)
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_btn($name,$id,$akey,$params,$method='get'){
  global $conf;
  global $lang;
  
  $label = $lang['btn_'.$name];
  
  $ret = '';

  //filter id (without urlencoding)
  $id = idfilter($id,false);
andi's avatar
andi committed

  //make nice URLs even for buttons  
  if(!$conf['userewrite']){
andi's avatar
andi committed
    $script = DOKU_BASE.DOKU_SCRIPT;
andi's avatar
andi committed
    $params['id'] = $id;
  }else{
    $script = DOKU_BASE.$id;
andi's avatar
andi committed
  }
  
  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'" onsubmit="return svchk()">';
  
  reset($params);
  while (list($key, $val) = each($params)) {
    $ret .= '<input type="hidden" name="'.$key.'" ';
    $ret .= 'value="'.htmlspecialchars($val).'" />';
  }
  
  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
  if($akey){
    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
    $ret .= 'accesskey="'.$akey.'" ';
  }
  $ret .= '/>';
  $ret .= '</form>';

  return $ret;
}

andi's avatar
andi committed
/**
 * Print the table of contents
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_toc($toc){
  global $lang;
  $ret  = '';
  $ret .= '<div class="toc">';
  $ret .=   '<div class="tocheader">';
  $ret .=      $lang['toc'];
  $ret .=     ' <script type="text/javascript">';
  $ret .=     'showTocToggle("+","-")';
  $ret .=     '</script>';
  $ret .=   '</div>';
  $ret .=   '<div id="tocinside">';
  $ret .=   html_buildlist($toc,'toc','html_list_toc');
  $ret .=   '</div>';
  $ret .= '</div>';
  return $ret;
}

/**
andi's avatar
andi committed
 * TOC item formatter
 *
andi's avatar
andi committed
 * User function for html_buildlist()
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_list_toc($item){
  $ret  = '';
  $ret .= '<a href="#'.$item['id'].'" class="toc">';
  $ret .= $item['name'];
  $ret .= '</a>';
  return $ret;
}

andi's avatar
andi committed
/**
 * show a wiki page
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_show($txt=''){
andi's avatar
andi committed
  global $ID;
  global $REV;
  global $HIGH;
  //disable section editing for old revisions or in preview
  if($text || $REV){
andi's avatar
andi committed
    $secedit = false;
  }else{
    $secedit = true;
andi's avatar
andi committed
  }
andi's avatar
andi committed
  
  if ($txt){
andi's avatar
andi committed
    //PreviewHeader
    print p_locale_xhtml('preview');
andi's avatar
andi committed
    print '<div class="preview">';
andi's avatar
andi committed
    print html_secedit(p_render_xhtml(p_get_instructions($txt)),$secedit);
andi's avatar
andi committed
    print '</div>';
andi's avatar
andi committed

andi's avatar
andi committed
  }else{
    if ($REV) print p_locale_xhtml('showrev');
    $html = p_wiki_xhtml($ID,$REV,true);
andi's avatar
andi committed
    $html = html_secedit($html,$secedit);
andi's avatar
andi committed
    print html_hilight($html,$HIGH);
  }
}

/**
 * Highlights searchqueries in HTML code
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_hilight($html,$query){
  $queries = preg_split ("/\s/",$query,-1,PREG_SPLIT_NO_EMPTY);
  foreach ($queries as $q){
    $q = preg_quote($q,'/');
    $html = preg_replace("/((<[^>]*)|$q)/ie", '"\2"=="\1"? "\1":"<span class=\"search_hit\">\1</span>"', $html);
  }
  return $html;
}

/**
andi's avatar
andi committed
 * Run a search and display the result
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_search(){
  require_once(DOKU_INC.'inc/search.php');
andi's avatar
andi committed
  global $conf;
  global $QUERY;
  global $ID;
  global $lang;

  print p_locale_xhtml('searchpage');
andi's avatar
andi committed
  flush();

andi's avatar
andi committed
  //show progressbar
  print '<div align="center">';
  print '<script language="JavaScript" type="text/javascript">';
  print 'showLoadBar();';
  print '</script>';
  print '<br /></div>';

andi's avatar
andi committed
  //do quick pagesearch
  $data = array();
andi's avatar
andi committed
  search($data,$conf['datadir'],'search_pagename',array(query => cleanID($QUERY)));
andi's avatar
andi committed
  if(count($data)){
    sort($data);
    print '<div class="search_quickresult">';
    print '<b>'.$lang[quickhits].':</b><br />';
    foreach($data as $row){
      print '<div class="search_quickhits">';
      print html_wikilink(':'.$row['id'],$row['id']);
      print '</div> ';
    }
    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
    print '<div class="clearer">&nbsp;</div>';
    print '</div>';
  }
  flush();

  //do fulltext search
  $data = array();
andi's avatar
andi committed
  search($data,$conf['datadir'],'search_fulltext',array(query => utf8_strtolower($QUERY)));
andi's avatar
andi committed
  if(count($data)){
    usort($data,'sort_search_fulltext');
    foreach($data as $row){
      print '<div class="search_result">';
      print html_wikilink(':'.$row['id'],$row['id'],$QUERY);
      print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
      print '<div class="search_snippet">'.$row['snippet'].'</div>';
      print '</div>';
    }
  }else{
    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
andi's avatar
andi committed
  }
andi's avatar
andi committed

  //hide progressbar
  print '<script language="JavaScript" type="text/javascript">';
  print 'hideLoadBar();';
  print '</script>';
andi's avatar
andi committed
}

andi's avatar
andi committed
/**
 * Display error on locked pages
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_locked($ip){
  global $ID;
  global $conf;
  global $lang;
  
  $locktime = filemtime(wikiFN($ID).'.lock');
  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);

  print p_locale_xhtml('locked');
andi's avatar
andi committed
  print '<ul>';
  print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>';
  print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>';
  print '</ul>';
}

andi's avatar
andi committed
/**
 * list old revisions
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_revisions(){
  global $ID;
  global $INFO;
  global $conf;
  global $lang;
  $revisions = getRevisions($ID); 
  $date = @date($conf['dformat'],$INFO['lastmod']);
  
  print p_locale_xhtml('revisions');
andi's avatar
andi committed
  print '<ul>';
  if($INFO['exists']){
andi's avatar
andi committed
    print '<li>';
    print $date.' <a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';

    print $INFO['sum'];
    print ' <span class="user">(';
    print $INFO['ip'];
    if($INFO['user']) print ' '.$INFO['user'];
    print ')</span> ';

    print '('.$lang['current'].')';
    print '</li>';
andi's avatar
andi committed
  }

  foreach($revisions as $rev){
    $date = date($conf['dformat'],$rev);
andi's avatar
andi committed
    $info = getRevisionInfo($ID,$rev);

andi's avatar
andi committed
    print '<li>';
    print $date.' <a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
andi's avatar
andi committed
    print $info['sum'];
    print ' <span class="user">(';
    print $info['ip'];
    if($info['user']) print ' '.$info['user'];
    print ')</span> ';

    print '<a href="'.wl($ID,"rev=$rev,do=diff").'">';
    print '<img src="'.DOKU_BASE.'images/diff.png" border="0" width="15" height="11" title="'.$lang['diff'].'" />';
andi's avatar
andi committed
    print '</a>';
andi's avatar
andi committed
    print '</li>';
  }
  print '</ul>';
}

andi's avatar
andi committed
/**
 * display recent changes
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_recent(){
  global $conf;
  $recents = getRecents(0,true);

  print p_locale_xhtml('recent');
andi's avatar
andi committed
  print '<ul>';
  foreach(array_keys($recents) as $id){
    $date = date($conf['dformat'],$recents[$id]['date']);
    print '<li>';
    print $date.' '.html_wikilink($id,$id);
    print ' '.htmlspecialchars($recents[$id]['sum']);
    print ' <span class="user">(';
    print $recents[$id]['ip'];
    if($recents[$id]['user']) print ' '.$recents[$id]['user'];
    print ')</span>';
    print '</li>';
  }
  print '</ul>';
}

andi's avatar
andi committed
/**
 * Display page index
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_index($ns){
  require_once(DOKU_INC.'inc/search.php');
andi's avatar
andi committed
  global $conf;
  global $ID;
  $dir = $conf['datadir'];
  $ns  = cleanID($ns);
  if(empty($ns)){
    $ns = dirname(str_replace(':','/',$ID));
    if($ns == '.') $ns ='';
  }
  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
andi's avatar
andi committed

  print p_locale_xhtml('index');
andi's avatar
andi committed

  $data = array();
  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
andi's avatar
andi committed
  print html_buildlist($data,'idx','html_list_index','html_li_index');
andi's avatar
andi committed
}

/**
andi's avatar
andi committed
 * Index item formatter
 *
andi's avatar
andi committed
 * User function for html_buildlist()
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_list_index($item){
  $ret = '';
  $base = ':'.$item['id'];
  $base = substr($base,strrpos($base,':')+1);
  if($item['type']=='d'){
    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
    $ret .= $base;
    $ret .= '</a>';
  }else{
    $ret .= html_wikilink(':'.$item['id']);
  }
  return $ret;
}

andi's avatar
andi committed
/**
 * Index List item
 *
 * This user function is used in html_build_lidt to build the
 * <li> tags for namespaces when displaying the page index
 * it gives different classes to opened or closed "folders"
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function html_li_index($item){
  if($item['type'] == "f"){
    return '<li class="level'.$item['level'].'">';
  }elseif($item['open']){
    return '<li class="open">';
  }else{
    return '<li class="closed">';
  }
}

/**
 * Default List item
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function html_li_default($item){
  return '<li class="level'.$item['level'].'">';
}

andi's avatar
andi committed
/**
andi's avatar
andi committed
 * Build an unordered list
 *
andi's avatar
andi committed
 * Build an unordered list from the given $data array
 * Each item in the array has to have a 'level' property
 * the item itself gets printed by the given $func user
andi's avatar
andi committed
 * function. The second and optional function is used to
 * print the <li> tag. Both user function need to accept
 * a single item.
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
andi's avatar
andi committed
function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
andi's avatar
andi committed
  $level = 0;
  $opens = 0;
  $ret   = '';

  foreach ($data as $item){

    if( $item['level'] > $level ){
      //open new list
andi's avatar
andi committed
      for($i=0; $i<($item['level'] - $level); $i++){
        if ($i) $ret .= "<li class=\"clear\">\n";
        $ret .= "\n<ul class=\"$class\">\n";
      }
andi's avatar
andi committed
    }elseif( $item['level'] < $level ){
      //close last item
      $ret .= "</li>\n";
      for ($i=0; $i<($level - $item['level']); $i++){
        //close higher lists
        $ret .= "</ul>\n</li>\n";
      }
    }else{
      //close last item
      $ret .= "</li>\n";
    }

    //remember current level 
    $level = $item['level'];

    //print item
andi's avatar
andi committed
    $ret .= $lifunc($item); //user function
andi's avatar
andi committed
    $ret .= '<span class="li">';
    $ret .= $func($item); //user function
    $ret .= '</span>';
  }

  //close remaining items and lists
  for ($i=0; $i < $level; $i++){
    $ret .= "</li></ul>\n";
  }

  return $ret;
}

andi's avatar
andi committed
/**
 * display backlinks
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_backlinks(){
  require_once(DOKU_INC.'inc/search.php');
andi's avatar
andi committed
  global $ID;
  global $conf;

  if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
    $opts['ns']   = $matches[1];
    $opts['name'] = $matches[2];
  }else{
    $opts['ns']   = '';
    $opts['name'] = $ID;
  }

  print p_locale_xhtml('backlinks');
andi's avatar
andi committed

  $data = array();
  search($data,$conf['datadir'],'search_backlinks',$opts);
  sort($data);

  print '<ul class="idx">';
  foreach($data as $row){
    print '<li>';
    print html_wikilink(':'.$row['id'],$row['id']);
    print '</li>';
  }
  print '</ul>';
}

andi's avatar
andi committed
/**
 * show diff
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_diff($text='',$intro=true){
  require_once(DOKU_INC.'inc/DifferenceEngine.php');
andi's avatar
andi committed
  global $ID;
  global $REV;
  global $lang;
  global $conf;
  if($text){
    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
                    split("\n",htmlspecialchars(cleanText($text))));
    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
              $lang['current'];
    $right = $lang['yours'];
  }else{
    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$REV))),
                    split("\n",htmlspecialchars(rawWiki($ID,''))));
    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$REV").'">'.
              $ID.' '.date($conf['dformat'],$REV).'</a>';
    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
              $lang['current'];
  }
  $tdf = new TableDiffFormatter();
  if($intro) print p_locale_xhtml('diff');
andi's avatar
andi committed
  ?>
    <table class="diff" width="100%">
      <tr>
        <td colspan="2" width="50%" class="diff-header">
          <?=$left?>
        </td>
        <td colspan="2" width="50%" class="diff-header">
          <?=$right?>
        </td>
      </tr>
      <?=$tdf->format($df)?>
    </table>
  <?
}

andi's avatar
andi committed
/**
 * show warning on conflict detection
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
andi's avatar
andi committed
function html_conflict($text,$summary){
  global $ID;
  global $lang;

  print p_locale_xhtml('conflict');
andi's avatar
andi committed
  ?>
  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
  <input type="hidden" name="id" value="<?=$ID?>" />
  <input type="hidden" name="wikitext" value="<?=formText($text)?>" />
  <input type="hidden" name="summary" value="<?=formText($summary)?>" />
  
  <div align="center">
    <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
    <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" />
  </div>
  </form>
  <br /><br /><br /><br />
  <?
}

/**
andi's avatar
andi committed
 * Prints the global message array
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_msgarea(){
  global $MSG;

  if(!isset($MSG)) return;

  foreach($MSG as $msg){
    print '<div class="'.$msg['lvl'].'">';
    print $msg['msg'];
    print '</div>';
  }
}

/**
 * Prints the registration form
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_register(){
  global $lang;
  global $ID;

  print p_locale_xhtml('register');
andi's avatar
andi committed
?>
  <div align="center">
  <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
  <input type="hidden" name="do" value="register" />
  <input type="hidden" name="save" value="1" />
  <fieldset>
    <legend><?=$lang['register']?></legend>
    <label>
      <?=$lang['user']?>
      <input type="text" name="login" class="edit" size="50" value="<?=formText($_POST['login'])?>" />
    </label><br />
    <label>
      <?=$lang['fullname']?>
      <input type="text" name="fullname" class="edit" size="50" value="<?=formText($_POST['fullname'])?>" />
    </label><br />
    <label>
      <?=$lang['email']?>
      <input type="text" name="email" class="edit" size="50" value="<?=formText($_POST['email'])?>" />
    </label><br />
    <input type="submit" class="button" value="<?=$lang['register']?>" />
  </fieldset>
  </form>
  </div>
<?
}

/**
 * This displays the edit form (lots of logic included)
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_edit($text=null,$include='edit'){ //FIXME: include needed?
  global $ID;
  global $REV;
  global $DATE;
  global $RANGE;
  global $PRE;
  global $SUF;
  global $INFO;
  global $SUM;
  global $lang;
  global $conf;

  //set summary default
  if(!$SUM){
    if($REV){
      $SUM = $lang['restored'];
    }elseif(!$INFO['exists']){
      $SUM = $lang['created'];
    }
  }

  //no text? Load it!
  if(!isset($text)){
    $pr = false; //no preview mode
    if($RANGE){
      list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
    }else{
      $text = rawWiki($ID,$REV);
    }
  }else{
    $pr = true; //preview mode
  }

  $wr = $INFO['writable'];
  if($wr){
    if ($REV) print p_locale_xhtml('editrev');
    print p_locale_xhtml($include);
andi's avatar
andi committed
  }else{
    print p_locale_xhtml('read');
andi's avatar
andi committed
    $ro='readonly="readonly"';
  }
  if(!$DATE) $DATE = $INFO['lastmod'];
?>
  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" onsubmit="return svchk()">
  <input type="hidden" name="id"   value="<?=$ID?>" />
  <input type="hidden" name="rev"  value="<?=$REV?>" />
  <input type="hidden" name="date" value="<?=$DATE?>" />
  <input type="hidden" name="prefix" value="<?=formText($PRE)?>" />
  <input type="hidden" name="suffix" value="<?=formText($SUF)?>" />
  <table style="width:99%">
    <tr>
      <td class="toolbar" colspan="3">
        <?if($wr){?>
        <script language="JavaScript" type="text/javascript">
          <?/* sets changed to true when previewed */?>
          textChanged = <? ($pr) ? print 'true' : print 'false' ?>;
          
          formatButton('images/bold.png','<?=$lang['qb_bold']?>','**','**','<?=$lang['qb_bold']?>','b');
          formatButton('images/italic.png','<?=$lang['qb_italic']?>',"\/\/","\/\/",'<?=$lang['qb_italic']?>','i');
          formatButton('images/underline.png','<?=$lang['qb_underl']?>','__','__','<?=$lang['qb_underl']?>','u');
          formatButton('images/code.png','<?=$lang['qb_code']?>','\'\'','\'\'','<?=$lang['qb_code']?>','c');

          formatButton('images/fonth1.png','<?=$lang['qb_h1']?>','====== ',' ======\n','<?=$lang['qb_h1']?>','1');
          formatButton('images/fonth2.png','<?=$lang['qb_h2']?>','===== ',' =====\n','<?=$lang['qb_h2']?>','2');
          formatButton('images/fonth3.png','<?=$lang['qb_h3']?>','==== ',' ====\n','<?=$lang['qb_h3']?>','3');
          formatButton('images/fonth4.png','<?=$lang['qb_h4']?>','=== ',' ===\n','<?=$lang['qb_h4']?>','4');
          formatButton('images/fonth5.png','<?=$lang['qb_h5']?>','== ',' ==\n','<?=$lang['qb_h5']?>','5');

          formatButton('images/link.png','<?=$lang['qb_link']?>','[[',']]','<?=$lang['qb_link']?>','l');
          formatButton('images/extlink.png','<?=$lang['qb_extlink']?>','[[',']]','http://www.example.com|<?=$lang['qb_extlink']?>');

          formatButton('images/list.png','<?=$lang['qb_ol']?>','  - ','\n','<?=$lang['qb_ol']?>');
          formatButton('images/list_ul.png','<?=$lang['qb_ul']?>','  * ','\n','<?=$lang['qb_ul']?>');

          insertButton('images/rule.png','<?=$lang['qb_hr']?>','----\n');
          mediaButton('images/image.png','<?=$lang['qb_media']?>','m','<?=$INFO['namespace']?>');

andi's avatar
andi committed
          <?
andi's avatar
andi committed
          if($conf['useacl'] && $_SERVER['REMOTE_USER']){
            echo "insertButton('images/sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
          }
          ?>
        </script>
        <?}?>
      </td>
    </tr>
    <tr>
      <td colspan="3">
andi's avatar
andi committed
        <textarea name="wikitext" id="wikitext" <?=$ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" onkeyup="summaryCheck();" tabindex="1"><?="\n".formText($text)?></textarea>
andi's avatar
andi committed
      </td>
    </tr>
    <tr>
      <td>
      <?if($wr){?>
        <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" />
        <input class="button" type="submit" name="do" value="<?=$lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" />
        <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" tabindex="5" />
      <?}?>
      </td>
      <td>
      <?if($wr){?>
        <?=$lang['summary']?>:
andi's avatar
andi committed
        <input type="text" class="edit" name="summary" id="summary" size="50" onkeyup="summaryCheck();" value="<?=formText($SUM)?>" tabindex="2" />
andi's avatar
andi committed
      <?}?>
      </td>
      <td align="right">
        <script type="text/javascript">
          showSizeCtl();
          <?if($wr){?>
            init_locktimer(<?=$conf['locktime']-60?>,'<?=$lang['willexpire']?>');
andi's avatar
andi committed
            document.editform.wikitext.focus();
andi's avatar
andi committed
          <?}?>
        </script>
      </td>
    </tr>
  </table>
  </form>
<?
}

/**
 * prepares the signature string as configured in the config
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_signature(){
  global $conf;
  global $INFO;

  $sig = $conf['signature'];
  $sig = strftime($sig);
  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
  return $sig;
}

/**
 * prints some debug info
andi's avatar
andi committed
 *
 * @author Andreas Gohr <andi@splitbrain.org>
andi's avatar
andi committed
 */
function html_debug(){
  global $conf;
andi's avatar
andi committed
  global $lang;
  //remove sensitive data
  $cnf = $conf;
  $cnf['auth']='***';
  $cnf['notify']='***';
andi's avatar
andi committed
  $cnf['ftp']='***';
andi's avatar
andi committed

  print '<html><body>';

  print '<p>When reporting bugs please send all the following ';
  print 'output as a mail to andi@splitbrain.org ';
  print 'The best way to do this is to save this page in your browser</p>';

  print '<b>$_SERVER:</b><pre>';
  print_r($_SERVER);
  print '</pre>';

  print '<b>$conf:</b><pre>';
  print_r($cnf);
andi's avatar
andi committed
  print '</pre>';

  print '<b>DOKU_BASE:</b><pre>';
  print DOKU_BASE;
  print '</pre>';
  
  print '<b>abs DOKU_BASE:</b><pre>';
  print DOKU_URL;
andi's avatar
andi committed
  print '</pre>';
  
  print '<b>rel DOKU_BASE:</b><pre>';
andi's avatar
andi committed
  print dirname($_SERVER['PHP_SELF']).'/';
  print '</pre>';

  print '<b>PHP Version:</b><pre>';
  print phpversion();
  print '</pre>';

  print '<b>locale:</b><pre>';
  print setlocale(LC_ALL,0);
  print '</pre>';

andi's avatar
andi committed
  print '<b>encoding:</b><pre>';
  print $lang['encoding'];
  print '</pre>';

andi's avatar
andi committed
  print '<b>Environment:</b><pre>';
  print_r($_ENV);
  print '</pre>';

  print '<b>PHP settings:</b><pre>';
  $inis = ini_get_all();
  print_r($inis);
  print '</pre>';

  print '</body></html>';
}

/**
 * Print the admin overview page
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 */
function html_admin(){
  global $ID;
  global $lang;

  print p_locale_xhtml('admin');

  ptln('<ul class="admin">');

  // currently ACL only - more to come
  ptln('<li><a href="'.wl($ID,'do=admin&page=acl').'">'.$lang['admin_acl'].'</a></li>');

  ptln('</ul>');
}


//Setup VIM: ex: et ts=2 enc=utf-8 :