From: Andrew Dolgov Date: Sun, 29 Jan 2012 13:51:00 +0000 (+0400) Subject: prefs: implement batch subscribe to feeds X-Git-Tag: 1.5.10~25 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=33f0fdd0a21ca7999e2d9d1a8db438711e518587;p=tt-rss.git prefs: implement batch subscribe to feeds --- diff --git a/classes/dlg.php b/classes/dlg.php index cd098d39..d39f691c 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -978,5 +978,54 @@ class Dlg extends Protected_Handler { } + function batchSubscribe() { + print ""; + print ""; + + print "
+ ".__("Add one valid RSS feed per line (no feed detection is done)")." + "; + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + print __('Place in category:') . " "; + print_feed_cat_select($this->link, "cat", false, 'dojoType="dijit.form.Select"'); + } + print "
"; + print ""; + + print "
"; + + print ""; + + print "
"; + + print "
+ +
"; + + print ""; + + print "
"; + + print "
+ + +
"; + } + } ?> diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php index 978a848e..0e77b6e5 100644 --- a/classes/pref_feeds.php +++ b/classes/pref_feeds.php @@ -1317,6 +1317,8 @@ class Pref_Feeds extends Protected_Handler { dojoType=\"dijit.MenuItem\">".__('Edit selected feeds').""; print "
".__('Reset sort order')."
"; + print "
".__('Batch subscribe')."
"; print ""; if (get_pref($this->link, 'ENABLE_FEED_CATS')) { diff --git a/classes/rpc.php b/classes/rpc.php index 58e25a45..ef89a214 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -788,5 +788,54 @@ class RPC extends Protected_Handler { print json_encode(array("hash" => $hash)); } + + function batchAddFeeds() { + $cat_id = db_escape_string($_REQUEST['cat']); + $feeds = explode("\n", db_escape_string($_REQUEST['feeds'])); + $login = db_escape_string($_REQUEST['login']); + $pass = db_escape_string($_REQUEST['pass']); + $need_auth = db_escape_string($_REQUEST['need_auth']) != ""; + + $result = db_query($this->link, "SELECT twitter_oauth FROM ttrss_users +WHERE id = ".$_SESSION['uid']); + $has_oauth = db_fetch_result($result, 0, 'twitter_oauth') != ""; + + foreach ($feeds as $feed) { + $feed = trim($feed); + + if (validate_feed_url($feed)) { + + db_query($this->link, "BEGIN"); + + if (!$need_auth || !$has_oauth || strpos($url, '://api.twitter.com') + === false) { + $update_method = 0; + } else { + $update_method = 3; + } + + if ($cat_id == "0" || !$cat_id) { + $cat_qpart = "NULL"; + } else { + $cat_qpart = "'$cat_id'"; + } + + $result = db_query($this->link, + "SELECT id FROM ttrss_feeds + WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + $result = db_query($this->link, + "INSERT INTO ttrss_feeds + (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method) + VALUES ('".$_SESSION["uid"]."', '$feed', + '[Unknown]', $cat_qpart, '$login', '$pass', '$update_method')"); + } + + db_query($this->link, "COMMIT"); + } + } + } + } ?> diff --git a/js/prefs.js b/js/prefs.js index ce233b74..a151cbed 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -2073,4 +2073,35 @@ function gotoExportOpml(filename, settings) { } +function batchSubscribe() { + try { + var query = "backend.php?op=dlg&method=batchSubscribe"; + + if (dijit.byId("batchSubDlg")) + dijit.byId("batchSubDlg").destroyRecursive(); + + var dialog = new dijit.Dialog({ + id: "batchSubDlg", + title: __("Batch subscribe"), + style: "width: 600px", + execute: function() { + if (this.validate()) { + console.log(dojo.objectToQuery(this.attr('value'))); + + notify_progress(__("Subscribing to feeds..."), true); + + new Ajax.Request("backend.php", { + parameters: dojo.objectToQuery(this.attr('value')), + onComplete: function(transport) { + this.hide(); + } }); + } + }, + href: query}); + + dialog.show(); + } catch (e) { + exception_error("batchSubscribe", e); + } +}