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 static function display() { if (isset($_POST['submit_edit_blog'])) { if (\PFBC\Form::isValid($_POST['submit_edit_blog'])) { new EditAdminBlogFormProcess(); } Framework\Url\HeaderUrl::redirect(); } $oBlogModel = new BlogModel(); $iBlogId = (new Http())->get('id', 'int'); $sPostId = $oBlogModel->getPostId($iBlogId); $oPost = $oBlogModel->readPost($sPostId); if (!empty($oPost) && (new Str())->equals($iBlogId, $oPost->blogId)) { $oCategoriesData = $oBlogModel->getCategory(null, 0, 300); $aCategoriesName = array(); foreach ($oCategoriesData as $oId) { $aCategoriesName[$oId->categoryId] = $oId->name; } $aSelectedCategories = array(); $oCategoryId = $oBlogModel->getCategory($iBlogId, 0, 300); unset($oBlogModel); foreach ($oCategoryId as $iId) { $aSelectedCategories[] = $iId->categoryId; } $oForm = new \PFBC\Form('form_blog', 650); $oForm->configure(array('action' => '')); $oForm->addElement(new \PFBC\Element\Hidden('submit_edit_blog', 'form_blog')); $oForm->addElement(new \PFBC\Element\Token('edit_blog')); $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('blog', 'main', 'index') . '/<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.'), '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.'), '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 article:'), 'lang_id', array('value' => $oPost->langId, 'description' => t('EX: "en", "fr", "es", "jp"'), '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/*'))); /** Disable the cache for the thumbnail if the user modifies * */ (new Browser())->noCache(); $oForm->addElement(new \PFBC\Element\HTMLExternal('<p><br /><img src="' . Blog::getThumb($oPost->blogId) . '" alt="' . t('Thumbnail') . '" title="' . t('The current thumbnail of your post.') . '" class="avatar" /></p>')); if (is_file(PH7_PATH_PUBLIC_DATA_SYS_MOD . 'blog/' . PH7_IMG . $iBlogId . '/thumb.png')) { $oForm->addElement(new \PFBC\Element\HTMLExternal('<a href="' . Uri::get('note', 'main', 'removethumb', $oPost->blogId . (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, 200), 'required' => 1))); $oForm->addElement(new \PFBC\Element\Textbox(t('Description (meta tag):'), 'meta_description', array('value' => $oPost->metaDescription, 'validation' => new \PFBC\Validation\Str(2, 200)))); $oForm->addElement(new \PFBC\Element\Textbox(t('Keywords (meta tag):'), 'meta_keywords', array('description' => t('Separate keywords by commas.'), 'value' => $oPost->metaKeywords, 'validation' => new \PFBC\Validation\Str(2, 200)))); $oForm->addElement(new \PFBC\Element\Textbox(t('Robots (meta tag):'), 'meta_robots', array('value' => $oPost->metaRobots, 'validation' => new \PFBC\Validation\Str(2, 50)))); $oForm->addElement(new \PFBC\Element\Textbox(t('Author (meta tag):'), 'meta_author', array('value' => $oPost->metaAuthor, 'validation' => new \PFBC\Validation\Str(2, 50)))); $oForm->addElement(new \PFBC\Element\Textbox(t('Copyright (meta tag):'), 'meta_copyright', array('value' => $oPost->metaCopyright, 'validation' => new \PFBC\Validation\Str(2, 50)))); $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 . 'blog/' . 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>'; } }
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!')); }