4
0

entryController.php 3.6 KB

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