From bd202c3f89af2d0b2d073841408212541d8031df Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 18 Mar 2011 12:55:45 +0300 Subject: [PATCH] backend/viewfeed: use JSON --- backend.php | 90 +++++------ feedlist.js | 54 ++++--- functions.php | 404 +++++++++++++++++++++++++------------------------- viewfeed.js | 137 ++++++----------- 4 files changed, 314 insertions(+), 371 deletions(-) diff --git a/backend.php b/backend.php index 20186b08..6fad38d2 100644 --- a/backend.php +++ b/backend.php @@ -50,14 +50,9 @@ if ((!$op || $op == "rpc" || $op == "rss" || $op == "digestSend" || $op == "dlg" || - $op == "viewfeed" || $op == "publish" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) { header("Content-Type: application/xml; charset=utf-8"); - if (ENABLE_GZIP_OUTPUT) { - ob_start("ob_gzhandler"); - } - } else { if (!$_REQUEST["noxml"]) { header("Content-Type: text/html; charset=utf-8"); @@ -66,6 +61,10 @@ } } + if (ENABLE_GZIP_OUTPUT) { + ob_start("ob_gzhandler"); + } + if (SINGLE_USER_MODE) { authenticate_user($link, "admin", null); } @@ -246,10 +245,9 @@ case "viewfeed": - $print_exec_time = true; $timing_info = getmicrotime(); - print ""; + $reply = array(); if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); @@ -269,8 +267,26 @@ * when there's nothing to load - e.g. no stuff in fresh feed */ if ($feed == -5) { - generate_dashboard_feed($link); - print ""; + print json_encode(generate_dashboard_feed($link)); + return; + } + + $result = false; + + if ($feed < -10) { + $label_feed = -10-$feed; + $result = db_query($link, "SELECT id FROM ttrss_labels2 WHERE + id = '$label_feed' AND owner_uid = " . $_SESSION['uid']); + } else if (!$cat_view && $feed > 0) { + $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE + id = '$feed' AND owner_uid = " . $_SESSION['uid']); + } else if ($cat_view) { + $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE + id = '$feed' AND owner_uid = " . $_SESSION['uid']); + } + + if ($result && db_num_rows($result) == 0) { + print json_encode(generate_error_feed($link, __("Feed not found."))); return; } @@ -290,11 +306,14 @@ WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); } - if (!$next_unread_feed) { - print ""; - } else { - print ""; - } + $reply['headlines'] = array(); + + if (!$next_unread_feed) + $reply['headlines']['id'] = $feed; + else + $reply['headlines']['id'] = $next_unread_feed; + + $reply['headlines']['is_cat'] = (bool) $cat_view; $override_order = false; @@ -332,7 +351,7 @@ if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); - $ret = outputHeadlinesList($link, $feed, $subop, + $ret = format_headlines_list($link, $feed, $subop, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgroup_last_feed, $override_order); @@ -342,64 +361,45 @@ $disable_cache = $ret[3]; $vgroup_last_feed = $ret[4]; - print ""; + $reply['headlines']['content'] = $ret[5]; + $reply['headlines']['toolbar'] = $ret[6]; if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); - //print ""; - //print ""; - $headlines_unread = ccache_find($link, $returned_feed, $_SESSION["uid"], $cat_view, true); if ($headlines_unread == -1) { $headlines_unread = getFeedUnread($link, $returned_feed, $cat_view); - } - //print ""; - //printf("", $disable_cache); - - print " (int) $headlines_count, + $reply['headlines-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 "]]>"; - - if ($_REQUEST["debug"]) $timing_info = print_checkpoint("10", $timing_info); - -/* if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); + if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { $articles = array(); foreach ($topmost_article_ids as $id) { array_push($articles, format_article($link, $id, $feed, false)); } - print ""; - } */ - - if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); + $reply['articles'] = $articles; + } - //if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop) { if ($subop) { - print ""; + $reply['counters'] = getAllCounters($link, $omode, $feed); } if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); - print_runtime_info($link); + $reply['runtime-info'] = make_runtime_info($link); + + print json_encode($reply); - print ""; break; // viewfeed case "pref-feeds": diff --git a/feedlist.js b/feedlist.js index b8dc473d..954a67c1 100644 --- a/feedlist.js +++ b/feedlist.js @@ -44,7 +44,7 @@ function viewfeed(feed, subop, is_cat, offset) { /* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") { if (getInitParam("hide_feedlist") == 1) { Element.hide("feeds-holder"); - } + } } */ dijit.byId("content-tabs").selectChild( @@ -79,7 +79,7 @@ function viewfeed(feed, subop, is_cat, offset) { return; } - _infscroll_request_sent = timestamp; + _infscroll_request_sent = timestamp; } hideAuxDlg(); @@ -141,7 +141,7 @@ function viewfeed(feed, subop, is_cat, offset) { console.log(query); /* var unread_ctr = -1; - + if (!is_cat) unread_ctr = getFeedUnread(feed); var cache_check = false; @@ -149,7 +149,7 @@ function viewfeed(feed, subop, is_cat, offset) { if (unread_ctr != -1 && !page_offset && !force_nocache && !subop) { var cache_prefix = ""; - + if (is_cat) { cache_prefix = "C:"; } else { @@ -163,8 +163,8 @@ function viewfeed(feed, subop, is_cat, offset) { if (cache_check) { setActiveFeedId(feed, is_cat); - - $("headlines-frame").innerHTML = cache_find_param(cache_prefix + feed, + + $("headlines-frame").innerHTML = cache_find_param(cache_prefix + feed, unread_ctr); request_counters(); @@ -181,34 +181,30 @@ function viewfeed(feed, subop, is_cat, offset) { new Ajax.Request("backend.php", { parameters: query, - onComplete: function(transport) { + onComplete: function(transport) { setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); - headlines_callback2(transport, page_offset); + headlines_callback2(transport, page_offset); } }); // } } catch (e) { exception_error("viewfeed", e); - } + } } function feedlist_init() { try { console.log("in feedlist init"); - + hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); document.onkeydown = hotkey_handler; setTimeout("hotkey_prefix_timeout()", 5*1000); if (!getActiveFeedId()) { - if (getInitParam("cdm_auto_catchup") != 1) { - setTimeout("viewfeed(-3)", 100); - } else { - setTimeout("viewfeed(-5)", 100); - } - } + setTimeout("viewfeed(-3)", 100); + } - console.log("T:" + + console.log("T:" + getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3)); hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); @@ -230,7 +226,7 @@ function request_counters_real() { new Ajax.Request("backend.php", { parameters: query, - onComplete: function(transport) { + onComplete: function(transport) { try { handle_rpc_json(transport); } catch (e) { @@ -316,7 +312,7 @@ function parse_counters(elems, scheduled_call) { // TODO: enable new content notification for categories - if (!activeFeedIsCat() && id == getActiveFeedId() + if (!activeFeedIsCat() && id == getActiveFeedId() && ctr > getFeedUnread(id) && scheduled_call) { displayNewContentPrompt(id); } @@ -329,7 +325,7 @@ function parse_counters(elems, scheduled_call) { if (id > 0) { if (has_img) { - setFeedIcon(id, false, + setFeedIcon(id, false, getInitParam("icons_url") + "/" + id + ".ico"); } else { setFeedIcon(id, false, 'images/blank_icon.gif'); @@ -337,7 +333,7 @@ function parse_counters(elems, scheduled_call) { } } } - + hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); } catch (e) { @@ -349,7 +345,7 @@ function getFeedUnread(feed, is_cat) { try { var tree = dijit.byId("feedTree"); - if (tree && tree.model) + if (tree && tree.model) return tree.model.getFeedUnread(feed, is_cat); } catch (e) { @@ -370,20 +366,20 @@ function hideOrShowFeeds(hide) { return tree.hideRead(hide, getInitParam("hide_read_shows_special")); } -function getFeedName(feed, is_cat) { +function getFeedName(feed, is_cat) { var tree = dijit.byId("feedTree"); - if (tree && tree.model) + if (tree && tree.model) return tree.model.getFeedValue(feed, is_cat, 'name'); } -function getFeedValue(feed, is_cat, key) { +function getFeedValue(feed, is_cat, key) { try { var tree = dijit.byId("feedTree"); - if (tree && tree.model) + if (tree && tree.model) return tree.model.getFeedValue(feed, is_cat, key); - + } catch (e) { // } @@ -394,7 +390,7 @@ function setFeedUnread(feed, is_cat, unread) { try { var tree = dijit.byId("feedTree"); - if (tree && tree.model) + if (tree && tree.model) return tree.model.setFeedUnread(feed, is_cat, unread); } catch (e) { @@ -406,7 +402,7 @@ function setFeedValue(feed, is_cat, key, value) { try { var tree = dijit.byId("feedTree"); - if (tree && tree.model) + if (tree && tree.model) return tree.model.setFeedValue(feed, is_cat, key, value); } catch (e) { diff --git a/functions.php b/functions.php index 3f1d72f9..b0c768ff 100644 --- a/functions.php +++ b/functions.php @@ -4019,135 +4019,136 @@ mb_strtolower(strip_tags($title), 'utf-8')); } - function print_headline_subtoolbar($link, $feed_site_url, $feed_title, + function format_headline_subtoolbar($link, $feed_site_url, $feed_title, $feed_id, $is_cat, $search, $match_on, $search_mode, $view_mode, $error) { - $page_prev_link = "viewFeedGoPage(-1)"; - $page_next_link = "viewFeedGoPage(1)"; - $page_first_link = "viewFeedGoPage(0)"; + $page_prev_link = "viewFeedGoPage(-1)"; + $page_next_link = "viewFeedGoPage(1)"; + $page_first_link = "viewFeedGoPage(0)"; - $catchup_page_link = "catchupPage()"; - $catchup_feed_link = "catchupCurrentFeed()"; - $catchup_sel_link = "catchupSelection()"; + $catchup_page_link = "catchupPage()"; + $catchup_feed_link = "catchupCurrentFeed()"; + $catchup_sel_link = "catchupSelection()"; - $archive_sel_link = "archiveSelection()"; - $delete_sel_link = "deleteSelection()"; + $archive_sel_link = "archiveSelection()"; + $delete_sel_link = "deleteSelection()"; - $sel_all_link = "selectArticles('all')"; - $sel_unread_link = "selectArticles('unread')"; - $sel_none_link = "selectArticles('none')"; - $sel_inv_link = "selectArticles('invert')"; + $sel_all_link = "selectArticles('all')"; + $sel_unread_link = "selectArticles('unread')"; + $sel_none_link = "selectArticles('none')"; + $sel_inv_link = "selectArticles('invert')"; - $tog_unread_link = "selectionToggleUnread()"; - $tog_marked_link = "selectionToggleMarked()"; - $tog_published_link = "selectionTogglePublished()"; + $tog_unread_link = "selectionToggleUnread()"; + $tog_marked_link = "selectionToggleMarked()"; + $tog_published_link = "selectionTogglePublished()"; - print "
"; + $reply = "
"; - print __('Select:')." - ".__('All').", - ".__('Unread').", - ".__('Invert').", - ".__('None').""; + $reply .= __('Select:')." + ".__('All').", + ".__('Unread').", + ".__('Invert').", + ".__('None').""; - print " "; + $reply .= " "; - print ""; + $reply .= ""; - print ""; + $reply .= ""; - print " - - "; + $reply .= " + + "; - print ""; + $reply .= ""; - print ""; + $reply .= ""; - if ($feed_id != "0") { - print ""; - } else { - print ""; - print ""; - - } + if ($feed_id != "0") { + $reply .= ""; + } else { + $reply .= ""; + $reply .= ""; - print ""; + } - $rss_link = htmlspecialchars(get_self_url_prefix() . - "/backend.php?op=rss&id=$feed_id&is_cat=$is_cat&view_mode=$view_mode$search_q"); + $reply .= ""; - print ""; + $rss_link = htmlspecialchars(get_self_url_prefix() . + "/backend.php?op=rss&id=$feed_id&is_cat=$is_cat&view_mode=$view_mode$search_q"); - print ""; + $reply .= ""; - print ""; + $reply .= ""; - print ""; + $reply .= ""; - print "
"; + $reply .= ""; - print "
"; + $reply .= "
"; - if ($feed_site_url) { - $target = "target=\"_blank\""; - print "". - truncate_string($feed_title,30).""; + $reply .= "
"; - if ($error) { - print " (Error)"; - } + if ($feed_site_url) { + $target = "target=\"_blank\""; + $reply .= "". + truncate_string($feed_title,30).""; - } else { - if ($feed_id < -10) { - $label_id = -11-$feed_id; + if ($error) { + $reply .= " (Error)"; + } - $result = db_query($link, "SELECT fg_color, bg_color - FROM ttrss_labels2 WHERE id = '$label_id' AND owner_uid = " . - $_SESSION["uid"]); + } else { + if ($feed_id < -10) { + $label_id = -11-$feed_id; - if (db_num_rows($result) != 0) { - $fg_color = db_fetch_result($result, 0, "fg_color"); - $bg_color = db_fetch_result($result, 0, "bg_color"); + $result = db_query($link, "SELECT fg_color, bg_color + FROM ttrss_labels2 WHERE id = '$label_id' AND owner_uid = " . + $_SESSION["uid"]); - print ""; - print $feed_title; - print ""; - } else { - print $feed_title; - } + if (db_num_rows($result) != 0) { + $fg_color = db_fetch_result($result, 0, "fg_color"); + $bg_color = db_fetch_result($result, 0, "bg_color"); + $reply .= ""; + $reply .= $feed_title; + $reply .= ""; } else { - print $feed_title; + $reply .= $feed_title; } - } - if ($search) { - $search_q = "&q=$search&m=$match_on&smode=$search_mode"; } else { - $search_q = ""; + $reply .= $feed_title; } + } - // Adaptive doesn't really make any sense for generated feeds - // All Articles is the default, so no need to insert it either - if ($view_mode == "adaptive" || $view_mode == "all_articles") - $view_mode = ""; - else - $view_mode = "&view-mode=$view_mode"; + if ($search) { + $search_q = "&q=$search&m=$match_on&smode=$search_mode"; + } else { + $search_q = ""; + } - print " - - "; + // Adaptive doesn't really make any sense for generated feeds + // All Articles is the default, so no need to insert it either + if ($view_mode == "adaptive" || $view_mode == "all_articles") + $view_mode = ""; + else + $view_mode = "&view-mode=$view_mode"; - print "
"; + $reply .= " + + "; - } + $reply .= "
"; + + return $reply; + } function outputFeedList($link, $special = true) { @@ -4730,12 +4731,14 @@ } - function outputHeadlinesList($link, $feed, $subop, $view_mode, $limit, $cat_view, + function format_headlines_list($link, $feed, $subop, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, $override_order = false) { $disable_cache = false; + $reply = array(); + $timing_info = getmicrotime(); $topmost_article_ids = array(); @@ -4780,8 +4783,7 @@ "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1"); if (db_num_rows($result) == 0) { - print "
".__('Feed not found.')."
"; - return; + $reply['content'] = "
".__('Feed not found.')."
"; } } @@ -4837,34 +4839,17 @@ $vgroup_last_feed = $vgr_last_feed; -/* if ($feed == -2) { - $feed_site_url = article_publish_url($link); - } */ - /// STOP ////////////////////////////////////////////////////////////////////////////////// - print ""; - - if (!$result) { - print "
".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."
"; - return; - } if (db_num_rows($result) > 0) { - print_headline_subtoolbar($link, $feed_site_url, $feed_title, + $reply['toolbar'] = format_headline_subtoolbar($link, $feed_site_url, $feed_title, $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, $last_error); - -// print "
"; - } } - print "]]> 0) { @@ -5006,7 +4991,7 @@ $vf_catchup_link = "(".__('mark as read').")"; - print "
". + $reply['content'] .= "
". "
$feed_icon_img
". "". $line["feed_title"]." $vf_catchup_link
"; @@ -5017,36 +5002,36 @@ $mouseover_attrs = "onmouseover='postMouseIn($id)' onmouseout='postMouseOut($id)'"; - print "
"; + $reply['content'] .= "
"; - print "
$update_pic
"; + $reply['content'] .= "
$update_pic
"; - print "
"; + $reply['content'] .= "
"; - print ""; - print "$marked_pic"; - print "$published_pic"; + $reply['content'] .= "$marked_pic"; + $reply['content'] .= "$published_pic"; - print "
"; + $reply['content'] .= "
"; - print "
"; - print "" . $line["title"]; if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { if ($content_preview) { - print " - $content_preview"; + $reply['content'] .= " - $content_preview"; } } - print ""; + $reply['content'] .= ""; - print $labels_str; + $reply['content'] .= $labels_str; /* if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) { if (@$line["feed_title"]) { @@ -5057,23 +5042,21 @@ } } */ - print "
"; - - + $reply['content'] .= "
"; - print "
"; - print "$updated_fmt"; - print $score_pic; + $reply['content'] .= "
"; + $reply['content'] .= "$updated_fmt"; + $reply['content'] .= $score_pic; if ($line["feed_title"] && !get_pref($link, 'VFEED_GROUP_BY_FEED')) { - print " $feed_icon_img"; } - print "
"; - print "
"; + $reply['content'] .= "
"; + $reply['content'] .= "
"; } else { @@ -5095,7 +5078,7 @@ //$feed_icon_img = "\"\""; } - print "
". + $reply['content'] .= "
". "
$feed_icon_img
". "". $line["feed_title"]." $vf_catchup_link
"; @@ -5107,31 +5090,31 @@ $mouseover_attrs = "onmouseover='postMouseIn($id)' onmouseout='postMouseOut($id)'"; - print "
"; - print "
"; + $reply['content'] .= "
"; - print "
"; - print "$updated_fmt"; - print "$score_pic"; + $reply['content'] .= "
"; + $reply['content'] .= "$updated_fmt"; + $reply['content'] .= "$score_pic"; if (!get_pref($link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) { - print "$feed_icon_img"; } - print "
$update_pic
"; + $reply['content'] .= "
$update_pic
"; - print "
"; + $reply['content'] .= "
"; - print ""; - print "$marked_pic"; - print "$published_pic"; + $reply['content'] .= "$marked_pic"; + $reply['content'] .= "$published_pic"; - print " "; - print $labels_str; + $reply['content'] .= $labels_str; if (!$expand_cdm) $content_hidden = "style=\"display : none\""; else $excerpt_hidden = "style=\"display : none\""; - print " - $content_preview"; - print ""; + $reply['content'] .= ""; - print "
"; + $reply['content'] .= "
"; - print "
"; - print "
"; + $reply['content'] .= "
"; if ($line["orig_feed_id"]) { @@ -5168,23 +5151,23 @@ if (db_num_rows($tmp_result) != 0) { - print ""; } } @@ -5210,13 +5193,13 @@ $article_content = ''; } - print "
"; + $reply['content'] .= "
"; if ($line['note']) { - print format_article_note($id, $line['note']); + $reply['content'] .= format_article_note($id, $line['note']); } - print "
"; + $reply['content'] .= "
"; - print "$article_content"; + $reply['content'] .= "$article_content"; $tmp_result = db_query($link, "SELECT always_display_enclosures FROM ttrss_feeds WHERE id = ". @@ -5226,24 +5209,24 @@ $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result, 0, "always_display_enclosures")); - print format_article_enclosures($link, $id, $always_display_enclosures, + $reply['content'] .= format_article_enclosures($link, $id, $always_display_enclosures, $article_content); - print "
"; + $reply['content'] .= "
"; - print "
"; + $reply['content'] .= "
"; $tags_str = format_tags_string(get_article_tags($link, $id), $id); - print "Tags $tags_str (+)"; - print "
"; + $reply['content'] .= "
"; - print "Zoom"; if (DIGEST_ENABLE) { - print "Zoom"; } if (ENABLE_TWEET_BUTTON) { - print "Zoom"; } - print "Dismiss"; - print "
"; - print "
"; + $reply['content'] .= "
"; + $reply['content'] .= "
"; - print "
"; + $reply['content'] .= "
"; - print "
"; + $reply['content'] .= "
"; } @@ -5309,9 +5292,9 @@ } if (!$offset && $message) { - print "
$message"; + $reply['content'] .= "
$message"; - print "

