comparison InputParser.inc @ 117:e01ce5722f2b

New change to how we save (X)HTML files. This time we simplify things by using DocumentFragments to load stuff, and preserve CDATA content.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Sun, 27 Mar 2016 21:33:08 +0200
parents 374e3eff07fd
children 8678ce12d533
comparison
equal deleted inserted replaced
116:374e3eff07fd 117:e01ce5722f2b
91 */ 91 */
92 function generateContent() 92 function generateContent()
93 { 93 {
94 //We may need to set and check the contenttype and replace 94 //We may need to set and check the contenttype and replace
95 //saveHTML with saveXML 95 //saveHTML with saveXML
96 $retVal = new PageContent($this->master->saveHTML($this->master)); 96 $retVal = new PageContent($this->master->saveXML());
97 $retVal->setHeader('Content-Language', $this->options->getLang()); 97 $retVal->setHeader('Content-Language', $this->options->getLang());
98 return $retVal; 98 return $retVal;
99 } 99 }
100 100
101 /** 101 /**
210 foreach($toRemove as $param) { 210 foreach($toRemove as $param) {
211 $parent = $param->parentNode; 211 $parent = $param->parentNode;
212 $parent->removeChild($param); 212 $parent->removeChild($param);
213 } 213 }
214 214
215 $body = getElementByTagName($doc,"body"); 215 $body = getElementByTagName($doc,"html");
216 $files = $body->getElementsByTagName("file"); 216 $files = $body->getElementsByTagName("file");
217 217
218 $toRemove = array(); 218 $toRemove = array();
219 219
220 foreach ($files as $file) { 220 foreach ($files as $file) {
262 } 262 }
263 } 263 }
264 $callString .= ");"; 264 $callString .= ");";
265 eval($callString); 265 eval($callString);
266 } 266 }
267 $ndoc = new DOMDocument(); 267 $ndoc = $doc->createDocumentFragment();
268
269 $ndoc->loadXml("<xml>${file_content}</xml>");
270 268
271 $parent = $file->parentNode; 269 $parent = $file->parentNode;
272 foreach ($ndoc->firstChild->childNodes as $child) { 270
273 $clonedChild = $doc->importNode($child, true); 271 $ndoc->appendXML($file_content);
274 $parent->insertBefore($clonedChild, $file); 272 $parent->insertBefore($ndoc, $file);
275 }
276 273
277 //We need to iterate in the opposite direction when removing, 274 //We need to iterate in the opposite direction when removing,
278 //so best shifting. 275 //so best shifting.
279 array_unshift($toRemove, $file); 276 array_unshift($toRemove, $file);
280 } 277 }