ReadingMode.php 2.5 KB

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