diff --git a/classes/api.php b/classes/api.php index 7759b43bf..fd2573033 100755 --- a/classes/api.php +++ b/classes/api.php @@ -106,7 +106,7 @@ class API extends Handler { $is_cat = self::_param_to_bool($_REQUEST["is_cat"] ?? false); if ($feed_id) { - return $this->_wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat))); + return $this->_wrap(self::STATUS_OK, array("unread" => Feeds::_get_counters($feed_id, $is_cat))); } else { return $this->_wrap(self::STATUS_OK, array("unread" => Feeds::_get_global_unread())); } @@ -152,7 +152,7 @@ class API extends Handler { foreach ($categories->find_many() as $category) { if ($include_empty || $category->num_feeds > 0 || $category->num_cats > 0) { - $unread = getFeedUnread($category->id, true); + $unread = Feeds::_get_counters($category->id, true); if ($enable_nested) $unread += Feeds::_get_cat_children_unread($category->id); @@ -170,7 +170,7 @@ class API extends Handler { foreach ([-2,-1,0] as $cat_id) { if ($include_empty || !$this->_is_cat_empty($cat_id)) { - $unread = getFeedUnread($cat_id, true); + $unread = Feeds::_get_counters($cat_id, true); if ($unread || !$unread_only) { array_push($cats, [ @@ -546,7 +546,7 @@ class API extends Handler { if ($cat_id == -4 || $cat_id == -1) { foreach ([-1, -2, -3, -4, -6, 0] as $i) { - $unread = getFeedUnread($i); + $unread = Feeds::_get_counters($i); if ($unread || !$unread_only) { $title = Feeds::_get_title($i); @@ -573,7 +573,7 @@ class API extends Handler { ->find_many(); foreach ($categories as $category) { - $unread = getFeedUnread($category->id, true) + + $unread = Feeds::_get_counters($category->id, true) + Feeds::_get_cat_children_unread($category->id); if ($unread || !$unread_only) { @@ -607,7 +607,7 @@ class API extends Handler { } foreach ($feeds_obj->find_many() as $feed) { - $unread = getFeedUnread($feed->id); + $unread = Feeds::_get_counters($feed->id); $has_icon = Feeds::_has_icon($feed->id); if ($unread || !$unread_only) { diff --git a/classes/counters.php b/classes/counters.php index c42e938f8..0814bc441 100644 --- a/classes/counters.php +++ b/classes/counters.php @@ -250,7 +250,7 @@ class Counters { for ($i = 0; $i >= -4; $i--) { - $count = getFeedUnread($i); + $count = Feeds::_get_counters($i); if ($i == 0 || $i == -1 || $i == -2) $auxctr = Feeds::_get_counters($i, false); diff --git a/classes/feeds.php b/classes/feeds.php index cc78b498c..4f30ad746 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -936,7 +936,15 @@ class Feeds extends Handler_Protected { } } - static function _get_counters(int $feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int { + /** + * @param int|string $feed feed id or tag name + * @param bool $is_cat + * @param bool $unread_only + * @param null|int $owner_uid + * @return int + * @throws PDOException + */ + static function _get_counters($feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int { $n_feed = (int) $feed; $need_entries = false; @@ -957,6 +965,7 @@ class Feeds extends Handler_Protected { return self::_get_cat_unread($n_feed, $owner_uid); } else if ($n_feed == -6) { return 0; + // tags } else if ($feed != "0" && $n_feed == 0) { $sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id) @@ -1498,7 +1507,7 @@ class Feeds extends Handler_Protected { $view_query_part = " "; } else if ($feed != -1) { - $unread = getFeedUnread($feed, $cat_view); + $unread = Feeds::_get_counters($feed, $cat_view); if ($cat_view && $feed > 0 && $include_children) $unread += self::_get_cat_children_unread($feed); diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index d2a30662b..f5b6333a6 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1111,7 +1111,7 @@ class Pref_Feeds extends Handler_Protected { $title = Feeds::_get_title($feed_id, false); if ($unread === false) - $unread = getFeedUnread($feed_id, false); + $unread = Feeds::_get_counters($feed_id, false); return [ 'id' => 'FEED:' . $feed_id, diff --git a/include/functions.php b/include/functions.php index f4a218ce3..91fb62ec5 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2,7 +2,7 @@ define('LABEL_BASE_INDEX', -1024); define('PLUGIN_FEED_BASE_INDEX', -128); - /** constant is @deprecated, use Config::SCHEMA_VERSION instead */ + /** @deprecated by Config::SCHEMA_VERSION */ define('SCHEMA_VERSION', Config::SCHEMA_VERSION); if (version_compare(PHP_VERSION, '8.0.0', '<')) { @@ -179,18 +179,24 @@ return Config::get_version(); } - /** function is @deprecated by Config::get_schema_version() */ + /** @deprecated by Config::get_schema_version() */ function get_schema_version(): int { return Config::get_schema_version(); } - /** function is @deprecated by Debug::log() */ + /** @deprecated by Debug::log() */ function _debug(string $msg): void { Debug::log($msg); } - /** function is @deprecated */ - function getFeedUnread(int $feed, bool $is_cat = false): int { + + /** @deprecated by Feeds::_get_counters() + * @param int|string $feed feed id or tag name + * @param bool $is_cat + * @return int + * @throws PDOException + */ + function getFeedUnread($feed, bool $is_cat = false): int { return Feeds::_get_counters($feed, $is_cat, true, $_SESSION["uid"]); } @@ -239,23 +245,23 @@ return UrlHelper::validate($url); } - /** function is @deprecated by UserHelper::authenticate() */ + /** @deprecated by UserHelper::authenticate() */ function authenticate_user(string $login = null, string $password = null, bool $check_only = false, string $service = null): bool { return UserHelper::authenticate($login, $password, $check_only, $service); } - /** function is @deprecated by TimeHelper::smart_date_time() */ + /** @deprecated by TimeHelper::smart_date_time() */ function smart_date_time(int $timestamp, int $tz_offset = 0, int $owner_uid = null, bool $eta_min = false): string { return TimeHelper::smart_date_time($timestamp, $tz_offset, $owner_uid, $eta_min); } - /** function is @deprecated by TimeHelper::make_local_datetime() */ + /** @deprecated by TimeHelper::make_local_datetime() */ function make_local_datetime(string $timestamp, bool $long, int $owner_uid = null, bool $no_smart_dt = false, bool $eta_min = false): string { return TimeHelper::make_local_datetime($timestamp, $long, $owner_uid, $no_smart_dt, $eta_min); } // this returns Config::SELF_URL_PATH sans ending slash - /** function is @deprecated by Config::get_self_url() */ + /** @deprecated by Config::get_self_url() */ function get_self_url_prefix(): string { return Config::get_self_url(); }