From e9175d13d76e8852b4df6beba29ab65c164feabd Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 29 Nov 2010 16:02:16 +0300 Subject: [PATCH] rpc/addfeed: use JSON --- functions.js | 22 ++++++---------------- modules/backend-rpc.php | 17 ++++------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/functions.js b/functions.js index ed4f4712..f0364deb 100644 --- a/functions.js +++ b/functions.js @@ -865,15 +865,10 @@ function quickAddFeed() { parameters: dojo.objectToQuery(this.attr('value')), onComplete: function(transport) { try { + + var reply = JSON.parse(transport.responseText); - if (!transport.responseXML) { - console.log(transport.responseText); - alert(__("Server error while trying to subscribe to specified feed.")); - return; - } - - var result = transport.responseXML.getElementsByTagName('result')[0]; - var rc = parseInt(result.getAttribute('code')); + var rc = parseInt(reply['result']); notify(''); @@ -899,16 +894,11 @@ function quickAddFeed() { parameters: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url), onComplete: function(transport, dialog, feed_url) { - if (!transport.responseXML) { - console.log(transport.responseText); - alert(__("Server error while trying to query feed URLs.")); - return; - } - notify(''); - var result = transport.responseXML.getElementsByTagName('urls')[0]; - var feeds = JSON.parse(result.firstChild.nodeValue); + var reply = JSON.parse(transport.responseText); + + var feeds = reply['urls']; console.log(transport.responseText); diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index bf475e63..54c66df3 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -88,8 +88,6 @@ if ($subop == "remarchive") { $ids = split(",", db_escape_string($_REQUEST["ids"])); - print ""; - foreach ($ids as $id) { $result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE (SELECT COUNT(*) FROM ttrss_user_entries @@ -97,17 +95,13 @@ id = '$id' AND owner_uid = ".$_SESSION["uid"]); $rc = db_affected_rows($link, $result); - - print ""; - } - print ""; - return; } if ($subop == "addfeed") { + header("Content-Type: text/plain"); $feed = db_escape_string($_REQUEST['feed']); $cat = db_escape_string($_REQUEST['cat']); @@ -116,21 +110,18 @@ $rc = subscribe_to_feed($link, $feed, $cat, $login, $pass); - print ""; - print ""; - print ""; + print json_encode(array("result" => $rc)); return; } if ($subop == "extractfeedurls") { - print ""; + header("Content-Type: text/plain"); $urls = get_feeds_from_html($_REQUEST['url']); - print ""; - print ""; + print json_encode(array("urls" => $urls)); return; } -- 2.39.5