Plugin Directory

Changeset 2741199


Ignore:
Timestamp:
06/12/2022 05:39:57 PM (4 years ago)
Author:
webcource
Message:

read.txt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wc-captcha/trunk/includes/class-core.php

    r2741189 r2741199  
    2929        add_filter('shake_error_codes', array(&$this, 'add_shake_error_codes'), 1);
    3030        add_filter('mod_rewrite_rules', array(&$this, 'block_direct_comments'));
     31
     32        add_action('custom_form_hook', array(&$this, 'add_captcha_form'));
     33        add_shortcode('wccaptcha', [&$this, 'custom_form_captcha_func']);
    3134    }
    3235
     
    4144            'time'   => '' . __('ERROR', 'wc-captcha') . ': ' . __('Captcha time expired.', 'wc-captcha')
    4245        );
    43         add_action("wp_ajax_custom_captcha_error_func",  array(&$this, 'custom_captcha_error_func'));
    44         add_action("wp_ajax_nopriv_custom_captcha_error_func",  array(&$this, 'custom_captcha_error_func'));
    45         add_action("woocommerce_login_form",  array(&$this, 'add_captcha_for_all_form'));
    46         add_action("woocommerce_register_form",  array(&$this, 'add_captcha_for_all_form'));
    4746    }
    4847
     
    9998            add_action('bbp_new_topic_pre_extras', array(&$this, 'check_bbpress_captcha'));
    10099        }
    101         //all forms
    102         // if (Wc_Captcha()->options['general']['enable_for']['all_forms'] && (!is_user_logged_in() || (is_user_logged_in() && !Wc_Captcha()->options['general']['hide_for_logged_users']))) {
    103         add_action('custom_form_hook', array(&$this, 'add_captcha_for_all_form'));
    104         add_shortcode('wccaptcha', array(&$this, 'custom_form_captcha_func'));
    105         // call ajax
    106         // }
    107100    }
    108101
     
    119112        return ob_get_clean();
    120113    }
    121 
    122     public function custom_captcha_error_func()
    123     {
    124 
    125         $error = '';
    126         if (isset($_POST['wc-value']) && $_POST['wc-value'] !== '') {
    127             if ($_COOKIE['wc_session_ids']['all_forms'] !== '' && get_transient('all_forms_' . $_COOKIE['wc_session_ids']['all_forms']) !== false) {
    128                 if (strcmp(get_transient('all_forms_' . $_COOKIE['wc_session_ids']['all_forms']), sha1(AUTH_KEY . $_POST['wc-value'] . $_COOKIE['wc_session_ids']['all_forms'], false)) !== 0)
    129                     $error = $this->error_messages['wrong'];
    130             } else
    131                 $error = $this->error_messages['time'];
     114    public function custom_captcha_error_func($wc_value)
     115    {
     116        $error = '';   
     117        if ($wc_value != '') {
     118            $wc_value = (int)$wc_value;
     119            if ($_SESSION["custom_hidden_answer"] != $wc_value)
     120                $error = 'Invalid captcha value';
    132121        } else
    133 
    134             $error = $this->error_messages['fill'];
    135         if ($error == '')
    136             $result['result'] = 'success';
    137         else
    138             $result['result'] = $error;
    139         echo wp_send_json($result);
    140         wp_die();
    141     }
    142 
     122            $error = 'Please enter captcha value.';
     123        return $error;
     124    }
    143125    public function add_lostpassword_captcha_message($errors)
    144126    {
     
    366348            <span>' . $this->generate_captcha_phrase('default') . '</span>
    367349        </p>';
    368     }
    369     /**
    370      * Display and generate captcha for all forms
    371      *
    372      * @return mixed
    373      */
    374     public function add_captcha_for_all_form()
    375     {
    376         if (is_admin())
    377             return;
    378         if (Wc_Captcha()->options['general']['enable_for']['all_forms']) {
    379 
    380             $captcha_title = apply_filters('Wc_Captcha_title', Wc_Captcha()->options['general']['title']);
    381 
    382             echo '
    383             <p class="wc_captcha-form wc_captch-allform">';
    384 
    385             if (!empty($captcha_title))
    386                 echo '
    387                 <label>' . $captcha_title . '<br/></label>';
    388 
    389             echo '
    390                 <span>' . $this->generate_captcha_phrase('all_forms') . '</span>
    391             </p>
    392             <div class="wc_error-msg"></div>
    393         ';
    394         } else {
    395             echo '<p class="wc_captcha-error">To show captcha. Please enable captcha for All forms.</p>';
    396         }
    397350    }
    398351
     
    551504
    552505        $operations = $groups = array();
    553         $input = '<input type="text" size="2" maxlength="2" id="wc-input" class="wc-input" name="wc-value" value="" aria-required="true"/>';
     506        $input = '<input type="text" size="2" length="2" id="wc-input" class="wc-input" name="wc-value" value="" aria-required="true"/>';
    554507
    555508        // available operations
     
    679632            }
    680633        }
     634
    681635        if (in_array($form, array('default', 'bbpress'), true)) {
    682636            // position of empty input
     
    709663            $transient_name = 'cf7';
    710664            $session_id = Wc_Captcha()->cookie_session->session_ids['multi'][$this->session_number++];
    711         } elseif (in_array($form, array('all_forms'), true)) {
    712             // position of empty input
    713             if ($rnd_input === 0)
    714                 $return = $input . ' ' . $number[3] . ' ' . $this->encode_operation($number[1]) . ' = ' . $this->encode_operation($number[2]);
    715             elseif ($rnd_input === 1)
    716                 $return = $this->encode_operation($number[0]) . ' ' . $number[3] . ' ' . $input . ' = ' . $this->encode_operation($number[2]);
    717             elseif ($rnd_input === 2)
    718                 $return = $this->encode_operation($number[0]) . ' ' . $number[3] . ' ' . $this->encode_operation($number[1]) . ' = ' . $input;
    719 
    720             $transient_name = 'all_forms';
    721             $session_id = Wc_Captcha()->cookie_session->session_ids['all_forms'];
    722         }
     665        }
     666        $_SESSION["custom_hidden_answer"] = $number[$rnd_input];
    723667        set_transient($transient_name . '_' . $session_id, sha1(AUTH_KEY . $number[$rnd_input] . $session_id, false), apply_filters('Wc_Captcha_time', Wc_Captcha()->options['general']['time']));
    724668
Note: See TracChangeset for help on using the changeset viewer.