From 7477a2f2a055c9286e54add0fc82cd15d484fc91 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 24 Jan 2018 12:50:45 +0100 Subject: [PATCH] Support new style features on copy Fixes #2519 --- .../lib/data/style/StyleAction.class.php | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/wcfsetup/install/files/lib/data/style/StyleAction.class.php b/wcfsetup/install/files/lib/data/style/StyleAction.class.php index f5a12254ef..9c6c1c1e27 100644 --- a/wcfsetup/install/files/lib/data/style/StyleAction.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleAction.class.php @@ -860,7 +860,8 @@ BROWSERCONFIG; 'license' => $this->styleEditor->license, 'authorName' => $this->styleEditor->authorName, 'authorURL' => $this->styleEditor->authorURL, - 'imagePath' => $this->styleEditor->imagePath + 'imagePath' => $this->styleEditor->imagePath, + 'apiVersion' => $this->styleEditor->apiVersion ]); // check if style description uses i18n @@ -899,24 +900,58 @@ BROWSERCONFIG; $statement->execute([$this->styleEditor->styleID]); // copy preview image - if ($this->styleEditor->image) { - // get extension - $fileExtension = mb_substr($this->styleEditor->image, mb_strrpos($this->styleEditor->image, '.')); - - // copy existing preview image - if (@copy(WCF_DIR.'images/'.$this->styleEditor->image, WCF_DIR.'images/stylePreview-'.$newStyle->styleID.$fileExtension)) { - // bypass StyleEditor::update() to avoid scaling of already fitting image - $sql = "UPDATE wcf".WCF_N."_style - SET image = ? + foreach (['image', 'image2x'] as $imageType) { + $image = $this->styleEditor->{$imageType}; + if ($image) { + // get extension + $fileExtension = mb_substr($image, mb_strrpos($image, '.')); + + // copy existing preview image + if (@copy(WCF_DIR . 'images/' . $image, WCF_DIR . 'images/stylePreview-' . $newStyle->styleID . $fileExtension)) { + // bypass StyleEditor::update() to avoid scaling of already fitting image + $sql = "UPDATE wcf" . WCF_N . "_style + SET ".$imageType." = ? + WHERE styleID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + 'stylePreview-' . $newStyle->styleID . $fileExtension, + $newStyle->styleID + ]); + } + } + } + + // copy cover photo + if ($this->styleEditor->coverPhotoExtension) { + if (@copy(WCF_DIR . "images/coverPhotos/{$this->styleEditor->styleID}.{$this->styleEditor->coverPhotoExtension}", WCF_DIR . "images/coverPhotos/{$newStyle->styleID}.{$this->styleEditor->coverPhotoExtension}")) { + $sql = "UPDATE wcf" . WCF_N . "_style + SET coverPhotoExtension = ? WHERE styleID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([ - 'stylePreview-'.$newStyle->styleID.$fileExtension, + $this->styleEditor->coverPhotoExtension, $newStyle->styleID ]); } } + // copy favicon + if ($this->styleEditor->hasFavicon) { + $path = WCF_DIR . 'images/favicon/'; + foreach (glob($path . "{$this->styleEditor->styleID}.*") as $filepath) { + @copy($filepath, $path . preg_replace('~^\d+\.~', "{$newStyle->styleID}.", basename($filepath))); + } + + $sql = "UPDATE wcf" . WCF_N . "_style + SET hasFavicon = ? + WHERE styleID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + 1, + $newStyle->styleID + ]); + } + // copy images if ($this->styleEditor->imagePath && is_dir(WCF_DIR . $this->styleEditor->imagePath)) { $path = FileUtil::removeTrailingSlash($this->styleEditor->imagePath); -- 2.20.1