WP-Chatbot for Facebook Messenger Customer Chat - Version 4.0.9

Version Description

= From Dashboard ( WordPress admin ) = * If plugin new version released - you can see 'update now' link at wp-admin -> plugins * click on 'update now'

= using FTP or similar = * Delete wp-chatbot folder - your setting will not lost. * unzip wp-chatbot file and * Upload "wp-chatbot" folder to the "/wp-content/plugins/" directory. * Activate the plugin through the "Plugins" menu in WordPress.

Download this release

Release Info

Developer yankovski
Plugin Icon 128x128 WP-Chatbot for Facebook Messenger Customer Chat
Version 4.0.9
Comparing to
See all releases

Code changes from version 4.0.8 to 4.0.9

admin/admin.php CHANGED
@@ -25,7 +25,7 @@ require_once('class-htcc-enqueue.php');
25
  $admin = new HTCC_Admin();
26
  add_action('admin_menu', array( $admin, 'htcc_options_page') );
27
  add_action( 'admin_init', array( $admin, 'htcc_custom_settings' ) );
28
-
29
 
30
 
31
  #premium
@@ -35,7 +35,24 @@ if ( 'true' == HTCC_PRO ) {
35
  }
36
 
37
 
38
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  /**
41
  * ht_cc_service_content - by default there is no option ..
25
  $admin = new HTCC_Admin();
26
  add_action('admin_menu', array( $admin, 'htcc_options_page') );
27
  add_action( 'admin_init', array( $admin, 'htcc_custom_settings' ) );
28
+ add_action('admin_init', 'general_admin_notice');
29
 
30
 
31
  #premium
35
  }
36
 
37
 
38
+ function general_admin_notice(){
39
+ if ($_GET['activate']) {
40
+ if( version_compare( get_bloginfo('version'), HTCC_WP_MIN_VERSION, '<') ) {
41
+ echo '<style>.update-nag, .updated, .error, .is-dismissible ,.settings{ display: none; }</style>';
42
+ echo '<style>.settings{ display: block; }</style><div class="updated error is-dismissible" style="display: block">
43
+ <p>Please update to WordPress '.HTCC_WP_MIN_VERSION.' or higher in order to be compatible with this plugin</p>
44
+ </div>';
45
+ deactivate_plugins(HTCC_PLUGIN_FILE);
46
+ }
47
+ if( version_compare(PHP_VERSION, HTCC_PHP_MIN_VERSION, '<') ) {
48
+ echo '<style>.update-nag, .updated, .error, .is-dismissible ,.settings{ display: none; }</style>';
49
+ echo '<style>.settings{ display: block; }</style><div class="updated error is-dismissible" style="display: block">
50
+ <p>Please update to PHP '.HTCC_WP_MIN_VERSION.' or higher in order to be compatible with this plugin</p>
51
+ </div>';
52
+ deactivate_plugins(HTCC_PLUGIN_FILE);
53
+ }
54
+ }
55
+ }
56
 
57
  /**
58
  * ht_cc_service_content - by default there is no option ..
admin/assets/css/admin-styles.css CHANGED
@@ -534,7 +534,7 @@ body .toc-tab-box .button {
534
  margin-bottom: 2px;
535
  }
536
 
537
- .acc-content .testchat:hover {
538
  background-color: #6071fb;
539
  color: #FFFFFF;
540
  }
@@ -583,4 +583,7 @@ body .toc-tab-box .button {
583
  display: inline-block;
584
  position: relative;
585
  text-align: justify;
 
 
 
586
  }
534
  margin-bottom: 2px;
535
  }
536
 
537
+ .acc-content .testchat:hover,.button.testchat:active {
538
  background-color: #6071fb;
539
  color: #FFFFFF;
540
  }
583
  display: inline-block;
584
  position: relative;
585
  text-align: justify;
586
+ }
587
+ .sp-input{
588
+ text-transform: uppercase;
589
  }
admin/class-htcc-admin.php CHANGED
@@ -22,6 +22,8 @@ if (!class_exists('HTCC_Admin')) :
22
  private $botid;
23
  private $token;
24
  private $test;
 
 
25
 
26
  public function __construct()
27
  {
@@ -29,7 +31,9 @@ if (!class_exists('HTCC_Admin')) :
29
  $this->token = $this->api->connectMobileMonkey();
30
  $this->options = get_option('htcc_options');
31
  $this->fb_page_id = $this->options['fb_page_id'];
32
- $this->botid = $this->api->getActivePage();
 
 
33
  }
34
 
35
  private function getApi()
@@ -112,7 +116,6 @@ if (!class_exists('HTCC_Admin')) :
112
  add_settings_field('htcc_fb_answer3','', array($this, 'htcc_fb_answer3_cb'), 'wp-chatbot', 'htcc_settings_as');
113
  add_settings_field('htcc_fb_thank_answer','', array($this, 'htcc_fb_thank_answer_cb'), 'wp-chatbot', 'htcc_settings_as');
114
  add_settings_field('htcc_fb_email_trans','', array($this, 'htcc_fb_email_trans_cb'), 'wp-chatbot', 'htcc_settings_as');
115
-
116
  register_setting('htcc_setting_group', 'htcc_as_options', array($this, 'htcc_as_options_sanitize'));
117
 
118
 
@@ -124,13 +127,11 @@ if (!class_exists('HTCC_Admin')) :
124
  add_settings_field('htcc_fb_greeting_dialog_display', __('Greeting Dialog Display', 'wp-chatbot'), array($this, 'htcc_fb_greeting_dialog_display_cb'), 'wp-chatbot', 'htcc_settings');
125
  add_settings_field('htcc_fb_greeting_dialog_delay', __('Greeting Dialog Delay', 'wp-chatbot'), array($this, 'htcc_fb_greeting_dialog_delay_cb'), 'wp-chatbot', 'htcc_settings');
126
  add_settings_field('htcc_fb_sdk_lang', __('Messenger language', 'wp-chatbot'), array($this, 'htcc_fb_sdk_lang_cb'), 'wp-chatbot', 'htcc_settings');
127
- add_settings_field('htcc_fb_ref', __('Ref', 'wp-chatbot'), array($this, 'htcc_fb_ref_cb'), 'wp-chatbot', 'htcc_settings');
128
  add_settings_field('htcc_show_hide', __('Hide Based on post type', 'wp-chatbot'), array($this, 'htcc_show_hide_post_types_cb'), 'wp-chatbot', 'htcc_settings');
129
  add_settings_field('htcc_list_id_tohide', __('Post, Page Id\'s to Hide', 'wp-chatbot'), array($this, 'htcc_list_id_tohide_cb'), 'wp-chatbot', 'htcc_settings');
130
  add_settings_field('htcc_list_cat_tohide', __('Categorys to Hide', 'wp-chatbot'), array($this, 'htcc_list_cat_tohide_cb'), 'wp-chatbot', 'htcc_settings');
131
  add_settings_field('htcc_devices_show_hide', __('Hide Based on Devices', 'wp-chatbot'), array($this, 'htcc_show_hide_devices_cb'), 'wp-chatbot', 'htcc_settings');
132
  add_settings_field('htcc_shortcode', __('Shortcode name', 'wp-chatbot'), array($this, 'htcc_custom_shortcode_cb'), 'wp-chatbot', 'htcc_settings');
133
- add_settings_field('htcc_page_load', __('Call SDK after Page Load', 'wp-chatbot'), array($this, 'htcc_page_load_cb'), 'wp-chatbot', 'htcc_settings');
134
  register_setting('htcc_setting_group', 'htcc_options', array($this, 'htcc_options_sanitize'));
135
  }
136
 
@@ -150,6 +151,7 @@ if (!class_exists('HTCC_Admin')) :
150
  ?>
151
  <?php
152
  if ($this->fb_page_id && $this->token && $this->botid){
 
153
  if ($this->api->mmOnlyCheck($this->fb_page_id)){
154
  $style = "disabled";
155
  $this->test = "none";
@@ -159,13 +161,13 @@ if (!class_exists('HTCC_Admin')) :
159
  }
160
  }
161
  ?>
162
- <h3 class="acc-title <?php if ($this->fb_page_id && $this->token && $this->botid){ echo "open"; } else {echo "close";}?>"><div class="circle">2</div>Set up your ChatBot<i class="fa fa-angle-down step_fa"></i></h3>
163
  <div class="acc-content answering-service <?php echo $style; ?>" style="display:block">
164
  <div class="accordionItemHeading">
165
 
166
  <div class="mm_only" style="display: none">
167
  <h6><?php _e('Looks like you\'ve already worked in MobileMonkey. Please use the MobileMonkey app to make additional edits to the \'Welcome message\' and \'Answering Service\'.', 'wp-chatbot') ?></h6>
168
- <a target="_blank" rel="noopener noreferrer" href='https://app.mobilemonkey.com/chatbot-editor/bot-builder' class="button">Go to MobileMonkey</a>
169
  </div>
170
  <?php
171
  }
@@ -173,7 +175,7 @@ if (!class_exists('HTCC_Admin')) :
173
  ?>
174
  </div>
175
  </div>
176
- <h3 class="acc-title <?php if ($this->fb_page_id && $this->token && $this->botid){ echo "open"; } else {echo "close";} ?>"><div class="circle">3</div>Customize<i class="fa fa-angle-down step_fa"></i></h3>
177
  <div class="acc-content" style="display:block">
178
  <div class="accordionItemHeading">
179
  <?php
@@ -188,64 +190,105 @@ if (!class_exists('HTCC_Admin')) :
188
  $token = $api->connectMobileMonkey();
189
 
190
  if ($token) {
191
-
192
  $reset = FALSE;
193
  if ($api->connectPage() || $api->disconnectPage()) {
194
  $reset = TRUE;
195
  }
196
 
197
  $pages = $api->getPages();
 
198
  $activePage = $api->getActivePage($reset);
199
  if ($activePage) {
200
- $test = $api->getWidgets($activePage['remote_id']);
201
- if ((float)$test->enabled!== (float)$options_as['fb_as_state']){
202
-
203
- if ($options_as['fb_as_state']==null || $options_as['fb_as_state']==0){
204
- $valuse = false;
205
- } else {
206
- $valuse = true;
207
- }
208
- $api->AsStateSave($valuse,$activePage['remote_id']);
209
- }
210
-
211
- if ($test) {
212
- foreach ($test->widgets as $key=>$value){
213
- if ($value->type == "quick_question"){
214
- $key+=1;
215
- if (!empty($options_as['fb_answer'.$key.'']) && $options_as['fb_answer'.$key.'']!== $value->config->body){
216
- $dump_value = $value;
217
- $dump_value->config->body = $options_as['fb_answer'.$key.''];
218
- $api->updateWidgets($dump_value);
219
  }
220
- }
221
- if ($value->type == 'text'){
222
- if (!empty($options_as['thank_message']) && $options_as['thank_message']!== $value->config->body) {
223
- $dump_value = $value;
224
- $dump_value->config->body = $options_as['thank_message'];
225
- $api->updateWidgets($dump_value);
226
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
- if ($value->type == 'email'){
230
- if (!empty($options_as['email']) && $options_as['email']!== $value->config->recipient) {
231
- $dump_value = $value;
232
- $dump_value->config->recipient = $options_as['email'];
233
- $api->updateWidgets($dump_value);
234
 
 
 
 
 
235
  }
236
  }
 
237
  }
238
- // var_dump($options_as = get_option('htcc_as_options'));
239
- }
240
 
241
- $current_welcome_message = $api->getWelcomeMessage($activePage['remote_id']);
242
- if (!empty($options['fb_welcome_message']) && $options['fb_welcome_message'] !== $current_welcome_message) {
243
- $api->updateWelcomeMessage($options['fb_welcome_message'], $activePage['remote_id']);
244
- }
245
- $current_language = $api->getLanguage($activePage['remote_id']);
246
- if (!empty($options['fb_sdk_lang']) && $options['fb_sdk_lang'] !== $current_language) {
247
- $api->updateLanguage($options['fb_sdk_lang'], $activePage['remote_id']);
248
- }
249
  $fb_connected_area_active_page_settings = [
250
  'connected_page' => $activePage,
251
  'current_facebook_page_block' => '',
@@ -257,7 +300,10 @@ if (!class_exists('HTCC_Admin')) :
257
  HT_CC::view('ht-cc-admin-fb-button-connected', $fb_connected_area_active_page_settings);
258
 
259
  } else {
260
-
 
 
 
261
  $fb_connected_area_pages_settings = [
262
  'pages' => $pages,
263
  'logout_path' => add_query_arg([
@@ -351,7 +397,6 @@ if (!class_exists('HTCC_Admin')) :
351
  <div class="fb-send-to-messenger"
352
  messenger_app_id="<?php echo $htcc_fb_app_id->fb_app_id; ?>"
353
  page_id="<?php echo $this->fb_page_id; ?>"
354
- data-ref="<?php echo $htcc_fb_welcome_message['ref'];; ?>"
355
  color="blue"
356
  size="large">
357
  </div>
@@ -362,8 +407,8 @@ if (!class_exists('HTCC_Admin')) :
362
  <a target="_blank" rel="noopener noreferrer" style="display: none" href="https://www.m.me/<?php echo $this->fb_page_id?>" id="messanger" class="button testchat">Open Messenger</a>
363
  <h6><?php _e('Welcome message', 'wp-chatbot') ?></h6>
364
  <div class="input-field col s12">
365
- <label for="fb_greeting_login"><?php _e('WP-Chatbot will greet your chat users with this message', 'wp-chatbot') ?></label>
366
- <textarea rows="5" cols="100" name="htcc_options[fb_welcome_message]" id="fb_welcome_message"> <?php echo esc_attr($htcc_fb_welcome_message['fb_welcome_message']) ?></textarea>
367
  </div>
368
  </div>
369
  <?php
@@ -375,7 +420,7 @@ if (!class_exists('HTCC_Admin')) :
375
  <div class="row as">
376
  <div class="input-field col s9">
377
  <h6><?php _e('Quick Questions', 'wp-chatbot') ?></h6>
378
- <label for="fb_answer1"><?php _e('WP-Chatbot will greet your chat users with this message', 'wp-chatbot') ?></label>
379
  <input type="text" name="htcc_as_options[fb_answer1]" id="fb_answer1"
380
  value="<?php echo esc_attr($htcc_fb_answer1['fb_answer1']) ?>">
381
  </div>
@@ -413,7 +458,7 @@ if (!class_exists('HTCC_Admin')) :
413
  <div class="row as">
414
  <div class="input-field col s9">
415
  <h6><?php _e('Thank you message', 'wp-chatbot') ?></h6>
416
- <label for="fb_answer1"><?php _e('Thank your users for answering your questions, and let them know you\'ll get back to them', 'wp-chatbot') ?></label>
417
  <input type="text" name="htcc_as_options[thank_message]" id="thank_message"
418
  value="<?php echo esc_attr($htcc_fb_thank_answer['thank_message']) ?>">
419
  </div>
@@ -427,7 +472,7 @@ if (!class_exists('HTCC_Admin')) :
427
  <div class="row as">
428
  <div class="input-field col s9">
429
  <h6><?php _e('Email to send transcripts to:', 'wp-chatbot') ?></h6>
430
- <label for="htcc_fb_email_trans"><?php _e('When people answer all of the questions below, we can send the answers to an email address of your choice! To disable, simply leave this field blank.', 'wp-chatbot') ?></label>
431
  <input type="text" name="htcc_as_options[email]" id="email"
432
  value="<?php echo esc_attr($htcc_fb_email_trans['email']) ?>">
433
  </div>
@@ -447,8 +492,8 @@ if (!class_exists('HTCC_Admin')) :
447
  ?>
448
  <div class="row">
449
  <div class="input-field col s12">
450
- <input type="text" name="htcc_options[fb_greeting_login]" id="fb_greeting_login"
451
- value="<?php echo esc_attr($htcc_fb_greeting_login['fb_greeting_login']) ?>">
452
  <label for="fb_greeting_login"><?php _e('Logged in Greetings', 'ht-click') ?></label>
453
  <p class="description"><?php _e('Greetings text - If Facebook logged in the current browser, leave empty for default message - ', 'wp-chatbot') ?>
454
  <a target="_blank"
@@ -469,8 +514,8 @@ if (!class_exists('HTCC_Admin')) :
469
  ?>
470
  <div class="row">
471
  <div class="input-field col s12">
472
- <input type="text" name="htcc_options[fb_greeting_logout]" id="fb_greeting_logout"
473
- value="<?php echo esc_attr($htcc_fb_greeting_logout['fb_greeting_logout']) ?>">
474
  <label for="fb_greeting_logout"><?php _e('Logged out Greetings', 'ht-click') ?></label>
475
  <p class="description"><?php _e('Greetings text - If Facebook logged out in the current browser, leave empty for default message - ', 'wp-chatbot') ?>
476
  <a target="_blank"
@@ -484,9 +529,9 @@ if (!class_exists('HTCC_Admin')) :
484
  // sdk lang. / messenger lang
485
  public function htcc_fb_sdk_lang_cb()
486
  {
487
-
488
- $sdk_lang = get_option('htcc_options');
489
- $lang = esc_attr($sdk_lang['fb_sdk_lang']);
490
  ?>
491
  <div class="row">
492
  <div class="input-field col s12">
@@ -518,11 +563,11 @@ if (!class_exists('HTCC_Admin')) :
518
  public function htcc_fb_greeting_dialog_display_cb()
519
  {
520
  $greeting_dialog_display = get_option('htcc_options');
521
- $min_value = esc_attr($greeting_dialog_display['greeting_dialog_display']);
522
  ?>
523
  <div class="row">
524
  <div class="input-field col s12">
525
- <select name="htcc_options[greeting_dialog_display]" class="select-1">
526
  <option value="" <?php echo $min_value == "" ? 'SELECTED' : ''; ?> >Default</option>
527
  <option value="show" <?php echo $min_value == "show" ? 'SELECTED' : ''; ?> >Show</option>
528
  <option value="fade" <?php echo $min_value == "fade" ? 'SELECTED' : ''; ?> >Fade</option>
@@ -544,14 +589,14 @@ if (!class_exists('HTCC_Admin')) :
544
  public function htcc_fb_greeting_dialog_delay_cb()
545
  {
546
  $greeting_dialog_delay = get_option('htcc_options');
547
- $delay_time = esc_attr($greeting_dialog_delay['greeting_dialog_delay']);
548
  ?>
549
  <div class="row">
550
  <div class="input-field col s12">
551
- <input type="number" min="0" name="htcc_options[greeting_dialog_delay]" id="greeting_dialog_delay"
552
  value="<?php echo $delay_time ?>">
553
- <label for="greeting_dialog_delay"><?php _e('Greeting Dialog Delay', 'ht-click') ?></label>
554
- <p class="description"><?php _e('Sets the number of seconds of delay before the greeting dialog is shown after the plugin is loaded - ', 'wp-chatbot') ?>
555
  <a target="_blank"
556
  href="https://mobilemonkey.com/wp-chatbot/greeting-dialog-delay/"><?php _e('more info', 'wp-chatbot') ?></a>
557
  </p>
@@ -561,25 +606,6 @@ if (!class_exists('HTCC_Admin')) :
561
  }
562
 
563
 
564
- // ref
565
- public function htcc_fb_ref_cb()
566
- {
567
-
568
- $reference = get_option('htcc_options');
569
- ?>
570
- <div class="row">
571
- <div class="input-field col s12">
572
- <input type="text" name="htcc_options[ref]" id="ref"
573
- value="<?php echo esc_attr($reference['ref']) ?>">
574
- <label for="ref"><?php _e('REF Attribute', 'ht-click') ?></label>
575
- <p class="description"><?php _e('Useful to create Entry Point to your messenger chatbot - ', 'wp-chatbot') ?>
576
- <a target="_blank"
577
- href="https://mobilemonkey.com/wp-chatbot/messenger-ref/"><?php _e('more info', 'wp-chatbot') ?></a>
578
- </p>
579
- </div>
580
- </div>
581
- <?php
582
- }
583
 
584
 
585
  // minimized - deprecated - since v2.2
@@ -833,12 +859,12 @@ if (!class_exists('HTCC_Admin')) :
833
  $htcc_devices = get_option('htcc_options');
834
 
835
  // Hide on Mobile Devices
836
- if (isset($htcc_devices['hideon_mobile'])) {
837
  ?>
838
  <p>
839
  <label>
840
- <input name="htcc_options[hideon_mobile]" type="checkbox"
841
- value="1" <?php checked($htcc_devices['hideon_mobile'], 1); ?> id="hideon_mobile"/>
842
  <span><?php _e('Hide on - Mobile Devices', 'wp-chatbot') ?></span>
843
  </label>
844
  </p>
@@ -847,7 +873,7 @@ if (!class_exists('HTCC_Admin')) :
847
  ?>
848
  <p>
849
  <label>
850
- <input name="htcc_options[hideon_mobile]" type="checkbox" value="1" id="hideon_mobile"/>
851
  <span><?php _e('Hide on - Mobile Devices', 'wp-chatbot') ?></span>
852
  </label>
853
  </p>
@@ -856,12 +882,12 @@ if (!class_exists('HTCC_Admin')) :
856
 
857
 
858
  // Hide on Desktop Devices
859
- if (isset($htcc_devices['hideon_desktop'])) {
860
  ?>
861
  <p>
862
  <label>
863
- <input name="htcc_options[hideon_desktop]" type="checkbox"
864
- value="1" <?php checked($htcc_devices['hideon_desktop'], 1); ?> id="hideon_desktop"/>
865
  <span><?php _e('Hide on - Desktops', 'wp-chatbot') ?></span>
866
  </label>
867
  </p>
@@ -870,7 +896,7 @@ if (!class_exists('HTCC_Admin')) :
870
  ?>
871
  <p>
872
  <label>
873
- <input name="htcc_options[hideon_desktop]" type="checkbox" value="1" id="hideon_desktop"/>
874
  <span><?php _e('Hide on - Desktops', 'wp-chatbot') ?></span>
875
  </label>
876
  </p>
@@ -906,83 +932,14 @@ if (!class_exists('HTCC_Admin')) :
906
  <?php
907
  }
908
 
909
- // page load
910
- public function htcc_page_load_cb()
911
- {
912
- $options = get_option('htcc_options');
913
-
914
- ?>
915
- <p class="description"><a href="https://mobilemonkey.com/wp-chatbot/call-sdk-after-page-loads/"
916
- target="_blank">Call SDK after page load</a></p>
917
- <p class="description">This feature is in beta stage ( please review these settings at least in the next two
918
- versions )</p>
919
- <p class="description">Don't enable this features If some other plugins or some other source also calls
920
- Facebook SDK.</p>
921
- <br>
922
-
923
- <?php
924
- // load sdk after page loaded
925
- if (isset($options['is_sdk_after_page_load'])) {
926
- ?>
927
- <p>
928
- <label>
929
- <input name="htcc_options[is_sdk_after_page_load]" type="checkbox"
930
- value="1" <?php checked($options['is_sdk_after_page_load'], 1); ?>
931
- id="is_sdk_after_page_load"/>
932
- <span><?php _e('Call SDK after page loads', 'wp-chatbot') ?></span>
933
- </label>
934
- </p>
935
- <?php
936
- } else {
937
- ?>
938
- <p>
939
- <label>
940
- <input name="htcc_options[is_sdk_after_page_load]" type="checkbox" value="1"
941
- id="is_sdk_after_page_load"/>
942
- <span><?php _e('Call SDK after page loads', 'wp-chatbot') ?></span>
943
- </label>
944
- </p>
945
- <?php
946
- }
947
- ?>
948
- <p class="description">Improves user experience. After webpage loaded, call SDK and display messenger</p>
949
- <br>
950
-
951
- <!-- <div class="time-delay" style="margin-left: 25px;"> -->
952
-
953
- <?php
954
-
955
- // +4 seconds - load sdk after page loaded
956
- if (isset($options['is_sdk_4_seconds'])) {
957
- ?>
958
- <p>
959
- <label>
960
- <input name="htcc_options[is_sdk_4_seconds]" type="checkbox"
961
- value="1" <?php checked($options['is_sdk_4_seconds'], 1); ?> id="is_sdk_4_seconds"/>
962
- <span><?php _e('+4 seconds after page loaded', 'wp-chatbot') ?></span>
963
- </label>
964
- </p>
965
- <?php
966
- } else {
967
- ?>
968
- <p>
969
- <label>
970
- <input name="htcc_options[is_sdk_4_seconds]" type="checkbox" value="1" id="is_sdk_4_seconds"/>
971
- <span><?php _e('+4 seconds after page loaded', 'wp-chatbot') ?></span>
972
- </label>
973
- </p>
974
- <?php
975
- }
976
- ?>
977
- <!-- <p class="description">After webpage loaded and after 4 seconds, call SDK and display Messenger</p> -->
978
- <p class="description">Adds benefit at page speed metrics</p>
979
- <?php
980
- }
981
 
982
 
983
  public function htcc_options_sanitize($input)
984
  {
985
-
 
 
 
986
  if (!current_user_can('manage_options')) {
987
  wp_die('not allowed to modify - please contact admin ');
988
  }
@@ -990,30 +947,74 @@ if (!class_exists('HTCC_Admin')) :
990
  $new_input = array();
991
 
992
  foreach ($input as $key => $value) {
993
- if (isset($input[$key])) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
994
  $new_input[$key] = sanitize_text_field($input[$key]);
995
  }
996
  }
997
-
998
-
 
 
 
 
 
 
 
999
  return $new_input;
1000
  }
1001
  public function htcc_as_options_sanitize($input)
1002
  {
 
 
 
1003
 
1004
  if (!current_user_can('manage_options')) {
1005
  wp_die('not allowed to modify - please contact admin ');
1006
  }
1007
  if ($input){
1008
- $new_input = array();
1009
-
1010
- foreach ($input as $key => $value) {
1011
- if (isset($input[$key])) {
1012
- $new_input[$key] = sanitize_text_field($input[$key]);
1013
- }
1014
- }
1015
- }
1016
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
  return $new_input;
1018
  }
1019
 
22
  private $botid;
23
  private $token;
24
  private $test;
25
+ private $internal;
26
+ private $stepdis;
27
 
28
  public function __construct()
29
  {
31
  $this->token = $this->api->connectMobileMonkey();
32
  $this->options = get_option('htcc_options');
33
  $this->fb_page_id = $this->options['fb_page_id'];
34
+ $this->botid = $this->api->getActivePage()['bot_id'];
35
+ $this->internal = get_option('mobilemonkey_active_page_id');
36
+ $this->stepdis = "close";
37
  }
38
 
39
  private function getApi()
116
  add_settings_field('htcc_fb_answer3','', array($this, 'htcc_fb_answer3_cb'), 'wp-chatbot', 'htcc_settings_as');
117
  add_settings_field('htcc_fb_thank_answer','', array($this, 'htcc_fb_thank_answer_cb'), 'wp-chatbot', 'htcc_settings_as');
118
  add_settings_field('htcc_fb_email_trans','', array($this, 'htcc_fb_email_trans_cb'), 'wp-chatbot', 'htcc_settings_as');
 
119
  register_setting('htcc_setting_group', 'htcc_as_options', array($this, 'htcc_as_options_sanitize'));
120
 
121
 
127
  add_settings_field('htcc_fb_greeting_dialog_display', __('Greeting Dialog Display', 'wp-chatbot'), array($this, 'htcc_fb_greeting_dialog_display_cb'), 'wp-chatbot', 'htcc_settings');
128
  add_settings_field('htcc_fb_greeting_dialog_delay', __('Greeting Dialog Delay', 'wp-chatbot'), array($this, 'htcc_fb_greeting_dialog_delay_cb'), 'wp-chatbot', 'htcc_settings');
129
  add_settings_field('htcc_fb_sdk_lang', __('Messenger language', 'wp-chatbot'), array($this, 'htcc_fb_sdk_lang_cb'), 'wp-chatbot', 'htcc_settings');
 
130
  add_settings_field('htcc_show_hide', __('Hide Based on post type', 'wp-chatbot'), array($this, 'htcc_show_hide_post_types_cb'), 'wp-chatbot', 'htcc_settings');
131
  add_settings_field('htcc_list_id_tohide', __('Post, Page Id\'s to Hide', 'wp-chatbot'), array($this, 'htcc_list_id_tohide_cb'), 'wp-chatbot', 'htcc_settings');
132
  add_settings_field('htcc_list_cat_tohide', __('Categorys to Hide', 'wp-chatbot'), array($this, 'htcc_list_cat_tohide_cb'), 'wp-chatbot', 'htcc_settings');
133
  add_settings_field('htcc_devices_show_hide', __('Hide Based on Devices', 'wp-chatbot'), array($this, 'htcc_show_hide_devices_cb'), 'wp-chatbot', 'htcc_settings');
134
  add_settings_field('htcc_shortcode', __('Shortcode name', 'wp-chatbot'), array($this, 'htcc_custom_shortcode_cb'), 'wp-chatbot', 'htcc_settings');
 
135
  register_setting('htcc_setting_group', 'htcc_options', array($this, 'htcc_options_sanitize'));
136
  }
137
 
151
  ?>
152
  <?php
153
  if ($this->fb_page_id && $this->token && $this->botid){
154
+ $this->stepdis = "open";
155
  if ($this->api->mmOnlyCheck($this->fb_page_id)){
156
  $style = "disabled";
157
  $this->test = "none";
161
  }
162
  }
163
  ?>
164
+ <h3 class="acc-title <?php echo $this->stepdis?>"><div class="circle">2</div>Set up your ChatBot<i class="fa fa-angle-down step_fa"></i></h3>
165
  <div class="acc-content answering-service <?php echo $style; ?>" style="display:block">
166
  <div class="accordionItemHeading">
167
 
168
  <div class="mm_only" style="display: none">
169
  <h6><?php _e('Looks like you\'ve already worked in MobileMonkey. Please use the MobileMonkey app to make additional edits to the \'Welcome message\' and \'Answering Service\'.', 'wp-chatbot') ?></h6>
170
+ <a target="_blank" rel="noopener noreferrer" href='https://app.mobilemonkey.com/chatbot-editor/<?php echo"$this->internal"?>/home' class="button">Go to MobileMonkey</a>
171
  </div>
172
  <?php
173
  }
175
  ?>
176
  </div>
177
  </div>
178
+ <h3 class="acc-title <?php echo $this->stepdis?>"><div class="circle">3</div>Customize<i class="fa fa-angle-down step_fa"></i></h3>
179
  <div class="acc-content" style="display:block">
180
  <div class="accordionItemHeading">
181
  <?php
190
  $token = $api->connectMobileMonkey();
191
 
192
  if ($token) {
 
193
  $reset = FALSE;
194
  if ($api->connectPage() || $api->disconnectPage()) {
195
  $reset = TRUE;
196
  }
197
 
198
  $pages = $api->getPages();
199
+
200
  $activePage = $api->getActivePage($reset);
201
  if ($activePage) {
202
+ if ($activePage['bot_id']){
203
+ if ($_REQUEST['settings-updated']){
204
+ if (!$this->api->mmOnlyCheck($this->fb_page_id)){
205
+ $test = $api->getWidgets($activePage['remote_id']);
206
+ if ((float)$test->enabled!== (float)$options_as['fb_as_state']){
207
+
208
+ if ($options_as['fb_as_state']== null || $options_as['fb_as_state']==0){
209
+ $valuse = false;
210
+ } else {
211
+ $valuse = true;
212
+ }
213
+ $api->AsStateSave($valuse,$activePage['remote_id']);
 
 
 
 
 
 
 
214
  }
215
+ if ($test) {
216
+ foreach ($test->widgets as $key=>$value){
217
+ if ($value->type == "quick_question"){
218
+ $key+=1;
219
+ if ($options_as['fb_answer'.$key.'']!== $value->config->body){
220
+ $dump_value = $value;
221
+ $dump_value->config->body = $options_as['fb_answer'.$key.''];
222
+ $api->updateWidgets($dump_value);
223
+ }
224
+ }
225
+ if ($value->type == 'text'){
226
+ if ($options_as['thank_message']!== $value->config->body) {
227
+ $dump_value = $value;
228
+ $dump_value->config->body = $options_as['thank_message'];
229
+ $api->updateWidgets($dump_value);
230
+
231
+ }
232
+ }
233
+ if ($value->type == 'email'){
234
+ if ($options_as['email']!== $value->config->recipient) {
235
+ $dump_value = $value;
236
+ $dump_value->config->recipient = $options_as['email'];
237
+ $api->updateWidgets($dump_value);
238
+
239
+ }
240
+ }
241
+ }
242
  }
243
+ $current_welcome_message = $api->getWelcomeMessage($activePage['remote_id']);
244
+ if ($options['fb_welcome_message'] !== $current_welcome_message) {
245
+ $api->updateWelcomeMessage($options['fb_welcome_message'], $activePage['remote_id']);
246
+ }
247
+ }
248
+ }
249
+ $custom_settings = $this->api->getCustomChatSettings($activePage['remote_id']);
250
+ if ($_REQUEST['settings-updated']){
251
+ if ($custom_settings) {
252
+ foreach ($custom_settings as $key=>$value){
253
+ if ($key != "js_src"){
254
+ if ($key == 'hide_mobile' || $key == 'hide_desktop'){
255
+ if (!$options['fb_'.$key]){
256
+ $options['fb_'.$key] = false;
257
+ }else{
258
+ $options['fb_'.$key] = true;
259
+ }
260
+ }
261
+ if ($options['fb_'.$key]!=$value){
262
+ $new_value[$key] = $options['fb_'.$key];
263
+
264
+ }
265
+ }
266
+ }
267
+ if (!empty($new_value)){
268
+ $api->updateCustomChatSettings($new_value,$activePage['remote_id']);
269
+ }
270
+ }
271
+ $current_language = $api->getLanguage($activePage['remote_id']);
272
+ if (!empty($options['fb_sdk_lang']) && $options['fb_sdk_lang'] !== $current_language) {
273
+ $api->updateLanguage($options['fb_sdk_lang'], $activePage['remote_id']);
274
  }
275
+ }else {
 
 
 
 
276
 
277
+ foreach ($custom_settings as $key=>$value){
278
+ $options['fb_'.$key]=$value;
279
+ if (!$reset){
280
+ update_option('htcc_options', $options);
281
  }
282
  }
283
+
284
  }
 
 
285
 
286
+ }else {
287
+ echo "<style>.settings-error{display: none}</style>";
288
+ $this->api->renderNotice('Your chatbot has been disabled in MobileMonkey. Please reactivate it before making additional edits. Go <a target="_blank" rel="noopener noreferrer" href="https://app.mobilemonkey.com/chatbot-editor/">here</a> to reactivate your chatbot');
289
+ }
290
+
291
+
 
 
292
  $fb_connected_area_active_page_settings = [
293
  'connected_page' => $activePage,
294
  'current_facebook_page_block' => '',
300
  HT_CC::view('ht-cc-admin-fb-button-connected', $fb_connected_area_active_page_settings);
301
 
302
  } else {
303
+ if ($this->internal){
304
+ echo "<style>.settings-error{display: none}</style>";
305
+ $this->api->renderNotice('Your Facebook page has been disconnected in MobileMonkey. Please connect to a page to reactivate your chatbot.');
306
+ }
307
  $fb_connected_area_pages_settings = [
308
  'pages' => $pages,
309
  'logout_path' => add_query_arg([
397
  <div class="fb-send-to-messenger"
398
  messenger_app_id="<?php echo $htcc_fb_app_id->fb_app_id; ?>"
399
  page_id="<?php echo $this->fb_page_id; ?>"
 
400
  color="blue"
401
  size="large">
402
  </div>
407
  <a target="_blank" rel="noopener noreferrer" style="display: none" href="https://www.m.me/<?php echo $this->fb_page_id?>" id="messanger" class="button testchat">Open Messenger</a>
408
  <h6><?php _e('Welcome message', 'wp-chatbot') ?></h6>
409
  <div class="input-field col s12">
410
+ <label for="fb_greeting_login"><?php _e('WP-Chatbot will greet your chat users with this message.', 'wp-chatbot') ?></label>
411
+ <textarea rows="5" style="width:78%" name="htcc_options[fb_welcome_message]" id="fb_welcome_message"> <?php echo esc_attr($htcc_fb_welcome_message['fb_welcome_message']) ?></textarea>
412
  </div>
413
  </div>
414
  <?php
420
  <div class="row as">
421
  <div class="input-field col s9">
422
  <h6><?php _e('Quick Questions', 'wp-chatbot') ?></h6>
423
+ <label for="fb_answer1"><?php _e('WP-Chatbot will ask your chat users a few questions.', 'wp-chatbot') ?></label>
424
  <input type="text" name="htcc_as_options[fb_answer1]" id="fb_answer1"
425
  value="<?php echo esc_attr($htcc_fb_answer1['fb_answer1']) ?>">
426
  </div>
458
  <div class="row as">
459
  <div class="input-field col s9">
460
  <h6><?php _e('Thank you message', 'wp-chatbot') ?></h6>
461
+ <label for="fb_answer1"><?php _e('Thank your users for answering your questions, and let them know you\'ll get back to them.', 'wp-chatbot') ?></label>
462
  <input type="text" name="htcc_as_options[thank_message]" id="thank_message"
463
  value="<?php echo esc_attr($htcc_fb_thank_answer['thank_message']) ?>">
464
  </div>
472
  <div class="row as">
473
  <div class="input-field col s9">
474
  <h6><?php _e('Email to send transcripts to:', 'wp-chatbot') ?></h6>
475
+ <label for="htcc_fb_email_trans"><?php _e('When people answer all of the questions below, we can send the answers to an email address of your choice!', 'wp-chatbot') ?></label>
476
  <input type="text" name="htcc_as_options[email]" id="email"
477
  value="<?php echo esc_attr($htcc_fb_email_trans['email']) ?>">
478
  </div>
492
  ?>
493
  <div class="row">
494
  <div class="input-field col s12">
495
+ <input type="text" name="htcc_options[fb_logged_in_greeting]" id="fb_greeting_login"
496
+ value="<?php echo esc_attr($htcc_fb_greeting_login['fb_logged_in_greeting']) ?>">
497
  <label for="fb_greeting_login"><?php _e('Logged in Greetings', 'ht-click') ?></label>
498
  <p class="description"><?php _e('Greetings text - If Facebook logged in the current browser, leave empty for default message - ', 'wp-chatbot') ?>
499
  <a target="_blank"
514
  ?>
515
  <div class="row">
516
  <div class="input-field col s12">
517
+ <input type="text" name="htcc_options[fb_logged_out_greeting]" id="fb_greeting_logout"
518
+ value="<?php echo esc_attr($htcc_fb_greeting_logout['fb_logged_out_greeting']) ?>">
519
  <label for="fb_greeting_logout"><?php _e('Logged out Greetings', 'ht-click') ?></label>
520
  <p class="description"><?php _e('Greetings text - If Facebook logged out in the current browser, leave empty for default message - ', 'wp-chatbot') ?>
521
  <a target="_blank"
529
  // sdk lang. / messenger lang
530
  public function htcc_fb_sdk_lang_cb()
531
  {
532
+ if ($this->fb_page_id && $this->token && $this->botid){
533
+ $lang = $this->api->getLanguage($this->fb_page_id);
534
+ }
535
  ?>
536
  <div class="row">
537
  <div class="input-field col s12">
563
  public function htcc_fb_greeting_dialog_display_cb()
564
  {
565
  $greeting_dialog_display = get_option('htcc_options');
566
+ $min_value = esc_attr($greeting_dialog_display['fb_greeting_dialog_display']);
567
  ?>
568
  <div class="row">
569
  <div class="input-field col s12">
570
+ <select name="htcc_options[fb_greeting_dialog_display]" class="select-1">
571
  <option value="" <?php echo $min_value == "" ? 'SELECTED' : ''; ?> >Default</option>
572
  <option value="show" <?php echo $min_value == "show" ? 'SELECTED' : ''; ?> >Show</option>
573
  <option value="fade" <?php echo $min_value == "fade" ? 'SELECTED' : ''; ?> >Fade</option>
589
  public function htcc_fb_greeting_dialog_delay_cb()
590
  {
591
  $greeting_dialog_delay = get_option('htcc_options');
592
+ $delay_time = esc_attr($greeting_dialog_delay['fb_greeting_dialog_delay']);
593
  ?>
594
  <div class="row">
595
  <div class="input-field col s12">
596
+ <input type="number" min="0" name="htcc_options[fb_greeting_dialog_delay]" id="fb_greeting_dialog_delay"
597
  value="<?php echo $delay_time ?>">
598
+ <label for="fb_greeting_dialog_delay"><?php _e('Greeting Dialog Delay', 'ht-click') ?></label>
599
+ <p class="description"><?php _e('Sets the number of seconds of delay before the greeting dialog is shown after the plugin is loaded. Leave blank to disable delay - ', 'wp-chatbot') ?>
600
  <a target="_blank"
601
  href="https://mobilemonkey.com/wp-chatbot/greeting-dialog-delay/"><?php _e('more info', 'wp-chatbot') ?></a>
602
  </p>
606
  }
607
 
608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
 
610
 
611
  // minimized - deprecated - since v2.2
859
  $htcc_devices = get_option('htcc_options');
860
 
861
  // Hide on Mobile Devices
862
+ if (isset($htcc_devices['fb_hide_mobile'])) {
863
  ?>
864
  <p>
865
  <label>
866
+ <input name="htcc_options[fb_hide_mobile]" type="checkbox"
867
+ value="1" <?php checked($htcc_devices['fb_hide_mobile'], 1); ?> id="fb_hide_mobile"/>
868
  <span><?php _e('Hide on - Mobile Devices', 'wp-chatbot') ?></span>
869
  </label>
870
  </p>
873
  ?>
874
  <p>
875
  <label>
876
+ <input name="htcc_options[fb_hide_mobile]" type="checkbox" value="1" id="fb_hide_mobile"/>
877
  <span><?php _e('Hide on - Mobile Devices', 'wp-chatbot') ?></span>
878
  </label>
879
  </p>
882
 
883
 
884
  // Hide on Desktop Devices
885
+ if (isset($htcc_devices['fb_hide_desktop'])) {
886
  ?>
887
  <p>
888
  <label>
889
+ <input name="htcc_options[fb_hide_desktop]" type="checkbox"
890
+ value="1" <?php checked($htcc_devices['fb_hide_desktop'], 1); ?> id="fb_hide_desktop"/>
891
  <span><?php _e('Hide on - Desktops', 'wp-chatbot') ?></span>
892
  </label>
893
  </p>
896
  ?>
897
  <p>
898
  <label>
899
+ <input name="htcc_options[fb_hide_desktop]" type="checkbox" value="1" id="fb_hide_desktop"/>
900
  <span><?php _e('Hide on - Desktops', 'wp-chatbot') ?></span>
901
  </label>
902
  </p>
932
  <?php
933
  }
934
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
935
 
936
 
937
  public function htcc_options_sanitize($input)
938
  {
939
+ $option = get_option('htcc_options');
940
+ $error=false;
941
+ $error_delay_lenght =false;
942
+ $error_delay_value =false;
943
  if (!current_user_can('manage_options')) {
944
  wp_die('not allowed to modify - please contact admin ');
945
  }
947
  $new_input = array();
948
 
949
  foreach ($input as $key => $value) {
950
+ if ($key == 'fb_welcome_message' && $_REQUEST['action']== 'update' && !$this->api->mmOnlyCheck($this->fb_page_id)){
951
+ if ($value == '' || ctype_space($value)){
952
+ $new_input[$key] = $option[$key];
953
+ $error = true;
954
+ }else {
955
+ $new_input[$key] = sanitize_text_field($input[$key]);
956
+ }
957
+ }elseif($key == 'fb_greeting_dialog_delay' && $_REQUEST['action']== 'update'){
958
+ if (strlen($value) > 9){
959
+ $new_input[$key] = $option[$key];
960
+ $error_delay_lenght = true;
961
+ }else {
962
+ if ($value == '0'){
963
+ $error_delay_value = true;
964
+ $new_input[$key] = $option[$key];
965
+ }else {
966
+ $new_input[$key] = sanitize_text_field($input[$key]);
967
+ }
968
+ }
969
+ }elseif(isset($input[$key])) {
970
  $new_input[$key] = sanitize_text_field($input[$key]);
971
  }
972
  }
973
+ if ($error){
974
+ $this->api->settingSaveError("welcome_message");
975
+ }
976
+ if ($error_delay_lenght){
977
+ $this->api->settingSaveError("delay_length");
978
+ }
979
+ if ($error_delay_value){
980
+ $this->api->settingSaveError("delay_0");
981
+ }
982
  return $new_input;
983
  }
984
  public function htcc_as_options_sanitize($input)
985
  {
986
+ $error=false;
987
+ $error_email=false;
988
+ $option = get_option('htcc_as_options');
989
 
990
  if (!current_user_can('manage_options')) {
991
  wp_die('not allowed to modify - please contact admin ');
992
  }
993
  if ($input){
994
+ $new_input = array();
 
 
 
 
 
 
 
995
 
996
+ foreach ($input as $key => $value) {
997
+ if ($value == '' || ctype_space($value)){
998
+ if ($_REQUEST['action'] == 'update'){
999
+ $new_input[$key] = $option[$key];
1000
+ $error = true;
1001
+ }
1002
+ }elseif (isset($input[$key])) {
1003
+ if ($key == 'email' && !is_email($value)){
1004
+ $new_input[$key] = $option[$key];
1005
+ $error_email = true;
1006
+ }else {
1007
+ $new_input[$key] = sanitize_text_field($input[$key]);
1008
+ }
1009
+ }
1010
+ }
1011
+ }
1012
+ if ($error){
1013
+ $this->api->settingSaveError("AS");
1014
+ }
1015
+ if ($error_email){
1016
+ $this->api->settingSaveError("email");
1017
+ }
1018
  return $new_input;
1019
  }
1020
 
admin/class-htcc-enqueue.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Admin - enqueue sytle, scripts
4
  */
