diff options
Diffstat (limited to 'app/Controllers/indexController.php')
| -rw-r--r-- | app/Controllers/indexController.php | 45 |
1 files changed, 42 insertions, 3 deletions
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 @@ -31,6 +31,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. */ public function normalAction(): void { @@ -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, |
