Easy Forms for MailChimp - Version 6.0.3.2

Version Description

Download this release

Release Info

Developer eherman24
Plugin Icon 128x128 Easy Forms for MailChimp
Version 6.0.3.2
Comparing to
See all releases

Code changes from version 6.0.3.1 to 6.0.3.2

admin/partials/menu/support.php CHANGED
@@ -17,6 +17,7 @@
17
  <p><?php printf( __( 'Purchasers of our paid add-ons qualify for premium support, <a href="%s" target="_blank" title="' . __( 'check them out', 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'check them out', 'yikes-inc-easy-mailchimp-extender' ) . '</a>!' , 'yikes-inc-easy-mailchimp-extender' ), esc_url( 'https://yikesplugins.com/' ) ); ?></p>
18
  <?php } else { ?>
19
  <p><?php _e( "It looks like you are one of our premium users! Fill out the form below to submit a priority support request." , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
 
20
  <?php } ?>
21
 
22
  <p><?php printf( __( 'Before submitting a support request, visit our %s.' , 'yikes-inc-easy-mailchimp-extender' ), '<a target="_blank" href="' . esc_url( 'https://yikesplugins.com/support/knowledge-base/product/easy-forms-for-mailchimp/' ) . '" title="' . __( 'Knowledge Base', 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'knowledge base', 'yikes-inc-easy-mailchimp-extender' ) . '</a> where we have step-by-step guides and troubleshooting help.' ); ?></p>
17
  <p><?php printf( __( 'Purchasers of our paid add-ons qualify for premium support, <a href="%s" target="_blank" title="' . __( 'check them out', 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'check them out', 'yikes-inc-easy-mailchimp-extender' ) . '</a>!' , 'yikes-inc-easy-mailchimp-extender' ), esc_url( 'https://yikesplugins.com/' ) ); ?></p>
18
  <?php } else { ?>
19
  <p><?php _e( "It looks like you are one of our premium users! Fill out the form below to submit a priority support request." , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
20
+ <p><?php _e( "If you have any problems with the form, send an email to <a href='mailto:support@yikesinc.com'>support@yikesinc.com</a> and a ticket will be created." , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
21
  <?php } ?>
22
 
23
  <p><?php printf( __( 'Before submitting a support request, visit our %s.' , 'yikes-inc-easy-mailchimp-extender' ), '<a target="_blank" href="' . esc_url( 'https://yikesplugins.com/support/knowledge-base/product/easy-forms-for-mailchimp/' ) . '" title="' . __( 'Knowledge Base', 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'knowledge base', 'yikes-inc-easy-mailchimp-extender' ) . '</a> where we have step-by-step guides and troubleshooting help.' ); ?></p>
includes/MailChimp/Mailchimp.php CHANGED
@@ -1 +1 @@
1
- <?php
2
 
3
  public $apikey;
4
  public $ch;
5
  public $root = 'https://api.mailchimp.com/2.0';
6
  public $debug = false;
7
  public static $error_map = array(
8
  "ValidationError" => "Mailchimp_ValidationError",
9
  "ServerError_MethodUnknown" => "Mailchimp_ServerError_MethodUnknown",
10
  "ServerError_InvalidParameters" => "Mailchimp_ServerError_InvalidParameters",
11
  "Unknown_Exception" => "Mailchimp_Unknown_Exception",
12
  "Request_TimedOut" => "Mailchimp_Request_TimedOut",
13
  "Zend_Uri_Exception" => "Mailchimp_Zend_Uri_Exception",
14
  "PDOException" => "Mailchimp_PDOException",
15
  "Avesta_Db_Exception" => "Mailchimp_Avesta_Db_Exception",
16
  "XML_RPC2_Exception" => "Mailchimp_XML_RPC2_Exception",
17
  "XML_RPC2_FaultException" => "Mailchimp_XML_RPC2_FaultException",
18
  "Too_Many_Connections" => "Mailchimp_Too_Many_Connections",
19
  "Parse_Exception" => "Mailchimp_Parse_Exception",
20
  "User_Unknown" => "Mailchimp_User_Unknown",
21
  "User_Disabled" => "Mailchimp_User_Disabled",
22
  "User_DoesNotExist" => "Mailchimp_User_DoesNotExist",
23
  "User_NotApproved" => "Mailchimp_User_NotApproved",
24
  "Invalid_ApiKey" => "Mailchimp_Invalid_ApiKey",
25
  "User_UnderMaintenance" => "Mailchimp_User_UnderMaintenance",
26
  "Invalid_AppKey" => "Mailchimp_Invalid_AppKey",
27
  "Invalid_IP" => "Mailchimp_Invalid_IP",
28
  "User_DoesExist" => "Mailchimp_User_DoesExist",
29
  "User_InvalidRole" => "Mailchimp_User_InvalidRole",
30
  "User_InvalidAction" => "Mailchimp_User_InvalidAction",
31
  "User_MissingEmail" => "Mailchimp_User_MissingEmail",
32
  "User_CannotSendCampaign" => "Mailchimp_User_CannotSendCampaign",
33
  "User_MissingModuleOutbox" => "Mailchimp_User_MissingModuleOutbox",
34
  "User_ModuleAlreadyPurchased" => "Mailchimp_User_ModuleAlreadyPurchased",
35
  "User_ModuleNotPurchased" => "Mailchimp_User_ModuleNotPurchased",
36
  "User_NotEnoughCredit" => "Mailchimp_User_NotEnoughCredit",
37
  "MC_InvalidPayment" => "Mailchimp_MC_InvalidPayment",
38
  "List_DoesNotExist" => "Mailchimp_List_DoesNotExist",
39
  "List_InvalidInterestFieldType" => "Mailchimp_List_InvalidInterestFieldType",
40
  "List_InvalidOption" => "Mailchimp_List_InvalidOption",
41
  "List_InvalidUnsubMember" => "Mailchimp_List_InvalidUnsubMember",
42
  "List_InvalidBounceMember" => "Mailchimp_List_InvalidBounceMember",
43
  "List_AlreadySubscribed" => "Mailchimp_List_AlreadySubscribed",
44
  "List_NotSubscribed" => "Mailchimp_List_NotSubscribed",
45
  "List_InvalidImport" => "Mailchimp_List_InvalidImport",
46
  "MC_PastedList_Duplicate" => "Mailchimp_MC_PastedList_Duplicate",
47
  "MC_PastedList_InvalidImport" => "Mailchimp_MC_PastedList_InvalidImport",
48
  "Email_AlreadySubscribed" => "Mailchimp_Email_AlreadySubscribed",
49
  "Email_AlreadyUnsubscribed" => "Mailchimp_Email_AlreadyUnsubscribed",
50
  "Email_NotExists" => "Mailchimp_Email_NotExists",
51
  "Email_NotSubscribed" => "Mailchimp_Email_NotSubscribed",
52
  "List_MergeFieldRequired" => "Mailchimp_List_MergeFieldRequired",
53
  "List_CannotRemoveEmailMerge" => "Mailchimp_List_CannotRemoveEmailMerge",
54
  "List_Merge_InvalidMergeID" => "Mailchimp_List_Merge_InvalidMergeID",
55
  "List_TooManyMergeFields" => "Mailchimp_List_TooManyMergeFields",
56
  "List_InvalidMergeField" => "Mailchimp_List_InvalidMergeField",
57
  "List_InvalidInterestGroup" => "Mailchimp_List_InvalidInterestGroup",
58
  "List_TooManyInterestGroups" => "Mailchimp_List_TooManyInterestGroups",
59
  "Campaign_DoesNotExist" => "Mailchimp_Campaign_DoesNotExist",
60
  "Campaign_StatsNotAvailable" => "Mailchimp_Campaign_StatsNotAvailable",
61
  "Campaign_InvalidAbsplit" => "Mailchimp_Campaign_InvalidAbsplit",
62
  "Campaign_InvalidContent" => "Mailchimp_Campaign_InvalidContent",
63
  "Campaign_InvalidOption" => "Mailchimp_Campaign_InvalidOption",
64
  "Campaign_InvalidStatus" => "Mailchimp_Campaign_InvalidStatus",
65
  "Campaign_NotSaved" => "Mailchimp_Campaign_NotSaved",
66
  "Campaign_InvalidSegment" => "Mailchimp_Campaign_InvalidSegment",
67
  "Campaign_InvalidRss" => "Mailchimp_Campaign_InvalidRss",
68
  "Campaign_InvalidAuto" => "Mailchimp_Campaign_InvalidAuto",
69
  "MC_ContentImport_InvalidArchive" => "Mailchimp_MC_ContentImport_InvalidArchive",
70
  "Campaign_BounceMissing" => "Mailchimp_Campaign_BounceMissing",
71
  "Campaign_InvalidTemplate" => "Mailchimp_Campaign_InvalidTemplate",
72
  "Invalid_EcommOrder" => "Mailchimp_Invalid_EcommOrder",
73
  "Absplit_UnknownError" => "Mailchimp_Absplit_UnknownError",
74
  "Absplit_UnknownSplitTest" => "Mailchimp_Absplit_UnknownSplitTest",
75
  "Absplit_UnknownTestType" => "Mailchimp_Absplit_UnknownTestType",
76
  "Absplit_UnknownWaitUnit" => "Mailchimp_Absplit_UnknownWaitUnit",
77
  "Absplit_UnknownWinnerType" => "Mailchimp_Absplit_UnknownWinnerType",
78
  "Absplit_WinnerNotSelected" => "Mailchimp_Absplit_WinnerNotSelected",
79
  "Invalid_Analytics" => "Mailchimp_Invalid_Analytics",
80
  "Invalid_DateTime" => "Mailchimp_Invalid_DateTime",
81
  "Invalid_Email" => "Mailchimp_Invalid_Email",
82
  "Invalid_SendType" => "Mailchimp_Invalid_SendType",
83
  "Invalid_Template" => "Mailchimp_Invalid_Template",
84
  "Invalid_TrackingOptions" => "Mailchimp_Invalid_TrackingOptions",
85
  "Invalid_Options" => "Mailchimp_Invalid_Options",
86
  "Invalid_Folder" => "Mailchimp_Invalid_Folder",
87
  "Invalid_URL" => "Mailchimp_Invalid_URL",
88
  "Module_Unknown" => "Mailchimp_Module_Unknown",
89
  "MonthlyPlan_Unknown" => "Mailchimp_MonthlyPlan_Unknown",
90
  "Order_TypeUnknown" => "Mailchimp_Order_TypeUnknown",
91
  "Invalid_PagingLimit" => "Mailchimp_Invalid_PagingLimit",
92
  "Invalid_PagingStart" => "Mailchimp_Invalid_PagingStart",
93
  "Max_Size_Reached" => "Mailchimp_Max_Size_Reached",
94
  "MC_SearchException" => "Mailchimp_MC_SearchException",
95
  "Goal_SaveFailed" => "Mailchimp_Goal_SaveFailed",
96
  "Conversation_DoesNotExist" => "Mailchimp_Conversation_DoesNotExist",
97
  "Conversation_ReplySaveFailed" => "Mailchimp_Conversation_ReplySaveFailed",
98
  "File_Not_Found_Exception" => "Mailchimp_File_Not_Found_Exception",
99
  "Folder_Not_Found_Exception" => "Mailchimp_Folder_Not_Found_Exception",
100
  "Folder_Exists_Exception" => "Mailchimp_Folder_Exists_Exception"
101
  );
102
  public function __construct($apikey=null, $opts=array()) {
103
  if (!$apikey) {
104
  $apikey = getenv('MAILCHIMP_APIKEY');
105
  }
106
  if (!$apikey) {
107
  $apikey = $this->readConfigs();
108
  }
109
  if (!$apikey) {
110
  throw new Mailchimp_Error('You must provide a MailChimp API key');
111
  }
112
  $this->apikey = $apikey;
113
  $dc = "us1";
114
  if (strstr($this->apikey, "-")){
115
  list($key, $dc) = explode("-", $this->apikey, 2);
116
  if (!$dc) {
117
  $dc = "us1";
118
  }
119
  }
120
  $this->root = str_replace('https://api', 'https://' . $dc . '.api', $this->root);
121
  $this->root = rtrim($this->root, '/') . '/';
122
  if (!isset($opts['timeout']) || !is_int($opts['timeout'])){
123
  $opts['timeout'] = 600;
124
  }
125
  if (isset($opts['debug'])){
126
  $this->debug = true;
127
  }
128
  $this->ch = curl_init();
129
  if (isset($opts['CURLOPT_FOLLOWLOCATION']) && $opts['CURLOPT_FOLLOWLOCATION'] === true) {
130
  curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
131
  }
132
  curl_setopt($this->ch, CURLOPT_USERAGENT, 'MailChimp-PHP/2.0.6');
133
  curl_setopt($this->ch, CURLOPT_POST, true);
134
  curl_setopt($this->ch, CURLOPT_HEADER, false);
135
  curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
136
  curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
137
  curl_setopt($this->ch, CURLOPT_TIMEOUT, $opts['timeout']);
138
  $this->folders = new Mailchimp_Folders($this);
139
  $this->templates = new Mailchimp_Templates($this);
140
  $this->users = new Mailchimp_Users($this);
141
  $this->helper = new Mailchimp_Helper($this);
142
  $this->mobile = new Mailchimp_Mobile($this);
143
  $this->conversations = new Mailchimp_Conversations($this);
144
  $this->ecomm = new Mailchimp_Ecomm($this);
145
  $this->neapolitan = new Mailchimp_Neapolitan($this);
146
  $this->lists = new Mailchimp_Lists($this);
147
  $this->campaigns = new Mailchimp_Campaigns($this);
148
  $this->vip = new Mailchimp_Vip($this);
149
  $this->reports = new Mailchimp_Reports($this);
150
  $this->gallery = new Mailchimp_Gallery($this);
151
  $this->goal = new Mailchimp_Goal($this);
152
  }
153
  public function __destruct() {
154
  if(is_resource($this->ch)) {
155
  curl_close($this->ch);
156
  }
157
  }
158
  public function call($url, $params) {
159
  $params['apikey'] = $this->apikey;
160
 
161
  $params = json_encode($params);
162
  $ch = $this->ch;
163
  curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json');
164
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
165
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
166
  curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);
167
  $start = microtime(true);
168
  $this->log('Call to ' . $this->root . $url . '.json: ' . $params);
169
  if($this->debug) {
170
  $curl_buffer = fopen('php://memory', 'w+');
171
  curl_setopt($ch, CURLOPT_STDERR, $curl_buffer);
172
  }
173
  $response_body = curl_exec($ch);
174
  $info = curl_getinfo($ch);
175
  $time = microtime(true) - $start;
176
  if($this->debug) {
177
  rewind($curl_buffer);
178
  $this->log(stream_get_contents($curl_buffer));
179
  fclose($curl_buffer);
180
  }
181
  $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms');
182
  $this->log('Got response: ' . $response_body);
183
  if(curl_error($ch)) {
184
  throw new Mailchimp_HttpError("API call to $url failed: " . curl_error($ch));
185
  }
186
  $result = json_decode($response_body, true);
187
 
188
  if(floor($info['http_code'] / 100) >= 4) {
189
  throw $this->castError($result);
190
  }
191
  return $result;
192
  }
193
  public function readConfigs() {
194
  $paths = array('~/.mailchimp.key', '/etc/mailchimp.key');
195
  foreach($paths as $path) {
196
  if(file_exists($path)) {
197
  $apikey = trim(file_get_contents($path));
198
  if ($apikey) {
199
  return $apikey;
200
  }
201
  }
202
  }
203
  return false;
204
  }
205
  public function castError($result) {
206
  if ($result['status'] !== 'error' || !$result['name']) {
207
  throw new Mailchimp_Error('We received an unexpected error: ' . json_encode($result));
208
  }
209
  $class = (isset(self::$error_map[$result['name']])) ? self::$error_map[$result['name']] : 'Mailchimp_Error';
210
  return new $class($result['error'], $result['code']);
211
  }
212
  public function log($msg) {
213
  if ($this->debug) {
214
  error_log($msg);
215
  }
216
  }
 
217
 
218
  public $apikey;
219
  public $ch;
220
  public $root = 'https://api.mailchimp.com/2.0';
221
  public $debug = false;
222
  public static $error_map = array(
223
  "ValidationError" => "Mailchimp_ValidationError",
224
  "ServerError_MethodUnknown" => "Mailchimp_ServerError_MethodUnknown",
225
  "ServerError_InvalidParameters" => "Mailchimp_ServerError_InvalidParameters",
226
  "Unknown_Exception" => "Mailchimp_Unknown_Exception",
227
  "Request_TimedOut" => "Mailchimp_Request_TimedOut",
228
  "Zend_Uri_Exception" => "Mailchimp_Zend_Uri_Exception",
229
  "PDOException" => "Mailchimp_PDOException",
230
  "Avesta_Db_Exception" => "Mailchimp_Avesta_Db_Exception",
231
  "XML_RPC2_Exception" => "Mailchimp_XML_RPC2_Exception",
232
  "XML_RPC2_FaultException" => "Mailchimp_XML_RPC2_FaultException",
233
  "Too_Many_Connections" => "Mailchimp_Too_Many_Connections",
234
  "Parse_Exception" => "Mailchimp_Parse_Exception",
235
  "User_Unknown" => "Mailchimp_User_Unknown",
236
  "User_Disabled" => "Mailchimp_User_Disabled",
237
  "User_DoesNotExist" => "Mailchimp_User_DoesNotExist",
238
  "User_NotApproved" => "Mailchimp_User_NotApproved",
239
  "Invalid_ApiKey" => "Mailchimp_Invalid_ApiKey",
240
  "User_UnderMaintenance" => "Mailchimp_User_UnderMaintenance",
241
  "Invalid_AppKey" => "Mailchimp_Invalid_AppKey",
242
  "Invalid_IP" => "Mailchimp_Invalid_IP",
243
  "User_DoesExist" => "Mailchimp_User_DoesExist",
244
  "User_InvalidRole" => "Mailchimp_User_InvalidRole",
245
  "User_InvalidAction" => "Mailchimp_User_InvalidAction",
246
  "User_MissingEmail" => "Mailchimp_User_MissingEmail",
247
  "User_CannotSendCampaign" => "Mailchimp_User_CannotSendCampaign",
248
  "User_MissingModuleOutbox" => "Mailchimp_User_MissingModuleOutbox",
249
  "User_ModuleAlreadyPurchased" => "Mailchimp_User_ModuleAlreadyPurchased",
250
  "User_ModuleNotPurchased" => "Mailchimp_User_ModuleNotPurchased",
251
  "User_NotEnoughCredit" => "Mailchimp_User_NotEnoughCredit",
252
  "MC_InvalidPayment" => "Mailchimp_MC_InvalidPayment",
253
  "List_DoesNotExist" => "Mailchimp_List_DoesNotExist",
254
  "List_InvalidInterestFieldType" => "Mailchimp_List_InvalidInterestFieldType",
255
  "List_InvalidOption" => "Mailchimp_List_InvalidOption",
256
  "List_InvalidUnsubMember" => "Mailchimp_List_InvalidUnsubMember",
257
  "List_InvalidBounceMember" => "Mailchimp_List_InvalidBounceMember",
258
  "List_AlreadySubscribed" => "Mailchimp_List_AlreadySubscribed",
259
  "List_NotSubscribed" => "Mailchimp_List_NotSubscribed",
260
  "List_InvalidImport" => "Mailchimp_List_InvalidImport",
261
  "MC_PastedList_Duplicate" => "Mailchimp_MC_PastedList_Duplicate",
262
  "MC_PastedList_InvalidImport" => "Mailchimp_MC_PastedList_InvalidImport",
263
  "Email_AlreadySubscribed" => "Mailchimp_Email_AlreadySubscribed",
264
  "Email_AlreadyUnsubscribed" => "Mailchimp_Email_AlreadyUnsubscribed",
265
  "Email_NotExists" => "Mailchimp_Email_NotExists",
266
  "Email_NotSubscribed" => "Mailchimp_Email_NotSubscribed",
267
  "List_MergeFieldRequired" => "Mailchimp_List_MergeFieldRequired",
268
  "List_CannotRemoveEmailMerge" => "Mailchimp_List_CannotRemoveEmailMerge",
269
  "List_Merge_InvalidMergeID" => "Mailchimp_List_Merge_InvalidMergeID",
270
  "List_TooManyMergeFields" => "Mailchimp_List_TooManyMergeFields",
271
  "List_InvalidMergeField" => "Mailchimp_List_InvalidMergeField",
272
  "List_InvalidInterestGroup" => "Mailchimp_List_InvalidInterestGroup",
273
  "List_TooManyInterestGroups" => "Mailchimp_List_TooManyInterestGroups",
274
  "Campaign_DoesNotExist" => "Mailchimp_Campaign_DoesNotExist",
275
  "Campaign_StatsNotAvailable" => "Mailchimp_Campaign_StatsNotAvailable",
276
  "Campaign_InvalidAbsplit" => "Mailchimp_Campaign_InvalidAbsplit",
277
  "Campaign_InvalidContent" => "Mailchimp_Campaign_InvalidContent",
278
  "Campaign_InvalidOption" => "Mailchimp_Campaign_InvalidOption",
279
  "Campaign_InvalidStatus" => "Mailchimp_Campaign_InvalidStatus",
280
  "Campaign_NotSaved" => "Mailchimp_Campaign_NotSaved",
281
  "Campaign_InvalidSegment" => "Mailchimp_Campaign_InvalidSegment",
282
  "Campaign_InvalidRss" => "Mailchimp_Campaign_InvalidRss",
283
  "Campaign_InvalidAuto" => "Mailchimp_Campaign_InvalidAuto",
284
  "MC_ContentImport_InvalidArchive" => "Mailchimp_MC_ContentImport_InvalidArchive",
285
  "Campaign_BounceMissing" => "Mailchimp_Campaign_BounceMissing",
286
  "Campaign_InvalidTemplate" => "Mailchimp_Campaign_InvalidTemplate",
287
  "Invalid_EcommOrder" => "Mailchimp_Invalid_EcommOrder",
288
  "Absplit_UnknownError" => "Mailchimp_Absplit_UnknownError",
289
  "Absplit_UnknownSplitTest" => "Mailchimp_Absplit_UnknownSplitTest",
290
  "Absplit_UnknownTestType" => "Mailchimp_Absplit_UnknownTestType",
291
  "Absplit_UnknownWaitUnit" => "Mailchimp_Absplit_UnknownWaitUnit",
292
  "Absplit_UnknownWinnerType" => "Mailchimp_Absplit_UnknownWinnerType",
293
  "Absplit_WinnerNotSelected" => "Mailchimp_Absplit_WinnerNotSelected",
294
  "Invalid_Analytics" => "Mailchimp_Invalid_Analytics",
295
  "Invalid_DateTime" => "Mailchimp_Invalid_DateTime",
296
  "Invalid_Email" => "Mailchimp_Invalid_Email",
297
  "Invalid_SendType" => "Mailchimp_Invalid_SendType",
298
  "Invalid_Template" => "Mailchimp_Invalid_Template",
299
  "Invalid_TrackingOptions" => "Mailchimp_Invalid_TrackingOptions",
300
  "Invalid_Options" => "Mailchimp_Invalid_Options",
301
  "Invalid_Folder" => "Mailchimp_Invalid_Folder",
302
  "Invalid_URL" => "Mailchimp_Invalid_URL",
303
  "Module_Unknown" => "Mailchimp_Module_Unknown",
304
  "MonthlyPlan_Unknown" => "Mailchimp_MonthlyPlan_Unknown",
305
  "Order_TypeUnknown" => "Mailchimp_Order_TypeUnknown",
306
  "Invalid_PagingLimit" => "Mailchimp_Invalid_PagingLimit",
307
  "Invalid_PagingStart" => "Mailchimp_Invalid_PagingStart",
308
  "Max_Size_Reached" => "Mailchimp_Max_Size_Reached",
309
  "MC_SearchException" => "Mailchimp_MC_SearchException",
310
  "Goal_SaveFailed" => "Mailchimp_Goal_SaveFailed",
311
  "Conversation_DoesNotExist" => "Mailchimp_Conversation_DoesNotExist",
312
  "Conversation_ReplySaveFailed" => "Mailchimp_Conversation_ReplySaveFailed",
313
  "File_Not_Found_Exception" => "Mailchimp_File_Not_Found_Exception",
314
  "Folder_Not_Found_Exception" => "Mailchimp_Folder_Not_Found_Exception",
315
  "Folder_Exists_Exception" => "Mailchimp_Folder_Exists_Exception"
316
  );
317
  public function __construct($apikey=null, $opts=array()) {
318
  if (!$apikey) {
319
  $apikey = getenv('MAILCHIMP_APIKEY');
320
  }
321
  if (!$apikey) {
322
  $apikey = $this->readConfigs();
323
  }
324
  if (!$apikey) {
325
  throw new Mailchimp_Error('You must provide a MailChimp API key');
326
  }
327
  $this->apikey = $apikey;
328
  $dc = "us1";
329
  if (strstr($this->apikey, "-")){
330
  list($key, $dc) = explode("-", $this->apikey, 2);
331
  if (!$dc) {
332
  $dc = "us1";
333
  }
334
  }
335
  $this->root = str_replace('https://api', 'https://' . $dc . '.api', $this->root);
336
  $this->root = rtrim($this->root, '/') . '/';
337
  if (!isset($opts['timeout']) || !is_int($opts['timeout'])){
338
  $opts['timeout'] = 600;
339
  }
340
  if (isset($opts['debug'])){
341
  $this->debug = true;
342
  }
343
  $this->ch = curl_init();
344
  if (isset($opts['CURLOPT_FOLLOWLOCATION']) && $opts['CURLOPT_FOLLOWLOCATION'] === true) {
345
  curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
346
  }
347
  curl_setopt($this->ch, CURLOPT_USERAGENT, 'MailChimp-PHP/2.0.6');
348
  curl_setopt($this->ch, CURLOPT_POST, true);
349
  curl_setopt($this->ch, CURLOPT_HEADER, false);
350
  curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
351
  curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
352
  curl_setopt($this->ch, CURLOPT_TIMEOUT, $opts['timeout']);
353
  $this->folders = new Mailchimp_Folders($this);
354
  $this->templates = new Mailchimp_Templates($this);
355
  $this->users = new Mailchimp_Users($this);
356
  $this->helper = new Mailchimp_Helper($this);
357
  $this->mobile = new Mailchimp_Mobile($this);
358
  $this->conversations = new Mailchimp_Conversations($this);
359
  $this->ecomm = new Mailchimp_Ecomm($this);
360
  $this->neapolitan = new Mailchimp_Neapolitan($this);
361
  $this->lists = new Mailchimp_Lists($this);
362
  $this->campaigns = new Mailchimp_Campaigns($this);
363
  $this->vip = new Mailchimp_Vip($this);
364
  $this->reports = new Mailchimp_Reports($this);
365
  $this->gallery = new Mailchimp_Gallery($this);
366
  $this->goal = new Mailchimp_Goal($this);
367
  }
368
  public function __destruct() {
369
  if(is_resource($this->ch)) {
370
  curl_close($this->ch);
371
  }
372
  }
373
  public function call($url, $params) {
374
  $params['apikey'] = $this->apikey;
375
 
376
  $params = json_encode($params);
377
  $ch = $this->ch;
378
  curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json');
379
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
380
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
381
  curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);
382
  $start = microtime(true);
383
  $this->log('Call to ' . $this->root . $url . '.json: ' . $params);
384
  if($this->debug) {
385
  $curl_buffer = fopen('php://memory', 'w+');
386
  curl_setopt($ch, CURLOPT_STDERR, $curl_buffer);
387
  }
388
  $response_body = curl_exec($ch);
389
  $info = curl_getinfo($ch);
390
  $time = microtime(true) - $start;
391
  if($this->debug) {
392
  rewind($curl_buffer);
393
  $this->log(stream_get_contents($curl_buffer));
394
  fclose($curl_buffer);
395
  }
396
  $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms');
397
  $this->log('Got response: ' . $response_body);
398
  if(curl_error($ch)) {
399
  throw new Mailchimp_HttpError("API call to $url failed: " . curl_error($ch));
400
  }
401
  $result = json_decode($response_body, true);
402
  if( defined( 'YIKES_MAILCHIMP_NULL_DEBUG' ) && YIKES_MAILCHIMP_NULL_DEBUG == '1' ) {
403
  if(floor($info['http_code'] / 100) >= 4) {
404
  throw $this->castError($result);
405
  }
406
  return $result;
407
  }
408
  public function readConfigs() {
409
  $paths = array('~/.mailchimp.key', '/etc/mailchimp.key');
410
  foreach($paths as $path) {
411
  if(file_exists($path)) {
412
  $apikey = trim(file_get_contents($path));
413
  if ($apikey) {
414
  return $apikey;
415
  }
416
  }
417
  }
418
  return false;
419
  }
420
  public function castError($result) {
421
  if ($result['status'] !== 'error' || !$result['name']) {
422
  throw new Mailchimp_Error('We received an unexpected error: ' . json_encode($result));
423
  }
424
  $class = (isset(self::$error_map[$result['name']])) ? self::$error_map[$result['name']] : 'Mailchimp_Error';
425
  return new $class($result['error'], $result['code']);
426
  }
427
  public function log($msg) {
428
  if ($this->debug) {
429
  error_log($msg);
430
  }
431
  }
 
1
 
2
  public $apikey;
3
  public $ch;
4
  public $root = 'https://api.mailchimp.com/2.0';
5
  public $debug = false;
6
  public static $error_map = array(
7
  "ValidationError" => "Mailchimp_ValidationError",
8
  "ServerError_MethodUnknown" => "Mailchimp_ServerError_MethodUnknown",
9
  "ServerError_InvalidParameters" => "Mailchimp_ServerError_InvalidParameters",
10
  "Unknown_Exception" => "Mailchimp_Unknown_Exception",
11
  "Request_TimedOut" => "Mailchimp_Request_TimedOut",
12
  "Zend_Uri_Exception" => "Mailchimp_Zend_Uri_Exception",
13
  "PDOException" => "Mailchimp_PDOException",
14
  "Avesta_Db_Exception" => "Mailchimp_Avesta_Db_Exception",
15
  "XML_RPC2_Exception" => "Mailchimp_XML_RPC2_Exception",
16
  "XML_RPC2_FaultException" => "Mailchimp_XML_RPC2_FaultException",
17
  "Too_Many_Connections" => "Mailchimp_Too_Many_Connections",
18
  "Parse_Exception" => "Mailchimp_Parse_Exception",
19
  "User_Unknown" => "Mailchimp_User_Unknown",
20
  "User_Disabled" => "Mailchimp_User_Disabled",
21
  "User_DoesNotExist" => "Mailchimp_User_DoesNotExist",
22
  "User_NotApproved" => "Mailchimp_User_NotApproved",
23
  "Invalid_ApiKey" => "Mailchimp_Invalid_ApiKey",
24
  "User_UnderMaintenance" => "Mailchimp_User_UnderMaintenance",
25
  "Invalid_AppKey" => "Mailchimp_Invalid_AppKey",
26
  "Invalid_IP" => "Mailchimp_Invalid_IP",
27
  "User_DoesExist" => "Mailchimp_User_DoesExist",
28
  "User_InvalidRole" => "Mailchimp_User_InvalidRole",
29
  "User_InvalidAction" => "Mailchimp_User_InvalidAction",
30
  "User_MissingEmail" => "Mailchimp_User_MissingEmail",
31
  "User_CannotSendCampaign" => "Mailchimp_User_CannotSendCampaign",
32
  "User_MissingModuleOutbox" => "Mailchimp_User_MissingModuleOutbox",
33
  "User_ModuleAlreadyPurchased" => "Mailchimp_User_ModuleAlreadyPurchased",
34
  "User_ModuleNotPurchased" => "Mailchimp_User_ModuleNotPurchased",
35
  "User_NotEnoughCredit" => "Mailchimp_User_NotEnoughCredit",
36
  "MC_InvalidPayment" => "Mailchimp_MC_InvalidPayment",
37
  "List_DoesNotExist" => "Mailchimp_List_DoesNotExist",
38
  "List_InvalidInterestFieldType" => "Mailchimp_List_InvalidInterestFieldType",
39
  "List_InvalidOption" => "Mailchimp_List_InvalidOption",
40
  "List_InvalidUnsubMember" => "Mailchimp_List_InvalidUnsubMember",
41
  "List_InvalidBounceMember" => "Mailchimp_List_InvalidBounceMember",
42
  "List_AlreadySubscribed" => "Mailchimp_List_AlreadySubscribed",
43
  "List_NotSubscribed" => "Mailchimp_List_NotSubscribed",
44
  "List_InvalidImport" => "Mailchimp_List_InvalidImport",
45
  "MC_PastedList_Duplicate" => "Mailchimp_MC_PastedList_Duplicate",
46
  "MC_PastedList_InvalidImport" => "Mailchimp_MC_PastedList_InvalidImport",
47
  "Email_AlreadySubscribed" => "Mailchimp_Email_AlreadySubscribed",
48
  "Email_AlreadyUnsubscribed" => "Mailchimp_Email_AlreadyUnsubscribed",
49
  "Email_NotExists" => "Mailchimp_Email_NotExists",
50
  "Email_NotSubscribed" => "Mailchimp_Email_NotSubscribed",
51
  "List_MergeFieldRequired" => "Mailchimp_List_MergeFieldRequired",
52
  "List_CannotRemoveEmailMerge" => "Mailchimp_List_CannotRemoveEmailMerge",
53
  "List_Merge_InvalidMergeID" => "Mailchimp_List_Merge_InvalidMergeID",
54
  "List_TooManyMergeFields" => "Mailchimp_List_TooManyMergeFields",
55
  "List_InvalidMergeField" => "Mailchimp_List_InvalidMergeField",
56
  "List_InvalidInterestGroup" => "Mailchimp_List_InvalidInterestGroup",
57
  "List_TooManyInterestGroups" => "Mailchimp_List_TooManyInterestGroups",
58
  "Campaign_DoesNotExist" => "Mailchimp_Campaign_DoesNotExist",
59
  "Campaign_StatsNotAvailable" => "Mailchimp_Campaign_StatsNotAvailable",
60
  "Campaign_InvalidAbsplit" => "Mailchimp_Campaign_InvalidAbsplit",
61
  "Campaign_InvalidContent" => "Mailchimp_Campaign_InvalidContent",
62
  "Campaign_InvalidOption" => "Mailchimp_Campaign_InvalidOption",
63
  "Campaign_InvalidStatus" => "Mailchimp_Campaign_InvalidStatus",
64
  "Campaign_NotSaved" => "Mailchimp_Campaign_NotSaved",
65
  "Campaign_InvalidSegment" => "Mailchimp_Campaign_InvalidSegment",
66
  "Campaign_InvalidRss" => "Mailchimp_Campaign_InvalidRss",
67
  "Campaign_InvalidAuto" => "Mailchimp_Campaign_InvalidAuto",
68
  "MC_ContentImport_InvalidArchive" => "Mailchimp_MC_ContentImport_InvalidArchive",
69
  "Campaign_BounceMissing" => "Mailchimp_Campaign_BounceMissing",
70
  "Campaign_InvalidTemplate" => "Mailchimp_Campaign_InvalidTemplate",
71
  "Invalid_EcommOrder" => "Mailchimp_Invalid_EcommOrder",
72
  "Absplit_UnknownError" => "Mailchimp_Absplit_UnknownError",
73
  "Absplit_UnknownSplitTest" => "Mailchimp_Absplit_UnknownSplitTest",
74
  "Absplit_UnknownTestType" => "Mailchimp_Absplit_UnknownTestType",
75
  "Absplit_UnknownWaitUnit" => "Mailchimp_Absplit_UnknownWaitUnit",
76
  "Absplit_UnknownWinnerType" => "Mailchimp_Absplit_UnknownWinnerType",
77
  "Absplit_WinnerNotSelected" => "Mailchimp_Absplit_WinnerNotSelected",
78
  "Invalid_Analytics" => "Mailchimp_Invalid_Analytics",
79
  "Invalid_DateTime" => "Mailchimp_Invalid_DateTime",
80
  "Invalid_Email" => "Mailchimp_Invalid_Email",
81
  "Invalid_SendType" => "Mailchimp_Invalid_SendType",
82
  "Invalid_Template" => "Mailchimp_Invalid_Template",
83
  "Invalid_TrackingOptions" => "Mailchimp_Invalid_TrackingOptions",
84
  "Invalid_Options" => "Mailchimp_Invalid_Options",
85
  "Invalid_Folder" => "Mailchimp_Invalid_Folder",
86
  "Invalid_URL" => "Mailchimp_Invalid_URL",
87
  "Module_Unknown" => "Mailchimp_Module_Unknown",
88
  "MonthlyPlan_Unknown" => "Mailchimp_MonthlyPlan_Unknown",
89
  "Order_TypeUnknown" => "Mailchimp_Order_TypeUnknown",
90
  "Invalid_PagingLimit" => "Mailchimp_Invalid_PagingLimit",
91
  "Invalid_PagingStart" => "Mailchimp_Invalid_PagingStart",
92
  "Max_Size_Reached" => "Mailchimp_Max_Size_Reached",
93
  "MC_SearchException" => "Mailchimp_MC_SearchException",
94
  "Goal_SaveFailed" => "Mailchimp_Goal_SaveFailed",
95
  "Conversation_DoesNotExist" => "Mailchimp_Conversation_DoesNotExist",
96
  "Conversation_ReplySaveFailed" => "Mailchimp_Conversation_ReplySaveFailed",
97
  "File_Not_Found_Exception" => "Mailchimp_File_Not_Found_Exception",
98
  "Folder_Not_Found_Exception" => "Mailchimp_Folder_Not_Found_Exception",
99
  "Folder_Exists_Exception" => "Mailchimp_Folder_Exists_Exception"
100
  );
101
  public function __construct($apikey=null, $opts=array()) {
102
  if (!$apikey) {
103
  $apikey = getenv('MAILCHIMP_APIKEY');
104
  }
105
  if (!$apikey) {
106
  $apikey = $this->readConfigs();
107
  }
108
  if (!$apikey) {
109
  throw new Mailchimp_Error('You must provide a MailChimp API key');
110
  }
111
  $this->apikey = $apikey;
112
  $dc = "us1";
113
  if (strstr($this->apikey, "-")){
114
  list($key, $dc) = explode("-", $this->apikey, 2);
115
  if (!$dc) {
116
  $dc = "us1";
117
  }
118
  }
119
  $this->root = str_replace('https://api', 'https://' . $dc . '.api', $this->root);
120
  $this->root = rtrim($this->root, '/') . '/';
121
  if (!isset($opts['timeout']) || !is_int($opts['timeout'])){
122
  $opts['timeout'] = 600;
123
  }
124
  if (isset($opts['debug'])){
125
  $this->debug = true;
126
  }
127
  $this->ch = curl_init();
128
  if (isset($opts['CURLOPT_FOLLOWLOCATION']) && $opts['CURLOPT_FOLLOWLOCATION'] === true) {
129
  curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
130
  }
131
  curl_setopt($this->ch, CURLOPT_USERAGENT, 'MailChimp-PHP/2.0.6');
132
  curl_setopt($this->ch, CURLOPT_POST, true);
133
  curl_setopt($this->ch, CURLOPT_HEADER, false);
134
  curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
135
  curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
136
  curl_setopt($this->ch, CURLOPT_TIMEOUT, $opts['timeout']);
137
  $this->folders = new Mailchimp_Folders($this);
138
  $this->templates = new Mailchimp_Templates($this);
139
  $this->users = new Mailchimp_Users($this);
140
  $this->helper = new Mailchimp_Helper($this);
141
  $this->mobile = new Mailchimp_Mobile($this);
142
  $this->conversations = new Mailchimp_Conversations($this);
143
  $this->ecomm = new Mailchimp_Ecomm($this);
144
  $this->neapolitan = new Mailchimp_Neapolitan($this);
145
  $this->lists = new Mailchimp_Lists($this);
146
  $this->campaigns = new Mailchimp_Campaigns($this);
147
  $this->vip = new Mailchimp_Vip($this);
148
  $this->reports = new Mailchimp_Reports($this);
149
  $this->gallery = new Mailchimp_Gallery($this);
150
  $this->goal = new Mailchimp_Goal($this);
151
  }
152
  public function __destruct() {
153
  if(is_resource($this->ch)) {
154
  curl_close($this->ch);
155
  }
156
  }
157
  public function call($url, $params) {
158
  $params['apikey'] = $this->apikey;
159
 
160
  $params = json_encode($params);
161
  $ch = $this->ch;
162
  curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json');
163
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
164
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
165
  curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);
166
  $start = microtime(true);
167
  $this->log('Call to ' . $this->root . $url . '.json: ' . $params);
168
  if($this->debug) {
169
  $curl_buffer = fopen('php://memory', 'w+');
170
  curl_setopt($ch, CURLOPT_STDERR, $curl_buffer);
171
  }
172
  $response_body = curl_exec($ch);
173
  $info = curl_getinfo($ch);
174
  $time = microtime(true) - $start;
175
  if($this->debug) {
176
  rewind($curl_buffer);
177
  $this->log(stream_get_contents($curl_buffer));
178
  fclose($curl_buffer);
179
  }
180
  $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms');
181
  $this->log('Got response: ' . $response_body);
182
  if(curl_error($ch)) {
183
  throw new Mailchimp_HttpError("API call to $url failed: " . curl_error($ch));
184
  }
185
  $result = json_decode($response_body, true);
186
 
187
  if(floor($info['http_code'] / 100) >= 4) {
188
  throw $this->castError($result);
189
  }
190
  return $result;
191
  }
