4
0

entryController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 (Minz_Translate::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 (!$get) {
  42. $entryDAO->markReadEntries ($idMax);
  43. } else {
  44. $typeGet = $get[0];
  45. $get = substr ($get, 2);
  46. switch ($typeGet) {
  47. case 'c':
  48. $entryDAO->markReadCat ($get, $idMax);
  49. break;
  50. case 'f':
  51. $entryDAO->markReadFeed ($get, $idMax);
  52. break;
  53. case 's':
  54. $entryDAO->markReadEntries ($idMax, true);
  55. break;
  56. case 'a':
  57. $entryDAO->markReadEntries ($idMax);
  58. break;
  59. }
  60. if ($nextGet !== 'a') {
  61. $this->params['get'] = $nextGet;
  62. }
  63. }
  64. $notif = array (
  65. 'type' => 'good',
  66. 'content' => Minz_Translate::t ('feeds_marked_read')
  67. );
  68. Minz_Session::_param ('notification', $notif);
  69. } else {
  70. $is_read = (bool)(Minz_Request::param ('is_read', true));
  71. $entryDAO->markRead ($id, $is_read);
  72. }
  73. }
  74. public function bookmarkAction () {
  75. $this->redirect = true;
  76. $id = Minz_Request::param ('id');
  77. if ($id) {
  78. $entryDAO = FreshRSS_Factory::createEntryDao();
  79. $entryDAO->markFavorite ($id, (bool)(Minz_Request::param ('is_favorite', true)));
  80. }
  81. }
  82. public function optimizeAction() {
  83. if (Minz_Request::isPost()) {
  84. @set_time_limit(300);
  85. // La table des entrées a tendance à grossir énormément
  86. // Cette action permet d'optimiser cette table permettant de grapiller un peu de place
  87. // Cette fonctionnalité n'est à appeler qu'occasionnellement
  88. $entryDAO = FreshRSS_Factory::createEntryDao();
  89. $entryDAO->optimizeTable();
  90. $feedDAO = FreshRSS_Factory::createFeedDao();
  91. $feedDAO->updateCachedValues();
  92. invalidateHttpCache();
  93. $notif = array (
  94. 'type' => 'good',
  95. 'content' => Minz_Translate::t ('optimization_complete')
  96. );
  97. Minz_Session::_param ('notification', $notif);
  98. }
  99. Minz_Request::forward(array(
  100. 'c' => 'configure',
  101. 'a' => 'archiving'
  102. ), true);
  103. }
  104. public function purgeAction() {
  105. @set_time_limit(300);
  106. $nb_month_old = max($this->view->conf->old_entries, 1);
  107. $date_min = time() - (3600 * 24 * 30 * $nb_month_old);
  108. $feedDAO = FreshRSS_Factory::createFeedDao();
  109. $feeds = $feedDAO->listFeeds();
  110. $nbTotal = 0;
  111. invalidateHttpCache();
  112. foreach ($feeds as $feed) {
  113. $feedHistory = $feed->keepHistory();
  114. if ($feedHistory == -2) { //default
  115. $feedHistory = $this->view->conf->keep_history_default;
  116. }
  117. if ($feedHistory >= 0) {
  118. $nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory);
  119. if ($nb > 0) {
  120. $nbTotal += $nb;
  121. Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);
  122. //$feedDAO->updateLastUpdate($feed->id());
  123. }
  124. }
  125. }
  126. $feedDAO->updateCachedValues();
  127. invalidateHttpCache();
  128. $notif = array(
  129. 'type' => 'good',
  130. 'content' => Minz_Translate::t('purge_completed', $nbTotal)
  131. );
  132. Minz_Session::_param('notification', $notif);
  133. Minz_Request::forward(array(
  134. 'c' => 'configure',
  135. 'a' => 'archiving'
  136. ), true);
  137. }
  138. }