Easy Forms for MailChimp - Version 5.4.4

Version Description

  • September 24th, 2015 =
  • Added: Admin notice to warn about the upcoming release (major re-write)
Download this release

Release Info

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

Code changes from version 5.4.3 to 5.4.4

classes/class.yksemeBase.php CHANGED
@@ -1,3924 +1,3970 @@
1
- <?php
2
- if(!class_exists("yksemeBase")) {
3
- class yksemeBase {
4
-
5
- /**
6
- * Variables
7
- */
8
- private $error = false;
9
- private $errorMsg = '';
10
- public $sessName = 'ykseme';
11
- public $optionVal = false;
12
- public $currentLists = false;
13
- public $currentListsCt = false;
14
-
15
- /**
16
- * Construct
17
- */
18
- public function __construct() {
19
- yksemeBase::initialize();
20
- add_action('init', array(&$this, 'ykes_mc_apply_filters'));
21
- }
22
-
23
- /**
24
- * Destruct
25
- */
26
- public function __destruct() {
27
- unset($this);
28
- }
29
-
30
- /**
31
- * Actions
32
- * These are called when the plug in is initialized/deactivated/un-installed
33
- */
34
- public function activate() {
35
- // redirect the user on plugin activation
36
- // to our MailChimp settings page
37
- add_option('yks_easy_mc_plugin_do_activation_redirect', true);
38
-
39
- // check if our option is already set
40
- // if it exists, return
41
- if( get_option( 'api_validation' ) ) {
42
- return;
43
- } else { // else create it
44
- add_option('api_validation' , 'invalid_api_key');
45
- }
46
-
47
- }
48
-
49
- public function deactivate() {
50
-
51
- }
52
-
53
- public function uninstall() { // delete options on plugin uninstall
54
- delete_option(YKSEME_OPTION);
55
- delete_option('api_validation');
56
- delete_option('imported_lists');
57
- }
58
-
59
- /***** INITIAL SETUP
60
- ****************************************************************************************************/
61
- public function initialize() {
62
- // include our initialization file
63
- include YKSEME_PATH . 'lib/inc/yks-mc-init.php';
64
-
65
- /*
66
- Conditionally Include the MailChimp Class File
67
- */
68
- if( !class_exists("Mailchimp") ) {
69
- if ( $this->optionVal['ssl_verify_peer'] == 'true' ) {
70
- require_once YKSEME_PATH.'classes/MCAPI_2.0.class.php';
71
- } else {
72
- require_once YKSEME_PATH.'classes/MCAPI_2.0.class.verify_false.php';
73
- }
74
- }
75
-
76
- /*
77
- * add our new ssl_verify_peer debug option, if it doesn't already exist
78
- * @since v5.2
79
- */
80
- if ( !isset( $this->optionVal['ssl_verify_peer'] ) ) {
81
- $options = get_option( YKSEME_OPTION );
82
- $options['ssl_verify_peer'] = 'true';
83
- update_option( YKSEME_OPTION , $options );
84
- }
85
-
86
- /*
87
- * add our new hide 'required text' option, if it doesn't already exist
88
- * @since v5.3
89
- */
90
- if ( !isset( $this->optionVal['yks-mailchimp-required-text'] ) ) {
91
- $options = get_option( YKSEME_OPTION );
92
- $options['yks-mailchimp-required-text'] = '0';
93
- update_option( YKSEME_OPTION , $options );
94
- }
95
-
96
- }
97
-
98
- // register and add our shortcodes
99
- public function createShortcodes() {
100
- add_shortcode( 'yks-mailchimp-list' , array( &$this, 'processShortcode' ) );
101
- add_shortcode( 'yks-mailchimp-subscriber-count' , array( &$this, 'displaySubscriberCount') );
102
- }
103
-
104
- /** Custom Filter To Alter User Submitted Data **/
105
- public function yikes_mc_get_form_data_filter( $mv ) {
106
- return $mv;
107
- }
108
-
109
- /** Custom Filter To Alter User Already Subscribed Error Message **/
110
- public function yikes_mc_user_already_subscribed_error_message_filter( $errorMessage , $email ) {
111
- return $errorMessage;
112
- }
113
-
114
- // Create and store our initial plugin options
115
- public function getOptionValue() {
116
- $blog_title = get_bloginfo( 'name' );
117
- $defaultVals = array(
118
- 'version' => YKSEME_VERSION_CURRENT,
119
- 'api-key' => '',
120
- 'flavor' => '1',
121
- 'debug' => '0',
122
- 'optin' => 'true',
123
- 'single-optin-message' => __('Thank You for subscribing!', 'yikes-inc-easy-mailchimp-extender'),
124
- 'double-optin-message' => __('Thank You for subscribing! Check your email for the confirmation message.', 'yikes-inc-easy-mailchimp-extender'),
125
- 'optIn-checkbox' => 'hide',
126
- 'yks-mailchimp-optIn-default-list' => 'select_list',
127
- 'yks-mailchimp-optin-checkbox-text' => 'Add me to the ' . $blog_title . ' mailing list',
128
- 'recaptcha-setting' => '0',
129
- 'yks-mailchimp-required-text' => '0',
130
- 'recaptcha-api-key' => '',
131
- 'recaptcha-private-api-key' => '',
132
- 'ssl_verify_peer' => 'true',
133
- 'lists' => array()
134
- );
135
- $ov = get_option(YKSEME_OPTION, $defaultVals);
136
- $this->optionVal = $ov;
137
- return $ov;
138
- }
139
-
140
- // run our update check to make sure the user is up to date
141
- private function runUpdateCheck() {
142
- if( ! isset( $this->optionVal['version'] ) || $this->optionVal['version'] < YKSEME_VERSION_CURRENT ) {
143
- $this->runUpdateTasks();
144
- }
145
- }
146
-
147
-
148
- /***** FUNCTIONS
149
- ****************************************************************************************************/
150
- // check if were on the login page
151
- function is_login_page() {
152
- return in_array( $GLOBALS['pagenow'] , array( 'wp-login.php', 'wp-register.php' ) );
153
- }
154
-
155
- // create a slug like string, given some text (ie: this-is-the-name)
156
- public function slugify( $text ) {
157
- // replace non letter or digits by -
158
- $text = preg_replace( '~[^\\pL\d]+~u', '-', $text );
159
- // trim
160
- $text = trim( $text, '-' );
161
- // transliterate
162
- $text = iconv( 'utf-8' , 'us-ascii//TRANSLIT' , $text );
163
- // lowercase
164
- $text = strtolower( $text);
165
- // remove unwanted characters
166
- $text = preg_replace( '~[^-\w]+~' , '' , $text );
167
- if(empty($text))
168
- {
169
- return 'n-a';
170
- }
171
- return $text;
172
- }
173
-
174
- // create an array for any fields left blank
175
- // not sure if still needed (CHECK)
176
- public function getBlankFieldsArray( $lid='' ) {
177
- $fields = array();
178
- // Add Field
179
- $name = $this->slugify('Email Address'.'-'.'EMAIL');
180
- $addField = array(
181
- 'id' => $lid.'-'.$name,
182
- 'name' => $lid.'-'.$name,
183
- 'merge' => 'EMAIL',
184
- 'label' => 'Email Address',
185
- 'require' => '1',
186
- 'active' => '1',
187
- 'locked' => '1',
188
- 'sort' => '1',
189
- 'type' => 'email',
190
- 'help' => '',
191
- 'defalt' => '',
192
- 'choices' => ''
193
- );
194
- $fields[$addField['id']] = $addField;
195
- // return our fields
196
- return $fields;
197
- }
198
-
199
- // Create an array of data for imported fields based on the Merge Varaibles passed back from MailChimp
200
- public function getImportedFieldsArray( $lid, $mv ) {
201
- if( empty( $mv ) ) {
202
- return false;
203
- } else {
204
- $fields = array();
205
- $num = 1;
206
- foreach($mv['data'][0]['merge_vars'] as $field) {
207
- // Add Field
208
- $name = $this->slugify(isset($field['label']).'-'.$field['tag']);
209
- $addField = array(
210
- 'id' => $lid.'-'.$name,
211
- 'name' => $lid.$field['tag'],
212
- 'merge' => $field['tag'],
213
- 'label' => $field['name'],
214
- 'require' => $field['req'],
215
- 'active' => '1',
216
- 'locked' => '1',
217
- 'sort' => $field['order'],
218
- 'type' => $field['field_type'],
219
- 'help' => $field['helptext'],
220
- 'default' => $field['default'],
221
- 'choices' => (isset($field['choices']) ? $field['choices'] : '')
222
- );
223
- $fields[$addField['id']] = $addField;
224
- $num++;
225
- }
226
- return $fields;
227
- }
228
- }
229
-
230
- // Get the current users browser information
231
- // Used specifically on the lists page
232
- public function getBrowser() {
233
- $u_agent = $_SERVER['HTTP_USER_AGENT'];
234
- $bname = 'Unknown';
235
- $platform = 'Unknown';
236
- $version = "";
237
- //First get the platform?
238
- if( preg_match( '/linux/i', $u_agent ) ) {
239
- $platform = 'Linux';
240
- } elseif( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
241
- $platform = 'Mac';
242
- } elseif( preg_match( '/windows|win32/i' , $u_agent ) ) {
243
- $platform = 'Windows';
244
- }
245
-
246
- // Next get the name of the useragent yes seperately and for good reason
247
- if( preg_match( '/MSIE/i' , $u_agent ) && ! preg_match( '/Opera/i' , $u_agent ) ) {
248
- $bname = 'Internet Explorer';
249
- $ub = "MSIE";
250
- } elseif( preg_match( '/Firefox/i' , $u_agent ) ) {
251
- $bname = 'Mozilla Firefox';
252
- $ub = "Firefox";
253
- } elseif( preg_match( '/Chrome/i' , $u_agent ) ) {
254
- $bname = 'Google Chrome';
255
- $ub = "Chrome";
256
- } elseif( preg_match( '/Safari/i' , $u_agent ) ) {
257
- $bname = 'Apple Safari';
258
- $ub = "Safari";
259
- } elseif( preg_match( '/Opera/i' , $u_agent ) ) {
260
- $bname = 'Opera';
261
- $ub = "Opera";
262
- } elseif( preg_match( '/Netscape/i' , $u_agent ) ) {
263
- $bname = 'Netscape';
264
- $ub = "Netscape";
265
- }
266
-
267
- // finally get the correct version number
268
- $known = array('Version', $ub, 'other');
269
- $pattern = '#(?<browser>' . join( '|' , $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
270
- if( ! preg_match_all( $pattern, $u_agent, $matches) ) {
271
- // we have no matching number just continue
272
- }
273
-
274
- // see how many we have
275
- $i = count($matches['browser']);
276
- if( $i != 1 ) {
277
- //we will have two since we are not using 'other' argument yet
278
- //see if version is before or after the name
279
- if( strripos( $u_agent ,"Version" ) < strripos( $u_agent , $ub ) ) {
280
- $version= $matches['version'][0];
281
- } else {
282
- $version= $matches['version'][1];
283
- }
284
- } else {
285
- $version= $matches['version'][0];
286
- }
287
-
288
- // check if we have a number
289
- if( $version==null || $version=="" ) { $version="?"; }
290
-
291
- return array(
292
- 'userAgent' => $u_agent,
293
- 'name' => $bname,
294
- 'version' => $version,
295
- 'platform' => $platform,
296
- 'pattern' => $pattern
297
- );
298
- }
299
-
300
- /***** Encryption/Decryption
301
- ****** API Keys (MailChimp and reCaptcha)
302
- *****************************************************************************************************/
303
- function yikes_mc_encryptIt( $q ) {
304
- $cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
305
- $qEncoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
306
- return( $qEncoded );
307
- }
308
-
309
- function yikes_mc_decryptIt( $q ) {
310
- $cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
311
- $qDecoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
312
- return( $qDecoded );
313
- }
314
-
315
-
316
- /***** CONFIGURATION
317
- ****************************************************************************************************/
318
- // Update our plug in options
319
- // Runs when the user updates the settings page with new values
320
- public function updateOptions( $p ) {
321
- if( ! empty( $p['form_data'] ) ) {
322
- parse_str( $p['form_data'] , $fd );
323
- // checking if the entered API key has copied out of the value field?
324
- if ( strlen( $fd['yks-mailchimp-api-key'] ) > 45 ) {
325
- $apiKey = $this->yikes_mc_decryptIt($fd['yks-mailchimp-api-key']);
326
- } else {
327
- $apiKey = $fd['yks-mailchimp-api-key'];
328
- }
329
- // check if the newly input API key differs from the previously stored one
330
- if ( $apiKey == $this->optionVal['api-key'] ) {
331
- $this->optionVal['api-key'] = $apiKey;
332
- $this->optionVal['flavor'] = $fd['yks-mailchimp-flavor'];
333
- $this->optionVal['optin'] = $fd['yks-mailchimp-optin'];
334
- $this->optionVal['single-optin-message'] = stripslashes($fd['single-optin-message']);
335
- $this->optionVal['double-optin-message'] = stripslashes($fd['double-optin-message']);
336
- $this->optionVal['optIn-checkbox'] = $fd['yks-mailchimp-optIn-checkbox'];
337
- $this->optionVal['yks-mailchimp-optIn-default-list'] = isset($fd['yks-mailchimp-optIn-default-list']) ? $fd['yks-mailchimp-optIn-default-list'] : null; // if its set, else set to null <- fixes save form settings bug
338
- $this->optionVal['yks-mailchimp-optin-checkbox-text'] = stripslashes($fd['yks-mailchimp-optin-checkbox-text']);
339
- $this->optionVal['yks-mailchimp-jquery-datepicker'] = isset( $fd['yks-mailchimp-jquery-datepicker'] ) ? '1' : '';
340
- $this->optionVal['yks-mailchimp-required-text'] = $fd['yks-mailchimp-required-text'];
341
- update_option('api_validation', 'valid_api_key');
342
- return update_option( YKSEME_OPTION , $this->optionVal );
343
- } else {
344
- $this->optionVal['api-key'] = $apiKey;
345
- $this->optionVal['flavor'] = $fd['yks-mailchimp-flavor'];
346
- $this->optionVal['optin'] = $fd['yks-mailchimp-optin'];
347
- $this->optionVal['single-optin-message'] = stripslashes($fd['single-optin-message']);
348
- $this->optionVal['double-optin-message'] = stripslashes($fd['double-optin-message']);
349
- $this->optionVal['optIn-checkbox'] = $fd['yks-mailchimp-optIn-checkbox'];
350
- $this->optionVal['yks-mailchimp-optIn-default-list'] = isset($fd['yks-mailchimp-optIn-default-list']) ? $fd['yks-mailchimp-optIn-default-list'] : null; // if its set, else set to null <- fixes save form settings bug
351
- $this->optionVal['yks-mailchimp-optin-checkbox-text'] = stripslashes($fd['yks-mailchimp-optin-checkbox-text']);
352
- $this->optionVal['yks-mailchimp-jquery-datepicker'] = isset( $fd['yks-mailchimp-jquery-datepicker'] ) ? '1' : '';
353
- $this->optionVal['yks-mailchimp-required-text'] = $fd['yks-mailchimp-required-text'];
354
- update_option('api_validation', 'valid_api_key');
355
- // if the new API key differs from the old one
356
- // we need to unset the previously set up widgets
357
- // 1 - empty the lists array of imported lists
358
- $this->optionVal['lists'] = array();
359
- // 2 - unset our previously set up widgets
360
- update_option( 'widget_yikes_mc_widget' , '' );
361
- return update_option( YKSEME_OPTION , $this->optionVal );
362
- }
363
- }
364
- return false;
365
- }
366
-
367
- // Update our recaptcha options
368
- // Runs when the user updates the recaptcha settings page with new values
369
- public function updateRecaptchaOptions( $p ) {
370
- if( !empty( $p['form_data'] ) ) {
371
- parse_str($p['form_data'], $fd);
372
- $this->optionVal['recaptcha-setting'] = isset($fd['yks-mailchimp-recaptcha-setting']) ? $fd['yks-mailchimp-recaptcha-setting'] : '0';
373
- $this->optionVal['recaptcha-api-key'] = isset($fd['yks-mailchimp-recaptcha-api-key']) ? $fd['yks-mailchimp-recaptcha-api-key'] : '';
374
- $this->optionVal['recaptcha-private-api-key'] = isset($fd['yks-mailchimp-recaptcha-private-api-key']) ? $fd['yks-mailchimp-recaptcha-private-api-key'] : '';
375
- return update_option( YKSEME_OPTION , $this->optionVal );
376
- }
377
- return false;
378
- }
379
-
380
- // Update our debug plugin options
381
- // Runs when the user updates the debug settings page with new values
382
- public function updateDebugOptions( $p ) {
383
- if( !empty( $p['form_data'] ) ) {
384
- parse_str($p['form_data'], $fd);
385
- $this->optionVal['debug'] = $fd['yks-mailchimp-debug'];
386
- $this->optionVal['ssl_verify_peer'] = $fd['yks-mailchimp-ssl-verify-peer'];
387
- return update_option(YKSEME_OPTION, $this->optionVal);
388
- }
389
- return false;
390
- }
391
-
392
- // Update the API Key
393
- public function updateApiKey( $k ) {
394
- $this->optionVal['api-key'] = $k;
395
- return update_option( YKSEME_OPTION , $this->optionVal );
396
- }
397
-
398
- // Update the version number
399
- public function updateVersion( $k ) {
400
- $this->optionVal['version'] = $k;
401
- return update_option( YKSEME_OPTION , $this->optionVal );
402
- }
403
-
404
- /***** LIST ACTIONS
405
- ****************************************************************************************************/
406
- // Import a list from MailChimp and add it to the lists page
407
- // Runs when user adds a list from the drop down on the list page
408
- // Sends a call to MailChimp api to retrieve list data
409
- public function addList( $lid='' , $name='' ) {
410
-
411
- if( $lid == '' || isset( $this->optionVal['lists'][$lid] ) ) return false;
412
-
413
- $api = new Mailchimp($this->optionVal['api-key']);
414
-
415
- $mv = $api->call('lists/merge-vars', array(
416
- 'id' => array($lid)
417
- )
418
- );
419
-
420
- // if merge variables are found
421
- if( $mv) {
422
- $list = array(
423
- 'id' => $lid,
424
- 'list-id' => $lid,
425
- 'name' => $name,
426
- 'fields' => $this->getImportedFieldsArray( $lid , $mv )
427
- );
428
-
429
- $this->optionVal['lists'][$list['id']] = $list;
430
-
431
- // store newly retreived list array in imported_list global option
432
- update_option( 'imported_lists' , $this->optionVal['lists'] );
433
-
434
- if( update_option( YKSEME_OPTION, $this->optionVal ) ) {
435
- return $this->generateListContainers( array( $list ) );
436
- }
437
- }
438
-
439
- return false;
440
- }
441
-
442
-
443
- /* Get Interest Groups */
444
- // Send request to MailChimp API to retreive interest groups associated to a specific list
445
- public function getInterestGroups( $list_id ) {
446
- // store our API key
447
- $api = new Mailchimp($this->optionVal['api-key']);
448
-
449
- // setup switch for div/table
450
- $yikes_mc_flavor = $this->optionVal['flavor'];
451
-
452
- // try the request, and catch any errors
453
- try {
454
-
455
- $interest_groups = $api->call('lists/interest-groupings', array( 'id' => $list_id ));
456
-
457
- // if the list has an interest group
458
- if ($interest_groups) {
459
- // json_encode the data, and store it in optionVal['interest-groups']
460
- $this->optionVal['interest-groups'] = json_encode($interest_groups);
461
-
462
- $num = 0;
463
-
464
- switch( $yikes_mc_flavor ) {
465
-
466
- // table flavor
467
- case '0':
468
-
469
- // loop over each interest group returned
470
- foreach($interest_groups as $interest_group) {
471
-
472
- ?> <!-- pass interest group data in a hidden form field , required to pass the data back to the correct interest-group -->
473
- <input type='hidden' name='interest-group-data' value='<?php echo $this->optionVal["interest-groups"]; ?>' /> <?php
474
-
475
- // get form type
476
- $list_form_type = $interest_group['form_field'];
477
- $interestGroupID = $interest_group['id'];
478
-
479
- switch( $list_form_type ) {
480
-
481
- // checkbox interest groups
482
- case 'checkboxes':
483
- echo '<tr class="yks_mc_table_interest_group_holder yks_mc_table_checkbox_holder">';
484
- echo '<td class="yks_mc_table_td">';
485
- // display the label
486
- echo '<label class="prompt yks_table_label yks-mailchimpFormTableRowLabel yks-mailchimpFormTableRowLabel-required font-secondary label-text">'.stripslashes( $interest_group['name'] ).'</label>'; // display the interest group name from MailChimp
487
- foreach ($interest_group['groups'] as $singleGrouping) {
488
- $checkboxValue = $interest_group['name'];
489
- echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="checkbox" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_checkbox" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'[]" value="'.$singleGrouping['name'].'"><span>'.$singleGrouping['name'].'</span></label>';
490
- }
491
- echo '</td>';
492
- echo '</tr>';
493
- break;
494
-
495
- // radiobuttons interest groups
496
- case 'radio':
497
- echo '<tr class="yks_mc_table_interest_group_holder yks_mc_table_radio_holder">';
498
- echo '<td class="yks_mc_interest_radio_button_holder yks_mc_table_td">';
499
- // display the label
500
- echo stripslashes($user_set_interest_group_label);
501
- foreach ($interest_group['groups'] as $singleGrouping) {
502
- $radioValue = $interest_group['name'];
503
- echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="radio" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_radio" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" value="'.$singleGrouping['name'].'"><span>'.stripslashes($singleGrouping['name']).'</span></label>';
504
- }
505
- echo '</td>';
506
- echo '</tr>';
507
- break;
508
-
509
- // drop down interest groups
510
- case 'dropdown':
511
- echo '<tr class="yks_mc_table_interest_group_holder yks_mc_table_dropdown_holder">';
512
- echo '<td class="yks_mc_table_dropdown_interest_group_holder yks_mc_table_td">';
513
- // display the label
514
- echo stripslashes($user_set_interest_group_label);
515
- echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
516
- foreach ($interest_group['groups'] as $singleGrouping) {
517
- $dropDownValue = $interest_group['name'];
518
- echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
519
- }
520
- echo '</select>';
521
- echo '</td>';
522
- echo '</tr>';
523
- break;
524
-
525
- // hidden dropdown interest groups
526
- case 'hidden':
527
- echo '<div class="yks_mc_interest_group_holder" style="display:none;">';
528
- echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
529
- foreach ($interest_group['groups'] as $singleGrouping) {
530
- $dropDownValue = $interest_group['name'];
531
- echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
532
- }
533
- echo '</select>';
534
- echo '</div>';
535
- break; //break dropdown interest group type
536
-
537
- }
538
-
539
- $num++;
540
- }
541
-
542
- break; // break case: 0;
543
-
544
- // div flavor
545
- case '1':
546
- // loop over each interest group returned
547
- foreach($interest_groups as $interest_group) {
548
-
549
- // get form type
550
- $list_form_type = $interest_group['form_field'];
551
- $interestGroupID = $interest_group['id'];
552
- if ( $list_form_type == 'hidden' ) { $hidden = 'style="display:none;"'; } else { $hidden = ''; }
553
-
554
- echo '<b class="yks_mc_interest_group_text" ' . $hidden . '>'.$interest_group['name'].'</b>';
555
- ?>
556
-
557
- <input type='hidden' name='interest-group-data' value='<?php echo $this->optionVal["interest-groups"]; ?>' />
558
-
559
- <?php
560
-
561
- switch($list_form_type) {
562
-
563
- // checkbox interest groups
564
- case 'checkboxes':
565
- echo '<div class="yks_mc_interest_group_holder">';
566
- foreach ($interest_group['groups'] as $singleGrouping) {
567
- $checkboxValue = $interest_group['name'];
568
- echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="checkbox" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_checkbox" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'[]" value="'.$singleGrouping['name'].'"><span></span>'.stripslashes($singleGrouping['name']).'</label>';
569
- }
570
- echo '</div>';
571
- break; // break checkbox interest group type
572
-
573
- // radiobuttons interest groups
574
- case 'radio':
575
- echo '<div class="yks_mc_interest_group_holder">';
576
- echo '<div class="yks_mc_interest_radio_button_holder">';
577
- echo stripslashes($user_set_interest_group_label);
578
- foreach ($interest_group['groups'] as $singleGrouping) {
579
- $radioValue = $interest_group['name'];
580
- echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="radio" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_radio" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" value="'.$singleGrouping['name'].'"><span></span>'.stripslashes($singleGrouping['name']).'</label>';
581
- }
582
- echo '</div>';
583
- echo '</div>';
584
- break; //break radio buttons interest group type
585
-
586
- // drop down interest groups
587
- case 'dropdown':
588
- echo '<div class="yks_mc_interest_group_holder">';
589
- echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
590
- foreach ($interest_group['groups'] as $singleGrouping) {
591
- $dropDownValue = $interest_group['name'];
592
- echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
593
- }
594
- echo '</select>';
595
- echo '</div>';
596
- break; //break dropdown interest group type
597
-
598
- // hidden dropdown interest groups
599
- case 'hidden':
600
- echo '<div class="yks_mc_interest_group_holder" style="display:none;">';
601
- // display the label
602
- echo stripslashes($user_set_interest_group_label);
603
- echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
604
- foreach ($interest_group['groups'] as $singleGrouping) {
605
- $dropDownValue = $interest_group['name'];
606
- echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
607
- }
608
- echo '</select>';
609
- echo '</div>';
610
- break; //break dropdown interest group type
611
-
612
- }
613
- $num++;
614
- }
615
- break; //break case: 1;
616
-
617
- }
618
- }
619
- // catch any errors if thrown
620
- } catch( Exception $e ) {
621
- if ( $this->optionVal['debug'] == 1 ) {
622
- $this->writeErrorToErrorLog( $e );
623
- }
624
- return;
625
- }
626
- return false;
627
- } // end getInterestGroups();
628
-
629
- // Send a call to the MailChimp API to retreive all lists on the account
630
- public function getLists() {
631
- $api = new Mailchimp($this->optionVal['api-key']);
632
- $lists = $this->getListsData();
633
- $listArr = (!isset($listArr) ? $this->optionVal['lists'] : $listArr);
634
- $theusedlist = array();
635
- if( count( $listArr ) > 0 ) {
636
- foreach( $listArr as $list ) {
637
- $theusedlist[] = $list['id'];
638
- }
639
- }
640
- if( $lists ) { // if list data is returned
641
- echo "<select id='yks-list-select' name='yks-list-select'>";
642
- echo "<option value=''> Select List</option>";
643
-
644
- foreach ( $lists as $lkey => $lvalue ) {
645
- if ( !in_array( $lkey , $theusedlist ) ) {
646
- echo "<option value='".$lkey."'>".$lvalue."</option>";
647
- }
648
- }
649
-
650
- echo "</select>";
651
- echo '<input type="submit" name="submit" class="button-primary" id="yks-submit-list-add" value="' .__ ("Create a Form For This List" , "yikes-inc-easy-mailchimp-extender" ) .'" >';
652
-
653
- // not currently possible to create new lists via API
654
- // echo '&nbsp;<a href="#" onclick="return false;" class="button-secondary"><span class="dashicons dashicons-plus" style="line-height:1.3"></span> Create New List</a>';
655
-
656
- } else {
657
- echo '<strong>' . __('Error - No Lists Found On Your Account. Please create at least one list on your MailChimp account.' , 'yikes-inc-easy-mailchimp-extender' ) . '</strong>';
658
- }
659
- return false;
660
- } // end getLists();
661
-
662
- // Get lists for the settings page
663
- // Used for default subscription list
664
- public function getOptionsLists() {
665
- $api = new Mailchimp($this->optionVal['api-key']);
666
- $lists = $this->getListsData();
667
- $listArr = (!isset($listArr) ? $this->optionVal['lists'] : $listArr);
668
- if( $lists ) {
669
- echo "<select id='yks-mailchimp-optIn-default-list' name='yks-mailchimp-optIn-default-list'>";
670
- echo "<option value='select_list'> Select List</option>";
671
- foreach ( $lists as $lkey => $list_name) {
672
- echo "<option ".selected( isset($this->optionVal['yks-mailchimp-optIn-default-list']) ? $this->optionVal['yks-mailchimp-optIn-default-list'] : "select_list", $lkey )." value='".$lkey."'>".$list_name."</option>";
673
- }
674
- echo "</select>";
675
- }
676
- return false;
677
- } // end getOptionsLists()
678
-
679
- // Send a call to MailChimp API to get the data associated with a specific list (in this instance: the fields, and the subscriber count)
680
- public function getListsData() {
681
- $api = new Mailchimp($this->optionVal['api-key']);
682
- $lists = $api->call('lists/list', array( 'limit' => 100 ));
683
- if( $lists ) {
684
- foreach ( $lists['data'] as $list ) {
685
- $theListItems[$list['id']] = $list['name'];
686
- $theListItems['subscriber-count']['subscriber-count-'.$list['id']] = $list['stats']['member_count'];
687
- }
688
- }
689
-
690
- if ( isset ( $theListItems ) ) {
691
- return $theListItems;
692
- }
693
- } // end getListsData();
694
-
695
- /*
696
- Send a call to MailChimp API to get the data associated with a specific list (in this instance: the fields, and the subscriber count)
697
- @since v5.2
698
- */
699
- public function getInterstGroupInfo( $list_id ) {
700
- $api = new Mailchimp($this->optionVal['api-key']);
701
- try {
702
- $interest_groups = $api->call('lists/interest-groupings', array( 'id' => $list_id ));
703
- return $interest_groups;
704
- } catch( Exception $e ) { // catch any errors returned from MailChimp
705
- return $e->getMessage();
706
- // write our error to the error log, when advanced debug is enabled
707
- if ( $this->optionVal['debug'] == 1 ) {
708
- $this->writeErrorToErrorLog( $e );
709
- }
710
- die();
711
- }
712
- }
713
-
714
- /*
715
- Get Interest Group Response
716
- @sinve v5.2
717
- */
718
- public function getListInterestGroups( $list_id ) {
719
- $interest_groups = $this->getInterstGroupInfo( $list_id );
720
- if ( is_array( $interest_groups ) ) {
721
- foreach ( $interest_groups as $interest_group ) {
722
- $interest_group_id = $interest_group['id'];
723
- $interest_group_type = $interest_group['form_field'];
724
- $interest_group_name = $interest_group['name'];
725
- echo '<div class="yks-mailchimp-fields-list-row" alt="' . $interest_group_id . '">
726
-
727
- <span class="yks-mc-interest-group-delete" title="Delete ' . $interest_group_name . '">
728
- <span class="dashicons dashicons-no-alt"></span>
729
- </span>
730
-
731
- <span class="yks-mc-interest-group-edit" title="Edit ' . $interest_group_name . '">
732
- <span class="dashicons dashicons-edit"></span>
733
- </span>
734
-
735
- <span class="yks-mc-interest-group-name">' . $interest_group_name . '</span>
736
-
737
- <span class="yks-mc-interest-group-type">' . $interest_group_type . '</span>
738
-
739
- </div>';
740
- }
741
- } else {
742
- ?>
743
- <style>
744
- #yks-mailchimp-interest-groups-container_<?php echo $list_id; ?> {
745
- background-color: transparent !important;
746
- border: none !important;
747
- }
748
- </style>
749
- <span class="no-interest-groups-found"><em><?php echo __( 'No interest groups have been setup for this form yet' , 'yikes-inc-easy-mailchimp-extender' ); ?></em></span>
750
- <?php
751
- }
752
- } // end getListInterestGroups();
753
-
754
- /*
755
- Get Specific Interest Group Response
756
- @since v5.2
757
- */
758
- public function getSpecificInterestGroupData( $list_id , $mc_interest_group_id ) {
759
- // get interest group info,
760
- $interest_groups = $this->getInterstGroupInfo( $list_id );
761
- if ( $interest_groups ) {
762
- foreach ( $interest_groups as $key ) {
763
- if ( $key['id'] == $mc_interest_group_id ) {
764
- echo json_encode( $key );
765
- }
766
- }
767
- } else {
768
- echo 'error retreiving group information...please try again';
769
- }
770
- }
771
-
772
- // Send a call to MailChimp API to get the data associated with a specific list (in this instance: the fields, and the subscriber count)
773
- public function getListsForStats() {
774
- $api = new Mailchimp($this->optionVal['api-key']);
775
- $lists = $this->getListsData();
776
- $listArr = (!isset($listArr) ? $this->optionVal['lists'] : $listArr);
777
- $theusedlist = array();
778
- if( count( $listArr ) > 0 ) {
779
- foreach( $listArr as $list ) {
780
- $theusedlist[] = $list['id'];
781
- }
782
- }
783
- if( $lists ) {
784
- // Drop Down to switch form stats
785
- echo '<h3>Select list to view stats</h3>';
786
- echo '<div class="list_container_for_stats">';
787
- echo "<a alt='' href='#' class='stats_list_name' onclick='return false;'><input type='button' class='asbestos-flat-button active_button' value='".__( 'All Lists' , 'yikes-inc-easy-mailchimp-extender')."'></a>";
788
- foreach ($lists as $lkey => $lvalue) {
789
- if ( is_array($lvalue) ) {
790
- continue;
791
- } else {
792
- // if ( is_array( $lvalue ) ) { $lvalue = '<em style="color:rgba(245, 79, 79, 0.74);">Error</em>'; } else { $lvalue = $lvalue; }
793
- echo "<a alt='".$lkey."' href='#' class='stats_list_name' onclick='return false;'><input type='button' class='asbestos-flat-button' value='".$lvalue."'></a>";
794
- }
795
- }
796
- echo '</div>';
797
- }
798
- return false;
799
- } // end getListsForStats()
800
-
801
- // Sort through the returned data
802
- public function sortList( $p ) {
803
- if( empty( $p['update_string'] ) || empty( $p['list_id'] ) ) {
804
- return false;
805
- } else {
806
- // Setup fields
807
- $a = explode( ';' , $p['update_string'] );
808
- if( $a !== false ) {
809
- foreach( $a as $f ) {
810
- $d = explode( ':' , $f );
811
- $this->optionVal['lists'][$p['list_id']]['fields'][$d[0]]['sort'] = $d[1];
812
- }
813
- }
814
- uasort($this->optionVal['lists'][$p['list_id']]['fields'], array(&$this, 'sortListFields'));
815
- return update_option(YKSEME_OPTION, $this->optionVal);
816
- }
817
- return false;
818
- } // end sortList();
819
-
820
- private function sortListfields( $a , $b ) {
821
- $a = $a['sort'];
822
- $b = $b['sort'];
823
- if( $a == $b ) {
824
- return 0;
825
- }
826
- return ( $a < $b ) ? -1 : 1;
827
- } // end sortListfields();
828
-
829
- // Update a single list on the lists page
830
- // This function fires when the user clicks 'save settings' for a specific form on the lists page
831
- public function updateList( $p ) {
832
- if( !empty( $p['form_data'] ) ) {
833
- parse_str($p['form_data'], $fd);
834
- if( !empty( $fd['yks-mailchimp-unique-id'] ) ) {
835
- $num = 1;
836
- foreach( $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'] as $k => $v ) {
837
- // Only proceed if the field is not locked
838
- if( $v['require'] == 0 ) {
839
- // Make sure this field was included in the update
840
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['active'] = (isset($fd[$v['name']]) ? '1' : '0');
841
- }
842
-
843
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['placeholder-'.$fd['yks-mailchimp-unique-id'].'-'.$num] = $fd['placeholder-'.$fd['yks-mailchimp-unique-id'].'-'.$num];
844
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['custom-field-class-'.$fd['yks-mailchimp-unique-id'].'-'.$num] = $fd['custom-field-class-'.$fd['yks-mailchimp-unique-id'].'-'.$num];
845
- $num++;
846
-
847
- // redirect checkbox
848
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['yks_mailchimp_redirect_'.$fd['yks-mailchimp-unique-id']] = (isset($fd['yks_mailchimp_redirect_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '');
849
-
850
- // send welcome checkbox
851
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['yks_mailchimp_send_welcome_'.$fd['yks-mailchimp-unique-id']] = (isset($fd['yks_mailchimp_send_welcome_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '');
852
-
853
- if(isset($fd['yks_mailchimp_redirect_'.$fd['yks-mailchimp-unique-id']])) {
854
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['page_id_'.$fd['yks-mailchimp-unique-id']] = $fd['page_id_'.$fd['yks-mailchimp-unique-id']];
855
- }
856
-
857
- // custom style setting
858
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['active'] = (isset($fd['yks_mailchimp_custom_styles_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '0');
859
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_template']['active'] = (isset($fd['yks_mailchimp_custom_template_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '0');
860
- }
861
-
862
- // save the selected form template, if custom template was set
863
- if ( $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_template']['active'] == 1 ) {
864
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_template']['template_file'] = $fd['yks-mc-template-file-selection'];
865
- }
866
-
867
- // save the color styles
868
- if ( $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['active'] == 1 ) {
869
-
870
- // save the custom styles colors here!
871
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_submit_button_color'] = $fd['yks-mc-submit-button-color'];
872
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_submit_button_text_color'] = $fd['yks-mc-submit-button-text-color'];
873
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_background_color'] = $fd['yks-mc-background-color'];
874
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_text_color'] = $fd['yks-mc-text-color'];
875
-
876
- // if the form width is left blank,
877
- // we'll just set it to 100%
878
- if ( $fd['yks-mc-form-width'] != '' ) {
879
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_width'] = $fd['yks-mc-form-width'];
880
- } else {
881
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_width'] = '100%';
882
- }
883
-
884
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_alignment'] = $fd['yks-mc-form-alignment'];
885
-
886
- $padding_matches = array();
887
- $matching_array = array( 'px' , 'em' , 'rem' , '%' );
888
-
889
- if ( preg_match( '/([0-9.]+)([^0-9]+)/', $fd['yks-mc-form-padding'], $padding_matches ) ) {
890
- // $padding_explosion = preg_split( '/[a-zA-Z]/' , $fd['yks-mc-form-padding'] );
891
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding'] = $padding_matches[1];
892
- if ( in_array( $padding_matches[2] , $matching_array ) ) {
893
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding_measurement'] = $padding_matches[2];
894
- } else {
895
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding_measurement'] = 'px';
896
- }
897
- } else {
898
- if ( trim( $fd['yks-mc-form-padding'] ) != '' ) {
899
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding'] = $fd['yks-mc-form-padding'];
900
- } else {
901
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding'] = '0';
902
- }
903
- $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding_measurement'] = 'px';
904
- }
905
- }
906
-
907
- return update_option(YKSEME_OPTION, $this->optionVal);
908
- }
909
- }
910
- return false;
911
- } // end updateList();
912
-
913
- // Remove a list from the lists page
914
- // Runs when a user clicks 'delete list' on the lists page
915
- public function deleteList( $i=false ) {
916
- if( $i == false ) {
917
- return false;
918
- } else {
919
- unset( $this->optionVal['lists'][$i] );
920
- update_option( 'imported_lists' , $this->optionVal['lists'] );
921
- return update_option( YKSEME_OPTION , $this->optionVal );
922
- }
923
- } // end deleteList();
924
-
925
- // Import a list to the lists page
926
- // Runs when a user adds a list from the drop down on the lists page
927
- public function importList( $i = false ) {
928
- if( $i == false ) {
929
- return false;
930
- } else {
931
- // create our variables
932
- $lid = $this->optionVal['lists'][$i]['list-id'];
933
- $name = $this->optionVal['lists'][$i]['name'];
934
- $api = new Mailchimp($this->optionVal['api-key']);
935
- $mv = $api->call('lists/merge-vars', array(
936
- 'id' => array( $lid )
937
- )
938
- );
939
- // if merge variables are returned
940
- $mv = $this->getImportedFieldsArray($lid, $mv);
941
- if( $mv ) {
942
- // Save the new list
943
- $this->optionVal['lists'][$i]['fields'] = $mv;
944
- if( update_option( YKSEME_OPTION , $this->optionVal ) ) {
945
- return $this->generateListContainers(array($this->optionVal['lists'][$i]));
946
- }
947
- }
948
- }
949
- return false;
950
- } // end importList();
951
-
952
- // reImport a list to the lists page
953
- // Runs when a user adds a list from the drop down on the lists page
954
- public function reImportMergeVariables( $i = false ) {
955
- if( $i == false ) {
956
- return false;
957
- } else {
958
- // create our variables
959
- $lid = $this->optionVal['lists'][$i]['list-id'];
960
- $name = $this->optionVal['lists'][$i]['name'];
961
- $api = new Mailchimp($this->optionVal['api-key']);
962
- $mv = $api->call('lists/merge-vars', array(
963
- 'id' => array( $lid )
964
- )
965
- );
966
- // if merge variables are returned
967
- $mv = $this->getImportedFieldsArray($lid, $mv);
968
- if( $mv ) {
969
- // Save the new list
970
- $this->optionVal['lists'][$i]['fields'] = $mv;
971
- // update the list with the new fields
972
- if( update_option( YKSEME_OPTION , $this->optionVal ) ) {
973
- return $this->generateMergeVariableContainers(array($this->optionVal['lists'][$i]));
974
- }
975
- }
976
- }
977
- return false;
978
- } // end reImportMergeVariables();
979
-
980
- // Make a call to the MailChimp API to retrieve all subscribers to a given list
981
- // Runs when the user clicks 'view' next to the subscriber count on the list page
982
- public function listAllSubscribers( $lid, $list_name ) {
983
- $api = new Mailchimp($this->optionVal['api-key']);
984
- $subscribers_list = $api->call('lists/members',
985
- array(
986
- 'id' => $lid,
987
- 'opts' => array(
988
- 'limit' => '100',
989
- 'sort_field' => 'optin_time',
990
- 'sort_dir' => 'DESC'
991
- )
992
- )
993
- );
994
- // if the subscriber count is greater than 0
995
- // display all subscribers in a table
996
- if( $subscribers_list['total'] > 0 ) { ?>
997
- <h2><?php echo $list_name; echo ' <span class="subscriber-count" style="font-size:11px;">(<span class="number">'.$subscribers_list['total'].'</span> '.__(" subscribers" , "yikes-inc-easy-mailchimp-extender").')</span>'; ?></h2>
998
- <p><?php _e( 'Click on a subscriber to see further information' , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
999
-
1000
- <table id="yikes-mailchimp-subscribers-table" class="yks-mailchimp-fields-list" style="width:100%;">
1001
- <thead class="yikes-mailchimp-subscribers-table-head">
1002
- <tr>
1003
- <th width="50%"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1004
- <th width="50%"><?php _e( 'Date Subscribed' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1005
- </tr>
1006
- </thead>
1007
- <?php foreach ( $subscribers_list['data'] as $subscriber ) {
1008
- $timeStamp = explode(' ', $subscriber['timestamp_opt'] );
1009
- echo '<tr class="yks-mailchimp-subscribers-list-row" id="yks-mailchimp-subscribers-list-row">';
1010
- echo '<td><a class="subscriber-mail-link" rel="'.$subscriber["email"].'" class="subscriberEmailAddress">'.$subscriber['email'].'</a></td>';
1011
- // echo '<td>'.str_replace('-', ' ', date("M-jS-Y", strtotime($subscriber['timestamp_opt']))).'</td>';
1012
- echo '<td>'.str_replace('-', ' ', date("M-jS-Y", strtotime($timeStamp[0]))).'</td></tr>';
1013
- } ?>
1014
- </table>
1015
-
1016
- <!-- display a single user profile in this div -->
1017
- <div id="individual_subscriber_information" style="display:none;"></div>
1018
- <?php
1019
- } else { // else display an error of sorts
1020
- ?>
1021
- <h2><?php echo $list_name; echo ' <span class="subscriber-count" style="font-size:11px;">(<span class="number">0</span> '.__(" subscribers" , "yikes-inc-easy-mailchimp-extender").')</span>'; ?></h2>
1022
- <?php
1023
- _e( "Sorry You Don't Currently Have Any Subscribers In This List!" , "yikes-inc-easy-mailchimp-extender" );
1024
- }
1025
- wp_die();
1026
- } // end listAllSubscribers();
1027
-
1028
- // Make a call to the MailChimp API to retrieve information about a specific user
1029
- // Runs when the user clicks a subscribers email address
1030
- public function getSubscriberInfo($lid, $email) {
1031
- $api = new Mailchimp($this->optionVal['api-key']);
1032
- $subscriber_info = $api->call('lists/member-info',
1033
- array(
1034
- 'id' => $lid,
1035
- 'emails' => array(
1036
- 0 => array(
1037
- 'email' => $email,
1038
- ),
1039
- )
1040
- )
1041
- );
1042
- // if the subscriber count is greater than 0
1043
- // display all subscribers in a table
1044
- if($subscriber_info) {
1045
- // store user data into variables
1046
- $subscriber_data = $subscriber_info['data'][0];
1047
- $member_rating = $subscriber_data['member_rating'];
1048
- // firstname/lastname data inside of new array
1049
- $subscriber_data_merges = $subscriber_data['merges'];
1050
- // seperate date+time
1051
- $subscriber_data_info_changed = explode(' ' , $subscriber_data['info_changed']);
1052
- $subscriber_data_timestamp_opt = explode (' ', $subscriber_data['timestamp_opt']);
1053
- // store date+time in seperate variables
1054
- $subscriber_data_info_changed_date = $subscriber_data_info_changed[0];
1055
- $subscriber_data_info_changed_time = $subscriber_data_info_changed[1];
1056
- // store optin-time+date in seperate variables
1057
- $subscriber_data_info_optin_date = $subscriber_data_timestamp_opt[0];
1058
- $subscriber_data_info_optin_time = $subscriber_data_timestamp_opt[1];
1059
- // create our language variable dependent on what is set in MailChimp
1060
- include_once('set_language.php');
1061
-
1062
- // create star rating variable, based on returned member_rating value
1063
- if(isset($member_rating)) {
1064
- if ($member_rating == 1) {
1065
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1066
- } else if ($member_rating == 2) {
1067
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1068
- } else if ($member_rating == 3) {
1069
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1070
- } else if ($member_rating == 4) {
1071
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1072
- } else if ($member_rating == 5) {
1073
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
1074
- }
1075
- } ?>
1076
-
1077
- <div class="yks-mc-subscriber-top">
1078
- <span class="button-primary dashicons dashicons-arrow-left-alt2 yks-mc-subscriber-go-back"><?php _e( 'Back to Subscriber List' , 'yikes-inc-easy-mailchimp-extender' ); ?></span>
1079
- <h2 class="yks-mc-subscriber-header"><?php _e( 'Subscriber Details' , 'yikes-inc-easy-mailchimp-extender' ); ?> </h2>
1080
- <!-- display users email address -->
1081
- <h3 id="yks-subscriber-info-email-address"><?php echo $subscriber_data['email']; ?></h3>
1082
- <!-- display member star rating pulled from MailChimp -->
1083
- <?php echo $member_rating_stars; ?>
1084
- <!-- user optin time and date -->
1085
- <span class="yks-subscriber-info-optin-data">
1086
- <?php echo 'Subscribed on : '.date('m/d/Y',strtotime($subscriber_data_info_optin_date)); ?><?php echo ' at '.date('g:i A',strtotime($subscriber_data_info_optin_time)); ?>
1087
- </span>
1088
- </div>
1089
-
1090
- <h2 class="yks-mc-subscriber-header"><?php _e( 'Overview' , 'yikes-inc-easy-mailchimp-extender' ); ?></h2>
1091
- <div class="yks-mc-subscriber-overview">
1092
-
1093
- <div class="yks-mc-subscriber-left-container">
1094
-
1095
- <label class="yks-mc-overview-title"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1096
- <p class="yks-mc-overview-info-value yks-mc-subscriber-firstName"><?php if(!empty($subscriber_data_merges['FNAME'])) { echo $subscriber_data_merges['FNAME']; } else { echo 'not provided'; } ?></p>
1097
-
1098
- <label class="yks-mc-overview-title"><?php _e( 'Last Updated' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1099
- <p class="yks-mc-overview-info-value"><?php echo date('m/d/Y',strtotime($subscriber_data_info_changed_date)); ?><?php echo ' at '.date('g:i A',strtotime($subscriber_data_info_changed_time)); ?></p>
1100
-
1101
- <label class="yks-mc-overview-title"><?php _e( 'Preferred Email Type' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1102
- <p class="yks-mc-overview-info-value"><?php if(!empty($subscriber_data['email_type'])) { echo $subscriber_data['email_type']; } else { echo 'No Preference.'; } ?></p>
1103
-
1104
- </div>
1105
-
1106
- <div class="yks-mc-subscriber-right-container">
1107
-
1108
- <label class="yks-mc-overview-title"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1109
- <p class="yks-mc-overview-info-value yks-mc-subscriber-lastName"><?php if(!empty($subscriber_data_merges['LNAME'])) { echo $subscriber_data_merges['LNAME']; } else { echo 'not provided'; } ?></p>
1110
-
1111
- <label class="yks-mc-overview-title"><?php _e( 'Language' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1112
- <p class="yks-mc-overview-info-value"><?php echo $subscriber_data_language; ?></p>
1113
-
1114
- </div>
1115
-
1116
- </div>
1117
-
1118
- <?php
1119
- // build our segment array to determine if the user is subscribed to any segments
1120
- $segment_count = array();
1121
- // check if groupings data is set (for segment and interest groups)
1122
- // this avoids an error being thrown when no segment/interest groups have been selected
1123
- if ( isset( $subscriber_data_merges['GROUPINGS'] ) ) {
1124
- foreach ($subscriber_data_merges['GROUPINGS'] as $group1) {
1125
- foreach ($group1['groups'] as $group2) {
1126
- if ($group2['interested'] == 1) {
1127
- array_push($segment_count, $group2['name']);
1128
- }
1129
- }
1130
- }
1131
- }
1132
- ?>
1133
-
1134
- <h2 class="yks-mc-subscriber-header"><?php _e( 'Groups Subscribed To' , 'yikes-inc-easy-mailchimp-extender' ); ?></h2>
1135
- <!-- display what groups/segments the subscriber is subscribed too -->
1136
- <?php
1137
- // if the user is subscribed to some segment
1138
- if(!empty($segment_count)) {
1139
- $groups_array = array(
1140
- 'group_name' => '',
1141
- 'segments' => array()
1142
- );
1143
- $num = 0;
1144
- foreach ($subscriber_data_merges['GROUPINGS'] as $group_name) {
1145
- $groups_array[$num]['group_name'] = $group_name['name'];
1146
- foreach ($group_name['groups'] as $groupData ) {
1147
- if ($groupData['interested'] == 1) {
1148
- $groups_array[$num]['segments'] = $groupData['name'];
1149
- }
1150
- }
1151
- $num++;
1152
- }
1153
- // build up the segments array that the user is subscribed too
1154
- foreach ( $groups_array as $group_data ) {
1155
- if(!empty($group_data['segments'])) { ?>
1156
- <ul>
1157
- <?php
1158
- echo '<li style="font-size:16px; color:#333;">'.$group_data['group_name'].'</li>';
1159
- if(!empty($group_data['group_name']) && isset($group_data['segments'])) {
1160
- echo 'Segments : '; echo implode(' ,', array($group_data['segments']));
1161
- } elseif (count($group_data['segments']) == 0) {
1162
- echo 'n/a';
1163
- }
1164
- ?>
1165
- </ul>
1166
- <?php
1167
- }
1168
- }
1169
- } else {
1170
- // if there are no segments subscribed too
1171
- // just print a message none specified
1172
- echo 'none specified';
1173
- }
1174
-
1175
- // display the notes associated with a user if there are any returned
1176
- if(!empty($subscriber_data['notes'])) { ?>
1177
- <div class="yks-mc-subscriber-bottom">
1178
- <h2 class="yks-mc-subscriber-header"><?php _e( 'Subscriber Notes' , 'yikes-inc-easy-mailchimp-extender' ); ?></h2>
1179
- <?php
1180
- foreach ( $subscriber_data['notes'] as $note ) {
1181
- ?>
1182
- <textarea style="width:100%; height:100px; resize:none;" id="yks-mc-subscriber-notes" disabled><?php echo $note['note']; ?></textarea>
1183
- <span style="font-size:11px; opacity:.75;"><?php _e( 'Written by' , 'yikes-inc-easy-mailchimp-extender' ); ?>: <?php echo $note['created_by_name']; ?> // <?php _e( 'Created on' , 'yikes-inc-easy-mailchimp-extender' ); ?>: <?php echo date('m/d/Y',strtotime($note['created'])); ?></span>
1184
- <?php
1185
- }
1186
- ?>
1187
- </div>
1188
- <?php
1189
- }
1190
- }
1191
- wp_die();
1192
- } // end getSubscriberInfo();
1193
-
1194
- // Make a call to the MailChimp API to remove a specified user from a given list
1195
- // Runs when the user clicks the 'X' next to a subscriber when viewing all subscribers on the lists page
1196
- public function yks_removeSubscriber($lid, $user_email) {
1197
- $api = new Mailchimp($this->optionVal['api-key']);
1198
- $subscribers_list = $api->call('lists/unsubscribe', array(
1199
- 'id' => $lid,
1200
- 'email' => array(
1201
- 'email' => $user_email
1202
- )
1203
- ));
1204
- } // end yks_removeSubscriber();
1205
-
1206
- /***** SCRIPTS/STYLES
1207
- ****************************************************************************************************/
1208
-
1209
- // enqueue dashboard styles
1210
- public function addStyles() {
1211
- include YKSEME_PATH . 'lib/inc/yks-mc-dashboard-styles.php';
1212
- } // end addStyles();
1213
-
1214
- // enqueue dashboard scripts
1215
- public function addScripts() {
1216
- include YKSEME_PATH . 'lib/inc/yks-mc-dashboard-scripts.php';
1217
- } // end addScripts();
1218
-
1219
- // enqueue our styles on the front end
1220
- public function addStyles_frontend() {
1221
- include YKSEME_PATH . 'lib/inc/yks-mc-frontend-styles.php';
1222
- } // end addStyles_frontend();
1223
-
1224
- // enqueue front end scripts
1225
- public function addScripts_frontend() {
1226
- // enqueue jQuery datepicker only when the user has specified to do so
1227
- if( isset( $this->optionVal['yks-mailchimp-jquery-datepicker'] ) && $this->optionVal['yks-mailchimp-jquery-datepicker'] == '1' ) {
1228
- wp_enqueue_script('jquery-ui-datepicker');
1229
- }
1230
- } // addScripts_frontend();
1231
-
1232
- // redirect the user to the settings page on initial activation
1233
- function yks_easy_mc_plugin_activation_redirect() {
1234
- if (get_option('yks_easy_mc_plugin_do_activation_redirect', false)) {
1235
- delete_option('yks_easy_mc_plugin_do_activation_redirect');
1236
- // redirect to settings page
1237
- wp_redirect(admin_url('/admin.php?page=yks-mailchimp-welcome'));
1238
- }
1239
- } // end yks_easy_mc_plugin_activation_redirect();
1240
-
1241
-
1242
- /***** SHORTCODES
1243
- ****************************************************************************************************/
1244
- // Function to process the shortcode provided by the plugin
1245
- // $p is the data associated with the shortcode (ie: form id and submit button text)
1246
- public function processShortcode( $p ) {
1247
- ob_start();
1248
- // check if the list is set, to prevent errors from being thrown
1249
- if ( isset( $this->optionVal['lists'][$p['id']] ) ) {
1250
-
1251
- if( $this->optionVal['api-key'] != '' && ( is_array( $this->optionVal['lists'][$p['id']] ) && !empty( $this->optionVal['lists'][$p['id']] ) ) ) {
1252
- // Setup this list
1253
- $list = $this->optionVal['lists'][$p['id']];
1254
- $submit_text = $p['submit_text'];
1255
- // Which form are we on?
1256
- if( !isset( $this->currentLists[$p['id']] ) ) {
1257
- $this->currentLists[$p['id']] = 0;
1258
- } else {
1259
- $this->currentLists[$p['id']]++;
1260
- }
1261
- $listCt = $this->currentLists[$p['id']];
1262
- // Add the count to the list vars
1263
- $list['id'] = $listCt.'-'.$list['id'];
1264
- if( count( $list['fields'] ) ) {
1265
- foreach( $list['fields'] as $fieldId => $field ) {
1266
- $list['fields'][$fieldId]['id'] = $listCt.'-'.$field['id'];
1267
- }
1268
- }
1269
- // List form
1270
- include YKSEME_PATH.'templates/shortcode_form.php';
1271
- }
1272
-
1273
- // if there is no api key entered, or it's an invalid api key
1274
- } else if ( $this->optionVal['api-key'] == '' || get_option( 'api_validation' ) == 'invalid_api_key' ) {
1275
- include YKSEME_PATH.'templates/shortcode_error_no_API_key.php';
1276
- // else if the form was removed from the lists page
1277
- } else {
1278
- include YKSEME_PATH.'templates/shortcode_error_data.php';
1279
- }
1280
- $shortcode = ob_get_contents();
1281
- ob_end_clean();
1282
- return $shortcode;
1283
- } // end processShortcode();
1284
-
1285
- /* New Function to Display Subscriber Count for a given list */
1286
- public function displaySubscriberCount( $p ) {
1287
- ob_start();
1288
- if( $this->optionVal['api-key'] != '' && ( is_array( $this->optionVal['lists'][$p['id']] ) && !empty( $this->optionVal['lists'][$p['id']] ) ) ) {
1289
- // Setup this list
1290
- $list = $this->optionVal['lists'][$p['id']];
1291
- $mailChimp = new yksemeBase();
1292
- $list = $mailChimp->getListsData();
1293
- $list_id = key($list);
1294
- // return just the subscriber count so the user can easily customize it!
1295
- echo $list['subscriber-count']['subscriber-count-'.$list_id];
1296
- } else if ( $this->optionVal['api-key'] == '' || get_option( 'api_validation' ) == 'invalid_api_key' ) {
1297
- include YKSEME_PATH.'templates/shortcode_error_no_API_key.php';
1298
- // else if the form was removed from the lists page
1299
- } else {
1300
- include YKSEME_PATH.'templates/shortcode_error_data.php';
1301
- }
1302
- $shortcode = ob_get_contents();
1303
- ob_end_clean();
1304
- return $shortcode;
1305
- } // end displaySubscriberCount();
1306
-
1307
- // Function to process the PHP snippet provided by the plugin
1308
- // Again the data passed in, is the shortcode/php snippet paramaters (form id, submit button text)
1309
- public function processSnippet($list=false, $submit_text) {
1310
- $p = array(
1311
- 'id' => $list,
1312
- 'submit_text' => $submit_text
1313
- );
1314
- return $this->processShortcode($p);
1315
- } // end processSnippet();
1316
-
1317
-
1318
- /***** ADMINISTRATION MENUS => Continue Editing Downward!
1319
- ****************************************************************************************************/
1320
- public function addAdministrationMenu() {
1321
- // Top Level Menu
1322
- add_menu_page( __('MailChimp Forms','yikes-inc-easy-mailchimp-extender'), 'MailChimp Forms', apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-form', array(&$this, 'generatePageOptions'), 'dashicons-welcome-write-blog', 400);
1323
- // Sub Items
1324
- add_submenu_page('yks-mailchimp-form', __('MailChimp Forms','yikes-inc-easy-mailchimp-extender'), __('MailChimp Settings','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-form', array(&$this, 'generatePageOptions'));
1325
- // if the user has entered a VALID API key
1326
- if ( get_option('api_validation') == 'valid_api_key') {
1327
- add_submenu_page('yks-mailchimp-form', __('My MailChimp','yikes-inc-easy-mailchimp-extender'), __('My MailChimp','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-my-mailchimp', array(&$this, 'generateUserMailChimpPage'));
1328
- }
1329
- add_submenu_page('yks-mailchimp-form', __('Manage List Forms','yikes-inc-easy-mailchimp-extender'), __('Manage List Forms','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-form-lists', array(&$this, 'generatePageLists'));
1330
- add_submenu_page('yks-mailchimp-form', __('About YIKES, Inc.','yikes-inc-easy-mailchimp-extender'), __('About YIKES, Inc.','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-about-yikes', array(&$this, 'generatePageAboutYikes'));
1331
- add_submenu_page('options.php', __('Welcome','yikes-inc-easy-mailchimp-extender'), __('Welcome','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-welcome', array(&$this, 'generateWelcomePage'));
1332
- } // end addAdministrationMenu();
1333
-
1334
-
1335
- /***** ADMINISTRATION PAGES
1336
- ****************************************************************************************************/
1337
- public function generatePageOptions() {
1338
- require_once YKSEME_PATH.'pages/options.php'; // include our options page
1339
- } // end generatePageOptions();
1340
-
1341
- public function generatePageLists() {
1342
- require_once YKSEME_PATH.'pages/lists.php'; // include our lists page
1343
- } // end generatePageLists();
1344
-
1345
- public function generatePageAboutYikes() {
1346
- require_once YKSEME_PATH.'pages/about.php'; // include our about page
1347
- } // end generatePageAboutYikes();
1348
-
1349
- public function registerMailChimpWidget() {
1350
- require_once YKSEME_PATH.'templates/yikes-mailchimp-widget.php'; // include our widget
1351
- } // end registerMailChimpWidget();
1352
-
1353
- public function includeRECAPTCHAlib() {
1354
- require_once YKSEME_PATH.'lib/recaptchalib.php'; // include our widget
1355
- } // end includeRECAPTCHAlib();
1356
-
1357
- public function generateUserMailChimpPage() {
1358
- require_once YKSEME_PATH.'pages/myMailChimp.php'; // include our widget
1359
- } // end generateUserMailChimpPage();
1360
-
1361
- public function generateWelcomePage() {
1362
- require_once YKSEME_PATH.'pages/welcome.php'; // include our widget
1363
- } // end generateWelcomePage();
1364
-
1365
- /***** FORM DATA
1366
- ****************************************************************************************************/
1367
- public function yks_resetPluginSettings() {
1368
- $blog_title = get_bloginfo( 'name' );
1369
- // reset the plugin settings back to defaults
1370
- $this->optionVal['api-key'] = '';
1371
- $this->optionVal['flavor'] = '1';
1372
- $this->optionVal['debug'] = '0';
1373
- $this->optionVal['optin'] = 'true';
1374
- $this->optionVal['single-optin-message'] = __('Thank You for subscribing!', 'yikes-inc-easy-mailchimp-extender');
1375
- $this->optionVal['double-optin-message'] = __('Thank You for subscribing! Check your email for the confirmation message.', 'yikes-inc-easy-mailchimp-extender');
1376
- $this->optionVal['optIn-checkbox'] = 'hide';
1377
- $this->optionVal['yks-mailchimp-optIn-default-list'] = 'select_list';
1378
- $this->optionVal['yks-mailchimp-optin-checkbox-text'] = 'Add me to the ' . $blog_title . ' mailing list';
1379
- $this->optionVal['recaptcha-setting'] = '0';
1380
- $this->optionVal['recaptcha-api-key'] = '';
1381
- $this->optionVal['recaptcha-private-api-key'] = '';
1382
- $this->optionVal['yks-mailchimp-jquery-datepicker'] = '';
1383
- $this->optionVal['yks-mailchimp-required-text'] = '';
1384
- $this->optionVal['version'] = YKSEME_VERSION_CURRENT;
1385
- $this->optionVal['ssl_verify_peer'] = 'true';
1386
- update_option('api_validation' , 'invalid_api_key');
1387
- // we need to unset the previously set up widgets
1388
- // and set up new erros if the API key doesn't exist
1389
-
1390
- // 1 - empty the lists array of imported lists
1391
- $this->optionVal['lists'] = array();
1392
- // 2 - unset our previously set up widgets
1393
- update_option( 'widget_yikes_mc_widget' , '' );
1394
- // update our options
1395
- return update_option( YKSEME_OPTION, $this->optionVal );
1396
- } // end yks_resetPluginSettings();
1397
-
1398
- // Make a call to MailChimp API to validate the provided API key - send request to helper/ping, returns a boolean
1399
- public function validateAPIkeySettings() {
1400
-
1401
- // right now we just check the length of the API key being passed in
1402
- // mailchimp api keys are around 30-40 characters
1403
- // we check if the string length is greater than 45...
1404
- if ( strlen($_POST['api_key']) > 45 ) {
1405
- // Create and store our variables to pass to MailChimp
1406
- $apiKey = $this->yikes_mc_decryptIt($_POST['api_key']); // api key
1407
- $apiKey_explosion = explode( "-" , $apiKey);
1408
- $dataCenter = $apiKey_explosion[0]; // data center (ie: us3)
1409
- $api = new Mailchimp($apiKey);
1410
- // try the call, catch any errors that may be thrown
1411
- try {
1412
- $resp = $api->call('helper/ping', array('apikey' => $apiKey));
1413
- echo $resp['msg'];
1414
- $this->getOptionsLists();
1415
- } catch( Exception $e ) {
1416
- $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1417
- echo $errorMessage;
1418
- // log our error message for display back to the user
1419
- $this->writeErrorToErrorLog( $e );
1420
- }
1421
- return $apiKey;
1422
- // always die or it will always return 1
1423
- wp_die();
1424
- } else {
1425
- $apiKey = $this->yikes_mc_encryptIt($_POST['api_key']);
1426
- // Create and store our variables to pass to MailChimp
1427
- $decryped_api_key = $this->yikes_mc_decryptIt($apiKey); // api key
1428
- $apiKey_explosion = explode( "-" , $decryped_api_key);
1429
- $dataCenter = $apiKey_explosion[0]; // data center (ie: us3)
1430
- $api = new Mailchimp($decryped_api_key);
1431
- // try the call, catch any errors that may be thrown
1432
- try {
1433
- $resp = $api->call('helper/ping', array('apikey' => $decryped_api_key));
1434
- echo $resp['msg'];
1435
- } catch( Exception $e ) {
1436
- $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1437
- echo $errorMessage;
1438
- // log our error message for display back to the user
1439
- $this->writeErrorToErrorLog( $e );
1440
- }
1441
- // always die or it will always return 1
1442
- return $apiKey;
1443
- wp_die();
1444
- }
1445
- } // end validateAPIkeySettings();
1446
-
1447
- // Make a call to MailChimp API to get the current users PROFILE
1448
- public function getUserProfileDetails() {
1449
- // Create and store our variables to pass to MailChimp
1450
- $apiKey = $_POST['api_key']; // api key
1451
- $api = new Mailchimp($apiKey);
1452
- // try the call, catch any errors that may be thrown
1453
- try {
1454
- $profile_response = $api->call('users/profile', array('apikey' => $apiKey));
1455
- include_once YKSEME_PATH.'templates/mailChimp-profile-template.php';
1456
- } catch( Exception $e ) {
1457
- $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1458
- echo $errorMessage;
1459
- // write our error to the error log,
1460
- // when advanced debug is enabled
1461
- if ( $this->optionVal['debug'] == 1 ) {
1462
- $this->writeErrorToErrorLog( $e );
1463
- }
1464
- }
1465
-
1466
- // try the call, catch any errors that may be thrown
1467
- try {
1468
- $account_details = $api->call('helper/account-details', array('apikey' => $apiKey));
1469
- include_once YKSEME_PATH.'templates/mailChimp-account-overview.php';
1470
- } catch( Exception $e ) {
1471
- $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1472
- echo $errorMessage;
1473
- // write our error to the error log,
1474
- // when advanced debug is enabled
1475
- if ( $this->optionVal['debug'] == 1 ) {
1476
- $this->writeErrorToErrorLog( $e );
1477
- }
1478
- }
1479
- // always die or it will always return 1
1480
- wp_die();
1481
- } // end getUserProfileDetails();
1482
-
1483
- /*
1484
- Send Update Profile Email
1485
- @since v5.2
1486
- */
1487
- public function sendUpdateProfileEmail( $user_email , $list_id ) {
1488
- $api = new Mailchimp($this->optionVal['api-key']);
1489
- $explode_key = explode( '-' , $this->optionVal['api-key'] );
1490
- $data_center = $explode_key[1];
1491
- $full_site_url = get_bloginfo('url');
1492
- $extracted_url = str_replace( 'https://' , '' , str_replace( 'www.' , '' , str_replace( 'http://' , '' , $full_site_url ) ) );
1493
- $site_name = str_replace( ' ' , '' , get_bloginfo('name') ) ;
1494
- try {
1495
- // get the site URL
1496
- // not sure this needs its own API call
1497
- $account_details = $api->call( 'helper/account-details', array('apikey' => $this->optionVal['api-key'] ) );
1498
- // get the list details (default from name, default from email)
1499
- $list_details = $api->call( 'lists/list',
1500
- array(
1501
- 'apikey' => $this->optionVal['api-key'],
1502
- 'filters' => array(
1503
- 'list_id' => $list_id
1504
- )
1505
- )
1506
- );
1507
- // get the subscribers info
1508
- $subscriber_account_details = $api->call('lists/member-info',
1509
- array(
1510
- 'id' => $list_id,
1511
- 'emails' => array(
1512
- 0 => array(
1513
- 'email' => $user_email,
1514
- ),
1515
- )
1516
- )
1517
- );
1518
- $subscriber_id = $subscriber_account_details['data'][0]['id'];
1519
- $explode_url = explode( '.' , $account_details['contact']['url'] );
1520
- $subject = 'MailChimp Profile Update';
1521
- $headers = 'From: ' . $list_details['data'][0]['default_from_name'] . ' <' . $list_details['data'][0]['default_from_email'] . '>' . "\r\n";
1522
- $headers .= 'Content-type: text/html';
1523
- $email_content = '<p>Dear user,</p> <p>A request has been made to update your account information. To do so use the following link: <a href="http://' . $explode_url[1] . '.' . $data_center . '.list-manage1.com/profile?u=' . $account_details['user_id'] . '&id=' . $list_id .'&e=' . $subscriber_id . '" title="Update MailChimp Profile">Update Profile Info.</a>';
1524
- $email_content .= "<p>If you didn't request this update, please disregard this email.</p>";
1525
- $email_content .= '<p>&nbsp;</p>';
1526
- $email_content .= '<p>This email was sent from : ' . $full_site_url . '</p>';
1527
- $email_content .= '<p>&nbsp;</p>';
1528
- $email_content .= '<p>&nbsp;</p>';
1529
- $email_content .= '<p style="font-size:13px;margin-top:5em;float:right;"><em>this email was generated by the <a href="http://www.wordpress.org/plugins/yikes-inc-easy-mailchimp-extender/" target="_blank">YIKES Inc. Easy MailChimp Extender</a> plugin, created by <a href="http://www.yikesinc.com" target="_blank">YIKES Inc.</a></em></p>';
1530
- if ( wp_mail( $user_email, $subject, $email_content, $headers ) ) {
1531
- echo '<span class="preloader-confirmation-box success">' . __( 'Update email successfully sent. Please check your inbox for the message.' , 'yikes-inc-easy-mailchimp-extender' ) . '</span>';
1532
- } else {
1533
- echo '<span class="preloader-confirmation-box error">' . __( 'Email failed to send. Please contact the site administrator.' , 'yikes-inc-easy-mailchimp-extender' ) . '</span>';
1534
- }
1535
- // print_r($account_details);
1536
- } catch( Exception $e ) {
1537
- $errorMessage = '<span class="error">' . __( 'Error sending update profile email. Please contact the site administrator.' , 'yikes-inc-easy-mailchimp-extender' ) . '</span>';
1538
- echo $errorMessage;
1539
- // write our error to the error log,
1540
- // when advanced debug is enabled
1541
- if ( $this->optionVal['debug'] == 1 ) {
1542
- $this->writeErrorToErrorLog( $e );
1543
- }
1544
- }
1545
- } // end sendUpdateProfileEmail();
1546
-
1547
-
1548
- // Make a call to MailChimp API to validate the provided API key - api request to helper/chimp-chatter, returns Account Activity
1549
- public function getMailChimpChatter() {
1550
- // Create and store our variables to pass to MailChimp
1551
- $apiKey = $this->optionVal['api-key']; // api key
1552
- $api = new Mailchimp($apiKey);
1553
- // try the call, catch any errors that may be thrown
1554
- try {
1555
- $resp = $api->call('helper/chimp-chatter', array('apikey' => $apiKey));
1556
- include_once YKSEME_PATH.'templates/mailChimpChatter-template.php';
1557
- } catch( Exception $e ) {
1558
- echo '<strong>'.$e->getMessage().'</strong>';
1559
- // write our error to the error log,
1560
- // when advanced debug is enabled
1561
- if ( $this->optionVal['debug'] == 1 ) {
1562
- $this->writeErrorToErrorLog( $e );
1563
- }
1564
-
1565
- }
1566
- // always die or it will always return 1
1567
- wp_die();
1568
- } // end getMailChimpChatter();
1569
-
1570
-
1571
- // Make a call to MailChimp API to validate the provided API key
1572
- // calls the helper/chimp-chatter method, and returns Account Activity
1573
- public function getMailChimpChatterForWidget() {
1574
- // Create and store our variables to pass to MailChimp
1575
- $apiKey = $this->optionVal['api-key']; // api key
1576
- $api = new Mailchimp($apiKey);
1577
- // try the call, catch any errors that may be thrown
1578
- try {
1579
- $resp = $api->call('helper/chimp-chatter', array('apikey' => $apiKey));
1580
- include_once YKSEME_PATH.'templates/mailChimpChatter-widget-template.php';
1581
- } catch( Exception $e ) {
1582
- echo '<strong>'.$e->getMessage().'</strong>';
1583
- // write our error to the error log,
1584
- // when advanced debug is enabled
1585
- if ( $this->optionVal['debug'] == 1 ) {
1586
- $this->writeErrorToErrorLog( $e );
1587
- }
1588
-
1589
- }
1590
- // always die or it will always return 1
1591
- wp_die();
1592
- } // end getMailChimpChatterForWidget();
1593
-
1594
-
1595
- // Make a call to MailChimp API to lists/growth history
1596
- public function getListGrowthHistory() {
1597
- // Create and store our variables to pass to MailChimp
1598
- $apiKey = $_POST['api_key']; // api key
1599
- if ( isset($_POST['list_id']) ) { $listID = $_POST['list_id']; } else { $listID = NULL; }
1600
- $api = new Mailchimp($apiKey);
1601
- // try the call, catch any errors that may be thrown
1602
- try {
1603
- $resp = $api->call('lists/growth-history', array( 'apikey' => $apiKey , 'id' => $listID ));
1604
- // include our Stats Template
1605
- include_once YKSEME_PATH.'templates/mailChimp-list-growth-template.php';
1606
- // Working File
1607
- // date is returned out of order tho...
1608
- // include_once YKSEME_PATH.'templates/mailChimp-list-growth-template.php';
1609
- } catch( Exception $e ) {
1610
- echo '<strong>'.$e->getMessage().'</strong>';
1611
- // write our error to the error log,
1612
- // when advanced debug is enabled
1613
- if ( $this->optionVal['debug'] == 1 ) {
1614
- $this->writeErrorToErrorLog( $e );
1615
- }
1616
-
1617
- }
1618
- // always die or it will always return 1
1619
- wp_die();
1620
- } // end getListGrowthHistory();
1621
-
1622
-
1623
- // Make a call to MailChimp API to
1624
- // get a specified all campaigns or specified list campaign data
1625
- // used for both overall aggregate stats AND single list stats
1626
- public function getCapmpaignData() {
1627
- // Create and store our variables to pass to MailChimp
1628
- $apiKey = $_POST['api_key']; // api key
1629
- $api = new Mailchimp($apiKey);
1630
- // try the call, catch any errors that may be thrown
1631
- try {
1632
- $resp = $api->call('campaigns/list', array( 'apikey' => $apiKey , 'limit' => 1000 ));
1633
- // include our Stats Template
1634
- include_once YKSEME_PATH.'templates/mailChimp-campaign-stats-template.php';
1635
- } catch( Exception $e ) {
1636
- echo '<strong>'.$e->getMessage().'</strong>';
1637
- // write our error to the error log,
1638
- // when advanced debug is enabled
1639
- if ( $this->optionVal['debug'] == 1 ) {
1640
- $this->writeErrorToErrorLog( $e );
1641
- }
1642
-
1643
- }
1644
- // always die or it will always return 1
1645
- wp_die();
1646
- } // end getCapmpaignData();
1647
-
1648
-
1649
- // Make a call to MailChimp API to
1650
- // To get our piechart for the link stats page
1651
- public function getPieChart() {
1652
- // Create and store our variables to pass to MailChimp
1653
- $pie_chart_link_data_array = $_POST['pie_chart_data_array']; // link data
1654
- // include our Stats Template
1655
- include YKSEME_PATH.'templates/mailChimp-campaign-clicks-pie-chart.php';
1656
-
1657
- // always die or it will always return 1
1658
- wp_die();
1659
- }
1660
-
1661
- // Make a call to MailChimp API to
1662
- // get a specified all campaigns or specified list campaign data
1663
- // used for both overall aggregate stats AND single list stats
1664
- public function getSpecificCapmpaignData() {
1665
- // Create and store our variables to pass to MailChimp
1666
- $apiKey = $_POST['api_key']; // api key
1667
- $api = new Mailchimp($apiKey);
1668
- $campaign_id = $_POST['campaign_id'];
1669
- $campaign_title = $_POST['campaign_title'];
1670
- $campaign_email_subject = $_POST['campaign_subject'];
1671
- $campaign_send_date = $_POST['campaign_send_date'];
1672
- $campaign_send_time = $_POST['campaign_send_time'];
1673
- $campaign_view_email_link = $_POST['campaign_view_email_link'];
1674
- $campaign_web_Id = $_POST['campaign_web_Id'];
1675
- // try the call, catch any errors that may be thrown
1676
- try {
1677
- $resp = $api->call('reports/summary', array( 'apikey' => $apiKey , 'cid' => $campaign_id ));
1678
- // include our Stats Template
1679
- include_once YKSEME_PATH.'templates/mailChimp-campaign-report.php';
1680
- // print_r($resp);
1681
- } catch( Exception $e ) {
1682
- echo '<strong>'.$e->getMessage().'</strong>';
1683
- // write our error to the error log,
1684
- // when advanced debug is enabled
1685
- if ( $this->optionVal['debug'] == 1 ) {
1686
- $this->writeErrorToErrorLog( $e );
1687
- }
1688
- }
1689
- // always die or it will always return 1
1690
- wp_die();
1691
- } // end getSpecificCapmpaignData();
1692
-
1693
- // Send a call to MailChimp API to get the email recipients of a specific campaign
1694
- public function getCampaignEmailToTable() {
1695
- // Create and store our variables to pass to MailChimp
1696
- $apiKey = $_POST['api_key']; // api key
1697
- $api = new Mailchimp($apiKey);
1698
- $campaign_id = $_POST['campaign_id'];
1699
- // try the call, catch any errors that may be thrown
1700
- try {
1701
- $resp = $api->call('reports/sent-to', array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array('limit' => '100') ));
1702
- // include our Stats Template
1703
- // include_once YKSEME_PATH.'templates/mailChimp-campaign-report.php';
1704
- // print_r($resp);
1705
- if ( $resp ) {
1706
- ?>
1707
- <script type="text/javascript">
1708
- jQuery(document).ready(function() {
1709
- jQuery('#yikes-mailchimp-emailed-subscribers').dataTable();
1710
- });
1711
- </script>
1712
-
1713
- <style>
1714
- .subscriber_rating_star { font-size:15px; }
1715
- </style>
1716
-
1717
- <table id="yikes-mailchimp-emailed-subscribers" class="yks-mailchimp-fields-list" style="width:100%;">
1718
- <thead class="yikes-mailchimp-subscribers-table-head">
1719
- <tr>
1720
- <th style="width:20%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1721
- <th style="width:19%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1722
- <th style="width:18%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1723
- <th style="width:25%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1724
- <th style="width:18%;"><?php _e( 'Last Changed' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1725
- </tr>
1726
- </thead>
1727
- <?php
1728
- foreach ( $resp['data'] as $recipient ) {
1729
-
1730
- // create the name variable, dependant on first and last name being stored
1731
- if ( isset ( $recipient['member']['merges']['FNAME'] ) && $recipient['member']['merges']['FNAME'] != '' ) {
1732
- $user_first_name = $recipient['member']['merges']['FNAME'];
1733
- } else {
1734
- $user_first_name = '';
1735
- }
1736
- if ( isset ( $recipient['member']['merges']['LNAME'] ) && $recipient['member']['merges']['LNAME'] != '' ) {
1737
- $user_last_name = $recipient['member']['merges']['LNAME'];
1738
- } else {
1739
- $user_last_name = '';
1740
- }
1741
-
1742
- $user_email = $recipient['member']['email'];
1743
- $user_id = $recipient['member']['id'];
1744
- $email_type = $recipient['member']['email_type'];
1745
- $user_rating = $recipient['member']['member_rating'];
1746
- $user_last_changed = $recipient['member']['info_changed'];
1747
- $exploded_change = explode( ' ' , $user_last_changed);
1748
- $user_last_changed_date = date( 'm/d/Y' , strtotime( $exploded_change[0] ) );
1749
- $user_last_changed_time = date( 'g:i a' , strtotime( $exploded_change[1] ) );
1750
-
1751
- if(isset($user_rating)) {
1752
- if ($user_rating == 1) {
1753
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1754
- } else if ($user_rating == 2) {
1755
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1756
- } else if ($user_rating == 3) {
1757
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1758
- } else if ($user_rating == 4) {
1759
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1760
- } else if ($user_rating == 5) {
1761
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
1762
- }
1763
- }
1764
-
1765
- // $timeStamp = explode(' ', $subscriber['timestamp_opt'] );
1766
- echo '<tr class="yks-mailchimp-subscribers-list-row" id="yks-mailchimp-subscribers-list-row">';
1767
- echo '<td><a class="subscriber-mail-link" rel="'.$user_email.'" class="subscriberEmailAddress">'.$user_email.'</a></td>';
1768
- echo '<td>'.ucfirst(strtolower($user_first_name)).'</td>';
1769
- echo '<td>'.ucfirst(strtolower($user_last_name)).'</td>';
1770
- echo '<td><span style="display:none;">'.$user_rating.'</span>'.$member_rating_stars.'</td>';
1771
- echo '<td>'.$user_last_changed_date . ' at ' . $user_last_changed_time .'</td>';
1772
- echo '</tr>';
1773
-
1774
- }
1775
- ?>
1776
- </table>
1777
- <?php
1778
- }
1779
- } catch( Exception $e ) {
1780
- echo '<strong>'.$e->getMessage().'</strong>';
1781
- // write our error to the error log,
1782
- // when advanced debug is enabled
1783
- if ( $this->optionVal['debug'] == 1 ) {
1784
- $this->writeErrorToErrorLog( $e );
1785
- }
1786
-
1787
- }
1788
- // always die or it will always return 1
1789
- wp_die();
1790
- } // end getCampaignEmailToTable();
1791
-
1792
-
1793
- // Send a call to MailChimp API to get the geo location of users who opened links
1794
- public function getGeoDataForCampaignOpenLinks() {
1795
- // Create and store our variables to pass to MailChimp
1796
- $apiKey = $_POST['api_key']; // api key
1797
- $api = new Mailchimp($apiKey);
1798
- $campaign_id = $_POST['campaign_id'];
1799
- // try the call, catch any errors that may be thrown
1800
- try {
1801
- $resp = $api->call('reports/geo-opens', array( 'apikey' => $apiKey , 'cid' => $campaign_id ) );
1802
- // include our Stats Template
1803
- // include_once YKSEME_PATH.'templates/mailChimp-campaign-report.php';
1804
- // print_r($resp);
1805
- if ( $resp ) {
1806
- include_once YKSEME_PATH.'templates/mailChimp-campaign-click-geo-map.php';
1807
- }
1808
- } catch( Exception $e ) {
1809
- // write our error to the error log,
1810
- // when advanced debug is enabled
1811
- if ( $this->optionVal['debug'] == 1 ) {
1812
- $this->writeErrorToErrorLog( $e );
1813
- }
1814
- ?>
1815
- <script>
1816
- jQuery(document).ready(function() {
1817
- setTimeout(function() {
1818
- var mailChimpError = '<?php echo "<strong class=yks-mc-report-error>".$e->getMessage()."</strong>"; ?>';
1819
- jQuery('#open_tracking_disabled_warning').fadeIn();
1820
- jQuery('#geo_map_no_data').append('<p class="geo_map_no_data_error">'+mailChimpError+'</p>');
1821
- }, 600);
1822
- });
1823
- </script>
1824
-
1825
- <section class="overview_information_section">
1826
-
1827
- <div class="overview_information">
1828
-
1829
- <h2>Campaign Activity Geo Map</h2>
1830
-
1831
- <div id="geo_map_no_data" style="max-width: 100%;min-width: 100%; background:#fff;">
1832
- <div id="geo_map_no_data_overlay"></div>
1833
- <img src="<?php echo plugins_url( '/../images/highcharts-worldmap-disabled.png' , __FILE__ ); ?>" alt="World Map Disabled" title="World Map Disabled">
1834
- </div>
1835
- </div>
1836
-
1837
- </section>
1838
-
1839
- <?php
1840
- }
1841
- // always die or it will always return 1
1842
- wp_die();
1843
- } // end getGeoDataForCampaignOpenLinks();
1844
-
1845
-
1846
- // Make a call to MailChimp API to
1847
- // get link tracking information for a specified campaign
1848
- // used in the world map on the campaign stats page
1849
- public function getCampaignLinkStats() {
1850
- // Create and store our variables to pass to MailChimp
1851
- $apiKey = $_POST['api_key']; // api key
1852
- $api = new Mailchimp($apiKey);
1853
- $campaign_id = $_POST['campaign_id'];
1854
- // try the call, catch any errors that may be thrown
1855
- try {
1856
- $campaign_click_stats = $api->call( '/reports/clicks' , array( 'apikey' => $apiKey , 'cid' => $campaign_id ) );
1857
- // include our Stats Template
1858
- include_once YKSEME_PATH.'templates/mailChimp-campaign-click-report.php';
1859
- } catch( Exception $e ) {
1860
- echo '<strong>'.$e->getMessage().'</strong>';
1861
- // write our error to the error log,
1862
- // when advanced debug is enabled
1863
- if ( $this->optionVal['debug'] == 1 ) {
1864
- $this->writeErrorToErrorLog( $e );
1865
- }
1866
- }
1867
- // always die or it will always return 1
1868
- wp_die();
1869
- } // end getCampaignLinkStats();
1870
-
1871
-
1872
- // Make a call to MailChimp API to
1873
- // get users who opened a specific campaign
1874
- // used in the stats page modal
1875
- public function getCampaignOpenedData() {
1876
- // Create and store our variables to pass to MailChimp
1877
- $apiKey = $_POST['api_key']; // api key
1878
- $api = new Mailchimp($apiKey);
1879
- $campaign_id = $_POST['campaign_id'];
1880
- // try the call, catch any errors that may be thrown
1881
- try {
1882
- // create our interactive data table
1883
- // and initialize it here...
1884
-
1885
- $campaign_open_stats = $api->call( '/reports/opened' , array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array( 'sort_field' => 'opens' , 'sort_dir' => 'DESC' ) ) );
1886
-
1887
- // create an empty array
1888
- $total_opens_array = array();
1889
- // build our total opens array
1890
- foreach ( $campaign_open_stats['data'] as $opened_data ) {
1891
- $total_opens_array[] = $opened_data['opens'];
1892
- }
1893
-
1894
- // display total unique opens
1895
- echo '<h2 style="float:left;">' . __( 'Unique Opens' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . $campaign_open_stats["total"] . '</h2>';
1896
- // display total opens
1897
- echo '<h2 style="float:right;">' . __( 'Total Opens' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . array_sum($total_opens_array) . '</h2>';
1898
-
1899
- // echo '<h2>' . __( 'Total Opens' 'yikes-inc-easy-mailchimp-extender' ) . $campaign_open_stats["total"] . '</h2>';
1900
-
1901
- ?>
1902
- <!-- initialize o ur data table -->
1903
- <script type="text/javascript">
1904
- jQuery(document).ready(function() {
1905
- jQuery('#yikes-mailchimp-subscribers-opens').dataTable({
1906
- "aaSorting": [[ 1, "desc" ]]
1907
- });
1908
- });
1909
- </script>
1910
-
1911
- <style>
1912
- .subscriber_rating_star { font-size:15px; }
1913
- </style>
1914
-
1915
- <!-- build our opened user table -->
1916
- <table id="yikes-mailchimp-subscribers-opens" class="yks-mailchimp-fields-list" style="width:100%;">
1917
- <thead class="yikes-mailchimp-subscribers-table-head">
1918
- <tr>
1919
- <th style="width:31%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1920
- <th style="width:14%;"><?php _e( 'Opens' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1921
- <th style="width:20%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1922
- <th style="width:20%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1923
- <th style="width:15%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1924
- </tr>
1925
- </thead>
1926
- <?php
1927
- // loop over to build create and store our user variables returned by mailchimp
1928
- foreach ( $campaign_open_stats['data'] as $opened_data ) {
1929
-
1930
- // checking if FNAME is set as a merge variable
1931
- // if not, we'll just make it an empty string
1932
- if ( isset ( $opened_data['member']['merges']['LNAME'] ) ) {
1933
- $opened_data['member']['merges']['LNAME'] = $opened_data['member']['merges']['LNAME'];
1934
- } else {
1935
- $opened_data['member']['merges']['LNAME'] = '';
1936
- }
1937
-
1938
- // checking if LNAME is set as a merge variable
1939
- // if not, we'll just make it an empty string
1940
- if ( isset ( $opened_data['member']['merges']['FNAME'] ) ) {
1941
- $opened_data['member']['merges']['FNAME'] = $opened_data['member']['merges']['FNAME'];
1942
- } else {
1943
- $opened_data['member']['merges']['FNAME'] = '';
1944
- }
1945
-
1946
-
1947
- if(isset($opened_data['member']['member_rating'])) {
1948
- if ($opened_data['member']['member_rating'] == 1) {
1949
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1950
- } else if ($opened_data['member']['member_rating'] == 2) {
1951
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1952
- } else if ($opened_data['member']['member_rating'] == 3) {
1953
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1954
- } else if ($opened_data['member']['member_rating'] == 4) {
1955
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1956
- } else if ($opened_data['member']['member_rating'] == 5) {
1957
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
1958
- }
1959
- }
1960
- // build our table inside the loop
1961
- echo '<tr>';
1962
- echo '<td><a href="mailto:'.$opened_data['member']['email'].'">'.$opened_data['member']['email'].'</a></td>';
1963
- echo '<td>'.$opened_data['opens'].'</td>';
1964
- echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['FNAME'])).'</td>';
1965
- echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['LNAME'])).'</td>';
1966
- echo '<td><span style="display:none;">'.$opened_data['member']['member_rating'].'</span>'.$member_rating_stars.'</td>';
1967
- echo '</tr>';
1968
- }
1969
-
1970
- } catch( Exception $e ) {
1971
- // if there is some error, lets return it
1972
- echo '<strong>'.$e->getMessage().'</strong>';
1973
- // write our error to the error log,
1974
- // when advanced debug is enabled
1975
- if ( $this->optionVal['debug'] == 1 ) {
1976
- $this->writeErrorToErrorLog( $e );
1977
- }
1978
- }
1979
- // always die or it will always return 1
1980
- wp_die();
1981
- } // end getCampaignOpenedData();
1982
-
1983
-
1984
- // Make a call to MailChimp API to
1985
- // get bounced email addressed for this campaign
1986
- // used in the stats page modal
1987
- public function getCampaignBouncedEmailData() {
1988
- // Create and store our variables to pass to MailChimp
1989
- $apiKey = $_POST['api_key']; // api key
1990
- $api = new Mailchimp($apiKey);
1991
- $campaign_id = $_POST['campaign_id'];
1992
- // try the call, catch any errors that may be thrown
1993
- try {
1994
- // create our interactive data table
1995
- // and initialize it here...
1996
-
1997
- $campaign_bounce_stats = $api->call( '/reports/bounce-messages' , array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array( 'limit' => '100' ) ) );
1998
-
1999
- // print_r($campaign_bounce_stats);
2000
-
2001
- // display total unique opens
2002
- echo '<h2 style="float:left;">' . __( 'Total Bounced Emails' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . $campaign_bounce_stats["total"] . '</h2>';
2003
-
2004
- // echo '<h2>' . __( 'Total Opens' 'yikes-inc-easy-mailchimp-extender' ) . $campaign_open_stats["total"] . '</h2>';
2005
-
2006
- ?>
2007
- <!-- initialize o ur data table -->
2008
- <script type="text/javascript">
2009
- jQuery(document).ready(function() {
2010
- jQuery('#yikes-mailchimp-subscribers-bounced').dataTable({
2011
- "aaSorting": [[ 1, "desc" ]]
2012
- });
2013
- });
2014
- </script>
2015
-
2016
- <style>
2017
- .subscriber_rating_star { font-size:15px; }
2018
- </style>
2019
-
2020
- <!-- build our opened user table -->
2021
- <table id="yikes-mailchimp-subscribers-bounced" class="yks-mailchimp-fields-list" style="width:100%;">
2022
- <thead class="yikes-mailchimp-subscribers-table-head">
2023
- <tr>
2024
- <th style="width:31%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2025
- <th style="width:20%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2026
- <th style="width:20%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2027
- <th style="width:15%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2028
- </tr>
2029
- </thead>
2030
- <?php
2031
- // loop over to build create and store our user variables
2032
- // returned by mailchimp
2033
- foreach ( $campaign_bounce_stats['data'] as $opened_data ) {
2034
-
2035
- // checking if FNAME is set as a merge variable
2036
- // if not, we'll just make it an empty string
2037
- if ( isset ( $opened_data['member']['merges']['LNAME'] ) ) {
2038
- $opened_data['member']['merges']['LNAME'] = $opened_data['member']['merges']['LNAME'];
2039
- } else {
2040
- $opened_data['member']['merges']['LNAME'] = '';
2041
- }
2042
-
2043
- // checking if LNAME is set as a merge variable
2044
- // if not, we'll just make it an empty string
2045
- if ( isset ( $opened_data['member']['merges']['FNAME'] ) ) {
2046
- $opened_data['member']['merges']['FNAME'] = $opened_data['member']['merges']['FNAME'];
2047
- } else {
2048
- $opened_data['member']['merges']['FNAME'] = '';
2049
- }
2050
-
2051
-
2052
- if(isset($opened_data['member']['member_rating'])) {
2053
- if ($opened_data['member']['member_rating'] == 1) {
2054
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2055
- } else if ($opened_data['member']['member_rating'] == 2) {
2056
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2057
- } else if ($opened_data['member']['member_rating'] == 3) {
2058
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2059
- } else if ($opened_data['member']['member_rating'] == 4) {
2060
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2061
- } else if ($opened_data['member']['member_rating'] == 5) {
2062
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
2063
- }
2064
- }
2065
- // build our table inside the loop
2066
- echo '<tr>';
2067
- echo '<td><a href="mailto:'.$opened_data['member']['email'].'">'.$opened_data['member']['email'].'</a></td>';
2068
- echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['FNAME'])).'</td>';
2069
- echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['LNAME'])).'</td>';
2070
- echo '<td><span style="display:none;">'.$opened_data['member']['member_rating'].'</span>'.$member_rating_stars.'</td>';
2071
- echo '</tr>';
2072
- }
2073
-
2074
- // print_r($campaign_open_stats);
2075
-
2076
- } catch( Exception $e ) {
2077
- // if there is some error, lets return it
2078
- echo '<strong>'.$e->getMessage().'</strong>';
2079
- // write our error to the error log,
2080
- // when advanced debug is enabled
2081
- if ( $this->optionVal['debug'] == 1 ) {
2082
- $this->writeErrorToErrorLog( $e );
2083
- }
2084
- }
2085
- // always die or it will always return 1
2086
- wp_die();
2087
- } // end getCampaignBouncedEmailData();
2088
-
2089
-
2090
- // Make a call to MailChimp API to
2091
- // get unsubscribed email addressed for this campaign
2092
- // used in the stats page modal
2093
- public function getCampaignUnsubscribeData() {
2094
- // Create and store our variables to pass to MailChimp
2095
- $apiKey = $_POST['api_key']; // api key
2096
- $api = new Mailchimp($apiKey);
2097
- $campaign_id = $_POST['campaign_id'];
2098
- // try the call, catch any errors that may be thrown
2099
- try {
2100
- // create our interactive data table
2101
- // and initialize it here...
2102
-
2103
- $campaign_unsubscribe_stats = $api->call( '/reports/unsubscribes' , array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array( 'limit' => '100' ) ) );
2104
-
2105
- // print_r($campaign_bounce_stats);
2106
-
2107
- // display total unique opens
2108
- echo '<h2 style="float:left;">' . __( 'Total Unsubscribes' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . $campaign_unsubscribe_stats["total"] . '</h2>';
2109
-
2110
- // echo '<h2>' . __( 'Total Opens' 'yikes-inc-easy-mailchimp-extender' ) . $campaign_open_stats["total"] . '</h2>';
2111
-
2112
- ?>
2113
- <!-- initialize o ur data table -->
2114
- <script type="text/javascript">
2115
- jQuery(document).ready(function() {
2116
- jQuery('#yikes-mailchimp-unsubscribe-table').dataTable({
2117
- "aaSorting": [[ 0, "desc" ]]
2118
- });
2119
- });
2120
- </script>
2121
-
2122
- <style>
2123
- .subscriber_rating_star { font-size:15px; }
2124
- </style>
2125
-
2126
- <!-- build our opened user table -->
2127
- <table id="yikes-mailchimp-unsubscribe-table" class="yks-mailchimp-fields-list" style="width:100%;">
2128
- <thead class="yikes-mailchimp-subscribers-table-head">
2129
- <tr>
2130
- <th style="width:31%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2131
- <th style="width:20%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2132
- <th style="width:20%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2133
- <th style="width:15%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2134
- <th style="width:15%;"><?php _e( 'Reason' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2135
- </tr>
2136
- </thead>
2137
- <?php
2138
- // loop over to build create and store our user variables
2139
- // returned by mailchimp
2140
- foreach ( $campaign_unsubscribe_stats['data'] as $opened_data ) {
2141
-
2142
- // checking if FNAME is set as a merge variable
2143
- // if not, we'll just make it an empty string
2144
- if ( isset ( $opened_data['member']['merges']['LNAME'] ) ) {
2145
- $opened_data['member']['merges']['LNAME'] = $opened_data['member']['merges']['LNAME'];
2146
- } else {
2147
- $opened_data['member']['merges']['LNAME'] = '';
2148
- }
2149
-
2150
- // checking if LNAME is set as a merge variable
2151
- // if not, we'll just make it an empty string
2152
- if ( isset ( $opened_data['member']['merges']['FNAME'] ) ) {
2153
- $opened_data['member']['merges']['FNAME'] = $opened_data['member']['merges']['FNAME'];
2154
- } else {
2155
- $opened_data['member']['merges']['FNAME'] = '';
2156
- }
2157
-
2158
-
2159
- if(isset($opened_data['member']['member_rating'])) {
2160
- if ($opened_data['member']['member_rating'] == 1) {
2161
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2162
- } else if ($opened_data['member']['member_rating'] == 2) {
2163
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2164
- } else if ($opened_data['member']['member_rating'] == 3) {
2165
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2166
- } else if ($opened_data['member']['member_rating'] == 4) {
2167
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2168
- } else if ($opened_data['member']['member_rating'] == 5) {
2169
- $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
2170
- }
2171
- }
2172
- // build our table inside the loop
2173
- echo '<tr>';
2174
- echo '<td><a href="mailto:'.$opened_data['member']['email'].'">'.$opened_data['member']['email'].'</a></td>';
2175
- echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['FNAME'])).'</td>';
2176
- echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['LNAME'])).'</td>';
2177
- echo '<td><span style="display:none;">'.$opened_data['member']['member_rating'].'</span>'.$member_rating_stars.'</td>';
2178
- echo '<td>'.strtolower($opened_data['reason']).'</td>';
2179
- echo '</tr>';
2180
- }
2181
-
2182
- } catch( Exception $e ) {
2183
- // if there is some error, lets return it
2184
- echo '<strong>'.$e->getMessage().'</strong>';
2185
- // write our error to the error log,
2186
- // when advanced debug is enabled
2187
- if ( $this->optionVal['debug'] == 1 ) {
2188
- $this->writeErrorToErrorLog( $e );
2189
- }
2190
- }
2191
- // always die or it will always return 1
2192
- wp_die();
2193
- } // end getCampaignUnsubscribeData();
2194
-
2195
-
2196
- // Make a call to MailChimp API to add a new subscriber to a specified list
2197
- // Runs when a user fills out the form on the frontend of the site
2198
- public function addUserToMailchimp( $p , $update_existing ) {
2199
-
2200
- if( !empty( $p['form_data'] ) ) {
2201
-
2202
- parse_str($p['form_data'], $fd);
2203
-
2204
- // grab and store our nonce field
2205
- // for security purposes
2206
- $yks_mc_form_submission_nonce = $fd['_wpnonce'];
2207
-
2208
- // cross check our nonce
2209
- // passing in the action used when we created the nonce field
2210
- // if the nonce does not match, we need to die()
2211
- if ( !wp_verify_nonce( $yks_mc_form_submission_nonce , 'yks_mc_front_end_form_'.$fd['yks-mailchimp-list-id'] ) ) {
2212
- die( __( 'Failed nonce security check. Please reload the page and submit this form again.' , 'yikes-inc-easy-mailchimp-extender' ) );
2213
- }
2214
-
2215
-
2216
- if( !empty( $fd['yks-mailchimp-list-id'] ) ) {
2217
-
2218
- // if reCAPTCHA is enabled
2219
- if ( $this->optionVal['recaptcha-setting'] == '1' ) {
2220
-
2221
- if ( isset( $fd['g-recaptcha-response'] ) && $fd['g-recaptcha-response'] == '' ) {
2222
- die( __( 'Please check off that you are not a robot.' , 'yikes-inc-easy-mailchimp-extender' ) );
2223
- }
2224
-
2225
- $privatekey = $this->optionVal['recaptcha-private-api-key'];
2226
- $response = $fd['g-recaptcha-response'];
2227
-
2228
- // if the CAPTCHA was entered properly
2229
- if ( $fd['g-recaptcha-response'] == '' ) {
2230
- // if the response returns invalid,
2231
- // lets add the animated shake and error fields
2232
- // to the captcha fields
2233
- ?>
2234
- <script>
2235
- jQuery(document).ready(function() {
2236
- jQuery('.g-recaptcha').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2237
- jQuery(this).removeClass('shake animated');
2238
- next();
2239
- });
2240
- });
2241
- </script>
2242
- <?php
2243
-
2244
- // if it returns valid...
2245
- // continue sending data to MailChimp
2246
- } else {
2247
-
2248
- // Create and store the variables needed to add a new subscriber
2249
- $email = false;
2250
- $lid = $fd['yks-mailchimp-list-id'];
2251
- $api = new Mailchimp($this->optionVal['api-key']);
2252
- $mv = array();
2253
- $optin = $this->optionVal['optin'];
2254
-
2255
- foreach($this->optionVal['lists'][$lid]['fields'] as $field) : if($field['active'] == '1') :
2256
-
2257
- // Check to see if the field is in the post
2258
- if(isset($fd[$field['name']])) :
2259
-
2260
- // Grab the primary email
2261
- if(strtolower($field['merge']) == 'email')
2262
- $email = $fd[$field['name']];
2263
-
2264
- // It exists, set the merge var that we send to mailchimp
2265
- switch($field['type'])
2266
- {
2267
- default:
2268
- $mv[$field['merge']] = $fd[$field['name']];
2269
- break;
2270
-
2271
- case 'address':
2272
- $mv[$field['merge']] = array(
2273
- 'addr1' => $fd[$field['name']],
2274
- 'addr2' => $fd[$field['name'].'-add2'],
2275
- 'city' => $fd[$field['name'].'-city'],
2276
- 'state' => $fd[$field['name'].'-state'],
2277
- 'zip' => $fd[$field['name'].'-zip'],
2278
- 'country' => 'US'
2279
- );
2280
- break;
2281
-
2282
- }
2283
-
2284
-
2285
-
2286
- endif;
2287
- endif; endforeach;
2288
-
2289
- // Interest group loop to build the GROUPINGS array
2290
- // The GROUPINGS array passes our interest group, and values back to the specific form
2291
- if ( isset($fd['interest-group-data']) ) {
2292
- $interest_group_option = json_decode($fd['interest-group-data'], true);
2293
- }
2294
- // if interest groups exist, continue and form an array
2295
- if ( isset($interest_group_option) ) {
2296
-
2297
- // print_r($interest_group_option);
2298
- $mv['GROUPINGS'] = array();
2299
-
2300
- // loop over each interest group
2301
- foreach ($interest_group_option as $group ) :
2302
-
2303
- switch($group['form_field'])
2304
- {
2305
- case 'radio':
2306
- case 'dropdown':
2307
- array_push($mv['GROUPINGS'], array(
2308
- 'id' => $group['id'],
2309
- // 'groups' => array($fd['interest-group'])
2310
- 'groups' => array(isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2311
- )
2312
- );
2313
- break;
2314
-
2315
- case 'checkboxes':
2316
- array_push($mv['GROUPINGS'], array(
2317
- 'id' => $group['id'],
2318
- // 'groups' => array($fd['interest-group'])
2319
- 'groups' => (isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2320
- // $fd[$group['form_field'].'-'.$group['id']]
2321
-
2322
- )
2323
- );
2324
- break;
2325
- }
2326
- endforeach; // end loop
2327
-
2328
- }
2329
-
2330
- // If no email provided, fail
2331
- $noemail = "The email address is blank";
2332
- if($email === false) return $noemail;
2333
-
2334
- // Add custom filter here, to capture user submitted
2335
- // data before it's sent off to MailChimp
2336
- $form_data = apply_filters( 'yikes_mc_get_form_data' , $mv );
2337
-
2338
- $form_data = apply_filters( 'yikes_mc_get_form_data_'.$lid, $mv );
2339
-
2340
- // setup our welcome email variable
2341
- if( isset( $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] ) && $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] == '1' ) {
2342
- $welcome = false;
2343
- } else {
2344
- $welcome = true;
2345
- }
2346
-
2347
- // try adding subscriber, catch any error thrown
2348
- try {
2349
- $retval = $api->call('lists/subscribe', array(
2350
- 'id' => $lid, // form id
2351
- 'email' => array( 'email' => $email ), // user email
2352
- 'merge_vars' => $form_data, // merge variables (ie: fields and interest groups)
2353
- 'double_optin' => $optin, // double optin value (retreived from the settings page)
2354
- 'send_welcome' => $welcome,
2355
- 'update_existing' => $update_existing
2356
- ));
2357
- return "done";
2358
- } catch( Exception $e ) { // catch any errors returned from MailChimp
2359
- $errorCode = $e->getCode();
2360
- if ( $errorCode = '214' ) {
2361
- $errorMessage = $e->getMessage();
2362
- return json_encode( array( 'errorCode' => $errorCode , 'errorResponse' => apply_filters( 'yikes_mc_user_already_subscribed' , $errorMessage , $email ) ) );
2363
- die();
2364
- } else {
2365
- echo '<strong>'.$e->getMessage().'</strong>';
2366
- die();
2367
- }
2368
- }
2369
- }
2370
-
2371
- // if reCAPTCHA is not active, we will just send the request
2372
- // without further verification
2373
- } else {
2374
-
2375
- // Create and store the variables needed to add a new subscriber
2376
- $email = false;
2377
- $lid = $fd['yks-mailchimp-list-id'];
2378
- $api = new Mailchimp($this->optionVal['api-key']);
2379
- $mv = array();
2380
- $optin = $this->optionVal['optin'];
2381
-
2382
- foreach($this->optionVal['lists'][$lid]['fields'] as $field) : if($field['active'] == '1') :
2383
-
2384
- // Check to see if the field is in the post
2385
- if(isset($fd[$field['name']])) :
2386
-
2387
- // Grab the primary email
2388
- if(strtolower($field['merge']) == 'email')
2389
- $email = $fd[$field['name']];
2390
-
2391
- // It exists, set the merge var that we send to mailchimp
2392
- switch($field['type'])
2393
- {
2394
- default:
2395
- $mv[$field['merge']] = $fd[$field['name']];
2396
- break;
2397
-
2398
- case 'address':
2399
- $mv[$field['merge']] = array(
2400
- 'addr1' => $fd[$field['name']],
2401
- 'addr2' => $fd[$field['name'].'-add2'],
2402
- 'city' => $fd[$field['name'].'-city'],
2403
- 'state' => $fd[$field['name'].'-state'],
2404
- 'zip' => $fd[$field['name'].'-zip'],
2405
- 'country' => 'US'
2406
- );
2407
- break;
2408
-
2409
- }
2410
-
2411
-
2412
-
2413
- endif;
2414
- endif; endforeach;
2415
-
2416
- // Interest group loop to build the GROUPINGS array
2417
- // The GROUPINGS array passes our interest group, and values back to the specific form
2418
- if ( isset($fd['interest-group-data']) ) {
2419
- $interest_group_option = json_decode($fd['interest-group-data'], true);
2420
- }
2421
- // if interest groups exist, continue and form an array
2422
- if ( isset($interest_group_option) ) {
2423
-
2424
- // print_r($interest_group_option);
2425
- $mv['GROUPINGS'] = array();
2426
-
2427
- // loop over each interest group
2428
- foreach ($interest_group_option as $group ) :
2429
-
2430
- switch($group['form_field'])
2431
- {
2432
- case 'radio':
2433
- case 'dropdown':
2434
- array_push($mv['GROUPINGS'], array(
2435
- 'id' => $group['id'],
2436
- // 'groups' => array($fd['interest-group'])
2437
- 'groups' => array(isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2438
- )
2439
- );
2440
- break;
2441
-
2442
- case 'checkboxes':
2443
- array_push($mv['GROUPINGS'], array(
2444
- 'id' => $group['id'],
2445
- // 'groups' => array($fd['interest-group'])
2446
- 'groups' => (isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2447
- // $fd[$group['form_field'].'-'.$group['id']]
2448
-
2449
- )
2450
- );
2451
- break;
2452
- }
2453
- endforeach; // end loop
2454
-
2455
- }
2456
-
2457
- // If no email provided, fail
2458
- $noemail = "The email address is blank";
2459
- if($email === false) return $noemail;
2460
-
2461
- // Add custom filter here, to capture user submitted
2462
- // data before it's sent off to MailChimp
2463
- $form_data = apply_filters( 'yikes_mc_get_form_data' , $mv );
2464
- $specific_form_data = apply_filters( 'yikes_mc_get_form_data_'.$lid, $lid, $mv );
2465
-
2466
- // setup our welcome email variable
2467
- if( isset( $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] ) && $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] == '1' ) {
2468
- $welcome = false;
2469
- } else {
2470
- $welcome = true;
2471
- }
2472
-
2473
- // try adding subscriber, catch any error thrown
2474
- try {
2475
- $retval = $api->call('lists/subscribe', array(
2476
- 'id' => $lid, // form id
2477
- 'email' => array( 'email' => $email ), // user email
2478
- 'merge_vars' => $form_data, // merge variables (ie: fields and interest groups)
2479
- 'double_optin' => $optin, // double optin value (retreived from the settings page)
2480
- 'send_welcome' => $welcome,
2481
- 'update_existing' => $update_existing
2482
- ));
2483
- return "done";
2484
- } catch( Exception $e ) { // catch any errors returned from MailChimp
2485
- $errorCode = $e->getCode();
2486
- if ( $errorCode = '214' ) {
2487
- $errorMessage = $e->getMessage();
2488
- return json_encode( array( 'errorCode' => $errorCode , 'errorResponse' => apply_filters( 'yikes_mc_user_already_subscribed' , $errorMessage , $email ) ) );
2489
- die();
2490
- } else {
2491
- echo '<strong>'.$e->getMessage().'</strong>';
2492
- die();
2493
- }
2494
- }
2495
- }
2496
-
2497
- }
2498
- } else {
2499
- return __('One or more fields are empty','yikes-inc-easy-mailchimp-extender'); // return an error if your leaving any necessary fields empty
2500
- }
2501
- } // end addUserToMailchimp();
2502
-
2503
-
2504
- // Generate the lists containers on the lists page
2505
- // This function gets any imported lists, and builds up the lists page
2506
- public function generateListContainers($listArr=false) {
2507
- $listArr = ($listArr == false ? $this->optionVal['lists'] : $listArr);
2508
- $thelistdata = $this->getListsData(); //Get list names from API
2509
- // if there are any imported lists in the array
2510
- if( count( $listArr ) > 0) {
2511
- include YKSEME_PATH . 'lib/inc/yks-mc-manage-list-form-table.php';
2512
- }
2513
- $output = ob_get_contents();
2514
- ob_end_clean();
2515
- return $output;
2516
- } // end generateListContainers();
2517
-
2518
-
2519
- // Generate the Merge Variable containers on the lists page
2520
- // we use this function to re-import merge variables from mailchimp
2521
- public function generateMergeVariableContainers($listArr=false) {
2522
- $listArr = ($listArr == false ? $this->optionVal['lists'] : $listArr);
2523
- $thelistdata = $this->getListsData(); //Get list names from API
2524
- // if there are any imported lists in the array
2525
- if(count($listArr) > 0) {
2526
- ob_start();
2527
- // loop over each lists and build the page
2528
- $i = 1;
2529
- foreach($listArr as $list) {
2530
- $get_list_data = $this->getListsData();
2531
- ?>
2532
- <td class="yks-mailchimp-fields-td" id="yks-mailchimp-fields-td_<?php echo $list['id']; ?>">
2533
- <fieldset class="yks-mailchimp-fields-container" id="yks-mailchimp-fields-container_<?php echo $list['id']; ?>">
2534
- <legend class="screen-reader-text"><span><?php _e( 'Active Fields' , 'yikes-inc-easy-mailchimp-extender' ); ?></span></legend>
2535
- <div class="yks-mailchimp-fields-list" id="yks-mailchimp-fields-list_<?php echo $list['id']; ?>" rel="<?php echo $list['id']; ?>">
2536
- <!-- create sortable rows populated with mailchimp data -->
2537
- <?php
2538
- $num = 1;
2539
- foreach($list['fields'] as $field) { ?>
2540
- <div class="yks-mailchimp-fields-list-row" alt="<?php echo $field['merge']; ?>" rel="<?php echo $field['id']; ?>">
2541
- <!-- update labels on initial creation as well! to do-->
2542
- <label title="Delete <?php echo $field['label']; ?> Field">
2543
- <span class="yks-mc-delete-merge-var"><span class="dashicons dashicons-no-alt"></span></span>
2544
- </label>
2545
- <label title="Edit <?php echo $field['label']; ?> Field">
2546
- <span class="yks-mc-merge-var-change"><span class="dashicons dashicons-edit"></span></span>
2547
- </label>
2548
- <label title="Reorder <?php echo $field['label']; ?>">
2549
- <span class="yks-mailchimp-sorthandle"><?php _e( 'Drag' , 'yikes-inc-easy-mailchimp-extender' ); ?> &amp; <?php _e( 'drop' , 'yikes-inc-easy-mailchimp-extender' ); ?></span>
2550
- </label>
2551
- <label title="Toggle Visibility of <?php echo $field['label']; ?>">
2552
- <input type="checkbox" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" value="1" <?php echo ($field['active'] == 1 ? 'checked="checked"' : ''); ?><?php echo ($field['require'] == 1 ? 'disabled="disabled"' : ''); ?> />
2553
- </label>
2554
- &nbsp;
2555
- <label>
2556
- <div class="yks-mailchimp-field-name"><?php echo $field['label']; ?></div>
2557
- </label>
2558
-
2559
- <!-- <span class="yks-mailchimp-field-merge"><span class="description"><?php _e( 'Merge field' , 'yikes-inc-easy-mailchimp-extender' ); ?>:</span> &nbsp; <input type="text" class="merge_field_input" name="<?php echo $field['name']; ?>-merge" id="<?php echo $field['id']; ?>-merge" value="<?php echo $field['merge']; ?>"<?php echo (($field['locked'] == 1 || $field['merge'] == false) ? ' disabled="disabled"' : ''); ?> /></span> -->
2560
- <span class="yks-mailchimp-field-placeholder"><span class="description"><?php _e( 'Placeholder' , 'yikes-inc-easy-mailchimp-extender' ); ?>:</span> &nbsp; <input type="text" class="custom-placeholder-field" name="placeholder-<?php echo $list['id'].'-'.$num; ?>" id="<?php echo $field['id']; ?>-placeholder" placeholder="<?php echo $field['label']; ?>" value="<?php if(isset($field['placeholder-'.$list['id'].'-'.$num])) { echo $field['placeholder-'.$list['id'].'-'.$num]; } ?>" /></span>
2561
- <span class="yks-mailchimp-field-custom-field-class"><span class="description"><?php _e( 'Custom Class' , 'yikes-inc-easy-mailchimp-extender' ); ?>:</span> &nbsp; <input type="text" name="custom-field-class-<?php echo $list['id'].'-'.$num; ?>" id="<?php echo $field['id']; ?>-custom-field-class" value="<?php if(isset($field['custom-field-class-'.$list['id'].'-'.$num])) { echo $field['custom-field-class-'.$list['id'].'-'.$num]; } ?>" /></span>
2562
- </div>
2563
- <?php
2564
- $num++;
2565
- } ?>
2566
- </div>
2567
- </fieldset>
2568
- </td>
2569
- <?php
2570
- $i++;
2571
- }
2572
- }
2573
- $output = ob_get_contents();
2574
- ob_end_clean();
2575
- return $output;
2576
- } // end generateMergeVariableContainers();
2577
-
2578
- // Get list data
2579
- public function getListDataRightMeow() {
2580
- echo json_encode( $this->optionVal['lists'] );
2581
- } // end getListDataRightMeow();
2582
-
2583
- // Generate our front end JavaScript , used to submit forms
2584
- public function getFrontendFormJavascript($list='') {
2585
- if($list === '') return false;
2586
- $js = false;
2587
- foreach($list['fields'] as $field) : if($field['active'] == 1) :
2588
- // Setup JavaScript
2589
- if($field['require'] == '1') :
2590
- $prefix = "ymce";
2591
- $js .= "\n";
2592
- switch($field['type']) {
2593
-
2594
- // default
2595
- default:
2596
- $prefixa = "ymce";
2597
- $js .= "if ($".$prefixa."('#".$field['id']."').val() == '')";
2598
- $js .= "{
2599
- msg += '<li>".$field['label']."'+'\\n</li>';
2600
- err++;
2601
- $".$prefixa."('#".$field['id']."').addClass('yks_error_field_required shake animated').delay(1200).queue(function(next){
2602
- $".$prefixa."(this).removeClass('shake animated');
2603
- next();
2604
- });
2605
- } else {
2606
- $".$prefixa."('#".$field['id']."').removeClass('yks_error_field_required');
2607
- }";
2608
- break;
2609
-
2610
- // address
2611
- case 'address':
2612
- $js .= "if($".$prefix."('#".$field['id']."').val() == '') {
2613
- msg += '<li>Street Address'+'\\n</li>';
2614
- err++;
2615
- $".$prefixa."('#".$field['id']."').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2616
- $".$prefixa."(this).removeClass('shake animated');
2617
- next();
2618
- });
2619
- } else {
2620
- $".$prefixa."('#".$field['id']."').removeClass('yks_error_field_required')
2621
- }
2622
-
2623
- if($".$prefix."('#".$field['id']."-city').val() == '') {
2624
- msg += '<li>City'+'\\n</li>';
2625
- err++;
2626
- $".$prefixa."('#".$field['id']."-city').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2627
- $".$prefixa."(this).removeClass('shake animated');
2628
- next();
2629
- });
2630
- } else {
2631
- $".$prefixa."('#".$field['id']."-city').removeClass('yks_error_field_required')
2632
- }
2633
- if($".$prefix."('#".$field['id']."-state').val() == '') {
2634
- msg += '<li>State'+'\\n</li>';
2635
- err++;
2636
- $".$prefixa."('#".$field['id']."-state').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2637
- $".$prefixa."(this).removeClass('shake animated');
2638
- next();
2639
- });
2640
- } else {
2641
- $".$prefixa."('#".$field['id']."-state').removeClass('yks_error_field_required')
2642
- }
2643
- if($".$prefix."('#".$field['id']."-zip').val() == '') {
2644
- msg += '<li>Zip Code'+'\\n</li>';
2645
- err++;
2646
- $".$prefixa."('#".$field['id']."-zip').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2647
- $".$prefixa."(this).removeClass('shake animated');
2648
- next();
2649
- });
2650
- } else {
2651
- $".$prefixa."('#".$field['id']."-zip').removeClass('yks_error_field_required')
2652
- }";
2653
- break;
2654
-
2655
- // radio
2656
- case 'radio':
2657
- $js .= "if($".$prefix."('.".$field['name'].":checked').length <= 0) {
2658
- msg += '<li>".$field['label']."\\n</li>';
2659
- err++;
2660
- $".$prefixa."('label[for=".$field['id']."]').next().find('input').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2661
- $".$prefixa."(this).removeClass('shake animated');
2662
- next();
2663
- });
2664
- } else {
2665
- $".$prefixa."('#".$field['id']."').removeClass('yks_error_field_required')
2666
- }";
2667
- break;
2668
- }
2669
-
2670
- $js .= "\n";
2671
- endif;
2672
- endif; endforeach;
2673
- return $js;
2674
- } // end getFrontendFormJavascript();
2675
-
2676
- // Generate the form on the front end of the site
2677
- // this is what the user will see, and interact with
2678
- public function getFrontendFormDisplay($list='', $submit_text) {
2679
- if($list === '') return false;
2680
- ob_start();
2681
- include YKSEME_PATH . 'lib/inc/yks-mc-frontend-form-display.php';
2682
- $output = ob_get_contents();
2683
- ob_end_clean();
2684
- return $output;
2685
- }
2686
-
2687
- // Generate the input fields for the form on the front end of the site
2688
- // based on the $field['type'] that is returned from MailChimp
2689
- private function getFrontendFormDisplay_field( $field = false , $num ) {
2690
- if($field === false) return false;
2691
- $o = '';
2692
- $fieldID = $field['id'];
2693
- $exploded_field_id = explode( '-' , $fieldID );
2694
- $form_id = $exploded_field_id[1];
2695
- // print_r($field);
2696
-
2697
- $class_title = 'yks-mc-input-' . sanitize_title( $field['label'] );
2698
-
2699
- // check to see if the custom class has been set up...
2700
- if ( isset( $field['custom-field-class-'.$form_id.'-'.$num] ) ) {
2701
- $custom_class = $field['custom-field-class-'.$form_id.'-'.$num];
2702
- } else {
2703
- $custom_class = '';
2704
- }
2705
-
2706
- // check to see if the placeholder value has been stored
2707
- // setup the placeholder field
2708
- if ( isset( $field['placeholder-'.$form_id.'-'.$num] ) ) {
2709
- $placeholder = $field['placeholder-'.$form_id.'-'.$num];
2710
- } else {
2711
- $placeholder = '';
2712
- }
2713
-
2714
- switch( $field['type'] ) {
2715
- default:
2716
- case 'email':
2717
- case 'number':
2718
- case 'zipcode':
2719
- case 'phone':
2720
- case 'website':
2721
- case 'imageurl':
2722
- // custom placeholder value goes here
2723
- $o .= '<input type="text" name="'.$field['name'].'" placeholder="'.$placeholder.'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : '') . ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="" />';
2724
- break;
2725
-
2726
- case 'text':
2727
- if ( $field['default'] ) {
2728
-
2729
- $custom_tag_array = apply_filters( 'yikes_mailchimp_default_value_tag' , $custom_tag_array=array() );
2730
-
2731
- /*
2732
- Lets Setup The Default Merge Variables Here
2733
- example : {post_title} , {post_id} , {page_url} , {user_logged_in}, {blog_name}
2734
- */
2735
- global $post;
2736
-
2737
- switch ( $field['default'] ) {
2738
-
2739
- case '{post_title}' :
2740
- $field['default'] = get_the_title( $post->ID );
2741
- break;
2742
-
2743
- case '{post_id}' :
2744
- $field['default'] = $post->ID;
2745
- break;
2746
-
2747
- case '{page_url}' :
2748
- $field['default'] = get_bloginfo( 'url' ) . $_SERVER['REQUEST_URI'];
2749
- break;
2750
-
2751
- case '{blog_name}' :
2752
- $field['default'] = get_bloginfo( 'name' );
2753
- break;
2754
-
2755
- case '{user_logged_in}' :
2756
- if ( is_user_logged_in() ) {
2757
- $field['default'] = 'Registered User';
2758
- } else {
2759
- $field['default'] = 'Guest';
2760
- }
2761
- break;
2762
-
2763
- case in_array( $field['default'] , $custom_tag_array ) :
2764
- $field['default'] = apply_filters( 'yikes_mailchimp_process_default_value_tag' , $field );
2765
- break;
2766
-
2767
- default:
2768
- $field['default'] = $field['default'];
2769
- break;
2770
-
2771
- }
2772
-
2773
- }
2774
- $o .= '<input type="text" placeholder="'.$placeholder.'" name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : '') . ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="'.$field['default'].'" />';
2775
- break;
2776
-
2777
- case 'dropdown':
2778
- $o .= '<select name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'">';
2779
- if(count($field['choices']) > 0) : foreach($field['choices'] as $ok => $ov) :
2780
- $o .= '<option value="'.htmlentities($ov, ENT_QUOTES).'">'.$ov.'</option>';
2781
- endforeach; endif;
2782
- $o .= '</select>';
2783
- break;
2784
-
2785
- case 'address':
2786
- $o .= '<input type="text" placeholder="'.$placeholder.'" name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="" /><span class="yks-mailchimp-form-tooltip">Street Address</span>';
2787
- $o .= '<input type="text" name="'.$field['name'].'-add2" class="'.$field['name'].'-add2'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-add2" value="" /><span class="yks-mailchimp-form-tooltip">Apt/Suite</span>';
2788
- $o .= '<input type="text" name="'.$field['name'].'-city" class="'.$field['name'].'-city'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-city" value="" /><span class="yks-mailchimp-form-tooltip">City</span>';
2789
- $o .= '<input type="text" name="'.$field['name'].'-state" class="'.$field['name'].'-state'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-state" value="" /><span class="yks-mailchimp-form-tooltip">State</span>';
2790
- $o .= '<input type="text" name="'.$field['name'].'-zip" class="'.$field['name'].'-zip'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-zip" value="" /><span class="yks-mailchimp-form-tooltip">Zip</span>';
2791
- break;
2792
-
2793
- case 'radio':
2794
- if(count($field['choices']) > 0) : $ct=0; foreach($field['choices'] as $ok => $ov) :
2795
- $ct++;
2796
- $o .= '<label class="yks_mc_interest_group_label" for="'.$field['id'].'-'.$ok.'">
2797
- <input type="radio" name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .' yikes_mc_interest_group_checkbox" id="'.$field['id'].'-'.$ok.'" value="'.htmlentities($ov, ENT_QUOTES).'" />
2798
- <span>'.$ov.'</span>
2799
- </label>';;
2800
- endforeach; endif;
2801
- break;
2802
-
2803
- case 'date':
2804
- case 'birthday':
2805
- $o .= '<input placeholder="'.$placeholder.'" type="text" name="'.$field['name'].'" class="'.$field['name'].' yks-field-type-date'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="" />';
2806
- break;
2807
-
2808
- }
2809
-
2810
- return $o;
2811
- }
2812
-
2813
-
2814
- /***** UPDATES
2815
- ****************************************************************************************************/
2816
- public function runUpdateTasks() {
2817
- $currentVersion = (!isset($this->optionVal['version']) || empty($this->optionVal['version']) ? '5.0.3' : $this->optionVal['version']);
2818
- $latestVersion = YKSEME_VERSION_CURRENT;
2819
- if($currentVersion < $latestVersion)
2820
- {
2821
- $updateFunction = 'runUpdateTasks_'.str_replace('.', '_', $currentVersion);
2822
- if(!method_exists($this, $updateFunction)) return false;
2823
- else
2824
- {
2825
- if(call_user_func(array(&$this, $updateFunction)))
2826
- {
2827
- update_option( YKSEME_OPTION, YKSEME_VERSION_CURRENT );
2828
- $this->runUpdateTasks();
2829
- }
2830
- }
2831
- }
2832
- else return false;
2833
- }
2834
-
2835
- /**
2836
- * This update makes the first name and last name optional
2837
- * To do this we need to loop through the existing fields and
2838
- * change the 'require' key to 0
2839
- *
2840
- * 1.1.0 => 1.2.0
2841
- */
2842
- private function runUpdateTasks_1_1_0() {
2843
- if($this->optionVal['lists']) {
2844
- foreach($this->optionVal['lists'] as $lid => $list) {
2845
- foreach($list['fields'] as $fid => $field) {
2846
- switch($field['name']) {
2847
- case 'yks-mailchimp-field-name-first':
2848
- case 'yks-mailchimp-field-name-last':
2849
- $this->optionVal['lists'][$lid]['fields'][$fid]['locked'] = 0;
2850
- break;
2851
- }
2852
- }
2853
- }
2854
- }
2855
- $this->optionVal['version'] = '1.2.0';
2856
- return true;
2857
- }
2858
-
2859
- /**
2860
- * This update adds a merge_vars key to each
2861
- * field array so that users can specify their
2862
- * own merge_var names
2863
- *
2864
- * 1.2.0 => 1.3.0
2865
- */
2866
- private function runUpdateTasks_1_2_0() {
2867
- if($this->optionVal['lists']) {
2868
- foreach($this->optionVal['lists'] as $lid => $list) {
2869
- $fct = 1;
2870
- foreach($list['fields'] as $fid => $field) {
2871
- switch($field['name']) {
2872
-
2873
- case 'yks-mailchimp-field-email':
2874
- $this->optionVal['lists'][$lid]['fields'][$fid]['merge'] = 'EMAIL';
2875
- break;
2876
-
2877
- case 'yks-mailchimp-field-apt-suite':
2878
- case 'yks-mailchimp-field-city':
2879
- case 'yks-mailchimp-field-state':
2880
- case 'yks-mailchimp-field-zip':
2881
- $this->optionVal['lists'][$lid]['fields'][$fid]['merge'] = false;
2882
- break;
2883
-
2884
- default:
2885
- if(empty($this->optionVal['lists'][$lid]['fields'][$fid]['merge']) || !isset($this->optionVal['lists'][$lid]['fields'][$fid]['merge']))
2886
- $this->optionVal['lists'][$lid]['fields'][$fid]['merge'] = 'MERGE'.$fct;
2887
- $fct++;
2888
- break;
2889
- }
2890
- }
2891
- }
2892
- }
2893
- $this->optionVal['version'] = '1.3.0';
2894
- return true;
2895
- }
2896
-
2897
- /**
2898
- * This update needs to pull in all of the custom form
2899
- * data for each of the lists, unfortunately it has to replace
2900
- * just about all of the data with the new schema. We also
2901
- * add in the flavor key (for table/div usage)
2902
- *
2903
- * 4.3 => 5.0.4
2904
- */
2905
- private function runUpdateTasks_4_3() {
2906
- if ( !isset( $this->optionVal['recaptcha-setting'] ) ) {
2907
- $this->optionVal['recaptcha-setting'] = '0';
2908
- }
2909
- if ( !isset( $this->optionVal['recaptcha-api-key'] ) ) {
2910
- $this->optionVal['recaptcha-api-key'] = '';
2911
- }
2912
- if ( !isset( $this->optionVal['recaptcha-private-api-key'] ) ) {
2913
- $this->optionVal['recaptcha-private-api-key'] = '';
2914
- }
2915
- $this->optionVal['version'] = '5.0.4';
2916
- return true;
2917
- }
2918
-
2919
- /** Update/Add New Merge Variables and Interest Group Containers */
2920
-
2921
- // generate a container to allow for creating new merge variables (form fields)
2922
- function generateNewMergeVariableContainer() {
2923
- include YKSEME_PATH . 'lib/inc/yks-mc-new-merge-variable-container.php';
2924
- }
2925
-
2926
- // generate a container to allow for editing merge variables
2927
- function generateMergeVariableUpdateContainer() {
2928
- $delete_icon = '<span class="dashicons dashicons-no-alt remove-radio-dropdown-option"></span>';
2929
- include YKSEME_PATH . 'lib/inc/yks-mc-update-merge-variable-container.php';
2930
- }
2931
-
2932
- // generate a container to allow for creating new interest groups
2933
- public function generateCreateInterestGroupContainer() {
2934
- include YKSEME_PATH . 'lib/inc/yks-mc-create-interest-group-container.php';
2935
- }
2936
-
2937
- // end merge variable and interest group containers
2938
-
2939
- // generate a thickbox container
2940
- // to display a preview of the form
2941
- function generateFormPreviewContainer() {
2942
- ?>
2943
- <div id="formPreviewContainer" style="display:none;">
2944
- <?php echo '<img src="' . admin_url() . '/images/wpspin_light.gif" alt="preloader" style="margin-left: 50%; margin-top: 25%;">'; ?>
2945
- </div>
2946
- <?php
2947
- }
2948
-
2949
- // generate a thickbox container
2950
- // to display a how to in using custom template files
2951
- function generateUserTemplateHowTo() {
2952
- ?>
2953
- <div id="user_template_how_to" style="display:none;">
2954
- <a href="http://www.yikesinc.com" title="YIKES, Inc." target="_blank"><img style="float:left;margin-bottom:0;width:75px;" src="<?php echo YKSEME_URL; ?>/images/yikes_logo.png" alt="YIKES, Inc." id="yksme-yikes-logo" /></a>
2955
- <h4 class="user_template_how_to_title"><?php _e( 'Custom User Template Files' , 'yikes-inc-easy-mailchimp-extender' ); ?></h4>
2956
-
2957
- <p style="margin-top: 2.5em;" ><?php _e( 'With the latest version of YIKES Inc. Easy MailChimp Extender you can now extend the plugin beyond what it can do out of the box. Now you can create your own MailChimp sign up template files and use them with any list , anywhere on your site. We have provided you with a few bundled templates, as well as two boilerplate template files for easy customization.' , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
2958
-
2959
- <p><?php _e( 'You can create your own templates in two ways.' , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
2960
- <hr />
2961
- <ul>
2962
- <li><h4><?php _e( 'Automatic Method :' , 'yikes-inc-easy-mailchimp-extender' ); ?></h4><p><?php _e( "The easiest way is to import the template files from the plugin automatically. You can do this by clicking on the 'import boilerplate files' button. This will copy over the necessary files right into your theme. From there you can start editing the template files found in your theme root inside of the newly created 'yikes-inc-easy-mailchimp-extender' directory." , "yikes-inc-easy-mailchimp-extender" ); ?></p></li>
2963
- <a href="#" onclick="return false;" class="button-secondary import_template_boilerplates" style="width:148px;display:block;margin:0 auto;"><?php _e( "import boilerplate files" , "yikes-inc-easy-mailchimp-extender" ); ?></a>
2964
- <hr />
2965
- <li><h4><?php _e( 'Manual Method' , 'yikes-inc-easy-mailchimp-extender' ); ?> :</h4><p><?php _e( "If the automatic method doesn't work for you, you can manually copy over the necessary files." , 'yikes-inc-easy-mailchimp-extender' ); ?></p> <p><?php _e( "Copy the following directory" , "yikes-inc-easy-mailchimp-extender" ); ?> :<br /> <em class="yks-mc-file-path"><?php echo YKSEME_PATH . 'templates/yikes-mailchimp-user-templates'; ?></em> <br /><?php _e( " into your theme root, found at " , "yikes-inc-easy-mailchimp-extender" ); ?><br /> <em class="yks-mc-file-path"><?php echo get_stylesheet_directory_uri(); ?></em></p></li>
2966
- <hr />
2967
- <li><h5><?php _e( "Notes" , "yikes-inc-easy-mailchimp-extender" ); ?></h5></li>
2968
- <ul>
2969
- <li><p><?php _e( "You can also copy over any of the default bundled themes into the 'yikes-mailchimp-user-templates' directory to customize the look and feel of a default bundled template file." , "yikes-inc-easy-mailchimp-extender" ); ?></p></li>
2970
- <li><p><?php _e( "If you are having any difficulties copying over the template files, or need help using them please open a support ticket on our" , "yikes-inc-easy-mailchimp-extender" ); ?> <a href="https://github.com/yikesinc/yikes-inc-easy-mailchimp-extender/issues" target="_blank"><?php _e( "github issue tracker" , "yikes-inc-easy-mailchimp-extender" ); ?></a>.</p></li>
2971
- </ul>
2972
- </div>
2973
- <?php
2974
- }
2975
-
2976
- // generate a thickbox container
2977
- // to display a preview of the form
2978
- function getFormPreview($shortcode,$form_title,$form_bg_color,$form_text_color,$form_submit_button_color,$form_submit_button_text_color,$form_padding,$form_width,$form_alignment) {
2979
- ?>
2980
- <h4 style="width:100%;text-align:center;">"<?php echo trim( $form_title ); ?>" Form Preview</h4>
2981
- <div class="yks_mc_preview_form_container"><?php echo do_shortcode( stripslashes( $shortcode ) ); ?></div>
2982
- <!-- override the styles for our preview container -->
2983
- <style>
2984
- .yks-mailchimpFormContainer {
2985
- background: <?php echo $form_bg_color; ?> !important;
2986
- padding: <?php echo $form_padding; ?> !important;
2987
- color: <?php echo $form_text_color; ?> !important;
2988
- width: <?php echo $form_width; ?> !important;
2989
- <?php
2990
- if ( $form_alignment == 'left' ) {
2991
- ?>
2992
- display: block;
2993
- float: left;
2994
- <?php
2995
- } elseif ( $form_alignment == 'center' ) {
2996
- ?>
2997
- display: block;
2998
- margin: 0 auto;
2999
- <?php
3000
- } elseif ( $form_alignment == 'right' ) {
3001
- ?>
3002
- display: block;
3003
- float: right;
3004
- <?php
3005
- }
3006
- ?>
3007
- }
3008
- .yks-mailchimpFormDivRowLabel, .yks_mc_interest_group_label, .yks-mailchimp-form-tooltip {
3009
- color: <?php echo $form_text_color; ?> !important;
3010
- }
3011
- .ykfmc-submit {
3012
- background: <?php echo $form_submit_button_color; ?> !important;
3013
- color: <?php echo $form_submit_button_text_color; ?> !important;
3014
- }
3015
- .yks_mc_interest_group_holder input[type=radio], .yks_mc_interest_group_holder input[type=checkbox] {
3016
- margin:0 5px 0 0 !important;
3017
- }
3018
- body.mailchimp-forms_page_yks-mailchimp-form-lists form[name="yks-mailchimp-form"] {
3019
- padding: 0 !important;
3020
- }
3021
- </style>
3022
- <?php
3023
- }
3024
-
3025
- // Get the selected form template screenshot
3026
- function getTemplateScreenshot( $template_name , $template_screenshot , $template_path ) {
3027
-
3028
- $default_headers = array(
3029
- 'YIKES Inc. MailChimp Template',
3030
- 'YIKES Inc. MailChimp Template Author',
3031
- 'YIKES Inc. MailChimp Template Description'
3032
- );
3033
- // end pre-packaged templates
3034
- $template_file_data = get_file_data( $template_path , $default_headers );
3035
-
3036
- ?>
3037
- <div id="selected_template_preview_container">
3038
- <span class="selected_template_preview_header">
3039
- <h3 class="template_name"><?php echo $template_name; ?></h3>
3040
-
3041
- <p class="template_author"><strong><?php _e( "Author " , "yikes-inc-easy-mailchimp-extender" ); ?> :</strong> <em> <?php echo $template_file_data[1]; ?></em></p>
3042
- </span>
3043
-
3044
- <p><strong><?php _e( "Description" , "yikes-inc-easy-mailchimp-extender" ); ?> :</strong> <?php echo $template_file_data[2]; ?></p>
3045
-
3046
- <hr />
3047
-
3048
- <img class="template_screenshot preview_template_screenshot" style="max-width:100%;" src="<?php echo YKSEME_URL . 'templates/yikes-mailchimp-bundled-templates/' . str_replace( ' ' , '_' , $template_name ) . '/' . $template_screenshot; ?>">
3049
- </div>
3050
- <?php
3051
- }
3052
-
3053
- /**
3054
- * This update needs to pull in all of the custom form
3055
- * data for each of the lists, unfortunately it has to replace
3056
- * just about all of the data with the new schema. We also
3057
- * add in the flavor key (for table/div usage)
3058
- *
3059
- * 1.3.0 => 2.0.0
3060
- */
3061
- private function runUpdateTasks_1_3_0() {
3062
- $this->optionVal['flavor'] = '0';
3063
- $this->optionVal['debug'] = '0';
3064
- if( $this->optionVal['lists'] ) {
3065
- foreach($this->optionVal['lists'] as $uid => $list) {
3066
- unset($this->optionVal['lists'][$uid]);
3067
- $this->addList($list['list-id']);
3068
- }
3069
- }
3070
- $this->optionVal['version'] = '2.2.1';
3071
- return true;
3072
- }
3073
-
3074
- // Copy the user template file from within the plugin
3075
- // into the users theme root
3076
- public function copyUserTemplatesToUserTheme() {
3077
- $src = YKSEME_PATH . 'templates/yikes-mailchimp-user-templates';
3078
- $dst = get_stylesheet_directory() . '/yikes-mailchimp-user-templates';
3079
-
3080
- function recurse_copy($src,$dst) {
3081
- $dir = opendir($src);
3082
- // mkdir( $dst . '/yiks-mailchimp-user-templates/' );
3083
- mkdir( $dst );
3084
- while(false !== ( $file = readdir($dir)) ) {
3085
- if (( $file != '.' ) && ( $file != '..' )) {
3086
- if ( is_dir($src . '/' . $file) ) {
3087
- recurse_copy($src . '/' . $file,$dst . '/' . $file);
3088
- }
3089
- else {
3090
- copy($src . '/' . $file,$dst . '/' . $file);
3091
- }
3092
- }
3093
- }
3094
- closedir($dir);
3095
- }
3096
- recurse_copy( $src , $dst );
3097
- }
3098
-
3099
- /*
3100
- generateRandomString();
3101
- @since v5.2
3102
- Generate a random string of text and numbers for merge variable creation
3103
- */
3104
- public function randomMergeVarString($length = 5) {
3105
- $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3106
- $randomString = '';
3107
- for ($i = 0; $i < $length; $i++) {
3108
- $randomString .= $characters[rand(0, strlen($characters) - 1)];
3109
- }
3110
- echo $randomString;
3111
- }
3112
-
3113
- /*
3114
- deleteInterestGroupFromList();
3115
- @since v5.2
3116
- Delete an interest group from a given list
3117
- */
3118
- public function deleteInterestGroupFromList($mc_list_id,$interest_group_id) {
3119
- $api = new Mailchimp($this->optionVal['api-key']);
3120
- try {
3121
- $retval = $api->call('lists/interest-grouping-del', array(
3122
- 'id' => $mc_list_id,
3123
- 'grouping_id' => $interest_group_id
3124
- ));
3125
- return "done";
3126
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3127
- $errorMessage = $e->getMessage();
3128
- echo $errorMessage;
3129
- // write our error to the error log,
3130
- // when advanced debug is enabled
3131
- if ( $this->optionVal['debug'] == 1 ) {
3132
- $this->writeErrorToErrorLog( $e );
3133
- }
3134
- die();
3135
- }
3136
- }
3137
-
3138
- /*
3139
- createNewInterestGroup();
3140
- @since v5.2
3141
- Delete an interest group from a given list
3142
- */
3143
- public function createNewInterestGroup($p) {
3144
-
3145
- $api = new Mailchimp($this->optionVal['api-key']);
3146
- parse_str( $p['form_data'], $formData );
3147
- $list_id = $formData['mc-list-id'];
3148
- $grouping_name = $formData['add-interest-group-name'];
3149
- $grouping_type = $formData['add-interest-group-type'];
3150
- $grouping_groups = $formData['radio-dropdown-option'];
3151
-
3152
- try {
3153
- $retval = $api->call('lists/interest-grouping-add', array(
3154
- 'id' => $list_id,
3155
- 'name' => $grouping_name,
3156
- 'type' => $grouping_type,
3157
- 'groups' => $grouping_groups
3158
- ));
3159
- return "done";
3160
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3161
- $errorMessage = $e->getMessage();
3162
- echo $errorMessage;
3163
- // write our error to the error log,
3164
- // when advanced debug is enabled
3165
- if ( $this->optionVal['debug'] == 1 ) {
3166
- $this->writeErrorToErrorLog( $e );
3167
- }
3168
- die();
3169
- }
3170
- }
3171
-
3172
- /*
3173
- updateInterestGroup();
3174
- @since v5.2
3175
- Update an interest group from a given list
3176
- */
3177
- public function updateInterestGroup( $mailchimp_list_id , $grouping_id , $previous_value , $new_value ) {
3178
-
3179
- $api = new Mailchimp($this->optionVal['api-key']);
3180
-
3181
- try {
3182
- $retval = $api->call('lists/interest-group-update', array(
3183
- 'id' => $mailchimp_list_id,
3184
- 'old_name' => $previous_value,
3185
- 'new_name' => $new_value,
3186
- 'grouping_id' => $grouping_id
3187
- ));
3188
- return "done";
3189
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3190
- if ( $e->getCode() == 211 ) {
3191
- return "done";
3192
- } else {
3193
- $errorMessage = $e->getMessage();
3194
- echo $errorMessage;
3195
- // write our error to the error log,
3196
- // when advanced debug is enabled
3197
- if ( $this->optionVal['debug'] == 1 ) {
3198
- $this->writeErrorToErrorLog( $e );
3199
- }
3200
- }
3201
- die();
3202
- }
3203
- }
3204
-
3205
- /*
3206
- updateInterestGroupingTitle();
3207
- @since v5.2
3208
- Update an interest group from a given list
3209
- */
3210
- public function updateInterestGroupingTitle( $mailchimp_list_id , $grouping_id , $value ) {
3211
-
3212
- $api = new Mailchimp($this->optionVal['api-key']);
3213
-
3214
- try {
3215
- $retval = $api->call('lists/interest-grouping-update', array(
3216
- 'grouping_id' => $grouping_id,
3217
- 'name' => 'name',
3218
- 'value' => $value
3219
- ));
3220
- return "done";
3221
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3222
- $errorMessage = $e->getMessage();
3223
- $errorCode = $e->getCode();
3224
- echo $errorMessage;
3225
- // write our error to the error log,
3226
- // when advanced debug is enabled
3227
- if ( $this->optionVal['debug'] == 1 ) {
3228
- $this->writeErrorToErrorLog( $e );
3229
- }
3230
- die();
3231
- }
3232
- }
3233
-
3234
- /*
3235
- addInterestGroupOption();
3236
- @since v5.2
3237
- Update an interest group from a given list
3238
- */
3239
- public function addInterestGroupOption( $mailchimp_list_id , $group_name , $grouping_id ) {
3240
-
3241
- $api = new Mailchimp($this->optionVal['api-key']);
3242
-
3243
- try {
3244
- $retval = $api->call('lists/interest-group-add', array(
3245
- 'id' => $mailchimp_list_id,
3246
- 'group_name' => $group_name,
3247
- 'grouping_id' => $grouping_id
3248
- ));
3249
- return "done";
3250
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3251
- $errorMessage = $e->getMessage();
3252
- echo $errorMessage;
3253
- // write our error to the error log,
3254
- // when advanced debug is enabled
3255
- if ( $this->optionVal['debug'] == 1 ) {
3256
- $this->writeErrorToErrorLog( $e );
3257
- }
3258
- die();
3259
- }
3260
-
3261
- }
3262
-
3263
- /*
3264
- deleteInterestGroupOption();
3265
- @since v5.2
3266
- Update an interest group from a given list
3267
- */
3268
- public function deleteInterestGroupOption( $mailchimp_list_id , $group_name , $grouping_id ) {
3269
-
3270
- $api = new Mailchimp($this->optionVal['api-key']);
3271
-
3272
- try {
3273
- $retval = $api->call('lists/interest-group-del', array(
3274
- 'id' => $mailchimp_list_id,
3275
- 'group_name' => $group_name,
3276
- 'grouping_id' => $grouping_id
3277
- ));
3278
- return "done";
3279
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3280
- $errorMessage = $e->getMessage();
3281
- echo $errorMessage;
3282
- // write our error to the error log,
3283
- // when advanced debug is enabled
3284
- if ( $this->optionVal['debug'] == 1 ) {
3285
- $this->writeErrorToErrorLog( $e );
3286
- }
3287
- die();
3288
- }
3289
- }
3290
-
3291
- /*
3292
- addNewFieldToList();
3293
- @since v5.2
3294
- MailChimp API Request to Add new field to a list
3295
- */
3296
- public function addNewFieldToList( $p ) {
3297
- include YKSEME_PATH . 'lib/inc/yks-mc-add-new-field-to-list.php';
3298
- }
3299
-
3300
- /*
3301
- @since v5.2
3302
- MailChimp API Request to Add new field to a list
3303
- */
3304
- public function deleteFieldFromList( $mailchimp_list_id , $merge_tag ) {
3305
- $api = new Mailchimp($this->optionVal['api-key']);
3306
- try {
3307
- $retval = $api->call('lists/merge-var-del', array(
3308
- 'id' => $mailchimp_list_id, // list id to delete merge tag from
3309
- 'tag' => $merge_tag // merge tag to be delete
3310
- ));
3311
- return "done";
3312
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3313
- $errorMessage = $e->getMessage();
3314
- echo $errorMessage;
3315
- // write our error to the error log,
3316
- // when advanced debug is enabled
3317
- if ( $this->optionVal['debug'] == 1 ) {
3318
- $this->writeErrorToErrorLog( $e );
3319
- }
3320
- die();
3321
- }
3322
- }
3323
-
3324
- /*
3325
- @since v5.2
3326
- Change the interest group type
3327
- */
3328
- public function changeListInterestGroupType( $grouping_id , $value ) {
3329
- $api = new Mailchimp($this->optionVal['api-key']);
3330
- try {
3331
- $retval = $api->call('lists/interest-grouping-update', array(
3332
- 'grouping_id' => $grouping_id, // list id to delete merge tag from
3333
- 'name' => 'type', // merge tag to be delete
3334
- 'value' => $value
3335
- ));
3336
- return "done";
3337
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3338
- $errorMessage = $e->getMessage();
3339
- echo $errorMessage;
3340
- // write our error to the error log,
3341
- // when advanced debug is enabled
3342
- if ( $this->optionVal['debug'] == 1 ) {
3343
- $this->writeErrorToErrorLog( $e );
3344
- }
3345
- die();
3346
- }
3347
- }
3348
-
3349
- /*
3350
- @since v5.2
3351
- MailChimp API Request to Update an existing field on a given list
3352
- */
3353
- public function updateListField( $p ) {
3354
- include YKSEME_PATH . 'lib/inc/yks-mc-update-list-field.php';
3355
- }
3356
-
3357
- // recursive directory scanning
3358
- // used to retreive template files from bundled+user template directories
3359
- function buildCustomTemplateDropdown($list) {
3360
-
3361
- $bundled_template_directory = YKSEME_PATH . 'templates/yikes-mailchimp-bundled-templates/';
3362
- $bundled_template_scan = scandir($bundled_template_directory);
3363
- $custom_template_directory = get_stylesheet_directory() . '/yikes-mailchimp-user-templates/';
3364
-
3365
- // only scan the directory when files DO exist
3366
- if( is_dir( $custom_template_directory ) ) {
3367
- $custom_template_scan = scandir($custom_template_directory);
3368
- }
3369
-
3370
- echo '<select class="template-selection-dropdown" name="yks-mc-template-file-selection" >';
3371
-
3372
- /* Bundled Template Dropdown Loop */
3373
- echo '<optgroup label="Bundled Templates">';
3374
- foreach( $bundled_template_scan as $bundled_template ) {
3375
- if( $bundled_template != '.' && $bundled_template != '..' ) {
3376
-
3377
- if( is_dir( $bundled_template_directory . $bundled_template ) ) {
3378
- $template_path = $this->getTemplateFilePath($bundled_template_directory.$bundled_template);
3379
- }
3380
-
3381
- // set the selected option
3382
- if ( $list['custom_template']['template_file'] == $template_path ) {
3383
- echo '<option value="' . $template_path . '" selected="selected" >' . str_replace( '_' , ' ' , $bundled_template ) . '</option>';
3384
- } else {
3385
- echo '<option value="' . $template_path . '">' . str_replace( '_' , ' ' , $bundled_template ) . '</option>';
3386
- }
3387
-
3388
- }
3389
- }
3390
- echo '</optgroup>';
3391
-
3392
- echo '<optgroup label="Custom Templates">';
3393
- /* Custom Template Dropdown Loop */
3394
- if( is_dir( get_stylesheet_directory() . '/yikes-mailchimp-user-templates' ) && count( $custom_template_scan ) >= 1 ) {
3395
- foreach( $custom_template_scan as $custom_template ) {
3396
- if( $custom_template != '.' && $custom_template != '..' ) {
3397
- if( is_dir( $custom_template_directory . $custom_template ) ) {
3398
- $custom_template_path = $this->getTemplateFilePath($custom_template_directory.$custom_template);
3399
- }
3400
- // set the selected option
3401
- if ( $list['custom_template']['template_file'] == $custom_template_path ) {
3402
- echo '<option value="' . $custom_template_path . '" selected="selected" >' . str_replace( '_' , ' ' , $custom_template ) . '</option>';
3403
- } else {
3404
- echo '<option value="' . $custom_template_path . '">' . str_replace( '_' , ' ' , $custom_template ) . '</option>';
3405
- }
3406
- }
3407
- }
3408
- } else {
3409
- echo '<option value="" disabled="disabled">None Found</option>';
3410
- }
3411
- echo '</optgroup>';
3412
- echo '</select>';
3413
- }
3414
-
3415
- // function to return our form template path
3416
- function getTemplateFilePath($directory) {
3417
- $get_files = scandir($directory);
3418
- $sub_files = array();
3419
- foreach( $get_files as $file ) {
3420
- if($file != '.' && $file != '..') {
3421
- $explode_file = explode( '.' , $file );
3422
- $file_extension = $explode_file[1];
3423
- if ( $file_extension == 'php' ) {
3424
- $file_extension_path = $directory . '/' . $file;
3425
- }
3426
- }
3427
- }
3428
- return $file_extension_path;
3429
- }
3430
-
3431
- // Adding Opt-In Checkbox to comment forms
3432
- // submit the user to mailchimp on a successful comment submission
3433
- function ymc_add_meta_settings($comment_id) {
3434
- add_comment_meta(
3435
- $comment_id,
3436
- 'mailchimp_subscribe',
3437
- $_POST['mailchimp_subscribe'],
3438
- true
3439
- );
3440
- }
3441
-
3442
- // add the checkbox after the comment form
3443
- function add_after_comment_form($arg) {
3444
- $custom_text = trim($this->optionVal['yks-mailchimp-optin-checkbox-text']);
3445
- if ( $custom_text == '' ) {
3446
- $custom_text = __("Sign Me Up For MAILCHIMP-REPLACE-THIS-TEXT's Newsletter", "gettext");
3447
- } else {
3448
- $custom_text = $custom_text;
3449
- }
3450
- // set the default checked state here...
3451
- $arg['comment_notes_after'] = '<label for="yikes_mailchimp_comment_subscribe">
3452
- <input type="checkbox" name="mailchimp_subscribe" id="yikes_mailchimp_comment_subscribe" checked="checked" />
3453
- '.$custom_text.'
3454
- </label>';
3455
- return $arg;
3456
- }
3457
-
3458
- // Replacing 'MAILCHIMP-REPLACE-THIS-TEXT' text with sitename
3459
- function yikes_mc_replace_this_text( $text ) {
3460
- $newtext = get_bloginfo('name');
3461
- $text = str_replace( 'MAILCHIMP-REPLACE-THIS-TEXT', $newtext, $text );
3462
- return $text;
3463
- }
3464
-
3465
- // Add our commenter to the list, when comment is submitted
3466
- function ymc_subscription_add( $cid, $comment='' ) {
3467
- $cid = (int) $cid;
3468
- $yikes_api_key = $this->optionVal['api-key'];
3469
- $exploded_api_key = explode('-',$yikes_api_key);
3470
- $yikes_data_center = $exploded_api_key[1];
3471
-
3472
- if ( !is_object($comment) )
3473
- $comment = get_comment($cid);
3474
-
3475
- if ( $comment->comment_karma == 0 ) {
3476
- $subscribe = get_comment_meta($cid, 'mailchimp_subscribe', true);
3477
- if ( $subscribe == 'on' ) {
3478
- global $current_user;
3479
- get_currentuserinfo();
3480
- $commenter_first_name = trim($current_user->user_firstname);
3481
- $commenter_last_name = trim($current_user->user_lastname);
3482
-
3483
- if( isset( $commenter_first_name ) && $commenter_first_name != '' ) {
3484
- $commenter_first_name = $commenter_first_name; // use the users first name set in the profile
3485
- } else {
3486
- $commenter_first_name = $comment->comment_author; // if no first name is set in the user profile, we will use the account name
3487
- }
3488
-
3489
- if( isset( $commenter_last_name ) && $commenter_last_name != '' ) {
3490
- $commenter_last_name = $commenter_last_name; // use the users last name set in the profile
3491
- } else {
3492
- $commenter_last_name = 'n/a'; // if the user has not set a last name in their profile, we set it to n/a
3493
- }
3494
-
3495
- // store our API key
3496
- // on the settings page, if they have chosen to display the checkbox
3497
- $api = new Mailchimp($this->optionVal['api-key']);
3498
-
3499
- $apikey = $yikes_api_key;
3500
- $listid = $this->optionVal['yks-mailchimp-optIn-default-list']; // Need to set up a default list to subscribe all users to
3501
- $endpoint = 'https://api.mailchimp.com';
3502
- $optin = $this->optionVal['optin'];
3503
-
3504
- // setup our welcome email variable
3505
- if( isset( $this->optionVal['lists'][$listid]['fields'][$listid.'-email']['yks_mailchimp_send_welcome_'.$listid] ) && $this->optionVal['lists'][$listid]['fields'][$listid.'-email']['yks_mailchimp_send_welcome_'.$listid] == '1' ) {
3506
- $welcome = false;
3507
- } else {
3508
- $welcome = true;
3509
- }
3510
-
3511
- // try adding subscriber, catch any error thrown
3512
- try {
3513
- $retval = $api->call('lists/subscribe', array(
3514
- 'id' => $listid, // form id
3515
- 'email' => array(
3516
- 'email' => $comment->comment_author_email
3517
- ),
3518
- 'merge_vars' => array(
3519
- 'FNAME' => $commenter_first_name,
3520
- 'LNAME' => $commenter_last_name,
3521
- 'NAME' => $commenter_first_name
3522
- ),
3523
- 'double_optin' => $optin, // double optin value (retreived from the settings page)
3524
- 'send_welcome' => $welcome
3525
- ));
3526
- return "done";
3527
- } catch( Exception $e ) { // catch any errors returned from MailChimp
3528
- $error_message = $e->getMessage();
3529
- if (strpos($error_message,'Click here to update your profile.') !== false) {
3530
- $errorMessage = str_replace('Click here to update your profile.', '', $e->getMessage());
3531
- $errorMessage_explode = explode('to list', $errorMessage);
3532
- echo $errorMessage_explode[0].'.';
3533
- die();
3534
- }
3535
- if (strpos($error_message,'Invalid') !== false) {
3536
- $display_errorMessage = str_replace('Invalid MailChimp List ID:', "Oops! The Webmaster hasn't set up the default MailChimp list to subscribe you too. Please contact them and let them know of this error. In the meantime, un-check the subscription checkbox in the comment form when submitting comments.", $error_message);
3537
- echo $display_errorMessage;
3538
- die();
3539
- } else {
3540
- // str_replace('Invalid MailChimp List ID: .', 'The Webmaster hasn\t set up the default MailChimp list to subscribe you too. Please contact them and let them know of this error. In the meantime, un-check the subscription checkbox in the comment form when submitting comments.', $e->getMessage());
3541
- echo $errorMessage;
3542
- die();
3543
- }
3544
- }
3545
- }
3546
- }
3547
- }
3548
-
3549
- // add our actions on initialize
3550
- // inside of __construct()
3551
- public function ykes_mc_apply_filters() {
3552
- // if the optin checkbox setting is set to show
3553
- // we wiill display the checkbox on the front end
3554
- if ( $this->optionVal['optIn-checkbox'] == 1 ) {
3555
- add_action('comment_post', array(&$this, 'ymc_add_meta_settings'), 10, 2);
3556
- add_action('comment_approved_', array(&$this, 'ymc_subscription_add'), 60, 2);
3557
- add_action('comment_post', array(&$this, 'ymc_subscription_add'));
3558
- add_filter('gettext', array(&$this, 'yikes_mc_replace_this_text'));
3559
- // only display the checkbox if the user is logged in, and the default list is set
3560
- if( is_user_logged_in() && isset( $this->optionVal['yks-mailchimp-optIn-default-list'] ) && $this->optionVal['yks-mailchimp-optIn-default-list'] != 'select_value' ) {
3561
- add_filter('comment_form_defaults', array(&$this, 'add_after_comment_form'));
3562
- }
3563
- }
3564
- }
3565
-
3566
-
3567
- /****
3568
- **
3569
- ** Custom The_Content filter
3570
- ** used to prevent other plugins from hooking here
3571
- **
3572
- ****/
3573
- function yks_mc_content() {
3574
- //Create our own version of the_content so that others can't accidentally loop into our output - Taken from default-filters.php, shortcodes.php, and media.php
3575
- if ( !has_filter( 'yks_mc_content', 'wptexturize' ) ) {
3576
- add_filter( 'yks_mc_content', 'wptexturize' );
3577
- add_filter( 'yks_mc_content', 'convert_smilies' );
3578
- add_filter( 'yks_mc_content', 'convert_chars' );
3579
- add_filter( 'yks_mc_content', 'wpautop' );
3580
- add_filter( 'yks_mc_content', 'shortcode_unautop' );
3581
- add_filter( 'yks_mc_content', 'prepend_attachment' );
3582
- $vidembed = new WP_Embed();
3583
- add_filter( 'yks_mc_content', array( &$vidembed, 'run_shortcode'), 8 );
3584
- add_filter( 'yks_mc_content', array( &$vidembed, 'autoembed'), 8 );
3585
- add_filter( 'yks_mc_content', 'do_shortcode', 11);
3586
- } //end has_filter
3587
- } //end yks_mc_content
3588
-
3589
-
3590
- // Check if cURL is enabled at the server level
3591
- // used on the options.php page
3592
- public function yikes_curl_check() {
3593
- if (in_array ('curl', get_loaded_extensions())) {
3594
- return true;
3595
- } else {
3596
- return false;
3597
- }
3598
- }
3599
-
3600
- // check if php.ini exists in the site root
3601
- function yks_check_if_php_ini_exists() {
3602
-
3603
- // get php ini path from the actively loaded php ini file
3604
- $wordpress_site_root = str_replace('php.ini','',php_ini_loaded_file());
3605
- // file name
3606
- $filename = '/php.ini';
3607
-
3608
- $php_ini_location = php_ini_loaded_file();
3609
-
3610
- if (file_exists($wordpress_site_root.$filename)) {
3611
- echo "<span class='yks_mc_no_phpini_success'>Good News </span>: We have located your <strong>".str_replace('/','',$filename)."</strong> file inside the directory <strong>".$wordpress_site_root."</strong>";
3612
- $filename = '/php.ini';
3613
- } else {
3614
- echo "<span class='yks_mc_no_phpini_alert'>Alert </span>: No <strong>".str_replace('/','',$filename)."</strong> was located in <strong>".$wordpress_site_root.'/'."</strong>.";
3615
- $filename = '/php.ini';
3616
- }
3617
-
3618
- }
3619
-
3620
- // display the php.ini location to the user
3621
- function yks_display_php_ini_location() {
3622
- echo php_ini_loaded_file();
3623
- }
3624
-
3625
-
3626
- // Add TinyMCE Buttons to the TinyMCE Editor
3627
- // We'll use the button to place form shortcodes!
3628
- // NOTE: This only runs on 3.9 or greater -> due to tinyMCE 4.0
3629
- // Custom TinyMCE Button to insert form shortcodes onto pages and posts
3630
- function yks_mc_add_tinyMCE() {
3631
- global $typenow;
3632
- // only on Post Type: post and page
3633
- if( ! in_array( $typenow, array( 'post', 'page' ) ) ) {
3634
- return ;
3635
- }
3636
- }
3637
-
3638
- // inlcude the js for tinymce
3639
- function yks_mc_add_tinymce_plugin( $plugin_array ) {
3640
- $plugin_array['yks_mc_tinymce_button'] = plugins_url( '/../js/yks_mc_tinymce_button.js', __FILE__ );
3641
- // Print all plugin js path
3642
- // var_dump( $plugin_array );
3643
- return $plugin_array;
3644
- }
3645
-
3646
- // Add the button key for address via JS
3647
- function yks_mc_add_tinymce_button( $buttons ) {
3648
- array_push( $buttons, 'yks_mc_tinymce_button_key' );
3649
- // Print all buttons
3650
- return $buttons;
3651
- }
3652
-
3653
- /**
3654
- * Localize Script
3655
- * Pass our imported list data, to the JS file
3656
- * to build the dropdown list in the modal
3657
- */
3658
- function yks_mc_js_admin_head() {
3659
- $yks_mc_imported_list_data = $this->optionVal['lists'];
3660
- // our list data array, we will pass to the js file
3661
- $list_value_array = array();
3662
- $i = 0;
3663
- // loop over the list data
3664
- foreach ( $yks_mc_imported_list_data as $single_list ) {
3665
- // store it temporarily and push it back to our array
3666
- $list_value_array[$i]['text'] = $single_list['name'];
3667
- $list_value_array[$i]['value'] = $single_list['id'];
3668
- $i++;
3669
- }
3670
- ?>
3671
- <!-- TinyMCE Shortcode Plugin -->
3672
- <script type='text/javascript'>
3673
- var yks_mc_lists_data = {
3674
- 'lists': <?php echo json_encode($list_value_array); ?>
3675
- };
3676
- </script>
3677
- <!-- TinyMCE Shortcode Plugin -->
3678
- <?php
3679
- }
3680
-
3681
-
3682
- /* Checking if the user is on localhost */
3683
- /* If they are we want to display a warning about SSL on localhost */
3684
- function yks_mc_is_user_localhost() {
3685
- $whitelist = array( '127.0.0.1', '::1' );
3686
- if( in_array( $_SERVER['REMOTE_ADDR'], $whitelist) ) {
3687
- return true;
3688
- }
3689
- }
3690
-
3691
- /*******************************************************/
3692
- /* Helper Functions */
3693
- /******************************************************/
3694
- /*
3695
- *
3696
- * Helper function when testing user submitted data
3697
- * to be used inside of the yikes_mc_get_form_data filter
3698
- *
3699
- */
3700
- function yks_mc_print_user_data( $form_ID, $merge_variables ) {
3701
- echo '<h3>The Data Returned From This Form</h3>';
3702
- echo '<strong>MailChimp List ID : </strong> '.$form_ID.' <br />';
3703
- echo '<hr />';
3704
- if ( isset( $merge_variables['FNAME'] ) && $merge_variables['FNAME'] != '' ) {
3705
- echo '<strong>User\'s Name : </strong> '.$merge_variables['FNAME'].' <br />';
3706
- echo '<hr />';
3707
- }
3708
- if ( isset( $merge_variables['LNAME'] ) && $merge_variables['LNAME'] != '' ) {
3709
- echo '<strong>User\'s Name : </strong> '.$merge_variables['LNAME'].' <br />';
3710
- echo '<hr />';
3711
- }
3712
- echo '<strong>Users Email : </strong>'.$merge_variables['EMAIL'].' <br />';
3713
- if ( isset( $merge_variables['GROUPINGS'] ) ) {
3714
- echo '<hr />';
3715
- echo '<strong>Interest Group Data : </strong><br /><br />';
3716
- foreach ( $merge_variables['GROUPINGS'] as $grouping_variable ) {
3717
- echo '<ol style="list-style:none;">Interest Group : '.$grouping_variable['id'].'</ol>';
3718
- if ( !isset($grouping_variable['groups'][0]) || $grouping_variable['groups'][0] == '' ) {
3719
- echo '<li style="list-style:none;">No interest groups selected</li><br />';
3720
- } else {
3721
- // loop over interest groups to build array
3722
- $interest_group_array = array();
3723
- foreach ( $grouping_variable['groups'] as $interest_group ) {
3724
- array_push( $interest_group_array , $interest_group );
3725
- }
3726
- if ( count($interest_group_array) > 0 ) {
3727
- foreach ( $interest_group_array as $interest_group_label ) {
3728
- echo '<li style="list-style:none;">'.$interest_group_label.'</li>';
3729
- }
3730
- echo '<br />';
3731
- }
3732
- }
3733
- }
3734
- }
3735
- echo '<em style="color:rgb(238, 93, 93);">Form data has not been sent to MailChimp</em><br />';
3736
- die(); // die to prevent data being sent over to MailChimp
3737
- }
3738
-
3739
- /*
3740
- * Helper function when testing user submitted data
3741
- * print_r($merge_variables) is returned
3742
- */
3743
- function yks_mc_dump_user_data( $form_ID, $merge_variables ) {
3744
- echo '<strong>Form ID :</strong> '.$form_ID. '<br />';
3745
- echo '<strong>Merge Variables :</strong><br />';
3746
- print_r($merge_variables);
3747
- echo '<br /><em style="color:rgb(238, 93, 93);">Form data has not been sent to MailChimp</em>';
3748
- die(); // die to prevent data being sent over to MailChimp
3749
- }
3750
-
3751
- /****************************************************************************************
3752
- * Begin Heartbeat API Code
3753
- * - Used on the Account Activity page for lilve updates
3754
- ****************************************************************************************/
3755
-
3756
- /*
3757
- Client-side code. First we enqueue the Heartbeat API and our Javascript.
3758
- Our Javascript is then setup to always send the message 'marco' to the server.
3759
- If a message comes back, the Javascript logs it (polo) to console.
3760
- */
3761
-
3762
- //enqueue heartbeat.js and our Javascript
3763
- function yks_mc_heartbeat_init() {
3764
- //enqueue the Heartbeat API
3765
- wp_enqueue_script('heartbeat');
3766
-
3767
- //load our Javascript in the footer
3768
- add_action("admin_print_footer_scripts", array( &$this ,"yks_mc_heartbeat_admin_footer" ) );
3769
- }
3770
-
3771
-
3772
- //our Javascript to send/process from the client side
3773
- function yks_mc_heartbeat_admin_footer() {
3774
- include YKSEME_PATH . 'lib/inc/yks-mc-heartbeat-api.php';
3775
- }
3776
-
3777
- /*
3778
- Our server-side code.
3779
- ------------------------------
3780
- This hooks into the heartbeat_received filter.
3781
- It checks for a key 'client' in the data array. If it is set to 'get_chimp_chatter_data',
3782
- a key 'server' is set to 'Get MailChimp Chatter Data' in the response array.
3783
- */
3784
- function yks_mc_heartbeat_received($response, $data) {
3785
- // if the client returns get chimp chatter data, popluate
3786
- // the response with some data
3787
- if( $data['yks_mc_chimp_chatter_heartbeat'] == 'get_chimp_chatter_data' ) {
3788
- // populate the response with something
3789
- $response['yks_mc_chimp_chatter_data'] = 'Get MailChimp Chatter Data';
3790
- } else if ( $data['yks_mc_chimp_chatter_heartbeat'] == 'get_chimp_chatter_widget_data' ) {
3791
- $response['yks_mc_chimp_chatter_data'] = 'Get MailChimp Chatter Widget Data';
3792
- }
3793
- return $response;
3794
- }
3795
-
3796
- /** Change Default HeartBeat API Pulse Time */
3797
- function yks_mc_tweak_heartbeat_settings( $settings ) {
3798
- $settings['interval'] = 45; //Anything between 15-60
3799
- return $settings;
3800
- }
3801
-
3802
- /*******************************************************
3803
- Custom Dashboard MailChimp Account Activity Widget
3804
- ********************************************************/
3805
- /**
3806
- * Add a widget to the dashboard.
3807
- *
3808
- * This function is hooked into the 'wp_dashboard_setup' action below.
3809
- */
3810
- function yks_mc_add_chimp_chatter_dashboard_widget() {
3811
- wp_add_dashboard_widget(
3812
- 'yks_mc_account_activity_widget', // Widget slug.
3813
- 'MailChimp Account Activity', // Title.
3814
- array( &$this , 'yks_mc_chimp_chatter_dashboard_widget_function' ) // Display function.
3815
- );
3816
- }
3817
-
3818
- /**
3819
- * Create the function to output the contents of our Dashboard Widget.
3820
- */
3821
- function yks_mc_chimp_chatter_dashboard_widget_function() {
3822
- include YKSEME_PATH . 'lib/inc/yks-mc-heartbeat-widget-functions.php';
3823
- }
3824
-
3825
-
3826
- // help , review container
3827
- public function help_review_container() {
3828
- ?>
3829
- <div id="yks_mc_review_this_plugin_container">
3830
- <a href="https://github.com/yikesinc/yikes-inc-easy-mailchimp-extender/issues?state=open" target="_blank">
3831
- <span class="yks_mc_need_support">
3832
- <strong>
3833
- <?php _e( 'Need Help?', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3834
- <?php _e( 'Get In Contact!', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3835
- <div class="dashicons dashicons-plus-alt"></div>
3836
- </strong>
3837
- </span>
3838
- </a>
3839
- <a href="http://wordpress.org/support/view/plugin-reviews/yikes-inc-easy-mailchimp-extender" target="_blank">
3840
- <span class="yks_mc_leave_us_a_review">
3841
- <strong>
3842
- <?php _e( 'Loving the plugin?', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3843
- <?php _e( 'Leave us a nice review', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3844
- <div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div>
3845
- </strong>
3846
- </span>
3847
- </a>
3848
- <a href="http://www.yikesinc.com" target="_blank" class="yks_header_logo">
3849
- <img src="<?php echo plugins_url().'/yikes-inc-easy-mailchimp-extender/images/yikes_logo.png'; ?>" alt="YIKES Inc. Logo" width=85 title="YIKES Inc. Logo" />
3850
- </a>
3851
- </div>
3852
- <?php
3853
- }
3854
-
3855
-
3856
- /**
3857
- Write our errors to an error log for display to the user
3858
- - should help minimize number of requests we receive, or at least help us diagnose user issues better
3859
- **/
3860
-
3861
- /*
3862
- * writeErrorToErrorLog()
3863
- * parameters: $errorResponse
3864
- * writes a returned API error to our log for display
3865
- *
3866
- * @since 5.2
3867
- */
3868
- public function writeErrorToErrorLog( $errorResponse ) {
3869
- // make sure file_get_contents and file_put_contents are available
3870
- if ( function_exists( 'file_get_contents' ) && function_exists( 'file_put_contents' ) ) {
3871
- $error_occurance_time = current_time( 'M' ) . '. ' . current_time( 'jS' ) . ', ' . current_time( 'Y' ) . ' - ' . current_time( 'g:i:sa' );
3872
- $error_log_location = YKSEME_PATH . 'lib/error_log/yks_mc_error_log.php';
3873
- $current_contents = file_get_contents( $error_log_location );
3874
- // get total count of errors, we only want to limit to 8 latest errors
3875
- $total_errors = explode( '<tr>' , $current_contents );
3876
- $error_array = array();
3877
- $i = 0;
3878
- foreach( $total_errors as $error ) {
3879
- $error_array[] = $error;
3880
- // limit the error log to the latest 10 errors
3881
- if ( ++$i == 11 ) {
3882
- break;
3883
- }
3884
- }
3885
- $new_content = '<tr>
3886
- <td>' . $errorResponse->getMessage() . '</td>
3887
- <td>' . $error_occurance_time . '</td>
3888
- </tr>' . implode( '<tr>' , $error_array );
3889
- file_put_contents( $error_log_location , $new_content );
3890
- }
3891
- }
3892
-
3893
- /*
3894
- * ytks_mc_generate_error_log_table()
3895
- * generate our erorr log table on the options settings page
3896
- *
3897
- * @since 5.2
3898
- */
3899
- public function yks_mc_generate_error_log_table() {
3900
- $error_log_contents = file_get_contents( YKSEME_PATH . 'lib/error_log/yks_mc_error_log.php' , true );
3901
- if ( $error_log_contents != '' ) {
3902
- return $error_log_contents;
3903
- }
3904
- }
3905
-
3906
- /*
3907
- * clearYksMCErrorLog()
3908
- * clear the error log of all errors
3909
- *
3910
- * @since 5.2
3911
- */
3912
- public function clearYksMCErrorLog() {
3913
- echo 'running';
3914
- try {
3915
- $clear_contents = file_put_contents( YKSEME_PATH . 'lib/error_log/yks_mc_error_log.php' , '' );
3916
- } catch ( Exception $e ) {
3917
- return $e->getMessage();
3918
- $this->writeErrorToErrorLog( $e );
3919
- }
3920
- }
3921
-
3922
- } // end class
3923
- } // end class check
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3924
  ?>
1
+ <?php
2
+ if(!class_exists("yksemeBase")) {
3
+ class yksemeBase {
4
+
5
+ /**
6
+ * Variables
7
+ */
8
+ private $error = false;
9
+ private $errorMsg = '';
10
+ public $sessName = 'ykseme';
11
+ public $optionVal = false;
12
+ public $currentLists = false;
13
+ public $currentListsCt = false;
14
+
15
+ /**
16
+ * Construct
17
+ */
18
+ public function __construct() {
19
+ yksemeBase::initialize();
20
+ add_action('init', array(&$this, 'ykes_mc_apply_filters'));
21
+ /* Display a notice that can be dismissed */
22
+ add_action('admin_notices', array( $this, 'yikes_mailchimp_update_admin_notice' ) );
23
+ add_action('admin_init', array( $this, 'yikes_mailchimp_update_nag_ignore' ) );
24
+ }
25
+
26
+ public function yikes_mailchimp_update_admin_notice() {
27
+ global $current_user ;
28
+ $user_id = $current_user->ID;
29
+ if( current_user_can( 'activate_plugins' ) ) {
30
+ /* Check that the user hasn't already clicked to ignore the message */
31
+ if ( ! get_option( 'yikes_mailchimp_upgrade_notice', '0' ) ) {
32
+ ?>
33
+ <style>
34
+ #yikes_mailchimp_mailing_list_form {
35
+ display: inline-block;
36
+ width: 100%;
37
+ }
38
+ #yikes_mailchimp_mailing_list_form label {
39
+ float: left;
40
+ margin-right: .5em;
41
+ }
42
+ #yikes_mailchimp_mailing_list_form .submit {
43
+ float: left;
44
+ margin-top: 33px;.
45
+ margin-bottom: 0;
46
+ }
47
+ </style>
48
+ <?php
49
+ $upgrade_notice = __( '<strong>Notice: The next release of YIKES Easy Forms for MailChimp is a major update.</strong> The entire plugin has been re-written from the ground up to iron out reoccurring bugs and make the plugin better than ever!', 'yikes-inc-easy-mailchimp-extender' );
50
+ $upgrade_notice .= '<p>' . __( '<a href="http://www.yikesinc.com/services/yikes-inc-easy-mailchimp-extender/" target="_blank" title="YIKES Plugins Mailing List">' . __( 'Sign up for our Plugins mailing list', 'yikes-inc-easy-mailchimp-extender' ) . '</a>, ' . 'and before launch, we will send you <strong>a Guide to Upgrading</strong> as well as <strong>a coupon code</strong> for great new add-ons we built for the new version of the plugin.', 'yikes-inc-easy-mailchimp-extender' ) . '</p>';
51
+ $jQuery = "jQuery( '#yikes_mailchimp_mailing_list_form' ).fadeIn();return false;";
52
+ $links = '<a href="?yikes_mailchimp_upgrade_notice=1">' . __( 'Thanks, I got it!', 'yikes-inc-easy-mailchimp-extender' ) . '</a> | <a href="http://www.yikesinc.com/services/yikes-inc-easy-mailchimp-extender/" target="_blank" title="YIKES Plugins Mailing List">' . __( 'Sign up for our Mailing List', 'yikes-inc-easy-mailchimp-extender' ) . '</a>';
53
+ echo '<div class="updated"><p>';
54
+ echo $upgrade_notice;
55
+ echo '<p>' . $links . '</p>';
56
+ echo "</p></div>";
57
+ }
58
+ }
59
+ }
60
+
61
+ public function yikes_mailchimp_update_nag_ignore() {
62
+ /* If user clicks to ignore the notice, add that to their user meta */
63
+ if ( isset($_GET['yikes_mailchimp_upgrade_notice']) && '1' == $_GET['yikes_mailchimp_upgrade_notice'] ) {
64
+ update_option( 'yikes_mailchimp_upgrade_notice', '1' );
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Destruct
70
+ */
71
+ public function __destruct() {
72
+ unset($this);
73
+ }
74
+
75
+ /**
76
+ * Actions
77
+ * These are called when the plug in is initialized/deactivated/un-installed
78
+ */
79
+ public function activate() {
80
+ // redirect the user on plugin activation
81
+ // to our MailChimp settings page
82
+ add_option('yks_easy_mc_plugin_do_activation_redirect', true);
83
+
84
+ // check if our option is already set
85
+ // if it exists, return
86
+ if( get_option( 'api_validation' ) ) {
87
+ return;
88
+ } else { // else create it
89
+ add_option('api_validation' , 'invalid_api_key');
90
+ }
91
+
92
+ }
93
+
94
+ public function deactivate() {
95
+
96
+ }
97
+
98
+ public function uninstall() { // delete options on plugin uninstall
99
+ delete_option (YKSEME_OPTION );
100
+ delete_option( 'api_validation' );
101
+ delete_option( 'imported_lists' );
102
+ delete_option( 'yikes_mailchimp_upgrade_notice' );
103
+ }
104
+
105
+ /***** INITIAL SETUP
106
+ ****************************************************************************************************/
107
+ public function initialize() {
108
+ // include our initialization file
109
+ include YKSEME_PATH . 'lib/inc/yks-mc-init.php';
110
+
111
+ /*
112
+ Conditionally Include the MailChimp Class File
113
+ */
114
+ if( !class_exists("Mailchimp") ) {
115
+ if ( $this->optionVal['ssl_verify_peer'] == 'true' ) {
116
+ require_once YKSEME_PATH.'classes/MCAPI_2.0.class.php';
117
+ } else {
118
+ require_once YKSEME_PATH.'classes/MCAPI_2.0.class.verify_false.php';
119
+ }
120
+ }
121
+
122
+ /*
123
+ * add our new ssl_verify_peer debug option, if it doesn't already exist
124
+ * @since v5.2
125
+ */
126
+ if ( !isset( $this->optionVal['ssl_verify_peer'] ) ) {
127
+ $options = get_option( YKSEME_OPTION );
128
+ $options['ssl_verify_peer'] = 'true';
129
+ update_option( YKSEME_OPTION , $options );
130
+ }
131
+
132
+ /*
133
+ * add our new hide 'required text' option, if it doesn't already exist
134
+ * @since v5.3
135
+ */
136
+ if ( !isset( $this->optionVal['yks-mailchimp-required-text'] ) ) {
137
+ $options = get_option( YKSEME_OPTION );
138
+ $options['yks-mailchimp-required-text'] = '0';
139
+ update_option( YKSEME_OPTION , $options );
140
+ }
141
+
142
+ }
143
+
144
+ // register and add our shortcodes
145
+ public function createShortcodes() {
146
+ add_shortcode( 'yks-mailchimp-list' , array( &$this, 'processShortcode' ) );
147
+ add_shortcode( 'yks-mailchimp-subscriber-count' , array( &$this, 'displaySubscriberCount') );
148
+ }
149
+
150
+ /** Custom Filter To Alter User Submitted Data **/
151
+ public function yikes_mc_get_form_data_filter( $mv ) {
152
+ return $mv;
153
+ }
154
+
155
+ /** Custom Filter To Alter User Already Subscribed Error Message **/
156
+ public function yikes_mc_user_already_subscribed_error_message_filter( $errorMessage , $email ) {
157
+ return $errorMessage;
158
+ }
159
+
160
+ // Create and store our initial plugin options
161
+ public function getOptionValue() {
162
+ $blog_title = get_bloginfo( 'name' );
163
+ $defaultVals = array(
164
+ 'version' => YKSEME_VERSION_CURRENT,
165
+ 'api-key' => '',
166
+ 'flavor' => '1',
167
+ 'debug' => '0',
168
+ 'optin' => 'true',
169
+ 'single-optin-message' => __('Thank You for subscribing!', 'yikes-inc-easy-mailchimp-extender'),
170
+ 'double-optin-message' => __('Thank You for subscribing! Check your email for the confirmation message.', 'yikes-inc-easy-mailchimp-extender'),
171
+ 'optIn-checkbox' => 'hide',
172
+ 'yks-mailchimp-optIn-default-list' => 'select_list',
173
+ 'yks-mailchimp-optin-checkbox-text' => 'Add me to the ' . $blog_title . ' mailing list',
174
+ 'recaptcha-setting' => '0',
175
+ 'yks-mailchimp-required-text' => '0',
176
+ 'recaptcha-api-key' => '',
177
+ 'recaptcha-private-api-key' => '',
178
+ 'ssl_verify_peer' => 'true',
179
+ 'lists' => array()
180
+ );
181
+ $ov = get_option(YKSEME_OPTION, $defaultVals);
182
+ $this->optionVal = $ov;
183
+ return $ov;
184
+ }
185
+
186
+ // run our update check to make sure the user is up to date
187
+ private function runUpdateCheck() {
188
+ if( ! isset( $this->optionVal['version'] ) || $this->optionVal['version'] < YKSEME_VERSION_CURRENT ) {
189
+ $this->runUpdateTasks();
190
+ }
191
+ }
192
+
193
+
194
+ /***** FUNCTIONS
195
+ ****************************************************************************************************/
196
+ // check if were on the login page
197
+ function is_login_page() {
198
+ return in_array( $GLOBALS['pagenow'] , array( 'wp-login.php', 'wp-register.php' ) );
199
+ }
200
+
201
+ // create a slug like string, given some text (ie: this-is-the-name)
202
+ public function slugify( $text ) {
203
+ // replace non letter or digits by -
204
+ $text = preg_replace( '~[^\\pL\d]+~u', '-', $text );
205
+ // trim
206
+ $text = trim( $text, '-' );
207
+ // transliterate
208
+ $text = iconv( 'utf-8' , 'us-ascii//TRANSLIT' , $text );
209
+ // lowercase
210
+ $text = strtolower( $text);
211
+ // remove unwanted characters
212
+ $text = preg_replace( '~[^-\w]+~' , '' , $text );
213
+ if(empty($text))
214
+ {
215
+ return 'n-a';
216
+ }
217
+ return $text;
218
+ }
219
+
220
+ // create an array for any fields left blank
221
+ // not sure if still needed (CHECK)
222
+ public function getBlankFieldsArray( $lid='' ) {
223
+ $fields = array();
224
+ // Add Field
225
+ $name = $this->slugify('Email Address'.'-'.'EMAIL');
226
+ $addField = array(
227
+ 'id' => $lid.'-'.$name,
228
+ 'name' => $lid.'-'.$name,
229
+ 'merge' => 'EMAIL',
230
+ 'label' => 'Email Address',
231
+ 'require' => '1',
232
+ 'active' => '1',
233
+ 'locked' => '1',
234
+ 'sort' => '1',
235
+ 'type' => 'email',
236
+ 'help' => '',
237
+ 'defalt' => '',
238
+ 'choices' => ''
239
+ );
240
+ $fields[$addField['id']] = $addField;
241
+ // return our fields
242
+ return $fields;
243
+ }
244
+
245
+ // Create an array of data for imported fields based on the Merge Varaibles passed back from MailChimp
246
+ public function getImportedFieldsArray( $lid, $mv ) {
247
+ if( empty( $mv ) ) {
248
+ return false;
249
+ } else {
250
+ $fields = array();
251
+ $num = 1;
252
+ foreach($mv['data'][0]['merge_vars'] as $field) {
253
+ // Add Field
254
+ $name = $this->slugify(isset($field['label']).'-'.$field['tag']);
255
+ $addField = array(
256
+ 'id' => $lid.'-'.$name,
257
+ 'name' => $lid.$field['tag'],
258
+ 'merge' => $field['tag'],
259
+ 'label' => $field['name'],
260
+ 'require' => $field['req'],
261
+ 'active' => '1',
262
+ 'locked' => '1',
263
+ 'sort' => $field['order'],
264
+ 'type' => $field['field_type'],
265
+ 'help' => $field['helptext'],
266
+ 'default' => $field['default'],
267
+ 'choices' => (isset($field['choices']) ? $field['choices'] : '')
268
+ );
269
+ $fields[$addField['id']] = $addField;
270
+ $num++;
271
+ }
272
+ return $fields;
273
+ }
274
+ }
275
+
276
+ // Get the current users browser information
277
+ // Used specifically on the lists page
278
+ public function getBrowser() {
279
+ $u_agent = $_SERVER['HTTP_USER_AGENT'];
280
+ $bname = 'Unknown';
281
+ $platform = 'Unknown';
282
+ $version = "";
283
+ //First get the platform?
284
+ if( preg_match( '/linux/i', $u_agent ) ) {
285
+ $platform = 'Linux';
286
+ } elseif( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
287
+ $platform = 'Mac';
288
+ } elseif( preg_match( '/windows|win32/i' , $u_agent ) ) {
289
+ $platform = 'Windows';
290
+ }
291
+
292
+ // Next get the name of the useragent yes seperately and for good reason
293
+ if( preg_match( '/MSIE/i' , $u_agent ) && ! preg_match( '/Opera/i' , $u_agent ) ) {
294
+ $bname = 'Internet Explorer';
295
+ $ub = "MSIE";
296
+ } elseif( preg_match( '/Firefox/i' , $u_agent ) ) {
297
+ $bname = 'Mozilla Firefox';
298
+ $ub = "Firefox";
299
+ } elseif( preg_match( '/Chrome/i' , $u_agent ) ) {
300
+ $bname = 'Google Chrome';
301
+ $ub = "Chrome";
302
+ } elseif( preg_match( '/Safari/i' , $u_agent ) ) {
303
+ $bname = 'Apple Safari';
304
+ $ub = "Safari";
305
+ } elseif( preg_match( '/Opera/i' , $u_agent ) ) {
306
+ $bname = 'Opera';
307
+ $ub = "Opera";
308
+ } elseif( preg_match( '/Netscape/i' , $u_agent ) ) {
309
+ $bname = 'Netscape';
310
+ $ub = "Netscape";
311
+ }
312
+
313
+ // finally get the correct version number
314
+ $known = array('Version', $ub, 'other');
315
+ $pattern = '#(?<browser>' . join( '|' , $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
316
+ if( ! preg_match_all( $pattern, $u_agent, $matches) ) {
317
+ // we have no matching number just continue
318
+ }
319
+
320
+ // see how many we have
321
+ $i = count($matches['browser']);
322
+ if( $i != 1 ) {
323
+ //we will have two since we are not using 'other' argument yet
324
+ //see if version is before or after the name
325
+ if( strripos( $u_agent ,"Version" ) < strripos( $u_agent , $ub ) ) {
326
+ $version= $matches['version'][0];
327
+ } else {
328
+ $version= $matches['version'][1];
329
+ }
330
+ } else {
331
+ $version= $matches['version'][0];
332
+ }
333
+
334
+ // check if we have a number
335
+ if( $version==null || $version=="" ) { $version="?"; }
336
+
337
+ return array(
338
+ 'userAgent' => $u_agent,
339
+ 'name' => $bname,
340
+ 'version' => $version,
341
+ 'platform' => $platform,
342
+ 'pattern' => $pattern
343
+ );
344
+ }
345
+
346
+ /***** Encryption/Decryption
347
+ ****** API Keys (MailChimp and reCaptcha)
348
+ *****************************************************************************************************/
349
+ function yikes_mc_encryptIt( $q ) {
350
+ $cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
351
+ $qEncoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
352
+ return( $qEncoded );
353
+ }
354
+
355
+ function yikes_mc_decryptIt( $q ) {
356
+ $cryptKey = 'qJB0rGtIn5UB1xG03efyCp';
357
+ $qDecoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
358
+ return( $qDecoded );
359
+ }
360
+
361
+
362
+ /***** CONFIGURATION
363
+ ****************************************************************************************************/
364
+ // Update our plug in options
365
+ // Runs when the user updates the settings page with new values
366
+ public function updateOptions( $p ) {
367
+ if( ! empty( $p['form_data'] ) ) {
368
+ parse_str( $p['form_data'] , $fd );
369
+ // checking if the entered API key has copied out of the value field?
370
+ if ( strlen( $fd['yks-mailchimp-api-key'] ) > 45 ) {
371
+ $apiKey = $this->yikes_mc_decryptIt($fd['yks-mailchimp-api-key']);
372
+ } else {
373
+ $apiKey = $fd['yks-mailchimp-api-key'];
374
+ }
375
+ // check if the newly input API key differs from the previously stored one
376
+ if ( $apiKey == $this->optionVal['api-key'] ) {
377
+ $this->optionVal['api-key'] = $apiKey;
378
+ $this->optionVal['flavor'] = $fd['yks-mailchimp-flavor'];
379
+ $this->optionVal['optin'] = $fd['yks-mailchimp-optin'];
380
+ $this->optionVal['single-optin-message'] = stripslashes($fd['single-optin-message']);
381
+ $this->optionVal['double-optin-message'] = stripslashes($fd['double-optin-message']);
382
+ $this->optionVal['optIn-checkbox'] = $fd['yks-mailchimp-optIn-checkbox'];
383
+ $this->optionVal['yks-mailchimp-optIn-default-list'] = isset($fd['yks-mailchimp-optIn-default-list']) ? $fd['yks-mailchimp-optIn-default-list'] : null; // if its set, else set to null <- fixes save form settings bug
384
+ $this->optionVal['yks-mailchimp-optin-checkbox-text'] = stripslashes($fd['yks-mailchimp-optin-checkbox-text']);
385
+ $this->optionVal['yks-mailchimp-jquery-datepicker'] = isset( $fd['yks-mailchimp-jquery-datepicker'] ) ? '1' : '';
386
+ $this->optionVal['yks-mailchimp-required-text'] = $fd['yks-mailchimp-required-text'];
387
+ update_option('api_validation', 'valid_api_key');
388
+ return update_option( YKSEME_OPTION , $this->optionVal );
389
+ } else {
390
+ $this->optionVal['api-key'] = $apiKey;
391
+ $this->optionVal['flavor'] = $fd['yks-mailchimp-flavor'];
392
+ $this->optionVal['optin'] = $fd['yks-mailchimp-optin'];
393
+ $this->optionVal['single-optin-message'] = stripslashes($fd['single-optin-message']);
394
+ $this->optionVal['double-optin-message'] = stripslashes($fd['double-optin-message']);
395
+ $this->optionVal['optIn-checkbox'] = $fd['yks-mailchimp-optIn-checkbox'];
396
+ $this->optionVal['yks-mailchimp-optIn-default-list'] = isset($fd['yks-mailchimp-optIn-default-list']) ? $fd['yks-mailchimp-optIn-default-list'] : null; // if its set, else set to null <- fixes save form settings bug
397
+ $this->optionVal['yks-mailchimp-optin-checkbox-text'] = stripslashes($fd['yks-mailchimp-optin-checkbox-text']);
398
+ $this->optionVal['yks-mailchimp-jquery-datepicker'] = isset( $fd['yks-mailchimp-jquery-datepicker'] ) ? '1' : '';
399
+ $this->optionVal['yks-mailchimp-required-text'] = $fd['yks-mailchimp-required-text'];
400
+ update_option('api_validation', 'valid_api_key');
401
+ // if the new API key differs from the old one
402
+ // we need to unset the previously set up widgets
403
+ // 1 - empty the lists array of imported lists
404
+ $this->optionVal['lists'] = array();
405
+ // 2 - unset our previously set up widgets
406
+ update_option( 'widget_yikes_mc_widget' , '' );
407
+ return update_option( YKSEME_OPTION , $this->optionVal );
408
+ }
409
+ }
410
+ return false;
411
+ }
412
+
413
+ // Update our recaptcha options
414
+ // Runs when the user updates the recaptcha settings page with new values
415
+ public function updateRecaptchaOptions( $p ) {
416
+ if( !empty( $p['form_data'] ) ) {
417
+ parse_str($p['form_data'], $fd);
418
+ $this->optionVal['recaptcha-setting'] = isset($fd['yks-mailchimp-recaptcha-setting']) ? $fd['yks-mailchimp-recaptcha-setting'] : '0';
419
+ $this->optionVal['recaptcha-api-key'] = isset($fd['yks-mailchimp-recaptcha-api-key']) ? $fd['yks-mailchimp-recaptcha-api-key'] : '';
420
+ $this->optionVal['recaptcha-private-api-key'] = isset($fd['yks-mailchimp-recaptcha-private-api-key']) ? $fd['yks-mailchimp-recaptcha-private-api-key'] : '';
421
+ return update_option( YKSEME_OPTION , $this->optionVal );
422
+ }
423
+ return false;
424
+ }
425
+
426
+ // Update our debug plugin options
427
+ // Runs when the user updates the debug settings page with new values
428
+ public function updateDebugOptions( $p ) {
429
+ if( !empty( $p['form_data'] ) ) {
430
+ parse_str($p['form_data'], $fd);
431
+ $this->optionVal['debug'] = $fd['yks-mailchimp-debug'];
432
+ $this->optionVal['ssl_verify_peer'] = $fd['yks-mailchimp-ssl-verify-peer'];
433
+ return update_option(YKSEME_OPTION, $this->optionVal);
434
+ }
435
+ return false;
436
+ }
437
+
438
+ // Update the API Key
439
+ public function updateApiKey( $k ) {
440
+ $this->optionVal['api-key'] = $k;
441
+ return update_option( YKSEME_OPTION , $this->optionVal );
442
+ }
443
+
444
+ // Update the version number
445
+ public function updateVersion( $k ) {
446
+ $this->optionVal['version'] = $k;
447
+ return update_option( YKSEME_OPTION , $this->optionVal );
448
+ }
449
+
450
+ /***** LIST ACTIONS
451
+ ****************************************************************************************************/
452
+ // Import a list from MailChimp and add it to the lists page
453
+ // Runs when user adds a list from the drop down on the list page
454
+ // Sends a call to MailChimp api to retrieve list data
455
+ public function addList( $lid='' , $name='' ) {
456
+
457
+ if( $lid == '' || isset( $this->optionVal['lists'][$lid] ) ) return false;
458
+
459
+ $api = new Mailchimp($this->optionVal['api-key']);
460
+
461
+ $mv = $api->call('lists/merge-vars', array(
462
+ 'id' => array($lid)
463
+ )
464
+ );
465
+
466
+ // if merge variables are found
467
+ if( $mv) {
468
+ $list = array(
469
+ 'id' => $lid,
470
+ 'list-id' => $lid,
471
+ 'name' => $name,
472
+ 'fields' => $this->getImportedFieldsArray( $lid , $mv )
473
+ );
474
+
475
+ $this->optionVal['lists'][$list['id']] = $list;
476
+
477
+ // store newly retreived list array in imported_list global option
478
+ update_option( 'imported_lists' , $this->optionVal['lists'] );
479
+
480
+ if( update_option( YKSEME_OPTION, $this->optionVal ) ) {
481
+ return $this->generateListContainers( array( $list ) );
482
+ }
483
+ }
484
+
485
+ return false;
486
+ }
487
+
488
+
489
+ /* Get Interest Groups */
490
+ // Send request to MailChimp API to retreive interest groups associated to a specific list
491
+ public function getInterestGroups( $list_id ) {
492
+ // store our API key
493
+ $api = new Mailchimp($this->optionVal['api-key']);
494
+
495
+ // setup switch for div/table
496
+ $yikes_mc_flavor = $this->optionVal['flavor'];
497
+
498
+ // try the request, and catch any errors
499
+ try {
500
+
501
+ $interest_groups = $api->call('lists/interest-groupings', array( 'id' => $list_id ));
502
+
503
+ // if the list has an interest group
504
+ if ($interest_groups) {
505
+ // json_encode the data, and store it in optionVal['interest-groups']
506
+ $this->optionVal['interest-groups'] = json_encode($interest_groups);
507
+
508
+ $num = 0;
509
+
510
+ switch( $yikes_mc_flavor ) {
511
+
512
+ // table flavor
513
+ case '0':
514
+
515
+ // loop over each interest group returned
516
+ foreach($interest_groups as $interest_group) {
517
+
518
+ ?> <!-- pass interest group data in a hidden form field , required to pass the data back to the correct interest-group -->
519
+ <input type='hidden' name='interest-group-data' value='<?php echo $this->optionVal["interest-groups"]; ?>' /> <?php
520
+
521
+ // get form type
522
+ $list_form_type = $interest_group['form_field'];
523
+ $interestGroupID = $interest_group['id'];
524
+
525
+ switch( $list_form_type ) {
526
+
527
+ // checkbox interest groups
528
+ case 'checkboxes':
529
+ echo '<tr class="yks_mc_table_interest_group_holder yks_mc_table_checkbox_holder">';
530
+ echo '<td class="yks_mc_table_td">';
531
+ // display the label
532
+ echo '<label class="prompt yks_table_label yks-mailchimpFormTableRowLabel yks-mailchimpFormTableRowLabel-required font-secondary label-text">'.stripslashes( $interest_group['name'] ).'</label>'; // display the interest group name from MailChimp
533
+ foreach ($interest_group['groups'] as $singleGrouping) {
534
+ $checkboxValue = $interest_group['name'];
535
+ echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="checkbox" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_checkbox" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'[]" value="'.$singleGrouping['name'].'"><span>'.$singleGrouping['name'].'</span></label>';
536
+ }
537
+ echo '</td>';
538
+ echo '</tr>';
539
+ break;
540
+
541
+ // radiobuttons interest groups
542
+ case 'radio':
543
+ echo '<tr class="yks_mc_table_interest_group_holder yks_mc_table_radio_holder">';
544
+ echo '<td class="yks_mc_interest_radio_button_holder yks_mc_table_td">';
545
+ // display the label
546
+ echo stripslashes($user_set_interest_group_label);
547
+ foreach ($interest_group['groups'] as $singleGrouping) {
548
+ $radioValue = $interest_group['name'];
549
+ echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="radio" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_radio" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" value="'.$singleGrouping['name'].'"><span>'.stripslashes($singleGrouping['name']).'</span></label>';
550
+ }
551
+ echo '</td>';
552
+ echo '</tr>';
553
+ break;
554
+
555
+ // drop down interest groups
556
+ case 'dropdown':
557
+ echo '<tr class="yks_mc_table_interest_group_holder yks_mc_table_dropdown_holder">';
558
+ echo '<td class="yks_mc_table_dropdown_interest_group_holder yks_mc_table_td">';
559
+ // display the label
560
+ echo stripslashes($user_set_interest_group_label);
561
+ echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
562
+ foreach ($interest_group['groups'] as $singleGrouping) {
563
+ $dropDownValue = $interest_group['name'];
564
+ echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
565
+ }
566
+ echo '</select>';
567
+ echo '</td>';
568
+ echo '</tr>';
569
+ break;
570
+
571
+ // hidden dropdown interest groups
572
+ case 'hidden':
573
+ echo '<div class="yks_mc_interest_group_holder" style="display:none;">';
574
+ echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
575
+ foreach ($interest_group['groups'] as $singleGrouping) {
576
+ $dropDownValue = $interest_group['name'];
577
+ echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
578
+ }
579
+ echo '</select>';
580
+ echo '</div>';
581
+ break; //break dropdown interest group type
582
+
583
+ }
584
+
585
+ $num++;
586
+ }
587
+
588
+ break; // break case: 0;
589
+
590
+ // div flavor
591
+ case '1':
592
+ // loop over each interest group returned
593
+ foreach($interest_groups as $interest_group) {
594
+
595
+ // get form type
596
+ $list_form_type = $interest_group['form_field'];
597
+ $interestGroupID = $interest_group['id'];
598
+ if ( $list_form_type == 'hidden' ) { $hidden = 'style="display:none;"'; } else { $hidden = ''; }
599
+
600
+ echo '<b class="yks_mc_interest_group_text" ' . $hidden . '>'.$interest_group['name'].'</b>';
601
+ ?>
602
+
603
+ <input type='hidden' name='interest-group-data' value='<?php echo $this->optionVal["interest-groups"]; ?>' />
604
+
605
+ <?php
606
+
607
+ switch($list_form_type) {
608
+
609
+ // checkbox interest groups
610
+ case 'checkboxes':
611
+ echo '<div class="yks_mc_interest_group_holder">';
612
+ foreach ($interest_group['groups'] as $singleGrouping) {
613
+ $checkboxValue = $interest_group['name'];
614
+ echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="checkbox" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_checkbox" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'[]" value="'.$singleGrouping['name'].'"><span></span>'.stripslashes($singleGrouping['name']).'</label>';
615
+ }
616
+ echo '</div>';
617
+ break; // break checkbox interest group type
618
+
619
+ // radiobuttons interest groups
620
+ case 'radio':
621
+ echo '<div class="yks_mc_interest_group_holder">';
622
+ echo '<div class="yks_mc_interest_radio_button_holder">';
623
+ echo stripslashes($user_set_interest_group_label);
624
+ foreach ($interest_group['groups'] as $singleGrouping) {
625
+ $radioValue = $interest_group['name'];
626
+ echo '<label class="yks_mc_interest_group_label" for="'.$singleGrouping['name'].'"><input type="radio" id="'.$singleGrouping['name'].'" class="yikes_mc_interest_group_radio" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" value="'.$singleGrouping['name'].'"><span></span>'.stripslashes($singleGrouping['name']).'</label>';
627
+ }
628
+ echo '</div>';
629
+ echo '</div>';
630
+ break; //break radio buttons interest group type
631
+
632
+ // drop down interest groups
633
+ case 'dropdown':
634
+ echo '<div class="yks_mc_interest_group_holder">';
635
+ echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
636
+ foreach ($interest_group['groups'] as $singleGrouping) {
637
+ $dropDownValue = $interest_group['name'];
638
+ echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
639
+ }
640
+ echo '</select>';
641
+ echo '</div>';
642
+ break; //break dropdown interest group type
643
+
644
+ // hidden dropdown interest groups
645
+ case 'hidden':
646
+ echo '<div class="yks_mc_interest_group_holder" style="display:none;">';
647
+ // display the label
648
+ echo stripslashes($user_set_interest_group_label);
649
+ echo '<select id="yks_mc_interest_dropdown" name="'.$interest_group['form_field'].'-'.$interest_group['id'].'" class="yks_mc_interest_group_select">';
650
+ foreach ($interest_group['groups'] as $singleGrouping) {
651
+ $dropDownValue = $interest_group['name'];
652
+ echo '<option value="'.$singleGrouping['name'].'" name="'.$dropDownValue.'">'.$singleGrouping['name'].'</option>';
653
+ }
654
+ echo '</select>';
655
+ echo '</div>';
656
+ break; //break dropdown interest group type
657
+
658
+ }
659
+ $num++;
660
+ }
661
+ break; //break case: 1;
662
+
663
+ }
664
+ }
665
+ // catch any errors if thrown
666
+ } catch( Exception $e ) {
667
+ if ( $this->optionVal['debug'] == 1 ) {
668
+ $this->writeErrorToErrorLog( $e );
669
+ }
670
+ return;
671
+ }
672
+ return false;
673
+ } // end getInterestGroups();
674
+
675
+ // Send a call to the MailChimp API to retreive all lists on the account
676
+ public function getLists() {
677
+ $api = new Mailchimp($this->optionVal['api-key']);
678
+ $lists = $this->getListsData();
679
+ $listArr = (!isset($listArr) ? $this->optionVal['lists'] : $listArr);
680
+ $theusedlist = array();
681
+ if( count( $listArr ) > 0 ) {
682
+ foreach( $listArr as $list ) {
683
+ $theusedlist[] = $list['id'];
684
+ }
685
+ }
686
+ if( $lists ) { // if list data is returned
687
+ echo "<select id='yks-list-select' name='yks-list-select'>";
688
+ echo "<option value=''> Select List</option>";
689
+
690
+ foreach ( $lists as $lkey => $lvalue ) {
691
+ if ( !in_array( $lkey , $theusedlist ) ) {
692
+ echo "<option value='".$lkey."'>".$lvalue."</option>";
693
+ }
694
+ }
695
+
696
+ echo "</select>";
697
+ echo '<input type="submit" name="submit" class="button-primary" id="yks-submit-list-add" value="' .__ ("Create a Form For This List" , "yikes-inc-easy-mailchimp-extender" ) .'" >';
698
+
699
+ // not currently possible to create new lists via API
700
+ // echo '&nbsp;<a href="#" onclick="return false;" class="button-secondary"><span class="dashicons dashicons-plus" style="line-height:1.3"></span> Create New List</a>';
701
+
702
+ } else {
703
+ echo '<strong>' . __('Error - No Lists Found On Your Account. Please create at least one list on your MailChimp account.' , 'yikes-inc-easy-mailchimp-extender' ) . '</strong>';
704
+ }
705
+ return false;
706
+ } // end getLists();
707
+
708
+ // Get lists for the settings page
709
+ // Used for default subscription list
710
+ public function getOptionsLists() {
711
+ $api = new Mailchimp($this->optionVal['api-key']);
712
+ $lists = $this->getListsData();
713
+ $listArr = (!isset($listArr) ? $this->optionVal['lists'] : $listArr);
714
+ if( $lists ) {
715
+ echo "<select id='yks-mailchimp-optIn-default-list' name='yks-mailchimp-optIn-default-list'>";
716
+ echo "<option value='select_list'> Select List</option>";
717
+ foreach ( $lists as $lkey => $list_name) {
718
+ echo "<option ".selected( isset($this->optionVal['yks-mailchimp-optIn-default-list']) ? $this->optionVal['yks-mailchimp-optIn-default-list'] : "select_list", $lkey )." value='".$lkey."'>".$list_name."</option>";
719
+ }
720
+ echo "</select>";
721
+ }
722
+ return false;
723
+ } // end getOptionsLists()
724
+
725
+ // Send a call to MailChimp API to get the data associated with a specific list (in this instance: the fields, and the subscriber count)
726
+ public function getListsData() {
727
+ $api = new Mailchimp($this->optionVal['api-key']);
728
+ $lists = $api->call('lists/list', array( 'limit' => 100 ));
729
+ if( $lists ) {
730
+ foreach ( $lists['data'] as $list ) {
731
+ $theListItems[$list['id']] = $list['name'];
732
+ $theListItems['subscriber-count']['subscriber-count-'.$list['id']] = $list['stats']['member_count'];
733
+ }
734
+ }
735
+
736
+ if ( isset ( $theListItems ) ) {
737
+ return $theListItems;
738
+ }
739
+ } // end getListsData();
740
+
741
+ /*
742
+ Send a call to MailChimp API to get the data associated with a specific list (in this instance: the fields, and the subscriber count)
743
+ @since v5.2
744
+ */
745
+ public function getInterstGroupInfo( $list_id ) {
746
+ $api = new Mailchimp($this->optionVal['api-key']);
747
+ try {
748
+ $interest_groups = $api->call('lists/interest-groupings', array( 'id' => $list_id ));
749
+ return $interest_groups;
750
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
751
+ return $e->getMessage();
752
+ // write our error to the error log, when advanced debug is enabled
753
+ if ( $this->optionVal['debug'] == 1 ) {
754
+ $this->writeErrorToErrorLog( $e );
755
+ }
756
+ die();
757
+ }
758
+ }
759
+
760
+ /*
761
+ Get Interest Group Response
762
+ @sinve v5.2
763
+ */
764
+ public function getListInterestGroups( $list_id ) {
765
+ $interest_groups = $this->getInterstGroupInfo( $list_id );
766
+ if ( is_array( $interest_groups ) ) {
767
+ foreach ( $interest_groups as $interest_group ) {
768
+ $interest_group_id = $interest_group['id'];
769
+ $interest_group_type = $interest_group['form_field'];
770
+ $interest_group_name = $interest_group['name'];
771
+ echo '<div class="yks-mailchimp-fields-list-row" alt="' . $interest_group_id . '">
772
+
773
+ <span class="yks-mc-interest-group-delete" title="Delete ' . $interest_group_name . '">
774
+ <span class="dashicons dashicons-no-alt"></span>
775
+ </span>
776
+
777
+ <span class="yks-mc-interest-group-edit" title="Edit ' . $interest_group_name . '">
778
+ <span class="dashicons dashicons-edit"></span>
779
+ </span>
780
+
781
+ <span class="yks-mc-interest-group-name">' . $interest_group_name . '</span>
782
+
783
+ <span class="yks-mc-interest-group-type">' . $interest_group_type . '</span>
784
+
785
+ </div>';
786
+ }
787
+ } else {
788
+ ?>
789
+ <style>
790
+ #yks-mailchimp-interest-groups-container_<?php echo $list_id; ?> {
791
+ background-color: transparent !important;
792
+ border: none !important;
793
+ }
794
+ </style>
795
+ <span class="no-interest-groups-found"><em><?php echo __( 'No interest groups have been setup for this form yet' , 'yikes-inc-easy-mailchimp-extender' ); ?></em></span>
796
+ <?php
797
+ }
798
+ } // end getListInterestGroups();
799
+
800
+ /*
801
+ Get Specific Interest Group Response
802
+ @since v5.2
803
+ */
804
+ public function getSpecificInterestGroupData( $list_id , $mc_interest_group_id ) {
805
+ // get interest group info,
806
+ $interest_groups = $this->getInterstGroupInfo( $list_id );
807
+ if ( $interest_groups ) {
808
+ foreach ( $interest_groups as $key ) {
809
+ if ( $key['id'] == $mc_interest_group_id ) {
810
+ echo json_encode( $key );
811
+ }
812
+ }
813
+ } else {
814
+ echo 'error retreiving group information...please try again';
815
+ }
816
+ }
817
+
818
+ // Send a call to MailChimp API to get the data associated with a specific list (in this instance: the fields, and the subscriber count)
819
+ public function getListsForStats() {
820
+ $api = new Mailchimp($this->optionVal['api-key']);
821
+ $lists = $this->getListsData();
822
+ $listArr = (!isset($listArr) ? $this->optionVal['lists'] : $listArr);
823
+ $theusedlist = array();
824
+ if( count( $listArr ) > 0 ) {
825
+ foreach( $listArr as $list ) {
826
+ $theusedlist[] = $list['id'];
827
+ }
828
+ }
829
+ if( $lists ) {
830
+ // Drop Down to switch form stats
831
+ echo '<h3>Select list to view stats</h3>';
832
+ echo '<div class="list_container_for_stats">';
833
+ echo "<a alt='' href='#' class='stats_list_name' onclick='return false;'><input type='button' class='asbestos-flat-button active_button' value='".__( 'All Lists' , 'yikes-inc-easy-mailchimp-extender')."'></a>";
834
+ foreach ($lists as $lkey => $lvalue) {
835
+ if ( is_array($lvalue) ) {
836
+ continue;
837
+ } else {
838
+ // if ( is_array( $lvalue ) ) { $lvalue = '<em style="color:rgba(245, 79, 79, 0.74);">Error</em>'; } else { $lvalue = $lvalue; }
839
+ echo "<a alt='".$lkey."' href='#' class='stats_list_name' onclick='return false;'><input type='button' class='asbestos-flat-button' value='".$lvalue."'></a>";
840
+ }
841
+ }
842
+ echo '</div>';
843
+ }
844
+ return false;
845
+ } // end getListsForStats()
846
+
847
+ // Sort through the returned data
848
+ public function sortList( $p ) {
849
+ if( empty( $p['update_string'] ) || empty( $p['list_id'] ) ) {
850
+ return false;
851
+ } else {
852
+ // Setup fields
853
+ $a = explode( ';' , $p['update_string'] );
854
+ if( $a !== false ) {
855
+ foreach( $a as $f ) {
856
+ $d = explode( ':' , $f );
857
+ $this->optionVal['lists'][$p['list_id']]['fields'][$d[0]]['sort'] = $d[1];
858
+ }
859
+ }
860
+ uasort($this->optionVal['lists'][$p['list_id']]['fields'], array(&$this, 'sortListFields'));
861
+ return update_option(YKSEME_OPTION, $this->optionVal);
862
+ }
863
+ return false;
864
+ } // end sortList();
865
+
866
+ private function sortListfields( $a , $b ) {
867
+ $a = $a['sort'];
868
+ $b = $b['sort'];
869
+ if( $a == $b ) {
870
+ return 0;
871
+ }
872
+ return ( $a < $b ) ? -1 : 1;
873
+ } // end sortListfields();
874
+
875
+ // Update a single list on the lists page
876
+ // This function fires when the user clicks 'save settings' for a specific form on the lists page
877
+ public function updateList( $p ) {
878
+ if( !empty( $p['form_data'] ) ) {
879
+ parse_str($p['form_data'], $fd);
880
+ if( !empty( $fd['yks-mailchimp-unique-id'] ) ) {
881
+ $num = 1;
882
+ foreach( $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'] as $k => $v ) {
883
+ // Only proceed if the field is not locked
884
+ if( $v['require'] == 0 ) {
885
+ // Make sure this field was included in the update
886
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['active'] = (isset($fd[$v['name']]) ? '1' : '0');
887
+ }
888
+
889
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['placeholder-'.$fd['yks-mailchimp-unique-id'].'-'.$num] = $fd['placeholder-'.$fd['yks-mailchimp-unique-id'].'-'.$num];
890
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['custom-field-class-'.$fd['yks-mailchimp-unique-id'].'-'.$num] = $fd['custom-field-class-'.$fd['yks-mailchimp-unique-id'].'-'.$num];
891
+ $num++;
892
+
893
+ // redirect checkbox
894
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['yks_mailchimp_redirect_'.$fd['yks-mailchimp-unique-id']] = (isset($fd['yks_mailchimp_redirect_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '');
895
+
896
+ // send welcome checkbox
897
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['yks_mailchimp_send_welcome_'.$fd['yks-mailchimp-unique-id']] = (isset($fd['yks_mailchimp_send_welcome_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '');
898
+
899
+ if(isset($fd['yks_mailchimp_redirect_'.$fd['yks-mailchimp-unique-id']])) {
900
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['fields'][$k]['page_id_'.$fd['yks-mailchimp-unique-id']] = $fd['page_id_'.$fd['yks-mailchimp-unique-id']];
901
+ }
902
+
903
+ // custom style setting
904
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['active'] = (isset($fd['yks_mailchimp_custom_styles_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '0');
905
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_template']['active'] = (isset($fd['yks_mailchimp_custom_template_'.$fd['yks-mailchimp-unique-id']]) ? '1' : '0');
906
+ }
907
+
908
+ // save the selected form template, if custom template was set
909
+ if ( $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_template']['active'] == 1 ) {
910
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_template']['template_file'] = $fd['yks-mc-template-file-selection'];
911
+ }
912
+
913
+ // save the color styles
914
+ if ( $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['active'] == 1 ) {
915
+
916
+ // save the custom styles colors here!
917
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_submit_button_color'] = $fd['yks-mc-submit-button-color'];
918
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_submit_button_text_color'] = $fd['yks-mc-submit-button-text-color'];
919
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_background_color'] = $fd['yks-mc-background-color'];
920
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_text_color'] = $fd['yks-mc-text-color'];
921
+
922
+ // if the form width is left blank,
923
+ // we'll just set it to 100%
924
+ if ( $fd['yks-mc-form-width'] != '' ) {
925
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_width'] = $fd['yks-mc-form-width'];
926
+ } else {
927
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_width'] = '100%';
928
+ }
929
+
930
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_alignment'] = $fd['yks-mc-form-alignment'];
931
+
932
+ $padding_matches = array();
933
+ $matching_array = array( 'px' , 'em' , 'rem' , '%' );
934
+
935
+ if ( preg_match( '/([0-9.]+)([^0-9]+)/', $fd['yks-mc-form-padding'], $padding_matches ) ) {
936
+ // $padding_explosion = preg_split( '/[a-zA-Z]/' , $fd['yks-mc-form-padding'] );
937
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding'] = $padding_matches[1];
938
+ if ( in_array( $padding_matches[2] , $matching_array ) ) {
939
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding_measurement'] = $padding_matches[2];
940
+ } else {
941
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding_measurement'] = 'px';
942
+ }
943
+ } else {
944
+ if ( trim( $fd['yks-mc-form-padding'] ) != '' ) {
945
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding'] = $fd['yks-mc-form-padding'];
946
+ } else {
947
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding'] = '0';
948
+ }
949
+ $this->optionVal['lists'][$fd['yks-mailchimp-unique-id']]['custom_styles']['yks_mc_form_padding_measurement'] = 'px';
950
+ }
951
+ }
952
+
953
+ return update_option(YKSEME_OPTION, $this->optionVal);
954
+ }
955
+ }
956
+ return false;
957
+ } // end updateList();
958
+
959
+ // Remove a list from the lists page
960
+ // Runs when a user clicks 'delete list' on the lists page
961
+ public function deleteList( $i=false ) {
962
+ if( $i == false ) {
963
+ return false;
964
+ } else {
965
+ unset( $this->optionVal['lists'][$i] );
966
+ update_option( 'imported_lists' , $this->optionVal['lists'] );
967
+ return update_option( YKSEME_OPTION , $this->optionVal );
968
+ }
969
+ } // end deleteList();
970
+
971
+ // Import a list to the lists page
972
+ // Runs when a user adds a list from the drop down on the lists page
973
+ public function importList( $i = false ) {
974
+ if( $i == false ) {
975
+ return false;
976
+ } else {
977
+ // create our variables
978
+ $lid = $this->optionVal['lists'][$i]['list-id'];
979
+ $name = $this->optionVal['lists'][$i]['name'];
980
+ $api = new Mailchimp($this->optionVal['api-key']);
981
+ $mv = $api->call('lists/merge-vars', array(
982
+ 'id' => array( $lid )
983
+ )
984
+ );
985
+ // if merge variables are returned
986
+ $mv = $this->getImportedFieldsArray($lid, $mv);
987
+ if( $mv ) {
988
+ // Save the new list
989
+ $this->optionVal['lists'][$i]['fields'] = $mv;
990
+ if( update_option( YKSEME_OPTION , $this->optionVal ) ) {
991
+ return $this->generateListContainers(array($this->optionVal['lists'][$i]));
992
+ }
993
+ }
994
+ }
995
+ return false;
996
+ } // end importList();
997
+
998
+ // reImport a list to the lists page
999
+ // Runs when a user adds a list from the drop down on the lists page
1000
+ public function reImportMergeVariables( $i = false ) {
1001
+ if( $i == false ) {
1002
+ return false;
1003
+ } else {
1004
+ // create our variables
1005
+ $lid = $this->optionVal['lists'][$i]['list-id'];
1006
+ $name = $this->optionVal['lists'][$i]['name'];
1007
+ $api = new Mailchimp($this->optionVal['api-key']);
1008
+ $mv = $api->call('lists/merge-vars', array(
1009
+ 'id' => array( $lid )
1010
+ )
1011
+ );
1012
+ // if merge variables are returned
1013
+ $mv = $this->getImportedFieldsArray($lid, $mv);
1014
+ if( $mv ) {
1015
+ // Save the new list
1016
+ $this->optionVal['lists'][$i]['fields'] = $mv;
1017
+ // update the list with the new fields
1018
+ if( update_option( YKSEME_OPTION , $this->optionVal ) ) {
1019
+ return $this->generateMergeVariableContainers(array($this->optionVal['lists'][$i]));
1020
+ }
1021
+ }
1022
+ }
1023
+ return false;
1024
+ } // end reImportMergeVariables();
1025
+
1026
+ // Make a call to the MailChimp API to retrieve all subscribers to a given list
1027
+ // Runs when the user clicks 'view' next to the subscriber count on the list page
1028
+ public function listAllSubscribers( $lid, $list_name ) {
1029
+ $api = new Mailchimp($this->optionVal['api-key']);
1030
+ $subscribers_list = $api->call('lists/members',
1031
+ array(
1032
+ 'id' => $lid,
1033
+ 'opts' => array(
1034
+ 'limit' => '100',
1035
+ 'sort_field' => 'optin_time',
1036
+ 'sort_dir' => 'DESC'
1037
+ )
1038
+ )
1039
+ );
1040
+ // if the subscriber count is greater than 0
1041
+ // display all subscribers in a table
1042
+ if( $subscribers_list['total'] > 0 ) { ?>
1043
+ <h2><?php echo $list_name; echo ' <span class="subscriber-count" style="font-size:11px;">(<span class="number">'.$subscribers_list['total'].'</span> '.__(" subscribers" , "yikes-inc-easy-mailchimp-extender").')</span>'; ?></h2>
1044
+ <p><?php _e( 'Click on a subscriber to see further information' , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
1045
+
1046
+ <table id="yikes-mailchimp-subscribers-table" class="yks-mailchimp-fields-list" style="width:100%;">
1047
+ <thead class="yikes-mailchimp-subscribers-table-head">
1048
+ <tr>
1049
+ <th width="50%"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1050
+ <th width="50%"><?php _e( 'Date Subscribed' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1051
+ </tr>
1052
+ </thead>
1053
+ <?php foreach ( $subscribers_list['data'] as $subscriber ) {
1054
+ $timeStamp = explode(' ', $subscriber['timestamp_opt'] );
1055
+ echo '<tr class="yks-mailchimp-subscribers-list-row" id="yks-mailchimp-subscribers-list-row">';
1056
+ echo '<td><a class="subscriber-mail-link" rel="'.$subscriber["email"].'" class="subscriberEmailAddress">'.$subscriber['email'].'</a></td>';
1057
+ // echo '<td>'.str_replace('-', ' ', date("M-jS-Y", strtotime($subscriber['timestamp_opt']))).'</td>';
1058
+ echo '<td>'.str_replace('-', ' ', date("M-jS-Y", strtotime($timeStamp[0]))).'</td></tr>';
1059
+ } ?>
1060
+ </table>
1061
+
1062
+ <!-- display a single user profile in this div -->
1063
+ <div id="individual_subscriber_information" style="display:none;"></div>
1064
+ <?php
1065
+ } else { // else display an error of sorts
1066
+ ?>
1067
+ <h2><?php echo $list_name; echo ' <span class="subscriber-count" style="font-size:11px;">(<span class="number">0</span> '.__(" subscribers" , "yikes-inc-easy-mailchimp-extender").')</span>'; ?></h2>
1068
+ <?php
1069
+ _e( "Sorry You Don't Currently Have Any Subscribers In This List!" , "yikes-inc-easy-mailchimp-extender" );
1070
+ }
1071
+ wp_die();
1072
+ } // end listAllSubscribers();
1073
+
1074
+ // Make a call to the MailChimp API to retrieve information about a specific user
1075
+ // Runs when the user clicks a subscribers email address
1076
+ public function getSubscriberInfo($lid, $email) {
1077
+ $api = new Mailchimp($this->optionVal['api-key']);
1078
+ $subscriber_info = $api->call('lists/member-info',
1079
+ array(
1080
+ 'id' => $lid,
1081
+ 'emails' => array(
1082
+ 0 => array(
1083
+ 'email' => $email,
1084
+ ),
1085
+ )
1086
+ )
1087
+ );
1088
+ // if the subscriber count is greater than 0
1089
+ // display all subscribers in a table
1090
+ if($subscriber_info) {
1091
+ // store user data into variables
1092
+ $subscriber_data = $subscriber_info['data'][0];
1093
+ $member_rating = $subscriber_data['member_rating'];
1094
+ // firstname/lastname data inside of new array
1095
+ $subscriber_data_merges = $subscriber_data['merges'];
1096
+ // seperate date+time
1097
+ $subscriber_data_info_changed = explode(' ' , $subscriber_data['info_changed']);
1098
+ $subscriber_data_timestamp_opt = explode (' ', $subscriber_data['timestamp_opt']);
1099
+ // store date+time in seperate variables
1100
+ $subscriber_data_info_changed_date = $subscriber_data_info_changed[0];
1101
+ $subscriber_data_info_changed_time = $subscriber_data_info_changed[1];
1102
+ // store optin-time+date in seperate variables
1103
+ $subscriber_data_info_optin_date = $subscriber_data_timestamp_opt[0];
1104
+ $subscriber_data_info_optin_time = $subscriber_data_timestamp_opt[1];
1105
+ // create our language variable dependent on what is set in MailChimp
1106
+ include_once('set_language.php');
1107
+
1108
+ // create star rating variable, based on returned member_rating value
1109
+ if(isset($member_rating)) {
1110
+ if ($member_rating == 1) {
1111
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1112
+ } else if ($member_rating == 2) {
1113
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1114
+ } else if ($member_rating == 3) {
1115
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1116
+ } else if ($member_rating == 4) {
1117
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1118
+ } else if ($member_rating == 5) {
1119
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
1120
+ }
1121
+ } ?>
1122
+
1123
+ <div class="yks-mc-subscriber-top">
1124
+ <span class="button-primary dashicons dashicons-arrow-left-alt2 yks-mc-subscriber-go-back"><?php _e( 'Back to Subscriber List' , 'yikes-inc-easy-mailchimp-extender' ); ?></span>
1125
+ <h2 class="yks-mc-subscriber-header"><?php _e( 'Subscriber Details' , 'yikes-inc-easy-mailchimp-extender' ); ?> </h2>
1126
+ <!-- display users email address -->
1127
+ <h3 id="yks-subscriber-info-email-address"><?php echo $subscriber_data['email']; ?></h3>
1128
+ <!-- display member star rating pulled from MailChimp -->
1129
+ <?php echo $member_rating_stars; ?>
1130
+ <!-- user optin time and date -->
1131
+ <span class="yks-subscriber-info-optin-data">
1132
+ <?php echo 'Subscribed on : '.date('m/d/Y',strtotime($subscriber_data_info_optin_date)); ?><?php echo ' at '.date('g:i A',strtotime($subscriber_data_info_optin_time)); ?>
1133
+ </span>
1134
+ </div>
1135
+
1136
+ <h2 class="yks-mc-subscriber-header"><?php _e( 'Overview' , 'yikes-inc-easy-mailchimp-extender' ); ?></h2>
1137
+ <div class="yks-mc-subscriber-overview">
1138
+
1139
+ <div class="yks-mc-subscriber-left-container">
1140
+
1141
+ <label class="yks-mc-overview-title"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1142
+ <p class="yks-mc-overview-info-value yks-mc-subscriber-firstName"><?php if(!empty($subscriber_data_merges['FNAME'])) { echo $subscriber_data_merges['FNAME']; } else { echo 'not provided'; } ?></p>
1143
+
1144
+ <label class="yks-mc-overview-title"><?php _e( 'Last Updated' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1145
+ <p class="yks-mc-overview-info-value"><?php echo date('m/d/Y',strtotime($subscriber_data_info_changed_date)); ?><?php echo ' at '.date('g:i A',strtotime($subscriber_data_info_changed_time)); ?></p>
1146
+
1147
+ <label class="yks-mc-overview-title"><?php _e( 'Preferred Email Type' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1148
+ <p class="yks-mc-overview-info-value"><?php if(!empty($subscriber_data['email_type'])) { echo $subscriber_data['email_type']; } else { echo 'No Preference.'; } ?></p>
1149
+
1150
+ </div>
1151
+
1152
+ <div class="yks-mc-subscriber-right-container">
1153
+
1154
+ <label class="yks-mc-overview-title"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1155
+ <p class="yks-mc-overview-info-value yks-mc-subscriber-lastName"><?php if(!empty($subscriber_data_merges['LNAME'])) { echo $subscriber_data_merges['LNAME']; } else { echo 'not provided'; } ?></p>
1156
+
1157
+ <label class="yks-mc-overview-title"><?php _e( 'Language' , 'yikes-inc-easy-mailchimp-extender' ); ?></label>
1158
+ <p class="yks-mc-overview-info-value"><?php echo $subscriber_data_language; ?></p>
1159
+
1160
+ </div>
1161
+
1162
+ </div>
1163
+
1164
+ <?php
1165
+ // build our segment array to determine if the user is subscribed to any segments
1166
+ $segment_count = array();
1167
+ // check if groupings data is set (for segment and interest groups)
1168
+ // this avoids an error being thrown when no segment/interest groups have been selected
1169
+ if ( isset( $subscriber_data_merges['GROUPINGS'] ) ) {
1170
+ foreach ($subscriber_data_merges['GROUPINGS'] as $group1) {
1171
+ foreach ($group1['groups'] as $group2) {
1172
+ if ($group2['interested'] == 1) {
1173
+ array_push($segment_count, $group2['name']);
1174
+ }
1175
+ }
1176
+ }
1177
+ }
1178
+ ?>
1179
+
1180
+ <h2 class="yks-mc-subscriber-header"><?php _e( 'Groups Subscribed To' , 'yikes-inc-easy-mailchimp-extender' ); ?></h2>
1181
+ <!-- display what groups/segments the subscriber is subscribed too -->
1182
+ <?php
1183
+ // if the user is subscribed to some segment
1184
+ if(!empty($segment_count)) {
1185
+ $groups_array = array(
1186
+ 'group_name' => '',
1187
+ 'segments' => array()
1188
+ );
1189
+ $num = 0;
1190
+ foreach ($subscriber_data_merges['GROUPINGS'] as $group_name) {
1191
+ $groups_array[$num]['group_name'] = $group_name['name'];
1192
+ foreach ($group_name['groups'] as $groupData ) {
1193
+ if ($groupData['interested'] == 1) {
1194
+ $groups_array[$num]['segments'] = $groupData['name'];
1195
+ }
1196
+ }
1197
+ $num++;
1198
+ }
1199
+ // build up the segments array that the user is subscribed too
1200
+ foreach ( $groups_array as $group_data ) {
1201
+ if(!empty($group_data['segments'])) { ?>
1202
+ <ul>
1203
+ <?php
1204
+ echo '<li style="font-size:16px; color:#333;">'.$group_data['group_name'].'</li>';
1205
+ if(!empty($group_data['group_name']) && isset($group_data['segments'])) {
1206
+ echo 'Segments : '; echo implode(' ,', array($group_data['segments']));
1207
+ } elseif (count($group_data['segments']) == 0) {
1208
+ echo 'n/a';
1209
+ }
1210
+ ?>
1211
+ </ul>
1212
+ <?php
1213
+ }
1214
+ }
1215
+ } else {
1216
+ // if there are no segments subscribed too
1217
+ // just print a message none specified
1218
+ echo 'none specified';
1219
+ }
1220
+
1221
+ // display the notes associated with a user if there are any returned
1222
+ if(!empty($subscriber_data['notes'])) { ?>
1223
+ <div class="yks-mc-subscriber-bottom">
1224
+ <h2 class="yks-mc-subscriber-header"><?php _e( 'Subscriber Notes' , 'yikes-inc-easy-mailchimp-extender' ); ?></h2>
1225
+ <?php
1226
+ foreach ( $subscriber_data['notes'] as $note ) {
1227
+ ?>
1228
+ <textarea style="width:100%; height:100px; resize:none;" id="yks-mc-subscriber-notes" disabled><?php echo $note['note']; ?></textarea>
1229
+ <span style="font-size:11px; opacity:.75;"><?php _e( 'Written by' , 'yikes-inc-easy-mailchimp-extender' ); ?>: <?php echo $note['created_by_name']; ?> // <?php _e( 'Created on' , 'yikes-inc-easy-mailchimp-extender' ); ?>: <?php echo date('m/d/Y',strtotime($note['created'])); ?></span>
1230
+ <?php
1231
+ }
1232
+ ?>
1233
+ </div>
1234
+ <?php
1235
+ }
1236
+ }
1237
+ wp_die();
1238
+ } // end getSubscriberInfo();
1239
+
1240
+ // Make a call to the MailChimp API to remove a specified user from a given list
1241
+ // Runs when the user clicks the 'X' next to a subscriber when viewing all subscribers on the lists page
1242
+ public function yks_removeSubscriber($lid, $user_email) {
1243
+ $api = new Mailchimp($this->optionVal['api-key']);
1244
+ $subscribers_list = $api->call('lists/unsubscribe', array(
1245
+ 'id' => $lid,
1246
+ 'email' => array(
1247
+ 'email' => $user_email
1248
+ )
1249
+ ));
1250
+ } // end yks_removeSubscriber();
1251
+
1252
+ /***** SCRIPTS/STYLES
1253
+ ****************************************************************************************************/
1254
+
1255
+ // enqueue dashboard styles
1256
+ public function addStyles() {
1257
+ include YKSEME_PATH . 'lib/inc/yks-mc-dashboard-styles.php';
1258
+ } // end addStyles();
1259
+
1260
+ // enqueue dashboard scripts
1261
+ public function addScripts() {
1262
+ include YKSEME_PATH . 'lib/inc/yks-mc-dashboard-scripts.php';
1263
+ } // end addScripts();
1264
+
1265
+ // enqueue our styles on the front end
1266
+ public function addStyles_frontend() {
1267
+ include YKSEME_PATH . 'lib/inc/yks-mc-frontend-styles.php';
1268
+ } // end addStyles_frontend();
1269
+
1270
+ // enqueue front end scripts
1271
+ public function addScripts_frontend() {
1272
+ // enqueue jQuery datepicker only when the user has specified to do so
1273
+ if( isset( $this->optionVal['yks-mailchimp-jquery-datepicker'] ) && $this->optionVal['yks-mailchimp-jquery-datepicker'] == '1' ) {
1274
+ wp_enqueue_script('jquery-ui-datepicker');
1275
+ }
1276
+ } // addScripts_frontend();
1277
+
1278
+ // redirect the user to the settings page on initial activation
1279
+ function yks_easy_mc_plugin_activation_redirect() {
1280
+ if (get_option('yks_easy_mc_plugin_do_activation_redirect', false)) {
1281
+ delete_option('yks_easy_mc_plugin_do_activation_redirect');
1282
+ // redirect to settings page
1283
+ wp_redirect(admin_url('/admin.php?page=yks-mailchimp-welcome'));
1284
+ }
1285
+ } // end yks_easy_mc_plugin_activation_redirect();
1286
+
1287
+
1288
+ /***** SHORTCODES
1289
+ ****************************************************************************************************/
1290
+ // Function to process the shortcode provided by the plugin
1291
+ // $p is the data associated with the shortcode (ie: form id and submit button text)
1292
+ public function processShortcode( $p ) {
1293
+ ob_start();
1294
+ // check if the list is set, to prevent errors from being thrown
1295
+ if ( isset( $this->optionVal['lists'][$p['id']] ) ) {
1296
+
1297
+ if( $this->optionVal['api-key'] != '' && ( is_array( $this->optionVal['lists'][$p['id']] ) && !empty( $this->optionVal['lists'][$p['id']] ) ) ) {
1298
+ // Setup this list
1299
+ $list = $this->optionVal['lists'][$p['id']];
1300
+ $submit_text = $p['submit_text'];
1301
+ // Which form are we on?
1302
+ if( !isset( $this->currentLists[$p['id']] ) ) {
1303
+ $this->currentLists[$p['id']] = 0;
1304
+ } else {
1305
+ $this->currentLists[$p['id']]++;
1306
+ }
1307
+ $listCt = $this->currentLists[$p['id']];
1308
+ // Add the count to the list vars
1309
+ $list['id'] = $listCt.'-'.$list['id'];
1310
+ if( count( $list['fields'] ) ) {
1311
+ foreach( $list['fields'] as $fieldId => $field ) {
1312
+ $list['fields'][$fieldId]['id'] = $listCt.'-'.$field['id'];
1313
+ }
1314
+ }
1315
+ // List form
1316
+ include YKSEME_PATH.'templates/shortcode_form.php';
1317
+ }
1318
+
1319
+ // if there is no api key entered, or it's an invalid api key
1320
+ } else if ( $this->optionVal['api-key'] == '' || get_option( 'api_validation' ) == 'invalid_api_key' ) {
1321
+ include YKSEME_PATH.'templates/shortcode_error_no_API_key.php';
1322
+ // else if the form was removed from the lists page
1323
+ } else {
1324
+ include YKSEME_PATH.'templates/shortcode_error_data.php';
1325
+ }
1326
+ $shortcode = ob_get_contents();
1327
+ ob_end_clean();
1328
+ return $shortcode;
1329
+ } // end processShortcode();
1330
+
1331
+ /* New Function to Display Subscriber Count for a given list */
1332
+ public function displaySubscriberCount( $p ) {
1333
+ ob_start();
1334
+ if( $this->optionVal['api-key'] != '' && ( is_array( $this->optionVal['lists'][$p['id']] ) && !empty( $this->optionVal['lists'][$p['id']] ) ) ) {
1335
+ // Setup this list
1336
+ $list = $this->optionVal['lists'][$p['id']];
1337
+ $mailChimp = new yksemeBase();
1338
+ $list = $mailChimp->getListsData();
1339
+ $list_id = key($list);
1340
+ // return just the subscriber count so the user can easily customize it!
1341
+ echo $list['subscriber-count']['subscriber-count-'.$list_id];
1342
+ } else if ( $this->optionVal['api-key'] == '' || get_option( 'api_validation' ) == 'invalid_api_key' ) {
1343
+ include YKSEME_PATH.'templates/shortcode_error_no_API_key.php';
1344
+ // else if the form was removed from the lists page
1345
+ } else {
1346
+ include YKSEME_PATH.'templates/shortcode_error_data.php';
1347
+ }
1348
+ $shortcode = ob_get_contents();
1349
+ ob_end_clean();
1350
+ return $shortcode;
1351
+ } // end displaySubscriberCount();
1352
+
1353
+ // Function to process the PHP snippet provided by the plugin
1354
+ // Again the data passed in, is the shortcode/php snippet paramaters (form id, submit button text)
1355
+ public function processSnippet($list=false, $submit_text) {
1356
+ $p = array(
1357
+ 'id' => $list,
1358
+ 'submit_text' => $submit_text
1359
+ );
1360
+ return $this->processShortcode($p);
1361
+ } // end processSnippet();
1362
+
1363
+
1364
+ /***** ADMINISTRATION MENUS => Continue Editing Downward!
1365
+ ****************************************************************************************************/
1366
+ public function addAdministrationMenu() {
1367
+ // Top Level Menu
1368
+ add_menu_page( __('MailChimp Forms','yikes-inc-easy-mailchimp-extender'), 'MailChimp Forms', apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-form', array(&$this, 'generatePageOptions'), 'dashicons-welcome-write-blog', 400);
1369
+ // Sub Items
1370
+ add_submenu_page('yks-mailchimp-form', __('MailChimp Forms','yikes-inc-easy-mailchimp-extender'), __('MailChimp Settings','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-form', array(&$this, 'generatePageOptions'));
1371
+ // if the user has entered a VALID API key
1372
+ if ( get_option('api_validation') == 'valid_api_key') {
1373
+ add_submenu_page('yks-mailchimp-form', __('My MailChimp','yikes-inc-easy-mailchimp-extender'), __('My MailChimp','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-my-mailchimp', array(&$this, 'generateUserMailChimpPage'));
1374
+ }
1375
+ add_submenu_page('yks-mailchimp-form', __('Manage List Forms','yikes-inc-easy-mailchimp-extender'), __('Manage List Forms','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-form-lists', array(&$this, 'generatePageLists'));
1376
+ add_submenu_page('yks-mailchimp-form', __('About YIKES, Inc.','yikes-inc-easy-mailchimp-extender'), __('About YIKES, Inc.','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-about-yikes', array(&$this, 'generatePageAboutYikes'));
1377
+ add_submenu_page('options.php', __('Welcome','yikes-inc-easy-mailchimp-extender'), __('Welcome','yikes-inc-easy-mailchimp-extender'), apply_filters( 'yks_mailchimp_user_role' , 'manage_options' ), 'yks-mailchimp-welcome', array(&$this, 'generateWelcomePage'));
1378
+ } // end addAdministrationMenu();
1379
+
1380
+
1381
+ /***** ADMINISTRATION PAGES
1382
+ ****************************************************************************************************/
1383
+ public function generatePageOptions() {
1384
+ require_once YKSEME_PATH.'pages/options.php'; // include our options page
1385
+ } // end generatePageOptions();
1386
+
1387
+ public function generatePageLists() {
1388
+ require_once YKSEME_PATH.'pages/lists.php'; // include our lists page
1389
+ } // end generatePageLists();
1390
+
1391
+ public function generatePageAboutYikes() {
1392
+ require_once YKSEME_PATH.'pages/about.php'; // include our about page
1393
+ } // end generatePageAboutYikes();
1394
+
1395
+ public function registerMailChimpWidget() {
1396
+ require_once YKSEME_PATH.'templates/yikes-mailchimp-widget.php'; // include our widget
1397
+ } // end registerMailChimpWidget();
1398
+
1399
+ public function includeRECAPTCHAlib() {
1400
+ require_once YKSEME_PATH.'lib/recaptchalib.php'; // include our widget
1401
+ } // end includeRECAPTCHAlib();
1402
+
1403
+ public function generateUserMailChimpPage() {
1404
+ require_once YKSEME_PATH.'pages/myMailChimp.php'; // include our widget
1405
+ } // end generateUserMailChimpPage();
1406
+
1407
+ public function generateWelcomePage() {
1408
+ require_once YKSEME_PATH.'pages/welcome.php'; // include our widget
1409
+ } // end generateWelcomePage();
1410
+
1411
+ /***** FORM DATA
1412
+ ****************************************************************************************************/
1413
+ public function yks_resetPluginSettings() {
1414
+ $blog_title = get_bloginfo( 'name' );
1415
+ // reset the plugin settings back to defaults
1416
+ $this->optionVal['api-key'] = '';
1417
+ $this->optionVal['flavor'] = '1';
1418
+ $this->optionVal['debug'] = '0';
1419
+ $this->optionVal['optin'] = 'true';
1420
+ $this->optionVal['single-optin-message'] = __('Thank You for subscribing!', 'yikes-inc-easy-mailchimp-extender');
1421
+ $this->optionVal['double-optin-message'] = __('Thank You for subscribing! Check your email for the confirmation message.', 'yikes-inc-easy-mailchimp-extender');
1422
+ $this->optionVal['optIn-checkbox'] = 'hide';
1423
+ $this->optionVal['yks-mailchimp-optIn-default-list'] = 'select_list';
1424
+ $this->optionVal['yks-mailchimp-optin-checkbox-text'] = 'Add me to the ' . $blog_title . ' mailing list';
1425
+ $this->optionVal['recaptcha-setting'] = '0';
1426
+ $this->optionVal['recaptcha-api-key'] = '';
1427
+ $this->optionVal['recaptcha-private-api-key'] = '';
1428
+ $this->optionVal['yks-mailchimp-jquery-datepicker'] = '';
1429
+ $this->optionVal['yks-mailchimp-required-text'] = '';
1430
+ $this->optionVal['version'] = YKSEME_VERSION_CURRENT;
1431
+ $this->optionVal['ssl_verify_peer'] = 'true';
1432
+ update_option('api_validation' , 'invalid_api_key');
1433
+ // we need to unset the previously set up widgets
1434
+ // and set up new erros if the API key doesn't exist
1435
+
1436
+ // 1 - empty the lists array of imported lists
1437
+ $this->optionVal['lists'] = array();
1438
+ // 2 - unset our previously set up widgets
1439
+ update_option( 'widget_yikes_mc_widget' , '' );
1440
+ // update our options
1441
+ return update_option( YKSEME_OPTION, $this->optionVal );
1442
+ } // end yks_resetPluginSettings();
1443
+
1444
+ // Make a call to MailChimp API to validate the provided API key - send request to helper/ping, returns a boolean
1445
+ public function validateAPIkeySettings() {
1446
+
1447
+ // right now we just check the length of the API key being passed in
1448
+ // mailchimp api keys are around 30-40 characters
1449
+ // we check if the string length is greater than 45...
1450
+ if ( strlen($_POST['api_key']) > 45 ) {
1451
+ // Create and store our variables to pass to MailChimp
1452
+ $apiKey = $this->yikes_mc_decryptIt($_POST['api_key']); // api key
1453
+ $apiKey_explosion = explode( "-" , $apiKey);
1454
+ $dataCenter = $apiKey_explosion[0]; // data center (ie: us3)
1455
+ $api = new Mailchimp($apiKey);
1456
+ // try the call, catch any errors that may be thrown
1457
+ try {
1458
+ $resp = $api->call('helper/ping', array('apikey' => $apiKey));
1459
+ echo $resp['msg'];
1460
+ $this->getOptionsLists();
1461
+ } catch( Exception $e ) {
1462
+ $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1463
+ echo $errorMessage;
1464
+ // log our error message for display back to the user
1465
+ $this->writeErrorToErrorLog( $e );
1466
+ }
1467
+ return $apiKey;
1468
+ // always die or it will always return 1
1469
+ wp_die();
1470
+ } else {
1471
+ $apiKey = $this->yikes_mc_encryptIt($_POST['api_key']);
1472
+ // Create and store our variables to pass to MailChimp
1473
+ $decryped_api_key = $this->yikes_mc_decryptIt($apiKey); // api key
1474
+ $apiKey_explosion = explode( "-" , $decryped_api_key);
1475
+ $dataCenter = $apiKey_explosion[0]; // data center (ie: us3)
1476
+ $api = new Mailchimp($decryped_api_key);
1477
+ // try the call, catch any errors that may be thrown
1478
+ try {
1479
+ $resp = $api->call('helper/ping', array('apikey' => $decryped_api_key));
1480
+ echo $resp['msg'];
1481
+ } catch( Exception $e ) {
1482
+ $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1483
+ echo $errorMessage;
1484
+ // log our error message for display back to the user
1485
+ $this->writeErrorToErrorLog( $e );
1486
+ }
1487
+ // always die or it will always return 1
1488
+ return $apiKey;
1489
+ wp_die();
1490
+ }
1491
+ } // end validateAPIkeySettings();
1492
+
1493
+ // Make a call to MailChimp API to get the current users PROFILE
1494
+ public function getUserProfileDetails() {
1495
+ // Create and store our variables to pass to MailChimp
1496
+ $apiKey = $_POST['api_key']; // api key
1497
+ $api = new Mailchimp($apiKey);
1498
+ // try the call, catch any errors that may be thrown
1499
+ try {
1500
+ $profile_response = $api->call('users/profile', array('apikey' => $apiKey));
1501
+ include_once YKSEME_PATH.'templates/mailChimp-profile-template.php';
1502
+ } catch( Exception $e ) {
1503
+ $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1504
+ echo $errorMessage;
1505
+ // write our error to the error log,
1506
+ // when advanced debug is enabled
1507
+ if ( $this->optionVal['debug'] == 1 ) {
1508
+ $this->writeErrorToErrorLog( $e );
1509
+ }
1510
+ }
1511
+
1512
+ // try the call, catch any errors that may be thrown
1513
+ try {
1514
+ $account_details = $api->call('helper/account-details', array('apikey' => $apiKey));
1515
+ include_once YKSEME_PATH.'templates/mailChimp-account-overview.php';
1516
+ } catch( Exception $e ) {
1517
+ $errorMessage = str_replace('API call to helper/ping failed:', '', $e->getMessage());
1518
+ echo $errorMessage;
1519
+ // write our error to the error log,
1520
+ // when advanced debug is enabled
1521
+ if ( $this->optionVal['debug'] == 1 ) {
1522
+ $this->writeErrorToErrorLog( $e );
1523
+ }
1524
+ }
1525
+ // always die or it will always return 1
1526
+ wp_die();
1527
+ } // end getUserProfileDetails();
1528
+
1529
+ /*
1530
+ Send Update Profile Email
1531
+ @since v5.2
1532
+ */
1533
+ public function sendUpdateProfileEmail( $user_email , $list_id ) {
1534
+ $api = new Mailchimp($this->optionVal['api-key']);
1535
+ $explode_key = explode( '-' , $this->optionVal['api-key'] );
1536
+ $data_center = $explode_key[1];
1537
+ $full_site_url = get_bloginfo('url');
1538
+ $extracted_url = str_replace( 'https://' , '' , str_replace( 'www.' , '' , str_replace( 'http://' , '' , $full_site_url ) ) );
1539
+ $site_name = str_replace( ' ' , '' , get_bloginfo('name') ) ;
1540
+ try {
1541
+ // get the site URL
1542
+ // not sure this needs its own API call
1543
+ $account_details = $api->call( 'helper/account-details', array('apikey' => $this->optionVal['api-key'] ) );
1544
+ // get the list details (default from name, default from email)
1545
+ $list_details = $api->call( 'lists/list',
1546
+ array(
1547
+ 'apikey' => $this->optionVal['api-key'],
1548
+ 'filters' => array(
1549
+ 'list_id' => $list_id
1550
+ )
1551
+ )
1552
+ );
1553
+ // get the subscribers info
1554
+ $subscriber_account_details = $api->call('lists/member-info',
1555
+ array(
1556
+ 'id' => $list_id,
1557
+ 'emails' => array(
1558
+ 0 => array(
1559
+ 'email' => $user_email,
1560
+ ),
1561
+ )
1562
+ )
1563
+ );
1564
+ $subscriber_id = $subscriber_account_details['data'][0]['id'];
1565
+ $explode_url = explode( '.' , $account_details['contact']['url'] );
1566
+ $subject = 'MailChimp Profile Update';
1567
+ $headers = 'From: ' . $list_details['data'][0]['default_from_name'] . ' <' . $list_details['data'][0]['default_from_email'] . '>' . "\r\n";
1568
+ $headers .= 'Content-type: text/html';
1569
+ $email_content = '<p>Dear user,</p> <p>A request has been made to update your account information. To do so use the following link: <a href="http://' . $explode_url[1] . '.' . $data_center . '.list-manage1.com/profile?u=' . $account_details['user_id'] . '&id=' . $list_id .'&e=' . $subscriber_id . '" title="Update MailChimp Profile">Update Profile Info.</a>';
1570
+ $email_content .= "<p>If you didn't request this update, please disregard this email.</p>";
1571
+ $email_content .= '<p>&nbsp;</p>';
1572
+ $email_content .= '<p>This email was sent from : ' . $full_site_url . '</p>';
1573
+ $email_content .= '<p>&nbsp;</p>';
1574
+ $email_content .= '<p>&nbsp;</p>';
1575
+ $email_content .= '<p style="font-size:13px;margin-top:5em;float:right;"><em>this email was generated by the <a href="http://www.wordpress.org/plugins/yikes-inc-easy-mailchimp-extender/" target="_blank">YIKES Inc. Easy MailChimp Extender</a> plugin, created by <a href="http://www.yikesinc.com" target="_blank">YIKES Inc.</a></em></p>';
1576
+ if ( wp_mail( $user_email, $subject, $email_content, $headers ) ) {
1577
+ echo '<span class="preloader-confirmation-box success">' . __( 'Update email successfully sent. Please check your inbox for the message.' , 'yikes-inc-easy-mailchimp-extender' ) . '</span>';
1578
+ } else {
1579
+ echo '<span class="preloader-confirmation-box error">' . __( 'Email failed to send. Please contact the site administrator.' , 'yikes-inc-easy-mailchimp-extender' ) . '</span>';
1580
+ }
1581
+ // print_r($account_details);
1582
+ } catch( Exception $e ) {
1583
+ $errorMessage = '<span class="error">' . __( 'Error sending update profile email. Please contact the site administrator.' , 'yikes-inc-easy-mailchimp-extender' ) . '</span>';
1584
+ echo $errorMessage;
1585
+ // write our error to the error log,
1586
+ // when advanced debug is enabled
1587
+ if ( $this->optionVal['debug'] == 1 ) {
1588
+ $this->writeErrorToErrorLog( $e );
1589
+ }
1590
+ }
1591
+ } // end sendUpdateProfileEmail();
1592
+
1593
+
1594
+ // Make a call to MailChimp API to validate the provided API key - api request to helper/chimp-chatter, returns Account Activity
1595
+ public function getMailChimpChatter() {
1596
+ // Create and store our variables to pass to MailChimp
1597
+ $apiKey = $this->optionVal['api-key']; // api key
1598
+ $api = new Mailchimp($apiKey);
1599
+ // try the call, catch any errors that may be thrown
1600
+ try {
1601
+ $resp = $api->call('helper/chimp-chatter', array('apikey' => $apiKey));
1602
+ include_once YKSEME_PATH.'templates/mailChimpChatter-template.php';
1603
+ } catch( Exception $e ) {
1604
+ echo '<strong>'.$e->getMessage().'</strong>';
1605
+ // write our error to the error log,
1606
+ // when advanced debug is enabled
1607
+ if ( $this->optionVal['debug'] == 1 ) {
1608
+ $this->writeErrorToErrorLog( $e );
1609
+ }
1610
+
1611
+ }
1612
+ // always die or it will always return 1
1613
+ wp_die();
1614
+ } // end getMailChimpChatter();
1615
+
1616
+
1617
+ // Make a call to MailChimp API to validate the provided API key
1618
+ // calls the helper/chimp-chatter method, and returns Account Activity
1619
+ public function getMailChimpChatterForWidget() {
1620
+ // Create and store our variables to pass to MailChimp
1621
+ $apiKey = $this->optionVal['api-key']; // api key
1622
+ $api = new Mailchimp($apiKey);
1623
+ // try the call, catch any errors that may be thrown
1624
+ try {
1625
+ $resp = $api->call('helper/chimp-chatter', array('apikey' => $apiKey));
1626
+ include_once YKSEME_PATH.'templates/mailChimpChatter-widget-template.php';
1627
+ } catch( Exception $e ) {
1628
+ echo '<strong>'.$e->getMessage().'</strong>';
1629
+ // write our error to the error log,
1630
+ // when advanced debug is enabled
1631
+ if ( $this->optionVal['debug'] == 1 ) {
1632
+ $this->writeErrorToErrorLog( $e );
1633
+ }
1634
+
1635
+ }
1636
+ // always die or it will always return 1
1637
+ wp_die();
1638
+ } // end getMailChimpChatterForWidget();
1639
+
1640
+
1641
+ // Make a call to MailChimp API to lists/growth history
1642
+ public function getListGrowthHistory() {
1643
+ // Create and store our variables to pass to MailChimp
1644
+ $apiKey = $_POST['api_key']; // api key
1645
+ if ( isset($_POST['list_id']) ) { $listID = $_POST['list_id']; } else { $listID = NULL; }
1646
+ $api = new Mailchimp($apiKey);
1647
+ // try the call, catch any errors that may be thrown
1648
+ try {
1649
+ $resp = $api->call('lists/growth-history', array( 'apikey' => $apiKey , 'id' => $listID ));
1650
+ // include our Stats Template
1651
+ include_once YKSEME_PATH.'templates/mailChimp-list-growth-template.php';
1652
+ // Working File
1653
+ // date is returned out of order tho...
1654
+ // include_once YKSEME_PATH.'templates/mailChimp-list-growth-template.php';
1655
+ } catch( Exception $e ) {
1656
+ echo '<strong>'.$e->getMessage().'</strong>';
1657
+ // write our error to the error log,
1658
+ // when advanced debug is enabled
1659
+ if ( $this->optionVal['debug'] == 1 ) {
1660
+ $this->writeErrorToErrorLog( $e );
1661
+ }
1662
+
1663
+ }
1664
+ // always die or it will always return 1
1665
+ wp_die();
1666
+ } // end getListGrowthHistory();
1667
+
1668
+
1669
+ // Make a call to MailChimp API to
1670
+ // get a specified all campaigns or specified list campaign data
1671
+ // used for both overall aggregate stats AND single list stats
1672
+ public function getCapmpaignData() {
1673
+ // Create and store our variables to pass to MailChimp
1674
+ $apiKey = $_POST['api_key']; // api key
1675
+ $api = new Mailchimp($apiKey);
1676
+ // try the call, catch any errors that may be thrown
1677
+ try {
1678
+ $resp = $api->call('campaigns/list', array( 'apikey' => $apiKey , 'limit' => 1000 ));
1679
+ // include our Stats Template
1680
+ include_once YKSEME_PATH.'templates/mailChimp-campaign-stats-template.php';
1681
+ } catch( Exception $e ) {
1682
+ echo '<strong>'.$e->getMessage().'</strong>';
1683
+ // write our error to the error log,
1684
+ // when advanced debug is enabled
1685
+ if ( $this->optionVal['debug'] == 1 ) {
1686
+ $this->writeErrorToErrorLog( $e );
1687
+ }
1688
+
1689
+ }
1690
+ // always die or it will always return 1
1691
+ wp_die();
1692
+ } // end getCapmpaignData();
1693
+
1694
+
1695
+ // Make a call to MailChimp API to
1696
+ // To get our piechart for the link stats page
1697
+ public function getPieChart() {
1698
+ // Create and store our variables to pass to MailChimp
1699
+ $pie_chart_link_data_array = $_POST['pie_chart_data_array']; // link data
1700
+ // include our Stats Template
1701
+ include YKSEME_PATH.'templates/mailChimp-campaign-clicks-pie-chart.php';
1702
+
1703
+ // always die or it will always return 1
1704
+ wp_die();
1705
+ }
1706
+
1707
+ // Make a call to MailChimp API to
1708
+ // get a specified all campaigns or specified list campaign data
1709
+ // used for both overall aggregate stats AND single list stats
1710
+ public function getSpecificCapmpaignData() {
1711
+ // Create and store our variables to pass to MailChimp
1712
+ $apiKey = $_POST['api_key']; // api key
1713
+ $api = new Mailchimp($apiKey);
1714
+ $campaign_id = $_POST['campaign_id'];
1715
+ $campaign_title = $_POST['campaign_title'];
1716
+ $campaign_email_subject = $_POST['campaign_subject'];
1717
+ $campaign_send_date = $_POST['campaign_send_date'];
1718
+ $campaign_send_time = $_POST['campaign_send_time'];
1719
+ $campaign_view_email_link = $_POST['campaign_view_email_link'];
1720
+ $campaign_web_Id = $_POST['campaign_web_Id'];
1721
+ // try the call, catch any errors that may be thrown
1722
+ try {
1723
+ $resp = $api->call('reports/summary', array( 'apikey' => $apiKey , 'cid' => $campaign_id ));
1724
+ // include our Stats Template
1725
+ include_once YKSEME_PATH.'templates/mailChimp-campaign-report.php';
1726
+ // print_r($resp);
1727
+ } catch( Exception $e ) {
1728
+ echo '<strong>'.$e->getMessage().'</strong>';
1729
+ // write our error to the error log,
1730
+ // when advanced debug is enabled
1731
+ if ( $this->optionVal['debug'] == 1 ) {
1732
+ $this->writeErrorToErrorLog( $e );
1733
+ }
1734
+ }
1735
+ // always die or it will always return 1
1736
+ wp_die();
1737
+ } // end getSpecificCapmpaignData();
1738
+
1739
+ // Send a call to MailChimp API to get the email recipients of a specific campaign
1740
+ public function getCampaignEmailToTable() {
1741
+ // Create and store our variables to pass to MailChimp
1742
+ $apiKey = $_POST['api_key']; // api key
1743
+ $api = new Mailchimp($apiKey);
1744
+ $campaign_id = $_POST['campaign_id'];
1745
+ // try the call, catch any errors that may be thrown
1746
+ try {
1747
+ $resp = $api->call('reports/sent-to', array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array('limit' => '100') ));
1748
+ // include our Stats Template
1749
+ // include_once YKSEME_PATH.'templates/mailChimp-campaign-report.php';
1750
+ // print_r($resp);
1751
+ if ( $resp ) {
1752
+ ?>
1753
+ <script type="text/javascript">
1754
+ jQuery(document).ready(function() {
1755
+ jQuery('#yikes-mailchimp-emailed-subscribers').dataTable();
1756
+ });
1757
+ </script>
1758
+
1759
+ <style>
1760
+ .subscriber_rating_star { font-size:15px; }
1761
+ </style>
1762
+
1763
+ <table id="yikes-mailchimp-emailed-subscribers" class="yks-mailchimp-fields-list" style="width:100%;">
1764
+ <thead class="yikes-mailchimp-subscribers-table-head">
1765
+ <tr>
1766
+ <th style="width:20%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1767
+ <th style="width:19%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1768
+ <th style="width:18%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1769
+ <th style="width:25%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1770
+ <th style="width:18%;"><?php _e( 'Last Changed' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1771
+ </tr>
1772
+ </thead>
1773
+ <?php
1774
+ foreach ( $resp['data'] as $recipient ) {
1775
+
1776
+ // create the name variable, dependant on first and last name being stored
1777
+ if ( isset ( $recipient['member']['merges']['FNAME'] ) && $recipient['member']['merges']['FNAME'] != '' ) {
1778
+ $user_first_name = $recipient['member']['merges']['FNAME'];
1779
+ } else {
1780
+ $user_first_name = '';
1781
+ }
1782
+ if ( isset ( $recipient['member']['merges']['LNAME'] ) && $recipient['member']['merges']['LNAME'] != '' ) {
1783
+ $user_last_name = $recipient['member']['merges']['LNAME'];
1784
+ } else {
1785
+ $user_last_name = '';
1786
+ }
1787
+
1788
+ $user_email = $recipient['member']['email'];
1789
+ $user_id = $recipient['member']['id'];
1790
+ $email_type = $recipient['member']['email_type'];
1791
+ $user_rating = $recipient['member']['member_rating'];
1792
+ $user_last_changed = $recipient['member']['info_changed'];
1793
+ $exploded_change = explode( ' ' , $user_last_changed);
1794
+ $user_last_changed_date = date( 'm/d/Y' , strtotime( $exploded_change[0] ) );
1795
+ $user_last_changed_time = date( 'g:i a' , strtotime( $exploded_change[1] ) );
1796
+
1797
+ if(isset($user_rating)) {
1798
+ if ($user_rating == 1) {
1799
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1800
+ } else if ($user_rating == 2) {
1801
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1802
+ } else if ($user_rating == 3) {
1803
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1804
+ } else if ($user_rating == 4) {
1805
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1806
+ } else if ($user_rating == 5) {
1807
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
1808
+ }
1809
+ }
1810
+
1811
+ // $timeStamp = explode(' ', $subscriber['timestamp_opt'] );
1812
+ echo '<tr class="yks-mailchimp-subscribers-list-row" id="yks-mailchimp-subscribers-list-row">';
1813
+ echo '<td><a class="subscriber-mail-link" rel="'.$user_email.'" class="subscriberEmailAddress">'.$user_email.'</a></td>';
1814
+ echo '<td>'.ucfirst(strtolower($user_first_name)).'</td>';
1815
+ echo '<td>'.ucfirst(strtolower($user_last_name)).'</td>';
1816
+ echo '<td><span style="display:none;">'.$user_rating.'</span>'.$member_rating_stars.'</td>';
1817
+ echo '<td>'.$user_last_changed_date . ' at ' . $user_last_changed_time .'</td>';
1818
+ echo '</tr>';
1819
+
1820
+ }
1821
+ ?>
1822
+ </table>
1823
+ <?php
1824
+ }
1825
+ } catch( Exception $e ) {
1826
+ echo '<strong>'.$e->getMessage().'</strong>';
1827
+ // write our error to the error log,
1828
+ // when advanced debug is enabled
1829
+ if ( $this->optionVal['debug'] == 1 ) {
1830
+ $this->writeErrorToErrorLog( $e );
1831
+ }
1832
+
1833
+ }
1834
+ // always die or it will always return 1
1835
+ wp_die();
1836
+ } // end getCampaignEmailToTable();
1837
+
1838
+
1839
+ // Send a call to MailChimp API to get the geo location of users who opened links
1840
+ public function getGeoDataForCampaignOpenLinks() {
1841
+ // Create and store our variables to pass to MailChimp
1842
+ $apiKey = $_POST['api_key']; // api key
1843
+ $api = new Mailchimp($apiKey);
1844
+ $campaign_id = $_POST['campaign_id'];
1845
+ // try the call, catch any errors that may be thrown
1846
+ try {
1847
+ $resp = $api->call('reports/geo-opens', array( 'apikey' => $apiKey , 'cid' => $campaign_id ) );
1848
+ // include our Stats Template
1849
+ // include_once YKSEME_PATH.'templates/mailChimp-campaign-report.php';
1850
+ // print_r($resp);
1851
+ if ( $resp ) {
1852
+ include_once YKSEME_PATH.'templates/mailChimp-campaign-click-geo-map.php';
1853
+ }
1854
+ } catch( Exception $e ) {
1855
+ // write our error to the error log,
1856
+ // when advanced debug is enabled
1857
+ if ( $this->optionVal['debug'] == 1 ) {
1858
+ $this->writeErrorToErrorLog( $e );
1859
+ }
1860
+ ?>
1861
+ <script>
1862
+ jQuery(document).ready(function() {
1863
+ setTimeout(function() {
1864
+ var mailChimpError = '<?php echo "<strong class=yks-mc-report-error>".$e->getMessage()."</strong>"; ?>';
1865
+ jQuery('#open_tracking_disabled_warning').fadeIn();
1866
+ jQuery('#geo_map_no_data').append('<p class="geo_map_no_data_error">'+mailChimpError+'</p>');
1867
+ }, 600);
1868
+ });
1869
+ </script>
1870
+
1871
+ <section class="overview_information_section">
1872
+
1873
+ <div class="overview_information">
1874
+
1875
+ <h2>Campaign Activity Geo Map</h2>
1876
+
1877
+ <div id="geo_map_no_data" style="max-width: 100%;min-width: 100%; background:#fff;">
1878
+ <div id="geo_map_no_data_overlay"></div>
1879
+ <img src="<?php echo plugins_url( '/../images/highcharts-worldmap-disabled.png' , __FILE__ ); ?>" alt="World Map Disabled" title="World Map Disabled">
1880
+ </div>
1881
+ </div>
1882
+
1883
+ </section>
1884
+
1885
+ <?php
1886
+ }
1887
+ // always die or it will always return 1
1888
+ wp_die();
1889
+ } // end getGeoDataForCampaignOpenLinks();
1890
+
1891
+
1892
+ // Make a call to MailChimp API to
1893
+ // get link tracking information for a specified campaign
1894
+ // used in the world map on the campaign stats page
1895
+ public function getCampaignLinkStats() {
1896
+ // Create and store our variables to pass to MailChimp
1897
+ $apiKey = $_POST['api_key']; // api key
1898
+ $api = new Mailchimp($apiKey);
1899
+ $campaign_id = $_POST['campaign_id'];
1900
+ // try the call, catch any errors that may be thrown
1901
+ try {
1902
+ $campaign_click_stats = $api->call( '/reports/clicks' , array( 'apikey' => $apiKey , 'cid' => $campaign_id ) );
1903
+ // include our Stats Template
1904
+ include_once YKSEME_PATH.'templates/mailChimp-campaign-click-report.php';
1905
+ } catch( Exception $e ) {
1906
+ echo '<strong>'.$e->getMessage().'</strong>';
1907
+ // write our error to the error log,
1908
+ // when advanced debug is enabled
1909
+ if ( $this->optionVal['debug'] == 1 ) {
1910
+ $this->writeErrorToErrorLog( $e );
1911
+ }
1912
+ }
1913
+ // always die or it will always return 1
1914
+ wp_die();
1915
+ } // end getCampaignLinkStats();
1916
+
1917
+
1918
+ // Make a call to MailChimp API to
1919
+ // get users who opened a specific campaign
1920
+ // used in the stats page modal
1921
+ public function getCampaignOpenedData() {
1922
+ // Create and store our variables to pass to MailChimp
1923
+ $apiKey = $_POST['api_key']; // api key
1924
+ $api = new Mailchimp($apiKey);
1925
+ $campaign_id = $_POST['campaign_id'];
1926
+ // try the call, catch any errors that may be thrown
1927
+ try {
1928
+ // create our interactive data table
1929
+ // and initialize it here...
1930
+
1931
+ $campaign_open_stats = $api->call( '/reports/opened' , array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array( 'sort_field' => 'opens' , 'sort_dir' => 'DESC' ) ) );
1932
+
1933
+ // create an empty array
1934
+ $total_opens_array = array();
1935
+ // build our total opens array
1936
+ foreach ( $campaign_open_stats['data'] as $opened_data ) {
1937
+ $total_opens_array[] = $opened_data['opens'];
1938
+ }
1939
+
1940
+ // display total unique opens
1941
+ echo '<h2 style="float:left;">' . __( 'Unique Opens' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . $campaign_open_stats["total"] . '</h2>';
1942
+ // display total opens
1943
+ echo '<h2 style="float:right;">' . __( 'Total Opens' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . array_sum($total_opens_array) . '</h2>';
1944
+
1945
+ // echo '<h2>' . __( 'Total Opens' 'yikes-inc-easy-mailchimp-extender' ) . $campaign_open_stats["total"] . '</h2>';
1946
+
1947
+ ?>
1948
+ <!-- initialize o ur data table -->
1949
+ <script type="text/javascript">
1950
+ jQuery(document).ready(function() {
1951
+ jQuery('#yikes-mailchimp-subscribers-opens').dataTable({
1952
+ "aaSorting": [[ 1, "desc" ]]
1953
+ });
1954
+ });
1955
+ </script>
1956
+
1957
+ <style>
1958
+ .subscriber_rating_star { font-size:15px; }
1959
+ </style>
1960
+
1961
+ <!-- build our opened user table -->
1962
+ <table id="yikes-mailchimp-subscribers-opens" class="yks-mailchimp-fields-list" style="width:100%;">
1963
+ <thead class="yikes-mailchimp-subscribers-table-head">
1964
+ <tr>
1965
+ <th style="width:31%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1966
+ <th style="width:14%;"><?php _e( 'Opens' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1967
+ <th style="width:20%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1968
+ <th style="width:20%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1969
+ <th style="width:15%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
1970
+ </tr>
1971
+ </thead>
1972
+ <?php
1973
+ // loop over to build create and store our user variables returned by mailchimp
1974
+ foreach ( $campaign_open_stats['data'] as $opened_data ) {
1975
+
1976
+ // checking if FNAME is set as a merge variable
1977
+ // if not, we'll just make it an empty string
1978
+ if ( isset ( $opened_data['member']['merges']['LNAME'] ) ) {
1979
+ $opened_data['member']['merges']['LNAME'] = $opened_data['member']['merges']['LNAME'];
1980
+ } else {
1981
+ $opened_data['member']['merges']['LNAME'] = '';
1982
+ }
1983
+
1984
+ // checking if LNAME is set as a merge variable
1985
+ // if not, we'll just make it an empty string
1986
+ if ( isset ( $opened_data['member']['merges']['FNAME'] ) ) {
1987
+ $opened_data['member']['merges']['FNAME'] = $opened_data['member']['merges']['FNAME'];
1988
+ } else {
1989
+ $opened_data['member']['merges']['FNAME'] = '';
1990
+ }
1991
+
1992
+
1993
+ if(isset($opened_data['member']['member_rating'])) {
1994
+ if ($opened_data['member']['member_rating'] == 1) {
1995
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1996
+ } else if ($opened_data['member']['member_rating'] == 2) {
1997
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
1998
+ } else if ($opened_data['member']['member_rating'] == 3) {
1999
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2000
+ } else if ($opened_data['member']['member_rating'] == 4) {
2001
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2002
+ } else if ($opened_data['member']['member_rating'] == 5) {
2003
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
2004
+ }
2005
+ }
2006
+ // build our table inside the loop
2007
+ echo '<tr>';
2008
+ echo '<td><a href="mailto:'.$opened_data['member']['email'].'">'.$opened_data['member']['email'].'</a></td>';
2009
+ echo '<td>'.$opened_data['opens'].'</td>';
2010
+ echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['FNAME'])).'</td>';
2011
+ echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['LNAME'])).'</td>';
2012
+ echo '<td><span style="display:none;">'.$opened_data['member']['member_rating'].'</span>'.$member_rating_stars.'</td>';
2013
+ echo '</tr>';
2014
+ }
2015
+
2016
+ } catch( Exception $e ) {
2017
+ // if there is some error, lets return it
2018
+ echo '<strong>'.$e->getMessage().'</strong>';
2019
+ // write our error to the error log,
2020
+ // when advanced debug is enabled
2021
+ if ( $this->optionVal['debug'] == 1 ) {
2022
+ $this->writeErrorToErrorLog( $e );
2023
+ }
2024
+ }
2025
+ // always die or it will always return 1
2026
+ wp_die();
2027
+ } // end getCampaignOpenedData();
2028
+
2029
+
2030
+ // Make a call to MailChimp API to
2031
+ // get bounced email addressed for this campaign
2032
+ // used in the stats page modal
2033
+ public function getCampaignBouncedEmailData() {
2034
+ // Create and store our variables to pass to MailChimp
2035
+ $apiKey = $_POST['api_key']; // api key
2036
+ $api = new Mailchimp($apiKey);
2037
+ $campaign_id = $_POST['campaign_id'];
2038
+ // try the call, catch any errors that may be thrown
2039
+ try {
2040
+ // create our interactive data table
2041
+ // and initialize it here...
2042
+
2043
+ $campaign_bounce_stats = $api->call( '/reports/bounce-messages' , array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array( 'limit' => '100' ) ) );
2044
+
2045
+ // print_r($campaign_bounce_stats);
2046
+
2047
+ // display total unique opens
2048
+ echo '<h2 style="float:left;">' . __( 'Total Bounced Emails' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . $campaign_bounce_stats["total"] . '</h2>';
2049
+
2050
+ // echo '<h2>' . __( 'Total Opens' 'yikes-inc-easy-mailchimp-extender' ) . $campaign_open_stats["total"] . '</h2>';
2051
+
2052
+ ?>
2053
+ <!-- initialize o ur data table -->
2054
+ <script type="text/javascript">
2055
+ jQuery(document).ready(function() {
2056
+ jQuery('#yikes-mailchimp-subscribers-bounced').dataTable({
2057
+ "aaSorting": [[ 1, "desc" ]]
2058
+ });
2059
+ });
2060
+ </script>
2061
+
2062
+ <style>
2063
+ .subscriber_rating_star { font-size:15px; }
2064
+ </style>
2065
+
2066
+ <!-- build our opened user table -->
2067
+ <table id="yikes-mailchimp-subscribers-bounced" class="yks-mailchimp-fields-list" style="width:100%;">
2068
+ <thead class="yikes-mailchimp-subscribers-table-head">
2069
+ <tr>
2070
+ <th style="width:31%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2071
+ <th style="width:20%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2072
+ <th style="width:20%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2073
+ <th style="width:15%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2074
+ </tr>
2075
+ </thead>
2076
+ <?php
2077
+ // loop over to build create and store our user variables
2078
+ // returned by mailchimp
2079
+ foreach ( $campaign_bounce_stats['data'] as $opened_data ) {
2080
+
2081
+ // checking if FNAME is set as a merge variable
2082
+ // if not, we'll just make it an empty string
2083
+ if ( isset ( $opened_data['member']['merges']['LNAME'] ) ) {
2084
+ $opened_data['member']['merges']['LNAME'] = $opened_data['member']['merges']['LNAME'];
2085
+ } else {
2086
+ $opened_data['member']['merges']['LNAME'] = '';
2087
+ }
2088
+
2089
+ // checking if LNAME is set as a merge variable
2090
+ // if not, we'll just make it an empty string
2091
+ if ( isset ( $opened_data['member']['merges']['FNAME'] ) ) {
2092
+ $opened_data['member']['merges']['FNAME'] = $opened_data['member']['merges']['FNAME'];
2093
+ } else {
2094
+ $opened_data['member']['merges']['FNAME'] = '';
2095
+ }
2096
+
2097
+
2098
+ if(isset($opened_data['member']['member_rating'])) {
2099
+ if ($opened_data['member']['member_rating'] == 1) {
2100
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2101
+ } else if ($opened_data['member']['member_rating'] == 2) {
2102
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2103
+ } else if ($opened_data['member']['member_rating'] == 3) {
2104
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2105
+ } else if ($opened_data['member']['member_rating'] == 4) {
2106
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2107
+ } else if ($opened_data['member']['member_rating'] == 5) {
2108
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
2109
+ }
2110
+ }
2111
+ // build our table inside the loop
2112
+ echo '<tr>';
2113
+ echo '<td><a href="mailto:'.$opened_data['member']['email'].'">'.$opened_data['member']['email'].'</a></td>';
2114
+ echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['FNAME'])).'</td>';
2115
+ echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['LNAME'])).'</td>';
2116
+ echo '<td><span style="display:none;">'.$opened_data['member']['member_rating'].'</span>'.$member_rating_stars.'</td>';
2117
+ echo '</tr>';
2118
+ }
2119
+
2120
+ // print_r($campaign_open_stats);
2121
+
2122
+ } catch( Exception $e ) {
2123
+ // if there is some error, lets return it
2124
+ echo '<strong>'.$e->getMessage().'</strong>';
2125
+ // write our error to the error log,
2126
+ // when advanced debug is enabled
2127
+ if ( $this->optionVal['debug'] == 1 ) {
2128
+ $this->writeErrorToErrorLog( $e );
2129
+ }
2130
+ }
2131
+ // always die or it will always return 1
2132
+ wp_die();
2133
+ } // end getCampaignBouncedEmailData();
2134
+
2135
+
2136
+ // Make a call to MailChimp API to
2137
+ // get unsubscribed email addressed for this campaign
2138
+ // used in the stats page modal
2139
+ public function getCampaignUnsubscribeData() {
2140
+ // Create and store our variables to pass to MailChimp
2141
+ $apiKey = $_POST['api_key']; // api key
2142
+ $api = new Mailchimp($apiKey);
2143
+ $campaign_id = $_POST['campaign_id'];
2144
+ // try the call, catch any errors that may be thrown
2145
+ try {
2146
+ // create our interactive data table
2147
+ // and initialize it here...
2148
+
2149
+ $campaign_unsubscribe_stats = $api->call( '/reports/unsubscribes' , array( 'apikey' => $apiKey , 'cid' => $campaign_id , 'opts' => array( 'limit' => '100' ) ) );
2150
+
2151
+ // print_r($campaign_bounce_stats);
2152
+
2153
+ // display total unique opens
2154
+ echo '<h2 style="float:left;">' . __( 'Total Unsubscribes' , 'yikes-inc-easy-mailchimp-extender' ) . ' - ' . $campaign_unsubscribe_stats["total"] . '</h2>';
2155
+
2156
+ // echo '<h2>' . __( 'Total Opens' 'yikes-inc-easy-mailchimp-extender' ) . $campaign_open_stats["total"] . '</h2>';
2157
+
2158
+ ?>
2159
+ <!-- initialize o ur data table -->
2160
+ <script type="text/javascript">
2161
+ jQuery(document).ready(function() {
2162
+ jQuery('#yikes-mailchimp-unsubscribe-table').dataTable({
2163
+ "aaSorting": [[ 0, "desc" ]]
2164
+ });
2165
+ });
2166
+ </script>
2167
+
2168
+ <style>
2169
+ .subscriber_rating_star { font-size:15px; }
2170
+ </style>
2171
+
2172
+ <!-- build our opened user table -->
2173
+ <table id="yikes-mailchimp-unsubscribe-table" class="yks-mailchimp-fields-list" style="width:100%;">
2174
+ <thead class="yikes-mailchimp-subscribers-table-head">
2175
+ <tr>
2176
+ <th style="width:31%;"><?php _e( 'E-Mail' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2177
+ <th style="width:20%;"><?php _e( 'First Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2178
+ <th style="width:20%;"><?php _e( 'Last Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2179
+ <th style="width:15%;"><?php _e( 'Member Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2180
+ <th style="width:15%;"><?php _e( 'Reason' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
2181
+ </tr>
2182
+ </thead>
2183
+ <?php
2184
+ // loop over to build create and store our user variables
2185
+ // returned by mailchimp
2186
+ foreach ( $campaign_unsubscribe_stats['data'] as $opened_data ) {
2187
+
2188
+ // checking if FNAME is set as a merge variable
2189
+ // if not, we'll just make it an empty string
2190
+ if ( isset ( $opened_data['member']['merges']['LNAME'] ) ) {
2191
+ $opened_data['member']['merges']['LNAME'] = $opened_data['member']['merges']['LNAME'];
2192
+ } else {
2193
+ $opened_data['member']['merges']['LNAME'] = '';
2194
+ }
2195
+
2196
+ // checking if LNAME is set as a merge variable
2197
+ // if not, we'll just make it an empty string
2198
+ if ( isset ( $opened_data['member']['merges']['FNAME'] ) ) {
2199
+ $opened_data['member']['merges']['FNAME'] = $opened_data['member']['merges']['FNAME'];
2200
+ } else {
2201
+ $opened_data['member']['merges']['FNAME'] = '';
2202
+ }
2203
+
2204
+
2205
+ if(isset($opened_data['member']['member_rating'])) {
2206
+ if ($opened_data['member']['member_rating'] == 1) {
2207
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2208
+ } else if ($opened_data['member']['member_rating'] == 2) {
2209
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2210
+ } else if ($opened_data['member']['member_rating'] == 3) {
2211
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2212
+ } else if ($opened_data['member']['member_rating'] == 4) {
2213
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-empty"></span></div>';
2214
+ } else if ($opened_data['member']['member_rating'] == 5) {
2215
+ $member_rating_stars = '<div class="yks-mc-subscriber-rating"><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span><span class="subscriber_rating_star dashicons dashicons-star-filled"></span></div>';
2216
+ }
2217
+ }
2218
+ // build our table inside the loop
2219
+ echo '<tr>';
2220
+ echo '<td><a href="mailto:'.$opened_data['member']['email'].'">'.$opened_data['member']['email'].'</a></td>';
2221
+ echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['FNAME'])).'</td>';
2222
+ echo '<td>'.ucfirst(strtolower($opened_data['member']['merges']['LNAME'])).'</td>';
2223
+ echo '<td><span style="display:none;">'.$opened_data['member']['member_rating'].'</span>'.$member_rating_stars.'</td>';
2224
+ echo '<td>'.strtolower($opened_data['reason']).'</td>';
2225
+ echo '</tr>';
2226
+ }
2227
+
2228
+ } catch( Exception $e ) {
2229
+ // if there is some error, lets return it
2230
+ echo '<strong>'.$e->getMessage().'</strong>';
2231
+ // write our error to the error log,
2232
+ // when advanced debug is enabled
2233
+ if ( $this->optionVal['debug'] == 1 ) {
2234
+ $this->writeErrorToErrorLog( $e );
2235
+ }
2236
+ }
2237
+ // always die or it will always return 1
2238
+ wp_die();
2239
+ } // end getCampaignUnsubscribeData();
2240
+
2241
+
2242
+ // Make a call to MailChimp API to add a new subscriber to a specified list
2243
+ // Runs when a user fills out the form on the frontend of the site
2244
+ public function addUserToMailchimp( $p , $update_existing ) {
2245
+
2246
+ if( !empty( $p['form_data'] ) ) {
2247
+
2248
+ parse_str($p['form_data'], $fd);
2249
+
2250
+ // grab and store our nonce field
2251
+ // for security purposes
2252
+ $yks_mc_form_submission_nonce = $fd['_wpnonce'];
2253
+
2254
+ // cross check our nonce
2255
+ // passing in the action used when we created the nonce field
2256
+ // if the nonce does not match, we need to die()
2257
+ if ( !wp_verify_nonce( $yks_mc_form_submission_nonce , 'yks_mc_front_end_form_'.$fd['yks-mailchimp-list-id'] ) ) {
2258
+ die( __( 'Failed nonce security check. Please reload the page and submit this form again.' , 'yikes-inc-easy-mailchimp-extender' ) );
2259
+ }
2260
+
2261
+
2262
+ if( !empty( $fd['yks-mailchimp-list-id'] ) ) {
2263
+
2264
+ // if reCAPTCHA is enabled
2265
+ if ( $this->optionVal['recaptcha-setting'] == '1' ) {
2266
+
2267
+ if ( isset( $fd['g-recaptcha-response'] ) && $fd['g-recaptcha-response'] == '' ) {
2268
+ die( __( 'Please check off that you are not a robot.' , 'yikes-inc-easy-mailchimp-extender' ) );
2269
+ }
2270
+
2271
+ $privatekey = $this->optionVal['recaptcha-private-api-key'];
2272
+ $response = $fd['g-recaptcha-response'];
2273
+
2274
+ // if the CAPTCHA was entered properly
2275
+ if ( $fd['g-recaptcha-response'] == '' ) {
2276
+ // if the response returns invalid,
2277
+ // lets add the animated shake and error fields
2278
+ // to the captcha fields
2279
+ ?>
2280
+ <script>
2281
+ jQuery(document).ready(function() {
2282
+ jQuery('.g-recaptcha').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2283
+ jQuery(this).removeClass('shake animated');
2284
+ next();
2285
+ });
2286
+ });
2287
+ </script>
2288
+ <?php
2289
+
2290
+ // if it returns valid...
2291
+ // continue sending data to MailChimp
2292
+ } else {
2293
+
2294
+ // Create and store the variables needed to add a new subscriber
2295
+ $email = false;
2296
+ $lid = $fd['yks-mailchimp-list-id'];
2297
+ $api = new Mailchimp($this->optionVal['api-key']);
2298
+ $mv = array();
2299
+ $optin = $this->optionVal['optin'];
2300
+
2301
+ foreach($this->optionVal['lists'][$lid]['fields'] as $field) : if($field['active'] == '1') :
2302
+
2303
+ // Check to see if the field is in the post
2304
+ if(isset($fd[$field['name']])) :
2305
+
2306
+ // Grab the primary email
2307
+ if(strtolower($field['merge']) == 'email')
2308
+ $email = $fd[$field['name']];
2309
+
2310
+ // It exists, set the merge var that we send to mailchimp
2311
+ switch($field['type'])
2312
+ {
2313
+ default:
2314
+ $mv[$field['merge']] = $fd[$field['name']];
2315
+ break;
2316
+
2317
+ case 'address':
2318
+ $mv[$field['merge']] = array(
2319
+ 'addr1' => $fd[$field['name']],
2320
+ 'addr2' => $fd[$field['name'].'-add2'],
2321
+ 'city' => $fd[$field['name'].'-city'],
2322
+ 'state' => $fd[$field['name'].'-state'],
2323
+ 'zip' => $fd[$field['name'].'-zip'],
2324
+ 'country' => 'US'
2325
+ );
2326
+ break;
2327
+
2328
+ }
2329
+
2330
+
2331
+
2332
+ endif;
2333
+ endif; endforeach;
2334
+
2335
+ // Interest group loop to build the GROUPINGS array
2336
+ // The GROUPINGS array passes our interest group, and values back to the specific form
2337
+ if ( isset($fd['interest-group-data']) ) {
2338
+ $interest_group_option = json_decode($fd['interest-group-data'], true);
2339
+ }
2340
+ // if interest groups exist, continue and form an array
2341
+ if ( isset($interest_group_option) ) {
2342
+
2343
+ // print_r($interest_group_option);
2344
+ $mv['GROUPINGS'] = array();
2345
+
2346
+ // loop over each interest group
2347
+ foreach ($interest_group_option as $group ) :
2348
+
2349
+ switch($group['form_field'])
2350
+ {
2351
+ case 'radio':
2352
+ case 'dropdown':
2353
+ array_push($mv['GROUPINGS'], array(
2354
+ 'id' => $group['id'],
2355
+ // 'groups' => array($fd['interest-group'])
2356
+ 'groups' => array(isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2357
+ )
2358
+ );
2359
+ break;
2360
+
2361
+ case 'checkboxes':
2362
+ array_push($mv['GROUPINGS'], array(
2363
+ 'id' => $group['id'],
2364
+ // 'groups' => array($fd['interest-group'])
2365
+ 'groups' => (isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2366
+ // $fd[$group['form_field'].'-'.$group['id']]
2367
+
2368
+ )
2369
+ );
2370
+ break;
2371
+ }
2372
+ endforeach; // end loop
2373
+
2374
+ }
2375
+
2376
+ // If no email provided, fail
2377
+ $noemail = "The email address is blank";
2378
+ if($email === false) return $noemail;
2379
+
2380
+ // Add custom filter here, to capture user submitted
2381
+ // data before it's sent off to MailChimp
2382
+ $form_data = apply_filters( 'yikes_mc_get_form_data' , $mv );
2383
+
2384
+ $form_data = apply_filters( 'yikes_mc_get_form_data_'.$lid, $mv );
2385
+
2386
+ // setup our welcome email variable
2387
+ if( isset( $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] ) && $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] == '1' ) {
2388
+ $welcome = false;
2389
+ } else {
2390
+ $welcome = true;
2391
+ }
2392
+
2393
+ // try adding subscriber, catch any error thrown
2394
+ try {
2395
+ $retval = $api->call('lists/subscribe', array(
2396
+ 'id' => $lid, // form id
2397
+ 'email' => array( 'email' => $email ), // user email
2398
+ 'merge_vars' => $form_data, // merge variables (ie: fields and interest groups)
2399
+ 'double_optin' => $optin, // double optin value (retreived from the settings page)
2400
+ 'send_welcome' => $welcome,
2401
+ 'update_existing' => $update_existing
2402
+ ));
2403
+ return "done";
2404
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
2405
+ $errorCode = $e->getCode();
2406
+ if ( $errorCode = '214' ) {
2407
+ $errorMessage = $e->getMessage();
2408
+ return json_encode( array( 'errorCode' => $errorCode , 'errorResponse' => apply_filters( 'yikes_mc_user_already_subscribed' , $errorMessage , $email ) ) );
2409
+ die();
2410
+ } else {
2411
+ echo '<strong>'.$e->getMessage().'</strong>';
2412
+ die();
2413
+ }
2414
+ }
2415
+ }
2416
+
2417
+ // if reCAPTCHA is not active, we will just send the request
2418
+ // without further verification
2419
+ } else {
2420
+
2421
+ // Create and store the variables needed to add a new subscriber
2422
+ $email = false;
2423
+ $lid = $fd['yks-mailchimp-list-id'];
2424
+ $api = new Mailchimp($this->optionVal['api-key']);
2425
+ $mv = array();
2426
+ $optin = $this->optionVal['optin'];
2427
+
2428
+ foreach($this->optionVal['lists'][$lid]['fields'] as $field) : if($field['active'] == '1') :
2429
+
2430
+ // Check to see if the field is in the post
2431
+ if(isset($fd[$field['name']])) :
2432
+
2433
+ // Grab the primary email
2434
+ if(strtolower($field['merge']) == 'email')
2435
+ $email = $fd[$field['name']];
2436
+
2437
+ // It exists, set the merge var that we send to mailchimp
2438
+ switch($field['type'])
2439
+ {
2440
+ default:
2441
+ $mv[$field['merge']] = $fd[$field['name']];
2442
+ break;
2443
+
2444
+ case 'address':
2445
+ $mv[$field['merge']] = array(
2446
+ 'addr1' => $fd[$field['name']],
2447
+ 'addr2' => $fd[$field['name'].'-add2'],
2448
+ 'city' => $fd[$field['name'].'-city'],
2449
+ 'state' => $fd[$field['name'].'-state'],
2450
+ 'zip' => $fd[$field['name'].'-zip'],
2451
+ 'country' => 'US'
2452
+ );
2453
+ break;
2454
+
2455
+ }
2456
+
2457
+
2458
+
2459
+ endif;
2460
+ endif; endforeach;
2461
+
2462
+ // Interest group loop to build the GROUPINGS array
2463
+ // The GROUPINGS array passes our interest group, and values back to the specific form
2464
+ if ( isset($fd['interest-group-data']) ) {
2465
+ $interest_group_option = json_decode($fd['interest-group-data'], true);
2466
+ }
2467
+ // if interest groups exist, continue and form an array
2468
+ if ( isset($interest_group_option) ) {
2469
+
2470
+ // print_r($interest_group_option);
2471
+ $mv['GROUPINGS'] = array();
2472
+
2473
+ // loop over each interest group
2474
+ foreach ($interest_group_option as $group ) :
2475
+
2476
+ switch($group['form_field'])
2477
+ {
2478
+ case 'radio':
2479
+ case 'dropdown':
2480
+ array_push($mv['GROUPINGS'], array(
2481
+ 'id' => $group['id'],
2482
+ // 'groups' => array($fd['interest-group'])
2483
+ 'groups' => array(isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2484
+ )
2485
+ );
2486
+ break;
2487
+
2488
+ case 'checkboxes':
2489
+ array_push($mv['GROUPINGS'], array(
2490
+ 'id' => $group['id'],
2491
+ // 'groups' => array($fd['interest-group'])
2492
+ 'groups' => (isset($fd[$group['form_field'].'-'.$group['id']]) ? $fd[$group['form_field'].'-'.$group['id']] : '')
2493
+ // $fd[$group['form_field'].'-'.$group['id']]
2494
+
2495
+ )
2496
+ );
2497
+ break;
2498
+ }
2499
+ endforeach; // end loop
2500
+
2501
+ }
2502
+
2503
+ // If no email provided, fail
2504
+ $noemail = "The email address is blank";
2505
+ if($email === false) return $noemail;
2506
+
2507
+ // Add custom filter here, to capture user submitted
2508
+ // data before it's sent off to MailChimp
2509
+ $form_data = apply_filters( 'yikes_mc_get_form_data' , $mv );
2510
+ $specific_form_data = apply_filters( 'yikes_mc_get_form_data_'.$lid, $lid, $mv );
2511
+
2512
+ // setup our welcome email variable
2513
+ if( isset( $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] ) && $this->optionVal['lists'][$lid]['fields'][$lid.'-email']['yks_mailchimp_send_welcome_'.$lid] == '1' ) {
2514
+ $welcome = false;
2515
+ } else {
2516
+ $welcome = true;
2517
+ }
2518
+
2519
+ // try adding subscriber, catch any error thrown
2520
+ try {
2521
+ $retval = $api->call('lists/subscribe', array(
2522
+ 'id' => $lid, // form id
2523
+ 'email' => array( 'email' => $email ), // user email
2524
+ 'merge_vars' => $form_data, // merge variables (ie: fields and interest groups)
2525
+ 'double_optin' => $optin, // double optin value (retreived from the settings page)
2526
+ 'send_welcome' => $welcome,
2527
+ 'update_existing' => $update_existing
2528
+ ));
2529
+ return "done";
2530
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
2531
+ $errorCode = $e->getCode();
2532
+ if ( $errorCode = '214' ) {
2533
+ $errorMessage = $e->getMessage();
2534
+ return json_encode( array( 'errorCode' => $errorCode , 'errorResponse' => apply_filters( 'yikes_mc_user_already_subscribed' , $errorMessage , $email ) ) );
2535
+ die();
2536
+ } else {
2537
+ echo '<strong>'.$e->getMessage().'</strong>';
2538
+ die();
2539
+ }
2540
+ }
2541
+ }
2542
+
2543
+ }
2544
+ } else {
2545
+ return __('One or more fields are empty','yikes-inc-easy-mailchimp-extender'); // return an error if your leaving any necessary fields empty
2546
+ }
2547
+ } // end addUserToMailchimp();
2548
+
2549
+
2550
+ // Generate the lists containers on the lists page
2551
+ // This function gets any imported lists, and builds up the lists page
2552
+ public function generateListContainers($listArr=false) {
2553
+ $listArr = ($listArr == false ? $this->optionVal['lists'] : $listArr);
2554
+ $thelistdata = $this->getListsData(); //Get list names from API
2555
+ // if there are any imported lists in the array
2556
+ if( count( $listArr ) > 0) {
2557
+ include YKSEME_PATH . 'lib/inc/yks-mc-manage-list-form-table.php';
2558
+ }
2559
+ $output = ob_get_contents();
2560
+ ob_end_clean();
2561
+ return $output;
2562
+ } // end generateListContainers();
2563
+
2564
+
2565
+ // Generate the Merge Variable containers on the lists page
2566
+ // we use this function to re-import merge variables from mailchimp
2567
+ public function generateMergeVariableContainers($listArr=false) {
2568
+ $listArr = ($listArr == false ? $this->optionVal['lists'] : $listArr);
2569
+ $thelistdata = $this->getListsData(); //Get list names from API
2570
+ // if there are any imported lists in the array
2571
+ if(count($listArr) > 0) {
2572
+ ob_start();
2573
+ // loop over each lists and build the page
2574
+ $i = 1;
2575
+ foreach($listArr as $list) {
2576
+ $get_list_data = $this->getListsData();
2577
+ ?>
2578
+ <td class="yks-mailchimp-fields-td" id="yks-mailchimp-fields-td_<?php echo $list['id']; ?>">
2579
+ <fieldset class="yks-mailchimp-fields-container" id="yks-mailchimp-fields-container_<?php echo $list['id']; ?>">
2580
+ <legend class="screen-reader-text"><span><?php _e( 'Active Fields' , 'yikes-inc-easy-mailchimp-extender' ); ?></span></legend>
2581
+ <div class="yks-mailchimp-fields-list" id="yks-mailchimp-fields-list_<?php echo $list['id']; ?>" rel="<?php echo $list['id']; ?>">
2582
+ <!-- create sortable rows populated with mailchimp data -->
2583
+ <?php
2584
+ $num = 1;
2585
+ foreach($list['fields'] as $field) { ?>
2586
+ <div class="yks-mailchimp-fields-list-row" alt="<?php echo $field['merge']; ?>" rel="<?php echo $field['id']; ?>">
2587
+ <!-- update labels on initial creation as well! to do-->
2588
+ <label title="Delete <?php echo $field['label']; ?> Field">
2589
+ <span class="yks-mc-delete-merge-var"><span class="dashicons dashicons-no-alt"></span></span>
2590
+ </label>
2591
+ <label title="Edit <?php echo $field['label']; ?> Field">
2592
+ <span class="yks-mc-merge-var-change"><span class="dashicons dashicons-edit"></span></span>
2593
+ </label>
2594
+ <label title="Reorder <?php echo $field['label']; ?>">
2595
+ <span class="yks-mailchimp-sorthandle"><?php _e( 'Drag' , 'yikes-inc-easy-mailchimp-extender' ); ?> &amp; <?php _e( 'drop' , 'yikes-inc-easy-mailchimp-extender' ); ?></span>
2596
+ </label>
2597
+ <label title="Toggle Visibility of <?php echo $field['label']; ?>">
2598
+ <input type="checkbox" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" value="1" <?php echo ($field['active'] == 1 ? 'checked="checked"' : ''); ?><?php echo ($field['require'] == 1 ? 'disabled="disabled"' : ''); ?> />
2599
+ </label>
2600
+ &nbsp;
2601
+ <label>
2602
+ <div class="yks-mailchimp-field-name"><?php echo $field['label']; ?></div>
2603
+ </label>
2604
+
2605
+ <!-- <span class="yks-mailchimp-field-merge"><span class="description"><?php _e( 'Merge field' , 'yikes-inc-easy-mailchimp-extender' ); ?>:</span> &nbsp; <input type="text" class="merge_field_input" name="<?php echo $field['name']; ?>-merge" id="<?php echo $field['id']; ?>-merge" value="<?php echo $field['merge']; ?>"<?php echo (($field['locked'] == 1 || $field['merge'] == false) ? ' disabled="disabled"' : ''); ?> /></span> -->
2606
+ <span class="yks-mailchimp-field-placeholder"><span class="description"><?php _e( 'Placeholder' , 'yikes-inc-easy-mailchimp-extender' ); ?>:</span> &nbsp; <input type="text" class="custom-placeholder-field" name="placeholder-<?php echo $list['id'].'-'.$num; ?>" id="<?php echo $field['id']; ?>-placeholder" placeholder="<?php echo $field['label']; ?>" value="<?php if(isset($field['placeholder-'.$list['id'].'-'.$num])) { echo $field['placeholder-'.$list['id'].'-'.$num]; } ?>" /></span>
2607
+ <span class="yks-mailchimp-field-custom-field-class"><span class="description"><?php _e( 'Custom Class' , 'yikes-inc-easy-mailchimp-extender' ); ?>:</span> &nbsp; <input type="text" name="custom-field-class-<?php echo $list['id'].'-'.$num; ?>" id="<?php echo $field['id']; ?>-custom-field-class" value="<?php if(isset($field['custom-field-class-'.$list['id'].'-'.$num])) { echo $field['custom-field-class-'.$list['id'].'-'.$num]; } ?>" /></span>
2608
+ </div>
2609
+ <?php
2610
+ $num++;
2611
+ } ?>
2612
+ </div>
2613
+ </fieldset>
2614
+ </td>
2615
+ <?php
2616
+ $i++;
2617
+ }
2618
+ }
2619
+ $output = ob_get_contents();
2620
+ ob_end_clean();
2621
+ return $output;
2622
+ } // end generateMergeVariableContainers();
2623
+
2624
+ // Get list data
2625
+ public function getListDataRightMeow() {
2626
+ echo json_encode( $this->optionVal['lists'] );
2627
+ } // end getListDataRightMeow();
2628
+
2629
+ // Generate our front end JavaScript , used to submit forms
2630
+ public function getFrontendFormJavascript($list='') {
2631
+ if($list === '') return false;
2632
+ $js = false;
2633
+ foreach($list['fields'] as $field) : if($field['active'] == 1) :
2634
+ // Setup JavaScript
2635
+ if($field['require'] == '1') :
2636
+ $prefix = "ymce";
2637
+ $js .= "\n";
2638
+ switch($field['type']) {
2639
+
2640
+ // default
2641
+ default:
2642
+ $prefixa = "ymce";
2643
+ $js .= "if ($".$prefixa."('#".$field['id']."').val() == '')";
2644
+ $js .= "{
2645
+ msg += '<li>".$field['label']."'+'\\n</li>';
2646
+ err++;
2647
+ $".$prefixa."('#".$field['id']."').addClass('yks_error_field_required shake animated').delay(1200).queue(function(next){
2648
+ $".$prefixa."(this).removeClass('shake animated');
2649
+ next();
2650
+ });
2651
+ } else {
2652
+ $".$prefixa."('#".$field['id']."').removeClass('yks_error_field_required');
2653
+ }";
2654
+ break;
2655
+
2656
+ // address
2657
+ case 'address':
2658
+ $js .= "if($".$prefix."('#".$field['id']."').val() == '') {
2659
+ msg += '<li>Street Address'+'\\n</li>';
2660
+ err++;
2661
+ $".$prefixa."('#".$field['id']."').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2662
+ $".$prefixa."(this).removeClass('shake animated');
2663
+ next();
2664
+ });
2665
+ } else {
2666
+ $".$prefixa."('#".$field['id']."').removeClass('yks_error_field_required')
2667
+ }
2668
+
2669
+ if($".$prefix."('#".$field['id']."-city').val() == '') {
2670
+ msg += '<li>City'+'\\n</li>';
2671
+ err++;
2672
+ $".$prefixa."('#".$field['id']."-city').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2673
+ $".$prefixa."(this).removeClass('shake animated');
2674
+ next();
2675
+ });
2676
+ } else {
2677
+ $".$prefixa."('#".$field['id']."-city').removeClass('yks_error_field_required')
2678
+ }
2679
+ if($".$prefix."('#".$field['id']."-state').val() == '') {
2680
+ msg += '<li>State'+'\\n</li>';
2681
+ err++;
2682
+ $".$prefixa."('#".$field['id']."-state').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2683
+ $".$prefixa."(this).removeClass('shake animated');
2684
+ next();
2685
+ });
2686
+ } else {
2687
+ $".$prefixa."('#".$field['id']."-state').removeClass('yks_error_field_required')
2688
+ }
2689
+ if($".$prefix."('#".$field['id']."-zip').val() == '') {
2690
+ msg += '<li>Zip Code'+'\\n</li>';
2691
+ err++;
2692
+ $".$prefixa."('#".$field['id']."-zip').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2693
+ $".$prefixa."(this).removeClass('shake animated');
2694
+ next();
2695
+ });
2696
+ } else {
2697
+ $".$prefixa."('#".$field['id']."-zip').removeClass('yks_error_field_required')
2698
+ }";
2699
+ break;
2700
+
2701
+ // radio
2702
+ case 'radio':
2703
+ $js .= "if($".$prefix."('.".$field['name'].":checked').length <= 0) {
2704
+ msg += '<li>".$field['label']."\\n</li>';
2705
+ err++;
2706
+ $".$prefixa."('label[for=".$field['id']."]').next().find('input').addClass('yks_error_field_required shake animated').delay(800).queue(function(next){
2707
+ $".$prefixa."(this).removeClass('shake animated');
2708
+ next();
2709
+ });
2710
+ } else {
2711
+ $".$prefixa."('#".$field['id']."').removeClass('yks_error_field_required')
2712
+ }";
2713
+ break;
2714
+ }
2715
+
2716
+ $js .= "\n";
2717
+ endif;
2718
+ endif; endforeach;
2719
+ return $js;
2720
+ } // end getFrontendFormJavascript();
2721
+
2722
+ // Generate the form on the front end of the site
2723
+ // this is what the user will see, and interact with
2724
+ public function getFrontendFormDisplay($list='', $submit_text) {
2725
+ if($list === '') return false;
2726
+ ob_start();
2727
+ include YKSEME_PATH . 'lib/inc/yks-mc-frontend-form-display.php';
2728
+ $output = ob_get_contents();
2729
+ ob_end_clean();
2730
+ return $output;
2731
+ }
2732
+
2733
+ // Generate the input fields for the form on the front end of the site
2734
+ // based on the $field['type'] that is returned from MailChimp
2735
+ private function getFrontendFormDisplay_field( $field = false , $num ) {
2736
+ if($field === false) return false;
2737
+ $o = '';
2738
+ $fieldID = $field['id'];
2739
+ $exploded_field_id = explode( '-' , $fieldID );
2740
+ $form_id = $exploded_field_id[1];
2741
+ // print_r($field);
2742
+
2743
+ $class_title = 'yks-mc-input-' . sanitize_title( $field['label'] );
2744
+
2745
+ // check to see if the custom class has been set up...
2746
+ if ( isset( $field['custom-field-class-'.$form_id.'-'.$num] ) ) {
2747
+ $custom_class = $field['custom-field-class-'.$form_id.'-'.$num];
2748
+ } else {
2749
+ $custom_class = '';
2750
+ }
2751
+
2752
+ // check to see if the placeholder value has been stored
2753
+ // setup the placeholder field
2754
+ if ( isset( $field['placeholder-'.$form_id.'-'.$num] ) ) {
2755
+ $placeholder = $field['placeholder-'.$form_id.'-'.$num];
2756
+ } else {
2757
+ $placeholder = '';
2758
+ }
2759
+
2760
+ switch( $field['type'] ) {
2761
+ default:
2762
+ case 'email':
2763
+ case 'number':
2764
+ case 'zipcode':
2765
+ case 'phone':
2766
+ case 'website':
2767
+ case 'imageurl':
2768
+ // custom placeholder value goes here
2769
+ $o .= '<input type="text" name="'.$field['name'].'" placeholder="'.$placeholder.'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : '') . ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="" />';
2770
+ break;
2771
+
2772
+ case 'text':
2773
+ if ( $field['default'] ) {
2774
+
2775
+ $custom_tag_array = apply_filters( 'yikes_mailchimp_default_value_tag' , $custom_tag_array=array() );
2776
+
2777
+ /*
2778
+ Lets Setup The Default Merge Variables Here
2779
+ example : {post_title} , {post_id} , {page_url} , {user_logged_in}, {blog_name}
2780
+ */
2781
+ global $post;
2782
+
2783
+ switch ( $field['default'] ) {
2784
+
2785
+ case '{post_title}' :
2786
+ $field['default'] = get_the_title( $post->ID );
2787
+ break;
2788
+
2789
+ case '{post_id}' :
2790
+ $field['default'] = $post->ID;
2791
+ break;
2792
+
2793
+ case '{page_url}' :
2794
+ $field['default'] = get_bloginfo( 'url' ) . $_SERVER['REQUEST_URI'];
2795
+ break;
2796
+
2797
+ case '{blog_name}' :
2798
+ $field['default'] = get_bloginfo( 'name' );
2799
+ break;
2800
+
2801
+ case '{user_logged_in}' :
2802
+ if ( is_user_logged_in() ) {
2803
+ $field['default'] = 'Registered User';
2804
+ } else {
2805
+ $field['default'] = 'Guest';
2806
+ }
2807
+ break;
2808
+
2809
+ case in_array( $field['default'] , $custom_tag_array ) :
2810
+ $field['default'] = apply_filters( 'yikes_mailchimp_process_default_value_tag' , $field );
2811
+ break;
2812
+
2813
+ default:
2814
+ $field['default'] = $field['default'];
2815
+ break;
2816
+
2817
+ }
2818
+
2819
+ }
2820
+ $o .= '<input type="text" placeholder="'.$placeholder.'" name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : '') . ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="'.$field['default'].'" />';
2821
+ break;
2822
+
2823
+ case 'dropdown':
2824
+ $o .= '<select name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'">';
2825
+ if(count($field['choices']) > 0) : foreach($field['choices'] as $ok => $ov) :
2826
+ $o .= '<option value="'.htmlentities($ov, ENT_QUOTES).'">'.$ov.'</option>';
2827
+ endforeach; endif;
2828
+ $o .= '</select>';
2829
+ break;
2830
+
2831
+ case 'address':
2832
+ $o .= '<input type="text" placeholder="'.$placeholder.'" name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="" /><span class="yks-mailchimp-form-tooltip">Street Address</span>';
2833
+ $o .= '<input type="text" name="'.$field['name'].'-add2" class="'.$field['name'].'-add2'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-add2" value="" /><span class="yks-mailchimp-form-tooltip">Apt/Suite</span>';
2834
+ $o .= '<input type="text" name="'.$field['name'].'-city" class="'.$field['name'].'-city'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-city" value="" /><span class="yks-mailchimp-form-tooltip">City</span>';
2835
+ $o .= '<input type="text" name="'.$field['name'].'-state" class="'.$field['name'].'-state'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-state" value="" /><span class="yks-mailchimp-form-tooltip">State</span>';
2836
+ $o .= '<input type="text" name="'.$field['name'].'-zip" class="'.$field['name'].'-zip'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'-zip" value="" /><span class="yks-mailchimp-form-tooltip">Zip</span>';
2837
+ break;
2838
+
2839
+ case 'radio':
2840
+ if(count($field['choices']) > 0) : $ct=0; foreach($field['choices'] as $ok => $ov) :
2841
+ $ct++;
2842
+ $o .= '<label class="yks_mc_interest_group_label" for="'.$field['id'].'-'.$ok.'">
2843
+ <input type="radio" name="'.$field['name'].'" class="'.$field['name'].($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .' yikes_mc_interest_group_checkbox" id="'.$field['id'].'-'.$ok.'" value="'.htmlentities($ov, ENT_QUOTES).'" />
2844
+ <span>'.$ov.'</span>
2845
+ </label>';;
2846
+ endforeach; endif;
2847
+ break;
2848
+
2849
+ case 'date':
2850
+ case 'birthday':
2851
+ $o .= '<input placeholder="'.$placeholder.'" type="text" name="'.$field['name'].'" class="'.$field['name'].' yks-field-type-date'.($field['require'] == 1 ? ' yks-require' : ''). ' ' . $custom_class . ' ' . $class_title .'" id="'.$field['id'].'" value="" />';
2852
+ break;
2853
+
2854
+ }
2855
+
2856
+ return $o;
2857
+ }
2858
+
2859
+
2860
+ /***** UPDATES
2861
+ ****************************************************************************************************/
2862
+ public function runUpdateTasks() {
2863
+ $currentVersion = (!isset($this->optionVal['version']) || empty($this->optionVal['version']) ? '5.0.3' : $this->optionVal['version']);
2864
+ $latestVersion = YKSEME_VERSION_CURRENT;
2865
+ if($currentVersion < $latestVersion)
2866
+ {
2867
+ $updateFunction = 'runUpdateTasks_'.str_replace('.', '_', $currentVersion);
2868
+ if(!method_exists($this, $updateFunction)) return false;
2869
+ else
2870
+ {
2871
+ if(call_user_func(array(&$this, $updateFunction)))
2872
+ {
2873
+ update_option( YKSEME_OPTION, YKSEME_VERSION_CURRENT );
2874
+ $this->runUpdateTasks();
2875
+ }
2876
+ }
2877
+ }
2878
+ else return false;
2879
+ }
2880
+
2881
+ /**
2882
+ * This update makes the first name and last name optional
2883
+ * To do this we need to loop through the existing fields and
2884
+ * change the 'require' key to 0
2885
+ *
2886
+ * 1.1.0 => 1.2.0
2887
+ */
2888
+ private function runUpdateTasks_1_1_0() {
2889
+ if($this->optionVal['lists']) {
2890
+ foreach($this->optionVal['lists'] as $lid => $list) {
2891
+ foreach($list['fields'] as $fid => $field) {
2892
+ switch($field['name']) {
2893
+ case 'yks-mailchimp-field-name-first':
2894
+ case 'yks-mailchimp-field-name-last':
2895
+ $this->optionVal['lists'][$lid]['fields'][$fid]['locked'] = 0;
2896
+ break;
2897
+ }
2898
+ }
2899
+ }
2900
+ }
2901
+ $this->optionVal['version'] = '1.2.0';
2902
+ return true;
2903
+ }
2904
+
2905
+ /**
2906
+ * This update adds a merge_vars key to each
2907
+ * field array so that users can specify their
2908
+ * own merge_var names
2909
+ *
2910
+ * 1.2.0 => 1.3.0
2911
+ */
2912
+ private function runUpdateTasks_1_2_0() {
2913
+ if($this->optionVal['lists']) {
2914
+ foreach($this->optionVal['lists'] as $lid => $list) {
2915
+ $fct = 1;
2916
+ foreach($list['fields'] as $fid => $field) {
2917
+ switch($field['name']) {
2918
+
2919
+ case 'yks-mailchimp-field-email':
2920
+ $this->optionVal['lists'][$lid]['fields'][$fid]['merge'] = 'EMAIL';
2921
+ break;
2922
+
2923
+ case 'yks-mailchimp-field-apt-suite':
2924
+ case 'yks-mailchimp-field-city':
2925
+ case 'yks-mailchimp-field-state':
2926
+ case 'yks-mailchimp-field-zip':
2927
+ $this->optionVal['lists'][$lid]['fields'][$fid]['merge'] = false;
2928
+ break;
2929
+
2930
+ default:
2931
+ if(empty($this->optionVal['lists'][$lid]['fields'][$fid]['merge']) || !isset($this->optionVal['lists'][$lid]['fields'][$fid]['merge']))
2932
+ $this->optionVal['lists'][$lid]['fields'][$fid]['merge'] = 'MERGE'.$fct;
2933
+ $fct++;
2934
+ break;
2935
+ }
2936
+ }
2937
+ }
2938
+ }
2939
+ $this->optionVal['version'] = '1.3.0';
2940
+ return true;
2941
+ }
2942
+
2943
+ /**
2944
+ * This update needs to pull in all of the custom form
2945
+ * data for each of the lists, unfortunately it has to replace
2946
+ * just about all of the data with the new schema. We also
2947
+ * add in the flavor key (for table/div usage)
2948
+ *
2949
+ * 4.3 => 5.0.4
2950
+ */
2951
+ private function runUpdateTasks_4_3() {
2952
+ if ( !isset( $this->optionVal['recaptcha-setting'] ) ) {
2953
+ $this->optionVal['recaptcha-setting'] = '0';
2954
+ }
2955
+ if ( !isset( $this->optionVal['recaptcha-api-key'] ) ) {
2956
+ $this->optionVal['recaptcha-api-key'] = '';
2957
+ }
2958
+ if ( !isset( $this->optionVal['recaptcha-private-api-key'] ) ) {
2959
+ $this->optionVal['recaptcha-private-api-key'] = '';
2960
+ }
2961
+ $this->optionVal['version'] = '5.0.4';
2962
+ return true;
2963
+ }
2964
+
2965
+ /** Update/Add New Merge Variables and Interest Group Containers */
2966
+
2967
+ // generate a container to allow for creating new merge variables (form fields)
2968
+ function generateNewMergeVariableContainer() {
2969
+ include YKSEME_PATH . 'lib/inc/yks-mc-new-merge-variable-container.php';
2970
+ }
2971
+
2972
+ // generate a container to allow for editing merge variables
2973
+ function generateMergeVariableUpdateContainer() {
2974
+ $delete_icon = '<span class="dashicons dashicons-no-alt remove-radio-dropdown-option"></span>';
2975
+ include YKSEME_PATH . 'lib/inc/yks-mc-update-merge-variable-container.php';
2976
+ }
2977
+
2978
+ // generate a container to allow for creating new interest groups
2979
+ public function generateCreateInterestGroupContainer() {
2980
+ include YKSEME_PATH . 'lib/inc/yks-mc-create-interest-group-container.php';
2981
+ }
2982
+
2983
+ // end merge variable and interest group containers
2984
+
2985
+ // generate a thickbox container
2986
+ // to display a preview of the form
2987
+ function generateFormPreviewContainer() {
2988
+ ?>
2989
+ <div id="formPreviewContainer" style="display:none;">
2990
+ <?php echo '<img src="' . admin_url() . '/images/wpspin_light.gif" alt="preloader" style="margin-left: 50%; margin-top: 25%;">'; ?>
2991
+ </div>
2992
+ <?php
2993
+ }
2994
+
2995
+ // generate a thickbox container
2996
+ // to display a how to in using custom template files
2997
+ function generateUserTemplateHowTo() {
2998
+ ?>
2999
+ <div id="user_template_how_to" style="display:none;">
3000
+ <a href="http://www.yikesinc.com" title="YIKES, Inc." target="_blank"><img style="float:left;margin-bottom:0;width:75px;" src="<?php echo YKSEME_URL; ?>/images/yikes_logo.png" alt="YIKES, Inc." id="yksme-yikes-logo" /></a>
3001
+ <h4 class="user_template_how_to_title"><?php _e( 'Custom User Template Files' , 'yikes-inc-easy-mailchimp-extender' ); ?></h4>
3002
+
3003
+ <p style="margin-top: 2.5em;" ><?php _e( 'With the latest version of YIKES Inc. Easy MailChimp Extender you can now extend the plugin beyond what it can do out of the box. Now you can create your own MailChimp sign up template files and use them with any list , anywhere on your site. We have provided you with a few bundled templates, as well as two boilerplate template files for easy customization.' , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
3004
+
3005
+ <p><?php _e( 'You can create your own templates in two ways.' , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
3006
+ <hr />
3007
+ <ul>
3008
+ <li><h4><?php _e( 'Automatic Method :' , 'yikes-inc-easy-mailchimp-extender' ); ?></h4><p><?php _e( "The easiest way is to import the template files from the plugin automatically. You can do this by clicking on the 'import boilerplate files' button. This will copy over the necessary files right into your theme. From there you can start editing the template files found in your theme root inside of the newly created 'yikes-inc-easy-mailchimp-extender' directory." , "yikes-inc-easy-mailchimp-extender" ); ?></p></li>
3009
+ <a href="#" onclick="return false;" class="button-secondary import_template_boilerplates" style="width:148px;display:block;margin:0 auto;"><?php _e( "import boilerplate files" , "yikes-inc-easy-mailchimp-extender" ); ?></a>
3010
+ <hr />
3011
+ <li><h4><?php _e( 'Manual Method' , 'yikes-inc-easy-mailchimp-extender' ); ?> :</h4><p><?php _e( "If the automatic method doesn't work for you, you can manually copy over the necessary files." , 'yikes-inc-easy-mailchimp-extender' ); ?></p> <p><?php _e( "Copy the following directory" , "yikes-inc-easy-mailchimp-extender" ); ?> :<br /> <em class="yks-mc-file-path"><?php echo YKSEME_PATH . 'templates/yikes-mailchimp-user-templates'; ?></em> <br /><?php _e( " into your theme root, found at " , "yikes-inc-easy-mailchimp-extender" ); ?><br /> <em class="yks-mc-file-path"><?php echo get_stylesheet_directory_uri(); ?></em></p></li>
3012
+ <hr />
3013
+ <li><h5><?php _e( "Notes" , "yikes-inc-easy-mailchimp-extender" ); ?></h5></li>
3014
+ <ul>
3015
+ <li><p><?php _e( "You can also copy over any of the default bundled themes into the 'yikes-mailchimp-user-templates' directory to customize the look and feel of a default bundled template file." , "yikes-inc-easy-mailchimp-extender" ); ?></p></li>
3016
+ <li><p><?php _e( "If you are having any difficulties copying over the template files, or need help using them please open a support ticket on our" , "yikes-inc-easy-mailchimp-extender" ); ?> <a href="https://github.com/yikesinc/yikes-inc-easy-mailchimp-extender/issues" target="_blank"><?php _e( "github issue tracker" , "yikes-inc-easy-mailchimp-extender" ); ?></a>.</p></li>
3017
+ </ul>
3018
+ </div>
3019
+ <?php
3020
+ }
3021
+
3022
+ // generate a thickbox container
3023
+ // to display a preview of the form
3024
+ function getFormPreview($shortcode,$form_title,$form_bg_color,$form_text_color,$form_submit_button_color,$form_submit_button_text_color,$form_padding,$form_width,$form_alignment) {
3025
+ ?>
3026
+ <h4 style="width:100%;text-align:center;">"<?php echo trim( $form_title ); ?>" Form Preview</h4>
3027
+ <div class="yks_mc_preview_form_container"><?php echo do_shortcode( stripslashes( $shortcode ) ); ?></div>
3028
+ <!-- override the styles for our preview container -->
3029
+ <style>
3030
+ .yks-mailchimpFormContainer {
3031
+ background: <?php echo $form_bg_color; ?> !important;
3032
+ padding: <?php echo $form_padding; ?> !important;
3033
+ color: <?php echo $form_text_color; ?> !important;
3034
+ width: <?php echo $form_width; ?> !important;
3035
+ <?php
3036
+ if ( $form_alignment == 'left' ) {
3037
+ ?>
3038
+ display: block;
3039
+ float: left;
3040
+ <?php
3041
+ } elseif ( $form_alignment == 'center' ) {
3042
+ ?>
3043
+ display: block;
3044
+ margin: 0 auto;
3045
+ <?php
3046
+ } elseif ( $form_alignment == 'right' ) {
3047
+ ?>
3048
+ display: block;
3049
+ float: right;
3050
+ <?php
3051
+ }
3052
+ ?>
3053
+ }
3054
+ .yks-mailchimpFormDivRowLabel, .yks_mc_interest_group_label, .yks-mailchimp-form-tooltip {
3055
+ color: <?php echo $form_text_color; ?> !important;
3056
+ }
3057
+ .ykfmc-submit {
3058
+ background: <?php echo $form_submit_button_color; ?> !important;
3059
+ color: <?php echo $form_submit_button_text_color; ?> !important;
3060
+ }
3061
+ .yks_mc_interest_group_holder input[type=radio], .yks_mc_interest_group_holder input[type=checkbox] {
3062
+ margin:0 5px 0 0 !important;
3063
+ }
3064
+ body.mailchimp-forms_page_yks-mailchimp-form-lists form[name="yks-mailchimp-form"] {
3065
+ padding: 0 !important;
3066
+ }
3067
+ </style>
3068
+ <?php
3069
+ }
3070
+
3071
+ // Get the selected form template screenshot
3072
+ function getTemplateScreenshot( $template_name , $template_screenshot , $template_path ) {
3073
+
3074
+ $default_headers = array(
3075
+ 'YIKES Inc. MailChimp Template',
3076
+ 'YIKES Inc. MailChimp Template Author',
3077
+ 'YIKES Inc. MailChimp Template Description'
3078
+ );
3079
+ // end pre-packaged templates
3080
+ $template_file_data = get_file_data( $template_path , $default_headers );
3081
+
3082
+ ?>
3083
+ <div id="selected_template_preview_container">
3084
+ <span class="selected_template_preview_header">
3085
+ <h3 class="template_name"><?php echo $template_name; ?></h3>
3086
+
3087
+ <p class="template_author"><strong><?php _e( "Author " , "yikes-inc-easy-mailchimp-extender" ); ?> :</strong> <em> <?php echo $template_file_data[1]; ?></em></p>
3088
+ </span>
3089
+
3090
+ <p><strong><?php _e( "Description" , "yikes-inc-easy-mailchimp-extender" ); ?> :</strong> <?php echo $template_file_data[2]; ?></p>
3091
+
3092
+ <hr />
3093
+
3094
+ <img class="template_screenshot preview_template_screenshot" style="max-width:100%;" src="<?php echo YKSEME_URL . 'templates/yikes-mailchimp-bundled-templates/' . str_replace( ' ' , '_' , $template_name ) . '/' . $template_screenshot; ?>">
3095
+ </div>
3096
+ <?php
3097
+ }
3098
+
3099
+ /**
3100
+ * This update needs to pull in all of the custom form
3101
+ * data for each of the lists, unfortunately it has to replace
3102
+ * just about all of the data with the new schema. We also
3103
+ * add in the flavor key (for table/div usage)
3104
+ *
3105
+ * 1.3.0 => 2.0.0
3106
+ */
3107
+ private function runUpdateTasks_1_3_0() {
3108
+ $this->optionVal['flavor'] = '0';
3109
+ $this->optionVal['debug'] = '0';
3110
+ if( $this->optionVal['lists'] ) {
3111
+ foreach($this->optionVal['lists'] as $uid => $list) {
3112
+ unset($this->optionVal['lists'][$uid]);
3113
+ $this->addList($list['list-id']);
3114
+ }
3115
+ }
3116
+ $this->optionVal['version'] = '2.2.1';
3117
+ return true;
3118
+ }
3119
+
3120
+ // Copy the user template file from within the plugin
3121
+ // into the users theme root
3122
+ public function copyUserTemplatesToUserTheme() {
3123
+ $src = YKSEME_PATH . 'templates/yikes-mailchimp-user-templates';
3124
+ $dst = get_stylesheet_directory() . '/yikes-mailchimp-user-templates';
3125
+
3126
+ function recurse_copy($src,$dst) {
3127
+ $dir = opendir($src);
3128
+ // mkdir( $dst . '/yiks-mailchimp-user-templates/' );
3129
+ mkdir( $dst );
3130
+ while(false !== ( $file = readdir($dir)) ) {
3131
+ if (( $file != '.' ) && ( $file != '..' )) {
3132
+ if ( is_dir($src . '/' . $file) ) {
3133
+ recurse_copy($src . '/' . $file,$dst . '/' . $file);
3134
+ }
3135
+ else {
3136
+ copy($src . '/' . $file,$dst . '/' . $file);
3137
+ }
3138
+ }
3139
+ }
3140
+ closedir($dir);
3141
+ }
3142
+ recurse_copy( $src , $dst );
3143
+ }
3144
+
3145
+ /*
3146
+ generateRandomString();
3147
+ @since v5.2
3148
+ Generate a random string of text and numbers for merge variable creation
3149
+ */
3150
+ public function randomMergeVarString($length = 5) {
3151
+ $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3152
+ $randomString = '';
3153
+ for ($i = 0; $i < $length; $i++) {
3154
+ $randomString .= $characters[rand(0, strlen($characters) - 1)];
3155
+ }
3156
+ echo $randomString;
3157
+ }
3158
+
3159
+ /*
3160
+ deleteInterestGroupFromList();
3161
+ @since v5.2
3162
+ Delete an interest group from a given list
3163
+ */
3164
+ public function deleteInterestGroupFromList($mc_list_id,$interest_group_id) {
3165
+ $api = new Mailchimp($this->optionVal['api-key']);
3166
+ try {
3167
+ $retval = $api->call('lists/interest-grouping-del', array(
3168
+ 'id' => $mc_list_id,
3169
+ 'grouping_id' => $interest_group_id
3170
+ ));
3171
+ return "done";
3172
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3173
+ $errorMessage = $e->getMessage();
3174
+ echo $errorMessage;
3175
+ // write our error to the error log,
3176
+ // when advanced debug is enabled
3177
+ if ( $this->optionVal['debug'] == 1 ) {
3178
+ $this->writeErrorToErrorLog( $e );
3179
+ }
3180
+ die();
3181
+ }
3182
+ }
3183
+
3184
+ /*
3185
+ createNewInterestGroup();
3186
+ @since v5.2
3187
+ Delete an interest group from a given list
3188
+ */
3189
+ public function createNewInterestGroup($p) {
3190
+
3191
+ $api = new Mailchimp($this->optionVal['api-key']);
3192
+ parse_str( $p['form_data'], $formData );
3193
+ $list_id = $formData['mc-list-id'];
3194
+ $grouping_name = $formData['add-interest-group-name'];
3195
+ $grouping_type = $formData['add-interest-group-type'];
3196
+ $grouping_groups = $formData['radio-dropdown-option'];
3197
+
3198
+ try {
3199
+ $retval = $api->call('lists/interest-grouping-add', array(
3200
+ 'id' => $list_id,
3201
+ 'name' => $grouping_name,
3202
+ 'type' => $grouping_type,
3203
+ 'groups' => $grouping_groups
3204
+ ));
3205
+ return "done";
3206
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3207
+ $errorMessage = $e->getMessage();
3208
+ echo $errorMessage;
3209
+ // write our error to the error log,
3210
+ // when advanced debug is enabled
3211
+ if ( $this->optionVal['debug'] == 1 ) {
3212
+ $this->writeErrorToErrorLog( $e );
3213
+ }
3214
+ die();
3215
+ }
3216
+ }
3217
+
3218
+ /*
3219
+ updateInterestGroup();
3220
+ @since v5.2
3221
+ Update an interest group from a given list
3222
+ */
3223
+ public function updateInterestGroup( $mailchimp_list_id , $grouping_id , $previous_value , $new_value ) {
3224
+
3225
+ $api = new Mailchimp($this->optionVal['api-key']);
3226
+
3227
+ try {
3228
+ $retval = $api->call('lists/interest-group-update', array(
3229
+ 'id' => $mailchimp_list_id,
3230
+ 'old_name' => $previous_value,
3231
+ 'new_name' => $new_value,
3232
+ 'grouping_id' => $grouping_id
3233
+ ));
3234
+ return "done";
3235
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3236
+ if ( $e->getCode() == 211 ) {
3237
+ return "done";
3238
+ } else {
3239
+ $errorMessage = $e->getMessage();
3240
+ echo $errorMessage;
3241
+ // write our error to the error log,
3242
+ // when advanced debug is enabled
3243
+ if ( $this->optionVal['debug'] == 1 ) {
3244
+ $this->writeErrorToErrorLog( $e );
3245
+ }
3246
+ }
3247
+ die();
3248
+ }
3249
+ }
3250
+
3251
+ /*
3252
+ updateInterestGroupingTitle();
3253
+ @since v5.2
3254
+ Update an interest group from a given list
3255
+ */
3256
+ public function updateInterestGroupingTitle( $mailchimp_list_id , $grouping_id , $value ) {
3257
+
3258
+ $api = new Mailchimp($this->optionVal['api-key']);
3259
+
3260
+ try {
3261
+ $retval = $api->call('lists/interest-grouping-update', array(
3262
+ 'grouping_id' => $grouping_id,
3263
+ 'name' => 'name',
3264
+ 'value' => $value
3265
+ ));
3266
+ return "done";
3267
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3268
+ $errorMessage = $e->getMessage();
3269
+ $errorCode = $e->getCode();
3270
+ echo $errorMessage;
3271
+ // write our error to the error log,
3272
+ // when advanced debug is enabled
3273
+ if ( $this->optionVal['debug'] == 1 ) {
3274
+ $this->writeErrorToErrorLog( $e );
3275
+ }
3276
+ die();
3277
+ }
3278
+ }
3279
+
3280
+ /*
3281
+ addInterestGroupOption();
3282
+ @since v5.2
3283
+ Update an interest group from a given list
3284
+ */
3285
+ public function addInterestGroupOption( $mailchimp_list_id , $group_name , $grouping_id ) {
3286
+
3287
+ $api = new Mailchimp($this->optionVal['api-key']);
3288
+
3289
+ try {
3290
+ $retval = $api->call('lists/interest-group-add', array(
3291
+ 'id' => $mailchimp_list_id,
3292
+ 'group_name' => $group_name,
3293
+ 'grouping_id' => $grouping_id
3294
+ ));
3295
+ return "done";
3296
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3297
+ $errorMessage = $e->getMessage();
3298
+ echo $errorMessage;
3299
+ // write our error to the error log,
3300
+ // when advanced debug is enabled
3301
+ if ( $this->optionVal['debug'] == 1 ) {
3302
+ $this->writeErrorToErrorLog( $e );
3303
+ }
3304
+ die();
3305
+ }
3306
+
3307
+ }
3308
+
3309
+ /*
3310
+ deleteInterestGroupOption();
3311
+ @since v5.2
3312
+ Update an interest group from a given list
3313
+ */
3314
+ public function deleteInterestGroupOption( $mailchimp_list_id , $group_name , $grouping_id ) {
3315
+
3316
+ $api = new Mailchimp($this->optionVal['api-key']);
3317
+
3318
+ try {
3319
+ $retval = $api->call('lists/interest-group-del', array(
3320
+ 'id' => $mailchimp_list_id,
3321
+ 'group_name' => $group_name,
3322
+ 'grouping_id' => $grouping_id
3323
+ ));
3324
+ return "done";
3325
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3326
+ $errorMessage = $e->getMessage();
3327
+ echo $errorMessage;
3328
+ // write our error to the error log,
3329
+ // when advanced debug is enabled
3330
+ if ( $this->optionVal['debug'] == 1 ) {
3331
+ $this->writeErrorToErrorLog( $e );
3332
+ }
3333
+ die();
3334
+ }
3335
+ }
3336
+
3337
+ /*
3338
+ addNewFieldToList();
3339
+ @since v5.2
3340
+ MailChimp API Request to Add new field to a list
3341
+ */
3342
+ public function addNewFieldToList( $p ) {
3343
+ include YKSEME_PATH . 'lib/inc/yks-mc-add-new-field-to-list.php';
3344
+ }
3345
+
3346
+ /*
3347
+ @since v5.2
3348
+ MailChimp API Request to Add new field to a list
3349
+ */
3350
+ public function deleteFieldFromList( $mailchimp_list_id , $merge_tag ) {
3351
+ $api = new Mailchimp($this->optionVal['api-key']);
3352
+ try {
3353
+ $retval = $api->call('lists/merge-var-del', array(
3354
+ 'id' => $mailchimp_list_id, // list id to delete merge tag from
3355
+ 'tag' => $merge_tag // merge tag to be delete
3356
+ ));
3357
+ return "done";
3358
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3359
+ $errorMessage = $e->getMessage();
3360
+ echo $errorMessage;
3361
+ // write our error to the error log,
3362
+ // when advanced debug is enabled
3363
+ if ( $this->optionVal['debug'] == 1 ) {
3364
+ $this->writeErrorToErrorLog( $e );
3365
+ }
3366
+ die();
3367
+ }
3368
+ }
3369
+
3370
+ /*
3371
+ @since v5.2
3372
+ Change the interest group type
3373
+ */
3374
+ public function changeListInterestGroupType( $grouping_id , $value ) {
3375
+ $api = new Mailchimp($this->optionVal['api-key']);
3376
+ try {
3377
+ $retval = $api->call('lists/interest-grouping-update', array(
3378
+ 'grouping_id' => $grouping_id, // list id to delete merge tag from
3379
+ 'name' => 'type', // merge tag to be delete
3380
+ 'value' => $value
3381
+ ));
3382
+ return "done";
3383
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3384
+ $errorMessage = $e->getMessage();
3385
+ echo $errorMessage;
3386
+ // write our error to the error log,
3387
+ // when advanced debug is enabled
3388
+ if ( $this->optionVal['debug'] == 1 ) {
3389
+ $this->writeErrorToErrorLog( $e );
3390
+ }
3391
+ die();
3392
+ }
3393
+ }
3394
+
3395
+ /*
3396
+ @since v5.2
3397
+ MailChimp API Request to Update an existing field on a given list
3398
+ */
3399
+ public function updateListField( $p ) {
3400
+ include YKSEME_PATH . 'lib/inc/yks-mc-update-list-field.php';
3401
+ }
3402
+
3403
+ // recursive directory scanning
3404
+ // used to retreive template files from bundled+user template directories
3405
+ function buildCustomTemplateDropdown($list) {
3406
+
3407
+ $bundled_template_directory = YKSEME_PATH . 'templates/yikes-mailchimp-bundled-templates/';
3408
+ $bundled_template_scan = scandir($bundled_template_directory);
3409
+ $custom_template_directory = get_stylesheet_directory() . '/yikes-mailchimp-user-templates/';
3410
+
3411
+ // only scan the directory when files DO exist
3412
+ if( is_dir( $custom_template_directory ) ) {
3413
+ $custom_template_scan = scandir($custom_template_directory);
3414
+ }
3415
+
3416
+ echo '<select class="template-selection-dropdown" name="yks-mc-template-file-selection" >';
3417
+
3418
+ /* Bundled Template Dropdown Loop */
3419
+ echo '<optgroup label="Bundled Templates">';
3420
+ foreach( $bundled_template_scan as $bundled_template ) {
3421
+ if( $bundled_template != '.' && $bundled_template != '..' ) {
3422
+
3423
+ if( is_dir( $bundled_template_directory . $bundled_template ) ) {
3424
+ $template_path = $this->getTemplateFilePath($bundled_template_directory.$bundled_template);
3425
+ }
3426
+
3427
+ // set the selected option
3428
+ if ( $list['custom_template']['template_file'] == $template_path ) {
3429
+ echo '<option value="' . $template_path . '" selected="selected" >' . str_replace( '_' , ' ' , $bundled_template ) . '</option>';
3430
+ } else {
3431
+ echo '<option value="' . $template_path . '">' . str_replace( '_' , ' ' , $bundled_template ) . '</option>';
3432
+ }
3433
+
3434
+ }
3435
+ }
3436
+ echo '</optgroup>';
3437
+
3438
+ echo '<optgroup label="Custom Templates">';
3439
+ /* Custom Template Dropdown Loop */
3440
+ if( is_dir( get_stylesheet_directory() . '/yikes-mailchimp-user-templates' ) && count( $custom_template_scan ) >= 1 ) {
3441
+ foreach( $custom_template_scan as $custom_template ) {
3442
+ if( $custom_template != '.' && $custom_template != '..' ) {
3443
+ if( is_dir( $custom_template_directory . $custom_template ) ) {
3444
+ $custom_template_path = $this->getTemplateFilePath($custom_template_directory.$custom_template);
3445
+ }
3446
+ // set the selected option
3447
+ if ( $list['custom_template']['template_file'] == $custom_template_path ) {
3448
+ echo '<option value="' . $custom_template_path . '" selected="selected" >' . str_replace( '_' , ' ' , $custom_template ) . '</option>';
3449
+ } else {
3450
+ echo '<option value="' . $custom_template_path . '">' . str_replace( '_' , ' ' , $custom_template ) . '</option>';
3451
+ }
3452
+ }
3453
+ }
3454
+ } else {
3455
+ echo '<option value="" disabled="disabled">None Found</option>';
3456
+ }
3457
+ echo '</optgroup>';
3458
+ echo '</select>';
3459
+ }
3460
+
3461
+ // function to return our form template path
3462
+ function getTemplateFilePath($directory) {
3463
+ $get_files = scandir($directory);
3464
+ $sub_files = array();
3465
+ foreach( $get_files as $file ) {
3466
+ if($file != '.' && $file != '..') {
3467
+ $explode_file = explode( '.' , $file );
3468
+ $file_extension = $explode_file[1];
3469
+ if ( $file_extension == 'php' ) {
3470
+ $file_extension_path = $directory . '/' . $file;
3471
+ }
3472
+ }
3473
+ }
3474
+ return $file_extension_path;
3475
+ }
3476
+
3477
+ // Adding Opt-In Checkbox to comment forms
3478
+ // submit the user to mailchimp on a successful comment submission
3479
+ function ymc_add_meta_settings($comment_id) {
3480
+ add_comment_meta(
3481
+ $comment_id,
3482
+ 'mailchimp_subscribe',
3483
+ $_POST['mailchimp_subscribe'],
3484
+ true
3485
+ );
3486
+ }
3487
+
3488
+ // add the checkbox after the comment form
3489
+ function add_after_comment_form($arg) {
3490
+ $custom_text = trim($this->optionVal['yks-mailchimp-optin-checkbox-text']);
3491
+ if ( $custom_text == '' ) {
3492
+ $custom_text = __("Sign Me Up For MAILCHIMP-REPLACE-THIS-TEXT's Newsletter", "gettext");
3493
+ } else {
3494
+ $custom_text = $custom_text;
3495
+ }
3496
+ // set the default checked state here...
3497
+ $arg['comment_notes_after'] = '<label for="yikes_mailchimp_comment_subscribe">
3498
+ <input type="checkbox" name="mailchimp_subscribe" id="yikes_mailchimp_comment_subscribe" checked="checked" />
3499
+ '.$custom_text.'
3500
+ </label>';
3501
+ return $arg;
3502
+ }
3503
+
3504
+ // Replacing 'MAILCHIMP-REPLACE-THIS-TEXT' text with sitename
3505
+ function yikes_mc_replace_this_text( $text ) {
3506
+ $newtext = get_bloginfo('name');
3507
+ $text = str_replace( 'MAILCHIMP-REPLACE-THIS-TEXT', $newtext, $text );
3508
+ return $text;
3509
+ }
3510
+
3511
+ // Add our commenter to the list, when comment is submitted
3512
+ function ymc_subscription_add( $cid, $comment='' ) {
3513
+ $cid = (int) $cid;
3514
+ $yikes_api_key = $this->optionVal['api-key'];
3515
+ $exploded_api_key = explode('-',$yikes_api_key);
3516
+ $yikes_data_center = $exploded_api_key[1];
3517
+
3518
+ if ( !is_object($comment) )
3519
+ $comment = get_comment($cid);
3520
+
3521
+ if ( $comment->comment_karma == 0 ) {
3522
+ $subscribe = get_comment_meta($cid, 'mailchimp_subscribe', true);
3523
+ if ( $subscribe == 'on' ) {
3524
+ global $current_user;
3525
+ get_currentuserinfo();
3526
+ $commenter_first_name = trim($current_user->user_firstname);
3527
+ $commenter_last_name = trim($current_user->user_lastname);
3528
+
3529
+ if( isset( $commenter_first_name ) && $commenter_first_name != '' ) {
3530
+ $commenter_first_name = $commenter_first_name; // use the users first name set in the profile
3531
+ } else {
3532
+ $commenter_first_name = $comment->comment_author; // if no first name is set in the user profile, we will use the account name
3533
+ }
3534
+
3535
+ if( isset( $commenter_last_name ) && $commenter_last_name != '' ) {
3536
+ $commenter_last_name = $commenter_last_name; // use the users last name set in the profile
3537
+ } else {
3538
+ $commenter_last_name = 'n/a'; // if the user has not set a last name in their profile, we set it to n/a
3539
+ }
3540
+
3541
+ // store our API key
3542
+ // on the settings page, if they have chosen to display the checkbox
3543
+ $api = new Mailchimp($this->optionVal['api-key']);
3544
+
3545
+ $apikey = $yikes_api_key;
3546
+ $listid = $this->optionVal['yks-mailchimp-optIn-default-list']; // Need to set up a default list to subscribe all users to
3547
+ $endpoint = 'https://api.mailchimp.com';
3548
+ $optin = $this->optionVal['optin'];
3549
+
3550
+ // setup our welcome email variable
3551
+ if( isset( $this->optionVal['lists'][$listid]['fields'][$listid.'-email']['yks_mailchimp_send_welcome_'.$listid] ) && $this->optionVal['lists'][$listid]['fields'][$listid.'-email']['yks_mailchimp_send_welcome_'.$listid] == '1' ) {
3552
+ $welcome = false;
3553
+ } else {
3554
+ $welcome = true;
3555
+ }
3556
+
3557
+ // try adding subscriber, catch any error thrown
3558
+ try {
3559
+ $retval = $api->call('lists/subscribe', array(
3560
+ 'id' => $listid, // form id
3561
+ 'email' => array(
3562
+ 'email' => $comment->comment_author_email
3563
+ ),
3564
+ 'merge_vars' => array(
3565
+ 'FNAME' => $commenter_first_name,
3566
+ 'LNAME' => $commenter_last_name,
3567
+ 'NAME' => $commenter_first_name
3568
+ ),
3569
+ 'double_optin' => $optin, // double optin value (retreived from the settings page)
3570
+ 'send_welcome' => $welcome
3571
+ ));
3572
+ return "done";
3573
+ } catch( Exception $e ) { // catch any errors returned from MailChimp
3574
+ $error_message = $e->getMessage();
3575
+ if (strpos($error_message,'Click here to update your profile.') !== false) {
3576
+ $errorMessage = str_replace('Click here to update your profile.', '', $e->getMessage());
3577
+ $errorMessage_explode = explode('to list', $errorMessage);
3578
+ echo $errorMessage_explode[0].'.';
3579
+ die();
3580
+ }
3581
+ if (strpos($error_message,'Invalid') !== false) {
3582
+ $display_errorMessage = str_replace('Invalid MailChimp List ID:', "Oops! The Webmaster hasn't set up the default MailChimp list to subscribe you too. Please contact them and let them know of this error. In the meantime, un-check the subscription checkbox in the comment form when submitting comments.", $error_message);
3583
+ echo $display_errorMessage;
3584
+ die();
3585
+ } else {
3586
+ // str_replace('Invalid MailChimp List ID: .', 'The Webmaster hasn\t set up the default MailChimp list to subscribe you too. Please contact them and let them know of this error. In the meantime, un-check the subscription checkbox in the comment form when submitting comments.', $e->getMessage());
3587
+ echo $errorMessage;
3588
+ die();
3589
+ }
3590
+ }
3591
+ }
3592
+ }
3593
+ }
3594
+
3595
+ // add our actions on initialize
3596
+ // inside of __construct()
3597
+ public function ykes_mc_apply_filters() {
3598
+ // if the optin checkbox setting is set to show
3599
+ // we wiill display the checkbox on the front end
3600
+ if ( $this->optionVal['optIn-checkbox'] == 1 ) {
3601
+ add_action('comment_post', array(&$this, 'ymc_add_meta_settings'), 10, 2);
3602
+ add_action('comment_approved_', array(&$this, 'ymc_subscription_add'), 60, 2);
3603
+ add_action('comment_post', array(&$this, 'ymc_subscription_add'));
3604
+ add_filter('gettext', array(&$this, 'yikes_mc_replace_this_text'));
3605
+ // only display the checkbox if the user is logged in, and the default list is set
3606
+ if( is_user_logged_in() && isset( $this->optionVal['yks-mailchimp-optIn-default-list'] ) && $this->optionVal['yks-mailchimp-optIn-default-list'] != 'select_value' ) {
3607
+ add_filter('comment_form_defaults', array(&$this, 'add_after_comment_form'));
3608
+ }
3609
+ }
3610
+ }
3611
+
3612
+
3613
+ /****
3614
+ **
3615
+ ** Custom The_Content filter
3616
+ ** used to prevent other plugins from hooking here
3617
+ **
3618
+ ****/
3619
+ function yks_mc_content() {
3620
+ //Create our own version of the_content so that others can't accidentally loop into our output - Taken from default-filters.php, shortcodes.php, and media.php
3621
+ if ( !has_filter( 'yks_mc_content', 'wptexturize' ) ) {
3622
+ add_filter( 'yks_mc_content', 'wptexturize' );
3623
+ add_filter( 'yks_mc_content', 'convert_smilies' );
3624
+ add_filter( 'yks_mc_content', 'convert_chars' );
3625
+ add_filter( 'yks_mc_content', 'wpautop' );
3626
+ add_filter( 'yks_mc_content', 'shortcode_unautop' );
3627
+ add_filter( 'yks_mc_content', 'prepend_attachment' );
3628
+ $vidembed = new WP_Embed();
3629
+ add_filter( 'yks_mc_content', array( &$vidembed, 'run_shortcode'), 8 );
3630
+ add_filter( 'yks_mc_content', array( &$vidembed, 'autoembed'), 8 );
3631
+ add_filter( 'yks_mc_content', 'do_shortcode', 11);
3632
+ } //end has_filter
3633
+ } //end yks_mc_content
3634
+
3635
+
3636
+ // Check if cURL is enabled at the server level
3637
+ // used on the options.php page
3638
+ public function yikes_curl_check() {
3639
+ if (in_array ('curl', get_loaded_extensions())) {
3640
+ return true;
3641
+ } else {
3642
+ return false;
3643
+ }
3644
+ }
3645
+
3646
+ // check if php.ini exists in the site root
3647
+ function yks_check_if_php_ini_exists() {
3648
+
3649
+ // get php ini path from the actively loaded php ini file
3650
+ $wordpress_site_root = str_replace('php.ini','',php_ini_loaded_file());
3651
+ // file name
3652
+ $filename = '/php.ini';
3653
+
3654
+ $php_ini_location = php_ini_loaded_file();
3655
+
3656
+ if (file_exists($wordpress_site_root.$filename)) {
3657
+ echo "<span class='yks_mc_no_phpini_success'>Good News </span>: We have located your <strong>".str_replace('/','',$filename)."</strong> file inside the directory <strong>".$wordpress_site_root."</strong>";
3658
+ $filename = '/php.ini';
3659
+ } else {
3660
+ echo "<span class='yks_mc_no_phpini_alert'>Alert </span>: No <strong>".str_replace('/','',$filename)."</strong> was located in <strong>".$wordpress_site_root.'/'."</strong>.";
3661
+ $filename = '/php.ini';
3662
+ }
3663
+
3664
+ }
3665
+
3666
+ // display the php.ini location to the user
3667
+ function yks_display_php_ini_location() {
3668
+ echo php_ini_loaded_file();
3669
+ }
3670
+
3671
+
3672
+ // Add TinyMCE Buttons to the TinyMCE Editor
3673
+ // We'll use the button to place form shortcodes!
3674
+ // NOTE: This only runs on 3.9 or greater -> due to tinyMCE 4.0
3675
+ // Custom TinyMCE Button to insert form shortcodes onto pages and posts
3676
+ function yks_mc_add_tinyMCE() {
3677
+ global $typenow;
3678
+ // only on Post Type: post and page
3679
+ if( ! in_array( $typenow, array( 'post', 'page' ) ) ) {
3680
+ return ;
3681
+ }
3682
+ }
3683
+
3684
+ // inlcude the js for tinymce
3685
+ function yks_mc_add_tinymce_plugin( $plugin_array ) {
3686
+ $plugin_array['yks_mc_tinymce_button'] = plugins_url( '/../js/yks_mc_tinymce_button.js', __FILE__ );
3687
+ // Print all plugin js path
3688
+ // var_dump( $plugin_array );
3689
+ return $plugin_array;
3690
+ }
3691
+
3692
+ // Add the button key for address via JS
3693
+ function yks_mc_add_tinymce_button( $buttons ) {
3694
+ array_push( $buttons, 'yks_mc_tinymce_button_key' );
3695
+ // Print all buttons
3696
+ return $buttons;
3697
+ }
3698
+
3699
+ /**
3700
+ * Localize Script
3701
+ * Pass our imported list data, to the JS file
3702
+ * to build the dropdown list in the modal
3703
+ */
3704
+ function yks_mc_js_admin_head() {
3705
+ $yks_mc_imported_list_data = $this->optionVal['lists'];
3706
+ // our list data array, we will pass to the js file
3707
+ $list_value_array = array();
3708
+ $i = 0;
3709
+ // loop over the list data
3710
+ foreach ( $yks_mc_imported_list_data as $single_list ) {
3711
+ // store it temporarily and push it back to our array
3712
+ $list_value_array[$i]['text'] = $single_list['name'];
3713
+ $list_value_array[$i]['value'] = $single_list['id'];
3714
+ $i++;
3715
+ }
3716
+ ?>
3717
+ <!-- TinyMCE Shortcode Plugin -->
3718
+ <script type='text/javascript'>
3719
+ var yks_mc_lists_data = {
3720
+ 'lists': <?php echo json_encode($list_value_array); ?>
3721
+ };
3722
+ </script>
3723
+ <!-- TinyMCE Shortcode Plugin -->
3724
+ <?php
3725
+ }
3726
+
3727
+
3728
+ /* Checking if the user is on localhost */
3729
+ /* If they are we want to display a warning about SSL on localhost */
3730
+ function yks_mc_is_user_localhost() {
3731
+ $whitelist = array( '127.0.0.1', '::1' );
3732
+ if( in_array( $_SERVER['REMOTE_ADDR'], $whitelist) ) {
3733
+ return true;
3734
+ }
3735
+ }
3736
+
3737
+ /*******************************************************/
3738
+ /* Helper Functions */
3739
+ /******************************************************/
3740
+ /*
3741
+ *
3742
+ * Helper function when testing user submitted data
3743
+ * to be used inside of the yikes_mc_get_form_data filter
3744
+ *
3745
+ */
3746
+ function yks_mc_print_user_data( $form_ID, $merge_variables ) {
3747
+ echo '<h3>The Data Returned From This Form</h3>';
3748
+ echo '<strong>MailChimp List ID : </strong> '.$form_ID.' <br />';
3749
+ echo '<hr />';
3750
+ if ( isset( $merge_variables['FNAME'] ) && $merge_variables['FNAME'] != '' ) {
3751
+ echo '<strong>User\'s Name : </strong> '.$merge_variables['FNAME'].' <br />';
3752
+ echo '<hr />';
3753
+ }
3754
+ if ( isset( $merge_variables['LNAME'] ) && $merge_variables['LNAME'] != '' ) {
3755
+ echo '<strong>User\'s Name : </strong> '.$merge_variables['LNAME'].' <br />';
3756
+ echo '<hr />';
3757
+ }
3758
+ echo '<strong>Users Email : </strong>'.$merge_variables['EMAIL'].' <br />';
3759
+ if ( isset( $merge_variables['GROUPINGS'] ) ) {
3760
+ echo '<hr />';
3761
+ echo '<strong>Interest Group Data : </strong><br /><br />';
3762
+ foreach ( $merge_variables['GROUPINGS'] as $grouping_variable ) {
3763
+ echo '<ol style="list-style:none;">Interest Group : '.$grouping_variable['id'].'</ol>';
3764
+ if ( !isset($grouping_variable['groups'][0]) || $grouping_variable['groups'][0] == '' ) {
3765
+ echo '<li style="list-style:none;">No interest groups selected</li><br />';
3766
+ } else {
3767
+ // loop over interest groups to build array
3768
+ $interest_group_array = array();
3769
+ foreach ( $grouping_variable['groups'] as $interest_group ) {
3770
+ array_push( $interest_group_array , $interest_group );
3771
+ }
3772
+ if ( count($interest_group_array) > 0 ) {
3773
+ foreach ( $interest_group_array as $interest_group_label ) {
3774
+ echo '<li style="list-style:none;">'.$interest_group_label.'</li>';
3775
+ }
3776
+ echo '<br />';
3777
+ }
3778
+ }
3779
+ }
3780
+ }
3781
+ echo '<em style="color:rgb(238, 93, 93);">Form data has not been sent to MailChimp</em><br />';
3782
+ die(); // die to prevent data being sent over to MailChimp
3783
+ }
3784
+
3785
+ /*
3786
+ * Helper function when testing user submitted data
3787
+ * print_r($merge_variables) is returned
3788
+ */
3789
+ function yks_mc_dump_user_data( $form_ID, $merge_variables ) {
3790
+ echo '<strong>Form ID :</strong> '.$form_ID. '<br />';
3791
+ echo '<strong>Merge Variables :</strong><br />';
3792
+ print_r($merge_variables);
3793
+ echo '<br /><em style="color:rgb(238, 93, 93);">Form data has not been sent to MailChimp</em>';
3794
+ die(); // die to prevent data being sent over to MailChimp
3795
+ }
3796
+
3797
+ /****************************************************************************************
3798
+ * Begin Heartbeat API Code
3799
+ * - Used on the Account Activity page for lilve updates
3800
+ ****************************************************************************************/
3801
+
3802
+ /*
3803
+ Client-side code. First we enqueue the Heartbeat API and our Javascript.
3804
+ Our Javascript is then setup to always send the message 'marco' to the server.
3805
+ If a message comes back, the Javascript logs it (polo) to console.
3806
+ */
3807
+
3808
+ //enqueue heartbeat.js and our Javascript
3809
+ function yks_mc_heartbeat_init() {
3810
+ //enqueue the Heartbeat API
3811
+ wp_enqueue_script('heartbeat');
3812
+
3813
+ //load our Javascript in the footer
3814
+ add_action("admin_print_footer_scripts", array( &$this ,"yks_mc_heartbeat_admin_footer" ) );
3815
+ }
3816
+
3817
+
3818
+ //our Javascript to send/process from the client side
3819
+ function yks_mc_heartbeat_admin_footer() {
3820
+ include YKSEME_PATH . 'lib/inc/yks-mc-heartbeat-api.php';
3821
+ }
3822
+
3823
+ /*
3824
+ Our server-side code.
3825
+ ------------------------------
3826
+ This hooks into the heartbeat_received filter.
3827
+ It checks for a key 'client' in the data array. If it is set to 'get_chimp_chatter_data',
3828
+ a key 'server' is set to 'Get MailChimp Chatter Data' in the response array.
3829
+ */
3830
+ function yks_mc_heartbeat_received($response, $data) {
3831
+ // if the client returns get chimp chatter data, popluate
3832
+ // the response with some data
3833
+ if( $data['yks_mc_chimp_chatter_heartbeat'] == 'get_chimp_chatter_data' ) {
3834
+ // populate the response with something
3835
+ $response['yks_mc_chimp_chatter_data'] = 'Get MailChimp Chatter Data';
3836
+ } else if ( $data['yks_mc_chimp_chatter_heartbeat'] == 'get_chimp_chatter_widget_data' ) {
3837
+ $response['yks_mc_chimp_chatter_data'] = 'Get MailChimp Chatter Widget Data';
3838
+ }
3839
+ return $response;
3840
+ }
3841
+
3842
+ /** Change Default HeartBeat API Pulse Time */
3843
+ function yks_mc_tweak_heartbeat_settings( $settings ) {
3844
+ $settings['interval'] = 45; //Anything between 15-60
3845
+ return $settings;
3846
+ }
3847
+
3848
+ /*******************************************************
3849
+ Custom Dashboard MailChimp Account Activity Widget
3850
+ ********************************************************/
3851
+ /**
3852
+ * Add a widget to the dashboard.
3853
+ *
3854
+ * This function is hooked into the 'wp_dashboard_setup' action below.
3855
+ */
3856
+ function yks_mc_add_chimp_chatter_dashboard_widget() {
3857
+ wp_add_dashboard_widget(
3858
+ 'yks_mc_account_activity_widget', // Widget slug.
3859
+ 'MailChimp Account Activity', // Title.
3860
+ array( &$this , 'yks_mc_chimp_chatter_dashboard_widget_function' ) // Display function.
3861
+ );
3862
+ }
3863
+
3864
+ /**
3865
+ * Create the function to output the contents of our Dashboard Widget.
3866
+ */
3867
+ function yks_mc_chimp_chatter_dashboard_widget_function() {
3868
+ include YKSEME_PATH . 'lib/inc/yks-mc-heartbeat-widget-functions.php';
3869
+ }
3870
+
3871
+
3872
+ // help , review container
3873
+ public function help_review_container() {
3874
+ ?>
3875
+ <div id="yks_mc_review_this_plugin_container">
3876
+ <a href="https://github.com/yikesinc/yikes-inc-easy-mailchimp-extender/issues?state=open" target="_blank">
3877
+ <span class="yks_mc_need_support">
3878
+ <strong>
3879
+ <?php _e( 'Need Help?', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3880
+ <?php _e( 'Get In Contact!', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3881
+ <div class="dashicons dashicons-plus-alt"></div>
3882
+ </strong>
3883
+ </span>
3884
+ </a>
3885
+ <a href="http://wordpress.org/support/view/plugin-reviews/yikes-inc-easy-mailchimp-extender" target="_blank">
3886
+ <span class="yks_mc_leave_us_a_review">
3887
+ <strong>
3888
+ <?php _e( 'Loving the plugin?', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3889
+ <?php _e( 'Leave us a nice review', 'yikes-inc-easy-mailchimp-extender' ); ?> <br />
3890
+ <div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div><div class="dashicons dashicons-star-filled"></div>
3891
+ </strong>
3892
+ </span>
3893
+ </a>
3894
+ <a href="http://www.yikesinc.com" target="_blank" class="yks_header_logo">
3895
+ <img src="<?php echo plugins_url().'/yikes-inc-easy-mailchimp-extender/images/yikes_logo.png'; ?>" alt="YIKES Inc. Logo" width=85 title="YIKES Inc. Logo" />
3896
+ </a>
3897
+ </div>
3898
+ <?php
3899
+ }
3900
+
3901
+
3902
+ /**
3903
+ Write our errors to an error log for display to the user
3904
+ - should help minimize number of requests we receive, or at least help us diagnose user issues better
3905
+ **/
3906
+
3907
+ /*
3908
+ * writeErrorToErrorLog()
3909
+ * parameters: $errorResponse
3910
+ * writes a returned API error to our log for display
3911
+ *
3912
+ * @since 5.2
3913
+ */
3914
+ public function writeErrorToErrorLog( $errorResponse ) {
3915
+ // make sure file_get_contents and file_put_contents are available
3916
+ if ( function_exists( 'file_get_contents' ) && function_exists( 'file_put_contents' ) ) {
3917
+ $error_occurance_time = current_time( 'M' ) . '. ' . current_time( 'jS' ) . ', ' . current_time( 'Y' ) . ' - ' . current_time( 'g:i:sa' );
3918
+ $error_log_location = YKSEME_PATH . 'lib/error_log/yks_mc_error_log.php';
3919
+ $current_contents = file_get_contents( $error_log_location );
3920
+ // get total count of errors, we only want to limit to 8 latest errors
3921
+ $total_errors = explode( '<tr>' , $current_contents );
3922
+ $error_array = array();
3923
+ $i = 0;
3924
+ foreach( $total_errors as $error ) {
3925
+ $error_array[] = $error;
3926
+ // limit the error log to the latest 10 errors
3927
+ if ( ++$i == 11 ) {
3928
+ break;
3929
+ }
3930
+ }
3931
+ $new_content = '<tr>
3932
+ <td>' . $errorResponse->getMessage() . '</td>
3933
+ <td>' . $error_occurance_time . '</td>
3934
+ </tr>' . implode( '<tr>' , $error_array );
3935
+ file_put_contents( $error_log_location , $new_content );
3936
+ }
3937
+ }
3938
+
3939
+ /*
3940
+ * ytks_mc_generate_error_log_table()
3941
+ * generate our erorr log table on the options settings page
3942
+ *
3943
+ * @since 5.2
3944
+ */
3945
+ public function yks_mc_generate_error_log_table() {
3946
+ $error_log_contents = file_get_contents( YKSEME_PATH . 'lib/error_log/yks_mc_error_log.php' , true );
3947
+ if ( $error_log_contents != '' ) {
3948
+ return $error_log_contents;
3949
+ }
3950
+ }
3951
+
3952
+ /*
3953
+ * clearYksMCErrorLog()
3954
+ * clear the error log of all errors
3955
+ *
3956
+ * @since 5.2
3957
+ */
3958
+ public function clearYksMCErrorLog() {
3959
+ echo 'running';
3960
+ try {
3961
+ $clear_contents = file_put_contents( YKSEME_PATH . 'lib/error_log/yks_mc_error_log.php' , '' );
3962
+ } catch ( Exception $e ) {
3963
+ return $e->getMessage();
3964
+ $this->writeErrorToErrorLog( $e );
3965
+ }
3966
+ }
3967
+
3968
+ } // end class
3969
+ } // end class check
3970
  ?>
composer.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "require": {
3
- "facebook/webdriver": "dev-master"
4
- },
5
- "require-dev": {
6
- "phpunit/phpunit": "3.7.*"
7
- }
8
- }
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: yikesinc, hiwhatsup, liljimmi, eherman24, seriouslysean
3
  Donate link: http://yikesinc.com
4
  Tags: mailchimp, marketing, email, mailing lists, newsletter, sign up, forms, sign up form
5
  Requires at least: 3.0
6
- Tested up to: 4.3
7
- Stable tag: 5.4.3
8
  License: GPLv2 or later
9
 
10
  Easy MailChimp Forms allows you to painlessly add MailChimp sign up forms to your WordPress site and track user activity with interactive reports.
@@ -835,6 +835,9 @@ These functions should be used in conjunction with the `yikes_mc_get_form_data`
835
 
836
  == Changelog ==
837
 
 
 
 
838
  = 5.4.3 - March 17th, 2015 =
839
 
840
  * Fixed: Re-import form fields function not properly refreshing the page
@@ -1136,6 +1139,9 @@ These functions should be used in conjunction with the `yikes_mc_get_form_data`
1136
 
1137
  == Upgrade Notice ==
1138
 
 
 
 
1139
  = 5.4.3 - March 17th, 2015 =
1140
  * Fixed: Re-import form fields function not properly refreshing the page
1141
  * Fixed: Updating a MailChimp list field no longer throws an empty error
3
  Donate link: http://yikesinc.com
4
  Tags: mailchimp, marketing, email, mailing lists, newsletter, sign up, forms, sign up form
5
  Requires at least: 3.0
6
+ Tested up to: 4.3.1
7
+ Stable tag: 5.4.4
8
  License: GPLv2 or later
9
 
10
  Easy MailChimp Forms allows you to painlessly add MailChimp sign up forms to your WordPress site and track user activity with interactive reports.
835
 
836
  == Changelog ==
837
 
838
+ = 5.4.4 - September 24th, 2015 =
839
+ * Added: Admin notice to warn about the upcoming release (major re-write)
840
+
841
  = 5.4.3 - March 17th, 2015 =
842
 
843
  * Fixed: Re-import form fields function not properly refreshing the page
1139
 
1140
  == Upgrade Notice ==
1141
 
1142
+ = 5.4.4 - September 24th, 2015 =
1143
+ * Added: Admin notice to warn about the upcoming release (major re-write)
1144
+
1145
  = 5.4.3 - March 17th, 2015 =
1146
  * Fixed: Re-import form fields function not properly refreshing the page
1147
  * Fixed: Updating a MailChimp list field no longer throws an empty error
yikes-inc-easy-mailchimp-extender.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Easy MailChimp Forms
5
  Plugin URI: http://www.yikesinc.com/services/yikes-inc-easy-mailchimp-extender/
6
  Description: Mailchimp integration in the form of a shortcode, php snippet or widget. Now track account status, campaign stats, view subscribers and so much more!
7
- Version: 5.4.3
8
  Author: YIKES Inc
9
  Author URI: http://yikesinc.com
10
  License: GPL3
@@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
 
31
  /** Configuration **/
32
  if(!defined('YKSEME_DEBUG')) define('YKSEME_DEBUG', false);
33
- if(!defined('YKSEME_VERSION_CURRENT')) define('YKSEME_VERSION_CURRENT', '5.4.3');
34
  if(!defined('YKSEME_REQ_PHP')) define('YKSEME_REQ_PHP', '5.0');
35
  if(!defined('YKSEME_AUTHOR')) define('YKSEME_AUTHOR', 'YIKES Inc');
36
  if(!defined('YKSEME_SITE')) define('YKSEME_SITE', site_url().'/');
4
  Plugin Name: Easy MailChimp Forms
5
  Plugin URI: http://www.yikesinc.com/services/yikes-inc-easy-mailchimp-extender/
6
  Description: Mailchimp integration in the form of a shortcode, php snippet or widget. Now track account status, campaign stats, view subscribers and so much more!
7
+ Version: 5.4.4
8
  Author: YIKES Inc
9
  Author URI: http://yikesinc.com
10
  License: GPL3
30
 
31
  /** Configuration **/
32
  if(!defined('YKSEME_DEBUG')) define('YKSEME_DEBUG', false);
33
+ if(!defined('YKSEME_VERSION_CURRENT')) define('YKSEME_VERSION_CURRENT', '5.4.4');
34
  if(!defined('YKSEME_REQ_PHP')) define('YKSEME_REQ_PHP', '5.0');
35
  if(!defined('YKSEME_AUTHOR')) define('YKSEME_AUTHOR', 'YIKES Inc');
36
  if(!defined('YKSEME_SITE')) define('YKSEME_SITE', site_url().'/');