Skip to content
Snippets Groups Projects
html.php 32 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
 */
andi's avatar
andi committed
function html_wikilink($id,$name=NULL,$search=''){
andi's avatar
andi committed
  static $xhtml_renderer = NULL;
  if(is_null($xhtml_renderer)){
    require_once(DOKU_INC.'inc/parser/xhtml.php');
Andreas Gohr's avatar
Andreas Gohr committed
    $xhtml_renderer = new Doku_Renderer_xhtml();
andi's avatar
andi committed
  }

  return $xhtml_renderer->internallink($id,$name,$search,true);
andi's avatar
andi committed
}

/**
 * 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;
Andreas Gohr's avatar
Andreas Gohr committed
  global $auth;
andi's avatar
andi committed

  print p_locale_xhtml('login');
andi's avatar
andi committed
  ?>
    <div class="centeralign">
matthiasgrimm's avatar
matthiasgrimm committed
    <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
andi's avatar
andi committed
      <fieldset>
matthiasgrimm's avatar
matthiasgrimm committed
        <legend><?php echo $lang['btn_login']?></legend>
        <input type="hidden" name="id" value="<?php echo $ID?>" />
andi's avatar
andi committed
        <input type="hidden" name="do" value="login" />
Andreas Gohr's avatar
Andreas Gohr committed
        <label class="block">
matthiasgrimm's avatar
matthiasgrimm committed
          <span><?php echo $lang['user']?></span>
          <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>" class="edit" />
andi's avatar
andi committed
        </label><br />
Andreas Gohr's avatar
Andreas Gohr committed
        <label class="block">
matthiasgrimm's avatar
matthiasgrimm committed
          <span><?php echo $lang['pass']?></span>
andi's avatar
andi committed
          <input type="password" name="p" class="edit" />
        </label><br />
matthiasgrimm's avatar
matthiasgrimm committed
        <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
Andreas Gohr's avatar
Andreas Gohr committed
        <label for="remember__me" class="simple">
Andreas Gohr's avatar
Andreas Gohr committed
          <input type="checkbox" name="r" id="remember__me" value="1" />
matthiasgrimm's avatar
matthiasgrimm committed
          <span><?php echo $lang['remember']?></span>
andi's avatar
andi committed
        </label>
andi's avatar
andi committed
      </fieldset>
    </form>
matthiasgrimm's avatar
matthiasgrimm committed
  <?php
    if($auth->canDo('addUser') && $conf['openregister']){
andi's avatar
andi committed
      print '<p>';
      print $lang['reghere'];
      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
      print '</p>';
    }
    if ($auth->canDo('modPass') && $conf['resendpasswd']) {
Matthias Grimm's avatar
Matthias Grimm committed
      print ': <a href="'.wl($ID,'do=resendpwd').'" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
andi's avatar
andi committed
  ?>
    </div>
matthiasgrimm's avatar
matthiasgrimm committed
  <?php
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  = '';
andi's avatar
andi committed
#  if($p) $secedit .= "</p>\n";
andi's avatar
andi committed
  $secedit .= '<div class="secedit">';
  $secedit .= html_btn('secedit',$ID,'',
                        array('do'      => 'edit',
                              'lines'   => "$section"),
                              'post');
  $secedit .= '</div>';
andi's avatar
andi committed
#  if($p) $secedit .= "\n<p>";
andi's avatar
andi committed
  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);
  }
  return $text;
}

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

  $ret  = '';
  $ret  = '<a href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" /></a>';
andi's avatar
andi committed
/**
 * Just the back to media window button in its own form
 *
 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
 */
function html_backtomedia_button($params,$akey=''){
  global $conf;
  global $lang;
Andreas Gohr's avatar
Andreas Gohr committed

  $ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/media.php"><div class="no">';
Andreas Gohr's avatar
Andreas Gohr committed

  reset($params);
  while (list($key, $val) = each($params)) {
    $ret .= '<input type="hidden" name="'.$key.'" ';
    $ret .= 'value="'.htmlspecialchars($val).'" />';
  }
Andreas Gohr's avatar
Andreas Gohr committed

  $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" ';
  if($akey){
    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
    $ret .= 'accesskey="'.$akey.'" ';
  }
  $ret .= '/>';
  $ret .= '</div></form>';

  return $ret;
}

