From 3bdbeef5d611a11ff425d3c3f415bd7bec855de7 Mon Sep 17 00:00:00 2001
From: Nathan Gray
Date: Wed, 7 Sep 2011 15:51:33 +0000
Subject: [PATCH] Taming tidy - fixes extra line breaks, don't detect encoding.
---
etemplate/inc/class.bo_merge.inc.php | 22 ++++++++++++++++++---
etemplate/templates/default/msoffice.xslt | 24 ++++++++++++++++++++---
etemplate/templates/default/wordml.xslt | 18 +++++++++++++++--
3 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php
index 2edab94c90..13f4e39ae6 100644
--- a/etemplate/inc/class.bo_merge.inc.php
+++ b/etemplate/inc/class.bo_merge.inc.php
@@ -64,6 +64,12 @@ abstract class bo_merge
'clean' => true,
'output-xhtml' => true,
'show-body-only' => true,
+ 'output-encoding' => 'utf-8',
+ 'input-encoding' => 'utf-8',
+ 'quote-ampersand' => false, // Prevent double encoding
+ 'quote-nbsp' => true, // XSLT can handle spaces easier
+ 'preserve-entities' => true,
+ 'wrap' => 0, // Wrapping can break output
);
/**
@@ -734,9 +740,19 @@ abstract class bo_merge
if (is_string($value) && (strpos($value,'<') !== false))
{
// Clean HTML, if it's being kept
- if($replace_tags && extension_loaded('tidy'))
- {
- $value = tidy_repair_string($value, self::$tidy_config, 'utf8');
+ if($replace_tags && extension_loaded('tidy')) {
+ $tidy = new tidy();
+ $cleaned = $tidy->repairString($value, self::$tidy_config);
+ // Found errors. Strip it all so there's some output
+ if($tidy->getStatus() == 2)
+ {
+ error_log($tidy->errorBuffer);
+ $value = strip_tags($value);
+ }
+ else
+ {
+ $value = $cleaned;
+ }
}
// replace
and
with CRLF (remove and CRLF)
$value = str_replace(array("\r","\n",'
','
','
'),array('','','',"\r\n","\r\n"),$value);
diff --git a/etemplate/templates/default/msoffice.xslt b/etemplate/templates/default/msoffice.xslt
index ebee7ad9dc..d39af698c1 100644
--- a/etemplate/templates/default/msoffice.xslt
+++ b/etemplate/templates/default/msoffice.xslt
@@ -86,7 +86,11 @@ Breakers
-->
-
+
+
+
+
+
@@ -210,9 +214,23 @@ Breakers
·
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/etemplate/templates/default/wordml.xslt b/etemplate/templates/default/wordml.xslt
index 15025c4255..d4be265251 100644
--- a/etemplate/templates/default/wordml.xslt
+++ b/etemplate/templates/default/wordml.xslt
@@ -208,9 +208,23 @@ Breakers
·
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+