indexController.php 3.1 KB

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