class BackdropDiffFormatter extends DiffFormatter {
private $rows;
private $lineStats = array(
'counter' => array('x' => 0, 'y' => 0),
'offset' => array('x' => 0, 'y' => 0),
);
private $showHeader = 0;
protected function startDiff() {
$this->rows = array();
}
protected function endDiff() {
return $this->rows;
}
protected function blockHeader($xbeg, $xlen, $ybeg, $ylen) {
return array(
array(
'data' => $xbeg + $this->lineStats['offset']['x'],
'colspan' => 2,
),
array(
'data' => $ybeg + $this->lineStats['offset']['y'],
'colspan' => 2,
)
);
}
protected function startBlock($header) {
if ($this->showHeader) {
$this->rows[] = $header;
}
}
protected function endBlock() {
}
protected function lines($lines, $prefix = ' ', $color = 'white') {
}
protected function addedLine($line) {
return array(
array(
'data' => '+',
'class' => 'diff-marker diff-addedline',
),
array(
'data' => $line,
'class' => 'diff-context diff-addedline',
)
);
}
protected function deletedLine($line) {
return array(
array(
'data' => '-',
'class' => 'diff-marker diff-deletedline',
),
array(
'data' => $line,
'class' => 'diff-context diff-deletedline',
)
);
}
protected function contextLine($line) {
return array(
' ',
array(
'data' => $line,
'class' => 'diff-context',
)
);
}
protected function emptyLine() {
return array(
' ',
' ',
);
}
protected function added($lines) {
foreach ($lines as $line) {
$this->rows[] = array_merge($this->emptyLine(), $this->addedLine(check_plain($line)));
}
}
protected function deleted($lines) {
foreach ($lines as $line) {
$this->rows[] = array_merge($this->deletedLine(check_plain($line)), $this->emptyLine());
}
}
protected 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();
while ($line = array_shift($del)) {
$aline = array_shift($add);
$this->rows[] = array_merge($this->deletedLine($line), isset($aline) ? $this->addedLine($aline) : $this->emptyLine());
}
foreach ($add as $line) {
$this->rows[] = array_merge($this->emptyLine(), $this->addedLine($line));
}
}
}