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;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
function ct_get_fields(&$email, &$message, $arr)
{
    foreach ($arr as $key => $value) {
        if (!is_array($value)) {
            if ($email === null && preg_match("/^\\S+@\\S+\\.\\S+\$/", $value)) {
                $email = $value;
            } else {
                $message .= "{$value}\n";
            }
        } else {
            ct_get_fields($email, $message, $value);
        }
    }
}