From 1170aad7c8f60b91902ba23ccf9b9562636da763 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 26 Aug 2016 09:53:35 +0200 Subject: [PATCH] Use enableoptions for captcha selection --- com.woltlab.wcf/option.xml | 5 +-- .../option/CaptchaSelectOptionType.class.php | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/com.woltlab.wcf/option.xml b/com.woltlab.wcf/option.xml index 3536ae5ebf..e9491cce1b 100644 --- a/com.woltlab.wcf/option.xml +++ b/com.woltlab.wcf/option.xml @@ -672,30 +672,27 @@ private:wcf.acp.option.exception_privacy.private captchaSelect com.woltlab.wcf.recaptcha 1 + :!register_use_captcha,!lost_password_use_captcha,!profile_mail_use_captcha,!search_use_captcha diff --git a/wcfsetup/install/files/lib/system/option/CaptchaSelectOptionType.class.php b/wcfsetup/install/files/lib/system/option/CaptchaSelectOptionType.class.php index 6b9b1973f3..059765bf98 100644 --- a/wcfsetup/install/files/lib/system/option/CaptchaSelectOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/CaptchaSelectOptionType.class.php @@ -27,13 +27,52 @@ class CaptchaSelectOptionType extends AbstractOptionType { ); } + $options = $this->parseEnableOptions($option); + return WCF::getTPL()->fetch('selectOptionType', 'wcf', [ + 'disableOptions' => $options['disableOptions'], + 'enableOptions' => $options['enableOptions'], 'selectOptions' => $selectOptions, 'option' => $option, 'value' => $value ]); } + /** + * Prepares JSON-encoded values for disabling or enabling dependent options. + * + * @param Option $option + * @return array + * @see SelectOptionType::parseEnableOptions() + */ + protected function parseEnableOptions(Option $option) { + $disableOptions = $enableOptions = ''; + + if (!empty($option->enableOptions)) { + $options = $option->parseMultipleEnableOptions(); + + foreach ($options as $key => $optionData) { + $tmp = explode(',', $optionData); + + foreach ($tmp as $item) { + if ($item{0} == '!') { + if (!empty($disableOptions)) $disableOptions .= ','; + $disableOptions .= "{ value: '".$key."', option: '".mb_substr($item, 1)."' }"; + } + else { + if (!empty($enableOptions)) $enableOptions .= ','; + $enableOptions .= "{ value: '".$key."', option: '".$item."' }"; + } + } + } + } + + return [ + 'disableOptions' => $disableOptions, + 'enableOptions' => $enableOptions + ]; + } + /** * @inheritDoc */ -- 2.20.1