Providing sane default values for style creation
authorAlexander Ebert <ebert@woltlab.com>
Sun, 13 Jan 2013 21:23:07 +0000 (22:23 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 13 Jan 2013 21:23:07 +0000 (22:23 +0100)
Fixed issue with exporting a style as an installable package.

wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php
wcfsetup/install/files/lib/data/style/StyleEditor.class.php
wcfsetup/install/files/lib/system/language/I18nHandler.class.php

index a4d91539214d11ad13286d8c6a0c4febc7e2a7f8..cb9529ca3cbd3a7161dd8f1c68a67af48ffa4874 100755 (executable)
@@ -2749,7 +2749,11 @@ WCF.MultipleLanguageInput = Class.extend({
                var $form = $(this._element.parents('form')[0]);
                var $elementID = this._element.wcfIdentify();
                
-               for (var $languageID in this._values) {
+               for (var $languageID in this._availableLanguages) {
+                       if (this._values[$languageID] === undefined) {
+                               this._values[$languageID] = '';
+                       }
+                       
                        $('<input type="hidden" name="' + $elementID + '_i18n[' + $languageID + ']" value="' + this._values[$languageID] + '" />').appendTo($form);
                }
                
index 9b188f295a30abb9b3135702c2c1a99efce84201..da508275f6945b3fb1923b227c0dddd25a554cf4 100644 (file)
@@ -250,10 +250,6 @@ class StyleAddForm extends AbstractForm {
                        throw new UserInputException('authorName');
                }
                
-               if (empty($this->license)) {
-                       throw new UserInputException('license');
-               }
-               
                // validate date
                if (empty($this->styleDate)) {
                        throw new UserInputException('styleDate');
@@ -280,7 +276,7 @@ class StyleAddForm extends AbstractForm {
                }
                
                // validate style description
-               if (!I18nHandler::getInstance()->validateValue('styleDescription', true)) {
+               if (!I18nHandler::getInstance()->validateValue('styleDescription', true, true)) {
                        throw new UserInputException('styleDescription');
                }
                
@@ -402,7 +398,9 @@ class StyleAddForm extends AbstractForm {
                }
                
                if (empty($_POST)) {
+                       $this->authorName = WCF::getUser()->username;
                        $this->styleDate = date('Y-m-d', TIME_NOW);
+                       $this->styleVersion = '1.0.0';
                }
        }
        
index f883e52a4618d2f0dcd23c5df134825861d193fd..f2201ecc3c55889d810c2042592636f06854a949 100644 (file)
@@ -630,6 +630,19 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                        $styleTar->add(WCF_DIR.'images/'.$this->image, '', FileUtil::addTrailingSlash(dirname(WCF_DIR.'images/'.$this->image)));
                }
                
+               // fetch style description
+               $sql = "SELECT          language.languageCode, language_item.languageItemValue
+                       FROM            wcf".WCF_N."_language_item language_item
+                       LEFT JOIN       wcf".WCF_N."_language language
+                       ON              (language.languageID = language_item.languageID)
+                       WHERE           language_item.languageItem = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($this->styleDescription));
+               $styleDescriptions = array();
+               while ($row = $statement->fetchArray()) {
+                       $styleDescriptions[$row['languageCode']] = $row['languageItemValue'];
+               }
+               
                // create style info file
                $xml = new XMLWriter();
                $xml->beginDocument('style', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/style.xsd');
@@ -637,7 +650,12 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                // general block
                $xml->startElement('general');
                $xml->writeElement('stylename', $this->styleName);
-               if ($this->styleDescription) $xml->writeElement('description', $this->styleDescription);
+               
+               // style description
+               foreach ($styleDescriptions as $languageCode => $value) {
+                       $xml->writeElement('description', $value, array('language' => $languageCode));
+               }
+               
                $xml->writeElement('date', $this->styleDate);
                $xml->writeElement('version', $this->styleVersion);
                if ($this->image) $xml->writeElement('image', $this->image);
@@ -775,14 +793,19 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                        
                        // append style tar
                        $styleTarName = FileUtil::unifyDirSeperator($styleTarName);
-                       $packageTar->add($styleTarName, '', dirname($styleTarName));
+                       $packageTar->add($styleTarName, '', FileUtil::addTrailingSlash(dirname($styleTarName)));
                        
                        // create package.xml
                        $xml->beginDocument('package', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/package.xsd', array('name' => $packageName));
                        
                        $xml->startElement('packageinformation');
                        $xml->writeElement('packagename', $this->styleName);
-                       $xml->writeElement('packagedescription', $this->styleDescription);
+                       
+                       // description
+                       foreach ($styleDescriptions as $languageCode => $value) {
+                               $xml->writeElement('packagedescription', $value, array('language' => $languageCode));
+                       }
+                       
                        $xml->writeElement('version', $this->styleVersion);
                        $xml->writeElement('date', $this->styleDate);
                        $xml->endElement();
@@ -792,7 +815,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                        if ($this->authorURL) $xml->writeElement('authorurl', $this->authorURL);
                        $xml->endElement();
                        
-                       $xml->startElement('instructions', array('name' => 'install'));
+                       $xml->startElement('instructions', array('type' => 'install'));
                        $xml->writeElement('instruction', basename($styleTarName), array('type' => 'style'));
                        $xml->endElement();
                        
index 6daa54a0b4e1788f4d390564df67e5cc025b2dc6..c9b52ab00a7ad412da82aa30b5cb9afd1be87ab7 100644 (file)
@@ -239,7 +239,7 @@ class I18nHandler extends SingletonFactory {
                                        return false;
                                }
                                
-                               if (empty($this->i18nValues[$elementID][$language->languageID])) {
+                               if (!$permitEmptyValue && empty($this->i18nValues[$elementID][$language->languageID])) {
                                        return false;
                                }
                        }