From 43a250e641d99fefe7bebbe28fa358b4a900e404 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 26 Apr 2013 01:46:51 +0200 Subject: [PATCH] Fixed template copy function --- .../files/acp/templates/templateAdd.tpl | 1 + .../lib/acp/form/TemplateAddForm.class.php | 43 +++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/templateAdd.tpl b/wcfsetup/install/files/acp/templates/templateAdd.tpl index a3f5bb8198..edcbf6df2c 100644 --- a/wcfsetup/install/files/acp/templates/templateAdd.tpl +++ b/wcfsetup/install/files/acp/templates/templateAdd.tpl @@ -79,6 +79,7 @@
+ {if $copy}{/if}
{else} diff --git a/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php b/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php index 7ad09cde43..f1b3dbdcca 100644 --- a/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php @@ -6,6 +6,7 @@ use wcf\data\template\group\TemplateGroupList; use wcf\data\template\Template; use wcf\data\template\TemplateAction; use wcf\form\AbstractForm; +use wcf\system\exception\IllegalLinkException; use wcf\system\exception\UserInputException; use wcf\system\WCF; use wcf\util\StringUtil; @@ -61,6 +62,35 @@ class TemplateAddForm extends AbstractForm { */ public $packageID = PACKAGE_ID; + /** + * id of copied template + * @var integer + */ + public $copy = 0; + + /** + * copied template object + * @var wcf\data\template\Template + */ + public $copiedTemplate = null; + + /** + * @see wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (!empty($_REQUEST['copy'])) { + $this->copy = intval($_REQUEST['copy']); + $this->copiedTemplate = new Template($this->copy); + if (!$this->copiedTemplate->templateID) { + throw new IllegalLinkException(); + } + + $this->packageID = $this->copiedTemplate->packageID; + } + } + /** * @see wcf\form\IForm::readFormParameters() */ @@ -171,13 +201,9 @@ class TemplateAddForm extends AbstractForm { $templateGroupList->readObjects(); $this->availableTemplateGroups = $templateGroupList->getObjects(); - if (!count($_POST)) { - if (!empty($_REQUEST['copy'])) { - $templateID = intval($_REQUEST['copy']); - $template = new Template($templateID); - $this->tplName = $template->templateName; - $this->templateSource = $template->getSource(); - } + if (!count($_POST) && $this->copiedTemplate !== null) { + $this->tplName = $this->copiedTemplate->templateName; + $this->templateSource = $this->copiedTemplate->getSource(); } } @@ -192,7 +218,8 @@ class TemplateAddForm extends AbstractForm { 'tplName' => $this->tplName, 'templateGroupID' => $this->templateGroupID, 'templateSource' => $this->templateSource, - 'availableTemplateGroups' => $this->availableTemplateGroups + 'availableTemplateGroups' => $this->availableTemplateGroups, + 'copy' => $this->copy )); } } -- 2.20.1