ViewMode.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Represents a view mode option for the reading configuration
  5. */
  6. final class FreshRSS_ViewMode {
  7. private string $id;
  8. private string $name;
  9. private string $controller;
  10. private string $action;
  11. public function __construct(string $id, string $name, string $controller = 'index', string $action = '') {
  12. $this->id = $id;
  13. $this->name = $name;
  14. $this->controller = $controller;
  15. $this->action = $action ?: $id;
  16. }
  17. public function id(): string {
  18. return $this->id;
  19. }
  20. public function name(): string {
  21. return $this->name;
  22. }
  23. public function controller(): string {
  24. return $this->controller;
  25. }
  26. public function action(): string {
  27. return $this->action;
  28. }
  29. /**
  30. * @return array<string,FreshRSS_ViewMode> Mode ID => FreshRSS_ViewMode
  31. */
  32. public static function getDefaultModes(): array {
  33. return [
  34. 'normal' => new self(id: 'normal', name: _t('conf.reading.view.normal'), controller: 'index', action: 'normal'),
  35. 'reader' => new self(id: 'reader', name: _t('conf.reading.view.reader'), controller: 'index', action: 'reader'),
  36. 'global' => new self(id: 'global', name: _t('conf.reading.view.global'), controller: 'index', action: 'global'),
  37. ];
  38. }
  39. /**
  40. * @return array<string,FreshRSS_ViewMode> Mode ID => FreshRSS_ViewMode
  41. */
  42. public static function getAllModes(): array {
  43. $modes = self::getDefaultModes();
  44. // Allow extensions to add their own view modes
  45. $extensionModes = Minz_ExtensionManager::callHook(Minz_HookType::ViewModes, []);
  46. if (is_array($extensionModes)) {
  47. foreach ($extensionModes as $mode) {
  48. if ($mode instanceof FreshRSS_ViewMode) {
  49. $modes[$mode->id()] = $mode;
  50. }
  51. }
  52. }
  53. return $modes;
  54. }
  55. }