mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-01 03:29:05 +01:00
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:
parent
9066385fa5
commit
132cafc8a9
@ -389,53 +389,52 @@ 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
|
switch($mimetype.$mso_application_progid)
|
||||||
if (class_exists(XSLTProcessor) && class_exists(DOMDocument))
|
|
||||||
{
|
{
|
||||||
switch($mimetype.$mso_application_progid)
|
case 'application/vnd.oasis.opendocument.text': // open office
|
||||||
{
|
case 'application/vnd.oasis.opendocument.spreadsheet':
|
||||||
case 'application/vnd.oasis.opendocument.text': // open office
|
// It seems easier to split the parent tags here
|
||||||
case 'application/vnd.oasis.opendocument.spreadsheet':
|
$replace_tags = array(
|
||||||
// It seems easier to split the parent tags here
|
'/<(ol|ul|table)( [^>]*)?>/' => '</text:p><$1$2>',
|
||||||
$replace_tags = array(
|
'/<\/(ol|ul|table)>/' => '</$1><text:p>',
|
||||||
'/<(ol|ul|table)( [^>]*)?>/' => '</text:p><$1$2>',
|
//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$1>',
|
||||||
'/<\/(ol|ul|table)>/' => '</$1><text:p>',
|
);
|
||||||
//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$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);
|
|
||||||
|
|
||||||
$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;
|
|
||||||
case 'application/xmlWord.Document': // Word 2003*/
|
//echo $content;die();
|
||||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
|
break;
|
||||||
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
case 'application/xmlWord.Document': // Word 2003*/
|
||||||
$replace_tags = array(
|
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
|
||||||
'b','strong','i','em','u','span'
|
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
||||||
);
|
$replace_tags = array(
|
||||||
// It seems easier to split the parent tags here
|
'b','strong','i','em','u','span'
|
||||||
$replace_tags = array(
|
);
|
||||||
// Tables, lists don't go inside <w:p>
|
// It seems easier to split the parent tags here
|
||||||
'/<(ol|ul|table)( [^>]*)?>/' => '</w:t></w:r></w:p><$1$2>',
|
$replace_tags = array(
|
||||||
'/<\/(ol|ul|table)>/' => '</$1><w:p><w:r><w:t>',
|
// Tables, lists don't go inside <w:p>
|
||||||
// Fix for things other than text (newlines) inside table row
|
'/<(ol|ul|table)( [^>]*)?>/' => '</w:t></w:r></w:p><$1$2>',
|
||||||
'/<(td)( [^>]*)?>((?!<w:t>))(.*?)<\/td>[\s]*?/' => '<$1$2><w:t>$4</w:t></td>',
|
'/<\/(ol|ul|table)>/' => '</$1><w:p><w:r><w:t>',
|
||||||
// Remove extra whitespace
|
// Fix for things other than text (newlines) inside table row
|
||||||
'/<li([^>]*?)>[^:print:]*?(.*?)<\/li>/' => '<li$1>$2</li>', // This doesn't get it all
|
'/<(td)( [^>]*)?>((?!<w:t>))(.*?)<\/td>[\s]*?/' => '<$1$2><w:t>$4</w:t></td>',
|
||||||
'/<w:t>[\s]+(.*?)<\/w:t>/' => '<w:t>$1</w:t>',
|
// Remove extra whitespace
|
||||||
// Remove spans with no attributes, linebreaks inside them cause problems
|
'/<li([^>]*?)>[^:print:]*?(.*?)<\/li>/' => '<li$1>$2</li>', // This doesn't get it all
|
||||||
'/<span>(.*?)<\/span>/' => '$1'
|
'/<w:t>[\s]+(.*?)<\/w:t>/' => '<w:t>$1</w:t>',
|
||||||
);
|
// Remove spans with no attributes, linebreaks inside them cause problems
|
||||||
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
|
'/<span>(.*?)<\/span>/' => '$1'
|
||||||
$doc = new DOMDocument();
|
);
|
||||||
$xslt = new XSLTProcessor();
|
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
|
||||||
$xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt';
|
//echo $content;die();
|
||||||
$doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/'.$xslt_file);
|
$doc = new DOMDocument();
|
||||||
$xslt->importStyleSheet($doc);
|
$xslt = new XSLTProcessor();
|
||||||
break;
|
$xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt';
|
||||||
}
|
$doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/'.$xslt_file);
|
||||||
|
$xslt->importStyleSheet($doc);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XSLT transform known tags
|
// XSLT transform known tags
|
||||||
@ -445,6 +444,8 @@ 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;
|
||||||
@ -698,23 +699,27 @@ 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)
|
// only keep tags, if we have xsl extension available
|
||||||
|
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':
|
{
|
||||||
$replace_tags = array(
|
case 'application/vnd.oasis.opendocument.text': // open office
|
||||||
'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
|
case 'application/vnd.oasis.opendocument.spreadsheet':
|
||||||
'<table>','<tr>','<td>',
|
$replace_tags = array(
|
||||||
);
|
'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
|
||||||
break;
|
'<table>','<tr>','<td>',
|
||||||
case 'application/xmlWord.Document': // Word 2003*/
|
);
|
||||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
|
break;
|
||||||
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
case 'application/xmlWord.Document': // Word 2003*/
|
||||||
$replace_tags = array(
|
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
|
||||||
'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
|
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
||||||
'<table>','<tr>','<td>',
|
$replace_tags = array(
|
||||||
);
|
'<b>','<strong>','<i>','<em>','<u>','<span>','<ol>','<ul>','<li>',
|
||||||
break;
|
'<table>','<tr>','<td>',
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// clean replacements from array values and html or html-entities, which mess up xml
|
// clean replacements from array values and html or html-entities, which mess up xml
|
||||||
foreach($replacements as $name => &$value)
|
foreach($replacements as $name => &$value)
|
||||||
@ -1040,8 +1045,11 @@ abstract class bo_merge
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply HTML formatting to target document, if possible
|
// Apply HTML formatting to target document, if possible
|
||||||
$this->apply_styles($merged, $mimetype);
|
// 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($name))
|
||||||
{
|
{
|
||||||
if(empty($ext))
|
if(empty($ext))
|
||||||
|
Loading…
Reference in New Issue
Block a user