ReadingMode.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 string $id
  29. * @param string $title
  30. * @param string[] $urlParams
  31. * @param bool $active
  32. */
  33. public function __construct($id, $title, $urlParams, $active) {
  34. $this->id = $id;
  35. $this->name = _i($id);
  36. $this->title = $title;
  37. $this->urlParams = $urlParams;
  38. $this->isActive = $active;
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function getId() {
  44. return $this->id;
  45. }
  46. /**
  47. * @return string
  48. */
  49. public function getName() {
  50. return $this->name;
  51. }
  52. /**
  53. * @param string $name
  54. * @return FreshRSS_ReadingMode
  55. */
  56. public function setName($name) {
  57. $this->name = $name;
  58. return $this;
  59. }
  60. /**
  61. * @return string
  62. */
  63. public function getTitle() {
  64. return $this->title;
  65. }
  66. /**
  67. * @param string $title
  68. * @return FreshRSS_ReadingMode
  69. */
  70. public function setTitle($title) {
  71. $this->title = $title;
  72. return $this;
  73. }
  74. /**
  75. * @return array<string>
  76. */
  77. public function getUrlParams() {
  78. return $this->urlParams;
  79. }
  80. /**
  81. * @param array<string> $urlParams
  82. * @return FreshRSS_ReadingMode
  83. */
  84. public function setUrlParams($urlParams) {
  85. $this->urlParams = $urlParams;
  86. return $this;
  87. }
  88. /**
  89. * @return bool
  90. */
  91. public function isActive() {
  92. return $this->isActive;
  93. }
  94. /**
  95. * @param bool $isActive
  96. * @return FreshRSS_ReadingMode
  97. */
  98. public function setIsActive($isActive) {
  99. $this->isActive = $isActive;
  100. return $this;
  101. }
  102. /**
  103. * Returns the built-in reading modes.
  104. * return ReadingMode[]
  105. */
  106. public static function getReadingModes() {
  107. $actualView = Minz_Request::actionName();
  108. $defaultCtrl = Minz_Request::defaultControllerName();
  109. $isDefaultCtrl = Minz_Request::controllerName() === $defaultCtrl;
  110. $urlOutput = Minz_Request::currentRequest();
  111. $readingModes = array(
  112. new FreshRSS_ReadingMode(
  113. "view-normal",
  114. _t('index.menu.normal_view'),
  115. array_merge($urlOutput, array('c' => $defaultCtrl, 'a' => 'normal')),
  116. ($isDefaultCtrl && $actualView === 'normal')
  117. ),
  118. new FreshRSS_ReadingMode(
  119. "view-global",
  120. _t('index.menu.global_view'),
  121. array_merge($urlOutput, array('c' => $defaultCtrl, 'a' => 'global')),
  122. ($isDefaultCtrl && $actualView === 'global')
  123. ),
  124. new FreshRSS_ReadingMode(
  125. "view-reader",
  126. _t('index.menu.reader_view'),
  127. array_merge($urlOutput, array('c' => $defaultCtrl, 'a' => 'reader')),
  128. ($isDefaultCtrl && $actualView === 'reader')
  129. ),
  130. );
  131. return $readingModes;
  132. }
  133. }