indexController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $catDAO = new CategoryDAO ();
  9. $mode = Session::param ('mode', $this->view->conf->defaultView ());
  10. $get = Request::param ('get');
  11. $order = $this->view->conf->sortOrder ();
  12. // Récupère les flux par catégorie, favoris ou tous
  13. if ($get == 'favoris') {
  14. $entries = $entryDAO->listFavorites ($mode, $order);
  15. View::prependTitle ('Vos favoris - ');
  16. } elseif ($get != false) {
  17. $entries = $entryDAO->listByCategory ($get, $mode, $order);
  18. $cat = $catDAO->searchById ($get);
  19. if ($cat) {
  20. View::prependTitle ($cat->name () . ' - ');
  21. } else {
  22. Error::error (
  23. 404,
  24. array ('error' => array ('La page que vous cherchez n\'existe pas'))
  25. );
  26. }
  27. } else {
  28. View::prependTitle ('Vos flux RSS - ');
  29. }
  30. $this->view->get = $get;
  31. // Cas où on ne choisie ni catégorie ni les favoris
  32. // ou si la catégorie ne correspond à aucune
  33. if (!isset ($entries)) {
  34. $entries = $entryDAO->listEntries ($mode, $order);
  35. }
  36. // Gestion pagination
  37. try {
  38. $page = Request::param ('page', 1);
  39. $this->view->entryPaginator = new Paginator ($entries);
  40. $this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ());
  41. $this->view->entryPaginator->_currentPage ($page);
  42. } catch (CurrentPagePaginationException $e) {
  43. Error::error (
  44. 404,
  45. array ('error' => array ('La page que vous cherchez n\'existe pas'))
  46. );
  47. }
  48. $this->view->cat_aside = $catDAO->listCategories ();
  49. $this->view->nb_favorites = $entryDAO->countFavorites ();
  50. $this->view->nb_total = $entryDAO->count ();
  51. }
  52. public function changeModeAction () {
  53. $mode = Request::param ('mode');
  54. if ($mode == 'not_read') {
  55. Session::_param ('mode', 'not_read');
  56. } else {
  57. Session::_param ('mode', 'all');
  58. }
  59. Request::forward (array (), true);
  60. }
  61. public function loginAction () {
  62. $this->view->_useLayout (false);
  63. $url = 'https://verifier.login.persona.org/verify';
  64. $assert = Request::param ('assertion');
  65. $params = 'assertion=' . $assert . '&audience=' .
  66. urlencode (Url::display () . ':80');
  67. $ch = curl_init ();
  68. $options = array (
  69. CURLOPT_URL => $url,
  70. CURLOPT_RETURNTRANSFER => TRUE,
  71. CURLOPT_POST => 2,
  72. CURLOPT_POSTFIELDS => $params
  73. );
  74. curl_setopt_array ($ch, $options);
  75. $result = curl_exec ($ch);
  76. curl_close ($ch);
  77. $res = json_decode ($result, true);
  78. if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) {
  79. Session::_param ('mail', $res['email']);
  80. } else {
  81. $res = array ();
  82. $res['status'] = 'failure';
  83. $res['reason'] = 'L\'identifiant est invalide';
  84. }
  85. $this->view->res = json_encode ($res);
  86. }
  87. public function logoutAction () {
  88. $this->view->_useLayout (false);
  89. Session::_param ('mail');
  90. }
  91. }