From b6c63d223931382aae84dc6d394cdd1bb58121bc Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 4 Nov 2025 12:49:21 +0100 Subject: Better transitions between groups of articles (#8174) fix https://github.com/FreshRSS/FreshRSS/issues/7520 fix https://github.com/FreshRSS/FreshRSS/issues/8168 fix https://github.com/FreshRSS/FreshRSS/discussions/8172 --- app/Controllers/indexController.php | 45 ++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 8043e8f79..9005dff93 100644 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -30,6 +30,44 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { ]); } + /** + * @return '.future'|'.today'|'.yesterday'|'' + */ + private static function dayRelative(int $timestamp, bool $mayBeFuture): string { + static $today = null; + if (!is_int($today)) { + $today = strtotime('today') ?: 0; + } + if ($today <= 0) { + return ''; + } elseif ($mayBeFuture && ($timestamp >= $today + 86400)) { + return '.future'; + } elseif ($timestamp >= $today) { + return '.today'; + } elseif ($timestamp >= $today - 86400) { + return '.yesterday'; + } + return ''; + } + + /** + * Content for displaying a transition between entries when sorting by specific criteria. + * @param 'id'|'c.name'|'date'|'f.name'|'link'|'title'|'rand'|'lastUserModified'|'length' $sort + */ + public static function transition(FreshRSS_Entry $entry, string $sort): string { + return match ($sort) { + 'id' => _t('index.feed.received' . self::dayRelative($entry->dateAdded(raw: true), mayBeFuture: false)) . + ' — ' . timestamptodate($entry->dateAdded(raw: true), hour: false), + 'date' => _t('index.feed.published' . self::dayRelative($entry->date(raw: true), mayBeFuture: true)) . + ' — ' . timestamptodate($entry->date(raw: true), hour: false), + 'lastUserModified' => _t('index.feed.userModified' . self::dayRelative($entry->lastUserModified(), mayBeFuture: false)) . + ' — ' . timestamptodate($entry->lastUserModified(), hour: false), + 'c.name' => $entry->feed()?->category()?->name() ?? '', + 'f.name' => $entry->feed()?->name() ?? '', + default => '', + }; + } + /** * This action displays the normal view of FreshRSS. */ @@ -297,10 +335,11 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { } $continuation_values[] = $pagingEntry === null ? 0 : match (FreshRSS_Context::$sort) { - 'c.name' => $pagingEntry->feed()?->category()?->name() ?? '', - 'date' => $pagingEntry->date(true), + 'c.name' => $pagingEntry->feed()?->categoryId() === FreshRSS_CategoryDAO::DEFAULTCATEGORYID ? + FreshRSS_CategoryDAO::DEFAULT_CATEGORY_NAME : $pagingEntry->feed()?->category()?->name() ?? '', + 'date' => $pagingEntry->date(raw: true), 'f.name' => $pagingEntry->feed()?->name() ?? '', - 'link' => $pagingEntry->link(true), + 'link' => $pagingEntry->link(raw: true), 'title' => $pagingEntry->title(), 'lastUserModified' => $pagingEntry->lastUserModified(), 'length' => $pagingEntry->sqlContentLength() ?? 0, -- cgit v1.2.3