Added ability to export styles as packages
authorAlexander Ebert <ebert@woltlab.com>
Fri, 12 Oct 2012 17:33:56 +0000 (19:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 12 Oct 2012 17:33:56 +0000 (19:33 +0200)
acptemplates/styleExport.tpl
files/lib/acp/form/StyleExportForm.class.php
language/de.xml

index cc6ad03c143264b1daab5dac40d4877aa0dc2314..444c7eb39ff1797f7fcdfc85d51cd71e8225d3fa 100644 (file)
                                </dd>
                        </dl>
                </fieldset>
+               
+               <fieldset>
+                       <legend>{lang}wcf.acp.style.exportStyle.asPackage{/lang}</legend>
+                       <small>{lang}wcf.acp.style.exportStyle.asPackage.description{/lang}</small>
+                       
+                       <dl>
+                               <dd>
+                                       <label><input type="checkbox" name="exportAsPackage" value="1"{if $exportAsPackage} checked="checked"{/if} /> <span>{lang}wcf.acp.style.exportAsPackage{/lang}</span></label>
+                               </dd>
+                       </dl>
+                       <dl{if $errorField == 'packageName'} class="formError"{/if}>
+                               <dt>
+                                       <label for="packageName">{lang}wcf.acp.style.packageName{/lang}</label>
+                               </dt>
+                               <dd>
+                                       <input type="text" name="packageName" id="packageName" class="long" value="{$packageName}" />
+                                       {if $errorField == 'packageName'}
+                                               <small class="innerError">
+                                                       {if $errorType == 'empty'}
+                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                       {else}
+                                                               {lang}wcf.acp.style.packageName.error.{$errorType}{/lang}
+                                                       {/if}
+                                               </small>
+                                       {/if}
+                                       <small>{lang}wcf.acp.style.packageName.description{/lang}</small>
+                               </dd>
+                       </dl>
+               </fieldset>
        </div>
        
        <div class="formSubmit">
index 3cdf15bd738515510ecb0a55c19aecb2b0abcf5d..229c7f255b1c3fb2c3ec7c215c0c593397c29b96 100644 (file)
@@ -1,5 +1,9 @@
 <?php
 namespace wcf\acp\form;
+use wcf\data\package\Package;
+
+use wcf\system\exception\UserInputException;
+
 use wcf\data\style\Style;
 use wcf\data\style\StyleEditor;
 use wcf\form\AbstractForm;
@@ -36,6 +40,12 @@ class StyleExportForm extends AbstractForm {
         */
        public $canExportTemplates = false;
        
+       /**
+        * export style as installable package
+        * @var boolean
+        */
+       public $exportAsPackage = false;
+       
        /**
         * true, if icons should be exported
         * @var boolean
@@ -59,6 +69,12 @@ class StyleExportForm extends AbstractForm {
         */
        public $neededPermissions = array('admin.style.canEditStyle');
        
+       /**
+        * package identifier
+        * @var string
+        */
+       public $packageName = '';
+       
        /**
         * style object
         * @var wcf\data\style\Style
@@ -97,6 +113,34 @@ class StyleExportForm extends AbstractForm {
                if ($this->canExportIcons && isset($_POST['exportIcons'])) $this->exportIcons = true;
                if ($this->canExportImages && isset($_POST['exportImages'])) $this->exportImages = true;
                if ($this->canExportTemplates && isset($_POST['exportTemplates'])) $this->exportTemplates = true;
+               
+               if (isset($_POST['exportAsPackage'])) {
+                       $this->exportAsPackage = true;
+                       
+                       if (isset($_POST['packageName'])) $this->packageName = StringUtil::trim($_POST['packageName']);
+               }
+       }
+       
+       /**
+        * @see wcf\form\IForm::validate()
+        */
+       public function validate() {
+               parent::validate();
+               
+               if ($this->exportAsPackage) {
+                       if (empty($this->packageName)) {
+                               throw new UserInputException('packageName');
+                       }
+                       
+                       if (!Package::isValidPackageName($this->packageName)) {
+                               throw new UserInputException('packageName', 'notValid');
+                       }
+                       
+                       // 3rd party packages may never have com.woltlab.* as name
+                       if (strpos($this->packageName, 'com.woltlab.') === 0) {
+                               throw new UserInputException('packageName', 'reserved');
+                       }
+               }
        }
        
        /**
@@ -110,11 +154,17 @@ class StyleExportForm extends AbstractForm {
                
                // send headers
                header('Content-Type: application/x-gzip; charset=utf-8');
-               header('Content-Disposition: attachment; filename="'.$filename.'-style.tgz"');
+               
+               if ($this->exportAsPackage) {
+                       header('Content-Disposition: attachment; filename="'.$this->packageName.'.tar.gz"');
+               }
+               else {
+                       header('Content-Disposition: attachment; filename="'.$filename.'-style.tgz"');
+               }
                
                // export style
                $styleEditor = new StyleEditor($this->style);
-               $styleEditor->export($this->exportTemplates, $this->exportImages, $this->exportIcons);
+               $styleEditor->export($this->exportTemplates, $this->exportImages, $this->exportIcons, $this->packageName);
                
                // call saved event
                $this->saved();
@@ -132,9 +182,11 @@ class StyleExportForm extends AbstractForm {
                        'canExportIcons' => $this->canExportIcons,
                        'canExportImages' => $this->canExportImages,
                        'canExportTemplates' => $this->canExportTemplates,
+                       'exportAsPackage' => $this->exportAsPackage,
                        'exportIcons' => $this->exportIcons,
                        'exportImages' => $this->exportImages,
                        'exportTemplates' => $this->exportTemplates,
+                       'packageName' => $this->packageName,
                        'style' => $this->style,
                        'styleID' => $this->styleID
                ));
index 250e3306aa4b75afed139b49650ba14274d7d9c5..241677b3be6285590b1cde067ea77404cf98115e 100644 (file)
                <item name="wcf.acp.style.copyStyle.confirmMessage"><![CDATA[Möchten Sie den Stil &bdquo;{$style->styleName}&ldquo; wirklich duplizieren?]]></item>
                <item name="wcf.acp.style.delete.confirmMessage"><![CDATA[Möchten Sie den Stil &bdquo;{$style->styleName}&ldquo; wirklich löschen?]]></item>
                <item name="wcf.acp.style.edit"><![CDATA[Stil bearbeiten]]></item>
+               <item name="wcf.acp.style.exportAsPackage"><![CDATA[Als Paket exportieren]]></item>
                <item name="wcf.acp.style.exportIcons"><![CDATA[Icons exportieren ({$style->iconPath})]]></item>
                <item name="wcf.acp.style.exportImages"><![CDATA[Grafiken exportieren ({$style->imagePath})]]></item>
                <item name="wcf.acp.style.exportTemplates"><![CDATA[Templates exportieren]]></item>
                <item name="wcf.acp.style.exportStyle"><![CDATA[Stil exportieren]]></item>
+               <item name="wcf.acp.style.exportStyle.asPackage"><![CDATA[Export als Paket]]></item>
+               <item name="wcf.acp.style.exportStyle.asPackage.description"><![CDATA[Wählen Sie hier aus, ob sie den Stil &bdquo;{$style->styleName}&ldquo; als Paket exportieren möchten. Pakete können über die Paketverwaltung installiert oder in den <a href="{@$__wcf->getPath()}acp/dereferrer.php?url=http://www.woltlab.com/de/pluginstore/">WoltLab® Plugin-Store</a> hochgeladen werden.]]></item>
                <item name="wcf.acp.style.exportStyle.components"><![CDATA[Optionen]]></item>
                <item name="wcf.acp.style.exportStyle.components.description"><![CDATA[Wählen Sie hier aus, welche Bestandteile des Stils &bdquo;{$style->styleName}&ldquo; mit exportiert werden sollen]]></item>
                <item name="wcf.acp.style.general"><![CDATA[Daten]]></item>
                <item name="wcf.acp.style.imagePath.description"><![CDATA[Wenn Ihr Stil eigene Grafiken benötigt, sollten diese in einem Unterordner des Ordners &bdquo;images&ldquo; ablegen. Geben Sie hier den Pfad zu diesem Ordner an.]]></item>
                <item name="wcf.acp.style.license"><![CDATA[Lizenz]]></item>
                <item name="wcf.acp.style.list"><![CDATA[Stile auflisten]]></item>
+               <item name="wcf.acp.style.packageName"><![CDATA[Paketbezeichner]]></item>
+               <item name="wcf.acp.style.packageName.description"><![CDATA[Geben Sie hier den Paketbezeichner in der Form &bdquo;tld.domain.paketName&ldquo; an. Wenn Ihnen beispielsweise die Domain &bdquo;example.com&ldquo; gehört und Ihr Stil &bdquo;Blue Sunrise&ldquo; heißt, so wäre &bdquo;com.example.style.blueSunrise&ldquo; ein passender und gültiger Paketbezeichner.]]></item>
+               <item name="wcf.acp.style.packageName.error.notValid"><![CDATA[Der eingegebene Paketbezeichner ist ungültig]]></item>
+               <item name="wcf.acp.style.packageName.error.reserved"><![CDATA[Der Paketbezeichner darf nicht mit &bdquo;com.woltlab.&ldquo; beginnen]]></item>
                <item name="wcf.acp.style.styleDate"><![CDATA[Datum]]></item>
                <item name="wcf.acp.style.styleDescription"><![CDATA[Beschreibung]]></item>
                <item name="wcf.acp.style.styleName"><![CDATA[Name]]></item>