Skip to content

Commit

Permalink
switch out problematic chars fro xml before replacing imgs
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasvielmetter committed Sep 11, 2017
1 parent 3beee5d commit a29bdab
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/WrkLst/DocxMustache/DocxMustache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand All @@ -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);
}
Expand All @@ -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');
Expand Down

0 comments on commit a29bdab

Please sign in to comment.