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

460 lines 15.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/wp_plugin.php
5 Description: onWebChat is a live chat system, that helps you communicate with your website's visitors.
6 Author: onWebChat
7 Version: 3.0.3
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.png' , __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
67 /*****************************************************************
68 * Ask server for chatId
69 *****************************************************************/
70 if ( isset( $_POST["action"] ) && $_POST["action"] == "login" ) {
71
72 $options = get_option('onwebchat_plugin_option');
73 $chatId = $options['text_string'];
74 //****************************
75
76 // get username, password and chatId
77 $userName = $_POST["onWebChatUser"];
78 $userPass = $_POST["onWebChatPass"];
79 $chatId = $_POST["chatId"];
80 $isSecondPage = $_POST["isSecondPage"];
81
82 $pagesSelect = $_POST["pages-select"];
83 $showOnPages = $_POST["showonpages"];
84 $hideOnPages = $_POST["hideonpages"];
85
86 if(isChatIdValid($chatId)) {
87
88 //----------- update chatId option ------------
89 $my_options = get_option('onwebchat_plugin_option');
90
91 $my_options['text_string'] = $chatId;
92
93 //Update entire array
94 update_option('onwebchat_plugin_option', $my_options);
95 //-----------------------------------------------
96
97 // remove user email from db
98 if(!$isSecondPage) {
99 update_option( 'onwebchat_plugin_option_user', '');
100 update_option( 'onwebchat_plugin_option_pages_select', 1);
101
102 } else {
103
104 update_option( 'onwebchat_plugin_option_pages_select', $pagesSelect);
105
106 if ($pagesSelect==2){
107 update_option( 'onwebchat_plugin_option_show_pages', $showOnPages);
108 } else if ($pagesSelect==3){
109 update_option( 'onwebchat_plugin_option_hide_pages', $hideOnPages);
110 }
111
112 }
113
114 // move to next page
115 print('<script>window.location.href="admin.php?page=onwebchat_settings"</script>');
116
117 } else {
118
119 // save username at options
120 update_option( 'onwebchat_plugin_option_user', $userName );
121
122 // ask server for chatId
123 $response = wp_remote_post(ONWEBCHAT_SERVER_URL, array(
124 'method' => 'POST',
125 'timeout' => 45,
126 'redirection' => 5,
127 'httpversion' => '1.0',
128 'blocking' => true,
129 'headers' => array(),
130 'body' => array( 'email' => $userName, 'pass' => $userPass ),
131 'cookies' => array()
132 ));
133
134 if ( is_wp_error( $response ) ) {
135 $error_message = $response->get_error_message();
136
137 } else {
138 // If no chatId returned
139 if($response['body'] == '-1') {
140 // display an error for wrong credentials
141 onwebchat_login_error(true);
142
143 } else {
144
145 //----------- update chatId
146 $my_options = get_option('onwebchat_plugin_option');
147
148 $my_options['text_string'] = $response['body'];
149
150 update_option('onwebchat_plugin_option', $my_options);
151 update_option( 'onwebchat_plugin_option_pages_select', 1);
152 //--------------------------------------------
153
154 // move to next page
155 print('<script>window.location.href="admin.php?page=onwebchat_settings"</script>');
156 }
157 }
158 }
159
160 update_option('onwebchat_plugin_option_hide', $_POST['onwebchat_plugin_option_hide']); //an einai stin proti selida tote to kanei keno (opote by default den einai epilegmeno)
161 }
162
163 //********************************************************************
164
165
166 /*********************************************************************
167 * Disconnect account
168 *********************************************************************/
169 if( isset($_GET["action"]) && $_GET["action"] == "deactivate" && $isConnected) {
170 $isConnected = false;
171
172 $my_options = get_option('onwebchat_plugin_option');
173
174 $my_options['text_string'] = '';
175
176 update_option('onwebchat_plugin_option', $my_options);
177 update_option( 'onwebchat_plugin_option_pages_select', 1);
178
179 $chatIdOption = get_option('onwebchat_plugin_option');
180 $chatId = $chatIdOption['text_string'];
181
182 print('<script>window.location.href="admin.php?page=onwebchat_settings"</script>');
183
184 }
185 //***********************************************************************
186
187
188
189 ?>
190 <div>
191 <h2 style="font-size:22px; color:#59808c">onWebChat <?php ($isConnected == true) ? print 'Settings' : print 'Activation'; ?> </h2>
192
193 <form action="admin.php?page=onwebchat_settings" method="post">
194 <input type="hidden" name="action" value="login">
195 <?php
196
197 // Login Page
198 if($isConnected != true) {
199
200 $chatId = get_option( 'onwebchat_plugin_option' );
201 $chatId = $chatId['text_string'];
202 ?>
203
204 <hr class="small-hr2">
205
206 <h3 class="header-1">Connect with your onWebChat account</h3>
207
208
209
210 <div class="username-div">
211 <strong>Email: </strong><input class="username-text-field" type="text" name="onWebChatUser" value="<?php echo get_option( 'onwebchat_plugin_option_user' ); ?>"/>
212 </div>
213 <div class="password-div">
214 <strong>Password: </strong><input class="password-text-field" type="password" name="onWebChatPass" value="<?php echo get_option( 'onWebChatPass' ); ?>"/>
215 </div>
216
217 <div style="width: 560px; height: 10px; border-bottom: 1px solid #bfbfbf; text-align: center; margin-top:30px">
218 <span class="header-or" style="font-size: 23px; background-color: #f1f1f1; padding: 0 10px;">
219 OR
220 </span>
221 </div>
222
223
224 <h3 class="header-2">Paste your onWebChat Chat Id</h3>
225 <div class="chatid-div">
226 <strong>Chat Id:</strong> <input class="chatid-text-field" type="text" name="chatId" value="<?php echo $chatId; ?>"/>
227 </div>
228
229 <hr class="small-hr2">
230
231 <div class="new-account-link">
232 <span class="info-star">*</span> If you don't have an account on onWebChat live chat service, you should create one <a href="https://www.onwebchat.com/signup.php" target="_blank">here</a>
233 </div>
234
235
236 <?php
237 }
238
239 // 2nd Page
240 else {
241 $options = get_option('onwebchat_plugin_option_user');
242
243 // display user email
244 if($options!=''){
245 $html = '<br><h3 class="header-1-p2">Activated for onWebChat account: </h3>';
246 $html .= "<strong class='account-id'>$options</strong> ";
247 }
248
249 // display chatId
250 else {
251 $chatId = get_option( 'onwebchat_plugin_option' );
252 $chatId = $chatId['text_string'];
253 $html = '<br><h3 class="header-1-p2">Activated for onWebChat Chat Id: </h3>';
254 $html .= "<strong class='account-id'>$chatId</strong> ";
255 }
256 $html .= ' <a href="admin.php?page=onwebchat_settings&amp;action=deactivate">Deactivate</a>';
257 $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>';
258 echo $html;
259
260 $options = get_option('onwebchat_plugin_option_hide');
261
262 $chatId = get_option( 'onwebchat_plugin_option' );
263 $chatId = $chatId['text_string'];
264
265 ?>
266 <div class="hide-div">
267 <strong>Hide Chat Widget:</strong> <input type="checkbox" id="plugin_text_checkbox" name="onwebchat_plugin_option_hide" value="1" <?php checked( $options, 1 ); ?> />
268 </div>
269
270 <div class="hide-div">
271 <select id="pages-select" name="pages-select" onchange="onwc_select_change()">
272 <option value="1" <?php selected( get_option('onwebchat_plugin_option_pages_select'), 1 ); ?>>Show chat widget on all pages</option>
273 <option value="2" <?php selected( get_option('onwebchat_plugin_option_pages_select'), 2 ); ?>>Show on the following pages:</option>
274 <option value="3" <?php selected( get_option('onwebchat_plugin_option_pages_select'), 3 ); ?>>Hide on the following pages:</option>
275 </select>
276 </div>
277
278 <div id="onwc_show_on_pages_div" style="display:none">
279 <input id="showonpages" name="showonpages" class="showhidepages" type="text" value="<?php echo 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>
280 </div>
281 <div id="onwc_hide_on_pages_div" style="display:none">
282 <input id="hideonpages" name="hideonpages" class="showhidepages" type="text" value="<?php echo 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>
283 </div>
284
285 <div id="help">
286 <span>You can insert multiple pages seperated by space. You can insert a part of the page or URL. e.g. &nbsp; index pric contact.php blog/</span>
287 </div>
288
289 <div>
290 <br /><br />
291 </div>
292
293 <!-- hiden fields -->
294 <input class="chatid-text-field-hide" type="text" name="chatId" value="<?php echo $chatId; ?>"/>
295 <input class="chatid-text-field-hide" type="text" name="onWebChatUser" value="<?php echo get_option( 'onwebchat_plugin_option_user' ); ?>"/>
296 <input class="chatid-text-field-hide" type="text" name="isSecondPage" value="1"/>
297 <?php
298 }
299
300 // Display the Save Button
301 $html = '<input class="button button-primary" style="margin-left: 230px;" type="submit" value="Save Changes"/>';
302 echo $html;
303 ?>
304 </form>
305 </div>
306
307 <script type="text/javascript">
308
309
310 function onwc_select_change() {
311 var e = document.getElementById("pages-select");
312 var selected = e.options[e.selectedIndex].value;
313 if (selected==1){
314 document.getElementById("onwc_show_on_pages_div").style.display = "none";
315 document.getElementById("onwc_hide_on_pages_div").style.display = "none";
316 } else if (selected==2){
317 document.getElementById("onwc_show_on_pages_div").style.display = "block";
318 document.getElementById("onwc_hide_on_pages_div").style.display = "none";
319 } else if (selected==3){
320 document.getElementById("onwc_show_on_pages_div").style.display = "none";
321 document.getElementById("onwc_hide_on_pages_div").style.display = "block";
322 }
323
324 }
325 document.addEventListener('DOMContentLoaded', function() {
326 onwc_select_change();
327 }, false);
328 </script>
329 <?php
330 }
331
332
333 /* ----------------------------------------------------- *
334 * Admin Page Styles Registration
335 * ----------------------------------------------------- */
336
337 function register_plugin_styles() {
338 wp_register_style( 'onwebchat', plugins_url( 'onwebchat/css/onwebchat.css' ) );
339 wp_enqueue_style( 'onwebchat' );
340 }
341
342
343 /* ----------------------------------------------------- *
344 * Tabs Settings Registration
345 * ----------------------------------------------------- */
346
347 function onwebchat_register_setttings() {
348
349 /******************** Account Tab ************************/
350 //* register the Chat Id
351 register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option');
352
353 //* register the username
354 register_setting( 'onwebchat_plugin_option', 'onwebchat_plugin_option_user');
355
356 //* register the hide (checkbox)
357 register_setting( 'onwebchat_plugin_option_checkbox', 'onwebchat_plugin_option_hide');
358 }
359
360
361 /* ----------------------------------------------------- *
362 * onWebChat Display Function
363 * ----------------------------------------------------- */
364
365 // print chat widget code
366 function onwebchat_add_script_at_footer() {
367
368 $options = get_option('onwebchat_plugin_option');
369 $chatId = $options['text_string'];
370 $hideWidget = get_option('onwebchat_plugin_option_hide');
371
372 $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>";
373
374 $apiCode = get_option('onwebchat_plugin_option_api');
375
376 $widgetCode .= $apiCode;
377
378
379 //check if user is logged if yes get username, email
380 if ( is_user_logged_in() ) {
381
382 global $current_user;
383 get_currentuserinfo();
384
385 // get user name
386 $onwebchat_user = $current_user->user_login;
387
388 // get user email
389 $onwebchat_email = $current_user->user_email;
390
391 //add api info
392 $widgetCode = $widgetCode."<script type='text/javascript'>onWebChat.set('name','$onwebchat_user');onWebChat.set('email','$onwebchat_email'); </script>";
393 }
394
395 $currentPage = substr( strtolower($_SERVER['SERVER_PROTOCOL']), 0, strpos( strtolower($_SERVER['SERVER_PROTOCOL']), "/") );
396 $currentPage .= ( empty($_SERVER['HTTPS']) ? NULL : ( ($_SERVER['HTTPS'] == "on") ? "s" : NULL) );
397 $currentPage .= "://" . $_SERVER['SERVER_NAME'];
398 $currentPage .= ( $_SERVER['SERVER_PORT'] == 80 ? "" : ":".$_SERVER['SERVER_PORT'] );
399 $currentPage .= $_SERVER['REQUEST_URI'];
400
401 $pagesSelect = get_option('onwebchat_plugin_option_pages_select');
402 $showPages = get_option('onwebchat_plugin_option_show_pages');
403 $showPages = explode(' ', $showPages);
404 $hidePages = get_option('onwebchat_plugin_option_hide_pages');
405 $hidePages = explode(' ', $hidePages);
406
407 $showSelect=true;
408 if ($pagesSelect==1){
409
410 } else if ($pagesSelect==2){
411 $showSelect=false;
412 foreach ($showPages as $page){
413 if ($page !== "") {
414 if (strpos($currentPage, $page) !== false) {
415 $showSelect = true;
416 }
417 }
418 }
419 } else if ($pagesSelect==3){
420 $showSelect=true;
421 foreach ($hidePages as $page){
422 if ($page !== "") {
423 if (strpos($currentPage, $page) !== false) {
424 $showSelect = false;
425 }
426 }
427 }
428 }
429
430 if(!$hideWidget && $showSelect) {
431 echo $widgetCode;
432 }
433
434 }
435
436 /************************************************************************
437 * display error function
438 ***********************************************************************/
439 function onwebchat_login_error($contition = false) {
440 if($contition) {
441 ?>
442 <div class="error">
443 <p><strong>Wrong credentials!</strong> Please enter correct <u>email and password</u> <strong>OR</strong> a valid <u>Chat Id</u>.</p>
444 </div>
445 <?php
446 }
447 else {
448 //display nothing
449 }
450 }
451
452 /************************************************************************
453 * Validate Chat Id function
454 ***********************************************************************/
455 function isChatIdValid($input) {
456 return preg_match('/^[a-f0-9]{32,40}+[\\/]?+[0-9]{0,2}+[\\/]?+[0-9]{0,2}$/i', $input);
457 }
458
459 ?>
460