PluginProbe
Live Chat & AI Chatbot – onWebChat / 3.3.0
Live Chat & AI Chatbot – onWebChat v3.3.0
3.9.2 3.9.3 3.9.1 3.9.0 3.8.4 3.8.2 3.8.1 3.8.0 3.7.2 3.7.1 3.7.0 3.6.0 3.5.5 trunk 1.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 48 releases
onwebchat / onwebchat.php

onwebchat.php in Live Chat & AI Chatbot – onWebChat 3.3.0, at onwebchat.php

572 lines 21.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: onWebChat Live Chat
4 Plugin URI: https://www.onwebchat.com/wordpress-live-chat-plugin.php
5 Description: live chat service that helps you communicate with your website's visitors.
6 Author: onWebChat
7 Version: 3.3.0
8 Author URI: https://www.onwebchat.com
9 */
10
11
12 /* ---------------------------------------------------- *
13 * Create Settings Page
14 * ---------------------------------------------------- */
15
16
17 define('ONWEBCHAT_SMALL_LOGO', plugins_url( 'images/onwebchat-logo.gif' , __FILE__ ));
18 define('ONWEBCHAT_SERVER_URL','https://www.onwebchat.com/get-chatid.php');
19
20
21 // add styles
22 add_action( 'admin_enqueue_scripts', 'register_plugin_styles' );
23
24 // call function on hook admin_menu
25 add_action('admin_menu','onwebchat_setup_menu');
26
27 // create login error notice
28 add_action( 'admin_notices', 'onwebchat_login_error' );
29
30 // define the settings
31 add_action('admin_init','onwebchat_register_setttings');
32
33
34 /* ---------------------------------------------------- *
35 * Display onWebChat on footer
36 * ---------------------------------------------------- */
37
38 // add widget plugin to the footer
39 add_action('wp_footer', 'onwebchat_add_script_at_footer');
40
41
42 /* ----------------------------------------------------- *
43 * Admin Page registration
44 * ----------------------------------------------------- */
45
46 function onwebchat_setup_menu() {
47 add_menu_page( 'onWebChat Settings', 'onWebChat', 'administrator', 'onwebchat_settings', 'onwebchat_init_menu_page', ONWEBCHAT_SMALL_LOGO);
48 }
49
50
51 /* ------------------------------------------------------ *
52 * Admin Page Display Function
53 * ------------------------------------------------------ */
54
55 function onwebchat_init_menu_page() {
56
57
58 $options = get_option('onwebchat_plugin_option');
59 $chatId = $options['text_string'];
60
61 $isConnected = false;
62 if($chatId !="") {
63 $isConnected = true;
64 }
65
66 $isSecondPage = false;
67
68
69 /*****************************************************************
70 * Ask server for chatId
71 *****************************************************************/
72 if ( isset( $_POST["action"] ) && $_POST["action"] == "login" ) {
73
74
75 // the following lines are added to verify a correct security nonce(token) by using "wp_verify_nonce()"
76 if (! isset($_POST['_wpnonce'])
77 || ! wp_verify_nonce( $_POST['_wpnonce'], 'on_web_chat_nonce')){
78 print 'Sorry, your nonce did not verify.';
79 exit;
80 }
81
82 $options = get_option('onwebchat_plugin_option');
83 $chatId = $options['text_string'];
84 //****************************
85
86 // get username, password and chatId
87 $userName = $_POST["onWebChatUser"];
88
89 if(isset($_POST["onWebChatPass"])) {
90 $userPass = $_POST["onWebChatPass"];
91 }
92
93 $chatId = $_POST["chatId"];
94
95
96 if( isset($_POST["pages-select"])) {
97 $pagesSelect = $_POST["pages-select"];
98 }
99
100 if( isset($_POST["showonpages"])) {
101 $showOnPages = $_POST["showonpages"];
102 }
103
104 if(isset($_POST["hideonpages"])) {
105 $hideOnPages = $_POST["hideonpages"];
106 }
107
108 if(isset($_POST["onwebchat-api"])) {
109 $onwebchatApi = $_POST["onwebchat-api"];
110 }
111
112
113 if(isChatIdValid($chatId)) {
114
115 if ( isset($_POST["isSecondPage"])){
116 $isSecondPage = $_POST["isSecondPage"];
117 }
118
119 //----------- update chatId option ------------
120 $my_options = get_option('onwebchat_plugin_option');
121
122 $my_options['text_string'] = $chatId;
123
124 //Update entire array
125 update_option('onwebchat_plugin_option', $my_options);
126 //-----------------------------------------------
127
128 // remove user email from db
129 if(!$isSecondPage) {
130 update_option( 'onwebchat_plugin_option_user', '');
131 update_option( 'onwebchat_plugin_option_pages_select', 1);
132
133 } else {
134
135 update_option( 'onwebchat_plugin_option_pages_select', $pagesSelect);
136
137 if ($pagesSelect==2){
138 update_option( 'onwebchat_plugin_option_show_pages', $showOnPages);
139 } else if ($pagesSelect==3){
140 update_option( 'onwebchat_plugin_option_hide_pages', $hideOnPages);
141 }
142
143 //TODO update textarea
144 update_option( 'onwebchat_plugin_option_api_code', $onwebchatApi);
145 }
146
147 // move to next page
148 print('<script>window.location.href="admin.php?page=onwebchat_settings"</script>');
149
150 } else {
151
152 // save username at options
153 update_option( 'onwebchat_plugin_option_user', $userName );
154
155 // ask server for chatId
156 $response = wp_remote_post(ONWEBCHAT_SERVER_URL, array(
157 'method' => 'POST',
158 'timeout' => 45,
159 'redirection' => 5,
160 'httpversion' => '1.0',
161 'blocking' => true,
162 'headers' => array(),
163 'body' => array( 'email' => $userName, 'pass' => $userPass ),
164 'cookies' => array()
165 ));
166
167
168
169
170 if ( is_wp_error( $response ) ) {
171 $error_message = $response->get_error_message();
172
173
174 } else {
175
176
177 // If no chatId returned
178 if($response['body'] == '') {
179 // display an error for wrong credentials
180 onwebchat_login_error(true);
181
182 } else {
183
184 //----------- update chatId
185 $my_options = get_option('onwebchat_plugin_option');
186
187 $my_options['text_string'] = $response['body'];
188
189 update_option('onwebchat_plugin_option', $my_options);
190 update_option( 'onwebchat_plugin_option_pages_select', 1);
191 //--------------------------------------------
192
193 // move to next page
194 print('<script>window.location.href="admin.php?page=onwebchat_settings"</script>');
195 }
196 }
197 }
198
199 $m_option_hide = false;
200 if(isset($_POST['onwebchat_plugin_option_hide'])) {
201 $m_option_hide = $_POST['onwebchat_plugin_option_hide'];
202 }
203
204 update_option('onwebchat_plugin_option_hide', $m_option_hide); //an einai stin proti selida tote to kanei keno (opote by default den einai epilegmeno)
205
206 }
207
208 //********************************************************************
209
210
211 /*********************************************************************
212 * Disconnect account
213 *********************************************************************/
214 if( isset($_GET["action"]) && $_GET["action"] == "deactivate" && $isConnected) {
215 $isConnected = false;
216
217 $my_options = get_option('onwebchat_plugin_option');
218
219 $my_options['text_string'] = '';
220
221 update_option('onwebchat_plugin_option', $my_options);
222 update_option( 'onwebchat_plugin_option_pages_select', 1);
223
224 $chatIdOption = get_option('onwebchat_plugin_option');
225 $chatId = $chatIdOption['text_string'];
226
227 print('<script>window.location.href="admin.php?page=onwebchat_settings"</script>');
228
229 }
230 //***********************************************************************
231
232
233
234 ?>
235 <div>
236
237
238
239
240 <h1 style="font-weight: 400;margin-top:34px">onWebChat <?php ($isConnected == true) ? print 'Settings' : print 'Activation'; ?> </h1>
241
242 <form action="admin.php?page=onwebchat_settings" method="post">
243 <input type="hidden" name="action" value="login">
244 <?php
245
246 //create nonce(token)
247 wp_nonce_field('on_web_chat_nonce');
248
249 // Login Page
250 if($isConnected != true) {
251
252 $chatId = get_option( 'onwebchat_plugin_option' );
253 $chatId = $chatId['text_string'];
254 ?>
255
256 <hr class="small-hr2">
257
258 <h3 class="header-1">Connect with your onWebChat account</h3>
259
260
261
262 <div class="username-div">
263 <!-- sanitize user-provided parameter -->
264 <strong>Email: </strong><input class="username-text-field" type="text" name="onWebChatUser" value="<?php echo esc_attr(get_option( 'onwebchat_plugin_option_user' )); ?>"/>
265 </div>
266
267 <div class="password-div">
268 <strong>Password: </strong><input class="password-text-field" type="password" name="onWebChatPass" value="<?php echo get_option( 'onWebChatPass' ); ?>"/>
269 </div>
270
271
272 <div style="width: 560px; height: 10px; border-bottom: 1px solid #bfbfbf; text-align: center; margin-top:30px">
273 <span class="header-or" style="color:#656565;font-size: 21px; background-color: #f1f1f1; padding: 0 10px;">
274
275 OR
276
277 </span>
278 </div>
279
280
281 <h3 class="header-2">Paste your onWebChat Chat Id</h3>
282 <div class="password-div">
283 <strong>Chat Id:</strong> <input class="chatid-text-field" type="text" name="chatId" value="<?php echo $chatId; ?>"/>
284 </div>
285
286 <hr class="small-hr2">
287
288 <div class="new-account-link">
289 Create your account with onWebChat live chat service if you haven't yet, by clicking <a href="https://www.onwebchat.com/signup.php" target="_blank">here</a>
290 </div>
291
292 <?php
293
294 $html = '<input class="button button-primary" style="margin-left: 230px;" type="submit" value="Activate"/>';
295 echo $html;
296 }
297
298 // 2nd Page
299 else {
300 $options = get_option('onwebchat_plugin_option_user');
301
302 // display user email
303 if($options!=''){
304 //sanitize user-provided parameter
305 $email = esc_html($options);
306 $html = '<br><h3 class="header-1-p2">Activated for onWebChat account: </h3>';
307 $html .= "<strong class='account-id'>$email</strong> ";
308 }
309
310 // display chatId
311 else {
312 $chatId = get_option( 'onwebchat_plugin_option' );
313 $chatId = $chatId['text_string'];
314 $html = '<br><h3 class="header-1-p2">Activated for onWebChat Chat Id: </h3>';
315 $html .= "<strong class='account-id'>$chatId</strong> ";
316 }
317 $html .= ' <a href="admin.php?page=onwebchat_settings&amp;action=deactivate">Deactivate</a>';
318 //$html .= ' <div class="admin-login-info"> <span>*</span> To connect to onWebChat Operator Console click <a target="_blank" href="https://www.onwebchat.com/login.php">here</a> </div>';
319 echo $html;
320
321 $options = get_option('onwebchat_plugin_option_hide');
322
323 $chatId = get_option( 'onwebchat_plugin_option' );
324 $chatId = $chatId['text_string'];
325
326 // get correct value
327 $onwebchatApi = get_option('onwebchat_plugin_option_api_code');
328 $onwebchatApi = str_replace('\\','',$onwebchatApi);
329 ?>
330
331
332 <br><br><br>
333
334 <div class="hide-div">
335 <select id="pages-select" name="pages-select" onchange="onwc_select_change()">
336 <option value="1" <?php selected( get_option('onwebchat_plugin_option_pages_select'), 1 ); ?>>Show chat widget on all pages</option>
337 <option value="2" <?php selected( get_option('onwebchat_plugin_option_pages_select'), 2 ); ?>>Show on the following pages:</option>
338 <option value="3" <?php selected( get_option('onwebchat_plugin_option_pages_select'), 3 ); ?>>Hide on the following pages:</option>
339 <option value="4" <?php selected( get_option('onwebchat_plugin_option_pages_select'), 4 ); ?>>Hide chat widget from all pages</option>
340 </select>
341 </div>
342
343 <div id="onwc_show_on_pages_div" style="display:none">
344 <input id="showonpages" name="showonpages" class="showhidepages" type="text" value="<?php echo esc_attr(get_option( 'onwebchat_plugin_option_show_pages' )); ?>" /><a href="#" style="text-decoration: none;" onmouseover="document.getElementById('help').style.visibility = 'visible'"; ONMOUSEOUT="document.getElementById('help').style.visibility = 'hidden'"><strong><font size="4" face="Arial"> ? </font></strong></a>
345 </div>
346 <div id="onwc_hide_on_pages_div" style="display:none">
347 <input id="hideonpages" name="hideonpages" class="showhidepages" type="text" value="<?php echo esc_attr(get_option( 'onwebchat_plugin_option_hide_pages' )); ?>" /><a href="#" style="text-decoration: none;" onmouseover="document.getElementById('help').style.visibility = 'visible'"; ONMOUSEOUT="document.getElementById('help').style.visibility = 'hidden'"><strong><font size="4" face="Arial"> ? </font></strong></a>
348 </div>
349
350 <div id="help">
351 <span>Add multiple pages by separating them with a space. Feel free to include either a section of the page or the entire URL. e.g. &nbsp; index price contact.php blog/</span>
352 </div>
353
354 <br>
355 <h3 class="header-1-p2">Enter Your Custom onWebChat JavaScript API Code Below</h3>
356 <div class="chatid-div">
357 <strong>onWebChat API:</strong>
358 <br>
359 <!-- sanitize user-provided parameter -->
360 <textarea class="chatid-text-field" style="margin-left: 0px;" rows="10" name="onwebchat-api"><?php echo esc_html($onwebchatApi); ?></textarea>
361 <br>
362 <br>
363 </div>
364
365 <div>
366 <br /><br />
367 </div>
368
369 <!-- hiden fields -->
370 <input class="chatid-text-field-hide" type="text" name="chatId" value="<?php echo esc_attr($chatId); ?>"/>
371 <input class="chatid-text-field-hide" type="text" name="onWebChatUser" value="<?php echo esc_attr(get_option( 'onwebchat_plugin_option_user' )); ?>"/>
372 <input class="chatid-text-field-hide" type="text" name="isSecondPage" value="1"/>
373
374 <div class="new-account-link">Click <a target="_blank" href="https://www.onwebchat.com/login.php">here</a> to access the onWebChat Operator Console </div>
375
376 <?php
377 // Display the Save Button
378 $html = '<input class="button button-primary" style="margin-left: 230px;" type="submit" value="Save Changes"/>';
379 echo $html;
380
381 }
382
383
384 ?>
385 </form>
386 </div>
387
388 <script type="text/javascript">
389
390
391 function onwc_select_change() {
392 var e = document.getElementById("pages-select");
393 if (!e) {
394 console.warn("Select element not found");
395 return;
396 }
397 var selected = e.options[e.selectedIndex].value;
398 if (selected == 1){
399 document.getElementById("onwc_show_on_pages_div").style.display = "none";
400 document.getElementById("onwc_hide_on_pages_div").style.display = "none";
401 } else if (selected == 2){
402 document.getElementById("onwc_show_on_pages_div").style.display = "block";
403 document.getElementById("onwc_hide_on_pages_div").style.display = "none";
404 } else if (selected == 3){
405 document.getElementById("onwc_show_on_pages_div").style.display = "none";
406 document.getElementById("onwc_hide_on_pages_div").style.display = "block";
407 } else if (selected == 4){
408 document.getElementById("onwc_show_on_pages_div").style.display = "none";
409 document.getElementById("onwc_hide_on_pages_div").style.display = "none";
410 }
411
412 }
413 document.addEventListener('DOMContentLoaded', function() {
414 onwc_select_change();
415 }, false);
416 </script>
417 <?php
418 }
419
420
421 /* ----------------------------------------------------- *
422 * Admin Page Styles Registration
423 * ----------------------------------------------------- */
424
425 function register_plugin_styles() {
426 wp_register_style( 'onwebchat', plugins_url( 'onwebchat/css/onwebchat.css' ) );
427 wp_enqueue_style( 'onwebchat' );
428 }
429
430
431 /* ----------------------------------------------------- *
432 * Tabs Settings Registration
433 * ----------------------------------------------------- */
434
435 function onwebchat_register_setttings() {
436
437 /******************** Account Tab ************************/
438 //* register the Chat Id
439 register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option');
440
441 //* register the username
442 register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option_user');
443
444 //* register the hide (checkbox)
445 register_setting( 'onwebchat_plugin_option_checkbox', 'onwebchat_plugin_option_hide');
446
447 //TODO api code
448 //* register the api code
449 register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option_api_code');
450 }
451
452
453 /* ----------------------------------------------------- *
454 * onWebChat Display Function
455 * ----------------------------------------------------- */
456
457 // print chat widget code
458 function onwebchat_add_script_at_footer() {
459
460 $options = get_option('onwebchat_plugin_option');
461 $chatId = $options['text_string'];
462 //$hideWidget = get_option('onwebchat_plugin_option_hide');
463 $hideWidget = false;
464
465 $widgetCode = "<script type='text/javascript'>var onWebChat={ar:[], set: function(a,b){if (typeof onWebChat_==='undefined'){this.ar.push([a,b]);}else{onWebChat_.set(a,b);}},get:function(a){return(onWebChat_.get(a));},w:(function(){ var ga=document.createElement('script'); ga.type = 'text/javascript';ga.async=1;ga.src='//www.onwebchat.com/clientchat/$chatId';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})()}</script>";
466
467 $apiCode = get_option('onwebchat_plugin_option_api_code');
468
469 $apiCode = str_replace('\\','',$apiCode);
470
471 $apiCode = "<script type='text/javascript'>$apiCode</script>";
472
473 $widgetCode .= $apiCode;
474
475
476 //check if user is logged if yes get username, email
477 if ( is_user_logged_in() ) {
478
479 global $current_user;
480 get_currentuserinfo();
481
482 // get user name
483 $onwebchat_user = $current_user->user_login;
484
485 // get user email
486 $onwebchat_email = $current_user->user_email;
487
488 //add api info
489 if ($onwebchat_user != null && $onwebchat_user != "" && $onwebchat_user != "guest" && $onwebchat_user != "Guest") {
490 if ($onwebchat_email != null && $onwebchat_email != ""){
491 $widgetCode = $widgetCode."<script type='text/javascript'>onWebChat.set('name','$onwebchat_user');
492 onWebChat.set('email','$onwebchat_email'); </script>";
493 } else {
494 $widgetCode = $widgetCode."<script type='text/javascript'>onWebChat.set('name','$onwebchat_user');</script>";
495 }
496 }
497 }
498
499 $currentPage = substr( strtolower($_SERVER['SERVER_PROTOCOL']), 0, strpos( strtolower($_SERVER['SERVER_PROTOCOL']), "/") );
500 $currentPage .= ( empty($_SERVER['HTTPS']) ? NULL : ( ($_SERVER['HTTPS'] == "on") ? "s" : NULL) );
501 $currentPage .= "://" . $_SERVER['SERVER_NAME'];
502 $currentPage .= ( $_SERVER['SERVER_PORT'] == 80 ? "" : ":".$_SERVER['SERVER_PORT'] );
503 $currentPage .= $_SERVER['REQUEST_URI'];
504
505 $pagesSelect = get_option('onwebchat_plugin_option_pages_select');
506 $showPages = get_option('onwebchat_plugin_option_show_pages');
507 $showPages = explode(' ', $showPages);
508 $hidePages = get_option('onwebchat_plugin_option_hide_pages');
509 $hidePages = explode(' ', $hidePages);
510
511 $showSelect=true;
512 if ($pagesSelect==1){
513
514 } else if ($pagesSelect==2){
515 $showSelect=false;
516 foreach ($showPages as $page){
517 if ($page !== "") {
518 if (strpos($currentPage, $page) !== false) {
519 $showSelect = true;
520 }
521 }
522 }
523 } else if ($pagesSelect==3){
524 $showSelect=true;
525 foreach ($hidePages as $page){
526 if ($page !== "") {
527 if (strpos($currentPage, $page) !== false) {
528 $showSelect = false;
529 }
530 }
531 }
532 } else if($pagesSelect == 4) {
533 //hide chat widget from all pages
534 $hideWidget = true;
535 }
536
537 if(!$hideWidget && $showSelect) {
538 echo $widgetCode;
539 }
540
541 }
542
543 /************************************************************************
544 * display error function
545 ***********************************************************************/
546 function onwebchat_login_error($contition = false) {
547
548
549
550 if($contition) {
551 ?>
552
553 <div class="error">
554 <p><strong>Invalid Credentials!</strong> Ensure you enter the correct email and password, <strong>OR</strong> provide a valid Chat ID</p>
555 </div>
556 <?php
557 }
558 else {
559 //display nothing
560 }
561 }
562
563 /************************************************************************
564 * Validate Chat Id function
565 ***********************************************************************/
566 function isChatIdValid($input) {
567 return preg_match('/^[a-f0-9]{32,40}+[\\/]?+[0-9]{0,2}+[\\/]?+[0-9]{0,2}$/i', $input);
568 }
569
570 ?>
571
572