This partially reverts commit
e60da622060274282dd92c2d41c4c0dce4724dd6.
Horde_Text_Filter is not part of Horde the application - so there is no
guarantee that text is in UTF-8. In fact, much of the usefulness of
this package is it does the necessary charset conversion as needed.
Example: for Horde_Mime_Part objects created from message data, the text
may be in a different charset than UTF-8. This is perfectly fine -
unnecessary charset conversion may just be a waste of time.
This fixes incorrect character display in IMP (at least for the few
messages I have tested so far).
*/
protected $_params = array(
'body_only' => false,
+ 'charset' => 'us-ascii',
'size' => false
);
'wrap' => 0
);
- $tidy = @tidy_parse_string($text, $tidy_config, 'utf8');
- $tidy->cleanRepair();
+ if (strtolower($this->_params['charset']) == 'us-ascii') {
+ $tidy = @tidy_parse_string($text, $tidy_config, 'ascii');
+ $tidy->cleanRepair();
+ $text = tidy_get_output($tidy);
+ } else {
+ $tidy = @tidy_parse_string(Horde_String::convertCharset($text, $this->_params['charset'], 'UTF-8'), $tidy_config, 'utf8');
+ $tidy->cleanRepair();
+ $text = Horde_String::convertCharset(tidy_get_output($tidy), 'UTF-8', $this->_params['charset']);
+ }
- return tidy_get_output($tidy);
+ return $text;
}
}
*/
protected $_params = array(
'callback' => null,
+ 'charset' => 'UTF-8',
'width' => 75
);
public function postProcess($text)
{
try {
- $dom = new Horde_Domhtml($text, 'UTF-8');
- $text = $this->_node($dom->dom, $dom->dom);
+ $dom = new Horde_Domhtml($text, $this->_params['charset']);
+ $text = Horde_String::convertCharset($this->_node($dom->dom, $dom->dom), null, $this->_params['charset']);
$dom_convert = true;
} catch (Exception $e) {
$text = strip_tags(preg_replace("/\<br\s*\/?\>/i", "\n", $text));
if ($dom_convert &&
$this->_params['_bq'] &&
class_exists('Horde_Text_Flowed')) {
- $flowed = new Horde_Text_Flowed($text, 'UTF-8');
+ $flowed = new Horde_Text_Flowed($text, $this->_params['charset']);
$flowed->setOptLength($this->_params['width']);
$text = $flowed->toFlowed();
} else {
* @var array
*/
protected $_params = array(
+ 'charset' => 'ISO-8859-1',
'encode' => false,
'encode_all' => false
);
public function preProcess($text)
{
if ($this->_params['encode']) {
- $text = htmlspecialchars($text);
+ $text = @htmlspecialchars($text, ENT_COMPAT, $this->_params['charset']);
}
return $text;
}
* @var array
*/
protected $_params = array(
+ 'charset' => 'ISO-8859-1',
'class' => 'fixed',
'emails' => false,
'linkurls' => false,
);
/**
+ * Constructor.
+ *
+ * @param array $params Any parameters that the filter instance needs.
+ */
+ public function __construct($params = array())
+ {
+ parent::__construct($params);
+
+ // Use ISO-8859-1 instead of US-ASCII
+ if (Horde_String::lower($this->_params['charset']) == 'us-ascii') {
+ $this->_params['charset'] = 'iso-8859-1';
+ }
+ }
+
+ /**
* Executes any code necessary before applying the filter patterns.
*
* @param string $text The text before the filtering.
}
if ($this->_params['parselevel'] == self::NOHTML_NOBREAK) {
- return htmlspecialchars($text);
+ return @htmlspecialchars($text, ENT_COMPAT, $this->_params['charset']);
}
if ($this->_params['parselevel'] < self::NOHTML) {
/* For level MICRO or NOHTML, start with htmlspecialchars(). */
$old_error = error_reporting(0);
- $text2 = htmlspecialchars($text);
+ $text2 = htmlspecialchars($text, ENT_COMPAT, $this->_params['charset']);
/* Bad charset input in may result in an empty string. If so, try
* using the default charset encoding instead. */
if (!$text2) {
- $text2 = htmlspecialchars($text);
+ $text2 = htmlspecialchars($text, ENT_COMPAT);
}
$text = $text2;
error_reporting($old_error);
* Filter parameters:
* ------------------
* <pre>
+ * 'charset' - (string) The charset of the text.
+ * DEFAULT: UTF-8
* 'noprefetch' - (boolean) Disable DNS pre-fetching? See:
* https://developer.mozilla.org/En/Controlling_DNS_prefetching
* DEFAULT: false
* @var array
*/
protected $_params = array(
+ 'charset' => 'UTF-8',
'noprefetch' => false,
'return_document' => false,
'return_dom' => false,
public function postProcess($text)
{
try {
- $dom = new Horde_Domhtml($text, 'UTF-8');
+ $dom = new Horde_Domhtml($text, $this->_params['charset']);
} catch (Exception $e) {
return $text;
}
}
}
- return Horde_String::convertCharset($text, $dom->encoding, 'UTF-8');
+ return Horde_String::convertCharset($text, $dom->encoding, $this->_params['charset']);
}
/**