public function __construct()
 {
     parent::__construct();
     $oBlog = new Blog();
     $oBlogModel = new BlogModel();
     if (!$oBlog->checkPostId($this->httpRequest->post('post_id'))) {
         \PFBC\Form::setError('form_blog', t('The ID of the article is invalid or incorrect.'));
     } else {
         $aData = ['post_id' => $this->httpRequest->post('post_id'), 'lang_id' => $this->httpRequest->post('lang_id'), 'title' => $this->httpRequest->post('title'), 'content' => $this->httpRequest->post('content', Http::ONLY_XSS_CLEAN), 'slogan' => $this->httpRequest->post('$slogan'), 'tags' => $this->httpRequest->post('tags'), 'page_title' => $this->httpRequest->post('page_title'), 'meta_description' => $this->httpRequest->post('meta_description'), 'meta_keywords' => $this->httpRequest->post('meta_keywords'), 'meta_robots' => $this->httpRequest->post('meta_robots'), 'meta_author' => $this->httpRequest->post('meta_author'), 'meta_copyright' => $this->httpRequest->post('meta_copyright'), 'enable_comment' => $this->httpRequest->post('enable_comment'), 'created_date' => $this->dateTime->get()->dateTime('Y-m-d H:i:s')];
         if (!$oBlogModel->addPost($aData)) {
             $this->sMsg = t('An error occurred while adding the article.');
         } else {
             /*** Set the categorie(s) ***/
             /**
              * WARNING: Be careful, you should use the \PH7\Framework\Mvc\Request\Http::ONLY_XSS_CLEAN constant, otherwise the Http::post() method
              * removes the special tags and damages the SQL queries for entry into the database.
              */
             $iBlogId = Db::getInstance()->lastInsertId();
             foreach ($this->httpRequest->post('category_id', Http::ONLY_XSS_CLEAN) as $iCategoryId) {
                 $oBlogModel->addCategory($iCategoryId, $iBlogId);
             }
             /*** Set the thumbnail if there's one ***/
             $oPost = $oBlogModel->readPost($aData['post_id']);
             $oBlog->setThumb($oPost, $this->file);
             /* Clean BlogModel Cache */
             (new Framework\Cache\Cache())->start(BlogModel::CACHE_GROUP, null, null)->clear();
             $this->sMsg = t('Post created successfully!');
         }
         Header::redirect(Uri::get('blog', 'main', 'read', $this->httpRequest->post('post_id')), $this->sMsg);
     }
 }
 public function __construct()
 {
     parent::__construct();
     $oBlog = new Blog();
     $oBlogModel = new BlogModel();
     $iBlogId = $this->httpRequest->get('id');
     $sPostId = $oBlogModel->getPostId($iBlogId);
     $oPost = $oBlogModel->readPost($sPostId);
     /*** Updating the ID of the post if it has changed ***/
     $sPostId = $this->httpRequest->post('post_id');
     if (!$this->str->equals($sPostId, $oPost->postId)) {
         if ($oBlog->checkPostId($sPostId)) {
             $oBlogModel->updatePost('postId', $sPostId, $iBlogId);
             /* Clean BlogModel Cache */
             (new Framework\Cache\Cache())->start(BlogModel::CACHE_GROUP, null, null)->clear();
         } else {
             \PFBC\Form::setError('form_blog', t('The ID of the article is invalid or incorrect.'));
         }
     }
     // WARNING: Be careful, you should use the \PH7\Framework\Mvc\Request\Http::ONLY_XSS_CLEAN constant, otherwise the Request\Http::post() method removes the special tags
     // and damages the SET function SQL for entry into the database.
     if (!$this->str->equals($this->httpRequest->post('category_id', Http::ONLY_XSS_CLEAN), $oPost->categoryId)) {
         $oBlogModel->deleteCategory($iBlogId);
         foreach ($this->httpRequest->post('category_id', Http::ONLY_XSS_CLEAN) as $iCategoryId) {
             $oBlogModel->addCategory($iCategoryId, $iBlogId);
         }
     }
     // Thumbnail
     $oBlog->setThumb($oPost, $this->file);
     if (!$this->str->equals($this->httpRequest->post('title'), $oPost->title)) {
         $oBlogModel->updatePost('title', $this->httpRequest->post('title'), $iBlogId);
     }
     // HTML contents, So we use the constant: \PH7\Framework\Mvc\Request\Http::ONLY_XSS_CLEAN
     if (!$this->str->equals($this->httpRequest->post('content', Http::ONLY_XSS_CLEAN), $oPost->content)) {
         $oBlogModel->updatePost('content', $this->httpRequest->post('content', Http::ONLY_XSS_CLEAN), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('lang_id'), $oPost->langId)) {
         $oBlogModel->updatePost('langId', $this->httpRequest->post('lang_id'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('slogan'), $oPost->slogan)) {
         $oBlogModel->updatePost('slogan', $this->httpRequest->post('slogan'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('tags'), $oPost->tags)) {
         $oBlogModel->updatePost('tags', $this->httpRequest->post('tags'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('page_title'), $oPost->pageTitle)) {
         $oBlogModel->updatePost('pageTitle', $this->httpRequest->post('page_title'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_description'), $oPost->metaDescription)) {
         $oBlogModel->updatePost('metaDescription', $this->httpRequest->post('meta_description'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_keywords'), $oPost->metaKeywords)) {
         $oBlogModel->updatePost('metaKeywords', $this->httpRequest->post('meta_keywords'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_robots'), $oPost->metaRobots)) {
         $oBlogModel->updatePost('metaRobots', $this->httpRequest->post('meta_robots'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_author'), $oPost->metaAuthor)) {
         $oBlogModel->updatePost('metaAuthor', $this->httpRequest->post('meta_author'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_copyright'), $oPost->metaCopyright)) {
         $oBlogModel->updatePost('metaCopyright', $this->httpRequest->post('meta_copyright'), $iBlogId);
     }
     if (!$this->str->equals($this->httpRequest->post('enable_comment'), $oPost->enableComment)) {
         $oBlogModel->updatePost('enableComment', $this->httpRequest->post('enable_comment'), $iBlogId);
     }
     // Updated the modification Date
     $oBlogModel->updatePost('updatedDate', $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $sPostId);
     unset($oBlogModel);
     /* Clean BlogModel Cache */
     (new Framework\Cache\Cache())->start(BlogModel::CACHE_GROUP, null, null)->clear();
     Header::redirect(Uri::get('blog', 'main', 'read', $sPostId), t('Your post has been saved successfully!'));
 }