Rev 5 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | Rev 13 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * PHP diff functions |
4 | * PHP diff functions |
5 | * Copyright 2012 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2012 Daniel Marschall, ViaThinkSoft |
6 | * Revision 2012-11-16 |
6 | * Revision 2012-11-16 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | * |
13 | * |
14 | * Unless required by applicable law or agreed to in writing, software |
14 | * Unless required by applicable law or agreed to in writing, software |
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | * See the License for the specific language governing permissions and |
17 | * See the License for the specific language governing permissions and |
18 | * limitations under the License. |
18 | * limitations under the License. |
19 | */ |
19 | */ |
20 | 20 | ||
21 | define('TABS_WS', 6); |
21 | define('TABS_WS', 6); |
22 | 22 | ||
23 | function output_unified_diff($fileA, $fileB, $num_lines=3) { |
23 | function output_unified_diff($fileA, $fileB, $num_lines=3) { |
24 | $fileA = realpath($fileA); |
24 | $fileA = realpath($fileA); |
25 | $fileB = realpath($fileB); |
25 | $fileB = realpath($fileB); |
26 | 26 | ||
27 | ob_start(); |
27 | ob_start(); |
28 | system("diff -wbB --ignore-blank-lines -U ".escapeshellarg($num_lines)." ".escapeshellarg($fileA)." ".escapeshellarg($fileB)); |
28 | system("diff -wbB --ignore-blank-lines -U ".escapeshellarg($num_lines)." ".escapeshellarg($fileA)." ".escapeshellarg($fileB)); |
29 | $cont = ob_get_contents(); |
29 | $cont = ob_get_contents(); |
30 | ob_end_clean(); |
30 | ob_end_clean(); |
31 | 31 | ||
32 | $ary = explode("\n", $cont); |
32 | $ary = explode("\n", $cont); |
33 | foreach ($ary as $n => $a) { |
33 | foreach ($ary as $n => $a) { |
34 | $c = substr($a, 0, 1); |
34 | $c = substr($a, 0, 1); |
35 | $c2 = substr($a, 0, 2); |
35 | $c2 = substr($a, 0, 2); |
36 | $c3 = substr($a, 0, 3); |
36 | $c3 = substr($a, 0, 3); |
37 | 37 | ||
38 | echo '<code>'; |
38 | echo '<code>'; |
39 | if (($c3 == '+++') || ($c3 == '---')) { |
39 | if (($c3 == '+++') || ($c3 == '---')) { |
40 | echo '<b><font color="gray">'.html_format($a).'</font></b>'; |
40 | echo '<b><font color="gray">'.html_format($a).'</font></b>'; |
41 | } else if ($c2 == '@@') { |
41 | } else if ($c2 == '@@') { |
42 | echo '<b><font color="blue">'.html_format($a).'</font></b>'; |
42 | echo '<b><font color="blue">'.html_format($a).'</font></b>'; |
43 | } else if ($c == '+') { |
43 | } else if ($c == '+') { |
44 | echo '<font color="green">'.html_format($a).'</font>'; |
44 | echo '<font color="green">'.html_format($a).'</font>'; |
45 | } else if ($c == '-') { |
45 | } else if ($c == '-') { |
46 | echo '<font color="red">'.html_format($a).'</font>'; |
46 | echo '<font color="red">'.html_format($a).'</font>'; |
47 | } else { |
47 | } else { |
48 | echo html_format($a); |
48 | echo html_format($a); |
49 | } |
49 | } |
50 | echo "</code><br />\n"; |
50 | echo "</code><br />\n"; |
51 | } |
51 | } |
52 | } |
52 | } |
53 | 53 | ||
54 | function output_diff($fileA, $fileB, $num_lines=3) { |
54 | function output_diff($fileA, $fileB, $num_lines=3) { |
55 | $fileA = realpath($fileA); |
55 | $fileA = realpath($fileA); |
56 | $fileB = realpath($fileB); |
56 | $fileB = realpath($fileB); |
57 | 57 | ||
58 | ob_start(); |
58 | ob_start(); |
59 | system("diff -wbB --ignore-blank-lines ".escapeshellarg($fileA)." ".escapeshellarg($fileB)); |
59 | system("diff -wbB --ignore-blank-lines ".escapeshellarg($fileA)." ".escapeshellarg($fileB)); |
60 | $cont = ob_get_contents(); |
60 | $cont = ob_get_contents(); |
61 | ob_end_clean(); |
61 | ob_end_clean(); |
62 | 62 | ||
63 | $ary = explode("\n", $cont); |
63 | $ary = explode("\n", $cont); |
64 | foreach ($ary as $n => $a) { |
64 | foreach ($ary as $n => $a) { |
65 | $c = substr($a, 0, 1); |
65 | $c = substr($a, 0, 1); |
66 | 66 | ||
67 | echo '<code>'; |
67 | echo '<code>'; |
68 | if (($c == '>') || ($c == '<')) { |
68 | if (($c == '>') || ($c == '<')) { |
69 | echo '<b><font color="blue">'.html_format($c).'</font></b>'.html_format(substr($a, 1)); |
69 | echo '<b><font color="blue">'.html_format($c).'</font></b>'.html_format(substr($a, 1)); |
70 | } else { |
70 | } else { |
71 | echo '<b><font color="blue">'.html_format($a).'</font></b>'; |
71 | echo '<b><font color="blue">'.html_format($a).'</font></b>'; |
72 | } |
72 | } |
73 | echo "</code><br />\n"; |
73 | echo "</code><br />\n"; |
74 | } |
74 | } |
75 | } |
75 | } |
76 | 76 | ||
77 | function html_format($x) { |
77 | function html_format($x) { |
78 | $x = htmlentities($x); |
78 | $x = htmlentities($x); |
79 | $x = str_replace("\t", str_repeat(' ', TABS_WS), $x); |
79 | $x = str_replace("\t", str_repeat(' ', TABS_WS), $x); |
80 | $x = str_replace(' ', ' ', $x); |
80 | $x = str_replace(' ', ' ', $x); |
81 | return $x; |
81 | return $x; |
82 | } |
82 | } |
83 | - | ||
84 | ?> |
- | |
85 | 83 |