]> git.wh0rd.org - tt-rss.git/commitdiff
prefs: implement batch subscribe to feeds
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 29 Jan 2012 13:51:00 +0000 (17:51 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 29 Jan 2012 13:51:00 +0000 (17:51 +0400)
classes/dlg.php
classes/pref_feeds.php
classes/rpc.php
js/prefs.js

index cd098d3968fa3d08f17a19f5a0cf738b57355b64..d39f691cb1d691a20f479d0714b4f7c05e0eafed 100644 (file)
@@ -978,5 +978,54 @@ class Dlg extends Protected_Handler {
 
        }
 
+       function batchSubscribe() {
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">";
+
+               print "<table width='100%'><tr><td>
+                       ".__("Add one valid RSS feed per line (no feed detection is done)")."
+               </td><td align='right'>";
+               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 "</td></tr><tr><td colspan='2'>";
+               print "<textarea
+                       style='font-size : 12px; width : 100%; height: 200px;'
+                       placeHolder=\"".__("Feeds to subscribe, One per line")."\"
+                       dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>";
+
+               print "</td></tr><tr><td colspan='2'>";
+
+               print "<div id='feedDlg_loginContainer' style='display : none'>
+                               " .
+                               " <input dojoType=\"dijit.form.TextBox\" name='login'\"
+                                       placeHolder=\"".__("Login")."\"
+                                       style=\"width : 10em;\"> ".
+                               " <input
+                                       placeHolder=\"".__("Password")."\"
+                                       dojoType=\"dijit.form.TextBox\" type='password'
+                                       style=\"width : 10em;\" name='pass'\">".
+                               " <p class='insensitive'>".__("OAuth will be used automatically for Twitter feeds.")."</p>
+                               </div>";
+
+               print "</td></tr><tr><td colspan='2'>";
+
+               print "<div style=\"clear : both\">
+                       <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
+                                       onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
+                               <label for=\"feedDlg_loginCheck\">".
+                               __('Feeds require authentication.')."</div>";
+
+               print "</form>";
+
+               print "</td></tr></table>";
+
+               print "<div class=\"dlgButtons\">
+                       <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button>
+                       <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button>
+                       </div>";
+       }
+
 }
 ?>
index 978a848e9804ca53fc7fa0911d3ce0731ff3ef8f..0e77b6e5f5f80983a2e6b81bef1d349db9690e3d 100644 (file)
@@ -1317,6 +1317,8 @@ class Pref_Feeds extends Protected_Handler {
                        dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
                print "<div onclick=\"resetFeedOrder()\"
                        dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
+               print "<div onclick=\"batchSubscribe()\"
+                       dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
                print "</div></div>";
 
                if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
index 58e25a4562abeac5f33ab42e537bf1736f6d0971..ef89a2141db726e8737def686067d42fa84f42ea 100644 (file)
@@ -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");
+                       }
+               }
+       }
+
 }
 ?>
index ce233b749d3fde300a827a9e30f1dbe2953879a1..a151cbedf0ef7e41bd6a1a3440d29df89e802893 100644 (file)
@@ -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);
+       }
+}