5
 
6
 
@@ -12,11 +12,11 @@ class HTCC_Enqueue {
12
 
13
 
14
  function enqueue( $hook ) {
15
-
16
  // echo $hook;
17
  if( 'toplevel_page_wp-chatbot' == $hook || 'wp-chatbot_page_wp-chatbot-features' == $hook || 'wp-chatbot_page_wp-chatbot-actions' == $hook || 'wp-chatbot_page_wp-chatbot-pro-woo' == $hook ) {
18
-
19
-
20
  // color picker..
21
  // wp_enqueue_style( 'htcc_admin_color_picker_styles', plugins_url( 'admin/assets/color/colors.css', HTCC_PLUGIN_FILE ), '', HTCC_VERSION );
22
  // wp_enqueue_script( 'htcc_admin_color_picker_js', plugins_url( 'admin/assets/color/colors.js', HTCC_PLUGIN_FILE ), array( 'jquery', 'wp-color-picker', 'htcc_admin_md_js' ), HTCC_VERSION );
@@ -31,11 +31,11 @@ class HTCC_Enqueue {
31
 
32
  wp_enqueue_style( 'htcc_admin_styles', plugins_url( 'admin/assets/css/admin-styles.css', HTCC_PLUGIN_FILE ), '', HTCC_VERSION );
33
  wp_enqueue_style( 'htcc_admin_md_styles', plugins_url( 'admin/assets/css/materialize.min.css', HTCC_PLUGIN_FILE ), '', HTCC_VERSION );
34
-
35
  wp_enqueue_style( 'wp-color-picker' );
36
  wp_enqueue_script( 'wp-color-picker');
37
 
38
-
39
  wp_enqueue_script( 'htcc_admin_js', plugins_url( 'admin/assets/js/admin.js', HTCC_PLUGIN_FILE ), array( 'wp-color-picker', 'jquery' ), HTCC_VERSION, true );
40
  wp_enqueue_script( 'htcc_admin_md_js', plugins_url( 'admin/assets/js/materialize.min.js', HTCC_PLUGIN_FILE ), array('wp-color-picker', 'jquery' ), HTCC_VERSION, true );
41
 
1
  <?php
2
  /**
3
+ * Admin - enqueue sytle, script
4
  */
5
 
6
 
12
 
13
 
14
  function enqueue( $hook ) {
15
+
16
  // echo $hook;
17
  if( 'toplevel_page_wp-chatbot' == $hook || 'wp-chatbot_page_wp-chatbot-features' == $hook || 'wp-chatbot_page_wp-chatbot-actions' == $hook || 'wp-chatbot_page_wp-chatbot-pro-woo' == $hook ) {
18
+
19
+
20
  // color picker..
21
  // wp_enqueue_style( 'htcc_admin_color_picker_styles', plugins_url( 'admin/assets/color/colors.css', HTCC_PLUGIN_FILE ), '', HTCC_VERSION );
22
  // wp_enqueue_script( 'htcc_admin_color_picker_js', plugins_url( 'admin/assets/color/colors.js', HTCC_PLUGIN_FILE ), array( 'jquery', 'wp-color-picker', 'htcc_admin_md_js' ), HTCC_VERSION );
31
 
32
  wp_enqueue_style( 'htcc_admin_styles', plugins_url( 'admin/assets/css/admin-styles.css', HTCC_PLUGIN_FILE ), '', HTCC_VERSION );
33
  wp_enqueue_style( 'htcc_admin_md_styles', plugins_url( 'admin/assets/css/materialize.min.css', HTCC_PLUGIN_FILE ), '', HTCC_VERSION );
34
+
35
  wp_enqueue_style( 'wp-color-picker' );
36
  wp_enqueue_script( 'wp-color-picker');
37
 
38
+
39
  wp_enqueue_script( 'htcc_admin_js', plugins_url( 'admin/assets/js/admin.js', HTCC_PLUGIN_FILE ), array( 'wp-color-picker', 'jquery' ), HTCC_VERSION, true );
40
  wp_enqueue_script( 'htcc_admin_md_js', plugins_url( 'admin/assets/js/materialize.min.js', HTCC_PLUGIN_FILE ), array('wp-color-picker', 'jquery' ), HTCC_VERSION, true );
41
 
admin/class-htcc-lang.php CHANGED
@@ -46,88 +46,9 @@ if (!class_exists('HTCC_Lang')) :
46
  "Swedish",
47
  "Turkish",
48
  "Thai"
49
- /*'af_ZA' => 'Afrikaans',
50
- 'sq_AL' => 'Albanian',
51
- 'hy_AM' => 'Armenian',
52
- 'ar_AR' => 'Arabic',
53
- 'az_AZ' => 'Azerbaijani',
54
- 'be_BY' => 'Belarusian',
55
- 'bg_BG' => 'Bulgarian *', // tried - not worked
56
- 'bn_IN' => 'Bengali',
57
- 'bs_BA' => 'Bosnian',
58
- 'eu_ES' => 'Basque',
59
- 'ca_ES' => 'Catalan',
60
- 'cs_CZ' => 'Czech',
61
- 'hr_HR' => 'Croatian',
62
- 'da_DK' => 'Danish',
63
- 'nl_NL' => 'Dutch',
64
- 'en_US' => 'English',
65
- 'eo_EO' => 'Esperanto',
66
- 'tl_PH' => 'Filipino',
67
- 'fi_FI' => 'Finnish',
68
- 'et_EE' => 'Estonian',
69
- 'fo_FO' => 'Faroese',
70
- 'fr_FR' => 'French (France)',
71
- 'fr_CA' => 'French (Canada)',
72
- 'fy_NL' => 'Frisian',
73
- 'de_DE' => 'German',
74
- 'el_GR' => 'Greek',
75
- 'ka_GE' => 'Georgian *', // tried - not worked
76
- 'gl_ES' => 'Galician',
77
- 'he_IL' => 'Hebrew',
78
- 'hi_IN' => 'Hindi',
79
- 'hu_HU' => 'Hungarian',
80
- 'id_ID' => 'Indonesian',
81
- 'it_IT' => 'Italian',
82
- 'is_IS' => 'Icelandic',
83
- 'ga_IE' => 'Irish',
84
- 'ja_JP' => 'Japanese',
85
- 'ko_KR' => 'Korean',
86
- 'ku_TR' => 'Kurdish',
87
- 'km_KH' => 'Khmer',
88
- 'la_VA' => 'Latin',
89
- 'lt_LT' => 'Lithuanian *', // tried - not worked
90
- 'lv_LV' => 'Latvian *', // tried - not worked
91
- 'mr_IN' => 'Marathi',
92
- 'mk_MK' => 'Macedonian',
93
- 'ml_IN' => 'Malayalam',
94
- 'ms_MY' => 'Malay',
95
- 'nb_NO' => 'Norwegian (bokmal)',
96
- 'ne_NP' => 'Nepali',
97
- 'nn_NO' => 'Norwegian (nynorsk)',
98
- 'fa_IR' => 'Persian',
99
- 'pa_IN' => 'Punjabi',
100
- 'pl_PL' => 'Polish',
101
- 'ps_AF' => 'Pashto',
102
- 'pt_BR' => 'Portuguese (Brazil)',
103
- 'pt_PT' => 'Portuguese (Portugal)',
104
- 'ro_RO' => 'Romanian',
105
- 'ru_RU' => 'Russian',
106
- 'es_LA' => 'Spanish',
107
- 'es_ES' => 'Spanish (Spain)',
108
- 'sk_SK' => 'Slovak *', // tried - not worked
109
- 'sl_SI' => 'Slovenian',
110
- 'sr_RS' => 'Serbian',
111
- 'sv_SE' => 'Swedish',
112
- 'sw_KE' => 'Swahili',
113
- 'ta_IN' => 'Tamil',
114
- 'te_IN' => 'Telugu',
115
- 'th_TH' => 'Thai',
116
- 'tr_TR' => 'Turkish',
117
- 'uk_UA' => 'Ukrainian',
118
- 'vi_VN' => 'Vietnamese',
119
- 'cy_GB' => 'Welsh',
120
- 'zh_CN' => 'zh_CN Simplified Chinese (China)',
121
- 'zh_HK' => 'zh_HK Traditional Chinese (Hong Kong)',
122
- 'zh_TW' => 'zh_TW Traditional Chinese (Taiwan)',*/
123
  );
124
 
125
 
126
- // http://www.loc.gov/standards/iso639-2/php/code_list.php
127
- // https://developers.facebook.com/docs/internationalization/
128
- // https://developers.facebook.com/apps/156589268405824/app-details/localize/
129
- // https://developers.facebook.com/docs/messenger-platform/messenger-profile/supported-locales ( but not all as expected )
130
-
131
  }
132
 
133
  endif; // END class_exists check
46
  "Swedish",
47
  "Turkish",
48
  "Thai"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  );
50
 
51
 
 
 
 
 
 
52
  }
53
 
54
  endif; // END class_exists check
admin/commons/ht-cc-admin-fb-button-connected.php CHANGED
@@ -17,7 +17,6 @@ $logout_button = [
17
  ];
18
 
19
  HT_CC::view('ht-cc-admin-logout-button', $logout_button);
20
-
21
  ?>
22
 
23
  <h5>Connected Facebook page</h5>
17
  ];
18
 
19
  HT_CC::view('ht-cc-admin-logout-button', $logout_button);
 
20
  ?>
21
 
22
  <h5>Connected Facebook page</h5>
admin/commons/ht-cc-admin-fb-button-error.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ *
6
+ * This file is used to markup the admin-facing aspects of the plugin.
7
+ *
8
+ *
9
+ */
10
+ ?>
11
+
12
+ <div class="notice notice-error is-dismissible">
13
+ <p><?php echo $text; ?></p>
14
+ </div>
admin/settings_page.php CHANGED
@@ -28,8 +28,11 @@ if (!defined('ABSPATH')) exit;
28
  </div>
29
  </div>
30
  <?php
31
- submit_button('Save Changes');
32
- ?>
 
 
 
33
  </div>
34
  </form>
35
  </div>
28
  </div>
29
  </div>
30
  <?php
31
+ if ($this->stepdis == "open"){
32
+ submit_button('Save Changes');
33
+ }
34
+ ?>
35
+
36
  </div>
37
  </form>
38
  </div>
inc/MobileMonkeyApi.php CHANGED
@@ -133,7 +133,7 @@ class MobileMonkeyApi
133
  } else {
134
  $user_email = get_option('admin_email', '');
135
  }
