From: Alexander Ebert Date: Tue, 21 May 2013 11:03:49 +0000 (+0200) Subject: Added validation for smileyCode/aliases upon manual creation X-Git-Tag: 2.0.0_Beta_1~103 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a33717d8a00db24d51b24369d19ce0e9a1d6f92f;p=GitHub%2FWoltLab%2FWCF.git Added validation for smileyCode/aliases upon manual creation --- diff --git a/wcfsetup/install/files/acp/templates/smileyAdd.tpl b/wcfsetup/install/files/acp/templates/smileyAdd.tpl index fd173559e8..bc586a7606 100644 --- a/wcfsetup/install/files/acp/templates/smileyAdd.tpl +++ b/wcfsetup/install/files/acp/templates/smileyAdd.tpl @@ -91,7 +91,7 @@ {if $errorField == 'aliases'} - {lang}wcf.acp.smiley.smileyCode.error.{@$errorType}{/lang} + {lang}wcf.acp.smiley.aliases.error.{@$errorType}{/lang} {/if} @@ -104,7 +104,7 @@ {if $errorField == 'showOrder'} - {lang}wcf.acp.smiley.smileyCode.error.{@$errorType}{/lang} + {lang}wcf.acp.smiley.showOrder.error.{@$errorType}{/lang} {/if} diff --git a/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php b/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php index a3b07ff3d9..9ab70371e6 100644 --- a/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php @@ -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'); + } + } + } } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 9558dd8827..388c1a770c 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -941,7 +941,9 @@ + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 0602293dbe..cc5d01a40f 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -940,7 +940,9 @@ Examples for medium ID detection: + +