]> git.wh0rd.org Git - tt-rss.git/commitdiff
rpc: mark silent methods, rework verifyRegexp to use JSON
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 29 Nov 2010 13:44:50 +0000 (16:44 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 29 Nov 2010 13:44:50 +0000 (16:44 +0300)
functions.js
modules/backend-rpc.php
prefs.js

index 615d59fc3aec5cf19a17be44c1487f020fc2399b..91318b020edbfbf87df3bee149672497292276c5 100644 (file)
@@ -962,15 +962,12 @@ function quickAddFilter() {
                                        new Ajax.Request("backend.php", {
                                                parameters: query,
                                                onComplete: function(transport) {
-                                                       handle_rpc_reply(transport);
-                                                       var response = transport.responseXML;
+                                                       var reply = JSON.parse(transport.responseText); 
 
-                                                       if (response) {
-                                                               var s = response.getElementsByTagName("status")[0].firstChild.nodeValue;
-       
+                                                       if (reply) {
                                                                notify('');
 
-                                                               if (s == "INVALID") {
+                                                               if (!reply['status']) {
                                                                        alert("Match regular expression seems to be invalid.");
                                                                        return;
                                                                } else {
@@ -1162,14 +1159,13 @@ function genUrlChangeKey(feed, is_cat) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) {
-                                               var new_link = transport.responseXML.getElementsByTagName("link")[0];
+                                               var reply = JSON.parse(transport.responseText);
+                                               var new_link = reply.link;
        
                                                var e = $('gen_feed_url');
        
                                                if (new_link) {
                                                        
-                                                       new_link = new_link.firstChild.nodeValue;
-
                                                        e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/, 
                                                                "&amp;key=" + new_link);
 
index 5721eb3c279d87d716347bfa9dc02f21dcbe630a..b8877da20eca1197d9bb7ea317fa9503cf7a0039 100644 (file)
@@ -4,6 +4,7 @@
                $subop = $_REQUEST["subop"];
                $seq = (int) $_REQUEST["seq"];
 
+               // Silent
                if ($subop == "setprofile") {
                        $id = db_escape_string($_REQUEST["id"]);
 
@@ -12,6 +13,7 @@
                        return;
                }
 
+               // Silent
                if ($subop == "remprofiles") {
                        $ids = split(",", db_escape_string(trim($_REQUEST["ids"])));
 
@@ -24,6 +26,7 @@
                        return;
                }
 
+               // Silent
                if ($subop == "addprofile") {
                        $title = db_escape_string(trim($_REQUEST["title"]));
                        if ($title) {
@@ -54,6 +57,7 @@
                        return;
                }
 
+               // Silent
                if ($subop == "saveprofile") {
                        $id = db_escape_string($_REQUEST["id"]);
                        $title = db_escape_string(trim($_REQUEST["value"]));
@@ -85,6 +89,7 @@
                        return;
                }
 
+               // Silent
                if ($subop == "remarchive") {
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
 
 
                                $rc = db_affected_rows($link, $result);
                        }
-
                        return;
                }
 
                                $mark = "false";
                        }
 
-                       // FIXME this needs collision testing
-
                        $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
                                WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
                        return;
                }
 
-               // XML method
                if ($subop == "regenOPMLKey") {
-
-                       print "<rpc-reply>";
+                       header("Content-Type: text/plain");
 
                        update_feed_access_key($link, 'OPML:Publish', 
                                false, $_SESSION["uid"]);
 
                        $new_link = opml_publish_url($link);            
-                       print "<link><![CDATA[$new_link]]></link>";
-                       print "</rpc-reply>";
+
+                       print json_encode(array("link" => $new_link));
                        return;
                }
 
                        return;
                }
 
+               // Silent
                if ($subop == "massSubscribe") {
 
                        $ids = split(",", db_escape_string($_REQUEST["ids"]));
                        return;
                }
 
-               // XML method
                if ($subop == "regenFeedKey") {
+                       header("Content-Type: text/plain");
+
                        $feed_id = db_escape_string($_REQUEST['id']);
                        $is_cat = (bool) db_escape_string($_REQUEST['is_cat']);
 
-                       print "<rpc-reply>";
-
                        $new_key = update_feed_access_key($link, $feed_id, $is_cat);
 
-                       print "<link><![CDATA[$new_key]]></link>";
-
-                       print "</rpc-reply>";
-
+                       print json_encode(array("link" => $new_key));
                        return;
                }
 
+               // Silent
                if ($subop == "clearKeys") {
                        db_query($link, "DELETE FROM ttrss_access_keys WHERE
                                owner_uid = " . $_SESSION["uid"]);
                        return;
                }
 
-               // XML method
                if ($subop == "verifyRegexp") {
-                       $reg_exp = $_REQUEST["reg_exp"];
-
-                       print "<rpc-reply><status>";
+                       header("Content-Type: text/plain");
 
-                       if (@preg_match("/$reg_exp/i", "TEST") === false) {
-                               print "INVALID";
-                       } else {
-                               print "OK";
-                       }
+                       $reg_exp = $_REQUEST["reg_exp"];
 
-                       print "</status></rpc-reply>";
+                       $status = @preg_match("/$reg_exp/i", "TEST") !== false;
 
+                       print json_encode(array("status" => $status));
                        return;
                }
 
index ea2bf09d343134d55235be5a94d206628c35c26e..c88ae2c06965c8a7dbc2de4d1aad8e538e058bb8 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -206,15 +206,12 @@ function editFilter(id) {
                                        new Ajax.Request("backend.php", {
                                                parameters: query,
                                                onComplete: function(transport) {
-                                                       handle_rpc_reply(transport);
-                                                       var response = transport.responseXML;
+                                                       var reply = JSON.parse(transport.responseText);
 
-                                                       if (response) {
-                                                               var s = response.getElementsByTagName("status")[0].firstChild.nodeValue;
-       
+                                                       if (reply) {
                                                                notify('');
 
-                                                               if (s == "INVALID") {
+                                                               if (!reply['status']) {
                                                                        alert("Match regular expression seems to be invalid.");
                                                                        return;
                                                                } else {
@@ -1248,13 +1245,15 @@ function opmlRegenKey() {
                        new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) {
-                                               var new_link = transport.responseXML.getElementsByTagName("link")[0];
+                                               var reply = JSON.parse(transport.responseText);
+
+                                               var new_link = reply.link;
        
                                                var e = $('pub_opml_url');
        
                                                if (new_link) {
-                                                       e.href = new_link.firstChild.nodeValue;
-                                                       e.innerHTML = new_link.firstChild.nodeValue;
+                                                       e.href = new_link;
+                                                       e.innerHTML = new_link;
        
                                                        new Effect.Highlight(e);