/**
 * General test for any post data
 */
function ct_contact_form_validate_postdata()
{
    global $pagenow, $cleantalk_executed, $cleantalk_url_exclusions;
    if ($cleantalk_executed) {
        return null;
    }
    if (defined('DOING_AJAX') && DOING_AJAX) {
        return null;
    }
    if (isset($cleantalk_url_exclusions)) {
        $ct_cnt = sizeof($cleantalk_url_exclusions);
    } else {
        $ct_cnt = 0;
    }
    @header("CtExclusions: " . $ct_cnt);
    if ($_SERVER['REQUEST_METHOD'] != 'POST' || isset($_POST['log']) && isset($_POST['pwd']) && isset($pagenow) && $pagenow == 'wp-login.php' || isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action'] == 'lostpassword' || ct_check_array_keys($_POST) || (isset($pagenow) && $pagenow == 'wp-cron.php' || strpos($_SERVER['REQUEST_URI'], '/checkout/') !== false) || strpos($_SERVER['REQUEST_URI'], '/wp-admin/') !== false || strpos($_SERVER['REQUEST_URI'], 'wp-login.php') !== false || strpos($_SERVER['REQUEST_URI'], 'wp-comments-post.php') !== false || @strpos($_SERVER['HTTP_REFERER'], '/wp-admin/') !== false || check_url_exclusions()) {
        return null;
    }
    $_POST = ct_filter_array($_POST);
    $checkjs = js_test('ct_checkjs', $_COOKIE, true);
    $post_info['comment_type'] = 'feedback_general_postdata';
    $post_info = json_encode($post_info);
    if ($post_info === false) {
        $post_info = '';
    }
    $message = '';
    ct_get_fields_any_postdata($message, $_POST);
    if (strlen(trim($message)) < 10) {
        return null;
    }
    $skip_params = array('ipn_track_id', 'txn_type', 'payment_status');
    foreach ($skip_params as $key => $value) {
        if (@array_key_exists($value, $_GET) || @array_key_exists($value, $_POST)) {
            return null;
        }
    }
    $ct_base_call_result = ct_base_call(array('message' => $message, 'example' => null, 'sender_email' => '', 'sender_nickname' => '', 'post_info' => $post_info, 'sender_info' => get_sender_info(), 'checkjs' => $checkjs));
    $cleantalk_executed = true;
    $ct = $ct_base_call_result['ct'];
    $ct_result = $ct_base_call_result['ct_result'];
    if ($ct_result->allow == 0) {
        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
            global $ct_comment;
            $ct_comment = $ct_result->comment;
            if (isset($_POST['cma-action']) && $_POST['cma-action'] == 'add') {
                $result = array('success' => 0, 'thread_id' => null, 'messages' => array($ct_result->comment));
                header("Content-Type: application/json");
                print json_encode($result);
                die;
            } else {
                ct_die(null, null);
            }
        } else {
            echo $ct_result->comment;
        }
        exit;
    }
    return null;
}
function ct_theme_submit()
{
    require_once CLEANTALK_PLUGIN_DIR . 'cleantalk-public.php';
    global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options, $ct_data;
    $ct_data = ct_get_data();
    $ct_options = ct_get_options();
    $sender_email = null;
    $message = '';
    if (isset($_POST['cscf']['confirm-email'])) {
        $tmp = $_POST['cscf']['confirm-email'];
        $_POST['cscf']['confirm-email'] = 1;
    }
    ct_get_fields($sender_email, $message, $_POST);
    if (isset($_POST['cscf']['confirm-email'])) {
        $_POST['cscf']['confirm-email'] = $tmp;
    }
    if ($sender_email != null) {
        $checkjs = js_test('ct_checkjs', $_COOKIE, true);
        $submit_time = submit_time_test();
        $sender_info = get_sender_info();
        $sender_info['post_checkjs_passed'] = $checkjs;
        $sender_info = json_encode($sender_info);
        if ($sender_info === false) {
            $sender_info = '';
        }
        $ct_base_call_result = ct_base_call(array('message' => $message, 'example' => null, 'sender_email' => $sender_email, 'sender_nickname' => null, 'sender_info' => $sender_info, 'post_info' => null, 'checkjs' => $checkjs));
        $ct = $ct_base_call_result['ct'];
        $ct_result = $ct_base_call_result['ct_result'];
        if ($ct_result->allow == 0) {
            $result = array('sent' => true, 'valid' => false, 'errorlist' => array('name' => $ct_result->comment));
            print json_encode($result);
            die;
        }
    }
}
function ct_ajax_hook()
{
    require_once CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php';
    global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options, $ct_data;
    $ct_options = ct_get_options();
    $ct_data = ct_get_data();
    $sender_email = null;
    $message = '';
    $nickname = null;
    if (isset($_POST['user_login'])) {
        $nickname = $_POST['user_login'];
    } else {
        $nickname = '';
    }
    if (isset($_POST['cscf']['confirm-email'])) {
        $tmp = $_POST['cscf']['confirm-email'];
        $_POST['cscf']['confirm-email'] = 1;
    }
    if (($_POST['action'] == 'request_appointment' || $_POST['action'] == 'send_message') && isset($_POST['target'])) {
        $tmp = $_POST['target'];
        $_POST['target'] = 1;
    }
    ct_get_fields($sender_email, $message, $_POST);
    if (isset($_POST['cscf']['confirm-email'])) {
        $_POST['cscf']['confirm-email'] = $tmp;
    }
    if (($_POST['action'] == 'request_appointment' || $_POST['action'] == 'send_message') && isset($_POST['target'])) {
        $_POST['target'] = $tmp;
    }
    if ($sender_email != null) {
        $checkjs = js_test('ct_checkjs', $_COOKIE, true);
        $submit_time = submit_time_test();
        $sender_info = get_sender_info();
        $sender_info['post_checkjs_passed'] = $checkjs;
        $sender_info = json_encode($sender_info);
        if ($sender_info === false) {
            $sender_info = '';
        }
        $ct_base_call_result = ct_base_call(array('message' => $message, 'example' => null, 'sender_email' => $sender_email, 'sender_nickname' => $nickname, 'sender_info' => $sender_info, 'post_info' => null, 'checkjs' => $checkjs));
        $ct = $ct_base_call_result['ct'];
        $ct_result = $ct_base_call_result['ct_result'];
        if ($ct_result->allow == 0) {
            if ($_POST['action'] == 'wpuf_submit_register') {
                $result = array('success' => false, 'error' => $ct_result->comment);
                @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
                print json_encode($result);
                die;
            } else {
                if ($_POST['action'] == 'mymail_form_submit') {
                    $result = array('success' => false, 'html' => $ct_result->comment);
                    @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
                    print json_encode($result);
                    die;
                } else {
                    if ($_POST['action'] == 'wysija_ajax' && $_POST['task'] != 'send_preview') {
                        $result = array('result' => false, 'msgs' => array('updated' => array($ct_result->comment)));
                        //@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
                        print $_GET['callback'] . '(' . json_encode($result) . ');';
                        die;
                    } else {
                        if ($_POST['action'] == 'cs_registration_validation') {
                            $result = array("type" => "error", "message" => $ct_result->comment);
                            print json_encode($result);
                            die;
                        } else {
                            if ($_POST['action'] == 'request_appointment' || $_POST['action'] == 'send_message') {
                                print $ct_result->comment;
                                die;
                            } else {
                                if ($_POST['action'] == 'zn_do_login') {
                                    print '<div id="login_error">' . $ct_result->comment . '</div>';
                                    die;
                                } else {
                                    if ($_POST['action'] == 'vfb_submit') {
                                        $result = array('result' => false, 'message' => $ct_result->comment);
                                        @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
                                        print json_encode($result);
                                        die;
                                    } else {
                                        if ($_POST['action'] == 'cscf-submitform') {
                                            $result = array('sent' => true, 'valid' => false, 'errorlist' => array('name' => $ct_result->comment));
                                            print json_encode($result);
                                            die;
                                        } else {
                                            if ($_POST['action'] == 'woocommerce_checkout') {
                                                print $ct_result->comment;
                                                die;
                                            } else {
                                                if ($_POST['action'] == 'frm_entries_create') {
                                                    $result = array('112' => $ct_result->comment);
                                                    print json_encode($result);
                                                    die;
                                                } else {
                                                    if (isset($_POST['cma-action']) && $_POST['cma-action'] == 'add') {
                                                        $result = array('success' => 0, 'thread_id' => null, 'messages' => array($ct_result->comment));
                                                        print json_encode($result);
                                                        die;
                                                    } else {
                                                        if ($_POST['action'] == 'td_mod_register') {
                                                            print json_encode(array('register', 0, $ct_result->comment));
                                                            die;
                                                        } else {
                                                            if ($_POST['action'] == 'tmpl_ajax_check_user_email') {
                                                                print "17,email";
                                                                die;
                                                            } else {
                                                                if ($_POST['action'] == 'tevolution_submit_from_preview' || $_POST['action'] == 'submit_form_recaptcha_validation') {
                                                                    print $ct_result->comment;
                                                                    die;
                                                                } else {
                                                                    if ($_POST['action'] == 'ninja_forms_ajax_submit') {
                                                                        print '{"form_id":' . $_POST['_form_id'] . ',"errors":false,"success":{"success_msg-Success":"' . $ct_result->comment . '"}}';
                                                                        die;
                                                                    } else {
                                                                        print $ct_result->comment;
                                                                        die;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 public function testjs_testByCookies()
 {
     global $ct_data;
     $ct_data['js_keys'] = ['my_js_key' => '213'];
     $_COOKIE['ct_checkjs'] = 'my_js_key';
     $this->assertEquals(1, js_test('ct_checkjs', $_COOKIE, true));
     $_COOKIE['ct_checkjs'] = 'bad_key';
     $this->assertEquals(0, js_test('ct_checkjs', $_COOKIE, true));
 }