remove unneeded xml from several more rpc methods

This commit is contained in:
Andrew Dolgov 2010-11-25 13:39:37 +03:00
parent 563b9c782d
commit 74d12bab83
3 changed files with 56 additions and 86 deletions

View File

@ -135,18 +135,13 @@
} }
if ($subop == "togglepref") { if ($subop == "togglepref") {
print "<rpc-reply>"; header("Content-Type: text/plain");
$key = db_escape_string($_REQUEST["key"]); $key = db_escape_string($_REQUEST["key"]);
set_pref($link, $key, !get_pref($link, $key)); set_pref($link, $key, !get_pref($link, $key));
$value = get_pref($link, $key); $value = get_pref($link, $key);
print "<param-set key=\"$key\" value=\"$value\"/>"; print json_encode(array("param" =>$key, "value" => $value));
print "</rpc-reply>";
return; return;
} }
@ -166,6 +161,8 @@
} }
if ($subop == "mark") { if ($subop == "mark") {
header("Content-Type: text/plain");
$mark = $_REQUEST["mark"]; $mark = $_REQUEST["mark"];
$id = db_escape_string($_REQUEST["id"]); $id = db_escape_string($_REQUEST["id"]);
@ -180,51 +177,45 @@
$result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
print "<rpc-reply>"; print json_encode(array("message" => "UPDATE_COUNTERS"));
print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return; return;
} }
if ($subop == "delete") { if ($subop == "delete") {
header("Content-Type: text/plain");
$ids = db_escape_string($_REQUEST["ids"]); $ids = db_escape_string($_REQUEST["ids"]);
$result = db_query($link, "DELETE FROM ttrss_user_entries $result = db_query($link, "DELETE FROM ttrss_user_entries
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
print "<rpc-reply>"; print json_encode(array("message" => "UPDATE_COUNTERS"));
print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return; return;
} }
if ($subop == "unarchive") { if ($subop == "unarchive") {
header("Content-Type: text/plain");
$ids = db_escape_string($_REQUEST["ids"]); $ids = db_escape_string($_REQUEST["ids"]);
$result = db_query($link, "UPDATE ttrss_user_entries $result = db_query($link, "UPDATE ttrss_user_entries
SET feed_id = orig_feed_id, orig_feed_id = NULL SET feed_id = orig_feed_id, orig_feed_id = NULL
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
print "<rpc-reply>"; print json_encode(array("message" => "UPDATE_COUNTERS"));
print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return; return;
} }
if ($subop == "archive") { if ($subop == "archive") {
header("Content-Type: text/plain");
$ids = split(",", db_escape_string($_REQUEST["ids"])); $ids = split(",", db_escape_string($_REQUEST["ids"]));
foreach ($ids as $id) { foreach ($ids as $id) {
archive_article($link, $id, $_SESSION["uid"]); archive_article($link, $id, $_SESSION["uid"]);
} }
print "<rpc-reply>"; print json_encode(array("message" => "UPDATE_COUNTERS"));
print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return; return;
} }
@ -268,7 +259,7 @@
return; return;
} }
if ($subop == "updateFeed") { /* if ($subop == "updateFeed") {
$feed_id = db_escape_string($_REQUEST["feed"]); $feed_id = db_escape_string($_REQUEST["feed"]);
update_rss_feed($link, $feed_id); update_rss_feed($link, $feed_id);
@ -278,7 +269,7 @@
print "</rpc-reply>"; print "</rpc-reply>";
return; return;
} } */
if ($subop == "updateAllFeeds" || $subop == "getAllCounters") { if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
@ -308,44 +299,38 @@
/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
if ($subop == "catchupSelected") { if ($subop == "catchupSelected") {
header("Content-Type: text/plain");
$ids = split(",", db_escape_string($_REQUEST["ids"])); $ids = split(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]); $cmode = sprintf("%d", $_REQUEST["cmode"]);
catchupArticlesById($link, $ids, $cmode); catchupArticlesById($link, $ids, $cmode);
print "<rpc-reply>"; print json_encode(array("message" => "UPDATE_COUNTERS"));
print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return; return;
} }
if ($subop == "markSelected") { if ($subop == "markSelected") {
header("Content-Type: text/plain");
$ids = split(",", db_escape_string($_REQUEST["ids"])); $ids = split(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]); $cmode = sprintf("%d", $_REQUEST["cmode"]);
markArticlesById($link, $ids, $cmode); markArticlesById($link, $ids, $cmode);
print "<rpc-reply>"; print json_encode(array("message" => "UPDATE_COUNTERS"));
print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return; return;
} }
if ($subop == "publishSelected") { if ($subop == "publishSelected") {
header("Content-Type: text/plain");
$ids = split(",", db_escape_string($_REQUEST["ids"])); $ids = split(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]); $cmode = sprintf("%d", $_REQUEST["cmode"]);
publishArticlesById($link, $ids, $cmode); publishArticlesById($link, $ids, $cmode);
print "<rpc-reply>"; print json_encode(array("message" => "UPDATE_COUNTERS"));
print "<message>UPDATE_COUNTERS</message>";
print "</rpc-reply>";
return; return;
} }
@ -467,6 +452,7 @@
} }
if ($subop == "completeTags") { if ($subop == "completeTags") {
header("Content-Type: text/plain");
$search = db_escape_string($_REQUEST["search"]); $search = db_escape_string($_REQUEST["search"]);
@ -488,24 +474,16 @@
$ids = split(",", db_escape_string($_REQUEST["ids"])); $ids = split(",", db_escape_string($_REQUEST["ids"]));
$days = sprintf("%d", $_REQUEST["days"]); $days = sprintf("%d", $_REQUEST["days"]);
print "<rpc-reply>";
print "<message><![CDATA[";
foreach ($ids as $id) { foreach ($ids as $id) {
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
id = '$id' AND owner_uid = ".$_SESSION["uid"]); id = '$id' AND owner_uid = ".$_SESSION["uid"]);
if (db_num_rows($result) == 1) { if (db_num_rows($result) == 1) {
purge_feed($link, $id, $days, true); purge_feed($link, $id, $days);
} }
} }
print "]]></message>";
print "</rpc-reply>";
return; return;
} }
@ -915,6 +893,8 @@
} }
if ($subop == "cdmGetArticle") { if ($subop == "cdmGetArticle") {
header("Content-Type: text/plain");
$id = db_escape_string($_REQUEST["id"]); $id = db_escape_string($_REQUEST["id"]);
$result = db_query($link, "SELECT content, $result = db_query($link, "SELECT content,
@ -934,14 +914,15 @@
$article_content = ''; $article_content = '';
} }
print "<rpc-reply><article id=\"$id\"><![CDATA["; print json_encode(array("article" =>
print "$article_content"; array("id" => $id, "content" => $article_content)));
print "]]></article></rpc-reply>";
return; return;
} }
if ($subop == "scheduleFeedUpdate") { if ($subop == "scheduleFeedUpdate") {
header("Content-Type: text/plain");
$feed_id = db_escape_string($_REQUEST["id"]); $feed_id = db_escape_string($_REQUEST["id"]);
$is_cat = db_escape_string($_REQUEST['is_cat']) == 'true'; $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true';
@ -973,10 +954,7 @@
$message = __("Can't update this kind of feed."); $message = __("Can't update this kind of feed.");
} }
print "<rpc-reply>"; print json_encode(array("message" => $message));
print "<message>$message</message>";
print "</rpc-reply>";
return; return;
} }

