From 74d12bab83ba5d806d130371fe8d9b76cc6e8c43 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 25 Nov 2010 13:39:37 +0300 Subject: [PATCH] remove unneeded xml from several more rpc methods --- modules/backend-rpc.php | 84 +++++++++++++++-------------------------- tt-rss.js | 14 +++---- viewfeed.js | 44 ++++++++++----------- 3 files changed, 56 insertions(+), 86 deletions(-) diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 93d8f074..510a9fd3 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -135,18 +135,13 @@ } if ($subop == "togglepref") { - print ""; + header("Content-Type: text/plain"); $key = db_escape_string($_REQUEST["key"]); - set_pref($link, $key, !get_pref($link, $key)); - $value = get_pref($link, $key); - print ""; - - print ""; - + print json_encode(array("param" =>$key, "value" => $value)); return; } @@ -166,6 +161,8 @@ } if ($subop == "mark") { + header("Content-Type: text/plain"); + $mark = $_REQUEST["mark"]; $id = db_escape_string($_REQUEST["id"]); @@ -180,51 +177,45 @@ $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); - print ""; - print "UPDATE_COUNTERS"; - print ""; - + print json_encode(array("message" => "UPDATE_COUNTERS")); return; } if ($subop == "delete") { + header("Content-Type: text/plain"); + $ids = db_escape_string($_REQUEST["ids"]); $result = db_query($link, "DELETE FROM ttrss_user_entries WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); - print ""; - print "UPDATE_COUNTERS"; - print ""; - + print json_encode(array("message" => "UPDATE_COUNTERS")); return; } if ($subop == "unarchive") { + header("Content-Type: text/plain"); + $ids = db_escape_string($_REQUEST["ids"]); $result = db_query($link, "UPDATE ttrss_user_entries SET feed_id = orig_feed_id, orig_feed_id = NULL WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); - print ""; - print "UPDATE_COUNTERS"; - print ""; - + print json_encode(array("message" => "UPDATE_COUNTERS")); return; } if ($subop == "archive") { + header("Content-Type: text/plain"); + $ids = split(",", db_escape_string($_REQUEST["ids"])); foreach ($ids as $id) { archive_article($link, $id, $_SESSION["uid"]); } - print ""; - print "UPDATE_COUNTERS"; - print ""; - + print json_encode(array("message" => "UPDATE_COUNTERS")); return; } @@ -268,7 +259,7 @@ return; } - if ($subop == "updateFeed") { +/* if ($subop == "updateFeed") { $feed_id = db_escape_string($_REQUEST["feed"]); update_rss_feed($link, $feed_id); @@ -278,7 +269,7 @@ print ""; return; - } + } */ if ($subop == "updateAllFeeds" || $subop == "getAllCounters") { @@ -308,44 +299,38 @@ /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ if ($subop == "catchupSelected") { + header("Content-Type: text/plain"); $ids = split(",", db_escape_string($_REQUEST["ids"])); $cmode = sprintf("%d", $_REQUEST["cmode"]); catchupArticlesById($link, $ids, $cmode); - print ""; - print "UPDATE_COUNTERS"; - print ""; - + print json_encode(array("message" => "UPDATE_COUNTERS")); return; } if ($subop == "markSelected") { + header("Content-Type: text/plain"); $ids = split(",", db_escape_string($_REQUEST["ids"])); $cmode = sprintf("%d", $_REQUEST["cmode"]); markArticlesById($link, $ids, $cmode); - print ""; - print "UPDATE_COUNTERS"; - print ""; - + print json_encode(array("message" => "UPDATE_COUNTERS")); return; } if ($subop == "publishSelected") { + header("Content-Type: text/plain"); $ids = split(",", db_escape_string($_REQUEST["ids"])); $cmode = sprintf("%d", $_REQUEST["cmode"]); publishArticlesById($link, $ids, $cmode); - print ""; - print "UPDATE_COUNTERS"; - print ""; - + print json_encode(array("message" => "UPDATE_COUNTERS")); return; } @@ -467,6 +452,7 @@ } if ($subop == "completeTags") { + header("Content-Type: text/plain"); $search = db_escape_string($_REQUEST["search"]); @@ -488,24 +474,16 @@ $ids = split(",", db_escape_string($_REQUEST["ids"])); $days = sprintf("%d", $_REQUEST["days"]); - print ""; - - print ""; - - print ""; - return; } @@ -915,6 +893,8 @@ } if ($subop == "cdmGetArticle") { + header("Content-Type: text/plain"); + $id = db_escape_string($_REQUEST["id"]); $result = db_query($link, "SELECT content, @@ -934,14 +914,15 @@ $article_content = ''; } - print "
"; + print json_encode(array("article" => + array("id" => $id, "content" => $article_content))); return; } if ($subop == "scheduleFeedUpdate") { + header("Content-Type: text/plain"); + $feed_id = db_escape_string($_REQUEST["id"]); $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true'; @@ -973,10 +954,7 @@ $message = __("Can't update this kind of feed."); } - print ""; - print "$message"; - print ""; - + print json_encode(array("message" => $message)); return; } diff --git a/tt-rss.js b/tt-rss.js index 6d799437..9790bb98 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -1078,18 +1078,16 @@ function scheduleFeedUpdate(id, is_cat) { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { + handle_rpc_json(transport); - if (transport.responseXML) { - var message = transport.responseXML.getElementsByTagName("message")[0]; + var reply = JSON.parse(transport.responseText); + var message = reply['message']; - if (message) { - notify_info(message.firstChild.nodeValue); - return; - } + if (message) { + notify_info(message); + return; } - notify_error("Error communicating with server."); - } }); diff --git a/viewfeed.js b/viewfeed.js index 8d0ab28a..37afd340 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -17,19 +17,6 @@ var preload_timeout_id = false; 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) { try { @@ -454,7 +441,7 @@ function toggleMark(id, client_only) { new Ajax.Request("backend.php", { parameters: query, 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", { parameters: query, 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 { var rows = getSelectedArticleIds2(); @@ -790,7 +777,8 @@ function selectionToggleUnread(set_state, callback_func, no_error) { new Ajax.Request("backend.php", { parameters: query, 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", { parameters: query, onComplete: function(transport) { - handle_rpc_reply(transport); + handle_rpc_json(transport); } }); } @@ -854,7 +842,7 @@ function selectionTogglePublished() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - handle_rpc_reply(transport); + handle_rpc_json(transport); } }); } @@ -982,6 +970,7 @@ function deleteSelection() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { + handle_rpc_json(transport); viewCurrentFeed(); } }); @@ -1031,6 +1020,7 @@ function archiveSelection() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { + handle_rpc_json(transport); viewCurrentFeed(); } }); @@ -1215,7 +1205,7 @@ function cdmWatchdog() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - handle_rpc_reply(transport); + handle_rpc_json(transport); } }); } @@ -1571,7 +1561,7 @@ function catchupRelativeToArticle(below) { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - catchup_callback2(transport); + handle_rpc_json(transport); } }); } @@ -1633,12 +1623,16 @@ function cdmExpandArticle(id) { onComplete: function(transport) { $("FUPDPIC-" + id).src = 'images/blank_icon.gif'; - if (transport.responseXML) { - var article = transport.responseXML.getElementsByTagName("article")[0]; - var recv_id = article.getAttribute("id"); + handle_rpc_json(transport); + + var reply = JSON.parse(transport.responseText); + + if (reply) { + var article = reply['article']['content']; + var recv_id = reply['article']['id']; if (recv_id == id) - $("CWRAP-" + id).innerHTML = article.firstChild.nodeValue; + $("CWRAP-" + id).innerHTML = article; } else { $("CWRAP-" + id).innerHTML = __("Unable to load article."); -- 2.39.5