From bd0920279b7f16dec80d13bbc434dfabc4063421 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 2 Feb 2022 14:39:03 +0100 Subject: [PATCH] [#13] Convert XML assets only for keeping binary files intact --- .../DocumentRenderer/LocalUnoconv.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/CRM/Civioffice/DocumentRenderer/LocalUnoconv.php b/CRM/Civioffice/DocumentRenderer/LocalUnoconv.php index 0e98c8a..85e1b25 100644 --- a/CRM/Civioffice/DocumentRenderer/LocalUnoconv.php +++ b/CRM/Civioffice/DocumentRenderer/LocalUnoconv.php @@ -252,19 +252,20 @@ public function render( // iterate through all docx components (files in zip) for ($i = 0; $i < $numberOfFiles; $i++) { - // todo: somehow skip binaries like jpegs? - /** - * TODO: Skip irrelevant parts - * @url https://github.com/systopia/de.systopia.civioffice/issues/13 - */ - // Step 1/4 unpack xml (.docx) file and handle it as a zip file as it is one $fileContent = $zip->getFromIndex($i); $fileName = $zip->getNameIndex($i); // Step 2/4 replace tokens - $fileContent = $this->wrapTokensInStringWithXmlEscapeCdata($fileContent); - $fileContent = $this->replaceAllTokens($fileContent, $entity_id, 'contact'); + /** + * TODO: Skip irrelevant parts, like binary files (images, etc.). + * @url https://github.com/systopia/de.systopia.civioffice/issues/13 + * As a first step, we filter for XML files only. + */ + if (0 === substr_compare($fileName, '.xml', - strlen('.xml'))) { + $fileContent = $this->wrapTokensInStringWithXmlEscapeCdata($fileContent); + $fileContent = $this->replaceAllTokens($fileContent, $entity_id, 'contact'); + } // Step 3/4 repack it again as xml (docx) $zip->addFromString($fileName, $fileContent);