]> git.wh0rd.org - tt-rss.git/commitdiff
remove unneeded xml from several more rpc methods
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 25 Nov 2010 10:39:37 +0000 (13:39 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 25 Nov 2010 10:54:34 +0000 (13:54 +0300)
modules/backend-rpc.php
tt-rss.js
viewfeed.js

index 93d8f074b5d7203db3ece4f8a67caf5bf20ed76d..510a9fd3692e15ee89a6bcd04048a329d25265e7 100644 (file)
                }
 
                if ($subop == "togglepref") {
-                       print "<rpc-reply>";
+                       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 "<param-set key=\"$key\" value=\"$value\"/>";
-
-                       print "</rpc-reply>";
-
+                       print json_encode(array("param" =>$key, "value" => $value));
                        return;
                }
 
                }
 
                if ($subop == "mark") {
+                       header("Content-Type: text/plain");
+
                        $mark = $_REQUEST["mark"];
                        $id = db_escape_string($_REQUEST["id"]);
 
                        $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
                                WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
-                       print "<rpc-reply>";
-                       print "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
+                       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 "<rpc-reply>";
-                       print "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
+                       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 "<rpc-reply>";
-                       print "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
+                       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 "<rpc-reply>";
-                       print "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
+                       print json_encode(array("message" => "UPDATE_COUNTERS"));
                        return;
                }
 
                        return;
                }
 
-               if ($subop == "updateFeed") {
+/*             if ($subop == "updateFeed") {
                        $feed_id = db_escape_string($_REQUEST["feed"]);
 
                        update_rss_feed($link, $feed_id);
                        print "</rpc-reply>";
 
                        return;
-               }
+               } */
 
                if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
 
 
                /* 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 "<rpc-reply>";
-                       print "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
+                       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 "<rpc-reply>";
-                       print "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
+                       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 "<rpc-reply>";
-                       print "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
+                       print json_encode(array("message" => "UPDATE_COUNTERS"));
                        return;
                }
 
                }
 
                if ($subop == "completeTags") {
+                       header("Content-Type: text/plain");
 
                        $search = db_escape_string($_REQUEST["search"]);
 
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
                        $days = sprintf("%d", $_REQUEST["days"]);
 
-                       print "<rpc-reply>";
-
-                       print "<message><![CDATA[";
-
                        foreach ($ids as $id) {
 
                                $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
                                        id = '$id' AND owner_uid = ".$_SESSION["uid"]);
 
                                if (db_num_rows($result) == 1) {
-                                       purge_feed($link, $id, $days, true);
+                                       purge_feed($link, $id, $days);
                                }
                        }
 
-                       print "]]></message>";
-
-                       print "</rpc-reply>";
-
                        return;
                }
 
                }
 
                if ($subop == "cdmGetArticle") {
+                       header("Content-Type: text/plain");
+
                        $id = db_escape_string($_REQUEST["id"]);
 
                        $result = db_query($link, "SELECT content, 
                                $article_content = '';
                        }
 
-                       print "<rpc-reply><article id=\"$id\"><![CDATA[";
-                       print "$article_content";
-                       print "]]></article></rpc-reply>";
+                       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';
 
                                $message = __("Can't update this kind of feed.");
                        }
 
-                       print "<rpc-reply>";
-                       print "<message>$message</message>";
-                       print "</rpc-reply>";
-
+                       print json_encode(array("message" => $message));
                        return;
                }
 
index 6d79943774f5c4e05a43d47e87a3fb7239863e2c..9790bb983232886262fb7fcbe72b8cc6f746b5b9 100644 (file)
--- 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.");
-
                        } });
 
 
index 8d0ab28a9689cc88b351983e9b604ad10d71f97e..37afd340a429d7cf9357de48b643a8ee7a1c45df 100644 (file)
@@ -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.");