private function displayDetails(Model_Articles $article) { if (empty($article)) { $this->response->error('L\'article demandé est introuvable.', 404); return; } $author = $article->load('author'); $isPublished = $article->prop('is_published'); $canReadUnpublished = $this->_currentUser->hasPermission(Model_Groups::PERM_READ_UNPUBLISHED_ARTICLES); if (!$isPublished && !$canReadUnpublished && !$this->_currentUser->equals($author)) { $this->response->error('L\'article demandé n\'est pas ou plus publié.', 403); return; } $canonical_url = $article->getUrl(); $og_article = ['publisher' => \Eliya\Config('main')->FACEBOOK['PAGE_URL'], 'category' => $article->load('category')->prop('name'), 'modified_time' => $article->prop('date_last_update'), 'published_time' => $article->prop('date_publication')]; Library_Facebook::setMetaOG(['og' => ['title' => $article->prop('title'), 'description' => $article->prop('introduction'), 'site_name' => \Eliya\Config('main')->SITE_NAME, 'url' => $canonical_url, 'image' => $article->getMainPictureURL(), 'type' => Library_Facebook::TYPE_ARTICLE, 'locale' => Library_Facebook::LOCALE_FR_FR], 'fb' => ['app_id' => \Eliya\Config('main')->FACEBOOK['APP_ID']], 'article' => $og_article]); \Eliya\Tpl::set('page_title', $article->prop('title')); \Eliya\Tpl::set('page_description', $article->prop('introduction')); \Eliya\Tpl::set('canonical_url', $canonical_url); $category = $article->prop('category'); $twitterDefaultText = $article->prop('title'); if ($category !== null) { $twitterDefaultText = $category->prop('name') . ' - ' . $twitterDefaultText; } $templateShareLinks = \Eliya\Tpl::get('articles/share_links', ['url' => $article->getUrl(), 'twitterDefaultText' => $twitterDefaultText]); $this->response->set(\Eliya\Tpl::get('articles/article', ['article' => $article, 'category' => $category, 'templateShareLinks' => $templateShareLinks])); }
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])); }
//Init DB require_once 'application/vendors/EntityPHP/src/EntityPHP.php'; $sql = \Eliya\Config('main')->SQL; //Handle received request $request = new \Eliya\Request($_SERVER['REQUEST_URI']); $current_url = $request->getProtocol() . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; define('BASE_URL', $request->getBaseURL()); define('STATIC_URL', \Eliya\Config('main')->STATIC_URL); define('PUBLIC_FOLDER_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR); if (substr($current_url, -1) !== '/') { $current_url .= '/'; } $page_description = 'Un site réalisé par des fans pour les fans de Nintendo. '; $page_description .= 'Retrouvez des articles en rapport avec Nintendo, que ce soit sur '; $page_description .= 'l\'actualité, des découvertes de jeux ou des dossiers sur divers sujets.'; \Eliya\Tpl::set(['page_title' => 'Le Chomp Enchainé', 'page_description' => $page_description, 'base_url' => BASE_URL, 'static_url' => STATIC_URL, 'current_url' => $current_url]); $response = $request->response(); try { if (!empty($sql)) { \EntityPHP\Core::connectToDB($sql['HOST'], $sql['USER'], $sql['PASSWORD'], $sql['DATABASE']); } else { throw new Exception('Impossible de se connecter à la base de données'); } $request->exec(); } catch (Exception $e) { ob_clean(); $response->set(null)->error($e->getMessage(), 500); } $response->render(); if ($response->isError()) { error_log("Error - " . $response->status() . " - Request: " . $_SERVER['REQUEST_URI'], 4);
public function __init() { $this->_currentUser = Model_Users::getCurrentUser(); \Eliya\Tpl::set('currentUser', $this->_currentUser); }