ReadingMode.php 2.5 KB

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