136
- return $this->getApiDomain() . 'wordpress/auth?callback="' . add_query_arg(['page' => $this->plugin_name], admin_url('admin.php')) . '"&email=' . $user_email . '&v=' . HTCC_VERSION;
137
  }
138
 
139
  public function connectMobileMonkey()
@@ -172,25 +172,13 @@ class MobileMonkeyApi
172
  ],
173
  'method' => 'GET',
174
  ];
175
- $response = wp_remote_post($this->getApiDomain() . 'api/facebook_pages/' . $this->getInternalPageId($page_id), $args);
176
- $content = wp_remote_retrieve_body($response);
177
- $connect_response = json_decode($content);
178
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
179
  return $connect_response->wordpress_settings->mm_only_mode;
180
- } elseif ($connect_response->error_code) {
181
- $this->renderNotice('Error code: ' . $connect_response->error_code);
182
- if (!empty($connect_response->errors)) {
183
- foreach ($connect_response->errors as $error) {
184
- $this->renderNotice('Error: ' . $error);
185
- }
186
- }
187
- } elseif (!empty($connect_response->errors)) {
188
- foreach ($connect_response->errors as $error) {
189
- $this->renderNotice('Error: ' . $error);
190
- }
191
- } else {
192
- $this->renderNotice('API communication error. Unable to receive MM Only State.');
193
  }
 
