Merge pull request #1485 from Timanx/develop

Fix parsing of Office 365 documents
This commit is contained in:
troosan 2018-11-25 01:38:48 +01:00 committed by GitHub
commit a7bfc8da51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -11,6 +11,7 @@ v0.16.0 (xx xxx 2018)
- Fix regex in `cloneBlock` function @nicoder #1269
- HTML Title Writer loses text when Title contains a TextRun instead a string. @begnini #1436
- RTF writer: Round getPageSizeW and getPageSizeH to avoid decimals @Patrick64 #1493
- Fix parsing of Office 365 documents @Timanx #1485
v0.15.0 (14 Jul 2018)
----------------------

View File

@ -503,11 +503,19 @@ class TemplateProcessor
}
/**
* Usually, the name of main part document will be 'document.xml'. However, some .docx files (possibly those from Office 365, experienced also on documents from Word Online created from blank templates) have file 'document22.xml' in their zip archive instead of 'document.xml'. This method searches content types file to correctly determine the file name.
*
* @return string
*/
protected function getMainPartName()
{
return 'word/document.xml';
$contentTypes = $this->zipClass->getFromName('[Content_Types].xml');
$pattern = '~PartName="\/(word\/document.*?\.xml)" ContentType="application\/vnd\.openxmlformats-officedocument\.wordprocessingml\.document\.main\+xml"~';
preg_match($pattern, $contentTypes, $matches);
return array_key_exists(1, $matches) ? $matches[1] : 'word/document.xml';
}
/**

View File

@ -276,4 +276,13 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
);
}
}
public function testMainPartNameDetection()
{
$templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/document22-xml.docx');
$variables = array('test');
$this->assertEquals($variables, $templateProcessor->getVariables());
}
}

Binary file not shown.