1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Theme function for a header line in the diff. |
4
|
|
|
*/ |
5
|
|
|
function diff_header_line($vars) { |
6
|
|
|
return '<strong>Line ' . $vars['lineno']. '</strong>'; |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
function check_plain($text) { |
10
|
|
|
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Theme function for a content line in the diff. |
15
|
|
|
*/ |
16
|
|
|
function diff_content_line($vars) { |
17
|
|
|
return '<div>'. $vars['line'] .'</div>'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Theme function for an empty line in the diff. |
22
|
|
|
*/ |
23
|
|
|
function diff_empty_line($vars) { |
24
|
|
|
return $vars['line']; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Diff formatter for Ariadne |
29
|
|
|
* @private |
30
|
|
|
* @subpackage DifferenceEngine |
31
|
|
|
*/ |
32
|
|
|
class AriadneDiffFormatter extends DiffFormatter { |
33
|
|
|
|
34
|
|
|
var $rows; |
35
|
|
|
|
36
|
|
|
function __construct() { |
37
|
|
|
$this->leading_context_lines = 2; |
38
|
|
|
$this->trailing_context_lines = 2; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function _start_diff() { |
42
|
|
|
$this->rows = array(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function _end_diff() { |
46
|
|
|
return $this->rows; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function _block_header($xbeg, $xlen, $ybeg, $ylen) { |
50
|
|
|
return array( |
51
|
|
|
array( |
52
|
|
|
'data' => diff_header_line(array('lineno' => $xbeg)), |
53
|
|
|
'colspan' => 2, |
54
|
|
|
), |
55
|
|
|
array( |
56
|
|
|
'data' => diff_header_line(array('lineno' => $ybeg)), |
57
|
|
|
'colspan' => 2, |
58
|
|
|
) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function _start_block($header) { |
63
|
|
|
if ($this->show_header) { |
64
|
|
|
$this->rows[] = $header; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function _end_block() { |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function _lines($lines, $prefix=' ', $color='white') { |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Note: you should HTML-escape parameter before calling this. |
76
|
|
|
*/ |
77
|
|
|
function addedLine($line) { |
78
|
|
|
return array( |
79
|
|
|
'+', |
80
|
|
|
array( |
81
|
|
|
'data' => diff_content_line(array('line' => $line)), |
82
|
|
|
'class' => 'diff-addedline', |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Note: you should HTML-escape parameter before calling this. |
89
|
|
|
*/ |
90
|
|
|
function deletedLine($line) { |
91
|
|
|
return array( |
92
|
|
|
'-', |
93
|
|
|
array( |
94
|
|
|
'data' => diff_content_line(array('line' => $line)), |
95
|
|
|
'class' => 'diff-deletedline', |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Note: you should HTML-escape parameter before calling this. |
102
|
|
|
*/ |
103
|
|
|
function contextLine($line) { |
104
|
|
|
return array( |
105
|
|
|
' ', |
106
|
|
|
array( |
107
|
|
|
'data' => diff_content_line(array('line' => $line)), |
108
|
|
|
'class' => 'diff-context', |
109
|
|
|
) |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
function emptyLine() { |
114
|
|
|
return array( |
115
|
|
|
' ', |
116
|
|
|
diff_empty_line(array('line' => ' ')), |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
function _added($lines) { |
121
|
|
View Code Duplication |
foreach ($lines as $line) { |
122
|
|
|
$this->rows[] = array_merge($this->emptyLine(), $this->addedLine(check_plain($line))); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
function _deleted($lines) { |
127
|
|
View Code Duplication |
foreach ($lines as $line) { |
128
|
|
|
$this->rows[] = array_merge($this->deletedLine(check_plain($line)), $this->emptyLine()); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
function _context($lines) { |
133
|
|
|
foreach ($lines as $line) { |
134
|
|
|
$this->rows[] = array_merge($this->contextLine(check_plain($line)), $this->contextLine(check_plain($line))); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
function _changed($orig, $closing) { |
139
|
|
|
$diff = new WordLevelDiff($orig, $closing); |
140
|
|
|
$del = $diff->orig(); |
141
|
|
|
$add = $diff->closing(); |
142
|
|
|
|
143
|
|
|
// Notice that WordLevelDiff returns HTML-escaped output. |
144
|
|
|
// Hence, we will be calling addedLine/deletedLine without HTML-escaping. |
145
|
|
|
|
146
|
|
|
while ($line = array_shift($del)) { |
147
|
|
|
$aline = array_shift( $add ); |
148
|
|
|
$this->rows[] = array_merge($this->deletedLine($line), $this->addedLine($aline)); |
149
|
|
|
} |
150
|
|
|
foreach ($add as $line) { // If any leftovers |
151
|
|
|
$this->rows[] = array_merge($this->emptyLine(), $this->addedLine($line)); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.