Subversion Repository Public Repository

Nextrek

Diff Revisions 794 vs 795 for /legal-map/ajax/openDiff.php

Diff revisions: vs.
  @@ -1,28 +1,39 @@
1 1 <?php
2 - require_once("SimpleXMLExtended.php");
2 +
3 3
4 4 $pathArticoli = dirname(__FILE__).'/../articoli/';
5 5 $originalFile = $pathArticoli.$_REQUEST['original'];
6 6 $changedFile = $pathArticoli.$_REQUEST['changed'];
7 7
8 8 function loadArticleAsString($originalFile) {
9 - $mock = new DOMDocument;
10 - $originalHtml = new DOMDocument;
11 - $originalHtml->loadHTML(file_get_contents($originalFile));
12 - $originalBody = $originalHtml->getElementsByTagName('body')->item(0);
13 - foreach ($originalBody->childNodes as $child){
14 - $mock->appendChild($mock->importNode($child, true));
15 - }
9 + $html = file_get_contents($originalFile);
10 + $html = str_replace("\r\n","\n", $html);
11 + $html = str_replace("\n\n","\n", $html);
12 + $html = str_replace("\n"," ", $html);
13 + $html = str_replace('<br>',"\n", $html);
14 + $html = str_replace('</p>',"</p>\n", $html);
15 + $html = str_replace('<p',"\n<p", $html);
16 + $html = str_replace(" \n","\n", $html);
17 +
18 + $bodyPos = strpos($html, '<body');
19 + $bodyPos = strpos($html, '>', $bodyPos) + 1;
20 + $endBody = strpos($html, '</body>');
16 21
17 - return $mock->saveHTML();
22 + $result = substr($html, $bodyPos, $endBody-$bodyPos);
23 +
24 + $result = utf8_encode($result);
25 +
26 + return $result;
18 27 }
19 28
20 29 $response = array(
21 30 'originalContent' => loadArticleAsString($originalFile),
22 31 'changedContent' => loadArticleAsString($changedFile)
23 32 );
24 -
33 +
34 + header('Content-Type: application/json');
25 35 echo json_encode($response);
36 + //ob_flush();
26 37
27 38 /*
28 39 if (isset($_REQUEST["popup"])) {