wrong formatted filetype fix
authordeb.monish <monish.deb@webaccessglobal.com>
Fri, 15 Jul 2016 15:50:49 +0000 (21:20 +0530)
committerdeb.monish <monish.deb@webaccessglobal.com>
Fri, 15 Jul 2016 19:09:25 +0000 (00:39 +0530)
CRM/Contact/Form/Task/PDFLetterCommon.php
CRM/Mailing/Page/AJAX.php
CRM/Utils/PDF/Document.php

index 5a242814cdf6f0b0d486acbc7a6bbe4f030ba6d3..e4849c93af5f6f6dcc3f8ad6e18c8fec7f11d909 100644 (file)
@@ -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'])) {
index 075e2d1f8cbecd0400baa7f9aeb78a99d687ceed..80df5a15c7c2c277cb71b519940bbd6889fbb1ba 100644 (file)
@@ -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);
index 8c9fc659780ca748d2578bfbb8c4b3b3209840a2..b18fdb55c2eb6c9cffa1be2d0e7a432258c9912e 100644 (file)
@@ -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);
   }
 
   /**