]> git.wh0rd.org Git - tt-rss.git/commitdiff
subscribe: verify XML before adding to the database; fetch: try to work around entity...
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 19 Apr 2013 09:17:28 +0000 (13:17 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 19 Apr 2013 09:17:28 +0000 (13:17 +0400)
include/functions.php
include/rssfuncs.php
js/functions.js

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);
+       }
+
 ?>
index 31d35bf8eeaf116b89e3f99c8b2bba41e45b3c11..47d6221698213d24fd85486b84cdcc231dd103f7 100644 (file)
                                        _debug("update_rss_feed: fetch done.");
                                }
 
+                               $error = verify_feed_xml($feed_data);
+
+                               if ($error) {
+                                       if ($debug_enabled) {
+                                               _debug("update_rss_feed: error verifying XML, code: " . $error->code);
+                                       }
+
+                                       if ($error->code == 26) {
+                                               if ($debug_enabled) {
+                                                       _debug("update_rss_feed: got error 26, trying to decode entities...");
+                                               }
+
+                                               $feed_data = html_entity_decode($feed_data, ENT_COMPAT, 'UTF-8');
+
+                                               $error = verify_feed_xml($feed_data);
+
+                                               if ($error) $feed_data = '';
+                                       }
+                               }
                        }
 
                        if (!$feed_data) {
                                        _debug("update_rss_feed: date $entry_timestamp [$entry_timestamp_fmt]");
                                }
 
-                               $entry_title = html_entity_decode($item->get_title());
+                               $entry_title = html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8');
 
                                $entry_link = rewrite_relative_url($site_url, $item->get_link());
 
                        mb_strtolower(strip_tags($title), 'utf-8'));
        }
 
+       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;
+       }
 
 ?>
index e0276750461959d357eb733f421386ab21c40589..04be58bf77a2961b7dd2ef3afe29f013fad080eb 100644 (file)
@@ -816,39 +816,6 @@ function quickAddFeed() {
                                                                        alert(__("Specified URL doesn't seem to contain any feeds."));
                                                                        break;
                                                                case 4:
-                                                                       /* notify_progress("Searching for feed urls...", true);
-
-                                                                       new Ajax.Request("backend.php", {
-                                                                               parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
-                                                                               onComplete: function(transport, dialog, feed_url) {
-
-                                                                                       notify('');
-
-                                                                                       var reply = JSON.parse(transport.responseText);
-
-                                                                                       var feeds = reply['urls'];
-
-                                                                                       console.log(transport.responseText);
-
-                                                                                       var select = dijit.byId("feedDlg_feedContainerSelect");
-
-                                                                                       while (select.getOptions().length > 0)
-                                                                                               select.removeOption(0);
-
-                                                                                       var count = 0;
-                                                                                       for (var feedUrl in feeds) {
-                                                                                               select.addOption({value: feedUrl, label: feeds[feedUrl]});
-                                                                                               count++;
-                                                                                       }
-
-//                                                                                     if (count > 5) count = 5;
-//                                                                                     select.size = count;
-
-                                                                                       Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
-                                                                               }
-                                                                       });
-                                                                       break; */
-
                                                                        feeds = rc['feeds'];
 
                                                                        var select = dijit.byId("feedDlg_feedContainerSelect");
@@ -871,6 +838,11 @@ function quickAddFeed() {
                                                                        alert(__("Couldn't download the specified URL: %s").
                                                                                        replace("%s", rc['message']));
                                                                        break;
+                                                               case 6:
+                                                                       alert(__("XML validation failed: %s").
+                                                                                       replace("%s", rc['message']));
+                                                                       break;
+                                                                       break;
                                                                case 0:
                                                                        alert(__("You are already subscribed to this feed."));
                                                                        break;