From: Matthias Schmidt Date: Fri, 12 Aug 2011 20:56:25 +0000 (+0200) Subject: Renamed option types X-Git-Tag: 2.0.0_Beta_1~1858^2^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=155a8c6712f3592b3971d9f418c489579c72e904;p=GitHub%2FWoltLab%2FWCF.git Renamed option types --- diff --git a/wcfsetup/install/files/lib/system/option/BooleanOptionType.class.php b/wcfsetup/install/files/lib/system/option/BooleanOptionType.class.php new file mode 100644 index 0000000000..39458dc3b9 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/BooleanOptionType.class.php @@ -0,0 +1,66 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class BooleanOptionType extends AbstractOptionType implements ISearchableUserOption { + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + $options = Option::parseEnableOptions($option->enableOptions); + + WCF::getTPL()->assign(array( + 'disableOptions' => $options['disableOptions'], + 'enableOptions' => $options['enableOptions'], + 'option' => $option, + 'value' => $value + )); + return WCF::getTPL()->fetch('optionTypeBoolean'); + } + + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(Option $option, $newValue) { + if ($newValue !== null) return 1; + return 0; + } + + /** + * @see wcf\system\option\IOptionType::getCSSClassName() + */ + public function getCSSClassName() { + return 'reversed'; + } + + /** + * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() + */ + public function getSearchFormElement(Option $option, $value) { + return $this->getFormElement($option, $value); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getCondition() + */ + public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { + $value = intval($value); + if (!$value) return false; + + $conditions->add("option_value.userOption".$option->optionID." = ?", array(1)); + return true; + } +} diff --git a/wcfsetup/install/files/lib/system/option/CustomselectOptionType.class.php b/wcfsetup/install/files/lib/system/option/CustomselectOptionType.class.php new file mode 100644 index 0000000000..1b56a94ca2 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/CustomselectOptionType.class.php @@ -0,0 +1,46 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class CustomselectOptionType extends SelectOptionType { + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + WCF::getTPL()->assign(array( + 'option' => $option, + 'selectOptions' => $option->parseSelectOptions(), + 'value' => $value, + 'customValue' => (!isset($options[$value]) ? $value : '') + )); + + return WCF::getTPL()->fetch('optionTypeCustomselect'); + } + + /** + * @see wcf\system\option\IOptionType::validate() + */ + public function validate(Option $option, $newValue) {} + + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(Option $option, $newValue) { + if (empty($newValue) && isset($_POST['values'][$option->optionName.'_custom'])) { + return $_POST['values'][$option->optionName.'_custom']; + } + return $newValue; + } +} diff --git a/wcfsetup/install/files/lib/system/option/DateOptionType.class.php b/wcfsetup/install/files/lib/system/option/DateOptionType.class.php new file mode 100644 index 0000000000..a03a057571 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/DateOptionType.class.php @@ -0,0 +1,142 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class DateOptionType extends AbstractOptionType implements ISearchableUserOption { + protected $yearRequired = true; + + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(array &$optionData) { + if (!isset($optionData['optionValue'])) { + if (isset($optionData['defaultValue'])) $optionData['optionValue'] = $optionData['defaultValue']; + else $optionData['optionValue'] = ''; + } + $optionData['isOptionGroup'] = true; + $optionData['divClass'] = 'formDate'; + + $year = $month = $day = ''; + $optionValue = explode('-', (is_array($optionData['optionValue']) ? implode('-', $optionData['optionValue']) : $optionData['optionValue'])); + if (isset($optionValue[0])) $year = intval($optionValue[0]); + if (empty($year)) $year = ''; + if (isset($optionValue[1])) $month = $optionValue[1]; + if (isset($optionValue[2])) $day = $optionValue[2]; + $dateInputOrder = explode('-', WCF::getLanguage()->get('wcf.global.dateInputOrder')); + + // generate days + $days = array(); + $days[0] = ''; + for ($i = 1; $i < 32; $i++) { + $days[$i] = $i; + } + + // generate months + $months = array(); + $months[0] = ''; + // TODO: $dateFormatLocalized is no longer available, fix this! + $monthFormat = (Language::$dateFormatLocalized ? '%B' : '%m'); + for ($i = 1; $i < 13; $i++) { + $months[$i] = DateUtil::formatDate($monthFormat, gmmktime(0, 0, 0, $i, 10, 2006), false, true); + } + + WCF::getTPL()->assign(array( + 'year' => $year, + 'month' => $month, + 'day' => $day, + 'days' => $days, + 'months' => $months, + 'optionData' => $optionData, + 'dateInputOrder' => $dateInputOrder, + 'yearRequired' => $this->yearRequired + )); + return WCF::getTPL()->fetch('optionTypeDate'); + } + + /** + * Formats the user input. + * + * @param array $newValue + */ + protected function getValue(array &$newValue) { + if (isset($newValue['year'])) $newValue['year'] = intval($newValue['year']); + else $newValue['year'] = 0; + if (isset($newValue['month'])) $newValue['month'] = intval($newValue['month']); + else $newValue['month'] = 0; + if (isset($newValue['day'])) $newValue['day'] = intval($newValue['day']); + else $newValue['day'] = 0; + } + + /** + * @see wcf\system\option\IOptionType::validate() + */ + public function validate(array $optionData, $newValue) { + $this->getValue($newValue); + + if ($newValue['year'] || $newValue['month'] || $newValue['day']) { + if (strlen($newValue['year']) == 2) { + $newValue['year'] = '19'.$newValue['year']; + } + + if (!checkdate(intval($newValue['month']), intval($newValue['day']), ((!$this->yearRequired && !$newValue['year']) ? 2000 : intval($newValue['year'])))) { + throw new UserInputException($optionData['optionName'], 'validationFailed'); + } + if (($newValue['year'] || $this->yearRequired) && ((strlen($newValue['year']) != 4 && strlen($newValue['year']) != 2) || $newValue['year'] < 1902)) { + throw new UserInputException($optionData['optionName'], 'validationFailed'); + } + } + } + + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(array $optionData, $newValue) { + $this->getValue($newValue); + + if ($newValue['year'] || $newValue['month'] || $newValue['day']) { + if ($newValue['month'] < 10) $newValue['month'] = '0'.$newValue['month']; + if ($newValue['day'] < 10) $newValue['day'] = '0'.$newValue['day']; + if (strlen($newValue['year']) == 2) { + $newValue['year'] = '19'.$newValue['year']; + } + if (!$this->yearRequired && strlen($newValue['year']) < 2) { + $newValue['year'] = '0000'; + } + return $newValue['year'].'-'.$newValue['month'].'-'.$newValue['day']; + } + + return ''; + } + + /** + * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() + */ + public function getSearchFormElement(array &$optionData) { + return $this->getFormElement($optionData); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getCondition() + */ + public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { + $value = $this->getData($optionData, $value); + if ($value == '') return false; + + $conditions->add("option_value.userOption".$option->optionID." = ?", array($value)); + return true; + } +} diff --git a/wcfsetup/install/files/lib/system/option/FloatOptionType.class.php b/wcfsetup/install/files/lib/system/option/FloatOptionType.class.php new file mode 100644 index 0000000000..503ca5473b --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/FloatOptionType.class.php @@ -0,0 +1,35 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class FloatOptionType extends TextOptionType { + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + $value = str_replace('.', WCF::getLanguage()->get('wcf.global.decimalPoint'), $value); + + return parent::getFormElement($option, $value); + } + + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(Option $option, $newValue) { + $newValue = str_replace(' ', '', $newValue); + $newValue = str_replace(WCF::getLanguage()->get('wcf.global.thousandsSeparator'), '', $newValue); + $newValue = str_replace(WCF::getLanguage()->get('wcf.global.decimalPoint'), '.', $newValue); + return floatval($newValue); + } +} diff --git a/wcfsetup/install/files/lib/system/option/IntegerOptionType.class.php b/wcfsetup/install/files/lib/system/option/IntegerOptionType.class.php new file mode 100644 index 0000000000..06ecd1fbdb --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/IntegerOptionType.class.php @@ -0,0 +1,22 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class IntegerOptionType extends TextOptionType { + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(Option $option, $newValue) { + return intval($newValue); + } +} diff --git a/wcfsetup/install/files/lib/system/option/MultiselectOptionType.class.php b/wcfsetup/install/files/lib/system/option/MultiselectOptionType.class.php new file mode 100644 index 0000000000..1db2609c93 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/MultiselectOptionType.class.php @@ -0,0 +1,80 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class MultiselectOptionType extends SelectOptionType { + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(array &$optionData) { + if (!isset($optionData['optionValue'])) { + if (isset($optionData['defaultValue'])) $optionData['optionValue'] = explode("\n", $optionData['defaultValue']); + else $optionData['optionValue'] = array(); + } + else if (!is_array($optionData['optionValue'])) { + $optionData['optionValue'] = explode("\n", $optionData['optionValue']); + } + + // get options + $options = OptionUtil::parseSelectOptions($optionData['selectOptions']); + + WCF::getTPL()->assign(array( + 'optionData' => $optionData, + 'options' => $options + )); + return WCF::getTPL()->fetch('optionTypeMultiselect'); + } + + /** + * @see wcf\system\option\IOptionType::validate() + */ + public function validate(array $optionData, $newValue) { + if (!is_array($newValue)) $newValue = array(); + $options = OptionUtil::parseSelectOptions($optionData['selectOptions']); + foreach ($newValue as $value) { + if (!isset($options[$value])) throw new UserInputException($optionData['optionName'], 'validationFailed'); + } + } + + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(array $optionData, $newValue) { + if (!is_array($newValue)) $newValue = array(); + return implode("\n", $newValue); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() + */ + public function getSearchFormElement(array &$optionData) { + return $this->getFormElement($optionData); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getCondition() + */ + public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $options, $value) { + if (!is_array($value) || !count($value)) return false; + $value = ArrayUtil::trim($value); + if (!count($value)) return false; + + $conditions->add("option_value.userOption".$option->optionID." = ?", array(implode("\n", $value))); + return true; + } +} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeBoolean.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeBoolean.class.php deleted file mode 100644 index 0c755add3b..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeBoolean.class.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeBoolean extends AbstractOptionType implements ISearchableUserOption { - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - $options = Option::parseEnableOptions($option->enableOptions); - - WCF::getTPL()->assign(array( - 'disableOptions' => $options['disableOptions'], - 'enableOptions' => $options['enableOptions'], - 'option' => $option, - 'value' => $value - )); - return WCF::getTPL()->fetch('optionTypeBoolean'); - } - - /** - * @see wcf\system\option\IOptionType::getData() - */ - public function getData(Option $option, $newValue) { - if ($newValue !== null) return 1; - return 0; - } - - /** - * @see wcf\system\option\IOptionType::getCSSClassName() - */ - public function getCSSClassName() { - return 'reversed'; - } - - /** - * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() - */ - public function getSearchFormElement(Option $option, $value) { - return $this->getFormElement($option, $value); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getCondition() - */ - public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { - $value = intval($value); - if (!$value) return false; - - $conditions->add("option_value.userOption".$option->optionID." = ?", array(1)); - return true; - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeCustomselect.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeCustomselect.class.php deleted file mode 100644 index f7549ea375..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeCustomselect.class.php +++ /dev/null @@ -1,46 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeCustomselect extends OptionTypeSelect { - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - WCF::getTPL()->assign(array( - 'option' => $option, - 'selectOptions' => $option->parseSelectOptions(), - 'value' => $value, - 'customValue' => (!isset($options[$value]) ? $value : '') - )); - - return WCF::getTPL()->fetch('optionTypeCustomselect'); - } - - /** - * @see wcf\system\option\IOptionType::validate() - */ - public function validate(Option $option, $newValue) {} - - /** - * @see wcf\system\option\IOptionType::getData() - */ - public function getData(Option $option, $newValue) { - if (empty($newValue) && isset($_POST['values'][$option->optionName.'_custom'])) { - return $_POST['values'][$option->optionName.'_custom']; - } - return $newValue; - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeDate.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeDate.class.php deleted file mode 100644 index b313b8dc6a..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeDate.class.php +++ /dev/null @@ -1,144 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeDate extends AbstractOptionType implements ISearchableUserOption { - protected $yearRequired = true; - - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(array &$optionData) { - if (!isset($optionData['optionValue'])) { - if (isset($optionData['defaultValue'])) $optionData['optionValue'] = $optionData['defaultValue']; - else $optionData['optionValue'] = ''; - } - $optionData['isOptionGroup'] = true; - $optionData['divClass'] = 'formDate'; - - $year = $month = $day = ''; - $optionValue = explode('-', (is_array($optionData['optionValue']) ? implode('-', $optionData['optionValue']) : $optionData['optionValue'])); - if (isset($optionValue[0])) $year = intval($optionValue[0]); - if (empty($year)) $year = ''; - if (isset($optionValue[1])) $month = $optionValue[1]; - if (isset($optionValue[2])) $day = $optionValue[2]; - $dateInputOrder = explode('-', WCF::getLanguage()->get('wcf.global.dateInputOrder')); - - // generate days - $days = array(); - $days[0] = ''; - for ($i = 1; $i < 32; $i++) { - $days[$i] = $i; - } - - // generate months - $months = array(); - $months[0] = ''; - // TODO: $dateFormatLocalized is no longer available, fix this! - $monthFormat = (Language::$dateFormatLocalized ? '%B' : '%m'); - for ($i = 1; $i < 13; $i++) { - $months[$i] = DateUtil::formatDate($monthFormat, gmmktime(0, 0, 0, $i, 10, 2006), false, true); - } - - WCF::getTPL()->assign(array( - 'year' => $year, - 'month' => $month, - 'day' => $day, - 'days' => $days, - 'months' => $months, - 'optionData' => $optionData, - 'dateInputOrder' => $dateInputOrder, - 'yearRequired' => $this->yearRequired - )); - return WCF::getTPL()->fetch('optionTypeDate'); - } - - /** - * Formats the user input. - * - * @param array $newValue - */ - protected function getValue(array &$newValue) { - if (isset($newValue['year'])) $newValue['year'] = intval($newValue['year']); - else $newValue['year'] = 0; - if (isset($newValue['month'])) $newValue['month'] = intval($newValue['month']); - else $newValue['month'] = 0; - if (isset($newValue['day'])) $newValue['day'] = intval($newValue['day']); - else $newValue['day'] = 0; - } - - /** - * @see wcf\system\option\IOptionType::validate() - */ - public function validate(array $optionData, $newValue) { - $this->getValue($newValue); - - if ($newValue['year'] || $newValue['month'] || $newValue['day']) { - if (strlen($newValue['year']) == 2) { - $newValue['year'] = '19'.$newValue['year']; - } - - if (!checkdate(intval($newValue['month']), intval($newValue['day']), ((!$this->yearRequired && !$newValue['year']) ? 2000 : intval($newValue['year'])))) { - throw new UserInputException($optionData['optionName'], 'validationFailed'); - } - if (($newValue['year'] || $this->yearRequired) && ((strlen($newValue['year']) != 4 && strlen($newValue['year']) != 2) || $newValue['year'] < 1902)) { - throw new UserInputException($optionData['optionName'], 'validationFailed'); - } - } - } - - /** - * @see wcf\system\option\IOptionType::getData() - */ - public function getData(array $optionData, $newValue) { - $this->getValue($newValue); - - if ($newValue['year'] || $newValue['month'] || $newValue['day']) { - if ($newValue['month'] < 10) $newValue['month'] = '0'.$newValue['month']; - if ($newValue['day'] < 10) $newValue['day'] = '0'.$newValue['day']; - if (strlen($newValue['year']) == 2) { - $newValue['year'] = '19'.$newValue['year']; - } - if (!$this->yearRequired && strlen($newValue['year']) < 2) { - $newValue['year'] = '0000'; - } - return $newValue['year'].'-'.$newValue['month'].'-'.$newValue['day']; - } - - return ''; - } - - /** - * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() - */ - public function getSearchFormElement(array &$optionData) { - return $this->getFormElement($optionData); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getCondition() - */ - public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { - $value = $this->getData($optionData, $value); - if ($value == '') return false; - - $conditions->add("option_value.userOption".$option->optionID." = ?", array($value)); - return true; - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeFloat.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeFloat.class.php deleted file mode 100644 index a7a7896a5b..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeFloat.class.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeFloat extends OptionTypeText { - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - $value = str_replace('.', WCF::getLanguage()->get('wcf.global.decimalPoint'), $value); - - return parent::getFormElement($option, $value); - } - - /** - * @see wcf\system\option\IOptionType::getData() - */ - public function getData(Option $option, $newValue) { - $newValue = str_replace(' ', '', $newValue); - $newValue = str_replace(WCF::getLanguage()->get('wcf.global.thousandsSeparator'), '', $newValue); - $newValue = str_replace(WCF::getLanguage()->get('wcf.global.decimalPoint'), '.', $newValue); - return floatval($newValue); - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeInteger.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeInteger.class.php deleted file mode 100644 index 26be493e20..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeInteger.class.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeInteger extends OptionTypeText { - /** - * @see wcf\system\option\IOptionType::getData() - */ - public function getData(Option $option, $newValue) { - return intval($newValue); - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeMultiselect.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeMultiselect.class.php deleted file mode 100644 index 4bd0fe8b66..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeMultiselect.class.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeMultiselect extends OptionTypeSelect { - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(array &$optionData) { - if (!isset($optionData['optionValue'])) { - if (isset($optionData['defaultValue'])) $optionData['optionValue'] = explode("\n", $optionData['defaultValue']); - else $optionData['optionValue'] = array(); - } - else if (!is_array($optionData['optionValue'])) { - $optionData['optionValue'] = explode("\n", $optionData['optionValue']); - } - - // get options - $options = OptionUtil::parseSelectOptions($optionData['selectOptions']); - - WCF::getTPL()->assign(array( - 'optionData' => $optionData, - 'options' => $options - )); - return WCF::getTPL()->fetch('optionTypeMultiselect'); - } - - /** - * @see wcf\system\option\IOptionType::validate() - */ - public function validate(array $optionData, $newValue) { - if (!is_array($newValue)) $newValue = array(); - $options = OptionUtil::parseSelectOptions($optionData['selectOptions']); - foreach ($newValue as $value) { - if (!isset($options[$value])) throw new UserInputException($optionData['optionName'], 'validationFailed'); - } - } - - /** - * @see wcf\system\option\IOptionType::getData() - */ - public function getData(array $optionData, $newValue) { - if (!is_array($newValue)) $newValue = array(); - return implode("\n", $newValue); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() - */ - public function getSearchFormElement(array &$optionData) { - return $this->getFormElement($optionData); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getCondition() - */ - public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $options, $value) { - if (!is_array($value) || !count($value)) return false; - $value = ArrayUtil::trim($value); - if (!count($value)) return false; - - $conditions->add("option_value.userOption".$option->optionID." = ?", array(implode("\n", $value))); - return true; - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypePassword.class.php b/wcfsetup/install/files/lib/system/option/OptionTypePassword.class.php deleted file mode 100644 index ac14a6715b..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypePassword.class.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypePassword extends OptionTypeText { - /** - * @see wcf\system\option\OptionTypeText::$inputType - */ - protected $inputType = 'password'; - - /** - * @see wcf\system\option\ISearchableUserOption::getCondition() - */ - public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { - return false; - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeRadiobuttons.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeRadiobuttons.class.php deleted file mode 100644 index 257e8a21cd..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeRadiobuttons.class.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeRadiobuttons extends AbstractOptionType implements ISearchableUserOption { - public $templateName = 'optionTypeRadiobuttons'; - - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - // get options - $selectOptions = $option->parseSelectOptions(); - - $availableOptions = $option->parseMultipleEnableOptions(); - $options = array( - 'disableOptions' => array(), - 'enableOptions' => array() - ); - - foreach ($availableOptions as $key => $enableOptions) { - $optionData = Option::parseEnableOptions($enableOptions); - - $options['disableOptions'][$key] = $optionData['disableOptions']; - $options['enableOptions'][$key] = $optionData['enableOptions']; - } - - WCF::getTPL()->assign(array( - 'disableOptions' => $options['disableOptions'], - 'enableOptions' => $options['enableOptions'], - 'option' => $option, - 'selectOptions' => $selectOptions, - 'value' => $value - )); - return WCF::getTPL()->fetch($this->templateName); - } - - /** - * @see wcf\system\option\IOptionType::validate() - */ - public function validate(Option $option, $newValue) { - if (!empty($newValue)) { - $options = $option->parseSelectOptions(); - if (!isset($options[$newValue])) { - throw new UserInputException($option->optionName, 'validationFailed'); - } - } - } - - /** - * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() - */ - public function getSearchFormElement(Option $option, $value) { - return $this->getFormElement($optionData, $value); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getCondition() - */ - public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { - $value = StringUtil::trim($value); - if (!$value) return false; - - $conditions->add("option_value.userOption".$option->optionID." = ?", array($value)); - return true; - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeSelect.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeSelect.class.php deleted file mode 100644 index a6377e35f0..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeSelect.class.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeSelect extends OptionTypeRadiobuttons { - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - // get options - $options = $this->parseEnableOptions($option); - - WCF::getTPL()->assign(array( - 'disableOptions' => $options['disableOptions'], - 'enableOptions' => $options['enableOptions'], - 'option' => $option, - 'selectOptions' => $option->parseSelectOptions(), - 'value' => $value - )); - return WCF::getTPL()->fetch('optionTypeSelect'); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() - */ - public function getSearchFormElement(Option $option, $value) { - return $this->getFormElement($optionData, $value); - } - - /** - * @todo This is not really tested yet! - * @param Option $option - * @return array - */ - protected function parseEnableOptions(Option $option) { - $disableOptions = $enableOptions = ''; - - if (!empty($option->enableOptions)) { - $options = $option->parseMultipleEnableOptions(); - - foreach ($options as $key => $optionData) { - $tmp = explode(',', $optionData); - - foreach ($optionData as $item) { - if ($item{0} == '!') { - if (!empty($disableOptions)) $disableOptions .= ','; - $disableOptions .= "{ value: '".$key."', option: '".StringUtil::substring($item, 1)."' }"; - } - else { - if (!empty($enableOptions)) $enableOptions .= ','; - $enableOptions .= "{ value: '".$key."', option: '".$item."' }"; - } - } - } - } - - return array( - 'disableOptions' => $disableOptions, - 'enableOptions' => $enableOptions - ); - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeText.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeText.class.php deleted file mode 100644 index 381c7d6ede..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeText.class.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeText extends AbstractOptionType implements ISearchableUserOption { - /** - * input type - * @var string - */ - protected $inputType = 'text'; - - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - WCF::getTPL()->assign(array( - 'option' => $option, - 'inputType' => $this->inputType, - 'value' => $value - )); - return WCF::getTPL()->fetch('optionTypeText'); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() - */ - public function getSearchFormElement(Option $option, $value) { - return $this->getFormElement($optionData, $value); - } - - /** - * @see wcf\system\option\ISearchableUserOption::getCondition() - */ - public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { - $value = StringUtil::trim($value); - if (empty($value)) return false; - - $conditions->add("option_value.userOption".$option->optionID." LIKE ?", array('%'.addcslashes($value, '_%').'%')); - return true; - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeTextarea.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeTextarea.class.php deleted file mode 100644 index 87a39ba2d6..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeTextarea.class.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeTextarea extends OptionTypeText { - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - WCF::getTPL()->assign(array( - 'option' => $option, - 'value' => $value - )); - return WCF::getTPL()->fetch('optionTypeTextarea'); - } -} diff --git a/wcfsetup/install/files/lib/system/option/OptionTypeTimezone.class.php b/wcfsetup/install/files/lib/system/option/OptionTypeTimezone.class.php deleted file mode 100644 index cde2c56688..0000000000 --- a/wcfsetup/install/files/lib/system/option/OptionTypeTimezone.class.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.option - * @category Community Framework - */ -class OptionTypeTimezone extends AbstractOptionType { - /** - * @see wcf\system\option\IOptionType::getFormElement() - */ - public function getFormElement(Option $option, $value) { - $timezoneOptions = array(); - foreach (DateUtil::getAvailableTimezones() as $timezone) { - $timezoneOptions[$timezone] = WCF::getLanguage()->get('wcf.global.date.timezone.'.str_replace('/', '.', strtolower($timezone))); - } - - WCF::getTPL()->assign(array( - 'option' => $option, - 'selectOptions' => $timezoneOptions, - 'value' => $value - )); - return WCF::getTPL()->fetch('optionTypeSelect'); - } - - /** - * @see wcf\system\option\IOptionType::validate() - */ - public function validate(Option $option, $newValue) { - if (!in_array($newValue, DateUtil::getAvailableTimezones())) { - throw new UserInputException($option->optionName, 'validationFailed'); - } - } -} diff --git a/wcfsetup/install/files/lib/system/option/PasswordOptionType.class.php b/wcfsetup/install/files/lib/system/option/PasswordOptionType.class.php new file mode 100644 index 0000000000..a8aa0403c6 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/PasswordOptionType.class.php @@ -0,0 +1,28 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class PasswordOptionType extends TextOptionType { + /** + * @see wcf\system\option\TextOptionType::$inputType + */ + protected $inputType = 'password'; + + /** + * @see wcf\system\option\ISearchableUserOption::getCondition() + */ + public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { + return false; + } +} diff --git a/wcfsetup/install/files/lib/system/option/RadiobuttonsOptionType.class.php b/wcfsetup/install/files/lib/system/option/RadiobuttonsOptionType.class.php new file mode 100644 index 0000000000..5677daee47 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/RadiobuttonsOptionType.class.php @@ -0,0 +1,85 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class RadiobuttonsOptionType extends AbstractOptionType implements ISearchableUserOption { + /** + * name of the template that contains the form element of this option type + * @var string + */ + public $templateName = 'optionTypeRadiobuttons'; + + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + // get options + $selectOptions = $option->parseSelectOptions(); + + $availableOptions = $option->parseMultipleEnableOptions(); + $options = array( + 'disableOptions' => array(), + 'enableOptions' => array() + ); + + foreach ($availableOptions as $key => $enableOptions) { + $optionData = Option::parseEnableOptions($enableOptions); + + $options['disableOptions'][$key] = $optionData['disableOptions']; + $options['enableOptions'][$key] = $optionData['enableOptions']; + } + + WCF::getTPL()->assign(array( + 'disableOptions' => $options['disableOptions'], + 'enableOptions' => $options['enableOptions'], + 'option' => $option, + 'selectOptions' => $selectOptions, + 'value' => $value + )); + return WCF::getTPL()->fetch($this->templateName); + } + + /** + * @see wcf\system\option\IOptionType::validate() + */ + public function validate(Option $option, $newValue) { + if (!empty($newValue)) { + $options = $option->parseSelectOptions(); + if (!isset($options[$newValue])) { + throw new UserInputException($option->optionName, 'validationFailed'); + } + } + } + + /** + * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() + */ + public function getSearchFormElement(Option $option, $value) { + return $this->getFormElement($optionData, $value); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getCondition() + */ + public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { + $value = StringUtil::trim($value); + if (!$value) return false; + + $conditions->add("option_value.userOption".$option->optionID." = ?", array($value)); + return true; + } +} diff --git a/wcfsetup/install/files/lib/system/option/SelectOptionType.class.php b/wcfsetup/install/files/lib/system/option/SelectOptionType.class.php new file mode 100644 index 0000000000..00229c4950 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/SelectOptionType.class.php @@ -0,0 +1,73 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class SelectOptionType extends RadiobuttonsOptionType { + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + // get options + $options = $this->parseEnableOptions($option); + + WCF::getTPL()->assign(array( + 'disableOptions' => $options['disableOptions'], + 'enableOptions' => $options['enableOptions'], + 'option' => $option, + 'selectOptions' => $option->parseSelectOptions(), + 'value' => $value + )); + return WCF::getTPL()->fetch('optionTypeSelect'); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() + */ + public function getSearchFormElement(Option $option, $value) { + return $this->getFormElement($optionData, $value); + } + + /** + * @todo This is not really tested yet! + * @param Option $option + * @return array + */ + protected function parseEnableOptions(Option $option) { + $disableOptions = $enableOptions = ''; + + if (!empty($option->enableOptions)) { + $options = $option->parseMultipleEnableOptions(); + + foreach ($options as $key => $optionData) { + $tmp = explode(',', $optionData); + + foreach ($optionData as $item) { + if ($item{0} == '!') { + if (!empty($disableOptions)) $disableOptions .= ','; + $disableOptions .= "{ value: '".$key."', option: '".StringUtil::substring($item, 1)."' }"; + } + else { + if (!empty($enableOptions)) $enableOptions .= ','; + $enableOptions .= "{ value: '".$key."', option: '".$item."' }"; + } + } + } + } + + return array( + 'disableOptions' => $disableOptions, + 'enableOptions' => $enableOptions + ); + } +} diff --git a/wcfsetup/install/files/lib/system/option/TextOptionType.class.php b/wcfsetup/install/files/lib/system/option/TextOptionType.class.php new file mode 100644 index 0000000000..c0ce5b9e58 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/TextOptionType.class.php @@ -0,0 +1,56 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class TextOptionType extends AbstractOptionType implements ISearchableUserOption { + /** + * input type + * @var string + */ + protected $inputType = 'text'; + + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + WCF::getTPL()->assign(array( + 'option' => $option, + 'inputType' => $this->inputType, + 'value' => $value + )); + return WCF::getTPL()->fetch('optionTypeText'); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getSearchFormElement() + */ + public function getSearchFormElement(Option $option, $value) { + return $this->getFormElement($option, $value); + } + + /** + * @see wcf\system\option\ISearchableUserOption::getCondition() + */ + public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) { + $value = StringUtil::trim($value); + if (empty($value)) return false; + + $conditions->add("option_value.userOption".$option->optionID." LIKE ?", array('%'.addcslashes($value, '_%').'%')); + return true; + } +} diff --git a/wcfsetup/install/files/lib/system/option/TextareaOptionType.class.php b/wcfsetup/install/files/lib/system/option/TextareaOptionType.class.php new file mode 100644 index 0000000000..082b0f1854 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/TextareaOptionType.class.php @@ -0,0 +1,27 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class TextareaOptionType extends TextOptionType { + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + WCF::getTPL()->assign(array( + 'option' => $option, + 'value' => $value + )); + return WCF::getTPL()->fetch('optionTypeTextarea'); + } +} diff --git a/wcfsetup/install/files/lib/system/option/TimezoneOptionType.class.php b/wcfsetup/install/files/lib/system/option/TimezoneOptionType.class.php new file mode 100644 index 0000000000..c8a1ea1b5c --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/TimezoneOptionType.class.php @@ -0,0 +1,45 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class TimezoneOptionType extends AbstractOptionType { + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + $timezoneOptions = array(); + foreach (DateUtil::getAvailableTimezones() as $timezone) { + $timezoneOptions[$timezone] = WCF::getLanguage()->get('wcf.global.date.timezone.'.str_replace('/', '.', strtolower($timezone))); + } + + WCF::getTPL()->assign(array( + 'option' => $option, + 'selectOptions' => $timezoneOptions, + 'value' => $value + )); + return WCF::getTPL()->fetch('optionTypeSelect'); + } + + /** + * @see wcf\system\option\IOptionType::validate() + */ + public function validate(Option $option, $newValue) { + if (!in_array($newValue, DateUtil::getAvailableTimezones())) { + throw new UserInputException($option->optionName, 'validationFailed'); + } + } +}