PluginProbe
WP Reset / 1.77
WP Reset v1.77
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 / Inline.php

Inline.php in WP Reset 1.77, at libs/diff/Renderer/Html/Inline.php

144 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Inline 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 WPR_Diff_Renderer_Html_Inline extends WPR_Diff_Renderer_Html_Array
46 {
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 }
60
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 }
80
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 }
127
128 foreach($change['changed']['lines'] as $no => $line) {
129 $toLine = $change['changed']['offset'] + $no + 1;
130 $html .= '<tr>';
131 $html .= '<th>&nbsp;</th>';
132 $html .= '<th>'.$toLine.'</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 }
143 }
144