function wplc_user_initiate_chat($name, $email, $cid = null, $session) { global $wpdb; global $wplc_tblname_chats; if (function_exists("wplc_list_chats_pro")) { /* check if functions-pro is around */ wplc_pro_notify_via_email(); } $wplc_settings = get_option('WPLC_SETTINGS'); if (isset($wplc_settings['wplc_record_ip_address']) && $wplc_settings['wplc_record_ip_address'] == 1) { $user_data = array('ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT']); $wplc_ce_ip = $_SERVER['REMOTE_ADDR']; } else { $user_data = array('ip' => "", 'user_agent' => $_SERVER['HTTP_USER_AGENT']); $wplc_ce_ip = null; } if (function_exists('wplc_ce_activate')) { /* Log the chat for statistical purposes as well */ if (function_exists('wplc_ce_record_initial_chat')) { wplc_ce_record_initial_chat($name, $email, $cid, $wplc_ce_ip, $_SERVER['HTTP_REFERER']); } } if ($cid != null) { /* change from a visitor to a chat */ // $query = // " // UPDATE $wplc_tblname_chats // SET // `status` = '2', // `timestamp` = '".date("Y-m-d H:i:s")."', // `name` = '$name', // `email` = '$email', // `session` = '$session', // `ip` = '".maybe_serialize($user_data)."', // `url` = '".$_SERVER['HTTP_REFERER']."', // `last_active_timestamp` = '".date("Y-m-d H:i:s")."' // // WHERE `id` = '$cid' // LIMIT 1 // "; // $results = $wpdb->query($query); $wpdb->update($wplc_tblname_chats, array('status' => 2, 'timestamp' => current_time('mysql'), 'name' => $name, 'email' => $email, 'session' => $session, 'ip' => maybe_serialize($user_data), 'url' => $_SERVER['HTTP_REFERER'], 'last_active_timestamp' => current_time('mysql')), array('id' => $cid), array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s'), array('%d')); return $cid; } else { // create new ID for the chat // $ins_array = array( // 'status' => '2', // 'timestamp' => date("Y-m-d H:i:s"), // 'name' => $name, // 'email' => $email, // 'session' => $session, // 'ip' => maybe_serialize($user_data), // 'url' => $_SERVER['HTTP_REFERER'], // 'last_active_timestamp' => date("Y-m-d H:i:s") // ); // $rows_affected = $wpdb->insert( $wplc_tblname_chats, $ins_array ); $wpdb->insert($wplc_tblname_chats, array('status' => '2', 'timestamp' => current_time('mysql'), 'name' => $name, 'email' => $email, 'session' => $session, 'ip' => maybe_serialize($user_data), 'url' => $_SERVER['HTTP_REFERER'], 'last_active_timestamp' => current_time('mysql')), array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')); $lastid = $wpdb->insert_id; return $lastid; } }
function wplc_user_initiate_chat($name, $email, $cid = null, $session) { global $wpdb; global $wplc_tblname_chats; if (function_exists("wplc_list_chats_pro")) { /* check if functions-pro is around */ wplc_pro_notify_via_email(); } $wplc_settings = get_option('WPLC_SETTINGS'); if (isset($wplc_settings['wplc_record_ip_address']) && $wplc_settings['wplc_record_ip_address'] == 1) { $user_data = array('ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT']); $wplc_ce_ip = $_SERVER['REMOTE_ADDR']; } else { $user_data = array('ip' => "", 'user_agent' => $_SERVER['HTTP_USER_AGENT']); $wplc_ce_ip = null; } if (function_exists('wplc_ce_activate')) { /* Log the chat for statistical purposes as well */ if (function_exists('wplc_ce_record_initial_chat')) { wplc_ce_record_initial_chat($name, $email, $cid, $wplc_ce_ip, $_SERVER['HTTP_REFERER']); } } if ($cid != null) { /* change from a visitor to a chat */ $query = "\n UPDATE {$wplc_tblname_chats}\n SET\n `status` = '2',\n `timestamp` = '" . date("Y-m-d H:i:s") . "',\n `name` = '{$name}',\n `email` = '{$email}',\n `session` = '{$session}',\n `ip` = '" . maybe_serialize($user_data) . "',\n `url` = '" . $_SERVER['HTTP_REFERER'] . "',\n `last_active_timestamp` = '" . date("Y-m-d H:i:s") . "'\n\n WHERE `id` = '{$cid}'\n LIMIT 1\n "; $results = $wpdb->query($query); return $cid; } else { // create new ID for the chat $ins_array = array('status' => '2', 'timestamp' => date("Y-m-d H:i:s"), 'name' => $name, 'email' => $email, 'session' => $session, 'ip' => maybe_serialize($user_data), 'url' => $_SERVER['HTTP_REFERER'], 'last_active_timestamp' => date("Y-m-d H:i:s")); $rows_affected = $wpdb->insert($wplc_tblname_chats, $ins_array); $lastid = $wpdb->insert_id; return $lastid; } }
function wplc_user_initiate_chat($name, $email, $cid = null, $session) { global $wpdb; global $wplc_tblname_chats; do_action("wplc_hook_initiate_chat", array("cid" => $cid, "name" => $name, "email" => $email)); $wplc_settings = get_option('WPLC_SETTINGS'); if (isset($wplc_settings['wplc_record_ip_address']) && $wplc_settings['wplc_record_ip_address'] == 1) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '') { $ip_address = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); } else { $ip_address = sanitize_text_field($_SERVER['REMOTE_ADDR']); } $user_data = array('ip' => $ip_address, 'user_agent' => sanitize_text_field($_SERVER['HTTP_USER_AGENT'])); $wplc_ce_ip = $ip_address; } else { $user_data = array('ip' => "", 'user_agent' => sanitize_text_field($_SERVER['HTTP_USER_AGENT'])); $wplc_ce_ip = null; } if (function_exists('wplc_ce_activate')) { /* Log the chat for statistical purposes as well */ if (function_exists('wplc_ce_record_initial_chat')) { wplc_ce_record_initial_chat($name, $email, $cid, $wplc_ce_ip, sanitize_text_field($_SERVER['HTTP_REFERER'])); } } if ($cid != null) { /* change from a visitor to a chat */ /** * This helps us identify if this user needs to be answered. The user can start typing so long but an agent still needs to answer the chat * @var serialized array */ $chat_data = wplc_get_chat_data($cid); if (isset($chat_data->other)) { $other_data = maybe_unserialize($chat_data->other); $other_data['unanswered'] = true; } $wpdb->update($wplc_tblname_chats, array('status' => 2, 'timestamp' => current_time('mysql'), 'name' => $name, 'email' => $email, 'session' => $session, 'ip' => maybe_serialize($user_data), 'url' => sanitize_text_field($_SERVER['HTTP_REFERER']), 'last_active_timestamp' => current_time('mysql'), 'other' => maybe_serialize($other_data)), array('id' => $cid), array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'), array('%d')); return $cid; } else { $other_data = array(); $other_data['unanswered'] = true; $wpdb->insert($wplc_tblname_chats, array('status' => 2, 'timestamp' => current_time('mysql'), 'name' => $name, 'email' => $email, 'session' => $session, 'ip' => maybe_serialize($user_data), 'url' => sanitize_text_field($_SERVER['HTTP_REFERER']), 'last_active_timestamp' => current_time('mysql'), 'other' => maybe_serialize($other_data)), array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')); $lastid = $wpdb->insert_id; /* Nick: moved from top of function to bottom of function to try speed up the process of accepting the chart - version 7 */ if (function_exists("wplc_list_chats_pro")) { /* check if functions-pro is around */ wplc_pro_notify_via_email(); } return $lastid; } }
function wplc_user_initiate_chat($name, $email, $cid = null, $session) { global $wpdb; global $wplc_tblname_chats; do_action("wplc_hook_initiate_chat", array("cid" => $cid, "name" => $name, "email" => $email)); if (function_exists("wplc_list_chats_pro")) { /* check if functions-pro is around */ wplc_pro_notify_via_email(); } $wplc_settings = get_option('WPLC_SETTINGS'); if (isset($wplc_settings['wplc_record_ip_address']) && $wplc_settings['wplc_record_ip_address'] == 1) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '') { $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip_address = $_SERVER['REMOTE_ADDR']; } $user_data = array('ip' => $ip_address, 'user_agent' => $_SERVER['HTTP_USER_AGENT']); $wplc_ce_ip = $ip_address; } else { $user_data = array('ip' => "", 'user_agent' => $_SERVER['HTTP_USER_AGENT']); $wplc_ce_ip = null; } if (function_exists('wplc_ce_activate')) { /* Log the chat for statistical purposes as well */ if (function_exists('wplc_ce_record_initial_chat')) { wplc_ce_record_initial_chat($name, $email, $cid, $wplc_ce_ip, $_SERVER['HTTP_REFERER']); } } if ($cid != null) { /* change from a visitor to a chat */ $wpdb->update($wplc_tblname_chats, array('status' => 2, 'timestamp' => current_time('mysql'), 'name' => $name, 'email' => $email, 'session' => $session, 'ip' => maybe_serialize($user_data), 'url' => $_SERVER['HTTP_REFERER'], 'last_active_timestamp' => current_time('mysql')), array('id' => $cid), array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s'), array('%d')); return $cid; } else { $wpdb->insert($wplc_tblname_chats, array('status' => 2, 'timestamp' => current_time('mysql'), 'name' => $name, 'email' => $email, 'session' => $session, 'ip' => maybe_serialize($user_data), 'url' => $_SERVER['HTTP_REFERER'], 'last_active_timestamp' => current_time('mysql')), array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')); $lastid = $wpdb->insert_id; return $lastid; } }