194
  }
195
 
196
 
@@ -214,7 +202,7 @@ class MobileMonkeyApi
214
  ],
215
  'method' => 'POST',
216
  ];
217
- $response = wp_remote_post($this->getApiDomain() . 'api/facebook_pages', $args);
218
  $content = wp_remote_retrieve_body($response);
219
  $connect_response = json_decode($content);
220
  if (json_last_error() !== JSON_ERROR_NONE) {
@@ -224,39 +212,43 @@ class MobileMonkeyApi
224
  $options = get_option('htcc_options', array());
225
  $options['fb_page_id'] = $connect_response->facebook_page->remote_id;
226
  $options['fb_internal_page_id'] = $connect_response->facebook_page->id;
 
227
  if ($connect_response->facebook_page->active_bot_id) {
228
- $ref_cont = $this->getBotRef($connect_response->facebook_page->active_bot_id);
229
- $ref = stristr($ref_cont->test_link, '=');
230
- $options['ref'] = str_replace("=", "", $ref);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  if ($connect_response->welcome_message) {
232
- $options['fb_welcome_message'] = $connect_response->welcome_message;
233
  } else {
234
  $options['fb_welcome_message'] = '';
235
  }
236
  $options['fb_sdk_lang'] = $this->getLanguage($connect_response->facebook_page->remote_id);
237
  update_option('htcc_options', $options);
238
- $test = $this->getWidgets($connect_response->facebook_page->remote_id);
239
-
240
- if ($test) {
241
- foreach ($test->widgets as $key => $value) {
242
- if ($value->type == "quick_question") {
243
- $key += 1;
244
- $value_new['fb_answer' . $key . ''] = $value->config->body;
245
- }
246
- if ($value->type == 'text') {
247
- $value_new['thank_message'] = $value->config->body;
248
- }
249
- if ($value->type == 'email') {
250
- $value_new['email'] = $value->config->recipient;
251
- }
252
- }
253
- }
254
- $value_new['fb_as_state'] = 0;
255
- update_option('htcc_as_options', $value_new);
256
-
257
  $this->refreshSettingsPage();
258
  return true;
259
  }
 
260
  }
261
 
262
  } elseif ($connect_response->error_code) {
@@ -288,29 +280,13 @@ class MobileMonkeyApi
288
  ],
289
  'body' => json_encode([
290
  'enabled' => $state,
291
- 'fb_page_remote_id' => $fb_page_id
 
292
  ]),
293
  'method' => 'PUT',
294
  ];
295
- $response = wp_remote_request($this->getApiDomain() . 'api/wordpress_settings/answering_service?v=' . HTCC_VERSION, $args);
296
- $content = wp_remote_retrieve_body($response);
297
- $connect_response = json_decode($content);
298
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
299
- // Succesfully updated welcome message for $options['fb_page_id'] page
300
- } elseif ($connect_response->error_code) {
301
- $this->renderNotice('Error code: ' . $connect_response->error_code);
302
- if (!empty($connect_response->errors)) {
303
- foreach ($connect_response->errors as $error) {
304
- $this->renderNotice('Error: ' . $error);
305
- }
306
- }
307
- } elseif (!empty($connect_response->errors)) {
308
- foreach ($connect_response->errors as $error) {
309
- $this->renderNotice('Error: ' . $error);
310
- }
311
- } else {
312
- $this->renderNotice('API communication error. Unable to save `AS` State');
313
- }
314
  }
315
 
316
  public function disconnectPage()
@@ -329,7 +305,7 @@ class MobileMonkeyApi
329
  ],
330
  'method' => 'DELETE',
331
  ];
332
- $response = wp_remote_request($this->getApiDomain() . '/api/facebook_pages/' . $pageId, $args);
333
  $content = wp_remote_retrieve_body($response);
334
  $connect_response = json_decode($content);
335
  if (empty($content)) {
@@ -376,10 +352,13 @@ class MobileMonkeyApi
376
  'headers' => [
377
  'Authorization' => $this->getToken()
378
  ],
 
 
 
379
  ];
380
  $pagesObj = NULL;
381
  $pages = [];
382
- $response = wp_remote_get($this->getApiDomain() . '/api/facebook_pages/available_options?src=' . $this->getSrc(), $args);
383
  $content = wp_remote_retrieve_body($response);
384
  if (!empty($content)) {
385
  $pagesObj = json_decode($content);
@@ -419,6 +398,7 @@ class MobileMonkeyApi
419
 
420
  $activePage = [];
421
  $pages = $this->getPages();
 
422
  $options = get_option('htcc_options', array());
423
  $active_remote_page_id = $options['fb_page_id'];
424
 
@@ -428,11 +408,15 @@ class MobileMonkeyApi
428
  $activePage['bot_id'] = $page['bot_id'];
429
  $activePage['name'] = $page['name'];
430
  $activePage['id'] = $page['id'];
 
431
  $activePage['path'] = add_query_arg([
432
  'page' => $this->plugin_name,
433
  'disconnect' => $page['id'],
434
  ], admin_url('admin.php'));
435
-
 
 
 
436
  update_option($this->option_prefix . 'active_page_remote_id', $page['remote_id']);
437
  $this->setActivePageId($page['id']);
438
  $this->setActiveBotId($page['bot_id']);
@@ -471,24 +455,7 @@ class MobileMonkeyApi
471
  ];
472
 
473
  $response = wp_remote_request($this->getApiDomain() . '/api/user/', $args);
474
- $content = wp_remote_retrieve_body($response);
475
- $connect_response = json_decode($content);
476
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
477
- // Email successfully sent
478
- } elseif ($connect_response->error_code) {
479
- $this->renderNotice('Error code: ' . $connect_response->error_code);
480
- if (!empty($connect_response->errors)) {
481
- foreach ($connect_response->errors as $error) {
482
- $this->renderNotice('Error: ' . $error);
483
- }
484
- }
485
- } elseif (!empty($connect_response->errors)) {
486
- foreach ($connect_response->errors as $error) {
487
- $this->renderNotice('Error: ' . $error);
488
- }
489
- } else {
490
- $this->renderNotice('API communication error. Unable to send user email.');
491
- }
492
  }
493
 
494
  public function getWelcomeMessage($remote_id)
@@ -498,28 +465,16 @@ class MobileMonkeyApi
498
  'headers' => [
499
  'Authorization' => $this->getToken(),
500
  'Content-Type' => 'application/json',
 
 
 
501
  ]
502
  ];
503
 
504
- $response = wp_remote_get($this->getApiDomain() . 'api/wordpress_settings/welcome_message?fb_page_remote_id=' . $remote_id . '&v=' . HTCC_VERSION, $args);
505
- $content = wp_remote_retrieve_body($response);
506
- $connect_response = json_decode($content);
507
-
508
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
509
- return str_replace('"', '', $content);
510
- } elseif ($connect_response->error_code) {
511
- $this->renderNotice('Error code: ' . $connect_response->error_code);
512
- if (!empty($connect_response->errors)) {
513
- foreach ($connect_response->errors as $error) {
514
- $this->renderNotice('Error: ' . $error);
515
- }
516
- }
517
- } elseif (!empty($connect_response->errors)) {
518
- foreach ($connect_response->errors as $error) {
519
- $this->renderNotice('Error: ' . $error);
520
- }
521
- } else {
522
- $this->renderNotice('API communication error. Unable to receive Welcome Message');
523
  }
524
  }
525
 
@@ -533,29 +488,14 @@ class MobileMonkeyApi
533
  ],
534
  'body' => json_encode([
535
  'body' => $new_welcome_message,
536
- 'fb_page_remote_id' => $fb_page_id
 
537
  ]),
538
  'method' => 'PUT',
539
  ];
540
- $response = wp_remote_request($this->getApiDomain() . 'api/wordpress_settings/welcome_message?v=' . HTCC_VERSION, $args);
541
- $content = wp_remote_retrieve_body($response);
542
- $connect_response = json_decode($content);
543
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
544
- // Succesfully updated welcome message for $options['fb_page_id'] page
545
- } elseif ($connect_response->error_code) {
546
- $this->renderNotice('Error code: ' . $connect_response->error_code);
547
- if (!empty($connect_response->errors)) {
548
- foreach ($connect_response->errors as $error) {
549
- $this->renderNotice('Error: ' . $error);
550
- }
551
- }
552
- } elseif (!empty($connect_response->errors)) {
553
- foreach ($connect_response->errors as $error) {
554
- $this->renderNotice('Error: ' . $error);
555
- }
556
- } else {
557
- $this->renderNotice('API communication error. Unable to Update Welcome Message');
558
- }
559
 
