/**
 * Validates JavaScript anti-spam test
 *
 */
function js_test_plugin($field_name = 'ct_checkjs', $data = null, $random_key = false)
{
    $ct_data = get_option("cleantalk_data");
    $checkjs = null;
    $js_post_value = null;
    if (!$data) {
        return $checkjs;
    }
    if (isset($data[$field_name])) {
        $js_post_value = $data[$field_name];
        if (isset($keys[$js_post_value])) {
            //
            // Random key check
            //
            if ($random_key) {
                $keys = $ct_data['js_keys'];
                $checkjs = 1;
            } else {
                $checkjs = 0;
            }
        } else {
            $ct_challenge = ct_get_checkjs_value();
            if (preg_match("/{$ct_challenge}/", $js_post_value)) {
                $checkjs = 1;
            } else {
                $checkjs = 0;
            }
        }
    }
    return $checkjs;
}
/**
 * return new cookie value
 */
function ct_get_cookie()
{
    global $ct_checkjs_def;
    $ct_checkjs_key = ct_get_checkjs_value(true);
    print $ct_checkjs_key;
    die;
}
/**
 * Cookies test for sender 
 * @return null|0|1;
 */
function ct_cookies_test($test = false)
{
    $cookie_label = 'ct_cookies_test';
    $secret_hash = ct_get_checkjs_value();
    $result = null;
    if (isset($_COOKIE[$cookie_label])) {
        if ($_COOKIE[$cookie_label] == $secret_hash) {
            $result = 1;
        } else {
            $result = 0;
        }
    } else {
        @setcookie($cookie_label, $secret_hash, 0, '/');
        if ($test) {
            $result = 0;
        }
    }
    return $result;
}