1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Caxy\HtmlDiff\HtmlDiff; |
4
|
|
|
|
5
|
|
|
ini_set('display_errors', 1); |
6
|
|
|
error_reporting(E_ALL); |
7
|
|
|
|
8
|
|
|
require __DIR__.'/../vendor/autoload.php'; |
9
|
|
|
|
10
|
|
|
$debugOutput = array(); |
11
|
|
|
|
12
|
|
|
function addDebugOutput($value, $key = 'general') |
13
|
|
|
{ |
14
|
|
|
global $debugOutput; |
15
|
|
|
|
16
|
|
|
if (!is_string($value)) { |
17
|
|
|
$value = var_export($value, true); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
if (!array_key_exists($key, $debugOutput)) { |
21
|
|
|
$debugOutput[$key] = array(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$debugOutput[$key][] = $value; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$input = file_get_contents('php://input'); |
28
|
|
|
|
29
|
|
|
if ($input) { |
30
|
|
|
header('Content-Type: application/json'); |
31
|
|
|
|
32
|
|
|
$data = json_decode($input, true); |
33
|
|
|
|
34
|
|
|
$oldText = $data['oldText']; |
35
|
|
|
$newText = $data['newText']; |
36
|
|
|
$useTableDiffing = isset($data['tableDiffing']) ? $data['tableDiffing'] : true; |
37
|
|
|
|
38
|
|
|
$diff = new HtmlDiff($oldText, $newText, 'UTF-8', array()); |
39
|
|
|
if (array_key_exists('matchThreshold', $data)) { |
40
|
|
|
$diff->setMatchThreshold($data['matchThreshold']); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
$diff->setUseTableDiffing($useTableDiffing); |
|
|
|
|
43
|
|
|
$diffOutput = $diff->build(); |
44
|
|
|
$diffOutput = iconv('UTF-8', 'UTF-8//IGNORE', $diffOutput); |
45
|
|
|
|
46
|
|
|
$jsonOutput = json_encode(array('diff' => $diffOutput, 'debug' => $debugOutput)); |
47
|
|
|
|
48
|
|
|
if (false === $jsonOutput) { |
49
|
|
|
throw new \Exception('Failed to encode JSON: '.json_last_error_msg()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
echo $jsonOutput; |
53
|
|
|
} else { |
54
|
|
|
header('Content-Type: text/html'); |
55
|
|
|
echo file_get_contents('demo.html'); |
56
|
|
|
} |
57
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.