"; + $reply['content'] .= "

"; $result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']); @@ -5319,7 +5302,7 @@ $last_updated = db_fetch_result($result, 0, "last_updated"); $last_updated = make_local_datetime($link, $last_updated, false); - printf(__("Feeds last updated at %s"), $last_updated); + $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); $result = db_query($link, "SELECT COUNT(id) AS num_errors FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); @@ -5327,11 +5310,11 @@ $num_errors = db_fetch_result($result, 0, "num_errors"); if ($num_errors > 0) { - print "
"; - print "". + $reply['content'] .= "
"; + $reply['content'] .= "
". __('Some feeds have update errors (click for details)').""; } - print "

"; + $reply['content'] .= "

"; } } @@ -5340,9 +5323,10 @@ # print ""; # } - print "]]>"; + #print "]]>"; - return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed); + return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, + $vgroup_last_feed, $reply['content'], $reply['toolbar']); } // from here: http://www.roscripts.com/Create_tag_cloud-71.html @@ -6608,16 +6592,34 @@ return $headlines; } - function generate_dashboard_feed($link) { - print ""; + function generate_error_feed($link, $error) { + $reply = array(); + + $reply['headlines']['id'] = -6; + $reply['headlines']['is_cat'] = false; + + $reply['headlines']['toolbar'] = ''; + $reply['headlines']['content'] = "
". $error . "
"; + + $reply['headlines-info'] = array("count" => 0, + "vgroup_last_feed" => '', + "unread" => 0, + "disable_cache" => true); + + return $reply; + } - print ""; - print '".__('No feed selected.'); + $reply['headlines']['toolbar'] = ''; + $reply['headlines']['content'] = "
".__('No feed selected.'); - print "

