ReadingMode.php 2.6 KB

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