check if we can use the XSL extension, to not give a fatal error and rendering whole merge-print non-functional AND only keep tags, if XSL is available

This commit is contained in:
Ralf Becker 2011-09-12 10:51:21 +00:00
parent 9066385fa5
commit 132cafc8a9

View File

@ -389,9 +389,6 @@ abstract class bo_merge
}
// Tags we can replace with the target document's version
$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)
{
case 'application/vnd.oasis.opendocument.text': // open office
@ -408,6 +405,8 @@ abstract class bo_merge
$xslt = new XSLTProcessor();
$doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/openoffice.xslt');
$xslt->importStyleSheet($doc);
//echo $content;die();
break;
case 'application/xmlWord.Document': // Word 2003*/
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
@ -429,6 +428,7 @@ abstract class bo_merge
'/<span>(.*?)<\/span>/' => '$1'
);
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
//echo $content;die();
$doc = new DOMDocument();
$xslt = new XSLTProcessor();
$xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt';
@ -436,7 +436,6 @@ abstract class bo_merge
$xslt->importStyleSheet($doc);
break;
}
}
// XSLT transform known tags
if($xslt)
@ -445,6 +444,8 @@ abstract class bo_merge
{
$element = new SimpleXMLelement($content);
$content = @$xslt->transformToXml($element);
//echo $content;die();
// Word 2003 needs two declarations, add extra declaration back in
if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
@ -698,6 +699,9 @@ abstract class bo_merge
// Tags we can replace with the target document's version
$replace_tags = array();
// only keep tags, if we have xsl extension available
if (class_exists(XSLTProcessor) && class_exists(DOMDocument))
{
switch($mimetype.$mso_application_progid)
{
case 'application/vnd.oasis.opendocument.text': // open office
@ -716,6 +720,7 @@ abstract class bo_merge
);
break;
}
}
// clean replacements from array values and html or html-entities, which mess up xml
foreach($replacements as $name => &$value)
{
@ -1040,8 +1045,11 @@ abstract class bo_merge
}
// Apply HTML formatting to target document, if possible
// 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))
{
$this->apply_styles($merged, $mimetype);
}
if(!empty($name))
{
if(empty($ext))