MailChimp for WooCommerce - Version 1.0.7

Version Description

Download this release

Release Info

Developer MailChimp
Plugin Icon wp plugin MailChimp for WooCommerce
Version 1.0.7
Comparing to
See all releases

Code changes from version 1.0.6 to 1.0.7

Files changed (32) hide show
  1. admin/class-mailchimp-woocommerce-admin.php +89 -3
  2. admin/partials/mailchimp-woocommerce-admin-tabs.php +27 -10
  3. admin/partials/tabs/api_key.php +2 -1
  4. admin/partials/tabs/campaign_defaults.php +2 -0
  5. admin/partials/tabs/newsletter_settings.php +39 -2
  6. admin/partials/tabs/store_info.php +1 -0
  7. admin/partials/tabs/store_sync.php +67 -21
  8. includes/api/assets/class-mailchimp-address.php +2 -2
  9. includes/api/assets/class-mailchimp-cart.php +1 -1
  10. includes/api/assets/class-mailchimp-customer.php +1 -1
  11. includes/api/class-mailchimp-api.php +24 -43
  12. includes/class-mailchimp-woocommerce-activator.php +5 -2
  13. includes/class-mailchimp-woocommerce-deactivator.php +3 -0
  14. includes/class-mailchimp-woocommerce-newsletter.php +26 -5
  15. includes/class-mailchimp-woocommerce-options.php +30 -0
  16. includes/class-mailchimp-woocommerce-service.php +88 -172
  17. includes/class-mailchimp-woocommerce.php +16 -23
  18. includes/processes/class-mailchimp-woocommerce-abstract-sync.php +3 -0
  19. includes/processes/class-mailchimp-woocommerce-process-products.php +19 -2
  20. includes/processes/class-mailchimp-woocommerce-user-submit.php +137 -0
  21. includes/slack/Contracts/Http/Interactor.php +0 -34
  22. includes/slack/Contracts/Http/Response.php +0 -26
  23. includes/slack/Contracts/Http/ResponseFactory.php +0 -15
  24. includes/slack/Core/Commander.php +0 -508
  25. includes/slack/Http/CurlInteractor.php +0 -106
  26. includes/slack/Http/SlackResponse.php +0 -84
  27. includes/slack/Http/SlackResponseFactory.php +0 -13
  28. includes/slack/Logger.php +0 -93
  29. mailchimp-woocommerce.php +76 -22
  30. public/class-mailchimp-woocommerce-public.php +4 -4
  31. public/js/mailchimp-woocommerce-public.js +137 -337
  32. public/js/mailchimp-woocommerce-public.min.js +1 -0
admin/class-mailchimp-woocommerce-admin.php CHANGED
@@ -241,6 +241,11 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
241
  case 'newsletter_settings':
242
  $data = $this->validatePostNewsletterSettings($input);
243
  break;
 
 
 
 
 
244
  }
245
 
246
  return (isset($data) && is_array($data)) ? array_merge($this->getOptions(), $data) : $this->getOptions();
@@ -377,10 +382,20 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
377
  */
378
  protected function validatePostNewsletterSettings($input)
379
  {
 
 
 
 
 
 
 
 
380
  $data = array(
381
  'mailchimp_list' => isset($input['mailchimp_list']) ? $input['mailchimp_list'] : $this->getOption('mailchimp_list', ''),
382
  'newsletter_label' => isset($input['newsletter_label']) ? $input['newsletter_label'] : $this->getOption('newsletter_label', 'Subscribe to our newsletter'),
383
  'mailchimp_auto_subscribe' => isset($input['mailchimp_auto_subscribe']) ? $input['mailchimp_auto_subscribe'] : $this->getOption('mailchimp_auto_subscribe', '0'),
 
 
384
  );
385
 
386
  if ($data['mailchimp_list'] === 'create_new') {
@@ -395,9 +410,8 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
395
 
396
  // start the sync automatically if the sync is false
397
  if ((bool) $this->getData('sync.started_at', false) === false) {
398
- $job = new MailChimp_WooCommerce_Process_Products();
399
- wp_queue($job);
400
- $job->flagStartSync();
401
  }
402
  }
403
 
@@ -466,6 +480,28 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
466
  return $this->api()->hasList($this->getOption('mailchimp_list'));
467
  }
468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
469
  /**
470
  * @return array|bool
471
  */
@@ -489,6 +525,33 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
489
  }
490
  }
491
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
  /**
493
  * @return bool
494
  */
@@ -690,4 +753,27 @@ class MailChimp_Woocommerce_Admin extends MailChimp_Woocommerce_Options {
690
 
691
  return true;
692
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
693
  }
241
  case 'newsletter_settings':
242
  $data = $this->validatePostNewsletterSettings($input);
243
  break;
244
+
245
+ case 'sync':
246
+ $this->startSync();
247
+ $this->showSyncStartedMessage();
248
+ break;
249
  }
250
 
251
  return (isset($data) && is_array($data)) ? array_merge($this->getOptions(), $data) : $this->getOptions();
382
  */
383
  protected function validatePostNewsletterSettings($input)
384
  {
385
+ // default value.
386
+ $checkbox = $this->getOption('mailchimp_checkbox_defaults', 'check');
387
+
388
+ // see if it's posted in the form.
389
+ if (isset($input['mailchimp_checkbox_defaults']) && !empty($input['mailchimp_checkbox_defaults'])) {
390
+ $checkbox = $input['mailchimp_checkbox_defaults'];
391
+ }
392
+
393
  $data = array(
394
  'mailchimp_list' => isset($input['mailchimp_list']) ? $input['mailchimp_list'] : $this->getOption('mailchimp_list', ''),
395
  'newsletter_label' => isset($input['newsletter_label']) ? $input['newsletter_label'] : $this->getOption('newsletter_label', 'Subscribe to our newsletter'),
396
  'mailchimp_auto_subscribe' => isset($input['mailchimp_auto_subscribe']) ? $input['mailchimp_auto_subscribe'] : $this->getOption('mailchimp_auto_subscribe', '0'),
397
+ 'mailchimp_checkbox_defaults' => $checkbox,
398
+ 'mailchimp_checkbox_action' => isset($input['mailchimp_checkbox_action']) ? $input['mailchimp_checkbox_action'] : $this->getOption('mailchimp_checkbox_action', 'woocommerce_after_checkout_billing_form'),
399
  );
400
 
401
  if ($data['mailchimp_list'] === 'create_new') {
410
 
411
  // start the sync automatically if the sync is false
412
  if ((bool) $this->getData('sync.started_at', false) === false) {
413
+ $this->startSync();
414
+ $this->showSyncStartedMessage();
 
415
  }
416
  }
417
 
480
  return $this->api()->hasList($this->getOption('mailchimp_list'));
481
  }
482
 
483
+
484
+ /**
485
+ * @return array|bool|mixed|null
486
+ */
487
+ public function getAccountDetails()
488
+ {
489
+ if (!$this->hasValidApiKey()) {
490
+ return false;
491
+ }
492
+
493
+ try {
494
+ if (($account = $this->getCached('api-account-name', null)) === null) {
495
+ if (($account = $this->api()->getProfile())) {
496
+ $this->setCached('api-account-name', $account, 120);
497
+ }
498
+ }
499
+ return $account;
500
+ } catch (\Exception $e) {
501
+ return false;
502
+ }
503
+ }
504
+
505
  /**
506
  * @return array|bool
507
  */
525
  }
526
  }
527
 
528
+ /**
529
+ * @return array|bool
530
+ */
531
+ public function getListName()
532
+ {
533
+ if (!$this->hasValidApiKey()) {
534
+ return false;
535
+ }
536
+
537
+ if (!($list_id = $this->getOption('mailchimp_list', false))) {
538
+ return false;
539
+ }
540
+
541
+ try {
542
+ if (($lists = $this->getCached('api-lists', null)) === null) {
543
+ $lists = $this->api()->getLists(true);
544
+ if ($lists) {
545
+ $this->setCached('api-lists', $lists, 120);
546
+ }
547
+ }
548
+
549
+ return array_key_exists($list_id, $lists) ? $lists[$list_id] : false;
550
+ } catch (\Exception $e) {
551
+ return array();
552
+ }
553
+ }
554
+
555
  /**
556
  * @return bool
557
  */
753
 
754
  return true;
755
  }
756
+
757
+ /**
758
+ * Start the sync
759
+ */
760
+ private function startSync()
761
+ {
762
+ $job = new MailChimp_WooCommerce_Process_Products();
763
+ $job->flagStartSync();
764
+ wp_queue($job);
765
+ }
766
+
767
+ /**
768
+ * Show the sync started message right when they sync things.
769
+ */
770
+ private function showSyncStartedMessage()
771
+ {
772
+ $text = 'Starting the sync process…<br/>'.
773
+ '<p id="sync-status-message">Please hang tight while we work our mojo. Sometimes the sync can take a while, '.
774
+ 'especially on sites with lots of orders and/or products. You may refresh this page at '.
775
+ 'anytime to check on the progress.</p>';
776
+
777
+ add_settings_error('mailchimp-woocommerce_notice', $this->plugin_name, __($text), 'updated');
778
+ }
779
  }
admin/partials/mailchimp-woocommerce-admin-tabs.php CHANGED
@@ -11,6 +11,8 @@ $show_campaign_defaults = true;
11
  $has_valid_api_key = false;
12
  $allow_new_list = true;
13
 
 
 
14
  if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
15
  $has_valid_api_key = true;
16
  // if we don't have a valid api key we need to redirect back to the 'api_key' tab.
@@ -26,8 +28,14 @@ if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
26
  }
27
  ?>
28
 
 
 
 
 
 
 
29
  <?php if (!defined('PHP_VERSION_ID') || (PHP_VERSION_ID < 50600)): ?>
30
- <div class="error notice is-dismissable">
31
  <p><?php _e('MailChimp says: Please upgrade your PHP version to a minimum of 5.6', 'mailchimp-woocommerce'); ?></p>
32
  </div>
33
  <?php endif; ?>
@@ -47,7 +55,7 @@ if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
47
  <?php endif; ?>
48
  <a href="?page=mailchimp-woocommerce&tab=newsletter_settings" class="nav-tab <?php echo $active_tab == 'newsletter_settings' ? 'nav-tab-active' : ''; ?>">List Settings</a>
49
  <?php if($show_sync_tab): ?>
50
- <a href="?page=mailchimp-woocommerce&tab=sync" class="nav-tab <?php echo $active_tab == 'sync' ? 'nav-tab-active' : ''; ?>">Sync Status</a>
51
  <?php endif; ?>
52
  <?php endif;?>
53
  <?php endif; ?>
@@ -55,11 +63,15 @@ if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
55
 
56
  <form method="post" name="cleanup_options" action="options.php">
57
 
 
 
58
  <?php
59
- settings_fields($this->plugin_name);
60
- do_settings_sections($this->plugin_name);
61
- //settings_errors();
62
- include('tabs/notices.php');
 
 
63
  ?>
64
 
65
  <input type="hidden" name="<?php echo $this->plugin_name; ?>[mailchimp_active_tab]" value="<?php echo $active_tab; ?>"/>
@@ -86,10 +98,15 @@ if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
86
 
87
  <?php if ($active_tab !== 'sync') submit_button('Save all changes', 'primary','submit', TRUE); ?>
88
 
89
- <?php if($show_sync_tab && isset($_GET['show_sync']) && $_GET['show_sync'] === '1'): ?>
90
- <p><a style="float:left;" class="btn" href="/?mailchimp_woocommerce[action]=sync">Re-Sync</a></p>
91
- <?php endif; ?>
92
-
93
  </form>
94
 
 
 
 
 
 
 
 
 
 
95
  </div><!-- /.wrap -->
11
  $has_valid_api_key = false;
12
  $allow_new_list = true;
13
 
14
+ $clicked_sync_button = isset($_POST['mailchimp_woocommerce_settings_hidden']) && $active_tab == 'sync';
15
+
16
  if (isset($options['mailchimp_api_key']) && $handler->hasValidApiKey()) {
17
  $has_valid_api_key = true;
18
  // if we don't have a valid api key we need to redirect back to the 'api_key' tab.
28
  }
29
  ?>
30
 
31
+ <style>
32
+ #sync-status-message strong {
33
+ font-weight:inherit;
34
+ }
35
+ </style>
36
+
37
  <?php if (!defined('PHP_VERSION_ID') || (PHP_VERSION_ID < 50600)): ?>
38
+ <div data-dismissible="notice-php-version" class="error notice notice-error is-dismissible">
39
  <p><?php _e('MailChimp says: Please upgrade your PHP version to a minimum of 5.6', 'mailchimp-woocommerce'); ?></p>
40
  </div>
41
  <?php endif; ?>
55
  <?php endif; ?>
56
  <a href="?page=mailchimp-woocommerce&tab=newsletter_settings" class="nav-tab <?php echo $active_tab == 'newsletter_settings' ? 'nav-tab-active' : ''; ?>">List Settings</a>
57
  <?php if($show_sync_tab): ?>
58
+ <a href="?page=mailchimp-woocommerce&tab=sync" class="nav-tab <?php echo $active_tab == 'sync' ? 'nav-tab-active' : ''; ?>">Sync</a>
59
  <?php endif; ?>
60
  <?php endif;?>
61
  <?php endif; ?>
63
 
64
  <form method="post" name="cleanup_options" action="options.php">
65
 
66
+ <input type="hidden" name="mailchimp_woocommerce_settings_hidden" value="Y">
67
+
68
  <?php
69
+ if (!$clicked_sync_button) {
70
+ settings_fields($this->plugin_name);
71
+ do_settings_sections($this->plugin_name);
72
+ //settings_errors();
73
+ include('tabs/notices.php');
74
+ }
75
  ?>
76
 
77
  <input type="hidden" name="<?php echo $this->plugin_name; ?>[mailchimp_active_tab]" value="<?php echo $active_tab; ?>"/>
98
 
99
  <?php if ($active_tab !== 'sync') submit_button('Save all changes', 'primary','submit', TRUE); ?>
100
 
 
 
 
 
101
  </form>
102
 
103
+ <?php if ($active_tab == 'sync'): ?>
104
+ <h2 style="padding-top: 1em;">More Information</h2>
105
+ <p>
106
+ Need help troubleshooting or connecting your store? Visit our MailChimp for WooCommerce
107
+ <a href="http://kb.mailchimp.com/integrations/e-commerce/connect-or-disconnect-mailchimp-for-woocommerce/" target="_blank">knowledge base</a> at anytime. Also, be sure to
108
+ <a href="https://wordpress.org/support/plugin/mailchimp-for-woocommerce/reviews/" target="_blank">leave a review</a> and let us know how we're doing.
109
+ </p>
110
+ <?php endif; ?>
111
+
112
  </div><!-- /.wrap -->
admin/partials/tabs/api_key.php CHANGED
@@ -8,6 +8,7 @@ if (isset($options['mailchimp_api_key']) && !$handler->hasValidApiKey()) {
8
  }
9
 
10
  ?>
 
11
 
12
  <h2 style="padding-top: 1em;">API Information</h2>
13
  <p>To find your MailChimp API key, log into your account settings > Extras > API keys. From there, either grab an existing key or generate a new one for your WooCommerce store. </p>
@@ -34,7 +35,7 @@ if (isset($options['mailchimp_api_key']) && !$handler->hasValidApiKey()) {
34
 
35
  $enable_mailchimp_debugging = (array_key_exists('mailchimp_debugging', $options) && !is_null($options['mailchimp_debugging'])) ? $options['mailchimp_debugging'] : '1';
36
 
37
- foreach (['0' => 'No', '1' => 'Yes'] as $key => $value ) {
38
  echo '<option value="' . esc_attr($key) . '" ' . selected($key == $enable_mailchimp_debugging, true, false ) . '>' . esc_html( $value ) . '</option>';
39
  }
40
  ?>
8
  }
9
 
10
  ?>
11
+ <input type="hidden" name="mailchimp_active_settings_tab" value="api_key"/>
12
 
13
  <h2 style="padding-top: 1em;">API Information</h2>
14
  <p>To find your MailChimp API key, log into your account settings > Extras > API keys. From there, either grab an existing key or generate a new one for your WooCommerce store. </p>
35
 
36
  $enable_mailchimp_debugging = (array_key_exists('mailchimp_debugging', $options) && !is_null($options['mailchimp_debugging'])) ? $options['mailchimp_debugging'] : '1';
37
 
38
+ foreach (array('0' => 'No', '1' => 'Yes') as $key => $value ) {
39
  echo '<option value="' . esc_attr($key) . '" ' . selected($key == $enable_mailchimp_debugging, true, false ) . '>' . esc_html( $value ) . '</option>';
40
  }
41
  ?>
