]> git.wh0rd.org Git - tt-rss.git/commitdiff
feed browser: allow subscribing by url for linked feeds
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 20 Apr 2011 14:39:30 +0000 (18:39 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 20 Apr 2011 14:39:30 +0000 (18:39 +0400)
functions.js
modules/backend-rpc.php
modules/pref-feeds.php

index 2a4268e8cbb934329d544556108a3bde0ae82ba7..278f32545fe51ea657050a0f8e47e1c541e21cf9 100644 (file)
@@ -1430,7 +1430,7 @@ function feedBrowser() {
                        id: "feedBrowserDlg",
                        title: __("More Feeds"),
                        style: "width: 600px",
-                       getSelectedFeeds: function() {
+                       getSelectedFeedIds: function() {
                                var list = $$("#browseFeedList li[id*=FBROW]");
                                var selected = new Array();
 
@@ -1444,26 +1444,48 @@ function feedBrowser() {
 
                                return selected;
                        },
+                       getSelectedFeeds: function() {
+                               var list = $$("#browseFeedList li.Selected");
+                               var selected = new Array();
+
+                               list.each(function(child) {
+                                       var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
+                                       var url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
+
+                                       selected.push([title,url]);
+
+                               });
+
+                               return selected;
+                       },
+
                        subscribe: function() {
-                               var selected = this.getSelectedFeeds();
                                var mode = this.attr('value').mode;
+                               var selected = [];
+
+                               if (mode == "1")
+                                       selected = this.getSelectedFeeds();
+                               else
+                                       selected = this.getSelectedFeedIds();
 
                                if (selected.length > 0) {
                                        dijit.byId("feedBrowserDlg").hide();
 
                                        notify_progress("Loading, please wait...", true);
 
-                                       var query = "?op=rpc&subop=massSubscribe&ids="+
-                                               param_escape(selected.toString()) + "&mode=" + param_escape(mode);
+                                       // we use dojo.toJson instead of JSON.stringify because
+                                       // it somehow escapes everything TWICE, at least in Chrome 9
+
+                                       var query = "?op=rpc&subop=massSubscribe&payload="+
+                                               param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
 
                                        console.log(query);
 
                                        new Ajax.Request("backend.php", {
                                                parameters: query,
                                                onComplete: function(transport) {
-                                                       if (inPreferences()) {
-                                                               updateFeedList();
-                                                       }
+                                                       notify('');
+                                                       updateFeedList();
                                                } });
 
                                } else {
index 75ce6886a0952c6058db837d28df0a3bf94f4040..4f2465e730755519cb66428eedc671f54c467287 100644 (file)
                // Silent
                if ($subop == "massSubscribe") {
 
-                       $ids = split(",", db_escape_string($_REQUEST["ids"]));
+                       $payload = json_decode($_REQUEST["payload"], false);
                        $mode = $_REQUEST["mode"];
 
+                       if (!$payload || !is_array($payload)) return;
+
+                       if ($mode == 1) {
+                               foreach ($payload as $feed) {
+
+                                       $title = db_escape_string($feed[0]);
+                                       $feed_url = db_escape_string($feed[1]);
+
+                                       $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+                                               feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
+
+                                       if (db_num_rows($result) == 0) {
+                                               $result = db_query($link, "INSERT INTO ttrss_feeds
+                                                               (owner_uid,feed_url,title,cat_id,site_url)
+                                                       VALUES ('".$_SESSION["uid"]."',
+                                                               '$feed_url', '$title', NULL, '')");
+                                       }
+                               }
+                       } else if ($mode == 2) {
+                               // feed archive
+                               foreach ($payload as $id) {
+                                       $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
+                                               WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+
+                                       if (db_num_rows($result) != 0) {
+                                               $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
+                                               $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
+                                               $title = db_escape_string(db_fetch_result($result, 0, "title"));
+
+                                               $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+                                                       feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
+
+                                               if (db_num_rows($result) == 0) {
+                                                       $result = db_query($link, "INSERT INTO ttrss_feeds
+                                                                       (owner_uid,feed_url,title,cat_id,site_url)
+                                                               VALUES ('$id','".$_SESSION["uid"]."',
+                                                                       '$feed_url', '$title', NULL, '$site_url')");
+                                               }
+                                       }
+                               }
+                       }
+
+/*                     $ids = split(",", db_escape_string($_REQUEST["ids"]));
+
                        $subscribed = array();
 
                        foreach ($ids as $id) {
                                        }
                                        array_push($subscribed, $title_orig);
                                }
-                       }
+                       } */
 
                        return;
                }
index 4baba572a77e546741196ec81e9d2d3bde6d5718..3211987ce7cecb0cf3c0f8460ba76b0822802fda 100644 (file)
                                                $site_url = "";
                                        }
 
-                                       $feed_url = "<a target=\"_blank\" href=\"$feed_url\"><img
+                                       $feed_url = "<a class=\"fb_feedUrl\" target=\"_blank\"
+                                               href=\"$feed_url\"><img
                                                style='border-width : 0px; vertical-align : middle'
                                                src='images/feed-icon-12x12.png'></a>";
 
-                                       $rv .= "<li title=\"".htmlspecialchars($details["site_url"])."\"
-                                               id=\"FBROW-".$details["id"]."\">$check_box".
-                                               "$feed_icon $feed_url " . htmlspecialchars($line["title"]) .
+                                       $rv .= "<li title=\"".htmlspecialchars($details["site_url"])."\">
+                                               $check_box".
+                                               "$feed_icon $feed_url " .
+                                               "<span class=\"fb_feedTitle\">".htmlspecialchars($line["title"]).
+                                               "</span>".
                                                "&nbsp;<span class='subscribers'>($subscribers)</span>
                                                $site_url</li>";