indexController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // Cas où on ne choisie ni catégorie ni les favoris
  31. // ou si la catégorie ne correspond à aucune
  32. if (!isset ($entries)) {
  33. $entries = $entryDAO->listEntries ($mode, $order);
  34. }
  35. // Gestion pagination
  36. $page = Request::param ('page', 1);
  37. $this->view->entryPaginator = new Paginator ($entries);
  38. $this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ());
  39. $this->view->entryPaginator->_currentPage ($page);
  40. $this->view->cat_aside = $catDAO->listCategories ();
  41. $this->view->nb_favorites = $entryDAO->countFavorites ();
  42. $this->view->nb_total = $entryDAO->count ();
  43. }
  44. public function changeModeAction () {
  45. $mode = Request::param ('mode');
  46. if ($mode == 'not_read') {
  47. Session::_param ('mode', 'not_read');
  48. } else {
  49. Session::_param ('mode', 'all');
  50. }
  51. Request::forward (array (), true);
  52. }
  53. public function loginAction () {
  54. $this->view->_useLayout (false);
  55. $url = 'https://verifier.login.persona.org/verify';
  56. $assert = Request::param ('assertion');
  57. $params = 'assertion=' . $assert . '&audience=' .
  58. urlencode (Url::display () . ':80');
  59. $ch = curl_init ();
  60. $options = array (
  61. CURLOPT_URL => $url,
  62. CURLOPT_RETURNTRANSFER => TRUE,
  63. CURLOPT_POST => 2,
  64. CURLOPT_POSTFIELDS => $params
  65. );
  66. curl_setopt_array ($ch, $options);
  67. $result = curl_exec ($ch);
  68. curl_close ($ch);
  69. $res = json_decode ($result, true);
  70. if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) {
  71. Session::_param ('mail', $res['email']);
  72. } else {
  73. $res = array ();
  74. $res['status'] = 'failure';
  75. $res['reason'] = 'L\'identifiant est invalide';
  76. }
  77. $this->view->res = json_encode ($res);
  78. }
  79. public function logoutAction () {
  80. $this->view->_useLayout (false);
  81. Session::_param ('mail');
  82. }
  83. }