Exemplo n.º 1
0
 public static function display()
 {
     if (isset($_POST['submit_edit_note'])) {
         if (\PFBC\Form::isValid($_POST['submit_edit_note'])) {
             new EditNoteFormProcess();
         }
         Framework\Url\Header::redirect();
     }
     // Generate edit form post of the note
     $oNoteModel = new NoteModel();
     $iNoteId = (new Http())->get('id', 'int');
     $iProfileId = (new Session())->get('member_id');
     $sPostId = $oNoteModel->getPostId($iNoteId);
     $oPost = $oNoteModel->readPost($sPostId, $iProfileId);
     if (!empty($oPost) && (new Str())->equals($iNoteId, $oPost->noteId)) {
         $oCategoriesData = $oNoteModel->getCategory(null, 0, 300);
         $aCategoriesName = array();
         foreach ($oCategoriesData as $oId) {
             $aCategoriesName[$oId->categoryId] = $oId->name;
         }
         $aSelectedCategories = array();
         $oCategoryId = $oNoteModel->getCategory($iNoteId, 0, 300);
         unset($oNoteModel);
         foreach ($oCategoryId as $iId) {
             $aSelectedCategories[] = $iId->categoryId;
         }
         $oForm = new \PFBC\Form('form_note', 650);
         $oForm->configure(array('action' => ''));
         $oForm->addElement(new \PFBC\Element\Hidden('submit_edit_note', 'form_note'));
         $oForm->addElement(new \PFBC\Element\Token('edit_note'));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Title of article:'), 'title', array('value' => $oPost->title, 'validation' => new \PFBC\Validation\Str(2, 100), 'required' => 1)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Article ID:'), 'post_id', array('value' => $oPost->postId, 'description' => Uri::get('note', 'main', 'read', (new Session())->get('member_username')) . '/<strong><span class="your-address">' . $oPost->postId . '</span><span class="post_id"></span></strong>', 'title' => t('Article ID will be the name of the url.'), 'data-profile_id' => $iProfileId, 'id' => 'post_id', 'validation' => new \PFBC\Validation\Str(2, 60), 'required' => 1)));
         $oForm->addElement(new \PFBC\Element\HTMLExternal('<div class="label_flow">'));
         $oForm->addElement(new \PFBC\Element\Checkbox(t('Categories:'), 'category_id', $aCategoriesName, array('description' => t('Select a category that best fits your article. You can select up to three different categories'), 'value' => $aSelectedCategories, 'required' => 1)));
         $oForm->addElement(new \PFBC\Element\HTMLExternal('</div>'));
         $oForm->addElement(new \PFBC\Element\CKEditor(t('Contents:'), 'content', array('value' => $oPost->content, 'description' => t('Content of the article'), 'validation' => new \PFBC\Validation\Str(30), 'required' => 1)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('The language of your post:'), 'lang_id', array('value' => $oPost->langId, 'description' => t('EX: "en", "fr", "es", "js"'), 'validation' => new \PFBC\Validation\Str(2, 2), 'required' => 1)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Slogan:'), 'slogan', array('value' => $oPost->slogan, 'validation' => new \PFBC\Validation\Str(2, 200))));
         $oForm->addElement(new \PFBC\Element\File(t('Thumbnail:'), 'thumb', array('accept' => 'image/*')));
         if (!empty($oPost->thumb)) {
             $oForm->addElement(new \PFBC\Element\HTMLExternal('<p><br /><img src="' . PH7_URL_DATA_SYS_MOD . 'note/' . PH7_IMG . $oPost->username . PH7_SH . $oPost->thumb . '" alt="' . t('Thumbnail') . '" title="' . t('The current thumbnail of your post.') . '" class="avatar" /></p>'));
         }
         if (!empty($oPost->thumb)) {
             $oForm->addElement(new \PFBC\Element\HTMLExternal('<a href="' . Uri::get('note', 'main', 'removethumb', $oPost->noteId . (new Token())->url(), false) . '">' . t('Remove this thumbnail?') . '</a>'));
         }
         $oForm->addElement(new \PFBC\Element\Textbox(t('Tags:'), 'tags', array('value' => $oPost->tags, 'description' => t('Separate keywords by commas and without spaces between the commas.'), 'validation' => new \PFBC\Validation\Str(2, 200))));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Title (meta tag):'), 'page_title', array('value' => $oPost->pageTitle, 'validation' => new \PFBC\Validation\Str(2, 100), 'required' => 1)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Description (meta tag):'), 'meta_description', array('validation' => new \PFBC\Validation\Str(2, 200), 'value' => $oPost->metaDescription)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Keywords (meta tag):'), 'meta_keywords', array('description' => t('Separate keywords by commas and without spaces between the commas.'), 'validation' => new \PFBC\Validation\Str(2, 200), 'value' => $oPost->metaKeywords)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Robots (meta tag):'), 'meta_robots', array('validation' => new \PFBC\Validation\Str(2, 50), 'value' => $oPost->metaRobots)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Author (meta tag):'), 'meta_author', array('validation' => new \PFBC\Validation\Str(2, 50), 'value' => $oPost->metaAuthor)));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Copyright (meta tag):'), 'meta_copyright', array('validation' => new \PFBC\Validation\Str(2, 50), 'value' => $oPost->metaCopyright)));
         $oForm->addElement(new \PFBC\Element\Radio(t('Enable Comment:'), 'enable_comment', array('1' => t('Enable'), '0' => t('Disable')), array('value' => $oPost->enableComment, 'required' => 1)));
         $oForm->addElement(new \PFBC\Element\Button());
         $oForm->addElement(new \PFBC\Element\HTMLExternal('<script src="' . PH7_URL_TPL_SYS_MOD . 'note/' . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_JS . 'common.js"></script>'));
         $oForm->render();
     } else {
         echo '<p class="center bold">' . t('Post Not Found!') . '</p>';
     }
 }
Exemplo n.º 2
0
 /**
  * Sets the Note Thumbnail.
  *
  * @param object $oPost
  * @param \PH7\NoteModel $oNoteModel
  * @param \PH7\Framework\File\File $oFile
  * @return void
  */
 public function setThumb($oPost, NoteModel $oNoteModel, Framework\File\File $oFile)
 {
     if (!empty($_FILES['thumb']['tmp_name'])) {
         $oImage = new Framework\Image\Image($_FILES['thumb']['tmp_name']);
         if (!$oImage->validate()) {
             \PFBC\Form::setError('form_note', Form::wrongImgFileTypeMsg());
         } else {
             /**
              * The method deleteFile first test if the file exists, if so it delete the file.
              */
             $sPathName = PH7_PATH_PUBLIC_DATA_SYS_MOD . 'note/' . PH7_IMG . $oPost->username . PH7_SH;
             $oFile->deleteFile($sPathName);
             // It erases the old thumbnail
             $oFile->createDir($sPathName);
             $sFileName = Various::genRnd($oImage->getFileName(), 20) . PH7_DOT . $oImage->getExt();
             $oImage->square(100);
             $oImage->save($sPathName . $sFileName);
             $oNoteModel->updatePost('thumb', $sFileName, $oPost->noteId, $oPost->profileId);
         }
         unset($oImage);
     }
 }
 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);
 }