prefs: implement batch subscribe to feeds
This commit is contained in:
parent
5081319e23
commit
33f0fdd0a2
4 changed files with 131 additions and 0 deletions
|
@ -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>";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1317,6 +1317,8 @@ class Pref_Feeds extends Protected_Handler {
|
||||||
dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
|
dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
|
||||||
print "<div onclick=\"resetFeedOrder()\"
|
print "<div onclick=\"resetFeedOrder()\"
|
||||||
dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
|
dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
|
||||||
|
print "<div onclick=\"batchSubscribe()\"
|
||||||
|
dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
|
||||||
print "</div></div>";
|
print "</div></div>";
|
||||||
|
|
||||||
if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
|
if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
|
||||||
|
|
|
@ -788,5 +788,54 @@ class RPC extends Protected_Handler {
|
||||||
|
|
||||||
print json_encode(array("hash" => $hash));
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
31
js/prefs.js
31
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue