From 47a906ead4a9ea1105bd2d1038b64b7bd0d67b76 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 9 Mar 2012 09:17:01 +0100 Subject: use inlinestyles for diffs in HTML mails --- inc/DifferenceEngine.php | 61 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 14 deletions(-) (limited to 'inc/DifferenceEngine.php') diff --git a/inc/DifferenceEngine.php b/inc/DifferenceEngine.php index 6e1d07382..52dca32c8 100644 --- a/inc/DifferenceEngine.php +++ b/inc/DifferenceEngine.php @@ -818,6 +818,39 @@ class DiffFormatter { } } +/** + * Utilityclass for styling HTML formatted diffs + * + * Depends on global var $DIFF_INLINESTYLES, if true some minimal predefined + * inline styles are used. Useful for HTML mails and RSS feeds + * + * @author Andreas Gohr + */ +class HTMLDiff { + /** + * Holds the style names and basic CSS + */ + static public $styles = array( + 'diff-addedline' => 'background-color: #ddffdd;', + 'diff-deletedline' => 'background-color: #ffdddd;', + 'diff-context' => 'background-color: #f5f5f5;', + 'diff-mark' => 'color: #ff0000;', + ); + + /** + * Return a class or style parameter + */ + static function css($classname){ + global $DIFF_INLINESTYLES; + + if($DIFF_INLINESTYLES){ + if(!isset(self::$styles[$classname])) return ''; + return 'style="'.self::$styles[$classname].'"'; + }else{ + return 'class="'.$classname.'"'; + } + } +} /** * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3 @@ -838,11 +871,11 @@ class _HWLDF_WordAccumulator { function _flushGroup($new_tag) { if ($this->_group !== '') { if ($this->_tag == 'mark') - $this->_line .= ''.$this->_group.''; + $this->_line .= ''.$this->_group.''; elseif ($this->_tag == 'add') - $this->_line .= ''.$this->_group.''; + $this->_line .= ''.$this->_group.''; elseif ($this->_tag == 'del') - $this->_line .= ''.$this->_group.''; + $this->_line .= ''.$this->_group.''; else $this->_line .= $this->_group; } @@ -1020,8 +1053,8 @@ class TableDiffFormatter extends DiffFormatter { global $lang; $l1 = $lang['line'].' '.$xbeg; $l2 = $lang['line'].' '.$ybeg; - $r = ''.$l1.":\n". - ''.$l2.":\n". + $r = ''.$l1.":\n". + ''.$l2.":\n". "\n"; return $r; } @@ -1037,11 +1070,11 @@ class TableDiffFormatter extends DiffFormatter { } function addedLine($line) { - return '+' . $line.''; + return '+' . $line.''; } function deletedLine($line) { - return '-' . $line.''; + return '-' . $line.''; } function emptyLine() { @@ -1049,7 +1082,7 @@ class TableDiffFormatter extends DiffFormatter { } function contextLine($line) { - return ' '.$line.''; + return ' '.$line.''; } function _added($lines) { @@ -1115,9 +1148,9 @@ class InlineDiffFormatter extends DiffFormatter { $xbeg .= "," . $xlen; if ($ylen != 1) $ybeg .= "," . $ylen; - $r = '@@ '.$lang['line']." -$xbeg +$ybeg @@"; - $r .= ' '.$lang['deleted'].''; - $r .= ' '.$lang['created'].''; + $r = '@@ '.$lang['line']." -$xbeg +$ybeg @@"; + $r .= ' '.$lang['deleted'].''; + $r .= ' '.$lang['created'].''; $r .= "\n"; return $r; } @@ -1134,19 +1167,19 @@ class InlineDiffFormatter extends DiffFormatter { function _added($lines) { foreach ($lines as $line) { - print(''. $line . "\n"); + print(''. $line . "\n"); } } function _deleted($lines) { foreach ($lines as $line) { - print('' . $line . "\n"); + print('' . $line . "\n"); } } function _context($lines) { foreach ($lines as $line) { - print(''.$line."\n"); + print(''.$line."\n"); } } -- cgit v1.2.3 From 63703ba5bd81f50c43bc45f8bf79c514afa3ee49 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 Mar 2012 12:09:30 +0100 Subject: coding style updates --- inc/DifferenceEngine.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'inc/DifferenceEngine.php') diff --git a/inc/DifferenceEngine.php b/inc/DifferenceEngine.php index 6e1d07382..01926b20c 100644 --- a/inc/DifferenceEngine.php +++ b/inc/DifferenceEngine.php @@ -29,7 +29,7 @@ class _DiffOp { class _DiffOp_Copy extends _DiffOp { var $type = 'copy'; - + function __construct($orig, $closing = false) { if (!is_array($closing)) $closing = $orig; @@ -44,7 +44,7 @@ class _DiffOp_Copy extends _DiffOp { class _DiffOp_Delete extends _DiffOp { var $type = 'delete'; - + function __construct($lines) { $this->orig = $lines; $this->closing = false; @@ -57,7 +57,7 @@ class _DiffOp_Delete extends _DiffOp { class _DiffOp_Add extends _DiffOp { var $type = 'add'; - + function __construct($lines) { $this->closing = $lines; $this->orig = false; @@ -70,7 +70,7 @@ class _DiffOp_Add extends _DiffOp { class _DiffOp_Change extends _DiffOp { var $type = 'change'; - + function __construct($orig, $closing) { $this->orig = $orig; $this->closing = $closing; @@ -924,7 +924,7 @@ class WordLevelDiff extends MappedDiff { } class InlineWordLevelDiff extends MappedDiff { - + function __construct($orig_lines, $closing_lines) { list ($orig_words, $orig_stripped) = $this->_split($orig_lines); list ($closing_words, $closing_stripped) = $this->_split($closing_lines); -- cgit v1.2.3 From e260f93b6cea05bc39bbd77b9db5bdc0c2c424bf Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Thu, 5 Jul 2012 22:58:24 +0100 Subject: xml compatibility fixes (mainly entities to unicode conversions) --- inc/DifferenceEngine.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'inc/DifferenceEngine.php') diff --git a/inc/DifferenceEngine.php b/inc/DifferenceEngine.php index 0a7ce8e7c..1b68cf6d3 100644 --- a/inc/DifferenceEngine.php +++ b/inc/DifferenceEngine.php @@ -1039,8 +1039,8 @@ class TableDiffFormatter extends DiffFormatter { // Preserve whitespaces by converting some to non-breaking spaces. // Do not convert all of them to allow word-wrap. $val = parent::format($diff); - $val = str_replace(' ','  ', $val); - $val = preg_replace('/ (?=<)|(?<=[ >]) /', ' ', $val); + $val = str_replace(' ','  ', $val); + $val = preg_replace('/ (?=<)|(?<=[ >]) /', ' ', $val); return $val; } @@ -1078,7 +1078,7 @@ class TableDiffFormatter extends DiffFormatter { } function emptyLine() { - return ' '; + return ' '; } function contextLine($line) { @@ -1132,8 +1132,8 @@ class InlineDiffFormatter extends DiffFormatter { // Preserve whitespaces by converting some to non-breaking spaces. // Do not convert all of them to allow word-wrap. $val = parent::format($diff); - $val = str_replace(' ','  ', $val); - $val = preg_replace('/ (?=<)|(?<=[ >]) /', ' ', $val); + $val = str_replace(' ','  ', $val); + $val = preg_replace('/ (?=<)|(?<=[ >]) /', ' ', $val); return $val; } -- cgit v1.2.3