diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index e9874638a6..62758e6028 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -389,53 +389,52 @@ 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) { - switch($mimetype.$mso_application_progid) - { - case 'application/vnd.oasis.opendocument.text': // open office - case 'application/vnd.oasis.opendocument.spreadsheet': - // It seems easier to split the parent tags here - $replace_tags = array( - '/<(ol|ul|table)( [^>]*)?>/' => '<$1$2>', - '/<\/(ol|ul|table)>/' => '', - //'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3', - ); - $content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content); + case 'application/vnd.oasis.opendocument.text': // open office + case 'application/vnd.oasis.opendocument.spreadsheet': + // It seems easier to split the parent tags here + $replace_tags = array( + '/<(ol|ul|table)( [^>]*)?>/' => '<$1$2>', + '/<\/(ol|ul|table)>/' => '', + //'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3', + ); + $content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content); - $doc = new DOMDocument(); - $xslt = new XSLTProcessor(); - $doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/openoffice.xslt'); - $xslt->importStyleSheet($doc); - break; - case 'application/xmlWord.Document': // Word 2003*/ - case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 - case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': - $replace_tags = array( - 'b','strong','i','em','u','span' - ); - // It seems easier to split the parent tags here - $replace_tags = array( - // Tables, lists don't go inside - '/<(ol|ul|table)( [^>]*)?>/' => '<$1$2>', - '/<\/(ol|ul|table)>/' => '', - // Fix for things other than text (newlines) inside table row - '/<(td)( [^>]*)?>((?!))(.*?)<\/td>[\s]*?/' => '<$1$2>$4', - // Remove extra whitespace - '/]*?)>[^:print:]*?(.*?)<\/li>/' => '$2', // This doesn't get it all - '/[\s]+(.*?)<\/w:t>/' => '$1', - // Remove spans with no attributes, linebreaks inside them cause problems - '/(.*?)<\/span>/' => '$1' - ); - $content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content); - $doc = new DOMDocument(); - $xslt = new XSLTProcessor(); - $xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt'; - $doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/'.$xslt_file); - $xslt->importStyleSheet($doc); - break; - } + $doc = new DOMDocument(); + $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 + case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + $replace_tags = array( + 'b','strong','i','em','u','span' + ); + // It seems easier to split the parent tags here + $replace_tags = array( + // Tables, lists don't go inside + '/<(ol|ul|table)( [^>]*)?>/' => '<$1$2>', + '/<\/(ol|ul|table)>/' => '', + // Fix for things other than text (newlines) inside table row + '/<(td)( [^>]*)?>((?!))(.*?)<\/td>[\s]*?/' => '<$1$2>$4', + // Remove extra whitespace + '/]*?)>[^:print:]*?(.*?)<\/li>/' => '$2', // This doesn't get it all + '/[\s]+(.*?)<\/w:t>/' => '$1', + // Remove spans with no attributes, linebreaks inside them cause problems + '/(.*?)<\/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'; + $doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/'.$xslt_file); + $xslt->importStyleSheet($doc); + break; } // XSLT transform known tags @@ -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, ''.$content; @@ -698,23 +699,27 @@ abstract class bo_merge // Tags we can replace with the target document's version $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 - case 'application/vnd.oasis.opendocument.spreadsheet': - $replace_tags = array( - '','','','','','','
    ','
      ','
    • ', - '','','
      ', - ); - break; - case 'application/xmlWord.Document': // Word 2003*/ - case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 - case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': - $replace_tags = array( - '','','','','','','
        ','
          ','
        • ', - '','','
          ', - ); - break; + switch($mimetype.$mso_application_progid) + { + case 'application/vnd.oasis.opendocument.text': // open office + case 'application/vnd.oasis.opendocument.spreadsheet': + $replace_tags = array( + '','','','','','','
            ','
              ','
            • ', + '','','
              ', + ); + break; + case 'application/xmlWord.Document': // Word 2003*/ + case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 + case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + $replace_tags = array( + '','','','','','','
                ','
                  ','
                • ', + '','','
                  ', + ); + 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 - $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($ext))