PluginProbe
Live Chat & AI Chatbot – onWebChat / 3.4.0
Live Chat & AI Chatbot – onWebChat v3.4.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.4.0, at onwebchat.php

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