Skip to content

Commit

Permalink
[#13] Convert XML assets only for keeping binary files intact
Browse files Browse the repository at this point in the history
  • Loading branch information
jensschuppe committed Feb 2, 2022
1 parent 3a8ac55 commit bd09202
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions CRM/Civioffice/DocumentRenderer/LocalUnoconv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bd09202

Please sign in to comment.