4
0

entryController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 ('Vous n\'avez pas le droit d\'accéder à cette page'))
  8. );
  9. }
  10. $this->redirect = false;
  11. $ajax = Request::param ('ajax');
  12. if ($ajax) {
  13. $this->view->_useLayout (false);
  14. }
  15. }
  16. public function lastAction () {
  17. $ajax = Request::param ('ajax');
  18. if (!$ajax && $this->redirect) {
  19. Request::forward (array (
  20. 'c' => 'index',
  21. 'a' => 'index',
  22. 'params' => $this->params
  23. ), true);
  24. } else {
  25. Request::_param ('ajax');
  26. }
  27. }
  28. public function readAction () {
  29. $this->redirect = true;
  30. $id = Request::param ('id');
  31. $is_read = Request::param ('is_read');
  32. $get = Request::param ('get');
  33. $dateMax = Request::param ('dateMax', time ());
  34. if ($is_read) {
  35. $is_read = true;
  36. } else {
  37. $is_read = false;
  38. }
  39. $entryDAO = new EntryDAO ();
  40. if ($id == false) {
  41. if (!$get) {
  42. $entryDAO->markReadEntries ($is_read, $dateMax);
  43. } else {
  44. $typeGet = $get[0];
  45. $get = substr ($get, 2);
  46. if ($typeGet == 'c') {
  47. $entryDAO->markReadCat ($get, $is_read, $dateMax);
  48. $this->params = array ('get' => 'c_' . $get);
  49. } elseif ($typeGet == 'f') {
  50. $entryDAO->markReadFeed ($get, $is_read, $dateMax);
  51. $this->params = array ('get' => 'f_' . $get);
  52. }
  53. }
  54. // notif
  55. $notif = array (
  56. 'type' => 'good',
  57. 'content' => 'Les flux ont été marqués comme lu'
  58. );
  59. Session::_param ('notification', $notif);
  60. } else {
  61. $entryDAO->updateEntry ($id, array ('is_read' => $is_read));
  62. }
  63. }
  64. public function bookmarkAction () {
  65. $this->redirect = true;
  66. $id = Request::param ('id');
  67. $is_fav = Request::param ('is_favorite');
  68. if ($is_fav) {
  69. $is_fav = true;
  70. } else {
  71. $is_fav = false;
  72. }
  73. $entryDAO = new EntryDAO ();
  74. if ($id != false) {
  75. $entry = $entryDAO->searchById ($id);
  76. if ($entry != false) {
  77. $values = array (
  78. 'is_favorite' => $is_fav,
  79. 'lastUpdate' => time ()
  80. );
  81. $entryDAO->updateEntry ($entry->id (), $values);
  82. }
  83. }
  84. }
  85. public function noteAction () {
  86. View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
  87. $not_found = false;
  88. $entryDAO = new EntryDAO ();
  89. $catDAO = new CategoryDAO ();
  90. $id = Request::param ('id');
  91. if ($id) {
  92. $entry = $entryDAO->searchById ($id);
  93. if ($entry) {
  94. $feed = $entry->feed (true);
  95. if (Request::isPost ()) {
  96. $note = htmlspecialchars (Request::param ('note', ''));
  97. $public = Request::param ('public', 'no');
  98. if ($public == 'yes') {
  99. $public = true;
  100. } else {
  101. $public = false;
  102. }
  103. $values = array (
  104. 'annotation' => $note,
  105. 'is_public' => $public,
  106. 'lastUpdate' => time ()
  107. );
  108. if ($entryDAO->updateEntry ($id, $values)) {
  109. $notif = array (
  110. 'type' => 'good',
  111. 'content' => 'Modifications enregistrées'
  112. );
  113. } else {
  114. $notif = array (
  115. 'type' => 'bad',
  116. 'content' => 'Une erreur est survenue'
  117. );
  118. }
  119. Session::_param ('notification', $notif);
  120. Request::forward (array (
  121. 'c' => 'entry',
  122. 'a' => 'note',
  123. 'params' => array (
  124. 'id' => $id
  125. )
  126. ), true);
  127. }
  128. } else {
  129. $not_found = true;
  130. }
  131. } else {
  132. $not_found = true;
  133. }
  134. if ($not_found) {
  135. Error::error (
  136. 404,
  137. array ('error' => array ('La page que vous cherchez n\'existe pas'))
  138. );
  139. } else {
  140. $this->view->entry = $entry;
  141. $this->view->cat_aside = $catDAO->listCategories ();
  142. $this->view->nb_favorites = $entryDAO->countFavorites ();
  143. $this->view->nb_total = $entryDAO->count ();
  144. $this->view->get_c = $feed->category ();
  145. $this->view->get_f = $feed->id ();
  146. }
  147. }
  148. }