From c44dc3ce03b31a49e8d2d1f6cc6564b3e3d54d04 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 8 Nov 2011 15:15:10 +0100 Subject: [PATCH] Added support for user options --- .../lib/data/user/option/UserOption.class.php | 12 ++++ .../files/lib/util/OptionUtil.class.php | 66 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 wcfsetup/install/files/lib/util/OptionUtil.class.php diff --git a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php index 06f97db1c7..4802f4a36a 100644 --- a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php +++ b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php @@ -22,4 +22,16 @@ class UserOption extends Option { * @see wcf\data\DatabaseObject::$databaseTableIndexName */ protected static $databaseTableIndexName = 'optionID'; + + /** + * option value + * @var string + */ + public $optionValue = ''; + + /** + * output data + * @var array + */ + public $outputData = array(); } diff --git a/wcfsetup/install/files/lib/util/OptionUtil.class.php b/wcfsetup/install/files/lib/util/OptionUtil.class.php new file mode 100644 index 0000000000..0c312555c0 --- /dev/null +++ b/wcfsetup/install/files/lib/util/OptionUtil.class.php @@ -0,0 +1,66 @@ + + * @package com.woltlab.wcf + * @subpackage util + * @category Community Framework + */ +class OptionUtil { + /** + * Returns a list of the available options. + * + * @param string $selectOptions + * @return array + */ + public static function parseSelectOptions($selectOptions) { + $result = array(); + $options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($selectOptions))); + foreach ($options as $option) { + $key = $value = $option; + if (StringUtil::indexOf($option, ':') !== false) { + $optionData = explode(':', $option); + $key = array_shift($optionData); + $value = implode(':', $optionData); + } + + $result[$key] = $value; + } + + return $result; + } + + /** + * Returns a list of the enable options. + * + * @param string $enableOptions + * @return array + */ + public static function parseMultipleEnableOptions($enableOptions) { + $result = array(); + if (!empty($enableOptions)) { + $options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($enableOptions))); + $key = -1; + foreach ($options as $option) { + if (StringUtil::indexOf($option, ':') !== false) { + $optionData = explode(':', $option); + $key = array_shift($optionData); + $value = implode(':', $optionData); + } + else { + $key++; + $value = $option; + } + + $result[$key] = $value; + } + } + + return $result; + } +} -- 2.20.1