4
0

indexController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * This class handles main actions of FreshRSS.
  4. */
  5. class FreshRSS_index_Controller extends Minz_ActionController {
  6. public function indexAction() {
  7. // TODO: update the context with information from request.
  8. // TODO: then, in dedicated action, get corresponding entries
  9. $prefered_output = FreshRSS_Context::$conf->view_mode;
  10. Minz_Request::forward(array(
  11. 'c' => 'index',
  12. 'a' => $prefered_output
  13. ));
  14. return;
  15. try {
  16. $entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb + 1, $first, $filter);
  17. if (count($entries) > $nb) {
  18. // We have more elements for pagination
  19. $last_entry = array_pop($entries);
  20. FreshRSS_Context::$next_id = $last_entry->id();
  21. }
  22. $this->view->entries = $entries;
  23. } catch (FreshRSS_EntriesGetter_Exception $e) {
  24. Minz_Log::notice($e->getMessage());
  25. Minz_Error::error(404);
  26. }
  27. }
  28. /**
  29. * This action displays the normal view of FreshRSS.
  30. */
  31. public function normalAction() {
  32. if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) {
  33. Minz_Request::forward(array('c' => 'auth', 'a' => 'login'));
  34. return;
  35. }
  36. try {
  37. $this->updateContext();
  38. } catch (Minz_Exception $e) {
  39. Minz_Error::error(404);
  40. }
  41. $this->view->categories = FreshRSS_Context::$categories;
  42. $title = FreshRSS_Context::$name;
  43. if (FreshRSS_Context::$get_unread > 0) {
  44. $title = '(' . FreshRSS_Context::$get_unread . ') · ' . $title;
  45. }
  46. Minz_View::prependTitle($title . ' · ');
  47. }
  48. /**
  49. * This action displays the global view of FreshRSS.
  50. */
  51. public function globalAction() {
  52. if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) {
  53. Minz_Request::forward(array('c' => 'auth', 'a' => 'login'));
  54. return;
  55. }
  56. Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js')));
  57. try {
  58. $this->updateContext();
  59. } catch (Minz_Exception $e) {
  60. Minz_Error::error(404);
  61. }
  62. $this->view->categories = FreshRSS_Context::$categories;
  63. Minz_View::prependTitle(_t('gen.title.global_view') . ' · ');
  64. }
  65. /**
  66. * This action displays the RSS feed of FreshRSS.
  67. */
  68. public function rssAction() {
  69. $token = FreshRSS_Context::$conf->token;
  70. $token_param = Minz_Request::param('token', '');
  71. $token_is_ok = ($token != '' && $token === $token_param);
  72. // Check if user has access.
  73. if (!FreshRSS_Auth::hasAccess() &&
  74. !Minz_Configuration::allowAnonymous() &&
  75. !$token_is_ok) {
  76. Minz_Error::error(403);
  77. }
  78. try {
  79. $this->updateContext();
  80. } catch (Minz_Exception $e) {
  81. Minz_Error::error(404);
  82. }
  83. // No layout for RSS output.
  84. $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();
  85. $this->view->_useLayout(false);
  86. header('Content-Type: application/rss+xml; charset=utf-8');
  87. }
  88. /**
  89. * This action updates the Context object by using request parameters.
  90. */
  91. private function updateContext() {
  92. FreshRSS_Context::_get(Minz_Request::param('get', 'a'));
  93. FreshRSS_Context::$state |= Minz_Request::param(
  94. 'state', FreshRSS_Context::$conf->default_view
  95. );
  96. if (FreshRSS_Context::$state & FreshRSS_Entry::STATE_NOT_READ &&
  97. FreshRSS_Context::$get_unread <= 0) {
  98. FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ;
  99. }
  100. FreshRSS_Context::$search = Minz_Request::param('search', '');
  101. FreshRSS_Context::$order = Minz_Request::param(
  102. 'order', FreshRSS_Context::$conf->sort_order
  103. );
  104. FreshRSS_Context::$number = Minz_Request::param(
  105. 'nb', FreshRSS_Context::$conf->posts_per_page
  106. );
  107. FreshRSS_Context::$first_id = Minz_Request::param('next', '');
  108. }
  109. /**
  110. * This action displays the about page of FreshRSS.
  111. */
  112. public function aboutAction() {
  113. Minz_View::prependTitle(_t('about') . ' · ');
  114. }
  115. /**
  116. * This action displays logs of FreshRSS for the current user.
  117. */
  118. public function logsAction() {
  119. if (!FreshRSS_Auth::hasAccess()) {
  120. Minz_Error::error(403);
  121. }
  122. Minz_View::prependTitle(_t('logs') . ' · ');
  123. if (Minz_Request::isPost()) {
  124. FreshRSS_LogDAO::truncate();
  125. }
  126. $logs = FreshRSS_LogDAO::lines(); //TODO: ask only the necessary lines
  127. //gestion pagination
  128. $page = Minz_Request::param('page', 1);
  129. $this->view->logsPaginator = new Minz_Paginator($logs);
  130. $this->view->logsPaginator->_nbItemsPerPage(50);
  131. $this->view->logsPaginator->_currentPage($page);
  132. }
  133. }