Exemple #1
0
 function cptch_contact_form_options()
 {
     global $cptch_options;
     if (!$cptch_options) {
         $cptch_options = get_option('cptch_options');
     }
     if (isset($cptch_options['cptch_contact_form']) && 1 == $cptch_options['cptch_contact_form'] && !cptch_whitelisted_ip()) {
         add_filter('cntctfrm_display_captcha', 'cptch_custom_form');
         add_filter('cntctfrm_check_form', 'cptch_check_custom_form');
         add_filter('cntctfrmpr_display_captcha', 'cptch_custom_form');
         add_filter('cntctfrmpr_check_form', 'cptch_check_custom_form');
     }
 }
Exemple #2
0
    function cptch_display_captcha_custom()
    {
        global $cptch_options, $cptch_time, $cptch_plugin_info, $cptch_ip_in_whitelist;
        if (empty($cptch_ip_in_whitelist)) {
            $cptch_ip_in_whitelist = cptch_whitelisted_ip();
        }
        if (!$cptch_ip_in_whitelist) {
            if (!$cptch_plugin_info) {
                include_once ABSPATH . 'wp-admin/includes/plugin.php';
                $cptch_plugin_info = get_plugin_data(__FILE__);
            }
            if (!isset($cptch_options['cptch_str_key'])) {
                $cptch_options = get_option('cptch_options');
            }
            if ('' == $cptch_options['cptch_str_key']['key'] || $cptch_options['cptch_str_key']['time'] < time() - 24 * 60 * 60) {
                cptch_generate_key();
            }
            $str_key = $cptch_options['cptch_str_key']['key'];
            /*
             * array of math actions
             */
            $math_actions = array();
            if (1 == $cptch_options['cptch_math_action_plus']) {
                /* If Plus enabled */
                $math_actions[] = '&#43;';
            }
            if (1 == $cptch_options['cptch_math_action_minus']) {
                /* If Minus enabled */
                $math_actions[] = '&minus;';
            }
            if (1 == $cptch_options['cptch_math_action_increase']) {
                /* If Increase enabled */
                $math_actions[] = '&times;';
            }
            /* current math action */
            $rand_math_action = rand(0, count($math_actions) - 1);
            /*
             * get elements of mathematical expression
             */
            $array_math_expretion = array();
            $array_math_expretion[0] = rand(1, 9);
            /* first part */
            $array_math_expretion[1] = rand(1, 9);
            /* second part */
            /* Calculation of the result */
            switch ($math_actions[$rand_math_action]) {
                case "&#43;":
                    $array_math_expretion[2] = $array_math_expretion[0] + $array_math_expretion[1];
                    break;
                case "&minus;":
                    /* Result must not be equal to the negative number */
                    if ($array_math_expretion[0] < $array_math_expretion[1]) {
                        $number = $array_math_expretion[0];
                        $array_math_expretion[0] = $array_math_expretion[1];
                        $array_math_expretion[1] = $number;
                    }
                    $array_math_expretion[2] = $array_math_expretion[0] - $array_math_expretion[1];
                    break;
                case "&times;":
                    $array_math_expretion[2] = $array_math_expretion[0] * $array_math_expretion[1];
                    break;
            }
            /*
             * array of allowed formats
             */
            $allowed_formats = array();
            if (1 == $cptch_options["cptch_difficulty_number"]) {
                /* If Numbers enabled */
                $allowed_formats[] = 'number';
            }
            if (1 == $cptch_options["cptch_difficulty_word"]) {
                /* If Words enabled */
                $allowed_formats[] = 'word';
            }
            if (1 == $cptch_options["cptch_difficulty_image"]) {
                /* If Images enabled */
                $allowed_formats[] = 'image';
            }
            $use_only_words = 1 == $cptch_options["cptch_difficulty_word"] && 0 == $cptch_options["cptch_difficulty_number"] || 0 == $cptch_options["cptch_difficulty_word"] ? true : false;
            /* number of field, which will be displayed as <input type="text"/> */
            $rand_input = rand(0, 2);
            /* 
             * get current format for each operand 
             * for example array( 'text', 'input', 'number' )
             */
            $operand_formats = array();
            $max_rand_value = count($allowed_formats) - 1;
            for ($i = 0; $i < 3; $i++) {
                $operand_formats[] = $rand_input == $i ? 'input' : $allowed_formats[mt_rand(0, $max_rand_value)];
            }
            /*
             * get value of each operand
             */
            $operand = array();
            $id_postfix = rand(0, 100);
            foreach ($operand_formats as $key => $format) {
                switch ($format) {
                    case 'input':
                        $operand[] = '<input id="cptch_input_' . $id_postfix . '" class="cptch_input" type="text" autocomplete="off" name="cptch_number" value="" maxlength="2" size="2" aria-required="true" required="required" style="margin-bottom:0;display:inline;font-size: 12px;width: 40px;" />';
                        break;
                    case 'word':
                        $operand[] = cptch_generate_value($array_math_expretion[$key]);
                        break;
                    case 'image':
                        $operand[] = cptch_get_image($array_math_expretion[$key], $key, $cptch_options['used_packages'][mt_rand(0, count($cptch_options['used_packages']) - 1)], $use_only_words);
                        break;
                    case 'number':
                    default:
                        $operand[] = $array_math_expretion[$key];
                        break;
                }
            }
            /*
             * get html-structure of CAPTCHA
             */
            $reload_button = 1 == $cptch_options['display_reload_button'] ? '<span class="cptch_reload_button_wrap hide-if-no-js">
						<noscript>
							<style type="text/css">
								.hide-if-no-js {
									display: none !important;
								}
							</style>
						</noscript>
						<span class="cptch_reload_button dashicons dashicons-update"></span>
					</span>' : '';
            return '<span class="cptch_wrap">
					<label class="cptch_label" for="cptch_input_' . $id_postfix . '">
						<span class="cptch_span">' . $operand[0] . '</span>
						<span class="cptch_span">&nbsp;' . $math_actions[$rand_math_action] . '&nbsp;</span>
						<span class="cptch_span">' . $operand[1] . '</span>
						<span class="cptch_span">&nbsp;=&nbsp;</span>
						<span class="cptch_span">' . $operand[2] . '</span>
						<input type="hidden" name="cptch_result" value="' . cptch_encode($array_math_expretion[$rand_input], $str_key, $cptch_time) . '" />
						<input type="hidden" name="cptch_time" value="' . $cptch_time . '" />
						<input type="hidden" value="Version: ' . $cptch_plugin_info["Version"] . '" />
					</label>' . $reload_button . '</span>';
        } else {
            return '<label class="cptch_whitelist_message">' . $cptch_options['whitelist_message'] . '</label>';
        }
    }
