diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index 3b85d98953..e367ccef55 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -313,8 +313,65 @@ abstract class bo_merge { $mimetype = 'application/rtf'; } + + // Apply HTML formatting to target document, if possible try { - return $this->merge_string($content,$ids,$err,$mimetype,$fix); + $content = $this->merge_string($content,$ids,$err,$mimetype,$fix); + // Tags we can replace with the target document's version + $replace_tags = array(); + switch($mimetype) + { + 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>', + '/<\/(ol|ul|table)>/' => '', + //'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3', + ); + $content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content); +//echo $content;die(); + $doc = new DOMDocument(); + $xslt = new XSLTProcessor(); + $doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/openoffice.xslt'); + $xslt->importStyleSheet($doc); + break; + 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( + '/<(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); +//echo $content;die(); + $doc = new DOMDocument(); + $xslt = new XSLTProcessor(); + $doc->load(EGW_INCLUDE_ROOT.'/etemplate/templates/default/msoffice.xslt'); + $xslt->importStyleSheet($doc); + break; + } + // XSLT transform known tags + if($xslt) + { + try + { + $element = new SimpleXMLelement($content); + $content = $xslt->transformToXml($element); +//echo $content;die(); + } + catch (Exception $e) + { +echo $content;die(); + // Failed... + } + } + return $content; + } catch (Exception $e) { $err = $e->getMessage(); return false; @@ -543,6 +600,7 @@ abstract class bo_merge break; } //error_log(__METHOD__."('$document', ... ,$mimetype) --> $charset (egw=".translation::charset().', export='.$this->contacts->prefs['csv_charset'].')'); + // do we need to convert charset if ($charset && $charset != translation::charset()) { @@ -553,6 +611,25 @@ abstract class bo_merge // Numeric fields $names = array(); + // Tags we can replace with the target document's version + $replace_tags = array(); + switch($mimetype) + { + case 'application/vnd.oasis.opendocument.text': // open office + case 'application/vnd.oasis.opendocument.spreadsheet': + $replace_tags = array( + '','','','','','','
    ','
      ','
    • ', + '','','
      ', + ); + break; + 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) { @@ -578,7 +655,8 @@ abstract class bo_merge { // replace

          and
          with CRLF (remove

          and CRLF) $value = str_replace(array("\r","\n",'

          ','

          ','
          '),array('','','',"\r\n","\r\n"),$value); - $value = strip_tags($value); + //$value = strip_tags($value); + $value = strip_tags($value,implode('',$replace_tags)); } // replace all control chars (C0+C1) but CR (\015), LF (\012) and TAB (\011) (eg. vertical tabulators) with space // as they are not allowed in xml @@ -637,7 +715,7 @@ abstract class bo_merge $break = ''; break; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms word 2007 - $break = ''; + $break = ''; break; case 'application/xmlExcel.Sheet': // Excel 2003 $break = ' '; @@ -654,7 +732,8 @@ abstract class bo_merge break; } // now decode &, < and >, which need to be encoded as entities in xml - $replacements = str_replace(array('&','<','>',"\r","\n"),array('&','<','>','',$break),$replacements); + //$replacements = str_replace(array('&','<','>',"\r","\n"),array('&','<','>','',$break),$replacements); + $replacements = str_replace(array('&',"\r","\n"),array('&','',$break),$replacements); } return str_replace(array_keys($replacements),array_values($replacements),$content); } diff --git a/etemplate/templates/default/msoffice.xslt b/etemplate/templates/default/msoffice.xslt new file mode 100644 index 0000000000..3abf53856e --- /dev/null +++ b/etemplate/templates/default/msoffice.xslt @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + . + + + + + + · + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etemplate/templates/default/openoffice.xslt b/etemplate/templates/default/openoffice.xslt new file mode 100644 index 0000000000..381ac9e01a --- /dev/null +++ b/etemplate/templates/default/openoffice.xslt @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +