diff options
| author | 2024-02-26 09:01:03 +0100 | |
|---|---|---|
| committer | 2024-02-26 09:01:03 +0100 | |
| commit | 39cc1c11ec596176e842cc98e6a54337e3c04d7e (patch) | |
| tree | dab89beb80268acb5e4bd58dfc55297bd30a8486 /app/Controllers/indexController.php | |
| parent | 25166c218be4e1ce1cb098de274a231b623d527e (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/Controllers/indexController.php')
| -rw-r--r-- | app/Controllers/indexController.php | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 20223d340..79e1a6210 100644 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -6,6 +6,10 @@ declare(strict_types=1); */ class FreshRSS_index_Controller extends FreshRSS_ActionController { + public function firstAction(): void { + $this->view->html_url = Minz_Url::display(['c' => 'index', 'a' => 'index'], 'html', 'root'); + } + /** * This action only redirect on the default view mode (normal or global) */ @@ -36,7 +40,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { } try { - FreshRSS_Context::updateUsingRequest(); + FreshRSS_Context::updateUsingRequest(true); } catch (FreshRSS_Context_Exception $e) { Minz_Error::error(404); } @@ -48,7 +52,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { 'media-src' => '*', ]); - $this->view->categories = FreshRSS_Context::$categories; + $this->view->categories = FreshRSS_Context::categories(); $this->view->rss_title = FreshRSS_Context::$name . ' | ' . FreshRSS_View::title(); $title = FreshRSS_Context::$name; @@ -60,15 +64,10 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { FreshRSS_Context::$id_max = time() . '000000'; $this->view->callbackBeforeFeeds = static function (FreshRSS_View $view) { - try { - $tagDAO = FreshRSS_Factory::createTagDao(); - $view->tags = $tagDAO->listTags(true) ?: []; - $view->nbUnreadTags = 0; - foreach ($view->tags as $tag) { - $view->nbUnreadTags += $tag->nbUnread(); - } - } catch (Exception $e) { - Minz_Log::notice($e->getMessage()); + $view->tags = FreshRSS_Context::labels(true); + $view->nbUnreadTags = 0; + foreach ($view->tags as $tag) { + $view->nbUnreadTags += $tag->nbUnread(); } }; @@ -117,12 +116,12 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { FreshRSS_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); try { - FreshRSS_Context::updateUsingRequest(); + FreshRSS_Context::updateUsingRequest(true); } catch (FreshRSS_Context_Exception $e) { Minz_Error::error(404); } - $this->view->categories = FreshRSS_Context::$categories; + $this->view->categories = FreshRSS_Context::categories(); $this->view->rss_title = FreshRSS_Context::$name . ' | ' . FreshRSS_View::title(); $title = _t('index.feed.title_global'); @@ -141,6 +140,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { /** * This action displays the RSS feed of FreshRSS. + * @deprecated See user query RSS sharing instead */ public function rssAction(): void { $allow_anonymous = FreshRSS_Context::systemConf()->allow_anonymous; @@ -156,7 +156,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { } try { - FreshRSS_Context::updateUsingRequest(); + FreshRSS_Context::updateUsingRequest(false); } catch (FreshRSS_Context_Exception $e) { Minz_Error::error(404); } @@ -168,13 +168,19 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { Minz_Error::error(404); } - // No layout for RSS output. - $this->view->rss_url = PUBLIC_TO_INDEX_PATH . '/' . (empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING']); + $this->view->html_url = Minz_Url::display('', 'html', true); $this->view->rss_title = FreshRSS_Context::$name . ' | ' . FreshRSS_View::title(); + $this->view->rss_url = htmlspecialchars( + PUBLIC_TO_INDEX_PATH . '/' . (empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING']), ENT_COMPAT, 'UTF-8'); + + // No layout for RSS output. $this->view->_layout(null); header('Content-Type: application/rss+xml; charset=utf-8'); } + /** + * @deprecated See user query OPML sharing instead + */ public function opmlAction(): void { $allow_anonymous = FreshRSS_Context::systemConf()->allow_anonymous; $token = FreshRSS_Context::userConf()->token; @@ -187,7 +193,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { } try { - FreshRSS_Context::updateUsingRequest(); + FreshRSS_Context::updateUsingRequest(false); } catch (FreshRSS_Context_Exception $e) { Minz_Error::error(404); } @@ -196,25 +202,23 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { $type = (string)$get[0]; $id = (int)$get[1]; - $catDAO = FreshRSS_Factory::createCategoryDao(); - $categories = $catDAO->listCategories(true, true); $this->view->excludeMutedFeeds = true; switch ($type) { case 'a': - $this->view->categories = $categories; + $this->view->categories = FreshRSS_Context::categories(); break; case 'c': - $cat = $categories[$id] ?? null; + $cat = FreshRSS_Context::categories()[$id] ?? null; if ($cat == null) { Minz_Error::error(404); return; } - $this->view->categories = [ $cat ]; + $this->view->categories = [ $cat->id() => $cat ]; break; case 'f': // We most likely already have the feed object in cache - $feed = FreshRSS_CategoryDAO::findFeed($categories, $id); + $feed = FreshRSS_Category::findFeed(FreshRSS_Context::categories(), $id); if ($feed === null) { $feedDAO = FreshRSS_Factory::createFeedDao(); $feed = $feedDAO->searchById($id); @@ -223,7 +227,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { return; } } - $this->view->feeds = [ $feed ]; + $this->view->feeds = [ $feed->id() => $feed ]; break; case 's': case 't': @@ -255,17 +259,14 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { $id = 0; } - $limit = FreshRSS_Context::$number; - $date_min = 0; - if (FreshRSS_Context::$sinceHours) { + if (FreshRSS_Context::$sinceHours > 0) { $date_min = time() - (FreshRSS_Context::$sinceHours * 3600); - $limit = FreshRSS_Context::userConf()->max_posts_per_rss; } foreach ($entryDAO->listWhere( $type, $id, FreshRSS_Context::$state, FreshRSS_Context::$order, - $limit, FreshRSS_Context::$first_id, + FreshRSS_Context::$number, FreshRSS_Context::$offset, FreshRSS_Context::$first_id, FreshRSS_Context::$search, $date_min) as $entry) { yield $entry; |
