indexController.php 2.4 KB

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