/**
 * Displays a button (using its 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;
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
  $label = $lang['btn_'.$name];
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
  $ret = '';

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

Andreas Gohr's avatar
Andreas Gohr committed
  //make nice URLs even for buttons
andi's avatar
andi committed
  if($conf['userewrite'] == 2){
    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
  }elseif($conf['userewrite']){
    $script = DOKU_BASE.$id;
  }else{
andi's avatar
andi committed
    $script = DOKU_BASE.DOKU_SCRIPT;
andi's avatar
andi committed
    $params['id'] = $id;
  }
Andreas Gohr's avatar
Andreas Gohr committed

  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">';
Andreas Gohr's avatar
Andreas Gohr committed

  if(is_array($params)){
    reset($params);
    while (list($key, $val) = each($params)) {
      $ret .= '<input type="hidden" name="'.$key.'" ';
      $ret .= 'value="'.htmlspecialchars($val).'" />';
    }
andi's avatar
andi committed
  }
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
  if($akey){
    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
    $ret .= 'accesskey="'.$akey.'" ';
  }
  $ret .= '/>';
  $ret .= '</div></form>';
andi's avatar
andi committed

  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
andi's avatar
andi committed
  if($txt || $REV){
andi's avatar
andi committed
    $secedit = false;
  }else{
    $secedit = true;
andi's avatar
andi committed
  }
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
  if ($txt){
andi's avatar
andi committed
    //PreviewHeader
    print '<br id="scroll__here" />';
    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),$info),$secedit);
    print '<div class="clearer"></div>';
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>
 * @author Harry Fuecks <hfuecks@gmail.com>
andi's avatar
andi committed
 */
function html_hilight($html,$query){
  //split at common delimiters
  $queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY);
andi's avatar
andi committed
  foreach ($queries as $q){
     $q = preg_quote($q,'/');
     $html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html);
andi's avatar
andi committed
  }
  return $html;
}

Andreas Gohr's avatar
Andreas Gohr committed
/**
 * Callback used by html_hilight()
 *
 * @author Harry Fuecks <hfuecks@gmail.com>
Andreas Gohr's avatar
Andreas Gohr committed
 */
function html_hilight_callback($m) {
  $hlight = unslash($m[0]);
  if ( !isset($m[2])) {
    $hlight = '<span class="search_hit">'.$hlight.'</span>';
  }
  return $hlight;
}

