From 51298cd6bc100b1cc6508abb602a59c01a9e2c04 Mon Sep 17 00:00:00 2001 From: Stefan <11146296+tryallthethings@users.noreply.github.com> Date: Sun, 22 Jun 2025 00:36:32 +0200 Subject: Exposed the reading modes for extensions through Minz (#7668) * + Exposed the reading modes for extensions through Minz. Now extensions can add a custom view mode. Graceful fallback to normal view in case the extension was disabled without resetting the view_mode through the uninstall method. In that case the user will be informed via Minz_Request::setBadNotification that the view has been reset to normal. + Added translation strings for de, en and en-us for the notification * + Added missing, generated translations * Simplify indexAction, performance * Minor settings htmlspecialchars * i18n: fr * Minor wording * Doc * Fix i18n --------- Co-authored-by: Alexandre Alapetite --- app/Models/View.php | 4 +++ app/Models/ViewMode.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 app/Models/ViewMode.php (limited to 'app/Models') diff --git a/app/Models/View.php b/app/Models/View.php index dd616b888..11ca3a105 100644 --- a/app/Models/View.php +++ b/app/Models/View.php @@ -132,4 +132,8 @@ class FreshRSS_View extends Minz_View { public string $errorMessage; /** @var array */ public array $message; + + // View modes + /** @var array */ + public array $viewModes; } diff --git a/app/Models/ViewMode.php b/app/Models/ViewMode.php new file mode 100644 index 000000000..54379b130 --- /dev/null +++ b/app/Models/ViewMode.php @@ -0,0 +1,65 @@ +id = $id; + $this->name = $name; + $this->controller = $controller; + $this->action = $action ?: $id; + } + + public function id(): string { + return $this->id; + } + + public function name(): string { + return $this->name; + } + + public function controller(): string { + return $this->controller; + } + + public function action(): string { + return $this->action; + } + + /** + * @return array Mode ID => FreshRSS_ViewMode + */ + public static function getDefaultModes(): array { + return [ + 'normal' => new self(id: 'normal', name: _t('conf.reading.view.normal'), controller: 'index', action: 'normal'), + 'reader' => new self(id: 'reader', name: _t('conf.reading.view.reader'), controller: 'index', action: 'reader'), + 'global' => new self(id: 'global', name: _t('conf.reading.view.global'), controller: 'index', action: 'global'), + ]; + } + + /** + * @return array Mode ID => FreshRSS_ViewMode + */ + public static function getAllModes(): array { + $modes = self::getDefaultModes(); + + // Allow extensions to add their own view modes + $extensionModes = Minz_ExtensionManager::callHook('view_modes', []); + if (is_array($extensionModes)) { + foreach ($extensionModes as $mode) { + if ($mode instanceof FreshRSS_ViewMode) { + $modes[$mode->id()] = $mode; + } + } + } + + return $modes; + } +} -- cgit v1.2.3