function wplc_admin_menu_layout_display()
{
    if (current_user_can('wplc_ma_agent') || current_user_can('manage_options')) {
        wplc_stats("chat_dashboard");
        global $wplc_basic_plugin_url;
        if (!isset($_GET['action'])) {
            ?>
        <style>
                #wplc-support-tabs a.wplc-support-link {
            background: url('<?php 
            echo $wplc_basic_plugin_url;
            ?>
/images/support.png');
            right: 0px;
            top: 250px;
            height: 108px;
            width: 45px;
            margin: 0;
            padding: 0;
            position: fixed;
            z-index: 9999;
            display:block;
        }
        </style>

            <div id="wplc-support-tabs">
                <a class="wplc-support-link wplc-rotate" href="?page=wplivechat-menu-support-page"></a>
            </div>
            <div class='wplc_page_title'>
                <h1><?php 
            _e("Chat Dashboard", "wplivechat");
            ?>
</h1>
                <?php 
            wplc_first_time_tutorial();
            ?>

                <p><?php 
            _e("Please note: This window must be open in order to receive new chat notifications.", "wplivechat");
            ?>
</p>
            </div>
            
            <div id="wplc_sound"></div>

            <div id="wplc_admin_chat_holder">
                <div id='wplc_admin_chat_info_new'>
                    <div class='wplc_chat_vis_count_box'>
                        <span class='wplc_vis_online'>0</span>
                        <span style='text-transform:uppercase;'>
                            <?php 
            _e("Visitors online", "wplivechat");
            ?>
                        </span>
                        <hr />
                        <p class='wplc-agent-info' id='wplc-agent-info'>
                            <span class='wplc_agents_online'>1</span>
                            <a href='javascript:void(0);'><?php 
            _e("Agent(s) online", "wplivechat");
            ?>
</a>
                        </p>
                        
                    </div>
                    
                </div>
                
                <div id="wplc_admin_chat_area_new">
                    <div style="display:block;padding:10px;">
                    <ul class='wplc_chat_ul_header'>
                        <li><span class='wplc_header_vh wplc_headerspan_v'><?php 
            _e("Visitor", "wplivechat");
            ?>
</span></li>
                        <li><span class='wplc_header_vh wplc_headerspan_t'><?php 
            _e("Time", "wplivechat");
            ?>
</span></li>
                        <li><span class='wplc_header_vh wplc_headerspan_nr'><?php 
            _e("Type", "wplivechat");
            ?>
</span></li>
                        <li><span class='wplc_header_vh wplc_headerspan_d'><?php 
            _e("Data", "wplivechat");
            ?>
</span></li>
                        <li><span class='wplc_header_vh wplc_headerspan_s'><?php 
            _e("Status", "wplivechat");
            ?>
</span></li>
                        <li><span class='wplc_header_vh wplc_headerspan_a'><?php 
            _e("Action", "wplivechat");
            ?>
</span></li>
                    </ul>
                    <ul id='wplc_chat_ul'>


                    </ul>
                        <p>
            <?php 
            _e("With the Pro add-on of WP Live Chat Support, you can", "wplivechat");
            ?>
 
            <a href="http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=initiate1" title="<?php 
            _e("see who's online and initiate chats", "wplivechat");
            ?>
" target=\"_BLANK\">
               <?php 
            _e("initiate chats", "wplivechat");
            ?>
            </a> <?php 
            _e("with your online visitors with the click of a button.", "wplivechat");
            ?>
 
            <a href="http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=initiate2" title="<?php 
            _e("Buy the Pro add-on now.", "wplivechat");
            ?>
" target=\"_BLANK\">
               <strong>
                   <?php 
            _e("Buy the Pro add-on now.", "wplivechat");
            ?>
               </strong>
            </a>
            </p>
                    </div>

                </div>
                
            </div>
            
            
          

            <?php 
        } else {
            if ($_GET['action'] == 'ac') {
                wplc_change_chat_status(sanitize_text_field($_GET['cid']), 3);
                if (function_exists('wplc_ma_register')) {
                    wplc_ma_update_agent_id(sanitize_text_field($_GET['cid']), sanitize_text_field($_GET['agent_id']));
                }
                if (function_exists("wplc_register_pro_version")) {
                    wplc_pro_draw_chat_area(sanitize_text_field($_GET['cid']));
                } else {
                    wplc_draw_chat_area(sanitize_text_field($_GET['cid']));
                }
            }
        }
    }
}
示例#2
0
         wplc_change_chat_status(sanitize_text_field($_POST['cid']), 9);
     } else {
         if ($_POST['status'] == 3) {
             wplc_change_chat_status(sanitize_text_field($_POST['cid']), 8);
         }
     }
     die;
 }
 if ($_POST['action'] == "wplc_user_minimize_chat") {
     $chat_id = $_POST['cid'];
     wplc_change_chat_status(sanitize_text_field($_POST['cid']), 10);
     die;
 }
 if ($_POST['action'] == "wplc_user_maximize_chat") {
     $chat_id = $_POST['cid'];
     wplc_change_chat_status(sanitize_text_field($_POST['cid']), 3);
     die;
 }
 if ($_POST['action'] == "wplc_user_send_msg") {
     $chat_id = sanitize_text_field($_POST['cid']);
     $chat_msg = sanitize_text_field($_POST['msg']);
     //wplc_error_log("[".__LINE__."] SENDING CHAT MSG FROM USER : $chat_id : $chat_msg");
     $wplc_rec_msg = wplc_record_chat_msg("1", $chat_id, $chat_msg);
     if ($wplc_rec_msg) {
         echo 'sent';
         die;
     } else {
         echo "There was an error sending your chat message. Please contact support";
         die;
     }
 }