andi's avatar
andi committed
/**
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');
  require_once(DOKU_INC.'inc/fulltext.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 class="centeralign" id="dw__loading">';
  print '<br /></div>';
  print '<script type="text/javascript" charset="utf-8">';
  print 'showLoadBar("dw__loading");';
andi's avatar
andi committed
  print '</script>';
andi's avatar
andi committed

andi's avatar
andi committed
  //do quick pagesearch
  $data = array();
  $data = ft_pageLookup(cleanID($QUERY));
andi's avatar
andi committed
  if(count($data)){
    sort($data);
    print '<div class="search_quickresult">';
    print '<h3>'.$lang[quickhits].':</h3>';
Anika Henke's avatar
Anika Henke committed
    print '<ul class="search_quickhits">';
    foreach($data as $id){
      print '<li> ';
      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id);
      print '</li> ';
andi's avatar
andi committed
    }
Anika Henke's avatar
Anika Henke committed
    print '</ul> ';
andi's avatar
andi committed
    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
    print '<div class="clearer">&nbsp;</div>';
    print '</div>';
  }
  flush();

  //do fulltext search
  $data = ft_pageSearch($QUERY,$poswords);
andi's avatar
andi committed
  if(count($data)){
    $num = 1;
    foreach($data as $id => $cnt){
andi's avatar
andi committed
      print '<div class="search_result">';
      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
        print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
      }
andi's avatar
andi committed
      print '</div>';
      flush();
      $num++;
andi's avatar
andi committed
    }
  }else{
    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
andi's avatar
andi committed
  }
andi's avatar
andi committed

  //hide progressbar
  print '<script type="text/javascript" charset="utf-8">';
  print 'hideLoadBar("dw__loading");';
andi's avatar
andi committed
  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(){
andi's avatar
andi committed
  global $ID;
  global $conf;
  global $lang;
  global $INFO;
Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
  $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><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
andi's avatar
andi committed
  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;
Andreas Gohr's avatar
Andreas Gohr committed
  $revisions = getRevisions($ID);
andi's avatar
andi committed
  $date = @date($conf['dformat'],$INFO['lastmod']);
Andreas Gohr's avatar
Andreas Gohr committed

  print p_locale_xhtml('revisions');
andi's avatar
andi committed
  print '<ul>';
  if($INFO['exists']){
Andreas Gohr's avatar
Andreas Gohr committed
    print ($INFO['minor']) ? '<li class="minor">' : '<li>';
    print '<div class="li">';
    print $date;

    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';

    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
andi's avatar
andi committed

    print $INFO['sum'];
    print ' <span class="user">';
    print $INFO['editor'];
    print '</span> ';
andi's avatar
andi committed

    print '('.$lang['current'].')';
    print '</div>';
andi's avatar
andi committed
    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);

Andreas Gohr's avatar
Andreas Gohr committed
    print ($info['minor']) ? '<li class="minor">' : '<li>';
    print '<div class="li">';
    print $date;

    print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
    $p = array();
    $p['src']    = DOKU_BASE.'lib/images/diff.png';
    $p['width']  = 15;
    $p['height'] = 11;
    $p['title']  = $lang['diff'];
    $p['alt']    = $lang['diff'];
    $att = buildAttributes($p);
    print "<img $att />";
    print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';

andi's avatar
andi committed
    print htmlspecialchars($info['sum']);
    print ' <span class="user">';
    if($info['user']){
      print $info['user'];
    }else{
      print $info['ip'];
    }
    print '</span>';
    print '</div>';
andi's avatar
andi committed
    print '</li>';
  }
  print '</ul>';
}

andi's avatar
andi committed
/**
 * display recent changes
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
andi's avatar
andi committed
 */
function html_recent($first=0){
andi's avatar
andi committed
  global $conf;
  /* we need to get one additionally log entry to be able to
   * decide if this is the last page or is there another one.
   * This is the cheapest solution to get this information.
   */
Andreas Gohr's avatar
Andreas Gohr committed
  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
  if(count($recents) == 0 && $first != 0){
    $first=0;
Andreas Gohr's avatar
Andreas Gohr committed
    $recents = getRecents(0,$conf['recent'] + 1,getNS($ID));
Andreas Gohr's avatar
Andreas Gohr committed
  $cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent'];
andi's avatar
andi committed

  print p_locale_xhtml('recent');
andi's avatar
andi committed
  print '<ul>';
Andreas Gohr's avatar
Andreas Gohr committed

  foreach($recents as $recent){
    $date = date($conf['dformat'],$recent['date']);
Andreas Gohr's avatar
Andreas Gohr committed
    print ($recent['minor']) ? '<li class="minor">' : '<li>';
    print '<div class="li">';
    print $date.' ';

    print '<a href="'.wl($recent['id'],"do=diff").'">';
    $p = array();
    $p['src']    = DOKU_BASE.'lib/images/diff.png';
    $p['width']  = 15;
    $p['height'] = 11;
    $p['title']  = $lang['diff'];
    $p['alt']    = $lang['diff'];
    $att = buildAttributes($p);
    print "<img $att />";
    print '<a href="'.wl($recent['id'],"do=revisions").'">';
    $p = array();
    $p['src']    = DOKU_BASE.'lib/images/history.png';
    $p['width']  = 12;
    $p['height'] = 14;
    $p['title']  = $lang['btn_revs'];
    $p['alt']    = $lang['btn_revs'];
    $att = buildAttributes($p);
    print "<img $att />";
    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
    print ' '.htmlspecialchars($recent['sum']);
Andreas Gohr's avatar
Andreas Gohr committed

    print ' <span class="user">';
    if($recent['user']){
      print $recent['user'];
      print $recent['ip'];
    }
    print '</span>';
    print '</div>';
andi's avatar
andi committed
    print '</li>';
  }
  print '</ul>';

  print '<div class="pagenav">';
  $last = $first + $conf['recent'];
  if ($first > 0) {
Andreas Gohr's avatar
Andreas Gohr committed
    $first -= $conf['recent'];
    if ($first < 0) $first = 0;
    print '<div class="pagenav-prev">';
    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
    print '</div>';
  }
  if ($conf['recent'] < count($recents)) {
    print '<div class="pagenav-next">';
    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
    print '</div>';
  }
  print '</div>';
andi's avatar
andi committed
}

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);
andi's avatar
andi committed
  #fixme use appropriate function
