Skip to content

Commit 0a9b6b3

Browse files
hungkoalahungkoala
hungkoala
authored and
hungkoala
committed
moved Webonyx custom code from local SVN to here so that we can merge with original branch
1 parent 30e103d commit 0a9b6b3

File tree

8 files changed

+99
-128
lines changed

8 files changed

+99
-128
lines changed

lib/Diff.php

100644100755
+12-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,19 @@ class Diff
8080
*
8181
* @param array $a Array containing the lines of the first string to compare.
8282
* @param array $b Array containing the lines for the second string to compare.
83-
* @param array $options
83+
* @param array $options
8484
*/
8585
public function __construct($a, $b, $options=array())
8686
{
87-
$this->a = $a;
87+
if (is_string($a)) {
88+
$a = explode("\n", $a);
89+
}
90+
91+
if (is_string($b)) {
92+
$b = explode("\n", $b);
93+
}
94+
95+
$this->a = $a;
8896
$this->b = $b;
8997

9098
$this->options = array_merge($this->defaultOptions, $options);
@@ -93,7 +101,7 @@ public function __construct($a, $b, $options=array())
93101
/**
94102
* Render a diff using the supplied rendering class and return it.
95103
*
96-
* @param Diff_Renderer_Abstract $renderer An instance of the rendering object to use for generating the diff.
104+
* @param object $renderer An instance of the rendering object to use for generating the diff.
97105
* @return mixed The generated diff. Exact return value depends on the rendered.
98106
*/
99107
public function render(Diff_Renderer_Abstract $renderer)
@@ -171,7 +179,7 @@ public function getGroupedOpcodes()
171179

172180
require_once dirname(__FILE__).'/Diff/SequenceMatcher.php';
173181
$sequenceMatcher = new Diff_SequenceMatcher($this->a, $this->b, null, $this->options);
174-
$this->groupedCodes = $sequenceMatcher->getGroupedOpcodes();
182+
$this->groupedCodes = $sequenceMatcher->getGroupedOpcodes($this->options['context']);
175183
return $this->groupedCodes;
176184
}
177185
}

lib/Diff/Renderer/Abstract.php

100644100755
File mode changed.

lib/Diff/Renderer/Html/Array.php

100644100755
+4-5
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,21 @@ private function getChangeExtent($fromLine, $toLine)
175175
private function formatLines($lines)
176176
{
177177
$lines = array_map(array($this, 'ExpandTabs'), $lines);
178-
$lines = array_map(array($this, 'HtmlSafe'), $lines);
178+
//$lines = array_map(array($this, 'HtmlSafe'), $lines);
179179
foreach($lines as &$line) {
180-
$line = preg_replace_callback('# ( +)|^ #', __CLASS__."::fixSpaces", $line);
180+
$line = preg_replace('# ( +)|^ #e', "\$this->fixSpaces('\\1')", $line);
181181
}
182182
return $lines;
183183
}
184184