"; + $reply['headlines']['content'] .= "

"; $result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']); @@ -6625,7 +6627,7 @@ $last_updated = db_fetch_result($result, 0, "last_updated"); $last_updated = make_local_datetime($link, $last_updated, false); - printf(__("Feeds last updated at %s"), $last_updated); + $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); $result = db_query($link, "SELECT COUNT(id) AS num_errors FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); @@ -6633,26 +6635,18 @@ $num_errors = db_fetch_result($result, 0, "num_errors"); if ($num_errors > 0) { - print "
"; - print "". + $reply['headlines']['content'] .= "
"; + $reply['headlines']['content'] .= "
". __('Some feeds have update errors (click for details)').""; } - print "

"; - - print "]]>"; - print ""; + $reply['headlines']['content'] .= "

"; - print " 0, + $reply['headlines-info'] = array("count" => 0, "vgroup_last_feed" => '', "unread" => 0, "disable_cache" => true); - print json_encode($info); - - print "]]>"; - + return $reply; } function save_email_address($link, $email) { diff --git a/viewfeed.js b/viewfeed.js index 6e220bb4..0e11a608 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -25,47 +25,35 @@ function headlines_callback2(transport, feed_cur_page) { var is_cat = false; var feed_id = false; - if (transport.responseXML) { - var headlines = transport.responseXML.getElementsByTagName("headlines")[0]; - if (headlines) { - is_cat = headlines.getAttribute("is_cat"); - feed_id = headlines.getAttribute("id"); - setActiveFeedId(feed_id, is_cat); - } - } - - var update_btn = document.forms["main_toolbar_form"].update; - - update_btn.disabled = !(feed_id >= 0 && !is_cat); + var reply; try { - if (feed_cur_page == 0) { - $("headlines-frame").scrollTop = 0; - } - } catch (e) { }; + reply = JSON.parse(transport.responseText); + } catch (e) { + console.error(e); + } - if (transport.responseXML) { - var response = transport.responseXML; + if (reply) { - var headlines = response.getElementsByTagName("headlines")[0]; + is_cat = reply['headlines']['is_cat']; + feed_id = reply['headlines']['id']; - var headlines_content = headlines.getElementsByTagName("content")[0]; - var headlines_toolbar = headlines.getElementsByTagName("toolbar")[0]; + setActiveFeedId(feed_id, is_cat); - var headlines_info = response.getElementsByTagName("headlines-info")[0]; + var update_btn = document.forms["main_toolbar_form"].update; - if (headlines_info) - headlines_info = JSON.parse(headlines_info.firstChild.nodeValue); - else { - console.error("didn't find headlines-info object in response"); - return; - } + update_btn.disabled = !(feed_id >= 0 && !is_cat); + + try { + if (feed_cur_page == 0) { + $("headlines-frame").scrollTop = 0; + } + } catch (e) { }; - var headlines_count = headlines_info.count; - var headlines_unread = headlines_info.unread; - var disable_cache = headlines_info.disable_cache; + var headlines_count = reply['headlines-info']['count']; + var headlines_unread = reply['headlines-info']['unread']; - vgroup_last_feed = headlines_info.vgroup_last_feed; + vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; if (parseInt(headlines_count) < getInitParam("default_article_limit")) { _infscroll_disable = 1; @@ -73,82 +61,49 @@ function headlines_callback2(transport, feed_cur_page) { _infscroll_disable = 0; } - var counters = response.getElementsByTagName("counters")[0]; - var articles = response.getElementsByTagName("article"); - var runtime_info = response.getElementsByTagName("runtime-info"); + var counters = reply['counters']; + var articles = reply['articles']; + var runtime_info = reply['runtime-info']; if (feed_cur_page == 0) { - if (headlines) { - dijit.byId("headlines-frame").attr('content', - headlines_content.firstChild.nodeValue); - - dijit.byId("headlines-toolbar").attr('content', - headlines_toolbar.firstChild.nodeValue); - - initHeadlinesMenu(); + dijit.byId("headlines-frame").attr('content', + reply['headlines']['content']); -/* var cache_prefix = ""; + dijit.byId("headlines-toolbar").attr('content', + reply['headlines']['toolbar']); - if (is_cat) { - cache_prefix = "C:"; - } else { - cache_prefix = "F:"; - } - - cache_invalidate(cache_prefix + feed_id); + initHeadlinesMenu(); - if (!disable_cache) { - cache_inject(cache_prefix + feed_id, - $("headlines-frame").innerHTML, headlines_unread); - } */ - - } else { - console.warn("headlines_callback: returned no data"); - dijit.byId("headlines-frame").attr('content', - "
" + - __('Could not update headlines (missing XML data)') + "
"); - - } } else { - if (headlines) { - if (headlines_count > 0) { - console.log("adding some more headlines..."); + if (headlines_count > 0) { + console.log("adding some more headlines..."); - var c = dijit.byId("headlines-frame"); - var ids = getSelectedArticleIds2(); + var c = dijit.byId("headlines-frame"); + var ids = getSelectedArticleIds2(); - //c.attr('content', c.attr('content') + - // headlines_content.firstChild.nodeValue); + $("headlines-tmp").innerHTML = reply['headlines']['content']; - $("headlines-tmp").innerHTML = headlines_content.firstChild.nodeValue; - - $$("#headlines-tmp > div").each(function(row) { - c.domNode.appendChild(row); - }); + $$("#headlines-tmp > div").each(function(row) { + c.domNode.appendChild(row); + }); - console.log("restore selected ids: " + ids); + console.log("restore selected ids: " + ids); - for (var i = 0; i < ids.length; i++) { - markHeadline(ids[i]); - } + for (var i = 0; i < ids.length; i++) { + markHeadline(ids[i]); + } - initHeadlinesMenu(); + initHeadlinesMenu(); - } else { - console.log("no new headlines received"); - } } else { - console.warn("headlines_callback: returned no data"); - notify_error("Error while trying to load more headlines"); + console.log("no new headlines received"); } - } if (articles) { for (var i = 0; i < articles.length; i++) { - var a_id = articles[i].getAttribute("id"); - //console.log("found id: " + a_id); - cache_inject(a_id, articles[i].firstChild.nodeValue); + var a_id = articles[i]['id']; + cache_inject(a_id, articles[i]['content']); } } else { console.log("no cached articles received"); @@ -162,11 +117,9 @@ function headlines_callback2(transport, feed_cur_page) { } else { console.warn("headlines_callback: returned no XML object"); dijit.byId("headlines-frame").attr('content', "
" + - __('Could not update headlines (missing XML object)') + "
"); + __('Could not update headlines (invalid object received)') + "
"); } - - _feed_cur_page = feed_cur_page; _infscroll_request_sent = 0; -- 2.39.5