560
  }
561
 
@@ -569,31 +509,18 @@ class MobileMonkeyApi
569
  ],
570
  'body' => json_encode([
571
  'language' => $new_language,
572
- 'fb_page_remote_id' => $fb_page_id
 
573
  ]),
574
  'method' => 'PUT',
575
  ];
576
-
577
- $response = wp_remote_request($this->getApiDomain() . 'api/wordpress_settings/language?v=' . HTCC_VERSION, $args);
578
- $content = wp_remote_retrieve_body($response);
579
- $connect_response = json_decode($content);
580
-
581
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
582
- } elseif ($connect_response->error_code) {
583
- $this->renderNotice('Error code: ' . $connect_response->error_code);
584
- if (!empty($connect_response->errors)) {
585
- foreach ($connect_response->errors as $error) {
586
- $this->renderNotice('Error: ' . $error);
587
- }
588
- }
589
- } elseif (!empty($connect_response->errors)) {
590
- foreach ($connect_response->errors as $error) {
591
- $this->renderNotice('Error: ' . $error);
592
- }
593
- } else {
594
- $this->renderNotice('API communication error. Unable to update Language');
595
  }
596
-
597
  }
598
 
599
  public function getLanguage($remote_id)
@@ -603,28 +530,16 @@ class MobileMonkeyApi
603
  'headers' => [
604
  'Authorization' => $this->getToken(),
605
  'Content-Type' => 'application/json',
 
 
 
606
  ]
607
  ];
608
 
609
- $response = wp_remote_get($this->getApiDomain() . 'api/wordpress_settings/language?fb_page_remote_id=' . $remote_id . '&v=' . HTCC_VERSION, $args);
610
- $content = wp_remote_retrieve_body($response);
611
- $connect_response = json_decode($content);
612
-
613
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
614
- return str_replace('"', '', $content);
615
- } elseif ($connect_response->error_code) {
616
- $this->renderNotice('Error code: ' . $connect_response->error_code);
617
- if (!empty($connect_response->errors)) {
618
- foreach ($connect_response->errors as $error) {
619
- $this->renderNotice('Error: ' . $error);
620
- }
621
- }
622
- } elseif (!empty($connect_response->errors)) {
623
- foreach ($connect_response->errors as $error) {
624
- $this->renderNotice('Error: ' . $error);
625
- }
626
- } else {
627
- $this->renderNotice('API communication error. Unable to get Language');
628
  }
629
  }
630
 
@@ -635,25 +550,17 @@ class MobileMonkeyApi
635
  'headers' => [
636
  'Authorization' => $this->getToken(),
637
  'Content-Type' => 'application/json',
 
 
 
638
  ]
639
  ];
640
 
641
- $response = wp_remote_get($this->getApiDomain() . 'api/wordpress_settings/answering_service?fb_page_remote_id=' . $remote_id . '&v=' . HTCC_VERSION, $args);
642
- $content = wp_remote_retrieve_body($response);
643
- $connect_response = json_decode($content);
644
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
645
- return json_decode($content);
646
- } elseif ($connect_response->error_code) {
647
- $this->renderNotice('Error code: ' . $connect_response->error_code);
648
- if (!empty($connect_response->errors)) {
649
- foreach ($connect_response->errors as $error) {
650
- $this->renderNotice('Error: ' . $error);
651
- }
652
- }
653
- } elseif (!empty($connect_response->errors)) {
654
- foreach ($connect_response->errors as $error) {
655
- $this->renderNotice('Error: ' . $error);
656
- }
657
  } else {
658
  return false;
659
  }
@@ -668,29 +575,14 @@ class MobileMonkeyApi
668
  'Authorization' => $this->getToken(),
669
  'Content-Type' => 'application/json',
670
  ],
671
- 'body' => json_encode(['config' => $argsas, 'src' => 'wordpress']),
672
  'method' => 'PATCH',
673
  ];
674
  $response = wp_remote_request($this->getApiDomain() . 'api/widgets/' . $object->id . '', $args);
675
- $content = wp_remote_retrieve_body($response);
676
- $connect_response = json_decode($content);
677
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
678
  return $response;
679
- } elseif ($connect_response->error_code) {
680
- $this->renderNotice('Error code: ' . $connect_response->error_code);
681
- if (!empty($connect_response->errors)) {
682
- foreach ($connect_response->errors as $error) {
683
- $this->renderNotice('Error: ' . $error);
684
- }
685
- }
686
- } elseif (!empty($connect_response->errors)) {
687
- foreach ($connect_response->errors as $error) {
688
- $this->renderNotice('Error: ' . $error);
689
- }
690
- } else {
691
- $this->renderNotice('API communication error. Unable to update Widgets.');
692
  }
693
-
694
  }
695
 
696
  public function getBotRef($bot_id)
@@ -701,26 +593,16 @@ class MobileMonkeyApi
701
  'Authorization' => $this->getToken(),
702
  'Content-Type' => 'application/json; charset=utf-8',
703
  ],
 
 
 
704
  'method' => 'GET',
705
  ];
706
  $response = wp_remote_post($this->getApiDomain() . 'api/bots/' . $bot_id, $args);
707
- $content = wp_remote_retrieve_body($response);
708
- $connect_response = json_decode($content);
709
- if (isset($response["response"]["code"]) && $response["response"]["code"] == 200) {
710
  return $connect_response;
711
- } elseif ($connect_response->error_code) {
712
- $this->renderNotice('Error code: ' . $connect_response->error_code);
713
- if (!empty($connect_response->errors)) {
714
- foreach ($connect_response->errors as $error) {
715
- $this->renderNotice('Error: ' . $error);
716
- }
717
- }
718
- } elseif (!empty($connect_response->errors)) {
719
- foreach ($connect_response->errors as $error) {
720
- $this->renderNotice('Error: ' . $error);
721
- }
722
- } else {
723
- $this->renderNotice('API communication error. Unable to receive BotRef.');
724
  }
725
  }
726
 
@@ -759,14 +641,48 @@ class MobileMonkeyApi
759
  return false;
760
  }
761
 
762
- private function renderNotice($text)
763
  {
764
  $setting_page_args = [
765
  'text' => $text,
766
  ];
767
  HT_CC::view('ht-cc-admin-fb-button-notice', $setting_page_args);
768
  }
 
 
 
 
 
 
 
769
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
770
  public function debug()
771
  {
772
  $options = [];
@@ -834,6 +750,72 @@ class MobileMonkeyApi
834
 
835
  }
836
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
837
  private function getData()
838
  {
839
  $get = $this->getArgs();
133
  } else {
134
  $user_email = get_option('admin_email', '');
135
  }
136
+ return $this->getApiDomain() . 'wordpress/auth?callback="' . add_query_arg(['page' => $this->plugin_name], admin_url('admin.php')) . '"&email=' . $user_email . '&v=' . HTCC_VERSION.'.2';
137
  }
138
 
139
  public function connectMobileMonkey()
172
  ],
173
  'method' => 'GET',
174
  ];
175
+ $response = wp_remote_post($this->getApiDomain() . 'api/facebook_pages/' . $this->getInternalPageId($page_id).'?v=' . HTCC_VERSION.'.2', $args);
176
+ $error = $this->ErrorHandler($response,'MM Only State','get');
177
+ if ($error) {
178
+ $connect_response = json_decode($error);
179
  return $connect_response->wordpress_settings->mm_only_mode;
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  }
181
+
182
  }
183
 
184
 
202
  ],
203
  'method' => 'POST',
204
  ];
205
+ $response = wp_remote_post($this->getApiDomain() . 'api/facebook_pages?v=' . HTCC_VERSION.'.2', $args);
206
  $content = wp_remote_retrieve_body($response);
207
  $connect_response = json_decode($content);
208
  if (json_last_error() !== JSON_ERROR_NONE) {
212
  $options = get_option('htcc_options', array());
213
  $options['fb_page_id'] = $connect_response->facebook_page->remote_id;
214
  $options['fb_internal_page_id'] = $connect_response->facebook_page->id;
215
+ update_option('htcc_options', $options);
216
  if ($connect_response->facebook_page->active_bot_id) {
217
+ $custom_settings = $this->getCustomChatSettings($options['fb_page_id']);
218
+ foreach ($custom_settings as $key=>$value){
219
+ $options['fb_'.$key]=$value;
220
+ }
221
+ update_option('htcc_fb_js_src', $custom_settings->js_src);
222
+ if (!$this->mmOnlyCheck($options['fb_page_id'])){
223
+ $test = $this->getWidgets($connect_response->facebook_page->remote_id);
224
+ if ($test) {
225
+ foreach ($test->widgets as $key => $value) {
226
+ if ($value->type == "quick_question") {
227
+ $key += 1;
228
+ $value_new['fb_answer' . $key . ''] = $value->config->body;
229
+ }
230
+ if ($value->type == 'text') {
231
+ $value_new['thank_message'] = $value->config->body;
232
+ }
233
+ if ($value->type == 'email') {
234
+ $value_new['email'] = $value->config->recipient;
235
+ }
236
+ }
237
+ }
238
+ $value_new['fb_as_state'] = 0;
239
+ update_option('htcc_as_options', $value_new);
240
+ }
241
  if ($connect_response->welcome_message) {
242
+ $options['fb_welcome_message'] = $connect_response->welcome_message->body;
243
  } else {
244
  $options['fb_welcome_message'] = '';
245
  }
246
  $options['fb_sdk_lang'] = $this->getLanguage($connect_response->facebook_page->remote_id);
247
  update_option('htcc_options', $options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  $this->refreshSettingsPage();
249
  return true;
250
  }
251
+
252
  }
253
 
254
  } elseif ($connect_response->error_code) {
280
  ],
281
  'body' => json_encode([
282
  'enabled' => $state,
283
+ 'fb_page_remote_id' => $fb_page_id,
284
+ 'src' => $this->getSrc()
285
  ]),
286
  'method' => 'PUT',
287
  ];
288
+ $response = wp_remote_request($this->getApiDomain() . 'api/wordpress_settings/answering_service?v=' . HTCC_VERSION.'.2', $args);
289
+ $this->ErrorHandler($response,'AS State Save','');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  }
291
 
292
  public function disconnectPage()
305
  ],
306
  'method' => 'DELETE',
307
  ];
308
+ $response = wp_remote_request($this->getApiDomain() . '/api/facebook_pages/' . $pageId.'?v=' . HTCC_VERSION.'.2', $args);
309
  $content = wp_remote_retrieve_body($response);
310
  $connect_response = json_decode($content);
311
  if (empty($content)) {
352
  'headers' => [
353
  'Authorization' => $this->getToken()
354
  ],
355
+ 'body' =>[
356
+ 'src' => $this->getSrc()
357
+ ]
358
  ];
359
  $pagesObj = NULL;
360
  $pages = [];
361
+ $response = wp_remote_get($this->getApiDomain() . '/api/facebook_pages/available_options?src=' . $this->getSrc().'&v=' . HTCC_VERSION.'.2', $args);
362
  $content = wp_remote_retrieve_body($response);
363
  if (!empty($content)) {
364
  $pagesObj = json_decode($content);
398
 
399
  $activePage = [];
400
  $pages = $this->getPages();
401
+
402
  $options = get_option('htcc_options', array());
403
  $active_remote_page_id = $options['fb_page_id'];
404
 
408
  $activePage['bot_id'] = $page['bot_id'];
409
  $activePage['name'] = $page['name'];
410
  $activePage['id'] = $page['id'];
411
+ if ($page['id']){
412
  $activePage['path'] = add_query_arg([
413
  'page' => $this->plugin_name,
414
  'disconnect' => $page['id'],
415
  ], admin_url('admin.php'));
416
+ }else {
417
+ return false;
418
+ break;
419
+ }
420
  update_option($this->option_prefix . 'active_page_remote_id', $page['remote_id']);
421
  $this->setActivePageId($page['id']);
422
  $this->setActiveBotId($page['bot_id']);
455
  ];
456
 
457
  $response = wp_remote_request($this->getApiDomain() . '/api/user/', $args);
458
+ $this->ErrorHandler($response,'User Email','put');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  }
460
 
461
  public function getWelcomeMessage($remote_id)
465
  'headers' => [
466
  'Authorization' => $this->getToken(),
467
  'Content-Type' => 'application/json',
468
+ ],
469
+ 'body' => [
470
+ 'src' => $this->getSrc()
471
  ]
472
  ];
473
 
474
+ $response = wp_remote_get($this->getApiDomain() . 'api/wordpress_settings/welcome_message?fb_page_remote_id=' . $remote_id . '&v=' . HTCC_VERSION.'.2', $args);
475
+ $error = ($this->ErrorHandler($response,'Welcome Message','get'));
476
+ if ($error) {
477
+ return str_replace('"', '', $error);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  }
479
  }
480
 
488
  ],
489
  'body' => json_encode([
490
  'body' => $new_welcome_message,
491
+ 'fb_page_remote_id' => $fb_page_id,
492
+ 'src' => $this->getSrc()
493
  ]),
494
  'method' => 'PUT',
495
  ];
496
+ $response = wp_remote_request($this->getApiDomain() . 'api/wordpress_settings/welcome_message?v=' . HTCC_VERSION.'.2', $args);
497
+ $this->ErrorHandler($response,'Welcome Message','put');
498
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
 
500
  }
501
 
509
  ],
510
  'body' => json_encode([
511
  'language' => $new_language,
512
+ 'fb_page_remote_id' => $fb_page_id,
513
+ 'src' => $this->getSrc()
514
  ]),
515
  'method' => 'PUT',
516
  ];
517
+ $fb_lang = HTCC_Lang::$fb_lang;
518
+ if (in_array($new_language, $fb_lang)){
519
+ $response = wp_remote_request($this->getApiDomain() . 'api/wordpress_settings/language?v=' . HTCC_VERSION.'.2', $args);
520
+ }else {
521
+ $this->renderNotice('Incorrect Language Value');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
522
  }
523
+ $this->ErrorHandler($response,'Language','put');
524
  }
525
 
526
  public function getLanguage($remote_id)
530
  'headers' => [
531
  'Authorization' => $this->getToken(),
532
  'Content-Type' => 'application/json',
533
+ ],
534
+ 'body' => [
535
+ 'src' => $this->getSrc()
536
  ]
537
  ];
538
 
539
+ $response = wp_remote_get($this->getApiDomain() . 'api/wordpress_settings/language?fb_page_remote_id=' . $remote_id . '&v=' . HTCC_VERSION.'.2', $args);
540
+ $error = ($this->ErrorHandler($response,'Language','get'));
541
+ if ($error) {
542
+ return str_replace('"', '', $error);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  }
544
  }
545
 
550
  'headers' => [
551
  'Authorization' => $this->getToken(),
552
  'Content-Type' => 'application/json',
553
+ ],
554
+ 'body' => [
555
+ 'src' => $this->getSrc()
556
  ]
557
  ];
558
 
559
+ $response = wp_remote_get($this->getApiDomain() . 'api/wordpress_settings/answering_service?fb_page_remote_id=' . $remote_id . '&v=' . HTCC_VERSION.'.2', $args);
560
+ $error = $this->ErrorHandler($response,'Widget','get');
561
+ if ($error) {
562
+ $connect_response = json_decode($error);
563
+ return $connect_response;
 
 
 
 
 
 
 
 
 
 
 
564
  } else {
565
  return false;
566
  }
575
  'Authorization' => $this->getToken(),
576
  'Content-Type' => 'application/json',
577
  ],
578
+ 'body' => json_encode(['config' => $argsas, 'src' => $this->getSrc()]),
579
  'method' => 'PATCH',
580
  ];
581
  $response = wp_remote_request($this->getApiDomain() . 'api/widgets/' . $object->id . '', $args);
582
+ $error = ($this->ErrorHandler($response,'Widget','put'));
583
+ if ($error) {
 
584
  return $response;
 
 
 
 
 
 
 
 
 
 
 
 
 
585
  }
 
586
  }
587
 
588
  public function getBotRef($bot_id)
593
  'Authorization' => $this->getToken(),
594
  'Content-Type' => 'application/json; charset=utf-8',
595
  ],
596
+ 'body' => [
597
+ 'src' => $this->getSrc()
598
+ ],
599
  'method' => 'GET',
600
  ];
601
  $response = wp_remote_post($this->getApiDomain() . 'api/bots/' . $bot_id, $args);
