]> git.wh0rd.org Git - tt-rss.git/commitdiff
digest: use pure JSON
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 25 Nov 2010 11:21:20 +0000 (14:21 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 25 Nov 2010 11:24:17 +0000 (14:24 +0300)
digest.js
modules/backend-rpc.php

index 520c3d6194cea8c35f86f1a474575f8555a4c249..0e50ff4c0ef929d63a88347b462e5e2a669785a7 100644 (file)
--- a/digest.js
+++ b/digest.js
@@ -485,6 +485,10 @@ function redraw_feedlist(feeds) {
                                "</a>" + "</li>";
                }
 
+               if (feeds.length == 0) {
+                       $('feeds-content').innerHTML = __("No unread feeds.");
+               }
+
        } catch (e) {
                exception_error("redraw_feedlist", e);
        }
@@ -492,13 +496,13 @@ function redraw_feedlist(feeds) {
 
 function parse_feeds(transport) {
        try {
+               var reply = JSON.parse(transport.responseText);
 
-               if (!transport.responseXML) return;
+               if (!reply) return;
 
-               var feeds = transport.responseXML.getElementsByTagName('feeds')[0];
+               var feeds = reply['feeds'];
 
                if (feeds) {
-                       feeds = JSON.parse(feeds.firstChild.nodeValue);
 
                        feeds.sort( function (a,b) 
                                { 
@@ -529,12 +533,12 @@ function parse_feeds(transport) {
 
 function parse_headlines(transport, replace, no_effects) {
        try {
-               if (!transport.responseXML) return;
+               var reply = JSON.parse(transport.responseText);
+               if (!reply) return;
 
-               var seq = transport.responseXML.getElementsByTagName('seq')[0];
+               var seq = reply['seq'];
 
                if (seq) {
-                       seq = seq.firstChild.nodeValue;
                        if (seq != _update_seq) {
                                console.log("parse_headlines: wrong sequence received.");
                                return;
@@ -543,15 +547,11 @@ function parse_headlines(transport, replace, no_effects) {
                        return;
                }
 
-               var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
-               var headlines_title = transport.responseXML.getElementsByTagName('headlines-title')[0];
+               var headlines = reply['headlines']['content'];
+               var headlines_title = reply['headlines']['title'];
 
                if (headlines && headlines_title) {
-                       headlines = JSON.parse(headlines.firstChild.nodeValue);
-
-                       var title = headlines_title.firstChild.nodeValue;
-
-                       $("headlines-title").innerHTML = title;
+                       $("headlines-title").innerHTML = headlines_title
 
                        if (replace) {
                                $('headlines-content').innerHTML = '';
index 510a9fd3692e15ee89a6bcd04048a329d25265e7..59faee7b317799f7d0d0eec265f4cfb5b9f7275d 100644 (file)
                }
 
                if ($subop == "digest-update") {
+                       header("Content-Type: text/plain");
+
                        $feed_id = db_escape_string($_REQUEST['feed_id']);
                        $offset = db_escape_string($_REQUEST['offset']);
                        $seq = db_escape_string($_REQUEST['seq']);
                
                        if (!$feed_id) $feed_id = -4;
                        if (!$offset) $offset = 0;
-                       print "<rpc-reply>";
 
-                       print "<seq>$seq</seq>";
+                       $reply = array();
+
+                       $reply['seq'] = $seq;
 
                        $headlines = api_get_headlines($link, $feed_id, 10, $offset,
                                '', ($feed_id == -4), true, false, "unread", "updated DESC");
                        //function api_get_headlines($link, $feed_id, $limit, $offset,
                        //              $filter, $is_cat, $show_excerpt, $show_content, $view_mode) {
 
-                       print "<headlines-title><![CDATA[" . getFeedTitle($link, $feed_id) . 
-                               "]]></headlines-title>";
-
-                       print "<headlines><![CDATA[" . json_encode($headlines) . "]]></headlines>";
+                       $reply['headlines'] = array();
+                       $reply['headlines']['title'] = getFeedTitle($link, $feed_id);
+                       $reply['headlines']['content'] = $headlines;
 
-                       print "</rpc-reply>";
+                       print json_encode($reply);
                        return;
                }
 
                if ($subop == "digest-init") {
-                       print "<rpc-reply>";
-               
+                       header("Content-Type: text/plain");
+
                        $tmp_feeds = api_get_feeds($link, -3, true, false, 0);
 
                        $feeds = array();
                                if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
                        }
 
-                       print "<feeds><![CDATA[" . json_encode($feeds) . "]]></feeds>";
+                       print json_encode(array("feeds" => $feeds));
 
-                       print "</rpc-reply>";
                        return;
                }