Creative Mail – Easier WordPress & WooCommerce Email Marketing - Version 1.1.7

Version Description

Download this release

Release Info

Developer constantcontact
Plugin Icon 128x128 Creative Mail – Easier WordPress & WooCommerce Email Marketing
Version 1.1.7
Comparing to
See all releases

Code changes from version 1.1.6 to 1.1.7

Files changed (46) hide show
  1. CHANGELOG.md +3 -0
  2. README.md +2 -1
  3. creative-mail-plugin.php +17 -16
  4. readme.txt +2 -1
  5. src/creativemail.php +21 -13
  6. src/helpers/encryption-helper.php +71 -69
  7. src/helpers/environment-helper.php +17 -10
  8. src/helpers/guid-helper.php +1 -0
  9. src/helpers/options-helper.php +39 -13
  10. src/helpers/sso-helper.php +18 -11
  11. src/integrations/integration.php +19 -9
  12. src/managers/admin-manager.php +71 -58
  13. src/managers/api-manager.php +150 -117
  14. src/managers/email-manager.php +158 -126
  15. src/managers/instance-manager.php +8 -4
  16. src/managers/integration-manager.php +35 -24
  17. src/modules/api/Models/ApiRequestItem.php +2 -1
  18. src/modules/api/Processes/ApiBackgroundProcess.php +14 -7
  19. src/modules/blog/models/BlogAttachment.php +20 -19
  20. src/modules/blog/models/BlogInformation.php +4 -2
  21. src/modules/blog/models/BlogPost.php +19 -17
  22. src/modules/contacts/Handlers/BaseContactFormPluginHandler.php +6 -3
  23. src/modules/contacts/Handlers/ContactFormSevenPluginHandler.php +41 -38
  24. src/modules/contacts/Handlers/ElementorPluginHandler.php +101 -0
  25. src/modules/contacts/Handlers/GravityFormsPluginHandler.php +4 -4
  26. src/modules/contacts/Handlers/JetpackPluginHandler.php +3 -2
  27. src/modules/contacts/Handlers/NewsLetterContactFormPluginHandler.php +13 -12
  28. src/modules/contacts/Handlers/WooCommercePluginHandler.php +65 -63
  29. src/modules/contacts/Handlers/WpFormsPluginHandler.php +113 -110
  30. src/modules/contacts/Services/ContactsSyncService.php +18 -11
  31. src/modules/contacts/models/ContactAddressModel.php +32 -16
  32. src/modules/contacts/models/ContactModel.php +51 -26
  33. src/modules/woocommerce/models/WCInformationModel.php +5 -3
  34. src/modules/woocommerce/models/WCProductModel.php +4 -2
  35. src/modules/woocommerce/models/WCStoreInformation.php +25 -26
  36. src/views/activated-integrations.php +4 -4
  37. src/views/available-integrations.php +5 -5
  38. src/views/consent.php +5 -5
  39. src/views/dashboard.php +2 -2
  40. src/views/onboarding.php +2 -3
  41. src/views/settings-internal.php +27 -27
  42. src/views/settings.php +34 -34
  43. vendor/autoload.php +1 -1
  44. vendor/composer/autoload_classmap.php +1 -0
  45. vendor/composer/autoload_real.php +4 -4
  46. vendor/composer/autoload_static.php +5 -4
CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
  Changelog
2
  =========
3
 
 
 
 
4
  #### 1.1.6 - September 21 2020
5
  - Add option to refresh the SSO url without reloading the entire page;
6
  - Add support for opt-in checkbox in the WooCommerce checkout flow;
1
  Changelog
2
  =========
3
 
4
+ #### 1.1.7 - October 5 2020
5
+ - Add support for Elementor forms.
6
+
7
  #### 1.1.6 - September 21 2020
8
  - Add option to refresh the SSO url without reloading the entire page;
9
  - Add support for opt-in checkbox in the WooCommerce checkout flow;
