1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
htmLawedTest.php, 28 May 2013 |
5
|
|
|
htmLawed 1.1.22, 5 March 2016 |
6
|
|
|
Copyright Santosh Patnaik |
7
|
|
|
Dual licensed with LGPL 3 and GPL 2+ |
8
|
|
|
A PHP Labware internal utility - http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed |
9
|
|
|
|
10
|
|
|
Test htmLawed; user provides text input; input and processed input are shown as highlighted code and rendered HTML; also shown are execution time and peak memory usage |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
// config |
14
|
|
|
$_errs = 0; // display PHP errors |
15
|
|
|
$_limit = 8000; // input character limit |
16
|
|
|
|
17
|
|
|
// more config |
18
|
|
|
$_hlimit = 1000; // input character limit for showing hexdumps |
19
|
|
|
$_hilite = 1; // 0 turns off slow Javascript-based code-highlighting, e.g., if $_limit is high |
20
|
|
|
$_w3c_validate = 1; // 1 to show buttons to send input/output to w3c validator |
21
|
|
|
$_sid = 'sid'; // session name; alphanum. |
22
|
|
|
$_slife = 30; // session life in min. |
23
|
|
|
|
24
|
|
|
// errors |
25
|
|
|
error_reporting(E_ALL | (defined('E_STRICT') ? E_STRICT : 0)); |
26
|
|
|
ini_set('display_errors', $_errs); |
27
|
|
|
|
28
|
|
|
// session |
29
|
|
|
session_name($_sid); |
30
|
|
|
session_cache_limiter('private'); |
31
|
|
|
session_cache_expire($_slife); |
32
|
|
|
ini_set('session.gc_maxlifetime', $_slife * 60); |
33
|
|
|
ini_set('session.use_only_cookies', 1); |
34
|
|
|
ini_set('session.cookie_lifetime', 0); |
35
|
|
|
session_start(); |
36
|
|
|
if (!isset($_SESSION['token'])) { |
37
|
|
|
$_SESSION['token'] = md5(uniqid(rand(), 1)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// slashes |
41
|
|
|
if (get_magic_quotes_gpc()) { |
42
|
|
|
foreach ($_POST as $k => $v) { |
43
|
|
|
$_POST[$k] = stripslashes($v); |
44
|
|
|
} |
45
|
|
|
ini_set('magic_quotes_gpc', 0); |
46
|
|
|
} |
47
|
|
|
if (get_magic_quotes_runtime()) { |
48
|
|
|
set_magic_quotes_runtime(0); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$_POST['enc'] = (isset($_POST['enc']) and preg_match('`^[-\w]+$`', $_POST['enc'])) ? $_POST['enc'] : 'utf-8'; |
52
|
|
|
|
53
|
|
|
// token for anti-CSRF |
54
|
|
|
if (count($_POST)) { |
55
|
|
|
if ((empty($_GET['pre']) and ((!empty($_POST['token']) and !empty($_SESSION['token']) and $_POST['token'] != $_SESSION['token']) or empty($_POST[$_sid]) or $_POST[$_sid] != session_id() or empty($_COOKIE[$_sid]) or $_COOKIE[$_sid] != session_id())) or ($_POST[$_sid] != session_id())) { |
56
|
|
|
$_POST = array('enc' => 'utf-8'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
if (empty($_GET['pre'])) { |
60
|
|
|
$_SESSION['token'] = md5(uniqid(rand(), 1)); |
61
|
|
|
$token = $_SESSION['token']; |
62
|
|
|
session_regenerate_id(1); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// compress |
66
|
|
|
if (function_exists('gzencode') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && preg_match('`gzip|deflate`i', $_SERVER['HTTP_ACCEPT_ENCODING']) && !ini_get('zlib.output_compression')) { |
67
|
|
|
ob_start('ob_gzhandler'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// HTM for unprocessed |
71
|
|
|
if (isset($_POST['inputH'])) { |
72
|
|
|
echo '<html><head><title>htmLawed test: HTML view of unprocessed input</title></head><body style="margin:0; padding: 0;"><p style="background-color: black; color: white; padding: 2px;"> Rendering of unprocessed input without an HTML doctype or charset declaration <small><a style="color: white; text-decoration: none;" href="1" onclick="javascript:window.close(this); return false;">close window</a> | <a style="color: white; text-decoration: none;" href="htmLawedTest.php" onclick="javascript: window.open(\'htmLawedTest.php\', \'hlmain\'); window.close(this); return false;">htmLawed test page</a></small></p><div>', $_POST['inputH'], '</div></body></html>'; |
73
|
|
|
exit; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// main |
77
|
|
|
$_POST['text'] = isset($_POST['text']) ? $_POST['text'] : 'text to process; < '.$_limit.' characters'.($_hlimit ? ' (for binary hexdump view, < '.$_hlimit.')' : ''); |
78
|
|
|
$do = (!empty($_POST[$_sid]) && isset($_POST['text'][0]) && !isset($_POST['text'][$_limit])) ? 1 : 0; |
79
|
|
|
$limit_exceeded = isset($_POST['text'][$_limit]) ? 1 : 0; |
80
|
|
|
$pre_mem = memory_get_usage(); |
81
|
|
|
$validation = (!empty($_POST[$_sid]) and isset($_POST['w3c_validate'][0])) ? 1 : 0; |
82
|
|
|
include './htmLawed.php'; |
83
|
|
|
|
84
|
|
|
function format($t) { |
85
|
|
|
$t = "\n".str_replace(array("\t", "\r\n", "\r", '&', '<', '>', "\n"), array(' ', "\n", "\n", '&', '<', '>', "<span class=\"newline\">¬</span><br />\n"), $t); |
86
|
|
|
return str_replace(array('<br />', "\n ", ' '), array("\n<br />\n", "\n ", ' '), $t); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function hexdump($d) { |
90
|
|
|
// Mainly by Aidan Lister <[email protected]>, Peter Waller <[email protected]> |
91
|
|
|
$hexi = ''; |
92
|
|
|
$ascii = ''; |
93
|
|
|
ob_start(); |
94
|
|
|
echo '<pre>'; |
95
|
|
|
$offset = 0; |
96
|
|
|
$len = strlen($d); |
97
|
|
|
for ($i = $j = 0; $i < $len; $i++) { |
98
|
|
|
// Convert to hexidecimal |
99
|
|
|
$hexi .= sprintf("%02X ", ord($d[$i])); |
100
|
|
|
// Replace non-viewable bytes with '.' |
101
|
|
|
if (ord($d[$i]) >= 32) { |
102
|
|
|
$ascii .= htmlspecialchars($d[$i]); |
103
|
|
|
} else { |
104
|
|
|
$ascii .= '.'; |
105
|
|
|
} |
106
|
|
|
// Add extra column spacing |
107
|
|
|
if ($j == 7) { |
108
|
|
|
$hexi .= ' '; |
109
|
|
|
$ascii .= ' '; |
110
|
|
|
} |
111
|
|
|
// Add row |
112
|
|
|
if (++$j == 16 || $i == $len - 1) { |
113
|
|
|
// Join the hexi / ascii output |
114
|
|
|
echo sprintf("%04X %-49s %s", $offset, $hexi, $ascii); |
115
|
|
|
// Reset vars |
116
|
|
|
$hexi = $ascii = ''; |
117
|
|
|
$offset += 16; |
118
|
|
|
$j = 0; |
119
|
|
|
// Add newline |
120
|
|
|
if ($i !== $len - 1) { |
121
|
|
|
echo "\n"; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
echo '</pre>'; |
126
|
|
|
$o = ob_get_contents(); |
127
|
|
|
ob_end_clean(); |
128
|
|
|
return $o; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
?> |
132
|
|
|
|
133
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
134
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
135
|
|
|
<html lang="en" xml:lang="en"> |
136
|
|
|
<head> |
137
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
138
|
|
|
<meta name="description" content="htmLawed <?php echo hl_version(); ?> test page"/> |
139
|
|
|
<style type="text/css"><!-- /*--><![CDATA[/*><!--*/ |
140
|
|
|
a, a.resizer { |
141
|
|
|
text-decoration: none; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
a:hover, a.resizer:hover { |
145
|
|
|
color: red; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
a.resizer { |
149
|
|
|
color: green; |
150
|
|
|
float: right; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
body { |
154
|
|
|
background-color: #efefef; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
body, button, div, html, input, p { |
158
|
|
|
font-size: 13px; |
159
|
|
|
font-family: 'Lucida grande', Verdana, Arial, Helvetica, sans-serif; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
button, input { |
163
|
|
|
font-size: 85%; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
div.help { |
167
|
|
|
border-top: 1px dotted gray; |
168
|
|
|
margin-top: 15px; |
169
|
|
|
padding-top: 15px; |
170
|
|
|
color: #999999; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
#inputC, #inputD, #inputF, #inputR, #outputD, #outputF, #outputH, #outputR, #settingF, #diff { |
174
|
|
|
display: block; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
#inputC, #settingF { |
178
|
|
|
background-color: white; |
179
|
|
|
border: 1px gray solid; |
180
|
|
|
padding: 3px; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
#inputC li { |
184
|
|
|
margin: 0; |
185
|
|
|
padding: 0; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
#inputC ul { |
189
|
|
|
margin: 0; |
190
|
|
|
padding: 0; |
191
|
|
|
margin-left: 14px; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
#inputC input { |
195
|
|
|
margin: 0; |
196
|
|
|
margin-left: 2px; |
197
|
|
|
margin-right: 2px; |
198
|
|
|
padding: 1px; |
199
|
|
|
vertical-align: middle; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
#inputD { |
203
|
|
|
overflow: auto; |
204
|
|
|
background-color: #ffff99; |
205
|
|
|
border: 1px #cc9966 solid; |
206
|
|
|
padding: 3px; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
#inputR { |
210
|
|
|
overflow: auto; |
211
|
|
|
background-color: #ffffcc; |
212
|
|
|
border: 1px #ffcc99 solid; |
213
|
|
|
padding: 3px; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
#inputC, #settingF, #inputD, #inputR, #outputD, #outputR, #diff, textarea { |
217
|
|
|
font-size: 100%; |
218
|
|
|
font-family: 'Bitstream vera sans mono', 'courier new', 'courier', monospace; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
#outputD { |
222
|
|
|
overflow: auto; |
223
|
|
|
background-color: #99ffcc; |
224
|
|
|
border: 1px #66cc99 solid; |
225
|
|
|
padding: 3px; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
#diff { |
229
|
|
|
overflow: auto; |
230
|
|
|
background-color: white; |
231
|
|
|
border: 1px #dcdcdc solid; |
232
|
|
|
padding: 3px; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
#outputH { |
236
|
|
|
overflow: auto; |
237
|
|
|
background-color: white; |
238
|
|
|
padding: 3px; |
239
|
|
|
border: 1px #dcdcdc solid; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
#outputR { |
243
|
|
|
overflow: auto; |
244
|
|
|
background-color: #ccffcc; |
245
|
|
|
border: 1px #99cc99 solid; |
246
|
|
|
padding: 3px; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
span.cmtcdata { |
250
|
|
|
color: orange; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
span.ctag { |
254
|
|
|
color: red; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
span.ent { |
258
|
|
|
border-bottom: 1px dotted #999999; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
span.etag { |
262
|
|
|
color: purple; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
span.help { |
266
|
|
|
color: #999999; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
span.newline { |
270
|
|
|
color: #dcdcdc; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
span.notice { |
274
|
|
|
color: green; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
span.otag { |
278
|
|
|
color: blue; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
#topmost { |
282
|
|
|
margin: auto; |
283
|
|
|
width: 98%; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/*]]>*/ |
287
|
|
|
--></style> |
288
|
|
|
<script type="text/javascript"><!--//--> |
289
|
|
|
<![CDATA[//><!-- |
290
|
|
|
window.name = 'hlmain'; |
291
|
|
|
function hl(i) { |
292
|
|
|
<?php if (!$_hilite) { |
293
|
|
|
echo 'return;'; |
294
|
|
|
}?> |
295
|
|
|
var e = document.getElementById(i); |
296
|
|
|
if (!e) { |
297
|
|
|
return; |
298
|
|
|
} |
299
|
|
|
run(e, '</[a-z1-6]+>', 'ctag'); |
300
|
|
|
run(e, '<[a-z]+(?:[^>]*)/>', 'etag'); |
301
|
|
|
run(e, '<[a-z1-6]+(?:[^>]*)>', 'otag'); |
302
|
|
|
run(e, '&[#a-z0-9]+;', 'ent'); |
303
|
|
|
run(e, '<!(?:(?:--(?:.|\n)*?--)|(?:\\[CDATA\\[(?:.|\n)*?\\]\\]))>', 'cmtcdata'); |
304
|
|
|
} |
305
|
|
|
function sndProc() { |
306
|
|
|
var f = document.getElementById('testform'); |
307
|
|
|
if (!f) { |
308
|
|
|
return; |
309
|
|
|
} |
310
|
|
|
var e = document.createElement('input'); |
311
|
|
|
e.type = 'hidden'; |
312
|
|
|
e.name = '<?php echo htmlspecialchars($_sid); ?>'; |
313
|
|
|
e.id = '<?php echo htmlspecialchars($_sid); ?>'; |
314
|
|
|
e.value = readCookie('<?php echo htmlspecialchars($_sid); ?>'); |
315
|
|
|
f.appendChild(e); |
316
|
|
|
f.submit(); |
317
|
|
|
} |
318
|
|
|
function readCookie(n) { |
319
|
|
|
var ne = n + '='; |
320
|
|
|
var ca = document.cookie.split(';'); |
321
|
|
|
for (var i = 0; i < ca.length; i++) { |
322
|
|
|
var c = ca[i]; |
323
|
|
|
while (c.charAt(0) == ' ') { |
324
|
|
|
c = c.substring(1, c.length); |
325
|
|
|
} |
326
|
|
|
if (c.indexOf(ne) == 0) { |
327
|
|
|
return c.substring(ne.length, c.length); |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
return null; |
331
|
|
|
} |
332
|
|
|
function run(e, q, c) { |
333
|
|
|
var q = new RegExp(q); |
334
|
|
|
if (e.firstChild == null) { |
335
|
|
|
var m = q.exec(e.data); |
336
|
|
|
if (m) { |
337
|
|
|
var v = m[0]; |
338
|
|
|
var k2 = e.splitText(m.index); |
339
|
|
|
var k3 = k2.splitText(v.length); |
340
|
|
|
var s = e.ownerDocument.createElement('span'); |
341
|
|
|
e.parentNode.replaceChild(s, k2); |
342
|
|
|
s.className = c; |
343
|
|
|
s.appendChild(k2); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
for (var k = e.firstChild; k != null; k = k.nextSibling) { |
347
|
|
|
if (k.nodeType == 3) { |
348
|
|
|
var m = q.exec(k.data); |
349
|
|
|
if (m) { |
350
|
|
|
var v = m[0]; |
351
|
|
|
var k2 = k.splitText(m.index); |
352
|
|
|
var k3 = k2.splitText(v.length); |
353
|
|
|
var s = k.ownerDocument.createElement('span'); |
354
|
|
|
k.parentNode.replaceChild(s, k2); |
355
|
|
|
s.className = c; |
356
|
|
|
s.appendChild(k2); |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
else if (c == 'ent' && k.nodeType == 1) { |
360
|
|
|
var d = k.firstChild; |
361
|
|
|
if (d) { |
362
|
|
|
var m = q.exec(d.data); |
363
|
|
|
if (m) { |
364
|
|
|
var v = m[0]; |
365
|
|
|
var d2 = d.splitText(m.index); |
366
|
|
|
var d3 = d2.splitText(v.length); |
367
|
|
|
var s = d.ownerDocument.createElement('span'); |
368
|
|
|
d.parentNode.replaceChild(s, d2); |
369
|
|
|
s.className = c; |
370
|
|
|
s.appendChild(d2); |
371
|
|
|
} |
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
function toggle(i) { |
377
|
|
|
var e = document.getElementById(i); |
378
|
|
|
if (!e) { |
379
|
|
|
return; |
380
|
|
|
} |
381
|
|
|
if (e.style) { |
382
|
|
|
var a = e.style.display; |
383
|
|
|
if (a == 'block') { |
384
|
|
|
e.style.display = 'none'; |
385
|
|
|
return; |
386
|
|
|
} |
387
|
|
|
if (a == 'none') { |
388
|
|
|
e.style.display = 'block'; |
389
|
|
|
} |
390
|
|
|
else { |
391
|
|
|
e.style.display = 'none'; |
392
|
|
|
} |
393
|
|
|
return; |
394
|
|
|
} |
395
|
|
|
var a = e.visibility; |
396
|
|
|
if (a == 'hidden') { |
397
|
|
|
e.visibility = 'show'; |
398
|
|
|
return; |
399
|
|
|
} |
400
|
|
|
if (a == 'show') { |
401
|
|
|
e.visibility = 'hidden'; |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
function sndUnproc() { |
405
|
|
|
var i = document.getElementById('text'); |
406
|
|
|
if (!i) { |
407
|
|
|
return; |
408
|
|
|
} |
409
|
|
|
i = i.value; |
410
|
|
|
var w = window.open('htmLawedTest.php?pre=1', 'hlprehtm'); |
411
|
|
|
var f = document.createElement('form'); |
412
|
|
|
f.enctype = 'application/x-www-form-urlencoded'; |
413
|
|
|
f.method = 'post'; |
414
|
|
|
f.acceptCharset = '<?php echo htmlspecialchars($_POST['enc']); ?>'; |
415
|
|
|
if (f.style) { |
416
|
|
|
f.style.display = 'none'; |
417
|
|
|
} |
418
|
|
|
else { |
419
|
|
|
f.visibility = 'hidden'; |
420
|
|
|
} |
421
|
|
|
f.innerHTML = '<p style="display:none;"><input style="display:none;" type="hidden" name="token" id="token" value="<?php echo $token; ?>" /><input style="display:none;" type="hidden" name="<?php echo htmlspecialchars($_sid); ?>" id="<?php echo htmlspecialchars($_sid); ?>" value="' + readCookie('<?php echo htmlspecialchars($_sid); ?>') + '" /></p>'; |
422
|
|
|
f.action = 'htmLawedTest.php?pre=1'; |
423
|
|
|
f.target = 'hlprehtm'; |
424
|
|
|
f.method = 'post'; |
425
|
|
|
var t = document.createElement('textarea'); |
426
|
|
|
t.name = 'inputH'; |
427
|
|
|
t.value = i; |
428
|
|
|
f.appendChild(t); |
429
|
|
|
var b = document.getElementsByTagName('body')[0]; |
430
|
|
|
b.appendChild(f); |
431
|
|
|
f.submit(); |
432
|
|
|
w.focus; |
433
|
|
|
} |
434
|
|
|
function sndValidn(id, type) { |
435
|
|
|
var i = document.getElementById(id); |
436
|
|
|
if (!i) { |
437
|
|
|
return; |
438
|
|
|
} |
439
|
|
|
i = i.value; |
440
|
|
|
var w = window.open('http://validator.w3.org/check', 'validate' + id + type); |
441
|
|
|
var f = document.createElement('form'); |
442
|
|
|
f.enctype = 'application/x-www-form-urlencoded'; |
443
|
|
|
f.method = 'post'; |
444
|
|
|
f.acceptCharset = '<?php echo htmlspecialchars($_POST['enc']); ?>'; |
445
|
|
|
if (f.style) { |
446
|
|
|
f.style.display = 'none'; |
447
|
|
|
} |
448
|
|
|
else { |
449
|
|
|
f.visibility = 'hidden'; |
450
|
|
|
} |
451
|
|
|
f.innerHTML = '<p style="display:none;"><input style="display:none;" type="hidden" name="prefill" id="prefill" value="1" /><input style="display:none;" type="hidden" name="prefill_doctype" id="prefill_doctype" value="' + type + '" /><input style="display:none;" type="hidden" name="group" id="group" value="1" /><input type="hidden" name="ss" id="ss" value="1" /></p>'; |
452
|
|
|
f.action = 'http://validator.w3.org/check'; |
453
|
|
|
f.target = 'validate' + id + type; |
454
|
|
|
var t = document.createElement('textarea'); |
455
|
|
|
t.name = 'fragment'; |
456
|
|
|
t.value = i; |
457
|
|
|
f.appendChild(t); |
458
|
|
|
var b = document.getElementsByTagName('body')[0]; |
459
|
|
|
b.appendChild(f); |
460
|
|
|
f.submit(); |
461
|
|
|
w.focus; |
462
|
|
|
} |
463
|
|
|
tRs = { |
464
|
|
|
formEl: null, |
465
|
|
|
resizeClass: 'textarea', |
466
|
|
|
adEv: function (t, ev, fn) { |
467
|
|
|
if (typeof document.addEventListener != 'undefined') { |
468
|
|
|
t.addEventListener(ev, fn, false); |
469
|
|
|
} else { |
470
|
|
|
t.attachEvent('on' + ev, fn); |
471
|
|
|
} |
472
|
|
|
}, |
473
|
|
|
rmEv: function (t, ev, fn) { |
474
|
|
|
if (typeof document.removeEventListener != 'undefined') { |
475
|
|
|
t.removeEventListener(ev, fn, false); |
476
|
|
|
} else { |
477
|
|
|
t.detachEvent('on' + ev, fn); |
478
|
|
|
} |
479
|
|
|
}, |
480
|
|
|
adBtn: function () { |
481
|
|
|
var textareas = document.getElementsByTagName('textarea'); |
482
|
|
|
for (var i = 0; i < textareas.length; i++) { |
483
|
|
|
var txtclass = textareas[i].className; |
484
|
|
|
if (txtclass.substring(0, tRs.resizeClass.length) == tRs.resizeClass || |
485
|
|
|
txtclass.substring(txtclass.length - tRs.resizeClass.length) == tRs.resizeClass) { |
486
|
|
|
var a = document.createElement('a'); |
487
|
|
|
a.appendChild(document.createTextNode("\u2195")); |
488
|
|
|
a.style.cursor = 'n-resize'; |
489
|
|
|
a.className = 'resizer'; |
490
|
|
|
a.title = 'click-drag to resize textarea' |
491
|
|
|
tRs.adEv(a, 'mousedown', tRs.initResize); |
492
|
|
|
textareas[i].parentNode.appendChild(a); |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
}, |
496
|
|
|
initResize: function (event) { |
497
|
|
|
if (typeof event == 'undefined') { |
498
|
|
|
event = window.event; |
499
|
|
|
} |
500
|
|
|
if (event.srcElement) { |
501
|
|
|
var target = event.srcElement.previousSibling; |
502
|
|
|
} else { |
503
|
|
|
var target = event.target.previousSibling; |
504
|
|
|
} |
505
|
|
|
if (target.nodeName.toLowerCase() == 'textarea' || (target.nodeName.toLowerCase() == 'input' && target.type == 'text')) { |
506
|
|
|
tRs.formEl = target; |
507
|
|
|
tRs.formEl.startHeight = tRs.formEl.clientHeight; |
508
|
|
|
tRs.formEl.startY = event.clientY; |
509
|
|
|
tRs.adEv(document, 'mousemove', tRs.resize); |
510
|
|
|
tRs.adEv(document, 'mouseup', tRs.stopResize); |
511
|
|
|
tRs.formEl.parentNode.style.cursor = 'n-resize'; |
512
|
|
|
tRs.formEl.style.cursor = 'n-resize'; |
513
|
|
|
try { |
514
|
|
|
event.preventDefault(); |
515
|
|
|
} catch (e) { |
516
|
|
|
} |
517
|
|
|
} |
518
|
|
|
}, |
519
|
|
|
resize: function (event) { |
520
|
|
|
if (typeof event == 'undefined') { |
521
|
|
|
event = window.event; |
522
|
|
|
} |
523
|
|
|
if (tRs.formEl.nodeName.toLowerCase() == 'textarea') { |
524
|
|
|
tRs.formEl.style.height = event.clientY - tRs.formEl.startY + tRs.formEl.startHeight + 'px'; |
525
|
|
|
} |
526
|
|
|
}, |
527
|
|
|
stopResize: function (event) { |
528
|
|
|
tRs.rmEv(document, 'mousedown', tRs.initResize); |
529
|
|
|
tRs.rmEv(document, 'mousemove', tRs.resize); |
530
|
|
|
tRs.formEl.style.cursor = 'text'; |
531
|
|
|
tRs.formEl.parentNode.style.cursor = 'auto'; |
532
|
|
|
return false; |
533
|
|
|
} |
534
|
|
|
}; |
535
|
|
|
tRs.adEv(window, 'load', tRs.adBtn); |
536
|
|
|
// Diff Match and Patch javascript code by Neil Fraser; Apache license 2.0; http://code.google.com/p/google-diff-match-patch/ |
537
|
|
|
(function () { |
538
|
|
|
function diff_match_patch() { |
539
|
|
|
this.Diff_Timeout = 1; |
540
|
|
|
this.Diff_EditCost = 4; |
541
|
|
|
this.Match_Threshold = 0.5; |
542
|
|
|
this.Match_Distance = 1E3; |
543
|
|
|
this.Patch_DeleteThreshold = 0.5; |
544
|
|
|
this.Patch_Margin = 4; |
545
|
|
|
this.Match_MaxBits = 32 |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
diff_match_patch.prototype.diff_main = function (a, b, c, d) { |
549
|
|
|
"undefined" == typeof d && (d = 0 >= this.Diff_Timeout ? Number.MAX_VALUE : (new Date).getTime() + 1E3 * this.Diff_Timeout); |
550
|
|
|
if (null == a || null == b)throw Error("Null input. (diff_main)"); |
551
|
|
|
if (a == b)return a ? [[0, a]] : []; |
552
|
|
|
"undefined" == typeof c && (c = !0); |
553
|
|
|
var e = c, f = this.diff_commonPrefix(a, b), c = a.substring(0, f), a = a.substring(f), b = b.substring(f), f = this.diff_commonSuffix(a, b), g = a.substring(a.length - f), a = a.substring(0, a.length - f), b = b.substring(0, b.length - f), a = this.diff_compute_(a, |
554
|
|
|
b, e, d); |
555
|
|
|
c && a.unshift([0, c]); |
556
|
|
|
g && a.push([0, g]); |
557
|
|
|
this.diff_cleanupMerge(a); |
558
|
|
|
return a |
559
|
|
|
}; |
560
|
|
|
diff_match_patch.prototype.diff_compute_ = function (a, b, c, d) { |
561
|
|
|
if (!a)return [[1, b]]; |
562
|
|
|
if (!b)return [[-1, a]]; |
563
|
|
|
var e = a.length > b.length ? a : b, f = a.length > b.length ? b : a, g = e.indexOf(f); |
564
|
|
|
if (-1 != g)return c = [[1, e.substring(0, g)], [0, f], [1, e.substring(g + f.length)]], a.length > b.length && (c[0][0] = c[2][0] = -1), c; |
565
|
|
|
if (1 == f.length)return [[-1, a], [1, b]]; |
566
|
|
|
return (e = this.diff_halfMatch_(a, b)) ? (f = e[0], a = e[1], g = e[2], b = e[3], e = e[4], f = this.diff_main(f, g, c, d), c = this.diff_main(a, b, c, d), f.concat([[0, e]], c)) : c && 100 < a.length && 100 < b.length ? this.diff_lineMode_(a, |
567
|
|
|
b, d) : this.diff_bisect_(a, b, d) |
568
|
|
|
}; |
569
|
|
|
diff_match_patch.prototype.diff_lineMode_ = function (a, b, c) { |
570
|
|
|
var d = this.diff_linesToChars_(a, b), a = d.chars1, b = d.chars2, d = d.lineArray, a = this.diff_main(a, b, !1, c); |
571
|
|
|
this.diff_charsToLines_(a, d); |
572
|
|
|
this.diff_cleanupSemantic(a); |
573
|
|
|
a.push([0, ""]); |
574
|
|
|
for (var e = d = b = 0, f = "", g = ""; b < a.length;) { |
575
|
|
|
switch (a[b][0]) { |
576
|
|
|
case 1: |
577
|
|
|
e++; |
578
|
|
|
g += a[b][1]; |
579
|
|
|
break; |
580
|
|
|
case -1: |
581
|
|
|
d++; |
582
|
|
|
f += a[b][1]; |
583
|
|
|
break; |
584
|
|
|
case 0: |
585
|
|
|
if (1 <= d && 1 <= e) { |
586
|
|
|
a.splice(b - d - e, d + e); |
587
|
|
|
b = b - d - e; |
588
|
|
|
d = this.diff_main(f, g, !1, c); |
589
|
|
|
for (e = d.length - 1; 0 <= e; e--)a.splice(b, 0, d[e]); |
590
|
|
|
b += d.length |
591
|
|
|
} |
592
|
|
|
d = e = 0; |
593
|
|
|
g = f = "" |
594
|
|
|
} |
595
|
|
|
b++ |
596
|
|
|
} |
597
|
|
|
a.pop(); |
598
|
|
|
return a |
599
|
|
|
}; |
600
|
|
|
diff_match_patch.prototype.diff_bisect_ = function (a, b, c) { |
601
|
|
|
for (var d = a.length, e = b.length, f = Math.ceil((d + e) / 2), g = f, h = 2 * f, j = Array(h), i = Array(h), k = 0; k < h; k++)j[k] = -1, i[k] = -1; |
602
|
|
|
j[g + 1] = 0; |
603
|
|
|
i[g + 1] = 0; |
604
|
|
|
for (var k = d - e, p = 0 != k % 2, q = 0, s = 0, o = 0, v = 0, u = 0; u < f && !((new Date).getTime() > c); u++) { |
605
|
|
|
for (var n = -u + q; n <= u - s; n += 2) { |
606
|
|
|
var l = g + n, m; |
607
|
|
|
m = n == -u || n != u && j[l - 1] < j[l + 1] ? j[l + 1] : j[l - 1] + 1; |
608
|
|
|
for (var r = m - n; m < d && r < e && a.charAt(m) == b.charAt(r);)m++, r++; |
609
|
|
|
j[l] = m; |
610
|
|
|
if (m > d)s += 2; else if (r > e)q += 2; else if (p && (l = g + k - n, 0 <= l && l < h && -1 != i[l])) { |
611
|
|
|
var t = d - i[l]; |
612
|
|
|
if (m >= |
613
|
|
|
t)return this.diff_bisectSplit_(a, b, m, r, c) |
614
|
|
|
} |
615
|
|
|
} |
616
|
|
|
for (n = -u + o; n <= u - v; n += 2) { |
617
|
|
|
l = g + n; |
618
|
|
|
t = n == -u || n != u && i[l - 1] < i[l + 1] ? i[l + 1] : i[l - 1] + 1; |
619
|
|
|
for (m = t - n; t < d && m < e && a.charAt(d - t - 1) == b.charAt(e - m - 1);)t++, m++; |
620
|
|
|
i[l] = t; |
621
|
|
|
if (t > d)v += 2; else if (m > e)o += 2; else if (!p && (l = g + k - n, 0 <= l && l < h && -1 != j[l] && (m = j[l], r = g + m - l, t = d - t, m >= t)))return this.diff_bisectSplit_(a, b, m, r, c) |
622
|
|
|
} |
623
|
|
|
} |
624
|
|
|
return [[-1, a], [1, b]] |
625
|
|
|
}; |
626
|
|
|
diff_match_patch.prototype.diff_bisectSplit_ = function (a, b, c, d, e) { |
627
|
|
|
var f = a.substring(0, c), g = b.substring(0, d), a = a.substring(c), b = b.substring(d), f = this.diff_main(f, g, !1, e), e = this.diff_main(a, b, !1, e); |
628
|
|
|
return f.concat(e) |
629
|
|
|
}; |
630
|
|
|
diff_match_patch.prototype.diff_linesToChars_ = function (a, b) { |
631
|
|
|
function c(a) { |
632
|
|
|
for (var b = "", c = 0, f = -1, g = d.length; f < a.length - 1;) { |
633
|
|
|
f = a.indexOf("\n", c); |
634
|
|
|
-1 == f && (f = a.length - 1); |
635
|
|
|
var q = a.substring(c, f + 1), c = f + 1; |
636
|
|
|
(e.hasOwnProperty ? e.hasOwnProperty(q) : void 0 !== e[q]) ? b += String.fromCharCode(e[q]) : (b += String.fromCharCode(g), e[q] = g, d[g++] = q) |
637
|
|
|
} |
638
|
|
|
return b |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
var d = [], e = {}; |
642
|
|
|
d[0] = ""; |
643
|
|
|
var f = c(a), g = c(b); |
644
|
|
|
return {chars1: f, chars2: g, lineArray: d} |
645
|
|
|
}; |
646
|
|
|
diff_match_patch.prototype.diff_charsToLines_ = function (a, b) { |
647
|
|
|
for (var c = 0; c < a.length; c++) { |
648
|
|
|
for (var d = a[c][1], e = [], f = 0; f < d.length; f++)e[f] = b[d.charCodeAt(f)]; |
649
|
|
|
a[c][1] = e.join("") |
650
|
|
|
} |
651
|
|
|
}; |
652
|
|
|
diff_match_patch.prototype.diff_commonPrefix = function (a, b) { |
653
|
|
|
if (!a || !b || a.charAt(0) != b.charAt(0))return 0; |
654
|
|
|
for (var c = 0, d = Math.min(a.length, b.length), e = d, f = 0; c < e;)a.substring(f, e) == b.substring(f, e) ? f = c = e : d = e, e = Math.floor((d - c) / 2 + c); |
655
|
|
|
return e |
656
|
|
|
}; |
657
|
|
|
diff_match_patch.prototype.diff_commonSuffix = function (a, b) { |
658
|
|
|
if (!a || !b || a.charAt(a.length - 1) != b.charAt(b.length - 1))return 0; |
659
|
|
|
for (var c = 0, d = Math.min(a.length, b.length), e = d, f = 0; c < e;)a.substring(a.length - e, a.length - f) == b.substring(b.length - e, b.length - f) ? f = c = e : d = e, e = Math.floor((d - c) / 2 + c); |
660
|
|
|
return e |
661
|
|
|
}; |
662
|
|
|
diff_match_patch.prototype.diff_commonOverlap_ = function (a, b) { |
663
|
|
|
var c = a.length, d = b.length; |
664
|
|
|
if (0 == c || 0 == d)return 0; |
665
|
|
|
c > d ? a = a.substring(c - d) : c < d && (b = b.substring(0, c)); |
666
|
|
|
c = Math.min(c, d); |
667
|
|
|
if (a == b)return c; |
668
|
|
|
for (var d = 0, e = 1; ;) { |
669
|
|
|
var f = a.substring(c - e), f = b.indexOf(f); |
670
|
|
|
if (-1 == f)return d; |
671
|
|
|
e += f; |
672
|
|
|
if (0 == f || a.substring(c - e) == b.substring(0, e))d = e, e++ |
673
|
|
|
} |
674
|
|
|
}; |
675
|
|
|
diff_match_patch.prototype.diff_halfMatch_ = function (a, b) { |
676
|
|
|
function c(a, b, c) { |
677
|
|
|
for (var d = a.substring(c, c + Math.floor(a.length / 4)), e = -1, g = "", h, j, n, l; -1 != (e = b.indexOf(d, e + 1));) { |
678
|
|
|
var m = f.diff_commonPrefix(a.substring(c), b.substring(e)), r = f.diff_commonSuffix(a.substring(0, c), b.substring(0, e)); |
679
|
|
|
g.length < r + m && (g = b.substring(e - r, e) + b.substring(e, e + m), h = a.substring(0, c - r), j = a.substring(c + m), n = b.substring(0, e - r), l = b.substring(e + m)) |
680
|
|
|
} |
681
|
|
|
return 2 * g.length >= a.length ? [h, j, n, l, g] : null |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
if (0 >= this.Diff_Timeout)return null; |
685
|
|
|
var d = a.length > b.length ? a : b, e = a.length > b.length ? b : a; |
686
|
|
|
if (4 > d.length || 2 * e.length < d.length)return null; |
687
|
|
|
var f = this, g = c(d, e, Math.ceil(d.length / 4)), d = c(d, e, Math.ceil(d.length / 2)), h; |
688
|
|
|
if (!g && !d)return null; |
689
|
|
|
h = d ? g ? g[4].length > d[4].length ? g : d : d : g; |
690
|
|
|
var j; |
691
|
|
|
a.length > b.length ? (g = h[0], d = h[1], e = h[2], j = h[3]) : (e = h[0], j = h[1], g = h[2], d = h[3]); |
692
|
|
|
h = h[4]; |
693
|
|
|
return [g, d, e, j, h] |
694
|
|
|
}; |
695
|
|
|
diff_match_patch.prototype.diff_cleanupSemantic = function (a) { |
696
|
|
|
for (var b = !1, c = [], d = 0, e = null, f = 0, g = 0, h = 0, j = 0, i = 0; f < a.length;)0 == a[f][0] ? (c[d++] = f, g = j, h = i, i = j = 0, e = a[f][1]) : (1 == a[f][0] ? j += a[f][1].length : i += a[f][1].length, e && e.length <= Math.max(g, h) && e.length <= Math.max(j, i) && (a.splice(c[d - 1], 0, [-1, e]), a[c[d - 1] + 1][0] = 1, d--, d--, f = 0 < d ? c[d - 1] : -1, i = j = h = g = 0, e = null, b = !0)), f++; |
697
|
|
|
b && this.diff_cleanupMerge(a); |
698
|
|
|
this.diff_cleanupSemanticLossless(a); |
699
|
|
|
for (f = 1; f < a.length;) { |
700
|
|
|
if (-1 == a[f - 1][0] && 1 == a[f][0]) { |
701
|
|
|
b = a[f - 1][1]; |
702
|
|
|
c = a[f][1]; |
703
|
|
|
d = this.diff_commonOverlap_(b, c); |
704
|
|
|
e = this.diff_commonOverlap_(c, b); |
705
|
|
|
if (d >= e) { |
706
|
|
|
if (d >= b.length / 2 || d >= c.length / 2)a.splice(f, 0, [0, c.substring(0, d)]), a[f - 1][1] = b.substring(0, b.length - d), a[f + 1][1] = c.substring(d), f++ |
707
|
|
|
} else if (e >= b.length / 2 || e >= c.length / 2)a.splice(f, 0, [0, b.substring(0, e)]), a[f - 1][0] = 1, a[f - 1][1] = c.substring(0, c.length - e), a[f + 1][0] = -1, a[f + 1][1] = b.substring(e), f++; |
708
|
|
|
f++ |
709
|
|
|
} |
710
|
|
|
f++ |
711
|
|
|
} |
712
|
|
|
}; |
713
|
|
|
diff_match_patch.prototype.diff_cleanupSemanticLossless = function (a) { |
714
|
|
|
function b(a, b) { |
715
|
|
|
if (!a || !b)return 6; |
716
|
|
|
var c = a.charAt(a.length - 1), d = b.charAt(0), e = c.match(diff_match_patch.nonAlphaNumericRegex_), f = d.match(diff_match_patch.nonAlphaNumericRegex_), g = e && c.match(diff_match_patch.whitespaceRegex_), h = f && d.match(diff_match_patch.whitespaceRegex_), c = g && c.match(diff_match_patch.linebreakRegex_), d = h && d.match(diff_match_patch.linebreakRegex_), i = c && a.match(diff_match_patch.blanklineEndRegex_), j = d && b.match(diff_match_patch.blanklineStartRegex_); |
717
|
|
|
return i || j ? 5 : c || d ? 4 : e && !g && h ? 3 : g || h ? 2 : e || f ? 1 : 0 |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
for (var c = 1; c < a.length - 1;) { |
721
|
|
|
if (0 == a[c - 1][0] && 0 == a[c + 1][0]) { |
722
|
|
|
var d = a[c - 1][1], e = a[c][1], f = a[c + 1][1], g = this.diff_commonSuffix(d, e); |
723
|
|
|
if (g)var h = e.substring(e.length - g), d = d.substring(0, d.length - g), e = h + e.substring(0, e.length - g), f = h + f; |
724
|
|
|
for (var g = d, h = e, j = f, i = b(d, e) + b(e, f); e.charAt(0) === f.charAt(0);) { |
725
|
|
|
var d = d + e.charAt(0), e = e.substring(1) + f.charAt(0), f = f.substring(1), k = b(d, e) + b(e, f); |
726
|
|
|
k >= i && (i = k, g = d, h = e, j = f) |
727
|
|
|
} |
728
|
|
|
a[c - 1][1] != g && (g ? a[c - 1][1] = g : (a.splice(c - 1, 1), c--), a[c][1] = |
729
|
|
|
h, j ? a[c + 1][1] = j : (a.splice(c + 1, 1), c--)) |
730
|
|
|
} |
731
|
|
|
c++ |
732
|
|
|
} |
733
|
|
|
}; |
734
|
|
|
diff_match_patch.nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/; |
735
|
|
|
diff_match_patch.whitespaceRegex_ = /\s/; |
736
|
|
|
diff_match_patch.linebreakRegex_ = /[\r\n]/; |
737
|
|
|
diff_match_patch.blanklineEndRegex_ = /\n\r?\n$/; |
738
|
|
|
diff_match_patch.blanklineStartRegex_ = /^\r?\n\r?\n/; |
739
|
|
|
diff_match_patch.prototype.diff_cleanupEfficiency = function (a) { |
740
|
|
|
for (var b = !1, c = [], d = 0, e = null, f = 0, g = !1, h = !1, j = !1, i = !1; f < a.length;) { |
741
|
|
|
if (0 == a[f][0])a[f][1].length < this.Diff_EditCost && (j || i) ? (c[d++] = f, g = j, h = i, e = a[f][1]) : (d = 0, e = null), j = i = !1; else if (-1 == a[f][0] ? i = !0 : j = !0, e && (g && h && j && i || e.length < this.Diff_EditCost / 2 && 3 == g + h + j + i))a.splice(c[d - 1], 0, [-1, e]), a[c[d - 1] + 1][0] = 1, d--, e = null, g && h ? (j = i = !0, d = 0) : (d--, f = 0 < d ? c[d - 1] : -1, j = i = !1), b = !0; |
742
|
|
|
f++ |
743
|
|
|
} |
744
|
|
|
b && this.diff_cleanupMerge(a) |
745
|
|
|
}; |
746
|
|
|
diff_match_patch.prototype.diff_cleanupMerge = function (a) { |
747
|
|
|
a.push([0, ""]); |
748
|
|
|
for (var b = 0, c = 0, d = 0, e = "", f = "", g; b < a.length;)switch (a[b][0]) { |
749
|
|
|
case 1: |
750
|
|
|
d++; |
751
|
|
|
f += a[b][1]; |
752
|
|
|
b++; |
753
|
|
|
break; |
754
|
|
|
case -1: |
755
|
|
|
c++; |
756
|
|
|
e += a[b][1]; |
757
|
|
|
b++; |
758
|
|
|
break; |
759
|
|
|
case 0: |
760
|
|
|
1 < c + d ? (0 !== c && 0 !== d && (g = this.diff_commonPrefix(f, e), 0 !== g && (0 < b - c - d && 0 == a[b - c - d - 1][0] ? a[b - c - d - 1][1] += f.substring(0, g) : (a.splice(0, 0, [0, f.substring(0, g)]), b++), f = f.substring(g), e = e.substring(g)), g = this.diff_commonSuffix(f, e), 0 !== g && (a[b][1] = f.substring(f.length - g) + a[b][1], f = f.substring(0, f.length - |
761
|
|
|
g), e = e.substring(0, e.length - g))), 0 === c ? a.splice(b - d, c + d, [1, f]) : 0 === d ? a.splice(b - c, c + d, [-1, e]) : a.splice(b - c - d, c + d, [-1, e], [1, f]), b = b - c - d + (c ? 1 : 0) + (d ? 1 : 0) + 1) : 0 !== b && 0 == a[b - 1][0] ? (a[b - 1][1] += a[b][1], a.splice(b, 1)) : b++, c = d = 0, f = e = "" |
762
|
|
|
} |
763
|
|
|
"" === a[a.length - 1][1] && a.pop(); |
764
|
|
|
c = !1; |
765
|
|
|
for (b = 1; b < a.length - 1;)0 == a[b - 1][0] && 0 == a[b + 1][0] && (a[b][1].substring(a[b][1].length - a[b - 1][1].length) == a[b - 1][1] ? (a[b][1] = a[b - 1][1] + a[b][1].substring(0, a[b][1].length - a[b - 1][1].length), a[b + 1][1] = a[b - 1][1] + a[b + 1][1], a.splice(b - 1, 1), c = !0) : a[b][1].substring(0, |
766
|
|
|
a[b + 1][1].length) == a[b + 1][1] && (a[b - 1][1] += a[b + 1][1], a[b][1] = a[b][1].substring(a[b + 1][1].length) + a[b + 1][1], a.splice(b + 1, 1), c = !0)), b++; |
767
|
|
|
c && this.diff_cleanupMerge(a) |
768
|
|
|
}; |
769
|
|
|
diff_match_patch.prototype.diff_xIndex = function (a, b) { |
770
|
|
|
var c = 0, d = 0, e = 0, f = 0, g; |
771
|
|
|
for (g = 0; g < a.length; g++) { |
772
|
|
|
1 !== a[g][0] && (c += a[g][1].length); |
773
|
|
|
-1 !== a[g][0] && (d += a[g][1].length); |
774
|
|
|
if (c > b)break; |
775
|
|
|
e = c; |
776
|
|
|
f = d |
777
|
|
|
} |
778
|
|
|
return a.length != g && -1 === a[g][0] ? f : f + (b - e) |
779
|
|
|
}; |
780
|
|
|
diff_match_patch.prototype.diff_prettyHtml = function (a) { |
781
|
|
|
for (var b = [], c = /&/g, d = /</g, e = />/g, f = /\n/g, g = 0; g < a.length; g++) { |
782
|
|
|
var h = a[g][0], j = a[g][1], j = j.replace(c, "&").replace(d, "<").replace(e, ">").replace(f, "<span style=\"color: #dcdcdc;\">¬</span><br>"); |
783
|
|
|
switch (h) { |
784
|
|
|
case 1: |
785
|
|
|
b[g] = '<ins style="background:#ccffcc; text-decoration: none;">' + j + "</ins>"; |
786
|
|
|
break; |
787
|
|
|
case -1: |
788
|
|
|
b[g] = '<del style="background:#ffffcc; text-decoration: line-through; color: orange;">' + j + "</del>"; |
789
|
|
|
break; |
790
|
|
|
case 0: |
791
|
|
|
b[g] = "<span>" + j + "</span>" |
792
|
|
|
} |
793
|
|
|
} |
794
|
|
|
return b.join("") |
795
|
|
|
}; |
796
|
|
|
diff_match_patch.prototype.diff_text1 = function (a) { |
797
|
|
|
for (var b = [], c = 0; c < a.length; c++)1 !== a[c][0] && (b[c] = a[c][1]); |
798
|
|
|
return b.join("") |
799
|
|
|
}; |
800
|
|
|
diff_match_patch.prototype.diff_text2 = function (a) { |
801
|
|
|
for (var b = [], c = 0; c < a.length; c++)-1 !== a[c][0] && (b[c] = a[c][1]); |
802
|
|
|
return b.join("") |
803
|
|
|
}; |
804
|
|
|
diff_match_patch.prototype.diff_levenshtein = function (a) { |
805
|
|
|
for (var b = 0, c = 0, d = 0, e = 0; e < a.length; e++) { |
806
|
|
|
var f = a[e][0], g = a[e][1]; |
807
|
|
|
switch (f) { |
808
|
|
|
case 1: |
809
|
|
|
c += g.length; |
810
|
|
|
break; |
811
|
|
|
case -1: |
812
|
|
|
d += g.length; |
813
|
|
|
break; |
814
|
|
|
case 0: |
815
|
|
|
b += Math.max(c, d), d = c = 0 |
816
|
|
|
} |
817
|
|
|
} |
818
|
|
|
return b += Math.max(c, d) |
819
|
|
|
}; |
820
|
|
|
diff_match_patch.prototype.diff_toDelta = function (a) { |
821
|
|
|
for (var b = [], c = 0; c < a.length; c++)switch (a[c][0]) { |
822
|
|
|
case 1: |
823
|
|
|
b[c] = "+" + encodeURI(a[c][1]); |
824
|
|
|
break; |
825
|
|
|
case -1: |
826
|
|
|
b[c] = "-" + a[c][1].length; |
827
|
|
|
break; |
828
|
|
|
case 0: |
829
|
|
|
b[c] = "=" + a[c][1].length |
830
|
|
|
} |
831
|
|
|
return b.join("\t").replace(/%20/g, " ") |
832
|
|
|
}; |
833
|
|
|
diff_match_patch.prototype.diff_fromDelta = function (a, b) { |
834
|
|
|
for (var c = [], d = 0, e = 0, f = b.split(/\t/g), g = 0; g < f.length; g++) { |
835
|
|
|
var h = f[g].substring(1); |
836
|
|
|
switch (f[g].charAt(0)) { |
837
|
|
|
case "+": |
838
|
|
|
try { |
839
|
|
|
c[d++] = [1, decodeURI(h)] |
840
|
|
|
} catch (j) { |
841
|
|
|
throw Error("Illegal escape in diff_fromDelta: " + h); |
842
|
|
|
} |
843
|
|
|
break; |
844
|
|
|
case "-": |
845
|
|
|
case "=": |
846
|
|
|
var i = parseInt(h, 10); |
847
|
|
|
if (isNaN(i) || 0 > i)throw Error("Invalid number in diff_fromDelta: " + h); |
848
|
|
|
h = a.substring(e, e += i); |
849
|
|
|
"=" == f[g].charAt(0) ? c[d++] = [0, h] : c[d++] = [-1, h]; |
850
|
|
|
break; |
851
|
|
|
default: |
852
|
|
|
if (f[g])throw Error("Invalid diff operation in diff_fromDelta: " + |
853
|
|
|
f[g]); |
854
|
|
|
} |
855
|
|
|
} |
856
|
|
|
if (e != a.length)throw Error("Delta length (" + e + ") does not equal source text length (" + a.length + ")."); |
857
|
|
|
return c |
858
|
|
|
}; |
859
|
|
|
diff_match_patch.prototype.match_main = function (a, b, c) { |
860
|
|
|
if (null == a || null == b || null == c)throw Error("Null input. (match_main)"); |
861
|
|
|
c = Math.max(0, Math.min(c, a.length)); |
862
|
|
|
return a == b ? 0 : a.length ? a.substring(c, c + b.length) == b ? c : this.match_bitap_(a, b, c) : -1 |
863
|
|
|
}; |
864
|
|
|
diff_match_patch.prototype.match_bitap_ = function (a, b, c) { |
865
|
|
|
function d(a, d) { |
866
|
|
|
var e = a / b.length, g = Math.abs(c - d); |
867
|
|
|
return !f.Match_Distance ? g ? 1 : e : e + g / f.Match_Distance |
868
|
|
|
} |
869
|
|
|
|
870
|
|
|
if (b.length > this.Match_MaxBits)throw Error("Pattern too long for this browser."); |
871
|
|
|
var e = this.match_alphabet_(b), f = this, g = this.Match_Threshold, h = a.indexOf(b, c); |
872
|
|
|
-1 != h && (g = Math.min(d(0, h), g), h = a.lastIndexOf(b, c + b.length), -1 != h && (g = Math.min(d(0, h), g))); |
873
|
|
|
for (var j = 1 << b.length - 1, h = -1, i, k, p = b.length + a.length, q, s = 0; s < b.length; s++) { |
874
|
|
|
i = 0; |
875
|
|
|
for (k = p; i < k;)d(s, c + |
876
|
|
|
k) <= g ? i = k : p = k, k = Math.floor((p - i) / 2 + i); |
877
|
|
|
p = k; |
878
|
|
|
i = Math.max(1, c - k + 1); |
879
|
|
|
var o = Math.min(c + k, a.length) + b.length; |
880
|
|
|
k = Array(o + 2); |
881
|
|
|
for (k[o + 1] = (1 << s) - 1; o >= i; o--) { |
882
|
|
|
var v = e[a.charAt(o - 1)]; |
883
|
|
|
k[o] = 0 === s ? (k[o + 1] << 1 | 1) & v : (k[o + 1] << 1 | 1) & v | (q[o + 1] | q[o]) << 1 | 1 | q[o + 1]; |
884
|
|
|
if (k[o] & j && (v = d(s, o - 1), v <= g))if (g = v, h = o - 1, h > c)i = Math.max(1, 2 * c - h); else break |
885
|
|
|
} |
886
|
|
|
if (d(s + 1, c) > g)break; |
887
|
|
|
q = k |
888
|
|
|
} |
889
|
|
|
return h |
890
|
|
|
}; |
891
|
|
|
diff_match_patch.prototype.match_alphabet_ = function (a) { |
892
|
|
|
for (var b = {}, c = 0; c < a.length; c++)b[a.charAt(c)] = 0; |
893
|
|
|
for (c = 0; c < a.length; c++)b[a.charAt(c)] |= 1 << a.length - c - 1; |
894
|
|
|
return b |
895
|
|
|
}; |
896
|
|
|
diff_match_patch.prototype.patch_addContext_ = function (a, b) { |
897
|
|
|
if (0 != b.length) { |
898
|
|
|
for (var c = b.substring(a.start2, a.start2 + a.length1), d = 0; b.indexOf(c) != b.lastIndexOf(c) && c.length < this.Match_MaxBits - this.Patch_Margin - this.Patch_Margin;)d += this.Patch_Margin, c = b.substring(a.start2 - d, a.start2 + a.length1 + d); |
899
|
|
|
d += this.Patch_Margin; |
900
|
|
|
(c = b.substring(a.start2 - d, a.start2)) && a.diffs.unshift([0, c]); |
901
|
|
|
(d = b.substring(a.start2 + a.length1, a.start2 + a.length1 + d)) && a.diffs.push([0, d]); |
902
|
|
|
a.start1 -= c.length; |
903
|
|
|
a.start2 -= c.length; |
904
|
|
|
a.length1 += |
905
|
|
|
c.length + d.length; |
906
|
|
|
a.length2 += c.length + d.length |
907
|
|
|
} |
908
|
|
|
}; |
909
|
|
|
diff_match_patch.prototype.patch_make = function (a, b, c) { |
910
|
|
|
var d; |
911
|
|
|
if ("string" == typeof a && "string" == typeof b && "undefined" == typeof c)d = a, b = this.diff_main(d, b, !0), 2 < b.length && (this.diff_cleanupSemantic(b), this.diff_cleanupEfficiency(b)); else if (a && "object" == typeof a && "undefined" == typeof b && "undefined" == typeof c)b = a, d = this.diff_text1(b); else if ("string" == typeof a && b && "object" == typeof b && "undefined" == typeof c)d = a; else if ("string" == typeof a && "string" == typeof b && c && "object" == typeof c)d = a, b = c; else throw Error("Unknown call format to patch_make."); |
912
|
|
|
if (0 === b.length)return []; |
913
|
|
|
for (var c = [], a = new diff_match_patch.patch_obj, e = 0, f = 0, g = 0, h = d, j = 0; j < b.length; j++) { |
914
|
|
|
var i = b[j][0], k = b[j][1]; |
915
|
|
|
if (!e && 0 !== i)a.start1 = f, a.start2 = g; |
916
|
|
|
switch (i) { |
917
|
|
|
case 1: |
918
|
|
|
a.diffs[e++] = b[j]; |
919
|
|
|
a.length2 += k.length; |
920
|
|
|
d = d.substring(0, g) + k + d.substring(g); |
921
|
|
|
break; |
922
|
|
|
case -1: |
923
|
|
|
a.length1 += k.length; |
924
|
|
|
a.diffs[e++] = b[j]; |
925
|
|
|
d = d.substring(0, g) + d.substring(g + k.length); |
926
|
|
|
break; |
927
|
|
|
case 0: |
928
|
|
|
k.length <= 2 * this.Patch_Margin && e && b.length != j + 1 ? (a.diffs[e++] = b[j], a.length1 += k.length, a.length2 += k.length) : k.length >= 2 * this.Patch_Margin && |
929
|
|
|
e && (this.patch_addContext_(a, h), c.push(a), a = new diff_match_patch.patch_obj, e = 0, h = d, f = g) |
930
|
|
|
} |
931
|
|
|
1 !== i && (f += k.length); |
932
|
|
|
-1 !== i && (g += k.length) |
933
|
|
|
} |
934
|
|
|
e && (this.patch_addContext_(a, h), c.push(a)); |
935
|
|
|
return c |
936
|
|
|
}; |
937
|
|
|
diff_match_patch.prototype.patch_deepCopy = function (a) { |
938
|
|
|
for (var b = [], c = 0; c < a.length; c++) { |
939
|
|
|
var d = a[c], e = new diff_match_patch.patch_obj; |
940
|
|
|
e.diffs = []; |
941
|
|
|
for (var f = 0; f < d.diffs.length; f++)e.diffs[f] = d.diffs[f].slice(); |
942
|
|
|
e.start1 = d.start1; |
943
|
|
|
e.start2 = d.start2; |
944
|
|
|
e.length1 = d.length1; |
945
|
|
|
e.length2 = d.length2; |
946
|
|
|
b[c] = e |
947
|
|
|
} |
948
|
|
|
return b |
949
|
|
|
}; |
950
|
|
|
diff_match_patch.prototype.patch_apply = function (a, b) { |
951
|
|
|
if (0 == a.length)return [b, []]; |
952
|
|
|
var a = this.patch_deepCopy(a), c = this.patch_addPadding(a), b = c + b + c; |
953
|
|
|
this.patch_splitMax(a); |
954
|
|
|
for (var d = 0, e = [], f = 0; f < a.length; f++) { |
955
|
|
|
var g = a[f].start2 + d, h = this.diff_text1(a[f].diffs), j, i = -1; |
956
|
|
|
if (h.length > this.Match_MaxBits) { |
957
|
|
|
if (j = this.match_main(b, h.substring(0, this.Match_MaxBits), g), -1 != j && (i = this.match_main(b, h.substring(h.length - this.Match_MaxBits), g + h.length - this.Match_MaxBits), -1 == i || j >= i))j = -1 |
958
|
|
|
} else j = this.match_main(b, h, g); |
959
|
|
|
if (-1 == j)e[f] = !1, d -= a[f].length2 - a[f].length1; else if (e[f] = !0, d = j - g, g = -1 == i ? b.substring(j, j + h.length) : b.substring(j, i + this.Match_MaxBits), h == g)b = b.substring(0, j) + this.diff_text2(a[f].diffs) + b.substring(j + h.length); else if (g = this.diff_main(h, g, !1), h.length > this.Match_MaxBits && this.diff_levenshtein(g) / h.length > this.Patch_DeleteThreshold)e[f] = !1; else { |
960
|
|
|
this.diff_cleanupSemanticLossless(g); |
961
|
|
|
for (var h = 0, k, i = 0; i < a[f].diffs.length; i++) { |
962
|
|
|
var p = a[f].diffs[i]; |
963
|
|
|
0 !== p[0] && (k = this.diff_xIndex(g, h)); |
964
|
|
|
1 === p[0] ? b = b.substring(0, |
965
|
|
|
j + k) + p[1] + b.substring(j + k) : -1 === p[0] && (b = b.substring(0, j + k) + b.substring(j + this.diff_xIndex(g, h + p[1].length))); |
966
|
|
|
-1 !== p[0] && (h += p[1].length) |
967
|
|
|
} |
968
|
|
|
} |
969
|
|
|
} |
970
|
|
|
b = b.substring(c.length, b.length - c.length); |
971
|
|
|
return [b, e] |
972
|
|
|
}; |
973
|
|
|
diff_match_patch.prototype.patch_addPadding = function (a) { |
974
|
|
|
for (var b = this.Patch_Margin, c = "", d = 1; d <= b; d++)c += String.fromCharCode(d); |
975
|
|
|
for (d = 0; d < a.length; d++)a[d].start1 += b, a[d].start2 += b; |
976
|
|
|
var d = a[0], e = d.diffs; |
977
|
|
|
if (0 == e.length || 0 != e[0][0])e.unshift([0, c]), d.start1 -= b, d.start2 -= b, d.length1 += b, d.length2 += b; else if (b > e[0][1].length) { |
978
|
|
|
var f = b - e[0][1].length; |
979
|
|
|
e[0][1] = c.substring(e[0][1].length) + e[0][1]; |
980
|
|
|
d.start1 -= f; |
981
|
|
|
d.start2 -= f; |
982
|
|
|
d.length1 += f; |
983
|
|
|
d.length2 += f |
984
|
|
|
} |
985
|
|
|
d = a[a.length - 1]; |
986
|
|
|
e = d.diffs; |
987
|
|
|
0 == e.length || 0 != e[e.length - 1][0] ? (e.push([0, |
988
|
|
|
c]), d.length1 += b, d.length2 += b) : b > e[e.length - 1][1].length && (f = b - e[e.length - 1][1].length, e[e.length - 1][1] += c.substring(0, f), d.length1 += f, d.length2 += f); |
989
|
|
|
return c |
990
|
|
|
}; |
991
|
|
|
diff_match_patch.prototype.patch_splitMax = function (a) { |
992
|
|
|
for (var b = this.Match_MaxBits, c = 0; c < a.length; c++)if (!(a[c].length1 <= b)) { |
993
|
|
|
var d = a[c]; |
994
|
|
|
a.splice(c--, 1); |
995
|
|
|
for (var e = d.start1, f = d.start2, g = ""; 0 !== d.diffs.length;) { |
996
|
|
|
var h = new diff_match_patch.patch_obj, j = !0; |
997
|
|
|
h.start1 = e - g.length; |
998
|
|
|
h.start2 = f - g.length; |
999
|
|
|
if ("" !== g)h.length1 = h.length2 = g.length, h.diffs.push([0, g]); |
1000
|
|
|
for (; 0 !== d.diffs.length && h.length1 < b - this.Patch_Margin;) { |
1001
|
|
|
var g = d.diffs[0][0], i = d.diffs[0][1]; |
1002
|
|
|
1 === g ? (h.length2 += i.length, f += i.length, h.diffs.push(d.diffs.shift()), |
1003
|
|
|
j = !1) : -1 === g && 1 == h.diffs.length && 0 == h.diffs[0][0] && i.length > 2 * b ? (h.length1 += i.length, e += i.length, j = !1, h.diffs.push([g, i]), d.diffs.shift()) : (i = i.substring(0, b - h.length1 - this.Patch_Margin), h.length1 += i.length, e += i.length, 0 === g ? (h.length2 += i.length, f += i.length) : j = !1, h.diffs.push([g, i]), i == d.diffs[0][1] ? d.diffs.shift() : d.diffs[0][1] = d.diffs[0][1].substring(i.length)) |
1004
|
|
|
} |
1005
|
|
|
g = this.diff_text2(h.diffs); |
1006
|
|
|
g = g.substring(g.length - this.Patch_Margin); |
1007
|
|
|
i = this.diff_text1(d.diffs).substring(0, this.Patch_Margin); |
1008
|
|
|
"" !== i && |
1009
|
|
|
(h.length1 += i.length, h.length2 += i.length, 0 !== h.diffs.length && 0 === h.diffs[h.diffs.length - 1][0] ? h.diffs[h.diffs.length - 1][1] += i : h.diffs.push([0, i])); |
1010
|
|
|
j || a.splice(++c, 0, h) |
1011
|
|
|
} |
1012
|
|
|
} |
1013
|
|
|
}; |
1014
|
|
|
diff_match_patch.prototype.patch_toText = function (a) { |
1015
|
|
|
for (var b = [], c = 0; c < a.length; c++)b[c] = a[c]; |
1016
|
|
|
return b.join("") |
1017
|
|
|
}; |
1018
|
|
|
diff_match_patch.prototype.patch_fromText = function (a) { |
1019
|
|
|
var b = []; |
1020
|
|
|
if (!a)return b; |
1021
|
|
|
for (var a = a.split("\n"), c = 0, d = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/; c < a.length;) { |
1022
|
|
|
var e = a[c].match(d); |
1023
|
|
|
if (!e)throw Error("Invalid patch string: " + a[c]); |
1024
|
|
|
var f = new diff_match_patch.patch_obj; |
1025
|
|
|
b.push(f); |
1026
|
|
|
f.start1 = parseInt(e[1], 10); |
1027
|
|
|
"" === e[2] ? (f.start1--, f.length1 = 1) : "0" == e[2] ? f.length1 = 0 : (f.start1--, f.length1 = parseInt(e[2], 10)); |
1028
|
|
|
f.start2 = parseInt(e[3], 10); |
1029
|
|
|
"" === e[4] ? (f.start2--, f.length2 = 1) : "0" == e[4] ? f.length2 = 0 : (f.start2--, f.length2 = |
1030
|
|
|
parseInt(e[4], 10)); |
1031
|
|
|
for (c++; c < a.length;) { |
1032
|
|
|
e = a[c].charAt(0); |
1033
|
|
|
try { |
1034
|
|
|
var g = decodeURI(a[c].substring(1)) |
1035
|
|
|
} catch (h) { |
1036
|
|
|
throw Error("Illegal escape in patch_fromText: " + g); |
1037
|
|
|
} |
1038
|
|
|
if ("-" == e)f.diffs.push([-1, g]); else if ("+" == e)f.diffs.push([1, g]); else if (" " == e)f.diffs.push([0, g]); else if ("@" == e)break; else if ("" !== e)throw Error('Invalid patch mode "' + e + '" in: ' + g); |
1039
|
|
|
c++ |
1040
|
|
|
} |
1041
|
|
|
} |
1042
|
|
|
return b |
1043
|
|
|
}; |
1044
|
|
|
diff_match_patch.patch_obj = function () { |
1045
|
|
|
this.diffs = []; |
1046
|
|
|
this.start2 = this.start1 = null; |
1047
|
|
|
this.length2 = this.length1 = 0 |
1048
|
|
|
}; |
1049
|
|
|
diff_match_patch.patch_obj.prototype.toString = function () { |
1050
|
|
|
var a, b; |
1051
|
|
|
a = 0 === this.length1 ? this.start1 + ",0" : 1 == this.length1 ? this.start1 + 1 : this.start1 + 1 + "," + this.length1; |
1052
|
|
|
b = 0 === this.length2 ? this.start2 + ",0" : 1 == this.length2 ? this.start2 + 1 : this.start2 + 1 + "," + this.length2; |
1053
|
|
|
a = ["@@ -" + a + " +" + b + " @@\n"]; |
1054
|
|
|
var c; |
1055
|
|
|
for (b = 0; b < this.diffs.length; b++) { |
1056
|
|
|
switch (this.diffs[b][0]) { |
1057
|
|
|
case 1: |
1058
|
|
|
c = "+"; |
1059
|
|
|
break; |
1060
|
|
|
case -1: |
1061
|
|
|
c = "-"; |
1062
|
|
|
break; |
1063
|
|
|
case 0: |
1064
|
|
|
c = " " |
1065
|
|
|
} |
1066
|
|
|
a[b + 1] = c + encodeURI(this.diffs[b][1]) + "\n" |
1067
|
|
|
} |
1068
|
|
|
return a.join("").replace(/%20/g, " ") |
1069
|
|
|
}; |
1070
|
|
|
this.diff_match_patch = diff_match_patch; |
1071
|
|
|
this.DIFF_DELETE = -1; |
1072
|
|
|
this.DIFF_INSERT = 1; |
1073
|
|
|
this.DIFF_EQUAL = 0; |
1074
|
|
|
})() |
1075
|
|
|
var dmp = new diff_match_patch(); |
1076
|
|
|
function diffLaunch() { |
1077
|
|
|
var text1 = document.getElementById('text').value; |
1078
|
|
|
var text2 = document.getElementById('text2').value; |
1079
|
|
|
dmp.Diff_Timeout = 0; |
1080
|
|
|
dmp.Diff_EditCost = 4; |
1081
|
|
|
var d = dmp.diff_main(text1, text2); |
1082
|
|
|
var ds = dmp.diff_prettyHtml(d); |
1083
|
|
|
document.getElementById('diff').innerHTML = ds; |
1084
|
|
|
} |
1085
|
|
|
//--><! |
1086
|
|
|
]]></script> |
1087
|
|
|
<title>htmLawed (<?php echo hl_version(); ?>) test</title> |
1088
|
|
|
</head> |
1089
|
|
|
<body> |
1090
|
|
|
<div id="topmost"> |
1091
|
|
|
|
1092
|
|
|
<h5 style="float: left; display: inline; margin-top: 0; margin-bottom: 5px;"><a |
1093
|
|
|
href="http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/index.php" title="htmLawed home">HTM<big><big>L</big></big>AWED</a> <?php echo hl_version(); ?> |
1094
|
|
|
<a href="htmLawedTest.php" title="test home">TEST</a></h5> |
1095
|
|
|
<span style="float: right;" class="help"><a href="htmLawed_README.htm"><span class="notice">htm</span></a> / <a |
1096
|
|
|
href="htmLawed_README.txt"><span class="notice">txt</span></a> documentation</span><br style="clear:both;"/> |
1097
|
|
|
|
1098
|
|
|
<a href="htmLawedTest.php" title="[toggle visibility] type or copy-paste" |
1099
|
|
|
onclick="javascript:toggle('inputF'); return false;"><span class="notice">Input »</span> <span class="help" |
1100
|
|
|
title="limit lower with multibyte characters<?php echo(($_hlimit < $_limit && $_hlimit) ? '; limit is '.$_hlimit.' for viewing binaries' : ''); ?>"><small> |
1101
|
|
|
(max. <?php echo htmlspecialchars($_limit); ?> chars) |
1102
|
|
|
</small></span></a> |
1103
|
|
|
|
1104
|
|
|
<form id="testform" name="testform" action="htmLawedTest.php" method="post" |
1105
|
|
|
accept-charset="<?php echo htmlspecialchars($_POST['enc']); ?>" style="padding:0; margin: 0; display:inline;"> |
1106
|
|
|
|
1107
|
|
|
<div id="inputF" style="display: block;"> |
1108
|
|
|
|
1109
|
|
|
<input type="hidden" name="token" id="token" value="<?php echo $token; ?>"/> |
1110
|
|
|
<div><textarea id="text" class="textarea" name="text" rows="5" cols="100" |
1111
|
|
|
style="width: 100%;"><?php echo htmlspecialchars($_POST['text']); ?></textarea></div> |
1112
|
|
|
<input type="submit" id="submitF" name="submitF" value="Process" style="float:left;" |
1113
|
|
|
title="filter using htmLawed" onclick="javascript: sndProc(); return false;" |
1114
|
|
|
onkeypress="javascript: sndProc(); return false;"/> |
1115
|
|
|
|
1116
|
|
|
<?php |
1117
|
|
|
if ($do) { |
1118
|
|
|
if ($validation) { |
1119
|
|
|
echo '<input type="hidden" value="1" name="w3c_validate" id="w3c_validate" />'; |
1120
|
|
|
} |
1121
|
|
|
?> |
1122
|
|
|
|
1123
|
|
|
<button type="button" title="rendered as web-page without a doctype or charset declaration" |
1124
|
|
|
style="float: right;" onclick="javascript: sndUnproc(); return false;" |
1125
|
|
|
onkeypress="javascript: sndUnproc(); return false;">View unprocessed |
1126
|
|
|
</button> |
1127
|
|
|
<button type="button" |
1128
|
|
|
onclick="javascript:document.getElementById('text').focus();document.getElementById('text').select()" |
1129
|
|
|
title="select all to copy" style="float:right;">Select all |
1130
|
|
|
</button> |
1131
|
|
|
|
1132
|
|
|
<?php |
1133
|
|
|
if ($_w3c_validate && $validation) { |
1134
|
|
|
?> |
1135
|
|
|
|
1136
|
|
|
<button type="button" title="HTML 4.01 W3C online validation" style="float: right;" |
1137
|
|
|
onclick="javascript: sndValidn('text', 'html401'); return false;" |
1138
|
|
|
onkeypress="javascript: sndValidn('text', 'html401'); return false;">Check HTML |
1139
|
|
|
</button> |
1140
|
|
|
<button type="button" title="XHTML 1.1 W3C online validation" style="float: right;" |
1141
|
|
|
onclick="javascript: sndValidn('text', 'xhtml110'); return false;" |
1142
|
|
|
onkeypress="javascript: sndValidn('text', 'xhtml110'); return false;">Check XHTML |
1143
|
|
|
</button> |
1144
|
|
|
|
1145
|
|
|
<?php |
1146
|
|
|
} |
1147
|
|
|
} else { |
1148
|
|
|
if ($_w3c_validate) { |
1149
|
|
|
echo '<span style="float: right;" class="help" title="for direct submission of input or output code to W3C validator for (X)HTML validation"><span style="font-size: 85%;"> Validator tools: </span><input type="checkbox" value="1" name="w3c_validate" id="w3c_validate" style="vertical-align: middle;"', ($validation ? ' checked="checked"' : ''), ' /></span>'; |
1150
|
|
|
} |
1151
|
|
|
} |
1152
|
|
|
?> |
1153
|
|
|
|
1154
|
|
|
<span style="float:right;" class="help" |
1155
|
|
|
title="IANA-recognized name of the input character-set; can be multiple ;- or space-separated values; may not work in some browsers"><span |
1156
|
|
|
style="font-size: 85%;">Encoding: </span><input type="text" size="8" id="enc" name="enc" |
1157
|
|
|
style="vertical-align: middle;" |
1158
|
|
|
value="<?php echo htmlspecialchars($_POST['enc']); ?>"/></span> |
1159
|
|
|
|
1160
|
|
|
</div> |
1161
|
|
|
<br style="clear:both;"/> |
1162
|
|
|
|
1163
|
|
|
<?php |
1164
|
|
|
if ($limit_exceeded) { |
1165
|
|
|
echo '<br /><strong>Input text is too long!</strong><br />'; |
1166
|
|
|
} |
1167
|
|
|
?> |
1168
|
|
|
|
1169
|
|
|
<br/> |
1170
|
|
|
|
1171
|
|
|
<a href="htmLawedTest.php" title="[toggle visibility] htmLawed configuration" |
1172
|
|
|
onclick="javascript:toggle('inputC'); return false;"><span class="notice">Settings »</span></a> |
1173
|
|
|
|
1174
|
|
|
<div id="inputC" style="display: none;"> |
1175
|
|
|
<table summary="none"> |
1176
|
|
|
<tr> |
1177
|
|
|
<td><span class="help" title="$config argument">Config:</span></td> |
1178
|
|
|
<td> |
1179
|
|
|
<ul> |
1180
|
|
|
|
1181
|
|
|
<?php |
1182
|
|
|
$cfg = array( |
1183
|
|
|
'abs_url' => array('3', '0', 'absolute/relative URL conversion', '-1'), |
1184
|
|
|
'and_mark' => array('2', '0', 'mark original <em>&</em> chars', '0', 'd' => 1), // 'd' to disable |
1185
|
|
|
'anti_link_spam' => array('1', '0', 'modify <em>href</em> values as an anti-link spam measure', '0', array(array('30', '1', '', 'regex for extra <em>rel</em>'), array('30', '2', '', 'regex for no <em>href</em>'))), |
1186
|
|
|
'anti_mail_spam' => array('1', '0', 'replace <em>@</em> in <em>mailto:</em> URLs', '0', '8', 'NO@SPAM', 'replacement'), |
1187
|
|
|
'balance' => array('2', '1', 'fix nestings and balance tags', '0'), |
1188
|
|
|
'base_url' => array('', '', 'base URL', '25'), |
1189
|
|
|
'cdata' => array('4', 'nil', 'allow <em>CDATA</em> sections', 'nil'), |
1190
|
|
|
'clean_ms_char' => array('3', '0', 'replace bad characters introduced by Microsoft apps. like <em>Word</em>', '0'), |
1191
|
|
|
'comment' => array('4', 'nil', 'allow HTML comments', 'nil'), |
1192
|
|
|
'css_expression' => array('2', 'nil', 'allow dynamic expressions in CSS style properties', 'nil'), |
1193
|
|
|
'deny_attribute' => array('1', '0', 'denied attributes', '0', '50', '', 'these'), |
1194
|
|
|
'direct_list_nest' => array('2', 'nil', 'allow direct nesting of a list within another without requiring it to be a list item', 'nil'), |
1195
|
|
|
'elements' => array('', '', 'allowed elements', '50'), |
1196
|
|
|
'hexdec_entity' => array('3', '1', 'convert hexadecimal numeric entities to decimal ones, or vice versa', '0'), |
1197
|
|
|
'hook' => array('', '', 'name of hook function', '25'), |
1198
|
|
|
'hook_tag' => array('', '', 'name of custom function to further check attribute values', '25'), |
1199
|
|
|
'keep_bad' => array('7', '6', 'keep, or remove <em>bad</em> tag content', '0'), |
1200
|
|
|
'lc_std_val' => array('2', '1', 'lower-case std. attribute values like <em>radio</em>', '0'), |
1201
|
|
|
'make_tag_strict' => array('3', 'nil', 'transform deprecated elements', 'nil'), |
1202
|
|
|
'named_entity' => array('2', '1', 'allow named entities, or convert numeric ones', '0'), |
1203
|
|
|
'no_deprecated_attr' => array('3', '1', 'allow deprecated attributes, or transform them', '0'), |
1204
|
|
|
'parent' => array('', 'div', 'name of parent element', '25'), |
1205
|
|
|
'safe' => array('2', '0', 'for most <em>safe</em> HTML', '0'), |
1206
|
|
|
'schemes' => array('', 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https', 'allowed URL protocols', '50'), |
1207
|
|
|
'show_setting' => array('', 'htmLawed_setting', 'variable name to record <em>finalized</em> htmLawed settings', '25', 'd' => 1), |
1208
|
|
|
'style_pass' => array('2', 'nil', 'do not look at <em>style</em> attribute values', 'nil'), |
1209
|
|
|
'tidy' => array('3', '0', 'beautify/compact', '-1', '8', '1t1', 'format'), |
1210
|
|
|
'unique_ids' => array('2', '1', 'unique <em>id</em> values', '0', '8', 'my_', 'prefix'), |
1211
|
|
|
'valid_xhtml' => array('2', 'nil', 'auto-set various parameters for most valid XHTML', 'nil'), |
1212
|
|
|
'xml:lang' => array('3', 'nil', 'auto-add <em>xml:lang</em> attribute', '0'), |
1213
|
|
|
); |
1214
|
|
|
foreach ($cfg as $k => $v) { |
1215
|
|
|
echo '<li>', $k, ': '; |
1216
|
|
|
if (!empty($v[0])) { // input radio |
1217
|
|
|
$j = $v[3]; |
1218
|
|
|
for ($i = $j - 1; ++$i < $v[0] + $v[3]; ++$j) { |
1219
|
|
|
echo '<input type="radio" name="h', $k, '" value="', $i, '"', (!isset($_POST['h'.$k]) ? ($v[1] == $i ? ' checked="checked"' : '') : ($_POST['h'.$k] == $i ? ' checked="checked"' : '')), (isset($v['d']) ? ' disabled="disabled"' : ''), ' />', $i, ' '; |
1220
|
|
|
} |
1221
|
|
|
if ($v[1] == 'nil') { |
1222
|
|
|
echo '<input type="radio" name="h', $k, '" value="nil"', ((!isset($_POST['h'.$k]) or $_POST['h'.$k] == 'nil') ? ' checked="checked"' : ''), (isset($v['d']) ? ' disabled="disabled"' : ''), ' />not set '; |
1223
|
|
|
} |
1224
|
|
|
if (!empty($v[4])) { // + input text box |
1225
|
|
|
echo '<input type="radio" name="h', $k, '" value="', $j, '"', (((isset($_POST['h'.$k]) && $_POST['h'.$k] == $j) or (!isset($_POST['h'.$k]) && $j == $v[1])) ? ' checked="checked"' : ''), (isset($v['d']) ? ' disabled="disabled"' : ''), ' />'; |
1226
|
|
|
if (!is_array($v[4])) { |
1227
|
|
|
echo $v[6], ': <input type="text" size="', $v[4], '" name="h', $k.$j, '" value="', htmlspecialchars(isset($_POST['h'.$k.$j][0]) ? $_POST['h'.$k.$j] : $v[5]), '"', (isset($v['d']) ? ' disabled="disabled"' : ''), ' />'; |
1228
|
|
|
} else { |
1229
|
|
|
foreach ($v[4] as $z) { |
1230
|
|
|
echo ' ', $z[3], ': <input type="text" size="', $z[0], '" name="h', $k.$j.$z[1], '" value="', htmlspecialchars(isset($_POST['h'.$k.$j.$z[1]][0]) ? $_POST['h'.$k.$j.$z[1]] : $z[2]), '"', (isset($v['d']) ? ' disabled="disabled"' : ''), ' />'; |
1231
|
|
|
} |
1232
|
|
|
} |
1233
|
|
|
} |
1234
|
|
|
} elseif (ctype_digit($v[3])) { // input text |
1235
|
|
|
echo '<input type="text" size="', $v[3], '" name="h', $k, '" value="', htmlspecialchars(isset($_POST['h'.$k][0]) ? $_POST['h'.$k] : $v[1]), '"', (isset($v['d']) ? ' disabled="disabled"' : ''), ' />'; |
1236
|
|
|
} else { |
1237
|
|
|
} // text-area |
1238
|
|
|
echo ' <span class="help">', $v[2], '</span></li>'; |
1239
|
|
|
} |
1240
|
|
|
echo '</ul></td></tr><tr><td><span style="vertical-align: top;" class="help" title="$spec argument: element-specific attribute rules">Spec:</span></td><td><textarea name="spec" id="spec" cols="70" rows="3" style="width:80%;">', htmlspecialchars((isset($_POST['spec']) ? $_POST['spec'] : '')), '</textarea></td></tr></table>'; |
1241
|
|
|
?> |
1242
|
|
|
|
1243
|
|
|
</div> |
1244
|
|
|
</form> |
1245
|
|
|
|
1246
|
|
|
<?php |
1247
|
|
|
if ($do) { |
1248
|
|
|
$cfg = array(); |
1249
|
|
|
foreach ($_POST as $k => $v) { |
1250
|
|
|
if ($k[0] == 'h' && $v != 'nil') { |
1251
|
|
|
$cfg[substr($k, 1)] = $v; |
1252
|
|
|
} |
1253
|
|
|
} |
1254
|
|
|
|
1255
|
|
|
if (isset($cfg['anti_link_spam']) && $cfg['anti_link_spam'] && (!empty($cfg['anti_link_spam11']) or !empty($cfg['anti_link_spam12']))) { |
1256
|
|
|
$cfg['anti_link_spam'] = array($cfg['anti_link_spam11'], $cfg['anti_link_spam12']); |
1257
|
|
|
} |
1258
|
|
|
unset($cfg['anti_link_spam11'], $cfg['anti_link_spam12']); |
1259
|
|
|
if (isset($cfg['anti_mail_spam']) && $cfg['anti_mail_spam'] == 1) { |
1260
|
|
|
$cfg['anti_mail_spam'] = isset($cfg['anti_mail_spam1'][0]) ? $cfg['anti_mail_spam1'] : 0; |
1261
|
|
|
} |
1262
|
|
|
unset($cfg['anti_mail_spam11']); |
1263
|
|
|
if (isset($cfg['deny_attribute']) && $cfg['deny_attribute'] == 1) { |
1264
|
|
|
$cfg['deny_attribute'] = isset($cfg['deny_attribute1'][0]) ? $cfg['deny_attribute1'] : 0; |
1265
|
|
|
} |
1266
|
|
|
unset($cfg['deny_attribute1']); |
1267
|
|
|
if (isset($cfg['tidy']) && $cfg['tidy'] == 2) { |
1268
|
|
|
$cfg['tidy'] = isset($cfg['tidy2'][0]) ? $cfg['tidy2'] : 0; |
1269
|
|
|
} |
1270
|
|
|
unset($cfg['tidy2']); |
1271
|
|
|
if (isset($cfg['unique_ids']) && $cfg['unique_ids'] == 2) { |
1272
|
|
|
$cfg['unique_ids'] = isset($cfg['unique_ids2'][0]) ? $cfg['unique_ids2'] : 1; |
1273
|
|
|
} |
1274
|
|
|
unset($cfg['unique_ids2']); |
1275
|
|
|
unset($cfg['and_mark']); // disabling and_mark |
1276
|
|
|
|
1277
|
|
|
$cfg['show_setting'] = 'hlcfg'; |
1278
|
|
|
$st = microtime(); |
1279
|
|
|
$out = htmLawed($_POST['text'], $cfg, $_POST['spec']); |
|
|
|
|
1280
|
|
|
$et = microtime(); |
1281
|
|
|
echo '<br /><a href="htmLawedTest.php" title="[toggle visibility] syntax-highlighted" onclick="javascript:toggle(\'inputR\'); return false;"><span class="notice">Input code »</span></a> <span class="help" title="tags estimated as half of total > and < chars; values may be inaccurate for non-ASCII text"><small><big>', strlen($_POST['text']), '</big> chars, ~<big>', ($tag = round((substr_count($_POST['text'], '>') + substr_count($_POST['text'], '<')) / 2)), '</big> tag', ($tag > 1 ? 's' : ''), '</small> </span><div id="inputR" style="display: none;">', format($_POST['text']), '</div><script type="text/javascript">hl(\'inputR\');</script>', (!isset($_POST['text'][$_hlimit]) ? ' <a href="htmLawedTest.php" title="[toggle visibility] hexdump; non-viewable characters like line-returns are shown as dots" onclick="javascript:toggle(\'inputD\'); return false;"><span class="notice">Input binary » </span></a><div id="inputD" style="display: none;">'.hexdump($_POST['text']).'</div>' : ''), ' <a href="htmLawedTest.php" title="[toggle visibility] finalized internal settings as interpreted by htmLawed; for developers" onclick="javascript:toggle(\'settingF\'); return false;"><span class="notice">Finalized internal settings » </span></a> <div id="settingF" style="display: none;">$config: ', str_replace(array(' ', "\t", ' '), array(' ', ' ', ' '), nl2br(htmlspecialchars(print_r($GLOBALS['hlcfg']['config'], true)))), '<br />$spec: ', str_replace(array(' ', "\t", ' '), array(' ', ' ', ' '), nl2br(htmlspecialchars(print_r($GLOBALS['hlcfg']['spec'], true)))), '</div><script type="text/javascript">hl(\'settingF\');</script>', '<br /><a href="htmLawedTest.php" title="[toggle visibility] suitable for copy-paste" onclick="javascript:toggle(\'outputF\'); return false;"><span class="notice">Output »</span></a> <span class="help" title="approx., server-specific value excluding the \'include()\' call"><small>htmLawed processing time <big>', number_format(((substr($et, 0, 9)) + (substr($et, -10)) - (substr($st, 0, 9)) - (substr($st, -10))), 4), '</big> s</small></span>', (($mem = memory_get_peak_usage()) !== false ? '<span class="help"><small>, peak memory usage <big>'.round(($mem - $pre_mem) / 1048576, 2).'</big> <small>MB</small>' : ''), '</small></span><div id="outputF" style="display: block;"><div><textarea id="text2" class="textarea" name="text2" rows="5" cols="100" style="width: 100%;">', htmlspecialchars($out), '</textarea></div><button type="button" onclick="javascript:document.getElementById(\'text2\').focus();document.getElementById(\'text2\').select()" title="select all to copy" style="float:right;">Select all</button>'; |
1282
|
|
|
if ($_w3c_validate && $validation) { |
1283
|
|
|
?> |
1284
|
|
|
|
1285
|
|
|
<button type="button" title="HTML 4.01 W3C online validation" style="float: right;" |
1286
|
|
|
onclick="javascript: sndValidn('text2', 'html401'); return false;" |
1287
|
|
|
onkeypress="javascript: sndValidn('text2', 'html401'); return false;">Check HTML |
1288
|
|
|
</button> |
1289
|
|
|
<button type="button" title="XHTML 1.1 W3C online validation" style="float: right;" |
1290
|
|
|
onclick="javascript: sndValidn('text2', 'xhtml110'); return false;" |
1291
|
|
|
onkeypress="javascript: sndValidn('text2', 'xhtml110'); return false;">Check XHTML |
1292
|
|
|
</button> |
1293
|
|
|
|
1294
|
|
|
<?php |
1295
|
|
|
} |
1296
|
|
|
echo '</div><br /><a href="htmLawedTest.php" title="[toggle visibility] syntax-highlighted" onclick="javascript:toggle(\'outputR\'); return false;"><span class="notice">Output code »</span></a><div id="outputR" style="display: block;">', format($out), '</div><script type="text/javascript">hl(\'outputR\');</script>', (!isset($_POST['text'][$_hlimit]) ? ' <a href="htmLawedTest.php" title="[toggle visibility] hexdump; non-viewable characters like line-returns are shown as dots" onclick="javascript:toggle(\'outputD\'); return false;"><span class="notice">Output binary »</span></a><div id="outputD" style="display: none;">'.hexdump($out).'</div>' : ''), ' <a href="htmLawedTest.php" title="[toggle visibility] inline output-input diff; might not be perfectly accurate, semantically or otherwise " onclick="javascript:toggle(\'diff\'); diffLaunch(); return false;"><span class="notice">Diff »</span></a> <div id="diff" style="display: none;"></div><br /><a href="htmLawedTest.php" title="[toggle visibility] XHTML 1 Transitional doctype" onclick="javascript:toggle(\'outputH\'); return false;"><span class="notice">Output rendered »</span></a><div id="outputH" style="display: block;">', $out, '</div>'; |
1297
|
|
|
} else { |
1298
|
|
|
?> |
1299
|
|
|
|
1300
|
|
|
<br/> |
1301
|
|
|
|
1302
|
|
|
<div class="help">Use with a Javascript- and cookie-enabled, relatively new version of a common browser. <em>Submitted |
1303
|
|
|
input will also be HTML-rendered (XHTML 1) after htmLawed-filtering.</em> |
1304
|
|
|
|
1305
|
|
|
<?php echo(file_exists('./htmLawed_TESTCASE.txt') ? '<br /><br />You can use text from <a href="htmLawed_TESTCASE.txt"><span class="notice">this collection of test-cases</span></a> in the input. Set the character encoding of the browser to Unicode/utf-8 before copying.' : ''); ?> |
1306
|
|
|
|
1307
|
|
|
<br/><br/>For anti-XSS tests, try the <a |
1308
|
|
|
href="http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/htmLawedSafeModeTest.php"><span |
1309
|
|
|
class="notice">special test-page</span></a> or see <a |
1310
|
|
|
href="http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/rsnake/RSnakeXSSTest.htm"><span |
1311
|
|
|
class="notice">these results</span></a>. |
1312
|
|
|
|
1313
|
|
|
<br/><br/> |
1314
|
|
|
<small>Change <em>Encoding</em> to reflect the character encoding of the input text. Even then, it may not |
1315
|
|
|
work or some characters may not display properly because of variable browser support and because of the |
1316
|
|
|
form interface. Developers can write some PHP code to capture the filtered input to a file if this is |
1317
|
|
|
important. |
1318
|
|
|
<br/><br/>Refer to the htmLawed documentation (<a href="htmLawed_README.htm"><span |
1319
|
|
|
class="notice">htm</span></a>/<a href="htmLawed_README.txt"><span class="notice">txt</span></a>) |
1320
|
|
|
for details about <em>Settings</em>, and htmLawed's behavior and limitations. For <em>Settings</em>, |
1321
|
|
|
incorrectly-specified values like regular expressions are silently ignored. One or more settings |
1322
|
|
|
form-fields may have been disabled. Some characters are not allowed in the <em>Spec</em> field. |
1323
|
|
|
|
1324
|
|
|
|
1325
|
|
|
<br/><br/>Hovering the mouse over some of the text can provide additional information in some browsers. |
1326
|
|
|
</small> |
1327
|
|
|
|
1328
|
|
|
<?php |
1329
|
|
|
if ($_w3c_validate) { |
1330
|
|
|
?> |
1331
|
|
|
|
1332
|
|
|
<small><br/><br/>Because of character-encoding issues, the W3C validator (anyway not perfect) may reject |
1333
|
|
|
validation requests or invalidate otherwise-valid code, esp. if text was copy-pasted in the input |
1334
|
|
|
box. Local applications like the <em>HTML Validator</em> Firefox browser add-on may be useful in |
1335
|
|
|
such cases. |
1336
|
|
|
</small> |
1337
|
|
|
|
1338
|
|
|
<?php |
1339
|
|
|
} |
1340
|
|
|
?> |
1341
|
|
|
|
1342
|
|
|
</div> |
1343
|
|
|
|
1344
|
|
|
<?php |
1345
|
|
|
} |
1346
|
|
|
?> |
1347
|
|
|
|
1348
|
|
|
</div> |
1349
|
|
|
</body> |
1350
|
|
|
</html> |
1351
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: