forked from extern/egroupware
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:
parent
2aff9d170b
commit
9066385fa5
@ -389,52 +389,53 @@ 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();
|
||||||
switch($mimetype.$mso_application_progid)
|
// 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))
|
||||||
{
|
{
|
||||||
case 'application/vnd.oasis.opendocument.text': // open office
|
switch($mimetype.$mso_application_progid)
|
||||||
case 'application/vnd.oasis.opendocument.spreadsheet':
|
{
|
||||||
// It seems easier to split the parent tags here
|
case 'application/vnd.oasis.opendocument.text': // open office
|
||||||
$replace_tags = array(
|
case 'application/vnd.oasis.opendocument.spreadsheet':
|
||||||
'/<(ol|ul|table)( [^>]*)?>/' => '</text:p><$1$2>',
|
// It seems easier to split the parent tags here
|
||||||
'/<\/(ol|ul|table)>/' => '</$1><text:p>',
|
$replace_tags = array(
|
||||||
//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$1>',
|
'/<(ol|ul|table)( [^>]*)?>/' => '</text:p><$1$2>',
|
||||||
);
|
'/<\/(ol|ul|table)>/' => '</$1><text:p>',
|
||||||
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
|
//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$1>',
|
||||||
|
);
|
||||||
|
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
|
||||||
|
|
||||||
$doc = new DOMDocument();
|
$doc = new DOMDocument();
|
||||||
$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);
|
||||||
|
break;
|
||||||
//echo $content;die();
|
case 'application/xmlWord.Document': // Word 2003*/
|
||||||
break;
|
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
|
||||||
case 'application/xmlWord.Document': // Word 2003*/
|
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
||||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
|
$replace_tags = array(
|
||||||
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
'b','strong','i','em','u','span'
|
||||||
$replace_tags = array(
|
);
|
||||||
'b','strong','i','em','u','span'
|
// It seems easier to split the parent tags here
|
||||||
);
|
$replace_tags = array(
|
||||||
// It seems easier to split the parent tags here
|
// Tables, lists don't go inside <w:p>
|
||||||
$replace_tags = array(
|
'/<(ol|ul|table)( [^>]*)?>/' => '</w:t></w:r></w:p><$1$2>',
|
||||||
// Tables, lists don't go inside <w:p>
|
'/<\/(ol|ul|table)>/' => '</$1><w:p><w:r><w:t>',
|
||||||
'/<(ol|ul|table)( [^>]*)?>/' => '</w:t></w:r></w:p><$1$2>',
|
// Fix for things other than text (newlines) inside table row
|
||||||
'/<\/(ol|ul|table)>/' => '</$1><w:p><w:r><w:t>',
|
'/<(td)( [^>]*)?>((?!<w:t>))(.*?)<\/td>[\s]*?/' => '<$1$2><w:t>$4</w:t></td>',
|
||||||
// Fix for things other than text (newlines) inside table row
|
// Remove extra whitespace
|
||||||
'/<(td)( [^>]*)?>((?!<w:t>))(.*?)<\/td>[\s]*?/' => '<$1$2><w:t>$4</w:t></td>',
|
'/<li([^>]*?)>[^:print:]*?(.*?)<\/li>/' => '<li$1>$2</li>', // This doesn't get it all
|
||||||
// Remove extra whitespace
|
'/<w:t>[\s]+(.*?)<\/w:t>/' => '<w:t>$1</w:t>',
|
||||||
'/<li([^>]*?)>[^:print:]*?(.*?)<\/li>/' => '<li$1>$2</li>', // This doesn't get it all
|
// Remove spans with no attributes, linebreaks inside them cause problems
|
||||||
'/<w:t>[\s]+(.*?)<\/w:t>/' => '<w:t>$1</w:t>',
|
'/<span>(.*?)<\/span>/' => '$1'
|
||||||
// Remove spans with no attributes, linebreaks inside them cause problems
|
);
|
||||||
'/<span>(.*?)<\/span>/' => '$1'
|
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
|
||||||
);
|
$doc = new DOMDocument();
|
||||||
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
|
$xslt = new XSLTProcessor();
|
||||||
//echo $content;die();
|
$xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt';
|
||||||
$doc = new DOMDocument();
|
$doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/'.$xslt_file);
|
||||||
$xslt = new XSLTProcessor();
|
$xslt->importStyleSheet($doc);
|
||||||
$xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt';
|
break;
|
||||||
$doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/'.$xslt_file);
|
}
|
||||||
$xslt->importStyleSheet($doc);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// XSLT transform known tags
|
// XSLT transform known tags
|
||||||
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user