whoami = $str;
if ( ! is_array( $data ) )
return false;
if ( isset( $data['whoami'] ) ) {
if ( isset( $data['rewrite'] ) && ! $data['rewrite'] && ! isset( $_SESSION['dt_captcha'][$data['whoami']] ) ) {
return false;
}
$this->whoami = trim( strip_tags( $data['whoami'] ) );
}
if ( isset( $data['enable'] ) && false !== $this->whoami ) {
$this->enable = $data['enable'];
$_SESSION['dt_captcha'][$this->whoami]['enable'] = $this->enable;
} elseif( isset( $_SESSION['dt_captcha'][$this->whoami]['enable'] ) ) {
$this->enable = ( bool ) $_SESSION['dt_captcha'][$this->whoami]['enable'];
}
}
function get_captcha() {
$out = '';
// skip captcha if user is logged in and the settings allow
if ( !self::$global_enable || (is_user_logged_in() && true == Dt_Captcha::$hide_register) ) {
return $out;
}
// if not enabled or bad init
if ( false === $this->whoami || !$this->enable ) {
return $out;
}
// captcha html - comment form
if ( ! empty( Dt_Captcha::$label_form ) ) {
$out .= '
'. stripslashes( Dt_Captcha::$label_form ) .'
';
}
$out .= '';
$out .= $this->generate_captcha();
$out .= '
';
return $out;
}
function generate_captcha() {
// In letters presentation of numbers 0-9
$number_string = array();
$number_string[0] = _x( 'null', 'captcha', LANGUAGE_ZONE );
$number_string[1] = _x( 'one', 'captcha', LANGUAGE_ZONE );
$number_string[2] = _x( 'two', 'captcha', LANGUAGE_ZONE );
$number_string[3] = _x( 'three', 'captcha', LANGUAGE_ZONE );
$number_string[4] = _x( 'four', 'captcha', LANGUAGE_ZONE );
$number_string[5] = _x( 'five', 'captcha', LANGUAGE_ZONE );
$number_string[6] = _x( 'six', 'captcha', LANGUAGE_ZONE );
$number_string[7] = _x( 'seven', 'captcha', LANGUAGE_ZONE );
$number_string[8] = _x( 'eight', 'captcha', LANGUAGE_ZONE );
$number_string[9] = _x( 'nine', 'captcha', LANGUAGE_ZONE );
// In letters presentation of numbers 11 -19
$number_two_string = array();
$number_two_string[1] = _x( 'eleven', 'captcha', LANGUAGE_ZONE );
$number_two_string[2] = _x( 'twelve', 'captcha', LANGUAGE_ZONE );
$number_two_string[3] = _x( 'thirteen', 'captcha', LANGUAGE_ZONE );
$number_two_string[4] = _x( 'fourteen', 'captcha', LANGUAGE_ZONE );
$number_two_string[5] = _x( 'fifteen', 'captcha', LANGUAGE_ZONE );
$number_two_string[6] = _x( 'sixteen', 'captcha', LANGUAGE_ZONE );
$number_two_string[7] = _x( 'seventeen', 'captcha', LANGUAGE_ZONE );
$number_two_string[8] = _x( 'eighteen', 'captcha', LANGUAGE_ZONE );
$number_two_string[9] = _x( 'nineteen', 'captcha', LANGUAGE_ZONE );
// In letters presentation of numbers 10, 20, 30, 40, 50, 60, 70, 80, 90
$number_three_string = array();
$number_three_string[1] = _x( 'ten', 'captcha', LANGUAGE_ZONE );
$number_three_string[2] = _x( 'twenty', 'captcha', LANGUAGE_ZONE );
$number_three_string[3] = _x( 'thirty', 'captcha', LANGUAGE_ZONE );
$number_three_string[4] = _x( 'forty', 'captcha', LANGUAGE_ZONE );
$number_three_string[5] = _x( 'fifty', 'captcha', LANGUAGE_ZONE );
$number_three_string[6] = _x( 'sixty', 'captcha', LANGUAGE_ZONE );
$number_three_string[7] = _x( 'seventy', 'captcha', LANGUAGE_ZONE );
$number_three_string[8] = _x( 'eighty', 'captcha', LANGUAGE_ZONE );
$number_three_string[9] = _x( 'ninety', 'captcha', LANGUAGE_ZONE );
// The array of math actions
$math_actions = array();
// If value for Plus on the settings page is set
if ( true == Dt_Captcha::$math_action_plus ) {
$math_actions[] = '+';
}
// If value for Minus on the settings page is set
if ( true == Dt_Captcha::$math_action_minus ) {
$math_actions[] = '−';
}
// If value for Increase on the settings page is set
if ( true == Dt_Captcha::$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 ( false == Dt_Captcha::$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 .= "";
else if ( 0 == $rand_number_string || false == Dt_Captcha::$difficulty_number )
$str_math_expretion .= $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 .= " ";
else if ( 1 == $rand_number_string || false == Dt_Captcha::$difficulty_number )
$str_math_expretion .= " ".$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 .= " ";
} else if ( 2 == $rand_number_string || false == Dt_Captcha::$difficulty_number ) {
if( $array_math_expretion[2] < 10 )
$str_math_expretion .= " ".$number_string[$array_math_expretion[2]];
else if( $array_math_expretion[2] < 20 && $array_math_expretion[2] > 10 )
$str_math_expretion .= " ".$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 ]. _x( "and", 'captcha', LANGUAGE_ZONE ) : '').$number_three_string[ $array_math_expretion[2] / 10 ];
} else {
$str_math_expretion .= " ".$number_three_string[ $array_math_expretion[2] / 10 ]." ".( 0 != $array_math_expretion[2] % 10 ? $number_string[ $array_math_expretion[2] % 10 ] : '');
}
}
} else {
$str_math_expretion .= $array_math_expretion[2];
}
$_SESSION['dt_captcha'][$this->whoami]['captcha'] = self::encode( $array_math_expretion[$rand_input], DT_CAPTCHA_KEY );
$str_math_expretion = str_replace( '' . $c_form->get_captcha() . '';
}