elseif (!empty($formValues['document_file'])) {
list($html_message, $formValues['document_type']) = CRM_Utils_PDF_Document::docReader($formValues['document_file']['name'], $formValues['document_file']['type']);
$formValues['document_file_path'] = $formValues['document_file']['name'];
- // Fixme: this shouldn't be necessary but the above docReader function is giving blank output for docx files
- list($html_message) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
}
if (!empty($formValues['update_format'])) {
$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $templateId);
foreach ((array) $documentInfo as $info) {
- $messages['file_type'] = array_search($info['mime_type'], CRM_Core_SelectValues::documentApplicationType());
- $messages['document_body'] = CRM_Utils_PDF_Document::docReader($info['fullPath'], $messages['file_type'], TRUE);
- $messages['mime_type'] = $info['mime_type'];
+ list($messages['document_body']) = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type']);
}
CRM_Utils_JSON::output($messages);
/**
* @param array $path docx/odt file path
* @param string $type File type
- * @param bool $returnHTMLBody extract entire or only HTNL body content of docx/odt file,
- * later used for token replacement or preview
*
- * @return string|array
- * Return extracted content of document in HTML
+ * @return array
+ * Return extracted content of document in HTML and document type
*/
- public static function docReader($path, $type, $returnHTMLBody = FALSE) {
-
+ public static function docReader($path, $type) {
+ $type = array_search($type, CRM_Core_SelectValues::documentApplicationType());
$fileType = ($type == 'docx') ? 'Word2007' : 'ODText';
+
$phpWord = \PhpOffice\PhpWord\IOFactory::load($path, $fileType);
$phpWordHTML = new \PhpOffice\PhpWord\Writer\HTML($phpWord);
- //return only the HTML body later used for preview
- if ($returnHTMLBody) {
- return $phpWordHTML->getWriterPart('Body')->write();
- }
-
// return the html content for tokenreplacment and eventually used for document download
- return array($phpWordHTML->getContent(), array_search($type, CRM_Core_SelectValues::documentApplicationType()));
+ return array($phpWordHTML->getWriterPart('Body')->write(), $type);
}
/**