From 5926c5e7be39e3ec202950e60805d4e2a6097715 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 7 Mar 2017 12:08:01 -0700 Subject: [PATCH] Allow docm and xlsm merge templates --- api/src/Storage/Merge.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index 1d12edb848..dce8bfcd03 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -178,8 +178,10 @@ abstract class Merge return true; // open office write xml files case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms word 2007 xml format case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': // ms excel 2007 xml format case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee': + case 'application/vnd.ms-excel.sheet.macroenabled.12': if (!$zip_available) break; return true; // ms word xml format case 'application/xml': @@ -617,7 +619,9 @@ abstract class Merge break; case 'application/xmlWord.Document': // Word 2003*/ case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': // It seems easier to split the parent tags here $replace_tags = array( // Tables, lists don't go inside @@ -758,7 +762,7 @@ abstract class Merge list($contentstart,$contentrepeat,$contentend) = preg_split('/\$\$pagerepeat\$\$/',$content,-1, PREG_SPLIT_NO_EMPTY); //get different parts of document, seperated by pagerepeat } } - if ($mimetype == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' && count($ids) > 1) + if (in_array($mimetype, array('application/vnd.ms-word.document.macroenabled.12', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')) && count($ids) > 1) { //for Word 2007 XML files we have to split the content and add a style for page break to the style area list($contentstart,$contentrepeat,$contentend) = preg_split('/w:body>/',$content,-1, PREG_SPLIT_NO_EMPTY); //get differt parts of document, seperatet by Pagerepeat @@ -797,7 +801,9 @@ abstract class Merge $joiner = ''; break; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': $joiner = ''; break; case 'text/plain': @@ -904,7 +910,9 @@ abstract class Merge case 'application/vnd.oasis.opendocument.spreadsheet': return $contentstart.implode('',$contentrepeatpages).$contentend; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': return $contentstart.implode('',$contentrepeatpages).$contentend; case 'text/plain': return $contentstart.implode("\r\n",$contentrep).$contentend; @@ -941,7 +949,9 @@ abstract class Merge case 'application/vnd.oasis.opendocument.text': // open office case 'application/vnd.oasis.opendocument.spreadsheet': case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': case 'application/xml': case 'text/xml': $is_xml = true; @@ -1012,7 +1022,9 @@ abstract class Merge break; case 'application/xmlWord.Document': // Word 2003*/ case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': $replace_tags = array( '','','','','','','
    ','
      ','
    • ', '','','
      ', @@ -1120,6 +1132,7 @@ abstract class Merge $break = ''; break; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms word 2007 + case 'application/vnd.ms-word.document.macroenabled.12': $break = ''; break; case 'application/xmlExcel.Sheet': // Excel 2003 @@ -1132,6 +1145,7 @@ abstract class Merge $break = '
      '; break; case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': // ms excel 2007 + case 'application/vnd.ms-excel.sheet.macroenabled.12': default: $break = "\r\n"; break; @@ -1301,7 +1315,8 @@ abstract class Merge { $date = new Api\DateTime($values[$key]); } - if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF + if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || + $mimetype == 'application/vnd.ms-excel.sheet.macroenabled.12')//Excel WTF { $interval = $date->diff(new Api\DateTime('1900-01-00 0:00')); $values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist @@ -1334,6 +1349,7 @@ abstract class Merge break; case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': break; } if($format && $names) @@ -1491,7 +1507,9 @@ abstract class Merge case 'application/vnd.oasis.opendocument.text': // open office case 'application/vnd.oasis.opendocument.spreadsheet': case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': case 'application/xml': case 'text/xml': case 'text/html': @@ -1515,7 +1533,9 @@ abstract class Merge $LF = ' '; break; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': + case 'application/vnd.ms-word.document.macroenabled.12': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': $LF ='
      '; break; case 'application/xml'; @@ -1605,6 +1625,7 @@ abstract class Merge case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars $mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': + case 'application/vnd.ms-word.document.macroenabled.12': $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.docx').'-').'.docx'; copy($content_url,$archive); $content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml'); @@ -1629,6 +1650,7 @@ abstract class Merge case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee': $mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + case 'application/vnd.ms-excel.sheet.macroenabled.12': $fix = array( // hack to get Excel 2007 to display additional rows in tables '/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"', );