Exemple #3
0
    function cptch_display_captcha_custom()
    {
        global $cptch_options, $cptch_time, $cptch_plugin_info, $cptch_ip_in_whitelist;
        if (empty($cptch_ip_in_whitelist)) {
            $cptch_ip_in_whitelist = cptch_whitelisted_ip();
        }
        if (!$cptch_ip_in_whitelist) {
            if (!$cptch_plugin_info) {
                include_once ABSPATH . 'wp-admin/includes/plugin.php';
                $cptch_plugin_info = get_plugin_data(__FILE__);
            }
            if (!isset($cptch_options['cptch_str_key'])) {
                $cptch_options = get_option('cptch_options');
            }
            if ('' == $cptch_options['cptch_str_key']['key'] || $cptch_options['cptch_str_key']['time'] < time() - 24 * 60 * 60) {
                cptch_generate_key();
            }
            $str_key = $cptch_options['cptch_str_key']['key'];
            $content = "";
            /* In letters presentation of numbers 0-9 */
            $number_string = array();
            $number_string[0] = __('zero', 'captcha');
            $number_string[1] = __('one', 'captcha');
            $number_string[2] = __('two', 'captcha');
            $number_string[3] = __('three', 'captcha');
            $number_string[4] = __('four', 'captcha');
            $number_string[5] = __('five', 'captcha');
            $number_string[6] = __('six', 'captcha');
            $number_string[7] = __('seven', 'captcha');
            $number_string[8] = __('eight', 'captcha');
            $number_string[9] = __('nine', 'captcha');
            /* In letters presentation of numbers 11 -19 */
            $number_two_string = array();
            $number_two_string[1] = __('eleven', 'captcha');
            $number_two_string[2] = __('twelve', 'captcha');
            $number_two_string[3] = __('thirteen', 'captcha');
            $number_two_string[4] = __('fourteen', 'captcha');
            $number_two_string[5] = __('fifteen', 'captcha');
            $number_two_string[6] = __('sixteen', 'captcha');
            $number_two_string[7] = __('seventeen', 'captcha');
            $number_two_string[8] = __('eighteen', 'captcha');
            $number_two_string[9] = __('nineteen', 'captcha');
            /* In letters presentation of numbers 10, 20, 30, 40, 50, 60, 70, 80, 90 */
            $number_three_string = array();
            $number_three_string[1] = __('ten', 'captcha');
            $number_three_string[2] = __('twenty', 'captcha');
            $number_three_string[3] = __('thirty', 'captcha');
            $number_three_string[4] = __('forty', 'captcha');
            $number_three_string[5] = __('fifty', 'captcha');
            $number_three_string[6] = __('sixty', 'captcha');
            $number_three_string[7] = __('seventy', 'captcha');
            $number_three_string[8] = __('eighty', 'captcha');
            $number_three_string[9] = __('ninety', 'captcha');
            /* The array of math actions */
            $math_actions = array();
            /* If value for Plus on the settings page is set */
            if (1 == $cptch_options['cptch_math_action_plus']) {
                $math_actions[] = '&#43;';
            }
            /* If value for Minus on the settings page is set */
            if (1 == $cptch_options['cptch_math_action_minus']) {
                $math_actions[] = '&minus;';
            }
            /* If value for Increase on the settings page is set */
            if (1 == $cptch_options['cptch_math_action_increase']) {
                $math_actions[] = '&times;';
            }
            /* Which field from three will be the input to enter required value */
            $rand_input = rand(0, 2);
            /* Which field from three will be the letters presentation of numbers */
            $rand_number_string = rand(0, 2);
            /* If don't check Word in setting page - $rand_number_string not display */
            if (0 == $cptch_options["cptch_difficulty_word"]) {
                $rand_number_string = -1;
            }
            /* Set value for $rand_number_string while $rand_input = $rand_number_string */
            while ($rand_input == $rand_number_string) {
                $rand_number_string = rand(0, 2);
            }
            /* What is math action to display in the form */
            $rand_math_action = rand(0, count($math_actions) - 1);
            $array_math_expretion = array();
            /* Add first part of mathematical expression */
            $array_math_expretion[0] = rand(1, 9);
            /* Add second part of mathematical expression */
            $array_math_expretion[1] = rand(1, 9);
            /* Calculation of the mathematical expression result */
            switch ($math_actions[$rand_math_action]) {
                case "&#43;":
                    $array_math_expretion[2] = $array_math_expretion[0] + $array_math_expretion[1];
                    break;
                case "&minus;":
                    /* Result must not be equal to the negative number */
                    if ($array_math_expretion[0] < $array_math_expretion[1]) {
                        $number = $array_math_expretion[0];
                        $array_math_expretion[0] = $array_math_expretion[1];
                        $array_math_expretion[1] = $number;
                    }
                    $array_math_expretion[2] = $array_math_expretion[0] - $array_math_expretion[1];
                    break;
                case "&times;":
                    $array_math_expretion[2] = $array_math_expretion[0] * $array_math_expretion[1];
                    break;
            }
            /* String for display */
            $id_postfix = rand(0, 100);
            $str_math_expretion = '<label class="cptch_label" for="cptch_input_' . $id_postfix . '" style="width: 100%;">';
            /* First part of mathematical expression */
            if (0 == $rand_input) {
                $str_math_expretion .= "<input id=\"cptch_input_" . $id_postfix . "\" class=\"cptch_input\" type=\"text\" autocomplete=\"off\" name=\"cptch_number\" value=\"\" maxlength=\"1\" size=\"1\" style=\"margin-bottom:0;display:inline;font-size: 12px;width: 40px;\" />";
            } else {
                if (0 == $rand_number_string || 0 == $cptch_options["cptch_difficulty_number"]) {
                    $str_math_expretion .= cptch_converting($number_string[$array_math_expretion[0]]);
                } else {
                    $str_math_expretion .= $array_math_expretion[0];
                }
            }
            /* Add math action */
            $str_math_expretion .= " " . $math_actions[$rand_math_action];
            /* Second part of mathematical expression */
            if (1 == $rand_input) {
                $str_math_expretion .= " <input id=\"cptch_input_" . $id_postfix . "\" class=\"cptch_input\" type=\"text\" autocomplete=\"off\" name=\"cptch_number\" value=\"\" maxlength=\"1\" size=\"1\" style=\"margin-bottom:0;display:inline;font-size: 12px;width: 40px;\" />";
            } else {
                if (1 == $rand_number_string || 0 == $cptch_options["cptch_difficulty_number"]) {
                    $str_math_expretion .= " " . cptch_converting($number_string[$array_math_expretion[1]]);
                } else {
                    $str_math_expretion .= " " . $array_math_expretion[1];
                }
            }
            /* Add = */
            $str_math_expretion .= " = ";
            /* Add result of mathematical expression */
            if (2 == $rand_input) {
                $str_math_expretion .= " <input id=\"cptch_input_" . $id_postfix . "\" class=\"cptch_input\" type=\"text\" autocomplete=\"off\" name=\"cptch_number\" value=\"\" maxlength=\"2\" size=\"1\" style=\"margin-bottom:0;display:inline;font-size: 12px;width: 40px;\" />";
            } else {
                if (2 == $rand_number_string || 0 == $cptch_options["cptch_difficulty_number"]) {
                    if (10 > $array_math_expretion[2]) {
                        $str_math_expretion .= " " . cptch_converting($number_string[$array_math_expretion[2]]);
                    } else {
                        if (20 > $array_math_expretion[2] && 10 < $array_math_expretion[2]) {
                            $str_math_expretion .= " " . cptch_converting($number_two_string[$array_math_expretion[2] % 10]);
                        } else {
                            if ("nl-NL" == get_bloginfo('language', 'Display')) {
                                $str_math_expretion .= " " . (0 != $array_math_expretion[2] % 10 ? $number_string[$array_math_expretion[2] % 10] . __("and", 'captcha') : '') . $number_three_string[$array_math_expretion[2] / 10];
                            } else {
                                $str_math_expretion .= " " . cptch_converting($number_three_string[$array_math_expretion[2] / 10]) . " " . (0 != $array_math_expretion[2] % 10 ? cptch_converting($number_string[$array_math_expretion[2] % 10]) : '');
                            }
                        }
                    }
                } else {
                    $str_math_expretion .= $array_math_expretion[2];
                }
            }
            $str_math_expretion .= '</label>';
            /* Add hidden field with encoding result */
            $content .= '<input type="hidden" name="cptch_result" value="' . ($str = cptch_encode($array_math_expretion[$rand_input], $str_key, $cptch_time) . '" />
				<input type="hidden" name="cptch_time" value="' . $cptch_time . '" />
				<input type="hidden" value="Version: ' . $cptch_plugin_info["Version"] . '" />' . $str_math_expretion);
            return $content;
        } else {
            return '<label class="cptch_whitelist_message">' . $cptch_options['whitelist_message'] . '</label>';
        }
    }