diff options
Diffstat (limited to 'classes/feeds.php')
-rwxr-xr-x | classes/feeds.php | 124 |
1 files changed, 74 insertions, 50 deletions
diff --git a/classes/feeds.php b/classes/feeds.php index ba2719f48..583cb3e12 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -108,7 +108,7 @@ class Feeds extends Handler_Protected { $this->_mark_timestamp("db query"); - $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && + $vfeed_group_enabled = get_pref(Prefs::VFEED_GROUP_BY_FEED) && !(in_array($feed, self::NEVER_GROUP_FEEDS) && !$cat_view); $result = $qfh_ret[0]; // this could be either a PDO query result or a -1 if first id changed @@ -167,7 +167,7 @@ class Feeds extends Handler_Protected { ++$headlines_count; - if (!get_pref('SHOW_CONTENT_PREVIEW')) { + if (!get_pref(Prefs::SHOW_CONTENT_PREVIEW)) { $line["content_preview"] = ""; } else { $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); @@ -208,15 +208,19 @@ class Feeds extends Handler_Protected { if ($label_cache) { if ($label_cache["no-labels"] ?? false == 1) - $labels = array(); + $labels = []; else $labels = $label_cache; } + + $line["labels"] = $labels; + } else { + $line["labels"] = []; } - if (!is_array($labels)) $labels = Article::_get_labels($id); + /*if (!is_array($labels)) $labels = Article::_get_labels($id); - $line["labels"] = Article::_get_labels($id); + $line["labels"] = Article::_get_labels($id);*/ if (count($topmost_article_ids) < 3) { array_push($topmost_article_ids, $id); @@ -262,22 +266,26 @@ class Feeds extends Handler_Protected { $this->_mark_timestamp(" note"); - if (!get_pref("CDM_EXPANDED")) { + if (!get_pref(Prefs::CDM_EXPANDED)) { $line["cdm_excerpt"] = "<span class='collapse'> <i class='material-icons' onclick='return Article.cdmUnsetActive(event)' title=\"" . __("Collapse article") . "\">remove_circle</i></span>"; - if (get_pref('SHOW_CONTENT_PREVIEW')) { + if (get_pref(Prefs::SHOW_CONTENT_PREVIEW)) { $line["cdm_excerpt"] .= "<span class='excerpt'>" . $line["content_preview"] . "</span>"; } } $this->_mark_timestamp(" pre-enclosures"); - $line["enclosures"] = Article::_format_enclosures($id, - $line["always_display_enclosures"], - $line["content"], - $line["hide_images"]); + if ($line["num_enclosures"] > 0) { + $line["enclosures"] = Article::_format_enclosures($id, + $line["always_display_enclosures"], + $line["content"], + $line["hide_images"]); + } else { + $line["enclosures"] = [ 'formatted' => '', 'entries' => [] ]; + } $this->_mark_timestamp(" enclosures"); @@ -292,9 +300,11 @@ class Feeds extends Handler_Protected { if ($line["tag_cache"]) $tags = explode(",", $line["tag_cache"]); else - $tags = false; + $tags = []; - $line["tags"] = Article::_get_tags($line["id"], false, $line["tag_cache"]); + $line["tags"] = $tags; + + //$line["tags"] = Article::_get_tags($line["id"], false, $line["tag_cache"]); $this->_mark_timestamp(" tags"); @@ -324,7 +334,7 @@ class Feeds extends Handler_Protected { /* we don't need those */ foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color", - "uuid", "label_cache", "yyiw"] as $k) + "uuid", "label_cache", "yyiw", "num_enclosures"] as $k) unset($line[$k]); array_push($reply['content'], $line); @@ -413,7 +423,7 @@ class Feeds extends Handler_Protected { $feed = $_REQUEST["feed"]; $method = $_REQUEST["m"] ?? ""; - $view_mode = $_REQUEST["view_mode"]; + $view_mode = $_REQUEST["view_mode"] ?? ""; $limit = 30; $cat_view = $_REQUEST["cat"] == "true"; $next_unread_feed = $_REQUEST["nuf"] ?? 0; @@ -459,8 +469,8 @@ class Feeds extends Handler_Protected { return; } - set_pref("_DEFAULT_VIEW_MODE", $view_mode); - set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by); + set_pref(Prefs::_DEFAULT_VIEW_MODE, $view_mode); + set_pref(Prefs::_DEFAULT_VIEW_ORDER_BY, $order_by); /* bump login timestamp if needed */ if (time() - $_SESSION["last_login_update"] > 3600) { @@ -499,7 +509,7 @@ class Feeds extends Handler_Protected { "disable_cache" => (bool) $disable_cache]; // this is parsed by handleRpcJson() on first viewfeed() to set cdm expanded, etc - $reply['runtime-info'] = RPC::make_runtime_info(); + $reply['runtime-info'] = RPC::_make_runtime_info(); print json_encode($reply); } @@ -573,7 +583,7 @@ class Feeds extends Handler_Protected { "show_language" => Config::get(Config::DB_TYPE) == "pgsql", "show_syntax_help" => count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0, "all_languages" => Pref_Feeds::get_ts_languages(), - "default_language" => get_pref('DEFAULT_SEARCH_LANGUAGE') + "default_language" => get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE) ]); } @@ -799,7 +809,7 @@ class Feeds extends Handler_Protected { if ($feed == -3) { - $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE"); + $intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE); if (Config::get(Config::DB_TYPE) == "pgsql") { $match_part = "date_entered > NOW() - INTERVAL '$intl hour' "; @@ -892,7 +902,7 @@ class Feeds extends Handler_Protected { } else if ($n_feed == -3) { $match_part = "unread = true AND score >= 0"; - $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); + $intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid); if (Config::get(Config::DB_TYPE) == "pgsql") { $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; @@ -1478,7 +1488,7 @@ class Feeds extends Handler_Protected { } else if ($feed == -3) { // fresh virtual feed $query_strategy_part = "unread = true AND score >= 0"; - $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); + $intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid); if (Config::get(Config::DB_TYPE) == "pgsql") { $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; @@ -1564,9 +1574,15 @@ class Feeds extends Handler_Protected { $first_id = 0; + if (Config::get(Config::DB_TYPE) == "pgsql") { + $yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw"; + } else { + $yyiw_qpart = "date_format(date_entered, '%Y-%u') AS yyiw"; + } + if (is_numeric($feed)) { // proper override_order applied above - if ($vfeed_query_part && !$ignore_vfeed_group && get_pref('VFEED_GROUP_BY_FEED', $owner_uid)) { + if ($vfeed_query_part && !$ignore_vfeed_group && get_pref(Prefs::VFEED_GROUP_BY_FEED, $owner_uid)) { if (!(in_array($feed, self::NEVER_GROUP_BY_DATE) && !$cat_view)) { $yyiw_desc = $order_by == "date_reverse" ? "" : "desc"; @@ -1583,7 +1599,7 @@ class Feeds extends Handler_Protected { } if (!$allow_archived) { - $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id),ttrss_feeds"; + $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id), ttrss_feeds"; $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND"; } else { @@ -1601,16 +1617,19 @@ class Feeds extends Handler_Protected { if (Config::get(Config::DB_TYPE) == "pgsql") { $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND"; - $yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw"; $distinct_columns = str_replace("desc", "", strtolower($order_by)); $distinct_qpart = "DISTINCT ON (id, $distinct_columns)"; } else { $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND"; - $yyiw_qpart = "date_format(date_entered, '%Y-%u') AS yyiw"; $distinct_qpart = "DISTINCT"; //fallback } + // except for Labels category + if (get_pref(Prefs::HEADLINES_NO_DISTINCT, $owner_uid) && !($feed == -2 && $cat_view)) { + $distinct_qpart = ""; + } + if (!$search && !$skip_first_id_check) { // if previous topmost article id changed that means our current pagination is no longer valid $query = "SELECT @@ -1675,7 +1694,8 @@ class Feeds extends Handler_Protected { last_marked, last_published, $vfeed_query_part $content_query_part - author,score + author,score, + (SELECT count(id) FROM ttrss_enclosures WHERE post_id = ttrss_entries.id) AS num_enclosures FROM $from_qpart WHERE @@ -1699,41 +1719,45 @@ class Feeds extends Handler_Protected { } else { // browsing by tag - if (Config::get(Config::DB_TYPE) == "pgsql") { - $distinct_columns = str_replace("desc", "", strtolower($order_by)); - $distinct_qpart = "DISTINCT ON (id, $distinct_columns)"; + if (get_pref(Prefs::HEADLINES_NO_DISTINCT, $owner_uid)) { + $distinct_qpart = ""; } else { - $distinct_qpart = "DISTINCT"; //fallback + if (Config::get(Config::DB_TYPE) == "pgsql") { + $distinct_columns = str_replace("desc", "", strtolower($order_by)); + $distinct_qpart = "DISTINCT ON (id, $distinct_columns)"; + } else { + $distinct_qpart = "DISTINCT"; //fallback + } } $query = "SELECT $distinct_qpart + ttrss_entries.id AS id, date_entered, + $yyiw_qpart, guid, - note, - ttrss_entries.id as id, - title, + ttrss_entries.title, updated, - unread, - feed_id, - marked, - published, + label_cache, + tag_cache, + always_display_enclosures, + site_url, + note, num_comments, comments, int_id, - tag_cache, - label_cache, - link, - lang, uuid, - last_read, - (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images, + lang, + hide_images, + unread,feed_id,marked,published,link,last_read, last_marked, last_published, $since_id_part $vfeed_query_part $content_query_part - author, score - FROM ttrss_entries, ttrss_user_entries, ttrss_tags + author, score, + (SELECT count(id) FROM ttrss_enclosures WHERE post_id = ttrss_entries.id) AS num_enclosures + FROM ttrss_entries, ttrss_user_entries, ttrss_tags, ttrss_feeds WHERE + ttrss_feeds.id = ttrss_user_entries.feed_id AND ref_id = ttrss_entries.id AND ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND post_int_id = int_id AND @@ -1975,7 +1999,7 @@ class Feeds extends Handler_Protected { $purge_unread = true; $purge_interval = Config::get(Config::FORCE_ARTICLE_PURGE); } else { - $purge_unread = get_pref("PURGE_UNREAD_ARTICLES", $owner_uid, false); + $purge_unread = get_pref(Prefs::PURGE_UNREAD_ARTICLES, $owner_uid); } $purge_interval = (int) $purge_interval; @@ -2038,7 +2062,7 @@ class Feeds extends Handler_Protected { $owner_uid = $row["owner_uid"]; if ($purge_interval == 0) - $purge_interval = get_pref('PURGE_OLD_DAYS', $owner_uid, false); + $purge_interval = get_pref(Prefs::PURGE_OLD_DAYS, $owner_uid); return $purge_interval; } else { @@ -2058,7 +2082,7 @@ class Feeds extends Handler_Protected { if ($search_language) $search_language = $pdo->quote(mb_strtolower($search_language)); else - $search_language = $pdo->quote(mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid))); + $search_language = $pdo->quote(mb_strtolower(get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE, $owner_uid))); foreach ($keywords as $k) { if (strpos($k, "-") === 0) { @@ -2166,7 +2190,7 @@ class Feeds extends Handler_Protected { default: if (strpos($k, "@") === 0) { - $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']); + $user_tz_string = get_pref(Prefs::USER_TIMEZONE, $_SESSION['uid']); $orig_ts = strtotime(substr($k, 1)); $k = date("Y-m-d", TimeHelper::convert_timestamp($orig_ts, $user_tz_string, 'UTC')); |