admin/partials/tabs/campaign_defaults.php CHANGED
@@ -12,6 +12,8 @@ if (!$handler->hasValidStoreInfo()) {
12
 
13
  ?>
14
 
 
 
15
  <h2 style="padding-top: 1em;">List Defaults</h2>
16
  <p>Please fill out the default campaign information.</p>
17
 
12
 
13
  ?>
14
 
15
+ <input type="hidden" name="mailchimp_active_settings_tab" value="campaign_defaults"/>
16
+
17
  <h2 style="padding-top: 1em;">List Defaults</h2>
18
  <p>Please fill out the default campaign information.</p>
19
 
admin/partials/tabs/newsletter_settings.php CHANGED
@@ -28,6 +28,8 @@ $list_is_configured = isset($options['mailchimp_list']) && (!empty($options['mai
28
  </div>
29
  <?php endif; ?>
30
 
 
 
31
  <h2 style="padding-top: 1em;">List Settings</h2>
32
  <p>Please apply your list settings. If you don't have a list, you can choose to create one.</p>
33
 
@@ -68,7 +70,7 @@ $list_is_configured = isset($options['mailchimp_list']) && (!empty($options['mai
68
  <?php
69
  $enable_auto_subscribe = (array_key_exists('mailchimp_auto_subscribe', $options) && !is_null($options['mailchimp_auto_subscribe'])) ? $options['mailchimp_auto_subscribe'] : '1';
70
 
71
- foreach (['0' => 'No', '1' => 'Yes'] as $key => $value ) {
72
  echo '<option value="' . esc_attr( $key ) . '" ' . selected($key == $enable_auto_subscribe, true, false ) . '>' . esc_html( $value ) . '</option>';
73
  }
74
  ?>
@@ -78,12 +80,47 @@ $list_is_configured = isset($options['mailchimp_list']) && (!empty($options['mai
78
  </label>
79
  </fieldset>
80
 
 
 
 
81
  <fieldset>
82
  <legend class="screen-reader-text">
83
- <span>MailChimp Newsletter Label</span>
84
  </legend>
85
  <label for="<?php echo $this->plugin_name; ?>-newsletter-checkbox-label">
86
  <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-newsletter-checkbox-label" name="<?php echo $this->plugin_name; ?>[newsletter_label]" value="<?php echo isset($options['newsletter_label']) ? $options['newsletter_label'] : 'Subscribe to our newsletter' ?>" />
87
  <span><?php esc_attr_e('Write a subscribe message for customers at checkout.', $this->plugin_name); ?></span>
88
  </label>
89
  </fieldset>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  </div>
29
  <?php endif; ?>
30
 
31
+ <input type="hidden" name="mailchimp_active_settings_tab" value="newsletter_settings"/>
32
+
33
  <h2 style="padding-top: 1em;">List Settings</h2>
34
  <p>Please apply your list settings. If you don't have a list, you can choose to create one.</p>
35
 
70
  <?php
71
  $enable_auto_subscribe = (array_key_exists('mailchimp_auto_subscribe', $options) && !is_null($options['mailchimp_auto_subscribe'])) ? $options['mailchimp_auto_subscribe'] : '1';
72
 
73
+ foreach (array('0' => 'No', '1' => 'Yes') as $key => $value ) {
74
  echo '<option value="' . esc_attr( $key ) . '" ' . selected($key == $enable_auto_subscribe, true, false ) . '>' . esc_html( $value ) . '</option>';
75
  }
76
  ?>
80
  </label>
81
  </fieldset>
82
 
83
+ <h2 style="padding-top: 1em;">Opt-in Settings</h2>
84
+ <p>Add text to go along with the opt-in checkbox, and choose a default display option.</p>
85
+
86
  <fieldset>
87
  <legend class="screen-reader-text">
88
+ <span>Newsletter Label</span>
89
  </legend>
90
  <label for="<?php echo $this->plugin_name; ?>-newsletter-checkbox-label">
91
  <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-newsletter-checkbox-label" name="<?php echo $this->plugin_name; ?>[newsletter_label]" value="<?php echo isset($options['newsletter_label']) ? $options['newsletter_label'] : 'Subscribe to our newsletter' ?>" />
92
  <span><?php esc_attr_e('Write a subscribe message for customers at checkout.', $this->plugin_name); ?></span>
93
  </label>
94
  </fieldset>
95
+
96
+ <h2 style="padding-top: 1em;">Checkbox Display Options</h2>
97
+
98
+ <fieldset>
99
+ <legend class="screen-reader-text">
100
+ <span>Checkbox Display Options</span>
101
+ </legend>
102
+ <label for="<?php echo $this->plugin_name; ?>-newsletter-checkbox-defaults">
103
+ <?php $checkbox_default_settings = (array_key_exists('mailchimp_checkbox_defaults', $options) && !is_null($options['mailchimp_checkbox_defaults'])) ? $options['mailchimp_checkbox_defaults'] : 'check'; ?>
104
+ <input type="radio" name="<?php echo $this->plugin_name; ?>[mailchimp_checkbox_defaults]" value="check"<?php if($checkbox_default_settings === 'check') echo ' checked="checked" '; ?>>Visible, checked by default<br>
105
+ <input type="radio" name="<?php echo $this->plugin_name; ?>[mailchimp_checkbox_defaults]" value="uncheck"<?php if($checkbox_default_settings === 'uncheck') echo ' checked="checked" '; ?>>Visible, unchecked by default<br/>
106
+ <input type="radio" name="<?php echo $this->plugin_name; ?>[mailchimp_checkbox_defaults]" value="hide"<?php if($checkbox_default_settings === 'hide') echo ' checked="checked" '; ?>>Hidden, not opted by default<br/>
107
+ </label>
108
+ </fieldset>
109
+
110
+ <h2 style="padding-top: 1em;">Advanced Checkbox Settings</h2>
111
+ <p>
112
+ To change the location of the opt-in checkbox at checkout, input one of the
113
+ <a href="https://docs.woocommerce.com/wc-apidocs/hook-docs.html" target="_blank">
114
+ available WooCommerce form actions.
115
+ </a>
116
+ </p>
117
+
118
+ <fieldset>
119
+ <legend class="screen-reader-text">
120
+ <span>Newsletter Checkbox Action</span>
121
+ </legend>
122
+ <label for="<?php echo $this->plugin_name; ?>-newsletter-checkbox-action">
123
+ <input style="width: 30%;" type="text" id="<?php echo $this->plugin_name; ?>-newsletter-checkbox-action" name="<?php echo $this->plugin_name; ?>[mailchimp_checkbox_action]" value="<?php echo isset($options['mailchimp_checkbox_action']) ? $options['mailchimp_checkbox_action'] : 'woocommerce_after_checkout_billing_form' ?>" />
124
+ <span><?php esc_attr_e('WooCommerce Action', $this->plugin_name); ?></span>
125
+ </label>
126
+ </fieldset>
admin/partials/tabs/store_info.php CHANGED
@@ -8,6 +8,7 @@ if (!$handler->hasValidApiKey()) {
8
  }
9
 
10
  ?>
 
11
 
12
  <h2 style="padding-top: 1em;">Store Settings</h2>
13
  <p>Please provide the following information about your WooCommerce store.</p>
8
  }
9
 
10
  ?>
11
+ <input type="hidden" name="mailchimp_active_settings_tab" value="store_info"/>
12
 
13
  <h2 style="padding-top: 1em;">Store Settings</h2>
14
  <p>Please provide the following information about your WooCommerce store.</p>
admin/partials/tabs/store_sync.php CHANGED
@@ -1,30 +1,76 @@
1
  <?php
2
 
3
- $handler = MailChimp_Woocommerce_Admin::connect();
4
-
5
- // if we're not ready for a sync, we need to redirect out of this page like now.
6
- //if (!$handler->isReadyForSync()) {
7
- // wp_redirect('options-general.php?page=mailchimp-woocommerce&tab=api_key&error_notice=not_ready_for_sync');
8
- //}
9
-
10
- if (($sync_started_at = $this->getData('sync.started_at', false))) {
11
- $date = mailchimp_date_local(date("c", $sync_started_at));
12
- $sync_started_at = $date->format('D, M j, Y g:i A');
13
- } else {
14
- $sync_started_at = 'N/A';
15
- }
16
 
17
- if (($sync_complete_at = $this->getData('sync.completed_at', false))) {
18
- $date = mailchimp_date_local(date("c", $sync_complete_at));
19
- $sync_complete_at = $date->format('D, M j, Y g:i A');
20
- } else {
21
- $sync_complete_at = $sync_started_at !== 'N/A' ? 'In Progress' : 'N/A';
22
  }
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ?>
25
 
26
- <h2 style="padding-top: 1em;">Sync Timeline</h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- <p>Sync Started: <?php echo $sync_started_at; ?></p>
29
- <p>Sync Completed: <?php echo $sync_complete_at; ?></p>
 
30
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ $mailchimp_total_products = $mailchimp_total_orders = 0;
4
+ $store_id = mailchimp_get_store_id();
5
+ $product_count = mailchimp_get_product_count();
6
+ $order_count = mailchimp_get_order_count();
7
+ $store_syncing = false;
8
+ $last_updated_time = get_option('mailchimp-woocommerce-resource-last-updated');
9
+ $account_name = 'n/a';
10
+ $mailchimp_list_name = 'n/a';
 
 
 
 
 
11
 
12
+ if (!empty($last_updated_time)) {
13
+ $last_updated_time = mailchimp_date_local($last_updated_time);
 
 
 
14
  }
15
 
16
+ if (($mailchimp_api = mailchimp_get_api()) && ($store = $mailchimp_api->getStore($store_id))) {
17
+
18
+ $store_syncing = $store->isSyncing();
19
+
20
+ if (($account_details = $handler->getAccountDetails())) {
21
+ $account_name = $account_details['account_name'];
22
+ }
23
+
24
+ try {
25
+ $products = $mailchimp_api->products($store_id, 1, 1);
26
+ $mailchimp_total_products = $products['total_items'];
27
+ if ($mailchimp_total_products > $product_count) $mailchimp_total_products = $product_count;
28
+ } catch (\Exception $e) { $mailchimp_total_products = 0; }
29
+
30
+ try {
31
+ $orders = $mailchimp_api->orders($store_id, 1, 1);
32
+ $mailchimp_total_orders = $orders['total_items'];
33
+ if ($mailchimp_total_orders > $order_count) $mailchimp_total_orders = $order_count;
34
+ } catch (\Exception $e) { $mailchimp_total_orders = 0; }
35
+
36
+ $mailchimp_list_name = $handler->getListName();
37
+ }
38
  ?>
39
 
40
+ <input type="hidden" name="mailchimp_active_settings_tab" value="store_sync"/>
41
+
42
+ <?php if($store_syncing): ?>
43
+ <h2 style="padding-top: 1em;">Sync Progress</h2>
44
+ <?php endif; ?>
45
+
46
+ <?php if(!$store_syncing): ?>
47
+ <h2 style="padding-top: 1em;">Sync Status</h2>
48
+ <?php endif; ?>
49
+
50
+ <p>
51
+ <strong>Account Connected:</strong> <?php echo $account_name; ?>
52
+ </p>
53
+
54
+ <p>
55
+ <strong>List Connected:</strong> <?php echo $mailchimp_list_name; ?>
56
+ </p>
57
+
58
+ <p>
59
+ <strong>Products:</strong> <?php echo $mailchimp_total_products; ?>/<?php echo $product_count; ?>
60
+ </p>
61
+
62
+ <p>
63
+ <strong>Orders:</strong> <?php echo $mailchimp_total_orders; ?>/<?php echo $order_count; ?>
64
+ </p>
65
 
66
+ <?php if ($last_updated_time): ?>
67
+ <p><strong>Last Updated:</strong> <i><?php echo $last_updated_time->format('D, M j, Y g:i A'); ?></i></p>
68
+ <?php endif; ?>
69
 
70
+ <?php if($mailchimp_api && (!$store_syncing || isset($_GET['resync']) && $_GET['resync'] === '1')): ?>
71
+ <h2 style="padding-top: 1em;">Advanced</h2>
72
+ <p>
73
+ You may sync your list again if necessary. When this is done, all ecommerce data will be reset in your MailChimp list - including products and transaction data.
74
+ </p>
75
+ <?php submit_button('Resync', 'primary','submit', TRUE); ?>
76
+ <?php endif; ?>
includes/api/assets/class-mailchimp-address.php CHANGED
@@ -306,8 +306,8 @@ class MailChimp_WooCommerce_Address
306
  'postal_code' => (string) $this->postal_code,
307
  'country' => (string) $this->country,
308
  'country_code' => (string) $this->country_code,
309
- 'longitude' => $this->longitude ? (int) $this->longitude : null,
310
- 'latitude' => $this->latitude ? (int) $this->latitude : null,
311
  'phone' => (string) $this->phone,
312
  'company' => (string) $this->company,
313
  ));
306
  'postal_code' => (string) $this->postal_code,
307
  'country' => (string) $this->country,
308
  'country_code' => (string) $this->country_code,
309
+ 'longitude' => ($this->longitude ? (int) $this->longitude : null),
310
+ 'latitude' => ($this->latitude ? (int) $this->latitude : null),
311
  'phone' => (string) $this->phone,
312
  'company' => (string) $this->company,
313
  ));
includes/api/assets/class-mailchimp-cart.php CHANGED
@@ -236,7 +236,7 @@ class MailChimp_WooCommerce_Cart
236
  'checkout_url' => (string) $this->getCheckoutURL(),
237
  'currency_code' => (string) $this->getCurrencyCode(),
238
  'order_total' => $this->getOrderTotal(),
239
- 'tax_total' => $this->getTaxTotal() > 0 ? $this->getTaxTotal() : null,
240
  'lines' => array_map(function($item) {
241
  return $item->toArray();
242
  }, $this->items()),
236
  'checkout_url' => (string) $this->getCheckoutURL(),
237
  'currency_code' => (string) $this->getCurrencyCode(),
238
  'order_total' => $this->getOrderTotal(),
239
+ 'tax_total' => ($this->getTaxTotal() > 0 ? $this->getTaxTotal() : null),
240
  'lines' => array_map(function($item) {
241
  return $item->toArray();
242
  }, $this->items()),
includes/api/assets/class-mailchimp-customer.php CHANGED
@@ -227,7 +227,7 @@ class MailChimp_WooCommerce_Customer
227
  'last_name' => (string) $this->getLastName(),
228
  'orders_count' => (int) $this->getOrdersCount(),
229
  'total_spent' => floatval(number_format($this->getTotalSpent(), 2)),
230
- 'address' => empty($address) ? null : $address,
231
  ));
232
  }
233
 
227
  'last_name' => (string) $this->getLastName(),
228
  'orders_count' => (int) $this->getOrdersCount(),
229
  'total_spent' => floatval(number_format($this->getTotalSpent(), 2)),
230
+ 'address' => (empty($address) ? null : $address),
231
  ));
232
  }
233
 
includes/api/class-mailchimp-api.php CHANGED
@@ -135,6 +135,17 @@ class MailChimp_WooCommerce_MailChimpApi
135
  return $this->get("lists/$list_id/members");
136
  }
137
 
 
 
 
 
 
 
 
 
 
 
 
138
  /**
139
  * @param $list_id
140
  * @param $email
@@ -148,7 +159,7 @@ class MailChimp_WooCommerce_MailChimpApi
148
  $data = array(
149
  'email_type' => 'html',
150
  'email_address' => $email,
151
- 'status' => $subscribed === true ? 'subscribed' : 'pending',
152
  'merge_fields' => $merge_fields,
153
  'interests' => $list_interests,
154
  );
@@ -210,7 +221,7 @@ class MailChimp_WooCommerce_MailChimpApi
210
  $data = array(
211
  'email_address' => $email,
212
  'status' => ($subscribed === null ? 'cleaned' : ($subscribed === true ? 'subscribed' : 'unsubscribed')),
213
- 'status_if_new' => $subscribed === true ? 'subscribed' : 'pending',
214
  'merge_fields' => $merge_fields,
215
  'interests' => $list_interests,
216
  );
@@ -360,7 +371,7 @@ class MailChimp_WooCommerce_MailChimpApi
360
  'start' => $page,
361
  'count' => $count,
362
  'offset' => ($page * $count),
363
- 'since' => $since ? $since->format('Y-m-d H:i:s') : null,
364
  'cid' => $campaign_id,
365
  ));
366
 
@@ -643,6 +654,7 @@ class MailChimp_WooCommerce_MailChimpApi
643
  return false;
644
  }
645
  $data = $this->post("ecommerce/stores/$store_id/orders", $order->toArray());
 
646
  return (new MailChimp_WooCommerce_Order)->fromArray($data);
647
  } catch (\Exception $e) {
648
  if (!$silent) throw $e;
@@ -748,6 +760,7 @@ class MailChimp_WooCommerce_MailChimpApi
748
  try {
749
  $this->validateStoreSubmission($product);
750
  $data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
 
751
  return (new MailChimp_WooCommerce_Product)->fromArray($data);
752
  } catch (\Exception $e) {
753
  if (!$silent) throw $e;
@@ -840,47 +853,15 @@ class MailChimp_WooCommerce_MailChimpApi
840
  */