View File

@ -1078,18 +1078,16 @@ function scheduleFeedUpdate(id, is_cat) {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_json(transport);
if (transport.responseXML) { var reply = JSON.parse(transport.responseText);
var message = transport.responseXML.getElementsByTagName("message")[0]; var message = reply['message'];
if (message) { if (message) {
notify_info(message.firstChild.nodeValue); notify_info(message);
return; return;
}
} }
notify_error("Error communicating with server.");
} }); } });

View File

@ -17,19 +17,6 @@ var preload_timeout_id = false;
var cache_added = []; var cache_added = [];
function catchup_callback2(transport, callback) {
try {
console.log("catchup_callback2 " + transport + ", " + callback);
notify("");
handle_rpc_reply(transport);
if (callback) {
setTimeout(callback, 10);
}
} catch (e) {
exception_error("catchup_callback2", e, transport);
}
}
function headlines_callback2(transport, feed_cur_page) { function headlines_callback2(transport, feed_cur_page) {
try { try {
@ -454,7 +441,7 @@ function toggleMark(id, client_only) {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_reply(transport); handle_rpc_json(transport);
} }); } });
} }
@ -654,7 +641,7 @@ function toggleUnread(id, cmode, effect) {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_reply(transport); handle_rpc_json(transport);
} }); } });
} }
@ -740,7 +727,7 @@ function selectionAssignLabel(id, ids) {
} }
} }
function selectionToggleUnread(set_state, callback_func, no_error) { function selectionToggleUnread(set_state, callback, no_error) {
try { try {
var rows = getSelectedArticleIds2(); var rows = getSelectedArticleIds2();
@ -790,7 +777,8 @@ function selectionToggleUnread(set_state, callback_func, no_error) {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
catchup_callback2(transport, callback_func); handle_rpc_json(transport);
if (callback) callback(transport);
} }); } });
} }
@ -822,7 +810,7 @@ function selectionToggleMarked() {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_reply(transport); handle_rpc_json(transport);
} }); } });
} }
@ -854,7 +842,7 @@ function selectionTogglePublished() {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_reply(transport); handle_rpc_json(transport);
} }); } });
} }
@ -982,6 +970,7 @@ function deleteSelection() {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_json(transport);
viewCurrentFeed(); viewCurrentFeed();
} }); } });
@ -1031,6 +1020,7 @@ function archiveSelection() {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_json(transport);
viewCurrentFeed(); viewCurrentFeed();
} }); } });
@ -1215,7 +1205,7 @@ function cdmWatchdog() {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
handle_rpc_reply(transport); handle_rpc_json(transport);
} }); } });
} }
@ -1571,7 +1561,7 @@ function catchupRelativeToArticle(below) {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
catchup_callback2(transport); handle_rpc_json(transport);
} }); } });
} }
@ -1633,12 +1623,16 @@ function cdmExpandArticle(id) {
onComplete: function(transport) { onComplete: function(transport) {
$("FUPDPIC-" + id).src = 'images/blank_icon.gif'; $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
if (transport.responseXML) { handle_rpc_json(transport);
var article = transport.responseXML.getElementsByTagName("article")[0];
var recv_id = article.getAttribute("id"); var reply = JSON.parse(transport.responseText);
if (reply) {
var article = reply['article']['content'];
var recv_id = reply['article']['id'];
if (recv_id == id) if (recv_id == id)
$("CWRAP-" + id).innerHTML = article.firstChild.nodeValue; $("CWRAP-" + id).innerHTML = article;
} else { } else {
$("CWRAP-" + id).innerHTML = __("Unable to load article."); $("CWRAP-" + id).innerHTML = __("Unable to load article.");