andi's avatar
andi committed
  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
 *
 * Both user functions can be given as array to point to
 * a member of an object.
 *
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";
    }

Andreas Gohr's avatar
Andreas Gohr committed
    //remember current level
andi's avatar
andi committed
    $level = $item['level'];

    //print item
    if(is_array($lifunc)){
      $ret .= $lifunc[0]->$lifunc[1]($item); //user object method
    }else{
      $ret .= $lifunc($item); //user function
    }
    $ret .= '<div class="li">';
    if(is_array($func)){
      $ret .= $func[0]->$func[1]($item); //user object method
    }else{
andi's avatar
andi committed
    $ret .= $func($item); //user function
    $ret .= '</div>';
andi's avatar
andi committed
  }

  //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/fulltext.php');
andi's avatar
andi committed
  global $ID;
  global $conf;

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

  $data = ft_backlinks($ID);
andi's avatar
andi committed

  print '<ul class="idx">';
  foreach($data as $blink){
    print '<li><div class="li">';
    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
    print '</div></li>';
andi's avatar
andi committed
  }
  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{
andi's avatar
andi committed
    if($REV){
      $r = $REV;
    }else{
      //use last revision if none given
      $revs = getRevisions($ID);
      $r = $revs[0];
    }

    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))),
andi's avatar
andi committed
                    split("\n",htmlspecialchars(rawWiki($ID,''))));
andi's avatar
andi committed
    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
              $ID.' '.date($conf['dformat'],$r).'</a>';
andi's avatar
andi committed
    $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
  ?>
andi's avatar
andi committed
      <tr>
matthiasgrimm's avatar
matthiasgrimm committed
          <?php echo $left?>
matthiasgrimm's avatar
matthiasgrimm committed
          <?php echo $right?>
andi's avatar
andi committed
      </tr>
matthiasgrimm's avatar
matthiasgrimm committed
      <?php echo $tdf->format($df)?>
andi's avatar
andi committed
    </table>
matthiasgrimm's avatar
matthiasgrimm committed
  <?php
andi's avatar
andi committed
}

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 id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
  <div class="centeralign">
    <input type="hidden" name="id" value="<?php echo $ID?>" />
    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />

matthiasgrimm's avatar
matthiasgrimm committed
    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" />
andi's avatar
andi committed
  </div>
  </form>
  <br /><br /><br /><br />
matthiasgrimm's avatar
matthiasgrimm committed
  <?php
andi's avatar
andi committed
}