192
  public function readConfigs() {
193
  $paths = array('~/.mailchimp.key', '/etc/mailchimp.key');
194
  foreach($paths as $path) {
195
  if(file_exists($path)) {
196
  $apikey = trim(file_get_contents($path));
197
  if ($apikey) {
198
  return $apikey;
199
  }
200
  }
201
  }
202
  return false;
203
  }
204
  public function castError($result) {
205
  if ($result['status'] !== 'error' || !$result['name']) {
206
  throw new Mailchimp_Error('We received an unexpected error: ' . json_encode($result));
207
  }
208
  $class = (isset(self::$error_map[$result['name']])) ? self::$error_map[$result['name']] : 'Mailchimp_Error';
209
  return new $class($result['error'], $result['code']);
210
  }
211
  public function log($msg) {
212
  if ($this->debug) {
213
  error_log($msg);
214
  }
215
  }
216
+ <?php
217
 
218
  public $apikey;
219
  public $ch;
220
  public $root = 'https://api.mailchimp.com/2.0';
221
  public $debug = false;
222
  public static $error_map = array(
223
  "ValidationError" => "Mailchimp_ValidationError",
224
  "ServerError_MethodUnknown" => "Mailchimp_ServerError_MethodUnknown",
225
  "ServerError_InvalidParameters" => "Mailchimp_ServerError_InvalidParameters",
226
  "Unknown_Exception" => "Mailchimp_Unknown_Exception",
227
  "Request_TimedOut" => "Mailchimp_Request_TimedOut",
228
  "Zend_Uri_Exception" => "Mailchimp_Zend_Uri_Exception",
229
  "PDOException" => "Mailchimp_PDOException",
230
  "Avesta_Db_Exception" => "Mailchimp_Avesta_Db_Exception",
231
  "XML_RPC2_Exception" => "Mailchimp_XML_RPC2_Exception",
232
  "XML_RPC2_FaultException" => "Mailchimp_XML_RPC2_FaultException",
233
  "Too_Many_Connections" => "Mailchimp_Too_Many_Connections",
234
  "Parse_Exception" => "Mailchimp_Parse_Exception",
235
  "User_Unknown" => "Mailchimp_User_Unknown",
236
  "User_Disabled" => "Mailchimp_User_Disabled",
237
  "User_DoesNotExist" => "Mailchimp_User_DoesNotExist",
238
  "User_NotApproved" => "Mailchimp_User_NotApproved",
239
  "Invalid_ApiKey" => "Mailchimp_Invalid_ApiKey",
240
  "User_UnderMaintenance" => "Mailchimp_User_UnderMaintenance",
241
  "Invalid_AppKey" => "Mailchimp_Invalid_AppKey",
242
  "Invalid_IP" => "Mailchimp_Invalid_IP",
243
  "User_DoesExist" => "Mailchimp_User_DoesExist",
244
  "User_InvalidRole" => "Mailchimp_User_InvalidRole",
245
  "User_InvalidAction" => "Mailchimp_User_InvalidAction",
246
  "User_MissingEmail" => "Mailchimp_User_MissingEmail",
247
  "User_CannotSendCampaign" => "Mailchimp_User_CannotSendCampaign",
248
  "User_MissingModuleOutbox" => "Mailchimp_User_MissingModuleOutbox",
249
  "User_ModuleAlreadyPurchased" => "Mailchimp_User_ModuleAlreadyPurchased",
250
  "User_ModuleNotPurchased" => "Mailchimp_User_ModuleNotPurchased",
251
  "User_NotEnoughCredit" => "Mailchimp_User_NotEnoughCredit",
252
  "MC_InvalidPayment" => "Mailchimp_MC_InvalidPayment",
253
  "List_DoesNotExist" => "Mailchimp_List_DoesNotExist",
254
  "List_InvalidInterestFieldType" => "Mailchimp_List_InvalidInterestFieldType",
255
  "List_InvalidOption" => "Mailchimp_List_InvalidOption",
256
  "List_InvalidUnsubMember" => "Mailchimp_List_InvalidUnsubMember",
257
  "List_InvalidBounceMember" => "Mailchimp_List_InvalidBounceMember",
258
  "List_AlreadySubscribed" => "Mailchimp_List_AlreadySubscribed",
259
  "List_NotSubscribed" => "Mailchimp_List_NotSubscribed",
260
  "List_InvalidImport" => "Mailchimp_List_InvalidImport",
261
  "MC_PastedList_Duplicate" => "Mailchimp_MC_PastedList_Duplicate",
262
  "MC_PastedList_InvalidImport" => "Mailchimp_MC_PastedList_InvalidImport",
263
  "Email_AlreadySubscribed" => "Mailchimp_Email_AlreadySubscribed",
264
  "Email_AlreadyUnsubscribed" => "Mailchimp_Email_AlreadyUnsubscribed",
265
  "Email_NotExists" => "Mailchimp_Email_NotExists",
266
  "Email_NotSubscribed" => "Mailchimp_Email_NotSubscribed",
267
  "List_MergeFieldRequired" => "Mailchimp_List_MergeFieldRequired",
268
  "List_CannotRemoveEmailMerge" => "Mailchimp_List_CannotRemoveEmailMerge",
269
  "List_Merge_InvalidMergeID" => "Mailchimp_List_Merge_InvalidMergeID",
270
  "List_TooManyMergeFields" => "Mailchimp_List_TooManyMergeFields",
271
  "List_InvalidMergeField" => "Mailchimp_List_InvalidMergeField",
272
  "List_InvalidInterestGroup" => "Mailchimp_List_InvalidInterestGroup",
273
  "List_TooManyInterestGroups" => "Mailchimp_List_TooManyInterestGroups",
274
  "Campaign_DoesNotExist" => "Mailchimp_Campaign_DoesNotExist",
275
  "Campaign_StatsNotAvailable" => "Mailchimp_Campaign_StatsNotAvailable",
276
  "Campaign_InvalidAbsplit" => "Mailchimp_Campaign_InvalidAbsplit",
277
  "Campaign_InvalidContent" => "Mailchimp_Campaign_InvalidContent",
278
  "Campaign_InvalidOption" => "Mailchimp_Campaign_InvalidOption",
279
  "Campaign_InvalidStatus" => "Mailchimp_Campaign_InvalidStatus",
280
  "Campaign_NotSaved" => "Mailchimp_Campaign_NotSaved",
281
  "Campaign_InvalidSegment" => "Mailchimp_Campaign_InvalidSegment",
282
  "Campaign_InvalidRss" => "Mailchimp_Campaign_InvalidRss",
283
  "Campaign_InvalidAuto" => "Mailchimp_Campaign_InvalidAuto",
284
  "MC_ContentImport_InvalidArchive" => "Mailchimp_MC_ContentImport_InvalidArchive",
285
  "Campaign_BounceMissing" => "Mailchimp_Campaign_BounceMissing",
286
  "Campaign_InvalidTemplate" => "Mailchimp_Campaign_InvalidTemplate",
287
  "Invalid_EcommOrder" => "Mailchimp_Invalid_EcommOrder",
288
  "Absplit_UnknownError" => "Mailchimp_Absplit_UnknownError",
289
  "Absplit_UnknownSplitTest" => "Mailchimp_Absplit_UnknownSplitTest",
290
  "Absplit_UnknownTestType" => "Mailchimp_Absplit_UnknownTestType",
291
  "Absplit_UnknownWaitUnit" => "Mailchimp_Absplit_UnknownWaitUnit",
292
  "Absplit_UnknownWinnerType" => "Mailchimp_Absplit_UnknownWinnerType",
293
  "Absplit_WinnerNotSelected" => "Mailchimp_Absplit_WinnerNotSelected",
294
  "Invalid_Analytics" => "Mailchimp_Invalid_Analytics",
295
  "Invalid_DateTime" => "Mailchimp_Invalid_DateTime",
296
  "Invalid_Email" => "Mailchimp_Invalid_Email",
297
  "Invalid_SendType" => "Mailchimp_Invalid_SendType",
298
  "Invalid_Template" => "Mailchimp_Invalid_Template",
299
  "Invalid_TrackingOptions" => "Mailchimp_Invalid_TrackingOptions",
300
  "Invalid_Options" => "Mailchimp_Invalid_Options",
301
  "Invalid_Folder" => "Mailchimp_Invalid_Folder",
302
  "Invalid_URL" => "Mailchimp_Invalid_URL",
303
  "Module_Unknown" => "Mailchimp_Module_Unknown",
304
  "MonthlyPlan_Unknown" => "Mailchimp_MonthlyPlan_Unknown",
305
  "Order_TypeUnknown" => "Mailchimp_Order_TypeUnknown",
306
  "Invalid_PagingLimit" => "Mailchimp_Invalid_PagingLimit",
307
  "Invalid_PagingStart" => "Mailchimp_Invalid_PagingStart",
308
  "Max_Size_Reached" => "Mailchimp_Max_Size_Reached",
309
  "MC_SearchException" => "Mailchimp_MC_SearchException",
310
  "Goal_SaveFailed" => "Mailchimp_Goal_SaveFailed",
311
  "Conversation_DoesNotExist" => "Mailchimp_Conversation_DoesNotExist",
312
  "Conversation_ReplySaveFailed" => "Mailchimp_Conversation_ReplySaveFailed",
313
  "File_Not_Found_Exception" => "Mailchimp_File_Not_Found_Exception",
314
  "Folder_Not_Found_Exception" => "Mailchimp_Folder_Not_Found_Exception",
315
  "Folder_Exists_Exception" => "Mailchimp_Folder_Exists_Exception"
316
  );
