Added content pattern
authorMarcel Werk <burntime@woltlab.com>
Wed, 8 May 2013 15:00:27 +0000 (17:00 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 8 May 2013 15:00:27 +0000 (17:00 +0200)
wcfsetup/install/files/lib/system/option/TextOptionType.class.php

index faff47c82f611cddd6625d81901fba7268a5b714..39520387e374448022e07f60e72b42bdc022a07b 100644 (file)
@@ -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;
+       }
 }