From 897e4a3f4a273d50c28157edb67612b2d7fa2e6f Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 27 Dec 2024 12:03:59 +0100 Subject: Search in all feeds (#7144) * Search in all feeds Search in PRIORITY_ARCHIVED with `&get=A` fix https://github.com/FreshRSS/FreshRSS/discussions/7143 * Fix type * Search in PRIORITY_ARCHIVED with `&get=Z` * More * Fixes * One more fix * Extra features in user queries * Move i18n key * Fix overview * Enlarge query boxes * Revert i18n spelling * i18n: it Thanks @UserRoot-Luca Co-authored-by: UserRoot-Luca <55756898+UserRoot-Luca@users.noreply.github.com> --------- Co-authored-by: UserRoot-Luca <55756898+UserRoot-Luca@users.noreply.github.com> --- app/Models/Context.php | 36 +++++++++++++++++++++++++++++++----- app/Models/EntryDAO.php | 19 +++++++++++-------- app/Models/UserQuery.php | 10 ++++++++-- 3 files changed, 50 insertions(+), 15 deletions(-) (limited to 'app/Models') diff --git a/app/Models/Context.php b/app/Models/Context.php index eeb16f414..6cdda909c 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -20,7 +20,7 @@ final class FreshRSS_Context { public static int $total_unread = 0; public static int $total_important_unread = 0; - /** @var array{'all':int,'read':int,'unread':int} */ + /** @var array{all:int,read:int,unread:int} */ public static array $total_starred = [ 'all' => 0, 'read' => 0, @@ -29,15 +29,17 @@ final class FreshRSS_Context { public static int $get_unread = 0; - /** @var array{'all':bool,'starred':bool,'important':bool,'feed':int|false,'category':int|false,'tag':int|false,'tags':bool} */ + /** @var array{all:bool,A:bool,starred:bool,important:bool,feed:int|false,category:int|false,tag:int|false,tags:bool,Z:bool} */ public static array $current_get = [ 'all' => false, + 'A' => false, 'starred' => false, 'important' => false, 'feed' => false, 'category' => false, 'tag' => false, 'tags' => false, + 'Z' => false, ]; public static string $next_get = 'a'; @@ -271,12 +273,14 @@ final class FreshRSS_Context { * Return the current get as a string or an array. * * If $array is true, the first item of the returned value is 'f' or 'c' or 't' and the second is the id. - * @phpstan-return ($asArray is true ? array{'a'|'c'|'f'|'i'|'s'|'t'|'T',bool|int} : string) + * @phpstan-return ($asArray is true ? array{'a'|'A'|'c'|'f'|'i'|'s'|'t'|'T'|'Z',bool|int} : string) * @return string|array{string,bool|int} */ public static function currentGet(bool $asArray = false): string|array { if (self::$current_get['all']) { return $asArray ? ['a', true] : 'a'; + } elseif (self::$current_get['A']) { + return $asArray ? ['A', true] : 'A'; } elseif (self::$current_get['important']) { return $asArray ? ['i', true] : 'i'; } elseif (self::$current_get['starred']) { @@ -301,6 +305,8 @@ final class FreshRSS_Context { } } elseif (self::$current_get['tags']) { return $asArray ? ['T', true] : 'T'; + } elseif (self::$current_get['Z']) { + return $asArray ? ['Z', true] : 'Z'; } return ''; } @@ -312,6 +318,14 @@ final class FreshRSS_Context { return self::$current_get['all'] != false; } + public static function isAllAndCategories(): bool { + return self::$current_get['A'] != false; + } + + public static function isAllAndArchived(): bool { + return self::$current_get['Z'] != false; + } + /** * @return bool true if the current request targets important feeds, false otherwise. */ @@ -349,12 +363,14 @@ final class FreshRSS_Context { return match ($type) { 'a' => self::$current_get['all'], + 'A' => self::$current_get['A'], 'i' => self::$current_get['important'], 's' => self::$current_get['starred'], 'f' => self::$current_get['feed'] == $id, 'c' => self::$current_get['category'] == $id, 't' => self::$current_get['tag'] == $id, 'T' => self::$current_get['tags'] || self::$current_get['tag'], + 'Z' => self::$current_get['Z'], default => false, }; } @@ -386,13 +402,23 @@ final class FreshRSS_Context { } switch ($type) { - case 'a': + case 'a': // All PRIORITY_MAIN_STREAM self::$current_get['all'] = true; + self::$description = FreshRSS_Context::systemConf()->meta_description; + self::$get_unread = self::$total_unread; + break; + case 'A': // All except PRIORITY_ARCHIVED + self::$current_get['A'] = true; + self::$description = FreshRSS_Context::systemConf()->meta_description; + self::$get_unread = self::$total_unread; + break; + case 'Z': // All including PRIORITY_ARCHIVED + self::$current_get['Z'] = true; self::$name = _t('index.feed.title'); self::$description = FreshRSS_Context::systemConf()->meta_description; self::$get_unread = self::$total_unread; break; - case 'i': + case 'i': // Priority important feeds self::$current_get['important'] = true; self::$name = _t('index.menu.important'); self::$description = FreshRSS_Context::systemConf()->meta_description; diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index f9bf57220..525687c90 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -1170,7 +1170,7 @@ SQL; } /** - * @phpstan-param 'a'|'A'|'i'|'s'|'S'|'c'|'f'|'t'|'T'|'ST' $type + * @phpstan-param 'a'|'A'|'i'|'s'|'S'|'c'|'f'|'t'|'T'|'ST'|'Z' $type * @param int $id category/feed/tag ID * @param 'ASC'|'DESC' $order * @return array{0:array,1:string} @@ -1185,13 +1185,16 @@ SQL; $where = ''; $values = []; switch ($type) { - case 'a': //All PRIORITY_MAIN_STREAM + case 'a': // All PRIORITY_MAIN_STREAM $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_MAIN_STREAM . ' '; break; - case 'A': //All except PRIORITY_ARCHIVED - $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; + case 'A': // All except PRIORITY_ARCHIVED + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_CATEGORY . ' '; + break; + case 'Z': // All including PRIORITY_ARCHIVED + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; break; - case 'i': //Priority important feeds + case 'i': // Priority important feeds $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_IMPORTANT . ' '; break; case 's': //Starred. Deprecated: use $state instead @@ -1240,7 +1243,7 @@ SQL; } /** - * @phpstan-param 'a'|'A'|'s'|'S'|'i'|'c'|'f'|'t'|'T'|'ST' $type + * @phpstan-param 'a'|'A'|'s'|'S'|'i'|'c'|'f'|'t'|'T'|'ST'|'Z' $type * @param 'ASC'|'DESC' $order * @param int $id category/feed/tag ID * @throws FreshRSS_EntriesGetter_Exception @@ -1275,7 +1278,7 @@ SQL; } /** - * @phpstan-param 'a'|'A'|'s'|'S'|'i'|'c'|'f'|'t'|'T'|'ST' $type + * @phpstan-param 'a'|'A'|'s'|'S'|'i'|'c'|'f'|'t'|'T'|'ST'|'Z' $type * @param int $id category/feed/tag ID * @param 'ASC'|'DESC' $order * @return Traversable @@ -1341,7 +1344,7 @@ SQL; } /** - * @phpstan-param 'a'|'A'|'s'|'S'|'c'|'f'|'t'|'T'|'ST' $type + * @phpstan-param 'a'|'A'|'s'|'S'|'c'|'f'|'t'|'T'|'ST'|'Z' $type * @param int $id category/feed/tag ID * @param 'ASC'|'DESC' $order * @return array|null diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.php index d3a56bb6a..6933deb1f 100644 --- a/app/Models/UserQuery.php +++ b/app/Models/UserQuery.php @@ -126,12 +126,18 @@ class FreshRSS_UserQuery { $this->get = $get; if ($this->get === '') { $this->get_type = 'all'; - } elseif (preg_match('/(?P[acfistT])(_(?P\d+))?/', $get, $matches)) { + } elseif (preg_match('/(?P[aAcfistTZ])(_(?P\d+))?/', $get, $matches)) { $id = intval($matches['id'] ?? '0'); switch ($matches['type']) { - case 'a': + case 'a': // All PRIORITY_MAIN_STREAM $this->get_type = 'all'; break; + case 'A': // All except PRIORITY_ARCHIVED + $this->get_type = 'A'; + break; + case 'Z': // All including PRIORITY_ARCHIVED + $this->get_type = 'Z'; + break; case 'c': $this->get_type = 'category'; $c = $this->categories[$id] ?? null; -- cgit v1.2.3