317
  public function __construct($apikey=null, $opts=array()) {
318
  if (!$apikey) {
319
  $apikey = getenv('MAILCHIMP_APIKEY');
320
  }
321
  if (!$apikey) {
322
  $apikey = $this->readConfigs();
323
  }
324
  if (!$apikey) {
325
  throw new Mailchimp_Error('You must provide a MailChimp API key');
326
  }
327
  $this->apikey = $apikey;
328
  $dc = "us1";
329
  if (strstr($this->apikey, "-")){
330
  list($key, $dc) = explode("-", $this->apikey, 2);
331
  if (!$dc) {
332
  $dc = "us1";
333
  }
334
  }
335
  $this->root = str_replace('https://api', 'https://' . $dc . '.api', $this->root);
336
  $this->root = rtrim($this->root, '/') . '/';
337
  if (!isset($opts['timeout']) || !is_int($opts['timeout'])){
338
  $opts['timeout'] = 600;
339
  }
340
  if (isset($opts['debug'])){
341
  $this->debug = true;
342
  }
343
  $this->ch = curl_init();
344
  if (isset($opts['CURLOPT_FOLLOWLOCATION']) && $opts['CURLOPT_FOLLOWLOCATION'] === true) {
345
  curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
346
  }
347
  curl_setopt($this->ch, CURLOPT_USERAGENT, 'MailChimp-PHP/2.0.6');
348
  curl_setopt($this->ch, CURLOPT_POST, true);
349
  curl_setopt($this->ch, CURLOPT_HEADER, false);
350
  curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
351
  curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
352
  curl_setopt($this->ch, CURLOPT_TIMEOUT, $opts['timeout']);
353
  $this->folders = new Mailchimp_Folders($this);
354
  $this->templates = new Mailchimp_Templates($this);
355
  $this->users = new Mailchimp_Users($this);
356
  $this->helper = new Mailchimp_Helper($this);
357
  $this->mobile = new Mailchimp_Mobile($this);
358
  $this->conversations = new Mailchimp_Conversations($this);
359
  $this->ecomm = new Mailchimp_Ecomm($this);
360
  $this->neapolitan = new Mailchimp_Neapolitan($this);
361
  $this->lists = new Mailchimp_Lists($this);
362
  $this->campaigns = new Mailchimp_Campaigns($this);
363
  $this->vip = new Mailchimp_Vip($this);
364
  $this->reports = new Mailchimp_Reports($this);
365
  $this->gallery = new Mailchimp_Gallery($this);
366
  $this->goal = new Mailchimp_Goal($this);
367
  }
