From d1f3fa9791a48de4991e8eae9e9939afd0316be3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 17 May 2013 20:09:43 +0400 Subject: [PATCH] try to force-convert feed data to utf8 --- classes/feedparser.php | 17 ++++++++++++++++- include/rssfuncs.php | 8 ++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/classes/feedparser.php b/classes/feedparser.php index bd67ca39d..6b84e59c7 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -17,7 +17,22 @@ class FeedParser { libxml_clear_errors(); $this->doc = new DOMDocument(); $this->doc->loadXML($data); - $this->error = $this->format_error(libxml_get_last_error()); + + $error = libxml_get_last_error(); + + if ($error && $error->code == 9) { + libxml_clear_errors(); + + // we might want to try guessing input encoding here too + $data = iconv("UTF-8", "UTF-8//IGNORE", $data); + + $this->doc = new DOMDocument(); + $this->doc->loadXML($data); + + $error = libxml_get_last_error(); + } + + $this->error = $this->format_error($error); libxml_clear_errors(); $this->items = array(); diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 612c914c0..e7c9f57dd 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -291,7 +291,7 @@ _debug("fetch done.", $debug_enabled); - if ($feed_data) { + /* if ($feed_data) { $error = verify_feed_xml($feed_data); if ($error) { @@ -307,7 +307,7 @@ if ($error) $feed_data = ''; } } - } + } */ } if (!$feed_data) { @@ -1349,14 +1349,14 @@ mb_strtolower(strip_tags($title), 'utf-8')); } - function verify_feed_xml($feed_data) { + /* function verify_feed_xml($feed_data) { libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc->loadXML($feed_data); $error = libxml_get_last_error(); libxml_clear_errors(); return $error; - } + } */ function housekeeping_common($debug) { expire_cached_files($debug);