PluginProbe
WP Reset / 1.70
WP Reset v1.70
trunk 1.0 1.1 1.11 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.77 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.90 All 42 releases
wp-reset / libs / diff / Renderer / Html / SideBySide.php

SideBySide.php in WP Reset 1.70, at libs/diff/Renderer/Html/SideBySide.php

163 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Side by Side HTML diff generator for PHP DiffLib.
4 *
5 * PHP version 5
6 *
7 * Copyright (c) 2009 Chris Boulton <chris.boulton@interspire.com>
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * 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
21 * without specific prior written permission.
22 *
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
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * @package DiffLib
36 * @author Chris Boulton <chris.boulton@interspire.com>
37 * @copyright (c) 2009 Chris Boulton
38 * @license New BSD License http://www.opensource.org/licenses/bsd-license.php
39 * @version 1.1
40 * @link http://github.com/chrisboulton/php-diff
41 */
42
43 require_once dirname(__FILE__).'/Array.php';
44
45 class Diff_Renderer_Html_SideBySide extends Diff_Renderer_Html_Array
46 {
47 /**
48 * Render a and return diff with changes between the two sequences
49 * displayed side by side.
50 *
51 * @return string The generated side by side diff.
52 */
53 public function render()
54 {
55 $changes = parent::render();
56
57 $html = '';
58 if(empty($changes)) {
59 return $html;
60 }
61
62 $html .= '<table class="Differences DifferencesSideBySide">';
63 //$html .= '<thead>';
64 //$html .= '<tr>';
65 //$html .= '<th colspan="2">Old Version</th>';
66 //$html .= '<th colspan="2">New Version</th>';
67 //$html .= '</tr>';
68 //$html .= '</thead>';
69 foreach($changes as $i => $blocks) {
70 if($i > 0) {
71 $html .= '<tbody class="Skipped">';
72 $html .= '<th>&hellip;</th><td>&nbsp;</td>';
73 $html .= '<th>&hellip;</th><td>&nbsp;</td>';
74 $html .= '</tbody>';
75 }
76
77 foreach($blocks as $change) {
78 $html .= '<tbody class="Change'.ucfirst($change['tag']).'">';
79 // Equal changes should be shown on both sides of the diff
80 if($change['tag'] == 'equal') {
81 foreach($change['base']['lines'] as $no => $line) {
82 $fromLine = $change['base']['offset'] + $no + 1;
83 $toLine = $change['changed']['offset'] + $no + 1;
84 $html .= '<tr>';
85 $html .= '<th>'.$fromLine.'</th>';
86 $html .= '<td class="Left"><span>'.$line.'</span>&nbsp;</span></td>';
87 $html .= '<th>'.$toLine.'</th>';
88 $html .= '<td class="Right"><span>'.$line.'</span>&nbsp;</span></td>';
89 $html .= '</tr>';
90 }
91 }
92 // Added lines only on the right side
93 else if($change['tag'] == 'insert') {
94 foreach($change['changed']['lines'] as $no => $line) {
95 $toLine = $change['changed']['offset'] + $no + 1;
96 $html .= '<tr>';
97 $html .= '<th>&nbsp;</th>';
98 $html .= '<td class="Left">&nbsp;</td>';
99 $html .= '<th>'.$toLine.'</th>';
100 $html .= '<td class="Right"><ins>'.$line.'</ins>&nbsp;</td>';
101 $html .= '</tr>';
102 }
103 }
104 // Show deleted lines only on the left side
105 else if($change['tag'] == 'delete') {
106 foreach($change['base']['lines'] as $no => $line) {
107 $fromLine = $change['base']['offset'] + $no + 1;
108 $html .= '<tr>';
109 $html .= '<th>'.$fromLine.'</th>';
110 $html .= '<td class="Left"><del>'.$line.'</del>&nbsp;</td>';
111 $html .= '<th>&nbsp;</th>';
112 $html .= '<td class="Right">&nbsp;</td>';
113 $html .= '</tr>';
114 }
115 }
116 // Show modified lines on both sides
117 else if($change['tag'] == 'replace') {
118 if(count($change['base']['lines']) >= count($change['changed']['lines'])) {
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 .= '<td class="Left"><span>'.$line.'</span>&nbsp;</td>';
124 if(!isset($change['changed']['lines'][$no])) {
125 $toLine = '&nbsp;';
126 $changedLine = '&nbsp;';
127 }
128 else {
129 $toLine = $change['base']['offset'] + $no + 1;
130 $changedLine = '<span>'.$change['changed']['lines'][$no].'</span>';
131 }
132 $html .= '<th>'.$toLine.'</th>';
133 $html .= '<td class="Right">'.$changedLine.'</td>';
134 $html .= '</tr>';
135 }
136 }
137 else {
138 foreach($change['changed']['lines'] as $no => $changedLine) {
139 if(!isset($change['base']['lines'][$no])) {
140 $fromLine = '&nbsp;';
141 $line = '&nbsp;';
142 }
143 else {
144 $fromLine = $change['base']['offset'] + $no + 1;
145 $line = '<span>'.$change['base']['lines'][$no].'</span>';
146 }
147 $html .= '<tr>';
148 $html .= '<th>'.$fromLine.'</th>';
149 $html .= '<td class="Left"><span>'.$line.'</span>&nbsp;</td>';
150 $toLine = $change['changed']['offset'] + $no + 1;
151 $html .= '<th>'.$toLine.'</th>';
152 $html .= '<td class="Right">'.$changedLine.'</td>';
153 $html .= '</tr>';
154 }
155 }
156 }
157 $html .= '</tbody>';
158 }
159 }
160 $html .= '</table>';
161 return $html;
162 }
163 }