368
  public function __destruct() {
369
  if(is_resource($this->ch)) {
370
  curl_close($this->ch);
371
  }
372
  }
373
  public function call($url, $params) {
374
  $params['apikey'] = $this->apikey;
375
 
376
  $params = json_encode($params);
377
  $ch = $this->ch;
378
  curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json');
379
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
380
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
381
  curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);
382
  $start = microtime(true);
383
  $this->log('Call to ' . $this->root . $url . '.json: ' . $params);
384
  if($this->debug) {
385
  $curl_buffer = fopen('php://memory', 'w+');
386
  curl_setopt($ch, CURLOPT_STDERR, $curl_buffer);
387
  }
388
  $response_body = curl_exec($ch);
389
  $info = curl_getinfo($ch);
390
  $time = microtime(true) - $start;
391
  if($this->debug) {
392
  rewind($curl_buffer);
393
  $this->log(stream_get_contents($curl_buffer));
394
  fclose($curl_buffer);
395
  }
396
  $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms');
397
  $this->log('Got response: ' . $response_body);
398
  if(curl_error($ch)) {
399
  throw new Mailchimp_HttpError("API call to $url failed: " . curl_error($ch));
400
  }
401
  $result = json_decode($response_body, true);
402
  if( defined( 'YIKES_MAILCHIMP_NULL_DEBUG' ) && YIKES_MAILCHIMP_NULL_DEBUG == '1' ) {
403
  if(floor($info['http_code'] / 100) >= 4) {
404
  throw $this->castError($result);
405
  }
406
  return $result;
407
  }
