public function __construct(Eliya\Response $response)
 {
     $error_message = $response->error();
     //If default message for non-existed page
     if (substr($error_message, 0, 10) === 'Controller') {
         $error_message = 'La page demandée ne peut être appelée de cette façon.';
     }
     $response->set(Eliya\Tpl::get('errors', ['error_number' => 405, 'message' => $error_message]));
 }
 public function post_index($email, $password)
 {
     $user = Model_Users::login($email, $password);
     if (empty($user)) {
         Eliya\Tpl::set('errorMessage', 'Vos identifiants sont incorrects.');
         $this->response->status(401)->redirectToFullErrorPage(false);
         $this->get_index();
         return;
     }
     $this->_currentUser = $user;
     \Eliya\Tpl::set('currentUser', $this->_currentUser);
     $this->response->redirect('articles', 200);
 }
 public function get_index($page = 1)
 {
     $articles = Model_Articles::getLast($page, self::ARTICLES_BY_PAGE);
     if ($articles->isEmpty()) {
         $this->response->set(\Eliya\Tpl::get('index/no_articles'));
         return;
     }
     $tpl_articles = Eliya\Tpl::get('common/articles/list', ['articles' => $articles]);
     $nbrPages = ceil(Model_Articles::count('is_published = ?', [1]) / self::ARTICLES_BY_PAGE);
     if ($page == 1) {
         \Eliya\Tpl::set('canonical_url', BASE_URL);
     }
     $this->response->set(\Eliya\Tpl::get('index/index', ['tpl_articles' => $tpl_articles, 'nbr_pages' => $nbrPages, 'current_page' => $page]));
 }
 private function displayDetails(Model_Categories $category, $page)
 {
     if (empty($category)) {
         $this->response->error('La catégorie demandée est introuvable.', 404);
         return;
     }
     \Eliya\Tpl::set('page_title', $category->prop('name'));
     $articles = Model_Articles::getLast($page, self::ARTICLES_BY_PAGE, $category);
     if ($articles->isEmpty()) {
         $this->response->set(\Eliya\Tpl::get('categories/no_articles', ['category' => $category]));
         return;
     }
     $tpl_articles = Eliya\Tpl::get('common/articles/list', ['articles' => $articles]);
     $nbrPages = ceil(Model_Articles::countByCategory($category) / self::ARTICLES_BY_PAGE);
     if ($page == 1) {
         \Eliya\Tpl::set('canonical_url', $category->getUrl());
     }
     $this->response->set(\Eliya\Tpl::get('categories/details', ['category' => $category, 'tpl_articles' => $tpl_articles, 'nbr_pages' => $nbrPages, 'current_page' => $page]));
 }
 public static function setMetaOG(array $metas)
 {
     $tpl_facebook_meta_og = null;
     $structure = self::_getMetaProperties();
     foreach ($metas as $type => $properties) {
         if (!isset($structure[$type])) {
             continue;
         }
         foreach ($properties as $property => $value) {
             if (!in_array($property, $structure[$type])) {
                 continue;
             }
             if (self::mustOgPropertyBeUrl($property) && parse_url($value, PHP_URL_SCHEME) === null) {
                 $value = 'https:' . $value;
             }
             $tpl_facebook_meta_og .= Eliya\Tpl::get('facebook/metas', ['type' => $type, 'property' => $property, 'value' => $value]);
         }
     }
     Eliya\Tpl::set('facebook_meta_og', $tpl_facebook_meta_og);
 }
 protected function _showAuthor($id_author)
 {
     $author = Model_Users::getById($id_author);
     if (empty($author)) {
         $this->response->error('L\'utilisateur demandé n\'existe pas ou plus.', 404);
         return;
     }
     $canReadUnpublished = $this->_currentUser->hasPermission(Model_Groups::PERM_READ_UNPUBLISHED_ARTICLES);
     if ($canReadUnpublished) {
         $articles = $author->getArticles();
     } else {
         $articles = $author->getPublishedArticles();
     }
     if ($articles->count() === 0) {
         $tpl_articles = Eliya\Tpl::get('authors/no_articles');
     } else {
         $tpl_articles = Eliya\Tpl::get('common/articles/list', ['articles' => $articles]);
     }
     $this->response->set(Eliya\Tpl::get('authors/details', ['author' => $author, 'tpl_articles' => $tpl_articles]));
 }
 public function __construct(Eliya\Response $response)
 {
     $response->set(Eliya\Tpl::get('errors', ['error_number' => 403, 'message' => $response->error()]));
 }