Always export all style images / assets
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 22 Jul 2020 14:10:01 +0000 (16:10 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 22 Jul 2020 14:10:01 +0000 (16:10 +0200)
wcfsetup/install/files/acp/templates/styleExport.tpl
wcfsetup/install/files/lib/acp/form/StyleExportForm.class.php
wcfsetup/install/files/lib/data/style/StyleEditor.class.php

index cd4d96cf4fce63bbfb68bead45b2249465714cb6..c1a24859f33a89e8eeb9e280e4ecc80bb9e4da1b 100644 (file)
                        <p class="sectionDescription">{lang}wcf.acp.style.exportStyle.components.description{/lang}</p>
                </header>
                
-               <dl>
-                       <dt></dt>
-                       <dd>
-                               <label><input type="checkbox" name="exportImages" value="1"{if $exportImages} checked{/if}{if !$canExportImages} disabled{/if}> <span>{lang}wcf.acp.style.exportImages{/lang}</span></label>
-                       </dd>
-               </dl>
                <dl>
                        <dt></dt>
                        <dd>
@@ -65,4 +59,4 @@
        </div>
 </form>
 
-{include file='footer'}
\ No newline at end of file
+{include file='footer'}
index 705e8c7bf9eb7c91a6f9668411949b2ada085eae..dd46bb32d4cd8d18111d7165d5378372031d0f38 100644 (file)
@@ -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
index cc00b240b9e7beb060dfc3a0c008ac8114e7e369..413b79d9e33739a66324b808510d8ea70b68c510 100644 (file)
@@ -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);