indexController.php 3.6 KB

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