From: deb.monish Date: Fri, 15 Jul 2016 15:50:49 +0000 (+0530) Subject: wrong formatted filetype fix X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=00eb08cf90f080eaa50d6b66838d386a0e89821a;p=civicrm-core.git wrong formatted filetype fix --- diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index 5a242814cd..e4849c93af 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -302,8 +302,6 @@ class CRM_Contact_Form_Task_PDFLetterCommon { 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'])) { diff --git a/CRM/Mailing/Page/AJAX.php b/CRM/Mailing/Page/AJAX.php index 075e2d1f8c..80df5a15c7 100644 --- a/CRM/Mailing/Page/AJAX.php +++ b/CRM/Mailing/Page/AJAX.php @@ -56,9 +56,7 @@ class CRM_Mailing_Page_AJAX { $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); diff --git a/CRM/Utils/PDF/Document.php b/CRM/Utils/PDF/Document.php index 8c9fc65978..b18fdb55c2 100644 --- a/CRM/Utils/PDF/Document.php +++ b/CRM/Utils/PDF/Document.php @@ -131,25 +131,19 @@ class CRM_Utils_PDF_Document { /** * @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); } /**