841
  protected function patch($url, $body)
842
  {
843
- try {
844
- // process the patch request the normal way
845
- $curl = curl_init();
846
-
847
- $options = $this->applyCurlOptions('PATCH', $url, array());
848
- $options[CURLOPT_POSTFIELDS] = json_encode($body);
849
-
850
- curl_setopt_array($curl, $options);
851
-
852
- return $this->processCurlResponse($curl);
853
-
854
- } catch (\Exception $e) {
855
 
856
- // if the error that we get is not the json parsing error, throw it.
857
- if (strpos(strtolower($e->getMessage()), 'json parsing error') === false) {
858
- throw $e;
859
- }
860
 
861
- // ah snap, gotta try the file get contents fallback.
862
- mailchimp_log('api.patch.fallback', 'stream', array('curl_version' => curl_version()));
863
-
864
- $context = stream_context_create(array(
865
- 'http' => array(
866
- 'method' => 'PATCH',
867
- 'header' => array(
868
- 'Authorization: Basic '.base64_encode('mailchimp:'.$this->api_key),
869
- 'Accept: application/json',
870
- 'Content-Type: application/json'
871
- ),
872
- 'content' => json_encode($body)
873
- )
874
- ));
875
-
876
- $response = file_get_contents($this->url($url), FALSE, $context);
877
-
878
- if ($response === false) {
879
- throw new MailChimp_WooCommerce_Error('Invalid patch request');
880
- }
881
 
882
- return json_decode($response, true);
883
- }
884
  }
885
 
886
  /**
@@ -965,7 +946,7 @@ class MailChimp_WooCommerce_MailChimpApi
965
  */
966
  protected function applyCurlOptions($method, $url, $params = array())
967
  {
968
- //$env = mailchimp_environment_variables();
969
 
970
  return array(
971
  CURLOPT_USERPWD => "mailchimp:{$this->api_key}",
@@ -979,7 +960,7 @@ class MailChimp_WooCommerce_MailChimpApi
979
  CURLINFO_HEADER_OUT => true,
980
  CURLOPT_HTTPHEADER => array(
981
  'content-type: application/json',
982
- 'user-agent: MailChimp for WooCommerce',
983
  )
984
  );
985
  }
135
  return $this->get("lists/$list_id/members");
136
  }
137
 
138
+ /**
139
+ * @param $list_id
140
+ * @param $email
141
+ * @return array|bool
142
+ */
143
+ public function deleteMember($list_id, $email)
144
+ {
145
+ $hash = md5(strtolower($email));
146
+ return $this->delete("lists/$list_id/members/$hash", array());
147
+ }
148
+
149
  /**
150
  * @param $list_id
151
  * @param $email
159
  $data = array(
160
  'email_type' => 'html',
161
  'email_address' => $email,
162
+ 'status' => ($subscribed === true ? 'subscribed' : 'pending'),
163
  'merge_fields' => $merge_fields,
164
  'interests' => $list_interests,
165
  );
221
  $data = array(
222
  'email_address' => $email,
223
  'status' => ($subscribed === null ? 'cleaned' : ($subscribed === true ? 'subscribed' : 'unsubscribed')),
224
+ 'status_if_new' => ($subscribed === true ? 'subscribed' : 'pending'),
225
  'merge_fields' => $merge_fields,
226
  'interests' => $list_interests,
227
  );
371
  'start' => $page,
372
  'count' => $count,
373
  'offset' => ($page * $count),
374
+ 'since' => ($since ? $since->format('Y-m-d H:i:s') : null),
375
  'cid' => $campaign_id,
376
  ));
377
 
654
  return false;
655
  }
656
  $data = $this->post("ecommerce/stores/$store_id/orders", $order->toArray());
657
+ update_option('mailchimp-woocommerce-resource-last-updated', time());
658
  return (new MailChimp_WooCommerce_Order)->fromArray($data);
659
  } catch (\Exception $e) {
660
  if (!$silent) throw $e;
760
  try {
761
  $this->validateStoreSubmission($product);
762
  $data = $this->post("ecommerce/stores/$store_id/products", $product->toArray());
763
+ update_option('mailchimp-woocommerce-resource-last-updated', time());
764
  return (new MailChimp_WooCommerce_Product)->fromArray($data);
765
  } catch (\Exception $e) {
766
  if (!$silent) throw $e;
853
  */
854
  protected function patch($url, $body)
855
  {
856
+ // process the patch request the normal way
857
+ $curl = curl_init();
 
 
 
 
 
 
 
 
 
 
858
 
859
+ $options = $this->applyCurlOptions('PATCH', $url, array());
860
+ $options[CURLOPT_POSTFIELDS] = json_encode($body);
 
 
861
 
862
+ curl_setopt_array($curl, $options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
863
 
864
+ return $this->processCurlResponse($curl);
 
865
  }
866
 
867
  /**
946
  */
947
  protected function applyCurlOptions($method, $url, $params = array())
948
  {
949
+ $env = mailchimp_environment_variables();
950
 
951
  return array(
952
  CURLOPT_USERPWD => "mailchimp:{$this->api_key}",
960
  CURLINFO_HEADER_OUT => true,
961
  CURLOPT_HTTPHEADER => array(
962
  'content-type: application/json',
963
+ "user-agent: MailChimp for WooCommerce/{$env->version}; WordPress/{$env->wp_version}",
964
  )
965
  );
966
  }
includes/class-mailchimp-woocommerce-activator.php CHANGED
@@ -20,7 +20,10 @@ class MailChimp_Woocommerce_Activator {
20
  */
21
  public static function activate() {
22
 
23
- add_option('mailchimp_woocommerce_plugin_do_activation_redirect', true);
 
 
 
24
 
25
  // create the queue tables because we need them for the sync jobs.
26
  static::create_queue_tables();
@@ -117,7 +120,7 @@ class MailChimp_Woocommerce_Activator {
117
  $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}mailchimp_carts (
118
  id VARCHAR (255) NOT NULL,
119
  email VARCHAR (100) NOT NULL,
120
- user_id INT (11) NULLABLE,
121
  cart text NOT NULL,
122
  created_at datetime NOT NULL
123
  ) $charset_collate;";
20
  */
21
  public static function activate() {
22
 
23
+ // only do this if the option has never been set before.
24
+ if (get_option('mailchimp_woocommerce_plugin_do_activation_redirect', null) === null) {
25
+ add_option('mailchimp_woocommerce_plugin_do_activation_redirect', true);
26
+ }
27
 
28
  // create the queue tables because we need them for the sync jobs.
29
  static::create_queue_tables();
120
  $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}mailchimp_carts (
121
  id VARCHAR (255) NOT NULL,
122
  email VARCHAR (100) NOT NULL,
123
+ user_id INT (11) DEFAULT NULL,
124
  cart text NOT NULL,
125
  created_at datetime NOT NULL
126
  ) $charset_collate;";
includes/class-mailchimp-woocommerce-deactivator.php CHANGED
@@ -34,6 +34,9 @@ class MailChimp_Woocommerce_Deactivator {
34
  if (($api = mailchimp_get_api())) {
35
  $api->deleteStore(mailchimp_get_store_id());
36
  }
 
 
 
37
  }
38
 
39
  }
34
  if (($api = mailchimp_get_api())) {
35
  $api->deleteStore(mailchimp_get_store_id());
36
  }
37
+
38
+ delete_option('mailchimp-woocommerce-sync.started_at');
39
+ delete_option('mailchimp-woocommerce-sync.completed_at');
40
  }
41
 
42
  }
includes/class-mailchimp-woocommerce-newsletter.php CHANGED
@@ -16,13 +16,34 @@ class MailChimp_Newsletter extends MailChimp_Woocommerce_Options
16
  public function applyNewsletterField($checkout)
