summaryrefslogtreecommitdiff
path: root/magpierss
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2007-08-13 04:31:57 +0100
committerAndrew Dolgov <[email protected]>2007-08-13 04:31:57 +0100
commitfeb3185124bd5f1257c6bdfaeb2300845c923ff5 (patch)
tree807d41110225fd53218f138fee3c9e53bf7fffc1 /magpierss
parent3a486dec89f5270812f1e699bb8844b359de53d7 (diff)
magpie: only force convert encoding if initial parsing failed
Diffstat (limited to 'magpierss')
-rw-r--r--magpierss/rss_fetch.inc2
-rw-r--r--magpierss/rss_parse.inc26
2 files changed, 27 insertions, 1 deletions
diff --git a/magpierss/rss_fetch.inc b/magpierss/rss_fetch.inc
index dd475e31d..77a1a704f 100644
--- a/magpierss/rss_fetch.inc
+++ b/magpierss/rss_fetch.inc
@@ -313,7 +313,7 @@ function _convert_entities ($string) {
Output: parsed RSS object (see rss_parse)
\*=======================================================================*/
function _response_to_rss ($resp) {
- $converted_source = _convert_entities(mb_convert_encoding($resp->results, "UTF-8", mb_detect_encoding($resp->results)));
+ $converted_source = _convert_entities($resp->results);
$rss = new MagpieRSS( $converted_source, MAGPIE_OUTPUT_ENCODING, "UTF-8", false);
// if RSS parsed successfully
diff --git a/magpierss/rss_parse.inc b/magpierss/rss_parse.inc
index 0b2ddc83a..8a67523b5 100644
--- a/magpierss/rss_parse.inc
+++ b/magpierss/rss_parse.inc
@@ -132,7 +132,33 @@ class MagpieRSS {
xml_set_character_data_handler( $this->parser, 'feed_cdata' );
$status = xml_parse( $this->parser, $source );
+
+ # try to force convert everything to UTF-8 and parse again
+ # to salvage at least some data from the feed
+ if (! $status) {
+ $errorcode = xml_get_error_code( $this->parser );
+ if ( $errorcode != XML_ERROR_NONE ) {
+
+ xml_parser_free( $this->parser );
+
+ list($parser, $source) = $this->create_parser($source,
+ $output_encoding, $input_encoding, $detect_encoding);
+
+ $source = mb_convert_encoding($source, "UTF-8",
+ mb_detect_encoding($source));
+
+ $this->parser = $parser;
+ xml_set_object( $this->parser, $this );
+ xml_set_element_handler($this->parser,
+ 'feed_start_element', 'feed_end_element' );
+
+ xml_set_character_data_handler( $this->parser, 'feed_cdata' );
+
+ $status = xml_parse( $this->parser, $source);
+ }
+ }
+
if (! $status ) {
$errorcode = xml_get_error_code( $this->parser );
if ( $errorcode != XML_ERROR_NONE ) {