ReadingMode.php 2.6 KB

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