/**
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 $conf;
andi's avatar
andi committed
  global $ID;

  print p_locale_xhtml('register');
andi's avatar
andi committed
?>
  <div class="centeralign">
  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
andi's avatar
andi committed
  <fieldset>
    <input type="hidden" name="do" value="register" />
    <input type="hidden" name="save" value="1" />

matthiasgrimm's avatar
matthiasgrimm committed
    <legend><?php echo $lang['register']?></legend>
Andreas Gohr's avatar
Andreas Gohr committed
    <label class="block">
matthiasgrimm's avatar
matthiasgrimm committed
      <?php echo $lang['user']?>
      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
andi's avatar
andi committed
    </label><br />
Andreas Gohr's avatar
Andreas Gohr committed

    <?php
      if (!$conf['autopasswd']) {
    ?>
Andreas Gohr's avatar
Andreas Gohr committed
      <label class="block">
matthiasgrimm's avatar
matthiasgrimm committed
        <?php echo $lang['pass']?>
        <input type="password" name="pass" class="edit" size="50" />
      </label><br />
Andreas Gohr's avatar
Andreas Gohr committed
      <label class="block">
matthiasgrimm's avatar
matthiasgrimm committed
        <?php echo $lang['passchk']?>
        <input type="password" name="passchk" class="edit" size="50" />
      </label><br />
    <?php
      }
    ?>

Andreas Gohr's avatar
Andreas Gohr committed
    <label class="block">
matthiasgrimm's avatar
matthiasgrimm committed
      <?php echo $lang['fullname']?>
      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
andi's avatar
andi committed
    </label><br />
Andreas Gohr's avatar
Andreas Gohr committed
    <label class="block">
matthiasgrimm's avatar
matthiasgrimm committed
      <?php echo $lang['email']?>
      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
andi's avatar
andi committed
    </label><br />
matthiasgrimm's avatar
matthiasgrimm committed
    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
andi's avatar
andi committed
  </fieldset>
  </form>
  </div>
matthiasgrimm's avatar
matthiasgrimm committed
<?php
andi's avatar
andi committed
}

/**
 * Print the update profile form
 *
 * @author Christopher Smith <chris@jalakai.co.uk>
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function html_updateprofile(){
  global $lang;
  global $conf;
  global $ID;
  global $INFO;
Andreas Gohr's avatar
Andreas Gohr committed

  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
?>
  <div class="centeralign">
  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
    <input type="hidden" name="do" value="profile" />
    <input type="hidden" name="save" value="1" />

    <legend><?php echo $lang['profile']?></legend>
    <label class="block">
      <?php echo $lang['user']?>
      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
Andreas Gohr's avatar
Andreas Gohr committed
    </label><br />
    <label class="block">
      <?php echo $lang['fullname']?>
      <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
    </label><br />
    <label class="block">
      <?php echo $lang['email']?>
      <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />

    <?php if($auth->canDo('modPass')) { ?>
    <label class="block">
      <?php echo $lang['newpass']?>
      <input type="password" name="newpass" class="edit" size="50" />
    </label><br />
    <label class="block">
      <?php echo $lang['passchk']?>
      <input type="password" name="passchk" class="edit" size="50" />
    </label><br />
Andreas Gohr's avatar
Andreas Gohr committed

    <?php if ($conf['profileconfirm']) { ?>
      <br />
      <label class="block">
      <?php echo $lang['oldpass']?>
Andreas Gohr's avatar
Andreas Gohr committed
      <input type="password" name="oldpass" class="edit" size="50" />
Andreas Gohr's avatar
Andreas Gohr committed

Matthias Grimm's avatar
Matthias Grimm committed
    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
  </fieldset>
  </form>
  </div>
<?php
}

andi's avatar
andi committed
/**
 * This displays the edit form (lots of logic included)
andi's avatar
andi committed
 *
Andreas Gohr's avatar
Andreas Gohr committed
 * @fixme  this is a huge lump of code and should be modularized
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
Andreas Gohr's avatar
Andreas Gohr committed
    if($INFO['exists']){
      if($RANGE){
        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
      }else{
        $text = rawWiki($ID,$REV);
      }
andi's avatar
andi committed
    }else{
Andreas Gohr's avatar
Andreas Gohr committed
      //try to load a pagetemplate
      $text = pageTemplate($ID);
andi's avatar
andi committed
    }
  }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'];
andi's avatar
andi committed

Andreas Gohr's avatar
Andreas Gohr committed

andi's avatar
andi committed
?>
Anika Henke's avatar
Anika Henke committed
  <div style="width:99%;">
  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">