You are here

class DrupalDiffFormatter in Diff 6.2

Same name and namespace in other branches
  1. 5.2 DiffEngine.php \DrupalDiffFormatter
  2. 6 DiffEngine.php \DrupalDiffFormatter
  3. 7.3 DiffEngine.php \DrupalDiffFormatter
  4. 7.2 DiffEngine.php \DrupalDiffFormatter

Diff formatter which uses Drupal theme functions. @private @subpackage DifferenceEngine

Hierarchy

Expanded class hierarchy of DrupalDiffFormatter

File

./DiffEngine.php, line 1083
A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)

View source
class DrupalDiffFormatter extends DiffFormatter {
  var $rows;
  function DrupalDiffFormatter() {
    $this->leading_context_lines = 2;
    $this->trailing_context_lines = 2;
  }
  function _start_diff() {
    $this->rows = array();
  }
  function _end_diff() {
    return $this->rows;
  }
  function _block_header($xbeg, $xlen, $ybeg, $ylen) {
    return array(
      array(
        'data' => theme('diff_header_line', $xbeg),
        'colspan' => 2,
      ),
      array(
        'data' => theme('diff_header_line', $ybeg),
        'colspan' => 2,
      ),
    );
  }
  function _start_block($header) {
    if ($this->show_header) {
      $this->rows[] = $header;
    }
  }
  function _end_block() {
  }
  function _lines($lines, $prefix = ' ', $color = 'white') {
  }

  /**
   * Note: you should HTML-escape parameter before calling this.
   */
  function addedLine($line) {
    return array(
      '+',
      array(
        'data' => theme('diff_content_line', $line),
        'class' => 'diff-addedline',
      ),
    );
  }

  /**
   * Note: you should HTML-escape parameter before calling this.
   */
  function deletedLine($line) {
    return array(
      '-',
      array(
        'data' => theme('diff_content_line', $line),
        'class' => 'diff-deletedline',
      ),
    );
  }

  /**
   * Note: you should HTML-escape parameter before calling this.
   */
  function contextLine($line) {
    return array(
      ' ',
      array(
        'data' => theme('diff_content_line', $line),
        'class' => 'diff-context',
      ),
    );
  }
  function emptyLine() {
    return array(
      ' ',
      theme('diff_empty_line', ' '),
    );
  }
  function _added($lines) {
    foreach ($lines as $line) {
      $this->rows[] = array_merge($this
        ->emptyLine(), $this
        ->addedLine(check_plain($line)));
    }
  }
  function _deleted($lines) {
    foreach ($lines as $line) {
      $this->rows[] = array_merge($this
        ->deletedLine(check_plain($line)), $this
        ->emptyLine());
    }
  }
  function _context($lines) {
    foreach ($lines as $line) {
      $this->rows[] = array_merge($this
        ->contextLine(check_plain($line)), $this
        ->contextLine(check_plain($line)));
    }
  }
  function _changed($orig, $closing) {
    $diff = new WordLevelDiff($orig, $closing);
    $del = $diff
      ->orig();
    $add = $diff
      ->closing();

    // Notice that WordLevelDiff returns HTML-escaped output.
    // Hence, we will be calling addedLine/deletedLine without HTML-escaping.
    while ($line = array_shift($del)) {
      $aline = array_shift($add);
      $this->rows[] = array_merge($this
        ->deletedLine($line), $this
        ->addedLine($aline));
    }
    foreach ($add as $line) {

      // If any leftovers
      $this->rows[] = array_merge($this
        ->emptyLine(), $this
        ->addedLine($line));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DiffFormatter::$leading_context_lines property Number of leading context "lines" to preserve.
DiffFormatter::$show_header property Should a block header be shown?
DiffFormatter::$trailing_context_lines property Number of trailing context "lines" to preserve.
DiffFormatter::format function Format a diff.
DiffFormatter::_block function
DrupalDiffFormatter::$rows property
DrupalDiffFormatter::addedLine function Note: you should HTML-escape parameter before calling this.
DrupalDiffFormatter::contextLine function Note: you should HTML-escape parameter before calling this.
DrupalDiffFormatter::deletedLine function Note: you should HTML-escape parameter before calling this.
DrupalDiffFormatter::DrupalDiffFormatter function
DrupalDiffFormatter::emptyLine function
DrupalDiffFormatter::_added function Overrides DiffFormatter::_added
DrupalDiffFormatter::_block_header function Overrides DiffFormatter::_block_header
DrupalDiffFormatter::_changed function Overrides DiffFormatter::_changed
DrupalDiffFormatter::_context function Overrides DiffFormatter::_context
DrupalDiffFormatter::_deleted function Overrides DiffFormatter::_deleted
DrupalDiffFormatter::_end_block function Overrides DiffFormatter::_end_block
DrupalDiffFormatter::_end_diff function Overrides DiffFormatter::_end_diff
DrupalDiffFormatter::_lines function Overrides DiffFormatter::_lines
DrupalDiffFormatter::_start_block function Overrides DiffFormatter::_start_block
DrupalDiffFormatter::_start_diff function Overrides DiffFormatter::_start_diff