2 namespace wcf\system\option
;
3 use wcf\data\option\Option
;
4 use wcf\system\database\util\PreparedStatementConditionBuilder
;
5 use wcf\system\exception\UserInputException
;
7 use wcf\util\StringUtil
;
10 * Option type implementation for textual input fields.
13 * @copyright 2001-2014 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.option
17 * @category Community Framework
19 class TextOptionType
extends AbstractOptionType
implements ISearchableUserOption
{
24 protected $inputType = 'text';
30 protected $inputClass = 'long';
33 * @see \wcf\system\option\IOptionType::getFormElement()
35 public function getFormElement(Option
$option, $value) {
36 WCF
::getTPL()->assign(array(
38 'inputType' => $this->inputType
,
39 'inputClass' => $this->inputClass
,
42 return WCF
::getTPL()->fetch('textOptionType');
46 * @see \wcf\system\option\ISearchableUserOption::getSearchFormElement()
48 public function getSearchFormElement(Option
$option, $value) {
49 WCF
::getTPL()->assign(array(
51 'inputType' => $this->inputType
,
52 'inputClass' => $this->inputClass
,
53 'searchOption' => isset($_POST['searchOptions'][$option->optionName
]),
56 return WCF
::getTPL()->fetch('textSearchableOptionType');
60 * @see \wcf\system\option\ISearchableUserOption::getCondition()
62 public function getCondition(PreparedStatementConditionBuilder
&$conditions, Option
$option, $value) {
63 if (!isset($_POST['searchOptions'][$option->optionName
])) return false;
65 $value = StringUtil
::trim($value);
67 $conditions->add("option_value.userOption".$option->optionID
." = ?", array(''));
70 $conditions->add("option_value.userOption".$option->optionID
." LIKE ?", array('%'.addcslashes($value, '_%').'%'));
77 * @see \wcf\system\option\IOptionType::validate()
79 public function validate(Option
$option, $newValue) {
80 $newValue = $this->getContent($option, $newValue);
82 if ($option->minlength
!== null && $option->minlength
> mb_strlen($newValue)) {
83 throw new UserInputException($option->optionName
, 'tooShort');
85 if ($option->maxlength
!== null && $option->maxlength
< mb_strlen($newValue)) {
86 throw new UserInputException($option->optionName
, 'tooLong');
91 * @see \wcf\system\option\IOptionType::getData()
93 public function getData(Option
$option, $newValue) {
94 return $this->getContent($option, $newValue);
98 * Tries to extract content from value.
100 * @param \wcf\data\option\Option $option
101 * @param string $newValue
104 protected function getContent(Option
$option, $newValue) {
105 if ($option->contentpattern
) {
106 if (preg_match('~'.$option->contentpattern
.'~', $newValue, $matches)) {
108 $newValue = implode('', $matches);