From: Tim Düsterhus Date: Wed, 22 Jul 2020 14:10:01 +0000 (+0200) Subject: Always export all style images / assets X-Git-Tag: 5.3.0_Alpha_1~100^2~19 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8e040651d8576853cc3a96dd74a7587783d51723;p=GitHub%2FWoltLab%2FWCF.git Always export all style images / assets --- diff --git a/wcfsetup/install/files/acp/templates/styleExport.tpl b/wcfsetup/install/files/acp/templates/styleExport.tpl index cd4d96cf4f..c1a24859f3 100644 --- a/wcfsetup/install/files/acp/templates/styleExport.tpl +++ b/wcfsetup/install/files/acp/templates/styleExport.tpl @@ -23,12 +23,6 @@

{lang}wcf.acp.style.exportStyle.components.description{/lang}

-
-
-
- -
-
@@ -65,4 +59,4 @@ -{include file='footer'} \ No newline at end of file +{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/form/StyleExportForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleExportForm.class.php index 705e8c7bf9..dd46bb32d4 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleExportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleExportForm.class.php @@ -38,12 +38,6 @@ class StyleExportForm extends AbstractForm { */ public $exportAsPackage = false; - /** - * true, if images should be exported - * @var boolean - */ - public $exportImages = false; - /** * true, if templates should be exported * @var boolean @@ -79,7 +73,6 @@ class StyleExportForm extends AbstractForm { throw new IllegalLinkException(); } - if ($this->style->imagePath && $this->style->imagePath != 'images/') $this->canExportImages = true; if ($this->style->templateGroupID) $this->canExportTemplates = true; } @@ -89,7 +82,6 @@ class StyleExportForm extends AbstractForm { public function readFormParameters() { parent::readFormParameters(); - if ($this->canExportImages && isset($_POST['exportImages'])) $this->exportImages = true; if ($this->canExportTemplates && isset($_POST['exportTemplates'])) $this->exportTemplates = true; if ($this->style->packageName && isset($_POST['exportAsPackage'])) { @@ -118,7 +110,7 @@ class StyleExportForm extends AbstractForm { // export style $styleEditor = new StyleEditor($this->style); - $styleEditor->export($this->exportTemplates, $this->exportImages, ($this->exportAsPackage ? $this->style->packageName : '')); + $styleEditor->export($this->exportTemplates, true, ($this->exportAsPackage ? $this->style->packageName : '')); // call saved event $this->saved(); @@ -133,10 +125,8 @@ class StyleExportForm extends AbstractForm { parent::assignVariables(); WCF::getTPL()->assign([ - 'canExportImages' => $this->canExportImages, 'canExportTemplates' => $this->canExportTemplates, 'exportAsPackage' => $this->exportAsPackage, - 'exportImages' => $this->exportImages, 'exportTemplates' => $this->exportTemplates, 'style' => $this->style, 'styleID' => $this->styleID diff --git a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php index cc00b240b9..413b79d9e3 100644 --- a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php @@ -753,7 +753,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject } // append cover photo - $coverPhoto = ($this->coverPhotoExtension) ? WCF_DIR.'images/coverPhotos/'.$this->styleID.'.'.$this->coverPhotoExtension : ''; + $coverPhoto = ($this->coverPhotoExtension) ? $this->getAssetPath().'coverPhoto.'.$this->coverPhotoExtension : ''; if ($coverPhoto && @file_exists($coverPhoto)) { $styleTar->add($coverPhoto, '', FileUtil::addTrailingSlash(dirname($coverPhoto))); } @@ -871,25 +871,27 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject @unlink($templatesTarName); } - if ($images && ($this->imagePath && $this->imagePath != 'images/')) { + if ($images) { // create images tar $imagesTarName = FileUtil::getTemporaryFilename('images_', '.tar'); $imagesTar = new TarWriter($imagesTarName); FileUtil::makeWritable($imagesTarName); - // append images to tar - $path = FileUtil::addTrailingSlash(WCF_DIR.$this->imagePath); - if (file_exists($path) && is_dir($path)) { - $handle = opendir($path); + $regEx = new Regex('\.(jpg|jpeg|gif|png|svg|ico|json|xml|txt)$', Regex::CASE_INSENSITIVE); + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator( + $this->getAssetPath(), + \FilesystemIterator::SKIP_DOTS + ), + \RecursiveIteratorIterator::SELF_FIRST + ); + foreach ($iterator as $file) { + /** @var \SplFileInfo $file */ + if (!$file->isFile()) continue; + if (!$regEx->match($file->getPathName())) continue; - $regEx = new Regex('\.(jpg|jpeg|gif|png|svg)$', Regex::CASE_INSENSITIVE); - while (($file = readdir($handle)) !== false) { - if (is_file($path.$file) && $regEx->match($file)) { - $imagesTar->add($path.$file, '', $path); - } - } + $imagesTar->add($file->getPathName(), '', $this->getAssetPath()); } - // append images tar to style tar $imagesTar->create(); $styleTar->add($imagesTarName, 'images.tar', $imagesTarName);