From: Marcel Werk Date: Wed, 8 May 2013 15:00:27 +0000 (+0200) Subject: Added content pattern X-Git-Tag: 2.0.0_Beta_1~228 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=12348253fb7b97831bbdd047b02aff17d7612790;p=GitHub%2FWoltLab%2FWCF.git Added content pattern --- diff --git a/wcfsetup/install/files/lib/system/option/TextOptionType.class.php b/wcfsetup/install/files/lib/system/option/TextOptionType.class.php index faff47c82f..39520387e3 100644 --- a/wcfsetup/install/files/lib/system/option/TextOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/TextOptionType.class.php @@ -64,6 +64,8 @@ class TextOptionType extends AbstractOptionType implements ISearchableUserOption * @see wcf\system\option\IOptionType::validate() */ public function validate(Option $option, $newValue) { + $newValue = $this->getContent($option, $newValue); + if ($option->minlength !== null && $option->minlength > StringUtil::length($newValue)) { throw new UserInputException($option->optionName, 'tooShort'); } @@ -71,4 +73,29 @@ class TextOptionType extends AbstractOptionType implements ISearchableUserOption throw new UserInputException($option->optionName, 'tooLong'); } } + + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(Option $option, $newValue) { + return $this->getContent($option, $newValue); + } + + /** + * Tries to extract content from value. + * + * @param wcf\data\option\Option $option + * @param string $newValue + * @return string + */ + protected function getContent(Option $option, $newValue) { + if ($option->contentpattern) { + if (preg_match('~'.$option->contentpattern.'~', $newValue, $matches)) { + unset($matches[0]); + $newValue = implode('', $matches); + } + } + + return $newValue; + } }