4
0

ReadingMode.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Manage the reading modes in FreshRSS.
  5. */
  6. class FreshRSS_ReadingMode {
  7. protected string $name;
  8. /**
  9. * ReadingMode constructor.
  10. * @param array{c:string,a:string,params:array<string,mixed>} $urlParams
  11. */
  12. public function __construct(protected string $id, protected string $title, protected array $urlParams, protected bool $isActive) {
  13. $this->name = _i($this->id);
  14. }
  15. public function getId(): string {
  16. return $this->id;
  17. }
  18. public function getName(): string {
  19. return $this->name;
  20. }
  21. public function setName(string $name): FreshRSS_ReadingMode {
  22. $this->name = $name;
  23. return $this;
  24. }
  25. public function getTitle(): string {
  26. return $this->title;
  27. }
  28. public function setTitle(string $title): FreshRSS_ReadingMode {
  29. $this->title = $title;
  30. return $this;
  31. }
  32. /** @return array{c:string,a:string,params:array<string,mixed>} */
  33. public function getUrlParams(): array {
  34. return $this->urlParams;
  35. }
  36. /** @param array{c:string,a:string,params:array<string,mixed>} $urlParams */
  37. public function setUrlParams(array $urlParams): FreshRSS_ReadingMode {
  38. $this->urlParams = $urlParams;
  39. return $this;
  40. }
  41. public function isActive(): bool {
  42. return $this->isActive;
  43. }
  44. public function setIsActive(bool $isActive): FreshRSS_ReadingMode {
  45. $this->isActive = $isActive;
  46. return $this;
  47. }
  48. /**
  49. * @return list<FreshRSS_ReadingMode> the built-in reading modes
  50. */
  51. public static function getReadingModes(): array {
  52. $actualView = Minz_Request::actionName();
  53. $defaultCtrl = Minz_Request::defaultControllerName();
  54. $isDefaultCtrl = Minz_Request::controllerName() === $defaultCtrl;
  55. $urlOutput = Minz_Request::currentRequest();
  56. $readingModes = [
  57. new FreshRSS_ReadingMode(
  58. "view-normal",
  59. _t('index.menu.normal_view'),
  60. array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'normal']),
  61. ($isDefaultCtrl && $actualView === 'normal')
  62. ),
  63. new FreshRSS_ReadingMode(
  64. "view-global",
  65. _t('index.menu.global_view'),
  66. array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'global']),
  67. ($isDefaultCtrl && $actualView === 'global')
  68. ),
  69. new FreshRSS_ReadingMode(
  70. "view-reader",
  71. _t('index.menu.reader_view'),
  72. array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'reader']),
  73. ($isDefaultCtrl && $actualView === 'reader')
  74. )
  75. ];
  76. return $readingModes;
  77. }
  78. }