示例#3
0
function wplc_record_chat_msg_pro($from, $cid, $msg)
{
    global $wpdb;
    global $wplc_tblname_msgs;
    if ($from == "1") {
        $fromname = wplc_return_chat_name($cid);
        $orig = '2';
    } else {
        $fromname = $_POST['admin_name'];
        $orig = '1';
    }
    if (function_exists('wplc_encrypt_msg')) {
        $msg = wplc_encrypt_msg($msg);
    }
    $ins_array = array('chat_sess_id' => $cid, 'timestamp' => date("Y-m-d H:i:s"), 'from' => $fromname, 'msg' => $msg, 'status' => 0, 'originates' => $orig);
    $rows_affected = $wpdb->insert($wplc_tblname_msgs, $ins_array);
    wplc_update_active_timestamp($cid);
    wplc_change_chat_status($cid, 3);
    return true;
}
示例#4
0
function wplc_update_chat_statuses()
{
    global $wpdb;
    global $wplc_tblname_chats;
    $results = $wpdb->get_results("\n        SELECT *\n        FROM {$wplc_tblname_chats}\n        WHERE `status` = '2' OR `status` = '3' OR `status` = '5' or `status` = '8' or `status` = '9' or `status` = '10'\n        ");
    foreach ($results as $result) {
        $id = $result->id;
        $timestamp = strtotime($result->last_active_timestamp);
        $datenow = current_time('timestamp');
        $difference = $datenow - $timestamp;
        if (intval($result->status) == 2) {
            if ($difference >= 60) {
                // 1 minute max
                wplc_change_chat_status($id, 0);
            }
        } else {
            if (intval($result->status) == 3) {
                if ($difference >= 300) {
                    // 30 seconds
                    wplc_change_chat_status($id, 1);
                }
            } else {
                if (intval($result->status) == 5) {
                    if ($difference >= 120) {
                        // 2 minute timeout
                        wplc_change_chat_status($id, 7);
                        // 7 - timedout
                    }
                } else {
                    if (intval($result->status) == 8) {
                        // chat is complete but user is still browsing
                        if ($difference >= 45) {
                            // 30 seconds
                            wplc_change_chat_status($id, 1);
                            // 1 - chat is now complete
                        }
                    } else {
                        if (intval($result->status) == 9 || $result->status == 10) {
                            if ($difference >= 120) {
                                // 120 seconds
                                wplc_change_chat_status($id, 7);
                                // 7 - timedout
                            }
                        }
                    }
                }
            }
        }
    }
}
function wplc_admin_pro_request_chat($cid)
{
    wplc_change_chat_status($cid, 6);
    // 6 = request chat
    wplc_pro_draw_chat_area($cid);
}
function wplc_api_record_admin_message($cid, $msg)
{
    global $wpdb;
    global $wplc_tblname_msgs;
    $fromname = apply_filters("wplc_filter_admin_name", "Admin");
    $orig = '1';
    $msg = apply_filters("wplc_filter_message_control", $msg);
    $wpdb->insert($wplc_tblname_msgs, array('chat_sess_id' => $cid, 'timestamp' => current_time('mysql'), 'msgfrom' => $fromname, 'msg' => $msg, 'status' => 0, 'originates' => $orig), array('%s', '%s', '%s', '%s', '%d', '%s'));
    wplc_update_active_timestamp(sanitize_text_field($cid));
    wplc_change_chat_status(sanitize_text_field($cid), 3);
    return true;
}
function wplc_init_ajax_callback()
{
    @ob_start();
    $check = check_ajax_referer('wplc', 'security');
    if ($check == 1) {
        $wplc_advanced_settings = get_option("wplc_advanced_settings");
        if (!$wplc_advanced_settings) {
            $wplc_delay_between_updates = 500000;
            $wplc_delay_between_loops = 500000;
            $wplc_iterations = 55;
        } else {
            if (isset($wplc_advanced_settings['wplc_delay_between_updates'])) {
                $wplc_delay_between_updates = intval($wplc_advanced_settings['wplc_delay_between_updates']);
            } else {
                $wplc_delay_between_updates = 500000;
            }
            if (isset($wplc_advanced_settings['wplc_delay_between_loops'])) {
                $wplc_delay_between_loops = intval($wplc_advanced_settings['wplc_delay_between_loops']);
            } else {
                $wplc_delay_between_loops = 500000;
            }
            if (isset($wplc_advanced_settings['wplc_iterations'])) {
                $wplc_iterations = intval($wplc_advanced_settings['wplc_iterations']);
            } else {
                $wplc_iterations = 55;
            }
            if ($wplc_iterations < 10) {
                $wplc_iterations = 10;
            }
            if ($wplc_iterations > 200) {
                $wplc_iterations = 200;
            }
            if ($wplc_delay_between_updates < 250000) {
                $wplc_delay_between_updates = 250000;
            }
            if ($wplc_delay_between_updates > 1000000) {
                $wplc_delay_between_updates = 1000000;
            }
            if ($wplc_delay_between_loops < 250000) {
                $wplc_delay_between_loops = 250000;
            }
            if ($wplc_delay_between_loops > 1000000) {
                $wplc_delay_between_loops = 1000000;
            }
        }
        $iterations = $wplc_iterations;
        /* time in microseconds between updating the user on the page within the DB  (lower number = higher resource usage) */
        define('WPLC_DELAY_BETWEEN_UPDATES', $wplc_delay_between_updates);
        /* time in microseconds between long poll loop (lower number = higher resource usage) */
        define('WPLC_DELAY_BETWEEN_LOOPS', $wplc_delay_between_loops);
        /* this needs to take into account the previous constants so that we dont run out of time, which in turn returns a 503 error */
        define('WPLC_TIMEOUT', (WPLC_DELAY_BETWEEN_UPDATES + WPLC_DELAY_BETWEEN_LOOPS) * $iterations / 1000000);
        global $wpdb;
        global $wplc_tblname_chats;
        global $wplc_tblname_msgs;
        /* we're using PHP 'sleep' which may lock other requests until our script wakes up. Call this function to ensure that other requests can run without waiting for us to finish */
        session_write_close();
        if ($_POST['action'] == "wplc_get_chat_box") {
            echo wplc_output_box_5100();
        }
        if ($_POST['action'] == 'wplc_admin_long_poll') {
            // header("HTTP/1.0 500"); //Simulate 500 error
            // header("HTTP/1.0 404"); //Simulate 404 error
            // die();
            if (defined('WPLC_TIMEOUT')) {
                @set_time_limit(WPLC_TIMEOUT);
            } else {
                @set_time_limit(120);
            }
            //sleep(6);
            $i = 1;
            $wplc_current_user = get_current_user_id();
            /* If user is either an agent or an admin, access the page. */
            if (!get_user_meta($wplc_current_user, 'wplc_ma_agent', true)) {
                $array['error'] = 1;
                echo json_encode($array);
                exit;
            }
            while ($i <= $iterations) {
                // update chats if they have timed out every 15 iterations
                if ($i % 15 == 0) {
                    wplc_update_chat_statuses();
                }
                if ($_POST['wplc_update_admin_chat_table'] == 'false') {
                    /* this is a new load of the page, return false so we can force a send of the new visitor data */
                    $old_chat_data = false;
                } else {
                    $old_chat_data = stripslashes($_POST['wplc_update_admin_chat_table']);
                }
                $pending = wplc_check_pending_chats();
                $new_chat_data = wplc_list_chats_new($_POST);
                if ($new_chat_data == "false") {
                    $new_chat_data = false;
                }
                if ($new_chat_data !== $old_chat_data) {
                    $array['old_chat_data'] = $old_chat_data;
                    $array['wplc_update_admin_chat_table'] = $new_chat_data;
                    $array['pending'] = $pending;
                    $array['action'] = "wplc_update_chat_list";
                }
                if (isset($array)) {
                    echo json_encode($array);
                    break;
                }
                @ob_end_flush();
                if (defined('WPLC_DELAY_BETWEEN_LOOPS')) {
                    usleep(WPLC_DELAY_BETWEEN_LOOPS);
                } else {
                    usleep(500000);
                }
                $i++;
            }
        }
        if ($_POST['action'] == "wplc_admin_long_poll_chat") {
            if (defined('WPLC_TIMEOUT')) {
                @set_time_limit(WPLC_TIMEOUT);
            } else {
                @set_time_limit(120);
            }
            $i = 1;
            $array = array();
            while ($i <= $iterations) {
                $array = apply_filters("wplc_filter_admin_long_poll_chat_loop_iteration", $array, $_POST, $i);
                if ($array) {
                    echo json_encode($array);
                    break;
                }
                @ob_end_flush();
                if (defined('WPLC_DELAY_BETWEEN_LOOPS')) {
                    usleep(WPLC_DELAY_BETWEEN_LOOPS);
                } else {
                    usleep(500000);
                }
                $i++;
            }
        }
        if ($_POST['action'] == "wplc_admin_accept_chat") {
            wplc_admin_accept_chat(sanitize_text_field($_POST['cid']));
        }
        if ($_POST['action'] == "wplc_admin_close_chat") {
            $chat_id = sanitize_text_field($_POST['cid']);
            wplc_change_chat_status($chat_id, 1);
            echo 'done';
        }
        if ($_POST['action'] == "wplc_admin_send_msg") {
            $chat_id = sanitize_text_field($_POST['cid']);
            $chat_msg = sanitize_text_field($_POST['msg']);
            $wplc_rec_msg = wplc_record_chat_msg("2", $chat_id, $chat_msg);
            if ($wplc_rec_msg) {
                echo 'sent';
            } else {
                echo "There was an error sending your chat message. Please contact support";
            }
        }
        //User Ajax
        if ($_POST['action'] == 'wplc_call_to_server_visitor') {
            if (defined('WPLC_TIMEOUT')) {
                @set_time_limit(WPLC_TIMEOUT);
            } else {
                @set_time_limit(120);
            }
            $i = 1;
            $array = array("check" => false);
            $array['debug'] = "";
            while ($i <= $iterations) {
                if ($_POST['cid'] == null || $_POST['cid'] == "" || $_POST['cid'] == "null" || $_POST['cid'] == 0) {
                    //                echo 1;
                    if (isset($_POST['wplc_name']) && $_POST['wplc_name'] !== '') {
                        $user = sanitize_text_field($_POST['wplc_name']);
                    } else {
                        $user = "******";
                    }
                    if (isset($_POST['wplc_email']) && $_POST['wplc_email'] !== '') {
                        $email = sanitize_text_field($_POST['wplc_email']);
                    } else {
                        $email = "no email set";
                    }
                    if (isset($_POST['wplc_is_mobile']) && ($_POST['wplc_is_mobile'] === 'true' || $_POST['wplc_is_mobile'] === true)) {
                        $is_mobile = true;
                    } else {
                        $is_mobile = false;
                    }
                    $cid = wplc_log_user_on_page($user, $email, sanitize_text_field($_POST['wplcsession']), $is_mobile);
                    $array['cid'] = $cid;
                    $array['status'] = wplc_return_chat_status($cid);
                    $array['wplc_name'] = $user;
                    $array['wplc_email'] = $email;
                    $array['check'] = true;
                } else {
                    //                echo 2;
                    $new_status = wplc_return_chat_status(sanitize_text_field($_POST['cid']));
                    $array['wplc_name'] = sanitize_text_field($_POST['wplc_name']);
                    $array['wplc_email'] = sanitize_text_field($_POST['wplc_email']);
                    $array['cid'] = sanitize_text_field($_POST['cid']);
                    $array = apply_filters("wplc_filter_user_long_poll_chat_loop_iteration", $array, $_POST, $i);
                    if ($new_status == $_POST['status']) {
                        // if status matches do the following
                        if ($_POST['status'] != 2) {
                            /* check if session_variable is different? if yes then stop this script completely. */
                            if (isset($_POST['wplcsession']) && $_POST['wplcsession'] != '' && $i > 1) {
                                $wplc_session_variable = sanitize_text_field($_POST['wplcsession']);
                                $current_session_variable = wplc_return_chat_session_variable(sanitize_text_field($_POST['cid']));
                                if ($current_session_variable != "" && $current_session_variable != $wplc_session_variable) {
                                    /* stop this script */
                                    $array['status'] = 11;
                                    echo json_encode($array);
                                    die;
                                }
                            }
                            if ($i == 1) {
                                wplc_update_user_on_page(sanitize_text_field($_POST['cid']), sanitize_text_field($_POST['status']), sanitize_text_field($_POST['wplcsession']));
                            }
                        }
                        if ($_POST['status'] == 0) {
                            // browsing - user tried to chat but admin didn't answer so turn back to browsing
                            wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 5, sanitize_text_field($_POST['wplcsession']));
                            $array['status'] = 5;
                            $array['check'] = true;
                        } else {
                            if ($_POST['status'] == 3) {
                                //wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 3);
                                $messages = wplc_return_user_chat_messages(sanitize_text_field($_POST['cid']));
                                if ($messages) {
                                    wplc_mark_as_read_user_chat_messages(sanitize_text_field($_POST['cid']));
                                    $array['status'] = 3;
                                    $array['data'] = $messages;
                                    $array['check'] = true;
                                }
                            }
                        }
                        /* check if this is part of the first run */
                        if (isset($_POST['first_run']) && sanitize_text_field($_POST['first_run']) == 1) {
                            /* if yes, then send data now and dont wait for all iterations to complete */
                            if (!isset($array['status'])) {
                                $array['status'] = $new_status;
                            }
                            $array['check'] = true;
                        } else {
                            if (isset($_POST['short_poll']) && sanitize_text_field($_POST['short_poll']) == "true") {
                                /* if yes, then send data now and dont wait for all iterations to complete */
                                if (!isset($array['status'])) {
                                    $array['status'] = $new_status;
                                }
                                $array['check'] = true;
                            }
                        }
                    } else {
                        // statuses do not match
                        $array['debug'] = $array['debug'] . " " . "Doesnt match {$new_status} " . $_POST['status'];
                        $array['status'] = $new_status;
                        if ($new_status == 1) {
                            // completed
                            wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 8, sanitize_text_field($_POST['wplcsession']));
                            $array['check'] = true;
                            $array['status'] = 8;
                            $array['data'] = __("Admin has closed and ended the chat", "wplivechat");
                        } else {
                            if ($new_status == 2) {
                                // pending
                                $array['check'] = true;
                                $array['wplc_name'] = wplc_return_chat_name(sanitize_text_field($_POST['cid']));
                                $array['wplc_email'] = wplc_return_chat_email(sanitize_text_field($_POST['cid']));
                            } else {
                                if ($new_status == 3) {
                                    // active
                                    $array['data'] = null;
                                    $array['check'] = true;
                                    if ($_POST['status'] == 5) {
                                        $messages = wplc_return_chat_messages(sanitize_text_field($_POST['cid']));
                                        if ($messages) {
                                            $array['data'] = $messages;
                                        }
                                    }
                                } else {
                                    if ($new_status == 7) {
                                        // timed out
                                        wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 5, sanitize_text_field($_POST['wplcsession']));
                                    } else {
                                        if ($new_status == 9) {
                                            // user closed chat without inputting or starting a chat
                                            $array['check'] = true;
                                        } else {
                                            if ($new_status == 0) {
                                                // no answer from admin
                                                $array['data'] = __('There is No Answer. Please Try Again Later', 'wplivechat');
                                                $array['check'] = true;
                                                @do_action("wplc_hook_missed_chat", array("cid" => $_POST['cid'], "name" => $_POST['wplc_name'], "email" => $_POST['wplc_email']));
                                            } else {
                                                if ($new_status == 10) {
                                                    // minimized active chat
                                                    $array['check'] = true;
                                                    if ($_POST['status'] == 5) {
                                                        $messages = wplc_return_chat_messages(sanitize_text_field($_POST['cid']));
                                                        if ($messages) {
                                                            $array['data'] = $messages;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        /* check if this is part of the first run */
                        if (isset($_POST['first_run']) && sanitize_text_field($_POST['first_run']) == "1") {
                            /* if yes, then send data now and dont wait for all iterations to complete */
                            if (!isset($array['status'])) {
                                $array['status'] = $new_status;
                            }
                            $array['check'] = true;
                        } else {
                            if (isset($_POST['short_poll']) && sanitize_text_field($_POST['short_poll']) == "true") {
                                /* if yes, then send data now and dont wait for all iterations to complete */
                                if (!isset($array['status'])) {
                                    $array['status'] = $new_status;
                                }
                                $array['check'] = true;
                            }
                        }
                        $array = apply_filters("wplc_filter_wplc_call_to_server_visitor_new_status_check", $array);
                    }
                }
                if ($array['check'] == true) {
                    echo json_encode($array);
                    break;
                }
                $i++;
                if (defined('WPLC_DELAY_BETWEEN_LOOPS')) {
                    usleep(WPLC_DELAY_BETWEEN_LOOPS);
                } else {
                    usleep(500000);
                }
                @ob_end_flush();
            }
        }
        /*  */
        if ($_POST['action'] == "wplc_user_close_chat") {
            if ($_POST['status'] == 5) {
                wplc_change_chat_status(sanitize_text_field($_POST['cid']), 9);
            } else {
                if ($_POST['status'] == 3) {
                    wplc_change_chat_status(sanitize_text_field($_POST['cid']), 8);
                }
            }
        }
        if ($_POST['action'] == "wplc_user_minimize_chat") {
            $chat_id = sanitize_text_field($_POST['cid']);
            wplc_change_chat_status(sanitize_text_field($_POST['cid']), 10);
        }
        if ($_POST['action'] == "wplc_user_maximize_chat") {
            $chat_id = sanitize_text_field($_POST['cid']);
            wplc_change_chat_status(sanitize_text_field($_POST['cid']), 3);
        }
        if ($_POST['action'] == "wplc_user_send_msg") {
            $chat_id = sanitize_text_field($_POST['cid']);
            $chat_msg = sanitize_text_field($_POST['msg']);
            $wplc_rec_msg = wplc_record_chat_msg("1", $chat_id, $chat_msg);
            if ($wplc_rec_msg) {
                echo 'sent';
            } else {
                echo "There was an error sending your chat message. Please contact support";
            }
        }
        if ($_POST['action'] == "wplc_start_chat") {
            if (isset($_POST['cid'])) {
                if ($_POST['name'] && $_POST['email']) {
                    echo wplc_user_initiate_chat(sanitize_text_field($_POST['name']), sanitize_email($_POST['email']), sanitize_text_field($_POST['cid']), sanitize_text_field($_POST['wplcsession']));
                    // echo the chat session id
                } else {
                    echo "error2";
                }
            } else {
                if ($_POST['name'] && $_POST['email']) {
                    echo wplc_user_initiate_chat(sanitize_text_field($_POST['name']), sanitize_email($_POST['email']), null, sanitize_text_field($_POST['wplcsession']));
                    // echo the chat session id
                } else {
                    echo "error2";
                }
            }
        }
    }
    die;
}
function wplc_hook_control_change_status_on_answer($get_data)
{
    $user_ID = get_current_user_id();
    wplc_change_chat_status(sanitize_text_field($get_data['cid']), 3, $user_ID);
}
function wplc_hook_control_change_status_on_answer($get_data)
{
    $user_ID = get_current_user_id();
    wplc_change_chat_status(sanitize_text_field($get_data['cid']), 3, $user_ID);
    wplc_record_chat_notification("joined", $get_data['cid'], array("aid" => $user_ID));
}
示例#10
0
function wplc_admin_menu_layout_display()
{
    if (!isset($_GET['action'])) {
        ?>
        <div style='float:right; display:block; width:450px;  padding:10px; text-align:center; background-color: #EEE; border: 1px solid #E6DB55; margin:10px;'>
            <strong><?php 
        _e("Experiencing problems with the plugin?", "wplivechat");
        ?>
</strong>
            <br />
            <a href='http://wp-livechat.com/documentation/' title='WP Live Chat Support Documentation' target='_BLANK'><?php 
        _e("Review the documentation.", "wplivechat");
        ?>
</a> 
        <?php 
        _e("Or ask a question on our", "wplivechat");
        ?>
  <a href='http://wp-livechat.com/forums/forum/support/' title='WP Live Chat Support Forum' target='_BLANK'><?php 
        _e('Support forum.', 'wplivechat');
        ?>
</a>
        </div>
        <br/>
        <br/>
        <br/>
        <div class='wplc_page_title'>
            <h1><?php 
        _e("Chat sessions", "wplivechat");
        ?>
</h1>

            <p><?php 
        _e("Please note: This window must be open in order to receive new chat notifications.", "wplivechat");
        ?>
</p>
        </div>
        <div id="wplc_sound"></div>

        <!----->

        <div class="wplc_admin_dashboard_container">
            <div id="wplc_sound"></div>
            <div id="wplc_admin_chat_area">
        <?php 
        if (function_exists("wplc_register_pro_version")) {
            echo wplc_list_chats_pro();
        } else {
            echo wplc_list_chats();
        }
        ?>
            </div>
            <div id="wplc_admin_visitor_area">
                <h1><?php 
        _e("Visitors on site", "wplivechat");
        ?>
</h1>    
                <p>
                    <?php 
        _e("With the Pro add-on of WP Live Chat Support, you can", "wplivechat");
        ?>
 
                    <a href="http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=initiate1" title="<?php 
        _e("see who's online and initiate chats", "wplivechat");
        ?>
" target=\"_BLANK\">
                        <?php 
        _e("see who's online and initiate chats", "wplivechat");
        ?>
                    </a> <?php 
        _e("with your online visitors with the click of a button.", "wplivechat");
        ?>
 
                    <a href="http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=initiate2" title="<?php 
        _e("Buy the Pro add-on now for only \$19.95 once off. Free Updates FOREVER.", "wplivechat");
        ?>
" target=\"_BLANK\">
                        <strong>
                            <?php 
        _e("Buy the Pro add-on now for only \$19.95 once off. Free Updates Forever.", "wplivechat");
        ?>
                        </strong>
                    </a>
                </p>
            </div>
        </div>

        <?php 
    } else {
        if ($_GET['action'] == 'ac') {
            wplc_change_chat_status($_GET['cid'], 3);
            if (function_exists('wplc_ma_register')) {
                wplc_ma_update_agent_id($_GET['cid'], $_GET['agent_id']);
            }
            if (function_exists("wplc_register_pro_version")) {
                wplc_pro_draw_chat_area($_GET['cid']);
            } else {
                wplc_draw_chat_area($_GET['cid']);
            }
        }
    }
}
示例#11
0
function wplc_init_ajax_callback_pro()
{
    $check = check_ajax_referer('wplc', 'security');
    $iterations = 55;
    /* time in microseconds between updating the user on the page within the DB  (lower number = higher resource usage) */
    define('WPLC_DELAY_BETWEEN_UPDATES', 500000);
    /* time in microseconds between long poll loop (lower number = higher resource usage) */
    define('WPLC_DELAY_BETWEEN_LOOPS', 500000);
    /* this needs to take into account the previous constants so that we dont run out of time, which in turn returns a 503 error */
    define('WPLC_TIMEOUT', (WPLC_DELAY_BETWEEN_UPDATES + WPLC_DELAY_BETWEEN_LOOPS) * $iterations / 1000000);
    global $wpdb;
    global $wplc_tblname_chats;
    global $wplc_tblname_msgs;
    $wplc_tblname_chats = $wpdb->prefix . "wplc_chat_sessions";
    $wplc_tblname_msgs = $wpdb->prefix . "wplc_chat_msgs";
    /* we're using PHP 'sleep' which may lock other requests until our script wakes up. Call this function to ensure that other requests can run without waiting for us to finish */
    session_write_close();
    if ($check == 1) {
        if ($_POST['action'] == "wplc_get_chat_box") {
            if (function_exists("wplc_output_box_ajax")) {
                echo wplc_output_box_ajax();
                die;
            } else {
                echo "x";
            }
        }
        if ($_POST['action'] == 'wplc_submit_chat_experience_rating') {
            if (function_exists('wplc_submit_chat_experience_rating')) {
                wplc_submit_chat_experience_rating($_POST['rating'], $_POST['cid']);
                die;
            }
        }
        if ($_POST['action'] == 'wplc_record_chat_experience_message') {
            if (function_exists('wplc_record_chat_experience_message')) {
                wplc_record_chat_experience_message($_POST['message'], $_POST['cid']);
                die;
            }
        }
        if ($_POST['action'] == 'wplc_admin_long_poll') {
            //wplc_error_log("[".__LINE__."] NEW ADMIN LONG POLL LOOP");
            if (defined('WPLC_TIMEOUT')) {
                set_time_limit(WPLC_TIMEOUT);
            } else {
                set_time_limit(120);
            }
            $i = 1;
            while ($i <= $iterations) {
                //wplc_error_log("[".__LINE__."] ADMIN LOOP $i");
                session_write_close();
                // update chats if they have timed out every x iterations
                if ($i % 15 == 0) {
                    wplc_update_chat_statuses();
                }
                //$new_visitor_data = wplc_list_visitors($_POST['wplc_agent_id']);
                $new_chat_data = wplc_list_chats_pro_new($_POST['wplc_agent_id']);
                if ($new_chat_data == "false") {
                    $new_chat_data = false;
                }
                if ($_POST['wplc_update_admin_chat_table'] == 'false') {
                    $old_chat_data = false;
                } else {
                    $old_chat_data = stripslashes($_POST['wplc_update_admin_chat_table']);
                }
                $pending = wplc_check_pending_chats();
                //                $new_chat_data = wplc_list_chats_pro($_POST['wplc_agent_id']);
                if ($new_chat_data !== $old_chat_data) {
                    $array['wplc_update_admin_chat_table'] = $new_chat_data;
                    $array['pending'] = $pending;
                    $array['action'] = "wplc_update_chat_list";
                }
                if (isset($array)) {
                    echo json_encode($array);
                    die;
                }
                @ob_end_flush();
                if (defined('WPLC_DELAY_BETWEEN_LOOPS')) {
                    usleep(WPLC_DELAY_BETWEEN_LOOPS);
                } else {
                    usleep(500000);
                }
                $i++;
            }
            die;
        }
        if ($_POST['action'] == "wplc_admin_long_poll_chat") {
            if (defined('WPLC_TIMEOUT')) {
                set_time_limit(WPLC_TIMEOUT);
            } else {
                set_time_limit(120);
            }
            //wplc_error_log("[".__LINE__."] NEW ADMIN CHAT LOOP");
            $i = 1;
            $array = array();
            while ($i <= $iterations) {
                //wplc_error_log("[".__LINE__."] ADMIN LP CHAT LOOP $i");
                session_write_close();
                if (isset($_POST['action_2']) && $_POST['action_2'] == "wplc_long_poll_check_user_opened_chat") {
                    //wplc_error_log("[".__LINE__."] ".$_POST['action_2']." ADMIN LP CHAT LOOP $i");
                    $chat_status = wplc_return_chat_status(sanitize_text_field($_POST['cid']));
                    if ($chat_status == 3) {
                        //wplc_error_log("[".__LINE__."] wplc_user_open_chat");
                        $array['action'] = "wplc_user_open_chat";
                    }
                } else {
                    $new_chat_status = wplc_return_chat_status(sanitize_text_field($_POST['cid']));
                    if ($new_chat_status != $_POST['chat_status']) {
                        //wplc_error_log("[".__LINE__."] wplc_update_chat_status");
                        $array['chat_status'] = $new_chat_status;
                        $array['action'] = "wplc_update_chat_status";
                    }
                    $new_chat_message = wplc_return_admin_chat_messages($_POST['cid']);
                    if ($new_chat_message) {
                        //wplc_error_log("[".__LINE__."] wplc_new_chat_message");
                        $array['chat_message'] = $new_chat_message;
                        $array['action'] = "wplc_new_chat_message";
                    }
                }
                if (wplc_ma_check_if_chat_answered_by_other_agent($_POST['cid'], $_POST['aid']) === true) {
                    //wplc_error_log("[".__LINE__."] wplc_ma_agant_already_answered");
                    $array['action'] = "wplc_ma_agant_already_answered";
                }
                if ($array) {
                    echo json_encode($array);
                    die;
                }
                @ob_end_flush();
                if (defined('WPLC_DELAY_BETWEEN_LOOPS')) {
                    usleep(WPLC_DELAY_BETWEEN_LOOPS);
                } else {
                    usleep(500000);
                }
                $i++;
            }
            die;
        }
        if ($_POST['action'] == "wplc_admin_accept_chat") {
            //wplc_error_log("[".__LINE__."] wplc_admin_accept_chat");
            wplc_admin_accept_chat(sanitize_text_field($_POST['cid']));
            die;
        }
        if ($_POST['action'] == "wplc_admin_close_chat") {
            //wplc_error_log("[".__LINE__."] wplc_admin_close_chat");
            $chat_id = sanitize_text_field($_POST['cid']);
            wplc_change_chat_status($chat_id, 1);
            if (function_exists('wplc_ce_record_chat_end')) {
                wplc_ce_record_chat_end($chat_id);
            }
            echo 'done';
            die;
        }
        if ($_POST['action'] == "wplc_admin_send_msg") {
            //wplc_error_log("[".__LINE__."] wplc_admin_send_msg");
            $chat_id = sanitize_text_field($_POST['cid']);
            $chat_msg = sanitize_text_field($_POST['msg']);
            $wplc_rec_msg = wplc_record_chat_msg_pro("2", $chat_id, $chat_msg);
            if ($wplc_rec_msg) {
                echo 'sent';
            } else {
                echo "There was an error sending your chat message. Please contact support";
            }
            die;
        }
        //User Ajax
        if ($_POST['action'] == 'wplc_call_to_server_visitor') {
            //wplc_error_log("[".__LINE__."] NEW USER REQUEST");
            if (defined('WPLC_TIMEOUT')) {
                set_time_limit(WPLC_TIMEOUT);
            } else {
                set_time_limit(120);
            }
            $i = 1;
            $array = array("check" => false);
            /* must record the session ID */
            while ($i <= $iterations) {
                session_write_close();
                //wplc_error_log("[".__LINE__."] USER LOOP $i");
                if ($_POST['cid'] == null || $_POST['cid'] == "null" || $_POST['cid'] == "") {
                    //wplc_error_log("[".__LINE__."] CID = null - log user on page");
                    $user = __("Guest", "wplivechat");
                    $email = "no email set";
                    $cid = wplc_log_user_on_page($user, $email, $_POST['wplcsession']);
                    $array['cid'] = $cid;
                    $array['status'] = wplc_return_chat_status($cid);
                    $array['wplc_name'] = $user;
                    $array['wplc_email'] = $email;
                    $array['check'] = true;
                } else {
                    //wplc_error_log("[".__LINE__."] CID != null - update user on page BEGIN");
                    $new_status = wplc_return_chat_status($_POST['cid']);
                    $array['wplc_name'] = sanitize_text_field($_POST['wplc_name']);
                    $array['wplc_email'] = sanitize_email($_POST['wplc_email']);
                    $array['cid'] = sanitize_text_field($_POST['cid']);
                    if ($new_status == $_POST['status']) {
                        // if status matches do the following
                        if ($_POST['status'] != 2) {
                            /* check if session_variable is different? if yes then stop this script completely. */
                            if (isset($_POST['wplcsession']) && $_POST['wplcsession'] != '' && $i > 1) {
                                $wplc_session_variable = $_POST['wplcsession'];
                                $current_session_variable = wplc_return_chat_session_variable($_POST['cid']);
                                //wplc_error_log("[".$_POST['wplcsession']."] [".__LINE__."] [*$i] Checking against session variable ".$current_session_variable);
                                if ($current_session_variable != "" && $current_session_variable != $wplc_session_variable) {
                                    /* stop this script */
                                    //wplc_error_log("[".$_POST['wplcsession']."] [".__LINE__."] [*$i] TERMINATING   STATUS 11");
                                    $array['status'] = 11;
                                    echo json_encode($array);
                                    die;
                                }
                            }
                            if ($i == 1) {
                                //wplc_error_log("[".$_POST['wplcsession']."] [".__LINE__."] [*$i] Updating user on page ".$_SERVER['HTTP_REFERER']);
                                wplc_update_user_on_page(sanitize_text_field($_POST['cid']), sanitize_text_field($_POST['status']), $_POST['wplcsession']);
                            }
                            //if (defined('WPLC_DELAY_BETWEEN_UPDATES')) { sleep(WPLC_DELAY_BETWEEN_UPDATES); } else { sleep(3); }
                        }
                        if ($_POST['status'] == 0) {
                            // browsing - user tried to chat but admin didn't answer so turn back to browsing
                            //wplc_error_log("[".__LINE__."] Status 0 - Updating user on page Status 0");
                            wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 5, $_POST['wplcsession']);
                            $array['status'] = 5;
                            $array['check'] = true;
                        } else {
                            if ($_POST['status'] == 3) {
                                //wplc_update_user_on_page($_POST['cid'], 3);
                                //wplc_error_log("[".__LINE__."] Status 3");
                                $messages = wplc_return_user_chat_messages(sanitize_text_field($_POST['cid']));
                                if ($messages) {
                                    wplc_mark_as_read_user_chat_messages(sanitize_text_field($_POST['cid']));
                                    $array['status'] = 3;
                                    $array['data'] = $messages;
                                    $array['check'] = true;
                                }
                            }
                        }
                        /* check if this is part of the first run */
                        if (isset($_POST['first_run']) && sanitize_text_field($_POST['first_run']) == 1) {
                            /* if yes, then send data now and dont wait for all iterations to complete */
                            if (!isset($array['status'])) {
                                $array['status'] = $new_status;
                            }
                            $array['check'] = true;
                        } else {
                            if (isset($_POST['short_poll']) && sanitize_text_field($_POST['short_poll']) == "true") {
                                /* if yes, then send data now and dont wait for all iterations to complete */
                                if (!isset($array['status'])) {
                                    $array['status'] = $new_status;
                                }
                                $array['check'] = true;
                            }
                        }
                    } else {
                        // statuses do not match
                        //wplc_error_log("[".__LINE__."] STATUS CHANGE   [OLD: ".$new_status."]  [NEW: ".$_POST['status']."]");
                        $array['status'] = $new_status;
                        if ($new_status == 1) {
                            // completed
                            //wplc_error_log("[".__LINE__."] Status 1 - Updating user on page");
                            wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 8, $_POST['wplcsession']);
                            $array['check'] = true;
                            $array['status'] = 8;
                            $array['data'] = __("Admin has closed and ended the chat", "wplivechat");
                        } else {
                            if ($new_status == 2) {
                                // pending
                                //wplc_error_log("[".__LINE__."] Status 2 - returning name and email");
                                $array['check'] = true;
                                $array['wplc_name'] = wplc_return_chat_name(sanitize_text_field($_POST['cid']));
                                $array['wplc_email'] = wplc_return_chat_email(sanitize_text_field($_POST['cid']));
                            } else {
                                if ($new_status == 3) {
                                    // active
                                    //wplc_error_log("[".__LINE__."] Status 3 - returning name and email");
                                    $array['data'] = null;
                                    $array['check'] = true;
                                    if ($_POST['status'] == 5) {
                                        //wplc_error_log("[".__LINE__."] Old status 3 now 5 - returing messages");
                                        $messages = wplc_return_chat_messages(sanitize_text_field($_POST['cid']));
                                        if ($messages) {
                                            $array['data'] = $messages;
                                        }
                                    }
                                } else {
                                    if ($new_status == 6) {
                                        // admin requests chat
                                        //wplc_error_log("[".__LINE__."] Status6 - Updating user on page");
                                        wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 3, $_POST['wplcsession']);
                                        $array['check'] = true;
                                        $array['status'] = 3;
                                        $array['wplc_name'] = "You";
                                    } else {
                                        if ($new_status == 7) {
                                            // timed out
                                            //wplc_error_log("[".__LINE__."] Status 7 TIMED OUT - Updating user on page");
                                            if ($i == 1) {
                                                wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 5, $_POST['wplcsession']);
                                            }
                                        } else {
                                            if ($new_status == 8) {
                                                // completed but still browsing
                                                if ($i == 1) {
                                                    wplc_update_user_on_page(sanitize_text_field($_POST['cid']), 8, $_POST['wplcsession']);
                                                }
                                            } else {
                                                if ($new_status == 9) {
                                                    // user closed chat without inputting or starting a chat
                                                    //wplc_error_log("[".__LINE__."] Status 9");
                                                    $array['check'] = true;
                                                } else {
                                                    if ($new_status == 0) {
                                                        // no answer from admin
                                                        //wplc_error_log("[".__LINE__."] Status 0?");
                                                        $array['data'] = __('There is No Answer. Please Try Again Later', 'wplivechat');
                                                        $array['check'] = true;
                                                    } else {
                                                        if ($new_status == 10) {
                                                            // minimized active chat
                                                            //wplc_error_log("[".__LINE__."] Status 10");
                                                            $array['check'] = true;
                                                            if ($_POST['status'] == 5) {
                                                                //wplc_error_log("[".__LINE__."] Status 10 NOW 5");
                                                                $messages = wplc_return_chat_messages(sanitize_text_field($_POST['cid']));
                                                                if ($messages) {
                                                                    $array['data'] = $messages;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        /* check if this is part of the first run */
                        if (isset($_POST['first_run']) && sanitize_text_field($_POST['first_run']) == "1") {
                            /* if yes, then send data now and dont wait for all iterations to complete */
                            if (!isset($array['status'])) {
                                $array['status'] = $new_status;
                            }
                            $array['check'] = true;
                        } else {
                            if (isset($_POST['short_poll']) && sanitize_text_field($_POST['short_poll']) == "true") {
                                /* if yes, then send data now and dont wait for all iterations to complete */
                                if (!isset($array['status'])) {
                                    $array['status'] = $new_status;
                                }
                                $array['check'] = true;
                            }
                        }
                    }
                }
                if ($array['check'] == true) {
                    echo json_encode($array);
                    break;
                }
                @ob_end_flush();
                if (defined('WPLC_DELAY_BETWEEN_LOOPS')) {
                    usleep(WPLC_DELAY_BETWEEN_LOOPS);
                } else {
                    usleep(500000);
                }
                $i++;
            }
            die;
        }
        if ($_POST['action'] == "wplc_user_close_chat") {
            //wplc_error_log("[".__LINE__."] ".$_POST['action']);
            if ($_POST['status'] == 5) {
                //wplc_error_log("[".__LINE__."] ".$_POST['action']);
                wplc_change_chat_status(sanitize_text_field($_POST['cid']), 9);
            } else {
                if ($_POST['status'] == 3) {
                    //wplc_error_log("[".__LINE__."] ".$_POST['action']);
                    wplc_change_chat_status(sanitize_text_field($_POST['cid']), 8);
                    if (function_exists('wplc_ce_record_chat_end')) {
                        wplc_ce_record_chat_end($_POST['cid']);
                    }
                }
            }
            die;
        }
        if ($_POST['action'] == "wplc_user_minimize_chat") {
            //wplc_error_log("[".__LINE__."] ".$_POST['action']);
            $chat_id = $_POST['cid'];
            wplc_change_chat_status(sanitize_text_field($_POST['cid']), 10);
            die;
        }
        if ($_POST['action'] == "wplc_user_maximize_chat") {
            //wplc_error_log("[".__LINE__."] ".$_POST['action']);
            wplc_change_chat_status(sanitize_text_field($_POST['cid']), 3);
            die;
        }
        if ($_POST['action'] == "wplc_user_send_msg") {
            $chat_id = sanitize_text_field($_POST['cid']);
            $chat_msg = sanitize_text_field($_POST['msg']);
            //wplc_error_log("[".__LINE__."] SENDING CHAT MSG FROM USER : $chat_id : $chat_msg");
            $wplc_rec_msg = wplc_record_chat_msg_pro("1", $chat_id, $chat_msg);
            if ($wplc_rec_msg) {
                echo 'sent';
                die;
            } else {
                echo "There was an error sending your chat message. Please contact support";
                die;
            }
        }
    }
    die;
}