function cptch_generate_value($value, $use_only_words = true) { $random = $use_only_words ? 1 : mt_rand(0, 1); if (1 == $random) { /* 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'); if ($value < 10) { return cptch_converting($number_string[$value]); } elseif ($value < 20 && $value > 10) { return cptch_converting($number_two_string[$value % 10]); } else { return in_array(get_bloginfo('language', 'Display'), array("nl-NL", "de_DE")) ? (0 != $value % 10 ? $number_string[$value % 10] . " " . __("and", 'captcha') . " " : '') . $number_three_string[$value / 10] : cptch_converting($number_three_string[$value / 10]) . " " . (0 != $value % 10 ? cptch_converting($number_string[$value % 10]) : ''); } } return $value; }
function cptch_display_captcha_custom() { global $cptch_options, $cptch_time; 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[] = '+'; } // If value for Minus on the settings page is set if (1 == $cptch_options['cptch_math_action_minus']) { $math_actions[] = '−'; } // If value for Increase on the settings page is set if (1 == $cptch_options['cptch_math_action_increase']) { $math_actions[] = '×'; } // 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 "+": $array_math_expretion[2] = $array_math_expretion[0] + $array_math_expretion[1]; break; case "−": // 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 "×": $array_math_expretion[2] = $array_math_expretion[0] * $array_math_expretion[1]; break; } // String for display $str_math_expretion = ""; // First part of mathematical expression if (0 == $rand_input) { $str_math_expretion .= "<input type=\"text\" autocomplete=\"off\" name=\"cptch_number\" value=\"\" maxlength=\"1\" size=\"1\" style=\"margin-bottom:0;display:inline;font-size: 12px;width: 30px;\" />"; } 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 type=\"text\" autocomplete=\"off\" name=\"cptch_number\" value=\"\" maxlength=\"1\" size=\"1\" style=\"margin-bottom:0;display:inline;font-size: 12px;width: 30px;\" />"; } 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 type=\"text\" autocomplete=\"off\" name=\"cptch_number\" value=\"\" maxlength=\"2\" size=\"1\" style=\"margin-bottom:0;display:inline;font-size: 12px;width: 30px;\" />"; } else { if (2 == $rand_number_string || 0 == $cptch_options["cptch_difficulty_number"]) { if ($array_math_expretion[2] < 10) { $str_math_expretion .= " " . cptch_converting($number_string[$array_math_expretion[2]]); } else { if ($array_math_expretion[2] < 20 && $array_math_expretion[2] > 10) { $str_math_expretion .= " " . cptch_converting($number_two_string[$array_math_expretion[2] % 10]); } else { if (get_bloginfo('language', 'Display') == "nl-NL") { $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]; } } // Add hidden field with encoding result $content .= '<input type="hidden" name="cptch_result" value="' . ($str = encode($array_math_expretion[$rand_input], $str_key, $cptch_time) . '" /> <input type="hidden" name="cptch_time" value="' . $cptch_time . '" /> <input type="hidden" value="Version: 2.4" />'); $content .= $str_math_expretion; return $content; }
function cptch_display_captcha_custom() { global $cptch_options, $cptch_time, $cptch_plugin_info; 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[] = '+'; } /* If value for Minus on the settings page is set */ if (1 == $cptch_options['cptch_math_action_minus']) { $math_actions[] = '−'; } /* If value for Increase on the settings page is set */ if (1 == $cptch_options['cptch_math_action_increase']) { $math_actions[] = '×'; } /* 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 "+": $array_math_expretion[2] = $array_math_expretion[0] + $array_math_expretion[1]; break; case "−": /* 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 "×": $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; }
function cptch_generate_value($value, $use_only_words = true) { $random = $use_only_words ? 1 : mt_rand(0, 1); if (1 == $random) { $number_string = array(0 => __('zero', 'captcha'), 1 => __('one', 'captcha'), 2 => __('two', 'captcha'), 3 => __('three', 'captcha'), 4 => __('four', 'captcha'), 5 => __('five', 'captcha'), 6 => __('six', 'captcha'), 7 => __('seven', 'captcha'), 8 => __('eight', 'captcha'), 9 => __('nine', 'captcha'), 10 => __('ten', 'captcha'), 11 => __('eleven', 'captcha'), 12 => __('twelve', 'captcha'), 13 => __('thirteen', 'captcha'), 14 => __('fourteen', 'captcha'), 15 => __('fifteen', 'captcha'), 16 => __('sixteen', 'captcha'), 17 => __('seventeen', 'captcha'), 18 => __('eighteen', 'captcha'), 19 => __('nineteen', 'captcha'), 20 => __('twenty', 'captcha'), 21 => __('twenty one', 'captcha'), 22 => __('twenty two', 'captcha'), 23 => __('twenty three', 'captcha'), 24 => __('twenty four', 'captcha'), 25 => __('twenty five', 'captcha'), 26 => __('twenty six', 'captcha'), 27 => __('twenty seven', 'captcha'), 28 => __('twenty eight', 'captcha'), 29 => __('twenty nine', 'captcha'), 30 => __('thirty', 'captcha'), 31 => __('thirty one', 'captcha'), 32 => __('thirty two', 'captcha'), 33 => __('thirty three', 'captcha'), 34 => __('thirty four', 'captcha'), 35 => __('thirty five', 'captcha'), 36 => __('thirty six', 'captcha'), 37 => __('thirty seven', 'captcha'), 38 => __('thirty eight', 'captcha'), 39 => __('thirty nine', 'captcha'), 40 => __('forty', 'captcha'), 41 => __('forty one', 'captcha'), 42 => __('forty two', 'captcha'), 43 => __('forty three', 'captcha'), 44 => __('forty four', 'captcha'), 45 => __('forty five', 'captcha'), 46 => __('forty six', 'captcha'), 47 => __('forty seven', 'captcha'), 48 => __('forty eight', 'captcha'), 49 => __('forty nine', 'captcha'), 50 => __('fifty', 'captcha'), 51 => __('fifty one', 'captcha'), 52 => __('fifty two', 'captcha'), 53 => __('fifty three', 'captcha'), 54 => __('fifty four', 'captcha'), 55 => __('fifty five', 'captcha'), 56 => __('fifty six', 'captcha'), 57 => __('fifty seven', 'captcha'), 58 => __('fifty eight', 'captcha'), 59 => __('fifty nine', 'captcha'), 60 => __('sixty', 'captcha'), 61 => __('sixty one', 'captcha'), 62 => __('sixty two', 'captcha'), 63 => __('sixty three', 'captcha'), 64 => __('sixty four', 'captcha'), 65 => __('sixty five', 'captcha'), 66 => __('sixty six', 'captcha'), 67 => __('sixty seven', 'captcha'), 68 => __('sixty eight', 'captcha'), 69 => __('sixty nine', 'captcha'), 70 => __('seventy', 'captcha'), 71 => __('seventy one', 'captcha'), 72 => __('seventy two', 'captcha'), 73 => __('seventy three', 'captcha'), 74 => __('seventy four', 'captcha'), 75 => __('seventy five', 'captcha'), 76 => __('seventy six', 'captcha'), 77 => __('seventy seven', 'captcha'), 78 => __('seventy eight', 'captcha'), 79 => __('seventy nine', 'captcha'), 80 => __('eighty', 'captcha'), 81 => __('eighty one', 'captcha'), 82 => __('eighty two', 'captcha'), 83 => __('eighty three', 'captcha'), 84 => __('eighty four', 'captcha'), 85 => __('eighty five', 'captcha'), 86 => __('eighty six', 'captcha'), 87 => __('eighty seven', 'captcha'), 88 => __('eighty eight', 'captcha'), 89 => __('eighty nine', 'captcha'), 90 => __('ninety', 'captcha'), 91 => __('ninety one', 'captcha'), 92 => __('ninety two', 'captcha'), 93 => __('ninety three', 'captcha'), 94 => __('ninety four', 'captcha'), 95 => __('ninety five', 'captcha'), 96 => __('ninety six', 'captcha'), 97 => __('ninety seven', 'captcha'), 98 => __('ninety eight', 'captcha'), 99 => __('ninety nine', 'captcha')); $value = cptch_converting($number_string[$value]); } return $value; }