Example #1
0
File: Main.php Project: FTTA/devels
 /**
  * The basic welcome message
  *
  * @access  public
  * @return  Response
  */
 public function action_index()
 {
     $lPage = Input::get('current_page', 1);
     $lArticles = Model_Articles::getAll($lPage, $this->lang);
     $lPagination = Pagination::forge('data_table', array('pagination_url' => '/main/index', 'total_items' => DB::count_last_query(), 'num_links' => 3, 'per_page' => \Config::get('db.items_per_page'), 'current_page' => $lPage, 'uri_segment' => 'current_page'))->render();
     $this->template->content = View::forge('index', ['articles' => $lArticles, 'pagination' => $lPagination], false);
     return $this->template;
     //return Response::forge(View::forge('welcome/index'));
 }
 public function remove()
 {
     $articles = $this->getArticles();
     // Change the author of each article to be able to keep it
     foreach ($articles as $article) {
         $article->prop('author', null);
         Model_Articles::update($article);
     }
     $this->deleteById($this->getId());
 }
 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 #4
0
 public function action_delete()
 {
     $lData = Input::post('article', null);
     if (empty($lData) || empty($lData['article_id']) || !is_numeric($lData['article_id'])) {
         die(json_encode(['status' => 'error', 'message' => 'Empty article data'], JSON_UNESCAPED_UNICODE));
     }
     $lResult = Model_Articles::getById($lData['article_id'], $this->lang);
     $lId = $lData['article_id'];
     unset($lData['article_id']);
     if ($lResult['user_id'] != $this->current_user['id'] && !$this->is_admin) {
         die(json_encode(['status' => 'error', 'message' => 'Permition denied. You have not rights to edit this article.'], JSON_UNESCAPED_UNICODE));
     }
     Model_Articles::edit(['is_deleted' => true], $lId);
     die(json_encode(['status' => 'ok'], JSON_UNESCAPED_UNICODE));
 }
Example #5
0
 public function action_edit()
 {
     $this->template->scripts[] = 'form_getter.js';
     $this->template->scripts[] = 'articles.js';
     $lArticleId = Input::get('article_id', null);
     if (empty($lArticleId) || !is_numeric($lArticleId)) {
         throw new Exception('Invalid article ID: ' . $lArticleId);
     }
     $lResult = Model_Articles::getById($lArticleId, $this->lang);
     if (empty($lResult)) {
         throw new Exception('Empty data, Sorry');
     }
     if ($lResult['user_id'] != $this->current_user['id'] && $this->current_user['role_id'] != AuthModule::UR_ADMIN) {
         throw new Exception('Permition denied. You have not rights to edit this article.');
     }
     $this->template->content = View::forge('article_add', ['article' => $lResult, 'edit_mode' => true]);
     return $this->template;
 }
 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 #7
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]));
 }
 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($title, $id_category)
 {
     $newArticle = new Model_Articles(['title' => $title, 'category' => Model_Categories::getById($id_category), 'author' => $this->_currentUser]);
     $newArticle = Model_Articles::add($newArticle);
     $this->response->redirect('articles/edit?id=' . $newArticle->getId(), 201);
 }
 public static function countByCategory(Model_Categories $category)
 {
     return Model_Articles::count('category.id = ? AND is_published = ?', [$category->getId(), 1]);
 }
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);
 }