From 29f5f0eebed0e5ef67d598e528f312ebd7de0b08 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 12 Jul 2016 11:21:35 +0200 Subject: [PATCH] Fixed issue in validation of box position --- .../files/lib/acp/form/BoxAddForm.class.php | 41 +++++++++++++++++-- .../files/lib/acp/form/BoxEditForm.class.php | 33 +-------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php index b388b7180f..eacb9df4f1 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php @@ -11,6 +11,7 @@ use wcf\data\page\Page; use wcf\data\page\PageNodeTree; use wcf\form\AbstractForm; use wcf\system\acl\simple\SimpleAclHandler; +use wcf\system\box\IBoxController; use wcf\system\box\IConditionBoxController; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\IllegalLinkException; @@ -187,6 +188,12 @@ class BoxAddForm extends AbstractForm { */ public $availableBoxControllers = []; + /** + * list of available positions per box handler + * @var array + */ + public $availableBoxPositions = []; + /** * @inheritDoc */ @@ -208,6 +215,18 @@ class BoxAddForm extends AbstractForm { } $this->availableBoxControllers = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.boxController'); + $this->readBoxPositions(); + } + + /** + * Loads available box positions per box controller. + */ + protected function readBoxPositions() { + foreach ($this->availableBoxControllers as $boxController) { + /** @var IBoxController $controller */ + $controller = $boxController->getProcessor(); + $this->availableBoxPositions[$boxController->objectTypeID] = $controller::getSupportedPositions(); + } } /** @@ -307,9 +326,7 @@ class BoxAddForm extends AbstractForm { } // validate box position - if (!in_array($this->position, Box::$availablePositions)) { - throw new UserInputException('position'); - } + $this->validateBoxPosition(); // validate link if ($this->linkType == 'internal') { @@ -399,6 +416,21 @@ class BoxAddForm extends AbstractForm { } } + /** + * Validates the selected box position. + */ + protected function validateBoxPosition() { + if (!in_array($this->position, Box::$availablePositions)) { + throw new UserInputException('position'); + } + + if ($this->boxType == 'system') { + if (!in_array($this->position, $this->availableBoxPositions[$this->boxController->objectTypeID])) { + throw new UserInputException('position', 'invalid'); + } + } + } + /** * @inheritDoc */ @@ -507,7 +539,8 @@ class BoxAddForm extends AbstractForm { 'boxController' => $this->boxController, 'pageNodeList' => $this->pageNodeList, 'pageHandlers' => $this->pageHandlers, - 'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues) + 'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues), + 'availableBoxPositions' => $this->availableBoxPositions ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php index e95643eba7..45a861a29f 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php @@ -27,12 +27,6 @@ class BoxEditForm extends BoxAddForm { */ public $activeMenuItem = 'wcf.acp.menu.link.cms.box.list'; - /** - * list of available positions per box handler - * @var array - */ - public $availableBoxPositions = []; - /** * box id * @var integer @@ -61,19 +55,6 @@ class BoxEditForm extends BoxAddForm { throw new IllegalLinkException(); } if ($this->box->isMultilingual) $this->isMultilingual = 1; - - $this->readBoxPositions(); - } - - /** - * Loads available box positions per box controller. - */ - protected function readBoxPositions() { - foreach ($this->availableBoxControllers as $boxController) { - /** @var IBoxController $controller */ - $controller = $boxController->getProcessor(); - $this->availableBoxPositions[$boxController->objectTypeID] = $controller::getSupportedPositions(); - } } /** @@ -98,19 +79,10 @@ class BoxEditForm extends BoxAddForm { public function validate() { parent::validate(); - $this->validateBoxPosition(); + } - /** - * Validates the selected box position. - */ - protected function validateBoxPosition() { - if ($this->boxType == 'system') { - if (!in_array($this->position, $this->availableBoxPositions[$this->boxController->objectTypeID])) { - throw new UserInputException('position', 'invalid'); - } - } - } + /** * @inheritDoc @@ -231,7 +203,6 @@ class BoxEditForm extends BoxAddForm { WCF::getTPL()->assign([ 'action' => 'edit', - 'availableBoxPositions' => $this->availableBoxPositions, 'boxID' => $this->boxID, 'box' => $this->box ]); -- 2.20.1