17
  {
18
  if (!is_admin()) {
19
- $status = is_user_logged_in() ? get_user_meta(get_current_user_id(), 'mailchimp_woocommerce_is_subscribed',
20
- true) : true;
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  $checkbox = '<p class="form-row form-row-wide create-account">';
23
- $checkbox .= '<input class="input-checkbox" id="mailchimp_woocommerce_newsletter" type="checkbox" name="mailchimp_woocommerce_newsletter" value="1" checked="' . ($status ? 'checked' : '') . '"> ';
24
- $checkbox .= '<label for="mailchimp_woocommerce_newsletter" class="checkbox">' . $this->getOption('newsletter_label',
25
- 'Subscribe to our newsletter') . '</label></p>';
26
  $checkbox .= '<div class="clear"></div>';
27
 
28
  echo $checkbox;
16
  public function applyNewsletterField($checkout)
17
  {
18
  if (!is_admin()) {
 
 
19
 
20
+ // if the user has chosen to hide the checkbox, don't do anything.
21
+ if (($default_setting = $this->getOption('mailchimp_checkbox_defaults', 'check')) === 'hide') {
22
+ return;
23
+ }
24
+
25
+ // allow the user to specify the text in the newsletter label.
26
+ $label = $this->getOption('newsletter_label', 'Subscribe to our newsletter');
27
+
28
+ // if the user chose 'check' or nothing at all, we default to true.
29
+ $default_checked = $default_setting === 'check';
30
+
31
+ // if the user is logged in, we will pull the 'is_subscribed' property out of the meta for the value.
32
+ // otherwise we use the default settings.
33
+ if (is_user_logged_in()) {
34
+ $status = get_user_meta(get_current_user_id(), 'mailchimp_woocommerce_is_subscribed', true);
35
+ if ($status === '' || $status === null) {
36
+ $status = $default_checked;
37
+ }
38
+ } else {
39
+ $status = $default_checked;
40
+ }
41
+
42
+ // echo out the checkbox.
43
  $checkbox = '<p class="form-row form-row-wide create-account">';
44
+ $checkbox .= '<input class="input-checkbox" id="mailchimp_woocommerce_newsletter" type="checkbox" ';
45
+ $checkbox .= 'name="mailchimp_woocommerce_newsletter" value="1"'.($status ? ' checked="checked"' : '').'>';
46
+ $checkbox .= '<label for="mailchimp_woocommerce_newsletter" class="checkbox">'.$label.'</label></p>';
47
  $checkbox .= '<div class="clear"></div>';
48
 
49
  echo $checkbox;
includes/class-mailchimp-woocommerce-options.php CHANGED
@@ -235,4 +235,34 @@ abstract class MailChimp_Woocommerce_Options
235
 
236
  return $default;
237
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
235
 
236
  return $default;
237
  }
238
+
239
+ /**
240
+ * @param bool $products
241
+ * @param bool $orders
242
+ * @return $this
243
+ */
244
+ public function removePointers($products = true, $orders = true)
245
+ {
246
+ if ($products) {
247
+ delete_option('mailchimp-woocommerce-sync.products.completed_at');
248
+ delete_option('mailchimp-woocommerce-sync.products.current_page');
249
+ }
250
+
251
+ if ($orders) {
252
+ delete_option('mailchimp-woocommerce-sync.orders.prevent');
253
+ delete_option('mailchimp-woocommerce-sync.orders.completed_at');
254
+ delete_option('mailchimp-woocommerce-sync.orders.current_page');
255
+ }
256
+
257
+ delete_option('mailchimp-woocommerce-sync.orders.prevent');
258
+ delete_option('mailchimp-woocommerce-errors.store_info');
259
+ delete_option('mailchimp-woocommerce-sync.syncing');
260
+ delete_option('mailchimp-woocommerce-sync.started_at');
261
+ delete_option('mailchimp-woocommerce-sync.completed_at');
262
+ delete_option('mailchimp-woocommerce-validation.api.ping');
263
+ delete_option('mailchimp-woocommerce-cached-api-lists');
264
+ delete_option('mailchimp-woocommerce-cached-api-ping-check');
265
+
266
+ return $this;
267
+ }
268
  }
includes/class-mailchimp-woocommerce-service.php CHANGED
@@ -25,8 +25,6 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
25
  {
26
  // make sure the site option for setting the mailchimp_carts has been saved.
27
  $this->validated_cart_db = get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false);
28
-
29
- $this->handleAdminFunctions();
30
  $this->is_admin = current_user_can('administrator');
31
  }
32
 
@@ -132,14 +130,71 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
132
  * @param WP_Post $post The post object.
133
  * @param bool $update Whether this is an existing post being updated or not.
134
  */
135
- public function handlePostSaved($post_id, $post, $update) {
136
- if ('product' == $post->post_type) {
137
- wp_queue(new MailChimp_WooCommerce_Single_Product($post_id), 5);
138
- } elseif ('shop_order' == $post->post_type) {
139
- $this->handleOrderStatusChanged($post_id);
 
 
 
140
  }
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  /**
144
  * @return bool|string
145
  */
@@ -158,8 +213,8 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
158
  /**
159
  * @return bool|array
160
  */
161
- public function getCartItems() {
162
-
163
  if (!($this->cart = $this->getWooSession('cart', false))) {
164
  $this->cart = WC()->cart->get_cart();
165
  } else {
@@ -304,153 +359,33 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
304
  }
305
 
306
  /**
307
- * @param string $time
308
- * @return int
309
- */
310
- protected function getCookieDuration($time = 'thirty_days')
311
- {
312
- $durations = array(
313
- 'one_day' => 86400, 'seven_days' => 604800, 'fourteen_days' => 1209600, 'thirty_days' => 2419200,
314
- );
315
-
316
- if (!array_key_exists($time, $durations)) {
317
- $time = 'thirty_days';
318
- }
319
-
320
- return time() + $durations[$time];
321
- }
322
-
323
- /**
324
- * Just a wrapper to call various methods from MailChimp to the store.
325
- * Authentication is based on the secret keys being correct or it will fail.
326
  *
327
- * The get requests need:
328
- * 1. mailchimp-woocommerce[action]
329
- * 2. mailchimp-woocommerce[submission]
330
- * 3. various other parts based on the api call.
331
  */
332
- protected function handleAdminFunctions()
333
  {
334
- if (isset($_GET['reset_cookies'])) {
335
- $buster = time()-300;
336
-
337
- setcookie('mailchimp_user_previous_email', '', $buster);
338
- setcookie('mailchimp_user_email', '', $buster);
339
- setcookie('mailchimp_campaign_id', '', $buster);
340
- setcookie('mailchimp_email_id', '', $buster);
341
-
342
- $this->previous_email = null;
343
- $this->user_email = null;
344
- }
345
-
346
- $methods = array(
347
- 'plugin-version' => 'respondAdminGetPluginVersion',
348
- 'submit-email' => 'respondAdminSubmitEmail',
349
- 'parse-email' => 'respondAdminParseEmail',
350
- 'track-campaign' => 'respondAdminTrackCampaign',
351
- 'get-tracking-data' => 'respondAdminGetTrackingData',
352
- 'verify' => 'respondAdminVerify',
353
- );
354
-
355
- if (($action = $this->get('action'))) {
356
-
357
- if ($action === 'sync') {
358
- return $this->sync();
359
- }
360
-
361
- if (array_key_exists($action, $methods)) {
362
- if (!in_array($action, array('submit-email', 'parse-email', 'track-campaign', 'get-tracking-data'))) {
363
- $this->authenticate();
364
- }
365
- $this->respondJSON($this->{$methods[$action]}());
366
- }
367
- }
368
- }
369
-
370
- /**
371
- * Delete all the options pointing to the pages, and re-start the sync process.
372
- * @return void
373
- */
374
- protected function sync()
375
- {
376
- // only do this if we're an admin user.
377
- if ($this->isAdmin()) {
378
-
379
- delete_option('mailchimp-woocommerce-errors.store_info');
380
- delete_option('mailchimp-woocommerce-sync.orders.completed_at');
381
- delete_option('mailchimp-woocommerce-sync.orders.current_page');
382
- delete_option('mailchimp-woocommerce-sync.products.completed_at');
383
- delete_option('mailchimp-woocommerce-sync.products.current_page');
384
- delete_option('mailchimp-woocommerce-sync.syncing');
385
- delete_option('mailchimp-woocommerce-sync.started_at');
386
- delete_option('mailchimp-woocommerce-sync.completed_at');
387
- delete_option('mailchimp-woocommerce-validation.api.ping');
388
- delete_option('mailchimp-woocommerce-cached-api-lists');
389
- delete_option('mailchimp-woocommerce-cached-api-ping-check');
390
-
391
- $job = new MailChimp_WooCommerce_Process_Products();
392
- $job->flagStartSync();
393
- wp_queue($job);
394
-
395
- wp_redirect('/options-general.php?page=mailchimp-woocommerce&tab=api_key&success_notice=re-sync-started');
396
- }
397
-
398
- return;
399
- }
400
-
401
- /**
402
- * @return array
403
- */
404
- protected function respondAdminGetPluginVersion()
405
- {
406
- return array('success' => true, 'version' => $this->getVersion());
407
- }
408
-
409
- /**
410
- * @return array
411
- */
412
- protected function respondAdminVerify()
413
- {
414
- return array('success' => true);
415
- }
416
-
417
- /**
418
- * @return array
419
- */
420
- protected function respondAdminParseEmail()
421
- {
422
- if ($this->is_admin) {
423
- return array('success' => false);
424
- }
425
-
426
- $submission = $this->get('submission');
427
-
428
- if (is_array($submission) && isset($submission['hash'])) {
429
-
430
- if (($cart = $this->getCart($submission['hash']))) {
431
- return array('success' => true, 'email' => $cart->email);
432
  }
433
  }
434
 
435
- return array('success' => false);
436
  }
437
 
438
  /**
439
- * @return array
440
  */
441
- protected function respondAdminSubmitEmail()
442
  {
443
  if ($this->is_admin) {
444
- return array('success' => false);
445
  }
446
 
447
- $submission = $this->get('submission');
448
-
449
- if (is_array($submission) && isset($submission['email'])) {
450
 
451
  $cookie_duration = $this->getCookieDuration();
452
 
453
- $this->user_email = trim(str_replace(' ','+', $submission['email']));
454
 
455
  if (($current_email = $this->getEmailFromSession()) && $current_email !== $this->user_email) {
456
  $this->previous_email = $current_email;
@@ -464,52 +399,33 @@ class MailChimp_Service extends MailChimp_Woocommerce_Options
464
 
465
  $this->handleCartUpdated();
466
 
467
- return array(
468
  'success' => true,
469
  'email' => $this->user_email,
470
  'previous' => $this->previous_email,
471
  'cart' => $this->cart,
472
- );
473
  }
474
- return array('success' => false);
 
475
  }
476
 
 
477
  /**
478
- * @return array
 
479
  */
480
- protected function respondAdminTrackCampaign()
481
  {
482
- if ($this->is_admin) {
483
- return array('success' => false);
484
- }
485
-
486
- $submission = $this->get('submission');
487
-
488
- if (is_array($submission) && isset($submission['campaign_id'])) {
489
-
490
- $duration = $this->getCookieDuration();
491
-
492
- $campaign_id = trim($submission['campaign_id']);
493
- $email_id = trim($submission['email_id']);
494
-
495
- @setcookie('mailchimp_campaign_id', $campaign_id, $duration, '/');
496
- @setcookie('mailchimp_email_id', $email_id, $duration, '/');
497
 
498
- return $this->respondAdminGetTrackingData();
 
499
  }
500
- return array('success' => false);
501
- }
502
 
503
- /**
504
- * @return array
505
- */
506
- protected function respondAdminGetTrackingData()
507
- {
508
- return array(
509
- 'success' => true,
510
- 'campaign_id' => $this->cookie('mailchimp_campaign_id', 'n/a'),
511
- 'email_id' => $this->cookie('mailchimp_email_id', 'n/a')
512
- );
513
  }
514
 
515
  /**
25
  {
26
  // make sure the site option for setting the mailchimp_carts has been saved.
27
  $this->validated_cart_db = get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false);
 
 
28
  $this->is_admin = current_user_can('administrator');
29
  }
30
 
130
  * @param WP_Post $post The post object.
131
  * @param bool $update Whether this is an existing post being updated or not.
132
  */
133
+ public function handlePostSaved($post_id, $post, $update)
134
+ {
135
+ if ($post->post_status !== 'auto-draft') {
136
+ if ('product' == $post->post_type) {
137
+ wp_queue(new MailChimp_WooCommerce_Single_Product($post_id), 5);
138
+ } elseif ('shop_order' == $post->post_type) {
139
+ $this->handleOrderStatusChanged($post_id);
140
+ }
141
  }
142
  }
143
 
144
+ /**
145
+ * @param $user_id
146
+ */
147
+ public function handleUserRegistration($user_id)
148
+ {
149
+ $subscribed = (bool) isset($_POST['mailchimp_woocommerce_newsletter']) ?
150
+ $_POST['mailchimp_woocommerce_newsletter'] : false;
151
+
152
+ // update the user meta with the 'is_subscribed' form element
153
+ update_user_meta($user_id, 'mailchimp_woocommerce_is_subscribed', $subscribed);
154
+
155
+ if ($subscribed) {
156
+ wp_queue(new MailChimp_WooCommerce_User_Submit($user_id, $subscribed));
157
+ }
158
+ }
159
+
160
+ /**
161
+ * @param $user_id
162
+ * @param $old_user_data
163
+ */
164
+ function handleUserUpdated($user_id, $old_user_data)
165
+ {
166
+ // only update this person if they were marked as subscribed before
167
+ $is_subscribed = (bool) get_user_meta($user_id, 'mailchimp_woocommerce_is_subscribed', true);
168
+ wp_queue(new MailChimp_WooCommerce_User_Submit($user_id, $is_subscribed, $old_user_data));
169
+ }
170
+
171
+ /**
172
+ * Delete all the options pointing to the pages, and re-start the sync process.
173
+ * @param bool $only_products
174
+ * @return bool
175
+ */
176
+ protected function syncProducts($only_products = false)
177
+ {
178
+ if (!$this->isAdmin()) return false;
179
+ $this->removePointers(true, ($only_products ? false : true));
180
+ update_option('mailchimp-woocommerce-sync.orders.prevent', $only_products);
181
+ MailChimp_WooCommerce_Process_Products::push();
182
+ return true;
183
+ }
184
+
185
+ /**
186
+ * Delete all the options pointing to the pages, and re-start the sync process.
187
+ * @return bool
188
+ */
189
+ protected function syncOrders()
190
+ {
191
+ if (!$this->isAdmin()) return false;
192
+ $this->removePointers(false, true);
193
+ // since the products are all good, let's sync up the orders now.
194
+ wp_queue(new MailChimp_WooCommerce_Process_Orders());
195
+ return true;
196
+ }
197
+
198
  /**
199
  * @return bool|string
200
  */
213
  /**
214
  * @return bool|array
215
  */
216
+ public function getCartItems()
217
+ {
218
  if (!($this->cart = $this->getWooSession('cart', false))) {
219
  $this->cart = WC()->cart->get_cart();
220
  } else {
359
  }
360
 
361
  /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  *
 
 
 
 
363
  */
364
+ public function get_user_by_hash()
365
  {
366
+ if (defined('DOING_AJAX') && DOING_AJAX && isset($_GET['hash'])) {
367
+ if (($cart = $this->getCart($_GET['hash']))) {
368
+ $this->respondJSON(array('success' => true, 'email' => $cart->email));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  }
370
  }
371
 
372
+ $this->respondJSON(array('success' => false, 'email' => false));
373
  }
374
 
375
  /**
376
+ *
377
  */
378
+ public function set_user_by_email()
379
  {
380
  if ($this->is_admin) {
381
+ $this->respondJSON(array('success' => false));
382
  }
383
 
384
+ if (defined('DOING_AJAX') && DOING_AJAX && isset($_GET['email'])) {
 
 
385
 
386
  $cookie_duration = $this->getCookieDuration();
387
 
388
+ $this->user_email = trim(str_replace(' ','+', $_GET['email']));
389
 
390
  if (($current_email = $this->getEmailFromSession()) && $current_email !== $this->user_email) {
391
  $this->previous_email = $current_email;
399
 
400
  $this->handleCartUpdated();
401
 
402
+ $this->respondJSON(array(
403
  'success' => true,
404
  'email' => $this->user_email,
405
  'previous' => $this->previous_email,
406
  'cart' => $this->cart,
407
+ ));
408
  }
409
+
410
+ $this->respondJSON(array('success' => false, 'email' => false));
411
  }
412
 
413
+
414
  /**
415
+ * @param string $time
416
+ * @return int
417
  */
418
+ protected function getCookieDuration($time = 'thirty_days')
419
  {
420
+ $durations = array(
421
+ 'one_day' => 86400, 'seven_days' => 604800, 'fourteen_days' => 1209600, 'thirty_days' => 2419200,
422
+ );
 
 
 
 
 
 
 
 
 
 
 
 
423
 
424
+ if (!array_key_exists($time, $durations)) {
425
+ $time = 'thirty_days';
426
  }
 
 
427
 
428
+ return time() + $durations[$time];
 
 
 
 
 
 
 
 
 
429
  }
430
 
431
  /**
includes/class-mailchimp-woocommerce.php CHANGED
@@ -148,8 +148,6 @@ class MailChimp_Woocommerce {
148
 
149
  $path = plugin_dir_path( dirname( __FILE__ ) );
150
 
151
- $this->slack();
152
-
153
  /** The abstract options class.*/
154
  require_once $path . 'includes/class-mailchimp-woocommerce-options.php';
155
 
@@ -212,31 +210,12 @@ class MailChimp_Woocommerce {
212
  require_once $path.'includes/processes/class-mailchimp-woocommerce-cart-update.php';
213
  require_once $path.'includes/processes/class-mailchimp-woocommerce-single-order.php';
214
  require_once $path.'includes/processes/class-mailchimp-woocommerce-single-product.php';
 
215
 
216
  // fire up the loader
217
  $this->loader = new MailChimp_Woocommerce_Loader();
218
  }
219
 
220
- /**
221
- *
222
- */
223
- private function slack()
224
- {
225
- $path = plugin_dir_path( dirname( __FILE__ ) );
226
-
227
- require_once $path.'includes/slack/Contracts/Http/Interactor.php';
228
- require_once $path.'includes/slack/Contracts/Http/Response.php';
229
- require_once $path.'includes/slack/Contracts/Http/ResponseFactory.php';
230
-
231
- require_once $path.'includes/slack/Core/Commander.php';
232
-
233
- require_once $path.'includes/slack/Http/CurlInteractor.php';
234
- require_once $path.'includes/slack/Http/SlackResponse.php';
235
- require_once $path.'includes/slack/Http/SlackResponseFactory.php';
236
-
237
- require_once $path.'includes/slack/Logger.php';
238
- }
239
-
240
  /**
241
  * Define the locale for this plugin for internationalization.
242
  *
@@ -310,7 +289,10 @@ class MailChimp_Woocommerce {
310
  $service->setEnvironment($this->environment);
311
  $service->setVersion($this->version);
312
 
313
- $this->loader->add_action('woocommerce_after_checkout_billing_form', $service, 'applyNewsletterField', 5);
 
 
 
314
  $this->loader->add_action('woocommerce_ppe_checkout_order_review', $service, 'applyNewsletterField', 5);
315
  $this->loader->add_action('woocommerce_register_form', $service, 'applyNewsletterField', 5);
316
 
@@ -354,6 +336,17 @@ class MailChimp_Woocommerce {
354
 
355
  // save post hook for products
356
  $this->loader->add_action('save_post', $service, 'handlePostSaved', 10, 3);
 
 
 
 
 
 
 
 
 
 
 
357
  }
358
  }
359
 
148
 
149
  $path = plugin_dir_path( dirname( __FILE__ ) );
150
 
 
 
151
  /** The abstract options class.*/
152
  require_once $path . 'includes/class-mailchimp-woocommerce-options.php';
153
 
210
  require_once $path.'includes/processes/class-mailchimp-woocommerce-cart-update.php';
211
  require_once $path.'includes/processes/class-mailchimp-woocommerce-single-order.php';
212
  require_once $path.'includes/processes/class-mailchimp-woocommerce-single-product.php';
213
+ require_once $path.'includes/processes/class-mailchimp-woocommerce-user-submit.php';
214
 
215
  // fire up the loader
216
  $this->loader = new MailChimp_Woocommerce_Loader();
217
  }
218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  /**
220
  * Define the locale for this plugin for internationalization.
221
  *
289
  $service->setEnvironment($this->environment);
290
  $service->setVersion($this->version);
291
 
292
+ // adding the ability to render the checkbox on another screen of the checkout page.
293
+ $render_on = $service->getOption('mailchimp_checkbox_action', 'woocommerce_after_checkout_billing_form');
294
+ $this->loader->add_action($render_on, $service, 'applyNewsletterField', 5);
295
+
296
  $this->loader->add_action('woocommerce_ppe_checkout_order_review', $service, 'applyNewsletterField', 5);
297
  $this->loader->add_action('woocommerce_register_form', $service, 'applyNewsletterField', 5);
298
 
336
 
337
  // save post hook for products
338
  $this->loader->add_action('save_post', $service, 'handlePostSaved', 10, 3);
339
+
340
+ // handle the user registration hook
341
+ $this->loader->add_action('user_register', $service, 'handleUserRegistration');
342
+ // handle the user updated profile hook
343
+ $this->loader->add_action('profile_update', $service, 'handleUserUpdated', 10, 2);
344
+
345
+ // when someone deletes a user??
346
+ //$this->loader->add_action('delete_user', $service, 'handleUserDeleting');
347
+
348
+ $this->loader->add_action('wp_ajax_nopriv_mailchimp_get_user_by_hash', $service, 'get_user_by_hash');
349
+ $this->loader->add_action('wp_ajax_nopriv_mailchimp_set_user_by_email', $service, 'set_user_by_email');
350
  }
351
  }
352
 
includes/processes/class-mailchimp-woocommerce-abstract-sync.php CHANGED
@@ -116,6 +116,9 @@ abstract class MailChimp_WooCommerce_Abtstract_Sync extends WP_Job
116
  $this->setData('sync.syncing', true);
117
  $this->setData('sync.started_at', time());
118
 
 
 
 
119
  // flag the store as syncing
120
  mailchimp_get_api()->flagStoreSync(mailchimp_get_store_id(), true);
121
 
116
  $this->setData('sync.syncing', true);
117
  $this->setData('sync.started_at', time());
118
 
119
+ $this->removeData('sync.products.current_page');
120
+ $this->removeData('sync.orders.current_page');
121
+
122
  // flag the store as syncing
123
  mailchimp_get_api()->flagStoreSync(mailchimp_get_store_id(), true);
124
 
includes/processes/class-mailchimp-woocommerce-process-products.php CHANGED
@@ -15,6 +15,15 @@ class MailChimp_WooCommerce_Process_Products extends MailChimp_WooCommerce_Abtst
15
  */
16
  protected $action = 'mailchimp_woocommerce_process_products';
17
 
 
 
 
 
 
 
 
 
 
18
  /**
19
  * @return string
20
  */
@@ -68,7 +77,15 @@ class MailChimp_WooCommerce_Process_Products extends MailChimp_WooCommerce_Abtst
68
  // add a timestamp for the product sync completion
69
  $this->setResourceCompleteTime();
70
 
71
- // since the products are all good, let's sync up the orders now.
72
- wp_queue(new MailChimp_WooCommerce_Process_Orders());
 
 
 
 
 
 
 
 
73
  }
74
  }
15
  */
16
  protected $action = 'mailchimp_woocommerce_process_products';
17
 
18
+
19
+ public static function push()
20
+ {
21
+ $job = new MailChimp_WooCommerce_Process_Products();
22
+ $job->flagStartSync();
23
+ wp_queue($job);
24
+ }
25
+
26
+
27
  /**
28
  * @return string
29
  */
77
  // add a timestamp for the product sync completion
78
  $this->setResourceCompleteTime();
79
 
80
+ $prevent_order_sync = get_option('mailchimp-woocommerce-sync.orders.prevent', false);
81
+
82
+ // only do this if we're not strictly syncing products ( which is the default ).
83
+ if (!$prevent_order_sync) {
84
+ // since the products are all good, let's sync up the orders now.
85
+ wp_queue(new MailChimp_WooCommerce_Process_Orders());
86
+ }
87
+
88
+ // since we skipped the orders feed we can delete this option.
89
+ delete_option('mailchimp-woocommerce-sync.orders.prevent');
90
  }
91
  }
includes/processes/class-mailchimp-woocommerce-user-submit.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Created by Vextras.
5
+ *
6
+ * Name: Ryan Hungate
7
+ * Email: ryan@vextras.com
8
+ * Date: 11/14/16
9
+ * Time: 9:38 AM
10
+ */
11
+ class MailChimp_WooCommerce_User_Submit extends WP_Job
12
+ {
13
+ public $user_id;
14
+ public $subscribed;
15
+ public $updated_data;
16
+
17
+ /**
18
+ * MailChimp_WooCommerce_User_Submit constructor.
19
+ * @param null $user_id
20
+ * @param null $subscribed
21
+ * @param WP_User|null $updated_data
22
+ */
23
+ public function __construct($user_id = null, $subscribed = null, $updated_data = null)
24
+ {
25
+ if (!empty($user_id)) {
26
+ $this->user_id = $user_id;
27
+ }
28
+
29
+ if (is_bool($subscribed)) {
30
+ $this->subscribed = $subscribed;
31
+ }
32
+
33
+ if (!empty($updated_data)) {
34
+ $this->updated_data = $updated_data->to_array();
35
+ }
36
+ }
37
+
38
+ /**
39
+ * @return bool
40
+ */
41
+ public function handle()
42
+ {
43
+ $options = get_option('mailchimp-woocommerce', array());
44
+ $store_id = mailchimp_get_store_id();
45
+
46
+ // load up the user.
47
+ $user = new WP_User($this->user_id);
48
+
49
+ // we need a valid user, a valid store id and options to continue
50
+ if ($user->ID <= 0 || empty($store_id) || !is_array($options)) {
51
+
52
+ // seems as if the database records are not being set by the time this queue job is fired,
53
+ // just a precautionary to make sure it's available during
54
+ sleep(3);
55
+
56
+ $options = get_option('mailchimp-woocommerce', array());
57
+ $store_id = mailchimp_get_store_id();
58
+
59
+ // load up the user.
60
+ $user = new WP_User($this->user_id);
61
+
62
+ if ($user->ID <= 0 || empty($store_id) || !is_array($options)) {
63
+ mailchimp_log('member.sync', 'Invalid Data For Submission :: '.$user->user_email);
64
+ return false;
65
+ }
66
+ }
67
+
68
+ // if we have a null value, we need to grab the correct user meta for is_subscribed
69
+ if (is_null($this->subscribed)) {
70
+ $this->subscribed = (bool) get_user_meta($this->user_id, 'mailchimp_woocommerce_is_subscribed', true);
71
+ }
72
+
73
+ $api_key = isset($options['mailchimp_api_key']) ? $options['mailchimp_api_key'] : false;
74
+ $list_id = isset($options['mailchimp_list']) ? $options['mailchimp_list'] : false;
75
+
76
+ // we need a valid api key and list id to continue
77
+ if (empty($api_key) || empty($list_id)) {
78
+ mailchimp_log('member.sync', 'Invalid Api Key or ListID :: '.$user->user_email);
79
+ return false;
80
+ }
81
+
82
+ $api = new MailChimp_WooCommerce_MailChimpApi($api_key);
83
+
84
+ $merge_vars = array();
85
+
86
+ $fn = trim($user->first_name);
87
+ $ln = trim($user->last_name);
88
+
89
+ if (!empty($fn)) $merge_vars['FNAME'] = $fn;
90
+ if (!empty($ln)) $merge_vars['LNAME'] = $ln;
91
+
92
+ try {
93
+
94
+ // see if we have a member.
95
+ $api->member($list_id, $user->user_email);
96
+
97
+ // if we're updating a member and the email is different, we need to delete the old person
98
+ if (is_array($this->updated_data) && isset($this->updated_data['user_email'])) {
99
+
100
+ if ($this->updated_data['user_email'] !== $user->user_email) {
101
+
102
+ // delete the old
103
+ $api->deleteMember($list_id, $this->updated_data['user_email']);
104
+
105
+ // subscribe the new
106
+ $api->subscribe($list_id, $user->user_email, $this->subscribed, $merge_vars);
107
+
108
+ mailchimp_log('member.sync', 'Subscriber Swap '.$this->updated_data['user_email'].' to '.$user->user_email, $merge_vars);
109
+
110
+ return false;
111
+ }
112
+ }
113
+
114
+ // ok let's update this member
115
+ $api->update($list_id, $user->user_email, $this->subscribed, $merge_vars);
116
+ mailchimp_log('member.sync', 'Updated Member '.$user->user_email, $merge_vars);
117
+ } catch (\Exception $e) {
118
+
119
+ // if we have a 404 not found, we can create the member
120
+ if ($e->getCode() == 404) {
121
+
122
+ try {
123
+ $api->subscribe($list_id, $user->user_email, $this->subscribed, $merge_vars);
124
+ mailchimp_log('member.sync', 'Subscribed Member '.$user->user_email, $merge_vars);
125
+ } catch (\Exception $e) {
126
+ mailchimp_log('member.sync', $e->getMessage());
127
+ }
128
+
129
+ return false;
130
+ }
131
+
132
+ mailchimp_log('member.sync', $e->getMessage());
133
+ }
134
+
135
+ return false;
136
+ }
137
+ }
includes/slack/Contracts/Http/Interactor.php DELETED
@@ -1,34 +0,0 @@
1
- <?php namespace Frlnc\Slack\Contracts\Http;
2
-
3
- interface Interactor {
4
-
5
- /**
6
- * Send a get request to a URL.
7
- *
8
- * @param string $url
9
- * @param array $parameters
10
- * @param array $headers
11
- * @return \Frlnc\Slack\Contracts\Http\Response
12
- */
13
- public function get($url, array $parameters = array(), array $headers = array());
14
-
15
- /**
16
- * Send a post request to a URL.
17
- *
18
- * @param string $url
19
- * @param array $urlParameters
20
- * @param array $postParameters
21
- * @param array $headers
22
- * @return \Frlnc\Slack\Contracts\Http\Response
23
- */
24
- public function post($url, array $urlParameters = array(), array $postParameters = array(), array $headers = array());
25
-
26
- /**
27
- * Sets the response factory to use.
28
- *
29
- * @param \Frlnc\Slack\Contracts\Http\ResponseFactory $factory
30
- * @return void
31
- */
32
- public function setResponseFactory(ResponseFactory $factory);
33
-
34
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/slack/Contracts/Http/Response.php DELETED
@@ -1,26 +0,0 @@
1
- <?php namespace Frlnc\Slack\Contracts\Http;
2
-
3
- interface Response {
4
-
5
- /**
6
- * Gets the body of the response.
7
- *
8
- * @return string
9
- */
10
- public function getBody();
11
-
12
- /**
13
- * Gets the headers of the response.
14
- *
15
- * @return array
16
- */
17
- public function getHeaders();
18
-
19
- /**
20
- * Gets the status code of the response.
21
- *
22
- * @return integer
23
- */
24
- public function getStatusCode();
25
-
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/slack/Contracts/Http/ResponseFactory.php DELETED
@@ -1,15 +0,0 @@
1
- <?php namespace Frlnc\Slack\Contracts\Http;
2
-
3
- interface ResponseFactory {
4
-
5
- /**
6
- * Builds the response.
7
- *
8
- * @param string $body
9
- * @param array $headers
10
- * @param integer $statusCode
11
- * @return \Frlnc\Slack\Contracts\Http\Response
12
- */
13
- public function build($body, array $headers, $statusCode);
14
-
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/slack/Core/Commander.php DELETED
@@ -1,508 +0,0 @@
1
- <?php namespace Frlnc\Slack\Core;
2
-
3
- use InvalidArgumentException;
4
- use Frlnc\Slack\Contracts\Http\Interactor;
5
-
6
- class Commander {
7
-
8
- /**
9
- * The default command headers.
10
- *
11
- * @var array
12
- */
13
- protected static $defaultHeaders = array();
14
-
15
- /**
16
- * The commands.
17
- *
18
- * @var array
19
- */
20
- protected static $commands = array(
21
- 'api.test' => array(
22
- 'endpoint' => '/api.test',
23
- 'token' => false
24
- ),
25
- 'auth.test' => array(
26
- 'endpoint' => '/auth.test',
27
- 'token' => true
28
- ),
29
- 'channels.archive' => array(
30
- 'token' => true,
31
- 'endpoint' => '/channels.archive'
32
- ),
33
- 'channels.create' => array(
34
- 'token' => true,
35
- 'endpoint' => '/channels.create'
36
- ),
37
- 'channels.history' => array(
38
- 'token' => true,
39
- 'endpoint' => '/channels.history'
40
- ),
41
- 'channels.info' => array(
42
- 'token' => true,
43
- 'endpoint' => '/channels.info'
44
- ),
45
- 'channels.invite' => array(
46
- 'token' => true,
47
- 'endpoint' => '/channels.invite'
48
- ),
49
- 'channels.join' => array(
50
- 'token' => true,
51
- 'endpoint' => '/channels.join'
52
- ),
53
- 'channels.kick' => array(
54
- 'token' => true,
55
- 'endpoint' => '/channels.kick'
56
- ),
57
- 'channels.leave' => array(
58
- 'token' => true,
59
- 'endpoint' => '/channels.leave'
60
- ),
61
- 'channels.list' => array(
62
- 'token' => true,
63
- 'endpoint' => '/channels.list'
64
- ),
65
- 'channels.mark' => array(
66
- 'token' => true,
67
- 'endpoint' => '/channels.mark'
68
- ),
69
- 'channels.rename' => array(
70
- 'token' => true,
71
- 'endpoint' => '/channels.rename'
72
- ),
73
- 'channels.setPurpose' => array(
74
- 'token' => true,
75
- 'endpoint' => '/channels.setPurpose',
76
- 'format' => array(
77
- 'purpose'
78
- ),
79
- ),
80
- 'channels.setTopic' => array(
81
- 'token' => true,
82
- 'endpoint' => '/channels.setTopic',
83
- 'format' => array(
84
- 'topic'
85
- )
86
- ),
87
- 'channels.unarchive' => array(
88
- 'token' => true,
89
- 'endpoint' => '/channels.unarchive'
90
- ),
91
- 'chat.delete' => array(
92
- 'token' => true,
93
- 'endpoint' => '/chat.delete'
94
- ),
95
- 'chat.postMessage' => array(
96
- 'token' => true,
97
- 'endpoint' => '/chat.postMessage',
98
- 'format' => array(
99
- 'text',
100
- 'username'
101
- ),
102
- ),
103
- 'chat.update' => array(
104
- 'token' => true,
105
- 'endpoint' => '/chat.update',
106
- 'format' => array(
107
- 'text'
108
- )
109
- ),
110
- 'dnd.endDnd' => array(
111
- 'token' => true,
112
- 'endpoint' => '/dnd.endDnd'
113
- ),
114
- 'dnd.endSnooze' => array(
115
- 'token' => true,
116
- 'endpoint' => '/dnd.endSnooze'
117
- ),
118
- 'dnd.info' => array(
119
- 'token' => true,
120
- 'endpoint' => '/dnd.info'
121
- ),
122
- 'dnd.setSnooze' => array(
123
- 'token' => true,
124
- 'endpoint' => '/dnd.setSnooze'
125
- ),
126
- 'dnd.teamInfo' => array(
127
- 'token' => true,
128
- 'endpoint' => '/dnd.teamInfo'
129
- ),
130
- 'emoji.list' => array(
131
- 'token' => true,
132
- 'endpoint' => '/emoji.list'
133
- ),
134
- 'files.comments.add' => array(
135
- 'token' => true,
136
- 'endpoint' => '/files.comments.add'
137
- ),
138
- 'files.comments.delete' => array(
139
- 'token' => true,
140
- 'endpoint' => '/files.comments.delete'
141
- ),
142
- 'files.comments.edit' => array(
143
- 'token' => true,
144
- 'endpoint' => '/files.comments.edit'
145
- ),
146
- 'files.delete' => array(
147
- 'token' => true,
148
- 'endpoint' => '/files.delete'
149
- ),
150
- 'files.info' => array(
151
- 'token' => true,
152
- 'endpoint' => '/files.info'
153
- ),
154
- 'files.list' => array(
155
- 'token' => true,
156
- 'endpoint' => '/files.list'
157
- ),
158
- 'files.revokePublicURL' => array(
159
- 'token' => true,
160
- 'endpoint' => '/files.revokePublicURL'
161
- ),
162
- 'files.sharedPublcURL' => array(
163
- 'token' => true,
164
- 'endpoint' => '/files.sharedPublcURL'
165
- ),
166
- 'files.upload' => array(
167
- 'token' => true,
168
- 'endpoint' => '/files.upload',
169
- 'post' => true,
170
- 'headers' => array(
171
- 'Content-Type' => 'multipart/form-data'
172
- ),
173
- 'format' => array(
174
- 'filename',
175
- 'title',
176
- 'initial_comment'
177
- ),
178
- ),
179
- 'groups.archive' => array(
180
- 'token' => true,
181
- 'endpoint' => '/groups.archive'
182
- ),
183
- 'groups.close' => array(
184
- 'token' => true,
185
- 'endpoint' => '/groups.close'
186
- ),
187
- 'groups.create' => array(
188
- 'token' => true,
189
- 'endpoint' => '/groups.create',
190
- 'format' => array(
191
- 'name'
192
- ),
193
- ),
194
- 'groups.createChild' => array(
195
- 'token' => true,
196
- 'endpoint' => '/groups.createChild'
197
- ),
198
- 'groups.history' => array(
199
- 'token' => true,
200
- 'endpoint' => '/groups.history'
201
- ),
202
- 'groups.info' => array(
203
- 'token' => true,
204
- 'endpoint' => '/groups.info'
205
- ),
206
- 'groups.invite' => array(
207
- 'token' => true,
208
- 'endpoint' => '/groups.invite'
209
- ),
210
- 'groups.kick' => array(
211
- 'token' => true,
212
- 'endpoint' => '/groups.kick'
213
- ),
214
- 'groups.leave' => array(
215
- 'token' => true,
216
- 'endpoint' => '/groups.leave'
217
- ),
218
- 'groups.list' => array(
219
- 'token' => true,
220
- 'endpoint' => '/groups.list'
221
- ),
222
- 'groups.mark' => array(
223
- 'token' => true,
224
- 'endpoint' => '/groups.mark'
225
- ),
226
- 'groups.open' => array(
227
- 'token' => true,
228
- 'endpoint' => '/groups.open'
229
- ),
230
- 'groups.rename' => array(
231
- 'token' => true,
232
- 'endpoint' => '/groups.rename'
233
- ),
234
- 'groups.setPurpose' => array(
235
- 'token' => true,
236
- 'endpoint' => '/groups.setPurpose',
237
- 'format' => array(
238
- 'purpose'
239
- ),
240
- ),
241
- 'groups.setTopic' => array(
242
- 'token' => true,
243
- 'endpoint' => '/groups.setTopic',
244
- 'format' => array(
245
- 'topic'
246
- ),
247
- ),
248
- 'groups.unarchive' => array(
249
- 'token' => true,
250
- 'endpoint' => '/groups.unarchive'
251
- ),
252
- 'im.close' => array(
253
- 'token' => true,
254
- 'endpoint' => '/im.close'
255
- ),
256
- 'im.history' => array(
257
- 'token' => true,
258
- 'endpoint' => '/im.history'
259
- ),
260
- 'im.list' => array(
261
- 'token' => true,
262
- 'endpoint' => '/im.list'
263
- ),
264
- 'im.mark' => array(
265
- 'token' => true,
266
- 'endpoint' => '/im.mark'
267
- ),
268
- 'im.open' => array(
269
- 'token' => true,
270
- 'endpoint' => '/im.open'
271
- ),
272
- 'mpim.close' => array(
273
- 'token' => true,
274
- 'endpoint' => '/mpim.close'
275
- ),
276
- 'mpmim.history' => array(
277
- 'token' => true,
278
- 'endpoint' => '/mpmim.history'
279
- ),
280
- 'mpim.list' => array(
281
- 'token' => true,
282
- 'endpoint' => '/mpim.list'
283
- ),
284
- 'mpim.mark' => array(
285
- 'token' => true,
286
- 'endpoint' => '/mpim.mark'
287
- ),
288
- 'mpim.open' => array(
289
- 'token' => true,
290
- 'endpoint' => '/mpim.open'
291
- ),
292
- 'oauth.access' => array(
293
- 'token' => false,
294
- 'endpoint' => '/oauth.access'
295
- ),
296
- 'pins.add' => array(
297
- 'token' => true,
298
- 'endpoint' => '/pins.add'
299
- ),
300
- 'pins.list' => array(
301
- 'token' => true,
302
- 'endpoint' => '/pins.list'
303
- ),
304
- 'pins.remove' => array(
305
- 'token' => true,
306
- 'endpoint' => '/pins.remove'
307
- ),
308
- 'reactions.add' => array(
309
- 'token' => true,
310
- 'endpoint' => '/reactions.add'
311
- ),
312
- 'reactions.get' => array(
313
- 'token' => true,
314
- 'endpoint' => '/reactions.get'
315
- ),
316
- 'reactions.list' => array(
317
- 'token' => true,
318
- 'endpoint' => '/reactions.list'
319
- ),
320
- 'reactions.remove' => array(
321
- 'token' => true,
322
- 'endpoint' => '/reactions.remove'
323
- ),
324
- 'rtm.start' => array(
325
- 'token' => true,
326
- 'endpoint' => '/rtm.start'
327
- ),
328
- 'search.all' => array(
329
- 'token' => true,
330
- 'endpoint' => '/search.all'
331
- ),
332
- 'search.files' => array(
333
- 'token' => true,
334
- 'endpoint' => '/search.files'
335
- ),
336
- 'search.messages' => array(
337
- 'token' => true,
338
- 'endpoint' => '/search.messages'
339
- ),
340
- 'stars.add' => array(
341
- 'token' => true,
342
- 'endpoint' => '/stars.add'
343
- ),
344
- 'stars.list' => array(
345
- 'token' => true,
346
- 'endpoint' => '/stars.list'
347
- ),
348
- 'stars.remove' => array(
349
- 'token' => true,
350
- 'endpoint' => '/stars.remove'
351
- ),
352
- 'team.accessLogs' => array(
353
- 'token' => true,
354
- 'endpoint' => '/team.accessLogs'
355
- ),
356
- 'team.info' => array(
357
- 'token' => true,
358
- 'endpoint' => '/team.info'
359
- ),
360
- 'team.integrationLogs' => array(
361
- 'token' => true,
362
- 'endpoint' => '/team.integrationLogs'
363
- ),
364
- 'usergroups.create' => array(
365
- 'token' => true,
366
- 'endpoint' => '/usergroups.create'
367
- ),
368
- 'usergroups.disable' => array(
369
- 'token' => true,
370
- 'endpoint' => '/usergroups.disable'
371
- ),
372
- 'usergroups.enable' => array(
373
- 'token' => true,
374
- 'endpoint' => '/usergroups.enable'
375
- ),
376
- 'usergroups.list' => array(
377
- 'token' => true,
378
- 'endpoint' => '/usergroups.list'
379
- ),
380
- 'usergroups.update' => array(
381
- 'token' => true,
382
- 'endpoint' => '/usergroups.update'
383
- ),
384
- 'usergroups.users.list' => array(
385
- 'token' => true,
386
- 'endpoint' => '/usergroups.users.list'
387
- ),
388
- 'usergroups.users.update' => array(
389
- 'token' => true,
390
- 'endpoint' => '/usergroups.users.update'
391
- ),
392
- 'users.getPresence' => array(
393
- 'token' => true,
394
- 'endpoint' => '/users.getPresence'
395
- ),
396
- 'users.info' => array(
397
- 'token' => true,
398
- 'endpoint' => '/users.info'
399
- ),
400
- 'users.list' => array(
401
- 'token' => true,
402
- 'endpoint' => '/users.list'
403
- ),
404
- 'users.setActive' => array(
405
- 'token' => true,
406
- 'endpoint' => '/users.setActive'
407
- ),
408
- 'users.setPresence' => array(
409
- 'token' => true,
410
- 'endpoint' => '/users.setPresence'
411
- ),
412
- 'users.admin.invite' => array(
413
- 'token' => true,
414
- 'endpoint' => '/users.admin.invite'
415
- ),
416
- );
417
-
418
- /**
419
- * The base URL.
420
- *
421
- * @var string
422
- */
423
- protected static $baseUrl = 'https://slack.com/api';
424
-
425
- /**
426
- * The API token.
427
- *
428
- * @var string
429
- */
430
- protected $token;
431
-
432
- /**
433
- * The Http interactor.
434
- *
435
- * @var \Frlnc\Slack\Contracts\Http\Interactor
436
- */
437
- protected $interactor;
438
-
439
- /**
440
- * @param string $token
441
- * @param \Frlnc\Slack\Contracts\Http\Interactor $interactor
442
- */
443
- public function __construct($token, Interactor $interactor)
444
- {
445
- $this->token = $token;
446
- $this->interactor = $interactor;
447
- }
448
-
449
- /**
450
- * Executes a command.
451
- *
452
- * @param string $command
453
- * @param array $parameters
454
- * @return \Frlnc\Slack\Contracts\Http\Response
455
- */
456
- public function execute($command, array $parameters = array())
457
- {
458
- if (!isset(self::$commands[$command]))
459
- throw new InvalidArgumentException("The command '{$command}' is not currently supported");
460
-
461
- $command = self::$commands[$command];
462
-
463
- if ($command['token'])
464
- $parameters = array_merge($parameters, array('token' => $this->token));
465
-
466
- if (isset($command['format']))
467
- foreach ($command['format'] as $format)
468
- if (isset($parameters[$format]))
469
- $parameters[$format] = self::format($parameters[$format]);
470
-
471
- $headers = array();
472
- if (isset($command['headers']))
473
- $headers = $command['headers'];
474
-
475
- $url = self::$baseUrl . $command['endpoint'];
476
-
477
- if (isset($command['post']) && $command['post'])
478
- return $this->interactor->post($url, array(), $parameters, $headers);
479
-
480
- return $this->interactor->get($url, $parameters, $headers);
481
- }
482
-
483
- /**
484
- * Sets the token.
485
- *
486
- * @param string $token
487
- */
488
- public function setToken($token)
489
- {
490
- $this->token = $token;
491
- }
492
-
493
- /**
494
- * Formats a string for Slack.
495
- *
496
- * @param string $string
497
- * @return string
498
- */
499
- public static function format($string)
500
- {
501
- $string = str_replace('&', '&amp;', $string);
502
- $string = str_replace('<', '&lt;', $string);
503
- $string = str_replace('>', '&gt;', $string);
504
-
505
- return $string;
506
- }
507
-
508
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/slack/Http/CurlInteractor.php DELETED
@@ -1,106 +0,0 @@
1
- <?php namespace Frlnc\Slack\Http;
2
-
3
- use Frlnc\Slack\Contracts\Http\ResponseFactory;
4
-
5
- class CurlInteractor implements \Frlnc\Slack\Contracts\Http\Interactor {
6
-
7
- /**
8
- * The response factory to use.
9
- *
10
- * @var \Frlnc\Slack\Contracts\Http\ResponseFactory
11
- */
12
- protected $factory;
13
-
14
- /**
15
- * {@inheritdoc}
16
- */
17
- public function get($url, array $parameters = array(), array $headers = array())
18
- {
19
- $request = $this->prepareRequest($url, $parameters, $headers);
20
-
21
- return $this->executeRequest($request);
22
- }
23
-
24
- /**
25
- * {@inheritdoc}
26
- */
27
- public function post($url, array $urlParameters = array(), array $postParameters = array(), array $headers = array())
28
- {
29
- $request = $this->prepareRequest($url, $urlParameters, $headers);
30
-
31
- curl_setopt($request, CURLOPT_POST, count($postParameters));
32
- curl_setopt($request, CURLOPT_POSTFIELDS, http_build_query($postParameters));
33
-
34
- return $this->executeRequest($request);
35
- }
36
-
37
- /**
38
- * Prepares a request using curl.
39
- *
40
- * @param string $url [description]
41
- * @param array $parameters [description]
42
- * @param array $headers [description]
43
- * @return resource
44
- */
45
- protected static function prepareRequest($url, $parameters = array(), $headers = array())
46
- {
47
- $request = curl_init();
48
-
49
- if ($query = http_build_query($parameters))
50
- $url .= '?' . $query;
51
-
52
- curl_setopt($request, CURLOPT_URL, $url);
53
- curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
54
- curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
55
- curl_setopt($request, CURLINFO_HEADER_OUT, true);
56
- curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
57
-
58
- return $request;
59
- }
60
-
61
- /**
62
- * Executes a curl request.
63
- *
64
- * @param resource $request
65
- * @return \Frlnc\Slack\Contracts\Http\Response
66
- */
67
- public function executeRequest($request)
68
- {
69
- $body = curl_exec($request);
70
- $info = curl_getinfo($request);
71
-
72
- curl_close($request);
73
-
74
- $statusCode = $info['http_code'];
75
- $headers = $info['request_header'];
76
-
77
- if (function_exists('http_parse_headers'))
78
- $headers = http_parse_headers($headers);
79
- else
80
- {
81
- $header_text = substr($headers, 0, strpos($headers, "\r\n\r\n"));
82
- $headers = array();
83
-
84
- foreach (explode("\r\n", $header_text) as $i => $line)
85
- if ($i === 0)
86
- continue;
87
- else
88
- {
89
- list ($key, $value) = explode(': ', $line);
90
-
91
- $headers[$key] = $value;
92
- }
93
- }
94
-
95
- return $this->factory->build($body, $headers, $statusCode);
96
- }
97
-
98
- /**
99
- * {@inheritdoc}
100
- */
101
- public function setResponseFactory(ResponseFactory $factory)
102
- {
103
- $this->factory = $factory;
104
- }
105
-
106
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/slack/Http/SlackResponse.php DELETED
@@ -1,84 +0,0 @@
1
- <?php namespace Frlnc\Slack\Http;
2
-
3
- class SlackResponse implements \Frlnc\Slack\Contracts\Http\Response, \JsonSerializable {
4
-
5
- /**
6
- * The response body.
7
- *
8
- * @var string
9
- */
10
- protected $body;
11
-
12
- /**
13
- * The response headers.
14
- *
15
- * @var array
16
- */
17
- protected $headers;
18
-
19
- /**
20
- * The response status code.
21
- *
22
- * @var integer
23
- */
24
- protected $statusCode;
25
-
26
- /**
27
- * @param string $body
28
- * @param array $headers
29
- * @param integer $statusCode
30
- */
31
- public function __construct($body, array $headers = array(), $statusCode = 404)
32
- {
33
- $this->body = json_decode($body, true);
34
- $this->headers = $headers;
35
- $this->statusCode = $statusCode;
36
- }
37
-
38
- /**
39
- * {@inheritdoc}
40
- */
41
- public function getBody()
42
- {
43
- return $this->body;
44
- }
45
-
46
- /**
47
- * {@inheritdoc}
48
- */
49
- public function getHeaders()
50
- {
51
- return $this->headers;
52
- }
53
-
54
- /**
55
- * {@inheritdoc}
56
- */
57
- public function getStatusCode()
58
- {
59
- return $this->statusCode;
60
- }
61
-
62
- /**
63
- * {@inheritdoc}
64
- */
65
- public function jsonSerialize()
66
- {
67
- return $this->toArray();
68
- }
69
-
70
- /**
71
- * Converts the response to an array.
72
- *
73
- * @return array
74
- */
75
- public function toArray()
76
- {
77
- return array(
78
- 'status_code' => $this->getStatusCode(),
79
- 'headers' => $this->getHeaders(),
80
- 'body' => $this->getBody()
81
- );
82
- }
83
-
84
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/slack/Http/SlackResponseFactory.php DELETED
@@ -1,13 +0,0 @@
1
- <?php namespace Frlnc\Slack\Http;
2
-
3
- class SlackResponseFactory implements \Frlnc\Slack\Contracts\Http\ResponseFactory {
4
-
5
- /**
6
- * {@inheritdoc}
7
- */
8
- public function build($body, array $headers, $statusCode)
9
- {
10
- return new SlackResponse($body, $headers, $statusCode);
11
- }
12
-
13
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/slack/Logger.php DELETED
@@ -1,93 +0,0 @@
1
- <?php namespace Frlnc\Slack;
2
-
3
- use Frlnc\Slack\Http\CurlInteractor;
4
- use Frlnc\Slack\Http\SlackResponseFactory;
5
- use Frlnc\Slack\Core\Commander;
6
-
7
- /**
8
- * Created by Vextras.
9
- *
10
- * Name: Ryan Hungate
11
- * Email: ryan@vextras.com
12
- * Date: 8/12/16
13
- * Time: 9:36 AM
14
- */
15
- class Logger
16
- {
17
- private static $instance = null;
18
-
19
- /**
20
- * @var null|Commander
21
- */
22
- private $commander = null;
23
- public $api_token = null;
24
- public $channel = null;
25
-
26
-
27
- /**
28
- * @return mixed
29
- */
30
- public static function instance()
31
- {
32
- if (empty(static::$instance)) {
33
- $vars = mailchimp_environment_variables();
34
- static::$instance = new Logger(
35
- (isset($vars->slack_token) ? $vars->slack_token : null),
36
- (isset($vars->slack_channel) ? $vars->slack_channel : null)
37
- );
38
- }
39
- return static::$instance;
40
- }
41
-
42
- /**
43
- * Logger constructor.
44
- * @param string $api_token
45
- * @param string $channel
46
- */
47
- public function __construct($api_token = null, $channel = null)
48
- {
49
- if ($api_token && $channel) {
50
- $this->setup($api_token, $channel);
51
- }
52
- }
53
-
54
- /**
55
- * @param $api_token
56
- * @param $channel
57
- * @return $this
58
- */
59
- public function setup($api_token, $channel)
60
- {
61
- $this->channel = $channel;
62
- $this->api_token = $api_token;
63
-
64
- $curl = new CurlInteractor;
65
- $curl->setResponseFactory(new SlackResponseFactory);
66
-
67
- $this->commander = new Commander($this->api_token, $curl);
68
-
69
- return $this;
70
- }
71
-
72
- /**
73
- * @param $message
74
- * @return Logger
75
- */
76
- public function notice($message)
77
- {
78
- if (empty($this->commander) || empty($this->api_token) || empty($this->channel)) {
79
- return $this;
80
- }
81
-
82
- try {
83
- $this->commander->execute('chat.postMessage', array(
84
- 'channel' => '#'.$this->channel,
85
- 'text' => $message
86
- ));
87
- } catch (\Exception $e) {
88
-
89
- }
90
-
91
- return $this;
92
- }
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
mailchimp-woocommerce.php CHANGED
@@ -16,7 +16,7 @@
16
  * Plugin Name: MailChimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
- * Version: 1.0.6
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
@@ -34,15 +34,28 @@ if ( ! defined( 'WPINC' ) ) {
34
  * @return object
35
  */
36
  function mailchimp_environment_variables() {
 
 
37
  return (object) array(
38
  'repo' => 'master',
39
  'environment' => 'production',
40
- 'version' => '1.0.6',
41
- 'slack_token' => false,
42
- 'slack_channel' => 'mc-woo',
43
  );
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  /**
47
  * @return string
48
  */
@@ -94,7 +107,14 @@ function mailchimp_get_data($key, $default) {
94
  function mailchimp_date_utc($date) {
95
  $timezone = wc_timezone_string();
96
  //$timezone = mailchimp_get_option('store_timezone', 'America/New_York');
97
- $date = new \DateTime($date, new DateTimeZone($timezone));
 
 
 
 
 
 
 
98
  $date->setTimezone(new DateTimeZone('UTC'));
99
  return $date;
100
  }
@@ -105,7 +125,14 @@ function mailchimp_date_utc($date) {
105
  */
106
  function mailchimp_date_local($date) {
107
  $timezone = mailchimp_get_option('store_timezone', 'America/New_York');
108
- $date = new \DateTime($date, new DateTimeZone('UTC'));
 
 
 
 
 
 
 
109
  $date->setTimezone(new DateTimeZone($timezone));
110
  return $date;
111
  }
@@ -190,8 +217,10 @@ function run_mailchimp_plugin_updater() {
190
  if (!class_exists('PucFactory')) {
191
  require plugin_dir_path( __FILE__ ) . 'includes/plugin-update-checker/plugin-update-checker.php';
192
  }
 
193
  /** @var \PucGitHubChecker_3_1 $checker */
194
  $updater = PucFactory::getLatestClassVersion('PucGitHubChecker');
 
195
  if (class_exists($updater)) {
196
  $env = mailchimp_environment_variables();
197
  $checker = new $updater('https://github.com/mailchimp/mc-woocommerce/', __FILE__, $env->repo, 1);
@@ -199,14 +228,6 @@ function run_mailchimp_plugin_updater() {
199
  }
200
  }
201
 
202
- /**
203
- * @return \Frlnc\Slack\Logger
204
- */
205
- function slack()
206
- {
207
- return Frlnc\Slack\Logger::instance();
208
- }
209
-
210
  /**
211
  * @param $action
212
  * @param $message
@@ -231,14 +252,6 @@ function mailchimp_log($action, $message, $data = array())
231
  'data' => $data,
232
  );
233
 
234
- $slack_message = "$action :: $message";
235
-
236
- if (!empty($data['data'])) {
237
- $slack_message .= "\n\n".(print_r($data['data'], true));
238
- }
239
-
240
- slack()->notice($slack_message);
241
-
242
  return wp_remote_post($options->endpoint, array(
243
  'headers' => array(
244
  'Accept: application/json',
@@ -266,6 +279,47 @@ function mailchimp_string_contains($haystack, $needles)
266
  return false;
267
  }
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce' );
270
  register_deactivation_hook( __FILE__, 'deactivate_mailchimp_woocommerce' );
271
 
16
  * Plugin Name: MailChimp for WooCommerce
17
  * Plugin URI: https://mailchimp.com/connect-your-store/
18
  * Description: MailChimp - WooCommerce plugin
19
+ * Version: 1.0.70
20
  * Author: MailChimp
21
  * Author URI: https://mailchimp.com
22
  * License: GPL-2.0+
34
  * @return object
35
  */
36
  function mailchimp_environment_variables() {
37
+ global $wp_version;
38
+
39
  return (object) array(
40
  'repo' => 'master',
41
  'environment' => 'production',
42
+ 'version' => '1.0.70',
43
+ 'wp_version' => (empty($wp_version) ? 'Unknown' : $wp_version),
 
44
  );
45
  }
46
 
47
+ /**
48
+ * @return bool|int
49
+ */
50
+ function mailchimp_get_list_id() {
51
+ if (($options = get_option('mailchimp-woocommerce', false)) && is_array($options)) {
52
+ if (isset($options['mailchimp_list'])) {
53
+ return $options['mailchimp_list'];
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+
59
  /**
60
  * @return string
61
  */
107
  function mailchimp_date_utc($date) {
108
  $timezone = wc_timezone_string();
109
  //$timezone = mailchimp_get_option('store_timezone', 'America/New_York');
110
+ if (is_numeric($date)) {
111
+ $stamp = $date;
112
+ $date = new \DateTime('now', new DateTimeZone($timezone));
113
+ $date->setTimestamp($stamp);
114
+ } else {
115
+ $date = new \DateTime($date, new DateTimeZone($timezone));
116
+ }
117
+
118
  $date->setTimezone(new DateTimeZone('UTC'));
119
  return $date;
120
  }
125
  */
126
  function mailchimp_date_local($date) {
127
  $timezone = mailchimp_get_option('store_timezone', 'America/New_York');
128
+ if (is_numeric($date)) {
129
+ $stamp = $date;
130
+ $date = new \DateTime('now', new DateTimeZone('UTC'));
131
+ $date->setTimestamp($stamp);
132
+ } else {
133
+ $date = new \DateTime($date, new DateTimeZone('UTC'));
134
+ }
135
+
136
  $date->setTimezone(new DateTimeZone($timezone));
137
  return $date;
138
  }
217
  if (!class_exists('PucFactory')) {
218
  require plugin_dir_path( __FILE__ ) . 'includes/plugin-update-checker/plugin-update-checker.php';
219
  }
220
+
221
  /** @var \PucGitHubChecker_3_1 $checker */
222
  $updater = PucFactory::getLatestClassVersion('PucGitHubChecker');
223
+
224
  if (class_exists($updater)) {
225
  $env = mailchimp_environment_variables();
226
  $checker = new $updater('https://github.com/mailchimp/mc-woocommerce/', __FILE__, $env->repo, 1);
228
  }
229
  }
230
 
 
 
 
 
 
 
 
 
231
  /**
232
  * @param $action
233
  * @param $message
252
  'data' => $data,
253
  );
254
 
 
 
 
 
 
 
 
 
255
  return wp_remote_post($options->endpoint, array(
256
  'headers' => array(
257
  'Accept: application/json',
279
  return false;
280
  }
281
 
282
+
283
+ /**
284
+ * @return int
285
+ */
286
+ function mailchimp_get_product_count() {
287
+ $posts = mailchimp_count_posts('product');
288
+ $total = 0;
289
+ foreach ($posts as $status => $count) {
290
+ $total += $count;
291
+ }
292
+ return $total;
293
+ }
294
+
295
+ /**
296
+ * @return int
297
+ */
298
+ function mailchimp_get_order_count() {
299
+ $posts = mailchimp_count_posts('shop_order');
300
+ unset($posts['auto-draft']);
301
+ $total = 0;
302
+ foreach ($posts as $status => $count) {
303
+ $total += $count;
304
+ }
305
+ return $total;
306
+ }
307
+
308
+ /**
309
+ * @param $type
310
+ * @return array|null|object
311
+ */
312
+ function mailchimp_count_posts($type) {
313
+ global $wpdb;
314
+ $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s GROUP BY post_status";
315
+ $posts = $wpdb->get_results( $wpdb->prepare($query, $type));
316
+ $response = array();
317
+ foreach ($posts as $post) {
318
+ $response[$post->post_status] = $post->num_posts;
319
+ }
320
+ return $response;
321
+ }
322
+
323
  register_activation_hook( __FILE__, 'activate_mailchimp_woocommerce' );
324
  register_deactivation_hook( __FILE__, 'deactivate_mailchimp_woocommerce' );
325
 
public/class-mailchimp-woocommerce-public.php CHANGED
@@ -51,7 +51,6 @@ class MailChimp_Woocommerce_Public {
51
 
52
  $this->plugin_name = $plugin_name;
53
  $this->version = $version;
54
-
55
  }
56
 
57
  /**
@@ -73,7 +72,7 @@ class MailChimp_Woocommerce_Public {
73
  * class.
74
  */
75
 
76
- wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mailchimp-woocommerce-public.css', array(), $this->version, 'all' );
77
 
78
  }
79
 
@@ -96,10 +95,11 @@ class MailChimp_Woocommerce_Public {
96
  * class.
97
  */
98
 
99
- wp_register_script($this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailchimp-woocommerce-public.js', array(), $this->version, false);
100
 
101
- wp_localize_script($this->plugin_name, 'public_data', array(
102
  'site_url' => site_url(),
 
103
  ));
104
 
105
  // Enqueued script with localized data.
51
 
52
  $this->plugin_name = $plugin_name;
53
  $this->version = $version;
 
54
  }
55
 
56
  /**
72
  * class.
73
  */
74
 
75
+ //wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mailchimp-woocommerce-public.css', array(), $this->version, 'all' );
76
 
77
  }
78
 
95
  * class.
96
  */
97
 
98
+ wp_register_script($this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailchimp-woocommerce-public.min.js', array(), $this->version, false);
99
 
100
+ wp_localize_script($this->plugin_name, 'mailchimp_public_data', array(
101
  'site_url' => site_url(),
102
+ 'ajax_url' => admin_url('admin-ajax.php'),
103
  ));
104
 
105
  // Enqueued script with localized data.
public/js/mailchimp-woocommerce-public.js CHANGED
@@ -1,341 +1,141 @@
1
- var mailchimp;
2
- var mailchimp_cart;
3
- var mailchimp_public_data;
4
- var mailchimp_billing_email;
5
-
6
- var mailchimpReady = function(f){
7
- /in/.test(document.readyState)?setTimeout('mailchimpReady('+f+')',9):f()
8
- };
9
-
10
- function mailchimpGetCurrentUserByHash(hash) {
11
- try {
12
- var get_email_url = mailchimp_public_data.site_url+
13
- '?mailchimp-woocommerce[action]=parse-email&mailchimp-woocommerce[submission][hash]='+hash;
14
-
15
- var get_email_request = new XMLHttpRequest();
16
-
17
- get_email_request.open('POST', get_email_url, true);
18
- get_email_request.onload = function() {
19
- if (get_email_request.status >= 200 && get_email_request.status < 400) {
20
- var response_json = JSON.parse(get_email_request.responseText);
21
- if (mailchimp_cart.valueEmail(response_json.email)) {
22
- mailchimp_cart.setEmail(response_json.email);
23
- console.log('mailchimp', 'setting '+response_json.email+' as the current user');
24
- }
25
- } else {
26
- console.log('error', get_email_request.responseText);
27
- }
28
- };
29
-
30
- get_email_request.onerror = function() {
31
- console.log('get email error', get_email_request.responseText);
32
- };
33
-
34
- get_email_request.setRequestHeader('Content-Type', 'application/json');
35
- get_email_request.setRequestHeader('Accept', 'application/json');
36
- get_email_request.send();
37
- } catch (e) {console.log('mailchimp.get_email_by_hasn.error', e);}
38
  }
39
-
40
  function mailchimpHandleBillingEmail() {
41
-
42
- var billing_email = document.querySelector('#billing_email');
43
- var user = undefined !== billing_email ? billing_email.value : '';
44
-
45
- if (!mailchimp_cart.valueEmail(user)) {
46
- return false;
47
- }
48
-
49
- mailchimp_cart.setEmail(user);
50
-
51
- try {
52
- var submit_email_url = mailchimp_public_data.site_url+
53
- '?mailchimp-woocommerce[action]=submit-email&mailchimp-woocommerce[submission][email]='+user;
54
-
55
- var submit_email_request = new XMLHttpRequest();
56
-
57
- submit_email_request.open('POST', submit_email_url, true);
58
-
59
- submit_email_request.onload = function() {
60
- if (submit_email_request.status >= 200 && submit_email_request.status < 400) {
61
- console.log('success', submit_email_request.responseText);
62
- } else {
63
- console.log('error', submit_email_request.responseText);
64
- }
65
- };
66
-
67
- submit_email_request.onerror = function() {
68
- console.log('submit email error', submit_email_request.responseText);
69
- };
70
-
71
- submit_email_request.setRequestHeader('Content-Type', 'application/json');
72
- submit_email_request.setRequestHeader('Accept', 'application/json');
73
- submit_email_request.send();
74
-
75
- } catch (e) {console.log('mailchimp_campaign_tracking.error', e);}
76
  }
77
-
78
- (function() {
79
- 'use strict';
80
- var requestTransport = null;
81
- var scriptTagCounter = 1, head;
82
- var storageLife = "30";
83
- var clientIP = null;
84
- var saved_ip;
85
- var script;
86
-
87
- mailchimp_public_data = public_data || {site_url:document.location.origin};
88
-
89
- function invokeJsonp(fullUrl, cacheOk)
90
- {
91
- var c = cacheOk || true;
92
- script = buildScriptTag(fullUrl, c);
93
- if (typeof head != 'object') {
94
- head = document.getElementsByTagName("head").item(0);
95
- }
96
- head.appendChild(script);
97
- return script;
98
- }
99
-
100
- function removeTag(tag)
101
- {
102
- if (typeof head != 'object') {
103
- head = document.getElementsByTagName("head").item(0);
104
- }
105
- head.removeChild(script);
106
- }
107
-
108
- function buildScriptTag(url, cacheOk)
109
- {
110
- var element = document.createElement("script"),
111
- additionalQueryParams, conjunction,
112
- actualUrl = url,
113
- elementId = 'jsonp-script-' + scriptTagCounter++;
114
- if (!cacheOk) {
115
- additionalQueryParams = '_=' + (new Date()).getTime();
116
- conjunction = (url.indexOf('?') == -1) ? '?' : '&';
117
- actualUrl = url + conjunction + additionalQueryParams;
118
- }
119
- element.setAttribute("type", "text/javascript");
120
- element.setAttribute("src", actualUrl);
121
- element.setAttribute("id", elementId);
122
- return element;
123
- }
124
-
125
- var mailchimpUtils =
126
- {
127
- extend:function (e, t) {
128
- for (var n in t || {}) {
129
- if (t.hasOwnProperty(n)) {
130
- e[n] = t[n]
131
- }
132
- }
133
- return e
134
- },
135
- getQueryStringVars:function ()
136
- {
137
- var e = window.location.search || "";
138
- var t = [];
139
- var n = {};
140
- e = e.substr(1);
141
- if (e.length) {
142
- t = e.split("&");
143
- for (var r in t)
144
- {
145
- var i = t[r];
146
- if(typeof i !== 'string'){continue;}
147
- var s = i.split("=");
148
- var o = s[0];
149
- var u = s[1];
150
- if (!o.length)continue;
151
- if (typeof n[o] === "undefined") {
152
- n[o] = []
153
- }
154
- n[o].push(u)
155
- }
156
- }
157
- return n
158
- },
159
- unEscape:function (e) {
160
- return decodeURIComponent(e)
161
- },
162
- escape:function (e) {
163
- return encodeURIComponent(e)
164
- },
165
- createDate:function (e, t) {
166
- if (!e) {
167
- e = 0
168
- }
169
- var n = new Date;
170
- var r = t ? n.getDate() - e : n.getDate() + e;
171
- n.setDate(r);
172
- return n
173
- },
174
- arrayUnique:function (e) {
175
- var t = e.concat();
176
- for (var n = 0; n < t.length; ++n) {
177
- for (var r = n + 1; r < t.length; ++r) {
178
- if (t[n] === t[r]) {
179
- t.splice(r, 1)
180
- }
181
- }
182
- }
183
- return t
184
- },
185
- objectCombineUnique:function (e) {
186
- var t = e[0];
187
- for (var n = 1; n < e.length; n++) {
188
- var r = e[n];
189
- for (var i in r) {
190
- t[i] = r[i]
191
- }
192
- }
193
- return t
194
- }
195
- };
196
-
197
- var mailchimpStorage = function(e, t)
198
- {
199
- var n = function (e, t, r) {
200
- return 1 === arguments.length ? n.get(e) : n.set(e, t, r)
201
- };
202
- n.get = function (t, r) {
203
- e.cookie !== n._cacheString && n._populateCache();
204
- return n._cache[t] == undefined ? r : n._cache[t]
205
- };
206
- n.defaults = {path:"/"};
207
- n.set = function (r, i, s) {
208
- s = {path:s && s.path || n.defaults.path, domain:s && s.domain || n.defaults.domain, expires:s && s.expires || n.defaults.expires, secure:s && s.secure !== t ? s.secure : n.defaults.secure};
209
- i === t && (s.expires = -1);
210
- switch (typeof s.expires) {
211
- case"number":
212
- s.expires = new Date((new Date).getTime() + 1e3 * s.expires);
213
- break;
214
- case"string":
215
- s.expires = new Date(s.expires)
216
- }
217
- r = encodeURIComponent(r) + "=" + (i + "").replace(/[^!#-+\--:<-\[\]-~]/g, encodeURIComponent);
218
- r += s.path ? ";path=" + s.path : "";
219
- r += s.domain ? ";domain=" + s.domain : "";
220
- r += s.expires ? ";expires=" + s.expires.toGMTString() : "";
221
- r += s.secure ? ";secure" : "";
222
- e.cookie = r;
223
- return n
224
- };
225
- n.expire = function (e, r) {
226
- return n.set(e, t, r)
227
- };
228
- n._populateCache = function () {
229
- n._cache = {};
230
- try {
231
- n._cacheString = e.cookie;
232
- for (var r = n._cacheString.split("; "), i = 0; i < r.length; i++) {
233
- var s = r[i].indexOf("="), o = decodeURIComponent(r[i].substr(0, s)), s = decodeURIComponent(r[i].substr(s + 1));
234
- n._cache[o] === t && (n._cache[o] = s)
235
- }
236
- } catch (e) {
237
- console.log(e);
238
- }
239
- };
240
- n.enabled = function () {
241
- var e = "1" === n.set("cookies.js", "1").get("cookies.js");
242
- n.expire("cookies.js");
243
- return e
244
- }();
245
- return n;
246
- }(document);
247
-
248
- var Jsonp = {invoke : invokeJsonp, removeTag: removeTag};
249
-
250
- mailchimp =
251
- {
252
- storage : mailchimpStorage,
253
- utils : mailchimpUtils
254
- };
255
-
256
- function MailChimpCart() {
257
-
258
- this.email_types = "input[type=email]";
259
- this.regex_email = /^([A-Za-z0-9_+\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
260
- this.current_email = null;
261
- this.previous_email = null;
262
-
263
- this.expireUser = function () {
264
- this.current_email = null;
265
- mailchimp.storage.expire('mailchimp.cart.current_email');
266
- };
267
-
268
- this.expireSaved = function () {
269
- mailchimp.storage.expire('mailchimp.cart.items');
270
- };
271
-
272
- this.setEmail = function (email) {
273
- if (this.valueEmail(email)) {
274
- this.setPreviousEmail(this.getEmail());
275
- this.current_email = email;
276
- mailchimp.storage.set('mailchimp.cart.current_email', email);
277
- }
278
- };
279
- this.getEmail = function () {
280
- if (this.current_email) {
281
- return this.current_email;
282
- }
283
- var current_email = mailchimp.storage.get('mailchimp.cart.current_email', false);
284
- if (!current_email || !this.valueEmail(current_email)) {
285
- return false;
286
- }
287
- this.current_email = current_email;
288
- return current_email;
289
- };
290
- this.setPreviousEmail = function (prev_email) {
291
- if (this.valueEmail(prev_email)) {
292
- mailchimp.storage.set('mailchimp.cart.previous_email', prev_email);
293
- this.previous_email = prev_email;
294
- }
295
- };
296
- this.valueEmail = function (email) {
297
- return this.regex_email.test(email);
298
- };
299
-
300
- return this;
301
- }
302
-
303
- mailchimp_cart = new MailChimpCart();
304
- })();
305
-
306
- mailchimpReady(function(){
307
-
308
- var qsc = mailchimp.utils.getQueryStringVars();
309
-
310
- if (qsc.mc_cart_id !== undefined) {
311
- mailchimpGetCurrentUserByHash(qsc.mc_cart_id);
312
- }
313
-
314
- // MailChimp Data //
315
- if (qsc.mc_cid !== undefined && qsc.mc_eid !== undefined) {
316
- var post_campaign_tracking_url = mailchimp_public_data.site_url+
317
- '?mailchimp-woocommerce[action]=track-campaign&mailchimp-woocommerce[submission][campaign_id]='+
318
- qsc.mc_cid[0]+
319
- '&mailchimp-woocommerce[submission][email_id]='+
320
- qsc.mc_eid[0];
321
-
322
- try {
323
- var post_campaign_request = new XMLHttpRequest();
324
- post_campaign_request.open('POST', post_campaign_tracking_url, true);
325
- post_campaign_request.setRequestHeader('Content-Type', 'application/json');
326
- post_campaign_request.setRequestHeader('Accept', 'application/json');
327
- post_campaign_request.send(data);
328
- } catch (e) {console.log('mailchimp_campaign_tracking.error', e);}
329
- }
330
-
331
- mailchimp_billing_email = document.querySelector('#billing_email');
332
-
333
- if (mailchimp_billing_email) {
334
- mailchimp_billing_email.onblur = function() {
335
- mailchimpHandleBillingEmail();
336
- };
337
- mailchimp_billing_email.onfocus = function() {
338
- mailchimpHandleBillingEmail();
339
- };
340
- }
341
  });
1
+ function mailchimpGetCurrentUserByHash(a) {
2
+ try {
3
+ var b = mailchimp_public_data.ajax_url + "?action=mailchimp_get_user_by_hash&hash=" + a, c = new XMLHttpRequest;
4
+ c.open("POST", b, !0), c.onload = function () {
5
+ if (c.status >= 200 && c.status < 400) {
6
+ var a = JSON.parse(c.responseText);
7
+ mailchimp_cart.valueEmail(a.email) && (mailchimp_cart.setEmail(a.email), console.log("mailchimp.get_email_by_hash.success", "setting " + a.email + " as the current user"))
8
+ } else console.log("mailchimp.get_email_by_hash.error", c.responseText)
9
+ }, c.onerror = function () {
10
+ console.log("mailchimp.get_email_by_hash.request.error", c.responseText)
11
+ }, c.setRequestHeader("Content-Type", "application/json"), c.setRequestHeader("Accept", "application/json"), c.send()
12
+ } catch (a) {
13
+ console.log("mailchimp.get_email_by_hash.error", a)
14
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  }
 
16
  function mailchimpHandleBillingEmail() {
17
+ var a = document.querySelector("#billing_email"), b = void 0 !== a ? a.value : "";
18
+ if (!mailchimp_cart.valueEmail(b))return !1;
19
+ if (mailchimp_submitted_email === b)return "already submitted " + b;
20
+ mailchimp_cart.setEmail(b);
21
+ try {
22
+ var c = mailchimp_public_data.ajax_url + "?action=mailchimp_set_user_by_email&email=" + b, d = new XMLHttpRequest;
23
+ d.open("POST", c, !0), d.onload = function () {
24
+ d.status >= 200 && d.status < 400 ? console.log("mailchimp.handle_billing_email.request.success", d.responseText) : console.log("mailchimp.handle_billing_email.request.error", d.responseText)
25
+ }, d.onerror = function () {
26
+ console.log("mailchimp.handle_billing_email.request.error", d.responseText)
27
+ }, d.setRequestHeader("Content-Type", "application/json"), d.setRequestHeader("Accept", "application/json"), d.send(), mailchimp_submitted_email = b
28
+ } catch (a) {
29
+ console.log("mailchimp.handle_billing_email.error", a), mailchimp_submitted_email = !1
30
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
+ var mailchimp, mailchimp_cart, mailchimp_billing_email, mailchimp_submitted_email = !1, mailchimpReady = function (a) {
33
+ /in/.test(document.readyState) ? setTimeout("mailchimpReady(" + a + ")", 9) : a()
34
+ };
35
+ !function () {
36
+ "use strict";
37
+ function j() {
38
+ return this.email_types = "input[type=email]", this.regex_email = /^([A-Za-z0-9_+\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/, this.current_email = null, this.previous_email = null, this.expireUser = function () {
39
+ this.current_email = null, mailchimp.storage.expire("mailchimp.cart.current_email")
40
+ }, this.expireSaved = function () {
41
+ mailchimp.storage.expire("mailchimp.cart.items")
42
+ }, this.setEmail = function (a) {
43
+ this.valueEmail(a) && (this.setPreviousEmail(this.getEmail()), this.current_email = a, mailchimp.storage.set("mailchimp.cart.current_email", a))
44
+ }, this.getEmail = function () {
45
+ if (this.current_email)return this.current_email;
46
+ var a = mailchimp.storage.get("mailchimp.cart.current_email", !1);
47
+ return !(!a || !this.valueEmail(a)) && (this.current_email = a, a)
48
+ }, this.setPreviousEmail = function (a) {
49
+ this.valueEmail(a) && (mailchimp.storage.set("mailchimp.cart.previous_email", a), this.previous_email = a)
50
+ }, this.valueEmail = function (a) {
51
+ return this.regex_email.test(a)
52
+ }, this
53
+ }
54
+
55
+ var g = {
56
+ extend: function (a, b) {
57
+ for (var c in b || {})b.hasOwnProperty(c) && (a[c] = b[c]);
58
+ return a
59
+ }, getQueryStringVars: function () {
60
+ var a = window.location.search || "", b = [], c = {};
61
+ if (a = a.substr(1), a.length) {
62
+ b = a.split("&");
63
+ for (var d in b) {
64
+ var e = b[d];
65
+ if ("string" == typeof e) {
66
+ var f = e.split("="), g = f[0], h = f[1];
67
+ g.length && ("undefined" == typeof c[g] && (c[g] = []), c[g].push(h))
68
+ }
69
+ }
70
+ }
71
+ return c
72
+ }, unEscape: function (a) {
73
+ return decodeURIComponent(a)
74
+ }, escape: function (a) {
75
+ return encodeURIComponent(a)
76
+ }, createDate: function (a, b) {
77
+ a || (a = 0);
78
+ var c = new Date, d = b ? c.getDate() - a : c.getDate() + a;
79
+ return c.setDate(d), c
80
+ }, arrayUnique: function (a) {
81
+ for (var b = a.concat(), c = 0; c < b.length; ++c)for (var d = c + 1; d < b.length; ++d)b[c] === b[d] && b.splice(d, 1);
82
+ return b
83
+ }, objectCombineUnique: function (a) {
84
+ for (var b = a[0], c = 1; c < a.length; c++) {
85
+ var d = a[c];
86
+ for (var e in d)b[e] = d[e]
87
+ }
88
+ return b
89
+ }
90
+ }, h = function (a, b) {
91
+ var c = function (a, b, d) {
92
+ return 1 === arguments.length ? c.get(a) : c.set(a, b, d)
93
+ };
94
+ return c.get = function (b, d) {
95
+ return a.cookie !== c._cacheString && c._populateCache(), void 0 == c._cache[b] ? d : c._cache[b]
96
+ }, c.defaults = {path: "/"}, c.set = function (d, e, f) {
97
+ switch (f = {
98
+ path: f && f.path || c.defaults.path,
99
+ domain: f && f.domain || c.defaults.domain,
100
+ expires: f && f.expires || c.defaults.expires,
101
+ secure: f && f.secure !== b ? f.secure : c.defaults.secure
102
+ }, e === b && (f.expires = -1), typeof f.expires) {
103
+ case"number":
104
+ f.expires = new Date((new Date).getTime() + 1e3 * f.expires);
105
+ break;
106
+ case"string":
107
+ f.expires = new Date(f.expires)
108
+ }
109
+ return d = encodeURIComponent(d) + "=" + (e + "").replace(/[^!#-+\--:<-\[\]-~]/g, encodeURIComponent), d += f.path ? ";path=" + f.path : "", d += f.domain ? ";domain=" + f.domain : "", d += f.expires ? ";expires=" + f.expires.toGMTString() : "", d += f.secure ? ";secure" : "", a.cookie = d, c
110
+ }, c.expire = function (a, d) {
111
+ return c.set(a, b, d)
112
+ }, c._populateCache = function () {
113
+ c._cache = {};
114
+ try {
115
+ c._cacheString = a.cookie;
116
+ for (var d = c._cacheString.split("; "), e = 0; e < d.length; e++) {
117
+ var f = d[e].indexOf("="), g = decodeURIComponent(d[e].substr(0, f)), f = decodeURIComponent(d[e].substr(f + 1));
118
+ c._cache[g] === b && (c._cache[g] = f)
119
+ }
120
+ } catch (a) {
121
+ console.log(a)
122
+ }
123
+ }, c.enabled = function () {
124
+ var a = "1" === c.set("cookies.js", "1").get("cookies.js");
125
+ return c.expire("cookies.js"), a
126
+ }(), c
127
+ }(document);
128
+ mailchimp = {storage: h, utils: g}, mailchimp_cart = new j
129
+ }(), mailchimpReady(function () {
130
+ if (void 0 === a)var a = {
131
+ site_url: document.location.origin,
132
+ defaulted: !0,
133
+ ajax_url: document.location.origin + "/wp-admin?admin-ajax.php"
134
+ };
135
+ var b = mailchimp.utils.getQueryStringVars();
136
+ void 0 !== b.mc_cart_id && mailchimpGetCurrentUserByHash(b.mc_cart_id), mailchimp_billing_email = document.querySelector("#billing_email"), mailchimp_billing_email && (mailchimp_billing_email.onblur = function () {
137
+ mailchimpHandleBillingEmail()
138
+ }, mailchimp_billing_email.onfocus = function () {
139
+ mailchimpHandleBillingEmail()
140
+ })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  });
public/js/mailchimp-woocommerce-public.min.js ADDED
@@ -0,0 +1 @@
 
1
+ function mailchimpGetCurrentUserByHash(a){try{var b=mailchimp_public_data.ajax_url+"?action=mailchimp_get_user_by_hash&hash="+a,c=new XMLHttpRequest;c.open("POST",b,!0),c.onload=function(){if(c.status>=200&&c.status<400){var a=JSON.parse(c.responseText);mailchimp_cart.valueEmail(a.email)&&(mailchimp_cart.setEmail(a.email),console.log("mailchimp.get_email_by_hash.success","setting "+a.email+" as the current user"))}else console.log("mailchimp.get_email_by_hash.error",c.responseText)},c.onerror=function(){console.log("mailchimp.get_email_by_hash.request.error",c.responseText)},c.setRequestHeader("Content-Type","application/json"),c.setRequestHeader("Accept","application/json"),c.send()}catch(a){console.log("mailchimp.get_email_by_hash.error",a)}}function mailchimpHandleBillingEmail(){var a=document.querySelector("#billing_email"),b=void 0!==a?a.value:"";if(!mailchimp_cart.valueEmail(b))return!1;if(mailchimp_submitted_email===b)return"already submitted "+b;mailchimp_cart.setEmail(b);try{var c=mailchimp_public_data.ajax_url+"?action=mailchimp_set_user_by_email&email="+b,d=new XMLHttpRequest;d.open("POST",c,!0),d.onload=function(){d.status>=200&&d.status<400?console.log("mailchimp.handle_billing_email.request.success",d.responseText):console.log("mailchimp.handle_billing_email.request.error",d.responseText)},d.onerror=function(){console.log("mailchimp.handle_billing_email.request.error",d.responseText)},d.setRequestHeader("Content-Type","application/json"),d.setRequestHeader("Accept","application/json"),d.send(),mailchimp_submitted_email=b}catch(a){console.log("mailchimp.handle_billing_email.error",a),mailchimp_submitted_email=!1}}var mailchimp,mailchimp_cart,mailchimp_billing_email,mailchimp_submitted_email=!1,mailchimpReady=function(a){/in/.test(document.readyState)?setTimeout("mailchimpReady("+a+")",9):a()};!function(){"use strict";function j(){return this.email_types="input[type=email]",this.regex_email=/^([A-Za-z0-9_+\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,this.current_email=null,this.previous_email=null,this.expireUser=function(){this.current_email=null,mailchimp.storage.expire("mailchimp.cart.current_email")},this.expireSaved=function(){mailchimp.storage.expire("mailchimp.cart.items")},this.setEmail=function(a){this.valueEmail(a)&&(this.setPreviousEmail(this.getEmail()),this.current_email=a,mailchimp.storage.set("mailchimp.cart.current_email",a))},this.getEmail=function(){if(this.current_email)return this.current_email;var a=mailchimp.storage.get("mailchimp.cart.current_email",!1);return!(!a||!this.valueEmail(a))&&(this.current_email=a,a)},this.setPreviousEmail=function(a){this.valueEmail(a)&&(mailchimp.storage.set("mailchimp.cart.previous_email",a),this.previous_email=a)},this.valueEmail=function(a){return this.regex_email.test(a)},this}var g={extend:function(a,b){for(var c in b||{})b.hasOwnProperty(c)&&(a[c]=b[c]);return a},getQueryStringVars:function(){var a=window.location.search||"",b=[],c={};if(a=a.substr(1),a.length){b=a.split("&");for(var d in b){var e=b[d];if("string"==typeof e){var f=e.split("="),g=f[0],h=f[1];g.length&&("undefined"==typeof c[g]&&(c[g]=[]),c[g].push(h))}}}return c},unEscape:function(a){return decodeURIComponent(a)},escape:function(a){return encodeURIComponent(a)},createDate:function(a,b){a||(a=0);var c=new Date,d=b?c.getDate()-a:c.getDate()+a;return c.setDate(d),c},arrayUnique:function(a){for(var b=a.concat(),c=0;c<b.length;++c)for(var d=c+1;d<b.length;++d)b[c]===b[d]&&b.splice(d,1);return b},objectCombineUnique:function(a){for(var b=a[0],c=1;c<a.length;c++){var d=a[c];for(var e in d)b[e]=d[e]}return b}},h=function(a,b){var c=function(a,b,d){return 1===arguments.length?c.get(a):c.set(a,b,d)};return c.get=function(b,d){return a.cookie!==c._cacheString&&c._populateCache(),void 0==c._cache[b]?d:c._cache[b]},c.defaults={path:"/"},c.set=function(d,e,f){switch(f={path:f&&f.path||c.defaults.path,domain:f&&f.domain||c.defaults.domain,expires:f&&f.expires||c.defaults.expires,secure:f&&f.secure!==b?f.secure:c.defaults.secure},e===b&&(f.expires=-1),typeof f.expires){case"number":f.expires=new Date((new Date).getTime()+1e3*f.expires);break;case"string":f.expires=new Date(f.expires)}return d=encodeURIComponent(d)+"="+(e+"").replace(/[^!#-+\--:<-\[\]-~]/g,encodeURIComponent),d+=f.path?";path="+f.path:"",d+=f.domain?";domain="+f.domain:"",d+=f.expires?";expires="+f.expires.toGMTString():"",d+=f.secure?";secure":"",a.cookie=d,c},c.expire=function(a,d){return c.set(a,b,d)},c._populateCache=function(){c._cache={};try{c._cacheString=a.cookie;for(var d=c._cacheString.split("; "),e=0;e<d.length;e++){var f=d[e].indexOf("="),g=decodeURIComponent(d[e].substr(0,f)),f=decodeURIComponent(d[e].substr(f+1));c._cache[g]===b&&(c._cache[g]=f)}}catch(a){console.log(a)}},c.enabled=function(){var a="1"===c.set("cookies.js","1").get("cookies.js");return c.expire("cookies.js"),a}(),c}(document);mailchimp={storage:h,utils:g},mailchimp_cart=new j}(),mailchimpReady(function(){if(void 0===a)var a={site_url:document.location.origin,defaulted:!0,ajax_url:document.location.origin+"/wp-admin?admin-ajax.php"};var b=mailchimp.utils.getQueryStringVars();void 0!==b.mc_cart_id&&mailchimpGetCurrentUserByHash(b.mc_cart_id),mailchimp_billing_email=document.querySelector("#billing_email"),mailchimp_billing_email&&(mailchimp_billing_email.onblur=function(){mailchimpHandleBillingEmail()},mailchimp_billing_email.onfocus=function(){mailchimpHandleBillingEmail()})});