diff options
author | Andrew Dolgov <[email protected]> | 2013-04-19 13:17:28 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2013-04-19 13:17:28 +0400 |
commit | ebec81a6fb2dff0b2fe6b569b021e057995ee6c7 (patch) | |
tree | 9acdc3fd78b47d19f98827b76dcf096dec814429 /include/functions.php | |
parent | 1367bc3f5e0f99f5b900bcd3ea9e7512b7c84388 (diff) |
subscribe: verify XML before adding to the database; fetch: try to work around entity problems if initial parsing fails
Diffstat (limited to 'include/functions.php')
-rw-r--r-- | include/functions.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/functions.php b/include/functions.php index 4cc8f134d..8ac5753c9 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1558,6 +1558,7 @@ * Here you should call extractfeedurls in rpc-backend * to get all possible feeds. * 5 - Couldn't download the URL content. + * 6 - Content is an invalid XML. */ function subscribe_to_feed($url, $cat_id = 0, $auth_login = '', $auth_pass = '') { @@ -1588,6 +1589,18 @@ $url = key($feedUrls); } + libxml_use_internal_errors(true); + $doc = new DOMDocument(); + $doc->loadXML(html_entity_decode($contents)); + $error = libxml_get_last_error(); + libxml_clear_errors(); + + if ($error) { + $error_message = format_libxml_error($error); + + return array("code" => 6, "message" => $error_message); + } + if ($cat_id == "0" || !$cat_id) { $cat_qpart = "NULL"; } else { @@ -4203,4 +4216,10 @@ return LABEL_BASE_INDEX - 1 + abs($feed); } + function format_libxml_error($error) { + return T_sprintf("LibXML error %s at line %d (column %d): %s", + $error->code, $error->line, $error->column, + $error->message); + } + ?> |