]> git.wh0rd.org - tt-rss.git/commitdiff
subscribe_to_feed: stop fetching URL multiple times while subscribing, various other...
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 23 Sep 2012 09:38:58 +0000 (13:38 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 23 Sep 2012 09:38:58 +0000 (13:38 +0400)
classes/handler/public.php
classes/rpc.php
include/functions.php
js/functions.js

index b9972df4fb7399427d6628ca5fd5171dda9822ed..7cb465594b4f2d343a07ae0cbd14720d31c2d4c3 100644 (file)
@@ -553,7 +553,7 @@ class Handler_Public extends Handler {
                                break;
                        case 4:
                                print_notice(__("Multiple feed URLs found."));
-                               $feed_urls = get_feeds_from_html($feed_url);
+                               $feed_urls = $rc["feeds"];
                                break;
                        case 5:
                                print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
index c4d0cd53c3f6561929cb4cc307a09a3a4878a3fb..f0d1d3d86795f27d0ee2304b2c84ea2113e7d7a6 100644 (file)
@@ -195,12 +195,6 @@ class RPC extends Handler_Protected {
                print json_encode(array("result" => $rc));
        }
 
-       function extractfeedurls() {
-               $urls = get_feeds_from_html($_REQUEST['url']);
-
-               print json_encode(array("urls" => $urls));
-       }
-
        function togglepref() {
                $key = db_escape_string($_REQUEST["key"]);
                set_pref($this->link, $key, !get_pref($this->link, $key));
index ba7cb75a8b14ef0009360a32f15843401dc99b83..cca02837eb2cf4b7a80c0c837725092c51357715 100644 (file)
 
                $update_method = 0;
 
-               if (!fetch_file_contents($url, false, $auth_login, $auth_pass))
+               $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
+
+               if (!$contents) {
                        return array("code" => 5, "message" => $fetch_last_error);
+               }
+
+               if (is_html($contents)) {
+                       $feedUrls = get_feeds_from_html($url, $contents);
 
-               if (url_is_html($url, $auth_login, $auth_pass)) {
-                       $feedUrls = get_feeds_from_html($url, $auth_login, $auth_pass);
                        if (count($feedUrls) == 0) {
                                return array("code" => 3);
                        } else if (count($feedUrls) > 1) {
-                               return array("code" => 4);
+                               return array("code" => 4, "feeds" => $feedUrls);
                        }
                        //use feed url as new URL
                        $url = key($feedUrls);
                return false;
        }
 
-       /**
-        * Extracts RSS/Atom feed URLs from the given HTML URL.
-        *
-        * @param string $url HTML page URL
-        *
-        * @return array Array of feeds. Key is the full URL, value the title
-        */
-       function get_feeds_from_html($url, $login = false, $pass = false)
+       function get_feeds_from_html($url, $content)
        {
                $url     = fix_url($url);
                $baseUrl = substr($url, 0, strrpos($url, '/') + 1);
 
                libxml_use_internal_errors(true);
 
-               $content = @fetch_file_contents($url, false, $login, $pass);
-
                $doc = new DOMDocument();
                $doc->loadHTML($content);
                $xpath = new DOMXPath($doc);
                return $feedUrls;
        }
 
-       /**
-        * Checks if the content behind the given URL is a HTML file
-        *
-        * @param string $url URL to check
-        *
-        * @return boolean True if the URL contains HTML content
-        */
-       function url_is_html($url, $login = false, $pass = false) {
-               $content = substr(fetch_file_contents($url, false, $login, $pass), 0, 1000);
-
-               if (stripos($content, '<html>') === false
-                       && stripos($content, '<html ') === false
-               ) {
-                       return false;
-               }
+       function is_html($content) {
+               return preg_match("/<html|DOCTYPE html/i", $content) !== 0;
+       }
 
-               return true;
+       function url_is_html($url, $login = false, $pass = false) {
+               return is_html(fetch_file_contents($url, false, $login, $pass));
        }
 
        function print_label_select($link, $name, $value, $attributes = "") {
index 97df318e530f8249305acfa06448585a4dbdfd8e..e9dcf3f3af1eb934f21861363ae9831d7ed6e423 100644 (file)
@@ -881,7 +881,7 @@ function quickAddFeed() {
                                                                        alert(__("Specified URL doesn't seem to contain any feeds."));
                                                                        break;
                                                                case 4:
-                                                                       notify_progress("Searching for feed urls...", true);
+                                                                       /* notify_progress("Searching for feed urls...", true);
 
                                                                        new Ajax.Request("backend.php", {
                                                                                parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
@@ -912,6 +912,23 @@ function quickAddFeed() {
                                                                                        Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
                                                                                }
                                                                        });
+                                                                       break; */
+
+                                                                       feeds = rc['feeds'];
+
+                                                                       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++;
+                                                                       }
+
+                                                                       Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
+
                                                                        break;
                                                                case 5:
                                                                        alert(__("Couldn't download the specified URL: %s").