public function __construct()
 {
     parent::__construct();
     $oCommentModel = new CommentModel();
     $sComment = $this->httpRequest->post('comment');
     $sCurrentTime = $this->dateTime->get()->dateTime('Y-m-d H:i:s');
     $iTimeDelay = (int) DbConfig::getSetting('timeDelaySendComment');
     $sTable = $this->httpRequest->get('table');
     $iRecipientId = $this->httpRequest->get('recipient', 'int');
     $iSenderId = (int) $this->session->get('member_id');
     if (!$oCommentModel->idExists($iRecipientId, $sTable)) {
         \PFBC\Form::setError('form_comment', t('The comment recipient does not exists.'));
     } elseif (!$oCommentModel->checkWaitSend($iSenderId, $iTimeDelay, $sCurrentTime, $sTable)) {
         \PFBC\Form::setError('form_comment', Form::waitWriteMsg($iTimeDelay));
     } elseif ($oCommentModel->isDuplicateContent($iSenderId, $sComment, $sTable)) {
         \PFBC\Form::setError('form_comment', Form::duplicateContentMsg());
     } else {
         if (!$oCommentModel->add($sComment, $iRecipientId, $iSenderId, 1, $sCurrentTime, $sTable)) {
             \PFBC\Form::setError('form_comment', t('Oops! Error when adding comment.'));
         } else {
             /* Clean All Data of CommentModel Cache */
             (new Framework\Cache\Cache())->start(CommentCoreModel::CACHE_GROUP, null, null)->clear();
             HeaderUrl::redirect(Uri::get('comment', 'comment', 'read', $sTable . ',' . $iRecipientId), t('The comment has been sent successfully!'));
         }
     }
     unset($oCommentModel);
 }
 public function __construct()
 {
     parent::__construct();
     $oForumModel = new ForumModel();
     $sMessage = $this->httpRequest->post('message', Http::ONLY_XSS_CLEAN);
     $sCurrentTime = $this->dateTime->get()->dateTime('Y-m-d H:i:s');
     $iTimeDelay = (int) DbConfig::getSetting('timeDelaySendForumTopic');
     $iProfileId = (int) $this->session->get('member_id');
     $iForumId = $this->httpRequest->get('forum_id', 'int');
     if (!$oForumModel->checkWaitTopic($iProfileId, $iTimeDelay, $sCurrentTime)) {
         \PFBC\Form::setError('form_msg', Form::waitWriteMsg($iTimeDelay));
     } elseif ($oForumModel->isDuplicateTopic($iProfileId, $sMessage)) {
         \PFBC\Form::setError('form_msg', Form::duplicateContentMsg());
     } else {
         $oForumModel->addTopic($iProfileId, $iForumId, $this->httpRequest->post('title'), $sMessage, $sCurrentTime);
         Header::redirect(Uri::get('forum', 'forum', 'post', $this->httpRequest->get('forum_name') . ',' . $iForumId . ',' . $this->httpRequest->post('title') . ',' . Db::getInstance()->lastInsertId()), t('Your message has been added successfully!'));
     }
     unset($oForumModel);
 }
 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();
     $oUserModel = new UserCoreModel();
     $oMailModel = new MailModel();
     $bIsAdmin = AdminCore::auth() && !UserCore::auth() && !$this->session->exists('login_user_as');
     $sMessage = $this->httpRequest->post('message', Http::ONLY_XSS_CLEAN);
     $sCurrentTime = $this->dateTime->get()->dateTime('Y-m-d H:i:s');
     $iTimeDelay = (int) DbConfig::getSetting('timeDelaySendMail');
     $sRecipient = $this->httpRequest->post('recipient');
     $iRecipientId = $oUserModel->getId(null, $sRecipient);
     $iSenderId = (int) ($bIsAdmin ? PH7_ADMIN_ID : $this->session->get('member_id'));
     if ($iSenderId == $iRecipientId) {
         \PFBC\Form::setError('form_compose_mail', t('Oops! You can not send a message to yourself.'));
     } elseif ($sRecipient == PH7_ADMIN_USERNAME) {
         \PFBC\Form::setError('form_compose_mail', t('Oops! You cannot reply to administrator! If you want to contact us, please use our <a href="%0%">contact form</a>.', Uri::get('contact', 'contact', 'index')));
     } elseif (!(new ExistsCoreModel())->id($iRecipientId, 'Members')) {
         \PFBC\Form::setError('form_compose_mail', t('Oops! The username "%0%" does not exist.', escape(substr($this->httpRequest->post('recipient'), 0, PH7_MAX_USERNAME_LENGTH), true)));
     } elseif (!$bIsAdmin && !$oMailModel->checkWaitSend($iSenderId, $iTimeDelay, $sCurrentTime)) {
         \PFBC\Form::setError('form_compose_mail', Form::waitWriteMsg($iTimeDelay));
     } elseif (!$bIsAdmin && $oMailModel->isDuplicateContent($iSenderId, $sMessage)) {
         \PFBC\Form::setError('form_compose_mail', Form::duplicateContentMsg());
     } else {
         $mSendMsg = $oMailModel->sendMsg($iSenderId, $iRecipientId, $this->httpRequest->post('title'), $sMessage, $sCurrentTime);
         if (false === $mSendMsg) {
             \PFBC\Form::setError('form_compose_mail', t('Problem while sending the message. Please try again later.'));
         } else {
             // If the notification is accepted and the message recipient isn't connected NOW, we send a message.
             if (!$oUserModel->isNotification($iRecipientId, 'newMsg') && $oUserModel->isOnline($iRecipientId, 0)) {
                 $this->view->content = t('Hello %0%!<br />You have received a new message from <strong>%1%</strong>.<br /> <a href="%2%">Click here</a> to read your message.', $this->httpRequest->post('recipient'), $this->session->get('member_username'), Uri::get('mail', 'main', 'inbox', $mSendMsg));
                 $sRecipientEmail = $oUserModel->getEmail($iRecipientId);
                 $sMessageHtml = $this->view->parseMail(PH7_PATH_SYS . 'global/' . PH7_VIEWS . PH7_TPL_NAME . '/mail/sys/mod/mail/new_msg.tpl', $sRecipientEmail);
                 $aInfo = ['to' => $sRecipientEmail, 'subject' => t('New private message from %0% on %site_name%', $this->session->get('member_first_name'))];
                 (new Mail())->send($aInfo, $sMessageHtml);
             }
             $sUrl = $bIsAdmin ? Uri::get(PH7_ADMIN_MOD, 'user', 'browse') : Uri::get('mail', 'main', 'index');
             Header::redirect($sUrl, t('Your message has been sent successfully!'));
         }
         unset($oUserModel, $oMailModel);
     }
 }