README.md CHANGED
@@ -3,7 +3,7 @@ Contributors: Constant Contact
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
- Stable tag: 1.1.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
@@ -88,6 +88,7 @@ Creative Mail by Constant Contact [Privacy Notice](https://www.endurance.com/pri
88
  6. Enhance your brand with logomaker
89
 
90
  == Changelog ==
 
91
  * 1.1.6 - Add option to refresh the SSO url without reloading the entire page, and add the support for opt-in checkbox in the WooCommerce checkout flow.
92
  * 1.1.5 - Fixes an issue where order notification emails would not always go out.
93
  * 1.1.4 - Minor improvements
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
+ Stable tag: 1.1.7
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
88
  6. Enhance your brand with logomaker
89
 
90
  == Changelog ==
91
+ * 1.1.7 - Add support for Elementor forms.
92
  * 1.1.6 - Add option to refresh the SSO url without reloading the entire page, and add the support for opt-in checkbox in the WooCommerce checkout flow.
93
  * 1.1.5 - Fixes an issue where order notification emails would not always go out.
94
  * 1.1.4 - Minor improvements
creative-mail-plugin.php CHANGED
@@ -6,22 +6,23 @@ use CreativeMail\CreativeMail;
6
  * Plugin URI: https://wordpress.org/plugins/creative-mail-by-constant-contact/
7
  * Description: Free email marketing designed specifically for WordPress, Jetpack and WooCommerce. Send newsletters, promotions, updates and transactional e-commerce emails. Simple and easy, powered by Constant Contact’s rock solid reliability.
8
  * Author: Constant Contact
9
- * Version: 1.1.6
10
  * Author URI: https://www.constantcontact.com
11
  */
12
 
13
- function _load_ce4wp_plugin() {
 
14
 
15
  global $creativemail;
16
 
17
- if($creativemail != null){
18
  return true;
19
  }
20
 
21
  define('CE4WP_PLUGIN_DIR', __DIR__ . '/');
22
  define('CE4WP_PLUGIN_URL', plugin_dir_url(__FILE__) . '/');
23
  define('CE4WP_PLUGIN_FILE', __FILE__);
24
- define('CE4WP_PLUGIN_VERSION', '1.1.6');
25
  define('CE4WP_INSTANCE_UUID_KEY', 'ce4wp_instance_uuid');
26
  define('CE4WP_INSTANCE_HANDSHAKE_TOKEN', 'ce4wp_handshake_token');
27
  define('CE4WP_INSTANCE_HANDSHAKE_EXPIRATION', 'ce4wp_handshake_expiration');
@@ -38,7 +39,7 @@ function _load_ce4wp_plugin() {
38
  define('CE4WP_APP_GATEWAY_URL', 'https://app-gateway.creativemail.com/');
39
  define('CE4WP_APP_URL', 'https://app.creativemail.com/');
40
  define('CE4WP_ENVIRONMENT', 'PRODUCTION');
41
- define('CE4WP_BUILD_NUMBER', '628');
42
  define('CE4WP_BATCH_SIZE', 500);
43
  define('CE4WP_WC_API_KEY_ID', 'ce4wp_woocommerce_api_key_id');
44
  define('CE4WP_WC_API_CONSUMER_KEY', 'ce4wp_woocommerce_consumer_key');
@@ -46,7 +47,7 @@ function _load_ce4wp_plugin() {
46
 
47
  // Load all the required files
48
  if (file_exists(__DIR__ . '/vendor/autoload.php')) {
49
- require_once __DIR__ . '/vendor/autoload.php';
50
  }
51
 
52
  $creativemail = CreativeMail::get_instance();
@@ -57,22 +58,22 @@ function _load_ce4wp_plugin() {
57
 
58
  function deactivate()
59
  {
60
- delete_option( 'ce4wp_activated');
61
- delete_option( 'ce4wp_install_date');
62
  }
63
 
64
  function activate()
65
  {
66
- add_option( 'ce4wp_activated', true );
67
- add_option( 'ce4wp_install_date', date('Y-m-d G:i:s'), '', 'yes');
68
- if (
69
- ( isset( $_REQUEST['action'] ) && 'activate-selected' === $_REQUEST['action'] ) &&
70
- ( isset( $_POST['checked'] ) && count( $_POST['checked'] ) > 1 ) ) {
71
  return;
72
  }
73
- add_option( 'ce4wp_activation_redirect', wp_get_current_user()->ID );
74
  }
75
 
76
  add_action('plugins_loaded', '_load_ce4wp_plugin', 10);
77
- register_activation_hook( __FILE__, 'activate' );
78
- register_deactivation_hook( __FILE__,'deactivate' );
6
  * Plugin URI: https://wordpress.org/plugins/creative-mail-by-constant-contact/
7
  * Description: Free email marketing designed specifically for WordPress, Jetpack and WooCommerce. Send newsletters, promotions, updates and transactional e-commerce emails. Simple and easy, powered by Constant Contact’s rock solid reliability.
8
  * Author: Constant Contact
9
+ * Version: 1.1.7
10
  * Author URI: https://www.constantcontact.com
11
  */
12
 
13
+ function _load_ce4wp_plugin()
14
+ {
15
 
16
  global $creativemail;
17
 
18
+ if($creativemail != null) {
19
  return true;
20
  }
21
 
22
  define('CE4WP_PLUGIN_DIR', __DIR__ . '/');
23
  define('CE4WP_PLUGIN_URL', plugin_dir_url(__FILE__) . '/');
24
  define('CE4WP_PLUGIN_FILE', __FILE__);
25
+ define('CE4WP_PLUGIN_VERSION', '1.1.7');
26
  define('CE4WP_INSTANCE_UUID_KEY', 'ce4wp_instance_uuid');
27
  define('CE4WP_INSTANCE_HANDSHAKE_TOKEN', 'ce4wp_handshake_token');
28
  define('CE4WP_INSTANCE_HANDSHAKE_EXPIRATION', 'ce4wp_handshake_expiration');
39
  define('CE4WP_APP_GATEWAY_URL', 'https://app-gateway.creativemail.com/');
40
  define('CE4WP_APP_URL', 'https://app.creativemail.com/');
41
  define('CE4WP_ENVIRONMENT', 'PRODUCTION');
42
+ define('CE4WP_BUILD_NUMBER', '644');
43
  define('CE4WP_BATCH_SIZE', 500);
44
  define('CE4WP_WC_API_KEY_ID', 'ce4wp_woocommerce_api_key_id');
45
  define('CE4WP_WC_API_CONSUMER_KEY', 'ce4wp_woocommerce_consumer_key');
47
 
48
  // Load all the required files
49
  if (file_exists(__DIR__ . '/vendor/autoload.php')) {
50
+ include_once __DIR__ . '/vendor/autoload.php';
51
  }
52
 
53
  $creativemail = CreativeMail::get_instance();
58
 
59
  function deactivate()
60
  {
61
+ delete_option('ce4wp_activated');
62
+ delete_option('ce4wp_install_date');
63
  }
64
 
65
  function activate()
66
  {
67
+ add_option('ce4wp_activated', true);
68
+ add_option('ce4wp_install_date', date('Y-m-d G:i:s'), '', 'yes');
69
+ if (( isset($_REQUEST['action']) && 'activate-selected' === $_REQUEST['action'] )
70
+ && ( isset($_POST['checked']) && count($_POST['checked']) > 1 )
71
+ ) {
72
  return;
73
  }
74
+ add_option('ce4wp_activation_redirect', wp_get_current_user()->ID);
75
  }
76
 
77
  add_action('plugins_loaded', '_load_ce4wp_plugin', 10);
78
+ register_activation_hook(__FILE__, 'activate');
79
+ register_deactivation_hook(__FILE__, 'deactivate');
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Constant Contact
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
- Stable tag: 1.1.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
@@ -93,6 +93,7 @@ Creative Mail by Constant Contact [Privacy Notice](https://www.endurance.com/pri
93
  6. Enhance your brand with logomaker
94
 
95
  == Changelog ==
 
96
  * 1.1.6 - Add option to refresh the SSO url without reloading the entire page, and add the support for opt-in checkbox in the WooCommerce checkout flow.
97
  * 1.1.5 - Fixes an issue where order notification emails would not always go out.
98
  * 1.1.4 - Minor improvements
3
  Tags: email, marketing, newsletter, subscribe, contact form, constant contact, crm, automations, ecommerce, promotion, offers, retargeting
4
  Requires at least: 4.6
5
  Tested up to: 5.5
6
+ Stable tag: 1.1.7
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Requires PHP: 5.6
93
  6. Enhance your brand with logomaker
94
 
95
  == Changelog ==
96
+ * 1.1.7 - Add support for Elementor forms.
97
  * 1.1.6 - Add option to refresh the SSO url without reloading the entire page, and add the support for opt-in checkbox in the WooCommerce checkout flow.
98
  * 1.1.5 - Fixes an issue where order notification emails would not always go out.
99
  * 1.1.4 - Minor improvements
src/creativemail.php CHANGED
@@ -19,10 +19,10 @@ class CreativeMail
19
  private $integration_manager;
20
  private $email_manager;
21
 
22
- public function __construct() {
 
23
 
24
- if (current_user_can('administrator'))
25
- {
26
  $this->admin_manager = new AdminManager();
27
  }
28
 
@@ -32,7 +32,8 @@ class CreativeMail
32
  $this->email_manager = new EmailManager();
33
  }
34
 
35
- public function add_hooks() {
 
36
 
37
  if (!$this->is_active()) {
38
  return;
@@ -48,33 +49,40 @@ class CreativeMail
48
  $this->email_manager->add_hooks();
49
  }
50
 
51
- public function get_integration_manager() {
 
52
  return $this->integration_manager;
53
  }
54
 
55
- public function get_instance_manager() {
 
56
  return $this->instance_manager;
57
  }
58
 
59
- public function get_api_manager() {
 
60
  return $this->api_manager;
61
  }
62
 
63
- public function get_email_manager() {
 
64
  return $this->email_manager;
65
  }
66
 
67
- public function get_admin_manager() {
 
68
  return $this->admin_manager;
69
  }
70
 
71
- public function is_active() {
72
- return in_array(plugin_basename( CE4WP_PLUGIN_FILE ) , apply_filters('active_plugins', get_option('active_plugins')));
 
73
  }
74
 
75
- public static function get_instance() {
 
76
 
77
- if (self::$instance === null){
78
  self::$instance = new CreativeMail();
79
  }
80
 
19
  private $integration_manager;
20
  private $email_manager;
21
 
22
+ public function __construct()
23
+ {
24
 
25
+ if (current_user_can('administrator')) {
 
26
  $this->admin_manager = new AdminManager();
27
  }
28
 
32
  $this->email_manager = new EmailManager();
33
  }
34
 
35
+ public function add_hooks()
36
+ {
37
 
38
  if (!$this->is_active()) {
39
  return;
49
  $this->email_manager->add_hooks();
50
  }
51
 
52
+ public function get_integration_manager()
53
+ {
54
  return $this->integration_manager;
55
  }
56
 
57
+ public function get_instance_manager()
58
+ {
59
  return $this->instance_manager;
60
  }
61
 
62
+ public function get_api_manager()
63
+ {
64
  return $this->api_manager;
65
  }
66
 
67
+ public function get_email_manager()
68
+ {
69
  return $this->email_manager;
70
  }
71
 
72
+ public function get_admin_manager()
73
+ {
74
  return $this->admin_manager;
75
  }
76
 
77
+ public function is_active()
78
+ {
79
+ return in_array(plugin_basename(CE4WP_PLUGIN_FILE), apply_filters('active_plugins', get_option('active_plugins')));
80
  }
81
 
82
+ public static function get_instance()
83
+ {
84
 
85
+ if (self::$instance === null) {
86
  self::$instance = new CreativeMail();
87
  }
88
 
src/helpers/encryption-helper.php CHANGED
@@ -6,78 +6,80 @@ namespace CreativeMail\Helpers;
6
  use Defuse\Crypto\Crypto;
7
  use Defuse\Crypto\Key;
8
 
9
- class EncryptionHelper {
 
10
 
11
- /**
12
- * Will get the previously used encryption key, or will generate a new key of no key is present.
13
- * @return Key
14
- * @throws \Defuse\Crypto\Exception\BadFormatException
15
- * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
16
- */
17
- private static function get_encryption_key()
18
- {
19
- $key = get_option(CE4WP_ENCRYPTION_KEY_KEY, null);
20
- if ($key === null) {
21
- $key = Key::createNewRandomKey();
22
- update_option(CE4WP_ENCRYPTION_KEY_KEY, $key->saveToAsciiSafeString());
23
- }
24
- else {
25
- $key = Key::loadFromAsciiSafeString($key);
26
- }
 
27
 
28
- return $key;
29
- }
30
 
31
- /**
32
- * Will update an existing option or create the option if it is not available.
33
- *
34
- * @param $option string The name of the option.
35
- * @param $value mixed The value that should be stored encrypted
36
- * @param $autoload bool Should this option be auto loaded.
37
- *
38
- * @return bool
39
- * @throws \Defuse\Crypto\Exception\BadFormatException
40
- * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
41
- */
42
- public static function update_option($option, $value, $autoload = null)
43
- {
44
- return update_option($option, Crypto::encrypt( $value, self::get_encryption_key()), $autoload );
45
- }
46
 
47
- /**
48
- * Will store and encrypt the option.
49
- *
50
- * @param $option string The name of the option.
51
- * @param $value mixed The value that should be stored encrypted
52
- * @param $autoload bool Should this option be auto loaded.
53
- *
54
- * @throws \Defuse\Crypto\Exception\BadFormatException
55
- * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
56
- */
57
- public static function add_option($option, $value, $autoload = true)
58
- {
59
- add_option( $option, Crypto::encrypt($value, self::get_encryption_key()), '', $autoload );
60
- }
61
 
62
- /**
63
- * Will load and decrypt the option.
64
- *
65
- * @param $option string The name of the option you want to load.
66
- * @param bool $default The fallback value that should be used when the option is not available.
67
- *
68
- * @return mixed
69
- */
70
- public static function get_option($option, $default = false)
71
- {
72
- $encrypted = get_option( $option, $default );
73
- if ( $encrypted === $default ) {
74
- return $default;
75
- } else {
76
- try {
77
- return Crypto::decrypt( $encrypted, self::get_encryption_key() );
78
- } catch ( \Exception $e ) {
79
- return $encrypted;
80
- }
81
- }
82
- }
83
  }
6
  use Defuse\Crypto\Crypto;
7
  use Defuse\Crypto\Key;
8
 
9
+ class EncryptionHelper
10
+ {
11
 
12
+ /**
13
+ * Will get the previously used encryption key, or will generate a new key of no key is present.
14
+ *
15
+ * @return Key
16
+ * @throws \Defuse\Crypto\Exception\BadFormatException
17
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
18
+ */
19
+ private static function get_encryption_key()
20
+ {
21
+ $key = get_option(CE4WP_ENCRYPTION_KEY_KEY, null);
22
+ if ($key === null) {
23
+ $key = Key::createNewRandomKey();
24
+ update_option(CE4WP_ENCRYPTION_KEY_KEY, $key->saveToAsciiSafeString());
25
+ }
26
+ else {
27
+ $key = Key::loadFromAsciiSafeString($key);
28
+ }
29
 
30
+ return $key;
31
+ }
32
 
33
+ /**
34
+ * Will update an existing option or create the option if it is not available.
35
+ *
36
+ * @param $option string The name of the option.
37
+ * @param $value mixed The value that should be stored encrypted
38
+ * @param $autoload bool Should this option be auto loaded.
39
+ *
40
+ * @return bool
41
+ * @throws \Defuse\Crypto\Exception\BadFormatException
42
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
43
+ */
44
+ public static function update_option($option, $value, $autoload = null)
45
+ {
46
+ return update_option($option, Crypto::encrypt($value, self::get_encryption_key()), $autoload);
47
+ }
48
 
49
+ /**
50
+ * Will store and encrypt the option.
51
+ *
52
+ * @param $option string The name of the option.
53
+ * @param $value mixed The value that should be stored encrypted
54
+ * @param $autoload bool Should this option be auto loaded.
55
+ *
56
+ * @throws \Defuse\Crypto\Exception\BadFormatException
57
+ * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
58
+ */
59
+ public static function add_option($option, $value, $autoload = true)
60
+ {
61
+ add_option($option, Crypto::encrypt($value, self::get_encryption_key()), '', $autoload);
62
+ }
63
 
64
+ /**
65
+ * Will load and decrypt the option.
66
+ *
67
+ * @param $option string The name of the option you want to load.
68
+ * @param bool $default The fallback value that should be used when the option is not available.
69
+ *
70
+ * @return mixed
71
+ */
72
+ public static function get_option($option, $default = false)
73
+ {
74
+ $encrypted = get_option($option, $default);
75
+ if ($encrypted === $default ) {
76
+ return $default;
77
+ } else {
78
+ try {
79
+ return Crypto::decrypt($encrypted, self::get_encryption_key());
80
+ } catch ( \Exception $e ) {
81
+ return $encrypted;
82
+ }
83
+ }
84
+ }
85
  }
src/helpers/environment-helper.php CHANGED
@@ -8,6 +8,7 @@ use http\Env;
8
 
9
  /**
10
  * Class EnvironmentHelper
 
11
  * @package CreativeMail\Helpers
12
  */
13
  class EnvironmentHelper
@@ -17,15 +18,18 @@ class EnvironmentHelper
17
  *
18
  * @returns bool
19
  */
20
- public static function is_test_environment() {
 
21
  return self::get_environment() !== EnvironmentNames::PRODUCTION;
22
  }
23
 
24
  /**
25
  * Gets the name of the environment this version of the plugin is build for.
 
26
  * @return string
27
  */
28
- public static function get_environment() {
 
29
 
30
  $environment = CE4WP_ENVIRONMENT;
31
  if ($environment === "{ENV}") {
@@ -37,22 +41,23 @@ class EnvironmentHelper
37
 
38
  /**
39
  * Gets the url of the app-gateway.
40
- * @param null $path
 
41
  * @return string
42
  */
43
- public static function get_app_gateway_url($path = null) {
 
44
  $url = CE4WP_APP_GATEWAY_URL;
45
  if ($url === '{GATEWAY_URL}') {
46
- $url = 'https://app-gateway.creativemail.com/';
47
  }
48
 
49
  if (is_null($path)) {
50
- return $url;
51
  }
52
 
53
- if (isset($path) && !empty($path))
54
- {
55
- return $url.$path;
56
  }
57
 
58
  return $url;
@@ -60,9 +65,11 @@ class EnvironmentHelper
60
 
61
  /**
62
  * Gets the url of the app.
 
63
  * @return string
64
  */
65
- public static function get_app_url() {
 
66
  $url = CE4WP_APP_URL;
67
  if ($url === '{APP_URL}') {
68
  return 'https://app.creativemail.com/';
8
 
9
  /**
10
  * Class EnvironmentHelper
11
+ *
12
  * @package CreativeMail\Helpers
13
  */
14
  class EnvironmentHelper
18
  *
19
  * @returns bool
20
  */
21
+ public static function is_test_environment()
22
+ {
23
  return self::get_environment() !== EnvironmentNames::PRODUCTION;
24
  }
25
 
26
  /**
27
  * Gets the name of the environment this version of the plugin is build for.
28
+ *
29
  * @return string
30
  */
31
+ public static function get_environment()
32
+ {
33
 
34
  $environment = CE4WP_ENVIRONMENT;
35
  if ($environment === "{ENV}") {
41
 
42
  /**
43
  * Gets the url of the app-gateway.
44
+ *
45
+ * @param null $path
46
  * @return string
47
  */
48
+ public static function get_app_gateway_url($path = null)
49
+ {
50
  $url = CE4WP_APP_GATEWAY_URL;
51
  if ($url === '{GATEWAY_URL}') {
52
+ $url = 'https://app-gateway.creativemail.com/';
53
  }
54
 
55
  if (is_null($path)) {
56
+ return $url;
57
  }
58
 
59
+ if (isset($path) && !empty($path)) {
60
+ return $url.$path;
 
61
  }
62
 
63
  return $url;
65
 
66
  /**
67
  * Gets the url of the app.
68
+ *
69
  * @return string
70
  */
71
+ public static function get_app_url()
72
+ {
73
  $url = CE4WP_APP_URL;
74
  if ($url === '{APP_URL}') {
75
  return 'https://app.creativemail.com/';
src/helpers/guid-helper.php CHANGED
@@ -4,6 +4,7 @@ namespace CreativeMail\Helpers;
4
 
5
  /**
6
  * Class GuidHelper
 
7
  * @package CreativeMail\Helpers
8
  */
9
  class GuidHelper
4
 
5
  /**
6
  * Class GuidHelper
7
+ *
8
  * @package CreativeMail\Helpers
9
  */
10
  class GuidHelper
src/helpers/options-helper.php CHANGED
@@ -7,13 +7,15 @@ use stdClass;
7
  /**
8
  * Class CE4WP_OptionsHelper
9
  * Exposes a wrapper around all the options that we register within the plugin.
 
10
  * @package CreativeMail\Helpers
11
- * @access private
12
  */
13
  class OptionsHelper
14
  {
15
  /**
16
  * Gets the generated unique id for this WP instance, or will generate a new unique id if none is present.
 
17
  * @return string
18
  */
19
  public static function get_instance_uuid()
@@ -33,6 +35,7 @@ class OptionsHelper
33
 
34
  /**
35
  * Gets the generated handshake token that should be used during setup.
 
36
  * @return string
37
  */
38
  public static function get_handshake_token()
@@ -54,6 +57,7 @@ class OptionsHelper
54
 
55
  /**
56
  * Gets the expiration time associated with the generated handshake token.
 
57
  * @return int|null
58
  */
59
  public static function get_handshake_expiration()
@@ -63,6 +67,7 @@ class OptionsHelper
63
 
64
  /**
65
  * Gets the consumer API key that can be used to interact with the Creative Mail platform.
 
66
  * @return string|null
67
  */
68
  public static function get_wc_consumer_key()
@@ -85,6 +90,7 @@ class OptionsHelper
85
 
86
  /**
87
  * Deletes the consumer key.
 
88
  * @return int|null
89
  */
90
  public static function delete_wc_consumer_key()
@@ -94,6 +100,7 @@ class OptionsHelper
94
 
95
  /**
96
  * Gets the assigned api key id.
 
97
  * @return int|null
98
  */
99
  public static function get_wc_api_key_id()
@@ -103,6 +110,7 @@ class OptionsHelper
103
 
104
  /**
105
  * Sets the assigned api key id that is generated when connecting this WP instance to the Creative Mail account.
 
106
  * @param $value int
107
  */
108
  public static function set_wc_api_key_id($value)
@@ -112,6 +120,7 @@ class OptionsHelper
112
 
113
  /**
114
  * Deletes the api key id.
 
115
  * @return int|null
116
  */
117
  public static function delete_wc_api_key_id()
@@ -121,6 +130,7 @@ class OptionsHelper
121
 
122
  /**
123
  * Gets the assigned instance id.
 
124
  * @return int|null
125
  */
126
  public static function get_instance_id()
@@ -130,6 +140,7 @@ class OptionsHelper
130
 
131
  /**
132
  * Sets the assigned instance id that is generated when connecting this WP instance to the Creative Mail account.
 
133
  * @param $value int
134
  */
135
  public static function set_instance_id($value)
@@ -139,6 +150,7 @@ class OptionsHelper
139
 
140
  /**
141
  * Gets the assigned checkbox text.
 
142
  * @return string
143
  */
144
  public static function get_checkout_checkbox_text()
@@ -148,6 +160,7 @@ class OptionsHelper
148
 
149
  /**
150
  * Sets the assigned checkout checkbox text.
 
151
  * @param $value string
152
  */
153
  public static function set_checkout_checkbox_text($value)
@@ -157,6 +170,7 @@ class OptionsHelper
157
 
158
  /**
159
  * Sets the assigned checkout checkbox enabled.
 
160
  * @param $value bool
161
  */
162
  public static function set_checkout_checkbox_enabled($value)
@@ -166,6 +180,7 @@ class OptionsHelper
166
 
167
  /**
168
  * Gets the assigned checkout checkbox enabled value
 
169
  * @return int|bool
170
  */
171
  public static function get_checkout_checkbox_enabled()
@@ -175,6 +190,7 @@ class OptionsHelper
175
 
176
  /**
177
  * Gets the id of the account that is connected to the combination of this WP unique id and Creative Mail account id.
 
178
  * @return int|null
179
  */
180
  public static function get_connected_account_id()
@@ -184,6 +200,7 @@ class OptionsHelper
184
 
185
  /**
186
  * Sets the id of the account that is connected to the combination of this WP unique id and Creative Mail account id.
 
187
  * @param $value int
188
  */
189
  public static function set_connected_account_id($value)
@@ -193,6 +210,7 @@ class OptionsHelper
193
 
194
  /**
195
  * Gets the API key that can be used to interact with the Creative Mail platform.
 
196
  * @return string|null
197
  */
198
  public static function get_instance_api_key()
@@ -215,6 +233,7 @@ class OptionsHelper
215
 
216
  /**
217
  * Gets a string representing all the plugins that were activated for synchronization during the setup process.
 
218
  * @return string|array
219
  */
220
  public static function get_activated_plugins()
@@ -224,6 +243,7 @@ class OptionsHelper
224
 
225
  /**
226
  * Sets a string representing all the plugins that were activated for synchronization during the setup process.
 
227
  * @param $plugins
228
  */
229
  public static function set_activated_plugins($plugins)
@@ -234,21 +254,22 @@ class OptionsHelper
234
  /**
235
  * @return string|array
236
  */
237
- public static function get_managed_email_notifications() {
 
238
  global $wpdb;
239
- $rows = $wpdb->get_results( $wpdb->prepare( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name like %s", CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '%' ) );
240
  $result = array();
241
  foreach ( $rows as $row ) {
242
  $name = $row->option_name;
243
- if ( $name === CE4WP_MANAGED_EMAIL_NOTIFICATIONS ) {
244
  //convert old to new format
245
  return self::convert_managed_email_notifications($row->option_value);
246
  }
247
 
248
  $item = new stdClass();
249
- $item->name = str_replace( CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '_', '', $name );
250
  $item->active =$row->option_value == 'true';
251
- array_push( $result, $item);
252
  }
253
 
254
  return $result;
@@ -256,19 +277,21 @@ class OptionsHelper
256
 
257
  /**
258
  * One time converts the email notifications to the new format
 
259
  * @return array
260
  */
261
- private static function convert_managed_email_notifications($items) {
 
262
  $items = maybe_unserialize($items);
263
- if ( empty( $items ) || $items == null ) {
264
  return array();
265
  }
266
 
267
  $result = array();
268
  foreach ( $items as $item ) {
269
- if ( property_exists( $item, 'name' ) ) {
270
- OptionsHelper::set_managed_email_notification( $item->name, $item->active == true ? 'true' : 'false' );
271
- array_push( $result, $item );
272
  }
273
  }
274
 
@@ -279,10 +302,11 @@ class OptionsHelper
279
  /**
280
  * Deletes all the email notifications options
281
  */
282
- private static function delete_managed_email_notifications() {
 
283
  $managed_notifications = self::get_managed_email_notifications();
284
  foreach ( $managed_notifications as $item ) {
285
- if ( property_exists( $item, 'name' ) ) {
286
  delete_option(CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '_' . $item->name);
287
  }
288
  }
@@ -298,6 +322,7 @@ class OptionsHelper
298
 
299
  /**
300
  * Gets an int value representing when the user did accept the terms on our consent screen.
 
301
  * @return int|null
302
  */
303
  public static function get_consent_accept_date()
@@ -315,6 +340,7 @@ class OptionsHelper
315
 
316
  /**
317
  * Gets an string value representing who referred this customer
 
318
  * @return string|null
319
  */
320
  public static function get_referred_by()
7
  /**
8
  * Class CE4WP_OptionsHelper
9
  * Exposes a wrapper around all the options that we register within the plugin.
10
+ *
11
  * @package CreativeMail\Helpers
12
+ * @access private
13
  */
14
  class OptionsHelper
15
  {
16
  /**
17
  * Gets the generated unique id for this WP instance, or will generate a new unique id if none is present.
18
+ *
19
  * @return string
20
  */
21
  public static function get_instance_uuid()
35
 
36
  /**
37
  * Gets the generated handshake token that should be used during setup.
38
+ *
39
  * @return string
40
  */
41
  public static function get_handshake_token()
57
 
58
  /**
59
  * Gets the expiration time associated with the generated handshake token.
60
+ *
61
  * @return int|null
62
  */
63
  public static function get_handshake_expiration()
67
 
68
  /**
69
  * Gets the consumer API key that can be used to interact with the Creative Mail platform.
70
+ *
71
  * @return string|null
72
  */
73
  public static function get_wc_consumer_key()
90
 
91
  /**
92
  * Deletes the consumer key.
93
+ *
94
  * @return int|null
95
  */
96
  public static function delete_wc_consumer_key()
100
 
101
  /**
102
  * Gets the assigned api key id.
103
+ *
104
  * @return int|null
105
  */
106
  public static function get_wc_api_key_id()
110
 
111
  /**
112
  * Sets the assigned api key id that is generated when connecting this WP instance to the Creative Mail account.
113
+ *
114
  * @param $value int
115
  */
116
  public static function set_wc_api_key_id($value)
120
 
121
  /**
122
  * Deletes the api key id.
123
+ *
124
  * @return int|null
125
  */
126
  public static function delete_wc_api_key_id()
130
 
131
  /**
132
  * Gets the assigned instance id.
133
+ *
134
  * @return int|null
135
  */
136
  public static function get_instance_id()
140
 
141
  /**
142
  * Sets the assigned instance id that is generated when connecting this WP instance to the Creative Mail account.
143
+ *
144
  * @param $value int
145
  */
146
  public static function set_instance_id($value)
150
 
151
  /**
152
  * Gets the assigned checkbox text.
153
+ *
154
  * @return string
155
  */
156
  public static function get_checkout_checkbox_text()
160
 
161
  /**
162
  * Sets the assigned checkout checkbox text.
163
+ *
164
  * @param $value string
165
  */
166
  public static function set_checkout_checkbox_text($value)
170
 
171
  /**
172
  * Sets the assigned checkout checkbox enabled.
173
+ *
174
  * @param $value bool
175
  */
176
  public static function set_checkout_checkbox_enabled($value)
180
 
181
  /**
182
  * Gets the assigned checkout checkbox enabled value
183
+ *
184
  * @return int|bool
185
  */
186
  public static function get_checkout_checkbox_enabled()
190
 
191
  /**
192
  * Gets the id of the account that is connected to the combination of this WP unique id and Creative Mail account id.
193
+ *
194
  * @return int|null
195
  */
196
  public static function get_connected_account_id()
200
 
201
  /**
202
  * Sets the id of the account that is connected to the combination of this WP unique id and Creative Mail account id.
203
+ *
204
  * @param $value int
205
  */
206
  public static function set_connected_account_id($value)
210
 
211
  /**
212
  * Gets the API key that can be used to interact with the Creative Mail platform.
213
+ *
214
  * @return string|null
215
  */
216
  public static function get_instance_api_key()
233
 
234
  /**
235
  * Gets a string representing all the plugins that were activated for synchronization during the setup process.
236
+ *
237
  * @return string|array
238
  */
239
  public static function get_activated_plugins()
243
 
244
  /**
245
  * Sets a string representing all the plugins that were activated for synchronization during the setup process.
246
+ *
247
  * @param $plugins
248
  */
249
  public static function set_activated_plugins($plugins)
254
  /**
255
  * @return string|array
256
  */
257
+ public static function get_managed_email_notifications()
258
+ {
259
  global $wpdb;
260
+ $rows = $wpdb->get_results($wpdb->prepare("SELECT option_name, option_value FROM $wpdb->options WHERE option_name like %s", CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '%'));
261
  $result = array();
262
  foreach ( $rows as $row ) {
263
  $name = $row->option_name;
264
+ if ($name === CE4WP_MANAGED_EMAIL_NOTIFICATIONS ) {
265
  //convert old to new format
266
  return self::convert_managed_email_notifications($row->option_value);
267
  }
268
 
269
  $item = new stdClass();
270
+ $item->name = str_replace(CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '_', '', $name);
271
  $item->active =$row->option_value == 'true';
272
+ array_push($result, $item);
273
  }
274
 
275
  return $result;
277
 
278
  /**
279
  * One time converts the email notifications to the new format
280
+ *
281
  * @return array
282
  */
283
+ private static function convert_managed_email_notifications($items)
284
+ {
285
  $items = maybe_unserialize($items);
286
+ if (empty($items) || $items == null ) {
287
  return array();
288
  }
289
 
290
  $result = array();
291
  foreach ( $items as $item ) {
292
+ if (property_exists($item, 'name') ) {
293
+ OptionsHelper::set_managed_email_notification($item->name, $item->active == true ? 'true' : 'false');
294
+ array_push($result, $item);
295
  }
296
  }
297
 
302
  /**
303
  * Deletes all the email notifications options
304
  */
305
+ private static function delete_managed_email_notifications()
306
+ {
307
  $managed_notifications = self::get_managed_email_notifications();
308
  foreach ( $managed_notifications as $item ) {
309
+ if (property_exists($item, 'name') ) {
310
  delete_option(CE4WP_MANAGED_EMAIL_NOTIFICATIONS . '_' . $item->name);
311
  }
312
  }
322
 
323
  /**
324
  * Gets an int value representing when the user did accept the terms on our consent screen.
325
+ *
326
  * @return int|null
327
  */
328
  public static function get_consent_accept_date()
340
 
341
  /**
342
  * Gets an string value representing who referred this customer
343
+ *
344
  * @return string|null
345
  */
346
  public static function get_referred_by()
src/helpers/sso-helper.php CHANGED
@@ -7,6 +7,7 @@ use Exception;
7
 
8
  /**
9
  * Class SsoHelper
 
10
  * @package CreativeMail\Helpers
11
  */
12
  class SsoHelper
@@ -14,18 +15,22 @@ class SsoHelper
14
 
15
  /**
16
  * Will request a one-time use link that can be used to initiate a single sign on into the Creative Mail product.
17
- * @param $instanceId int
18
- * @param $apiKey string
19
- * @param $connectedAccountId int
 
20
  * @return string|null Returns the sso link or null if the link could not be generated.
21
  * @throws Exception When one of the required arguments is not present.
22
  */
23
  public static function generate_sso_link($instanceId, $apiKey, $connectedAccountId)
24
  {
25
 
26
- if(!isset($instanceId)) throw new Exception("Please provide a valid siteId");
27
- if(!isset($apiKey)) throw new Exception("Please provide a valid apiKey");
28
- if(!isset($connectedAccountId)) throw new Exception("Please provide a valid connectedAccountId");
 
 
 
29
 
30
  // Build the request
31
  $arguments = array(
@@ -35,16 +40,18 @@ class SsoHelper
35
  'x-account-id' => $connectedAccountId,
36
  'content-type' => 'application/json'
37
  ),
38
- 'body' => wp_json_encode(array(
 
39
  'instance_url' => get_bloginfo('wpurl'),
40
- 'plugin_version' => CE4WP_PLUGIN_VERSION,
41
- 'word_press_version' => get_bloginfo('version')
42
- ))
 
43
  );
44
 
45
  $response = wp_remote_post(EnvironmentHelper::get_app_gateway_url() . 'wordpress/v1.0/account/sso', $arguments);
46
  if (is_wp_error($response)) {
47
- return null;
48
  }
49
 
50
  $properties = json_decode($response["body"], true);
7
 
8
  /**
9
  * Class SsoHelper
10
+ *
11
  * @package CreativeMail\Helpers
12
  */
13
  class SsoHelper
15
 
16
  /**
17
  * Will request a one-time use link that can be used to initiate a single sign on into the Creative Mail product.
18
+ *
19
+ * @param $instanceId int
20
+ * @param $apiKey string
21
+ * @param $connectedAccountId int
22
  * @return string|null Returns the sso link or null if the link could not be generated.
23
  * @throws Exception When one of the required arguments is not present.
24
  */
25
  public static function generate_sso_link($instanceId, $apiKey, $connectedAccountId)
26
  {
27
 
28
+ if(!isset($instanceId)) { throw new Exception("Please provide a valid siteId");
29
+ }
30
+ if(!isset($apiKey)) { throw new Exception("Please provide a valid apiKey");
31
+ }
32
+ if(!isset($connectedAccountId)) { throw new Exception("Please provide a valid connectedAccountId");
33
+ }
34
 
35
  // Build the request
36
  $arguments = array(
40
  'x-account-id' => $connectedAccountId,
41
  'content-type' => 'application/json'
42
  ),
43
+ 'body' => wp_json_encode(
44
+ array(
45
  'instance_url' => get_bloginfo('wpurl'),
46
+ 'plugin_version' => CE4WP_PLUGIN_VERSION,
47
+ 'word_press_version' => get_bloginfo('version')
48
+ )
49
+ )
50
  );
51
 
52
  $response = wp_remote_post(EnvironmentHelper::get_app_gateway_url() . 'wordpress/v1.0/account/sso', $arguments);
53
  if (is_wp_error($response)) {
54
+ return null;
55
  }
56
 
57
  $properties = json_decode($response["body"], true);
src/integrations/integration.php CHANGED
@@ -20,10 +20,10 @@ class Integration
20
  /**
21
  * Integration constructor.
22
  *
23
- * @param $slug string The slug that you want to use for this integration.
24
- * @param $name string The display name of the plugin
25
- * @param $class string The path the the plugin class that should be used to check if the plugin required for this integration is installed.
26
- * @param $integration_handler string The name of the class that should be instantiated when this integration gets activated.
27
  * @param $hide_from_suggestions boolean If you want to hide this plugin from the suggestion list, set this to true
28
  */
29
  public function __construct($slug, $name, $class, $integration_handler, $hide_from_suggestions)
@@ -37,41 +37,51 @@ class Integration
37
 
38
  /**
39
  * Gets the slug assigned to this integration.
 
40
  * @return string
41
  */
42
- public function get_slug() {
 
43
  return $this->slug;
44
  }
45
 
46
  /**
47
  * Gets the display name assigned to this integration.
 
48
  * @return string
49
  */
50
- public function get_name() {
 
51
  return $this->name;
52
  }
53
 
54
  /**
55
  * Gets the path to the main class of the plugin that is required for this integration.
 
56
  * @return string
57
  */
58
- public function get_class() {
 
59
  return $this->class;
60
  }
61
 
62
  /**
63
  * Gets the name of the class that should be instantiated when activating this integration.
 
64
  * @return string
65
  */
66
- public function get_integration_handler() {
 
67
  return $this->integrationHandler;
68
  }
69
 
70
  /**
71
  * Gets if this integration should be hidden from the suggestion list
 
72
  * @return bool
73
  */
74
- public function is_hidden_from_suggestions() {
 
75
  return $this->hide_from_suggestions;
76
  }
77
  }
20
  /**
21
  * Integration constructor.
22
  *
23
+ * @param $slug string The slug that you want to use for this integration.
24
+ * @param $name string The display name of the plugin
25
+ * @param $class string The path the the plugin class that should be used to check if the plugin required for this integration is installed.
26
+ * @param $integration_handler string The name of the class that should be instantiated when this integration gets activated.
27
  * @param $hide_from_suggestions boolean If you want to hide this plugin from the suggestion list, set this to true
28
  */
29
  public function __construct($slug, $name, $class, $integration_handler, $hide_from_suggestions)
37
 
38
  /**
39
  * Gets the slug assigned to this integration.
40
+ *
41
  * @return string
42
  */
43
+ public function get_slug()
44
+ {
45
  return $this->slug;
46
  }
47
 
48
  /**
49
  * Gets the display name assigned to this integration.
50
+ *
51
  * @return string
52
  */
53
+ public function get_name()
54
+ {
55
  return $this->name;
56
  }
57
 
58
  /**
59
  * Gets the path to the main class of the plugin that is required for this integration.
60
+ *
61
  * @return string
62
  */
63
+ public function get_class()
64
+ {
65
  return $this->class;
66
  }
67
 
68
  /**
69
  * Gets the name of the class that should be instantiated when activating this integration.
70
+ *
71
  * @return string
72
  */
73
+ public function get_integration_handler()
74
+ {
75
  return $this->integrationHandler;
76
  }
77
 
78
  /**
79
  * Gets if this integration should be hidden from the suggestion list
80
+ *
81
  * @return bool
82
  */
83
+ public function is_hidden_from_suggestions()
84
+ {
85
  return $this->hide_from_suggestions;
86
  }
87
  }
src/managers/admin-manager.php CHANGED
@@ -18,15 +18,15 @@ class AdminManager
18
 
19
  protected $instance_name;
20
  protected $instance_uuid;
21
- protected $instance_handshake_token;
22
  protected $instance_id;
23
  protected $instance_url;
24
  protected $instance_callback_url;
25
  protected $dashboard_url;
26
 
27
- /**
28
- * AdminManager constructor.
29
- */
30
  public function __construct()
31
  {
32
  $this->instance_name = rawurlencode(get_bloginfo('name'));
@@ -41,7 +41,7 @@ class AdminManager
41
  . '&wp_instance_url=' . $this->instance_url
42
  . '&wp_version=' . get_bloginfo('version')
43
  . '&plugin_version=' . CE4WP_PLUGIN_VERSION;
44
- }
45
 
46
  /**
47
  * Will register all the hooks for the admin portion of the plugin.
@@ -54,83 +54,91 @@ class AdminManager
54
  add_action('admin_notices', array($this, 'add_admin_notice_review' ));
55
  add_action('admin_init', array($this, 'activation_redirect' ));
56
  add_action('admin_init', array($this, 'ignore_review_notice' ));
57
- add_filter('admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
58
- add_action('wp_ajax_woocommerce_ce4wp_rated', array( $this, 'mark_as_rated' ) );
59
  }
60
 
61
- function add_admin_notice_review() {
 
62
 
63
- $install_date = get_option( 'ce4wp_install_date');
64
  if (!$install_date) {
65
  return false;
66
  }
67
 
68
- $install_date = date_create( $install_date );
69
- $date_now = date_create( date('Y-m-d G:i:s') );
70
- $date_diff = date_diff( $install_date, $date_now );
71
 
72
- if ( $date_diff->format("%d") < 7 ) {
73
 
74
  return false;
75
  }
76
 
77
- if ( ! get_option( 'ce4wp_ignore_review_notice' ) ) {
78
 
79
  echo '<div class="updated"><p>';
80
 
81
- printf(__( 'Awesome, you\'ve been using <a href="admin.php?page=creativemail">Creative Mail</a> for more than 1 week. May we ask you to give it a 5-star rating on WordPress? | <a href="%2$s" target="_blank">Ok, you deserved it</a> | <a href="%1$s">I already did</a> | <a href="%1$s">No, not good enough</a>', 'ce4wp' ), '?ce4wp-ignore-notice=0',
82
- 'https://wordpress.org/plugins/creative-mail-by-constant-contact/');
 
 
83
  echo "</p></div>";
84
  }
85
  }
86
 
87
  public function ignore_review_notice()
88
  {
89
- if ( isset($_GET['ce4wp-ignore-notice']) && '0' == $_GET['ce4wp-ignore-notice'] ) {
90
- update_option( 'ce4wp_ignore_review_notice', 'true' );
91
  }
92
  }
93
 
94
- public function mark_as_rated() {
 
95
 
96
- if ( ! current_user_can( 'manage_woocommerce' ) ) {
97
- wp_die( -1 );
98
  }
99
 
100
- update_option( 'ce4wp_admin_footer_text_rated', 1 );
101
 
102
  wp_die();
103
  }
104
 
105
  /**
106
  * Changes the admin footer text on admin pages.
107
- * @param string $footer_text
 
108
  * @return string
109
  */
110
- public function admin_footer_text( $footer_text ) {
 
111
 
112
- if ( ! current_user_can( 'manage_woocommerce' ) ) {
113
  return $footer_text;
114
  }
115
 
116
  $screen = get_current_screen();
117
 
118
- if ( ! empty( $screen )
119
  && ('toplevel_page_creativemail' === $screen->id || 'creative-mail_page_creativemail_settings' === $screen->id )
120
- && ! get_option( 'ce4wp_admin_footer_text_rated' ))
121
- {
122
  $footer_text = sprintf(
123
- esc_html__( 'If you like %1$s please leave us a %2$s rating. A huge thanks in advance!', 'ce4wp' ),
124
- sprintf( '<strong>%s</strong>', esc_html__( 'Creative Mail', 'ce4wp' ) ),
125
- '<a href="https://wordpress.org/plugins/creative-mail-by-constant-contact/#reviews?rate=5#new-post" target="_blank" class="ce4wp-rating-link" data-rated="' . esc_attr__( 'Thank You', 'ce4wp' ) . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
126
  );
127
 
128
- wc_enqueue_js( "
 
129
  jQuery( 'a.ce4wp-rating-link' ).click( function() {
130
  jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_ce4wp_rated' } );
131
  jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
132
  });
133
- ");
 
134
  }
135
 
136
  return $footer_text;
@@ -139,11 +147,12 @@ class AdminManager
139
  /**
140
  * Redirects the user after plugin activation.
141
  */
142
- function activation_redirect() {
143
- if ( intval( get_option( 'ce4wp_activation_redirect', false ) ) === wp_get_current_user()->ID ) {
 
144
  // Make sure we don't redirect again after this one
145
- delete_option( 'ce4wp_activation_redirect' );
146
- wp_safe_redirect( admin_url( 'admin.php?page=creativemail' ) );
147
  exit;
148
  }
149
  }
@@ -154,7 +163,7 @@ class AdminManager
154
  public function add_assets()
155
  {
156
  wp_register_style('ce4wp_admin', CE4WP_PLUGIN_URL . 'assets/css/admin.css', null, CE4WP_PLUGIN_VERSION);
157
- wp_enqueue_style( 'ce4wp_admin');
158
  wp_enqueue_style('ce4wp-font-poppins', 'https://fonts.googleapis.com/css?family=Poppins:400,500');
159
  wp_enqueue_script('wp-api');
160
  }
@@ -170,12 +179,12 @@ class AdminManager
170
  : array( $this, 'show_setup' );
171
 
172
  // Create the root menu item
173
- $icon = file_get_contents( CE4WP_PLUGIN_DIR . 'assets/images/icon.svg');
174
- add_menu_page('Creative Mail', esc_html__('Creative Mail'), 'manage_options', 'creativemail', $main_action, 'data:image/svg+xml;base64,' . base64_encode( $icon ), '99.68491');
175
 
176
  $sub_actions = array(
177
  array(
178
- 'title' => esc_html__( 'Settings', 'ce4wp' ),
179
  'text' => 'Settings',
180
  'slug' => 'creativemail_settings',
181
  'callback' => array( $this, 'show_settings_page' )
@@ -183,13 +192,14 @@ class AdminManager
183
  );
184
 
185
  foreach ($sub_actions as $sub_action) {
186
- add_submenu_page( 'creativemail', 'Creative Mail - ' . $sub_action['title'], $sub_action['text'], 'manage_options', $sub_action['slug'], $sub_action['callback']);
187
  }
188
  }
189
 
190
- public function add_admin_notice_permalink() {
 
191
  if (CreativeMail::get_instance()->get_integration_manager()->is_plugin_active('woocommerce')) {
192
- if ( ! CreativeMail::get_instance()->get_integration_manager()->get_permalinks_enabled() ) {
193
  print( '<div class="notice notice-error is-dismissible"><p>Ohoh, pretty permalinks are disabled. To enable the CreativeMail WooCommerce integration <a href="/wp-admin/options-permalink.php">please update your permalink settings</a>.</p></div>');
194
  return;
195
  }
@@ -201,16 +211,16 @@ class AdminManager
201
  */
202
  public function show_setup()
203
  {
204
- require CE4WP_PLUGIN_DIR . 'src/views/onboarding.php';
205
  }
206
 
207
- /**
208
- * Renders the consent screen.
209
- */
210
- public function show_consent()
211
- {
212
- require CE4WP_PLUGIN_DIR . 'src/views/consent.php';
213
- }
214
 
215
  /**
216
  * Renders the Creative Mail dashboard when the site is connected to an account.
@@ -219,23 +229,25 @@ class AdminManager
219
  {
220
  try {
221
  $sso_link = $this->get_sso_link();
222
- if(isset($sso_link)){
223
  $this->dashboard_url = $sso_link;
224
  }
225
  }
226
- catch(Exception $ex) { }
 
227
 
228
- require CE4WP_PLUGIN_DIR . 'src/views/dashboard.php';
229
  }
230
 
231
  /**
232
  * Generates an SSO link for the current user.
 
233
  * @since 1.1.5
234
  */
235
  public function get_sso_link()
236
  {
237
  // Only if you are running in wp-admin
238
- if(!current_user_can( 'administrator' )) {
239
  return null;
240
  }
241
 
@@ -248,7 +260,8 @@ class AdminManager
248
  try {
249
  return SsoHelper::generate_sso_link($instance_id, $instance_api_key, $connected_account_id);
250
  }
251
- catch(Exception $ex) { }
 
252
  }
253
 
254
  return null;
@@ -259,6 +272,6 @@ class AdminManager
259
  */
260
  public function show_settings_page()
261
  {
262
- require CE4WP_PLUGIN_DIR . 'src/views/settings.php';
263
  }
264
  }
18
 
19
  protected $instance_name;
20
  protected $instance_uuid;
21
+ protected $instance_handshake_token;
22
  protected $instance_id;
23
  protected $instance_url;
24
  protected $instance_callback_url;
25
  protected $dashboard_url;
26
 
27
+ /**
28
+ * AdminManager constructor.
29
+ */
30
  public function __construct()
31
  {
32
  $this->instance_name = rawurlencode(get_bloginfo('name'));
41
  . '&wp_instance_url=' . $this->instance_url
42
  . '&wp_version=' . get_bloginfo('version')
43
  . '&plugin_version=' . CE4WP_PLUGIN_VERSION;
44
+ }
45
 
46
  /**
47
  * Will register all the hooks for the admin portion of the plugin.
54
  add_action('admin_notices', array($this, 'add_admin_notice_review' ));
55
  add_action('admin_init', array($this, 'activation_redirect' ));
56
  add_action('admin_init', array($this, 'ignore_review_notice' ));
57
+ add_filter('admin_footer_text', array( $this, 'admin_footer_text' ), 1);
58
+ add_action('wp_ajax_woocommerce_ce4wp_rated', array( $this, 'mark_as_rated' ));
59
  }
60
 
61
+ function add_admin_notice_review()
62
+ {
63
 
64
+ $install_date = get_option('ce4wp_install_date');
65
  if (!$install_date) {
66
  return false;
67
  }
68
 
69
+ $install_date = date_create($install_date);
70
+ $date_now = date_create(date('Y-m-d G:i:s'));
71
+ $date_diff = date_diff($install_date, $date_now);
72
 
73
+ if ($date_diff->format("%d") < 7 ) {
74
 
75
  return false;
76
  }
77
 
78
+ if (! get_option('ce4wp_ignore_review_notice') ) {
79
 
80
  echo '<div class="updated"><p>';
81
 
82
+ printf(
83
+ __('Awesome, you\'ve been using <a href="admin.php?page=creativemail">Creative Mail</a> for more than 1 week. May we ask you to give it a 5-star rating on WordPress? | <a href="%2$s" target="_blank">Ok, you deserved it</a> | <a href="%1$s">I already did</a> | <a href="%1$s">No, not good enough</a>', 'ce4wp'), '?ce4wp-ignore-notice=0',
84
+ 'https://wordpress.org/plugins/creative-mail-by-constant-contact/'
85
+ );
86
  echo "</p></div>";
87
  }
88
  }
89
 
90
  public function ignore_review_notice()
91
  {
92
+ if (isset($_GET['ce4wp-ignore-notice']) && '0' == $_GET['ce4wp-ignore-notice'] ) {
93
+ update_option('ce4wp_ignore_review_notice', 'true');
94
  }
95
  }
96
 
97
+ public function mark_as_rated()
98
+ {
99
 
100
+ if (! current_user_can('manage_woocommerce') ) {
101
+ wp_die(-1);
102
  }
103
 
104
+ update_option('ce4wp_admin_footer_text_rated', 1);
105
 
106
  wp_die();
107
  }
108
 
109
  /**
110
  * Changes the admin footer text on admin pages.
111
+ *
112
+ * @param string $footer_text
113
  * @return string
114
  */
115
+ public function admin_footer_text( $footer_text )
116
+ {
117
 
118
+ if (! current_user_can('manage_woocommerce') ) {
119
  return $footer_text;
120
  }
121
 
122
  $screen = get_current_screen();
123
 
124
+ if (! empty($screen)
125
  && ('toplevel_page_creativemail' === $screen->id || 'creative-mail_page_creativemail_settings' === $screen->id )
126
+ && ! get_option('ce4wp_admin_footer_text_rated')
127
+ ) {
128
  $footer_text = sprintf(
129
+ esc_html__('If you like %1$s please leave us a %2$s rating. A huge thanks in advance!', 'ce4wp'),
130
+ sprintf('<strong>%s</strong>', esc_html__('Creative Mail', 'ce4wp')),
131
+ '<a href="https://wordpress.org/plugins/creative-mail-by-constant-contact/#reviews?rate=5#new-post" target="_blank" class="ce4wp-rating-link" data-rated="' . esc_attr__('Thank You', 'ce4wp') . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
132
  );
133
 
134
+ wc_enqueue_js(
135
+ "
136
  jQuery( 'a.ce4wp-rating-link' ).click( function() {
137
  jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_ce4wp_rated' } );
138
  jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
139
  });
140
+ "
141
+ );
142
  }
143
 
144
  return $footer_text;
147
  /**
148
  * Redirects the user after plugin activation.
149
  */
150
+ function activation_redirect()
151
+ {
152
+ if (intval(get_option('ce4wp_activation_redirect', false)) === wp_get_current_user()->ID ) {
153
  // Make sure we don't redirect again after this one
154
+ delete_option('ce4wp_activation_redirect');
155
+ wp_safe_redirect(admin_url('admin.php?page=creativemail'));
156
  exit;
157
  }
158
  }
163
  public function add_assets()
164
  {
165
  wp_register_style('ce4wp_admin', CE4WP_PLUGIN_URL . 'assets/css/admin.css', null, CE4WP_PLUGIN_VERSION);
166
+ wp_enqueue_style('ce4wp_admin');
167
  wp_enqueue_style('ce4wp-font-poppins', 'https://fonts.googleapis.com/css?family=Poppins:400,500');
168
  wp_enqueue_script('wp-api');
169
  }
179
  : array( $this, 'show_setup' );
180
 
181
  // Create the root menu item
182
+ $icon = file_get_contents(CE4WP_PLUGIN_DIR . 'assets/images/icon.svg');
183
+ add_menu_page('Creative Mail', esc_html__('Creative Mail'), 'manage_options', 'creativemail', $main_action, 'data:image/svg+xml;base64,' . base64_encode($icon), '99.68491');
184
 
185
  $sub_actions = array(
186
  array(
187
+ 'title' => esc_html__('Settings', 'ce4wp'),
188
  'text' => 'Settings',
189
  'slug' => 'creativemail_settings',
190
  'callback' => array( $this, 'show_settings_page' )
192
  );
193
 
194
  foreach ($sub_actions as $sub_action) {
195
+ add_submenu_page('creativemail', 'Creative Mail - ' . $sub_action['title'], $sub_action['text'], 'manage_options', $sub_action['slug'], $sub_action['callback']);
196
  }
197
  }
198
 
199
+ public function add_admin_notice_permalink()
200
+ {
201
  if (CreativeMail::get_instance()->get_integration_manager()->is_plugin_active('woocommerce')) {
202
+ if (! CreativeMail::get_instance()->get_integration_manager()->get_permalinks_enabled() ) {
203
  print( '<div class="notice notice-error is-dismissible"><p>Ohoh, pretty permalinks are disabled. To enable the CreativeMail WooCommerce integration <a href="/wp-admin/options-permalink.php">please update your permalink settings</a>.</p></div>');
204
  return;
205
  }
211
  */
212
  public function show_setup()
213
  {
214
+ include CE4WP_PLUGIN_DIR . 'src/views/onboarding.php';
215
  }
216
 
217
+ /**
218
+ * Renders the consent screen.
219
+ */
220
+ public function show_consent()
221
+ {
222
+ include CE4WP_PLUGIN_DIR . 'src/views/consent.php';
223
+ }
224
 
225
  /**
226
  * Renders the Creative Mail dashboard when the site is connected to an account.
229
  {
230
  try {
231
  $sso_link = $this->get_sso_link();
232
+ if(isset($sso_link)) {
233
  $this->dashboard_url = $sso_link;
234
  }
235
  }
236
+ catch(Exception $ex) {
237
+ }
238
 
239
+ include CE4WP_PLUGIN_DIR . 'src/views/dashboard.php';
240
  }
241
 
242
  /**
243
  * Generates an SSO link for the current user.
244
+ *
245
  * @since 1.1.5
246
  */
247
  public function get_sso_link()
248
  {
249
  // Only if you are running in wp-admin
250
+ if(!current_user_can('administrator')) {
251
  return null;
252
  }
253
 
260
  try {
261
  return SsoHelper::generate_sso_link($instance_id, $instance_api_key, $connected_account_id);
262
  }
263
+ catch(Exception $ex) {
264
+ }
265
  }
266
 
267
  return null;
272
  */
273
  public function show_settings_page()
274
  {
275
+ include CE4WP_PLUGIN_DIR . 'src/views/settings.php';
276
  }
277
  }
src/managers/api-manager.php CHANGED
@@ -17,6 +17,7 @@ use WP_REST_Response;
17
 
18
  /**
19
  * Class ApiManager
 
20
  * @package CreativeMail\Managers
21
  */
22
  class ApiManager
@@ -37,118 +38,124 @@ class ApiManager
37
  $this->api_background_process = new ApiBackgroundProcess();
38
  }
39
 
40
- public function get_api_background_process() {
 
41
  return $this->api_background_process;
42
  }
43
 
44
  /**
45
  * Will add all the hooks that are required to setup our plugin API.
46
  */
47
- public function add_hooks() {
 
48
 
49
- add_action( 'rest_api_init', array($this, 'add_rest_endpoints'));
50
  }
51
 
52
- public function validate_wp_admin() {
53
- if(!current_user_can('administrator')){
54
- return new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( self::HTTP_STATUS => 401 ) );
 
55
  }
56
 
57
  return true;
58
  }
59
 
60
- public function validate_api_key() {
 
61
  //never cache our rest endpoints
62
  nocache_headers();
63
 
64
- if ( ! array_key_exists( "HTTP_X_API_KEY", $_SERVER ) ) {
65
- return new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( self::HTTP_STATUS => 401 ) );
66
  }
67
 
68
  $key = OptionsHelper::get_instance_api_key();
69
  $apiKey = $_SERVER["HTTP_X_API_KEY"];
70
  // verify that api key is valid
71
- if ( $apiKey === $key ) {
72
  return true;
73
  }
74
 
75
- return new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( self::HTTP_STATUS => 401 ) );
76
  }
77
 
78
- public function validate_callback() {
 
79
  //never cache our rest endpoints
80
  nocache_headers();
81
 
82
- if ( ! array_key_exists( "HTTP_X_API_KEY", $_SERVER ) ) {
83
- return new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( self::HTTP_STATUS => 401 ) );
84
  }
85
 
86
  $apiKey = $_SERVER["HTTP_X_API_KEY"];
87
  // Verify handshake expiration
88
  $expiration = OptionsHelper::get_handshake_expiration();
89
- if ( $expiration === null || $expiration < time() ) {
90
- return new WP_Error( 'rest_unauthorized', 'Unauthorized', array( self::HTTP_STATUS => 401 ) );
91
  }
92
 
93
  // Verify handshake
94
- if ( $apiKey === OptionsHelper::get_handshake_token() ) {
95
  return true;
96
  }
97
 
98
- return new WP_Error( 'rest_unauthorized', 'Unauthorized', array( self::HTTP_STATUS => 401 ) );
99
  }
100
 
101
- public function add_rest_endpoints() {
 
102
  // Add the endpoint to handle the callback
103
  $routes = array (
104
  array (
105
  self::ROUTE_PATH => '/callback',
106
  self::ROUTE_METHODS => 'POST',
107
  self::ROUTE_CALLBACK => array(CreativeMail::get_instance()->get_instance_manager(), 'handle_callback'),
108
- self::ROUTE_PERMISSION_CALLBACK => function() {
109
  return $this->validate_callback();
110
  }
111
  ),
112
  array (
113
  self::ROUTE_PATH => '/available_plugins',
114
  self::ROUTE_METHODS => 'GET',
115
- self::ROUTE_CALLBACK => function() {
116
  return $this->modify_response($this->get_plugin_info(true));
117
  }
118
  ),
119
  array (
120
  self::ROUTE_PATH => '/available_plugins',
121
  self::ROUTE_METHODS => 'POST',
122
- self::ROUTE_CALLBACK => function($request) {
123
  CreativeMail::get_instance()->get_integration_manager()->set_activated_plugins(json_decode($request->get_body()));
124
  }
125
  ),
126
  array (
127
  self::ROUTE_PATH => '/sso',
128
  self::ROUTE_METHODS => 'GET',
129
- self::ROUTE_CALLBACK => function() {
130
  $admin_manager = CreativeMail::get_instance()->get_admin_manager();
131
  if(isset($admin_manager)) {
132
  $sso_url = $admin_manager->get_sso_link();
133
- if(isset($sso_url)){
134
  return $this->modify_response(new WP_REST_Response(array('url' => $sso_url)));
135
  }
136
  }
137
 
138
- return new WP_Error( 'rest_unauthorized', 'Unauthorized', array( self::HTTP_STATUS => 401 ) );
139
  }
140
  ),
141
  array (
142
  self::ROUTE_PATH => '/plugins',
143
  self::ROUTE_METHODS => 'GET',
144
- self::ROUTE_CALLBACK => function() {
145
  return $this->modify_response($this->get_plugin_info(false));
146
  }
147
  ),
148
  array (
149
  self::ROUTE_PATH => '/managed_email_notifications',
150
  self::ROUTE_METHODS => 'GET',
151
- self::ROUTE_CALLBACK => function() {
152
  $result = CreativeMail::get_instance()->get_email_manager()->get_managed_email_notifications();
153
  return $this->modify_response(new WP_REST_Response($result, 200));
154
  }
@@ -156,9 +163,9 @@ class ApiManager
156
  array (
157
  self::ROUTE_PATH => '/managed_email_notifications',
158
  self::ROUTE_METHODS => 'POST',
159
- self::ROUTE_CALLBACK => function($request) {
160
  if(!CreativeMail::get_instance()->get_integration_manager()->get_permalinks_enabled()) {
161
- return $this->modify_response(new WP_REST_Response( array( 'message' => 'Please enable pretty permalinks in the WordPress settings.'), 400 ));
162
  }
163
 
164
  $result = CreativeMail::get_instance()->get_email_manager()->set_managed_email_notifications(json_decode($request->get_body()));
@@ -168,45 +175,45 @@ class ApiManager
168
  array (
169
  self::ROUTE_PATH => '/wc_key',
170
  self::ROUTE_METHODS => 'GET',
171
- self::ROUTE_CALLBACK => function() {
172
  return $this->modify_response($this->get_wc_keys());
173
  }
174
  ),
175
  array (
176
  self::ROUTE_PATH => '/synchronize',
177
  self::ROUTE_METHODS => 'POST',
178
- self::ROUTE_CALLBACK => function() {
179
- do_action(CE4WP_SYNCHRONIZE_ACTION, 250);
180
- return $this->modify_response(new WP_REST_Response(null, 200));
181
- }
182
  ),
183
  array (
184
  self::ROUTE_PATH => '/wc_information',
185
  self::ROUTE_METHODS => 'GET',
186
- self::ROUTE_CALLBACK => function() {
187
  return $this->modify_response(new WP_REST_Response(new WCInformationModel(), 200));
188
  }
189
  ),
190
  array (
191
  self::ROUTE_PATH => '/wc_products',
192
  self::ROUTE_METHODS => 'GET',
193
- self::ROUTE_CALLBACK => function($request) {
194
  $productData = array();
195
- if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))
196
- {
197
  $page = 1;
198
- if (key_exists('page', $request))
199
- {
200
  $page = (int)$request['page'];
201
  }
202
 
203
  // Get 25 most recent products
204
- $products = wc_get_products(array(
 
205
  'limit' => 25,
206
  'paged' => $page,
207
- ));
 
208
  foreach ($products as $product) {
209
- array_push($productData, new WCProductModel($product->get_data()));
210
  }
211
  }
212
  return $this->modify_response(new WP_REST_Response($productData, 200));
@@ -215,31 +222,32 @@ class ApiManager
215
  array (
216
  self::ROUTE_PATH => '/blog_information',
217
  self::ROUTE_METHODS => 'GET',
218
- self::ROUTE_CALLBACK => function() {
219
  return $this->modify_response(new WP_REST_Response(new BlogInformation(), 200));
220
  }
221
  ),
222
  array (
223
  self::ROUTE_PATH => '/wp_posts',
224
  self::ROUTE_METHODS => 'GET',
225
- self::ROUTE_CALLBACK => function($request) {
226
 
227
  $page = 1;
228
- if (key_exists('page', $request))
229
- {
230
  $page = (int)$request['page'];
231
  }
232
 
233
- $posts = get_posts(array(
 
234
  'posts_per_page' => 10,
235
  'paged' => $page,
236
  'post_type' => 'post'
237
- ));
 
238
 
239
  $postData = array();
240
  foreach ($posts as $post)
241
  {
242
- array_push($postData, new BlogPost($post));
243
  }
244
 
245
  return $this->modify_response(new WP_REST_Response($postData, 200));
@@ -248,18 +256,20 @@ class ApiManager
248
  array (
249
  self::ROUTE_PATH => '/images',
250
  self::ROUTE_METHODS => 'GET',
251
- self::ROUTE_CALLBACK => function() {
252
  $attachmentData = array();
253
- $attachments = get_posts(array(
254
- 'post_type' => 'attachment',
255
- 'post_mime_type' => 'image',
256
- 'post_status' => 'inherit',
257
- 'posts_per_page' => -1
258
- ));
 
 
259
 
260
  foreach ($attachments as $attachment)
261
  {
262
- array_push($attachmentData, new BlogAttachment($attachment));
263
  }
264
 
265
  return $this->modify_response(new WP_REST_Response($attachmentData, 200));
@@ -272,15 +282,18 @@ class ApiManager
272
  }
273
  }
274
 
275
- private function get_plugin_info($onlyActivePlugins) {
 
276
  $result = array();
277
  $activePlugins = CreativeMail::get_instance()->get_integration_manager()->get_active_plugins();
278
- if ( $onlyActivePlugins === true ) {
279
  foreach ( $activePlugins as $activePlugin ) {
280
- array_push( $result, array(
 
281
  'name' => $activePlugin->get_name(),
282
  'slug' => $activePlugin->get_slug()
283
- ) );
 
284
  }
285
  } else {
286
  $allPlugins = CreativeMail::get_instance()->get_integration_manager()->get_supported_integrations();
@@ -289,57 +302,63 @@ class ApiManager
289
  if ($plugin->is_hidden_from_suggestions()) {
290
  continue;
291
  }
292
- array_push( $result, array(
 
293
  'name' => $plugin->get_name(),
294
  'slug' => $plugin->get_slug(),
295
- 'installed' => in_array( $plugin, $activePlugins, true ) !== false,
296
- 'activated' => array_search( $plugin->get_slug(), $activatedPlugins, true ) !== false,
297
- ) );
 
298
  }
299
  }
300
 
301
- return new WP_REST_Response( $result, 200 );
302
  }
303
 
304
  /**
305
  * Modifies the response to disable caching
306
  *
307
- * @param WP_REST_Response $response The endpoint its response
308
  * @return WP_REST_Response
309
  */
310
- private function modify_response($response) {
 
311
  return $response;
312
  }
313
 
314
- private function get_wc_keys() {
 
315
  $wcKey = CreativeMail::get_instance()->get_api_manager()->get_or_generate_key();
316
  $key = sha1(OptionsHelper::get_instance_api_key() . OptionsHelper::get_instance_uuid());
317
- $salt = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) );
318
  $salted = '';
319
  $dx = '';
320
- while ( strlen( $salted ) < 48 ) {
321
- $dx = md5( $dx . $key . $salt, true );
322
  $salted .= $dx;
323
  }
324
- $key = substr( $salted, 0, 32 );
325
- $iv = substr( $salted, 32, 16 );
326
- $cs = openssl_encrypt( $wcKey->consumer_secret, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv );
327
- $ck = openssl_encrypt( $wcKey->consumer_key, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv );
328
 
329
  $result = new \stdClass();
330
- $result->salt = bin2hex( $salt );
331
- $result->secret = base64_encode( $cs );
332
- $result->key = base64_encode( $ck );
333
  $result->version = '1';
334
 
335
- return new WP_REST_Response( $result, 200 );
336
  }
337
 
338
  /**
339
  * Registers a route to the WP Rest endpoints for this plugin.
 
340
  * @param array $route
341
  */
342
- private function register_route(array $route) {
 
343
 
344
  // Make sure the route is valid
345
  $path = $route[self::ROUTE_PATH];
@@ -349,7 +368,7 @@ class ApiManager
349
  if (array_key_exists(self::ROUTE_PERMISSION_CALLBACK, $route)) {
350
  $permission_callback = $route[self::ROUTE_PERMISSION_CALLBACK];
351
  }
352
- else if(in_array($path, self::ROUTE_REQUIRES_WP_ADMIN)){
353
  $permission_callback = array( $this, 'validate_wp_admin' );
354
  }
355
  else {
@@ -357,7 +376,8 @@ class ApiManager
357
  }
358
 
359
  // Make sure we at least have a path
360
- if (empty($path)) return;
 
361
 
362
  // If we don't have a method, assume it is GET
363
  if(empty($methods)) {
@@ -378,15 +398,16 @@ class ApiManager
378
  *
379
  * @since 1.1.0
380
  *
381
- * @param int $user_id WordPress user ID
382
  * @return object|bool
383
  * @throws Exception
384
  */
385
- public function refresh_key( $user_id = null ) {
 
386
 
387
  $this->revoke_key();
388
 
389
- return $this->create_key( $user_id );
390
  }
391
 
392
 
@@ -395,52 +416,55 @@ class ApiManager
395
  *
396
  * @since 1.1.0
397
  *
398
- * @param int $user_id WordPress user ID
399
  * @return object
400
  * @throws Exception
401
  */
402
- public function create_key( $user_id = null ) {
 
403
  global $wpdb;
404
 
405
  // if no user is specified, try the current user or find an eligible admin
406
- if ( ! $user_id ) {
407
 
408
  $user_id = get_current_user_id();
409
 
410
  // if the current user can't manage WC, try and get the first admin
411
- if ( ! user_can( $user_id, 'manage_woocommerce' ) ) {
412
 
413
  $user_id = null;
414
 
415
- $administrator_ids = get_users( array(
 
416
  'role' => 'administrator',
417
  'fields' => 'ID',
418
- ) );
 
419
 
420
  foreach ( $administrator_ids as $administrator_id ) {
421
 
422
- if ( user_can( $administrator_id, 'manage_woocommerce' ) ) {
423
 
424
  $user_id = $administrator_id;
425
  break;
426
  }
427
  }
428
 
429
- if ( ! $user_id ) {
430
- throw new Exception( 'No eligible users could be found' );
431
  }
432
  }
433
 
434
  // otherwise, check the user that's specified
435
- } elseif ( ! user_can( $user_id, 'manage_woocommerce' ) ) {
436
 
437
- throw new Exception( "User {$user_id} does not have permission" );
438
  }
439
 
440
- $user = get_userdata( $user_id );
441
 
442
- if ( ! $user ) {
443
- throw new Exception( 'Invalid user' );
444
  }
445
 
446
  $consumer_key = 'ck_' . wc_rand_hash();
@@ -452,9 +476,9 @@ class ApiManager
452
  'user_id' => $user->ID,
453
  'description' => 'CreativeMail',
454
  'permissions' => 'read_write',
455
- 'consumer_key' => wc_api_hash( $consumer_key ),
456
  'consumer_secret' => $consumer_secret,
457
- 'truncated_key' => substr( $consumer_key, -7 ),
458
  ),
459
  array(
460
  '%d',
@@ -466,8 +490,8 @@ class ApiManager
466
  )
467
  );
468
 
469
- if ( ! $result ) {
470
- throw new Exception( 'The key could not be saved' );
471
  }
472
 
473
  $key = new \stdClass();
@@ -478,7 +502,7 @@ class ApiManager
478
  $key->consumer_secret = $consumer_secret;
479
 
480
  // store the new key ID
481
- $this->set_key_id( $key->key_id );
482
  $this->set_consumer_key($consumer_key);
483
 
484
  return $key;
@@ -490,11 +514,12 @@ class ApiManager
490
  *
491
  * @since 1.1.0
492
  */
493
- public function revoke_key() {
 
494
  global $wpdb;
495
 
496
- if ( $key_id = $this->get_key_id() ) {
497
- $wpdb->delete( $wpdb->prefix . 'woocommerce_api_keys', array( 'key_id' => $key_id ), array( '%d' ) );
498
  }
499
 
500
  OptionsHelper::delete_wc_api_key_id();
@@ -509,19 +534,24 @@ class ApiManager
509
  *
510
  * @return object|null
511
  */
512
- public function get_key() {
 
513
  global $wpdb;
514
 
515
  $key = null;
516
 
517
- if ( $id = $this->get_key_id() ) {
518
- $key = $wpdb->get_row( $wpdb->prepare( "
 
 
519
  SELECT key_id, user_id, permissions, consumer_secret
520
  FROM {$wpdb->prefix}woocommerce_api_keys
521
  WHERE key_id = %d
522
- ", $id ) );
 
 
523
 
524
- if ( isset( $key ) ) {
525
  $key->consumer_key = $this->get_consumer_key();
526
  }
527
  }
@@ -536,7 +566,8 @@ class ApiManager
536
  *
537
  * @return object|null
538
  */
539
- public function get_or_generate_key() {
 
540
  $key = $this->get_key();
541
 
542
  if ($key == null) {
@@ -554,12 +585,14 @@ class ApiManager
554
  *
555
  * @return int
556
  */
557
- public function get_key_id() {
 
558
 
559
  return OptionsHelper::get_wc_api_key_id();
560
  }
561
 
562
- public function get_consumer_key() {
 
563
 
564
  return OptionsHelper::get_wc_consumer_key();
565
  }
17
 
18
  /**
19
  * Class ApiManager
20
+ *
21
  * @package CreativeMail\Managers
22
  */
23
  class ApiManager
38
  $this->api_background_process = new ApiBackgroundProcess();
39
  }
40
 
41
+ public function get_api_background_process()
42
+ {
43
  return $this->api_background_process;
44
  }
45
 
46
  /**
47
  * Will add all the hooks that are required to setup our plugin API.
48
  */
49
+ public function add_hooks()
50
+ {
51
 
52
+ add_action('rest_api_init', array($this, 'add_rest_endpoints'));
53
  }
54
 
55
+ public function validate_wp_admin()
56
+ {
57
+ if(!current_user_can('administrator')) {
58
+ return new WP_Error('rest_forbidden', __('Sorry, you are not allowed to do that.'), array( self::HTTP_STATUS => 401 ));
59
  }
60
 
61
  return true;
62
  }
63
 
64
+ public function validate_api_key()
65
+ {
66
  //never cache our rest endpoints
67
  nocache_headers();
68
 
69
+ if (! array_key_exists("HTTP_X_API_KEY", $_SERVER) ) {
70
+ return new WP_Error('rest_forbidden', __('Sorry, you are not allowed to do that.'), array( self::HTTP_STATUS => 401 ));
71
  }
72
 
73
  $key = OptionsHelper::get_instance_api_key();
74
  $apiKey = $_SERVER["HTTP_X_API_KEY"];
75
  // verify that api key is valid
76
+ if ($apiKey === $key ) {
77
  return true;
78
  }
79
 
80
+ return new WP_Error('rest_forbidden', __('Sorry, you are not allowed to do that.'), array( self::HTTP_STATUS => 401 ));
81
  }
82
 
83
+ public function validate_callback()
84
+ {
85
  //never cache our rest endpoints
86
  nocache_headers();
87
 
88
+ if (! array_key_exists("HTTP_X_API_KEY", $_SERVER) ) {
89
+ return new WP_Error('rest_forbidden', __('Sorry, you are not allowed to do that.'), array( self::HTTP_STATUS => 401 ));
90
  }
91
 
92
  $apiKey = $_SERVER["HTTP_X_API_KEY"];
93
  // Verify handshake expiration
94
  $expiration = OptionsHelper::get_handshake_expiration();
95
+ if ($expiration === null || $expiration < time() ) {
96
+ return new WP_Error('rest_unauthorized', 'Unauthorized', array( self::HTTP_STATUS => 401 ));
97
  }
98
 
99
  // Verify handshake
100
+ if ($apiKey === OptionsHelper::get_handshake_token() ) {
101
  return true;
102
  }
103
 
104
+ return new WP_Error('rest_unauthorized', 'Unauthorized', array( self::HTTP_STATUS => 401 ));
105
  }
106
 
107
+ public function add_rest_endpoints()
108
+ {
109
  // Add the endpoint to handle the callback
110
  $routes = array (
111
  array (
112
  self::ROUTE_PATH => '/callback',
113
  self::ROUTE_METHODS => 'POST',
114
  self::ROUTE_CALLBACK => array(CreativeMail::get_instance()->get_instance_manager(), 'handle_callback'),
115
+ self::ROUTE_PERMISSION_CALLBACK => function () {
116
  return $this->validate_callback();
117
  }
118
  ),
119
  array (
120
  self::ROUTE_PATH => '/available_plugins',
121
  self::ROUTE_METHODS => 'GET',
122
+ self::ROUTE_CALLBACK => function () {
123
  return $this->modify_response($this->get_plugin_info(true));
124
  }
125
  ),
126
  array (
127
  self::ROUTE_PATH => '/available_plugins',
128
  self::ROUTE_METHODS => 'POST',
129
+ self::ROUTE_CALLBACK => function ($request) {
130
  CreativeMail::get_instance()->get_integration_manager()->set_activated_plugins(json_decode($request->get_body()));
131
  }
132
  ),
133
  array (
134
  self::ROUTE_PATH => '/sso',
135
  self::ROUTE_METHODS => 'GET',
136
+ self::ROUTE_CALLBACK => function () {
137
  $admin_manager = CreativeMail::get_instance()->get_admin_manager();
138
  if(isset($admin_manager)) {
139
  $sso_url = $admin_manager->get_sso_link();
140
+ if(isset($sso_url)) {
141
  return $this->modify_response(new WP_REST_Response(array('url' => $sso_url)));
142
  }
143
  }
144
 
145
+ return new WP_Error('rest_unauthorized', 'Unauthorized', array( self::HTTP_STATUS => 401 ));
146
  }
147
  ),
148
  array (
149
  self::ROUTE_PATH => '/plugins',
150
  self::ROUTE_METHODS => 'GET',
151
+ self::ROUTE_CALLBACK => function () {
152
  return $this->modify_response($this->get_plugin_info(false));
153
  }
154
  ),
155
  array (
156
  self::ROUTE_PATH => '/managed_email_notifications',
157
  self::ROUTE_METHODS => 'GET',
158
+ self::ROUTE_CALLBACK => function () {
159
  $result = CreativeMail::get_instance()->get_email_manager()->get_managed_email_notifications();
160
  return $this->modify_response(new WP_REST_Response($result, 200));
161
  }
163
  array (
164
  self::ROUTE_PATH => '/managed_email_notifications',
165
  self::ROUTE_METHODS => 'POST',
166
+ self::ROUTE_CALLBACK => function ($request) {
167
  if(!CreativeMail::get_instance()->get_integration_manager()->get_permalinks_enabled()) {
168
+ return $this->modify_response(new WP_REST_Response(array( 'message' => 'Please enable pretty permalinks in the WordPress settings.'), 400));
169
  }
170
 
171
  $result = CreativeMail::get_instance()->get_email_manager()->set_managed_email_notifications(json_decode($request->get_body()));
175
  array (
176
  self::ROUTE_PATH => '/wc_key',
177
  self::ROUTE_METHODS => 'GET',
178
+ self::ROUTE_CALLBACK => function () {
179
  return $this->modify_response($this->get_wc_keys());
180
  }
181
  ),
182
  array (
183
  self::ROUTE_PATH => '/synchronize',
184
  self::ROUTE_METHODS => 'POST',
185
+ self::ROUTE_CALLBACK => function () {
186
+ do_action(CE4WP_SYNCHRONIZE_ACTION, 250);
187
+ return $this->modify_response(new WP_REST_Response(null, 200));
188
+ }
189
  ),
190
  array (
191
  self::ROUTE_PATH => '/wc_information',
192
  self::ROUTE_METHODS => 'GET',
193
+ self::ROUTE_CALLBACK => function () {
194
  return $this->modify_response(new WP_REST_Response(new WCInformationModel(), 200));
195
  }
196
  ),
197
  array (
198
  self::ROUTE_PATH => '/wc_products',
199
  self::ROUTE_METHODS => 'GET',
200
+ self::ROUTE_CALLBACK => function ($request) {
201
  $productData = array();
202
+ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
 
203
  $page = 1;
204
+ if (key_exists('page', $request)) {
 
205
  $page = (int)$request['page'];
206
  }
207
 
208
  // Get 25 most recent products
209
+ $products = wc_get_products(
210
+ array(
211
  'limit' => 25,
212
  'paged' => $page,
213
+ )
214
+ );
215
  foreach ($products as $product) {
216
+ array_push($productData, new WCProductModel($product->get_data()));
217
  }
218
  }
219
  return $this->modify_response(new WP_REST_Response($productData, 200));
222
  array (
223
  self::ROUTE_PATH => '/blog_information',
224
  self::ROUTE_METHODS => 'GET',
225
+ self::ROUTE_CALLBACK => function () {
226
  return $this->modify_response(new WP_REST_Response(new BlogInformation(), 200));
227
  }
228
  ),
229
  array (
230
  self::ROUTE_PATH => '/wp_posts',
231
  self::ROUTE_METHODS => 'GET',
232
+ self::ROUTE_CALLBACK => function ($request) {
233
 
234
  $page = 1;
235
+ if (key_exists('page', $request)) {
 
236
  $page = (int)$request['page'];
237
  }
238
 
239
+ $posts = get_posts(
240
+ array(
241
  'posts_per_page' => 10,
242
  'paged' => $page,
243
  'post_type' => 'post'
244
+ )
245
+ );
246
 
247
  $postData = array();
248
  foreach ($posts as $post)
249
  {
250
+ array_push($postData, new BlogPost($post));
251
  }
252
 
253
  return $this->modify_response(new WP_REST_Response($postData, 200));
256
  array (
257
  self::ROUTE_PATH => '/images',
258
  self::ROUTE_METHODS => 'GET',
259
+ self::ROUTE_CALLBACK => function () {
260
  $attachmentData = array();
261
+ $attachments = get_posts(
262
+ array(
263
+ 'post_type' => 'attachment',
264
+ 'post_mime_type' => 'image',
265
+ 'post_status' => 'inherit',
266
+ 'posts_per_page' => -1
267
+ )
268
+ );
269
 
270
  foreach ($attachments as $attachment)
271
  {
272
+ array_push($attachmentData, new BlogAttachment($attachment));
273
  }
274
 
275
  return $this->modify_response(new WP_REST_Response($attachmentData, 200));
282
  }
283
  }
284
 
285
+ private function get_plugin_info($onlyActivePlugins)
286
+ {
287
  $result = array();
288
  $activePlugins = CreativeMail::get_instance()->get_integration_manager()->get_active_plugins();
289
+ if ($onlyActivePlugins === true ) {
290
  foreach ( $activePlugins as $activePlugin ) {
291
+ array_push(
292
+ $result, array(
293
  'name' => $activePlugin->get_name(),
294
  'slug' => $activePlugin->get_slug()
295
+ )
296
+ );
297
  }
298
  } else {
299
  $allPlugins = CreativeMail::get_instance()->get_integration_manager()->get_supported_integrations();
302
  if ($plugin->is_hidden_from_suggestions()) {
303
  continue;
304
  }
305
+ array_push(
306
+ $result, array(
307
  'name' => $plugin->get_name(),
308
  'slug' => $plugin->get_slug(),
309
+ 'installed' => in_array($plugin, $activePlugins, true) !== false,
310
+ 'activated' => array_search($plugin->get_slug(), $activatedPlugins, true) !== false,
311
+ )
312
+ );
313
  }
314
  }
315
 
316
+ return new WP_REST_Response($result, 200);
317
  }
318
 
319
  /**
320
  * Modifies the response to disable caching
321
  *
322
+ * @param WP_REST_Response $response The endpoint its response
323
  * @return WP_REST_Response
324
  */
325
+ private function modify_response($response)
326
+ {
327
  return $response;
328
  }
329
 
330
+ private function get_wc_keys()
331
+ {
332
  $wcKey = CreativeMail::get_instance()->get_api_manager()->get_or_generate_key();
333
  $key = sha1(OptionsHelper::get_instance_api_key() . OptionsHelper::get_instance_uuid());
334
+ $salt = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
335
  $salted = '';
336
  $dx = '';
337
+ while ( strlen($salted) < 48 ) {
338
+ $dx = md5($dx . $key . $salt, true);
339
  $salted .= $dx;
340
  }
341
+ $key = substr($salted, 0, 32);
342
+ $iv = substr($salted, 32, 16);
343
+ $cs = openssl_encrypt($wcKey->consumer_secret, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
344
+ $ck = openssl_encrypt($wcKey->consumer_key, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
345
 
346
  $result = new \stdClass();
347
+ $result->salt = bin2hex($salt);
348
+ $result->secret = base64_encode($cs);
349
+ $result->key = base64_encode($ck);
350
  $result->version = '1';
351
 
352
+ return new WP_REST_Response($result, 200);
353
  }
354
 
355
  /**
356
  * Registers a route to the WP Rest endpoints for this plugin.
357
+ *
358
  * @param array $route
359
  */
360
+ private function register_route(array $route)
361
+ {
362
 
363
  // Make sure the route is valid
364
  $path = $route[self::ROUTE_PATH];
368
  if (array_key_exists(self::ROUTE_PERMISSION_CALLBACK, $route)) {
369
  $permission_callback = $route[self::ROUTE_PERMISSION_CALLBACK];
370
  }
371
+ else if(in_array($path, self::ROUTE_REQUIRES_WP_ADMIN)) {
372
  $permission_callback = array( $this, 'validate_wp_admin' );
373
  }
374
  else {
376
  }
377
 
378
  // Make sure we at least have a path
379
+ if (empty($path)) { return;
380
+ }
381
 
382
  // If we don't have a method, assume it is GET
383
  if(empty($methods)) {
398
  *
399
  * @since 1.1.0
400
  *
401
+ * @param int $user_id WordPress user ID
402
  * @return object|bool
403
  * @throws Exception
404
  */
405
+ public function refresh_key( $user_id = null )
406
+ {
407
 
408
  $this->revoke_key();
409
 
410
+ return $this->create_key($user_id);
411
  }
412
 
413
 
416
  *
417
  * @since 1.1.0
418
  *
419
+ * @param int $user_id WordPress user ID
420
  * @return object
421
  * @throws Exception
422
  */
423
+ public function create_key( $user_id = null )
424
+ {
425
  global $wpdb;
426
 
427
  // if no user is specified, try the current user or find an eligible admin
428
+ if (! $user_id ) {
429
 
430
  $user_id = get_current_user_id();
431
 
432
  // if the current user can't manage WC, try and get the first admin
433
+ if (! user_can($user_id, 'manage_woocommerce') ) {
434
 
435
  $user_id = null;
436
 
437
+ $administrator_ids = get_users(
438
+ array(
439
  'role' => 'administrator',
440
  'fields' => 'ID',
441
+ )
442
+ );
443
 
444
  foreach ( $administrator_ids as $administrator_id ) {
445
 
446
+ if (user_can($administrator_id, 'manage_woocommerce') ) {
447
 
448
  $user_id = $administrator_id;
449
  break;
450
  }
451
  }
452
 
453
+ if (! $user_id ) {
454
+ throw new Exception('No eligible users could be found');
455
  }
456
  }
457
 
458
  // otherwise, check the user that's specified
459
+ } elseif (! user_can($user_id, 'manage_woocommerce') ) {
460
 
461
+ throw new Exception("User {$user_id} does not have permission");
462
  }
463
 
464
+ $user = get_userdata($user_id);
465
 
466
+ if (! $user ) {
467
+ throw new Exception('Invalid user');
468
  }
469
 
470
  $consumer_key = 'ck_' . wc_rand_hash();
476
  'user_id' => $user->ID,
477
  'description' => 'CreativeMail',
478
  'permissions' => 'read_write',
479
+ 'consumer_key' => wc_api_hash($consumer_key),
480
  'consumer_secret' => $consumer_secret,
481
+ 'truncated_key' => substr($consumer_key, -7),
482
  ),
483
  array(
484
  '%d',
490
  )
491
  );
492
 
493
+ if (! $result ) {
494
+ throw new Exception('The key could not be saved');
495
  }
496
 
497
  $key = new \stdClass();
502
  $key->consumer_secret = $consumer_secret;
503
 
504
  // store the new key ID
505
+ $this->set_key_id($key->key_id);
506
  $this->set_consumer_key($consumer_key);
507
 
508
  return $key;
514
  *
515
  * @since 1.1.0
516
  */
517
+ public function revoke_key()
518
+ {
519
  global $wpdb;
520
 
521
+ if ($key_id = $this->get_key_id() ) {
522
+ $wpdb->delete($wpdb->prefix . 'woocommerce_api_keys', array( 'key_id' => $key_id ), array( '%d' ));
523
  }
524
 
525
  OptionsHelper::delete_wc_api_key_id();
534
  *
535
  * @return object|null
536
  */
537
+ public function get_key()
538
+ {
539
  global $wpdb;
540
 
541
  $key = null;
542
 
543
+ if ($id = $this->get_key_id() ) {
544
+ $key = $wpdb->get_row(
545
+ $wpdb->prepare(
546
+ "
547
  SELECT key_id, user_id, permissions, consumer_secret
548
  FROM {$wpdb->prefix}woocommerce_api_keys
549
  WHERE key_id = %d
550
+ ", $id
551
+ )
552
+ );
553
 
554
+ if (isset($key) ) {
555
  $key->consumer_key = $this->get_consumer_key();
556
  }
557
  }
566
  *
567
  * @return object|null
568
  */
569
+ public function get_or_generate_key()
570
+ {
571
  $key = $this->get_key();
572
 
573
  if ($key == null) {
585
  *
586
  * @return int
587
  */
588
+ public function get_key_id()
589
+ {
590
 
591
  return OptionsHelper::get_wc_api_key_id();
592
  }
593
 
594
+ public function get_consumer_key()
595
+ {
596
 
597
  return OptionsHelper::get_wc_consumer_key();
598
  }
src/managers/email-manager.php CHANGED
@@ -11,21 +11,25 @@ use stdClass;
11
 
12
  /**
13
  * Class EmailManager
 
14
  * @package CreativeMail\Managers
15
  */
16
  class EmailManager
17
  {
18
- /** @var array email ids being managed by CreativeMail */
 
 
19
  protected $managed_email_notifications;
20
 
21
- public function __construct() {
 
22
 
23
  }
24
 
25
- public function add_hooks() {
 
26
  // check if woocommerce is active
27
- if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))
28
- {
29
  add_action('init', array($this, 'manage_emails'));
30
 
31
  // email settings table customizations
@@ -34,27 +38,26 @@ class EmailManager
34
  add_action('woocommerce_email_settings_before', array($this, 'redirect_managed_email_settings_to_creative_mail'));
35
 
36
  //woocommerce hooks
37
- add_action( 'woocommerce_new_order', array($this, 'ce_email_notification_new_order'), 10, 2);
38
- add_action( 'woocommerce_order_status_cancelled', array($this, 'ce_email_notification_cancelled'), 10, 2);
39
- add_action( 'woocommerce_order_status_failed', array($this, 'ce_email_notification_failed'), 10, 2);
40
- add_action( 'woocommerce_order_status_on-hold', array($this, 'ce_email_notification_hold'), 10, 2);
41
- add_action( 'woocommerce_order_status_processing', array($this, 'ce_email_notification_processing'), 10, 2);
42
- add_action( 'woocommerce_order_status_completed', array($this, 'ce_email_notification_completed'), 10, 2);
43
- add_action( 'woocommerce_order_status_refunded', array($this, 'ce_email_notification_refunded'), 10, 2);
44
- add_action( 'woocommerce_after_resend_order_email', array($this, 'ce_email_notification_invoice'), 10, 2);
45
  //payment complete
46
- add_action( 'woocommerce_payment_complete', array( $this, 'ce_email_notification_payment_complete'), 10, 1 );
47
  //
48
- add_action( 'woocommerce_new_customer_note', array( $this, 'ce_email_notification_new_customer_note'), 10, 2 );
49
  //
50
- add_action( 'woocommerce_reset_password_notification', array( $this, 'ce_email_notification_customer_reset_password' ), 10, 2 );
51
- add_action( 'woocommerce_created_customer', array( $this, 'ce_email_notification_customer_new_account' ), 10, 3 );
52
  // replace wc email settings
53
  add_filter('woocommerce_email_settings', array($this, 'replace_wc_email_settings'));
54
  add_action('woocommerce_admin_field_ce_manage_button', array($this, 'print_ce_manage_button'));
55
  // add checkbox to checkout if enabled
56
- if (OptionsHelper::get_checkout_checkbox_enabled() === '1')
57
- {
58
  add_filter('woocommerce_after_order_notes', array($this, 'add_checkout_field'));
59
  add_action('woocommerce_checkout_update_order_meta', array($this, 'ce_checkout_order_meta'));
60
  }
@@ -63,35 +66,36 @@ class EmailManager
63
 
64
  public function ce_checkout_order_meta( $order_id )
65
  {
66
- if ($_POST['ce_checkout_consent_checkbox'])
67
- {
68
  $checkbox_value = esc_attr($_POST['ce_checkout_consent_checkbox']);
69
- update_post_meta( $order_id, 'ce_checkout_consent', $checkbox_value);
70
  }
71
  }
72
 
73
  public function add_checkout_field( $checkout)
74
  {
75
- $checked = $checkout->get_value( 'ce_checkout_consent_checkbox' ) ? $checkout->get_value( 'ce_checkout_consent_checkbox' ) : 1;
76
  $checkbox_text = stripslashes(OptionsHelper::get_checkout_checkbox_text());
77
 
78
- woocommerce_form_field( 'ce_checkout_consent_checkbox', array(
79
- 'type' => 'checkbox',
80
- 'class' => array('ce-field form-row-wide'),
81
- 'label' => $checkbox_text,
82
- ), $checked );
 
 
83
  }
84
 
85
  public function replace_wc_email_settings($settings)
86
  {
87
  $default_setting_replacement = array(
88
- 'woocommerce_email_header_image' => 'header_image',
89
- 'woocommerce_email_footer_text' => 'footer_content_text',
90
- 'woocommerce_email_base_color' => null,
91
- 'woocommerce_email_background_color' => 'background_color',
92
- 'woocommerce_email_body_background_color' => 'email_background_color',
93
- 'woocommerce_email_text_color' => 'text_color'
94
- );
95
 
96
  // Define options that need to be replaced
97
  $replace = array_merge(array_keys($default_setting_replacement), array('email_template_options'));
@@ -139,12 +143,13 @@ class EmailManager
139
  return OptionsHelper::get_managed_email_notifications();
140
  }
141
 
142
- public function set_managed_email_notifications($body) {
143
- if ( empty( $body ) || $body === null ) {
 
144
  return null;
145
  }
146
 
147
- if ( property_exists( $body, 'name' ) ) {
148
  $valid_names = [
149
  'customer_completed_order',
150
  'customer_refunded_order',
@@ -155,8 +160,8 @@ class EmailManager
155
  'customer_invoice',
156
  'customer_note'
157
  ];
158
- if ( in_array( $body->name, $valid_names ) ) {
159
- OptionsHelper::set_managed_email_notification( $body->name, $body->active == true ? 'true' : 'false' );
160
  return $body;
161
  }
162
  }
@@ -173,37 +178,39 @@ class EmailManager
173
  *
174
  * @param \WC_Email $email the email
175
  */
176
- public function render_email_status_column( \WC_Email $email ) {
 
177
 
178
  echo '<td class="wc-email-settings-table-status">';
179
 
180
- if ( $this->is_email_managed( $email->id ) ) {
181
- echo '<span class="status-creativemail tips" data-tip="' . esc_attr__( 'Managed by Creative Mail', 'creativ-email-wordpress-plugin' ) . '">' . esc_html__( 'Managed by CreativeMail', 'creativ-email-wordpress-plugin' ) . '</span>';
182
- } elseif ( $email->is_manual() ) {
183
- echo '<span class="status-manual tips" data-tip="' . esc_attr__( 'Manually sent', 'woocommerce' ) . '">' . esc_html__( 'Manual', 'woocommerce' ) . '</span>';
184
- } elseif ( $email->is_enabled() ) {
185
- echo '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Enabled', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>';
186
  } else {
187
- echo '<span class="status-disabled tips" data-tip="' . esc_attr__( 'Disabled', 'woocommerce' ) . '">-</span>';
188
  }
189
 
190
  echo '</td>';
191
  }
192
 
193
- public function customize_email_setting_columns( $columns ) {
 
194
 
195
- $column_keys = array_keys( $columns );
196
 
197
  // replace the status column, or put at the beginning if status isn't found
198
- $status_index = array_search( 'status', $column_keys, true );
199
- array_splice( $column_keys, is_numeric( $status_index ) ? $status_index : 0, is_numeric( $status_index ) ? 1 : 0, 'wc_ce_status' );
200
 
201
  $new_columns = array();
202
  $columns['wc_ce_status'] = '';
203
 
204
  foreach ( $column_keys as $column_key )
205
  {
206
- if ( isset( $columns[ $column_key ] ) ) {
207
  $new_columns[ $column_key ] = $columns[ $column_key ];
208
  }
209
  }
@@ -211,7 +218,8 @@ class EmailManager
211
  return $new_columns;
212
  }
213
 
214
- public function ce_email_notification_new_customer_note($array) {
 
215
  $data = new stdClass();
216
  $data->order_id = $array['order_id'];
217
  $data->note = $array['customer_note'];
@@ -220,13 +228,13 @@ class EmailManager
220
  $this->execute_trigger("customer_note", $data, wc_get_order($data->order_id));
221
  }
222
 
223
- public function ce_email_notification_customer_new_account($customer_id, $new_customer_data, $password_generated) {
 
224
  $data = new stdClass();
225
  $data->customer_id = $customer_id;
226
  $data->account_url = $this->get_my_account_url();
227
 
228
- if ($password_generated && key_exists("user_pass", $new_customer_data))
229
- {
230
  try {
231
  $generated_password = $new_customer_data['user_pass'];
232
  $key = sha1(OptionsHelper::get_instance_api_key() . OptionsHelper::get_instance_uuid());
@@ -250,22 +258,26 @@ class EmailManager
250
  $this->execute_trigger("customer_new_account", $data);
251
  }
252
 
253
- public function ce_email_notification_customer_reset_password($user_login = '', $reset_key = '') {
254
- if ( $user_login && $reset_key ) {
 
255
  $data = new stdClass();
256
- $user = get_user_by( 'login', $user_login );
257
  $data->customer_id = $user->ID;
258
  $data->account_url = $this->get_my_account_url();
259
- $data->reset_url = add_query_arg( array(
 
260
  'key' => $reset_key,
261
  'id' => $data->customer_id
262
- ), wc_get_endpoint_url( 'lost-password', '', $data->account_url ) );
 
263
 
264
- $this->execute_trigger( "customer_reset_password", $data );
265
  }
266
  }
267
 
268
- public function ce_email_notification_payment_complete( $order_id ) {
 
269
  $data = new stdClass();
270
  $data->order_id = $order_id;
271
  $data->order_url = $this->get_view_order_url($order_id, null);
@@ -273,42 +285,48 @@ class EmailManager
273
  $this->execute_trigger("payment_received", $data, wc_get_order($order_id));
274
  }
275
 
276
- public function ce_email_notification_failed($order_id, $order) {
 
277
  $data = new stdClass();
278
  $data->order_id = $order_id;
279
  $data->order_url = $this->get_view_order_url($order_id, $order);
280
 
281
  $this->execute_trigger("failed_order", $data, $order);
282
  }
283
- public function ce_email_notification_hold($order_id, $order) {
 
284
  $data = new stdClass();
285
  $data->order_id = $order_id;
286
  $data->order_url = $this->get_view_order_url($order_id, $order);
287
 
288
  $this->execute_trigger("customer_on_hold_order", $data, $order);
289
  }
290
- public function ce_email_notification_processing($order_id, $order) {
 
291
  $data = new stdClass();
292
  $data->order_id = $order_id;
293
  $data->order_url = $this->get_view_order_url($order_id, $order);
294
 
295
  $this->execute_trigger("customer_processing_order", $data, $order);
296
  }
297
- public function ce_email_notification_completed($order_id, $order) {
 
298
  $data = new stdClass();
299
  $data->order_id = $order_id;
300
  $data->order_url = $this->get_view_order_url($order_id, $order);
301
 
302
  $this->execute_trigger("customer_completed_order", $data, $order);
303
  }
304
- public function ce_email_notification_refunded($order_id, $order) {
 
305
  $data = new stdClass();
306
  $data->order_id = $order_id;
307
  $data->order_url = $this->get_view_order_url($order_id, $order);
308
 
309
  $this->execute_trigger("customer_refunded_order", $data, $order);
310
  }
311
- public function ce_email_notification_cancelled($order_id, $order) {
 
312
  $data = new stdClass();
313
  $data->order_id = $order_id;
314
  $data->order_url = $this->get_view_order_url($order_id, $order);
@@ -316,7 +334,8 @@ class EmailManager
316
  $this->execute_trigger("cancelled_order", $data, $order);
317
  }
318
 
319
- public function ce_email_notification_new_order($order_id, $order) {
 
320
  $data = new stdClass();
321
  $data->order_id = $order_id;
322
  $data->order_url = $this->get_view_order_url($order_id, $order);
@@ -324,20 +343,22 @@ class EmailManager
324
  $this->execute_trigger("new_order", $data, $order);
325
  }
326
 
327
- public function ce_email_notification_invoice($order, $type) {
328
- if ( $type === 'new_order' ) {
329
- $this->ce_email_notification_new_order( $order->id, $order );
 
330
  return;
331
  }
332
 
333
  $data = new stdClass();
334
  $data->order_id = $order->get_id();
335
- $data->order_url = $this->get_view_order_url( $order->get_id(), $order );
336
 
337
- $this->execute_trigger( "customer_invoice", $data, $order );
338
  }
339
 
340
- public function execute_trigger($type, $data, $order = null) {
 
341
  // if not managed do not trigger
342
  if (!$this->is_email_managed($type)) {
343
  return;
@@ -346,8 +367,7 @@ class EmailManager
346
  $requestItem = new stdClass();
347
  $requestItem->type = $type;
348
  $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress').'/v1.0/wc/trigger';
349
- if(!is_null($order))
350
- {
351
  try {
352
  $dp = 2; // decimal point
353
  $order_data = array(
@@ -434,8 +454,7 @@ class EmailManager
434
  $product_data["sale_price"] = $product->get_sale_price();
435
  $product_data["regular_price"] = $product->get_regular_price();
436
 
437
- if ($product->is_downloadable())
438
- {
439
  $item_downloads = $item->get_item_downloads();
440
  foreach ($item_downloads as $item_download)
441
  {
@@ -460,8 +479,8 @@ class EmailManager
460
  }
461
 
462
  $src = wc_placeholder_img_src();
463
- if ( $image_id = $product->get_image_id() ) {
464
- list( $src ) = wp_get_attachment_image_src( $image_id, 'full' );
465
  }
466
 
467
  $order_data['line_items'][] = array(
@@ -479,7 +498,7 @@ class EmailManager
479
  'product_data' => $product_data,
480
  'sku' => is_object($product) ? $product->get_sku() : null,
481
  'meta' => array_values($item_meta),
482
- 'product_url' => get_the_permalink( $item->get_product_id() ),
483
  'variation_id' => $item->get_variation_id()
484
  );
485
  }
@@ -536,7 +555,8 @@ class EmailManager
536
 
537
  $requestItem->data = wp_json_encode($data);
538
 
539
- wp_remote_post($endpoint, array(
 
540
  'method' => 'POST',
541
  'timeout' => 10,
542
  'headers' => array(
@@ -545,7 +565,8 @@ class EmailManager
545
  'content-type' => 'application/json'
546
  ),
547
  'body' => wp_json_encode($requestItem)
548
- ));
 
549
  }
550
 
551
  /**
@@ -555,24 +576,25 @@ class EmailManager
555
  *
556
  * @since 1.1.0
557
  */
558
- public function manage_emails() {
 
559
 
560
  $this->managed_email_notifications = $this->get_managed_email_notifications();
561
 
562
- if ( empty( $this->managed_email_notifications ) || ! is_array( $this->managed_email_notifications ) ) {
563
- return;
564
  }
565
 
566
  // disable managed emails
567
  foreach ( $this->managed_email_notifications as $notification )
568
  {
569
- if ( $this->is_email_managed( $notification->name ) ) {
570
- add_filter( "woocommerce_email_enabled_". $notification->name ."", '__return_false' );
571
  }
572
  }
573
 
574
- add_filter( 'woocommerce_email_title', array( $this, 'override_managed_email_title' ), 10, 2 );
575
- add_filter( 'woocommerce_email_description', array( $this, 'override_managed_email_description' ), 10, 2 );
576
  }
577
 
578
 
@@ -583,15 +605,16 @@ class EmailManager
583
  *
584
  * @since 1.1.0
585
  *
586
- * @param string $title the email title
587
- * @param \WC_Email $email the email object
588
  * @return string
589
  */
590
- public function override_managed_email_title( $title, $email ) {
 
591
 
592
- if ( isset( $email->id ) && $this->is_email_managed( $email->id ) ) {
593
 
594
- $title .= __( ' (Managed by Creative Mail)', 'creativ-email-wordpress-plugin' );
595
  }
596
 
597
  return $title;
@@ -605,15 +628,16 @@ class EmailManager
605
  *
606
  * @since 1.1.0
607
  *
608
- * @param string $description description text
609
- * @param \WC_Email $email the email object
610
  * @return string
611
  */
612
- public function override_managed_email_description( $description, $email ) {
 
613
 
614
- if ( isset( $email->id ) && $this->is_email_managed( $email->id ) ) {
615
 
616
- $description .= __( ' This email is being managed and sent by Creative Mail.', 'creativ-email-wordpress-plugin' );
617
  }
618
 
619
  return $description;
@@ -626,10 +650,11 @@ class EmailManager
626
  *
627
  * @param \WC_Email $email the email object
628
  */
629
- public function redirect_managed_email_settings_to_creative_mail( $email ) {
 
630
 
631
- if ( $this->is_email_managed( $email->id )) {
632
- wp_redirect(admin_url( 'admin.php?page=creativemail' ));
633
  exit;
634
  }
635
  }
@@ -639,11 +664,12 @@ class EmailManager
639
  *
640
  * @since 1.1.0
641
  *
642
- * @param string $email_id woocommerce email ID
643
  * @return bool
644
  */
645
- public function is_email_managed( $email_id ) {
646
- return (bool) $this->get_managed_notification_param( $email_id, 'active' );
 
647
  }
648
 
649
  /**
@@ -651,11 +677,12 @@ class EmailManager
651
  *
652
  * @since 1.1.0
653
  *
654
- * @param string $email_id woocommerce email ID
655
- * @param string $param param name
656
  * @return mixed|null
657
  */
658
- public function get_managed_notification_param( $email_id, $param ) {
 
659
 
660
  foreach($this->managed_email_notifications as $managed_email_notification) {
661
  if ($email_id == $managed_email_notification->name && property_exists($managed_email_notification, $param)) {
@@ -670,11 +697,12 @@ class EmailManager
670
  *
671
  * @since 1.1.0
672
  *
673
- * @param array $items managed email notifications
674
- * @param string $email_id woocommerce email ID
675
  * @return mixed|null
676
  */
677
- public function get_managed_notification( $items, $email_id ) {
 
678
 
679
  foreach($items as $managed_email_notification) {
680
  if ($email_id == $managed_email_notification->name) {
@@ -689,12 +717,13 @@ class EmailManager
689
  *
690
  * @since 1.1.0
691
  *
692
- * @param string $email_id woocommerce email ID
693
  * @return int|null
694
  */
695
- public function get_transactional_notification_id( $email_id ) {
 
696
 
697
- return $this->get_managed_notification_param( $email_id, 'transactional_notification_id' );
698
  }
699
 
700
  /**
@@ -702,21 +731,23 @@ class EmailManager
702
  *
703
  * @since 1.1.0
704
  *
705
- * @param string $email_id woocommerce email ID
706
  * @return string|null
707
  */
708
- public function get_managed_notification_state( $email_id ) {
 
709
 
710
- return $this->get_managed_notification_param( $email_id, 'state' );
711
  }
712
 
713
- private function get_view_order_url($order_id, $order) {
 
714
  try {
715
  if (!isset($order)) {
716
- $order = wc_get_order( $order_id );
717
  }
718
 
719
- if ( isset( $order ) && method_exists( $order, 'get_view_order_url' ) ) {
720
  return $order->get_view_order_url();
721
  }
722
  } catch ( \Exception $exception ) {
@@ -726,9 +757,10 @@ class EmailManager
726
  return null;
727
  }
728
 
729
- private function get_my_account_url() {
 
730
  try {
731
- return wc_get_page_permalink( 'myaccount' );
732
  } catch ( \Exception $exception ) {
733
  // silent exception
734
  }
11
 
12
  /**
13
  * Class EmailManager
14
+ *
15
  * @package CreativeMail\Managers
16
  */
17
  class EmailManager
18
  {
19
+ /**
20
+ * @var array email ids being managed by CreativeMail
21
+ */
22
  protected $managed_email_notifications;
23
 
24
+ public function __construct()
25
+ {
26
 
27
  }
28
 
29
+ public function add_hooks()
30
+ {
31
  // check if woocommerce is active
32
+ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
 
33
  add_action('init', array($this, 'manage_emails'));
34
 
35
  // email settings table customizations
38
  add_action('woocommerce_email_settings_before', array($this, 'redirect_managed_email_settings_to_creative_mail'));
39
 
40
  //woocommerce hooks
41
+ add_action('woocommerce_new_order', array($this, 'ce_email_notification_new_order'), 10, 2);
42
+ add_action('woocommerce_order_status_cancelled', array($this, 'ce_email_notification_cancelled'), 10, 2);
43
+ add_action('woocommerce_order_status_failed', array($this, 'ce_email_notification_failed'), 10, 2);
44
+ add_action('woocommerce_order_status_on-hold', array($this, 'ce_email_notification_hold'), 10, 2);
45
+ add_action('woocommerce_order_status_processing', array($this, 'ce_email_notification_processing'), 10, 2);
46
+ add_action('woocommerce_order_status_completed', array($this, 'ce_email_notification_completed'), 10, 2);
47
+ add_action('woocommerce_order_status_refunded', array($this, 'ce_email_notification_refunded'), 10, 2);
48
+ add_action('woocommerce_after_resend_order_email', array($this, 'ce_email_notification_invoice'), 10, 2);
49
  //payment complete
50
+ add_action('woocommerce_payment_complete', array( $this, 'ce_email_notification_payment_complete'), 10, 1);
51
  //
52
+ add_action('woocommerce_new_customer_note', array( $this, 'ce_email_notification_new_customer_note'), 10, 2);
53
  //
54
+ add_action('woocommerce_reset_password_notification', array( $this, 'ce_email_notification_customer_reset_password' ), 10, 2);
55
+ add_action('woocommerce_created_customer', array( $this, 'ce_email_notification_customer_new_account' ), 10, 3);
56
  // replace wc email settings
57
  add_filter('woocommerce_email_settings', array($this, 'replace_wc_email_settings'));
58
  add_action('woocommerce_admin_field_ce_manage_button', array($this, 'print_ce_manage_button'));
59
  // add checkbox to checkout if enabled
60
+ if (OptionsHelper::get_checkout_checkbox_enabled() === '1') {
 
61
  add_filter('woocommerce_after_order_notes', array($this, 'add_checkout_field'));
62
  add_action('woocommerce_checkout_update_order_meta', array($this, 'ce_checkout_order_meta'));
63
  }
66
 
67
  public function ce_checkout_order_meta( $order_id )
68
  {
69
+ if ($_POST['ce_checkout_consent_checkbox']) {
 
70
  $checkbox_value = esc_attr($_POST['ce_checkout_consent_checkbox']);
71
+ update_post_meta($order_id, 'ce_checkout_consent', $checkbox_value);
72
  }
73
  }
74
 
75
  public function add_checkout_field( $checkout)
76
  {
77
+ $checked = $checkout->get_value('ce_checkout_consent_checkbox') ? $checkout->get_value('ce_checkout_consent_checkbox') : 1;
78
  $checkbox_text = stripslashes(OptionsHelper::get_checkout_checkbox_text());
79
 
80
+ woocommerce_form_field(
81
+ 'ce_checkout_consent_checkbox', array(
82
+ 'type' => 'checkbox',
83
+ 'class' => array('ce-field form-row-wide'),
84
+ 'label' => $checkbox_text,
85
+ ), $checked
86
+ );
87
  }
88
 
89
  public function replace_wc_email_settings($settings)
90
  {
91
  $default_setting_replacement = array(
92
+ 'woocommerce_email_header_image' => 'header_image',
93
+ 'woocommerce_email_footer_text' => 'footer_content_text',
94
+ 'woocommerce_email_base_color' => null,
95
+ 'woocommerce_email_background_color' => 'background_color',
96
+ 'woocommerce_email_body_background_color' => 'email_background_color',
97
+ 'woocommerce_email_text_color' => 'text_color'
98
+ );
99
 
100
  // Define options that need to be replaced
101
  $replace = array_merge(array_keys($default_setting_replacement), array('email_template_options'));
143
  return OptionsHelper::get_managed_email_notifications();
144
  }
145
 
146
+ public function set_managed_email_notifications($body)
147
+ {
148
+ if (empty($body) || $body === null ) {
149
  return null;
150
  }
151
 
152
+ if (property_exists($body, 'name') ) {
153
  $valid_names = [
154
  'customer_completed_order',
155
  'customer_refunded_order',
160
  'customer_invoice',
161
  'customer_note'
162
  ];
163
+ if (in_array($body->name, $valid_names) ) {
164
+ OptionsHelper::set_managed_email_notification($body->name, $body->active == true ? 'true' : 'false');
165
  return $body;
166
  }
167
  }
178
  *
179
  * @param \WC_Email $email the email
180
  */
181
+ public function render_email_status_column( \WC_Email $email )
182
+ {
183
 
184
  echo '<td class="wc-email-settings-table-status">';
185
 
186
+ if ($this->is_email_managed($email->id) ) {
187
+ echo '<span class="status-creativemail tips" data-tip="' . esc_attr__('Managed by Creative Mail', 'creativ-email-wordpress-plugin') . '">' . esc_html__('Managed by CreativeMail', 'creativ-email-wordpress-plugin') . '</span>';
188
+ } elseif ($email->is_manual() ) {
189
+ echo '<span class="status-manual tips" data-tip="' . esc_attr__('Manually sent', 'woocommerce') . '">' . esc_html__('Manual', 'woocommerce') . '</span>';
190
+ } elseif ($email->is_enabled() ) {
191
+ echo '<span class="status-enabled tips" data-tip="' . esc_attr__('Enabled', 'woocommerce') . '">' . esc_html__('Yes', 'woocommerce') . '</span>';
192
  } else {
193
+ echo '<span class="status-disabled tips" data-tip="' . esc_attr__('Disabled', 'woocommerce') . '">-</span>';
194
  }
195
 
196
  echo '</td>';
197
  }
198
 
199
+ public function customize_email_setting_columns( $columns )
200
+ {
201
 
202
+ $column_keys = array_keys($columns);
203
 
204
  // replace the status column, or put at the beginning if status isn't found
205
+ $status_index = array_search('status', $column_keys, true);
206
+ array_splice($column_keys, is_numeric($status_index) ? $status_index : 0, is_numeric($status_index) ? 1 : 0, 'wc_ce_status');
207
 
208
  $new_columns = array();
209
  $columns['wc_ce_status'] = '';
210
 
211
  foreach ( $column_keys as $column_key )
212
  {
213
+ if (isset($columns[ $column_key ]) ) {
214
  $new_columns[ $column_key ] = $columns[ $column_key ];
215
  }
216
  }
218
  return $new_columns;
219
  }
220
 
221
+ public function ce_email_notification_new_customer_note($array)
222
+ {
223
  $data = new stdClass();
224
  $data->order_id = $array['order_id'];
225
  $data->note = $array['customer_note'];
228
  $this->execute_trigger("customer_note", $data, wc_get_order($data->order_id));
229
  }
230
 
231
+ public function ce_email_notification_customer_new_account($customer_id, $new_customer_data, $password_generated)
232
+ {
233
  $data = new stdClass();
234
  $data->customer_id = $customer_id;
235
  $data->account_url = $this->get_my_account_url();
236
 
237
+ if ($password_generated && key_exists("user_pass", $new_customer_data)) {
 
238
  try {
239
  $generated_password = $new_customer_data['user_pass'];
240
  $key = sha1(OptionsHelper::get_instance_api_key() . OptionsHelper::get_instance_uuid());
258
  $this->execute_trigger("customer_new_account", $data);
259
  }
260
 
261
+ public function ce_email_notification_customer_reset_password($user_login = '', $reset_key = '')
262
+ {
263
+ if ($user_login && $reset_key ) {
264
  $data = new stdClass();
265
+ $user = get_user_by('login', $user_login);
266
  $data->customer_id = $user->ID;
267
  $data->account_url = $this->get_my_account_url();
268
+ $data->reset_url = add_query_arg(
269
+ array(
270
  'key' => $reset_key,
271
  'id' => $data->customer_id
272
+ ), wc_get_endpoint_url('lost-password', '', $data->account_url)
273
+ );
274
 
275
+ $this->execute_trigger("customer_reset_password", $data);
276
  }
277
  }
278
 
279
+ public function ce_email_notification_payment_complete( $order_id )
280
+ {
281
  $data = new stdClass();
282
  $data->order_id = $order_id;
283
  $data->order_url = $this->get_view_order_url($order_id, null);
285
  $this->execute_trigger("payment_received", $data, wc_get_order($order_id));
286
  }
287
 
288
+ public function ce_email_notification_failed($order_id, $order)
289
+ {
290
  $data = new stdClass();
291
  $data->order_id = $order_id;
292
  $data->order_url = $this->get_view_order_url($order_id, $order);
293
 
294
  $this->execute_trigger("failed_order", $data, $order);
295
  }
296
+ public function ce_email_notification_hold($order_id, $order)
297
+ {
298
  $data = new stdClass();
299
  $data->order_id = $order_id;
300
  $data->order_url = $this->get_view_order_url($order_id, $order);
301
 
302
  $this->execute_trigger("customer_on_hold_order", $data, $order);
303
  }
304
+ public function ce_email_notification_processing($order_id, $order)
305
+ {
306
  $data = new stdClass();
307
  $data->order_id = $order_id;
308
  $data->order_url = $this->get_view_order_url($order_id, $order);
309
 
310
  $this->execute_trigger("customer_processing_order", $data, $order);
311
  }
312
+ public function ce_email_notification_completed($order_id, $order)
313
+ {
314
  $data = new stdClass();
315
  $data->order_id = $order_id;
316
  $data->order_url = $this->get_view_order_url($order_id, $order);
317
 
318
  $this->execute_trigger("customer_completed_order", $data, $order);
319
  }
320
+ public function ce_email_notification_refunded($order_id, $order)
321
+ {
322
  $data = new stdClass();
323
  $data->order_id = $order_id;
324
  $data->order_url = $this->get_view_order_url($order_id, $order);
325
 
326
  $this->execute_trigger("customer_refunded_order", $data, $order);
327
  }
328
+ public function ce_email_notification_cancelled($order_id, $order)
329
+ {
330
  $data = new stdClass();
331
  $data->order_id = $order_id;
332
  $data->order_url = $this->get_view_order_url($order_id, $order);
334
  $this->execute_trigger("cancelled_order", $data, $order);
335
  }
336
 
337
+ public function ce_email_notification_new_order($order_id, $order)
338
+ {
339
  $data = new stdClass();
340
  $data->order_id = $order_id;
341
  $data->order_url = $this->get_view_order_url($order_id, $order);
343
  $this->execute_trigger("new_order", $data, $order);
344
  }
345
 
346
+ public function ce_email_notification_invoice($order, $type)
347
+ {
348
+ if ($type === 'new_order' ) {
349
+ $this->ce_email_notification_new_order($order->id, $order);
350
  return;
351
  }
352
 
353
  $data = new stdClass();
354
  $data->order_id = $order->get_id();
355
+ $data->order_url = $this->get_view_order_url($order->get_id(), $order);
356
 
357
+ $this->execute_trigger("customer_invoice", $data, $order);
358
  }
359
 
360
+ public function execute_trigger($type, $data, $order = null)
361
+ {
362
  // if not managed do not trigger
363
  if (!$this->is_email_managed($type)) {
364
  return;
367
  $requestItem = new stdClass();
368
  $requestItem->type = $type;
369
  $endpoint = EnvironmentHelper::get_app_gateway_url('wordpress').'/v1.0/wc/trigger';
370
+ if(!is_null($order)) {
 
371
  try {
372
  $dp = 2; // decimal point
373
  $order_data = array(
454
  $product_data["sale_price"] = $product->get_sale_price();
455
  $product_data["regular_price"] = $product->get_regular_price();
456
 
457
+ if ($product->is_downloadable()) {
 
458
  $item_downloads = $item->get_item_downloads();
459
  foreach ($item_downloads as $item_download)
460
  {
479
  }
480
 
481
  $src = wc_placeholder_img_src();
482
+ if ($image_id = $product->get_image_id() ) {
483
+ list( $src ) = wp_get_attachment_image_src($image_id, 'full');
484
  }
485
 
486
  $order_data['line_items'][] = array(
498
  'product_data' => $product_data,
499
  'sku' => is_object($product) ? $product->get_sku() : null,
500
  'meta' => array_values($item_meta),
501
+ 'product_url' => get_the_permalink($item->get_product_id()),
502
  'variation_id' => $item->get_variation_id()
503
  );
504
  }
555
 
556
  $requestItem->data = wp_json_encode($data);
557
 
558
+ wp_remote_post(
559
+ $endpoint, array(
560
  'method' => 'POST',
561
  'timeout' => 10,
562
  'headers' => array(
565
  'content-type' => 'application/json'
566
  ),
567
  'body' => wp_json_encode($requestItem)
568
+ )
569
+ );
570
  }
571
 
572
  /**
576
  *
577
  * @since 1.1.0
578
  */
579
+ public function manage_emails()
580
+ {
581
 
582
  $this->managed_email_notifications = $this->get_managed_email_notifications();
583
 
584
+ if (empty($this->managed_email_notifications) || ! is_array($this->managed_email_notifications) ) {
585
+ return;
586
  }
587
 
588
  // disable managed emails
589
  foreach ( $this->managed_email_notifications as $notification )
590
  {
591
+ if ($this->is_email_managed($notification->name) ) {
592
+ add_filter("woocommerce_email_enabled_". $notification->name ."", '__return_false');
593
  }
594
  }
595
 
596
+ add_filter('woocommerce_email_title', array( $this, 'override_managed_email_title' ), 10, 2);
597
+ add_filter('woocommerce_email_description', array( $this, 'override_managed_email_description' ), 10, 2);
598
  }
599
 
600
 
605
  *
606
  * @since 1.1.0
607
  *
608
+ * @param string $title the email title
609
+ * @param \WC_Email $email the email object
610
  * @return string
611
  */
612
+ public function override_managed_email_title( $title, $email )
613
+ {
614
 
615
+ if (isset($email->id) && $this->is_email_managed($email->id) ) {
616
 
617
+ $title .= __(' (Managed by Creative Mail)', 'creativ-email-wordpress-plugin');
618
  }
619
 
620
  return $title;
628
  *
629
  * @since 1.1.0
630
  *
631
+ * @param string $description description text
632
+ * @param \WC_Email $email the email object
633
  * @return string
634
  */
635
+ public function override_managed_email_description( $description, $email )
636
+ {
637
 
638
+ if (isset($email->id) && $this->is_email_managed($email->id) ) {
639
 
640
+ $description .= __(' This email is being managed and sent by Creative Mail.', 'creativ-email-wordpress-plugin');
641
  }
642
 
643
  return $description;
650
  *
651
  * @param \WC_Email $email the email object
652
  */
653
+ public function redirect_managed_email_settings_to_creative_mail( $email )
654
+ {
655
 
656
+ if ($this->is_email_managed($email->id)) {
657
+ wp_redirect(admin_url('admin.php?page=creativemail'));
658
  exit;
659
  }
660
  }
664
  *
665
  * @since 1.1.0
666
  *
667
+ * @param string $email_id woocommerce email ID
668
  * @return bool
669
  */
670
+ public function is_email_managed( $email_id )
671
+ {
672
+ return (bool) $this->get_managed_notification_param($email_id, 'active');
673
  }
674
 
675
  /**
677
  *
678
  * @since 1.1.0
679
  *
680
+ * @param string $email_id woocommerce email ID
681
+ * @param string $param param name
682
  * @return mixed|null
683
  */
684
+ public function get_managed_notification_param( $email_id, $param )
685
+ {
686
 
687
  foreach($this->managed_email_notifications as $managed_email_notification) {
688
  if ($email_id == $managed_email_notification->name && property_exists($managed_email_notification, $param)) {
697
  *
698
  * @since 1.1.0
699
  *
700
+ * @param array $items managed email notifications
701
+ * @param string $email_id woocommerce email ID
702
  * @return mixed|null
703
  */
704
+ public function get_managed_notification( $items, $email_id )
705
+ {
706
 
707
  foreach($items as $managed_email_notification) {
708
  if ($email_id == $managed_email_notification->name) {
717
  *
718
  * @since 1.1.0
719
  *
720
+ * @param string $email_id woocommerce email ID
721
  * @return int|null
722
  */
723
+ public function get_transactional_notification_id( $email_id )
724
+ {
725
 
726
+ return $this->get_managed_notification_param($email_id, 'transactional_notification_id');
727
  }
728
 
729
  /**
731
  *
732
  * @since 1.1.0
733
  *
734
+ * @param string $email_id woocommerce email ID
735
  * @return string|null
736
  */
737
+ public function get_managed_notification_state( $email_id )
738
+ {
739
 
740
+ return $this->get_managed_notification_param($email_id, 'state');
741
  }
742
 
743
+ private function get_view_order_url($order_id, $order)
744
+ {
745
  try {
746
  if (!isset($order)) {
747
+ $order = wc_get_order($order_id);
748
  }
749
 
750
+ if (isset($order) && method_exists($order, 'get_view_order_url') ) {
751
  return $order->get_view_order_url();
752
  }
753
  } catch ( \Exception $exception ) {
757
  return null;
758
  }
759
 
760
+ private function get_my_account_url()
761
+ {
762
  try {
763
+ return wc_get_page_permalink('myaccount');
764
  } catch ( \Exception $exception ) {
765
  // silent exception
766
  }
src/managers/instance-manager.php CHANGED
@@ -9,28 +9,32 @@ use WP_Error;
9
 
10
  /**
11
  * Class InstanceManager
 
12
  * @package CreativeMail\Managers
13
  */
14
  class InstanceManager
15
  {
16
- public function __construct() {
 
17
 
18
  }
19
 
20
- public function add_hooks() {
 
21
 
22
  }
23
 
24
  /**
25
  * Handles the callback from the WordPress API and will store all the instance details.
26
- * @param $request
 
27
  * @return bool|WP_Error
28
  */
29
  public function handle_callback($request)
30
  {
31
  $account_information = json_decode($request->get_body());
32
  if ($account_information === null) {
33
- return new WP_Error( 'rest_bad_request', 'Invalid account details', array('status' => 400));
34
  }
35
 
36
  // Store the account information in the settings
9
 
10
  /**
11
  * Class InstanceManager
12
+ *
13
  * @package CreativeMail\Managers
14
  */
15
  class InstanceManager
16
  {
17
+ public function __construct()
18
+ {
19
 
20
  }
21
 
22
+ public function add_hooks()
23
+ {
24
 
25
  }
26
 
27
  /**
28
  * Handles the callback from the WordPress API and will store all the instance details.
29
+ *
30
+ * @param $request
31
  * @return bool|WP_Error
32
  */
33
  public function handle_callback($request)
34
  {
35
  $account_information = json_decode($request->get_body());
36
  if ($account_information === null) {
37
+ return new WP_Error('rest_bad_request', 'Invalid account details', array('status' => 400));
38
  }
39
 
40
  // Store the account information in the settings
src/managers/integration-manager.php CHANGED
@@ -6,6 +6,7 @@ namespace CreativeMail\Managers;
6
  use CreativeMail\Helpers\OptionsHelper;
7
  use CreativeMail\Integrations\Integration;
8
  use CreativeMail\Modules\Contacts\Handlers\ContactFormSevenPluginHandler;
 
9
  use CreativeMail\Modules\Contacts\Handlers\GravityFormsPluginHandler;
10
  use CreativeMail\Modules\Contacts\Handlers\NewsLetterContactFormPluginHandler;
11
  use CreativeMail\Modules\Contacts\Handlers\WooCommercePluginHandler;
@@ -34,12 +35,13 @@ class IntegrationManager
34
  $this->supported_integrations = array(
35
  new Integration('jetpack', 'Jetpack Forms', 'jetpack/jetpack.php', JetpackPluginHandler::class, false),
36
  new Integration('jetpack-beta', 'Jetpack Forms (Beta)', 'jetpack-beta-master/jetpack-beta.php', JetpackPluginHandler::class, true),
37
- new Integration('woocommerce','WooCommerce', 'woocommerce/woocommerce.php', WooCommercePluginHandler::class, false),
38
  new Integration('contact-form-7', 'Contact Form 7', 'contact-form-7/wp-contact-form-7.php', ContactFormSevenPluginHandler::class, false),
39
- new Integration('newsletter','Newsletter', 'newsletter/plugin.php', NewsLetterContactFormPluginHandler::class, false),
40
  new Integration('wpforms', 'WPForms', 'wpforms/wpforms.php', WpFormsPluginHandler::class, false),
41
  new Integration('wpformslite', 'WPForms Lite', 'wpforms-lite/wpforms.php', WpFormsPluginHandler::class, true),
42
- new Integration('gravityforms', 'GravityForms', 'gravityforms/gravityforms.php', GravityFormsPluginHandler::class, false)
 
43
  );
44
  }
45
 
@@ -48,16 +50,17 @@ class IntegrationManager
48
  */
49
  public function add_hooks()
50
  {
51
- $active_plugins = array_filter($this->get_active_plugins(), function($item) {
52
- return array_search($item->get_slug(), $this->get_activated_plugins(), true) !== false;
53
- });
 
 
54
 
55
  foreach ($active_plugins as $active_plugin)
56
  {
57
  try
58
  {
59
- if (array_key_exists($active_plugin->get_slug(), $this->active_integrations) === false)
60
- {
61
  // use reflection to create instance of class
62
  $class = new ReflectionClass($active_plugin->get_integration_handler());
63
  $this->active_integrations[$active_plugin->get_slug()] = $class->newInstance();
@@ -65,7 +68,7 @@ class IntegrationManager
65
  // register hooks for integration class
66
  $this->active_integrations[$active_plugin->get_slug()]->registerHooks();
67
  } catch (\Exception $e) {
68
- // silent
69
  }
70
  }
71
  }
@@ -82,6 +85,7 @@ class IntegrationManager
82
 
83
  /**
84
  * Will get all the supported plugins that are installed and active on this WP instance.
 
85
  * @return array
86
  */
87
  public function get_active_plugins()
@@ -92,8 +96,7 @@ class IntegrationManager
92
  foreach ($this->supported_integrations as $integration) {
93
 
94
  // Check if the plugin is activated
95
- if (in_array($integration->get_class(), apply_filters('active_plugins', get_option('active_plugins'))))
96
- {
97
  array_push($activated_plugins, $integration);
98
  }
99
  }
@@ -101,12 +104,14 @@ class IntegrationManager
101
  return $activated_plugins;
102
  }
103
 
104
- public function is_plugin_active($slug) {
 
105
  return array_key_exists($slug, $this->active_integrations);
106
  }
107
 
108
  /**
109
  * Stores the plugins that were activated by the user.
 
110
  * @param $plugins
111
  */
112
  public function set_activated_plugins($plugins)
@@ -124,41 +129,47 @@ class IntegrationManager
124
 
125
  /**
126
  * Gets a list of slugs representing the plugins that were activated by the user.
 
127
  * @return array
128
  */
129
  public function get_activated_plugins()
130
  {
131
  $activated_plugins = OptionsHelper::get_activated_plugins();
132
  if (is_null($activated_plugins)) {
133
- $activated_plugins = '';
134
  }
135
  if (is_array($activated_plugins)) {
136
- $activated_plugins = implode(';', $activated_plugins);
137
  }
138
  return explode(';', $activated_plugins);
139
  }
140
 
141
  /**
142
  * Will return a list of the activated integrations.
 
143
  * @return array
144
  */
145
  public function get_activated_integrations()
146
  {
147
- return array_filter($this->get_active_plugins(), function($item) {
148
- return array_search($item->get_slug(), $this->get_activated_plugins(), true) !== false;
149
- });
 
 
150
  }
151
 
152
- /**
153
- * Will return a list of all the integrations that we support.
154
- * @return array A list of all the supported integrations.
155
- */
 
156
  public function get_supported_integrations()
157
  {
158
- return $this->supported_integrations;
159
  }
160
 
161
- public function get_permalinks_enabled() {
162
- return get_option( 'permalink_structure' ) !== '';
 
163
  }
164
  }
6
  use CreativeMail\Helpers\OptionsHelper;
7
  use CreativeMail\Integrations\Integration;
8
  use CreativeMail\Modules\Contacts\Handlers\ContactFormSevenPluginHandler;
9
+ use CreativeMail\Modules\Contacts\Handlers\ElementorPluginHandler;
10
  use CreativeMail\Modules\Contacts\Handlers\GravityFormsPluginHandler;
11
  use CreativeMail\Modules\Contacts\Handlers\NewsLetterContactFormPluginHandler;
12
  use CreativeMail\Modules\Contacts\Handlers\WooCommercePluginHandler;
35
  $this->supported_integrations = array(
36
  new Integration('jetpack', 'Jetpack Forms', 'jetpack/jetpack.php', JetpackPluginHandler::class, false),
37
  new Integration('jetpack-beta', 'Jetpack Forms (Beta)', 'jetpack-beta-master/jetpack-beta.php', JetpackPluginHandler::class, true),
38
+ new Integration('woocommerce', 'WooCommerce', 'woocommerce/woocommerce.php', WooCommercePluginHandler::class, false),
39
  new Integration('contact-form-7', 'Contact Form 7', 'contact-form-7/wp-contact-form-7.php', ContactFormSevenPluginHandler::class, false),
40
+ new Integration('newsletter', 'Newsletter', 'newsletter/plugin.php', NewsLetterContactFormPluginHandler::class, false),
41
  new Integration('wpforms', 'WPForms', 'wpforms/wpforms.php', WpFormsPluginHandler::class, false),
42
  new Integration('wpformslite', 'WPForms Lite', 'wpforms-lite/wpforms.php', WpFormsPluginHandler::class, true),
43
+ new Integration('gravityforms', 'GravityForms', 'gravityforms/gravityforms.php', GravityFormsPluginHandler::class, false),
44
+ new Integration('elementor', 'Elementor', 'elementor/elementor.php', ElementorPluginHandler::class, false)
45
  );
46
  }
47
 
50
  */
51
  public function add_hooks()
52
  {
53
+ $active_plugins = array_filter(
54
+ $this->get_active_plugins(), function ($item) {
55
+ return array_search($item->get_slug(), $this->get_activated_plugins(), true) !== false;
56
+ }
57
+ );
58
 
59
  foreach ($active_plugins as $active_plugin)
60
  {
61
  try
62
  {
63
+ if (array_key_exists($active_plugin->get_slug(), $this->active_integrations) === false) {
 
64
  // use reflection to create instance of class
65
  $class = new ReflectionClass($active_plugin->get_integration_handler());
66
  $this->active_integrations[$active_plugin->get_slug()] = $class->newInstance();
68
  // register hooks for integration class
69
  $this->active_integrations[$active_plugin->get_slug()]->registerHooks();
70
  } catch (\Exception $e) {
71
+ // silent
72
  }
73
  }
74
  }
85
 
86
  /**
87
  * Will get all the supported plugins that are installed and active on this WP instance.
88
+ *
89
  * @return array
90
  */
91
  public function get_active_plugins()
96
  foreach ($this->supported_integrations as $integration) {
97
 
98
  // Check if the plugin is activated
99
+ if (in_array($integration->get_class(), apply_filters('active_plugins', get_option('active_plugins')))) {
 
100
  array_push($activated_plugins, $integration);
101
  }
102
  }
104
  return $activated_plugins;
105
  }
106
 
107
+ public function is_plugin_active($slug)
108
+ {
109
  return array_key_exists($slug, $this->active_integrations);
110
  }
111
 
112
  /**
113
  * Stores the plugins that were activated by the user.
114
+ *
115
  * @param $plugins
116
  */
117
  public function set_activated_plugins($plugins)
129
 
130
  /**
131
  * Gets a list of slugs representing the plugins that were activated by the user.
132
+ *
133
  * @return array
134
  */
135
  public function get_activated_plugins()
136
  {
137
  $activated_plugins = OptionsHelper::get_activated_plugins();
138
  if (is_null($activated_plugins)) {
139
+ $activated_plugins = '';
140
  }
141
  if (is_array($activated_plugins)) {
142
+ $activated_plugins = implode(';', $activated_plugins);
143
  }
144
  return explode(';', $activated_plugins);
145
  }
146
 
147
  /**
148
  * Will return a list of the activated integrations.
149
+ *
150
  * @return array
151
  */
152
  public function get_activated_integrations()
153
  {
154
+ return array_filter(
155
+ $this->get_active_plugins(), function ($item) {
156
+ return array_search($item->get_slug(), $this->get_activated_plugins(), true) !== false;
157
+ }
158
+ );
159
  }
160
 
161
+ /**
162
+ * Will return a list of all the integrations that we support.
163
+ *
164
+ * @return array A list of all the supported integrations.
165
+ */
166
  public function get_supported_integrations()
167
  {
168
+ return $this->supported_integrations;
169
  }
170
 
171
+ public function get_permalinks_enabled()
172
+ {
173
+ return get_option('permalink_structure') !== '';
174
  }
175
  }
src/modules/api/Models/ApiRequestItem.php CHANGED
@@ -15,7 +15,8 @@ class ApiRequestItem
15
  public $apiKey;
16
  public $accountId;
17
 
18
- function __construct($httpMethod, $contentType, $endpoint, $payload) {
 
19
 
20
  $apiKey = OptionsHelper::get_instance_api_key();
21
  $accountId = OptionsHelper::get_connected_account_id();
15
  public $apiKey;
16
  public $accountId;
17
 
18
+ function __construct($httpMethod, $contentType, $endpoint, $payload)
19
+ {
20
 
21
  $apiKey = OptionsHelper::get_instance_api_key();
22
  $accountId = OptionsHelper::get_connected_account_id();
src/modules/api/Processes/ApiBackgroundProcess.php CHANGED
@@ -5,7 +5,8 @@ namespace CreativeMail\Modules\Api\Processes;
5
  use CreativeMail\Modules\Api\Models\ApiRequestItem;
6
  use WP_Background_Process;
7
 
8
- class ApiBackgroundProcess extends WP_Background_Process {
 
9
 
10
  protected $action = 'ce_api_background_process';
11
 
@@ -21,7 +22,8 @@ class ApiBackgroundProcess extends WP_Background_Process {
21
  *
22
  * @return mixed
23
  */
24
- protected function task( $item ) {
 
25
  if (!isset($item->httpMethod) || empty($item->httpMethod)) {
26
  return false;
27
  }
@@ -33,7 +35,8 @@ class ApiBackgroundProcess extends WP_Background_Process {
33
  $httpMethod = strtoupper($item->httpMethod);
34
 
35
  if ($httpMethod === 'POST') {
36
- wp_remote_post($item->endpoint, array(
 
37
  'method' => $httpMethod,
38
  'headers' => array(
39
  'x-account-id' => $item->accountId,
@@ -41,18 +44,21 @@ class ApiBackgroundProcess extends WP_Background_Process {
41
  'content-type' => $item->contentType
42
  ),
43
  'body' => $item->payload
44
- ));
 
45
  return false;
46
  }
47
 
48
- wp_remote_get($item->endpoint, array(
 
49
  'method' => $httpMethod,
50
  'headers' => array(
51
  'x-account-id' => $item->accountId,
52
  'x-api-key' => $item->apiKey,
53
  'content-type' => $item->contentType
54
  )
55
- ));
 
56
  return false;
57
  }
58
 
@@ -62,7 +68,8 @@ class ApiBackgroundProcess extends WP_Background_Process {
62
  * Override if applicable, but ensure that the below actions are
63
  * performed, or, call parent::complete().
64
  */
65
- protected function complete() {
 
66
  parent::complete();
67
  }
68
  }
5
  use CreativeMail\Modules\Api\Models\ApiRequestItem;
6
  use WP_Background_Process;
7
 
8
+ class ApiBackgroundProcess extends WP_Background_Process
9
+ {
10
 
11
  protected $action = 'ce_api_background_process';
12
 
22
  *
23
  * @return mixed
24
  */
25
+ protected function task( $item )
26
+ {
27
  if (!isset($item->httpMethod) || empty($item->httpMethod)) {
28
  return false;
29
  }
35
  $httpMethod = strtoupper($item->httpMethod);
36
 
37
  if ($httpMethod === 'POST') {
38
+ wp_remote_post(
39
+ $item->endpoint, array(
40
  'method' => $httpMethod,
41
  'headers' => array(
42
  'x-account-id' => $item->accountId,
44
  'content-type' => $item->contentType
45
  ),
46
  'body' => $item->payload
47
+ )
48
+ );
49
  return false;
50
  }
51
 
52
+ wp_remote_get(
53
+ $item->endpoint, array(
54
  'method' => $httpMethod,
55
  'headers' => array(
56
  'x-account-id' => $item->accountId,
57
  'x-api-key' => $item->apiKey,
58
  'content-type' => $item->contentType
59
  )
60
+ )
61
+ );
62
  return false;
63
  }
64
 
68
  * Override if applicable, but ensure that the below actions are
69
  * performed, or, call parent::complete().
70
  */
71
+ protected function complete()
72
+ {
73
  parent::complete();
74
  }
75
  }
src/modules/blog/models/BlogAttachment.php CHANGED
@@ -2,26 +2,27 @@
2
 
3
  namespace CreativeMail\Modules\Blog\Models;
4
 
5
- class BlogAttachment {
6
- public $id;
7
- public $date;
8
- public $name;
9
- public $modified;
10
- public $url;
11
- public $thumbnail;
 
12
 
13
- function __construct($wp_attachment) {
14
- $this->id = $wp_attachment->ID;
15
- $this->name = $wp_attachment->post_title;
16
- $this->date = $wp_attachment->post_date;
17
- $this->modified = $wp_attachment->post_modified;
18
- $this->url = wp_get_attachment_url($wp_attachment->ID);
19
- $this->thumbnail = wp_get_attachment_image_url($wp_attachment->ID, 'medium_large');
20
- $this->meta_data = wp_get_attachment_metadata($wp_attachment->ID);
21
- // in case false on failure
22
- if ($this->meta_data === false)
23
  {
24
- $this->meta_data = array();
 
 
 
 
 
 
 
 
 
 
25
  }
26
- }
27
  }
2
 
3
  namespace CreativeMail\Modules\Blog\Models;
4
 
5
+ class BlogAttachment
6
+ {
7
+ public $id;
8
+ public $date;
9
+ public $name;
10
+ public $modified;
11
+ public $url;
12
+ public $thumbnail;
13
 
14
+ function __construct($wp_attachment)
 
 
 
 
 
 
 
 
 
15
  {
16
+ $this->id = $wp_attachment->ID;
17
+ $this->name = $wp_attachment->post_title;
18
+ $this->date = $wp_attachment->post_date;
19
+ $this->modified = $wp_attachment->post_modified;
20
+ $this->url = wp_get_attachment_url($wp_attachment->ID);
21
+ $this->thumbnail = wp_get_attachment_image_url($wp_attachment->ID, 'medium_large');
22
+ $this->meta_data = wp_get_attachment_metadata($wp_attachment->ID);
23
+ // in case false on failure
24
+ if ($this->meta_data === false) {
25
+ $this->meta_data = array();
26
+ }
27
  }
 
28
  }
src/modules/blog/models/BlogInformation.php CHANGED
@@ -4,7 +4,8 @@ namespace CreativeMail\Modules\Blog\Models;
4
 
5
  use CreativeMail\Modules\WooCommerce\Models\WCStoreInformation;
6
 
7
- class BlogInformation {
 
8
  public $title;
9
  public $description;
10
  public $url;
@@ -21,7 +22,8 @@ class BlogInformation {
21
 
22
  public $woocommerce;
23
 
24
- function __construct() {
 
25
  $this->plugin_version = CE4WP_PLUGIN_VERSION;
26
  $this->title = get_bloginfo('name');
27
  $this->description = get_bloginfo('description');
4
 
5
  use CreativeMail\Modules\WooCommerce\Models\WCStoreInformation;
6
 
7
+ class BlogInformation
8
+ {
9
  public $title;
10
  public $description;
11
  public $url;
22
 
23
  public $woocommerce;
24
 
25
+ function __construct()
26
+ {
27
  $this->plugin_version = CE4WP_PLUGIN_VERSION;
28
  $this->title = get_bloginfo('name');
29
  $this->description = get_bloginfo('description');
src/modules/blog/models/BlogPost.php CHANGED
@@ -2,7 +2,8 @@
2
 
3
  namespace CreativeMail\Modules\Blog\Models;
4
 
5
- class BlogPost {
 
6
  public $id;
7
  public $author;
8
  public $date;
@@ -21,21 +22,22 @@ class BlogPost {
21
  public $url;
22
  public $thumbnail;
23
 
24
- function __construct($wp_post) {
25
- $this->id = $wp_post->ID;
26
- $this->author = $wp_post->post_author;
27
- $this->date = $wp_post->post_date;
28
- $this->modified = $wp_post->post_modified;
29
- $this->content = apply_filters("the_content", $wp_post->post_content);
30
- $this->title = apply_filters("the_title", $wp_post->post_title);
31
- $this->excerpt = $wp_post->post_excerpt;
32
- $this->status = $wp_post->post_status;
33
- $this->parent_id = $wp_post->post_parent;
34
- $this->menu_order = $wp_post->menu_order;
35
- $this->comment_count = $wp_post->comment_count;
36
- $this->url = get_permalink($wp_post->ID);
37
- if (has_post_thumbnail($wp_post->ID)) {
38
- $this->thumbnail = get_the_post_thumbnail_url($wp_post->ID);
39
- }
 
40
  }
41
  }
2
 
3
  namespace CreativeMail\Modules\Blog\Models;
4
 
5
+ class BlogPost
6
+ {
7
  public $id;
8
  public $author;
9
  public $date;
22
  public $url;
23
  public $thumbnail;
24
 
25
+ function __construct($wp_post)
26
+ {
27
+ $this->id = $wp_post->ID;
28
+ $this->author = $wp_post->post_author;
29
+ $this->date = $wp_post->post_date;
30
+ $this->modified = $wp_post->post_modified;
31
+ $this->content = apply_filters("the_content", $wp_post->post_content);
32
+ $this->title = apply_filters("the_title", $wp_post->post_title);
33
+ $this->excerpt = $wp_post->post_excerpt;
34
+ $this->status = $wp_post->post_status;
35
+ $this->parent_id = $wp_post->post_parent;
36
+ $this->menu_order = $wp_post->menu_order;
37
+ $this->comment_count = $wp_post->comment_count;
38
+ $this->url = get_permalink($wp_post->ID);
39
+ if (has_post_thumbnail($wp_post->ID)) {
40
+ $this->thumbnail = get_the_post_thumbnail_url($wp_post->ID);
41
+ }
42
  }
43
  }
src/modules/contacts/Handlers/BaseContactFormPluginHandler.php CHANGED
@@ -14,7 +14,8 @@ abstract class BaseContactFormPluginHandler
14
  public abstract function unregisterHooks();
15
  public abstract function syncAction($limit = null);
16
 
17
- public function upsertContact($model) {
 
18
 
19
  if (!isset($model)) {
20
  throw new Exception('No model provided');
@@ -31,7 +32,8 @@ abstract class BaseContactFormPluginHandler
31
  $this->contactSyncService->upsertContact($contactModel);
32
  }
33
 
34
- public function batchUpsertContacts($models) {
 
35
  if (!isset($models)) {
36
  throw new Exception('No models provided');
37
  }
@@ -39,7 +41,8 @@ abstract class BaseContactFormPluginHandler
39
  $this->contactSyncService->upsertContacts($models);
40
  }
41
 
42
- protected function isNotNullOrEmpty($value) {
 
43
  return isset($value) && !empty($value);
44
  }
45
 
14
  public abstract function unregisterHooks();
15
  public abstract function syncAction($limit = null);
16
 
17
+ public function upsertContact($model)
18
+ {
19
 
20
  if (!isset($model)) {
21
  throw new Exception('No model provided');
32
  $this->contactSyncService->upsertContact($contactModel);
33
  }
34
 
35
+ public function batchUpsertContacts($models)
36
+ {
37
  if (!isset($models)) {
38
  throw new Exception('No models provided');
39
  }
41
  $this->contactSyncService->upsertContacts($models);
42
  }
43
 
44
+ protected function isNotNullOrEmpty($value)
45
+ {
46
  return isset($value) && !empty($value);
47
  }
48
 
src/modules/contacts/Handlers/ContactFormSevenPluginHandler.php CHANGED
@@ -8,13 +8,15 @@ use CreativeMail\Modules\Contacts\Models\ContactFormSevenSubmission;
8
  use CreativeMail\Modules\Contacts\Models\ContactModel;
9
  use CreativeMail\Modules\Contacts\Models\OptActionBy;
10
 
11
- class ContactFormSevenPluginHandler extends BaseContactFormPluginHandler {
 
12
 
13
  private $emailFields = array('your-email','email', 'emailaddress', 'email_address');
14
  private $firstnameFields = array('firstname', 'first_name','name','your-name');
15
  private $lastnameFields = array('lastname', 'last_name');
16
 
17
- private function findValue($data, $fieldOptions) {
 
18
  foreach ($fieldOptions as $fieldOption) {
19
  $value = $data->get_posted_data($fieldOption);
20
  if (isset($value) && !empty($value)) {
@@ -25,21 +27,22 @@ class ContactFormSevenPluginHandler extends BaseContactFormPluginHandler {
25
  return null;
26
  }
27
 
28
- private function findValueFromDb($formData, $fieldOptions) {
 
29
  foreach ($fieldOptions as $fieldOption) {
30
- if (array_key_exists($fieldOption, $formData)) {
31
- $value = $formData[$fieldOption];
32
- if ($this->isNotNullOrEmpty($value)) {
33
- return $value;
 
34
  }
35
- }
36
  }
37
  return null;
38
  }
39
 
40
  public function convertToContactModel($contactForm)
41
  {
42
- $contactForm = ContactFormSevenSubmission::get_instance( null, array('skip_mail' => true));
43
 
44
  // convert
45
  $contactModel = new ContactModel();
@@ -88,7 +91,7 @@ class ContactFormSevenPluginHandler extends BaseContactFormPluginHandler {
88
  if (in_array('contact-form-cfdb7/contact-form-cfdb-7.php', apply_filters('active_plugins', get_option('active_plugins')))) {
89
  global $wpdb;
90
 
91
- $cfdb = apply_filters( 'cfdb7_database', $wpdb );
92
  $cfdbtable = $cfdb->prefix.'db7_forms';
93
  $cfdbQuery = "SELECT form_id, form_post_id, form_value FROM $cfdbtable";
94
 
@@ -106,28 +109,28 @@ class ContactFormSevenPluginHandler extends BaseContactFormPluginHandler {
106
  $contactsArray = array();
107
 
108
  foreach ($results as $formSubmission) {
109
- $form_data = unserialize($formSubmission->form_value);
110
- $contactModel = new ContactModel();
111
- $contactModel->setOptIn(true);
112
- $contactModel->setOptOut(false);
113
- $contactModel->setOptActionBy(OptActionBy::Visitor);
114
- $email = $this->findValueFromDb($form_data, $this->emailFields);
115
- if ($this->isNotNullOrEmpty($email)) {
116
- $contactModel->setEmail($email);
117
- }
118
- $firstname = $this->findValueFromDb($form_data, $this->firstnameFields);
119
- if ($this->isNotNullOrEmpty($firstname)) {
120
- $contactModel->setFirstName($firstname);
121
- }
122
- $lastname = $this->findValueFromDb($form_data, $this->lastnameFields);
123
- if ($this->isNotNullOrEmpty($lastname)) {
124
- $contactModel->setLastName($lastname);
125
- }
126
-
127
- if ($this->isNotNullOrEmpty($contactModel->getEmail())){
128
- $contactModel->setEventType(CE4WP_CF7_EventType);
129
- array_push($contactsArray, $contactModel);
130
- }
131
  }
132
 
133
  if (!empty($contactsArray)) {
@@ -142,12 +145,12 @@ class ContactFormSevenPluginHandler extends BaseContactFormPluginHandler {
142
 
143
  function ceHandleContactFormSevenSubmit($contact_form)
144
  {
145
- try {
146
- $this->upsertContact($this->convertToContactModel($contact_form));
147
- }
148
- catch (\Exception $exception) {
149
- // silent exception
150
- }
151
  }
152
 
153
  function __construct()
8
  use CreativeMail\Modules\Contacts\Models\ContactModel;
9
  use CreativeMail\Modules\Contacts\Models\OptActionBy;
10
 
11
+ class ContactFormSevenPluginHandler extends BaseContactFormPluginHandler
12
+ {
13
 
14
  private $emailFields = array('your-email','email', 'emailaddress', 'email_address');
15
  private $firstnameFields = array('firstname', 'first_name','name','your-name');
16
  private $lastnameFields = array('lastname', 'last_name');
17
 
18
+ private function findValue($data, $fieldOptions)
19
+ {
20
  foreach ($fieldOptions as $fieldOption) {
21
  $value = $data->get_posted_data($fieldOption);
22
  if (isset($value) && !empty($value)) {
27
  return null;
28
  }
29
 
30
+ private function findValueFromDb($formData, $fieldOptions)
31
+ {
32
  foreach ($fieldOptions as $fieldOption) {
33
+ if (array_key_exists($fieldOption, $formData)) {
34
+ $value = $formData[$fieldOption];
35
+ if ($this->isNotNullOrEmpty($value)) {
36
+ return $value;
37
+ }
38
  }
 
39
  }
40
  return null;
41
  }
42
 
43
  public function convertToContactModel($contactForm)
44
  {
45
+ $contactForm = ContactFormSevenSubmission::get_instance(null, array('skip_mail' => true));
46
 
47
  // convert
48
  $contactModel = new ContactModel();
91
  if (in_array('contact-form-cfdb7/contact-form-cfdb-7.php', apply_filters('active_plugins', get_option('active_plugins')))) {
92
  global $wpdb;
93
 
94
+ $cfdb = apply_filters('cfdb7_database', $wpdb);
95
  $cfdbtable = $cfdb->prefix.'db7_forms';
96
  $cfdbQuery = "SELECT form_id, form_post_id, form_value FROM $cfdbtable";
97
 
109
  $contactsArray = array();
110
 
111
  foreach ($results as $formSubmission) {
112
+ $form_data = unserialize($formSubmission->form_value);
113
+ $contactModel = new ContactModel();
114
+ $contactModel->setOptIn(true);
115
+ $contactModel->setOptOut(false);
116
+ $contactModel->setOptActionBy(OptActionBy::Visitor);
117
+ $email = $this->findValueFromDb($form_data, $this->emailFields);
118
+ if ($this->isNotNullOrEmpty($email)) {
119
+ $contactModel->setEmail($email);
120
+ }
121
+ $firstname = $this->findValueFromDb($form_data, $this->firstnameFields);
122
+ if ($this->isNotNullOrEmpty($firstname)) {
123
+ $contactModel->setFirstName($firstname);
124
+ }
125
+ $lastname = $this->findValueFromDb($form_data, $this->lastnameFields);
126
+ if ($this->isNotNullOrEmpty($lastname)) {
127
+ $contactModel->setLastName($lastname);
128
+ }
129
+
130
+ if ($this->isNotNullOrEmpty($contactModel->getEmail())) {
131
+ $contactModel->setEventType(CE4WP_CF7_EventType);
132
+ array_push($contactsArray, $contactModel);
133
+ }
134
  }
135
 
136
  if (!empty($contactsArray)) {
145
 
146
  function ceHandleContactFormSevenSubmit($contact_form)
147
  {
148
+ try {
149
+ $this->upsertContact($this->convertToContactModel($contact_form));
150
+ }
151
+ catch (\Exception $exception) {
152
+ // silent exception
153
+ }
154
  }
155
 
156
  function __construct()
src/modules/contacts/Handlers/ElementorPluginHandler.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace CreativeMail\Modules\Contacts\Handlers;
4
+
5
+ define('CE4WP_EL_EventType', 'WordPress - Elementor');
6
+
7
+ use CreativeMail\Modules\Contacts\Models\ContactModel;
8
+ use CreativeMail\Modules\Contacts\Models\OptActionBy;
9
+
10
+ class ElementorPluginHandler extends BaseContactFormPluginHandler
11
+ {
12
+ function __construct()
13
+ {
14
+ parent::__construct();
15
+ }
16
+
17
+ private function GetNameFromForm($fields)
18
+ {
19
+ foreach ($fields as $field) {
20
+ //Try to find a name value based on the default Elementor form with name field
21
+ if(array_key_exists('type', $field) && ($field['type'] === "text" && $field['id'] === "name")) {
22
+ return $field["value"];
23
+ }
24
+ }
25
+ return null;
26
+ }
27
+
28
+ private function GetEmailFromForm($fields)
29
+ {
30
+ foreach ($fields as $field) {
31
+ if(array_key_exists('type', $field) && $field['type'] === "email") {
32
+ return $field["value"];
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+
38
+ public function convertToContactModel($contact)
39
+ {
40
+ $contactModel = new ContactModel();
41
+
42
+ $contactModel->setEventType(CE4WP_EL_EventType);
43
+
44
+ $contactModel->setOptIn(true);
45
+ $contactModel->setOptOut(false);
46
+ $contactModel->setOptActionBy(OptActionBy::Visitor);
47
+
48
+ $email = $contact->email;
49
+ if ($this->isNotNullOrEmpty($email)) {
50
+ $contactModel->setEmail($email);
51
+ }
52
+
53
+ $values = explode(' ', $contact->name);
54
+ $firstName = array_shift($values);
55
+ $lastName = implode(' ', $values);
56
+
57
+ if ($this->isNotNullOrEmpty($firstName)) {
58
+ $contactModel->setFirstName($firstName);
59
+ }
60
+ if ($this->isNotNullOrEmpty($lastName)) {
61
+ $contactModel->setLastName($lastName);
62
+ }
63
+
64
+ return $contactModel;
65
+ }
66
+
67
+ public function ceHandleElementorFormSubmission($settings, $record)
68
+ {
69
+ try {
70
+ $fields = $record->get("fields");
71
+ $elemContact = new \stdClass();
72
+ $elemContact->name = $this->GetNameFromForm($fields);
73
+ $elemContact->email = $this->GetEmailFromForm($fields);
74
+ if (empty($elemContact->email)) {
75
+ return;
76
+ };
77
+ $this->upsertContact($this->convertToContactModel($elemContact));
78
+ } catch (\Exception $exception) {
79
+ // silent exception
80
+ }
81
+ }
82
+
83
+ public function registerHooks()
84
+ {
85
+ add_action('elementor_pro/forms/mail_sent', array($this, 'ceHandleElementorFormSubmission'), 10, 2);
86
+ // add hook function to synchronize
87
+ add_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
88
+ }
89
+
90
+ public function unregisterHooks()
91
+ {
92
+ remove_action('elementor_pro/forms/mail_sent', array($this, 'ceHandleJetpackFormSubmission'));
93
+ // remove hook function to synchronize
94
+ remove_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
95
+ }
96
+
97
+ public function syncAction($limit = null)
98
+ {
99
+ //Elementor seems to not store form submissions locally
100
+ }
101
+ }
src/modules/contacts/Handlers/GravityFormsPluginHandler.php CHANGED
@@ -47,8 +47,8 @@ class GravityFormsPluginHandler extends BaseContactFormPluginHandler
47
  //Gets the first name, optional insertion and last name from the contactform
48
  //Returns the concatenated name
49
  /**
50
- * @param $entry (The form submission)
51
- * @param $form (The form used)
52
  * @return string (concatenated firstname, insertion and lastname)
53
  */
54
  private function GetNameValuesFromForm($entry, $form)
@@ -69,8 +69,8 @@ class GravityFormsPluginHandler extends BaseContactFormPluginHandler
69
  //otherwise searches text fields for email labels and values
70
  //Returns the value of the email field or the first valid email found in an "email" labelled text field, or NULL
71
  /**
72
- * @param $entry (The form submission)
73
- * @param $form (The form used)
74
  * @return string (either a validated email or NULL)
75
  */
76
  private function GetEmailFromForm($entry, $form)
47
  //Gets the first name, optional insertion and last name from the contactform
48
  //Returns the concatenated name
49
  /**
50
+ * @param $entry (The form submission)
51
+ * @param $form (The form used)
52
  * @return string (concatenated firstname, insertion and lastname)
53
  */
54
  private function GetNameValuesFromForm($entry, $form)
69
  //otherwise searches text fields for email labels and values
70
  //Returns the value of the email field or the first valid email found in an "email" labelled text field, or NULL
71
  /**
72
+ * @param $entry (The form submission)
73
+ * @param $form (The form used)
74
  * @return string (either a validated email or NULL)
75
  */
76
  private function GetEmailFromForm($entry, $form)
src/modules/contacts/Handlers/JetpackPluginHandler.php CHANGED
@@ -100,8 +100,9 @@ class JetpackPluginHandler extends BaseContactFormPluginHandler
100
  }
101
 
102
  // Relies on plugin => Jetpack or Jetpack beta
103
- if (in_array('jetpack/jetpack.php', apply_filters('active_plugins', get_option('active_plugins'))) ||
104
- in_array('jetpack-beta-master/jetpack-beta.php', apply_filters('active_plugins', get_option('active_plugins')))) {
 
105
  $authorRegex = '/(?:^AUTHOR: )(.*)/mi';
106
  $authorMailRegex = '/(?:^AUTHOR EMAIL: )(.*)/mi';
107
  $consentRegex = '/(?:\[email_marketing_consent] =&gt; )(.*)/mi';
100
  }
101
 
102
  // Relies on plugin => Jetpack or Jetpack beta
103
+ if (in_array('jetpack/jetpack.php', apply_filters('active_plugins', get_option('active_plugins')))
104
+ || in_array('jetpack-beta-master/jetpack-beta.php', apply_filters('active_plugins', get_option('active_plugins')))
105
+ ) {
106
  $authorRegex = '/(?:^AUTHOR: )(.*)/mi';
107
  $authorMailRegex = '/(?:^AUTHOR EMAIL: )(.*)/mi';
108
  $consentRegex = '/(?:\[email_marketing_consent] =&gt; )(.*)/mi';
src/modules/contacts/Handlers/NewsLetterContactFormPluginHandler.php CHANGED
@@ -19,41 +19,42 @@ class NewsLetterContactFormPluginHandler extends BaseContactFormPluginHandler
19
 
20
  $email = $user->email;
21
  if ($this->isNotNullOrEmpty($email)) {
22
- $contactModel->setEmail($email);
23
  }
24
 
25
  $name = $user->name;
26
  if ($this->isNotNullOrEmpty($name)) {
27
- $contactModel->setFirstName($name);
28
  }
29
 
30
  $surname = $user->surname;
31
  if ($this->isNotNullOrEmpty($surname)) {
32
- $contactModel->setLastName($surname);
33
  }
34
 
35
  return $contactModel;
36
  }
37
 
38
- public function ceHandleContactNewsletterSubmit($user) {
39
- try {
40
- $this->upsertContact($this->convertToContactModel($user));
41
- }
42
- catch (\Exception $exception) {
43
- // silent exception
44
- }
 
45
  }
46
 
47
  public function registerHooks()
48
  {
49
- add_action( 'newsletter_user_confirmed', array($this, 'ceHandleContactNewsletterSubmit'));
50
  // add hook function to synchronize
51
  add_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
52
  }
53
 
54
  public function unregisterHooks()
55
  {
56
- remove_action( 'newsletter_user_confirmed', array($this, 'ceHandleContactNewsletterSubmit'));
57
  // remove hook function to synchronize
58
  remove_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
59
  }
19
 
20
  $email = $user->email;
21
  if ($this->isNotNullOrEmpty($email)) {
22
+ $contactModel->setEmail($email);
23
  }
24
 
25
  $name = $user->name;
26
  if ($this->isNotNullOrEmpty($name)) {
27
+ $contactModel->setFirstName($name);
28
  }
29
 
30
  $surname = $user->surname;
31
  if ($this->isNotNullOrEmpty($surname)) {
32
+ $contactModel->setLastName($surname);
33
  }
34
 
35
  return $contactModel;
36
  }
37
 
38
+ public function ceHandleContactNewsletterSubmit($user)
39
+ {
40
+ try {
41
+ $this->upsertContact($this->convertToContactModel($user));
42
+ }
43
+ catch (\Exception $exception) {
44
+ // silent exception
45
+ }
46
  }
47
 
48
  public function registerHooks()
49
  {
50
+ add_action('newsletter_user_confirmed', array($this, 'ceHandleContactNewsletterSubmit'));
51
  // add hook function to synchronize
52
  add_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
53
  }
54
 
55
  public function unregisterHooks()
56
  {
57
+ remove_action('newsletter_user_confirmed', array($this, 'ceHandleContactNewsletterSubmit'));
58
  // remove hook function to synchronize
59
  remove_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
60
  }
src/modules/contacts/Handlers/WooCommercePluginHandler.php CHANGED
@@ -16,85 +16,87 @@ class WooCommercePluginHandler extends BaseContactFormPluginHandler
16
  {
17
  public function convertToContactModel($orderId)
18
  {
19
- $contactModel = new ContactModel();
20
- $products_detail = get_post_meta($orderId);
21
 
22
- if (isset($products_detail)) {
23
- if ($this->isNotNullOrEmpty($products_detail["_billing_first_name"])) {
24
- $contactModel->setFirstName($products_detail["_billing_first_name"][0]);
25
- }
26
- if ($this->isNotNullOrEmpty($products_detail["_billing_last_name"])) {
27
- $contactModel->setLastName($products_detail["_billing_last_name"][0]);
28
- }
29
 
30
- if ($this->isNotNullOrEmpty($products_detail["_billing_email"])) {
31
- $contactModel->setEmail($products_detail["_billing_email"][0]);
32
- }
33
 
34
- if ($this->isNotNullOrEmpty($contactModel->getEmail())) {
35
- $contactModel->setEventType(CE4WP_WC_EventType);
36
- $contactModel->setOptActionBy(2);
37
- $contactModel->setOptIn(false);
38
- $contactModel->setOptOut(false);
39
- }
40
 
41
- if (array_key_exists('ce_checkout_consent_checkbox', $_POST))
42
- {
43
- $checkbox_value = esc_attr($_POST['ce_checkout_consent_checkbox']);
 
 
 
 
 
 
 
44
 
45
- }
46
- else if ($this->isNotNullOrEmpty($products_detail["ce_checkout_consent_checkbox"]))
47
- {
48
- $checkbox_value = $products_detail["ce_checkout_consent_checkbox"];
49
- }
50
 
51
- if (!is_null($checkbox_value)) {
52
- $contactModel->setOptActionBy(1);
53
- $contactModel->setOptIn((bool)$checkbox_value);
54
  }
55
-
56
- }
57
- return $contactModel;
58
  }
59
 
60
- // public function ceHandlerWooCommerceNewCustomer($customer_id, $new_customer_data) {
61
- // try {
62
- // $this->upsertContact($this->convertToContactModel($new_customer_data));
63
- // }
64
- // catch (\Exception $exception) {
65
- // // silent exception
66
- // }
67
- // }
68
-
69
- function ceHandlerWooCommerceNewOrder($order_id) {
70
- try {
71
- $order = wc_get_order( $order_id );
72
- $this->upsertContact($this->convertToContactModel($order->ID));
73
- }
74
- catch (\Exception $exception) {
75
- // silent exception
76
- }
 
77
  }
78
 
79
  public function registerHooks()
80
  {
81
- add_action('woocommerce_new_order', array($this, 'ceHandlerWooCommerceNewOrder'));
82
- // hook function to synchronize
83
- add_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
84
- //add_action('woocommerce_created_customer', array($this,'ceHandlerWooCommerceNewCustomer'));
85
  }
86
 
87
  public function unregisterHooks()
88
  {
89
- remove_action('woocommerce_new_order', array($this, 'ceHandlerWooCommerceOrder'));
90
- // remove hook function to synchronize
91
- remove_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
92
- //remove_action('woocommerce_created_customer', array($this,'ceHandlerWooCommerceNewCustomer'));
93
  }
94
 
95
  public function syncAction($limit = null)
96
  {
97
- if(!is_int($limit) || $limit <= 0){
98
  $limit = null;
99
  }
100
 
@@ -112,13 +114,13 @@ class WooCommercePluginHandler extends BaseContactFormPluginHandler
112
 
113
  $products_orders = get_posts($args);
114
 
115
- foreach ( $products_orders as $products_order ) {
116
 
117
- $contactModel = $this->convertToContactModel($products_order->ID);
118
 
119
- if($this->isNotNullOrEmpty($contactModel->getEmail())) {
120
- array_push($backfillArray, $contactModel);
121
- }
122
 
123
  }
124
 
16
  {
17
  public function convertToContactModel($orderId)
18
  {
19
+ $contactModel = new ContactModel();
20
+ $products_detail = get_post_meta($orderId);
21
 
22
+ if (isset($products_detail)) {
23
+ if ($this->isNotNullOrEmpty($products_detail["_billing_first_name"])) {
24
+ $contactModel->setFirstName($products_detail["_billing_first_name"][0]);
25
+ }
26
+ if ($this->isNotNullOrEmpty($products_detail["_billing_last_name"])) {
27
+ $contactModel->setLastName($products_detail["_billing_last_name"][0]);
28
+ }
29
 
30
+ if ($this->isNotNullOrEmpty($products_detail["_billing_email"])) {
31
+ $contactModel->setEmail($products_detail["_billing_email"][0]);
32
+ }
33
 
34
+ if ($this->isNotNullOrEmpty($contactModel->getEmail())) {
35
+ $contactModel->setEventType(CE4WP_WC_EventType);
36
+ $contactModel->setOptActionBy(2);
37
+ $contactModel->setOptIn(false);
38
+ $contactModel->setOptOut(false);
39
+ }
40
 
41
+ if (array_key_exists('ce_checkout_consent_checkbox', $_POST)) {
42
+ $checkbox_value = esc_attr($_POST['ce_checkout_consent_checkbox']);
43
+ } else if ($this->isNotNullOrEmpty($products_detail["ce_checkout_consent_checkbox"])) {
44
+ $checkbox_value = $products_detail["ce_checkout_consent_checkbox"];
45
+ } else if (array_key_exists('ce_checkout_consent', $_POST)) {
46
+ // In the database the value is saved as ce_checkout_consent instead of ce_checkout_consent_checkbox
47
+ $checkbox_value = esc_attr($_POST['ce_checkout_consent']);
48
+ } else if ($this->isNotNullOrEmpty($products_detail["ce_checkout_consent"])) {
49
+ $checkbox_value = $products_detail["ce_checkout_consent"];
50
+ }
51
 
52
+ if (!is_null($checkbox_value)) {
53
+ $contactModel->setOptActionBy(1);
54
+ $contactModel->setOptIn((bool)$checkbox_value);
55
+ }
 
56
 
 
 
 
57
  }
58
+ return $contactModel;
 
 
59
  }
60
 
61
+ // public function ceHandlerWooCommerceNewCustomer($customer_id, $new_customer_data) {
62
+ // try {
63
+ // $this->upsertContact($this->convertToContactModel($new_customer_data));
64
+ // }
65
+ // catch (\Exception $exception) {
66
+ // // silent exception
67
+ // }
68
+ // }
69
+
70
+ function ceHandlerWooCommerceNewOrder($order_id)
71
+ {
72
+ try {
73
+ $order = wc_get_order($order_id);
74
+ $this->upsertContact($this->convertToContactModel($order->ID));
75
+ }
76
+ catch (\Exception $exception) {
77
+ // silent exception
78
+ }
79
  }
80
 
81
  public function registerHooks()
82
  {
83
+ add_action('woocommerce_new_order', array($this, 'ceHandlerWooCommerceNewOrder'));
84
+ // hook function to synchronize
85
+ add_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
86
+ //add_action('woocommerce_created_customer', array($this,'ceHandlerWooCommerceNewCustomer'));
87
  }
88
 
89
  public function unregisterHooks()
90
  {
91
+ remove_action('woocommerce_new_order', array($this, 'ceHandlerWooCommerceOrder'));
92
+ // remove hook function to synchronize
93
+ remove_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
94
+ //remove_action('woocommerce_created_customer', array($this,'ceHandlerWooCommerceNewCustomer'));
95
  }
96
 
97
  public function syncAction($limit = null)
98
  {
99
+ if(!is_int($limit) || $limit <= 0) {
100
  $limit = null;
101
  }
102
 
114
 
115
  $products_orders = get_posts($args);
116
 
117
+ foreach ( $products_orders as $products_order ) {
118
 
119
+ $contactModel = $this->convertToContactModel($products_order->ID);
120
 
121
+ if($this->isNotNullOrEmpty($contactModel->getEmail())) {
122
+ array_push($backfillArray, $contactModel);
123
+ }
124
 
125
  }
126
 
src/modules/contacts/Handlers/WpFormsPluginHandler.php CHANGED
@@ -11,123 +11,126 @@ use function Sodium\add;
11
 
12
  class WpFormsPluginHandler extends BaseContactFormPluginHandler
13
  {
14
- private function get_form_type_field($formData, $type)
15
- {
16
- foreach ($formData as $field) {
17
- if(array_key_exists('type', $field) && $field['type'] === $type) {
18
- return $field;
19
- }
 
 
20
  }
21
- return null;
22
- }
23
-
24
- private function convertEntryStringToFormData($entry){
25
- $formdata = array();
26
- $entry = json_decode($entry->fields, true);
27
- foreach ($entry as $field) {
28
- if(array_key_exists('type', $field)) {
29
- $formdata[$field["type"]] = $field["value"];
30
- }
31
- }
32
- return $entry;
33
- }
34
-
35
- public function convertToContactModel($formData)
36
- {
37
- $contactModel = new ContactModel();
38
-
39
- $contactModel->setEventType(CE4WP_WPF_EventType);
40
- $contactModel->setOptIn(true);
41
- $contactModel->setOptOut(false);
42
- $contactModel->setOptActionBy(OptActionBy::Visitor);
43
-
44
- $emailField = $this->get_form_type_field($formData, 'email');
45
- if (array_key_exists('value', $emailField)) {
46
- if ($this->isNotNullOrEmpty($emailField['value'])) {
47
- $contactModel->setEmail($emailField['value']);
48
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
 
51
- $nameField = $this->get_form_type_field($formData, 'name');
52
- if (array_key_exists('first', $nameField)) {
53
- if ($this->isNotNullOrEmpty($nameField['first'])) {
54
- $contactModel->setFirstName($nameField['first']);
55
- }
 
 
 
56
  }
57
- if (array_key_exists('last', $nameField)) {
58
- if ($this->isNotNullOrEmpty($nameField['last'])) {
59
- $contactModel->setLastName($nameField['last']);
60
- }
 
 
61
  }
62
 
63
- return $contactModel;
64
- }
 
 
65
 
66
- public function ceHandleWpFormsProcessComplete($fields) {
67
- try {
68
- $this->upsertContact($this->convertToContactModel($fields));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
- catch (\Exception $exception) {
71
- // silent exception
 
 
72
  }
73
- }
74
-
75
- public function registerHooks()
76
- {
77
- // https://wpforms.com/developers/wpforms_process_complete/
78
- add_action( 'wpforms_process_complete', array($this, 'ceHandleWpFormsProcessComplete'), 10, 4);
79
- add_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
80
- }
81
-
82
- public function unregisterHooks()
83
- {
84
- remove_action( 'wpforms_process_complete', array($this, 'ceHandleWpFormsProcessComplete'));
85
- }
86
-
87
- public function syncAction($limit = null)
88
- {
89
- if (!is_int($limit) || $limit <= 0) {
90
- $limit = null;
91
- }
92
-
93
- // Relies on plugin => wpforms paid or pro
94
- if (in_array('wpforms/wpforms.php', apply_filters('active_plugins', get_option('active_plugins'))) ||
95
- in_array('wpforms-lite/wpforms.php', apply_filters('active_plugins', get_option('active_plugins')))) { //this is a guess, have to test first
96
-
97
- //Get form submissions from the wpforms db
98
- global $wpdb;
99
- $contactsArray = array();
100
-
101
- //get the form entries
102
- $entriesQuery = 'SELECT fields FROM wp_wpforms_entries';
103
- $entryResult = $wpdb->get_results($wpdb->prepare($entriesQuery));
104
-
105
- //Loop through entries and create the contacts
106
- foreach ($entryResult as $entry) {
107
- $entryData = $this->convertEntryStringToFormData($entry);
108
- $contact = $this->convertToContactModel($entryData);
109
- array_push($contactsArray, $contact);
110
-
111
- if (isset($limit) && count($contactsArray) >= $limit) {
112
- break;
113
- }
114
- }
115
-
116
- if (!empty($contactsArray)) {
117
- $batches = array_chunk($contactsArray, CE4WP_BATCH_SIZE);
118
- foreach ($batches as $batch) {
119
- try {
120
- $this->batchUpsertContacts($batch);
121
- } catch (\Exception $exception) {
122
- // silent exception
123
- }
124
- }
125
- }
126
- }
127
- }
128
-
129
- function __construct()
130
- {
131
- parent::__construct();
132
- }
133
  }
11
 
12
  class WpFormsPluginHandler extends BaseContactFormPluginHandler
13
  {
14
+ private function get_form_type_field($formData, $type)
15
+ {
16
+ foreach ($formData as $field) {
17
+ if(array_key_exists('type', $field) && $field['type'] === $type) {
18
+ return $field;
19
+ }
20
+ }
21
+ return null;
22
  }
23
+
24
+ private function convertEntryStringToFormData($entry)
25
+ {
26
+ $formdata = array();
27
+ $entry = json_decode($entry->fields, true);
28
+ foreach ($entry as $field) {
29
+ if(array_key_exists('type', $field)) {
30
+ $formdata[$field["type"]] = $field["value"];
31
+ }
32
+ }
33
+ return $entry;
34
+ }
35
+
36
+ public function convertToContactModel($formData)
37
+ {
38
+ $contactModel = new ContactModel();
39
+
40
+ $contactModel->setEventType(CE4WP_WPF_EventType);
41
+ $contactModel->setOptIn(true);
42
+ $contactModel->setOptOut(false);
43
+ $contactModel->setOptActionBy(OptActionBy::Visitor);
44
+
45
+ $emailField = $this->get_form_type_field($formData, 'email');
46
+ if (array_key_exists('value', $emailField)) {
47
+ if ($this->isNotNullOrEmpty($emailField['value'])) {
48
+ $contactModel->setEmail($emailField['value']);
49
+ }
50
+ }
51
+
52
+ $nameField = $this->get_form_type_field($formData, 'name');
53
+ if (array_key_exists('first', $nameField)) {
54
+ if ($this->isNotNullOrEmpty($nameField['first'])) {
55
+ $contactModel->setFirstName($nameField['first']);
56
+ }
57
+ }
58
+ if (array_key_exists('last', $nameField)) {
59
+ if ($this->isNotNullOrEmpty($nameField['last'])) {
60
+ $contactModel->setLastName($nameField['last']);
61
+ }
62
+ }
63
+
64
+ return $contactModel;
65
  }
66
 
67
+ public function ceHandleWpFormsProcessComplete($fields)
68
+ {
69
+ try {
70
+ $this->upsertContact($this->convertToContactModel($fields));
71
+ }
72
+ catch (\Exception $exception) {
73
+ // silent exception
74
+ }
75
  }
76
+
77
+ public function registerHooks()
78
+ {
79
+ // https://wpforms.com/developers/wpforms_process_complete/
80
+ add_action('wpforms_process_complete', array($this, 'ceHandleWpFormsProcessComplete'), 10, 4);
81
+ add_action(CE4WP_SYNCHRONIZE_ACTION, array($this, 'syncAction'));
82
  }
83
 
84
+ public function unregisterHooks()
85
+ {
86
+ remove_action('wpforms_process_complete', array($this, 'ceHandleWpFormsProcessComplete'));
87
+ }
88
 
89
+ public function syncAction($limit = null)
90
+ {
91
+ if (!is_int($limit) || $limit <= 0) {
92
+ $limit = null;
93
+ }
94
+
95
+ // Relies on plugin => wpforms paid or pro
96
+ if (in_array('wpforms/wpforms.php', apply_filters('active_plugins', get_option('active_plugins')))
97
+ || in_array('wpforms-lite/wpforms.php', apply_filters('active_plugins', get_option('active_plugins')))
98
+ ) { //this is a guess, have to test first
99
+
100
+ //Get form submissions from the wpforms db
101
+ global $wpdb;
102
+ $contactsArray = array();
103
+
104
+ //get the form entries
105
+ $entriesQuery = 'SELECT fields FROM wp_wpforms_entries';
106
+ $entryResult = $wpdb->get_results($wpdb->prepare($entriesQuery));
107
+
108
+ //Loop through entries and create the contacts
109
+ foreach ($entryResult as $entry) {
110
+ $entryData = $this->convertEntryStringToFormData($entry);
111
+ $contact = $this->convertToContactModel($entryData);
112
+ array_push($contactsArray, $contact);
113
+
114
+ if (isset($limit) && count($contactsArray) >= $limit) {
115
+ break;
116
+ }
117
+ }
118
+
119
+ if (!empty($contactsArray)) {
120
+ $batches = array_chunk($contactsArray, CE4WP_BATCH_SIZE);
121
+ foreach ($batches as $batch) {
122
+ try {
123
+ $this->batchUpsertContacts($batch);
124
+ } catch (\Exception $exception) {
125
+ // silent exception
126
+ }
127
+ }
128
+ }
129
+ }
130
  }
131
+
132
+ function __construct()
133
+ {
134
+ parent::__construct();
135
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  }
src/modules/contacts/Services/ContactsSyncService.php CHANGED
@@ -9,13 +9,15 @@ use Exception;
9
 
10
  class ContactsSyncService
11
  {
12
- private function validate_email_address($emailAddress) {
 
13
  if (!isset($emailAddress) && empty($emailAddress)) {
14
  throw new Exception('No valid email address provided');
15
  }
16
  }
17
 
18
- private function ensure_event_type($eventType) {
 
19
  // DEV: For now, we only support WordPress.
20
  if (isset($eventType) && !empty($eventType)) {
21
  return $eventType;
@@ -24,7 +26,8 @@ class ContactsSyncService
24
  return 'WordPress';
25
  }
26
 
27
- private function build_payload($contactModels) {
 
28
  $contacts = array();
29
  foreach ($contactModels as $model) {
30
  array_push($contacts, $model->toArray());
@@ -37,7 +40,8 @@ class ContactsSyncService
37
  return wp_json_encode($data);
38
  }
39
 
40
- public function upsertContact(ContactModel $contactModel) {
 
41
  if(!isset($contactModel)) {
42
  return false;
43
  }
@@ -50,7 +54,8 @@ class ContactsSyncService
50
  return true;
51
  }
52
 
53
- public function upsertContacts($contactModels, $batchSize = 250) {
 
54
 
55
  $creativemail = CreativeMail::get_instance();
56
 
@@ -60,12 +65,14 @@ class ContactsSyncService
60
  {
61
  $jsonData = $this->build_payload($chunk);
62
 
63
- $creativemail->get_api_manager()->get_api_background_process()->push_to_queue( new ApiRequestItem(
64
- 'POST',
65
- 'application/json',
66
- '/v1.0/contacts',
67
- $jsonData
68
- ));
 
 
69
  }
70
 
71
  // Start the queue.
9
 
10
  class ContactsSyncService
11
  {
12
+ private function validate_email_address($emailAddress)
13
+ {
14
  if (!isset($emailAddress) && empty($emailAddress)) {
15
  throw new Exception('No valid email address provided');
16
  }
17
  }
18
 
19
+ private function ensure_event_type($eventType)
20
+ {
21
  // DEV: For now, we only support WordPress.
22
  if (isset($eventType) && !empty($eventType)) {
23
  return $eventType;
26
  return 'WordPress';
27
  }
28
 
29
+ private function build_payload($contactModels)
30
+ {
31
  $contacts = array();
32
  foreach ($contactModels as $model) {
33
  array_push($contacts, $model->toArray());
40
  return wp_json_encode($data);
41
  }
42
 
43
+ public function upsertContact(ContactModel $contactModel)
44
+ {
45
  if(!isset($contactModel)) {
46
  return false;
47
  }
54
  return true;
55
  }
56
 
57
+ public function upsertContacts($contactModels, $batchSize = 250)
58
+ {
59
 
60
  $creativemail = CreativeMail::get_instance();
61
 
65
  {
66
  $jsonData = $this->build_payload($chunk);
67
 
68
+ $creativemail->get_api_manager()->get_api_background_process()->push_to_queue(
69
+ new ApiRequestItem(
70
+ 'POST',
71
+ 'application/json',
72
+ '/v1.0/contacts',
73
+ $jsonData
74
+ )
75
+ );
76
  }
77
 
78
  // Start the queue.
src/modules/contacts/models/ContactAddressModel.php CHANGED
@@ -2,7 +2,8 @@
2
 
3
  namespace CreativeMail\Modules\Contacts\Models;
4
 
5
- class ContactAddressModel {
 
6
  public $countryCode;
7
  public $postalCode;
8
  public $state;
@@ -11,63 +12,78 @@ class ContactAddressModel {
11
  public $address2;
12
  public $city;
13
 
14
- public function setCountryCode($countryCode) {
 
15
  $this->countryCode = $countryCode;
16
  }
17
 
18
- public function getCountryCode() {
 
19
  return $this->countryCode;
20
  }
21
 
22
- public function setPostalCode($postalCode) {
 
23
  $this->postalCode = $postalCode;
24
  }
25
 
26
- public function getPostalCode() {
 
27
  return $this->postalCode;
28
  }
29
 
30
- public function setState($state) {
 
31
  $this->state = $state;
32
  }
33
 
34
- public function getState() {
 
35
  return $this->state;
36
  }
37
 
38
- public function setStateCode($stateCode) {
 
39
  $this->stateCode = $stateCode;
40
  }
41
 
42
- public function getStateCode() {
 
43
  return $this->stateCode;
44
  }
45
 
46
- public function setAddress($address) {
 
47
  $this->address = $address;
48
  }
49
 
50
- public function getAddress() {
 
51
  return $this->address;
52
  }
53
 
54
- public function setAddress2($address2) {
 
55
  $this->address2 = $address2;
56
  }
57
 
58
- public function getAddress2() {
 
59
  return $this->address2;
60
  }
61
 
62
- public function setCity($city) {
 
63
  $this->city = $city;
64
  }
65
 
66
- public function getCity() {
 
67
  return $this->city;
68
  }
69
 
70
- public function toArray() {
 
71
  return array(
72
  "country_code" => $this->getCountryCode(),
73
  "state_code" => $this->getStateCode(),
2
 
3
  namespace CreativeMail\Modules\Contacts\Models;
4
 
5
+ class ContactAddressModel
6
+ {
7
  public $countryCode;
8
  public $postalCode;
9
  public $state;
12
  public $address2;
13
  public $city;
14
 
15
+ public function setCountryCode($countryCode)
16
+ {
17
  $this->countryCode = $countryCode;
18
  }
19
 
20
+ public function getCountryCode()
21
+ {
22
  return $this->countryCode;
23
  }
24
 
25
+ public function setPostalCode($postalCode)
26
+ {
27
  $this->postalCode = $postalCode;
28
  }
29
 
30
+ public function getPostalCode()
31
+ {
32
  return $this->postalCode;
33
  }
34
 
35
+ public function setState($state)
36
+ {
37
  $this->state = $state;
38
  }
39
 
40
+ public function getState()
41
+ {
42
  return $this->state;
43
  }
44
 
45
+ public function setStateCode($stateCode)
46
+ {
47
  $this->stateCode = $stateCode;
48
  }
49
 
50
+ public function getStateCode()
51
+ {
52
  return $this->stateCode;
53
  }
54
 
55
+ public function setAddress($address)
56
+ {
57
  $this->address = $address;
58
  }
59
 
60
+ public function getAddress()
61
+ {
62
  return $this->address;
63
  }
64
 
65
+ public function setAddress2($address2)
66
+ {
67
  $this->address2 = $address2;
68
  }
69
 
70
+ public function getAddress2()
71
+ {
72
  return $this->address2;
73
  }
74
 
75
+ public function setCity($city)
76
+ {
77
  $this->city = $city;
78
  }
79
 
80
+ public function getCity()
81
+ {
82
  return $this->city;
83
  }
84
 
85
+ public function toArray()
86
+ {
87
  return array(
88
  "country_code" => $this->getCountryCode(),
89
  "state_code" => $this->getStateCode(),
src/modules/contacts/models/ContactModel.php CHANGED
@@ -16,10 +16,12 @@ class ContactModel
16
  public $contactAddresses;
17
  public $eventType;
18
 
19
- function __construct() {
 
20
  }
21
 
22
- public function setEmail($email) {
 
23
  if (isset($email) && !empty($email)) {
24
  $this->email = $email;
25
  }
@@ -28,91 +30,113 @@ class ContactModel
28
  }
29
  }
30
 
31
- public function getEmail() {
 
32
  return $this->email;
33
  }
34
 
35
- public function setPhone($phone) {
 
36
  $this->phone = $phone;
37
  }
38
 
39
- public function getPhone() {
 
40
  return $this->phone;
41
  }
42
 
43
- public function setCompanyName($companyName) {
 
44
  $this->companyName = $companyName;
45
  }
46
 
47
- public function getCompanyName() {
 
48
  return $this->companyName;
49
  }
50
 
51
- public function setName($name) {
 
52
  $this->name = $name;
53
  }
54
 
55
- public function getName() {
 
56
  return $this->name;
57
  }
58
 
59
- public function setFirstName($firstName) {
 
60
  $this->firstName = $firstName;
61
  }
62
 
63
- public function getFirstName() {
 
64
  return $this->firstName;
65
  }
66
 
67
- public function setLastName($lastName) {
 
68
  $this->lastName = $lastName;
69
  }
70
 
71
- public function getLastName() {
 
72
  return $this->lastName;
73
  }
74
 
75
- public function setOptIn($optIn) {
 
76
  $this->optIn = $optIn;
77
  }
78
 
79
- public function setOptOut($optOut) {
 
80
  $this->optOut = $optOut;
81
  }
82
 
83
- public function getOptIn() {
 
84
  return $this->optIn;
85
  }
86
 
87
- public function getOptOut() {
 
88
  return $this->optOut;
89
  }
90
 
91
- public function setOptActionBy($optActionBy) {
 
92
  $this->optActionBy = $optActionBy;
93
  }
94
 
95
- public function getOptActionBy() {
 
96
  return $this->optActionBy;
97
  }
98
 
99
- public function setContactAddress(ContactAddressModel $contactAddresses) {
 
100
  $this->contactAddresses = $contactAddresses;
101
  }
102
 
103
- public function getContactAddress() {
 
104
  return $this->contactAddresses;
105
  }
106
 
107
- public function setEventType($eventType) {
 
108
  $this->eventType = $eventType;
109
  }
110
 
111
- public function getEventType() {
 
112
  return $this->eventType;
113
  }
114
 
115
- function toArray() {
 
116
  $result = array(
117
  "email" => $this->getEmail(),
118
  "phone" => $this->getPhone(),
@@ -127,14 +151,15 @@ class ContactModel
127
  );
128
 
129
  $address = $this->getContactAddress();
130
- if(isset($address)){
131
  $result["addresses"] = array($address->toArray());
132
  }
133
 
134
  return $result;
135
  }
136
 
137
- function toJson() {
 
138
  return wp_json_encode($this->toArray());
139
  }
140
  }
16
  public $contactAddresses;
17
  public $eventType;
18
 
19
+ function __construct()
20
+ {
21
  }
22
 
23
+ public function setEmail($email)
24
+ {
25
  if (isset($email) && !empty($email)) {
26
  $this->email = $email;
27
  }
30
  }
31
  }
32
 
33
+ public function getEmail()
34
+ {
35
  return $this->email;
36
  }
37
 
38
+ public function setPhone($phone)
39
+ {
40
  $this->phone = $phone;
41
  }
42
 
43
+ public function getPhone()
44
+ {
45
  return $this->phone;
46
  }
47
 
48
+ public function setCompanyName($companyName)
49
+ {
50
  $this->companyName = $companyName;
51
  }
52
 
53
+ public function getCompanyName()
54
+ {
55
  return $this->companyName;
56
  }
57
 
58
+ public function setName($name)
59
+ {
60
  $this->name = $name;
61
  }
62
 
63
+ public function getName()
64
+ {
65
  return $this->name;
66
  }
67
 
68
+ public function setFirstName($firstName)
69
+ {
70
  $this->firstName = $firstName;
71
  }
72
 
73
+ public function getFirstName()
74
+ {
75
  return $this->firstName;
76
  }
77
 
78
+ public function setLastName($lastName)
79
+ {
80
  $this->lastName = $lastName;
81
  }
82
 
83
+ public function getLastName()
84
+ {
85
  return $this->lastName;
86
  }
87
 
88
+ public function setOptIn($optIn)
89
+ {
90
  $this->optIn = $optIn;
91
  }
92
 
93
+ public function setOptOut($optOut)
94
+ {
95
  $this->optOut = $optOut;
96
  }
97
 
98
+ public function getOptIn()
99
+ {
100
  return $this->optIn;
101
  }
102
 
103
+ public function getOptOut()
104
+ {
105
  return $this->optOut;
106
  }
107
 
108
+ public function setOptActionBy($optActionBy)
109
+ {
110
  $this->optActionBy = $optActionBy;
111
  }
112
 
113
+ public function getOptActionBy()
114
+ {
115
  return $this->optActionBy;
116
  }
117
 
118
+ public function setContactAddress(ContactAddressModel $contactAddresses)
119
+ {
120
  $this->contactAddresses = $contactAddresses;
121
  }
122
 
123
+ public function getContactAddress()
124
+ {
125
  return $this->contactAddresses;
126
  }
127
 
128
+ public function setEventType($eventType)
129
+ {
130
  $this->eventType = $eventType;
131
  }
132
 
133
+ public function getEventType()
134
+ {
135
  return $this->eventType;
136
  }
137
 
138
+ function toArray()
139
+ {
140
  $result = array(
141
  "email" => $this->getEmail(),
142
  "phone" => $this->getPhone(),
151
  );
152
 
153
  $address = $this->getContactAddress();
154
+ if(isset($address)) {
155
  $result["addresses"] = array($address->toArray());
156
  }
157
 
158
  return $result;
159
  }
160
 
161
+ function toJson()
162
+ {
163
  return wp_json_encode($this->toArray());
164
  }
165
  }
src/modules/woocommerce/models/WCInformationModel.php CHANGED
@@ -3,13 +3,15 @@
3
  namespace CreativeMail\Modules\WooCommerce\Models;
4
  use CreativeMail\CreativeMail;
5
 
6
- class WCInformationModel {
 
7
  public $wc_installed;
8
  public $wc_version;
9
  public $plugin_version;
10
 
11
- function __construct() {
12
- $this->wc_installed = in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
 
13
  if ($this->wc_installed) {
14
  global $woocommerce;
15
  $this->wc_version = $woocommerce->version;
3
  namespace CreativeMail\Modules\WooCommerce\Models;
4
  use CreativeMail\CreativeMail;
5
 
6
+ class WCInformationModel
7
+ {
8
  public $wc_installed;
9
  public $wc_version;
10
  public $plugin_version;
11
 
12
+ function __construct()
13
+ {
14
+ $this->wc_installed = in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')));
15
  if ($this->wc_installed) {
16
  global $woocommerce;
17
  $this->wc_version = $woocommerce->version;
src/modules/woocommerce/models/WCProductModel.php CHANGED
@@ -2,7 +2,8 @@
2
 
3
  namespace CreativeMail\Modules\WooCommerce\Models;
4
 
5
- class WCProductModel {
 
6
  public $id;
7
  public $name;
8
  public $sku;
@@ -19,7 +20,8 @@ class WCProductModel {
19
  public $url;
20
  public $image_url;
21
 
22
- function __construct($data) {
 
23
  $this->id = $data['id'];
24
  $this->name = $data['name'];
25
  $this->sku = $data['sku'];
2
 
3
  namespace CreativeMail\Modules\WooCommerce\Models;
4
 
5
+ class WCProductModel
6
+ {
7
  public $id;
8
  public $name;
9
  public $sku;
20
  public $url;
21
  public $image_url;
22
 
23
+ function __construct($data)
24
+ {
25
  $this->id = $data['id'];
26
  $this->name = $data['name'];
27
  $this->sku = $data['sku'];
src/modules/woocommerce/models/WCStoreInformation.php CHANGED
@@ -8,33 +8,32 @@ use WC_Countries;
8
 
9
  class WCStoreInformation
10
  {
11
- public $address1;
12
- public $address2;
13
- public $city;
14
- public $postcode;
15
- public $state;
16
- public $country;
17
- public $country_code;
18
- public $currency;
19
- public $currency_symbol;
20
- public $email_from;
21
- public $email_name;
22
 
23
- function __construct()
24
- {
25
- if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))
26
  {
27
- $this->address1 = WC()->countries->get_base_address();
28
- $this->address2 = WC()->countries->get_base_address_2();
29
- $this->city = WC()->countries->get_base_city();
30
- $this->postcode = WC()->countries->get_base_postcode();
31
- $this->state = WC()->countries->get_base_state();
32
- $this->country = WC()->countries->countries[WC()->countries->get_base_country()];
33
- $this->country_code = WC()->countries->get_base_country();
34
- $this->currency_symbol = get_woocommerce_currency_symbol();
35
- $this->currency = get_woocommerce_currency();
36
- $this->email_from = apply_filters( 'woocommerce_email_from_address', get_option( 'woocommerce_email_from_address' ));
37
- $this->email_name = apply_filters( 'woocommerce_email_from_name', get_option( 'woocommerce_email_from_name' ));
 
 
38
  }
39
- }
40
  }
8
 
9
  class WCStoreInformation
10
  {
11
+ public $address1;
12
+ public $address2;
13
+ public $city;
14
+ public $postcode;
15
+ public $state;
16
+ public $country;
17
+ public $country_code;
18
+ public $currency;
19
+ public $currency_symbol;
20
+ public $email_from;
21
+ public $email_name;
22
 
23
+ function __construct()
 
 
24
  {
25
+ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
26
+ $this->address1 = WC()->countries->get_base_address();
27
+ $this->address2 = WC()->countries->get_base_address_2();
28
+ $this->city = WC()->countries->get_base_city();
29
+ $this->postcode = WC()->countries->get_base_postcode();
30
+ $this->state = WC()->countries->get_base_state();
31
+ $this->country = WC()->countries->countries[WC()->countries->get_base_country()];
32
+ $this->country_code = WC()->countries->get_base_country();
33
+ $this->currency_symbol = get_woocommerce_currency_symbol();
34
+ $this->currency = get_woocommerce_currency();
35
+ $this->email_from = apply_filters('woocommerce_email_from_address', get_option('woocommerce_email_from_address'));
36
+ $this->email_name = apply_filters('woocommerce_email_from_name', get_option('woocommerce_email_from_name'));
37
+ }
38
  }
 
39
  }
src/views/activated-integrations.php CHANGED
@@ -30,14 +30,14 @@ $activated_integrations = CreativeMail::get_instance()->get_integration_manager(
30
  <ul style="color: rgba(0, 0, 0, 0.6);">
31
  <?php
32
  foreach ($available_integrations as $available_integration) {
33
- $active = in_array($available_integration, $activated_integrations);
34
- $checked = $active === true ? 'checked' : '';
35
 
36
- echo '<li><label class="ce4wp-checkbox"><input type="checkbox" name="activated_plugins[]" value="' . esc_attr($available_integration->get_slug()) . '" '.esc_attr($checked).' /><span>' . esc_html($available_integration->get_name()) . '</span></label></li>';
37
  }
38
  ?>
39
  </ul>
40
- <div class="ce-kvp">
41
  <input name="save_button" type="submit" class="ce4wp-button-text-primary ce4wp-right" id="save-activated-plugins" value="Save" onclick="showConsentModal(); return false;" />
42
  <!-- -->
43
  </div>
30
  <ul style="color: rgba(0, 0, 0, 0.6);">
31
  <?php
32
  foreach ($available_integrations as $available_integration) {
33
+ $active = in_array($available_integration, $activated_integrations);
34
+ $checked = $active === true ? 'checked' : '';
35
 
36
+ echo '<li><label class="ce4wp-checkbox"><input type="checkbox" name="activated_plugins[]" value="' . esc_attr($available_integration->get_slug()) . '" '.esc_attr($checked).' /><span>' . esc_html($available_integration->get_name()) . '</span></label></li>';
37
  }
38
  ?>
39
  </ul>
40
+ <div class="ce-kvp">
41
  <input name="save_button" type="submit" class="ce4wp-button-text-primary ce4wp-right" id="save-activated-plugins" value="Save" onclick="showConsentModal(); return false;" />
42
  <!-- -->
43
  </div>
src/views/available-integrations.php CHANGED
@@ -12,11 +12,11 @@ $supported_integrations = CreativeMail::get_instance()->get_integration_manager(
12
  </p>
13
  <ul style="color: rgba(0, 0, 0, 0.6);">
14
  <?php
15
- foreach ($supported_integrations as $supported_integration) {
16
- if ($supported_integration->is_hidden_from_suggestions()) {
17
- continue;
18
- }
19
- echo '<li>- ' . esc_html($supported_integration->get_name()) . '</li>';
20
  }
 
 
21
  ?>
22
  </ul>
12
  </p>
13
  <ul style="color: rgba(0, 0, 0, 0.6);">
14
  <?php
15
+ foreach ($supported_integrations as $supported_integration) {
16
+ if ($supported_integration->is_hidden_from_suggestions()) {
17
+ continue;
 
 
18
  }
19
+ echo '<li>- ' . esc_html($supported_integration->get_name()) . '</li>';
20
+ }
21
  ?>
22
  </ul>
src/views/consent.php CHANGED
@@ -4,11 +4,11 @@ use CreativeMail\Helpers\EnvironmentHelper;
4
  use CreativeMail\Helpers\OptionsHelper;
5
 
6
  if ($_SERVER['REQUEST_METHOD'] === 'POST') {
7
- if($_POST['action'] === 'consent') {
8
- OptionsHelper::set_did_accept_consent();
9
- require 'onboarding.php';
10
- exit;
11
- }
12
  }
13
 
14
  ?>
4
  use CreativeMail\Helpers\OptionsHelper;
5
 
6
  if ($_SERVER['REQUEST_METHOD'] === 'POST') {
7
+ if($_POST['action'] === 'consent') {
8
+ OptionsHelper::set_did_accept_consent();
9
+ include 'onboarding.php';
10
+ exit;
11
+ }
12
  }
13
 
14
  ?>
src/views/dashboard.php CHANGED
@@ -15,9 +15,9 @@ use CreativeMail\Helpers\EnvironmentHelper;
15
  }
16
  </script>
17
  <div class="ce4wp-admin-wrapper">
18
- <header class="ce4wp-swoosh-header"></header>
19
 
20
- <div class="ce4wp-swoosh-container">
21
  <div style="margin-top: 0px;">
22
  <div class="ce4wp-backdrop">
23
  <div class="ce4wp-backdrop-container">
15
  }
16
  </script>
17
  <div class="ce4wp-admin-wrapper">
18
+ <header class="ce4wp-swoosh-header"></header>
19
 
20
+ <div class="ce4wp-swoosh-container">
21
  <div style="margin-top: 0px;">
22
  <div class="ce4wp-backdrop">
23
  <div class="ce4wp-backdrop-container">
src/views/onboarding.php CHANGED
@@ -11,12 +11,11 @@ $onboardingUrl = EnvironmentHelper::get_app_url() . 'marketing/onboarding/signup
11
  . '&wp_version=' . get_bloginfo('version')
12
  . '&plugin_version=' . CE4WP_PLUGIN_VERSION;
13
  $referred_by = OptionsHelper::get_referred_by();
14
- if (isset($referred_by))
15
- {
16
  $utm_campaign = '';
17
  if (is_array($referred_by) && array_key_exists('plugin', $referred_by) && array_key_exists('source', $referred_by)) {
18
  $utm_campaign = $referred_by['plugin'] . $referred_by['source'];
19
- } else if (is_string($referred_by)){
20
  $utm_campaign = str_replace(';', '|', $referred_by);
21
  }
22
  $onboardingUrl .= '&utm_source=wordpress&utm_medium=plugin&utm_campaign=' . $utm_campaign;
11
  . '&wp_version=' . get_bloginfo('version')
12
  . '&plugin_version=' . CE4WP_PLUGIN_VERSION;
13
  $referred_by = OptionsHelper::get_referred_by();
14
+ if (isset($referred_by)) {
 
15
  $utm_campaign = '';
16
  if (is_array($referred_by) && array_key_exists('plugin', $referred_by) && array_key_exists('source', $referred_by)) {
17
  $utm_campaign = $referred_by['plugin'] . $referred_by['source'];
18
+ } else if (is_string($referred_by)) {
19
  $utm_campaign = str_replace(';', '|', $referred_by);
20
  }
21
  $onboardingUrl .= '&utm_source=wordpress&utm_medium=plugin&utm_campaign=' . $utm_campaign;
src/views/settings-internal.php CHANGED
@@ -3,37 +3,37 @@ use CreativeMail\Helpers\EnvironmentHelper;
3
  ?>
4
 
5
  <div class="ce4wp-card">
6
- <div class="ce4wp-px-4 ce4wp-py-4">
7
- <h2 class="ce4wp-typography-root ce4wp-typography-h2 ce4wp-mb-2">Technical details</h2>
8
 
9
- <div class="ce4wp-kvp">
10
- <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Instance UUID</h4>
11
- <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html($this->instance_uuid) ?></p>
12
- </div>
13
 
14
- <div class="ce4wp-kvp">
15
- <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Instance Id</h4>
16
- <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html($this->instance_id) ?></p>
17
- </div>
18
 
19
- <div class="ce4wp-kvp">
20
- <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Environment</h4>
21
- <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html(EnvironmentHelper::get_environment()) ?></p>
22
- </div>
23
 
24
- <div class="ce4wp-kvp">
25
- <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Plugin version</h4>
26
- <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html(CE4WP_PLUGIN_VERSION) . '.' . esc_html(CE4WP_BUILD_NUMBER) ?></p>
27
- </div>
28
 
29
- <div class="ce4wp-kvp">
30
- <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">App</h4>
31
- <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_js(EnvironmentHelper::get_app_url()) ?></p>
32
- </div>
33
 
34
- <div class="ce4wp-kvp">
35
- <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">App Gateway</h4>
36
- <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_js(EnvironmentHelper::get_app_gateway_url()) ?></p>
37
- </div>
38
- </div>
39
  </div>
3
  ?>
4
 
5
  <div class="ce4wp-card">
6
+ <div class="ce4wp-px-4 ce4wp-py-4">
7
+ <h2 class="ce4wp-typography-root ce4wp-typography-h2 ce4wp-mb-2">Technical details</h2>
8
 
9
+ <div class="ce4wp-kvp">
10
+ <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Instance UUID</h4>
11
+ <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html($this->instance_uuid) ?></p>
12
+ </div>
13
 
14
+ <div class="ce4wp-kvp">
15
+ <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Instance Id</h4>
16
+ <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html($this->instance_id) ?></p>
17
+ </div>
18
 
19
+ <div class="ce4wp-kvp">
20
+ <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Environment</h4>
21
+ <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html(EnvironmentHelper::get_environment()) ?></p>
22
+ </div>
23
 
24
+ <div class="ce4wp-kvp">
25
+ <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">Plugin version</h4>
26
+ <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_html(CE4WP_PLUGIN_VERSION) . '.' . esc_html(CE4WP_BUILD_NUMBER) ?></p>
27
+ </div>
28
 
29
+ <div class="ce4wp-kvp">
30
+ <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">App</h4>
31
+ <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_js(EnvironmentHelper::get_app_url()) ?></p>
32
+ </div>
33
 
34
+ <div class="ce4wp-kvp">
35
+ <h4 class="ce4wp-typography-root ce4wp-typography-h4 ce4wp-mb-2">App Gateway</h4>
36
+ <p class="ce4wp-typography-root ce4wp-body2" style="color: rgba(0, 0, 0, 0.6);"><?php echo esc_js(EnvironmentHelper::get_app_gateway_url()) ?></p>
37
+ </div>
38
+ </div>
39
  </div>
src/views/settings.php CHANGED
@@ -4,41 +4,41 @@
4
  use CreativeMail\Helpers\EnvironmentHelper;
5
  use CreativeMail\Helpers\OptionsHelper;
6
 
7
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
8
 
9
- if($_POST['action'] === 'disconnect') {
10
- OptionsHelper::clear_options(true);
11
- $this->instance_id = null;
12
- }
13
-
14
- if($_POST['action'] === 'change_activated_plugins') {
15
- $activated_plugins = array();
16
- $keys = $_POST["activated_plugins"];
17
- foreach ($keys as $key) {
18
- array_push($activated_plugins, sanitize_key($key));
19
- }
20
 
21
- CreativeMail::get_instance()->get_integration_manager()->set_activated_plugins($activated_plugins);
 
 
 
 
22
  }
23
 
24
- if ($_POST['action'] === 'change_marketing_information') {
25
- if(array_key_exists('ce4wp_show_marketing_checkbox', $_POST) && sanitize_key($_POST['ce4wp_show_marketing_checkbox']) === 'on') {
26
- OptionsHelper::set_checkout_checkbox_enabled('1');
27
- } else {
28
- OptionsHelper::set_checkout_checkbox_enabled('0');
29
- }
30
- OptionsHelper::set_checkout_checkbox_text(sanitize_text_field($_POST['ce4wp_checkbox_text']));
 
31
  }
 
32
  }
 
33
 
34
  $contact_sync_available = !empty(CreativeMail::get_instance()->get_integration_manager()->get_active_plugins());
35
 
36
  ?>
37
 
38
  <div class="ce4wp-admin-wrapper">
39
- <header class="ce4wp-swoosh-header"></header>
40
 
41
- <div class="ce4wp-swoosh-container">
42
  <div style="margin-top: 0px;">
43
  <div class="ce4wp-backdrop">
44
  <div class="ce4wp-backdrop-container">
@@ -55,12 +55,12 @@
55
 
56
  <?php
57
  if (OptionsHelper::get_instance_id()) {
58
- include 'unlink.php';
59
  }
60
  else {
61
- include 'pending-setup.php';
62
  }
63
- ?>
64
  </div>
65
  </div>
66
 
@@ -69,21 +69,21 @@
69
  <h2 class="ce4wp-typography-root ce4wp-typography-h2 ce4wp-mb-2">Contact Sync</h2>
70
 
71
  <?php
72
- if ($contact_sync_available) {
73
- include 'activated-integrations.php';
74
- }
75
- else {
76
- include 'available-integrations.php';
77
- }
78
- ?>
79
  </div>
80
  </div>
81
 
82
  <?php
83
  if (EnvironmentHelper::is_test_environment()) {
84
- include 'settings-internal.php';
85
  }
86
- ?>
87
 
88
  <div class="ce4wp-card">
89
  <div class="ce4wp-px-4 ce4wp-py-4">
4
  use CreativeMail\Helpers\EnvironmentHelper;
5
  use CreativeMail\Helpers\OptionsHelper;
6
 
7
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
8
 
9
+ if($_POST['action'] === 'disconnect') {
10
+ OptionsHelper::clear_options(true);
11
+ $this->instance_id = null;
12
+ }
 
 
 
 
 
 
 
13
 
14
+ if($_POST['action'] === 'change_activated_plugins') {
15
+ $activated_plugins = array();
16
+ $keys = $_POST["activated_plugins"];
17
+ foreach ($keys as $key) {
18
+ array_push($activated_plugins, sanitize_key($key));
19
  }
20
 
21
+ CreativeMail::get_instance()->get_integration_manager()->set_activated_plugins($activated_plugins);
22
+ }
23
+
24
+ if ($_POST['action'] === 'change_marketing_information') {
25
+ if(array_key_exists('ce4wp_show_marketing_checkbox', $_POST) && sanitize_key($_POST['ce4wp_show_marketing_checkbox']) === 'on') {
26
+ OptionsHelper::set_checkout_checkbox_enabled('1');
27
+ } else {
28
+ OptionsHelper::set_checkout_checkbox_enabled('0');
29
  }
30
+ OptionsHelper::set_checkout_checkbox_text(sanitize_text_field($_POST['ce4wp_checkbox_text']));
31
  }
32
+ }
33
 
34
  $contact_sync_available = !empty(CreativeMail::get_instance()->get_integration_manager()->get_active_plugins());
35
 
36
  ?>
37
 
38
  <div class="ce4wp-admin-wrapper">
39
+ <header class="ce4wp-swoosh-header"></header>
40
 
41
+ <div class="ce4wp-swoosh-container">
42
  <div style="margin-top: 0px;">
43
  <div class="ce4wp-backdrop">
44
  <div class="ce4wp-backdrop-container">
55
 
56
  <?php
57
  if (OptionsHelper::get_instance_id()) {
58
+ include 'unlink.php';
59
  }
60
  else {
61
+ include 'pending-setup.php';
62
  }
63
+ ?>
64
  </div>
65
  </div>
66
 
69
  <h2 class="ce4wp-typography-root ce4wp-typography-h2 ce4wp-mb-2">Contact Sync</h2>
70
 
71
  <?php
72
+ if ($contact_sync_available) {
73
+ include 'activated-integrations.php';
74
+ }
75
+ else {
76
+ include 'available-integrations.php';
77
+ }
78
+ ?>
79
  </div>
80
  </div>
81
 
82
  <?php
83
  if (EnvironmentHelper::is_test_environment()) {
84
+ include 'settings-internal.php';
85
  }
86
+ ?>
87
 
88
  <div class="ce4wp-card">
89
  <div class="ce4wp-px-4 ce4wp-py-4">
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit89dc2c82c00051b8500b11edfc1a216b::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit0b2d56d34d8e06197d46233b4a9b58b3::getLoader();
vendor/composer/autoload_classmap.php CHANGED
@@ -26,6 +26,7 @@ return array(
26
  'CreativeMail\\Modules\\Blog\\Models\\BlogPost' => $baseDir . '/src/modules/blog/models/BlogPost.php',
27
  'CreativeMail\\Modules\\Contacts\\Handlers\\BaseContactFormPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/BaseContactFormPluginHandler.php',
28
  'CreativeMail\\Modules\\Contacts\\Handlers\\ContactFormSevenPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/ContactFormSevenPluginHandler.php',
 
29
  'CreativeMail\\Modules\\Contacts\\Handlers\\GravityFormsPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/GravityFormsPluginHandler.php',
30
  'CreativeMail\\Modules\\Contacts\\Handlers\\JetpackPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/JetpackPluginHandler.php',
31
  'CreativeMail\\Modules\\Contacts\\Handlers\\NewsLetterContactFormPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/NewsLetterContactFormPluginHandler.php',
26
  'CreativeMail\\Modules\\Blog\\Models\\BlogPost' => $baseDir . '/src/modules/blog/models/BlogPost.php',
27
  'CreativeMail\\Modules\\Contacts\\Handlers\\BaseContactFormPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/BaseContactFormPluginHandler.php',
28
  'CreativeMail\\Modules\\Contacts\\Handlers\\ContactFormSevenPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/ContactFormSevenPluginHandler.php',
29
+ 'CreativeMail\\Modules\\Contacts\\Handlers\\ElementorPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/ElementorPluginHandler.php',
30
  'CreativeMail\\Modules\\Contacts\\Handlers\\GravityFormsPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/GravityFormsPluginHandler.php',
31
  'CreativeMail\\Modules\\Contacts\\Handlers\\JetpackPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/JetpackPluginHandler.php',
32
  'CreativeMail\\Modules\\Contacts\\Handlers\\NewsLetterContactFormPluginHandler' => $baseDir . '/src/modules/contacts/Handlers/NewsLetterContactFormPluginHandler.php',
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit89dc2c82c00051b8500b11edfc1a216b
6
  {
7
  private static $loader;
8
 
@@ -22,15 +22,15 @@ class ComposerAutoloaderInit89dc2c82c00051b8500b11edfc1a216b
22
  return self::$loader;
23
  }
24
 
25
- spl_autoload_register(array('ComposerAutoloaderInit89dc2c82c00051b8500b11edfc1a216b', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
27
- spl_autoload_unregister(array('ComposerAutoloaderInit89dc2c82c00051b8500b11edfc1a216b', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
  require_once __DIR__ . '/autoload_static.php';
32
 
33
- call_user_func(\Composer\Autoload\ComposerStaticInit89dc2c82c00051b8500b11edfc1a216b::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit0b2d56d34d8e06197d46233b4a9b58b3
6
  {
7
  private static $loader;
8
 
22
  return self::$loader;
23
  }
24
 
25
+ spl_autoload_register(array('ComposerAutoloaderInit0b2d56d34d8e06197d46233b4a9b58b3', 'loadClassLoader'), true, true);
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
27
+ spl_autoload_unregister(array('ComposerAutoloaderInit0b2d56d34d8e06197d46233b4a9b58b3', 'loadClassLoader'));
28
 
29
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
  if ($useStaticLoader) {
31
  require_once __DIR__ . '/autoload_static.php';
32
 
33
+ call_user_func(\Composer\Autoload\ComposerStaticInit0b2d56d34d8e06197d46233b4a9b58b3::getInitializer($loader));
34
  } else {
35
  $map = require __DIR__ . '/autoload_namespaces.php';
36
  foreach ($map as $namespace => $path) {
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit89dc2c82c00051b8500b11edfc1a216b
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'F' =>
@@ -82,6 +82,7 @@ class ComposerStaticInit89dc2c82c00051b8500b11edfc1a216b
82
  'CreativeMail\\Modules\\Blog\\Models\\BlogPost' => __DIR__ . '/../..' . '/src/modules/blog/models/BlogPost.php',
83
  'CreativeMail\\Modules\\Contacts\\Handlers\\BaseContactFormPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/BaseContactFormPluginHandler.php',
84
  'CreativeMail\\Modules\\Contacts\\Handlers\\ContactFormSevenPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/ContactFormSevenPluginHandler.php',
 
85
  'CreativeMail\\Modules\\Contacts\\Handlers\\GravityFormsPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/GravityFormsPluginHandler.php',
86
  'CreativeMail\\Modules\\Contacts\\Handlers\\JetpackPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/JetpackPluginHandler.php',
87
  'CreativeMail\\Modules\\Contacts\\Handlers\\NewsLetterContactFormPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/NewsLetterContactFormPluginHandler.php',
@@ -121,9 +122,9 @@ class ComposerStaticInit89dc2c82c00051b8500b11edfc1a216b
121
  public static function getInitializer(ClassLoader $loader)
122
  {
123
  return \Closure::bind(function () use ($loader) {
124
- $loader->prefixLengthsPsr4 = ComposerStaticInit89dc2c82c00051b8500b11edfc1a216b::$prefixLengthsPsr4;
125
- $loader->prefixDirsPsr4 = ComposerStaticInit89dc2c82c00051b8500b11edfc1a216b::$prefixDirsPsr4;
126
- $loader->classMap = ComposerStaticInit89dc2c82c00051b8500b11edfc1a216b::$classMap;
127
 
128
  }, null, ClassLoader::class);
129
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInit0b2d56d34d8e06197d46233b4a9b58b3
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'F' =>
82
  'CreativeMail\\Modules\\Blog\\Models\\BlogPost' => __DIR__ . '/../..' . '/src/modules/blog/models/BlogPost.php',
83
  'CreativeMail\\Modules\\Contacts\\Handlers\\BaseContactFormPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/BaseContactFormPluginHandler.php',
84
  'CreativeMail\\Modules\\Contacts\\Handlers\\ContactFormSevenPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/ContactFormSevenPluginHandler.php',
85
+ 'CreativeMail\\Modules\\Contacts\\Handlers\\ElementorPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/ElementorPluginHandler.php',
86
  'CreativeMail\\Modules\\Contacts\\Handlers\\GravityFormsPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/GravityFormsPluginHandler.php',
87
  'CreativeMail\\Modules\\Contacts\\Handlers\\JetpackPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/JetpackPluginHandler.php',
88
  'CreativeMail\\Modules\\Contacts\\Handlers\\NewsLetterContactFormPluginHandler' => __DIR__ . '/../..' . '/src/modules/contacts/Handlers/NewsLetterContactFormPluginHandler.php',
122
  public static function getInitializer(ClassLoader $loader)
123
  {
124
  return \Closure::bind(function () use ($loader) {
125
+ $loader->prefixLengthsPsr4 = ComposerStaticInit0b2d56d34d8e06197d46233b4a9b58b3::$prefixLengthsPsr4;
126
+ $loader->prefixDirsPsr4 = ComposerStaticInit0b2d56d34d8e06197d46233b4a9b58b3::$prefixDirsPsr4;
127
+ $loader->classMap = ComposerStaticInit0b2d56d34d8e06197d46233b4a9b58b3::$classMap;
128
 
129
  }, null, ClassLoader::class);
130
  }