]> git.wh0rd.org Git - tt-rss.git/commitdiff
headlines: use JSON instead of separate helper xml objects like headlines-unread
authorAndrew Dolgov <fox@fakecake.org>
Sat, 6 Nov 2010 19:19:08 +0000 (22:19 +0300)
committerAndrew Dolgov <fox@fakecake.org>
Sat, 6 Nov 2010 19:19:08 +0000 (22:19 +0300)
backend.php
functions.php
viewfeed.js

index 521472051473027336449e3998d780789da67fc8..761fc0dc02351b963c23973008e0bc895cd158f7 100644 (file)
 
                        print "]]></headlines>";
 
-                       print "<headlines-count value=\"$headlines_count\"/>";
-                       print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
+                       //print "<headlines-count value=\"$headlines_count\"/>";
+                       //print "<vgroup-last-feed value=\"$vgroup_last_feed\"/>";
 
                        $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"],
                                        $cat_view, true);
 
                        }
 
-                       print "<headlines-unread value=\"$headlines_unread\"/>";
-                       printf("<disable-cache value=\"%d\"/>", $disable_cache);
+                       //print "<headlines-unread value=\"$headlines_unread\"/>";
+                       //printf("<disable-cache value=\"%d\"/>", $disable_cache);
+
+                       print "<headlines-info><![CDATA[";
+
+                       $info = array("count" => (int) $headlines_count,
+                               "vgroup_last_feed" => $vgroup_last_feed,
+                               "unread" => (int) $headlines_unread,
+                               "disable_cache" => (bool) $disable_cache);
+
+                       print json_encode($info);
+
+                       print "]]></headlines-info>";
 
                        if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info);
 
index abc52b43ede473d1dc18aa6f78f4f48f4b8c8a5c..d5b3c436d7ab7129ff040132a8e8b9da41a474b1 100644 (file)
                print "</div>]]>";
                print "</headlines>";
 
-               print "<headlines-count value=\"0\"/>";
-               print "<vgroup-last-feed value=\"0\"/>";
-               print "<headlines-unread value=\"0\"/>";
-               print "<disable-cache value=\"1\"/>";
+               print "<headlines-info><![CDATA[";
+
+               $info = array("count" => 0,
+                       "vgroup_last_feed" => '',
+                       "unread" => 0,
+                       "disable_cache" => true);
+
+               print json_encode($info);
+
+               print "]]></headlines-info>";
 
        }
 
index 1e9a11a1656a165f4a24fa2f33eac251e1f631aa..5a0bf77edbc030dcbb4d6b1eab23f64cf82c6cff 100644 (file)
@@ -107,18 +107,21 @@ function headlines_callback2(transport, feed_cur_page) {
                } catch (e) { };
        
                if (transport.responseXML) {
-                       var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
-                       var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
-                       var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
-                       var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0];
+                       var response = transport.responseXML;
 
-                       var vgroup_last_feed_obj =  transport.responseXML.getElementsByTagName("vgroup-last-feed")[0];
+                       var headlines = response.getElementsByTagName("headlines")[0];
+                       var headlines_info = response.getElementsByTagName("headlines-info")[0];
 
-                       var headlines_count = headlines_count_obj.getAttribute("value");
-                       var headlines_unread = headlines_unread_obj.getAttribute("value");
-                       var disable_cache = disable_cache_obj.getAttribute("value") != "0";
+                       if (headlines_info)
+                               headlines_info = JSON.parse(headlines_info.firstChild.nodeValue);
+                       else
+                               console.log("didn't find headlines-info object in response");
 
-                       vgroup_last_feed = vgroup_last_feed_obj.getAttribute("value");
+                       var headlines_count = headlines_info.count;
+                       var headlines_unread = headlines_info.unread;
+                       var disable_cache = headlines_info.disable_cache;
+                       
+                       vgroup_last_feed = headlines_info.vgroup_last_feed;
 
                        if (headlines_count == 0) {
                                _infscroll_disable = 1;
@@ -126,9 +129,9 @@ function headlines_callback2(transport, feed_cur_page) {
                                _infscroll_disable = 0;
                        }
 
-                       var counters = transport.responseXML.getElementsByTagName("counters")[0];
-                       var articles = transport.responseXML.getElementsByTagName("article");
-                       var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
+                       var counters = response.getElementsByTagName("counters")[0];
+                       var articles = response.getElementsByTagName("article");
+                       var runtime_info = response.getElementsByTagName("runtime-info");
        
                        if (feed_cur_page == 0) {
                                if (headlines) {