]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
subscribe: verify XML before adding to the database; fetch: try to work around entity...
[tt-rss.git] / include / functions.php
index 4cc8f134da6962b90557ba9507cad915d6701ca5..8ac5753c9b5e7618e46e3e997daa5e54bb7bbc27 100644 (file)
         *                     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 = '') {
                        $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 {
                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);
+       }
+
 ?>