aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Context.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/Context.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/Context.php')
-rw-r--r--app/Models/Context.php54
1 files changed, 38 insertions, 16 deletions
diff --git a/app/Models/Context.php b/app/Models/Context.php
index 2d22290bc..37a2064c6 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -10,11 +10,11 @@ final class FreshRSS_Context {
/**
* @var array<int,FreshRSS_Category>
*/
- public static array $categories = [];
+ private static array $categories = [];
/**
* @var array<int,FreshRSS_Tag>
*/
- public static array $tags = [];
+ private static array $tags = [];
public static string $name = '';
public static string $description = '';
public static int $total_unread = 0;
@@ -47,6 +47,7 @@ final class FreshRSS_Context {
*/
public static string $order = 'DESC';
public static int $number = 0;
+ public static int $offset = 0;
public static FreshRSS_BooleanSearch $search;
public static string $first_id = '';
public static string $next_id = '';
@@ -173,10 +174,33 @@ final class FreshRSS_Context {
FreshRSS_Context::$user_conf = null;
}
+ /** @return array<int,FreshRSS_Category> */
+ public static function categories(): array {
+ if (empty(self::$categories)) {
+ $catDAO = FreshRSS_Factory::createCategoryDao();
+ self::$categories = $catDAO->listSortedCategories(true, false);
+ }
+ return self::$categories;
+ }
+
+ /** @return array<int,FreshRSS_Feed> */
+ public static function feeds(): array {
+ return FreshRSS_Category::findFeeds(self::categories());
+ }
+
+ /** @return array<int,FreshRSS_Tag> */
+ public static function labels(bool $precounts = false): array {
+ if (empty(self::$tags) || $precounts) {
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ self::$tags = $tagDAO->listTags($precounts) ?: [];
+ }
+ return self::$tags;
+ }
+
/**
* This action updates the Context object by using request parameters.
*
- * Parameters are:
+ * HTTP GET request parameters are:
* - state (default: conf->default_view)
* - search (default: empty string)
* - order (default: conf->sort_order)
@@ -187,18 +211,15 @@ final class FreshRSS_Context {
* @throws Minz_ConfigurationNamespaceException
* @throws Minz_PDOConnectionException
*/
- public static function updateUsingRequest(): void {
- if (empty(self::$categories)) {
- $catDAO = FreshRSS_Factory::createCategoryDao();
- self::$categories = $catDAO->listSortedCategories();
+ public static function updateUsingRequest(bool $computeStatistics): void {
+ if ($computeStatistics && self::$total_unread === 0) {
+ // Update number of read / unread variables.
+ $entryDAO = FreshRSS_Factory::createEntryDao();
+ self::$total_starred = $entryDAO->countUnreadReadFavorites();
+ self::$total_unread = FreshRSS_Category::countUnread(self::categories(), FreshRSS_Feed::PRIORITY_MAIN_STREAM);
+ self::$total_important_unread = FreshRSS_Category::countUnread(self::categories(), FreshRSS_Feed::PRIORITY_IMPORTANT);
}
- // Update number of read / unread variables.
- $entryDAO = FreshRSS_Factory::createEntryDao();
- self::$total_starred = $entryDAO->countUnreadReadFavorites();
- self::$total_unread = FreshRSS_CategoryDAO::countUnread(self::$categories, FreshRSS_Feed::PRIORITY_MAIN_STREAM);
- self::$total_important_unread = FreshRSS_CategoryDAO::countUnread(self::$categories, FreshRSS_Feed::PRIORITY_IMPORTANT);
-
self::_get(Minz_Request::paramString('get') ?: 'a');
self::$state = Minz_Request::paramInt('state') ?: FreshRSS_Context::userConf()->default_state;
@@ -224,6 +245,7 @@ final class FreshRSS_Context {
FreshRSS_Context::userConf()->max_posts_per_rss,
FreshRSS_Context::userConf()->posts_per_page);
}
+ self::$offset = Minz_Request::paramInt('offset');
self::$first_id = Minz_Request::paramString('next');
self::$sinceHours = Minz_Request::paramInt('hours');
}
@@ -394,7 +416,7 @@ final class FreshRSS_Context {
break;
case 'f':
// We try to find the corresponding feed. When allowing robots, always retrieve the full feed including description
- $feed = FreshRSS_Context::systemConf()->allow_robots ? null : FreshRSS_CategoryDAO::findFeed(self::$categories, $id);
+ $feed = FreshRSS_Context::systemConf()->allow_robots ? null : FreshRSS_Category::findFeed(self::$categories, $id);
if ($feed === null) {
$feedDAO = FreshRSS_Factory::createFeedDao();
$feed = $feedDAO->searchById($id);
@@ -417,7 +439,7 @@ final class FreshRSS_Context {
if ($cat === null) {
throw new FreshRSS_Context_Exception('Invalid category: ' . $id);
}
- //self::$categories[$id] = $cat;
+ self::$categories[$id] = $cat;
} else {
$cat = self::$categories[$id];
}
@@ -433,7 +455,7 @@ final class FreshRSS_Context {
if ($tag === null) {
throw new FreshRSS_Context_Exception('Invalid tag: ' . $id);
}
- //self::$tags[$id] = $tag;
+ self::$tags[$id] = $tag;
} else {
$tag = self::$tags[$id];
}