From bd202c3f89af2d0b2d073841408212541d8031df Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 18 Mar 2011 12:55:45 +0300 Subject: backend/viewfeed: use JSON --- functions.php | 404 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 199 insertions(+), 205 deletions(-) (limited to 'functions.php') diff --git a/functions.php b/functions.php index 3f1d72f97..b0c768ff8 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) { -- cgit v1.2.3-54-g00ecf