Move applying HTML styles into its own function

This commit is contained in:
Nathan Gray 2011-08-02 18:41:18 +00:00
parent a182e0b9cc
commit e6355334f4

View File

@ -314,9 +314,16 @@ abstract class bo_merge
$mimetype = 'application/rtf'; $mimetype = 'application/rtf';
} }
// Apply HTML formatting to target document, if possible
try { try {
$content = $this->merge_string($content,$ids,$err,$mimetype,$fix); $content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
} catch (Exception $e) {
$err = $e->getMessage();
return false;
}
return $content;
}
protected function apply_styles (&$content, $mimetype) {
// 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) switch($mimetype)
@ -330,11 +337,13 @@ abstract class bo_merge
//'/<(li)(.*?)>(.*?)<\/\1>/' => '<$1 $2>$3</$1>', //'/<(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);
//echo $content;die();
$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);
//echo $content;die();
break; break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
@ -370,12 +379,6 @@ abstract class bo_merge
// Failed... // Failed...
} }
} }
return $content;
} catch (Exception $e) {
$err = $e->getMessage();
return false;
}
} }
/** /**
@ -937,6 +940,10 @@ abstract class bo_merge
//error_log(__METHOD__."() !this->merge() err=$err"); //error_log(__METHOD__."() !this->merge() err=$err");
return $err; return $err;
} }
// Apply HTML formatting to target document, if possible
$this->apply_styles($merged, $mimetype);
if(!empty($name)) if(!empty($name))
{ {
if(empty($ext)) if(empty($ext))