From fe53b336aa0335579b7a2330237754930a48556c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 2 May 2016 16:33:12 +0200 Subject: [PATCH] Fixed page editing --- .../files/lib/acp/form/PageAddForm.class.php | 43 ++++++++++-------- .../files/lib/acp/form/PageEditForm.class.php | 45 ++++++++++++++----- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php index e405afd117..335258b476 100644 --- a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php @@ -144,23 +144,7 @@ class PageAddForm extends AbstractForm { public function readParameters() { parent::readParameters(); - // work-around to force adding pages via dialog overlay - if (empty($_POST) && !isset($_GET['pageType'])) { - HeaderUtil::redirect(LinkHandler::getInstance()->getLink('PageList', ['showPageAddDialog' => 1])); - exit; - } - - if (!empty($_REQUEST['isMultilingual'])) $this->isMultilingual = 1; - if (!empty($_REQUEST['pageType'])) $this->pageType = $_REQUEST['pageType']; - - if ($this->action == 'add') { - try { - $this->validatePageType(); - } - catch (UserInputException $e) { - throw new IllegalLinkException(); - } - } + $this->readPageType(); // get available applications $applicationList = new ApplicationList(); @@ -174,6 +158,29 @@ class PageAddForm extends AbstractForm { $this->availableBoxes = $boxList->getObjects(); } + /** + * Reads basic page parameters controlling type and i18n. + * + * @throws IllegalLinkException + */ + protected function readPageType() { + if (!empty($_REQUEST['isMultilingual'])) $this->isMultilingual = 1; + if (!empty($_REQUEST['pageType'])) $this->pageType = $_REQUEST['pageType']; + + // work-around to force adding pages via dialog overlay + if (empty($_POST) && $this->pageType == '') { + HeaderUtil::redirect(LinkHandler::getInstance()->getLink('PageList', ['showPageAddDialog' => 1])); + exit; + } + + try { + $this->validatePageType(); + } + catch (UserInputException $e) { + throw new IllegalLinkException(); + } + } + /** * @inheritDoc */ @@ -232,7 +239,7 @@ class PageAddForm extends AbstractForm { * Validates page type. */ protected function validatePageType() { - if (!in_array($this->pageType, Page::$availablePageTypes) || ($this->action == 'add' && $this->pageType == 'system')) { + if (!in_array($this->pageType, Page::$availablePageTypes) || $this->pageType == 'system') { throw new UserInputException('pageType'); } diff --git a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php index a81b81e22e..b0c1d27a8d 100644 --- a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php @@ -34,7 +34,7 @@ class PageEditForm extends PageAddForm { * page object * @var Page */ - public $page = null; + public $page; /** * @inheritDoc @@ -50,6 +50,13 @@ class PageEditForm extends PageAddForm { if ($this->page->isMultilingual) $this->isMultilingual = 1; } + /** + * @inheritDoc + */ + protected function readPageType() { + // not required for editing + } + /** * @inheritDoc */ @@ -69,6 +76,13 @@ class PageEditForm extends PageAddForm { } } + /** + * @inheritDoc + */ + protected function validatePageType() { + // type is immutable + } + /** * @inheritDoc */ @@ -84,43 +98,50 @@ class PageEditForm extends PageAddForm { public function save() { AbstractForm::save(); - $data = array( + $data = [ 'name' => $this->name, 'isDisabled' => ($this->isDisabled) ? 1 : 0, 'lastUpdateTime' => TIME_NOW, 'parentPageID' => ($this->parentPageID ?: null), 'applicationPackageID' => $this->applicationPackageID - ); + ]; if ($this->pageType == 'system') { $data['controllerCustomURL'] = (!empty($_POST['customURL'][0]) ? $_POST['customURL'][0] : ''); - $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, $data), 'boxToPage' => $this->getBoxToPage())); + $this->objectAction = new PageAction([$this->page], 'update', [ + 'data' => array_merge($this->additionalFields, $data), + 'boxToPage' => $this->getBoxToPage() + ]); $this->objectAction->executeAction(); } else { - $content = array(); + $content = []; if ($this->page->isMultilingual) { foreach (LanguageFactory::getInstance()->getLanguages() as $language) { - $content[$language->languageID] = array( + $content[$language->languageID] = [ 'customURL' => (!empty($_POST['customURL'][$language->languageID]) ? $_POST['customURL'][$language->languageID] : ''), 'title' => (!empty($_POST['title'][$language->languageID]) ? $_POST['title'][$language->languageID] : ''), 'content' => (!empty($_POST['content'][$language->languageID]) ? $_POST['content'][$language->languageID] : ''), 'metaDescription' => (!empty($_POST['metaDescription'][$language->languageID]) ? $_POST['metaDescription'][$language->languageID] : ''), 'metaKeywords' => (!empty($_POST['metaKeywords'][$language->languageID]) ? $_POST['metaKeywords'][$language->languageID] : '') - ); + ]; } } else { - $content[0] = array( + $content[0] = [ 'customURL' => (!empty($_POST['customURL'][0]) ? $_POST['customURL'][0] : ''), 'title' => (!empty($_POST['title'][0]) ? $_POST['title'][0] : ''), 'content' => (!empty($_POST['content'][0]) ? $_POST['content'][0] : ''), 'metaDescription' => (!empty($_POST['metaDescription'][0]) ? $_POST['metaDescription'][0] : ''), 'metaKeywords' => (!empty($_POST['metaKeywords'][0]) ? $_POST['metaKeywords'][0] : '') - ); + ]; } - $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, $data), 'content' => $content, 'boxToPage' => $this->getBoxToPage())); + $this->objectAction = new PageAction([$this->page], 'update', [ + 'data' => array_merge($this->additionalFields, $data), + 'content' => $content, + 'boxToPage' => $this->getBoxToPage() + ]); $this->objectAction->executeAction(); } @@ -181,10 +202,10 @@ class PageEditForm extends PageAddForm { public function assignVariables() { parent::assignVariables(); - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'action' => 'edit', 'pageID' => $this->pageID, 'page' => $this->page - )); + ]); } } -- 2.20.1