public function __construct()
 {
     parent::__construct();
     $oNote = new Note();
     $oNoteModel = new NoteModel();
     $sCurrentTime = $this->dateTime->get()->dateTime('Y-m-d H:i:s');
     $iProfileId = $this->session->get('member_id');
     $iTimeDelay = (int) DbConfig::getSetting('timeDelaySendNote');
     if (!$oNote->checkPostId($this->httpRequest->post('post_id'), $iProfileId)) {
         \PFBC\Form::setError('form_note', t('The ID of the article is invalid or incorrect.'));
     } elseif (!$oNoteModel->checkWaitSend($this->session->get('member_id'), $iTimeDelay, $sCurrentTime)) {
         \PFBC\Form::setError('form_note', Form::waitWriteMsg($iTimeDelay));
     } else {
         $iApproved = DbConfig::getSetting('noteManualApproval') == 0 ? '1' : '0';
         $aData = ['profile_id' => $iProfileId, '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' => $sCurrentTime, 'approved' => $iApproved];
         if (!$oNoteModel->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.
              */
             if (count($this->httpRequest->post('category_id', Http::ONLY_XSS_CLEAN)) > 3) {
                 \PFBC\Form::setError('form_note', t('You can not select more than 3 categories.'));
                 return;
                 // Stop execution of the method.
             }
             $iNoteId = Db::getInstance()->lastInsertId();
             foreach ($this->httpRequest->post('category_id', Http::ONLY_XSS_CLEAN) as $iCategoryId) {
                 $oNoteModel->addCategory($iCategoryId, $iNoteId, $iProfileId);
             }
             /*** Set the thumbnail if there's one ***/
             $oPost = $oNoteModel->readPost($aData['post_id'], $iProfileId, null);
             $oNote->setThumb($oPost, $oNoteModel, $this->file);
             /* Clean NoteModel Cache */
             (new Framework\Cache\Cache())->start(NoteModel::CACHE_GROUP, null, null)->clear();
             $this->sMsg = $iApproved == '0' ? t('Your Note has been received! But it will be visible once approved by our moderators. Please do not send a new Note because this is useless!') : t('Post created successfully!');
         }
         Header::redirect(Uri::get('note', 'main', 'read', $this->session->get('member_username') . ',' . $this->httpRequest->post('post_id')), $this->sMsg);
     }
 }
 public function __construct()
 {
     parent::__construct();
     $oNote = new Note();
     $oNoteModel = new NoteModel();
     $iNoteId = $this->httpRequest->get('id');
     $sPostId = $oNoteModel->getPostId($iNoteId);
     $sUsername = $this->session->get('member_username');
     $iProfileId = $this->session->get('member_id');
     $oPost = $oNoteModel->readPost($sPostId, $iProfileId);
     /*** Updating the ID of the post if it has changed ***/
     $sPostId = $this->httpRequest->post('post_id');
     if (!$this->str->equals($sPostId, $oPost->postId)) {
         if ($oNote->checkPostId($sPostId, $iProfileId)) {
             $oNoteModel->updatePost('postId', $sPostId, $iNoteId, $iProfileId);
             /* Clean NoteModel Cache */
             (new Framework\Cache\Cache())->start(NoteModel::CACHE_GROUP, null, null)->clear();
         } else {
             \PFBC\Form::setError('form_note', t('ID Article must be unique!'));
         }
     }
     // WARNING: Be careful, you should use the \PH7\Framework\Mvc\Request\Http::ONLY_XSS_CLEAN constant otherwise the post method of the HttpRequest class removes the tags special
     // 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)) {
         if (count($this->httpRequest->post('category_id', Http::ONLY_XSS_CLEAN)) > 3) {
             \PFBC\Form::setError('form_note', t('You can not select more than 3 categories.'));
             return;
             // Stop execution of the method.
         }
         $oNoteModel->deleteCategory($iNoteId);
         foreach ($this->httpRequest->post('category_id', Http::ONLY_XSS_CLEAN) as $iCategoryId) {
             $oNoteModel->addCategory($iCategoryId, $iNoteId, $iProfileId);
         }
     }
     // Thumbnail
     $oNote->setThumb($oPost, $oNoteModel, $this->file);
     if (!$this->str->equals($this->httpRequest->post('title'), $oPost->title)) {
         $oNoteModel->updatePost('title', $this->httpRequest->post('title'), $iNoteId, $iProfileId);
     }
     // 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)) {
         $oNoteModel->updatePost('content', $this->httpRequest->post('content', Http::ONLY_XSS_CLEAN), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('lang_id'), $oPost->langId)) {
         $oNoteModel->updatePost('langId', $this->httpRequest->post('lang_id'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('slogan'), $oPost->slogan)) {
         $oNoteModel->updatePost('slogan', $this->httpRequest->post('slogan'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('tags'), $oPost->tags)) {
         $oNoteModel->updatePost('tags', $this->httpRequest->post('tags'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('page_title'), $oPost->pageTitle)) {
         $oNoteModel->updatePost('pageTitle', $this->httpRequest->post('page_title'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_description'), $oPost->metaDescription)) {
         $oNoteModel->updatePost('metaDescription', $this->httpRequest->post('meta_description'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_keywords'), $oPost->metaKeywords)) {
         $oNoteModel->updatePost('metaKeywords', $this->httpRequest->post('meta_keywords'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_robots'), $oPost->metaRobots)) {
         $oNoteModel->updatePost('metaRobots', $this->httpRequest->post('meta_robots'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_author'), $oPost->metaAuthor)) {
         $oNoteModel->updatePost('metaAuthor', $this->httpRequest->post('meta_author'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('meta_copyright'), $oPost->metaCopyright)) {
         $oNoteModel->updatePost('metaCopyright', $this->httpRequest->post('meta_copyright'), $iNoteId, $iProfileId);
     }
     if (!$this->str->equals($this->httpRequest->post('enable_comment'), $oPost->enableComment)) {
         $oNoteModel->updatePost('enableComment', $this->httpRequest->post('enable_comment'), $iNoteId, $iProfileId);
     }
     // Updated the approved status
     $iApproved = DbConfig::getSetting('noteManualApproval') == 0 ? '1' : '0';
     $oNoteModel->updatePost('approved', $iApproved, $iNoteId, $iProfileId);
     // Updated the modification Date
     $oNoteModel->updatePost('updatedDate', $this->dateTime->get()->dateTime('Y-m-d H:i:s'), $iNoteId, $iProfileId);
     unset($oNote, $oNoteModel);
     /* Clean NoteModel Cache */
     (new Framework\Cache\Cache())->start(NoteModel::CACHE_GROUP, null, null)->clear();
     $sMsg = $iApproved == '0' ? t('Your Note has been received! But it will be visible once approved by our moderators. Please do not send a new Note because this is useless!') : t('Post created successfully!');
     Header::redirect(Uri::get('note', 'main', 'read', $sUsername . ',' . $sPostId), $sMsg);
 }