408
  public function readConfigs() {
409
  $paths = array('~/.mailchimp.key', '/etc/mailchimp.key');
410
  foreach($paths as $path) {
411
  if(file_exists($path)) {
412
  $apikey = trim(file_get_contents($path));
413
  if ($apikey) {
414
  return $apikey;
415
  }
416
  }
417
  }
418
  return false;
419
  }
420
  public function castError($result) {
421
  if ($result['status'] !== 'error' || !$result['name']) {
422
  throw new Mailchimp_Error('We received an unexpected error: ' . json_encode($result));
423
  }
424
  $class = (isset(self::$error_map[$result['name']])) ? self::$error_map[$result['name']] : 'Mailchimp_Error';
425
  return new $class($result['error'], $result['code']);
426
  }
427
  public function log($msg) {
428
  if ($this->debug) {
429
  error_log($msg);
430
  }
431
  }
includes/class-yikes-inc-easy-mailchimp-extender.php CHANGED
@@ -62,7 +62,7 @@ class Yikes_Inc_Easy_Mailchimp_Extender {
62
  */
63
  public function __construct() {
64
  $this->yikes_inc_easy_mailchimp_extender = 'yikes-inc-easy-mailchimp-extender';
65
- $this->version = '6.0.3.1';
66
  $this->load_dependencies();
67
  $this->set_locale();
68
  $this->define_admin_hooks();
62
  */
63
  public function __construct() {
64
  $this->yikes_inc_easy_mailchimp_extender = 'yikes-inc-easy-mailchimp-extender';
65
+ $this->version = '6.0.3.2';
66
  $this->load_dependencies();
67
  $this->set_locale();
68
  $this->define_admin_hooks();
includes/error_log/yikes-easy-mailchimp-error-log.php CHANGED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <tr>
2
+ <td class="row-title">
3
+ <label for="tablecell">
4
+ <em>API Call To Helper/ping Failed: Could Not Resolve Host: Us32.api.mailchimp.com</em>
5
+ </label>
6
+ </td>
7
+ <td>
8
+ Page: Settings Page/General Settings || Type: Connecting to MailChimp || Time: November 9, 2015 4:29 pm </td>
9
+ </tr>
10
+ <tr>
11
+ <td class="row-title">
12
+ <label for="tablecell">
13
+ <em>API Call To Helper/ping Failed: Could Not Resolve Host: Us32.api.mailchimp.com</em>
14
+ </label>
15
+ </td>
16
+ <td>
17
+ Page: Settings Page/General Settings || Type: Connecting to MailChimp || Time: November 9, 2015 4:28 pm </td>
18
+ </tr>
19
+ <tr>
20
+ <td class="row-title">
21
+ <label for="tablecell">
22
+ <em>API Call To Helper/ping Failed: Could Not Resolve Host: Us32.api.mailchimp.com</em>
23
+ </label>
24
+ </td>
25
+ <td>
26
+ Page: Settings Page/General Settings || Type: Connecting to MailChimp || Time: November 9, 2015 3:43 pm </td>
27
+ </tr>
28
+ <tr>
29
+ <td class="row-title">
30
+ <label for="tablecell">
31
+ <em>You Must Provide A MailChimp API Key</em>
32
+ </label>
33
+ </td>
34
+ <td>
35
+ Page: Settings Page/General Settings || Type: Connecting to MailChimp || Time: November 9, 2015 3:39 pm </td>
36
+ </tr>
37
+ <tr>
38
+ <td class="row-title">
39
+ <label for="tablecell">
40
+ <em>You Must Provide A MailChimp API Key</em>
41
+ </label>
42
+ </td>
43
+ <td>
44
+ Page: Settings Page/General Settings || Type: Connecting to MailChimp || Time: November 9, 2015 3:37 pm </td>
45
+ </tr>
46
+
public/class-yikes-inc-easy-mailchimp-extender-public.php CHANGED
@@ -63,6 +63,8 @@ class Yikes_Inc_Easy_Mailchimp_Extender_Public {
63
  add_action( 'init' , array( $this , 'load_checkbox_integration_classes' ) , 1 );
64
  // custom front end filter
65
  add_action( 'init', array( $this, 'yikes_custom_frontend_content_filter' ) );
 
 
66
  }
67
 
68
  /**
@@ -117,6 +119,37 @@ class Yikes_Inc_Easy_Mailchimp_Extender_Public {
117
  $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging;
118
  }
119
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  }
122
 
63
  add_action( 'init' , array( $this , 'load_checkbox_integration_classes' ) , 1 );
64
  // custom front end filter
65
  add_action( 'init', array( $this, 'yikes_custom_frontend_content_filter' ) );
66
+ // check if the form was submit, confirm redirect setting, and re-direct in the proper way/location
67
+ add_action( 'template_redirect', array( $this, 'redirect_user_non_ajax_forms' ) );
68
  }
69
 
70
  /**
119
  $error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging;
120
  }
121
  }
122
+
123
+ /*
124
+ * Proper redirect for non-ajax forms, using wp_redirect() -- not JavaScript
125
+ * - Ensure the form was submit, grab the data and redirect as needed
126
+ * - Processes the submission, and then redirects the users properly
127
+ * @since 6.0.3.2
128
+ */
129
+ public function redirect_user_non_ajax_forms() {
130
+ // confirm the data was submitted for our forms
131
+ if( isset( $_POST['yikes-mailchimp-submitted-form'] ) && ( isset( $_POST['yikes-mailchimp-honeypot'] ) && empty( $_POST['yikes-mailchimp-honeypot'] ) ) ) {
132
+ global $wpdb, $post;
133
+ $page_data = $post; // store global post data
134
+ $form_id = (int) $_POST['yikes-mailchimp-submitted-form']; // store form id
135
+ $form_results = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'yikes_easy_mc_forms WHERE id = ' . $form_id . '', ARRAY_A ); // query for our form data
136
+ if( $form_results ) {
137
+ $form_data = $form_results[0]; // store the results
138
+ // lets include our form processing file -- since this get's skipped when a re-direct is setup
139
+ include_once( YIKES_MC_PATH . 'public/partials/shortcodes/process/process_form_submission.php' );
140
+ // decode our settings
141
+ $submission_settings = json_decode( stripslashes( $form_data['submission_settings'] ) , true );
142
+ // confirm the submission setting is set
143
+ if( $submission_settings['redirect_on_submission'] == '1' ) {
144
+ // grab the page
145
+ $redirect_page = get_permalink( (int) $form_data['redirect_page'] );
146
+ wp_redirect( apply_filters( 'yikes-mailchimp-redirect-url', esc_url( $redirect_page ), $form_id, $page_data ) );
147
+ exit;
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
 
154
  }
155
 
public/partials/shortcodes/process/process_form_submission.php CHANGED
@@ -17,7 +17,7 @@ if ( ! isset( $_POST['yikes_easy_mc_new_subscriber'] ) || ! wp_verify_nonce( $_P
17
  }
18
 
19
  // Check reCaptcha Response
20
- if( get_option( 'yikes-mc-recaptcha-status' , '' ) == '1' ) {
21
  $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key' , '' ) . '&response=' . $_POST['g-recaptcha-response'] . '&remoteip=' . $_SERVER["REMOTE_ADDR"] );
22
  $response = wp_remote_get( $url );
23
  $response_body = json_decode( $response['body'] , true );
@@ -138,11 +138,9 @@ if ( ! isset( $_POST['yikes_easy_mc_new_subscriber'] ) || ! wp_verify_nonce( $_P
138
  do_action( 'yikes-mailchimp-after-submission-'.$form , $merge_variables );
139
 
140
  /*
141
- * Successful form submission redirect
 
142
  */
143
- if( $submission_settings['redirect_on_submission'] == '1' ) {
144
- echo '<script type="text/javascript">setTimeout(function() { window.location="' . apply_filters( 'yikes-mailchimp-redirect-url', get_permalink( $submission_settings['redirect_page'] ), $form, $page_data ) . '"; }, ' . apply_filters( 'yikes-mailchimp-redirect-timer' , 1500, $form ) . ');</script>';
145
- }
146
 
147
  /*
148
  * yikes-mailchimp-form-submission
17
  }
18
 
19
  // Check reCaptcha Response
20
+ if( isset( $_POST['g-recaptcha-response'] ) ) {
21
  $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key' , '' ) . '&response=' . $_POST['g-recaptcha-response'] . '&remoteip=' . $_SERVER["REMOTE_ADDR"] );
22
  $response = wp_remote_get( $url );
23
  $response_body = json_decode( $response['body'] , true );
138
  do_action( 'yikes-mailchimp-after-submission-'.$form , $merge_variables );
139
 
140
  /*
141
+ * Non-AJAX redirects now handled in class-yikes-inc-easy-mailchimp-extender-public.php
142
+ * function: redirect_user_non_ajax_forms
143
  */
 
 
 
144
 
145
  /*
146
  * yikes-mailchimp-form-submission
public/partials/shortcodes/process/process_form_submission_ajax.php CHANGED
@@ -23,8 +23,11 @@
23
  $submission_settings = json_decode( stripslashes( $form_data['submission_settings'] ), true );
24
  // decode our optin settings
25
  $optin_settings = json_decode( stripslashes( $form_data['optin_settings'] ), true );
26
- // decode our error messages
27
- $error_messages = json_decode( stripslashes( $form_data['error_messages'] ), true );
 
 
 
28
  /** Submit Process **/
29
  $notifications = json_decode( stripslashes( $form_data['custom_notifications'] ), true );
30
  /* Page Data */
@@ -49,8 +52,8 @@
49
  return;
50
  }
51
 
52
- // Check reCaptcha Response
53
- if( get_option( 'yikes-mc-recaptcha-status' , '' ) == '1' ) {
54
  $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key' , '' ) . '&response=' . $data['g-recaptcha-response'] . '&remoteip=' . $_SERVER["REMOTE_ADDR"] );
55
  $response = wp_remote_get( $url );
56
  $response_body = json_decode( $response['body'] , true );
@@ -71,7 +74,7 @@
71
  'response' => __( "It looks like we've run into a reCaptcha error." , 'yikes-inc-easy-mailchimp-extender' ) .' '. implode( ' ', $error_messages ),
72
  ) );
73
  exit();
74
- }
75
  }
76
 
77
  // loop to push variables to our array
23
  $submission_settings = json_decode( stripslashes( $form_data['submission_settings'] ), true );
24
  // decode our optin settings
25
  $optin_settings = json_decode( stripslashes( $form_data['optin_settings'] ), true );
26
+ /* Decode our error messages
27
+ * Workaround for international characters (cyrillic etc)
28
+ * See: https://wordpress.org/support/topic/custom-messages-do-not-support-cyrillic-characters?replies=11#post-7629620
29
+ */
30
+ $error_messages = ( get_magic_quotes_gpc() ) ? json_decode( stripslashes( $form_data['error_messages'] ), true ) : json_decode( $form_data['error_messages'], true );
31
  /** Submit Process **/
32
  $notifications = json_decode( stripslashes( $form_data['custom_notifications'] ), true );
33
  /* Page Data */
52
  return;
53
  }
54
 
55
+ // Check reCaptcha Response was submitted with the form data
56
+ if( isset( $data['g-recaptcha-response'] ) ) {
57
  $url = esc_url_raw( 'https://www.google.com/recaptcha/api/siteverify?secret=' . get_option( 'yikes-mc-recaptcha-secret-key' , '' ) . '&response=' . $data['g-recaptcha-response'] . '&remoteip=' . $_SERVER["REMOTE_ADDR"] );
58
  $response = wp_remote_get( $url );
59
  $response_body = json_decode( $response['body'] , true );
74
  'response' => __( "It looks like we've run into a reCaptcha error." , 'yikes-inc-easy-mailchimp-extender' ) .' '. implode( ' ', $error_messages ),
75
  ) );
76
  exit();
77
+ }
78
  }
79
 
80
  // loop to push variables to our array
public/partials/shortcodes/process_form_shortcode.php CHANGED
@@ -9,8 +9,16 @@ function process_mailchimp_shortcode( $atts ) {
9
  'form' => '',
10
  'submit' => 'Submit',
11
  'title' => '0',
 
12
  'description' => '0',
13
  'ajax' => '',
 
 
 
 
 
 
 
14
  ), $atts , 'yikes-mailchimp' )
