← All changes
|
app/Services/Integrations/MailChimp/MailChimpIntegration.php
+216
-160
3.6.62
→
6.2.15
View file →
| @@ -1,14 +1,17 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentForm\App\Services\Integrations\MailChimp; |
| 4 | 4 | |
| 5 | -use FluentForm\App\Services\Integrations\IntegrationManager; | |
| 5 | +defined('ABSPATH') or die; | |
| 6 | + | |
| 7 | +use FluentForm\App\Http\Controllers\IntegrationManagerController; | |
| 8 | +use FluentForm\App\Modules\Acl\Acl; | |
| 6 | 9 | use FluentForm\App\Services\Integrations\MailChimp\MailChimpSubscriber as Subscriber; |
| 7 | 10 | use FluentForm\Framework\Foundation\Application; |
| 8 | 11 | use FluentForm\Framework\Helpers\ArrayHelper; |
| 9 | 12 | |
| 10 | -class MailChimpIntegration extends IntegrationManager | |
| 13 | +class MailChimpIntegration extends IntegrationManagerController | |
| 11 | 14 | { |
| 12 | 15 | /** |
| 13 | 16 | * MailChimp Subscriber that handles & process all the subscribing logics. |
| 14 | 17 | */ |
| @@ -17,9 +20,9 @@ | ||
| 17 | 20 | public function __construct(Application $application) |
| 18 | 21 | { |
| 19 | 22 | parent::__construct( |
| 20 | 23 | $application, |
| 21 | - 'MailChimp', | |
| 24 | + 'Mailchimp', | |
| 22 | 25 | 'mailchimp', |
| 23 | 26 | '_fluentform_mailchimp_details', |
| 24 | 27 | 'mailchimp_feeds', |
| 25 | 28 | 12 |
| @@ -24,16 +27,18 @@ | ||
| 24 | 27 | 'mailchimp_feeds', |
| 25 | 28 | 12 |
| 26 | 29 | ); |
| 27 | 30 | |
| 28 | - $this->description = 'WP Fluent Forms Mailchimp module allows you to create Mailchimp newsletter signup forms in WordPress'; | |
| 31 | + $this->description = __('Fluent Forms Mailchimp module allows you to create Mailchimp newsletter signup forms in WordPress', 'fluentform'); | |
| 29 | 32 | |
| 30 | - $this->logo = $this->app->url('public/img/integrations/mailchimp.png'); | |
| 33 | + $this->logo = fluentFormMix('img/integrations/mailchimp.png'); | |
| 31 | 34 | $this->registerAdminHooks(); |
| 32 | - | |
| 33 | - add_action('wp_ajax_fluentform_mailchimp_interest_groups', array($this, 'fetchInterestGroups')); | |
| 34 | 35 | |
| 35 | -// add_filter('fluentform_notifying_async_mailchimp', '__return_false'); | |
| 36 | + add_action('wp_ajax_fluentform_mailchimp_interest_groups', [$this, 'fetchInterestGroups']); | |
| 37 | + | |
| 38 | + add_filter('fluentform/save_integration_value_mailchimp', [$this, 'sanitizeSettings'], 10, 3); | |
| 39 | + | |
| 40 | + // add_filter('fluentform/notifying_async_mailchimp', '__return_false'); | |
| 36 | 41 | } |
| 37 | 42 | |
| 38 | 43 | public function getGlobalFields($fields) |
| 39 | 44 | { |
| @@ -39,9 +44,9 @@ | ||
| 39 | 44 | { |
| 40 | 45 | return [ |
| 41 | 46 | 'logo' => $this->logo, |
| 42 | 47 | 'menu_title' => __('Mailchimp Settings', 'fluentform'), |
| 43 | - 'menu_description' => __('Mailchimp is a marketing platform for small businesses. Send beautiful emails, connect your e-commerce store, advertise, and build your brand. Use Fluent Form to collect customer information and automatically add it to your Mailchimp campaign list. If you don\'t have a Mailchimp account, you can <a href="http://www.mailchimp.com/" target="_blank">sign up for one here.</a>', 'fluentform'), | |
| 48 | + 'menu_description' => __('Mailchimp is a marketing platform for small businesses. Send beautiful emails, connect your e-commerce store, advertise, and build your brand. Use Fluent Forms to collect customer information and automatically add it to your Mailchimp campaign list. If you don\'t have a Mailchimp account, you can <a href="https://mailchimp.com/" target="_blank">sign up for one here.</a>', 'fluentform'), | |
| 44 | 49 | 'valid_message' => __('Your Mailchimp API Key is valid', 'fluentform'), |
| 45 | 50 | 'invalid_message' => __('Your Mailchimp API Key is not valid', 'fluentform'), |
| 46 | 51 | 'save_button_text' => __('Save Settings', 'fluentform'), |
| 47 | 52 | 'fields' => [ |
| @@ -46,21 +51,21 @@ | ||
| 46 | 51 | 'save_button_text' => __('Save Settings', 'fluentform'), |
| 47 | 52 | 'fields' => [ |
| 48 | 53 | 'apiKey' => [ |
| 49 | 54 | 'type' => 'text', |
| 50 | - 'label_tips' => __("Enter your Mailchimp API Key, if you do not have <br>Please login to your MailChimp account and go to<br>Profile -> Extras -> Api Keys", 'fluentform'), | |
| 55 | + 'label_tips' => __('Enter your Mailchimp API Key, if you do not have <br>Please login to your Mailchimp account and go to<br>Profile -> Extras -> Api Keys', 'fluentform'), | |
| 51 | 56 | 'label' => __('Mailchimp API Key', 'fluentform'), |
| 52 | - ] | |
| 57 | + ], | |
| 53 | 58 | ], |
| 54 | 59 | 'hide_on_valid' => true, |
| 55 | 60 | 'discard_settings' => [ |
| 56 | - 'section_description' => 'Your Mailchimp API integration is up and running', | |
| 57 | - 'button_text' => 'Disconnect Mailchimp', | |
| 61 | + 'section_description' => __('Your Mailchimp API integration is up and running', 'fluentform'), | |
| 62 | + 'button_text' => __('Disconnect Mailchimp', 'fluentform'), | |
| 58 | 63 | 'data' => [ |
| 59 | - 'apiKey' => '' | |
| 64 | + 'apiKey' => '', | |
| 60 | 65 | ], |
| 61 | - 'show_verify' => true | |
| 62 | - ] | |
| 66 | + 'show_verify' => true, | |
| 67 | + ], | |
| 63 | 68 | ]; |
| 64 | 69 | } |
| 65 | 70 | |
| 66 | 71 | public function getGlobalSettings($settings) |
| @@ -65,14 +70,14 @@ | ||
| 65 | 70 | |
| 66 | 71 | public function getGlobalSettings($settings) |
| 67 | 72 | { |
| 68 | 73 | $globalSettings = get_option($this->optionKey); |
| 69 | - if (!$globalSettings) { | |
| 74 | + if (! $globalSettings) { | |
| 70 | 75 | $globalSettings = []; |
| 71 | 76 | } |
| 72 | 77 | $defaults = [ |
| 73 | 78 | 'apiKey' => '', |
| 74 | - 'status' => '' | |
| 79 | + 'status' => '', | |
| 75 | 80 | ]; |
| 76 | 81 | |
| 77 | 82 | return wp_parse_args($globalSettings, $defaults); |
| 78 | 83 | } |
| @@ -78,18 +83,18 @@ | ||
| 78 | 83 | } |
| 79 | 84 | |
| 80 | 85 | public function saveGlobalSettings($mailChimp) |
| 81 | 86 | { |
| 82 | - if (!$mailChimp['apiKey']) { | |
| 87 | + if (! $mailChimp['apiKey']) { | |
| 83 | 88 | $mailChimpSettings = [ |
| 84 | 89 | 'apiKey' => '', |
| 85 | - 'status' => false | |
| 90 | + 'status' => false, | |
| 86 | 91 | ]; |
| 87 | 92 | // Update the reCaptcha details with siteKey & secretKey. |
| 88 | 93 | update_option($this->optionKey, $mailChimpSettings, 'no'); |
| 89 | 94 | wp_send_json_success([ |
| 90 | 95 | 'message' => __('Your settings has been updated and disconnected', 'fluentform'), |
| 91 | - 'status' => false | |
| 96 | + 'status' => false, | |
| 92 | 97 | ], 200); |
| 93 | 98 | } |
| 94 | 99 | |
| 95 | 100 | // Verify API key now |
| @@ -95,22 +100,22 @@ | ||
| 95 | 100 | // Verify API key now |
| 96 | 101 | try { |
| 97 | 102 | $MailChimp = new MailChimp($mailChimp['apiKey']); |
| 98 | 103 | $result = $MailChimp->get('lists'); |
| 99 | - if (!$MailChimp->success()) { | |
| 104 | + if (! $MailChimp->success()) { | |
| 100 | 105 | throw new \Exception($MailChimp->getLastError()); |
| 101 | 106 | } |
| 102 | 107 | } catch (\Exception $exception) { |
| 103 | 108 | wp_send_json_error([ |
| 104 | - 'message' => $exception->getMessage() | |
| 109 | + 'message' => $exception->getMessage(), | |
| 105 | 110 | ], 400); |
| 106 | 111 | } |
| 107 | 112 | |
| 108 | - // MailChimp key is verified now, Proceed now | |
| 113 | + // Mailchimp key is verified now, Proceed now | |
| 109 | 114 | |
| 110 | 115 | $mailChimpSettings = [ |
| 111 | 116 | 'apiKey' => sanitize_text_field($mailChimp['apiKey']), |
| 112 | - 'status' => true | |
| 117 | + 'status' => true, | |
| 113 | 118 | ]; |
| 114 | 119 | |
| 115 | 120 | // Update the reCaptcha details with siteKey & secretKey. |
| 116 | 121 | update_option($this->optionKey, $mailChimpSettings, 'no`'); |
| @@ -115,10 +120,10 @@ | ||
| 115 | 120 | // Update the reCaptcha details with siteKey & secretKey. |
| 116 | 121 | update_option($this->optionKey, $mailChimpSettings, 'no`'); |
| 117 | 122 | |
| 118 | 123 | wp_send_json_success([ |
| 119 | - 'message' => __('Your mailchimp api key has been verfied and successfully set', 'fluentform'), | |
| 120 | - 'status' => true | |
| 124 | + 'message' => __('Your mailchimp api key has been verified and successfully set', 'fluentform'), | |
| 125 | + 'status' => true, | |
| 121 | 126 | ], 200); |
| 122 | 127 | } |
| 123 | 128 | |
| 124 | 129 | public function pushIntegration($integrations, $formId) |
| @@ -127,11 +132,11 @@ | ||
| 127 | 132 | 'title' => __('Mailchimp Feed', 'fluentform'), |
| 128 | 133 | 'logo' => $this->logo, |
| 129 | 134 | 'is_active' => $this->isConfigured(), |
| 130 | 135 | 'configure_title' => __('Configuration required!', 'fluentform'), |
| 131 | - 'global_configure_url' => admin_url('admin.php?page=fluent_forms_settings#mailchimp'), | |
| 136 | + 'global_configure_url' => admin_url('admin.php?page=fluent_forms_settings#general-mailchimp-settings'), | |
| 132 | 137 | 'configure_message' => __('Mailchimp is not configured yet! Please configure your mailchimp api first', 'fluentform'), |
| 133 | - 'configure_button_text' => __('Set Mailchimp API', 'fluentform') | |
| 138 | + 'configure_button_text' => __('Set Mailchimp API', 'fluentform'), | |
| 134 | 139 | ]; |
| 135 | 140 | |
| 136 | 141 | return $integrations; |
| 137 | 142 | } |
| @@ -138,25 +143,26 @@ | ||
| 138 | 143 | |
| 139 | 144 | public function getIntegrationDefaults($settings, $formId) |
| 140 | 145 | { |
| 141 | 146 | $settings = [ |
| 142 | - 'conditionals' => [ | |
| 147 | + 'conditionals' => [ | |
| 143 | 148 | 'conditions' => [], |
| 144 | 149 | 'status' => false, |
| 145 | - 'type' => 'all' | |
| 150 | + 'type' => 'all', | |
| 146 | 151 | ], |
| 147 | - 'enabled' => true, | |
| 148 | - 'list_id' => '', | |
| 149 | - 'list_name' => '', | |
| 150 | - 'name' => '', | |
| 151 | - 'merge_fields' => (object)[], | |
| 152 | - 'tags' => '', | |
| 152 | + 'enabled' => true, | |
| 153 | + 'list_id' => '', | |
| 154 | + 'list_name' => '', | |
| 155 | + 'name' => '', | |
| 156 | + 'merge_fields' => (object) [], | |
| 157 | + 'tags' => '', | |
| 153 | 158 | 'tag_routers' => [], |
| 154 | 159 | 'tag_ids_selection_type' => 'simple', |
| 155 | - 'markAsVIP' => false, | |
| 156 | - 'fieldEmailAddress' => '', | |
| 157 | - 'doubleOptIn' => false, | |
| 158 | - 'note' => '' | |
| 160 | + 'markAsVIP' => false, | |
| 161 | + 'fieldEmailAddress' => '', | |
| 162 | + 'doubleOptIn' => false, | |
| 163 | + 'resubscribe' => false, | |
| 164 | + 'note' => '', | |
| 159 | 165 | ]; |
| 160 | 166 | |
| 161 | 167 | return $settings; |
| 162 | 168 | } |
| @@ -163,21 +169,21 @@ | ||
| 163 | 169 | |
| 164 | 170 | public function getSettingsFields($settings, $formId) |
| 165 | 171 | { |
| 166 | 172 | return [ |
| 167 | - 'fields' => [ | |
| 173 | + 'fields' => [ | |
| 168 | 174 | [ |
| 169 | 175 | 'key' => 'name', |
| 170 | - 'label' => 'Name', | |
| 176 | + 'label' => __('Name', 'fluentform'), | |
| 171 | 177 | 'required' => true, |
| 172 | - 'placeholder' => 'Your Feed Name', | |
| 173 | - 'component' => 'text' | |
| 178 | + 'placeholder' => __('Your Feed Name', 'fluentform'), | |
| 179 | + 'component' => 'text', | |
| 174 | 180 | ], |
| 175 | 181 | [ |
| 176 | 182 | 'key' => 'list_id', |
| 177 | - 'label' => 'Mailchimp List', | |
| 178 | - 'placeholder' => 'Select Mailchimp List', | |
| 179 | - 'tips' => 'Select the Mailchimp list you would like to add your contacts to.', | |
| 183 | + 'label' => __('Mailchimp List', 'fluentform'), | |
| 184 | + 'placeholder' => __('Select Mailchimp List', 'fluentform'), | |
| 185 | + 'tips' => __('Select the Mailchimp list you would like to add your contacts to.', 'fluentform'), | |
| 180 | 186 | 'component' => 'list_ajax_options', |
| 181 | 187 | 'options' => $this->getLists(), |
| 182 | 188 | ], |
| 183 | 189 | [ |
| @@ -182,114 +188,118 @@ | ||
| 182 | 188 | ], |
| 183 | 189 | [ |
| 184 | 190 | 'key' => 'merge_fields', |
| 185 | 191 | 'require_list' => true, |
| 186 | - 'label' => 'Map Fields', | |
| 187 | - 'tips' => 'Associate your Mailchimp merge tags to the appropriate Fluent Form fields by selecting the appropriate form field from the list.', | |
| 192 | + 'label' => __('Map Fields', 'fluentform'), | |
| 193 | + 'tips' => __('Associate your Mailchimp merge tags to the appropriate Fluent Forms fields by selecting the appropriate form field from the list. Also, Mailchimp Date fields supports only MM/DD/YYYY and DD/MM/YYYY format.', 'fluentform'), | |
| 188 | 194 | 'component' => 'map_fields', |
| 189 | - 'field_label_remote' => 'Mailchimp Field', | |
| 190 | - 'field_label_local' => 'Form Field', | |
| 195 | + 'field_label_remote' => __('Mailchimp Field', 'fluentform'), | |
| 196 | + 'field_label_local' => __('Form Field', 'fluentform'), | |
| 191 | 197 | 'primary_fileds' => [ |
| 192 | 198 | [ |
| 193 | 199 | 'key' => 'fieldEmailAddress', |
| 194 | - 'label' => 'Email Address', | |
| 200 | + 'label' => __('Email Address', 'fluentform'), | |
| 195 | 201 | 'required' => true, |
| 196 | - 'input_options' => 'emails' | |
| 197 | - ] | |
| 198 | - ] | |
| 202 | + 'input_options' => 'emails', | |
| 203 | + ], | |
| 204 | + ], | |
| 199 | 205 | ], |
| 200 | 206 | [ |
| 201 | - 'key' => 'interest_group', | |
| 202 | - 'require_list' => true, | |
| 203 | - 'label' => 'Interest Group', | |
| 204 | - 'tips' => 'You can map your mailchimp interest group for this contact', | |
| 205 | - 'component' => 'chained_fields', | |
| 206 | - 'sub_type' => 'radio', | |
| 207 | - 'category_label' => 'Select Interest Category', | |
| 208 | - 'subcategory_label' => 'Select Interest', | |
| 209 | - 'remote_url' => admin_url('admin-ajax.php?action=fluentform_mailchimp_interest_groups'), | |
| 210 | - 'inline_tip' => 'Select the mailchimp interest category and interest' | |
| 207 | + 'key' => 'interest_group', | |
| 208 | + 'require_list' => true, | |
| 209 | + 'label' => __('Interest Group', 'fluentform'), | |
| 210 | + 'tips' => __('You can map your mailchimp interest group for this contact', 'fluentform'), | |
| 211 | + 'component' => 'chained_fields', | |
| 212 | + 'sub_type' => 'radio', | |
| 213 | + 'category_label' => __('Select Interest Category', 'fluentform'), | |
| 214 | + 'subcategory_label' => __('Select Interest', 'fluentform'), | |
| 215 | + 'remote_url' => add_query_arg([ | |
| 216 | + 'action' => 'fluentform_mailchimp_interest_groups', | |
| 217 | + 'form_id' => (int) $formId, | |
| 218 | + ], admin_url('admin-ajax.php')), | |
| 219 | + 'inline_tip' => __('Select the mailchimp interest category and interest', 'fluentform'), | |
| 211 | 220 | ], |
| 212 | 221 | [ |
| 213 | - 'key' => 'tags', | |
| 214 | - 'require_list' => true, | |
| 215 | - 'label' => 'Tags', | |
| 216 | - 'tips' => 'Associate tags to your MailChimp contacts with a comma separated list (e.g. new lead, FluentForms, web source). Commas within a merge tag value will be created as a single tag.', | |
| 217 | - 'component' => 'selection_routing', | |
| 218 | - 'simple_component' => 'value_text', | |
| 222 | + 'key' => 'tags', | |
| 223 | + 'require_list' => true, | |
| 224 | + 'label' => __('Tags', 'fluentform'), | |
| 225 | + 'tips' => __('Associate tags to your Mailchimp contacts with a comma separated list (e.g. new lead, FluentForms, web source). Commas within a merge tag value will be created as a single tag.', 'fluentform'), | |
| 226 | + 'component' => 'selection_routing', | |
| 227 | + 'simple_component' => 'value_text', | |
| 219 | 228 | 'routing_input_type' => 'text', |
| 220 | - 'routing_key' => 'tag_ids_selection_type', | |
| 221 | - 'settings_key' => 'tag_routers', | |
| 222 | - 'labels' => [ | |
| 223 | - 'choice_label' => 'Enable Dynamic Tag Input', | |
| 229 | + 'routing_key' => 'tag_ids_selection_type', | |
| 230 | + 'settings_key' => 'tag_routers', | |
| 231 | + 'labels' => [ | |
| 232 | + 'choice_label' => __('Enable Dynamic Tag Input', 'fluentform'), | |
| 224 | 233 | 'input_label' => '', |
| 225 | - 'input_placeholder' => 'Tag' | |
| 234 | + 'input_placeholder' => __('Tag', 'fluentform'), | |
| 226 | 235 | ], |
| 227 | - 'inline_tip' => 'Please provide each tag by comma separated value, You can use dynamic smart codes' | |
| 236 | + 'inline_tip' => __('Please provide each tag by comma separated value, You can use dynamic smart codes', 'fluentform'), | |
| 228 | 237 | ], |
| 229 | 238 | [ |
| 230 | 239 | 'key' => 'note', |
| 231 | 240 | 'require_list' => true, |
| 232 | - 'label' => 'Note', | |
| 233 | - 'tips' => 'You can write a note for this contact', | |
| 234 | - 'component' => 'value_textarea' | |
| 241 | + 'label' => __('Note', 'fluentform'), | |
| 242 | + 'tips' => __('You can write a note for this contact', 'fluentform'), | |
| 243 | + 'component' => 'value_textarea', | |
| 235 | 244 | ], |
| 236 | 245 | [ |
| 237 | - 'key' => 'doubleOptIn', | |
| 238 | - 'require_list' => true, | |
| 239 | - 'label' => 'Double Opt-in', | |
| 240 | - 'tips' => 'When the double opt-in option is enabled,<br />Mailchimp will send a confirmation email<br />to the user and will only add them to your <br /Mailchimp list upon confirmation.', | |
| 241 | - 'component' => 'checkbox-single', | |
| 242 | - 'checkbox_label' => 'Enable Double Opt-in' | |
| 246 | + 'key' => 'doubleOptIn', | |
| 247 | + 'require_list' => true, | |
| 248 | + 'label' => __('Double Opt-in', 'fluentform'), | |
| 249 | + 'tips' => __('When the double opt-in option is enabled, Mailchimp will send a confirmation email to the user and will only add them to your <br /Mailchimp list upon confirmation.', 'fluentform'), | |
| 250 | + 'component' => 'checkbox-single', | |
| 251 | + 'checkbox_label' => __('Enable Double Opt-in', 'fluentform'), | |
| 243 | 252 | ], |
| 244 | 253 | [ |
| 245 | - 'key' => 'markAsVIP', | |
| 246 | - 'require_list' => true, | |
| 247 | - 'label' => 'VIP', | |
| 248 | - 'tips' => 'When enabled,<br /> This contact will be marked as VIP.', | |
| 249 | - 'component' => 'checkbox-single', | |
| 250 | - 'checkbox_label' => 'Mark as VIP Contact' | |
| 254 | + 'key' => 'resubscribe', | |
| 255 | + 'require_list' => true, | |
| 256 | + 'label' => __('ReSubscribe', 'fluentform'), | |
| 257 | + 'tips' => __('When this option is enabled, if the subscriber is in an inactive state or has previously been unsubscribed, they will be re-added to the active list. Therefore, this option should be used with caution and only when appropriate.', 'fluentform'), | |
| 258 | + 'component' => 'checkbox-single', | |
| 259 | + 'checkbox_label' => __('Enable ReSubscription', 'fluentform'), | |
| 251 | 260 | ], |
| 252 | 261 | [ |
| 262 | + 'key' => 'markAsVIP', | |
| 263 | + 'require_list' => true, | |
| 264 | + 'label' => __('VIP', 'fluentform'), | |
| 265 | + 'tips' => __('When enabled, This contact will be marked as VIP.', 'fluentform'), | |
| 266 | + 'component' => 'checkbox-single', | |
| 267 | + 'checkbox_label' => __('Mark as VIP Contact', 'fluentform'), | |
| 268 | + ], | |
| 269 | + [ | |
| 253 | 270 | 'require_list' => true, |
| 254 | 271 | 'key' => 'conditionals', |
| 255 | - 'label' => 'Conditional Logics', | |
| 256 | - 'tips' => 'Allow mailchimp integration conditionally based on your submission values', | |
| 257 | - 'component' => 'conditional_block' | |
| 272 | + 'label' => __('Conditional Logics', 'fluentform'), | |
| 273 | + 'tips' => __('Allow mailchimp integration conditionally based on your submission values', 'fluentform'), | |
| 274 | + 'component' => 'conditional_block', | |
| 258 | 275 | ], |
| 259 | 276 | [ |
| 260 | - 'require_list' => true, | |
| 261 | - 'key' => 'enabled', | |
| 262 | - 'label' => 'Status', | |
| 263 | - 'component' => 'checkbox-single', | |
| 264 | - 'checkbox_label' => 'Enable This feed' | |
| 265 | - ] | |
| 277 | + 'require_list' => true, | |
| 278 | + 'key' => 'enabled', | |
| 279 | + 'label' => __('Status', 'fluentform'), | |
| 280 | + 'component' => 'checkbox-single', | |
| 281 | + 'checkbox_label' => __('Enable This feed', 'fluentform'), | |
| 282 | + ], | |
| 266 | 283 | ], |
| 267 | 284 | 'button_require_list' => true, |
| 268 | - 'integration_title' => 'Mailchimp' | |
| 285 | + 'integration_title' => __('Mailchimp', 'fluentform'), | |
| 269 | 286 | ]; |
| 270 | 287 | } |
| 271 | 288 | |
| 272 | - public function setFeedAtributes($feed, $formId) | |
| 273 | - { | |
| 274 | - $feed['provider'] = 'mailchimp'; | |
| 275 | - $feed['provider_logo'] = $this->logo; | |
| 276 | - return $feed; | |
| 277 | - } | |
| 278 | - | |
| 279 | 289 | public function prepareIntegrationFeed($setting, $feed, $formId) |
| 280 | 290 | { |
| 281 | 291 | $defaults = $this->getIntegrationDefaults([], $formId); |
| 282 | 292 | |
| 283 | 293 | foreach ($setting as $settingKey => $settingValue) { |
| 284 | - if ($settingValue == 'true') { | |
| 294 | + if ('true' == $settingValue) { | |
| 285 | 295 | $setting[$settingKey] = true; |
| 286 | - } else if ($settingValue == 'false') { | |
| 296 | + } elseif ('false' == $settingValue) { | |
| 287 | 297 | $setting[$settingKey] = false; |
| 288 | - } else if ($settingKey == 'conditionals') { | |
| 289 | - if ($settingValue['status'] == 'true') { | |
| 298 | + } elseif ('conditionals' == $settingKey) { | |
| 299 | + if ('true' == $settingValue['status']) { | |
| 290 | 300 | $settingValue['status'] = true; |
| 291 | - } else if ($settingValue['status'] == 'false') { | |
| 301 | + } elseif ('false' == $settingValue['status']) { | |
| 292 | 302 | $settingValue['status'] = false; |
| 293 | 303 | } |
| 294 | 304 | $setting['conditionals'] = $settingValue; |
| 295 | 305 | } |
| @@ -294,10 +304,10 @@ | ||
| 294 | 304 | $setting['conditionals'] = $settingValue; |
| 295 | 305 | } |
| 296 | 306 | } |
| 297 | 307 | |
| 298 | - if (!empty($setting['list_id'])) { | |
| 299 | - $setting['list_id'] = (string)$setting['list_id']; | |
| 308 | + if (! empty($setting['list_id'])) { | |
| 309 | + $setting['list_id'] = (string) $setting['list_id']; | |
| 300 | 310 | } |
| 301 | 311 | |
| 302 | 312 | $settings['markAsVIP'] = ArrayHelper::isTrue($setting, 'markAsVIP'); |
| 303 | 313 | $settings['doubleOptIn'] = ArrayHelper::isTrue($setting, 'doubleOptIn'); |
| @@ -309,10 +319,10 @@ | ||
| 309 | 319 | { |
| 310 | 320 | $settings = get_option('_fluentform_mailchimp_details'); |
| 311 | 321 | try { |
| 312 | 322 | $MailChimp = new MailChimp($settings['apiKey']); |
| 313 | - $lists = $MailChimp->get('lists', array('count' => 9999)); | |
| 314 | - if (!$MailChimp->success()) { | |
| 323 | + $lists = $MailChimp->get('lists', ['count' => 9999]); | |
| 324 | + if (! $MailChimp->success()) { | |
| 315 | 325 | return []; |
| 316 | 326 | } |
| 317 | 327 | } catch (\Exception $exception) { |
| 318 | 328 | return []; |
| @@ -318,10 +328,12 @@ | ||
| 318 | 328 | return []; |
| 319 | 329 | } |
| 320 | 330 | |
| 321 | 331 | $formattedLists = []; |
| 322 | - foreach ($lists['lists'] as $list) { | |
| 323 | - $formattedLists[$list['id']] = $list['name']; | |
| 332 | + if (is_array($lists) && isset($lists['lists'])) { | |
| 333 | + foreach ($lists['lists'] as $list) { | |
| 334 | + $formattedLists[$list['id']] = $list['name']; | |
| 335 | + } | |
| 324 | 336 | } |
| 325 | 337 | |
| 326 | 338 | return $formattedLists; |
| 327 | 339 | } |
| @@ -327,18 +339,33 @@ | ||
| 327 | 339 | } |
| 328 | 340 | |
| 329 | 341 | public function getMergeFields($list, $listId, $formId) |
| 330 | 342 | { |
| 343 | + if (! $this->isConfigured()) { | |
| 344 | + return false; | |
| 345 | + } | |
| 331 | 346 | |
| 332 | - if (!$this->isConfigured()) { | |
| 333 | - return false; | |
| 347 | + $mergedFields = $this->findMergeFields($listId); | |
| 348 | + | |
| 349 | + $fields = []; | |
| 350 | + | |
| 351 | + foreach ($mergedFields as $merged_field) { | |
| 352 | + $fields[$merged_field['tag']] = $merged_field['name']; | |
| 334 | 353 | } |
| 354 | + | |
| 355 | + return $fields; | |
| 356 | + } | |
| 357 | + | |
| 358 | + public function findMergeFields($listId) | |
| 359 | + { | |
| 335 | 360 | $settings = get_option('_fluentform_mailchimp_details'); |
| 336 | 361 | |
| 337 | 362 | try { |
| 338 | 363 | $MailChimp = new MailChimp($settings['apiKey']); |
| 339 | - $list = $MailChimp->get('lists/' . $listId . '/merge-fields', array('count' => 9999)); | |
| 340 | - if (!$MailChimp->success()) { | |
| 364 | + | |
| 365 | + $list = $MailChimp->get('lists/' . $listId . '/merge-fields', ['count' => 9999]); | |
| 366 | + | |
| 367 | + if (! $MailChimp->success()) { | |
| 341 | 368 | return false; |
| 342 | 369 | } |
| 343 | 370 | } catch (\Exception $exception) { |
| 344 | 371 | return false; |
| @@ -343,43 +370,43 @@ | ||
| 343 | 370 | } catch (\Exception $exception) { |
| 344 | 371 | return false; |
| 345 | 372 | } |
| 346 | 373 | |
| 347 | - $mergedFields = $list['merge_fields']; | |
| 348 | - $fields = array(); | |
| 349 | - | |
| 350 | - foreach ($mergedFields as $merged_field) { | |
| 351 | - $fields[$merged_field['tag']] = $merged_field['name']; | |
| 352 | - } | |
| 353 | - | |
| 354 | - return $fields; | |
| 374 | + return $list['merge_fields']; | |
| 355 | 375 | } |
| 356 | 376 | |
| 357 | 377 | public function fetchInterestGroups() |
| 358 | 378 | { |
| 359 | - $settings = $_REQUEST['settings']; | |
| 379 | + // SECURITY (FINDING-04): this AJAX action reads the site's global Mailchimp API key and | |
| 380 | + // issues an authenticated request on the caller's behalf; it had no capability/nonce check. | |
| 381 | + // Acl::verify enforces both the capability and the fluent_forms_admin_nonce for AJAX. | |
| 382 | + $formId = Acl::verifyFormId($this->app->request->get('form_id')); | |
| 383 | + Acl::verify('fluentform_forms_manager', $formId); | |
| 360 | 384 | |
| 361 | - $listId = ArrayHelper::get($settings, 'list_id'); | |
| 362 | - if(!$listId) { | |
| 385 | + $settings = $this->app->request->get('settings', []); | |
| 386 | + $settings = is_array($settings) ? wp_unslash($settings) : []; | |
| 387 | + | |
| 388 | + $listId = sanitize_text_field((string) ArrayHelper::get($settings, 'list_id')); | |
| 389 | + if (! $listId) { | |
| 363 | 390 | wp_send_json_success([ |
| 364 | - 'categories' => [], | |
| 391 | + 'categories' => [], | |
| 365 | 392 | 'subcategories' => [], |
| 366 | - 'reset_values' => true | |
| 393 | + 'reset_values' => true, | |
| 367 | 394 | ]); |
| 368 | 395 | } |
| 369 | 396 | |
| 370 | - $categoryId = ArrayHelper::get($settings, 'interest_group.category'); | |
| 397 | + $categoryId = sanitize_text_field((string) ArrayHelper::get($settings, 'interest_group.category')); | |
| 371 | 398 | $categories = $this->getInterestCategories($listId); |
| 372 | 399 | |
| 373 | 400 | $subCategories = []; |
| 374 | - if($categoryId) { | |
| 401 | + if ($categoryId) { | |
| 375 | 402 | $subCategories = $this->getInterestSubCategories($listId, $categoryId); |
| 376 | 403 | } |
| 377 | 404 | |
| 378 | 405 | wp_send_json_success([ |
| 379 | - 'categories' => $categories, | |
| 406 | + 'categories' => $categories, | |
| 380 | 407 | 'subcategories' => $subCategories, |
| 381 | - 'reset_values' => !$categories && !$subCategories | |
| 408 | + 'reset_values' => ! $categories && ! $subCategories, | |
| 382 | 409 | ]); |
| 383 | 410 | } |
| 384 | 411 | |
| 385 | 412 | private function getInterestCategories($listId) |
| @@ -386,13 +413,13 @@ | ||
| 386 | 413 | { |
| 387 | 414 | $settings = get_option('_fluentform_mailchimp_details'); |
| 388 | 415 | try { |
| 389 | 416 | $MailChimp = new MailChimp($settings['apiKey']); |
| 390 | - $categories = $MailChimp->get('/lists/'.$listId.'/interest-categories', array( | |
| 391 | - 'count' => 9999, | |
| 392 | - 'fields' => 'categories.id,categories.title' | |
| 393 | - )); | |
| 394 | - if (!$MailChimp->success()) { | |
| 417 | + $categories = $MailChimp->get('/lists/' . $listId . '/interest-categories', [ | |
| 418 | + 'count' => 9999, | |
| 419 | + 'fields' => 'categories.id,categories.title', | |
| 420 | + ]); | |
| 421 | + if (! $MailChimp->success()) { | |
| 395 | 422 | return []; |
| 396 | 423 | } |
| 397 | 424 | } catch (\Exception $exception) { |
| 398 | 425 | return []; |
| @@ -400,10 +427,10 @@ | ||
| 400 | 427 | $categories = ArrayHelper::get($categories, 'categories', []); |
| 401 | 428 | $formattedLists = []; |
| 402 | 429 | foreach ($categories as $list) { |
| 403 | 430 | $formattedLists[] = [ |
| 404 | - 'value' => $list['id'], | |
| 405 | - 'label' => $list['title'] | |
| 431 | + 'value' => $list['id'], | |
| 432 | + 'label' => $list['title'], | |
| 406 | 433 | ]; |
| 407 | 434 | } |
| 408 | 435 | return $formattedLists; |
| 409 | 436 | } |
| @@ -412,13 +439,13 @@ | ||
| 412 | 439 | { |
| 413 | 440 | $settings = get_option('_fluentform_mailchimp_details'); |
| 414 | 441 | try { |
| 415 | 442 | $MailChimp = new MailChimp($settings['apiKey']); |
| 416 | - $categories = $MailChimp->get('/lists/'.$listId.'/interest-categories/'.$categoryId.'/interests', array( | |
| 417 | - 'count' => 9999, | |
| 418 | - 'fields' => 'interests.id,interests.name' | |
| 419 | - )); | |
| 420 | - if (!$MailChimp->success()) { | |
| 443 | + $categories = $MailChimp->get('/lists/' . $listId . '/interest-categories/' . $categoryId . '/interests', [ | |
| 444 | + 'count' => 9999, | |
| 445 | + 'fields' => 'interests.id,interests.name', | |
| 446 | + ]); | |
| 447 | + if (! $MailChimp->success()) { | |
| 421 | 448 | return []; |
| 422 | 449 | } |
| 423 | 450 | } catch (\Exception $exception) { |
| 424 | 451 | return []; |
| @@ -427,14 +454,35 @@ | ||
| 427 | 454 | $formattedLists = []; |
| 428 | 455 | foreach ($categories as $list) { |
| 429 | 456 | $formattedLists[] = [ |
| 430 | 457 | 'value' => $list['id'], |
| 431 | - 'label' => $list['name'] | |
| 458 | + 'label' => $list['name'], | |
| 432 | 459 | ]; |
| 433 | 460 | } |
| 434 | 461 | return $formattedLists; |
| 435 | 462 | } |
| 436 | 463 | |
| 464 | + public function sanitizeSettings($integration, $integrationId, $formId) | |
| 465 | + { | |
| 466 | + if (fluentformCanUnfilteredHTML()) { | |
| 467 | + return $integration; | |
| 468 | + } | |
| 469 | + $sanitizeMap = [ | |
| 470 | + 'status' => 'rest_sanitize_boolean', | |
| 471 | + 'enabled' => 'rest_sanitize_boolean', | |
| 472 | + 'type' => 'sanitize_text_field', | |
| 473 | + 'list_id' => 'sanitize_text_field', | |
| 474 | + 'list_name' => 'sanitize_text_field', | |
| 475 | + 'name' => 'sanitize_text_field', | |
| 476 | + 'tags' => 'sanitize_text_field', | |
| 477 | + 'tag_ids_selection_type' => 'sanitize_text_field', | |
| 478 | + 'fieldEmailAddress' => 'sanitize_text_field', | |
| 479 | + 'doubleOptIn' => 'rest_sanitize_boolean', | |
| 480 | + 'resubscribe' => 'rest_sanitize_boolean', | |
| 481 | + 'note' => 'sanitize_text_field', | |
| 482 | + ]; | |
| 483 | + return fluentform_backend_sanitizer($integration, $sanitizeMap); | |
| 484 | + } | |
| 437 | 485 | |
| 438 | 486 | /* |
| 439 | 487 | * For Handling Notifications broadcast |
| 440 | 488 | */ |
| @@ -440,16 +488,24 @@ | ||
| 440 | 488 | */ |
| 441 | 489 | public function notify($feed, $formData, $entry, $form) |
| 442 | 490 | { |
| 443 | 491 | $response = $this->subscribe($feed, $formData, $entry, $form); |
| 444 | - | |
| 445 | - if ($response == true) { | |
| 446 | - do_action('ff_integration_action_result', $feed, 'success', 'MailChimp feed has been successfully initialed and pushed data'); | |
| 492 | + | |
| 493 | + if (true == $response && !is_wp_error($response)) { | |
| 494 | + $message = __('Mailchimp feed has been successfully initialed and pushed data', 'fluentform'); | |
| 495 | + do_action('fluentform/integration_action_result', $feed, 'success', $message); | |
| 447 | 496 | } else { |
| 448 | - $message = 'Mailchimp feed has been failed to deliver feed'; | |
| 497 | + $message = __('Mailchimp feed has been failed to deliver feed', 'fluentform'); | |
| 449 | 498 | if (is_wp_error($response)) { |
| 450 | 499 | $message = $response->get_error_message(); |
| 500 | + if (is_array($message)) { | |
| 501 | + $messageArray = $message; | |
| 502 | + $message = ''; | |
| 503 | + foreach ($messageArray as $error) { | |
| 504 | + $message .= ArrayHelper::get($error, 'message'); | |
| 505 | + } | |
| 506 | + } | |
| 451 | 507 | } |
| 452 | - do_action('ff_integration_action_result', $feed, 'failed', $message); | |
| 508 | + do_action('fluentform/integration_action_result', $feed, 'failed', $message); | |
| 453 | 509 | } |
| 454 | 510 | } |
| 455 | 511 | } |