headlines: use JSON instead of separate helper xml objects like headlines-unread

This commit is contained in:
Andrew Dolgov 2010-11-06 22:19:08 +03:00
parent f72a7b6696
commit ffbe082dd0
3 changed files with 40 additions and 20 deletions

View File

@ -363,8 +363,8 @@
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);
@ -374,8 +374,19 @@
}
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);

View File

@ -6842,10 +6842,16 @@
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>";
}

View 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) {