Added validation for smileyCode/aliases upon manual creation
authorAlexander Ebert <ebert@woltlab.com>
Tue, 21 May 2013 11:03:49 +0000 (13:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 21 May 2013 11:03:49 +0000 (13:03 +0200)
wcfsetup/install/files/acp/templates/smileyAdd.tpl
wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index fd173559e84a0d57647717b9f1371e3d0f4ef309..bc586a76066b9babaffd78daa2218f608e68382b 100644 (file)
@@ -91,7 +91,7 @@
                                        
                                        {if $errorField == 'aliases'}
                                                <small class="innerError">
-                                                       {lang}wcf.acp.smiley.smileyCode.error.{@$errorType}{/lang}
+                                                       {lang}wcf.acp.smiley.aliases.error.{@$errorType}{/lang}
                                                </small>
                                        {/if}
                                </dd>
                                        
                                        {if $errorField == 'showOrder'}
                                                <small class="innerError">
-                                                       {lang}wcf.acp.smiley.smileyCode.error.{@$errorType}{/lang}
+                                                       {lang}wcf.acp.smiley.showOrder.error.{@$errorType}{/lang}
                                                </small>
                                        {/if}
                                </dd>
index a3b07ff3d94419aab7bd56f4be74e113474118c9..9ab70371e6f41d332b58dcf7ae5d3495a4e7f840 100644 (file)
@@ -147,7 +147,7 @@ class SmileyAddForm extends AbstractForm {
                                'smileyCode' => $this->smileyCode,
                                'showOrder' => $this->showOrder,
                                'categoryID' => $this->categoryID ?: null,
-                               'packageID' => PackageCache::getInstance()->getPackageID('com.woltlab.wcf.bbcode'),
+                               'packageID' => 1,
                                'aliases' => $this->aliases
                        )
                ));
@@ -157,7 +157,7 @@ class SmileyAddForm extends AbstractForm {
                $smileyID = $returnValues['returnValues']->smileyID;
                
                if (!I18nHandler::getInstance()->isPlainValue('smileyTitle')) {
-                       I18nHandler::getInstance()->save('smileyTitle', 'wcf.smiley.title'.$smileyID, 'wcf.smiley', PackageCache::getInstance()->getPackageID('com.woltlab.wcf.bbcode'));
+                       I18nHandler::getInstance()->save('smileyTitle', 'wcf.smiley.title'.$smileyID, 'wcf.smiley', 1);
                        
                        // update title
                        $smileyEditor->update(array(
@@ -189,17 +189,40 @@ class SmileyAddForm extends AbstractForm {
                        throw new UserInputException('smileyTitle');
                }
                
-               if ($this->categoryID !== 0) {
+               if ($this->categoryID) {
                        $category = new Category($this->categoryID);
                        if (!$category->categoryID) {
                                throw new UserInputException('categoryID', 'notValid');
                        }
                }
                
-               if ($this->smileyCode === '') {
+               if (empty($this->smileyCode)) {
                        throw new UserInputException('smileyCode');
                }
                
-               // TODO: Validate uniqueness of smileyCode and aliases
+               // validate smiley code and aliases against existing smilies
+               $sql = "SELECT  smileyCode, aliases
+                       FROM    wcf".WCF_N."_smiley";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute();
+               
+               $aliases = explode("\n", $this->aliases);
+               while ($row = $statement->fetchArray()) {
+                       $known = array();
+                       if (!empty($row['aliases'])) {
+                               $known = explode("\n", $row['aliases']);
+                       }
+                       $known[] = $row['smileyCode'];
+                       
+                       if (in_array($this->smileyCode, $known)) {
+                               throw new UserInputException('smileyCode', 'notUnique');
+                       }
+                       else {
+                               $conflicts = array_intersect($aliases, $known);
+                               if (!empty($conflicts)) {
+                                       throw new UserInputException('aliases', 'notUnique');
+                               }
+                       }
+               }
        }
 }
index 9558dd8827033274553b1d63fa19e9e5b3a39779..388c1a770ccc6531329caacf161e94ec5325099d 100644 (file)
                <item name="wcf.acp.smiley.categoryID.default"><![CDATA[Standard-Kategorie]]></item>
                <item name="wcf.acp.smiley.categoryID.error.notValid"><![CDATA[Die gewählte Kategorie ist nicht gültig.]]></item>
                <item name="wcf.acp.smiley.smileyCode"><![CDATA[Primärer Smiley-Code]]></item>
+               <item name="wcf.acp.smiley.smileyCode.error.notUnique"><![CDATA[Dieser Smiley-Code wird bereits von einem anderen Smiley verwendet]]></item>
                <item name="wcf.acp.smiley.aliases"><![CDATA[Alternative Smiley-Codes]]></item>
+               <item name="wcf.acp.smiley.aliases.error.notUnique"><![CDATA[Mindestens ein alternative Smiley-Code wird bereits von einem anderen Smiley verwendet]]></item>
                <item name="wcf.acp.smiley.showOrder"><![CDATA[Position]]></item>
        </category>
        
index 0602293dbef8197930d4b4d3c8106204766400e9..cc5d01a40fc9a3535612405a7e4835f443ef9c4c 100644 (file)
@@ -940,7 +940,9 @@ Examples for medium ID detection:
                <item name="wcf.acp.smiley.categoryID.default"><![CDATA[Default Category]]></item>
                <item name="wcf.acp.smiley.categoryID.error.notValid"><![CDATA[Chosen category is invalid.]]></item>
                <item name="wcf.acp.smiley.smileyCode"><![CDATA[Primary Smiley Code]]></item>
+               <item name="wcf.acp.smiley.smileyCode.error.notUnique"><![CDATA[This smiley code is already in use by an other smiley]]></item>
                <item name="wcf.acp.smiley.aliases"><![CDATA[Alternative Smiley Codes]]></item>
+               <item name="wcf.acp.smiley.aliases.error.notUnique"><![CDATA[At least one alternative smiley code is already in use by an other smiley]]></item>
                <item name="wcf.acp.smiley.showOrder"><![CDATA[Show Order]]></item>
        </category>