public function get_index($id_article = 0)
 {
     $article = Model_Articles::getById($id_article);
     if (empty($article)) {
         $this->response->error('L\'article demandé est introuvable.', 404);
     } else {
         $this->displayDetails($article);
     }
 }
Example #2
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 #3
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;
 }
Example #4
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);
 }