15
  );
16
 
@@ -32,27 +40,45 @@ function process_mailchimp_shortcode( $atts ) {
32
  if( !$form_results ) {
33
  return __( "Oh no...This form doesn't exist. Head back to the manage forms page and select a different form." , 'yikes-inc-easy-mailchimp-extender' );
34
  }
35
-
36
  /*
37
  * Check if the user wants to use reCAPTCHA Spam Prevention
38
  */
39
  if( get_option( 'yikes-mc-recaptcha-status' , '' ) == '1' ) {
40
- // if either of the Private the Secret key is left blank, we should display an error back to the user
41
- if( get_option( 'yikes-mc-recaptcha-site-key' , '' ) == '' ) {
42
- return __( "Whoops! It looks like you enabled reCAPTCHA but forgot to enter the reCAPTCHA site key!" , 'yikes-inc-easy-mailchimp-extender' ) . '<span class="edit-link yikes-easy-mc-edit-link"><a class="post-edit-link" href="' . esc_url( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=recaptcha-settings' ) ) . '" title="' . __( 'ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'Edit ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '</a></span>';
43
- }
44
- if( get_option( 'yikes-mc-recaptcha-secret-key' , '' ) == '' ) {
45
- return __( "Whoops! It looks like you enabled reCAPTCHA but forgot to enter the reCAPTCHA secret key!" , 'yikes-inc-easy-mailchimp-extender' ) . '<span class="edit-link yikes-easy-mc-edit-link"><a class="post-edit-link" href="' . esc_url( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=recaptcha-settings' ) ) . '" title="' . __( 'ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'Edit ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '</a></span>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  }
47
- // Store the site language (to load recaptcha in a specific language)
48
- $locale = get_locale();
49
- $locale_split = explode( '_', $locale );
50
- $lang = ( isset( $locale_split ) ? $locale_split[0] : $locale );
51
- // enqueue Google recaptcha JS
52
- wp_register_script( 'google-recaptcha-js' , 'https://www.google.com/recaptcha/api.js?hl=' . $lang , array( 'jquery' ) , 'all' );
53
- wp_enqueue_script( 'google-recaptcha-js' );
54
- $recaptcha_site_key = get_option( 'yikes-mc-recaptcha-site-key' , '' );
55
- $recaptcha_box = '<div name="g-recaptcha" class="g-recaptcha" data-sitekey="' . $recaptcha_site_key . '"></div>';
56
  }
57
 
58
  // place our results into a seperate variable for easy looping
@@ -66,8 +92,6 @@ function process_mailchimp_shortcode( $atts ) {
66
  $fields = json_decode( $form_data['fields'] , true );
67
  $styles = json_decode( stripslashes( $form_data['custom_styles'] ) , true );
68
  $send_welcome = $form_data['send_welcome_email'];
69
- $redirect_user = $form_data['redirect_user_on_submit'];
70
- $redirect_page = $form_data['redirect_page'];
71
  $submission_settings = json_decode( stripslashes( $form_data['submission_settings'] ) , true );
72
  $optin_settings = json_decode( stripslashes( $form_data['optin_settings'] ) , true );
73
  $error_messages = json_decode( $form_data['error_messages'] , true );
@@ -132,10 +156,18 @@ function process_mailchimp_shortcode( $atts ) {
132
  // used to hide the form, keep values in the form etc.
133
  $form_submitted = 0;
134
 
135
- // display the form description if the user
136
- // has specified to do so
137
- if( !empty( $title ) && $title == 1 ) {
138
- echo '<h3 class="yikes-mailchimp-form-title yikes-mailchimp-form-title-'.$form_id.'">' . apply_filters( 'yikes-mailchimp-form-title', apply_filters( 'the_title', $form_name ), $form_id ) . '</h3>';
 
 
 
 
 
 
 
 
139
  }
140
 
141
  // display the form description if the user
@@ -818,7 +850,7 @@ function process_mailchimp_shortcode( $atts ) {
818
  <input type="hidden" name="yikes-mailchimp-submitted-form" id="yikes-mailchimp-submitted-form" value="<?php echo $form_id; ?>">
819
 
820
  <!-- Submit Button -->
821
- <?php echo apply_filters( 'yikes-mailchimp-form-submit-button', '<button type="submit" class="yikes-easy-mc-submit-button yikes-easy-mc-submit-button-' . esc_attr( $form_data['id'] ) . ' btn btn-primary ' . $admin_class . '">' . apply_filters( 'yikes-mailchimp-form-submit-button-text', esc_attr( stripslashes( $submit ) ), $form_data['id'] ) . '</button>', $form_data['id'] ); ?>
822
  <!-- Nonce Security Check -->
823
  <?php wp_nonce_field( 'yikes_easy_mc_form_submit', 'yikes_easy_mc_new_subscriber' ); ?>
824
 
9
  'form' => '',
10
  'submit' => 'Submit',
11
  'title' => '0',
12
+ 'custom_title' => '',
13
  'description' => '0',
14
  'ajax' => '',
15
+ 'recaptcha' => '', // manually set googles recptcha state
16
+ 'recaptcha_lang' => '', // manually set the recaptcha language in the shortcode - also available is the yikes-mailchimp-recaptcha-language filter
17
+ 'recaptcha_type' => '', // manually set the recaptcha type - audio/image - default image
18
+ 'recaptcha_theme' => '', // manually set the recaptcha theme - light/dark - default light
19
+ 'recaptcha_size' => '', // set the recaptcha size - normal/compact - default normal
20
+ 'recaptcha_data_callback' => '', // set a custom js callback function to run after a successful recaptcha response - default none
21
+ 'recaptcha_expired_callback' => '', // set a custom js callback function to run after the recaptcha has expired - default none
22
  ), $atts , 'yikes-mailchimp' )
23
  );
24
 
40
  if( !$form_results ) {
41
  return __( "Oh no...This form doesn't exist. Head back to the manage forms page and select a different form." , 'yikes-inc-easy-mailchimp-extender' );
42
  }
43
+
44
  /*
45
  * Check if the user wants to use reCAPTCHA Spam Prevention
46
  */
47
  if( get_option( 'yikes-mc-recaptcha-status' , '' ) == '1' ) {
48
+ // allow users to manually set recaptcha (instead of globally - recaptcha="1"/recaptcha="0" - but still needs to be globally enabled on the settings page)
49
+ if( ! isset( $atts['recaptcha'] ) || ( isset( $atts['recaptcha'] ) && $atts['recaptcha'] == '1' ) ) {
50
+ // if either of the Private the Secret key is left blank, we should display an error back to the user
51
+ if( get_option( 'yikes-mc-recaptcha-site-key' , '' ) == '' ) {
52
+ return __( "Whoops! It looks like you enabled reCAPTCHA but forgot to enter the reCAPTCHA site key!" , 'yikes-inc-easy-mailchimp-extender' ) . '<span class="edit-link yikes-easy-mc-edit-link"><a class="post-edit-link" href="' . esc_url( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=recaptcha-settings' ) ) . '" title="' . __( 'ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'Edit ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '</a></span>';
53
+ }
54
+ if( get_option( 'yikes-mc-recaptcha-secret-key' , '' ) == '' ) {
55
+ return __( "Whoops! It looks like you enabled reCAPTCHA but forgot to enter the reCAPTCHA secret key!" , 'yikes-inc-easy-mailchimp-extender' ) . '<span class="edit-link yikes-easy-mc-edit-link"><a class="post-edit-link" href="' . esc_url( admin_url( 'admin.php?page=yikes-inc-easy-mailchimp-settings&section=recaptcha-settings' ) ) . '" title="' . __( 'ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( 'Edit ReCaptcha Settings' , 'yikes-inc-easy-mailchimp-extender' ) . '</a></span>';
56
+ }
57
+ // Store the site language (to load recaptcha in a specific language)
58
+ $locale = get_locale();
59
+ $locale_split = explode( '_', $locale );
60
+ $lang = ( isset( $locale_split ) ? $locale_split[0] : $locale );
61
+ $lang = ( isset( $atts['recaptcha_lang'] ) ) ? $atts['recaptcha_lang'] : $locale_split[0];
62
+ $type = ( isset( $atts['recaptcha_type'] ) ) ? strtolower( $atts['recaptcha_type'] ) : 'image'; // setup recaptcha type
63
+ $theme= ( isset( $atts['recaptcha_theme'] ) ) ? strtolower( $atts['recaptcha_theme'] ) : 'light'; // setup recaptcha theme
64
+ $size = ( isset( $atts['recaptcha_size'] ) ) ? strtolower( $atts['recaptcha_size'] ) : 'normal'; // setup recaptcha size
65
+ $data_callback = ( isset( $atts['recaptcha_data_callback'] ) ) ? $atts['recaptcha_data_callback'] : false; // setup recaptcha size
66
+ $expired_callback = ( isset( $atts['recaptcha_expired_callback'] ) ) ? $atts['recaptcha_expired_callback'] : false; // setup recaptcha size
67
+ // Pass the shortcode parameters through a filter
68
+ $recaptcha_shortcode_params = apply_filters( 'yikes-mailchimp-recaptcha-parameters', array(
69
+ 'language' => $lang,
70
+ 'theme' => $theme,
71
+ 'type' => $type,
72
+ 'size' => $size,
73
+ 'success_callback' => $data_callback,
74
+ 'expired_callback' => $expired_callback,
75
+ ), $form );
76
+ // enqueue Google recaptcha JS
77
+ wp_register_script( 'google-recaptcha-js' , 'https://www.google.com/recaptcha/api.js?hl=' . $recaptcha_shortcode_params['language'] , array( 'jquery' ) , 'all' );
78
+ wp_enqueue_script( 'google-recaptcha-js' );
79
+ $recaptcha_site_key = get_option( 'yikes-mc-recaptcha-site-key' , '' );
80
+ $recaptcha_box = '<div name="g-recaptcha" class="g-recaptcha" data-sitekey="' . $recaptcha_site_key . '" data-theme="' . $recaptcha_shortcode_params['theme'] . '" data-type="' . $recaptcha_shortcode_params['type'] . '" data-size="' . $recaptcha_shortcode_params['size'] . '" data-callback="' . $recaptcha_shortcode_params['success_callback'] . '" data-expired-callback="' . $recaptcha_shortcode_params['expired_callback'] . '"></div>';
81
  }
 
 
 
 
 
 
 
 
 
82
  }
83
 
84
  // place our results into a seperate variable for easy looping
92
  $fields = json_decode( $form_data['fields'] , true );
93
  $styles = json_decode( stripslashes( $form_data['custom_styles'] ) , true );
94
  $send_welcome = $form_data['send_welcome_email'];
 
 
95
  $submission_settings = json_decode( stripslashes( $form_data['submission_settings'] ) , true );
96
  $optin_settings = json_decode( stripslashes( $form_data['optin_settings'] ) , true );
97
  $error_messages = json_decode( $form_data['error_messages'] , true );
156
  // used to hide the form, keep values in the form etc.
157
  $form_submitted = 0;
158
 
159
+ /*
160
+ * Set a custom title using custom_title="lorem ipsum" parameter in the shortcode
161
+ * - This takes precedence over the title set
162
+ */
163
+ if( ! empty( $title ) && $title == 1 && isset( $atts['custom_title'] ) ) {
164
+ echo '<h3 class="yikes-mailchimp-form-title yikes-mailchimp-form-title-'.$form_id.'">' . apply_filters( 'yikes-mailchimp-form-title', apply_filters( 'the_title', $atts['custom_title'] ), $form_id ) . '</h3>';
165
+ } else {
166
+ // display the form description if the user
167
+ // has specified to do so
168
+ if( ! empty( $title ) && $title == 1 ) {
169
+ echo '<h3 class="yikes-mailchimp-form-title yikes-mailchimp-form-title-'.$form_id.'">' . apply_filters( 'yikes-mailchimp-form-title', apply_filters( 'the_title', $form_name ), $form_id ) . '</h3>';
170
+ }
171
  }
172
 
173
  // display the form description if the user
850
  <input type="hidden" name="yikes-mailchimp-submitted-form" id="yikes-mailchimp-submitted-form" value="<?php echo $form_id; ?>">
851
 
852
  <!-- Submit Button -->
853
+ <?php echo apply_filters( 'yikes-mailchimp-form-submit-button', '<button type="submit" class="' . apply_filters( 'yikes-mailchimp-form-submit-button-classes', 'yikes-easy-mc-submit-button yikes-easy-mc-submit-button-' . esc_attr( $form_data['id'] ) . ' btn btn-primary ' . $admin_class, $form_data['id'] ) . '">' . apply_filters( 'yikes-mailchimp-form-submit-button-text', esc_attr( stripslashes( $submit ) ), $form_data['id'] ) . '</button>', $form_data['id'] ); ?>
854
  <!-- Nonce Security Check -->
855
  <?php wp_nonce_field( 'yikes_easy_mc_form_submit', 'yikes_easy_mc_new_subscriber' ); ?>
856
 
readme.txt CHANGED
@@ -1 +1 @@
1
- === Easy Forms for MailChimp ===
2
- added `stripslashes()` to the following settings fields :
3
- Updated readme FAQ section
4
- added `stripslashes()` to the following settings fields :
5
- Updated readme FAQ section
6
- added `stripslashes()` to the following settings fields :
7
- Updated readme FAQ section
8
- added `stripslashes()` to the following settings fields :
9
- Updated readme FAQ section
1
+ === Easy Forms for MailChimp ===
 
 
 
 
 
 
 
 
yikes-inc-easy-mailchimp-extender.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Easy Forms for MailChimp by YIKES
4
  * Plugin URI: http://www.yikesinc.com/services/yikes-inc-easy-mailchimp-extender/
5
  * Description: YIKES Easy Forms for MailChimp links your site to MailChimp and allows you to generate and display mailing list opt-in forms anywhere on your site with ease.
6
- * Version: 6.0.3.1
7
  * Author: YIKES
8
  * Author URI: http://www.yikesinc.com/
9
  * License: GPL-3.0+
3
  * Plugin Name: Easy Forms for MailChimp by YIKES
4
  * Plugin URI: http://www.yikesinc.com/services/yikes-inc-easy-mailchimp-extender/
5
  * Description: YIKES Easy Forms for MailChimp links your site to MailChimp and allows you to generate and display mailing list opt-in forms anywhere on your site with ease.
6
+ * Version: 6.0.3.2
7
  * Author: YIKES
8
  * Author URI: http://www.yikesinc.com/
9
  * License: GPL-3.0+