entryController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. class entryController extends ActionController {
  3. public function firstAction () {
  4. if (login_is_conf ($this->view->conf) && !is_logged ()) {
  5. Error::error (
  6. 403,
  7. array ('error' => array (Translate::t ('access denied')))
  8. );
  9. }
  10. $this->params = array ();
  11. $this->redirect = false;
  12. $ajax = Request::param ('ajax');
  13. if ($ajax) {
  14. $this->view->_useLayout (false);
  15. }
  16. }
  17. public function lastAction () {
  18. $ajax = Request::param ('ajax');
  19. if (!$ajax && $this->redirect) {
  20. Request::forward (array (
  21. 'c' => 'index',
  22. 'a' => 'index',
  23. 'params' => $this->params
  24. ), true);
  25. } else {
  26. Request::_param ('ajax');
  27. }
  28. }
  29. public function readAction () {
  30. $this->redirect = true;
  31. $id = Request::param ('id');
  32. $is_read = Request::param ('is_read');
  33. $get = Request::param ('get');
  34. $dateMax = Request::param ('dateMax', time ());
  35. if ($is_read) {
  36. $is_read = true;
  37. } else {
  38. $is_read = false;
  39. }
  40. $entryDAO = new EntryDAO ();
  41. if ($id == false) {
  42. if (!$get) {
  43. $entryDAO->markReadEntries ($is_read, $dateMax);
  44. } else {
  45. $typeGet = $get[0];
  46. $get = substr ($get, 2);
  47. if ($typeGet == 'c') {
  48. $entryDAO->markReadCat ($get, $is_read, $dateMax);
  49. $this->params = array ('get' => 'c_' . $get);
  50. } elseif ($typeGet == 'f') {
  51. $entryDAO->markReadFeed ($get, $is_read, $dateMax);
  52. $this->params = array ('get' => 'f_' . $get);
  53. }
  54. }
  55. // notif
  56. $notif = array (
  57. 'type' => 'good',
  58. 'content' => Translate::t ('feeds_marked_read')
  59. );
  60. Session::_param ('notification', $notif);
  61. } else {
  62. $entryDAO->updateEntry ($id, array ('is_read' => $is_read));
  63. }
  64. }
  65. public function bookmarkAction () {
  66. $this->redirect = true;
  67. $id = Request::param ('id');
  68. $is_fav = Request::param ('is_favorite');
  69. if ($is_fav) {
  70. $is_fav = true;
  71. } else {
  72. $is_fav = false;
  73. }
  74. $entryDAO = new EntryDAO ();
  75. if ($id != false) {
  76. $entry = $entryDAO->searchById ($id);
  77. if ($entry != false) {
  78. $values = array (
  79. 'is_favorite' => $is_fav,
  80. 'lastUpdate' => time ()
  81. );
  82. $entryDAO->updateEntry ($entry->id (), $values);
  83. }
  84. }
  85. }
  86. public function noteAction () {
  87. View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
  88. $not_found = false;
  89. $entryDAO = new EntryDAO ();
  90. $catDAO = new CategoryDAO ();
  91. $id = Request::param ('id');
  92. if ($id) {
  93. $entry = $entryDAO->searchById ($id);
  94. if ($entry) {
  95. $feed = $entry->feed (true);
  96. if (Request::isPost ()) {
  97. $note = htmlspecialchars (Request::param ('note', ''));
  98. $public = Request::param ('public', 'no');
  99. if ($public == 'yes') {
  100. $public = true;
  101. } else {
  102. $public = false;
  103. }
  104. $values = array (
  105. 'annotation' => $note,
  106. 'is_public' => $public,
  107. 'lastUpdate' => time ()
  108. );
  109. if ($entryDAO->updateEntry ($id, $values)) {
  110. $notif = array (
  111. 'type' => 'good',
  112. 'content' => Translate::t ('updated')
  113. );
  114. } else {
  115. $notif = array (
  116. 'type' => 'bad',
  117. 'content' => Translate::t ('error_occured')
  118. );
  119. }
  120. Session::_param ('notification', $notif);
  121. Request::forward (array (
  122. 'c' => 'entry',
  123. 'a' => 'note',
  124. 'params' => array (
  125. 'id' => $id
  126. )
  127. ), true);
  128. }
  129. } else {
  130. $not_found = true;
  131. }
  132. } else {
  133. $not_found = true;
  134. }
  135. if ($not_found) {
  136. Error::error (
  137. 404,
  138. array ('error' => array (Translate::t ('page_not_found')))
  139. );
  140. } else {
  141. $this->view->entry = $entry;
  142. $this->view->cat_aside = $catDAO->listCategories ();
  143. $this->view->nb_favorites = $entryDAO->countFavorites ();
  144. $this->view->nb_total = $entryDAO->count ();
  145. $this->view->get_c = $feed->category ();
  146. $this->view->get_f = $feed->id ();
  147. }
  148. }
  149. }