1
|
|
|
<?php |
2
|
|
|
global $AR; |
3
|
|
|
require_once($AR->dir->install."/lib/includes/diff/DiffEngine.php"); |
4
|
|
|
require_once($AR->dir->install."/lib/includes/diff/ariadne.diff.inc"); |
5
|
|
|
|
6
|
|
|
ar_pinp::allow( 'ar_beta_diff' ); |
7
|
|
|
|
8
|
|
|
class ar_beta_diff extends arBase { |
9
|
|
|
public static function diff ($a, $b){ |
10
|
|
|
$a = is_array($a) ? $a : explode("\n", $a); |
11
|
|
|
$b = is_array($b) ? $b : explode("\n", $b); |
12
|
|
|
|
13
|
|
|
$diff = new Diff($a, $b); |
14
|
|
|
|
15
|
|
|
if ($diff) { |
16
|
|
|
$formatter = new AriadneDiffFormatter(); |
17
|
|
|
$result = $formatter->format($diff); |
18
|
|
|
|
19
|
|
|
$rows = ar_html::nodes(); |
20
|
|
|
foreach ($result as $line) { |
|
|
|
|
21
|
|
|
$cells = ar_html::nodes(); |
22
|
|
|
foreach ($line as $content) { |
23
|
|
|
if (is_array($content)) { |
24
|
|
|
$options = array(); |
25
|
|
|
if ($content['class']) { |
26
|
|
|
$options['class'] = $content['class']; |
27
|
|
|
} |
28
|
|
|
if ($content['colspan']) { |
29
|
|
|
$options['colspan'] = $content['colspan']; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$cell = ar_html::tag("td", $options, $content['data']); |
33
|
|
|
$cells[] = $cell; |
34
|
|
|
} else { |
35
|
|
|
$cells[] = ar_html::tag("td", $content); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
$rows[] = ar_html::tag("tr", $cells); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if (count($rows)) { |
42
|
|
|
$table = ar_html::tag("table", array("class" => "diff"), $rows); |
43
|
|
|
$table->insertBefore(ar_html::tag("col", array("class" => "content")), $table->firstChild); |
44
|
|
|
$table->insertBefore(ar_html::tag("col"), $table->firstChild); |
45
|
|
|
$table->insertBefore(ar_html::tag("col", array("class" => "content")), $table->firstChild); |
46
|
|
|
$table->insertBefore(ar_html::tag("col"), $table->firstChild); |
47
|
|
|
|
48
|
|
|
return $table; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function style () { |
54
|
|
|
$css = ar_css::stylesheet() |
55
|
|
|
->import(" |
56
|
|
|
html.js .diff-js-hidden { display:none; } |
57
|
|
|
.diff-inline-metadata { |
58
|
|
|
padding:4px; |
59
|
|
|
border:1px solid #ddd; |
60
|
|
|
background:#fff; |
61
|
|
|
margin:0px 0px 10px; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
.diff-inline-legend { font-size:11px; } |
65
|
|
|
|
66
|
|
|
.diff-inline-legend span, |
67
|
|
|
.diff-inline-legend label { margin-right:5px; } |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Inline diff markup |
71
|
|
|
*/ |
72
|
|
|
span.diff-deleted { color:#ccc; } |
73
|
|
|
span.diff-deleted img { border: solid 2px #ccc; } |
74
|
|
|
span.diff-changed { background:#ffb; } |
75
|
|
|
span.diff-changed img { border:solid 2px #ffb; } |
76
|
|
|
span.diff-added { background:#cfc; } |
77
|
|
|
span.diff-added img { border: solid 2px #cfc; } |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Traditional split diff theming |
81
|
|
|
*/ |
82
|
|
|
table.diff { |
83
|
|
|
border-spacing: 0px; |
84
|
|
|
border-collapse: collapse; |
85
|
|
|
margin-bottom: 20px; |
86
|
|
|
width: 100%; |
87
|
|
|
table-layout: fixed; |
88
|
|
|
} |
89
|
|
|
table.diff col { |
90
|
|
|
width: 1.4em; |
91
|
|
|
} |
92
|
|
|
table.diff col.content { |
93
|
|
|
width: 50%; |
94
|
|
|
} |
95
|
|
|
table.diff tr.even, table.diff tr.odd { |
96
|
|
|
background-color: inherit; |
97
|
|
|
border: none; |
98
|
|
|
} |
99
|
|
|
td.diff-prevlink { |
100
|
|
|
text-align: left; |
101
|
|
|
} |
102
|
|
|
td.diff-nextlink { |
103
|
|
|
text-align: right; |
104
|
|
|
} |
105
|
|
|
td.diff-section-title, div.diff-section-title { |
106
|
|
|
background-color: #f0f0ff; |
107
|
|
|
font-size: 0.83em; |
108
|
|
|
font-weight: bold; |
109
|
|
|
padding: 0.1em 1em; |
110
|
|
|
} |
111
|
|
|
table.diff td { |
112
|
|
|
vertical-align: top; |
113
|
|
|
border-bottom: 1px solid #CCCCCC; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
td.diff-deletedline { |
117
|
|
|
background-color: #ffa; |
118
|
|
|
width: 50%; |
119
|
|
|
} |
120
|
|
|
td.diff-addedline { |
121
|
|
|
background-color: #afa; |
122
|
|
|
width: 50%; |
123
|
|
|
} |
124
|
|
|
td.diff-context { |
125
|
|
|
background-color: #fafafa; |
126
|
|
|
} |
127
|
|
|
span.diffchange { |
128
|
|
|
color: #f00; |
129
|
|
|
font-weight: bold; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
table.diff col.diff-marker { |
133
|
|
|
width: 1.4em; |
134
|
|
|
} |
135
|
|
|
table.diff col.diff-content { |
136
|
|
|
width: 50%; |
137
|
|
|
} |
138
|
|
|
table.diff th { |
139
|
|
|
padding-right: inherit; |
140
|
|
|
} |
141
|
|
|
table.diff td div { |
142
|
|
|
overflow: auto; |
143
|
|
|
padding: 0.1ex 0.5em; |
144
|
|
|
word-wrap: break-word; |
145
|
|
|
} |
146
|
|
|
table.diff td { |
147
|
|
|
padding: 0.1ex 0.4em; |
148
|
|
|
} |
149
|
|
|
"); |
150
|
|
|
|
151
|
|
|
return $css; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|