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 get_index()
 {
     $tpl_articles = null;
     $my_articles = $this->_currentUser->getArticles();
     if ($my_articles->isEmpty()) {
         $tpl_articles = \Eliya\Tpl::get('admin/articles/none');
     } else {
         $tpl_articles = \Eliya\Tpl::get('admin/articles/list', ['articles' => $my_articles]);
     }
     $this->response->set(\Eliya\Tpl::get('admin/articles/index', ['tpl_articles' => $tpl_articles, 'categories' => Model_Categories::getAll()]));
 }
 public function get_index()
 {
     $tpl_categories = null;
     $all_categories = Model_Categories::getAll();
     if ($all_categories->isEmpty()) {
         $tpl_categories = \Eliya\Tpl::get('admin/categories/none');
     } else {
         $tpl_categories = \Eliya\Tpl::get('admin/categories/list', ['all_categories' => $all_categories]);
     }
     $tpl_form = \Eliya\Tpl::get('admin/categories/form', ['edit_mode' => false, 'end_action_url' => '']);
     $this->response->set(\Eliya\Tpl::get('admin/categories/index', ['tpl_categories' => $tpl_categories, 'tpl_form' => $tpl_form]));
 }
 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 post_index($username, $email, $id_group)
 {
     $checkExisting = Model_Users::createRequest()->where('username = ? OR email = ?', [$username, $email])->exec();
     if (!$checkExisting->isEmpty()) {
         $this->response->error('Un utilisateur avec ce pseudo ou cette adresse existe déjà.', 403);
         return;
     }
     $password = Library_String::generatePassword();
     $group = Model_Groups::getById($id_group);
     Model_Users::add(new Model_Users($username, $email, $password, $group));
     $email_content = \Eliya\Tpl::get('emails/register', ['username' => $username, 'email' => $email, 'password' => $password, 'login_url' => BASE_URL . 'admin/login']);
     Library_Email::send($email, 'Bienvenue sur Le Chomp Enchaîné !', $email_content);
     $this->get_index();
 }
 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]));
 }
Example #7
0
 public function get_index($id = null)
 {
     $can_manage_categories = $this->_currentUser->hasPermission(Model_Groups::PERM_MANAGE_CATEGORIES);
     if (!$can_manage_categories) {
         $this->response->error('Vous ne pouvez pas modifier cette catégorie.', 403);
         return;
     }
     $category = Model_Categories::getById($id);
     if (empty($category)) {
         $this->response->status(404)->redirectToFullErrorPage(false)->set(\Eliya\Tpl::get('admin/categories/edit/not_found'));
         return;
     }
     $tpl_form = \Eliya\Tpl::get('admin/categories/form', ['edit_mode' => true, 'category_name' => $category->prop('name'), 'category_description' => $category->prop('description'), 'category_picture' => $category->getMainPictureURL(), 'end_action_url' => 'edit?id=' . $id]);
     $this->response->set(\Eliya\Tpl::get('admin/categories/edit/index', ['tpl_form' => $tpl_form]));
 }
Example #8
0
 public function get_index($id = null)
 {
     // Force to edit the current user if they don't have the proper permissions
     if (!$this->_currentUser->hasPermission(Model_Groups::PERM_MANAGE_USERS)) {
         $id = $this->_currentUser->getId();
     } else {
         $groups = Model_Groups::getAll();
     }
     $user = Model_Users::getById($id);
     if (!$user) {
         $this->response->error("L'utilisateur demandé n'existe pas !", 404);
         return;
     }
     $this->response->set(\Eliya\Tpl::get('admin/users/edit/index', ['edit_current' => $id == $this->_currentUser->getId(), 'user' => $user, 'usergroup' => $user->load('usergroup'), 'groups' => isset($groups) ? $groups : null]));
 }
 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]));
 }
Example #10
0
 public function get_index($unused_param = 0)
 {
     $this->response->type(\Eliya\Mime::XML)->isRaw(true);
     $categories = Model_Categories::getAll();
     $categoriesIdsToNames = [];
     foreach ($categories as $category) {
         $categoriesIdsToNames[$category->getId()] = $category->prop('name');
     }
     $authors = Model_Users::getAll();
     $authorsIdsToNames = [];
     foreach ($authors as $author) {
         $authorsIdsToNames[$author->getId()] = $author->prop('username');
     }
     $tpl_items = null;
     $articles = Model_Articles::getLast(1, self::ARTICLES_BY_PAGE);
     foreach ($articles as $article) {
         $tpl_items .= \Eliya\Tpl::get('rss/item_article', ['article' => $article, 'author' => $authorsIdsToNames[$article->id_author] ?: null, 'category' => $categoriesIdsToNames[$article->id_category] ?: null]);
     }
     $this->response->set(\Eliya\Tpl::get('rss/index', ['tpl_items' => $tpl_items]));
 }
Example #11
0
 protected function setPublishStatus($id, $published)
 {
     $article = Model_Articles::getById($id);
     if (empty($article)) {
         $this->response->status(404)->redirectToFullErrorPage(false)->set(\Eliya\Tpl::get('admin/articles/edit/not_found'));
         return;
     }
     $author_is_current_user = $article->load('author')->equals($this->_currentUser);
     $can_publish_other_articles = $this->_currentUser->hasPermission(Model_Groups::PERM_PUBLISH_OTHER_ARTICLES);
     if (!$author_is_current_user && !$can_publish_other_articles) {
         $this->response->error('Vous ne pouvez pas modifier la publication de cet article.', 403);
         return;
     }
     $date_publication = $article->prop('date_publication');
     if ($published && empty($date_publication)) {
         $article->prop('date_publication', $_SERVER['REQUEST_TIME']);
     }
     $article->prop('is_published', $published);
     // Don't forget to load category to not erase it!
     $article->load('category');
     Model_Articles::update($article);
     $this->response->redirect($this->request->getBaseURL() . 'articles?id_article=' . $id, 200);
 }
Example #12
0
 public function get_index($unused_param = 0)
 {
     $this->response->set(\Eliya\Tpl::get('about/index'));
 }
Example #13
0
//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);
Example #14
0
 public function __init()
 {
     $this->_currentUser = Model_Users::getCurrentUser();
     \Eliya\Tpl::set('currentUser', $this->_currentUser);
 }