'javascript', 'a' => 'main'))); View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'actualize'))); $entryDAO = new EntryDAO (); $feedDAO = new FeedDAO (); $catDAO = new CategoryDAO (); $error = false; // pour optimiser $page = Request::param ('page', 1); $entryDAO->_nbItemsPerPage ($this->view->conf->postsPerPage ()); $entryDAO->_currentPage ($page); // récupération de la catégorie/flux à filtrer $this->initFilter (); // Compte le nombre d'articles non lus en prenant en compte le filtre $this->countNotRead (); // mode de vue (tout ou seulement non lus) $this->initCurrentMode (); // ordre de listage des flux $order = Session::param ('order', $this->view->conf->sortOrder ()); // recherche sur les titres (pour le moment) $search = Request::param ('search'); // Récupère les flux par catégorie, favoris ou tous if ($this->get['type'] == 'all') { $entries = $entryDAO->listEntries ($this->mode, $search, $order); View::prependTitle (Translate::t ('your_rss_feeds') . ' - '); } elseif ($this->get['type'] == 'favoris') { $entries = $entryDAO->listFavorites ($this->mode, $search, $order); View::prependTitle (Translate::t ('your_favorites') . ' - '); } elseif ($this->get['type'] == 'public') { $entries = $entryDAO->listPublic ($this->mode, $search, $order); View::prependTitle (Translate::t ('public') . ' - '); } elseif ($this->get != false) { if ($this->get['type'] == 'c') { $cat = $catDAO->searchById ($this->get['filter']); if ($cat) { $entries = $entryDAO->listByCategory ($this->get['filter'], $this->mode, $search, $order); View::prependTitle ($cat->name () . ' - '); } else { $error = true; } } elseif ($this->get['type'] == 'f') { $feed = $feedDAO->searchById ($this->get['filter']); if ($feed) { $entries = $entryDAO->listByFeed ($this->get['filter'], $this->mode, $search, $order); $this->view->get_c = $feed->category (); View::prependTitle ($feed->name () . ' - '); } else { $error = true; } } else { $error = true; } } else { $error = true; } if ($error) { Error::error ( 404, array ('error' => array (Translate::t ('page_not_found'))) ); } else { $this->view->mode = $this->mode; $this->view->order = $order; try { $this->view->entryPaginator = $entryDAO->getPaginator ($entries); } catch (CurrentPagePaginationException $e) { } $this->view->cat_aside = $catDAO->listCategories (); $this->view->nb_favorites = $entryDAO->countFavorites (); $this->view->nb_total = $entryDAO->count (); if (Request::param ('output', '') == 'rss') { $this->view->_useLayout (false); } } } public function aboutAction () { View::prependTitle (Translate::t ('about') . ' - '); } public function changeModeAction () { $mode = Request::param ('mode'); if ($mode == 'not_read') { Session::_param ('mode', 'not_read'); } else { Session::_param ('mode', 'all'); } Request::forward (array (), true); } public function changeOrderAction () { $order = Request::param ('order'); if ($order == 'low_to_high') { Session::_param ('order', 'low_to_high'); } else { Session::_param ('order', 'high_to_low'); } Request::forward (array (), true); } public function loginAction () { $this->view->_useLayout (false); $url = 'https://verifier.login.persona.org/verify'; $assert = Request::param ('assertion'); $params = 'assertion=' . $assert . '&audience=' . urlencode (Url::display () . ':80'); $ch = curl_init (); $options = array ( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_POST => 2, CURLOPT_POSTFIELDS => $params ); curl_setopt_array ($ch, $options); $result = curl_exec ($ch); curl_close ($ch); $res = json_decode ($result, true); if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) { Session::_param ('mail', $res['email']); } else { $res = array (); $res['status'] = 'failure'; $res['reason'] = Translate::t ('invalid_login'); } $this->view->res = json_encode ($res); } public function logoutAction () { $this->view->_useLayout (false); Session::_param ('mail'); } private function initFilter () { $get = Request::param ('get'); $this->view->get_c = false; $this->view->get_f = false; $typeGet = $get[0]; $filter = substr ($get, 2); if ($get == 'favoris') { $this->view->get_c = $get; $this->get = array ( 'type' => $get, 'filter' => $get ); } elseif ($get == 'public') { $this->view->get_c = $get; $this->get = array ( 'type' => $get, 'filter' => $get ); } elseif ($get == false) { $this->get = array ( 'type' => 'all', 'filter' => 'all' ); } else { if ($typeGet == 'f') { $this->view->get_f = $filter; $this->get = array ( 'type' => $typeGet, 'filter' => $filter ); } elseif ($typeGet == 'c') { $this->view->get_c = $filter; $this->get = array ( 'type' => $typeGet, 'filter' => $filter ); } else { $this->get = false; } } } private function countNotRead () { $entryDAO = new EntryDAO (); if ($this->get != false) { if ($this->get['type'] == 'all') { $this->nb_not_read = $this->view->nb_not_read; } elseif ($this->get['type'] == 'favoris') { $this->nb_not_read = $entryDAO->countNotReadFavorites (); } elseif ($this->get['type'] == 'c') { $this->nb_not_read = $entryDAO->countNotReadByCat ($this->get['filter']); } elseif ($this->get['type'] == 'f') { $this->nb_not_read = $entryDAO->countNotReadByFeed ($this->get['filter']); } } } private function initCurrentMode () { $default_view = $this->view->conf->defaultView (); $mode = Session::param ('mode'); if ($mode == false) { if ($default_view == 'not_read' && $this->nb_not_read < 1) { $mode = 'all'; } else { $mode = $default_view; } } $this->mode = $mode; } }