-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdiff.php
88 lines (62 loc) · 1.83 KB
/
diff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require "app/Init.php";
require "lib/FineDiff/finediff.php";
$error = null;
try {
$file = empty($_GET['file']) ? null : $_GET['file'];
$dirPart = empty($_GET['dir']) ? null : trim($_GET['dir'], './');
if (!$file || !$dirPart) {
throw new Exception("No required parameters passed");
}
$dir = "tmp/convert/$dirPart/source";
if (!is_dir($dir)) {
throw new Exception("Folder does not exist - perhaps your session has expired");
}
$file = strtr($file, array(
'../' => '',
'..\\' => '',
));
$origFile = "$dir/original/$file";
$convFile = "$dir/converted/$file";
if (!is_file($origFile) && !is_file($convFile)) {
throw new Exception("Cannot find file");
}
if ($file == 'install.rdf') {
// reformat XML because the diff cannot ignore indentation
$doc = new DOMDocument('1.0', 'utf-8');
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$doc->load($origFile);
$doc->encoding = 'utf-8';
$content1 = trim($doc->saveXML());
} else {
if (is_file($origFile)) {
$content1 = strtr(trim(file_get_contents($origFile)), array(
"\r\n" => "\n",
));
} else {
$content1 = "";
}
}
if (is_file($convFile)) {
$content2 = strtr(trim(file_get_contents($convFile)), array(
"\r\n" => "\n",
));
} else {
$content2 = "";
}
$diff = new FineDiff($content1, $content2, FineDiff::$paragraphGranularity);
$diffHtml = $diff->renderDiffToHTML();
} catch (Exception $ex) {
$error = $ex->getMessage();
}
?>
<? $mainClass = "diff-page" ?>
<? include "templates/header.php" ?>
<h2>diff: <?=htmlspecialchars($file) ?></h2>
<? if ($error === null): ?>
<div class="diff"><?=$diffHtml ?></div>
<? else: ?>
<div class="error"><?=$error ?></div>
<? endif ?>
<? include "templates/footer.php" ?>