aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Category.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-02-26 09:01:03 +0100
committerGravatar GitHub <noreply@github.com> 2024-02-26 09:01:03 +0100
commit39cc1c11ec596176e842cc98e6a54337e3c04d7e (patch)
treedab89beb80268acb5e4bd58dfc55297bd30a8486 /app/Models/Category.php
parent25166c218be4e1ce1cb098de274a231b623d527e (diff)
New feature: shareable user query (#6052)
* New feature: shareable user query Share the output of a user query by RSS / HTML / OPML with other people through unique URLs. Replaces the global admin token, which was the only option (but unsafe) to share RSS outputs with other people. Also add a new HTML output for people without an RSS reader. fix https://github.com/FreshRSS/FreshRSS/issues/3066#issuecomment-648977890 fix https://github.com/FreshRSS/FreshRSS/issues/3178#issuecomment-769435504 * Remove unused method * Fix token saving * Implement HTML view * Update i18n for master token * Revert i18n get_favorite * Fix missing i18n for user queries from before this PR * Remove irrelevant tests * Add link to RSS version * Fix getGet * Fix getState * Fix getSearch * Alternative getSearch * Default getOrder * Explicit default state * Fix test * Add OPML sharing * Remove many redundant SQL queries from original implementation of user queries * Fix article tags * Use default user settings * Prepare public search * Fixes * Allow user search on article tags * Implement user search * Revert filter bug * Revert wrong SQL left outer join change * Implement checkboxes * Safe check of OPML * Fix label * Remove RSS button to favour new sharing method That sharing button was using a global admin token * First version of HTTP 304 * Disallow some recusrivity fix https://github.com/FreshRSS/FreshRSS/issues/6086 * Draft of nav * Minor httpConditional * Add support for offset for pagination * Fix offset pagination * Fix explicit order ASC * Add documentation * Help links i18n * Note about deprecated master token * Typo * Doc about format
Diffstat (limited to 'app/Models/Category.php')
-rw-r--r--app/Models/Category.php54
1 files changed, 48 insertions, 6 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 1f5b4dc61..6674b4e72 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -95,7 +95,7 @@ class FreshRSS_Category extends Minz_Model {
}
/**
- * @return array<FreshRSS_Feed>
+ * @return array<int,FreshRSS_Feed>
* @throws Minz_ConfigurationNamespaceException
* @throws Minz_PDOConnectionException
*/
@@ -110,10 +110,8 @@ class FreshRSS_Category extends Minz_Model {
$this->nbNotRead += $feed->nbNotRead();
$this->hasFeedsWithError |= ($feed->inError() && !$feed->mute());
}
-
$this->sortFeeds();
}
-
return $this->feeds ?? [];
}
@@ -143,7 +141,6 @@ class FreshRSS_Category extends Minz_Model {
if (!is_array($values)) {
$values = [$values];
}
-
$this->feeds = $values;
$this->sortFeeds();
}
@@ -157,7 +154,6 @@ class FreshRSS_Category extends Minz_Model {
}
$feed->_category($this);
$this->feeds[] = $feed;
-
$this->sortFeeds();
}
@@ -243,8 +239,54 @@ class FreshRSS_Category extends Minz_Model {
if ($this->feeds === null) {
return;
}
- usort($this->feeds, static function (FreshRSS_Feed $a, FreshRSS_Feed $b) {
+ uasort($this->feeds, static function (FreshRSS_Feed $a, FreshRSS_Feed $b) {
return strnatcasecmp($a->name(), $b->name());
});
}
+
+ /**
+ * Access cached feed
+ * @param array<FreshRSS_Category> $categories
+ */
+ public static function findFeed(array $categories, int $feed_id): ?FreshRSS_Feed {
+ foreach ($categories as $category) {
+ foreach ($category->feeds() as $feed) {
+ if ($feed->id() === $feed_id) {
+ $feed->_category($category); // Should already be done; just to be safe
+ return $feed;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Access cached feeds
+ * @param array<FreshRSS_Category> $categories
+ * @return array<int,FreshRSS_Feed>
+ */
+ public static function findFeeds(array $categories): array {
+ $result = [];
+ foreach ($categories as $category) {
+ foreach ($category->feeds() as $feed) {
+ $result[$feed->id()] = $feed;
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * @param array<FreshRSS_Category> $categories
+ */
+ public static function countUnread(array $categories, int $minPriority = 0): int {
+ $n = 0;
+ foreach ($categories as $category) {
+ foreach ($category->feeds() as $feed) {
+ if ($feed->priority() >= $minPriority) {
+ $n += $feed->nbNotRead();
+ }
+ }
+ }
+ return $n;
+ }
}