185185
/**
186186
* Replace a string containing spaces with a HTML representation using  .
187187
*
188-
* @param string $matches Regex matches array.
188+
* @param string $spaces The string of spaces.
189189
* @return string The HTML representation of the string.
190190
*/
191-
public static function fixSpaces($matches)
191+
function fixSpaces($spaces='')
192192
{
193-
$spaces = isset($matches[1]) ? $matches[1] : '';
194193
$count = strlen($spaces);
195194
if($count == 0) {
196195
return '';

lib/Diff/Renderer/Html/Inline.php

100644100755
+79-109
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
* PHP version 5
66
*
77
* Copyright (c) 2009 Chris Boulton <[email protected]>
8-
*
8+
*
99
* All rights reserved.
10-
*
11-
* Redistribution and use in source and binary forms, with or without
10+
*
11+
* Redistribution and use in source and binary forms, with or without
1212
* modification, are permitted provided that the following conditions are met:
1313
*
1414
* - Redistributions of source code must retain the above copyright notice,
1515
* this list of conditions and the following disclaimer.
1616
* - Redistributions in binary form must reproduce the above copyright notice,
1717
* this list of conditions and the following disclaimer in the documentation
1818
* and/or other materials provided with the distribution.
19-
* - Neither the name of the Chris Boulton nor the names of its contributors
20-
* may be used to endorse or promote products derived from this software
19+
* - Neither the name of the Chris Boulton nor the names of its contributors
20+
* may be used to endorse or promote products derived from this software
2121
* without specific prior written permission.
2222
*
23-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3333
* POSSIBILITY OF SUCH DAMAGE.
3434
*
3535
* @package DiffLib
@@ -40,104 +40,74 @@
4040
* @link http://github.com/chrisboulton/php-diff
4141
*/
4242

43-
require_once dirname(__FILE__).'/Array.php';
43+
require_once dirname(__FILE__) . '/Array.php';
4444

4545
class Diff_Renderer_Html_Inline extends Diff_Renderer_Html_Array
4646
{
47-
/**
48-
* Render a and return diff with changes between the two sequences
49-
* displayed inline (under each other)
50-
*
51-
* @return string The generated inline diff.
52-
*/
53-
public function render()
54-
{
55-
$changes = parent::render();
56-
$html = '';
57-
if(empty($changes)) {
58-
return $html;
59-
}
6047

61-
$html .= '<table class="Differences DifferencesInline">';
62-
$html .= '<thead>';
63-
$html .= '<tr>';
64-
$html .= '<th>Old</th>';
65-
$html .= '<th>New</th>';
66-
$html .= '<th>Differences</th>';
67-
$html .= '</tr>';
68-
$html .= '</thead>';
69-
foreach($changes as $i => $blocks) {
70-
// If this is a separate block, we're condensing code so output ...,
71-
// indicating a significant portion of the code has been collapsed as
72-
// it is the same
73-
if($i > 0) {
74-
$html .= '<tbody class="Skipped">';
75-
$html .= '<th>&hellip;</th>';
76-
$html .= '<th>&hellip;</th>';
77-
$html .= '<td>&nbsp;</td>';
78-
$html .= '</tbody>';
79-
}
48+
/**
49+
* Render a and return diff with changes between the two sequences
50+
* displayed inline (under each other)
51+
*
52+
* @return string The generated inline diff.
53+
*/
54+
public function render()
55+
{
56+
$changes = parent::render();
57+
$html = '';
58+
if (empty($changes)) {
59+
return $html;
60+
}
61+
62+
foreach ($changes as $i => $blocks) {
63+
// If this is a separate block, we're condensing code so output ...,
64+
// indicating a significant portion of the code has been collapsed as
65+
// it is the same
66+
if ($i > 0) {
67+
$html .= '<div class="diff diff-empty"></div>';
68+
}
69+
70+
foreach ($blocks as $change) {
8071

81-
foreach($blocks as $change) {
82-
$html .= '<tbody class="Change'.ucfirst($change['tag']).'">';
83-
// Equal changes should be shown on both sides of the diff
84-
if($change['tag'] == 'equal') {
85-
foreach($change['base']['lines'] as $no => $line) {
86-
$fromLine = $change['base']['offset'] + $no + 1;
87-
$toLine = $change['changed']['offset'] + $no + 1;
88-
$html .= '<tr>';
89-
$html .= '<th>'.$fromLine.'</th>';
90-
$html .= '<th>'.$toLine.'</th>';
91-
$html .= '<td class="Left">'.$line.'</td>';
92-
$html .= '</tr>';
93-
}
94-
}
95-
// Added lines only on the right side
96-
else if($change['tag'] == 'insert') {
97-
foreach($change['changed']['lines'] as $no => $line) {
98-
$toLine = $change['changed']['offset'] + $no + 1;
99-
$html .= '<tr>';
100-
$html .= '<th>&nbsp;</th>';
101-
$html .= '<th>'.$toLine.'</th>';
102-
$html .= '<td class="Right"><ins>'.$line.'</ins>&nbsp;</td>';
103-
$html .= '</tr>';
104-
}
105-
}
106-
// Show deleted lines only on the left side
107-
else if($change['tag'] == 'delete') {
108-
foreach($change['base']['lines'] as $no => $line) {
109-
$fromLine = $change['base']['offset'] + $no + 1;
110-
$html .= '<tr>';
111-
$html .= '<th>'.$fromLine.'</th>';
112-
$html .= '<th>&nbsp;</th>';
113-
$html .= '<td class="Left"><del>'.$line.'</del>&nbsp;</td>';
114-
$html .= '</tr>';
115-
}
116-
}
117-
// Show modified lines on both sides
118-
else if($change['tag'] == 'replace') {
119-
foreach($change['base']['lines'] as $no => $line) {
120-
$fromLine = $change['base']['offset'] + $no + 1;
121-
$html .= '<tr>';
122-
$html .= '<th>'.$fromLine.'</th>';
123-
$html .= '<th>&nbsp;</th>';
124-
$html .= '<td class="Left"><span>'.$line.'</span></td>';
125-
$html .= '</tr>';
126-
}
72+
// Equal changes should be shown on both sides of the diff
73+
if ($change['tag'] == 'equal') {
74+
foreach ($change['base']['lines'] as $no => $line) {
75+
$html .= '<div class="diff diff-equal">'
76+
. $line
77+
. '</div>';
78+
}
79+
} // Added lines only on the right side
80+
else if ($change['tag'] == 'insert') {
81+
foreach ($change['changed']['lines'] as $no => $line) {
82+
$html .= '<div class="diff diff-added" style="background-color: #DDFADE;">'
83+
. '<ins style="background: #9e9; text-decoration: none !important;">'
84+
. $line
85+
. '</ins>&nbsp;</div>';
86+
}
87+
} // Show deleted lines only on the left side
88+
else if ($change['tag'] == 'delete') {
89+
foreach ($change['base']['lines'] as $no => $line) {
90+
$html .= '<div class="diff diff-removed" style="background-color: #FFE7E7;">'
91+
. '<del style="background: #e99; text-decoration: line-through;">'
92+
. $line
93+
. '</del>&nbsp;</div>';
94+
}
95+
} // Show modified lines on both sides
96+
else if ($change['tag'] == 'replace') {
97+
foreach ($change['base']['lines'] as $no => $line) {
98+
$html .= '<div class="diff diff-removed" style="background-color: #FFE7E7;"><span>'
99+
. $line
100+
. '</span></div>';
101+
}
127102

128-
foreach($change['changed']['lines'] as $no => $line) {
129-
$toLine = $change['changed']['offset'] + $no + 1;
130-
$html .= '<tr>';
131-
$html .= '<th>'.$toLine.'</th>';
132-
$html .= '<th>&nbsp;</th>';
133-
$html .= '<td class="Right"><span>'.$line.'</span></td>';
134-
$html .= '</tr>';
135-
}
136-
}
137-
$html .= '</tbody>';
138-
}
139-
}
140-
$html .= '</table>';
141-
return $html;
142-
}
103+
foreach ($change['changed']['lines'] as $no => $line) {
104+
$html .= '<div class="diff diff-added" style="background-color: #DDFADE;"><span>'
105+
. $line
106+
. '</span></div>';
107+
}
108+
}
109+
}
110+
}
111+
return $html;
112+
}
143113
}

lib/Diff/Renderer/Html/SideBySide.php

100644100755
File mode changed.

lib/Diff/Renderer/Text/Context.php

100644100755
File mode changed.

lib/Diff/Renderer/Text/Unified.php

100644100755
File mode changed.

lib/Diff/SequenceMatcher.php

100644100755
+4-10
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class Diff_SequenceMatcher
8383
* @param string|array $a A string or array containing the lines to compare against.
8484
* @param string|array $b A string or array containing the lines to compare.
8585
* @param string|array $junkCallback Either an array or string that references a callback function (if there is one) to determine 'junk' characters.
86-
* @param array $options
8786
*/
8887
public function __construct($a, $b, $junkCallback=null, $options)
8988
{
@@ -94,11 +93,6 @@ public function __construct($a, $b, $junkCallback=null, $options)
9493
$this->setSequences($a, $b);
9594
}
9695

97-
/**
98-
* Set new options
99-
*
100-
* @param array $options
101-
*/
10296
public function setOptions($options)
10397
{
10498
$this->options = array_merge($this->defaultOptions, $options);
@@ -212,8 +206,8 @@ private function chainB()
212206
/**
213207
* Checks if a particular character is in the junk dictionary
214208
* for the list of junk characters.
215-
* @param $b
216-
* @return boolean True if the character is considered junk. False if not.
209+
*
210+
* @return boolean $b True if the character is considered junk. False if not.
217211
*/
218212
private function isBJunk($b)
219213
{
@@ -637,7 +631,7 @@ private function quickRatio()
637631
{
638632
if($this->fullBCount === null) {
639633
$this->fullBCount = array();
640-
$bLength = count ($this->b);
634+
$bLength = count ($b);
641635
for($i = 0; $i < $bLength; ++$i) {
642636
$char = $this->b[$i];
643637
$this->fullBCount[$char] = $this->arrayGetDefault($this->fullBCount, $char, 0) + 1;
@@ -735,7 +729,7 @@ private function tupleSort($a, $b)
735729
}
736730
}
737731

738-
if(count($a) == count($b)) {
732+
if(count($a) == $count($b)) {
739733
return 0;
740734
}
741735
else if(count($a) < count($b)) {

0 commit comments

Comments
 (0)