Use enableoptions for captcha selection
authorMatthias Schmidt <gravatronics@live.com>
Fri, 26 Aug 2016 07:53:35 +0000 (09:53 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 26 Aug 2016 07:53:38 +0000 (09:53 +0200)
com.woltlab.wcf/option.xml
wcfsetup/install/files/lib/system/option/CaptchaSelectOptionType.class.php

index 3536ae5ebff13b1bcd98f19f59d2b47e49c4af1e..e9491cce1b96c13d39cc4959cef9d98bf7318be1 100644 (file)
@@ -672,30 +672,27 @@ private:wcf.acp.option.exception_privacy.private</selectoptions>
                                <optiontype>captchaSelect</optiontype>
                                <defaultvalue>com.woltlab.wcf.recaptcha</defaultvalue>
                                <allowemptyvalue>1</allowemptyvalue>
+                               <enableoptions>:!register_use_captcha,!lost_password_use_captcha,!profile_mail_use_captcha,!search_use_captcha</enableoptions>
                        </option>
                        <option name="register_use_captcha">
                                <categoryname>security.antispam.captcha</categoryname>
                                <optiontype>boolean</optiontype>
                                <defaultvalue>1</defaultvalue>
-                               <options>captcha_type</options>
                        </option>
                        <option name="lost_password_use_captcha">
                                <categoryname>security.antispam.captcha</categoryname>
                                <optiontype>boolean</optiontype>
                                <defaultvalue>1</defaultvalue>
-                               <options>captcha_type</options>
                        </option>
                        <option name="profile_mail_use_captcha">
                                <categoryname>security.antispam.captcha</categoryname>
                                <optiontype>boolean</optiontype>
                                <defaultvalue>1</defaultvalue>
-                               <options>captcha_type</options>
                        </option>
                        <option name="search_use_captcha">
                                <categoryname>security.antispam.captcha</categoryname>
                                <optiontype>boolean</optiontype>
                                <defaultvalue>0</defaultvalue>
-                               <options>captcha_type</options>
                        </option>
                        <!-- /security.antispam.captcha -->
                        
index 6b9b1973f3c9a92b69292cc22d3f4b8db06e7a8a..059765bf983b1bdf0a4c7be1950ad159c51b4e7d 100644 (file)
@@ -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
         */