602
+ $error = ($this->ErrorHandler($response,'Bot Ref','get'));
603
+ if ($error) {
604
+ $connect_response = json_decode($error);
605
  return $connect_response;
 
 
 
 
 
 
 
 
 
 
 
 
 
606
  }
607
  }
608
 
641
  return false;
642
  }
643
 
644
+ public function renderNotice($text)
645
  {
646
  $setting_page_args = [
647
  'text' => $text,
648
  ];
649
  HT_CC::view('ht-cc-admin-fb-button-notice', $setting_page_args);
650
  }
651
+ public function renderError($text)
652
+ {
653
+ $setting_page_args = [
654
+ 'text' => $text,
655
+ ];
656
+ HT_CC::view('ht-cc-admin-fb-button-error', $setting_page_args);
657
+ }
658
 
659
+ public function settingSaveError($type)
660
+ {
661
+ $text = "";
662
+ switch ($type){
663
+ case "AS":
664
+ $text = "Changes to the Answering Service fields will not be saved if you leave the fields blank. Please include non-empty field if you wish to make a change.";
665
+ break;
666
+ case "email":
667
+ $text = "Validation failed: Invalid recipient email address(es)";
668
+ break;
669
+ case "welcome_message":
670
+ $text = "Changes to the Welcome Message field will not be saved if you leave the fields blank. Please include non-empty field if you wish to make a change";
671
+ break;
672
+ case "delay_length":
673
+ $text = "Greeting Dialog Delay shouldn't exceed 9 digits.";
674
+ break;
675
+ case "delay_0":
676
+ $text = "Greeting Dialog Delay cannot be lower than 1 second";
677
+ break;
678
+ }
679
+ add_settings_error(
680
+ 'htcc_setting_group', // setting name
681
+ '', //
682
+ __("$text", 'wp-chatbot'),
683
+ 'error' // type of notify
684
+ );
685
+ }
686
  public function debug()
687
  {
688
  $options = [];
750
 
751
  }
752
 
753
+
754
+ public function updateCustomChatSettings($new_value, $fb_page_id)
755
+ {
756
+ $args = [
757
+ 'timeout' => 10,
758
+ 'headers' => [
759
+ 'Authorization' => $this->getToken(),
760
+ 'Content-Type' => 'application/json',
761
+ ],
762
+ 'body' => json_encode(
763
+ $new_value
764
+ ),
765
+ 'method' => 'PUT',
766
+ ];
767
+ $response = wp_remote_request($this->getApiDomain() . '/api/wordpress_settings/customer_chat?fb_page_remote_id=' . $fb_page_id . '&v=' . HTCC_VERSION.'.2', $args);
768
+ $error = ($this->ErrorHandler($response,"custom settings",'put'));
769
+
770
+ }
771
+
772
+ public function getCustomChatSettings($remote_id)
773
+ {
774
+ $args = [
775
+ 'timeout' => 10,
776
+ 'headers' => [
777
+ 'Authorization' => $this->getToken(),
778
+ 'Content-Type' => 'application/json',
779
+ ],'method' => 'GET',
780
+ ];
781
+
782
+ $response = wp_remote_get($this->getApiDomain() . 'api/wordpress_settings/customer_chat?fb_page_remote_id=' . $remote_id . '&v=' . HTCC_VERSION.'.2', $args);
783
+ $error = ($this->ErrorHandler($response,"custom settings",'get'));
784
+ if ($error) {
785
+ return json_decode($error);
786
+ }
787
+ }
788
+
789
+
790
+ private function ErrorHandler($response,$point,$type){
791
+ $content = wp_remote_retrieve_body($response);
792
+ $connect_response = json_decode($content);
793
+ $code = wp_remote_retrieve_response_code( $response );
794
+ $type = "<style>#setting-error-settings_updated{display: none;}</style>";
795
+ if (isset($code) && $code == 200) {
796
+ $type ='';
797
+ return $content;
798
+ } elseif ($connect_response->error_code) {
799
+ $this->renderError('Error code: ' . $connect_response->error_code);
800
+ if (!empty($connect_response->errors)) {
801
+ foreach ($connect_response->errors as $error) {
802
+ $this->renderError('Error: ' . $error);
803
+ }
804
+ }
805
+ } elseif (!empty($connect_response->errors)) {
806
+ foreach ($connect_response->errors as $error) {
807
+ $this->renderError('Error: ' . $error);
808
+ }
809
+ } else {
810
+ if ($point=="Welcome Message" && $code==422){
811
+ return true;
812
+ }else {
813
+ $this->renderError('API communication error. Unable to '.$type .' ' .$point.'');
814
+ }
815
+ }
816
+ echo $type;
817
+ }
818
+
819
  private function getData()
