From 003a7447c3cba9b1108b0a97d1263e7a72261f5b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 4 Dec 2017 10:26:22 +0300 Subject: [PATCH] format_headlines_list: prevent warning on first_id changed check --- classes/feeds.php | 521 +++++++++++++++++++++++----------------------- 1 file changed, 262 insertions(+), 259 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 983a8551..87830673 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -286,7 +286,7 @@ class Feeds extends Handler_Protected { if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info); - $result = $qfh_ret[0]; + $result = $qfh_ret[0]; // this could be either a PDO query result or a -1 if first id changed $feed_title = $qfh_ret[1]; $feed_site_url = $qfh_ret[2]; $last_error = $qfh_ret[3]; @@ -318,430 +318,433 @@ class Feeds extends Handler_Protected { if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info); $expand_cdm = get_pref('CDM_EXPANDED'); - while ($line = $result->fetch()) { + if (is_object($result)) { - ++$headlines_count; + while ($line = $result->fetch()) { - $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); + ++$headlines_count; - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { - $line = $p->hook_query_headlines($line, 250, false); - } + $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); - if (get_pref('SHOW_CONTENT_PREVIEW')) { - $content_preview = $line["content_preview"]; - } + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { + $line = $p->hook_query_headlines($line, 250, false); + } - $id = $line["id"]; - $feed_id = $line["feed_id"]; - $label_cache = $line["label_cache"]; - $labels = false; + if (get_pref('SHOW_CONTENT_PREVIEW')) { + $content_preview = $line["content_preview"]; + } - if ($label_cache) { - $label_cache = json_decode($label_cache, true); + $id = $line["id"]; + $feed_id = $line["feed_id"]; + $label_cache = $line["label_cache"]; + $labels = false; - if ($label_cache) { - if ($label_cache["no-labels"] == 1) - $labels = array(); - else - $labels = $label_cache; - } - } + if ($label_cache) { + $label_cache = json_decode($label_cache, true); - if (!is_array($labels)) $labels = Article::get_article_labels($id); + if ($label_cache) { + if ($label_cache["no-labels"] == 1) + $labels = array(); + else + $labels = $label_cache; + } + } - $labels_str = ""; - $labels_str .= Article::format_article_labels($labels); - $labels_str .= ""; + if (!is_array($labels)) $labels = Article::get_article_labels($id); - if (count($topmost_article_ids) < 3) { - array_push($topmost_article_ids, $id); - } + $labels_str = ""; + $labels_str .= Article::format_article_labels($labels); + $labels_str .= ""; - $class = ""; + if (count($topmost_article_ids) < 3) { + array_push($topmost_article_ids, $id); + } - if ($line["unread"]) { - $class .= " Unread"; - ++$num_unread; - } + $class = ""; - if ($line["marked"]) { - $marked_pic = "\"Unstar"; - $class .= " marked"; - } else { - $marked_pic = "\"Star"; - } + } - if ($line["published"]) { - $published_pic = "\"Unpublish"; - $class .= " published"; - } else { - $published_pic = "\"Publish"; - } + } - $updated_fmt = make_local_datetime($line["updated"], false, false, false, true); - $date_entered_fmt = T_sprintf("Imported at %s", - make_local_datetime($line["date_entered"], false)); + $updated_fmt = make_local_datetime($line["updated"], false, false, false, true); + $date_entered_fmt = T_sprintf("Imported at %s", + make_local_datetime($line["date_entered"], false)); - $score = $line["score"]; + $score = $line["score"]; - $score_pic = "images/" . get_score_pic($score); + $score_pic = "images/" . get_score_pic($score); - $score_pic = ""; - if ($score > 500) { - $hlc_suffix = "high"; - } else if ($score < -100) { - $hlc_suffix = "low"; - } else { - $hlc_suffix = ""; - } + if ($score > 500) { + $hlc_suffix = "high"; + } else if ($score < -100) { + $hlc_suffix = "low"; + } else { + $hlc_suffix = ""; + } - $entry_author = $line["author"]; + $entry_author = $line["author"]; - if ($entry_author) { - $entry_author = " — $entry_author"; - } + if ($entry_author) { + $entry_author = " — $entry_author"; + } - $has_feed_icon = feeds::feedHasIcon($feed_id); + $has_feed_icon = feeds::feedHasIcon($feed_id); - if ($has_feed_icon) { - $feed_icon_img = "\"\""; - } else { - $feed_icon_img = "\"\""; - } + if ($has_feed_icon) { + $feed_icon_img = "\"\""; + } else { + $feed_icon_img = "\"\""; + } - $entry_site_url = $line["site_url"]; + $entry_site_url = $line["site_url"]; - //setting feed headline background color, needs to change text color based on dark/light - $fav_color = $line['favicon_avg_color']; + //setting feed headline background color, needs to change text color based on dark/light + $fav_color = $line['favicon_avg_color']; - require_once "colors.php"; + require_once "colors.php"; - if ($fav_color && $fav_color != 'fail') { - if (!isset($rgba_cache[$feed_id])) { - $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color)); - } - } + if ($fav_color && $fav_color != 'fail') { + if (!isset($rgba_cache[$feed_id])) { + $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color)); + } + } - if (!get_pref('COMBINED_DISPLAY_MODE')) { + if (!get_pref('COMBINED_DISPLAY_MODE')) { - if ($vfeed_group_enabled) { - if ($feed_id != $vgroup_last_feed && $line["feed_title"]) { + if ($vfeed_group_enabled) { + if ($feed_id != $vgroup_last_feed && $line["feed_title"]) { - $vgroup_last_feed = $feed_id; + $vgroup_last_feed = $feed_id; - $vf_catchup_link = "".__('mark feed as read').""; + $vf_catchup_link = "".__('mark feed as read').""; - $reply['content'] .= "
". - "
$feed_icon_img
". - "". - $line["feed_title"]." + $reply['content'] .= "
". + "
$feed_icon_img
". + "". + $line["feed_title"]." $vf_catchup_link
"; - } - } + } + } - $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' + $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' onmouseout='postMouseOut($id)'"; - $reply['content'] .= "
"; + $reply['content'] .= "
"; - $reply['content'] .= "
"; + $reply['content'] .= "
"; - $reply['content'] .= ""; - $reply['content'] .= "$marked_pic"; - $reply['content'] .= "$published_pic"; + $reply['content'] .= "$marked_pic"; + $reply['content'] .= "$published_pic"; - $reply['content'] .= "
"; + $reply['content'] .= "
"; - $reply['content'] .= "
"; - $reply['content'] .= "" . - truncate_string($line["title"], 200); + truncate_string($line["title"], 200); - if (get_pref('SHOW_CONTENT_PREVIEW')) { - $reply['content'] .= "" . $line["content_preview"] . ""; - } + if (get_pref('SHOW_CONTENT_PREVIEW')) { + $reply['content'] .= "" . $line["content_preview"] . ""; + } - $reply['content'] .= ""; + $reply['content'] .= ""; - $reply['content'] .= $labels_str; + $reply['content'] .= $labels_str; - $reply['content'] .= "
"; + $reply['content'] .= "
"; - if (!$vfeed_group_enabled) { - if (@$line["feed_title"]) { - $rgba = @$rgba_cache[$feed_id]; + if (!$vfeed_group_enabled) { + if (@$line["feed_title"]) { + $rgba = @$rgba_cache[$feed_id]; - $reply['content'] .= "". - truncate_string($line["feed_title"],30).""; - } - } + $reply['content'] .= "". + truncate_string($line["feed_title"],30).""; + } + } - $reply['content'] .= ""; + $reply['content'] .= ""; - $reply['content'] .= "
$updated_fmt
+ $reply['content'] .= "
$updated_fmt
"; - $reply['content'] .= "
"; + $reply['content'] .= "
"; - $reply['content'] .= $score_pic; + $reply['content'] .= $score_pic; - if ($line["feed_title"] && !$vfeed_group_enabled) { + if ($line["feed_title"] && !$vfeed_group_enabled) { - $reply['content'] .= " $feed_icon_img"; - } + } - $reply['content'] .= "
"; - $reply['content'] .= "
"; + $reply['content'] .= "
"; + $reply['content'] .= "
"; - } else { + } else { - if ($line["tag_cache"]) - $tags = explode(",", $line["tag_cache"]); - else - $tags = false; + if ($line["tag_cache"]) + $tags = explode(",", $line["tag_cache"]); + else + $tags = false; - $line["content"] = sanitize($line["content"], - $line['hide_images'], false, $entry_site_url, $highlight_words, $line["id"]); + $line["content"] = sanitize($line["content"], + $line['hide_images'], false, $entry_site_url, $highlight_words, $line["id"]); - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) { - $line = $p->hook_render_article_cdm($line); - } + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) { + $line = $p->hook_render_article_cdm($line); + } - if ($vfeed_group_enabled && $line["feed_title"]) { - if ($feed_id != $vgroup_last_feed) { + if ($vfeed_group_enabled && $line["feed_title"]) { + if ($feed_id != $vgroup_last_feed) { - $vgroup_last_feed = $feed_id; + $vgroup_last_feed = $feed_id; - $vf_catchup_link = "".__('mark feed as read').""; + $vf_catchup_link = "".__('mark feed as read').""; - $feed_icon_src = Feeds::getFeedIcon($feed_id); - $feed_icon_img = ""; + $feed_icon_src = Feeds::getFeedIcon($feed_id); + $feed_icon_img = ""; - $reply['content'] .= "
". - "
$feed_icon_img
". - "". - $line["feed_title"]." $vf_catchup_link
"; + $reply['content'] .= "
". + "
$feed_icon_img
". + "". + $line["feed_title"]." $vf_catchup_link
"; - } - } + } + } - $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' + $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' onmouseout='postMouseOut($id)'"; - $expanded_class = $expand_cdm ? "expanded" : "expandable"; + $expanded_class = $expand_cdm ? "expanded" : "expandable"; - $tmp_content = "
"; - $tmp_content .= "
"; - $tmp_content .= "
"; + $tmp_content .= "
"; + $tmp_content .= "
"; - $tmp_content .= ""; - $tmp_content .= "$marked_pic"; - $tmp_content .= "$published_pic"; + $tmp_content .= "$marked_pic"; + $tmp_content .= "$published_pic"; - $tmp_content .= "
"; + $tmp_content .= "
"; - if ($highlight_words && count($highlight_words) > 0) { - foreach ($highlight_words as $word) { - $line["title"] = preg_replace("/(\Q$word\E)/i", - "$1", $line["title"]); - } - } + if ($highlight_words && count($highlight_words) > 0) { + foreach ($highlight_words as $word) { + $line["title"] = preg_replace("/(\Q$word\E)/i", + "$1", $line["title"]); + } + } - // data-article-id included for context menu - $tmp_content .= " ". - $line["title"] . - " $entry_author"; + htmlspecialchars($line["link"])."\">". + $line["title"] . + " $entry_author"; - $tmp_content .= $labels_str; + $tmp_content .= $labels_str; - $tmp_content .= ""; + $tmp_content .= ""; - if (!$vfeed_group_enabled) { - if (@$line["feed_title"]) { - $rgba = @$rgba_cache[$feed_id]; + if (!$vfeed_group_enabled) { + if (@$line["feed_title"]) { + $rgba = @$rgba_cache[$feed_id]; - $tmp_content .= "
+ $tmp_content .= "
". - truncate_string($line["feed_title"],30)." + truncate_string($line["feed_title"],30)."
"; - } - } + } + } - $tmp_content .= "$updated_fmt"; + $tmp_content .= "$updated_fmt"; - $tmp_content .= "
"; - $tmp_content .= "$score_pic"; + $tmp_content .= "
"; + $tmp_content .= "$score_pic"; - if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) { - $tmp_content .= "$feed_icon_img"; - } - $tmp_content .= "
"; //scoreWrap + } + $tmp_content .= "
"; //scoreWrap - $tmp_content .= "
"; //cdmHeader + $tmp_content .= "
"; //cdmHeader - $tmp_content .= "
"; - $tmp_content .= "
"; - if ($line['note']) { - $tmp_content .= Article::format_article_note($id, $line['note']); - } - $tmp_content .= "
"; //POSTNOTE + $tmp_content .= "
"; + if ($line['note']) { + $tmp_content .= Article::format_article_note($id, $line['note']); + } + $tmp_content .= "
"; //POSTNOTE - if (!$line['lang']) $line['lang'] = 'en'; + if (!$line['lang']) $line['lang'] = 'en'; - $tmp_content .= "
"; + $tmp_content .= "
"; - if ($line["orig_feed_id"]) { + if ($line["orig_feed_id"]) { - $ofgh = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds + $ofgh = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds WHERE id = ? AND owner_uid = ?"); - $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]); + $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]); - if ($tmp_line = $ofgh->fetch()) { + if ($tmp_line = $ofgh->fetch()) { - $tmp_content .= "
"; - $tmp_content .= __("Originally from:"); + $tmp_content .= "
"; + $tmp_content .= __("Originally from:"); - $tmp_content .= " "; + $tmp_content .= " "; - $tmp_content .= "" . - $tmp_line['title'] . ""; + $tmp_line['title'] . ""; - $tmp_content .= " "; + $tmp_content .= " "; - $tmp_content .= ""; - $tmp_content .= ""; + $tmp_content .= ""; + $tmp_content .= ""; - $tmp_content .= "
"; - } - } + $tmp_content .= "
"; + } + } - $tmp_content .= ""; - $tmp_content .= ""; - $tmp_content .= htmlspecialchars($line["content"]); - $tmp_content .= ""; - $tmp_content .= ""; + $tmp_content .= ""; + $tmp_content .= ""; + $tmp_content .= htmlspecialchars($line["content"]); + $tmp_content .= ""; + $tmp_content .= ""; - $tmp_content .= "
"; //cdmContentInner + $tmp_content .= "
"; //cdmContentInner - $tmp_content .= "
"; + $tmp_content .= "
"; - $always_display_enclosures = $line["always_display_enclosures"]; - $tmp_content .= Article::format_article_enclosures($id, $always_display_enclosures, - $line["content"], $line["hide_images"]); + $always_display_enclosures = $line["always_display_enclosures"]; + $tmp_content .= Article::format_article_enclosures($id, $always_display_enclosures, + $line["content"], $line["hide_images"]); - $tmp_content .= "
"; // cdmIntermediate + $tmp_content .= "
"; // cdmIntermediate - $tmp_content .= "
"; + $tmp_content .= "
"; - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { - $tmp_content .= $p->hook_article_left_button($line); - } + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { + $tmp_content .= $p->hook_article_left_button($line); + } - $tags_str = Article::format_tags_string($tags, $id); + $tags_str = Article::format_tags_string($tags, $id); - $tmp_content .= ""; + $tmp_content .= ""; - $tmp_content .= "Tags + $tmp_content .= "Tags $tags_str (+)"; - $num_comments = (int) $line["num_comments"]; - $entry_comments = ""; + $num_comments = (int) $line["num_comments"]; + $entry_comments = ""; - if ($num_comments > 0) { - if ($line["comments"]) { - $comments_url = htmlspecialchars($line["comments"]); - } else { - $comments_url = htmlspecialchars($line["link"]); - } - $entry_comments = " 0) { + if ($line["comments"]) { + $comments_url = htmlspecialchars($line["comments"]); + } else { + $comments_url = htmlspecialchars($line["link"]); + } + $entry_comments = "$num_comments ". - _ngettext("comment", "comments", $num_comments).""; + _ngettext("comment", "comments", $num_comments).""; - } else { - if ($line["comments"] && $line["link"] != $line["comments"]) { - $entry_comments = "".__("comments").""; - } - } + } else { + if ($line["comments"] && $line["link"] != $line["comments"]) { + $entry_comments = "".__("comments").""; + } + } - if ($entry_comments) $tmp_content .= " ($entry_comments)"; + if ($entry_comments) $tmp_content .= " ($entry_comments)"; - $tmp_content .= ""; - $tmp_content .= "
"; + $tmp_content .= ""; + $tmp_content .= "
"; - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) { - $tmp_content .= $p->hook_article_button($line); - } + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) { + $tmp_content .= $p->hook_article_button($line); + } - $tmp_content .= "
"; // buttons + $tmp_content .= "
"; // buttons - $tmp_content .= "
"; // cdmFooter - $tmp_content .= "
"; // cdmContent - $tmp_content .= "
"; // RROW.cdm + $tmp_content .= "
"; // cdmFooter + $tmp_content .= "
"; // cdmContent + $tmp_content .= ""; // RROW.cdm - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE_CDM) as $p) { - $tmp_content = $p->hook_format_article_cdm($tmp_content, $line); - } + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE_CDM) as $p) { + $tmp_content = $p->hook_format_article_cdm($tmp_content, $line); + } - $reply['content'] .= $tmp_content; - } + $reply['content'] .= $tmp_content; + } - ++$lnum; + ++$lnum; + } } if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);