summaryrefslogtreecommitdiff
path: root/classes/feedparser.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-04-01 09:02:05 +0300
committerAndrew Dolgov <[email protected]>2019-04-01 09:02:05 +0300
commit1a484ec3f58ff5e7a5745f231b68cb64ba65929d (patch)
tree9b1f44f77a09cd11373f9679f26ef38791dd6b8a /classes/feedparser.php
parentcb0c81729d30daae48f15c4d9dbc026aea506710 (diff)
feedparser: remove horrible hacks for feeds with broken encoding
Diffstat (limited to 'classes/feedparser.php')
-rw-r--r--classes/feedparser.php54
1 files changed, 0 insertions, 54 deletions
diff --git a/classes/feedparser.php b/classes/feedparser.php
index dc67e204e..400cc7095 100644
--- a/classes/feedparser.php
+++ b/classes/feedparser.php
@@ -13,20 +13,6 @@ class FeedParser {
const FEED_RSS = 1;
const FEED_ATOM = 2;
- function normalize_encoding($data) {
- if (preg_match('/^(<\?xml[\t\n\r ].*?encoding[\t\n\r ]*=[\t\n\r ]*["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) {
-
- $encoding = strtolower($matches[2]);
-
- if (in_array($encoding, array_map('strtolower', mb_list_encodings())))
- $data = mb_convert_encoding($data, 'UTF-8', $encoding);
-
- $data = preg_replace('/^<\?xml[\t\n\r ].*?\?>/s', $matches[1] . "UTF-8" . $matches[3] , $data);
- }
-
- return $data;
- }
-
function __construct($data) {
libxml_use_internal_errors(true);
libxml_clear_errors();
@@ -37,46 +23,6 @@ class FeedParser {
$error = libxml_get_last_error();
- // libxml compiled without iconv?
- if ($error && $error->code == 32) {
- $data = $this->normalize_encoding($data);
-
- if ($data) {
- libxml_clear_errors();
-
- $this->doc = new DOMDocument();
- $this->doc->loadXML($data);
-
- $error = libxml_get_last_error();
- }
- }
-
- // some terrible invalid unicode entity?
- if ($error) {
- foreach (libxml_get_errors() as $err) {
- if ($err->code == 9) {
- // if the source feed is not in utf8, next conversion will fail
- $data = $this->normalize_encoding($data);
-
- // remove dangling bytes
- $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
-
- // apparently not all UTF-8 characters are valid for XML
- $data = preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $data);
-
- if ($data) {
- libxml_clear_errors();
-
- $this->doc = new DOMDocument();
- $this->doc->loadXML($data);
-
- $error = libxml_get_last_error();
- }
- break;
- }
- }
- }
-
if ($error) {
foreach (libxml_get_errors() as $error) {
if ($error->level == LIBXML_ERR_FATAL) {