More Html2text fixes
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 19 Aug 2010 17:59:33 +0000 (11:59 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 19 Aug 2010 18:53:32 +0000 (12:53 -0600)
Use proper charset for html_entity_encode() and charset conversion.
Fallback to strip_tags() if DOM extension is not available.

framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php

index 9212d96..1689d70 100644 (file)
@@ -114,7 +114,9 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base
                 libxml_use_internal_errors(false);
             }
 
-            $text = Horde_String::convertCharset($this->_node($doc, $doc), 'UTF-8', $this->_params['charset']);
+            $text = Horde_String::convertCharset($this->_node($doc, $doc), $doc->encoding, $this->_params['charset']);
+        } else {
+            $text = strip_tags(preg_replace("/\<br\s*\/?\>/i", "\n", $text));
         }
 
         /* Bring down number of empty lines to 2 max, and remove trailing
@@ -306,7 +308,7 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base
                     if (!$child->nextSibling) {
                         $tmp = rtrim($tmp);
                     }
-                    $out .= html_entity_decode($tmp, ENT_QUOTES, 'UTF-8');
+                    $out .= html_entity_decode($tmp, ENT_QUOTES, $this->_params['charset']);
                 }
             }
         }