WP Live Chat Support - Version 4.0.1

Version Description

  • Fixed a bug (missing function)
Download this release

Release Info

Developer WP-LiveChat
Plugin Icon 128x128 WP Live Chat Support
Version 4.0.1
Comparing to
See all releases

Code changes from version 4.0.0 to 4.0.1

Files changed (2) hide show
  1. readme.txt +3 -0
  2. wp-live-chat-support.php +948 -933
readme.txt CHANGED
@@ -84,6 +84,9 @@ Overhauled Ajax calls to be less resource intensive in version 4. It's recommend
84
 
85
  == Changelog ==
86
 
 
 
 
87
  = 4.0.0 =
88
 
89
  * Overhauled the live chat Ajax calls to be less resource intensive
84
 
85
  == Changelog ==
86
 
87
+ = 4.0.1 =
88
+ * Fixed a bug (missing function)
89
+
90
  = 4.0.0 =
91
 
92
  * Overhauled the live chat Ajax calls to be less resource intensive
wp-live-chat-support.php CHANGED
@@ -1,933 +1,948 @@
1
- <?php
2
- /*
3
- Plugin Name: WP Live Chat Support
4
- Plugin URI: http://www.wp-livechat.com
5
- Description: The easiest to use website live chat plugin. Let your visitors chat with you and increase sales conversion rates with WP Live Chat Support. No third party connection required!
6
- Version: 4.0.0
7
- Author: WP-LiveChat
8
- Author URI: http://www.wp-livechat.com
9
- */
10
-
11
- error_reporting(E_ERROR);
12
- global $wplc_version;
13
- global $wplc_p_version;
14
- global $wplc_tblname;
15
- global $wpdb;
16
- global $wplc_tblname_chats;
17
- global $wplc_tblname_msgs;
18
- $wplc_tblname_chats = $wpdb->prefix . "wplc_chat_sessions";
19
- $wplc_tblname_msgs = $wpdb->prefix . "wplc_chat_msgs";
20
- $wplc_version = "4.0.0";
21
-
22
-
23
-
24
-
25
- require_once (plugin_dir_path( __FILE__ )."functions.php");
26
- add_action('wp_ajax_wplc_admin_set_transient', 'wplc_action_callback');
27
-
28
- add_action('wp_footer', 'wplc_display_box');
29
-
30
- add_action('init','wplc_init');
31
-
32
- if (function_exists('wplc_head_pro')) {
33
- add_action('admin_head', 'wplc_head_pro');
34
- } else {
35
- add_action('admin_head', 'wplc_head_basic');
36
- }
37
-
38
-
39
- add_action('wp_enqueue_scripts', 'wplc_add_user_stylesheet' );
40
- add_action('admin_enqueue_scripts', 'wplc_add_admin_stylesheet');
41
-
42
- if(function_exists('wplc_admin_menu_pro')){
43
- add_action('admin_menu', 'wplc_admin_menu_pro');
44
- } else {
45
- add_action('admin_menu', 'wplc_admin_menu');
46
- }
47
- add_action('admin_head', 'wplc_superadmin_javascript');
48
- register_activation_hook( __FILE__, 'wplc_activate' );
49
-
50
- function wplc_basic_check(){
51
- // check if basic exists if pro is installed
52
- }
53
- function wplc_init() {
54
- $plugin_dir = basename(dirname(__FILE__))."/languages/";
55
- load_plugin_textdomain( 'wplivechat', false, $plugin_dir );
56
- }
57
-
58
-
59
- function wplc_action_callback() {
60
- global $wpdb;
61
- global $wplc_tblname_chats;
62
- $check = check_ajax_referer( 'wplc', 'security' );
63
-
64
- if ($check == 1) {
65
- if ($_POST['action'] == "wplc_admin_set_transient") {
66
- set_transient("wplc_is_admin_logged_in", "1", 70 );
67
-
68
- }
69
- }
70
- die(); // this is required to return a proper result
71
-
72
- }
73
-
74
-
75
- function wplc_feedback_page_include(){
76
- include 'includes/feedback-page.php';
77
- }
78
-
79
- function wplc_admin_menu() {
80
- $wplc_mainpage = add_menu_page('WP Live Chat', __('Live Chat','wplivechat'), 'manage_options', 'wplivechat-menu', 'wplc_admin_menu_layout');
81
- add_submenu_page('wplivechat-menu', __('Settings','wplivechat'), __('Settings','wplivechat'), 'manage_options' , 'wplivechat-menu-settings', 'wplc_admin_settings_layout');
82
- add_submenu_page('wplivechat-menu', __('History','wplivechat'), __('History','wplivechat'), 'manage_options' , 'wplivechat-menu-history', 'wplc_admin_history_layout');
83
- add_submenu_page('wplivechat-menu', __('Feedback','wplivechat'), __('Feedback','wplivechat'), 'manage_options' , 'wplivechat-menu-feedback-page', 'wplc_feedback_page_include');
84
- }
85
- add_action('wp_head','wplc_user_top_js');
86
- function wplc_user_top_js() {
87
- echo "<!-- DEFINING DO NOT CACHE -->";
88
- define('DONOTCACHEPAGE', true);
89
- define('DONOTCACHEDB', true);
90
- $ajax_nonce = wp_create_nonce("wplc");
91
- wp_register_script( 'wplc-user-jquery-cookie', plugins_url('/js/jquery-cookie.js', __FILE__) , array('jquery-ui-draggable'));
92
- wp_enqueue_script( 'wplc-user-jquery-cookie');
93
- $wplc_settings = get_option("WPLC_SETTINGS");
94
-
95
- ?>
96
-
97
- <script type="text/javascript">
98
- <?php if (!function_exists("wplc_register_pro_version")) { ?>
99
- var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
100
-
101
- <?php } ?>
102
- var wplc_nonce = '<?php echo $ajax_nonce; ?>';
103
- </script>
104
- <?php
105
-
106
-
107
- }
108
-
109
- function wplc_draw_user_box() {
110
- $wplc_settings = get_option("WPLC_SETTINGS");
111
- if ($wplc_settings["wplc_settings_enabled"] == 2) { return; }
112
-
113
-
114
- wp_register_script( 'wplc-user-script', plugins_url('/js/wplc_u.js', __FILE__) );
115
- wp_enqueue_script( 'wplc-user-script' );
116
- wp_localize_script('wplc-user-script', 'wplc_hide_chat', null);
117
- wp_enqueue_script( 'jquery' );
118
- wp_enqueue_script( 'jquery-ui-core' );
119
- wp_enqueue_script( 'jquery-ui-draggable');
120
- wplc_output_box();
121
-
122
- }
123
- function wplc_output_box() {
124
-
125
-
126
- $wplc_settings = get_option("WPLC_SETTINGS");
127
- if ($wplc_settings["wplc_settings_enabled"] == 2) { return; }
128
-
129
- if ($wplc_settings["wplc_settings_align"] == 1) { $wplc_box_align = "left:100px;"; } else { $wplc_box_align = "right:100px;"; }
130
- if ($wplc_settings["wplc_settings_fill"]) { $wplc_settings_fill = "#".$wplc_settings["wplc_settings_fill"]; } else { $wplc_settings_fill = "#73BE28"; }
131
- if ($wplc_settings["wplc_settings_font"]) { $wplc_settings_font = "#".$wplc_settings["wplc_settings_font"]; } else { $wplc_settings_font = "#FFFFFF"; }
132
-
133
- $wplc_is_admin_logged_in = get_transient("wplc_is_admin_logged_in");
134
- if (!function_exists("wplc_register_pro_version") && $wplc_is_admin_logged_in != 1) {
135
- return "";
136
- }
137
- if($wplc_settings["wplc_settings_align"] == 1){
138
- $original_pos = "left";
139
- } else {
140
- $original_pos = "right";
141
- }
142
-
143
- ?>
144
- <div id="wp-live-chat" style="display:none; <?php echo $wplc_box_align; ?>;" original_pos="<?php echo $original_pos ?>">
145
-
146
-
147
- <?php if (function_exists("wplc_register_pro_version")) {
148
- wplc_pro_output_box();
149
- } else {
150
- ?>
151
- <div id="wp-live-chat-header" style="background-color: <?php echo $wplc_settings_fill; ?> !important; color: <?php echo $wplc_settings_font; ?> !important;">
152
-
153
- <i id="wp-live-chat-minimize" class="fa fa-minus" style="display:none;" ></i>
154
- <i id="wp-live-chat-close" class="fa fa-times" style="display:none;" ></i>
155
-
156
- <div id="wp-live-chat-1" >
157
- <div style="display:block; ">
158
- <strong><?php _e("Questions?", "wplivechat") ?></strong> <?php _e("Chat with us", "wplivechat") ?>
159
- </div>
160
- </div>
161
- </div>
162
- <div id="wp-live-chat-2" style="display:none;">
163
-
164
- <div id="wp-live-chat-2-info">
165
- <strong>Start Live Chat</strong>
166
- </div>
167
-
168
- <input type="text" name="wplc_name" id="wplc_name" value="" placeholder="<?php _e("Name","wplivechat"); ?>" />
169
-
170
- <input type="text" name="wplc_email" id="wplc_email" value="" placeholder="<?php _e("Email","wplivechat"); ?>" />
171
-
172
- <input id="wplc_start_chat_btn" type="button" value="<?php _e("Start Chat","wplivechat"); ?>" style="background-color: <?php echo $wplc_settings_fill; ?> !important; color: <?php echo $wplc_settings_font; ?> !important;"/>
173
-
174
-
175
-
176
- </div>
177
-
178
- <div id="wp-live-chat-3" style="display:none;">
179
- <p><?php _e("Connecting you to a sales person. Please be patient.","wplivechat") ?></p>
180
- </div>
181
- <div id="wp-live-chat-react" style="display:none;">
182
- <p><?php _e("Reactivating your previous chat...", "wplivechat") ?></p>
183
- </div>
184
- <div id="wp-live-chat-4" style="display:none;">
185
- <div id="wplc_chatbox"></div>
186
- <p style="text-align:center; font-size:11px;"><?php _e("Press ENTER to send your message", "wplivechat" )?></p>
187
- <p>
188
- <input type="text" name="wplc_chatmsg" id="wplc_chatmsg" value="" />
189
- <input type="hidden" name="wplc_cid" id="wplc_cid" value="" />
190
- <input id="wplc_send_msg" type="button" value="<?php _e("Send","wplivechat"); ?>" style="display:none;" /></p>
191
- </div>
192
-
193
- </div>
194
- <?php
195
- }
196
- }
197
-
198
- function wplc_display_box() {
199
- $wplc_is_admin_logged_in = get_transient("wplc_is_admin_logged_in");
200
- if ($wplc_is_admin_logged_in != 1) { echo "<!-- wplc a-n-c -->"; }
201
- if (function_exists("wplc_register_pro_version")) { wplc_pro_draw_user_box(); } else { wplc_draw_user_box(); }
202
- }
203
-
204
-
205
-
206
- function wplc_admin_display_chat($cid) {
207
- global $wpdb;
208
- global $wplc_tblname_msgs;
209
- $results = $wpdb->get_results(
210
- "
211
- SELECT *
212
- FROM $wplc_tblname_msgs
213
- WHERE `chat_sess_id` = '$cid'
214
- ORDER BY `timestamp` DESC
215
- LIMIT 0, 100
216
- "
217
- );
218
- foreach ($results as $result) {
219
- $from = $result->from;
220
- $msg = stripslashes($result->msg);
221
- $msg_hist .= "$from: $msg<br />";
222
-
223
- }
224
- echo $msg_hist;
225
- }
226
- function wplc_admin_accept_chat($cid) {
227
- wplc_change_chat_status($cid,3);
228
- return true;
229
-
230
- }
231
- add_action('admin_head','wplc_update_chat_statuses');
232
-
233
-
234
- function wplc_superadmin_javascript() {
235
-
236
- if (isset($_GET['page']) && $_GET['page'] == 'wplivechat-menu') {
237
-
238
- if (!isset($_GET['action'])) {
239
- if (function_exists("wplc_register_pro_version")) {
240
- wplc_pro_admin_javascript();
241
- } else {
242
- wplc_admin_javascript();
243
- }
244
-
245
- } // main page
246
- else if (isset($_GET['action'])) {
247
- if (function_exists("wplc_register_pro_version")) {
248
- wplc_return_pro_admin_chat_javascript($_GET['cid']);
249
- } else {
250
- wplc_return_admin_chat_javascript($_GET['cid']);
251
- }
252
-
253
- }
254
-
255
-
256
-
257
- }
258
-
259
- $ajax_nonce = wp_create_nonce("wplc");
260
- ?>
261
- <script type="text/javascript">
262
- jQuery(document).ready(function() {
263
-
264
-
265
- var wplc_set_transient = null;
266
-
267
- wplc_set_transient = setInterval(function (){wpcl_admin_set_transient();}, 60000);
268
- wpcl_admin_set_transient();
269
- function wpcl_admin_set_transient() {
270
- var data = {
271
- action: 'wplc_admin_set_transient',
272
- security: '<?php echo $ajax_nonce; ?>'
273
-
274
- };
275
- jQuery.post(ajaxurl, data, function(response) {
276
- //console.log("wplc_admin_set_transient");
277
- });
278
- }
279
-
280
-
281
-
282
-
283
-
284
- });
285
-
286
-
287
-
288
- </script>
289
- <?php
290
- }
291
- function wplc_admin_javascript() {
292
- $ajax_nonce = wp_create_nonce("wplc");
293
- ?>
294
-
295
- <script type="text/javascript">
296
- var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
297
- var data = {
298
- action: 'wplc_admin_long_poll',
299
- security: '<?php echo $ajax_nonce; ?>',
300
- wplc_list_visitors_data: false ,
301
- wplc_update_admin_chat_table: false
302
- };
303
- var wplc_pending_refresh = null;
304
-
305
- var wplc_run = true;
306
- function wplc_call_to_server(data) {
307
-
308
-
309
- jQuery.ajax({
310
- url: wplc_ajaxurl,
311
- data:data,
312
- type:"POST",
313
- success: function(response) {
314
-
315
- //Update your dashboard gauge
316
- if(response){
317
-
318
- response = JSON.parse(response);
319
- //console.log(response);
320
- data["wplc_update_admin_chat_table"] = response['wplc_update_admin_chat_table'];
321
- //console.log(response['visitors']);
322
-
323
- if(response['action'] === "wplc_update_admin_chat"){
324
- jQuery("#wplc_admin_chat_area").html(response['wplc_update_admin_chat_table']);
325
- if (response['pending'] === true) {
326
-
327
- var orig_title = document.getElementsByTagName("title")[0].innerHTML;
328
- wplc_pending_refresh = setInterval(function (){
329
- document.title = "** CHAT REQUEST **";
330
- wplc_title_alerts1 = setTimeout(function (){ document.title = "__ CHAT Request __"; }, 1000);
331
- wplc_title_alerts2 = setTimeout(function (){ document.title = "** CHAT REQUEST **"; }, 1500);
332
- wplc_title_alerts3 = setTimeout(function (){ document.title = "__ CHAT Request __"; }, 2000);
333
- wplc_title_alerts4 = setTimeout(function (){ document.title = orig_title; }, 2500);
334
-
335
- document.getElementById("wplc_sound").innerHTML="<embed src='<?php echo plugins_url('/ring.wav', __FILE__); ?>' hidden=true autostart=true loop=false>";
336
- }, 3000);
337
- } else {
338
- //console.log("end");
339
- clearInterval(wplc_pending_refresh);
340
- }
341
- }
342
-
343
- }
344
- },
345
- error: function(jqXHR, exception) {
346
- if (jqXHR.status == 404) {
347
- console.log('Requested page not found. [404]');
348
- wplc_run = false;
349
- } else if (jqXHR.status == 500) {
350
- console.log('Internal Server Error [500].');
351
- wplc_run = false;
352
- } else if (exception === 'parsererror') {
353
- console.log('Requested JSON parse failed.');
354
- wplc_run = false;
355
- } else if (exception === 'abort') {
356
- console.log('Ajax request aborted.');
357
- wplc_run = false;
358
- } else {
359
- console.log('Uncaught Error.\n' + jqXHR.responseText);
360
- wplc_run = false;
361
- }
362
- },
363
- complete: function(response){
364
- //console.log(wplc_run);
365
- if (wplc_run) {
366
- wplc_call_to_server(data);
367
- }
368
- },
369
- timeout: 120000
370
- });
371
- };
372
-
373
-
374
-
375
- jQuery(document).ready(function() {
376
- jQuery('body').on("click", "a", function (event) {
377
- if(jQuery(this).hasClass('wplc_open_chat')){
378
- event.preventDefault();
379
- window.open(jQuery(this).attr("href"), jQuery(this).attr("window-title" ), "width=600,height=600,scrollbars=yes", false);
380
- }
381
- });
382
-
383
- wplc_call_to_server(data);
384
- });
385
-
386
-
387
-
388
- </script>
389
- <?php
390
- }
391
-
392
-
393
-
394
- function wplc_admin_menu_layout() {
395
- if (function_exists("wplc_register_pro_version")) {
396
- global $wplc_pro_version;
397
- if (floatval($wplc_pro_version) < 4.0) {
398
- ?>
399
- <div class='error below-h1'>
400
-
401
- <p><?php _e("Dear Pro User", "wplivechat") ?><br /></p>
402
- <p><?php _e("You are using an outdated version of WP Live Chat Support Pro. Please" , "wplivechat")?> <a href="http://wp-livechat.com/get-updated-version/" target=\"_BLANK\"><?php _e("update to at least version", "wplivechat") ?> 4.0</a> <?php _e("to ensure all functionality is in working order", "wplivechat" ) ?>.</p>
403
- <p>&nbsp;</p>
404
- <p><?php _e("If you are having difficulty updating the plugin, please contact","wplivechat") ?> nick@wp-livechat.com</p>
405
-
406
- </div>
407
- <?php
408
- }
409
- }
410
- if(get_option("WPLC_FIRST_TIME") == true && !class_exists("APC_Object_Cache")){
411
- update_option('WPLC_FIRST_TIME', false);
412
- include 'includes/welcome_page.php';
413
- } else {
414
- update_option('WPLC_FIRST_TIME', false);
415
- if (function_exists("wplc_register_pro_version")) {
416
- wplc_pro_admin_menu_layout_display();
417
- } else {
418
- wplc_admin_menu_layout_display();
419
- }
420
- }
421
-
422
- }
423
-
424
- function wplc_admin_menu_layout_display() {
425
- if (!isset($_GET['action'])) {
426
-
427
- ?>
428
- <div style='float:right; display:block; width:450px; padding:10px; text-align:center; background-color: #EEE; border: 1px solid #E6DB55; margin:10px;'>
429
- <strong><?php _e("Experiencing problems with the plugin?", "wplivechat") ?></strong>
430
- <br />
431
- <a href='http://wp-livechat.com/documentation/' title='WP Live Chat Support Documentation' target='_BLANK'><?php _e("Review the documentation.", "wplivechat") ?></a>
432
- <?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'>Support forum.</a>
433
- </div>
434
-
435
- <h1><?php _e("Live Chat", "wplivechat") ?> </h1>
436
- <div id="wplc_sound"></div>
437
-
438
-
439
-
440
-
441
- <div id="wplc_admin_chat_area">
442
-
443
- <?php if (function_exists("wplc_register_pro_version")) {
444
- echo wplc_list_chats_pro();
445
-
446
- } else {
447
- echo wplc_list_chats();
448
-
449
- }
450
-
451
- ?>
452
- </div>
453
-
454
- <h1><?php _e("Visitors on site","wplivechat") ?></h1>
455
- <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 $29.95 once off. Free Updates FOREVER.","wplivechat"); ?>" target=\"_BLANK\"><strong><?php _e("Buy the Pro add-on now for only $29.95 once off. Free Updates Forever.","wplivechat"); ?></strong></a></p>
456
- <?php
457
- }
458
- else {
459
-
460
- if ($_GET['action'] == 'ac') {
461
- wplc_change_chat_status($_GET['cid'],3);
462
- if(function_exists('wplc_ma_register')){
463
- wplc_ma_update_agent_id($_GET['cid'], $_GET['agent_id']);
464
- }
465
- if (function_exists("wplc_register_pro_version")) { wplc_pro_draw_chat_area($_GET['cid']); } else { wplc_draw_chat_area($_GET['cid']); }
466
- }
467
- }
468
- }
469
-
470
- function wplc_draw_chat_area($cid) {
471
-
472
- global $wpdb;
473
- global $wplc_tblname_chats;
474
- $results = $wpdb->get_results(
475
- "
476
- SELECT *
477
- FROM $wplc_tblname_chats
478
- WHERE `id` = '$cid'
479
- LIMIT 1
480
- "
481
- );?>
482
- <style>
483
- .wplc-user-message{
484
- display: inline-block;
485
- padding: 5px;
486
- -webkit-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
487
- -moz-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
488
- box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
489
- border-radius: 5px;
490
- float: left;
491
- margin-bottom: 5px;
492
- }
493
- .wplc-user-message hr , .wplc-admin-message hr{
494
- margin:0;
495
- }
496
- .wplc-clear-float-message{
497
- clear: both;
498
- }
499
-
500
- .wplc-admin-message{
501
- display: inline-block;
502
- padding: 5px;
503
- -webkit-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
504
- -moz-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
505
- box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
506
- border-radius: 5px;
507
- float: right;
508
- margin-bottom: 5px;
509
- }
510
- </style>
511
- <?php
512
-
513
-
514
- foreach ($results as $result) {
515
- if ($result->status == 1) { $status = __("Previous", "wplivechat"); } else { $status = __("Active", "wplivechat"); }
516
-
517
- echo "<h2>$status Chat with ".$result->name."</h2>";
518
- echo "<style>#adminmenuwrap { display:none; } #adminmenuback { display:none; } #wpadminbar { display:none; } #wpfooter { display:none; } .update-nag { display:none; }</style>";
519
- echo "<div style='display:block;'>";
520
- echo "<div style='float:left; width:100px;'><img src=\"http://www.gravatar.com/avatar/".md5($result->email)."\" /></div>";
521
- echo "<div id=\"wplc_sound_update\"></div>";
522
- echo "<div style='float:left; width:350px;'>";
523
- echo "<table>";
524
- echo "<tr><td>Email address</td><td><a href='mailto:".$result->email."' title='".$result->email."'>".$result->email."</a></td></tr>";
525
- echo "<tr><td>IP Address</td><td><a href='http://www.ip-adress.com/ip_tracer/".$result->ip."' title='Whois for ".$result->ip."'>".$result->ip."</a></td></tr>";
526
- echo "<tr><td>From URL</td><td>".$result->url. " (<a href='".$result->url."' target='_BLANK'>open</a>)"."</td></tr>";
527
- echo "<tr><td>Date</td><td>".$result->timestamp."</td></tr>";
528
- echo "</table><br />";
529
- echo "</div>";
530
- echo "</div>";
531
-
532
- echo "
533
- <p style=\"display:block; width:290px; text-align:right; font-size:10px;\"><a href=\"javascript:void(0);\" class=\"wplc_admin_close_chat\" id=\"wplc_admin_close_chat\">".__("End chat","wplivechat")."</a></p>
534
- <div id='admin_chat_box'>
535
- <div id='admin_chat_box_area_".$result->id."' style='height:200px; width:290px; border:1px solid #ccc; overflow:auto; padding: 5px;'>".wplc_return_chat_messages($cid)."</div>
536
- <p>
537
- ";
538
- if ($result->status != 1) {
539
- echo "
540
- <p style=\"text-align:left; font-size:11px;\">Press ENTER to send your message</p>
541
- <input type='text' name='wplc_admin_chatmsg' id='wplc_admin_chatmsg' value='' style=\"border:1px solid #666; width:290px;\" />
542
- <input id='wplc_admin_cid' type='hidden' value='".$_GET['cid']."' />
543
- <input id='wplc_admin_send_msg' type='button' value='".__("Send","wplivechat")."' style=\"display:none;\" />
544
- </p>
545
- </div>
546
- ";
547
- //echo wplc_return_admin_chat_javascript($_GET['cid']);
548
- }
549
-
550
- }
551
- }
552
-
553
- function wplc_return_admin_chat_javascript($cid) {
554
- $ajax_nonce = wp_create_nonce("wplc");
555
- if(function_exists("wplc_pro_get_admin_picture")){
556
- $src = wplc_pro_get_admin_picture();
557
- if($src){
558
- $image = "<img src=".$src." width='20px' id='wp-live-chat-2-img'/>";
559
- }
560
- }
561
- ?>
562
- <script type="text/javascript">
563
- var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
564
- var chat_status = 3;
565
- var cid = <?php echo $cid; ?>;
566
- var data = {
567
- action: 'wplc_admin_long_poll_chat',
568
- security: '<?php echo $ajax_nonce; ?>',
569
- cid: cid,
570
- chat_status: chat_status
571
- };
572
- var wplc_run = true;
573
- function wplc_call_to_server_admin_chat(data) {
574
- jQuery.ajax({
575
- url: wplc_ajaxurl,
576
- data:data,
577
- type:"POST",
578
- success: function(response) {
579
- if(response){
580
-
581
- response = JSON.parse(response);
582
- //console.log(response);
583
- if(response['action'] === "wplc_update_chat_status"){
584
- data['chat_status'] = response['chat_status'];
585
- wplc_display_chat_status_update(response['chat_status'],cid);
586
- }
587
- if(response['action'] === "wplc_new_chat_message"){
588
- current_len = jQuery("#admin_chat_box_area_"+cid).html().length;
589
- jQuery("#admin_chat_box_area_"+cid).append(response['chat_message']);
590
- new_length = jQuery("#admin_chat_box_area_"+cid).html().length;
591
- if (current_len < new_length) {
592
- document.getElementById("wplc_sound_update").innerHTML="<embed src='<?php echo plugins_url('/ding.mp3', __FILE__); ?>' hidden=true autostart=true loop=false>";
593
- }
594
- var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
595
- jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
596
- }
597
- if(response['action'] === "wplc_user_open_chat"){
598
- data['action_2'] = "";
599
- <?php $url = admin_url( 'admin.php?page=wplivechat-menu&action=ac&cid='.$cid); ?>
600
- window.location.replace('<?php echo $url; ?>');
601
- }
602
-
603
- }
604
- },
605
- error: function(jqXHR, exception) {
606
- if (jqXHR.status == 404) {
607
- console.log('Requested page not found. [404]');
608
- wplc_run = false;
609
- } else if (jqXHR.status == 500) {
610
- console.log('Internal Server Error [500].');
611
- wplc_run = false;
612
- } else if (exception === 'parsererror') {
613
- console.log('Requested JSON parse failed.');
614
- wplc_run = false;
615
- } else if (exception === 'abort') {
616
- console.log('Ajax request aborted.');
617
- wplc_run = false;
618
- } else {
619
- console.log('Uncaught Error.\n' + jqXHR.responseText);
620
- wplc_run = false;
621
- }
622
- },
623
- complete: function(response){
624
- //console.log(wplc_run);
625
- if (wplc_run) {
626
- wplc_call_to_server_admin_chat(data);
627
- }
628
- },
629
-
630
- timeout: 120000
631
- });
632
- };
633
-
634
- function wplc_display_chat_status_update(new_chat_status, cid){
635
- if (new_chat_status === "0") { } else {
636
- if (chat_status !== new_chat_status) {
637
- previous_chat_status = chat_status;
638
- //console.log("previous chat status: "+previous_chat_status);
639
- chat_status = new_chat_status;
640
- //console.log("chat status: "+chat_status);
641
-
642
- if ((previous_chat_status === "2" && chat_status === "3") || (previous_chat_status === "5" && chat_status === "3")) {
643
- jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has opened the chat window","wplivechat"); ?></em><br />");
644
- var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
645
- jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
646
-
647
- } else if (chat_status == "10" && previous_chat_status == "3") {
648
- jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has minimized the chat window","wplivechat"); ?></em><br />");
649
- var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
650
- jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
651
- }
652
- else if(chat_status === "3" && previous_chat_status === "10"){
653
- jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has maximized the chat window","wplivechat"); ?></em><br />");
654
- var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
655
- jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
656
- }
657
- else if (chat_status === "1" || chat_status === "8") {
658
- jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has closed and ended the chat","wplivechat"); ?></em><br />");
659
- var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
660
- jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
661
- document.getElementById('wplc_admin_chatmsg').disabled = true;
662
- }
663
- }
664
- }
665
- }
666
-
667
-
668
-
669
- jQuery(document).ready(function() {
670
-
671
- var wplc_image = "<?php echo $image ?>";
672
- var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
673
-
674
-
675
- jQuery("#wplc_admin_chatmsg").focus();
676
-
677
-
678
-
679
-
680
- wplc_call_to_server_admin_chat(data);
681
-
682
- if (jQuery('#wplc_admin_cid').length){
683
- var wplc_cid = jQuery("#wplc_admin_cid").val();
684
- var height = jQuery('#admin_chat_box_area_'+wplc_cid)[0].scrollHeight;
685
- jQuery('#admin_chat_box_area_'+wplc_cid).scrollTop(height);
686
- }
687
-
688
- jQuery(".wplc_admin_accept").on("click", function() {
689
- wplc_title_alerts3 = setTimeout(function (){ document.title = "WP Live Chat Support"; }, 2500);
690
- var cid = jQuery(this).attr("cid");
691
-
692
- var data = {
693
- action: 'wplc_admin_accept_chat',
694
- cid: cid,
695
- security: '<?php echo $ajax_nonce; ?>'
696
- };
697
- jQuery.post(wplc_ajaxurl, data, function(response) {
698
- //console.log("wplc_admin_accept_chat");
699
- wplc_refresh_chat_boxes[cid] = setInterval(function (){wpcl_admin_update_chat_box(cid);}, 3000);
700
- jQuery("#admin_chat_box_"+cid).show();
701
- });
702
- });
703
-
704
- jQuery("#wplc_admin_chatmsg").keyup(function(event){
705
- if(event.keyCode == 13){
706
- jQuery("#wplc_admin_send_msg").click();
707
- }
708
- });
709
-
710
- jQuery("#wplc_admin_close_chat").on("click", function() {
711
- var wplc_cid = jQuery("#wplc_admin_cid").val();
712
- var data = {
713
- action: 'wplc_admin_close_chat',
714
- security: '<?php echo $ajax_nonce; ?>',
715
- cid: wplc_cid
716
-
717
- };
718
- jQuery.post(wplc_ajaxurl, data, function(response) {
719
- //console.log("wplc_admin_close_chat");
720
- //console.log(response);
721
- window.close();
722
- });
723
-
724
- });
725
-
726
- jQuery("#wplc_admin_send_msg").on("click", function() {
727
- var wplc_cid = jQuery("#wplc_admin_cid").val();
728
- var wplc_chat = jQuery("#wplc_admin_chatmsg").val();
729
- var wplc_name = "a"+"d"+"m"+"i"+"n";
730
- jQuery("#wplc_admin_chatmsg").val('');
731
-
732
-
733
- jQuery("#admin_chat_box_area_"+wplc_cid).append("<span class='wplc-admin-message'>"+wplc_image+" <strong>"+wplc_name+"</strong>:<hr/>"+wplc_chat+"</span><br /><div class='wplc-clear-float-message'></div>");
734
- var height = jQuery('#admin_chat_box_area_'+wplc_cid)[0].scrollHeight;
735
- jQuery('#admin_chat_box_area_'+wplc_cid).scrollTop(height);
736
-
737
-
738
- var data = {
739
- action: 'wplc_admin_send_msg',
740
- security: '<?php echo $ajax_nonce; ?>',
741
- cid: wplc_cid,
742
- msg: wplc_chat
743
- };
744
- jQuery.post(wplc_ajaxurl, data, function(response) {
745
- //console.log("wplc_admin_send_msg");
746
-
747
- /* do nothing
748
- jQuery("#admin_chat_box_area_"+wplc_cid).html(response);
749
- var height = jQuery('#admin_chat_box_area_'+wplc_cid)[0].scrollHeight;
750
- jQuery('#admin_chat_box_area_'+wplc_cid).scrollTop(height);
751
- */
752
- });
753
-
754
-
755
- });
756
-
757
-
758
-
759
-
760
-
761
-
762
-
763
- });
764
- </script>
765
- <?php
766
-
767
- }
768
- function wplc_activate() {
769
- wplc_handle_db();
770
- if (!get_option("WPLC_SETTINGS")) {
771
- add_option('WPLC_SETTINGS',array("wplc_settings_align" => "2", "wplc_settings_enabled" => "1", "wplc_settings_fill" => "73BE28", "wplc_settings_font" => "FFFFFF"));
772
- }
773
- add_option("WPLC_HIDE_CHAT","true");
774
- add_option("WPLC_FIRST_TIME", true);
775
- }
776
-
777
-
778
- function wplc_handle_db() {
779
- global $wpdb;
780
- global $wplc_version;
781
- global $wplc_tblname_chats;
782
- global $wplc_tblname_msgs;
783
-
784
- $sql = "
785
- CREATE TABLE ".$wplc_tblname_chats." (
786
- id int(11) NOT NULL AUTO_INCREMENT,
787
- timestamp datetime NOT NULL,
788
- name varchar(700) NOT NULL,
789
- email varchar(700) NOT NULL,
790
- ip varchar(700) NOT NULL,
791
- status int(11) NOT NULL,
792
- url varchar(700) NOT NULL,
793
- last_active_timestamp datetime NOT NULL,
794
- PRIMARY KEY (id)
795
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
796
- ";
797
-
798
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
799
- dbDelta($sql);
800
-
801
- $sql = "
802
- CREATE TABLE ".$wplc_tblname_msgs." (
803
- id int(11) NOT NULL AUTO_INCREMENT,
804
- chat_sess_id int(11) NOT NULL,
805
- from varchar(150) CHARACTER SET utf8 NOT NULL,
806
- msg varchar(700) CHARACTER SET utf8 NOT NULL,
807
- timestamp datetime NOT NULL,
808
- status INT(3) NOT NULL,
809
- originates INT(3) NOT NULL,
810
- PRIMARY KEY (id)
811
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
812
- ";
813
-
814
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
815
- dbDelta($sql);
816
- add_option("wplc_db_version", $wplc_version);
817
- update_option("wplc_db_version",$wplc_version);
818
- }
819
-
820
- function wplc_add_user_stylesheet() {
821
- wp_register_style( 'wplc-font-awesome', plugins_url('/css/font-awesome.min.css', __FILE__) );
822
- wp_enqueue_style( 'wplc-font-awesome' );
823
- wp_register_style( 'wplc-style', plugins_url('/css/wplcstyle.css', __FILE__) );
824
- wp_enqueue_style( 'wplc-style' );
825
-
826
- }
827
- function wplc_add_admin_stylesheet() {
828
- wp_register_style( 'wplc-admin-style', 'http://code.jquery.com/ui/1.8.24/themes/smoothness/jquery-ui.css' );
829
- wp_enqueue_style( 'wplc-admin-style' );
830
-
831
- }
832
-
833
- if (isset($_GET['page']) && $_GET['page'] == 'wplivechat-menu-settings') {
834
- add_action('admin_print_scripts', 'wplc_admin_scripts_basic');
835
- }
836
- function wplc_admin_scripts_basic() {
837
-
838
- if ($_GET['page'] == "wplivechat-menu-settings") {
839
- wp_enqueue_script( 'jquery' );
840
- wp_enqueue_script('jquery-ui-core');
841
-
842
- wp_register_script('my-wplc-color', plugins_url('js/jscolor.js',__FILE__), false, '1.4.1', false);
843
- wp_enqueue_script('my-wplc-color');
844
- wp_enqueue_script( 'jquery-ui-tabs');
845
- wp_register_script('my-wplc-tabs', plugins_url('js/wplc_tabs.js',__FILE__), array('jquery-ui-core'), '', true);
846
- wp_enqueue_script('my-wplc-tabs');
847
- }
848
- }
849
-
850
-
851
- function wplc_admin_settings_layout() {
852
- wplc_settings_page_basic();
853
- }
854
- function wplc_admin_history_layout() {
855
- echo"<div class=\"wrap\"><div id=\"icon-edit\" class=\"icon32 icon32-posts-post\"><br></div><h2>".__("WP Live Chat History","wplivechat")."</h2>";
856
- if (function_exists("wplc_register_pro_version")) {
857
- wplc_pro_admin_display_history();
858
- }
859
- else {
860
- echo "<br /><br >This option is only available in the <a href=\"http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=history1\" title=\"".__("Pro Add-on","wplivechat")."\" target=\"_BLANK\">Pro Add-on</a> of WP Live Chat. <a href=\"http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=history2\" title=\"".__("Pro Add-on","wplivechat")."\" target=\"_BLANK\">Get it now for only $29.95 once off!</a>";
861
- }
862
- }
863
-
864
-
865
- function wplc_settings_page_basic() {
866
- if(function_exists("wplc_register_pro_version")){
867
- wplc_settings_page_pro();
868
- } else {
869
- include 'includes/settings_page.php';
870
- }
871
- }
872
- function wplc_head_basic() {
873
- global $wpdb;
874
-
875
- if (isset($_POST['wplc_save_settings'])){
876
-
877
- $wplc_data['wplc_settings_align'] = esc_attr($_POST['wplc_settings_align']);
878
- $wplc_data['wplc_settings_fill'] = esc_attr($_POST['wplc_settings_fill']);
879
- $wplc_data['wplc_settings_font'] = esc_attr($_POST['wplc_settings_font']);
880
- $wplc_data['wplc_settings_enabled'] = esc_attr($_POST['wplc_settings_enabled']);
881
- update_option('WPLC_SETTINGS', $wplc_data);
882
- update_option("WPLC_HIDE_CHAT", $_POST['wplc_hide_chat']);
883
- echo "<div class='updated'>";
884
- _e("Your settings have been saved.","wplivechat");
885
- echo "</div>";
886
- }
887
- if(isset($_POST['action']) && $_POST['action'] == "wplc_submit_find_us"){
888
- if (function_exists('curl_version')) {
889
- $request_url = "http://www.wp-livechat.com/apif/rec.php";
890
- $ch = curl_init();
891
- curl_setopt($ch, CURLOPT_URL, $request_url);
892
- curl_setopt($ch, CURLOPT_POST, 1);
893
- curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
894
- curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
895
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
896
- $output = curl_exec($ch);
897
- curl_close($ch);
898
- }
899
- echo "<div class=\"updated\"><p>". __("Thank You for your feedback!","wplivechat")."</p></div>";
900
- }
901
- if (isset($_POST['wplc_nl_send_feedback'])) {
902
- if(wp_mail("nick@wp-livechat.com", "Plugin feedback", "Name: ".$_POST['wplc_nl_feedback_name']."\n\r"."Email: ".$_POST['wplc_nl_feedback_email']."\n\r"."Website: ".$_POST['wplc_nl_feedback_website']."\n\r"."Feedback:".$_POST['wplc_nl_feedback_feedback'] )){
903
- echo "<div id=\"message\" class=\"updated\"><p>".__("Thank you for your feedback. We will be in touch soon","wplc")."</p></div>";
904
- } else {
905
-
906
- if (function_exists('curl_version')) {
907
- $request_url = "http://www.wp-livechat.com/apif/rec_feedback.php";
908
- $ch = curl_init();
909
- curl_setopt($ch, CURLOPT_URL, $request_url);
910
- curl_setopt($ch, CURLOPT_POST, 1);
911
- curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
912
- curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
913
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
914
- $output = curl_exec($ch);
915
- curl_close($ch);
916
- echo "<div id=\"message\" class=\"updated\"><p>".__("Thank you for your feedback. We will be in touch soon","wplc")."</p></div>";
917
- }
918
- else {
919
- echo "<div id=\"message\" class=\"error\">";
920
- echo "<p>".__("There was a problem sending your feedback. Please log your feedback on ","wplc")."<a href='http://wp-livechat.com/forums/forum/support/' target='_BLANK'>http://wp-livechat.com/forums/forum/support/</a></p>";
921
- echo "</div>";
922
- }
923
- }
924
- }
925
-
926
- }
927
-
928
- function wplc_logout() {
929
- delete_transient('wplc_is_admin_logged_in');
930
- }
931
- add_action('wp_logout', 'wplc_logout');
932
-
933
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP Live Chat Support
4
+ Plugin URI: http://www.wp-livechat.com
5
+ Description: The easiest to use website live chat plugin. Let your visitors chat with you and increase sales conversion rates with WP Live Chat Support. No third party connection required!
6
+ Version: 4.0.1
7
+ Author: WP-LiveChat
8
+ Author URI: http://www.wp-livechat.com
9
+ */
10
+
11
+ error_reporting(E_ERROR);
12
+ global $wplc_version;
13
+ global $wplc_p_version;
14
+ global $wplc_tblname;
15
+ global $wpdb;
16
+ global $wplc_tblname_chats;
17
+ global $wplc_tblname_msgs;
18
+ $wplc_tblname_chats = $wpdb->prefix . "wplc_chat_sessions";
19
+ $wplc_tblname_msgs = $wpdb->prefix . "wplc_chat_msgs";
20
+ $wplc_version = "4.0.1";
21
+
22
+
23
+
24
+
25
+ require_once (plugin_dir_path( __FILE__ )."functions.php");
26
+ add_action('wp_ajax_wplc_admin_set_transient', 'wplc_action_callback');
27
+
28
+ add_action('wp_footer', 'wplc_display_box');
29
+
30
+ add_action('init','wplc_init');
31
+
32
+ if (function_exists('wplc_head_pro')) {
33
+ add_action('admin_head', 'wplc_head_pro');
34
+ } else {
35
+ add_action('admin_head', 'wplc_head_basic');
36
+ }
37
+
38
+
39
+ add_action('wp_enqueue_scripts', 'wplc_add_user_stylesheet' );
40
+ add_action('admin_enqueue_scripts', 'wplc_add_admin_stylesheet');
41
+
42
+ if(function_exists('wplc_admin_menu_pro')){
43
+ add_action('admin_menu', 'wplc_admin_menu_pro');
44
+ } else {
45
+ add_action('admin_menu', 'wplc_admin_menu');
46
+ }
47
+ add_action('admin_head', 'wplc_superadmin_javascript');
48
+ register_activation_hook( __FILE__, 'wplc_activate' );
49
+
50
+ function wplc_basic_check(){
51
+ // check if basic exists if pro is installed
52
+ }
53
+ function wplc_init() {
54
+ $plugin_dir = basename(dirname(__FILE__))."/languages/";
55
+ load_plugin_textdomain( 'wplivechat', false, $plugin_dir );
56
+ }
57
+
58
+
59
+ function wplc_action_callback() {
60
+ global $wpdb;
61
+ global $wplc_tblname_chats;
62
+ $check = check_ajax_referer( 'wplc', 'security' );
63
+
64
+ if ($check == 1) {
65
+ if ($_POST['action'] == "wplc_admin_set_transient") {
66
+ set_transient("wplc_is_admin_logged_in", "1", 70 );
67
+
68
+ }
69
+ }
70
+ die(); // this is required to return a proper result
71
+
72
+ }
73
+
74
+
75
+ function wplc_feedback_page_include(){
76
+ include 'includes/feedback-page.php';
77
+ }
78
+
79
+ function wplc_admin_menu() {
80
+ $wplc_mainpage = add_menu_page('WP Live Chat', __('Live Chat','wplivechat'), 'manage_options', 'wplivechat-menu', 'wplc_admin_menu_layout');
81
+ add_submenu_page('wplivechat-menu', __('Settings','wplivechat'), __('Settings','wplivechat'), 'manage_options' , 'wplivechat-menu-settings', 'wplc_admin_settings_layout');
82
+ add_submenu_page('wplivechat-menu', __('History','wplivechat'), __('History','wplivechat'), 'manage_options' , 'wplivechat-menu-history', 'wplc_admin_history_layout');
83
+ add_submenu_page('wplivechat-menu', __('Feedback','wplivechat'), __('Feedback','wplivechat'), 'manage_options' , 'wplivechat-menu-feedback-page', 'wplc_feedback_page_include');
84
+ }
85
+ add_action('wp_head','wplc_user_top_js');
86
+ function wplc_user_top_js() {
87
+ echo "<!-- DEFINING DO NOT CACHE -->";
88
+ define('DONOTCACHEPAGE', true);
89
+ define('DONOTCACHEDB', true);
90
+ $ajax_nonce = wp_create_nonce("wplc");
91
+ wp_register_script( 'wplc-user-jquery-cookie', plugins_url('/js/jquery-cookie.js', __FILE__) , array('jquery-ui-draggable'));
92
+ wp_enqueue_script( 'wplc-user-jquery-cookie');
93
+ $wplc_settings = get_option("WPLC_SETTINGS");
94
+
95
+ ?>
96
+
97
+ <script type="text/javascript">
98
+ <?php if (!function_exists("wplc_register_pro_version")) { ?>
99
+ var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
100
+
101
+ <?php } ?>
102
+ var wplc_nonce = '<?php echo $ajax_nonce; ?>';
103
+ </script>
104
+ <?php
105
+
106
+
107
+ }
108
+
109
+ function wplc_draw_user_box() {
110
+ $wplc_settings = get_option("WPLC_SETTINGS");
111
+ if ($wplc_settings["wplc_settings_enabled"] == 2) { return; }
112
+
113
+
114
+ wp_register_script( 'wplc-user-script', plugins_url('/js/wplc_u.js', __FILE__) );
115
+ wp_enqueue_script( 'wplc-user-script' );
116
+ wp_localize_script('wplc-user-script', 'wplc_hide_chat', null);
117
+ wp_enqueue_script( 'jquery' );
118
+ wp_enqueue_script( 'jquery-ui-core' );
119
+ wp_enqueue_script( 'jquery-ui-draggable');
120
+ wplc_output_box();
121
+
122
+ }
123
+ function wplc_output_box() {
124
+
125
+
126
+ $wplc_settings = get_option("WPLC_SETTINGS");
127
+ if ($wplc_settings["wplc_settings_enabled"] == 2) { return; }
128
+
129
+ if ($wplc_settings["wplc_settings_align"] == 1) { $wplc_box_align = "left:100px;"; } else { $wplc_box_align = "right:100px;"; }
130
+ if ($wplc_settings["wplc_settings_fill"]) { $wplc_settings_fill = "#".$wplc_settings["wplc_settings_fill"]; } else { $wplc_settings_fill = "#73BE28"; }
131
+ if ($wplc_settings["wplc_settings_font"]) { $wplc_settings_font = "#".$wplc_settings["wplc_settings_font"]; } else { $wplc_settings_font = "#FFFFFF"; }
132
+
133
+ $wplc_is_admin_logged_in = get_transient("wplc_is_admin_logged_in");
134
+ if (!function_exists("wplc_register_pro_version") && $wplc_is_admin_logged_in != 1) {
135
+ return "";
136
+ }
137
+ if($wplc_settings["wplc_settings_align"] == 1){
138
+ $original_pos = "left";
139
+ } else {
140
+ $original_pos = "right";
141
+ }
142
+
143
+ ?>
144
+ <div id="wp-live-chat" style="display:none; <?php echo $wplc_box_align; ?>;" original_pos="<?php echo $original_pos ?>">
145
+
146
+
147
+ <?php if (function_exists("wplc_register_pro_version")) {
148
+ wplc_pro_output_box();
149
+ } else {
150
+ ?>
151
+ <div id="wp-live-chat-header" style="background-color: <?php echo $wplc_settings_fill; ?> !important; color: <?php echo $wplc_settings_font; ?> !important;">
152
+
153
+ <i id="wp-live-chat-minimize" class="fa fa-minus" style="display:none;" ></i>
154
+ <i id="wp-live-chat-close" class="fa fa-times" style="display:none;" ></i>
155
+
156
+ <div id="wp-live-chat-1" >
157
+ <div style="display:block; ">
158
+ <strong><?php _e("Questions?", "wplivechat") ?></strong> <?php _e("Chat with us", "wplivechat") ?>
159
+ </div>
160
+ </div>
161
+ </div>
162
+ <div id="wp-live-chat-2" style="display:none;">
163
+
164
+ <div id="wp-live-chat-2-info">
165
+ <strong>Start Live Chat</strong>
166
+ </div>
167
+
168
+ <input type="text" name="wplc_name" id="wplc_name" value="" placeholder="<?php _e("Name","wplivechat"); ?>" />
169
+
170
+ <input type="text" name="wplc_email" id="wplc_email" value="" placeholder="<?php _e("Email","wplivechat"); ?>" />
171
+
172
+ <input id="wplc_start_chat_btn" type="button" value="<?php _e("Start Chat","wplivechat"); ?>" style="background-color: <?php echo $wplc_settings_fill; ?> !important; color: <?php echo $wplc_settings_font; ?> !important;"/>
173
+
174
+
175
+
176
+ </div>
177
+
178
+ <div id="wp-live-chat-3" style="display:none;">
179
+ <p><?php _e("Connecting you to a sales person. Please be patient.","wplivechat") ?></p>
180
+ </div>
181
+ <div id="wp-live-chat-react" style="display:none;">
182
+ <p><?php _e("Reactivating your previous chat...", "wplivechat") ?></p>
183
+ </div>
184
+ <div id="wp-live-chat-4" style="display:none;">
185
+ <div id="wplc_chatbox"></div>
186
+ <p style="text-align:center; font-size:11px;"><?php _e("Press ENTER to send your message", "wplivechat" )?></p>
187
+ <p>
188
+ <input type="text" name="wplc_chatmsg" id="wplc_chatmsg" value="" />
189
+ <input type="hidden" name="wplc_cid" id="wplc_cid" value="" />
190
+ <input id="wplc_send_msg" type="button" value="<?php _e("Send","wplivechat"); ?>" style="display:none;" /></p>
191
+ </div>
192
+
193
+ </div>
194
+ <?php
195
+ }
196
+ }
197
+
198
+ function wplc_display_box() {
199
+ $wplc_is_admin_logged_in = get_transient("wplc_is_admin_logged_in");
200
+ if ($wplc_is_admin_logged_in != 1) { echo "<!-- wplc a-n-c -->"; }
201
+ if (function_exists("wplc_register_pro_version")) { wplc_pro_draw_user_box(); } else { wplc_draw_user_box(); }
202
+ }
203
+
204
+
205
+
206
+ function wplc_admin_display_chat($cid) {
207
+ global $wpdb;
208
+ global $wplc_tblname_msgs;
209
+ $results = $wpdb->get_results(
210
+ "
211
+ SELECT *
212
+ FROM $wplc_tblname_msgs
213
+ WHERE `chat_sess_id` = '$cid'
214
+ ORDER BY `timestamp` DESC
215
+ LIMIT 0, 100
216
+ "
217
+ );
218
+ foreach ($results as $result) {
219
+ $from = $result->from;
220
+ $msg = stripslashes($result->msg);
221
+ $msg_hist .= "$from: $msg<br />";
222
+
223
+ }
224
+ echo $msg_hist;
225
+ }
226
+ function wplc_admin_accept_chat($cid) {
227
+ wplc_change_chat_status($cid,3);
228
+ return true;
229
+
230
+ }
231
+ add_action('admin_head','wplc_update_chat_statuses');
232
+
233
+
234
+ function wplc_superadmin_javascript() {
235
+
236
+ if (isset($_GET['page']) && $_GET['page'] == 'wplivechat-menu') {
237
+
238
+ if (!isset($_GET['action'])) {
239
+ if (function_exists("wplc_register_pro_version")) {
240
+ wplc_pro_admin_javascript();
241
+ } else {
242
+ wplc_admin_javascript();
243
+ }
244
+
245
+ } // main page
246
+ else if (isset($_GET['action'])) {
247
+ if (function_exists("wplc_register_pro_version")) {
248
+ wplc_return_pro_admin_chat_javascript($_GET['cid']);
249
+ } else {
250
+ wplc_return_admin_chat_javascript($_GET['cid']);
251
+ }
252
+
253
+ }
254
+
255
+
256
+
257
+ }
258
+
259
+ $ajax_nonce = wp_create_nonce("wplc");
260
+ ?>
261
+ <script type="text/javascript">
262
+ jQuery(document).ready(function() {
263
+
264
+
265
+ var wplc_set_transient = null;
266
+
267
+ wplc_set_transient = setInterval(function (){wpcl_admin_set_transient();}, 60000);
268
+ wpcl_admin_set_transient();
269
+ function wpcl_admin_set_transient() {
270
+ var data = {
271
+ action: 'wplc_admin_set_transient',
272
+ security: '<?php echo $ajax_nonce; ?>'
273
+
274
+ };
275
+ jQuery.post(ajaxurl, data, function(response) {
276
+ //console.log("wplc_admin_set_transient");
277
+ });
278
+ }
279
+
280
+
281
+
282
+
283
+
284
+ });
285
+
286
+
287
+
288
+ </script>
289
+ <?php
290
+ }
291
+ function wplc_admin_javascript() {
292
+ $ajax_nonce = wp_create_nonce("wplc");
293
+ ?>
294
+
295
+ <script type="text/javascript">
296
+ var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
297
+ var data = {
298
+ action: 'wplc_admin_long_poll',
299
+ security: '<?php echo $ajax_nonce; ?>',
300
+ wplc_list_visitors_data: false ,
301
+ wplc_update_admin_chat_table: false
302
+ };
303
+ var wplc_pending_refresh = null;
304
+
305
+ var wplc_run = true;
306
+ function wplc_call_to_server(data) {
307
+
308
+
309
+ jQuery.ajax({
310
+ url: wplc_ajaxurl,
311
+ data:data,
312
+ type:"POST",
313
+ success: function(response) {
314
+
315
+ //Update your dashboard gauge
316
+ if(response){
317
+
318
+ response = JSON.parse(response);
319
+ //console.log(response);
320
+ data["wplc_update_admin_chat_table"] = response['wplc_update_admin_chat_table'];
321
+ //console.log(response['visitors']);
322
+
323
+ if(response['action'] === "wplc_update_admin_chat"){
324
+ jQuery("#wplc_admin_chat_area").html(response['wplc_update_admin_chat_table']);
325
+ if (response['pending'] === true) {
326
+
327
+ var orig_title = document.getElementsByTagName("title")[0].innerHTML;
328
+ wplc_pending_refresh = setInterval(function (){
329
+ document.title = "** CHAT REQUEST **";
330
+ wplc_title_alerts1 = setTimeout(function (){ document.title = "__ CHAT Request __"; }, 1000);
331
+ wplc_title_alerts2 = setTimeout(function (){ document.title = "** CHAT REQUEST **"; }, 1500);
332
+ wplc_title_alerts3 = setTimeout(function (){ document.title = "__ CHAT Request __"; }, 2000);
333
+ wplc_title_alerts4 = setTimeout(function (){ document.title = orig_title; }, 2500);
334
+
335
+ document.getElementById("wplc_sound").innerHTML="<embed src='<?php echo plugins_url('/ring.wav', __FILE__); ?>' hidden=true autostart=true loop=false>";
336
+ }, 3000);
337
+ } else {
338
+ //console.log("end");
339
+ clearInterval(wplc_pending_refresh);
340
+ }
341
+ }
342
+
343
+ }
344
+ },
345
+ error: function(jqXHR, exception) {
346
+ if (jqXHR.status == 404) {
347
+ console.log('Requested page not found. [404]');
348
+ wplc_run = false;
349
+ } else if (jqXHR.status == 500) {
350
+ console.log('Internal Server Error [500].');
351
+ wplc_run = false;
352
+ } else if (exception === 'parsererror') {
353
+ console.log('Requested JSON parse failed.');
354
+ wplc_run = false;
355
+ } else if (exception === 'abort') {
356
+ console.log('Ajax request aborted.');
357
+ wplc_run = false;
358
+ } else {
359
+ console.log('Uncaught Error.\n' + jqXHR.responseText);
360
+ wplc_run = false;
361
+ }
362
+ },
363
+ complete: function(response){
364
+ //console.log(wplc_run);
365
+ if (wplc_run) {
366
+ wplc_call_to_server(data);
367
+ }
368
+ },
369
+ timeout: 120000
370
+ });
371
+ };
372
+
373
+
374
+
375
+ jQuery(document).ready(function() {
376
+ jQuery('body').on("click", "a", function (event) {
377
+ if(jQuery(this).hasClass('wplc_open_chat')){
378
+ event.preventDefault();
379
+ window.open(jQuery(this).attr("href"), jQuery(this).attr("window-title" ), "width=600,height=600,scrollbars=yes", false);
380
+ }
381
+ });
382
+
383
+ wplc_call_to_server(data);
384
+ });
385
+
386
+
387
+
388
+ </script>
389
+ <?php
390
+ }
391
+
392
+
393
+
394
+ function wplc_admin_menu_layout() {
395
+ if (function_exists("wplc_register_pro_version")) {
396
+ global $wplc_pro_version;
397
+ if (floatval($wplc_pro_version) < 4.0) {
398
+ ?>
399
+ <div class='error below-h1'>
400
+
401
+ <p><?php _e("Dear Pro User", "wplivechat") ?><br /></p>
402
+ <p><?php _e("You are using an outdated version of WP Live Chat Support Pro. Please" , "wplivechat")?> <a href="http://wp-livechat.com/get-updated-version/" target=\"_BLANK\"><?php _e("update to at least version", "wplivechat") ?> 4.0</a> <?php _e("to ensure all functionality is in working order", "wplivechat" ) ?>.</p>
403
+ <p>&nbsp;</p>
404
+ <p><?php _e("If you are having difficulty updating the plugin, please contact","wplivechat") ?> nick@wp-livechat.com</p>
405
+
406
+ </div>
407
+ <?php
408
+ }
409
+ }
410
+ if(get_option("WPLC_FIRST_TIME") == true && !class_exists("APC_Object_Cache")){
411
+ update_option('WPLC_FIRST_TIME', false);
412
+ include 'includes/welcome_page.php';
413
+ } else {
414
+ update_option('WPLC_FIRST_TIME', false);
415
+ if (function_exists("wplc_register_pro_version")) {
416
+ wplc_pro_admin_menu_layout_display();
417
+ } else {
418
+ wplc_admin_menu_layout_display();
419
+ }
420
+ }
421
+
422
+ }
423
+
424
+ function wplc_admin_menu_layout_display() {
425
+ if (!isset($_GET['action'])) {
426
+
427
+ ?>
428
+ <div style='float:right; display:block; width:450px; padding:10px; text-align:center; background-color: #EEE; border: 1px solid #E6DB55; margin:10px;'>
429
+ <strong><?php _e("Experiencing problems with the plugin?", "wplivechat") ?></strong>
430
+ <br />
431
+ <a href='http://wp-livechat.com/documentation/' title='WP Live Chat Support Documentation' target='_BLANK'><?php _e("Review the documentation.", "wplivechat") ?></a>
432
+ <?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'>Support forum.</a>
433
+ </div>
434
+
435
+ <h1><?php _e("Live Chat", "wplivechat") ?> </h1>
436
+ <div id="wplc_sound"></div>
437
+
438
+
439
+
440
+
441
+ <div id="wplc_admin_chat_area">
442
+
443
+ <?php if (function_exists("wplc_register_pro_version")) {
444
+ echo wplc_list_chats_pro();
445
+
446
+ } else {
447
+ echo wplc_list_chats();
448
+
449
+ }
450
+
451
+ ?>
452
+ </div>
453
+
454
+ <h1><?php _e("Visitors on site","wplivechat") ?></h1>
455
+ <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 $29.95 once off. Free Updates FOREVER.","wplivechat"); ?>" target=\"_BLANK\"><strong><?php _e("Buy the Pro add-on now for only $29.95 once off. Free Updates Forever.","wplivechat"); ?></strong></a></p>
456
+ <?php
457
+ }
458
+ else {
459
+
460
+ if ($_GET['action'] == 'ac') {
461
+ wplc_change_chat_status($_GET['cid'],3);
462
+ if(function_exists('wplc_ma_register')){
463
+ wplc_ma_update_agent_id($_GET['cid'], $_GET['agent_id']);
464
+ }
465
+ if (function_exists("wplc_register_pro_version")) { wplc_pro_draw_chat_area($_GET['cid']); } else { wplc_draw_chat_area($_GET['cid']); }
466
+ }
467
+ }
468
+ }
469
+
470
+ function wplc_draw_chat_area($cid) {
471
+
472
+ global $wpdb;
473
+ global $wplc_tblname_chats;
474
+ $results = $wpdb->get_results(
475
+ "
476
+ SELECT *
477
+ FROM $wplc_tblname_chats
478
+ WHERE `id` = '$cid'
479
+ LIMIT 1
480
+ "
481
+ );?>
482
+ <style>
483
+ .wplc-user-message{
484
+ display: inline-block;
485
+ padding: 5px;
486
+ -webkit-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
487
+ -moz-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
488
+ box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
489
+ border-radius: 5px;
490
+ float: left;
491
+ margin-bottom: 5px;
492
+ }
493
+ .wplc-user-message hr , .wplc-admin-message hr{
494
+ margin:0;
495
+ }
496
+ .wplc-clear-float-message{
497
+ clear: both;
498
+ }
499
+
500
+ .wplc-admin-message{
501
+ display: inline-block;
502
+ padding: 5px;
503
+ -webkit-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
504
+ -moz-box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
505
+ box-shadow: 0px 0px 5px 0px rgba(50, 50, 50, 0.5);
506
+ border-radius: 5px;
507
+ float: right;
508
+ margin-bottom: 5px;
509
+ }
510
+ </style>
511
+ <?php
512
+
513
+
514
+ foreach ($results as $result) {
515
+ if ($result->status == 1) { $status = __("Previous", "wplivechat"); } else { $status = __("Active", "wplivechat"); }
516
+
517
+ echo "<h2>$status Chat with ".$result->name."</h2>";
518
+ echo "<style>#adminmenuwrap { display:none; } #adminmenuback { display:none; } #wpadminbar { display:none; } #wpfooter { display:none; } .update-nag { display:none; }</style>";
519
+ echo "<div style='display:block;'>";
520
+ echo "<div style='float:left; width:100px;'><img src=\"http://www.gravatar.com/avatar/".md5($result->email)."\" /></div>";
521
+ echo "<div id=\"wplc_sound_update\"></div>";
522
+ echo "<div style='float:left; width:350px;'>";
523
+ echo "<table>";
524
+ echo "<tr><td>Email address</td><td><a href='mailto:".$result->email."' title='".$result->email."'>".$result->email."</a></td></tr>";
525
+ echo "<tr><td>IP Address</td><td><a href='http://www.ip-adress.com/ip_tracer/".$result->ip."' title='Whois for ".$result->ip."'>".$result->ip."</a></td></tr>";
526
+ echo "<tr><td>From URL</td><td>".$result->url. " (<a href='".$result->url."' target='_BLANK'>open</a>)"."</td></tr>";
527
+ echo "<tr><td>Date</td><td>".$result->timestamp."</td></tr>";
528
+ echo "</table><br />";
529
+ echo "</div>";
530
+ echo "</div>";
531
+
532
+ echo "
533
+ <p style=\"display:block; width:290px; text-align:right; font-size:10px;\"><a href=\"javascript:void(0);\" class=\"wplc_admin_close_chat\" id=\"wplc_admin_close_chat\">".__("End chat","wplivechat")."</a></p>
534
+ <div id='admin_chat_box'>
535
+ <div id='admin_chat_box_area_".$result->id."' style='height:200px; width:290px; border:1px solid #ccc; overflow:auto; padding: 5px;'>".wplc_return_chat_messages($cid)."</div>
536
+ <p>
537
+ ";
538
+ if ($result->status != 1) {
539
+ echo "
540
+ <p style=\"text-align:left; font-size:11px;\">Press ENTER to send your message</p>
541
+ <input type='text' name='wplc_admin_chatmsg' id='wplc_admin_chatmsg' value='' style=\"border:1px solid #666; width:290px;\" />
542
+ <input id='wplc_admin_cid' type='hidden' value='".$_GET['cid']."' />
543
+ <input id='wplc_admin_send_msg' type='button' value='".__("Send","wplivechat")."' style=\"display:none;\" />
544
+ </p>
545
+ </div>
546
+ ";
547
+ //echo wplc_return_admin_chat_javascript($_GET['cid']);
548
+ }
549
+
550
+ }
551
+ }
552
+
553
+ function wplc_return_admin_chat_javascript($cid) {
554
+ $ajax_nonce = wp_create_nonce("wplc");
555
+ if(function_exists("wplc_pro_get_admin_picture")){
556
+ $src = wplc_pro_get_admin_picture();
557
+ if($src){
558
+ $image = "<img src=".$src." width='20px' id='wp-live-chat-2-img'/>";
559
+ }
560
+ }
561
+ ?>
562
+ <script type="text/javascript">
563
+ var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
564
+ var chat_status = 3;
565
+ var cid = <?php echo $cid; ?>;
566
+ var data = {
567
+ action: 'wplc_admin_long_poll_chat',
568
+ security: '<?php echo $ajax_nonce; ?>',
569
+ cid: cid,
570
+ chat_status: chat_status
571
+ };
572
+ var wplc_run = true;
573
+ function wplc_call_to_server_admin_chat(data) {
574
+ jQuery.ajax({
575
+ url: wplc_ajaxurl,
576
+ data:data,
577
+ type:"POST",
578
+ success: function(response) {
579
+ if(response){
580
+
581
+ response = JSON.parse(response);
582
+ //console.log(response);
583
+ if(response['action'] === "wplc_update_chat_status"){
584
+ data['chat_status'] = response['chat_status'];
585
+ wplc_display_chat_status_update(response['chat_status'],cid);
586
+ }
587
+ if(response['action'] === "wplc_new_chat_message"){
588
+ current_len = jQuery("#admin_chat_box_area_"+cid).html().length;
589
+ jQuery("#admin_chat_box_area_"+cid).append(response['chat_message']);
590
+ new_length = jQuery("#admin_chat_box_area_"+cid).html().length;
591
+ if (current_len < new_length) {
592
+ document.getElementById("wplc_sound_update").innerHTML="<embed src='<?php echo plugins_url('/ding.mp3', __FILE__); ?>' hidden=true autostart=true loop=false>";
593
+ }
594
+ var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
595
+ jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
596
+ }
597
+ if(response['action'] === "wplc_user_open_chat"){
598
+ data['action_2'] = "";
599
+ <?php $url = admin_url( 'admin.php?page=wplivechat-menu&action=ac&cid='.$cid); ?>
600
+ window.location.replace('<?php echo $url; ?>');
601
+ }
602
+
603
+ }
604
+ },
605
+ error: function(jqXHR, exception) {
606
+ if (jqXHR.status == 404) {
607
+ console.log('Requested page not found. [404]');
608
+ wplc_run = false;
609
+ } else if (jqXHR.status == 500) {
610
+ console.log('Internal Server Error [500].');
611
+ wplc_run = false;
612
+ } else if (exception === 'parsererror') {
613
+ console.log('Requested JSON parse failed.');
614
+ wplc_run = false;
615
+ } else if (exception === 'abort') {
616
+ console.log('Ajax request aborted.');
617
+ wplc_run = false;
618
+ } else {
619
+ console.log('Uncaught Error.\n' + jqXHR.responseText);
620
+ wplc_run = false;
621
+ }
622
+ },
623
+ complete: function(response){
624
+ //console.log(wplc_run);
625
+ if (wplc_run) {
626
+ wplc_call_to_server_admin_chat(data);
627
+ }
628
+ },
629
+
630
+ timeout: 120000
631
+ });
632
+ };
633
+
634
+ function wplc_display_chat_status_update(new_chat_status, cid){
635
+ if (new_chat_status === "0") { } else {
636
+ if (chat_status !== new_chat_status) {
637
+ previous_chat_status = chat_status;
638
+ //console.log("previous chat status: "+previous_chat_status);
639
+ chat_status = new_chat_status;
640
+ //console.log("chat status: "+chat_status);
641
+
642
+ if ((previous_chat_status === "2" && chat_status === "3") || (previous_chat_status === "5" && chat_status === "3")) {
643
+ jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has opened the chat window","wplivechat"); ?></em><br />");
644
+ var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
645
+ jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
646
+
647
+ } else if (chat_status == "10" && previous_chat_status == "3") {
648
+ jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has minimized the chat window","wplivechat"); ?></em><br />");
649
+ var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
650
+ jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
651
+ }
652
+ else if(chat_status === "3" && previous_chat_status === "10"){
653
+ jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has maximized the chat window","wplivechat"); ?></em><br />");
654
+ var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
655
+ jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
656
+ }
657
+ else if (chat_status === "1" || chat_status === "8") {
658
+ jQuery("#admin_chat_box_area_"+cid).append("<em><?php _e("User has closed and ended the chat","wplivechat"); ?></em><br />");
659
+ var height = jQuery('#admin_chat_box_area_'+cid)[0].scrollHeight;
660
+ jQuery('#admin_chat_box_area_'+cid).scrollTop(height);
661
+ document.getElementById('wplc_admin_chatmsg').disabled = true;
662
+ }
663
+ }
664
+ }
665
+ }
666
+
667
+
668
+
669
+ jQuery(document).ready(function() {
670
+
671
+ var wplc_image = "<?php echo $image ?>";
672
+ var wplc_ajaxurl = '<?php echo plugins_url('/ajax.php', __FILE__); ?>';
673
+
674
+
675
+ jQuery("#wplc_admin_chatmsg").focus();
676
+
677
+
678
+
679
+
680
+ wplc_call_to_server_admin_chat(data);
681
+
682
+ if (jQuery('#wplc_admin_cid').length){
683
+ var wplc_cid = jQuery("#wplc_admin_cid").val();
684
+ var height = jQuery('#admin_chat_box_area_'+wplc_cid)[0].scrollHeight;
685
+ jQuery('#admin_chat_box_area_'+wplc_cid).scrollTop(height);
686
+ }
687
+
688
+ jQuery(".wplc_admin_accept").on("click", function() {
689
+ wplc_title_alerts3 = setTimeout(function (){ document.title = "WP Live Chat Support"; }, 2500);
690
+ var cid = jQuery(this).attr("cid");
691
+
692
+ var data = {
693
+ action: 'wplc_admin_accept_chat',
694
+ cid: cid,
695
+ security: '<?php echo $ajax_nonce; ?>'
696
+ };
697
+ jQuery.post(wplc_ajaxurl, data, function(response) {
698
+ //console.log("wplc_admin_accept_chat");
699
+ wplc_refresh_chat_boxes[cid] = setInterval(function (){wpcl_admin_update_chat_box(cid);}, 3000);
700
+ jQuery("#admin_chat_box_"+cid).show();
701
+ });
702
+ });
703
+
704
+ jQuery("#wplc_admin_chatmsg").keyup(function(event){
705
+ if(event.keyCode == 13){
706
+ jQuery("#wplc_admin_send_msg").click();
707
+ }
708
+ });
709
+
710
+ jQuery("#wplc_admin_close_chat").on("click", function() {
711
+ var wplc_cid = jQuery("#wplc_admin_cid").val();
712
+ var data = {
713
+ action: 'wplc_admin_close_chat',
714
+ security: '<?php echo $ajax_nonce; ?>',
715
+ cid: wplc_cid
716
+
717
+ };
718
+ jQuery.post(wplc_ajaxurl, data, function(response) {
719
+ //console.log("wplc_admin_close_chat");
720
+ //console.log(response);
721
+ window.close();
722
+ });
723
+
724
+ });
725
+
726
+ jQuery("#wplc_admin_send_msg").on("click", function() {
727
+ var wplc_cid = jQuery("#wplc_admin_cid").val();
728
+ var wplc_chat = jQuery("#wplc_admin_chatmsg").val();
729
+ var wplc_name = "a"+"d"+"m"+"i"+"n";
730
+ jQuery("#wplc_admin_chatmsg").val('');
731
+
732
+
733
+ jQuery("#admin_chat_box_area_"+wplc_cid).append("<span class='wplc-admin-message'>"+wplc_image+" <strong>"+wplc_name+"</strong>:<hr/>"+wplc_chat+"</span><br /><div class='wplc-clear-float-message'></div>");
734
+ var height = jQuery('#admin_chat_box_area_'+wplc_cid)[0].scrollHeight;
735
+ jQuery('#admin_chat_box_area_'+wplc_cid).scrollTop(height);
736
+
737
+
738
+ var data = {
739
+ action: 'wplc_admin_send_msg',
740
+ security: '<?php echo $ajax_nonce; ?>',
741
+ cid: wplc_cid,
742
+ msg: wplc_chat
743
+ };
744
+ jQuery.post(wplc_ajaxurl, data, function(response) {
745
+ //console.log("wplc_admin_send_msg");
746
+
747
+ /* do nothing
748
+ jQuery("#admin_chat_box_area_"+wplc_cid).html(response);
749
+ var height = jQuery('#admin_chat_box_area_'+wplc_cid)[0].scrollHeight;
750
+ jQuery('#admin_chat_box_area_'+wplc_cid).scrollTop(height);
751
+ */
752
+ });
753
+
754
+
755
+ });
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+ });
764
+ </script>
765
+ <?php
766
+
767
+ }
768
+ function wplc_activate() {
769
+ wplc_handle_db();
770
+ if (!get_option("WPLC_SETTINGS")) {
771
+ add_option('WPLC_SETTINGS',array("wplc_settings_align" => "2", "wplc_settings_enabled" => "1", "wplc_settings_fill" => "73BE28", "wplc_settings_font" => "FFFFFF"));
772
+ }
773
+ add_option("WPLC_HIDE_CHAT","true");
774
+ add_option("WPLC_FIRST_TIME", true);
775
+ }
776
+
777
+
778
+ function wplc_handle_db() {
779
+ global $wpdb;
780
+ global $wplc_version;
781
+ global $wplc_tblname_chats;
782
+ global $wplc_tblname_msgs;
783
+
784
+ $sql = "
785
+ CREATE TABLE ".$wplc_tblname_chats." (
786
+ id int(11) NOT NULL AUTO_INCREMENT,
787
+ timestamp datetime NOT NULL,
788
+ name varchar(700) NOT NULL,
789
+ email varchar(700) NOT NULL,
790
+ ip varchar(700) NOT NULL,
791
+ status int(11) NOT NULL,
792
+ url varchar(700) NOT NULL,
793
+ last_active_timestamp datetime NOT NULL,
794
+ PRIMARY KEY (id)
795
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
796
+ ";
797
+
798
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
799
+ dbDelta($sql);
800
+
801
+ $sql = "
802
+ CREATE TABLE ".$wplc_tblname_msgs." (
803
+ id int(11) NOT NULL AUTO_INCREMENT,
804
+ chat_sess_id int(11) NOT NULL,
805
+ from varchar(150) CHARACTER SET utf8 NOT NULL,
806
+ msg varchar(700) CHARACTER SET utf8 NOT NULL,
807
+ timestamp datetime NOT NULL,
808
+ status INT(3) NOT NULL,
809
+ originates INT(3) NOT NULL,
810
+ PRIMARY KEY (id)
811
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
812
+ ";
813
+
814
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
815
+ dbDelta($sql);
816
+ add_option("wplc_db_version", $wplc_version);
817
+ update_option("wplc_db_version",$wplc_version);
818
+ }
819
+
820
+ function wplc_add_user_stylesheet() {
821
+ wp_register_style( 'wplc-font-awesome', plugins_url('/css/font-awesome.min.css', __FILE__) );
822
+ wp_enqueue_style( 'wplc-font-awesome' );
823
+ wp_register_style( 'wplc-style', plugins_url('/css/wplcstyle.css', __FILE__) );
824
+ wp_enqueue_style( 'wplc-style' );
825
+
826
+ }
827
+ function wplc_add_admin_stylesheet() {
828
+ wp_register_style( 'wplc-admin-style', 'http://code.jquery.com/ui/1.8.24/themes/smoothness/jquery-ui.css' );
829
+ wp_enqueue_style( 'wplc-admin-style' );
830
+
831
+ }
832
+
833
+ if (isset($_GET['page']) && $_GET['page'] == 'wplivechat-menu-settings') {
834
+ add_action('admin_print_scripts', 'wplc_admin_scripts_basic');
835
+ }
836
+ function wplc_admin_scripts_basic() {
837
+
838
+ if ($_GET['page'] == "wplivechat-menu-settings") {
839
+ wp_enqueue_script( 'jquery' );
840
+ wp_enqueue_script('jquery-ui-core');
841
+
842
+ wp_register_script('my-wplc-color', plugins_url('js/jscolor.js',__FILE__), false, '1.4.1', false);
843
+ wp_enqueue_script('my-wplc-color');
844
+ wp_enqueue_script( 'jquery-ui-tabs');
845
+ wp_register_script('my-wplc-tabs', plugins_url('js/wplc_tabs.js',__FILE__), array('jquery-ui-core'), '', true);
846
+ wp_enqueue_script('my-wplc-tabs');
847
+ }
848
+ }
849
+
850
+
851
+ function wplc_admin_settings_layout() {
852
+ wplc_settings_page_basic();
853
+ }
854
+ function wplc_admin_history_layout() {
855
+ echo"<div class=\"wrap\"><div id=\"icon-edit\" class=\"icon32 icon32-posts-post\"><br></div><h2>".__("WP Live Chat History","wplivechat")."</h2>";
856
+ if (function_exists("wplc_register_pro_version")) {
857
+ wplc_pro_admin_display_history();
858
+ }
859
+ else {
860
+ echo "<br /><br >This option is only available in the <a href=\"http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=history1\" title=\"".__("Pro Add-on","wplivechat")."\" target=\"_BLANK\">Pro Add-on</a> of WP Live Chat. <a href=\"http://www.wp-livechat.com/purchase-pro/?utm_source=plugin&utm_medium=link&utm_campaign=history2\" title=\"".__("Pro Add-on","wplivechat")."\" target=\"_BLANK\">Get it now for only $29.95 once off!</a>";
861
+ }
862
+ }
863
+
864
+
865
+ function wplc_settings_page_basic() {
866
+ if(function_exists("wplc_register_pro_version")){
867
+ wplc_settings_page_pro();
868
+ } else {
869
+ include 'includes/settings_page.php';
870
+ }
871
+ }
872
+ function wplc_head_basic() {
873
+ global $wpdb;
874
+
875
+ if (isset($_POST['wplc_save_settings'])){
876
+
877
+ $wplc_data['wplc_settings_align'] = esc_attr($_POST['wplc_settings_align']);
878
+ $wplc_data['wplc_settings_fill'] = esc_attr($_POST['wplc_settings_fill']);
879
+ $wplc_data['wplc_settings_font'] = esc_attr($_POST['wplc_settings_font']);
880
+ $wplc_data['wplc_settings_enabled'] = esc_attr($_POST['wplc_settings_enabled']);
881
+ update_option('WPLC_SETTINGS', $wplc_data);
882
+ update_option("WPLC_HIDE_CHAT", $_POST['wplc_hide_chat']);
883
+ echo "<div class='updated'>";
884
+ _e("Your settings have been saved.","wplivechat");
885
+ echo "</div>";
886
+ }
887
+ if(isset($_POST['action']) && $_POST['action'] == "wplc_submit_find_us"){
888
+ if (function_exists('curl_version')) {
889
+ $request_url = "http://www.wp-livechat.com/apif/rec.php";
890
+ $ch = curl_init();
891
+ curl_setopt($ch, CURLOPT_URL, $request_url);
892
+ curl_setopt($ch, CURLOPT_POST, 1);
893
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
894
+ curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
895
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
896
+ $output = curl_exec($ch);
897
+ curl_close($ch);
898
+ }
899
+ echo "<div class=\"updated\"><p>". __("Thank You for your feedback!","wplivechat")."</p></div>";
900
+ }
901
+ if (isset($_POST['wplc_nl_send_feedback'])) {
902
+ if(wp_mail("nick@wp-livechat.com", "Plugin feedback", "Name: ".$_POST['wplc_nl_feedback_name']."\n\r"."Email: ".$_POST['wplc_nl_feedback_email']."\n\r"."Website: ".$_POST['wplc_nl_feedback_website']."\n\r"."Feedback:".$_POST['wplc_nl_feedback_feedback'] )){
903
+ echo "<div id=\"message\" class=\"updated\"><p>".__("Thank you for your feedback. We will be in touch soon","wplc")."</p></div>";
904
+ } else {
905
+
906
+ if (function_exists('curl_version')) {
907
+ $request_url = "http://www.wp-livechat.com/apif/rec_feedback.php";
908
+ $ch = curl_init();
909
+ curl_setopt($ch, CURLOPT_URL, $request_url);
910
+ curl_setopt($ch, CURLOPT_POST, 1);
911
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
912
+ curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
913
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
914
+ $output = curl_exec($ch);
915
+ curl_close($ch);
916
+ echo "<div id=\"message\" class=\"updated\"><p>".__("Thank you for your feedback. We will be in touch soon","wplc")."</p></div>";
917
+ }
918
+ else {
919
+ echo "<div id=\"message\" class=\"error\">";
920
+ echo "<p>".__("There was a problem sending your feedback. Please log your feedback on ","wplc")."<a href='http://wp-livechat.com/forums/forum/support/' target='_BLANK'>http://wp-livechat.com/forums/forum/support/</a></p>";
921
+ echo "</div>";
922
+ }
923
+ }
924
+ }
925
+
926
+ }
927
+
928
+ function wplc_logout() {
929
+ delete_transient('wplc_is_admin_logged_in');
930
+ }
931
+ add_action('wp_logout', 'wplc_logout');
932
+
933
+
934
+ function wplc_get_home_path() {
935
+ $home = get_option( 'home' );
936
+ $siteurl = get_option( 'siteurl' );
937
+ if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
938
+ $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
939
+ $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
940
+ $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
941
+ $home_path = trailingslashit( $home_path );
942
+ } else {
943
+ $home_path = ABSPATH;
944
+ }
945
+
946
+ return str_replace( '\\', '/', $home_path );
947
+ }
948
+