From 77a80c4e2ab79078373a9978a9b31fd9ed6e8867 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Mon, 6 Jun 2016 16:12:14 +0530 Subject: [PATCH] improvement in docReader fn --- CRM/Utils/PDF/Document.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/CRM/Utils/PDF/Document.php b/CRM/Utils/PDF/Document.php index 51432213d1..81da9b58ea 100644 --- a/CRM/Utils/PDF/Document.php +++ b/CRM/Utils/PDF/Document.php @@ -104,19 +104,28 @@ class CRM_Utils_PDF_Document { * Return filepath of created html copy of document OR extracted content of document */ public static function docReader($path, $type, $returnContent = FALSE) { + // get path of civicrm upload directory which is used for temporary file storage + $uploadDir = Civi::settings()->get('uploadDir'); + + // build the path of of new html file + $pathInfo = pathinfo($path); + $newFile = $pathInfo['filename'] . ".html"; + $absPath = Civi::paths()->getPath($uploadDir) . $newFile; + + // cleanup temporary html file created for preview + if (file_exists($absPath)) { + unlink($absPath); + } + if ($returnContent) { return self::doc2Text($path, $type); } - $newpath = str_replace('.' . $type, '.html', $path); $fileType = ($type == 'docx') ? 'Word2007' : 'ODText'; - if (!file_exists($newpath)) { - $phpWord = \PhpOffice\PhpWord\IOFactory::load($path, $fileType); - $phpWord->save($newpath, 'HTML'); - } + $phpWord = \PhpOffice\PhpWord\IOFactory::load($path, $fileType); + $phpWord->save($absPath, 'HTML'); - $relPath = str_replace('/Users/monish/www/civicrm-master/', CRM_Utils_System::baseURL(), $newpath); - return $relPath; + return \Civi::paths()->getUrl($uploadDir) . $newFile; } /** -- 2.25.1