diff options
Diffstat (limited to 'classes/feeds.php')
-rwxr-xr-x | classes/feeds.php | 111 |
1 files changed, 69 insertions, 42 deletions
diff --git a/classes/feeds.php b/classes/feeds.php index a06486883..de2f750cd 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -122,7 +122,7 @@ class Feeds extends Handler_Protected { $feed_title = $qfh_ret[1]; $feed_site_url = $qfh_ret[2]; $last_error = $qfh_ret[3]; - $last_updated = strpos($qfh_ret[4], '1970-') === false ? + $last_updated = strpos($qfh_ret[4] ?? "", '1970-') === false ? TimeHelper::make_local_datetime($qfh_ret[4], false) : __("Never"); $highlight_words = $qfh_ret[5]; $reply['first_id'] = $qfh_ret[6]; @@ -248,11 +248,12 @@ class Feeds extends Handler_Protected { function ($result, $plugin) use (&$line, &$button_doc) { if ($result && $button_doc->loadXML($result)) { - /** @var DOMElement|null */ + /** @var DOMElement|null $child */ $child = $button_doc->firstChild; if ($child) { do { + /** @var DOMElement|null $child */ $child->setAttribute('data-plugin-name', get_class($plugin)); } while ($child = $child->nextSibling); @@ -271,11 +272,12 @@ class Feeds extends Handler_Protected { function ($result, $plugin) use (&$line, &$button_doc) { if ($result && $button_doc->loadXML($result)) { - /** @var DOMElement|null */ + /** @var DOMElement|null $child */ $child = $button_doc->firstChild; if ($child) { do { + /** @var DOMElement|null $child */ $child->setAttribute('data-plugin-name', get_class($plugin)); } while ($child = $child->nextSibling); @@ -429,12 +431,11 @@ class Feeds extends Handler_Protected { $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors - FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); - $sth->execute([$_SESSION['uid']]); - $row = $sth->fetch(); - - $num_errors = $row["num_errors"]; + $num_errors = ORM::for_table('ttrss_feeds') + ->where_not_equal('last_error', '') + ->where('owner_uid', $_SESSION['uid']) + ->where_gte('update_interval', 0) + ->count('id'); if ($num_errors > 0) { $reply['content'] .= "<br/>"; @@ -583,12 +584,11 @@ class Feeds extends Handler_Protected { $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors - FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); - $sth->execute([$_SESSION['uid']]); - $row = $sth->fetch(); - - $num_errors = $row["num_errors"]; + $num_errors = ORM::for_table('ttrss_feeds') + ->where_not_equal('last_error', '') + ->where('owner_uid', $_SESSION['uid']) + ->where_gte('update_interval', 0) + ->count('id'); if ($num_errors > 0) { $reply['headlines']['content'] .= "<br/>"; @@ -665,7 +665,7 @@ class Feeds extends Handler_Protected { } Debug::set_enabled(true); - Debug::set_loglevel($xdebug); + Debug::set_loglevel((int)Debug::map_loglevel($xdebug)); $feed_id = (int)$_REQUEST["feed_id"]; $do_update = ($_REQUEST["action"] ?? "") == "do_update"; @@ -963,6 +963,15 @@ class Feeds extends Handler_Protected { if ($is_cat) { return self::_get_cat_unread($n_feed, $owner_uid); + } else if(is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { // virtual Feed + $feed_id = PluginHost::feed_to_pfeed_id($feed); + $handler = PluginHost::getInstance()->get_feed_handler($feed_id); + if (implements_interface($handler, 'IVirtualFeed')) { + /** @var IVirtualFeed $handler */ + return $handler->get_unread($feed_id); + } else { + return 0; + } } else if ($n_feed == -6) { return 0; // tags @@ -1152,11 +1161,28 @@ class Feeds extends Handler_Protected { } static function _get_icon_file(int $feed_id): string { - return Config::get(Config::ICONS_DIR) . "/$feed_id.ico"; + $favicon_cache = DiskCache::instance('feed-icons'); + + return $favicon_cache->get_full_path((string)$feed_id); + } + + static function _get_icon_url(int $feed_id, string $fallback_url = "") : string { + if (self::_has_icon($feed_id)) { + $icon_url = Config::get_self_url() . "/public.php?" . http_build_query([ + 'op' => 'feed_icon', + 'id' => $feed_id, + ]); + + return $icon_url; + } + + return $fallback_url; } - static function _has_icon(int $id): bool { - return is_file(Config::get(Config::ICONS_DIR) . "/$id.ico") && filesize(Config::get(Config::ICONS_DIR) . "/$id.ico") > 0; + static function _has_icon(int $feed_id): bool { + $favicon_cache = DiskCache::instance('feed-icons'); + + return $favicon_cache->exists((string)$feed_id); } /** @@ -1180,16 +1206,9 @@ class Feeds extends Handler_Protected { if ($id < LABEL_BASE_INDEX) { return "label"; } else { - $icon = self::_get_icon_file($id); - - if ($icon && file_exists($icon)) { - return Config::get(Config::ICONS_URL) . "/" . basename($icon) . "?" . filemtime($icon); - } + return self::_get_icon_url($id); } - break; } - - return false; } /** @@ -1738,11 +1757,11 @@ 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 { - $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id) + $from_qpart = "{$ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id) LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)"; $feed_check_qpart = ""; } @@ -1936,8 +1955,8 @@ class Feeds extends Handler_Protected { $sth->execute([$cat, $owner_uid]); while ($line = $sth->fetch()) { - array_push($rv, (int)$line["parent_cat"]); - $rv = array_merge($rv, self::_get_parent_cats($line["parent_cat"], $owner_uid)); + $cat = (int) $line["parent_cat"]; + array_push($rv, $cat, ...self::_get_parent_cats($cat, $owner_uid)); } return $rv; @@ -1956,8 +1975,7 @@ class Feeds extends Handler_Protected { $sth->execute([$cat, $owner_uid]); while ($line = $sth->fetch()) { - array_push($rv, $line["id"]); - $rv = array_merge($rv, self::_get_child_cats($line["id"], $owner_uid)); + array_push($rv, $line["id"], ...self::_get_child_cats($line["id"], $owner_uid)); } return $rv; @@ -1978,16 +1996,18 @@ class Feeds extends Handler_Protected { $sth = $pdo->prepare("SELECT DISTINCT cat_id, fc.parent_cat FROM ttrss_feeds f LEFT JOIN ttrss_feed_categories fc ON (fc.id = f.cat_id) WHERE f.owner_uid = ? AND f.id IN ($feeds_qmarks)"); - $sth->execute(array_merge([$owner_uid], $feeds)); + $sth->execute([$owner_uid, ...$feeds]); $rv = []; if ($row = $sth->fetch()) { + $cat_id = (int) $row["cat_id"]; + $rv[] = $cat_id; array_push($rv, (int)$row["cat_id"]); - if ($with_parents && $row["parent_cat"]) - $rv = array_merge($rv, - self::_get_parent_cats($row["cat_id"], $owner_uid)); + if ($with_parents && $row["parent_cat"]) { + array_push($rv, ...self::_get_parent_cats($cat_id, $owner_uid)); + } } $rv = array_unique($rv); @@ -2226,7 +2246,7 @@ class Feeds extends Handler_Protected { * @return array{0: string, 1: array<int, string>} [$search_query_part, $search_words] */ private static function _search_to_sql(string $search, string $search_language, int $owner_uid): array { - $keywords = str_getcsv(preg_replace('/(-?\w+)\:"(\w+)/', '"${1}:${2}', trim($search)), ' '); + $keywords = str_getcsv(preg_replace('/(-?\w+)\:"(\w+)/', '"{$1}:{$2}', trim($search)), ' '); $query_keywords = array(); $search_words = array(); $search_query_leftover = array(); @@ -2357,8 +2377,11 @@ class Feeds extends Handler_Protected { $k = mb_strtolower($k); array_push($search_query_leftover, $not ? "!$k" : $k); } else { - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") - OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); + $k = mb_strtolower($k); + array_push($search_query_leftover, $not ? "-$k" : $k); + + //array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") + // OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); } if (!$not) array_push($search_words, $k); @@ -2380,12 +2403,16 @@ class Feeds extends Handler_Protected { array_push($query_keywords, "(tsvector_combined @@ to_tsquery($search_language, $tsquery))"); - } + } else { + $ft_query = $pdo->quote(implode(" ", $search_query_leftover)); + array_push($query_keywords, + "MATCH (ttrss_entries.title, ttrss_entries.content) AGAINST ($ft_query IN BOOLEAN MODE)"); + } } if (count($query_keywords) > 0) - $search_query_part = implode("AND", $query_keywords); + $search_query_part = implode("AND ", $query_keywords); else $search_query_part = "false"; |