Allow docm and xlsm merge templates

This commit is contained in:
nathangray 2017-03-07 12:08:01 -07:00
parent 2dbe3e785e
commit 5926c5e7be

View File

@ -178,8 +178,10 @@ abstract class Merge
return true; // open office write xml files 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.document': // ms word 2007 xml format
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars 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.sheet': // ms excel 2007 xml format
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
if (!$zip_available) break; if (!$zip_available) break;
return true; // ms word xml format return true; // ms word xml format
case 'application/xml': case 'application/xml':
@ -617,7 +619,9 @@ abstract class Merge
break; break;
case 'application/xmlWord.Document': // Word 2003*/ case 'application/xmlWord.Document': // Word 2003*/
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 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.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
// It seems easier to split the parent tags here // It seems easier to split the parent tags here
$replace_tags = array( $replace_tags = array(
// Tables, lists don't go inside <w:p> // Tables, lists don't go inside <w:p>
@ -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 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 //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 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 = ''; $joiner = '';
break; break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 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.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
$joiner = '<w:br w:type="page" />'; $joiner = '<w:br w:type="page" />';
break; break;
case 'text/plain': case 'text/plain':
@ -904,7 +910,9 @@ abstract class Merge
case 'application/vnd.oasis.opendocument.spreadsheet': case 'application/vnd.oasis.opendocument.spreadsheet':
return $contentstart.implode('</text:p><text:p>',$contentrepeatpages).$contentend; return $contentstart.implode('</text:p><text:p>',$contentrepeatpages).$contentend;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 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.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
return $contentstart.implode('<w:br w:type="page" />',$contentrepeatpages).$contentend; return $contentstart.implode('<w:br w:type="page" />',$contentrepeatpages).$contentend;
case 'text/plain': case 'text/plain':
return $contentstart.implode("\r\n",$contentrep).$contentend; 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.text': // open office
case 'application/vnd.oasis.opendocument.spreadsheet': case 'application/vnd.oasis.opendocument.spreadsheet':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 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.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
case 'application/xml': case 'application/xml':
case 'text/xml': case 'text/xml':
$is_xml = true; $is_xml = true;
@ -1012,7 +1022,9 @@ abstract class Merge
break; break;
case 'application/xmlWord.Document': // Word 2003*/ case 'application/xmlWord.Document': // Word 2003*/
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 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.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
$replace_tags = array( $replace_tags = array(
'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>', '<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
'<table>','<tr>','<td>', '<table>','<tr>','<td>',
@ -1120,6 +1132,7 @@ abstract class Merge
$break = '</text:p><text:p>'; $break = '</text:p><text:p>';
break; break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms word 2007 case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms word 2007
case 'application/vnd.ms-word.document.macroenabled.12':
$break = '</w:t><w:br/><w:t>'; $break = '</w:t><w:br/><w:t>';
break; break;
case 'application/xmlExcel.Sheet': // Excel 2003 case 'application/xmlExcel.Sheet': // Excel 2003
@ -1132,6 +1145,7 @@ abstract class Merge
$break = '<br/>'; $break = '<br/>';
break; break;
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': // ms excel 2007 case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': // ms excel 2007
case 'application/vnd.ms-excel.sheet.macroenabled.12':
default: default:
$break = "\r\n"; $break = "\r\n";
break; break;
@ -1301,7 +1315,8 @@ abstract class Merge
{ {
$date = new Api\DateTime($values[$key]); $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')); $interval = $date->diff(new Api\DateTime('1900-01-00 0:00'));
$values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist $values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist
@ -1334,6 +1349,7 @@ abstract class Merge
break; break;
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
break; break;
} }
if($format && $names) if($format && $names)
@ -1491,7 +1507,9 @@ abstract class Merge
case 'application/vnd.oasis.opendocument.text': // open office case 'application/vnd.oasis.opendocument.text': // open office
case 'application/vnd.oasis.opendocument.spreadsheet': case 'application/vnd.oasis.opendocument.spreadsheet':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 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.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
case 'application/xml': case 'application/xml':
case 'text/xml': case 'text/xml':
case 'text/html': case 'text/html':
@ -1515,7 +1533,9 @@ abstract class Merge
$LF = '&#10;'; $LF = '&#10;';
break; break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 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.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.ms-excel.sheet.macroenabled.12':
$LF ='</w:t></w:r></w:p><w:p><w:r><w:t>'; $LF ='</w:t></w:r></w:p><w:p><w:r><w:t>';
break; break;
case 'application/xml'; 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 case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d': // mimetypes in vfs are limited to 64 chars
$mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; $mimetype = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
case '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'; $archive = tempnam($GLOBALS['egw_info']['server']['temp_dir'], basename($document,'.docx').'-').'.docx';
copy($content_url,$archive); copy($content_url,$archive);
$content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml'); $content_url = 'zip://'.$archive.'#'.($content_file = 'word/document.xml');
@ -1629,6 +1650,7 @@ abstract class Merge
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.shee':
$mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
case '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 $fix = array( // hack to get Excel 2007 to display additional rows in tables
'/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"', '/ss:ExpandedRowCount="\d+"/' => 'ss:ExpandedRowCount="9999"',
); );