check if we can use the XSL extension, to not give a fatal error and rendering whole merge-print non-functional

This commit is contained in:
Ralf Becker 2011-09-12 10:21:18 +00:00
parent 2aff9d170b
commit 9066385fa5

View File

@ -389,6 +389,9 @@ abstract class bo_merge
} }
// Tags we can replace with the target document's version // Tags we can replace with the target document's version
$replace_tags = array(); $replace_tags = array();
// check if we can use the XSL extension, to not give a fatal error and rendering whole merge-print non-functional
if (class_exists(XSLTProcessor) && class_exists(DOMDocument))
{
switch($mimetype.$mso_application_progid) switch($mimetype.$mso_application_progid)
{ {
case 'application/vnd.oasis.opendocument.text': // open office case 'application/vnd.oasis.opendocument.text': // open office
@ -405,8 +408,6 @@ abstract class bo_merge
$xslt = new XSLTProcessor(); $xslt = new XSLTProcessor();
$doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/openoffice.xslt'); $doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/openoffice.xslt');
$xslt->importStyleSheet($doc); $xslt->importStyleSheet($doc);
//echo $content;die();
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
@ -428,7 +429,6 @@ abstract class bo_merge
'/<span>(.*?)<\/span>/' => '$1' '/<span>(.*?)<\/span>/' => '$1'
); );
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content); $content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
//echo $content;die();
$doc = new DOMDocument(); $doc = new DOMDocument();
$xslt = new XSLTProcessor(); $xslt = new XSLTProcessor();
$xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt'; $xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt';
@ -436,6 +436,7 @@ abstract class bo_merge
$xslt->importStyleSheet($doc); $xslt->importStyleSheet($doc);
break; break;
} }
}
// XSLT transform known tags // XSLT transform known tags
if($xslt) if($xslt)
@ -444,8 +445,6 @@ abstract class bo_merge
{ {
$element = new SimpleXMLelement($content); $element = new SimpleXMLelement($content);
$content = @$xslt->transformToXml($element); $content = @$xslt->transformToXml($element);
//echo $content;die();
// Word 2003 needs two declarations, add extra declaration back in // Word 2003 needs two declarations, add extra declaration back in
if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) { if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content; $content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;