<?php
require_once(PHPWS_SOURCE_DIR . 'mod/article/lib/pear/Text/Diff.php');
require_once(PHPWS_SOURCE_DIR . 'mod/article/lib/pear/Text/Diff/Renderer.php');
/**
* This is a "HTML" diff renderer. class.  
*
* This class renders a diff in "Html diff" format.
*
* @version $Id: unified_diff.php,v 1.1 2004/08/21 17:02:09 adarkling Exp $
*
* @author Eloi George <eloi@NOSPAM.bygeorgeware.com>
* @module Article Manager
* @param int context_lines : Number of leading context "lines" to preserve.
*/

class Text_Diff_Renderer_html extends Text_Diff_Renderer 
{
  /**
  * Number of leading context "lines" to preserve.
  *
  * This should be left at zero for this class, but subclasses
  * may want to set this to other values.
  */
  var $linesadded = 0;
  
  /**
  * Number of leading context "lines" to preserve.
  *
  * This should be left at zero for this class, but subclasses
  * may want to set this to other values.
  */
  var $linesdeleted = 0;
  
  /**
  * Number of leading context "lines" to preserve.
  *
  * This should be left at zero for this class, but subclasses
  * may want to set this to other values.
  */
  var $lineschanged = 0;
  
  function Text_Diff_Renderer_html($context_lines = 4)
  {
    $this->_leading_context_lines = $context_lines;
    $this->_trailing_context_lines = $context_lines;
  }
  
  function _blockHeader($xbeg, $xlen, $ybeg, $ylen) {}
 
  function _lines($lines, $prefix = ' ', $suffix = ' ')
  {
      foreach ($lines as $line) {
          echo "$prefix$line$suffix\n";
      }
  }
 
  function _context($lines)
  {
    $this->_lines($lines, '<tr><td colspan="4">', '</td></tr>');
  }
  
  function _added($lines)
  {
    $this->linesadded=$this->linesadded+count($lines);
    $this->_lines($lines, '<tr><td width="50%" colspan="2">&nbsp;</td><td width="2%" bgcolor="white">++</td><td width="45%" bgcolor="#ebf9a4">', '</td></tr>');
  }
  
  function _deleted($lines)
  {
    $this->linesdeleted=$this->linesdeleted+count($lines);
    $this->_lines($lines, '<tr><td width="2%" bgcolor="white">--</td><td bgcolor="#ffdbde" width="45%">', '</td><td width="50%" colspan="2">&nbsp;</td></tr>');
  }
  
  function _changed($orig, $final)
  {
    $orig = array_pad($orig, count($final), ' '); 
    $final = array_pad($final, count($orig), ' '); 
    $this->lineschanged=$this->lineschanged+count($final);
    while (($origLine = each($orig)) && ($finalLine = each($final))) {
      $this->_lines(array($origLine[1]), '<tr><td width="2%" bgcolor="white">--</td><td bgcolor="#ffdbde" width="50%">', '</td>');
      $this->_lines(array($finalLine[1]), '<td width="2%" bgcolor="white">++</td><td bgcolor="#ebf9a4" width="50%">', '</td></tr>');
    }
  }
}
?>