4
0

entryController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. class FreshRSS_entry_Controller extends Minz_ActionController {
  3. public function firstAction () {
  4. if (!$this->view->loginOk) {
  5. Minz_Error::error (
  6. 403,
  7. array ('error' => array (_t('access_denied')))
  8. );
  9. }
  10. $this->params = array ();
  11. $output = Minz_Request::param('output', '');
  12. if (($output != '') && ($this->view->conf->view_mode !== $output)) {
  13. $this->params['output'] = $output;
  14. }
  15. $this->redirect = false;
  16. $ajax = Minz_Request::param ('ajax');
  17. if ($ajax) {
  18. $this->view->_useLayout (false);
  19. }
  20. }
  21. public function lastAction () {
  22. $ajax = Minz_Request::param ('ajax');
  23. if (!$ajax && $this->redirect) {
  24. Minz_Request::forward (array (
  25. 'c' => 'index',
  26. 'a' => 'index',
  27. 'params' => $this->params
  28. ), true);
  29. } else {
  30. Minz_Request::_param ('ajax');
  31. }
  32. }
  33. public function readAction () {
  34. $this->redirect = true;
  35. $id = Minz_Request::param ('id');
  36. $get = Minz_Request::param ('get');
  37. $nextGet = Minz_Request::param ('nextGet', $get);
  38. $idMax = Minz_Request::param ('idMax', 0);
  39. $entryDAO = FreshRSS_Factory::createEntryDao();
  40. if ($id == false) {
  41. if (!Minz_Request::isPost()) {
  42. return;
  43. }
  44. if (!$get) {
  45. $entryDAO->markReadEntries ($idMax);
  46. } else {
  47. $typeGet = $get[0];
  48. $get = substr ($get, 2);
  49. switch ($typeGet) {
  50. case 'c':
  51. $entryDAO->markReadCat ($get, $idMax);
  52. break;
  53. case 'f':
  54. $entryDAO->markReadFeed ($get, $idMax);
  55. break;
  56. case 's':
  57. $entryDAO->markReadEntries ($idMax, true);
  58. break;
  59. case 'a':
  60. $entryDAO->markReadEntries ($idMax);
  61. break;
  62. }
  63. if ($nextGet !== 'a') {
  64. $this->params['get'] = $nextGet;
  65. }
  66. }
  67. $notif = array (
  68. 'type' => 'good',
  69. 'content' => _t('feeds_marked_read')
  70. );
  71. Minz_Session::_param ('notification', $notif);
  72. } else {
  73. $is_read = (bool)(Minz_Request::param ('is_read', true));
  74. $entryDAO->markRead ($id, $is_read);
  75. }
  76. }
  77. public function bookmarkAction () {
  78. $this->redirect = true;
  79. $id = Minz_Request::param ('id');
  80. if ($id) {
  81. $entryDAO = FreshRSS_Factory::createEntryDao();
  82. $entryDAO->markFavorite ($id, (bool)(Minz_Request::param ('is_favorite', true)));
  83. }
  84. }
  85. public function optimizeAction() {
  86. if (Minz_Request::isPost()) {
  87. @set_time_limit(300);
  88. // La table des entrées a tendance à grossir énormément
  89. // Cette action permet d'optimiser cette table permettant de grapiller un peu de place
  90. // Cette fonctionnalité n'est à appeler qu'occasionnellement
  91. $entryDAO = FreshRSS_Factory::createEntryDao();
  92. $entryDAO->optimizeTable();
  93. $feedDAO = FreshRSS_Factory::createFeedDao();
  94. $feedDAO->updateCachedValues();
  95. invalidateHttpCache();
  96. $notif = array (
  97. 'type' => 'good',
  98. 'content' => _t('optimization_complete')
  99. );
  100. Minz_Session::_param ('notification', $notif);
  101. }
  102. Minz_Request::forward(array(
  103. 'c' => 'configure',
  104. 'a' => 'archiving'
  105. ), true);
  106. }
  107. public function purgeAction() {
  108. @set_time_limit(300);
  109. $nb_month_old = max($this->view->conf->old_entries, 1);
  110. $date_min = time() - (3600 * 24 * 30 * $nb_month_old);
  111. $feedDAO = FreshRSS_Factory::createFeedDao();
  112. $feeds = $feedDAO->listFeeds();
  113. $nbTotal = 0;
  114. invalidateHttpCache();
  115. foreach ($feeds as $feed) {
  116. $feedHistory = $feed->keepHistory();
  117. if ($feedHistory == -2) { //default
  118. $feedHistory = $this->view->conf->keep_history_default;
  119. }
  120. if ($feedHistory >= 0) {
  121. $nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory);
  122. if ($nb > 0) {
  123. $nbTotal += $nb;
  124. Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);
  125. //$feedDAO->updateLastUpdate($feed->id());
  126. }
  127. }
  128. }
  129. $feedDAO->updateCachedValues();
  130. invalidateHttpCache();
  131. $notif = array(
  132. 'type' => 'good',
  133. 'content' => _t('purge_completed', $nbTotal)
  134. );
  135. Minz_Session::_param('notification', $notif);
  136. Minz_Request::forward(array(
  137. 'c' => 'configure',
  138. 'a' => 'archiving'
  139. ), true);
  140. }
  141. }