820
  {
821
  $get = $this->getArgs();
inc/class-ht-cc.php CHANGED
@@ -134,6 +134,7 @@ class HT_CC {
134
  // $this->define( 'HTCC_VERSION', $this->version );
135
 
136
  $this->define( 'HTCC_WP_MIN_VERSION', '4.6' );
 
137
 
138
  $this->define( 'HTCC_PLUGIN_DIR', plugin_dir_path( HTCC_PLUGIN_FILE ) );
139
  $this->define( 'HTCC_PLUGIN_BASENAME', plugin_basename( HTCC_PLUGIN_FILE ) );
@@ -200,12 +201,13 @@ class HT_CC {
200
  *
201
  * plugins_loaded - Check Diff - uses when plugin updates.
202
  */
 
203
  private function hooks() {
204
 
205
  register_activation_hook( __FILE__, array( 'HTCC_Register', 'activate' ) );
206
  register_deactivation_hook( __FILE__, array( 'HTCC_Register', 'deactivate' ) );
207
  register_uninstall_hook(__FILE__, array( 'HTCC_Register', 'uninstall' ) );
208
-
209
 
210
  // initilaze classes
211
  if ( ! is_admin() ) {
@@ -220,6 +222,7 @@ class HT_CC {
220
 
221
  }
222
 
 
223
  public static function view($name, array $args = [])
224
  {
225
  $args = apply_filters('plugin_view_arguments', $args, $name);
134
  // $this->define( 'HTCC_VERSION', $this->version );
135
 
136
  $this->define( 'HTCC_WP_MIN_VERSION', '4.6' );
137
+ $this->define( 'HTCC_PHP_MIN_VERSION', '5.4' );
138
 
139
  $this->define( 'HTCC_PLUGIN_DIR', plugin_dir_path( HTCC_PLUGIN_FILE ) );
140
  $this->define( 'HTCC_PLUGIN_BASENAME', plugin_basename( HTCC_PLUGIN_FILE ) );
201
  *
202
  * plugins_loaded - Check Diff - uses when plugin updates.
203
  */
204
+
205
  private function hooks() {
206
 
207
  register_activation_hook( __FILE__, array( 'HTCC_Register', 'activate' ) );
208
  register_deactivation_hook( __FILE__, array( 'HTCC_Register', 'deactivate' ) );
209
  register_uninstall_hook(__FILE__, array( 'HTCC_Register', 'uninstall' ) );
210
+ add_action( 'activated_plugin', array( 'HTCC_Register', 'activate_plugin' ) );
211
 
212
  // initilaze classes
213
  if ( ! is_admin() ) {
222
 
223
  }
224
 
225
+
226
  public static function view($name, array $args = [])
227
  {
228
  $args = apply_filters('plugin_view_arguments', $args, $name);
inc/class-htcc-chatbot.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
  /**
3
  * check condtions to display messenger or not
4
  * get app id
@@ -6,7 +6,7 @@
6
  * and add it to script, div
7
  */
8
 
9
- if ( ! defined( 'ABSPATH' ) ) exit;
10
 
11
  if ( ! class_exists( 'HTCC_Chatbot' ) ) :
12
 
@@ -15,53 +15,43 @@ class HTCC_Chatbot {
15
  // if sdk is not added then dont add - customer chat html content
16
  public $sdk_added = 'no';
17
  public $sdk_added_for_shortcode = 'no';
18
- public $sdk_load_time = '';
19
 
20
  public $api;
21
 
22
  public function __construct()
23
  {
24
  $this->api = new MobileMonkeyApi();
 
25
  }
26
-
27
  /**
28
  * load Customer Chat SDK at header
29
  * if shortcode is used load sdk - even if hided based on other way.
30
  */
31
  public function chatbot() {
32
 
33
- // $htcc_options = get_option('htcc_options');
34
- $htcc_options = ht_cc()->variables->get_option;
35
-
36
- $fb_page_id = esc_attr( $htcc_options['fb_page_id'] );
37
- $fb_app_id = esc_attr( $htcc_options['fb_app_id'] );
38
  $log_events_value = esc_attr( $htcc_options['log_events'] );
39
- $fb_sdk_lang = esc_attr( $htcc_options['fb_sdk_lang'] );
40
- $fb_greeting_dialog_display = esc_attr( $htcc_options['greeting_dialog_display'] );
41
- $fb_greeting_dialog_delay = esc_attr( $htcc_options['greeting_dialog_delay'] );
42
- $fb_ref = esc_attr( $htcc_options['ref'] );
43
- $fb_color = esc_attr( $htcc_options['fb_color'] );
44
- $fb_greeting_login = esc_attr( $htcc_options['fb_greeting_login'] );
45
- $fb_greeting_logout = esc_attr( $htcc_options['fb_greeting_logout'] );
46
  $shortcode_name = esc_attr( $htcc_options['shortcode'] );
47
 
48
  $is_mobile = ht_cc()->device_type->is_mobile;
49
-
50
  /**
51
- * shortocode can add or have to work only on singular pages ..
52
- *
53
- * so check for shortocode in singular post ..
54
  * if shortocode exists - load sdk - and dont load cc code ..
55
- *
56
- * and for not singular post .. or is shortcode not exist ..
57
- * then check for other conditions ..
58
- * and load sdk, cc code ..
59
- *
60
  */
61
 
62
  // check shortcode exists only on singular post .. if yes load sdk .. and dont load cc code
63
  if ( is_singular() ) {
64
-
65
  global $post;
66
  if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $shortcode_name ) ) {
67
  // If shortcode is added in this page - add sdk.
@@ -71,14 +61,14 @@ class HTCC_Chatbot {
71
  }
72
  }
73
 
74
-
75
  /**
76
- * if shortcode is not added .. ( in singular post ) - then check for other conditons ..
77
  * if in a singular post - shortcode is added - then no need to check other conditons
78
- * as sdk is need for shortcode ..
79
  */
80
  if ( 'yes' !== $this->sdk_added_for_shortcode ) {
81
- // check for conditions that any thing is hiding
82
  // - other then place where shortcode added in singular posts
83
 
84
  // in pro version .. hide base on device will be handle by js
@@ -86,17 +76,16 @@ class HTCC_Chatbot {
86
  if ( 'true' !== HTCC_PRO ) {
87
  // Hide based on Devices - Mobile, Desktop
88
  if ( 'yes' == $is_mobile ) {
89
- if ( isset( $htcc_options['hideon_mobile'] ) ) {
90
  return;
91
  }
92
  } else {
93
- if ( isset( $htcc_options['hideon_desktop'] ) ) {
94
  return;
95
  }
96
  }
97
  }
98
-
99
-
100
 
101
  // single post
102
  if ( is_single() && isset( $htcc_options['hideon_posts'] ) ) {
@@ -109,39 +98,39 @@ class HTCC_Chatbot {
109
  return;
110
  }
111
  }
112
-
113
  if ( is_home() && isset( $htcc_options['hideon_homepage'] ) ) {
114
  return;
115
  }
116
-
117
  if ( is_front_page() && isset( $htcc_options['hideon_frontpage'] ) ) {
118
  return;
119
  }
120
-
121
  if ( is_category() && isset( $htcc_options['hideon_category'] ) ) {
122
  return;
123
  }
124
-
125
  if ( is_archive() && isset( $htcc_options['hideon_archive'] ) ) {
126
  return;
127
  }
128
-
129
  if ( is_404() && isset( $htcc_options['hideon_404'] ) ) {
130
  return;
131
- }
132
-
133
-
134
  $this_page_id = get_the_ID();
135
  $pages_list_tohide = $htcc_options['list_hideon_pages'];
136
  $pages_list_tohide_array = explode(',', $pages_list_tohide);
137
-
138
  if( ( is_single() || is_page() ) && in_array( $this_page_id, $pages_list_tohide_array ) ) {
139
  return;
140
  }
141
-
142
  // Hide styles on this catergorys - list
143
  $list_hideon_cat = $htcc_options['list_hideon_cat'];
144
-
145
  if( $list_hideon_cat ) {
146
  // Get current post Categorys list and create an array for that..
147
  $current_categorys_array = array();
@@ -149,9 +138,9 @@ class HTCC_Chatbot {
149
  foreach ( $current_categorys as $category ) {
150
  $current_categorys_array[] = strtolower($category->name);
151
  }
152
-
153
  $list_hideon_cat_array = explode(',', $list_hideon_cat);
154
-
155
  foreach ( $list_hideon_cat_array as $category ) {
156
  $category_trim = trim($category);
157
  if ( in_array( strtolower($category_trim), $current_categorys_array ) ) {
@@ -160,111 +149,13 @@ class HTCC_Chatbot {
160
  }
161
  }
162
  }
163
-
164
-
165
-
166
- $fb_sdk_src = "//connect.facebook.net/$fb_sdk_lang/sdk/xfbml.customerchat.js";
167
- // $fb_sdk_src = "https://connect.facebook.net/$fb_sdk_lang/sdk.js";
168
-
169
-
170
- // log events
171
- if ( 'yes' == $log_events_value ) {
172
- $log_events = true;
173
- } else {
174
- $log_events = false;
175
- }
176
-
177
-
178
- // update xfbml
179
- $xfbml = true;
180
- if ( 'true' == HTCC_PRO ) {
181
- // if pro set to false - parse form js after conditons check .. ..
182
- $xfbml = false;
183
- }
184
-
185
- // is_sdk_after_page_load
186
- // is_sdk_4_seconds
187
- $is_sdk_after_page_load = 'no';
188
- if ( isset( $htcc_options['is_sdk_after_page_load'] ) ) {
189
- $is_sdk_after_page_load = 'yes';
190
- }
191
-
192
- $sdk_load_time = '';
193
- $is_sdk_4_seconds = 'no';
194
- if ( isset( $htcc_options['is_sdk_4_seconds'] ) ) {
195
- $is_sdk_4_seconds = 'yes';
196
- $sdk_load_time = '4';
197
- }
198
-
199
-
200
- if ( isset( $htcc_options['sdk_load_time'] ) ) {
201
- $db_sdk_load_time = esc_attr( $htcc_options['sdk_load_time'] );
202
-
203
- // to avoud - if +2 is enabled and sdk_load_time value is empty.
204
- if ( '0.1' < $db_sdk_load_time ) {
205
- $sdk_load_time = $db_sdk_load_time;
206
- }
207
- }
208
-
209
- if ( 'yes' == $is_sdk_after_page_load && '0.1' <= $sdk_load_time ) {
210
- ?>
211
- <!-- Add Messenger - wp-chatbot - HoliThemes - https://www.holithemes.com/wp-chatbot -->
212
- <script>
213
- window.onload = function() {
214
- setTimeout(function(){
215
- htcc_load_fb_sdk();
216
- }, <?php echo $sdk_load_time ?> * 1000 );
217
- }
218
- function htcc_load_fb_sdk() {
219
- window.fbAsyncInit = function() {
220
- FB.init({
221
- appId : '<?php echo $fb_app_id ?>',
222
- autoLogAppEvents : <?php echo $log_events ? 'true' : 'false' ?>,
223
- xfbml : <?php echo $xfbml ? 'true' : 'false' ?>,
224
- version : 'v3.2'
225
- });
226
- };
227
-
228
- (function(d, s, id){
229
- var js, fjs = d.getElementsByTagName(s)[0];
230
- if (d.getElementById(id)) {return;}
231
- js = d.createElement(s); js.id = id;
232
- js.src = '<?php echo $fb_sdk_src ?>';
233
- fjs.parentNode.insertBefore(js, fjs);
234
- }(document, 'script', 'facebook-jssdk'));
235
- }
236
- </script>
237
- <!-- / Add Messenger - wp-chatbot - HoliThemes -->
238
- <?php
239
- } else {
240
  ?>
241
- <!-- Add Messenger - wp-chatbot - HoliThemes - https://www.holithemes.com/wp-chatbot -->
242
- <script>
243
- window.fbAsyncInit = function() {
244
- FB.init({
245
- appId : '<?php echo $fb_app_id ?>',
246
- autoLogAppEvents : <?php echo $log_events ? 'true' : 'false' ?>,
247
- xfbml : <?php echo $xfbml ? 'true' : 'false' ?>,
248
- version : 'v3.2'
249
- });
250
- };
251
-
252
- (function(d, s, id){
253
- var js, fjs = d.getElementsByTagName(s)[0];
254
- if (d.getElementById(id)) {return;}
255
- js = d.createElement(s); js.id = id;
256
- js.src = '<?php echo $fb_sdk_src ?>';
257
- fjs.parentNode.insertBefore(js, fjs);
258
- }(document, 'script', 'facebook-jssdk'));
259
- </script>
260
- <!-- / Add Messenger - wp-chatbot - HoliThemes -->
261
  <?php
262
- }
263
 
264
  // After sdk is added
265
  // for customer_chat(), var htcc_values
266
  $this->sdk_added = 'yes';
267
- $this->sdk_load_time = $sdk_load_time;
268
 
269
  }
270
 
@@ -275,31 +166,19 @@ class HTCC_Chatbot {
275
  // instead of adding the cc code in header added like this ..
276
  // can check more conditions as calling from footer .. woocommerce or so ...
277
 
278
- $htcc_options = ht_cc()->variables->get_option;
279
-
280
- $fb_page_id = esc_attr( $htcc_options['fb_page_id'] );
281
- $fb_greeting_dialog_display = esc_attr( $htcc_options['greeting_dialog_display'] );
282
- $fb_greeting_dialog_delay = esc_attr( $htcc_options['greeting_dialog_delay'] );
283
- $fb_ref = esc_attr( $htcc_options['ref'] );
284
- $fb_color = esc_attr( $htcc_options['fb_color'] );
285
- $fb_greeting_login = esc_attr( $htcc_options['fb_greeting_login'] );
286
- $fb_greeting_logout = esc_attr( $htcc_options['fb_greeting_logout'] );
287
-
288
-
289
-
290
  /**
291
  * update values for woocommerce selected pages
292
- *
293
  * placeholders .. these are final values that place in cc code ..
294
  * localize this values if need to use in js - Actions ..
295
- *
296
  */
297
  if ( 'true' == HTCC_PRO ) {
298
  include_once HTCC_PLUGIN_DIR . 'inc/pro/htcc-pro-woo.php';
299
  include_once HTCC_PLUGIN_DIR . 'inc/pro/htcc-pro-values.php';
300
  }
301
 
302
- // custom image - call this if sdk only..
303
  // call this before - checking sdk_added_for_shortcode
304
  if ( 'true' == HTCC_PRO ) {
305
  include_once HTCC_PLUGIN_DIR . 'inc/pro/htcc-pro-custom-image.php';
@@ -309,7 +188,7 @@ class HTCC_Chatbot {
309
  // make this check only after included - htcc-pro-values.php - using if statement
310
 
311
  // if sdk added for shortcode then this cc code not needed to add .. so return
312
- // cc code will added by shortocodes ..
313
  if ( 'yes' == $this->sdk_added_for_shortcode ) {
314
  return;
315
  }
@@ -318,55 +197,31 @@ class HTCC_Chatbot {
318
  return;
319
  }
320
 
321
-
322
-
323
 
324
  if ( 'true' == HTCC_PRO ) {
325
  ?>
326
-
327
- <!-- Add Messenger - wp-chatbot pro - HoliThemes - https://www.holithemes.com/wp-chatbot -->
328
  <div id="htcc-messenger" class="htcc-messenger">
329
-
330
- </div>
331
- <!-- / Add Messenger - wp-chatbot pro - HoliThemes -->
332
 
 
 
333
 
334
  <?php
335
  } else {
336
  ?>
337
-
338
- <!-- Add Messenger - wp-chatbot - HoliThemes - https://www.holithemes.com/wp-chatbot -->
339
- <div id="htcc-messenger" class="htcc-messenger">
340
- <div id="htcc-customerchat" class="fb-customerchat"
341
- page_id="<?php echo $fb_page_id ?>"
342
- theme_color="<?php echo $fb_color ?>"
343
- logged_in_greeting="<?php echo $fb_greeting_login ?>"
344
- logged_out_greeting="<?php echo $fb_greeting_logout ?>"
345
- ref="<?php echo $fb_ref ?>"
346
- greeting_dialog_display = "<?php echo $fb_greeting_dialog_display ?>"
347
- greeting_dialog_delay = "<?php echo $fb_greeting_dialog_delay ?>"
348
- >
349
- </div>
350
- </div>
351
- <!-- / Add Messenger - wp-chatbot - HoliThemes -->
352
-
353
  <?php
354
  }
355
 
356
-
357
-
358
  }
359
 
360
 
361
-
362
-
363
  }
364
 
365
-
366
-
367
  $chatbot = new HTCC_Chatbot();
368
  add_action( 'wp_head', array( $chatbot, 'chatbot' ), 1 );
369
- add_action( 'wp_footer', array( $chatbot, 'customer_chat' ) );
370
 
371
 
372
  endif; // END class_exists check
1
+ <?php
2
  /**
3
  * check condtions to display messenger or not
4
  * get app id
6
  * and add it to script, div
7
  */
8
 
9
+ if ( ! defined( 'ABSPATH' ) ) exit;
10
 
11
  if ( ! class_exists( 'HTCC_Chatbot' ) ) :
12
 
15
  // if sdk is not added then dont add - customer chat html content
16
  public $sdk_added = 'no';
17
  public $sdk_added_for_shortcode = 'no';
18
+ public $htcc_js_options;
19
 
20
  public $api;
21
 
22
  public function __construct()
23
  {
24
  $this->api = new MobileMonkeyApi();
25
+ $this->htcc_js_options = get_option('htcc_fb_js_src');
26
  }
27
+
28
  /**
29
  * load Customer Chat SDK at header
30
  * if shortcode is used load sdk - even if hided based on other way.
31
  */
32
  public function chatbot() {
33
 
34
+ $htcc_options = ht_cc()->variables->get_option;;
 
 
 
 
35
  $log_events_value = esc_attr( $htcc_options['log_events'] );
 
 
 
 
 
 
 
36
  $shortcode_name = esc_attr( $htcc_options['shortcode'] );
37
 
38
  $is_mobile = ht_cc()->device_type->is_mobile;
39
+
40
  /**
41
+ * shortocode can add or have to work only on singular pages ..
42
+ *
43
+ * so check for shortocode in singular post ..
44
  * if shortocode exists - load sdk - and dont load cc code ..
45
+ *
46
+ * and for not singular post .. or is shortcode not exist ..
47
+ * then check for other conditions ..
48
+ * and load sdk, cc code ..
49
+ *
50
  */
51
 
52
  // check shortcode exists only on singular post .. if yes load sdk .. and dont load cc code
53
  if ( is_singular() ) {
54
+
55
  global $post;
56
  if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $shortcode_name ) ) {
57
  // If shortcode is added in this page - add sdk.
61
  }
62
  }
63
 
64
+
65
  /**
66
+ * if shortcode is not added .. ( in singular post ) - then check for other conditons ..
67
  * if in a singular post - shortcode is added - then no need to check other conditons
68
+ * as sdk is need for shortcode ..
69
  */
70
  if ( 'yes' !== $this->sdk_added_for_shortcode ) {
71
+ // check for conditions that any thing is hiding
72
  // - other then place where shortcode added in singular posts
73
 
74
  // in pro version .. hide base on device will be handle by js
76
  if ( 'true' !== HTCC_PRO ) {
77
  // Hide based on Devices - Mobile, Desktop
78
  if ( 'yes' == $is_mobile ) {
79
+ if ( isset( $htcc_options['fb_hide_mobile'] ) ) {
80
  return;
81
  }
82
  } else {
83
+ if ( isset( $htcc_options['fb_hide_desktop'] ) ) {
84
  return;
85
  }
86
  }
87
  }
88
+
 
89
 
90
  // single post
91
  if ( is_single() && isset( $htcc_options['hideon_posts'] ) ) {
98
  return;
99
  }
100
  }
101
+
102
  if ( is_home() && isset( $htcc_options['hideon_homepage'] ) ) {
103
  return;
104
  }
105
+
106
  if ( is_front_page() && isset( $htcc_options['hideon_frontpage'] ) ) {
107
  return;
108
  }
109
+
110
  if ( is_category() && isset( $htcc_options['hideon_category'] ) ) {
111
  return;
112
  }
113
+
114
  if ( is_archive() && isset( $htcc_options['hideon_archive'] ) ) {
115
  return;
116
  }
117
+
118
  if ( is_404() && isset( $htcc_options['hideon_404'] ) ) {
119
  return;
120
+ }
121
+
122
+
123
  $this_page_id = get_the_ID();
124
  $pages_list_tohide = $htcc_options['list_hideon_pages'];
125
  $pages_list_tohide_array = explode(',', $pages_list_tohide);
126
+
127
  if( ( is_single() || is_page() ) && in_array( $this_page_id, $pages_list_tohide_array ) ) {
128
  return;
129
  }
130
+
131
  // Hide styles on this catergorys - list
132
  $list_hideon_cat = $htcc_options['list_hideon_cat'];
133
+
134
  if( $list_hideon_cat ) {
135
  // Get current post Categorys list and create an array for that..
136
  $current_categorys_array = array();
138
  foreach ( $current_categorys as $category ) {
139
  $current_categorys_array[] = strtolower($category->name);
140
  }
141
+
142
  $list_hideon_cat_array = explode(',', $list_hideon_cat);
143
+
144
  foreach ( $list_hideon_cat_array as $category ) {
145
  $category_trim = trim($category);
146
  if ( in_array( strtolower($category_trim), $current_categorys_array ) ) {
149
  }
150
  }
151
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  ?>
153
+ <script async="async" src='<?php echo $this->htcc_js_options?>'></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  <?php
 
155
 
156
  // After sdk is added
157
  // for customer_chat(), var htcc_values
158
  $this->sdk_added = 'yes';
 
159
 
160
  }
161
 
166
  // instead of adding the cc code in header added like this ..
167
  // can check more conditions as calling from footer .. woocommerce or so ...
168
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /**
170
  * update values for woocommerce selected pages
171
+ *
172
  * placeholders .. these are final values that place in cc code ..
173
  * localize this values if need to use in js - Actions ..
174
+ *
175
  */
176
  if ( 'true' == HTCC_PRO ) {
177
  include_once HTCC_PLUGIN_DIR . 'inc/pro/htcc-pro-woo.php';
178
  include_once HTCC_PLUGIN_DIR . 'inc/pro/htcc-pro-values.php';
179
  }
180
 
181
+ // custom image - call this if sdk only..
182
  // call this before - checking sdk_added_for_shortcode
183
  if ( 'true' == HTCC_PRO ) {
184
  include_once HTCC_PLUGIN_DIR . 'inc/pro/htcc-pro-custom-image.php';
188
  // make this check only after included - htcc-pro-values.php - using if statement
189
 
190
  // if sdk added for shortcode then this cc code not needed to add .. so return
191
+ // cc code will added by shortocodes ..
192
  if ( 'yes' == $this->sdk_added_for_shortcode ) {
193
  return;
194
  }
197
  return;
198
  }
199
 
 
 
200
 
201
  if ( 'true' == HTCC_PRO ) {
202
  ?>
203
+ <!-- Add Messenger - wp-chatbot pro - HoliThemes - https://www.holithemes.com/wp-chatbot -->
 
204
  <div id="htcc-messenger" class="htcc-messenger">
 
 
 
205
 
206
+ </div>
207
+ <!-- / Add Messenger - wp-chatbot pro - HoliThemes -->
208
 
209
  <?php
210
  } else {
211
  ?>
212
+ <!-- Add Messenger - wp-chatbot - HoliThemes - https://www.holithemes.com/wp-chatbot -->
213
+ <script async="async" src='<?php echo $this->htcc_js_options?>'></script>
214
+ <!-- / Add Messenger - wp-chatbot - HoliThemes -->
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  <?php
216
  }
217
 
 
 
218
  }
219
 
220
 
 
 
221
  }
222
 
 
 
223
  $chatbot = new HTCC_Chatbot();
224
  add_action( 'wp_head', array( $chatbot, 'chatbot' ), 1 );
 
225
 
226
 
227
  endif; // END class_exists check
inc/class-htcc-db.php CHANGED
@@ -50,12 +50,21 @@ class HTCC_db {
50
  * greeting_dialog_delay - number in seconds with in quotes
51
  *
52
  *
53
- * sdk_load_time - set time when to load sdk after page load..
54
  *
55
  * checkbox
56
  * is_sdk_after_page_load - if checked sdk will load after page load
57
  * is_sdk_4_seconds - if both checked - after page loaded, load sdk after 4 seconds
58
  */
 
 
 
 
 
 
 
 
 
59
  $values = array(
60
  // 'enable' => '1', Deprecated
61
  'fb_page_id' => '',
@@ -73,14 +82,15 @@ class HTCC_db {
73
 
74
  'greeting_dialog_display' => '',
75
  'greeting_dialog_delay' => '',
76
- 'ref' => '',
77
 
78
- 'sdk_load_time' => '4',
79
  );
80
 
81
  $db_values = get_option( 'htcc_options', array() );
82
  $update_values = array_merge($values, $db_values);
83
  update_option('htcc_options', $update_values);
 
 
 
84
  }
85
 
86
 
50
  * greeting_dialog_delay - number in seconds with in quotes
51
  *
52
  *
53
+
54
  *
55
  * checkbox
56
  * is_sdk_after_page_load - if checked sdk will load after page load
57
  * is_sdk_4_seconds - if both checked - after page loaded, load sdk after 4 seconds
58
  */
59
+ $defpage_value =array (
60
+ 'mobilemonkey_company_id' =>'',
61
+ 'mobilemonkey_active_page_remote_id' =>'',
62
+ 'mobilemonkey_active_page_id' =>'',
63
+ 'mobilemonkey_active_bot' =>'',
64
+ 'mobilemonkey_token' =>'',
65
+ 'htcc_fb_js_src' =>''
66
+ );
67
+
68
  $values = array(
69
  // 'enable' => '1', Deprecated
70
  'fb_page_id' => '',
82
 
83
  'greeting_dialog_display' => '',
84
  'greeting_dialog_delay' => '',
 
85
 
 
86
  );
87
 
88
  $db_values = get_option( 'htcc_options', array() );
89
  $update_values = array_merge($values, $db_values);
90
  update_option('htcc_options', $update_values);
91
+ foreach ($defpage_value as $key=>$value){
92
+ update_option($key, $value);
93
+ }
94
  }
95
 
96
 
inc/class-htcc-register.php CHANGED
@@ -28,11 +28,6 @@ class HTCC_Register {
28
  */
29
  public static function activate() {
30
 
31
- // check minimum version required to run this plugin
32
- if( version_compare( get_bloginfo('version'), HTCC_WP_MIN_VERSION, '<') ) {
33
- wp_die( 'please update WordPress' );
34
- }
35
-
36
  require_once HTCC_PLUGIN_DIR .'inc/class-htcc-db.php';
37
 
38
  // update plugin details to wp_options table
@@ -49,6 +44,22 @@ class HTCC_Register {
49
 
50
  }
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  /**
53
  * When plugin deactivate
54
  * @since 1.0.0
28
  */
29
  public static function activate() {
30
 
 
 
 
 
 
31
  require_once HTCC_PLUGIN_DIR .'inc/class-htcc-db.php';
32
 
33
  // update plugin details to wp_options table
44
 
45
  }
46
 
47
+ /**
48
+ * After plugin activate this function will call
49
+ *
50
+ * Redirect to setting page
51
+ *
52
+ * @since 1.0.0
53
+ * @uses activated_plugin
54
+ *
55
+ * @return void
56
+ */
57
+ public static function activate_plugin( $plugin ){
58
+ if( $plugin == plugin_basename( HTCC_PLUGIN_FILE ) ) {
59
+ exit( wp_redirect( admin_url( 'admin.php?page=wp-chatbot' ) ) );
60
+ }
61
+ }
62
+
63
  /**
64
  * When plugin deactivate
65
  * @since 1.0.0
inc/class-htcc-shortcode.php CHANGED
@@ -1,78 +1,39 @@
1
  <?php
2
  /**
3
- * shortcodes
4
  * base shorcode name is [chat]
5
  * for list of attribute support check -> shortcode_atts ( $a )
6
  *
7
  * @package ccw
8
  * @since 1.0
9
- */
10
 
11
  if ( ! defined( 'ABSPATH' ) ) exit;
12
 
13
  if ( ! class_exists( 'HTCC_Shortcode' ) ) :
14
-
15
  class HTCC_Shortcode {
16
 
17
-
18
  function shortcode($atts = [], $content = null, $shortcode = '') {
19
 
20
- // let the script add - when shortcode added
21
  // ~ any how fb won't load the sdk second time ..
22
 
23
- // $htcc_options = get_option('htcc_options');
24
- $htcc_options = ht_cc()->variables->get_option;
25
-
26
- $is_mobile = ht_cc()->device_type->is_mobile;
27
-
28
- $fb_app_id = esc_attr( $htcc_options['fb_app_id'] );
29
- $fb_page_id = esc_attr( $htcc_options['fb_page_id'] );
30
- $fb_sdk_lang = esc_attr( $htcc_options['fb_sdk_lang'] );
31
- $fb_ref = esc_attr( $htcc_options['ref'] );
32
- $fb_color = esc_attr( $htcc_options['fb_color'] );
33
- $fb_greeting_login = esc_attr( $htcc_options['fb_greeting_login'] );
34
- $fb_greeting_logout = esc_attr( $htcc_options['fb_greeting_logout'] );
35
 
36
- $fb_greeting_dialog_display = esc_attr( $htcc_options['greeting_dialog_display'] );
37
- $fb_greeting_dialog_delay = esc_attr( $htcc_options['greeting_dialog_delay'] );
38
 
39
 
40
  $a = shortcode_atts(
41
  array(
42
- 'page_id' => $fb_page_id,
43
-
44
- 'color' => $fb_color,
45
- 'logged_in_greetings' => $fb_greeting_login,
46
- 'logged_out_greetings' => $fb_greeting_logout,
47
-
48
- 'greeting_dialog_display' => $fb_greeting_dialog_display,
49
- 'greeting_dialog_delay' => $fb_greeting_dialog_delay,
50
-
51
- 'ref' => $fb_ref,
52
-
53
  'hide_mobile' => '',
54
  'hide_desktop' => '',
55
-
56
- 'app_id' => $fb_app_id, // Deprecated
57
-
58
  ), $atts, $shortcode );
59
 
60
-
61
- $app_id = $a["app_id"];
62
- $page_id = $a["page_id"];
63
- $fb_color = $a["color"];
64
- $fb_greeting_login = $a["logged_in_greetings"];
65
- $fb_greeting_logout = $a["logged_out_greetings"];
66
-
67
- $greeting_dialog_display = $a["greeting_dialog_display"];
68
- $greeting_dialog_delay = $a["greeting_dialog_delay"];
69
-
70
- $ref = $a["ref"];
71
-
72
-
73
- // hide based on device
74
- $hide_mobile = $a["hide_mobile"];
75
- $hide_desktop = $a["hide_desktop"];
76
  // if set to true then hide. - here shortcode wont use main options
77
  if ( 'yes' == $is_mobile ) {
78
  if ( "true" == $hide_mobile ) {
@@ -84,64 +45,21 @@ class HTCC_Shortcode {
84
  }
85
  }
86
 
87
-
88
-
89
- // js.src = '//connect.facebook.net/$fb_sdk_lang/sdk/xfbml.customerchat.js';
90
- // js.src = 'https://connect.facebook.net/$fb_sdk_lang/sdk.js';
91
-
92
- $o = '';
93
- // $o .= "<script>
94
- // window.fbAsyncInit = function() {
95
- // FB.init({
96
- // appId : '$app_id',
97
- // autoLogAppEvents : true,
98
- // xfbml : true,
99
- // version : 'v3.2'
100
- // });
101
- // };
102
-
103
- // (function(d, s, id){
104
- // var js, fjs = d.getElementsByTagName(s)[0];
105
- // if (d.getElementById(id)) {return;}
106
- // js = d.createElement(s); js.id = id;
107
- // js.src = '//connect.facebook.net/$fb_sdk_lang/sdk/xfbml.customerchat.js';
108
- // fjs.parentNode.insertBefore(js, fjs);
109
- // }(document, 'script', 'facebook-jssdk'));
110
- // </script>";
111
-
112
-
113
- $o .= '';
114
- $o .= '<div id="htcc-messenger-shortcode" class="htcc-messenger htcc-shortcode">
115
- <div id="htcc-customerchat" class="fb-customerchat"
116
- page_id="'.$page_id.'"
117
- theme_color="' .$fb_color. '"
118
- logged_in_greeting="' .$fb_greeting_login. '"
119
- logged_out_greeting="' .$fb_greeting_logout. '"
120
- ref="'.$ref.'"
121
- greeting_dialog_display="'.$greeting_dialog_display.'"
122
- greeting_dialog_delay="'.$greeting_dialog_delay.'"
123
- >
124
- </div>
125
- </div>';
126
- $o .= '';
127
-
128
 
129
  return $o;
130
  }
131
 
132
-
133
  // Register shortcode
134
  function htcc_shortcodes_init() {
135
 
136
  $htcc_options = get_option('htcc_options');
137
-
138
  $shortcode_name = esc_attr( $htcc_options['shortcode'] );
139
-
140
- // add_shortcode('chatbot', array( $this, 'shortcode' ));
141
  add_shortcode( $shortcode_name, array( $this, 'shortcode' ) );
142
  }
143
 
144
-
145
  }
146
 
147
  $shortcode = new HTCC_Shortcode();
1
  <?php
2
  /**
3
+ * shortcodes
4
  * base shorcode name is [chat]
5
  * for list of attribute support check -> shortcode_atts ( $a )
6
  *
7
  * @package ccw
8
  * @since 1.0
9
+ */
10
 
11
  if ( ! defined( 'ABSPATH' ) ) exit;
12
 
13
  if ( ! class_exists( 'HTCC_Shortcode' ) ) :
14
+
15
  class HTCC_Shortcode {
16
 
17
+
18
  function shortcode($atts = [], $content = null, $shortcode = '') {
19
 
20
+ // let the script add - when shortcode added
21
  // ~ any how fb won't load the sdk second time ..
22
 
23
+ $htcc_js_options = get_option('htcc_fb_js_src');
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ $is_mobile = ht_cc()->device_type->is_mobile;
 
26
 
27
 
28
  $a = shortcode_atts(
29
  array(
 
 
 
 
 
 
 
 
 
 
 
30
  'hide_mobile' => '',
31
  'hide_desktop' => '',
 
 
 
32
  ), $atts, $shortcode );
33
 
34
+ // hide based on device
35
+ $hide_mobile = $a["fb_hide_mobile"];
36
+ $hide_desktop = $a["fb_hide_desktop"];
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  // if set to true then hide. - here shortcode wont use main options
38
  if ( 'yes' == $is_mobile ) {
39
  if ( "true" == $hide_mobile ) {
45
  }
46
  }
47
 
48
+ $o="<script async='async' src=$htcc_js_options></script>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  return $o;
51
  }
52
 
 
53
  // Register shortcode
54
  function htcc_shortcodes_init() {
55
 
56
  $htcc_options = get_option('htcc_options');
57
+
58
  $shortcode_name = esc_attr( $htcc_options['shortcode'] );
59
+
 
60
  add_shortcode( $shortcode_name, array( $this, 'shortcode' ) );
61
  }
62
 
 
63
  }
64
 
65
  $shortcode = new HTCC_Shortcode();
inc/class-htcc-test-chatbot.php CHANGED
@@ -13,9 +13,6 @@ if (!class_exists('HTCC_Test_Chatbot')) :
13
  class HTCC_Test_Chatbot
14
  {
15
 
16
- public $sdk_added = 'no';
17
- public $sdk_load_time = '';
18
-
19
  public $api;
20
 
21
  public function __construct()
@@ -27,92 +24,49 @@ if (!class_exists('HTCC_Test_Chatbot')) :
27
  {
28
 
29
  $htcc_options = ht_cc()->variables->get_option;
30
- $fb_page_id = esc_attr($htcc_options['fb_page_id']);
31
- $fb_app_id = esc_attr($htcc_options['fb_app_id']);
32
- $fb_sdk_lang = esc_attr($htcc_options['fb_sdk_lang']);
33
- $fb_greeting_dialog_display = esc_attr($htcc_options['greeting_dialog_display']);
34
- $fb_greeting_dialog_delay = esc_attr($htcc_options['greeting_dialog_delay']);
35
- $fb_ref = esc_attr($htcc_options['ref']);
36
- $fb_color = esc_attr($htcc_options['fb_color']);
37
- $fb_greeting_login = esc_attr($htcc_options['fb_greeting_login']);
38
- $fb_greeting_logout = esc_attr($htcc_options['fb_greeting_logout']);
39
- $is_mobile = ht_cc()->device_type->is_mobile;
40
- $fb_sdk_src = "//connect.facebook.net/$fb_sdk_lang/sdk/xfbml.customerchat.js";
41
- $xfbml = true;
42
- if ('true' == HTCC_PRO) {
43
- $xfbml = false;
44
- }
45
-
46
- $is_sdk_after_page_load = 'no';
47
- if (isset($htcc_options['is_sdk_after_page_load'])) {
48
- $is_sdk_after_page_load = 'yes';
49
- }
50
-
51
- $sdk_load_time = '';
52
- $is_sdk_4_seconds = 'no';
53
- if (isset($htcc_options['is_sdk_4_seconds'])) {
54
- $is_sdk_4_seconds = 'yes';
55
- $sdk_load_time = '4';
56
- }
57
-
58
-
59
- if (isset($htcc_options['sdk_load_time'])) {
60
- $db_sdk_load_time = esc_attr($htcc_options['sdk_load_time']);
61
- if ('0.1' < $db_sdk_load_time) {
62
- $sdk_load_time = $db_sdk_load_time;
63
- }
64
- }
65
-
66
  ?>
67
- <!-- Add Messenger - wp-chatbot - HoliThemes - https://www.holithemes.com/wp-chatbot -->
68
- <script>
69
- window.onload = function () {
70
- jQuery(document).ready(function ($) {
71
-
72
- window.fbAsyncInit = function () {
73
- FB.init({
74
- appId: '<?php echo $fb_app_id ?>',
75
- autoLogAppEvents: false,
76
- xfbml: true,
77
- version: 'v3.2'
78
- });
79
- FB.Event.subscribe('send_to_messenger', function(e) {
80
- if (e.event === 'opt_in'){
81
- $('.test-bot-button').hide();
82
- $('.testchat').show();
83
- $("#htcc-messenger").remove();
84
- $("#htcc-customerchat").remove();
85
- $(".fb_dialog").remove();
86
- $("body").append("<div id='htcc-messenger' class='htcc-messenger'><div id='htcc-customerchat' class='fb-customerchat' greeting_dialog_delay='1' greeting_dialog_display='show' page_id='<?php echo $fb_page_id ?>' ref='<?php echo $fb_ref ?>'> </div></div>");
87
- FB.XFBML.parse($("#htcc-messenger").ref);
88
- $('.testchat').on('click',function () {
89
- FB.XFBML.parse($("#htcc-messenger").ref);
90
- $('.test-bot-button').show();
91
- $('.testchat').hide();
92
- })
93
- }
94
- });
95
- };
96
- (function (d, s, id) {
97
- var js, fjs = d.getElementsByTagName(s)[0];
98
- if (d.getElementById(id)) {
99
- return;
100
- }
101
- js = d.createElement(s);
102
- js.id = id;
103
- js.src = '<?php echo $fb_sdk_src ?>';
104
- fjs.parentNode.insertBefore(js, fjs);
105
- }(document, 'script', 'facebook-jssdk'));
106
-
107
-
108
  });
109
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- </script>
112
  <?php
113
- $this->sdk_added = 'yes';
114
- $this->sdk_load_time = $sdk_load_time;
115
-
116
  }
117
 
118
 
13
  class HTCC_Test_Chatbot
14
  {
15
 
 
 
 
16
  public $api;
17
 
18
  public function __construct()
24
  {
25
 
26
  $htcc_options = ht_cc()->variables->get_option;
27
+ $htcc_js_options = get_option('htcc_fb_js_src');
28
+ if ($_GET['page']== HTCC_PLUGIN_MAIN_MENU){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  ?>
30
+ <script src='<?php echo $htcc_js_options?>'></script>
31
+ <script>
32
+ var oldCB = window.fbAsyncInit;
33
+ window.fbAsyncInit = function () {
34
+ if (typeof oldCB === 'function') {
35
+ oldCB();
36
+ }
37
+ var waitForEl = function(selector, callback) {
38
+ if (jQuery(selector).length) {
39
+ callback();
40
+ } else {
41
+ setTimeout(function() {
42
+ waitForEl(selector, callback);
43
+ }, 100);
44
+ }
45
+ };
46
+
47
+ waitForEl('.fb_dialog', function() {
48
+ jQuery('#fb-root').hide();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  });
50
+ FB.Event.subscribe('send_to_messenger', function (e) {
51
+ if (e.event === 'opt_in') {
52
+ jQuery('#fb-root').show();
53
+ jQuery('.test-bot-button').hide();
54
+ FB.XFBML.parse();
55
+ jQuery('.testchat').show();
56
+ jQuery('.testchat').on('click',function () {
57
+ setTimeout(function(){
58
+ FB.XFBML.parse();
59
+ jQuery('.test-bot-button').show();
60
+ jQuery('.testchat').hide();
61
+ }, 5000);
62
+ })
63
+ }
64
+ });
65
+ };
66
+ </script>
67
 
 
68
  <?php
69
+ }
 
 
70
  }
71
 
72
 
readme.txt CHANGED
@@ -19,6 +19,15 @@ WP-Chatbot adds a Facebook Messenger chat widget to your website. The Messenger
19
  - 100% integration with your Facebook Business page and Facebook Messenger
20
 
21
 
 
 
 
 
 
 
 
 
 
22
 
23
  == WP-Chatbot’s Explosive Results and Huge Fans ==
24
 
@@ -88,17 +97,6 @@ By simply installing this Messenger chatbot plugin on your WordPress site, you a
88
 
89
  [Here is a complete demo of all of the default capabilities and functions of the WP-Chatbot.](https://mobilemonkey.com/wp-chatbot/demo-default/)
90
 
91
- == Screenshots ==
92
-
93
- 1. modified demo - In reality, messenger icon display's at - circle, please check demo links
94
- 2. modified demo - In reality, messenger icon display's at - circle, please check demo links
95
- 3. Setting page
96
- 4. Setting page
97
- 5. Setting page
98
- 6. Setting page
99
- 7. Shortcode
100
-
101
-
102
  ==FAQs: WP-Chatbot Plugin Questions and Answers==
103
 
104
 
19
  - 100% integration with your Facebook Business page and Facebook Messenger
20
 
21
 
22
+ == Screenshots ==
23
+
24
+ 1. modified demo - In reality, messenger icon display's at - circle, please check demo links
25
+ 2. modified demo - In reality, messenger icon display's at - circle, please check demo links
26
+ 3. Setting page
27
+ 4. Setting page
28
+ 5. Setting page
29
+ 6. Setting page
30
+ 7. Shortcode
31
 
32
  == WP-Chatbot’s Explosive Results and Huge Fans ==
33
 
97
 
98
  [Here is a complete demo of all of the default capabilities and functions of the WP-Chatbot.](https://mobilemonkey.com/wp-chatbot/demo-default/)
99
 
 
 
 
 
 
 
 
 
 
 
 
100
  ==FAQs: WP-Chatbot Plugin Questions and Answers==
101
 
102
 
wp-chatbot.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Chatbot
4
  Plugin URI: https://mobilemonkey.com/wp-chatbot/
5
  Description: Add Messenger to your website, Chatbot or live Chat using Facebook Messenger
6
- Version: 4.0.8
7
  Author: MobileMonkey
8
  Author URI: https://mobilemonkey.com/wp-chatbot/
9
  License: GPL2
@@ -17,7 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
17
 
18
  // Version - define HTCC_VERSION
19
  if ( ! defined( 'HTCC_VERSION' ) ) {
20
- define( 'HTCC_VERSION', '4.0.8' );
21
  }
22
 
23
 
3
  Plugin Name: WP Chatbot
4
  Plugin URI: https://mobilemonkey.com/wp-chatbot/
5
  Description: Add Messenger to your website, Chatbot or live Chat using Facebook Messenger
6
+ Version: 4.0.9
7
  Author: MobileMonkey
8
  Author URI: https://mobilemonkey.com/wp-chatbot/
9
  License: GPL2
17
 
18
  // Version - define HTCC_VERSION
19
  if ( ! defined( 'HTCC_VERSION' ) ) {
20
+ define( 'HTCC_VERSION', '4.0.9' );
21
  }
22
 
23