indexController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. class indexController extends ActionController {
  3. public function indexAction () {
  4. View::appendScript (Url::display ('/scripts/smoothscroll.js'));
  5. View::appendScript (Url::display ('/scripts/shortcut.js'));
  6. View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
  7. $entryDAO = new EntryDAO ();
  8. $feedDAO = new FeedDAO ();
  9. $catDAO = new CategoryDAO ();
  10. // pour optimiser
  11. $page = Request::param ('page', 1);
  12. $entryDAO->_nbItemsPerPage ($this->view->conf->postsPerPage ());
  13. $entryDAO->_currentPage ($page);
  14. $default_view = $this->view->conf->defaultView ();
  15. $mode = Session::param ('mode');
  16. if ($mode == false) {
  17. if ($default_view == 'not_read' && $this->view->nb_not_read < 1) {
  18. $mode = 'all';
  19. } else {
  20. $mode = $default_view;
  21. }
  22. }
  23. $get = Request::param ('get');
  24. $this->view->get_c = false;
  25. $this->view->get_f = false;
  26. $order = $this->view->conf->sortOrder ();
  27. $error = false;
  28. // Récupère les flux par catégorie, favoris ou tous
  29. if ($get == 'favoris') {
  30. $entries = $entryDAO->listFavorites ($mode, $order);
  31. $this->view->get_c = $get;
  32. View::prependTitle ('Vos favoris - ');
  33. } elseif ($get != false) {
  34. $typeGet = $get[0];
  35. $get = substr ($get, 2);
  36. if ($typeGet == 'c') {
  37. $entries = $entryDAO->listByCategory ($get, $mode, $order);
  38. $cat = $catDAO->searchById ($get);
  39. if ($cat) {
  40. $this->view->get_c = $get;
  41. View::prependTitle ($cat->name () . ' - ');
  42. } else {
  43. $error = true;
  44. }
  45. } elseif ($typeGet == 'f') {
  46. $entries = $entryDAO->listByFeed ($get, $mode, $order);
  47. $feed = $feedDAO->searchById ($get);
  48. if ($feed) {
  49. $this->view->get_f = $get;
  50. $this->view->get_c = $feed->category ();
  51. View::prependTitle ($feed->name () . ' - ');
  52. } else {
  53. $error = true;
  54. }
  55. } else {
  56. $error = true;
  57. }
  58. } else {
  59. View::prependTitle ('Vos flux RSS - ');
  60. }
  61. $this->view->mode = $mode;
  62. // Cas où on ne choisie ni catégorie ni les favoris
  63. // ou si la catégorie ne correspond à aucune
  64. if (!isset ($entries)) {
  65. $entries = $entryDAO->listEntries ($mode, $order);
  66. }
  67. try {
  68. $this->view->entryPaginator = $entryDAO->getPaginator ($entries);
  69. } catch (CurrentPagePaginationException $e) { }
  70. $this->view->cat_aside = $catDAO->listCategories ();
  71. $this->view->nb_favorites = $entryDAO->countFavorites ();
  72. $this->view->nb_total = $entryDAO->count ();
  73. if ($error) {
  74. Error::error (
  75. 404,
  76. array ('error' => array ('La page que vous cherchez n\'existe pas'))
  77. );
  78. }
  79. }
  80. public function aboutAction () {
  81. View::prependTitle ('À propos - ');
  82. }
  83. public function changeModeAction () {
  84. $mode = Request::param ('mode');
  85. if ($mode == 'not_read') {
  86. Session::_param ('mode', 'not_read');
  87. } else {
  88. Session::_param ('mode', 'all');
  89. }
  90. Request::forward (array (), true);
  91. }
  92. public function loginAction () {
  93. $this->view->_useLayout (false);
  94. $url = 'https://verifier.login.persona.org/verify';
  95. $assert = Request::param ('assertion');
  96. $params = 'assertion=' . $assert . '&audience=' .
  97. urlencode (Url::display () . ':80');
  98. $ch = curl_init ();
  99. $options = array (
  100. CURLOPT_URL => $url,
  101. CURLOPT_RETURNTRANSFER => TRUE,
  102. CURLOPT_POST => 2,
  103. CURLOPT_POSTFIELDS => $params
  104. );
  105. curl_setopt_array ($ch, $options);
  106. $result = curl_exec ($ch);
  107. curl_close ($ch);
  108. $res = json_decode ($result, true);
  109. if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) {
  110. Session::_param ('mail', $res['email']);
  111. } else {
  112. $res = array ();
  113. $res['status'] = 'failure';
  114. $res['reason'] = 'L\'identifiant est invalide';
  115. }
  116. $this->view->res = json_encode ($res);
  117. }
  118. public function logoutAction () {
  119. $this->view->_useLayout (false);
  120. Session::_param ('mail');
  121. }
  122. }