From a29bdabc8ea82d4bdf5b57532e84a7dbefa194b1 Mon Sep 17 00:00:00 2001 From: Tobias Vielmetter Date: Mon, 11 Sep 2017 16:08:58 -0700 Subject: [PATCH] switch out problematic chars fro xml before replacing imgs --- src/WrkLst/DocxMustache/DocxMustache.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/WrkLst/DocxMustache/DocxMustache.php b/src/WrkLst/DocxMustache/DocxMustache.php index e01d65d..b7d298a 100644 --- a/src/WrkLst/DocxMustache/DocxMustache.php +++ b/src/WrkLst/DocxMustache/DocxMustache.php @@ -104,6 +104,7 @@ protected function exctractOpenXmlFile($file) protected function ReadOpenXmlFile($file, $type = 'file') { $this->exctractOpenXmlFile($file); + $this->tempChangeProblematicChars($file); if ($type == 'file') { if ($file_contents = \Storage::disk($this->storageDisk)->get($this->local_path.$file)) { @@ -122,6 +123,8 @@ protected function ReadOpenXmlFile($file, $type = 'file') protected function SaveOpenXmlFile($file, $folder, $content) { + $content = str_replace('%%KAUFUND%%','&',$content); + \Storage::disk($this->storageDisk) ->put($this->local_path.$file, $content); //add new content to word doc @@ -138,6 +141,7 @@ protected function SaveOpenXmlObjectToFile($xmlObject, $file, $folder) { if ($xmlString = $xmlObject->asXML()) { $this->SaveOpenXmlFile($file, $folder, $xmlString); + $this->tempChangeProblematicChars($file, true); } else { throw new Exception('Cannot generate xml for '.$file); } @@ -163,6 +167,18 @@ public function ReadTeamplate() $this->zipper->close(); } + protected function tempChangeProblematicChars($file, $reverse = false) + { + $content = \Storage::disk($this->storageDisk) + ->get($this->local_path.$file); + if(!$reverse) + $content = str_replace('&','%%KAUFUND%%',$content); + else + $content = str_replace('%%KAUFUND%%','&',$content); + \Storage::disk($this->storageDisk) + ->put($this->local_path.$file, $content); + } + protected function AddContentType($imageCt = 'jpeg') { $ct_file = $this->ReadOpenXmlFile('[Content_Types].xml', 'object');