backend/viewfeed: use JSON

This commit is contained in:
Andrew Dolgov 2011-03-18 12:55:45 +03:00
parent 009646d23a
commit bd202c3f89
4 changed files with 343 additions and 400 deletions

View File

@ -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>";
$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 "</reply>";
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 "<headlines id=\"$feed\" is_cat=\"$cat_view\">";
} else {
print "<headlines id=\"$next_unread_feed\" is_cat=\"$cat_view\">";
}
$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 "</headlines>";
$reply['headlines']['content'] = $ret[5];
$reply['headlines']['toolbar'] = $ret[6];
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
//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);
if ($headlines_unread == -1) {
$headlines_unread = getFeedUnread($link, $returned_feed, $cat_view);
}
//print "<headlines-unread value=\"$headlines_unread\"/>";
//printf("<disable-cache value=\"%d\"/>", $disable_cache);
print "<headlines-info><![CDATA[";
$info = array("count" => (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 "]]></headlines-info>";
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 "<articles><![CDATA[";
print json_encode($articles);
print "]]></articles>";
} */
$reply['articles'] = $articles;
}
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
//if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop) {
if ($subop) {
print "<counters><![CDATA[";
print json_encode(getAllCounters($link, $omode, $feed));
print "]]></counters>";
$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 "</reply>";
break; // viewfeed
case "pref-feeds":

View File

@ -201,11 +201,7 @@ function feedlist_init() {
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:" +

View File

@ -4019,136 +4019,137 @@
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 "<div id=\"subtoolbar_main\">";
$reply = "<div id=\"subtoolbar_main\">";
print __('Select:')."
<a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
<a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
<a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
<a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
$reply .= __('Select:')."
<a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
<a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
<a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
<a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
print " ";
$reply .= " ";
print "<select dojoType=\"dijit.form.Select\"
onchange=\"headlineActionsChange(this)\">";
print "<option value=\"false\">".__('Actions...')."</option>";
$reply .= "<select dojoType=\"dijit.form.Select\"
onchange=\"headlineActionsChange(this)\">";
$reply .= "<option value=\"false\">".__('Actions...')."</option>";
print "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
$reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
print "<option value=\"$tog_unread_link\">".__('Unread')."</option>
<option value=\"$tog_marked_link\">".__('Starred')."</option>
<option value=\"$tog_published_link\">".__('Published')."</option>";
$reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
<option value=\"$tog_marked_link\">".__('Starred')."</option>
<option value=\"$tog_published_link\">".__('Published')."</option>";
print "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
$reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
print "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
$reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
if ($feed_id != "0") {
print "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
} else {
print "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
print "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
}
print "<option value=\"emailArticle(false)\">".__('Forward by email').
"</option>";
$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 "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
print "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
print "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
print "</select>";
print "</div>";
print "<div id=\"subtoolbar_ftitle\">";
if ($feed_site_url) {
$target = "target=\"_blank\"";
print "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
truncate_string($feed_title,30)."</a>";
if ($error) {
print " (<span class=\"error\" title=\"$error\">Error</span>)";
}
} else {
if ($feed_id < -10) {
$label_id = -11-$feed_id;
$result = db_query($link, "SELECT fg_color, bg_color
FROM ttrss_labels2 WHERE id = '$label_id' AND owner_uid = " .
$_SESSION["uid"]);
if (db_num_rows($result) != 0) {
$fg_color = db_fetch_result($result, 0, "fg_color");
$bg_color = db_fetch_result($result, 0, "bg_color");
print "<span style='background : $bg_color; color : $fg_color'>";
print $feed_title;
print "</span>";
} else {
print $feed_title;
}
} else {
print $feed_title;
}
}
if ($search) {
$search_q = "&q=$search&m=$match_on&smode=$search_mode";
} else {
$search_q = "";
}
// 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 "
<a href=\"#\"
title=\"".__("View as RSS feed")."\"
onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
<img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
print "</div>";
if ($feed_id != "0") {
$reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
} else {
$reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
$reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
}
$reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
"</option>";
$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 .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
$reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
$reply .= "</select>";
$reply .= "</div>";
$reply .= "<div id=\"subtoolbar_ftitle\">";
if ($feed_site_url) {
$target = "target=\"_blank\"";
$reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
truncate_string($feed_title,30)."</a>";
if ($error) {
$reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
}
} else {
if ($feed_id < -10) {
$label_id = -11-$feed_id;
$result = db_query($link, "SELECT fg_color, bg_color
FROM ttrss_labels2 WHERE id = '$label_id' AND owner_uid = " .
$_SESSION["uid"]);
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 .= "<span style='background : $bg_color; color : $fg_color'>";
$reply .= $feed_title;
$reply .= "</span>";
} else {
$reply .= $feed_title;
}
} else {
$reply .= $feed_title;
}
}
if ($search) {
$search_q = "&q=$search&m=$match_on&smode=$search_mode";
} else {
$search_q = "";
}
// 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";
$reply .= "
<a href=\"#\"
title=\"".__("View as RSS feed")."\"
onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
<img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
$reply .= "</div>";
return $reply;
}
function outputFeedList($link, $special = true) {
$feedlist = array();
@ -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 "<div align='center'>".__('Feed not found.')."</div>";
return;
$reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
}
}
@ -4837,34 +4839,17 @@
$vgroup_last_feed = $vgr_last_feed;
/* if ($feed == -2) {
$feed_site_url = article_publish_url($link);
} */
/// STOP //////////////////////////////////////////////////////////////////////////////////
print "<toolbar><![CDATA[";
if (!$offset) {
// print "<div id=\"headlinesContainer\" $rtl_tag>";
if (!$result) {
print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
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 "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
}
}
print "]]></toolbar><content><![CDATA[";
$headlines_count = db_num_rows($result);
if (db_num_rows($result) > 0) {
@ -5006,7 +4991,7 @@
$vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
print "<div class='cdmFeedTitle'>".
$reply['content'] .= "<div class='cdmFeedTitle'>".
"<div style=\"float : right\">$feed_icon_img</div>".
"<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
$line["feed_title"]."</a> $vf_catchup_link</div>";
@ -5017,36 +5002,36 @@
$mouseover_attrs = "onmouseover='postMouseIn($id)'
onmouseout='postMouseOut($id)'";
print "<div class='$class' id='RROW-$id' $mouseover_attrs>";
$reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
print "<div class='hlUpdPic'>$update_pic</div>";
$reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
print "<div class='hlLeft'>";
$reply['content'] .= "<div class='hlLeft'>";
print "<input type=\"checkbox\" onclick=\"tSR(this)\"
$reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
id=\"RCHK-$id\">";
print "$marked_pic";
print "$published_pic";
$reply['content'] .= "$marked_pic";
$reply['content'] .= "$published_pic";
print "</div>";
$reply['content'] .= "</div>";
print "<div onclick='return hlClicked(event, $id)'
$reply['content'] .= "<div onclick='return hlClicked(event, $id)'
class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
print "<a id=\"RTITLE-$id\"
$reply['content'] .= "<a id=\"RTITLE-$id\"
href=\"" . htmlspecialchars($line["link"]) . "\"
onclick=\"return false;\">" .
$line["title"];
if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
if ($content_preview) {
print "<span class=\"contentPreview\"> - $content_preview</span>";
$reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
}
}
print "</a></span>";
$reply['content'] .= "</a></span>";
print $labels_str;
$reply['content'] .= $labels_str;
/* if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) {
if (@$line["feed_title"]) {
@ -5057,23 +5042,21 @@
}
} */
print "</div>";
$reply['content'] .= "</div>";
print "<div class=\"hlRight\">";
print "<span class=\"hlUpdated\">$updated_fmt</span>";
print $score_pic;
$reply['content'] .= "<div class=\"hlRight\">";
$reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
$reply['content'] .= $score_pic;
if ($line["feed_title"] && !get_pref($link, 'VFEED_GROUP_BY_FEED')) {
print "<span onclick=\"viewfeed($feed_id)\"
$reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
title=\"".htmlspecialchars($line['feed_title'])."\">
$feed_icon_img<span>";
}
print "</div>";
print "</div>";
$reply['content'] .= "</div>";
$reply['content'] .= "</div>";
} else {
@ -5095,7 +5078,7 @@
//$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
}
print "<div class='cdmFeedTitle'>".
$reply['content'] .= "<div class='cdmFeedTitle'>".
"<div style=\"float : right\">$feed_icon_img</div>".
"<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
$line["feed_title"]."</a> $vf_catchup_link</div>";
@ -5107,31 +5090,31 @@
$mouseover_attrs = "onmouseover='postMouseIn($id)'
onmouseout='postMouseOut($id)'";
print "<div class=\"$class\"
$reply['content'] .= "<div class=\"$class\"
id=\"RROW-$id\" $mouseover_attrs'>";
print "<div class=\"cdmHeader\">";
$reply['content'] .= "<div class=\"cdmHeader\">";
print "<div style='float : right'>";
print "<span class='updated'>$updated_fmt</span>";
print "$score_pic";
$reply['content'] .= "<div style='float : right'>";
$reply['content'] .= "<span class='updated'>$updated_fmt</span>";
$reply['content'] .= "$score_pic";
if (!get_pref($link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
print "<span style=\"cursor : pointer\"
$reply['content'] .= "<span style=\"cursor : pointer\"
title=\"".htmlspecialchars($line["feed_title"])."\"
onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
}
print "<div class=\"updPic\">$update_pic</div>";
$reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
print "</div>";
$reply['content'] .= "</div>";
print "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
$reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
'RROW-$id')\" id=\"RCHK-$id\"/>";
print "$marked_pic";
print "$published_pic";
$reply['content'] .= "$marked_pic";
$reply['content'] .= "$published_pic";
print "<span id=\"RTITLE-$id\"
$reply['content'] .= "<span id=\"RTITLE-$id\"
onclick=\"return cdmClicked(event, $id);\"
class=\"titleWrap$hlc_suffix\">
<a class=\"title\"
@ -5141,25 +5124,25 @@
truncate_string($line["title"], 100) .
" $entry_author</a>";
print $labels_str;
$reply['content'] .= $labels_str;
if (!$expand_cdm)
$content_hidden = "style=\"display : none\"";
else
$excerpt_hidden = "style=\"display : none\"";
print "<span $excerpt_hidden
$reply['content'] .= "<span $excerpt_hidden
id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
print "</span>";
$reply['content'] .= "</span>";
print "</div>";
$reply['content'] .= "</div>";
print "<div class=\"cdmContent\" $content_hidden
$reply['content'] .= "<div class=\"cdmContent\" $content_hidden
onclick=\"return cdmClicked(event, $id);\"
id=\"CICD-$id\">";
print "<div class=\"cdmContentInner\">";
$reply['content'] .= "<div class=\"cdmContentInner\">";
if ($line["orig_feed_id"]) {
@ -5168,23 +5151,23 @@
if (db_num_rows($tmp_result) != 0) {
print "<div clear='both'>";
print __("Originally from:");
$reply['content'] .= "<div clear='both'>";
$reply['content'] .= __("Originally from:");
print "&nbsp;";
$reply['content'] .= "&nbsp;";
$tmp_line = db_fetch_assoc($tmp_result);
print "<a target='_blank'
$reply['content'] .= "<a target='_blank'
href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
$tmp_line['title'] . "</a>";
print "&nbsp;";
$reply['content'] .= "&nbsp;";
print "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
print "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.gif'></a>";
$reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
$reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.gif'></a>";
print "</div>";
$reply['content'] .= "</div>";
}
}
@ -5210,13 +5193,13 @@
$article_content = '';
}
print "<div id=\"POSTNOTE-$id\">";
$reply['content'] .= "<div id=\"POSTNOTE-$id\">";
if ($line['note']) {
print format_article_note($id, $line['note']);
$reply['content'] .= format_article_note($id, $line['note']);
}
print "</div>";
$reply['content'] .= "</div>";
print "<span id=\"CWRAP-$id\">$article_content</span>";
$reply['content'] .= "<span id=\"CWRAP-$id\">$article_content</span>";
$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 "</div>";
$reply['content'] .= "</div>";
print "<div class=\"cdmFooter\">";
$reply['content'] .= "<div class=\"cdmFooter\">";
$tags_str = format_tags_string(get_article_tags($link, $id), $id);
print "<img src='".theme_image($link,
$reply['content'] .= "<img src='".theme_image($link,
'images/tag.png')."' alt='Tags' title='Tags'>
<span id=\"ATSTR-$id\">$tags_str</span>
<a title=\"".__('Edit tags for this article')."\"
href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
print "<div style=\"float : right\">";
$reply['content'] .= "<div style=\"float : right\">";
print "<img src=\"images/art-zoom.png\"
$reply['content'] .= "<img src=\"images/art-zoom.png\"
onclick=\"zoomToArticle(event, $id)\"
style=\"cursor : pointer\"
alt='Zoom'
@ -5251,36 +5234,36 @@
//$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
print "<img src=\"images/art-pub-note.png\"
$reply['content'] .= "<img src=\"images/art-pub-note.png\"
style=\"cursor : pointer\" style=\"cursor : pointer\"
onclick=\"editArticleNote($id)\"
alt='PubNote' title='".__('Edit article note')."'>";
if (DIGEST_ENABLE) {
print "<img src=\"".theme_image($link, 'images/art-email.png')."\"
$reply['content'] .= "<img src=\"".theme_image($link, 'images/art-email.png')."\"
style=\"cursor : pointer\"
onclick=\"emailArticle($id)\"
alt='Zoom' title='".__('Forward by email')."'>";
}
if (ENABLE_TWEET_BUTTON) {
print "<img src=\"".theme_image($link, 'images/art-tweet.png')."\"
$reply['content'] .= "<img src=\"".theme_image($link, 'images/art-tweet.png')."\"
class='tagsPic' style=\"cursor : pointer\"
onclick=\"tweetArticle($id)\"
alt='Zoom' title='".__('Share on Twitter')."'>";
}
print "<img src=\"images/digest_checkbox.png\"
$reply['content'] .= "<img src=\"images/digest_checkbox.png\"
style=\"cursor : pointer\" style=\"cursor : pointer\"
onclick=\"dismissArticle($id)\"
alt='Dismiss' title='".__('Dismiss article')."'>";
print "</div>";
print "</div>";
$reply['content'] .= "</div>";
$reply['content'] .= "</div>";
print "</div>";
$reply['content'] .= "</div>";
print "</div>";
$reply['content'] .= "</div>";
}
@ -5309,9 +5292,9 @@
}
if (!$offset && $message) {
print "<div class='whiteBox'>$message";
$reply['content'] .= "<div class='whiteBox'>$message";
print "<p class=\"small\"><span class=\"insensitive\">";
$reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
$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 "<br/>";
print "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
$reply['content'] .= "<br/>";
$reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
__('Some feeds have update errors (click for details)')."</a>";
}
print "</span></p></div>";
$reply['content'] .= "</span></p></div>";
}
}
@ -5340,9 +5323,10 @@
# print "</div>";
# }
print "]]></content>";
#print "]]></content>";
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_error_feed($link, $error) {
$reply = array();
$reply['headlines']['id'] = -6;
$reply['headlines']['is_cat'] = false;
$reply['headlines']['toolbar'] = '';
$reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
$reply['headlines-info'] = array("count" => 0,
"vgroup_last_feed" => '',
"unread" => 0,
"disable_cache" => true);
return $reply;
}
function generate_dashboard_feed($link) {
print "<headlines id=\"-5\" is_cat=\"\">";
$reply = array();
print "<toolbar><![CDATA[]]></toolbar>";
$reply['headlines']['id'] = -5;
$reply['headlines']['is_cat'] = false;
print '<content><![CDATA[';
$reply['headlines']['toolbar'] = '';
$reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
print "<div class='whiteBox'>".__('No feed selected.');
print "<p class=\"small\"><span class=\"insensitive\">";
$reply['headlines']['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
$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 "<br/>";
print "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
$reply['headlines']['content'] .= "<br/>";
$reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
__('Some feeds have update errors (click for details)')."</a>";
}
print "</span></p>";
$reply['headlines']['content'] .= "</span></p>";
print "]]></content>";
print "</headlines>";
print "<headlines-info><![CDATA[";
$info = array("count" => 0,
$reply['headlines-info'] = array("count" => 0,
"vgroup_last_feed" => '',
"unread" => 0,
"disable_cache" => true);
print json_encode($info);
print "]]></headlines-info>";
return $reply;
}
function save_email_address($link, $email) {

View File

@ -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);
var headlines_count = headlines_info.count;
var headlines_unread = headlines_info.unread;
var disable_cache = headlines_info.disable_cache;
try {
if (feed_cur_page == 0) {
$("headlines-frame").scrollTop = 0;
}
} catch (e) { };
vgroup_last_feed = headlines_info.vgroup_last_feed;
var headlines_count = reply['headlines-info']['count'];
var headlines_unread = reply['headlines-info']['unread'];
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-frame").attr('content',
reply['headlines']['content']);
dijit.byId("headlines-toolbar").attr('content',
headlines_toolbar.firstChild.nodeValue);
dijit.byId("headlines-toolbar").attr('content',
reply['headlines']['toolbar']);
initHeadlinesMenu();
} else {
if (headlines_count > 0) {
console.log("adding some more headlines...");
var c = dijit.byId("headlines-frame");
var ids = getSelectedArticleIds2();
$("headlines-tmp").innerHTML = reply['headlines']['content'];
$$("#headlines-tmp > div").each(function(row) {
c.domNode.appendChild(row);
});
console.log("restore selected ids: " + ids);
for (var i = 0; i < ids.length; i++) {
markHeadline(ids[i]);
}
initHeadlinesMenu();
/* var cache_prefix = "";
if (is_cat) {
cache_prefix = "C:";
} else {
cache_prefix = "F:";
}
cache_invalidate(cache_prefix + feed_id);
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',
"<div class='whiteBox'>" +
__('Could not update headlines (missing XML data)') + "</div>");
console.log("no new headlines received");
}
} else {
if (headlines) {
if (headlines_count > 0) {
console.log("adding some more headlines...");
var c = dijit.byId("headlines-frame");
var ids = getSelectedArticleIds2();
//c.attr('content', c.attr('content') +
// headlines_content.firstChild.nodeValue);
$("headlines-tmp").innerHTML = headlines_content.firstChild.nodeValue;
$$("#headlines-tmp > div").each(function(row) {
c.domNode.appendChild(row);
});
console.log("restore selected ids: " + ids);
for (var i = 0; i < ids.length; i++) {
markHeadline(ids[i]);
}
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");
}
}
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', "<div class='whiteBox'>" +
__('Could not update headlines (missing XML object)') + "</div>");
__('Could not update headlines (invalid object received)') + "</div>");
}
_feed_cur_page = feed_cur_page;
_infscroll_request_sent = 0;