class DrupalDiffFormatter in Diff 7.2
Same name and namespace in other branches
- 5.2 DiffEngine.php \DrupalDiffFormatter
- 6.2 DiffEngine.php \DrupalDiffFormatter
- 6 DiffEngine.php \DrupalDiffFormatter
- 7.3 DiffEngine.php \DrupalDiffFormatter
Diff formatter which uses Drupal theme functions. @private @subpackage DifferenceEngine
Hierarchy
- class \DiffFormatter
- class \DrupalDiffFormatter
Expanded class hierarchy of DrupalDiffFormatter
File
- ./
DiffEngine.php, line 1084 - 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', array(
'lineno' => $xbeg,
)),
'colspan' => 2,
),
array(
'data' => theme('diff_header_line', array(
'lineno' => $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', array(
'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', array(
'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', array(
'line' => $line,
)),
'class' => 'diff-context',
),
);
}
function emptyLine() {
return array(
' ',
theme('diff_empty_line', array(
'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));
}
}
}