4
0

ReadingMode.php 2.5 KB

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