MailChimp List Subscribe Form - Version 1.2

Version Description

Download this release

Release Info

Developer crowdfavorite
Plugin Icon wp plugin MailChimp List Subscribe Form
Version 1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.2

css/admin.css ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ .error_msg {
2
+ color: red;
3
+ margin: 0px;
4
+ font-weight: bold;
5
+ }
6
+ .success_msg {
7
+ color: green;
8
+ margin: 0px;
9
+ font-weight: bold;
10
+ }
css/ie.css ADDED
@@ -0,0 +1 @@
 
1
+ #mc_message { padding-top:1em; }
js/mailchimp.js CHANGED
@@ -1,29 +1,37 @@
1
- var mce_jQuery = jQuery.noConflict();
2
- mce_jQuery(document).ready( function($) {
3
- mce_jQuery('#mc_submit_type').val('js');
4
- options = { url: mc_ajax_url, type: 'POST', dataType: 'text',
5
- beforeSubmit: mc_beforeForm,
6
- success: mc_success
7
- };
8
- mce_jQuery('#mc_signup_form').ajaxForm(options);
9
-
10
- });
11
-
12
- function mc_beforeForm(){
13
- try{
14
- mce_jQuery('#mc_signup_submit').attr("disabled","disabled");
15
- }catch(e){}
16
- }
17
- function mc_success(data){
18
- try{
19
- mce_jQuery('#mc_signup_submit').attr("disabled","");
20
- }catch(e){}
21
- mce_jQuery('#mc_message').html(data);
22
- var reg = new RegExp("class='mc_success_msg'", 'i');
23
- if (reg.test(data)){
24
- mce_jQuery('#mc_signup_form').each(function(){
25
- this.reset();
26
- });
27
- mce_jQuery('#mc_submit_type').val('js');
28
- }
29
- }
 
 
 
 
 
 
 
 
1
+ /* Form submission functions for the MailChimp Widget */
2
+ ;(function($){
3
+ $(function($) {
4
+ // Change our submit type from HTML (default) to JS
5
+ $('#mc_submit_type').val('js');
6
+
7
+ // Attach our form submitter action
8
+ $('#mc_signup_form').ajaxForm({
9
+ url: mailchimpSF.ajax_url,
10
+ type: 'POST',
11
+ dataType: 'text',
12
+ beforeSubmit: mc_beforeForm,
13
+ success: mc_success
14
+ });
15
+ });
16
+
17
+ function mc_beforeForm(){
18
+ // Disable the submit button
19
+ $('#mc_signup_submit').attr("disabled","disabled");
20
+ }
21
+ function mc_success(data){
22
+ // Re-enable the submit button
23
+ $('#mc_signup_submit').attr("disabled","");
24
+
25
+ // Put the response in the message div
26
+ $('#mc_message').html(data);
27
+
28
+ // See if we're successful, if so, wipe the fields
29
+ var reg = new RegExp("class='mc_success_msg'", 'i');
30
+ if (reg.test(data)){
31
+ $('#mc_signup_form').each(function(){
32
+ this.reset();
33
+ });
34
+ $('#mc_submit_type').val('js');
35
+ }
36
+ }
37
+ })(jQuery);
mailchimp.php CHANGED
@@ -2,12 +2,11 @@
2
  /*
3
  Plugin Name: MailChimp
4
  Plugin URI: http://www.mailchimp.com/plugins/mailchimp-wordpress-plugin/
5
- Description: The MailChimp plugin allows you to easily setup a Subscribe box for your MailChimp list - So easy a chimp could do it!
6
- Version: 1.1.15
7
- Author: MailChimp API Support Team
8
  Author URI: http://mailchimp.com/api/
9
  */
10
-
11
  /* Copyright 2008 MailChimp.com (email : api@mailchimp.com)
12
 
13
  This program is free software; you can redistribute it and/or modify
@@ -24,239 +23,349 @@ Author URI: http://mailchimp.com/api/
24
  along with this program; if not, write to the Free Software
25
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
  */
 
 
 
 
 
 
 
 
 
 
 
27
  if (!class_exists('MCAPI')) {
28
- require_once( str_replace('//','/',dirname(__FILE__).'/') .'MCAPI.class.php');
29
  }
 
30
  // includes the widget code so it can be easily called either normally or via ajax
31
- include_once('mailchimp_includes.php');
32
- // some custom CSS//
33
- function mailchimpSF_admin_css() {
34
- echo "
35
- <style type='text/css'>
36
- .error_msg { color: red; }
37
- .success_msg { color: green; }
38
- </style>
39
- ";
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
- function mailchimpSF_main_css() {
42
- echo "
43
- <style type='text/css'>
44
- .mc_error_msg { color: red; }
45
- .mc_success_msg { color: green; }
46
- .mc_merge_var{ padding:0; margin:0; }
47
- #mc_signup_form { ";
48
- if (get_option('mc_custom_style')=='on'){
49
- echo "padding:5px; ";
50
- echo "border-width: ".get_option('mc_form_border_width').'px;';
51
- if (get_option('mc_form_border_width')==0){
52
- echo "border-style: none;";
53
- } else {
54
- echo "border-style: solid;";
55
- }
56
- echo "border-color: #".get_option('mc_form_border_color').';';
57
- echo "color: #".get_option('mc_form_text_color').';';
58
- echo "background-color: #".get_option('mc_form_background').';';
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
- echo "
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
- .mc_custom_border_hdr {";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  if (get_option('mc_custom_style')=='on'){
64
- echo "border-width: ".get_option('mc_header_border_width').'px;';
65
- if (get_option('mc_header_border_width')==0){
66
- echo "border-style: none;";
67
- } else {
68
- echo "border-style: solid;";
69
- }
70
- echo "border-color: #".get_option('mc_header_border_color').';';
71
- echo "color: #".get_option('mc_header_text_color').';';
72
- echo "background-color: #".get_option('mc_header_background').';';
73
- echo "font-size: 1.2em;padding:5px 10px;";
74
- echo "width: 100%;";
75
- }
76
- echo "
 
 
 
 
 
 
 
 
 
77
  }
78
- #mc_signup_container{}
79
- #mc_signup_form {}
80
- #mc_signup_form .mc_var_label { }
81
- #mc_signup_form .mc_input { }
82
- #mc-indicates-required { width:100%; }
83
- #mc_display_rewards { }
84
- #mc_interests_header { font-weight:bold; }
85
- div.mc_interest{width:100%; }
86
- #mc_signup_form input.mc_interest { }
87
- #mc_signup_form select { }
88
- #mc_signup_form label.mc_interest_label { display:inline; }
89
- .mc_signup_submit { text-align:center; }
90
- </style>
91
- <!--[if IE]>
92
- <style type='text/css'>
93
- #mc_message { padding-top:1em; }
94
- </style>
95
- <![endif]-->
96
- ";
97
- }//mc_main_css
98
-
99
- // some javascript to get ajax version submitting to the proper location
100
- function mailchimpSF_main_js(){
101
- $url = get_bloginfo( 'wpurl' ).'/wp-content/plugins/mailchimp/mailchimp_ajax.php';
102
- echo '<script type="text/javascript">
103
- var mc_ajax_url = "'.$url.'";
104
- </script>';
105
  }
106
 
107
 
108
- // Hook for initializing the plugins, mostly for i18n
109
- add_action( 'init', 'mailchimpSF_plugin_init' );
110
-
111
- // Hook for our css
112
- add_action('admin_head', 'mailchimpSF_admin_css');
113
- add_action('admin_head', 'mailchimpSF_main_js'); //just to stop js error
114
- add_action('wp_head', 'mailchimpSF_main_css');
115
- add_action('wp_head', 'mailchimpSF_main_js');
116
-
117
- // Hook for adding admin menus
118
  add_action('admin_menu', 'mailchimpSF_add_pages');
119
 
120
- // Initialize this plugin. Called by 'init' hook.
121
- function mailchimpSF_plugin_init(){
122
- //the "complicated" path is so people can use this with WPMU or just move things around
123
- load_plugin_textdomain( 'mailchimp_i18n', str_replace(ABSPATH,'',dirname(__FILE__).'/po') );
124
- if (get_option('mc_use_javascript')=='on'){
125
- wp_enqueue_script( 'mcJavascript', get_bloginfo('wpurl').'/wp-content/plugins/mailchimp/js/mailchimp.js', array('jquery', 'jquery-form'));
126
- }
127
-
128
- }
129
 
130
- // action function for above hook
131
- function mailchimpSF_add_pages(){
132
- //7 is lowest w/ Plugin Editing capability
133
- add_options_page( __( 'MailChimp Setup', 'mailchimp_i18n' ), __( 'MailChimp Setup', 'mailchimp_i18n' ), 7, 'mailchimpSF_setup_page', 'mailchimpSF_setup_page');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
 
 
135
 
136
- function mailchimpSF_setup_page(){
137
 
138
- $msg = '';
139
- if (get_option('mc_password')!=''){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  //some upgrade code for < 0.5 users - we want to rip out the password we've been saving.
141
  $api = new MCAPI(get_option('mc_username'), get_option('mc_password'));
142
- if ($api->errorCode == ''){
143
  update_option('mc_apikey', $api->api_key);
144
  //this should already be here, but let's make sure anyway
145
  $req = $api->getAffiliateInfo();
146
  update_option('mc_user_id', $req['user_id']);
147
  } else {
148
- $msg = "<span class='error_msg'>".__( "While upgrading the plugin setup, we were unable to login to your account. You will need to login again and setup your list.", 'mailchimp_i18n' )."<br/>";
 
149
  }
150
  delete_option('mc_password');
151
  }
152
- ?>
153
- <div class="wrap">
154
- <h2><?php echo __( 'MailChimp List Setup', 'mailchimp_i18n');?> </h2>
155
- <?php
156
- if ($_REQUEST['action']==='logout'){
157
- update_option('mc_apikey', '');
158
- }
159
- //see if we need to set/change the username & password.
160
- if (isset($_REQUEST['mc_apikey'])){
161
  $delete_setup = false;
162
- $api = new MCAPI($_REQUEST['mc_apikey']);
163
  $api->ping();
164
- if ($api->errorCode == ''){
165
- $msg = "<span class='success_msg'>".htmlentities(__( "Success! We were able to verify your username & password! Let's continue, shall we?", 'mailchimp_i18n' ),ENT_COMPAT,'UTF-8')."</span>";
166
- update_option('mc_apikey', $_REQUEST['mc_apikey']);
167
  $req = $api->getAccountDetails();
168
  update_option('mc_username', $req['username']);
169
  update_option('mc_user_id', $req['user_id']);
170
- if (get_option('mc_list_id')!=''){
 
171
  $lists = $api->lists();
172
  //but don't delete if the list still exists...
173
  $delete_setup = true;
174
- foreach($lists as $list){ if ($list['id']==get_option('mc_list_id')){ $list_id = $_REQUEST['mc_list_id']; $delete_setup=false; } }
 
 
 
 
 
175
  }
176
  } else {
177
- $msg .= "<span class='error_msg'>".htmlentities(__( 'Uh-oh, we were unable to verify your API Key. Please check them and try again!', 'mailchimp_i18n' ),ENT_COMPAT,'UTF-8')."<br/>";
178
- $msg .= __( 'The server said:', 'mailchimp_i18n' )."<i>".$api->errorMessage."</i></span>";
179
- if (get_option('mc_username')==''){
 
180
  $delete_setup = true;
181
  }
182
  }
 
 
 
 
 
183
  if ($delete_setup){
184
- delete_option('mc_user_id');
185
- delete_option('mc_rewards');
186
- delete_option('mc_use_javascript');
187
- delete_option('mc_use_unsub_link');
188
- delete_option('mc_list_id');
189
- delete_option('mc_list_name');
190
- delete_option('mc_interest_groups');
191
- delete_option('mc_show_interest_groups');
192
- $mv = get_option('mc_merge_vars');
193
- if (!is_array($mv)){
194
- $mv = unserialize($mv);
195
- }
196
- if (is_array($mv)){
197
- foreach($mv as $var){
198
- $opt = 'mc_mv_'.$var['tag'];
199
- delete_option($opt);
200
- }
201
- }
202
- delete_option('mc_merge_vars');
203
  }
 
204
  //set these for the form fields below
205
  $user = $_REQUEST['mc_username'];
206
- } else {
207
- $user = get_option('mc_username');
208
- $apikey = get_option('mc_apikey');
209
- }
210
- if (get_option('mc_apikey')!=''){
211
- $api = new MCAPI(get_option('mc_apikey'));
212
- $lists = (array)$api->lists();
213
 
214
- foreach($lists as $list){ if ($list['id']==$_REQUEST['mc_list_id']){ $list_id = $_REQUEST['mc_list_id']; $list_name = $list['name']; } }
215
- $orig_list = get_option('mc_list_id');
216
- if ($list_id != ''){
217
- update_option('mc_list_id', $list_id);
218
- update_option('mc_list_name', $list_name);
219
- if ($orig_list != $list_id){
220
- update_option('mc_header_content',__( 'Sign up for', 'mailchimp_i18n' ).' '.$list_name);
221
- update_option('mc_submit_text',__( 'Subscribe', 'mailchimp_i18n' ));
222
-
223
- update_option('mc_custom_style','on');
224
- update_option('mc_use_javascript','on');
225
- update_option('mc_use_unsub_link','off');
226
- update_option('mc_header_border_width','1');
227
- update_option('mc_header_border_color','E3E3E3');
228
- update_option('mc_header_background','FFFFFF');
229
- update_option('mc_header_text_color','CC6600');
230
-
231
- update_option('mc_form_border_width','1');
232
- update_option('mc_form_border_color','C4D3EA');
233
- update_option('mc_form_background','EEF3F8');
234
- update_option('mc_form_text_color','555555');
235
-
236
- update_option('mc_show_interest_groups', 'on' );
237
- }
238
- $mv = $api->listMergeVars($list_id);
239
- $ig = $api->listInterestGroups($list_id);
240
-
241
- update_option('mc_merge_vars', serialize( $mv ) );
242
- foreach($mv as $var){
243
- $opt = 'mc_mv_'.$var['tag'];
244
- //turn them all on by default
245
- if ($orig_list != $list_id){
246
- update_option($opt, 'on' );
247
- }
248
- }
249
- update_option('mc_interest_groups', serialize( $ig ) );
250
 
251
- $msg = '<span class="success_msg">'.
252
- sprintf(__( 'Success! Loaded and saved the info for %d Merge Variables and %d Interest Groups from your list'),
253
- sizeof($mv) , sizeof($ig) ).
254
- ' "'.$list_name.'"<br/><br/>'.
255
- __('Now you should either Turn On the MailChimp Widget or change your options below, then turn it on.', 'mailchimp_i18n').'</span>';
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  }
257
-
258
  }
259
- if (isset($_REQUEST['reset_list'])){
 
 
 
 
 
 
 
260
  delete_option('mc_list_id');
261
  delete_option('mc_list_name');
262
  delete_option('mc_merge_vars');
@@ -280,367 +389,585 @@ if (isset($_REQUEST['reset_list'])){
280
  delete_option('mc_form_border_color');
281
  delete_option('mc_form_background');
282
  delete_option('mc_form_text_color');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
 
284
- $msg = '<span class="success_msg">'.__('Successfully Reset your List selection... Now you get to pick again!', 'mailchimp_i18n').'</span>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  }
286
- if (isset($_REQUEST['change_form_settings'])){
287
- if (isset($_REQUEST['mc_rewards'])){
 
 
 
 
 
 
288
  update_option('mc_rewards', 'on');
289
- if ($msg) $msg .= '<br/>';
290
- $msg .= '<span class="success_msg">'.__('Monkey Rewards turned On!', 'mailchimp_i18n').'</span>';
291
  } else if (get_option('mc_rewards')!='off') {
292
  update_option('mc_rewards', 'off');
293
- if ($msg) $msg .= '<br/>';
294
- $msg .= '<span class="success_msg">'.__('Monkey Rewards turned Off!', 'mailchimp_i18n').'</span>';
295
  }
296
- if (isset($_REQUEST['mc_use_javascript'])){
297
  update_option('mc_use_javascript', 'on');
298
- if ($msg) $msg .= '<br/>';
299
- $msg .= '<span class="success_msg">'.__('Fancy Javascript submission turned On!', 'mailchimp_i18n').'</span>';
300
  } else if (get_option('mc_use_javascript')!='off') {
301
  update_option('mc_use_javascript', 'off');
302
- if ($msg) $msg .= '<br/>';
303
- $msg .= '<span class="success_msg">'.__('Fancy Javascript submission turned Off!', 'mailchimp_i18n').'</span>';
304
  }
305
 
306
- if (isset($_REQUEST['mc_use_unsub_link'])){
307
  update_option('mc_use_unsub_link', 'on');
308
- if ($msg) $msg .= '<br/>';
309
- $msg .= '<span class="success_msg">'.__('Unsubscribe link turned On!', 'mailchimp_i18n').'</span>';
310
  } else if (get_option('mc_use_unsub_link')!='off') {
311
  update_option('mc_use_unsub_link', 'off');
312
- if ($msg) $msg .= '<br/>';
313
- $msg .= '<span class="success_msg">'.__('Unsubscribe link turned Off!', 'mailchimp_i18n').'</span>';
314
  }
315
 
316
- $content = stripslashes($_REQUEST['mc_header_content']);
317
  $content = str_replace("\r\n","<br/>", $content);
318
  update_option('mc_header_content', $content );
319
 
320
- $content = stripslashes($_REQUEST['mc_subheader_content']);
321
  $content = str_replace("\r\n","<br/>", $content);
322
  update_option('mc_subheader_content', $content );
323
 
324
 
325
- $submit_text = stripslashes($_REQUEST['mc_submit_text']);
326
  $submit_text = str_replace("\r\n","", $submit_text);
327
  update_option('mc_submit_text', $submit_text);
328
-
329
- if (isset($_REQUEST['mc_custom_style'])){
330
- update_option('mc_custom_style','on');
331
- } else {
332
- update_option('mc_custom_style','off');
333
- }
334
 
335
  //we told them not to put these things we are replacing in, but let's just make sure they are listening...
336
- update_option('mc_header_border_width',str_replace('px','',$_REQUEST['mc_header_border_width']) );
337
- update_option('mc_header_border_color', str_replace('#','',$_REQUEST['mc_header_border_color']));
338
- update_option('mc_header_background',str_replace('#','',$_REQUEST['mc_header_background']));
339
- update_option('mc_header_text_color', str_replace('#','',$_REQUEST['mc_header_text_color']));
340
-
341
- update_option('mc_form_border_width',str_replace('px','',$_REQUEST['mc_form_border_width']) );
342
- update_option('mc_form_border_color', str_replace('#','',$_REQUEST['mc_form_border_color']));
343
- update_option('mc_form_background',str_replace('#','',$_REQUEST['mc_form_background']));
344
- update_option('mc_form_text_color', str_replace('#','',$_REQUEST['mc_form_text_color']));
345
-
346
- if (isset($_REQUEST['mc_show_interest_groups'])){
347
- update_option('mc_show_interest_groups','on');
348
- } else {
349
- update_option('mc_show_interest_groups','off');
350
- }
351
  $mv = get_option('mc_merge_vars');
352
- if (!is_array($mv)){
353
- $mv = unserialize(get_option('mc_merge_vars'));
 
 
 
 
 
 
 
354
  }
355
- foreach($mv as $var){
356
- $opt = 'mc_mv_'.$var['tag'];
357
- if (isset($_REQUEST[$opt]) || $var['req']=='Y'){
358
- update_option($opt,'on');
359
- } else {
360
- update_option($opt,'off');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  }
362
  }
363
- if ($msg) $msg .= '<br/>';
364
- $msg .= '<span class="success_msg">'.__('Successfully Updated your List Subscribe Form Settings!', 'mailchimp_i18n').'</span>';
 
 
 
 
 
 
 
 
 
 
 
 
 
365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  }
367
- if ($msg){
368
- echo '<div id="mc_message" class=""><p><strong>'.$msg.'</strong></p></div>';
 
 
 
 
 
 
 
 
369
  }
 
370
  ?>
371
- <?php
372
- //wp_nonce_field('update-options');
373
- if (get_option('mc_apikey')==''){
374
- ?>
375
- <div>
376
- <form method="post" action="options-general.php?page=mailchimpSF_setup_page">
377
- <h3><?php echo __('Login Info', 'mailchimp_i18n');?></h3>
378
- <?php echo __('To start using the MailChimp plugin, we first need to login and get your API Key. Please enter your MailChimp username and password below.', 'mailchimp_i18n'); ?>
379
- <br/>
380
- <?php echo __("Don't have a MailChimp account? <a href='http://www.mailchimp.com/signup/' target='_blank'>Try one for Free</a>!", 'mailchimp_i18n'); ?>
381
- <br/>
382
- <table class="form-table">
383
- <tr valign="top">
384
- <th scope="row"><?php echo __('API Key', 'mailchimp_i18n');?>:</th>
385
- <td><input name="mc_apikey" type="text" id="mc_apikey" class="code" value="<?php echo $apikey; ?>" size="32" /><br/>
386
- <a href="http://admin.mailchimp.com/account/api-key-popup" target="_blank">get your API Key here</a>
387
- </td>
388
- </tr>
389
- </table>
390
- <input type="hidden" name="action" value="update"/>
391
- <input type="hidden" name="page_options" value="mc_apikey" />
392
- <input type="submit" name="Submit" value="<?php echo htmlentities(__('Save & Check'),ENT_COMPAT,'UTF-8');?>" class="button" />
393
- </form>
394
- </div>
395
- <?php
396
- if (get_option('mc_username')!=''){
397
- echo '<strong>'.__('Notes', 'mailchimp_i18n').':</strong><ul>
398
- <li><i>'.__('Changing your settings at MailChimp.com may cause this to stop working.', 'mailchimp_i18n').'</i></li>
399
- <li><i>'.__('If you change your login to a different account, the info you have setup below will be erased.', 'mailchimp_i18n').'</i></li>
400
- <li><i>'.__('If any of that happens, no biggie - just reconfigure your login and the items below...', 'mailchimp_i18n').'</i></li></ul>
401
- <br/>';
402
- }
403
- echo '</p>';
404
- } else {
405
- ?>
406
- <table style="min-width:400px;"><tr><td><h3><?php echo __('Logged in as', 'mailchimp_i18n');?>: <?php echo get_option('mc_username')?></h3>
407
- </td><td>
408
- <form method="post" action="options-general.php?page=mailchimpSF_setup_page">
409
- <input type="hidden" name="action" value="logout"/>
410
- <input type="submit" name="Submit" value="<?php echo __('Logout', 'mailchimp_i18n');?>" class="button" />
411
- </form>
412
- </td></tr></table>
413
  <?php
 
 
 
 
 
 
 
414
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
416
  <?php
 
 
 
 
417
  //Just get out if nothing else matters...
418
  if (get_option('mc_apikey') == '') return;
419
 
420
  if (get_option('mc_apikey')!=''){
421
- ?>
422
- <?php
423
- //wp_nonce_field('update-options'); ?>
424
- <h3><?php echo __('Your Lists', 'mailchimp_i18n')?></h3>
425
  <div>
426
- <?php echo __('Please select the List you wish to create a Signup Form for.', 'mailchimp_i18n');?><br/>
427
- <form method="post" action="options-general.php?page=mailchimpSF_setup_page">
428
- <?php
429
- $GLOBALS["mc_api_key"] = get_option('mc_apikey');
430
- $api = new MCAPI('no_login','is_needed');
431
- $lists = (array)$api->lists();
432
- rsort($lists);
433
- if (sizeof($lists)==0){
434
- echo "<span class='error_msg'>".
435
- sprintf(__("Uh-oh, you don't have any lists defined! Please visit %s, login, and setup a list before using this tool!", 'mailchimp_i18n'),
436
- "<a href='http://www.mailchimp.com/'>MailChimp</a>")."</span>";
437
- } else {
438
- echo '<table style="min-width:400px"><tr><td>
439
- <select name="mc_list_id" style="min-width:200px;">
440
- <option value=""> --- '.__('Select A List','mailchimp_i18n').' --- </option>';
441
- foreach ($lists as $list){
442
- if ($list['id'] == get_option('mc_list_id')){
443
- $sel = ' selected="selected" ';
444
- } else {
445
- $sel = '';
446
- }
447
- echo '<option value="'.$list['id'].'" '.$sel.'>'.htmlentities($list['name'],ENT_COMPAT,'UTF-8').'</option>';
448
- }
449
- ?>
450
- </select></td><td>
451
- <input type="hidden" name="action" value="update" />
452
- <input type="hidden" name="page_options" value="mc_list_id" />
453
- <input type="submit" name="Submit" value="<?php echo __('Update List', 'mailchimp_i18n');?>" class="button" />
454
- </td></tr>
455
- <tr><td colspan="2">
456
- <strong><?php echo __('Note:', 'mailchimp_i18n');?></strong> <em><?php echo __('Updating your list will not cause settings below to be lost. Changing to a new list will.', 'mailchimp_i18n');?></em>
457
- </td></tr>
458
- </table>
459
- </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  </div>
 
461
  <br/>
 
462
  <?php
463
- } //end select list
464
- } else {
465
  //display the selected list...
466
  ?>
467
 
468
- <?php
469
- //wp_nonce_field('update-options'); ?>
470
  <p class="submit">
471
- <form method="post" action="options-general.php?page=mailchimpSF_setup_page">
472
- <input type="hidden" name="action" value="update" />
473
- <input type="hidden" name="page_options" value="mc_list_id" />
474
- <input type="submit" name="reset_list" value="<?php echo __('Reset List Options and Select again', 'mailchimp_i18n');?>" class="button" />
475
- </form>
476
  </p>
477
- <h3><?php echo __('Subscribe Form Widget Settings for this List', 'mailchimp_i18n');?>:</h3>
478
- <h4><?php echo __('Selected MailChimp List', 'mailchimp_i18n');?>: <?php echo get_option('mc_list_name'); ?></h4>
479
  <?php
480
  }
481
  //Just get out if nothing else matters...
482
  if (get_option('mc_list_id') == '') return;
483
- $mv = get_option('mc_merge_vars');
484
- $ig = get_option('mc_interest_groups');
485
- if (!is_array($mv)){
486
- //apparently in WP 2.6 get_option() unserializes arrays for us.
487
- $mv = unserialize($mv);
488
- $ig = unserialize($ig);
489
- }
490
- if (!is_array($ig)){
491
- //means we got false returned
492
- $ig = unserialize($ig);
493
- }
494
  ?>
495
 
496
  <div>
497
- <form method="post" action="options-general.php?page=mailchimpSF_setup_page">
498
  <div style="width:600px;">
499
- <input type="submit" name="change_form_settings" value="<?php echo __('Update Subscribe Form Settings', 'mailchimp_i18n');?>" class="button" />
 
 
500
  <table class="widefat">
501
  <tr valign="top">
502
- <th scope="row"><?php echo __('Monkey Rewards', 'mailchimp_i18n');?>:</th>
503
- <td><input name="mc_rewards" type="checkbox" <?php if (get_option('mc_rewards')=='on' || get_option('mc_rewards')=='' ) {echo 'checked="checked"';} ?> id="mc_rewards" class="code" />
504
- <i><label for="mc_rewards"><?php echo __('turning this on will place a "powered by MailChimp" link in your form that will earn you credits with us. It is optional and can be turned on or off at any time.');?></label></i>
505
  </td>
506
  </tr>
507
  <tr valign="top">
508
- <th scope="row"><?php echo __('Use Javascript Support?', 'mailchimp_i18n');?>:</th>
509
- <td><input name="mc_use_javascript" type="checkbox" <?php if (get_option('mc_use_javascript')=='on' ) {echo 'checked="checked"';} ?> id="mc_use_javascript" class="code" />
510
- <i><label for="mc_use_javascript"><?php echo __('turning this on will use fancy javascript submission and should degrade gracefully for users not using javascript. It is optional and can be turned on or off at any time.');?></label></i>
511
  </td>
512
  </tr>
513
  <tr valign="top">
514
- <th scope="row"><?php echo __('Include Unsubscribe link?', 'mailchimp_i18n');?>:</th>
515
- <td><input name="mc_use_unsub_link" type="checkbox" <?php if (get_option('mc_use_unsub_link')=='on' ) {echo 'checked="checked"';} ?> id="mc_use_unsub_link" class="code" />
516
- <i><label for="mc_use_unsub_link"><?php echo __('turning this on will add a link to your host unsubscribe form');?></label></i>
517
  </td>
518
  </tr>
519
  <tr valign="top">
520
- <th scope="row"><?php echo __('Header content', 'mailchimp_i18n');?>:</th>
521
  <td>
522
- <textarea name="mc_header_content" rows="2" cols="50"><?php echo htmlentities(get_option('mc_header_content'),ENT_COMPAT,'UTF-8');?></textarea><br/>
523
- <i><?php echo __('You can fill this with your own Text, HTML markup (including image links), or Nothing!', 'mailchimp_i18n');?></i>
524
  </td>
525
  </tr>
526
 
527
  <tr valign="top">
528
- <th scope="row"><?php echo __('Sub-header content', 'mailchimp_i18n');?>:</th>
529
  <td>
530
- <textarea name="mc_subheader_content" rows="2" cols="50"><?php echo htmlentities(get_option('mc_subheader_content'),ENT_COMPAT,'UTF-8');?></textarea><br/>
531
- <i><?php echo __('You can fill this with your own Text, HTML markup (including image links), or Nothing!', 'mailchimp_i18n');?></i>.
532
- <?php echo __('This will be displayed under the heading and above the form.', 'mailchimp_i18n');?>
533
  </td>
534
  </tr>
535
 
536
 
537
  <tr valign="top">
538
- <th scope="row"><?php echo __('Submit Button text', 'mailchimp_i18n');?>:</th>
539
  <td>
540
- <input type="text" name="mc_submit_text" size="30" value="<?php echo get_option('mc_submit_text');?>"/>
541
  </td>
542
  </tr>
543
 
544
  <tr valign="top">
545
- <th scope="row"><?php echo __('Custom Styling', 'mailchimp_i18n');?>:</th>
546
  <td>
547
  <table class="widefat">
548
 
549
- <tr><th><label for="mc_custom_style"><?php echo __('Turned On?', 'mailchimp_i18n');?></label></th><td><input type="checkbox" name="mc_custom_style" id="mc_custom_style" <?php if (get_option('mc_custom_style')=='on'){echo 'checked="checked"';}?> /></td></tr>
550
- <tr><th colspan="2"><?php echo __('Header Settings (only applies if there are no HTML tags in the Header Content area above)', 'mailchimp_i18n');?>:</th></tr>
551
- <tr><th><?php echo __('Border Width', 'mailchimp_i18n');?>:</th><td><input type="text" name="mc_header_border_width" size="3" maxlength="3" value="<?php echo get_option('mc_header_border_width');?>"/> px<br/>
552
- <i><?php echo __('Set to 0 for no border, do not enter <strong>px</strong>!', 'mailchimp_i18n');?></i>
553
  </td></tr>
554
- <tr><th><?php echo __('Border Color', 'mailchimp_i18n');?>:</th><td>#<input type="text" name="mc_header_border_color" size="7" maxlength="6" value="<?php echo get_option('mc_header_border_color');?>"/><br/>
555
- <i><?php echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');?></i>
556
  </td></tr>
557
- <tr><th>Text Color:</th><td>#<input type="text" name="mc_header_text_color" size="7" maxlength="6" value="<?php echo get_option('mc_header_text_color');?>"/><br/>
558
- <i><?php echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');?></i>
559
  </td></tr>
560
- <tr><th>Background Color:</th><td>#<input type="text" name="mc_header_background" size="7" maxlength="6" value="<?php echo get_option('mc_header_background');?>"/><br/>
561
- <i><?php echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');?></i>
562
  </td></tr>
563
 
564
- <tr><th colspan="2"><?php echo __('Form Settings', 'mailchimp_i18n');?>:</th></tr>
565
- <tr><th><?php echo __('Border Width', 'mailchimp_i18n');?>:</th><td><input type="text" name="mc_form_border_width" size="3" maxlength="3" value="<?php echo get_option('mc_form_border_width');?>"/> px<br/>
566
- <i><?php echo __('Set to 0 for no border, do not enter <strong>px</strong>!', 'mailchimp_i18n');?></i>
567
  </td></tr>
568
- <tr><th><?php echo __('Border Color', 'mailchimp_i18n');?>:</th><td>#<input type="text" name="mc_form_border_color" size="7" maxlength="6" value="<?php echo get_option('mc_form_border_color');?>"/><br/>
569
- <i><?php echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');?></i>
570
  </td></tr>
571
- <tr><th>Text Color:</th><td>#<input type="text" name="mc_form_text_color" size="7" maxlength="6" value="<?php echo get_option('mc_form_text_color');?>"/><br/>
572
- <i><?php echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');?></i>
573
  </td></tr>
574
- <tr><th>Background Color:</th><td>#<input type="text" name="mc_form_background" size="7" maxlength="6" value="<?php echo get_option('mc_form_background');?>"/><br/>
575
- <i><?php echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');?></i>
576
  </td></tr>
577
  </table>
578
  </td>
579
  </tr>
580
  </table>
581
  </div>
582
- <input type="submit" name="change_form_settings" value="<?php echo __('Update Subscribe Form Settings', 'mailchimp_i18n');?>" class="button" />
 
 
 
 
583
  <div style="width:400px;">
584
- <h4><?php echo __('Merge Variables Included', 'mailchimp_i18n');?></h4>
 
 
585
  <?php
586
- if (sizeof($mv)==0 || !is_array($mv)){
587
- echo "<i>".__('No Merge Variables found.', 'mailchimp_i18n')."</i>";
 
 
 
 
588
  } else {
589
  ?>
590
 
591
  <table class='widefat'>
592
- <tr valign="top">
593
- <th><?php echo __('Name', 'mailchimp_i18n');?></th>
594
- <th><?php echo __('Tag', 'mailchimp_i18n');?></th>
595
- <th><?php echo __('Required?', 'mailchimp_i18n');?></th>
596
- <th><?php echo __('Include?', 'mailchimp_i18n');?></th>
597
- </tr>
598
  <?php
599
  foreach($mv as $var){
600
- echo '<tr valign="top">
601
- <td>'.htmlentities($var['name'],ENT_COMPAT,'UTF-8').'</td>
602
- <td>'.$var['tag'].'</td>
603
- <td>'.($var['req']==1?'Y':'N').'</td><td>';
604
- if (!$var['req']){
605
- $opt = 'mc_mv_'.$var['tag'];
606
- echo '<input name="'.$opt.'" type="checkbox" ';
607
- if (get_option($opt)=='on') { echo ' checked="checked" '; }
608
- echo 'id="'.$opt.'" class="code" />';
609
- } else {
610
- echo ' - ';
611
- }
612
- echo '</td></tr>';
 
 
 
 
 
 
 
 
613
  }
614
- echo '</table>';
 
 
615
  }
616
- echo '<h4>'.__('Interest Groups', 'mailchimp_i18n').'</h4>';
617
- if (!$ig || $ig=='' || $ig=='N'){
618
- echo "<i>".__('No Interest Groups Setup for this List', 'mailchimp_i18n')."</i>";
619
- } else {
 
 
 
 
 
 
620
  ?>
621
- <table class='widefat'>
622
- <tr valign="top">
623
- <th width="75px"><label for="mc_show_interest_groups"><?php echo __('Show?', 'mailchimp_i18n');?></label></th><th>
624
- <input name="mc_show_interest_groups" id="mc_show_interest_groups" type="checkbox" <?php if (get_option('mc_show_interest_groups')=='on') { echo 'checked="checked"'; } ?> id="mc_show_interest_groups" class="code" />
625
- </th></tr>
626
- <tr valign="top">
627
- <th><?php echo __('Name', 'mailchimp_i18n');?>:</th><th><?php echo $ig['name']; ?></th>
628
- </tr>
629
- <tr valign="top">
630
- <th><?php echo __('Input Type', 'mailchimp_i18n');?>:</th><td><?php echo $ig['form_field']; ?></td>
631
- </tr>
632
- <tr valign="top">
633
- <th><?php echo __('Options', 'mailchimp_i18n');?>:</th><td><ul>
634
  <?php
635
- foreach($ig['groups'] as $interest){
636
- echo '<li>'.htmlentities($interest,ENT_COMPAT,'UTF-8');
637
- }
638
- echo '</ul></td></tr></table>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
639
  }
640
  ?>
641
  <p class="submit">
642
- <input type="hidden" name="action" value="update" />
643
- <input type="submit" name="change_form_settings" value="<?php echo __('Update Subscribe Form Settings', 'mailchimp_i18n');?>" class="button" />
644
  </p>
645
  </div>
646
  </form>
@@ -650,18 +977,183 @@ if (!$ig || $ig=='' || $ig=='N'){
650
  }//mailchimpSF_setup_page()
651
 
652
 
653
- add_action('plugins_loaded', 'mailchimpSF_register_widgets');
654
- function mailchimpSF_register_widgets(){
 
 
655
 
656
- if (!function_exists('register_sidebar_widget')) {
657
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  }
659
- register_sidebar_widget( 'MailChimp Widget', 'mailchimpSF_display_widget');
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  }
661
 
662
- function mailchimpSF_shortcode($atts){
663
- mailchimpSF_display_widget();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  }
665
- add_shortcode('mailchimpsf_widget', 'mailchimpSF_shortcode');
666
 
667
  ?>
2
  /*
3
  Plugin Name: MailChimp
4
  Plugin URI: http://www.mailchimp.com/plugins/mailchimp-wordpress-plugin/
5
+ Description: The MailChimp plugin allows you to quickly and easily add a signup form for your MailChimp list.
6
+ Version: 1.2
7
+ Author: MailChimp and Crowd Favorite
8
  Author URI: http://mailchimp.com/api/
9
  */
 
10
  /* Copyright 2008 MailChimp.com (email : api@mailchimp.com)
11
 
12
  This program is free software; you can redistribute it and/or modify
23
  along with this program; if not, write to the Free Software
24
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
+
27
+ // Version constant for easy CSS refreshes
28
+ define('MCSF_VER', '1.2');
29
+
30
+ // What's our permission (capability) threshold
31
+ define('MCSF_CAP_THRESHOLD', 'edit_plugins');
32
+
33
+ // Define our location constants, both MCSF_DIR and MCSF_URL
34
+ mailchimpSF_where_am_i();
35
+
36
+ // Get our MailChimp API class in scope
37
  if (!class_exists('MCAPI')) {
38
+ require_once('MCAPI.class.php');
39
  }
40
+
41
  // includes the widget code so it can be easily called either normally or via ajax
42
+ include_once('mailchimp_widget.php');
43
+
44
+ // includes the backwards compatibility functions
45
+ include_once('mailchimp_compat.php');
46
+
47
+
48
+
49
+
50
+ /**
51
+ * Do the following plugin setup steps here
52
+ *
53
+ * Internationalization
54
+ * Resource (JS & CSS) enqueuing
55
+ *
56
+ * @return void
57
+ */
58
+ function mailchimpSF_plugin_init() {
59
+ // Internationalize the plugin
60
+ load_plugin_textdomain( 'mailchimp_i18n', MCSF_DIR.'po/');
61
+
62
+ // Bring in our appropriate JS and CSS resources
63
+ mailchimpSF_load_resources();
64
  }
65
+ add_action( 'init', 'mailchimpSF_plugin_init' );
66
+
67
+ /**
68
+ * Loads the appropriate JS and CSS resources depending on
69
+ * settings and context (admin or not)
70
+ *
71
+ * @return void
72
+ */
73
+ function mailchimpSF_load_resources() {
74
+ // JS
75
+ if (get_option('mc_use_javascript') == 'on') {
76
+ if (!is_admin()) {
77
+ wp_enqueue_script('mailchimpSF_main_js', MCSF_URL.'js/mailchimp.js', array('jquery', 'jquery-form'), MCSF_VER);
78
+ // some javascript to get ajax version submitting to the proper location
79
+ global $wp_scripts;
80
+ $wp_scripts->localize('mailchimpSF_main_js', 'mailchimpSF', array(
81
+ 'ajax_url' => trailingslashit(home_url()),
82
+ ));
83
+ }
84
+ }
85
+
86
+ // CSS
87
+ if (is_admin() && $_GET['page'] == 'mailchimpSF_options') {
88
+ wp_enqueue_style('mailchimpSF_admin_css', MCSF_URL.'css/admin.css');
89
+ }
90
+ else {
91
+ wp_enqueue_style('mailchimpSF_main_css', home_url('?mcsf_action=main_css&ver='.MCSF_VER));
92
+ wp_enqueue_style('mailchimpSF_ie_css', MCSF_URL.'css/ie.css');
93
+ global $wp_styles;
94
+ $wp_styles->add_data( 'mailchimpSF_ie_css', 'conditional', 'IE' );
95
+ }
96
  }
97
+
98
+ /**
99
+ * Handles requests that as light-weight a load as possible.
100
+ * typically, JS or CSS
101
+ **/
102
+ function mailchimpSF_early_request_handler() {
103
+ if (isset($_GET['mcsf_action'])) {
104
+ switch ($_GET['mcsf_action']) {
105
+ case 'main_css':
106
+ header("Content-type: text/css");
107
+ mailchimpSF_main_css();
108
+ exit;
109
+ }
110
+ }
111
  }
112
+ add_action('init', 'mailchimpSF_early_request_handler', 0);
113
+
114
+ /**
115
+ * Outputs the front-end CSS. This checks several options, so it
116
+ * was best to put it in a Request-handled script, as opposed to
117
+ * a static file.
118
+ */
119
+ function mailchimpSF_main_css() {
120
+ ?>
121
+ .mc_error_msg {
122
+ color: red;
123
+ }
124
+ .mc_success_msg {
125
+ color: green;
126
+ }
127
+ .mc_merge_var{
128
+ padding:0;
129
+ margin:0;
130
+ }
131
+ <?php
132
+ // If we're utilizing custom styles
133
  if (get_option('mc_custom_style')=='on'){
134
+ ?>
135
+ #mc_signup_form {
136
+ padding:5px;
137
+ border-width: <?php echo get_option('mc_form_border_width'); ?>px;
138
+ border-style: <?php echo (get_option('mc_form_border_width')==0) ? 'none' : 'solid'; ?>;
139
+ border-color: #<?php echo get_option('mc_form_border_color'); ?>;
140
+ color: #<?php echo get_option('mc_form_text_color'); ?>;
141
+ background-color: #<?php echo get_option('mc_form_background'); ?>;
142
+ }
143
+
144
+
145
+ .mc_custom_border_hdr {
146
+ border-width: <?php echo get_option('mc_header_border_width'); ?>px;
147
+ border-style: <?php echo (get_option('mc_header_border_width')==0) ? 'none' : 'solid'; ?>;
148
+ border-color: #<?php echo get_option('mc_header_border_color'); ?>;
149
+ color: #<?php echo get_option('mc_header_text_color'); ?>;
150
+ background-color: #<?php echo get_option('mc_header_background'); ?>;
151
+ font-size: 1.2em;
152
+ padding:5px 10px;
153
+ width: 100%;
154
+ }
155
+ <?php
156
  }
157
+ ?>
158
+ #mc_signup_container {}
159
+ #mc_signup_form {}
160
+ #mc_signup_form .mc_var_label {}
161
+ #mc_signup_form .mc_input {}
162
+ #mc-indicates-required {
163
+ width:100%;
164
+ }
165
+ #mc_display_rewards {}
166
+ #mc_interests_header {
167
+ font-weight:bold;
168
+ }
169
+ div.mc_interest{
170
+ width:100%;
171
+ }
172
+ #mc_signup_form input.mc_interest {}
173
+ #mc_signup_form select {}
174
+ #mc_signup_form label.mc_interest_label {
175
+ display:inline;
176
+ }
177
+ .mc_signup_submit {
178
+ text-align:center;
179
+ }
180
+ <?php
 
 
 
181
  }
182
 
183
 
184
+ /**
185
+ * Add our settings page to the admin menu
186
+ *
187
+ * @return void
188
+ */
189
+ function mailchimpSF_add_pages(){
190
+ // Add settings page for users who can edit plugins
191
+ add_options_page( __( 'MailChimp Setup', 'mailchimp_i18n' ), __( 'MailChimp Setup', 'mailchimp_i18n' ), MCSF_CAP_THRESHOLD, 'mailchimpSF_options', 'mailchimpSF_setup_page');
192
+ }
 
193
  add_action('admin_menu', 'mailchimpSF_add_pages');
194
 
195
+ function mailchimpSF_request_handler() {
196
+ if (isset($_POST['mcsf_action'])) {
197
+ switch ($_POST['mcsf_action']) {
198
+ case 'logout':
199
+ // Check capability & Verify nonce
200
+ if (!current_user_can(MCSF_CAP_THRESHOLD) || !wp_verify_nonce($_POST['_mcsf_nonce_action'], 'mc_logout')) {
201
+ wp_die('Cheatin&rsquo; huh?');
202
+ }
 
203
 
204
+ // erase API Key
205
+ update_option('mc_apikey', '');
206
+ break;
207
+ case 'update_mc_apikey':
208
+ // Check capability & Verify nonce
209
+ if (!current_user_can(MCSF_CAP_THRESHOLD) || !wp_verify_nonce($_POST['_mcsf_nonce_action'], 'update_mc_api_key')) {
210
+ wp_die('Cheatin&rsquo; huh?');
211
+ }
212
+
213
+ mailchimpSF_set_api_key(strip_tags(stripslashes($_POST['mc_apikey'])));
214
+ break;
215
+ case 'reset_list':
216
+ // Check capability & Verify nonce
217
+ if (!current_user_can(MCSF_CAP_THRESHOLD) || !wp_verify_nonce($_POST['_mcsf_nonce_action'], 'reset_mailchimp_list')) {
218
+ wp_die('Cheatin&rsquo; huh?');
219
+ }
220
+
221
+ mailchimpSF_reset_list_settings();
222
+ break;
223
+ case 'change_form_settings':
224
+ if (!current_user_can(MCSF_CAP_THRESHOLD) || !wp_verify_nonce($_POST['_mcsf_nonce_action'], 'update_general_form_settings')) {
225
+ wp_die('Cheatin&rsquo; huh?');
226
+ }
227
+
228
+ // Update the form settings
229
+ mailchimpSF_save_general_form_settings();
230
+ break;
231
+ case 'mc_submit_signup_form':
232
+ // Validate nonce
233
+ if (!wp_verify_nonce($_POST['_mc_submit_signup_form_nonce'], 'mc_submit_signup_form')) {
234
+ wp_die('Cheatin&rsquo; huh?');
235
+ }
236
+
237
+ // Attempt the signup
238
+ mailchimpSF_signup_submit();
239
+
240
+ // Do a different action for html vs. js
241
+ switch ($_POST['mc_submit_type']) {
242
+ case 'html':
243
+ /* Allow to fall through. The widget will pick up the
244
+ * global message left over from the signup_submit function */
245
+ break;
246
+ case 'js':
247
+ if (!headers_sent()){ //just in case...
248
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT', true, 200);
249
+ }
250
+ echo mailchimpSF_global_msg(); // Don't esc_html this, b/c we've already escaped it
251
+ exit;
252
+ }
253
+ }
254
+ }
255
  }
256
+ add_action('init', 'mailchimpSF_request_handler');
257
+
258
 
 
259
 
260
+ /**
261
+ * Checks to see if we're storing a password, if so, we need
262
+ * to upgrade to the API key
263
+ *
264
+ * @return bool
265
+ **/
266
+ function mailchimpSF_needs_upgrade() {
267
+ $pass = get_option('mc_password');
268
+ return !empty($pass);
269
+ }
270
+
271
+ /**
272
+ * If we have a password, then we need to get our API key, store
273
+ * it and the username, then delete the password
274
+ */
275
+ function mailchimpSF_do_upgrade() {
276
  //some upgrade code for < 0.5 users - we want to rip out the password we've been saving.
277
  $api = new MCAPI(get_option('mc_username'), get_option('mc_password'));
278
+ if (empty($api->errorCode)) {
279
  update_option('mc_apikey', $api->api_key);
280
  //this should already be here, but let's make sure anyway
281
  $req = $api->getAffiliateInfo();
282
  update_option('mc_user_id', $req['user_id']);
283
  } else {
284
+ $msg = "<p class='error_msg'>".esc_html(__( "While upgrading the plugin setup, we were unable to login to your account. You will need to login again and setup your list.", 'mailchimp_i18n' ))."</p>";
285
+ mailchimpSF_global_msg($msg);
286
  }
287
  delete_option('mc_password');
288
  }
289
+
290
+ /**
291
+ * Sets the API Key to whatever value was passed to this func
292
+ *
293
+ * @return array of vars
294
+ **/
295
+ function mailchimpSF_set_api_key($api_key = '') {
 
 
296
  $delete_setup = false;
297
+ $api = new MCAPI($api_key);
298
  $api->ping();
299
+ if (empty($api->errorCode)) {
300
+ $msg = "<p class='success_msg'>".esc_html(__("Success! We were able to verify your API Key! Let's continue, shall we?", 'mailchimp_i18n'))."</p>";
301
+ update_option('mc_apikey', $api_key);
302
  $req = $api->getAccountDetails();
303
  update_option('mc_username', $req['username']);
304
  update_option('mc_user_id', $req['user_id']);
305
+ $cur_list_id = get_option('mc_list_id');
306
+ if (!empty($cur_list_id)) {
307
  $lists = $api->lists();
308
  //but don't delete if the list still exists...
309
  $delete_setup = true;
310
+ foreach($lists as $list) {
311
+ if ($list['id'] == $cur_list_id) {
312
+ $list_id = $_POST['mc_list_id'];
313
+ $delete_setup = false;
314
+ }
315
+ }
316
  }
317
  } else {
318
+ $msg = "<p class='error_msg'>".esc_html(__('Uh-oh, we were unable to verify your API Key. Please check them and try again!', 'mailchimp_i18n'))."<br/>";
319
+ $msg .= __('The server said:', 'mailchimp_i18n')."<em>".esc_html($api->errorMessage)."</em></p>";
320
+ $username = get_option('mc_username');
321
+ if (empty($username)) {
322
  $delete_setup = true;
323
  }
324
  }
325
+
326
+ // Set a global message
327
+ mailchimpSF_global_msg($msg);
328
+
329
+ // If we need to delete our setup, do it
330
  if ($delete_setup){
331
+ mailchimpSF_delete_setup();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  }
333
+
334
  //set these for the form fields below
335
  $user = $_REQUEST['mc_username'];
 
 
 
 
 
 
 
336
 
337
+ // return compact('user', 'delete_setup', 'list_id')
338
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
+ /**
341
+ * Deletes all mailchimp options
342
+ **/
343
+ function mailchimpSF_delete_setup() {
344
+ delete_option('mc_user_id');
345
+ delete_option('mc_rewards');
346
+ delete_option('mc_use_javascript');
347
+ delete_option('mc_use_unsub_link');
348
+ delete_option('mc_list_id');
349
+ delete_option('mc_list_name');
350
+ delete_option('mc_interest_groups');
351
+ delete_option('mc_show_interest_groups');
352
+ $mv = get_option('mc_merge_vars');
353
+ if (is_array($mv)){
354
+ foreach($mv as $var){
355
+ $opt = 'mc_mv_'.$var['tag'];
356
+ delete_option($opt);
357
+ }
358
  }
359
+ delete_option('mc_merge_vars');
360
  }
361
+
362
+ /**
363
+ * Resets the list settings, there's only one list
364
+ * that can have settings at a time, so no list_id
365
+ * parameter is necessary.
366
+ **/
367
+ function mailchimpSF_reset_list_settings() {
368
+
369
  delete_option('mc_list_id');
370
  delete_option('mc_list_name');
371
  delete_option('mc_merge_vars');
389
  delete_option('mc_form_border_color');
390
  delete_option('mc_form_background');
391
  delete_option('mc_form_text_color');
392
+
393
+ $msg = '<p class="success_msg">'.esc_html(__('Successfully Reset your List selection... Now you get to pick again!', 'mailchimp_i18n')).'</p>';
394
+ mailchimpSF_global_msg($msg);
395
+ }
396
+
397
+ /**
398
+ * Gets or sets a global message based on parameter passed to it
399
+ *
400
+ * @return string/bool depending on get/set
401
+ **/
402
+ function mailchimpSF_global_msg($msg = null) {
403
+ global $mcsf_msgs;
404
+
405
+ // Make sure we're formed properly
406
+ if (!is_array($mcsf_msgs)) {
407
+ $mcsf_msgs = array();
408
+ }
409
+
410
+ // See if we're getting
411
+ if (is_null($msg)) {
412
+ return implode('', $mcsf_msgs);
413
+ }
414
+
415
+ // Must be setting
416
+ $mcsf_msgs[] = $msg;
417
+ return true;
418
+ }
419
 
420
+ /**
421
+ * Sets the default options for the option form
422
+ **/
423
+ function mailchimpSF_set_form_defaults($list_name = '') {
424
+ update_option('mc_header_content',__( 'Sign up for', 'mailchimp_i18n' ).' '.$list_name);
425
+ update_option('mc_submit_text',__( 'Subscribe', 'mailchimp_i18n' ));
426
+
427
+ update_option('mc_custom_style','on');
428
+ update_option('mc_use_javascript','on');
429
+ update_option('mc_use_unsub_link','off');
430
+ update_option('mc_header_border_width','1');
431
+ update_option('mc_header_border_color','E3E3E3');
432
+ update_option('mc_header_background','FFFFFF');
433
+ update_option('mc_header_text_color','CC6600');
434
+
435
+ update_option('mc_form_border_width','1');
436
+ update_option('mc_form_border_color','C4D3EA');
437
+ update_option('mc_form_background','EEF3F8');
438
+ update_option('mc_form_text_color','555555');
439
+
440
+ update_option('mc_show_interest_groups', 'on' );
441
  }
442
+
443
+ /**
444
+ * Saves the General Form settings on the options page
445
+ *
446
+ * @return void
447
+ **/
448
+ function mailchimpSF_save_general_form_settings() {
449
+ if (isset($_POST['mc_rewards'])){
450
  update_option('mc_rewards', 'on');
451
+ $msg = '<p class="success_msg">'.__('Monkey Rewards turned On!', 'mailchimp_i18n').'</p>';
452
+ mailchimpSF_global_msg($msg);
453
  } else if (get_option('mc_rewards')!='off') {
454
  update_option('mc_rewards', 'off');
455
+ $msg = '<p class="success_msg">'.__('Monkey Rewards turned Off!', 'mailchimp_i18n').'</p>';
456
+ mailchimpSF_global_msg($msg);
457
  }
458
+ if (isset($_POST['mc_use_javascript'])){
459
  update_option('mc_use_javascript', 'on');
460
+ $msg = '<p class="success_msg">'.__('Fancy Javascript submission turned On!', 'mailchimp_i18n').'</p>';
461
+ mailchimpSF_global_msg($msg);
462
  } else if (get_option('mc_use_javascript')!='off') {
463
  update_option('mc_use_javascript', 'off');
464
+ $msg = '<p class="success_msg">'.__('Fancy Javascript submission turned Off!', 'mailchimp_i18n').'</p>';
465
+ mailchimpSF_global_msg($msg);
466
  }
467
 
468
+ if (isset($_POST['mc_use_unsub_link'])){
469
  update_option('mc_use_unsub_link', 'on');
470
+ $msg = '<p class="success_msg">'.__('Unsubscribe link turned On!', 'mailchimp_i18n').'</p>';
471
+ mailchimpSF_global_msg($msg);
472
  } else if (get_option('mc_use_unsub_link')!='off') {
473
  update_option('mc_use_unsub_link', 'off');
474
+ $msg = '<p class="success_msg">'.__('Unsubscribe link turned Off!', 'mailchimp_i18n').'</p>';
475
+ mailchimpSF_global_msg($msg);
476
  }
477
 
478
+ $content = stripslashes($_POST['mc_header_content']);
479
  $content = str_replace("\r\n","<br/>", $content);
480
  update_option('mc_header_content', $content );
481
 
482
+ $content = stripslashes($_POST['mc_subheader_content']);
483
  $content = str_replace("\r\n","<br/>", $content);
484
  update_option('mc_subheader_content', $content );
485
 
486
 
487
+ $submit_text = stripslashes($_POST['mc_submit_text']);
488
  $submit_text = str_replace("\r\n","", $submit_text);
489
  update_option('mc_submit_text', $submit_text);
490
+
491
+ // Set Custom Style option
492
+ update_option('mc_custom_style', (isset($_POST['mc_custom_style'])) ? 'on' : 'off');
 
 
 
493
 
494
  //we told them not to put these things we are replacing in, but let's just make sure they are listening...
495
+ update_option('mc_header_border_width',str_replace('px','',$_POST['mc_header_border_width']) );
496
+ update_option('mc_header_border_color', str_replace('#','',$_POST['mc_header_border_color']));
497
+ update_option('mc_header_background',str_replace('#','',$_POST['mc_header_background']));
498
+ update_option('mc_header_text_color', str_replace('#','',$_POST['mc_header_text_color']));
499
+
500
+ update_option('mc_form_border_width',str_replace('px','',$_POST['mc_form_border_width']) );
501
+ update_option('mc_form_border_color', str_replace('#','',$_POST['mc_form_border_color']));
502
+ update_option('mc_form_background',str_replace('#','',$_POST['mc_form_background']));
503
+ update_option('mc_form_text_color', str_replace('#','',$_POST['mc_form_text_color']));
504
+
505
+ update_option('mc_show_interest_groups', (isset($_POST['mc_show_interest_groups'])) ? 'on' : 'off');
506
+
 
 
 
507
  $mv = get_option('mc_merge_vars');
508
+ if (is_array($mv)) {
509
+ foreach($mv as $var){
510
+ $opt = 'mc_mv_'.$var['tag'];
511
+ if (isset($_POST[$opt]) || $var['req']=='Y'){
512
+ update_option($opt,'on');
513
+ } else {
514
+ update_option($opt,'off');
515
+ }
516
+ }
517
  }
518
+ $msg = '<p class="success_msg">'.esc_html(__('Successfully Updated your List Subscribe Form Settings!', 'mailchimp_i18n')).'</p>';
519
+ mailchimpSF_global_msg($msg);
520
+ }
521
+
522
+ /**
523
+ * Sees if the user changed the list, and updates options accordingly
524
+ **/
525
+ function mailchimpSF_change_list_if_necessary($api_key) {
526
+ // Simple permission check before going through all this
527
+ if (!current_user_can(MCSF_CAP_THRESHOLD)) { return; }
528
+
529
+ $api = new MCAPI($api_key);
530
+ $lists = (array)$api->lists();
531
+
532
+ /* If our incoming list ID (the one chosen in the select dropdown)
533
+ is in our array of lists, the set it to be the active list */
534
+ foreach($lists as $list) {
535
+ if ($list['id'] == $_POST['mc_list_id']) {
536
+ $list_id = $_POST['mc_list_id'];
537
+ $list_name = $list['name'];
538
  }
539
  }
540
+
541
+ $orig_list = get_option('mc_list_id');
542
+ if ($list_id != '') {
543
+ update_option('mc_list_id', $list_id);
544
+ update_option('mc_list_name', $list_name);
545
+
546
+ // See if the user changed the list
547
+ if ($orig_list != $list_id){
548
+ // The user changed the list, Reset the Form Defaults
549
+ mailchimpSF_set_form_defaults($list_name);
550
+ }
551
+
552
+ // Grab the merge vars and interest groups
553
+ $mv = $api->listMergeVars($list_id);
554
+ $ig = $api->listInterestGroups($list_id);
555
 
556
+ update_option('mc_merge_vars', $mv);
557
+ foreach($mv as $var){
558
+ $opt = 'mc_mv_'.$var['tag'];
559
+ //turn them all on by default
560
+ if ($orig_list != $list_id){
561
+ update_option($opt, 'on' );
562
+ }
563
+ }
564
+ update_option('mc_interest_groups', $ig);
565
+
566
+ $msg = '<p class="success_msg">'.
567
+ sprintf(
568
+ __( 'Success! Loaded and saved the info for %d Merge Variables and %d Interest Groups from your list'),
569
+ count($mv),
570
+ count($ig)
571
+ ).
572
+ ' "'.$list_name.'"<br/><br/>'.
573
+ __('Now you should either Turn On the MailChimp Widget or change your options below, then turn it on.', 'mailchimp_i18n').'</p>';
574
+ mailchimpSF_global_msg($msg);
575
+ }
576
  }
577
+
578
+ /**
579
+ * Outputs the Settings/Options page
580
+ */
581
+ function mailchimpSF_setup_page() {
582
+
583
+ // See if we need an upgrade
584
+ if (mailchimpSF_needs_upgrade()) {
585
+ // remove password option if it's set
586
+ mailchimpSF_do_upgrade();
587
  }
588
+
589
  ?>
590
+ <div class="wrap">
591
+
592
+ <h2><?php esc_html_e(__( 'MailChimp List Setup', 'mailchimp_i18n'));?> </h2>
593
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
594
  <?php
595
+
596
+ $user = get_option('mc_username');
597
+ $api_key = get_option('mc_apikey');
598
+
599
+ // If we have an API Key, see if we need to change the lists and its options
600
+ if (!empty($api_key)){
601
+ mailchimpSF_change_list_if_necessary($api_key);
602
  }
603
+
604
+
605
+
606
+ // Display our success/error message(s) if have them
607
+ if (mailchimpSF_global_msg() != ''){
608
+ // Message has already been html escaped, so we don't want to 2x escape it here
609
+ ?>
610
+ <div id="mc_message" class=""><?php echo mailchimpSF_global_msg(); ?></div>
611
+ <?php
612
+ }
613
+
614
+
615
+ // If we don't have an API Key, do a login form
616
+ if (get_option('mc_apikey') == '') {
617
+ ?>
618
+ <div>
619
+ <form method="post" action="options-general.php?page=mailchimpSF_options">
620
+ <h3><?php esc_html_e(__('Login Info', 'mailchimp_i18n'));?></h3>
621
+ <?php esc_html_e(__('To start using the MailChimp plugin, we first need to login and get your API Key. Please enter your MailChimp API Key below.', 'mailchimp_i18n')); ?>
622
+
623
+ <br/>
624
+
625
+ <?php
626
+ echo sprintf(
627
+ '%1$s <a href="http://www.mailchimp.com/signup/" target="_blank">%2$s</a>',
628
+ esc_html(__("Don't have a MailChimp account?", 'mailchimp_i18n')),
629
+ esc_html(__('Try one for Free!', 'mailchimp_i18n'))
630
+ );
631
+ ?>
632
+
633
+ <br/>
634
+
635
+ <table class="form-table">
636
+ <tr valign="top">
637
+ <th scope="row"><?php esc_html_e(__('API Key', 'mailchimp_i18n')); ?>:</th>
638
+ <td>
639
+ <input name="mc_apikey" type="text" id="mc_apikey" class="code" value="<?php esc_attr_e($apikey); ?>" size="32" />
640
+ <br/>
641
+ <a href="http://admin.mailchimp.com/account/api-key-popup" target="_blank">get your API Key here</a>
642
+ </td>
643
+ </tr>
644
+ </table>
645
+
646
+ <input type="hidden" name="mcsf_action" value="update_mc_apikey"/>
647
+ <input type="submit" name="Submit" value="<?php esc_attr_e(__('Save & Check'));?>" class="button" />
648
+ <?php wp_nonce_field('update_mc_api_key', '_mcsf_nonce_action'); ?>
649
+ </form>
650
+ </div>
651
+
652
+ <?php
653
+ if (get_option('mc_username')!=''){
654
+ ?>
655
+ <strong><?php esc_html_e(__('Notes', 'mailchimp_i18n')); ?>:</strong>
656
+ <ul>
657
+ <li><em><?php esc_html_e(__('Changing your settings at MailChimp.com may cause this to stop working.', 'mailchimp_i18n')); ?></em></li>
658
+ <li><em><?php esc_html_e(__('If you change your login to a different account, the info you have setup below will be erased.', 'mailchimp_i18n')); ?></em></li>
659
+ <li><em><?php esc_html_e(__('If any of that happens, no biggie - just reconfigure your login and the items below...', 'mailchimp_i18n')); ?></em></li>
660
+ </ul>
661
+ <br/>
662
+ <?php
663
+ }
664
+ } // End of login form
665
+
666
+ // Start logout form
667
+ else {
668
  ?>
669
+ <table style="min-width:400px;">
670
+ <tr>
671
+ <td><h3><?php esc_html_e(__('Logged in as', 'mailchimp_i18n'));?>: <?php esc_html_e(get_option('mc_username')); ?></h3>
672
+ </td>
673
+ <td>
674
+ <form method="post" action="options-general.php?page=mailchimpSF_options">
675
+ <input type="hidden" name="mcsf_action" value="logout"/>
676
+ <input type="submit" name="Submit" value="<?php esc_attr_e(__('Logout', 'mailchimp_i18n'));?>" class="button" />
677
+ <?php wp_nonce_field('mc_logout', '_mcsf_nonce_action'); ?>
678
+ </form>
679
+ </td>
680
+ </tr>
681
+ </table>
682
  <?php
683
+ } // End Logout form
684
+
685
+
686
+
687
  //Just get out if nothing else matters...
688
  if (get_option('mc_apikey') == '') return;
689
 
690
  if (get_option('mc_apikey')!=''){
691
+ ?>
692
+ <h3><?php esc_html_e(__('Your Lists', 'mailchimp_i18n')); ?></h3>
693
+
 
694
  <div>
695
+
696
+ <p><?php esc_html_e(__('Please select the List you wish to create a Signup Form for.', 'mailchimp_i18n')); ?></p>
697
+
698
+ <form method="post" action="options-general.php?page=mailchimpSF_options">
699
+ <?php
700
+ $GLOBALS["mc_api_key"] = get_option('mc_apikey');
701
+ $api = new MCAPI('no_login','is_needed');
702
+ $lists = (array)$api->lists();
703
+ rsort($lists);
704
+ if (count($lists) == 0) {
705
+ ?>
706
+ <span class='error_msg'>
707
+ <?php
708
+ echo sprintf(
709
+ esc_html(__("Uh-oh, you don't have any lists defined! Please visit %s, login, and setup a list before using this tool!", 'mailchimp_i18n')),
710
+ "<a href='http://www.mailchimp.com/'>MailChimp</a>"
711
+ );
712
+ ?>
713
+ </span>
714
+ <?php
715
+ }
716
+ else {
717
+ ?>
718
+ <table style="min-width:400px">
719
+ <tr>
720
+ <td>
721
+ <select name="mc_list_id" style="min-width:200px;">
722
+ <option value=""> &mdash; <?php esc_html_e(__('Select A List','mailchimp_i18n')); ?> &mdash; </option>
723
+ <?php
724
+ foreach ($lists as $list) {
725
+ $option = get_option('mc_list_id');
726
+ ?>
727
+ <option value="<?php esc_attr_e($list['id']); ?>"<?php selected($list['id'], $option); ?>><?php esc_html_e($list['name']); ?></option>
728
+ <?php
729
+ }
730
+ ?>
731
+ </select>
732
+ </td>
733
+ <td>
734
+ <input type="hidden" name="mcsf_action" value="update_mc_list_id" />
735
+ <input type="submit" name="Submit" value="<?php esc_attr_e(__('Update List', 'mailchimp_i18n')); ?>" class="button" />
736
+ </td>
737
+ </tr>
738
+ <tr>
739
+ <td colspan="2">
740
+ <strong><?php esc_html_e(__('Note:', 'mailchimp_i18n')); ?></strong> <em><?php esc_html_e(__('Updating your list will not cause settings below to be lost. Changing to a new list will.', 'mailchimp_i18n')); ?></em>
741
+ </td>
742
+ </tr>
743
+ </table>
744
+ <?php
745
+ } //end select list
746
+ ?>
747
+ </form>
748
  </div>
749
+
750
  <br/>
751
+
752
  <?php
753
+ }
754
+ else {
755
  //display the selected list...
756
  ?>
757
 
 
 
758
  <p class="submit">
759
+ <form method="post" action="options-general.php?page=mailchimpSF_options">
760
+ <input type="hidden" name="mcsf_action" value="reset_list" />
761
+ <input type="submit" name="reset_list" value="<?php esc_attr_e(__('Reset List Options and Select again', 'mailchimp_i18n')); ?>" class="button" />
762
+ <?php wp_nonce_field('reset_mailchimp_list', '_mcsf_nonce_action'); ?>
763
+ </form>
764
  </p>
765
+ <h3><?php esc_html_e(__('Subscribe Form Widget Settings for this List', 'mailchimp_i18n')); ?>:</h3>
766
+ <h4><?php esc_html_e(__('Selected MailChimp List', 'mailchimp_i18n')); ?>: <?php esc_html_e(get_option('mc_list_name')); ?></h4>
767
  <?php
768
  }
769
  //Just get out if nothing else matters...
770
  if (get_option('mc_list_id') == '') return;
771
+
772
+
773
+ // The main Settings form
 
 
 
 
 
 
 
 
774
  ?>
775
 
776
  <div>
777
+ <form method="post" action="options-general.php?page=mailchimpSF_options">
778
  <div style="width:600px;">
779
+ <input type="hidden" name="mcsf_action" value="change_form_settings">
780
+ <?php wp_nonce_field('update_general_form_settings', '_mcsf_nonce_action'); ?>
781
+ <input type="submit" value="<?php esc_attr_e(__('Update Subscribe Form Settings', 'mailchimp_i18n')); ?>" class="button" />
782
  <table class="widefat">
783
  <tr valign="top">
784
+ <th scope="row"><?php esc_html_e(__('Monkey Rewards', 'mailchimp_i18n')); ?>:</th>
785
+ <td><input name="mc_rewards" type="checkbox"<?php if (get_option('mc_rewards')=='on' || get_option('mc_rewards')=='' ) { echo ' checked="checked"'; } ?> id="mc_rewards" class="code" />
786
+ <em><label for="mc_rewards"><?php esc_html_e(__('turning this on will place a "powered by MailChimp" link in your form that will earn you credits with us. It is optional and can be turned on or off at any time.', 'mailchimp_i18n')); ?></label></em>
787
  </td>
788
  </tr>
789
  <tr valign="top">
790
+ <th scope="row"><?php esc_html_e(__('Use Javascript Support?', 'mailchimp_i18n')); ?>:</th>
791
+ <td><input name="mc_use_javascript" type="checkbox" <?php checked(get_option('mc_use_javascript'), 'on'); ?> id="mc_use_javascript" class="code" />
792
+ <em><label for="mc_use_javascript"><?php esc_html_e(__('turning this on will use fancy javascript submission and should degrade gracefully for users not using javascript. It is optional and can be turned on or off at any time.', 'mailchimp_i18n')); ?></label></em>
793
  </td>
794
  </tr>
795
  <tr valign="top">
796
+ <th scope="row"><?php esc_html_e(__('Include Unsubscribe link?', 'mailchimp_i18n')); ?>:</th>
797
+ <td><input name="mc_use_unsub_link" type="checkbox"<?php checked(get_option('mc_use_unsub_link'), 'on'); ?> id="mc_use_unsub_link" class="code" />
798
+ <em><label for="mc_use_unsub_link"><?php esc_html_e(__('turning this on will add a link to your host unsubscribe form', 'mailchimp_i18n')); ?></label></em>
799
  </td>
800
  </tr>
801
  <tr valign="top">
802
+ <th scope="row"><?php esc_html_e(__('Header content', 'mailchimp_i18n')); ?>:</th>
803
  <td>
804
+ <textarea name="mc_header_content" rows="2" cols="50"><?php esc_html_e(get_option('mc_header_content')); ?></textarea><br/>
805
+ <em><?php esc_html_e(__('You can fill this with your own Text, HTML markup (including image links), or Nothing!', 'mailchimp_i18n')); ?></em>
806
  </td>
807
  </tr>
808
 
809
  <tr valign="top">
810
+ <th scope="row"><?php esc_html_e(__('Sub-header content', 'mailchimp_i18n')); ?>:</th>
811
  <td>
812
+ <textarea name="mc_subheader_content" rows="2" cols="50"><?php esc_html_e(get_option('mc_subheader_content')); ?></textarea><br/>
813
+ <em><?php esc_html_e(__('You can fill this with your own Text, HTML markup (including image links), or Nothing!', 'mailchimp_i18n')); ?></em>.
814
+ <?php esc_html_e(__('This will be displayed under the heading and above the form.', 'mailchimp_i18n')); ?>
815
  </td>
816
  </tr>
817
 
818
 
819
  <tr valign="top">
820
+ <th scope="row"><?php esc_html_e(__('Submit Button text', 'mailchimp_i18n')); ?>:</th>
821
  <td>
822
+ <input type="text" name="mc_submit_text" size="30" value="<?php esc_attr_e(get_option('mc_submit_text')); ?>"/>
823
  </td>
824
  </tr>
825
 
826
  <tr valign="top">
827
+ <th scope="row"><?php esc_html_e(__('Custom Styling', 'mailchimp_i18n')); ?>:</th>
828
  <td>
829
  <table class="widefat">
830
 
831
+ <tr><th><label for="mc_custom_style"><?php esc_html_e(__('Turned On?', 'mailchimp_i18n')); ?></label></th><td><input type="checkbox" name="mc_custom_style" id="mc_custom_style"<?php checked(get_option('mc_custom_style'), 'on'); ?> /></td></tr>
832
+ <tr><th colspan="2"><?php esc_html_e(__('Header Settings (only applies if there are no HTML tags in the Header Content area above)', 'mailchimp_i18n')); ?>:</th></tr>
833
+ <tr><th><?php esc_html_e(__('Border Width', 'mailchimp_i18n')); ?>:</th><td><input type="text" name="mc_header_border_width" size="3" maxlength="3" value="<?php esc_attr_e(get_option('mc_header_border_width')); ?>"/> px<br/>
834
+ <em><?php esc_html_e(__('Set to 0 for no border, do not enter', 'mailchimp_i18n')); ?> <strong>px</strong>!</em>
835
  </td></tr>
836
+ <tr><th><?php esc_html_e(__('Border Color', 'mailchimp_i18n')); ?>:</th><td>#<input type="text" name="mc_header_border_color" size="7" maxlength="6" value="<?php esc_attr_e(get_option('mc_header_border_color')); ?>"/><br/>
837
+ <em><?php esc_html_e(__('do not enter initial', 'mailchimp_i18n')); ?> <strong>#</strong></em>
838
  </td></tr>
839
+ <tr><th>Text Color:</th><td>#<input type="text" name="mc_header_text_color" size="7" maxlength="6" value="<?php esc_attr_e(get_option('mc_header_text_color')); ?>"/><br/>
840
+ <em><?php esc_html_e(__('do not enter initial', 'mailchimp_i18n')); ?> <strong>#</strong></em>
841
  </td></tr>
842
+ <tr><th>Background Color:</th><td>#<input type="text" name="mc_header_background" size="7" maxlength="6" value="<?php esc_attr_e(get_option('mc_header_background')); ?>"/><br/>
843
+ <em><?php esc_html_e(__('do not enter initial', 'mailchimp_i18n')); ?> <strong>#</strong></em>
844
  </td></tr>
845
 
846
+ <tr><th colspan="2"><?php esc_html_e(__('Form Settings', 'mailchimp_i18n')); ?>:</th></tr>
847
+ <tr><th><?php esc_html_e(__('Border Width', 'mailchimp_i18n')); ?>:</th><td><input type="text" name="mc_form_border_width" size="3" maxlength="3" value="<?php esc_attr_e(get_option('mc_form_border_width')); ?>"/> px<br/>
848
+ <em><?php esc_html_e(__('Set to 0 for no border, do not enter', 'mailchimp_i18n')); ?> <strong>px</strong>!</em>
849
  </td></tr>
850
+ <tr><th><?php esc_html_e(__('Border Color', 'mailchimp_i18n')); ?>:</th><td>#<input type="text" name="mc_form_border_color" size="7" maxlength="6" value="<?php esc_attr_e(get_option('mc_form_border_color')); ?>"/><br/>
851
+ <em><?php esc_html_e(__('do not enter initial', 'mailchimp_i18n')); ?> <strong>#</strong></em>
852
  </td></tr>
853
+ <tr><th>Text Color:</th><td>#<input type="text" name="mc_form_text_color" size="7" maxlength="6" value="<?php esc_attr_e(get_option('mc_form_text_color')); ?>"/><br/>
854
+ <em><?php esc_html_e(__('do not enter initial', 'mailchimp_i18n')); ?> <strong>#</strong></em>
855
  </td></tr>
856
+ <tr><th>Background Color:</th><td>#<input type="text" name="mc_form_background" size="7" maxlength="6" value="<?php esc_attr_e(get_option('mc_form_background')); ?>"/><br/>
857
+ <em><?php esc_html_e(__('do not enter initial', 'mailchimp_i18n')); ?> <strong>#</strong></em>
858
  </td></tr>
859
  </table>
860
  </td>
861
  </tr>
862
  </table>
863
  </div>
864
+ <input type="submit" value="<?php esc_attr_e(__('Update Subscribe Form Settings', 'mailchimp_i18n')); ?>" class="button" />
865
+
866
+ <?php
867
+ // Merge Variables Table
868
+ ?>
869
  <div style="width:400px;">
870
+
871
+ <h4><?php esc_html_e(__('Merge Variables Included', 'mailchimp_i18n')); ?></h4>
872
+
873
  <?php
874
+ $mv = get_option('mc_merge_vars');
875
+
876
+ if (count($mv) == 0 || !is_array($mv)){
877
+ ?>
878
+ <em><?php esc_html_e(__('No Merge Variables found.', 'mailchimp_i18n')); ?></em>
879
+ <?php
880
  } else {
881
  ?>
882
 
883
  <table class='widefat'>
884
+ <tr valign="top">
885
+ <th><?php esc_html_e(__('Name', 'mailchimp_i18n'));?></th>
886
+ <th><?php esc_html_e(__('Tag', 'mailchimp_i18n'));?></th>
887
+ <th><?php esc_html_e(__('Required?', 'mailchimp_i18n'));?></th>
888
+ <th><?php esc_html_e(__('Include?', 'mailchimp_i18n'));?></th>
889
+ </tr>
890
  <?php
891
  foreach($mv as $var){
892
+ ?>
893
+ <tr valign="top">
894
+ <td><?php esc_html_e($var['name']); ?></td>
895
+ <td><?php esc_html_e($var['tag']); ?></td>
896
+ <td><?php esc_html_e(($var['req'] == 1) ? 'Y' : 'N'); ?></td>
897
+ <td>
898
+ <?php
899
+ if (!$var['req']){
900
+ $opt = 'mc_mv_'.$var['tag'];
901
+ ?>
902
+ <input name="<?php esc_attr_e($opt); ?>" type="checkbox" id="<?php esc_attr_e($opt); ?>" class="code"<?php checked(get_option($opt), 'on'); ?> />
903
+ <?php
904
+ } else {
905
+ ?>
906
+ &nbsp;&mdash;&nbsp;
907
+ <?php
908
+ }
909
+ ?>
910
+ </td>
911
+ </tr>
912
+ <?php
913
  }
914
+ ?>
915
+ </table>
916
+ <?php
917
  }
918
+
919
+ ?>
920
+
921
+ <h4><?php esc_html_e(__('Interest Groups', 'mailchimp_i18n')); ?></h4>
922
+
923
+ <?php
924
+ // Interest Groups Table
925
+ $ig = get_option('mc_interest_groups');
926
+
927
+ if (!is_array($ig) || empty($ig) || $ig == 'N') {
928
  ?>
929
+ <em><?php esc_html_e(__('No Interest Groups Setup for this List', 'mailchimp_i18n')); ?></em>
 
 
 
 
 
 
 
 
 
 
 
 
930
  <?php
931
+ }
932
+ else {
933
+ ?>
934
+ <table class='widefat'>
935
+ <tr valign="top">
936
+ <th width="75px">
937
+ <label for="mc_show_interest_groups"><?php esc_html_e(__('Show?', 'mailchimp_i18n')); ?></label>
938
+ </th>
939
+ <th>
940
+ <input name="mc_show_interest_groups" id="mc_show_interest_groups" type="checkbox" id="mc_show_interest_groups" class="code"<?php checked('on', get_option('mc_show_interest_groups')); ?> />
941
+ </th>
942
+ </tr>
943
+ <tr valign="top">
944
+ <th><?php esc_html_e(__('Name', 'mailchimp_i18n')); ?>:</th>
945
+ <th><?php esc_html_e($ig['name']); ?></th>
946
+ </tr>
947
+ <tr valign="top">
948
+ <th><?php esc_html_e(__('Input Type', 'mailchimp_i18n')); ?>:</th>
949
+ <td><?php esc_html_e($ig['form_field']); ?></td>
950
+ </tr>
951
+ <tr valign="top">
952
+ <th><?php esc_html_e(__('Options', 'mailchimp_i18n')); ?>:</th>
953
+ <td>
954
+ <ul>
955
+ <?php
956
+ foreach($ig['groups'] as $interest){
957
+ ?>
958
+ <li><?php esc_html_e($interest); ?></li>
959
+ <?php
960
+ }
961
+ ?>
962
+ </ul>
963
+ </td>
964
+ </tr>
965
+ </table>
966
+ <?php
967
  }
968
  ?>
969
  <p class="submit">
970
+ <input type="submit" value="<?php esc_attr_e(__('Update Subscribe Form Settings', 'mailchimp_i18n')); ?>" class="button" />
 
971
  </p>
972
  </div>
973
  </form>
977
  }//mailchimpSF_setup_page()
978
 
979
 
980
+ function mailchimpSF_register_widgets() {
981
+ register_widget('mailchimpSF_Widget');
982
+ }
983
+ add_action('widgets_init', 'mailchimpSF_register_widgets');
984
 
985
+ function mailchimpSF_shortcode($atts){
986
+ ob_start();
987
+ mailchimpSF_signup_form();
988
+ return ob_get_clean();
989
+ }
990
+ add_shortcode('mailchimpsf_form', 'mailchimpSF_shortcode');
991
+
992
+ /**
993
+ * Attempts to signup a user, per the $_POST args.
994
+ *
995
+ * This sets a global message, that is then used in the widget
996
+ * output to retrieve and display that message.
997
+ *
998
+ * @return bool
999
+ */
1000
+ function mailchimpSF_signup_submit() {
1001
+ $mv = get_option('mc_merge_vars');
1002
+ $ig = get_option('mc_interest_groups');
1003
+
1004
+ $success = true;
1005
+ $listId = get_option('mc_list_id');
1006
+ $email = $_POST['mc_mv_EMAIL'];
1007
+ $merge = $errs = array(); // Set up some vars
1008
+
1009
+ // Loop through our Merge Vars, and if they're empty, but required, then print an error, and mark as failed
1010
+ foreach($mv as $var) {
1011
+ $opt = 'mc_mv_'.$var['tag'];
1012
+ if ($var['req'] == 'Y' && trim($_POST[$opt]) == '') {
1013
+ $success = false;
1014
+ $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name']));
1015
+ }
1016
+ else {
1017
+ if ($var['tag'] != 'EMAIL') {
1018
+ $merge[$var['tag']] = $_POST[$opt];
1019
+ }
1020
+ }
1021
+ }
1022
+
1023
+ // Head back to the beginning of the merge vars array
1024
+ reset($mv);
1025
+
1026
+
1027
+ if (get_option('mc_show_interest_groups')) {
1028
+ switch ($ig['form_field']) {
1029
+ case 'select':
1030
+ case 'dropdown':
1031
+ case 'radio':
1032
+ $merge['INTERESTS'] = str_replace(',', '\,', $_POST['interests']);
1033
+ break;
1034
+ case 'checkbox':
1035
+ if (isset($_POST['interests'])) {
1036
+ foreach ($_POST['interests'] as $i => $nothing) {
1037
+ $merge['INTERESTS'] .= str_replace(',', '\,', $i).',';
1038
+ }
1039
+ }
1040
+ break;
1041
+ default:
1042
+ // Nothing
1043
+ break;
1044
+ }
1045
+ }
1046
+
1047
+
1048
+ // If we're good
1049
+ if ($success) {
1050
+ // Clear out empty merge vars
1051
+ foreach ($merge as $k => $v) {
1052
+ if (trim($v) === '') {
1053
+ unset($merge[$k]);
1054
+ }
1055
+ }
1056
+
1057
+ // If we have an empty $merge, then assign empty string.
1058
+ if (count($merge) == 0 || $merge == '') {
1059
+ $merge = '';
1060
+ }
1061
+
1062
+ $GLOBALS["mc_api_key"] = get_option('mc_apikey');
1063
+ $api = new MCAPI('no_login','is_needed');
1064
+ $retval = $api->listSubscribe( $listId, $email, $merge);
1065
+ if (!$retval) {
1066
+ switch($api->errorCode) {
1067
+ case '214' :
1068
+ $errs[] = __("That email address is already subscribed to the list", 'mailchimp_i18n').'.';
1069
+ break;
1070
+ case '250' :
1071
+ list($field, $rest) = explode(' ', $api->errorMessage, 2);
1072
+ $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($field));
1073
+ break;
1074
+ case '254' :
1075
+ list($i1, $i2, $i3, $field, $rest) = explode(' ',$api->errorMessage,5);
1076
+ $errs[] = sprintf(__("%s has invalid content.", 'mailchimp_i18n'), esc_html($field));
1077
+ break;
1078
+ case '270' :
1079
+ $errs[] = __("An invalid Interest Group was selected", 'mailchimp_i18n').'.';
1080
+ break;
1081
+ case '502' :
1082
+ $errs[] = __("That email address is invalid", 'mailchimp_i18n').'.';
1083
+ break;
1084
+ default:
1085
+ $errs[] = $api->errorCode.":".$api->errorMessage;
1086
+ break;
1087
+ }
1088
+ $success = false;
1089
+ }
1090
+ else {
1091
+ $msg = "<strong class='mc_success_msg'>".esc_html(__("Success, you've been signed up! Please look for our confirmation email!", 'mailchimp_i18n'))."</strong>";
1092
+ }
1093
  }
1094
+
1095
+ // If we have errors, then show them
1096
+ if (count($errs) > 0) {
1097
+ $msg = '<span class="mc_error_msg">';
1098
+ foreach($errs as $error){
1099
+ $msg .= '&raquo; '.esc_html($error).'<br />';
1100
+ }
1101
+ $msg .= '</span>';
1102
+ }
1103
+
1104
+ // Set our global message
1105
+ mailchimpSF_global_msg($msg);
1106
+
1107
+ return $success;
1108
  }
1109
 
1110
+
1111
+
1112
+ /**********************
1113
+ * Utility Functions *
1114
+ **********************/
1115
+ /**
1116
+ * Utility function to allow placement of plugin in plugins, mu-plugins, child or parent theme's plugins folders
1117
+ *
1118
+ * This function must be ran _very early_ in the load process, as it sets up important constants for the rest of the plugin
1119
+ */
1120
+ function mailchimpSF_where_am_i() {
1121
+ $locations = array(
1122
+ 'plugins' => array(
1123
+ 'dir' => WP_PLUGIN_DIR,
1124
+ 'url' => WP_PLUGIN_URL,
1125
+ ),
1126
+ 'mu_plugins' => array(
1127
+ 'dir' => WPMU_PLUGIN_DIR,
1128
+ 'url' => WPMU_PLUGIN_URL,
1129
+ ),
1130
+ 'template' => array(
1131
+ 'dir' => trailingslashit(get_template_directory()).'plugins/',
1132
+ 'url' => trailingslashit(get_template_directory_uri()).'plugins/',
1133
+ ),
1134
+ 'stylesheet' => array(
1135
+ 'dir' => trailingslashit(get_stylesheet_directory()).'plugins/',
1136
+ 'url' => trailingslashit(get_stylesheet_directory_uri()).'plugins/',
1137
+ ),
1138
+ );
1139
+
1140
+ // Set defaults
1141
+ $mscf_dir = trailingslashit(WP_PLUGIN_DIR).'mailchimp/';
1142
+ $mscf_url = trailingslashit(WP_PLUGIN_URL).'mailchimp/';
1143
+
1144
+ // Try our hands at finding the real location
1145
+ foreach ($locations as $key => $loc) {
1146
+ $dir = trailingslashit($loc['dir']).'mailchimp/';
1147
+ $url = trailingslashit($loc['url']).'mailchimp/';
1148
+ if (is_file($dir.basename(__FILE__))) {
1149
+ $mscf_dir = $dir;
1150
+ $mscf_url = $url;
1151
+ break;
1152
+ }
1153
+ }
1154
+ define('MCSF_DIR', $mscf_dir);
1155
+ define('MCSF_URL', $mscf_url);
1156
  }
1157
+
1158
 
1159
  ?>
mailchimp_ajax.php DELETED
@@ -1,8 +0,0 @@
1
- <?php
2
- ob_start();//start buffering for the ajax call just in case
3
- include_once('../../../wp-blog-header.php');
4
- include_once('mailchimp_includes.php');
5
- ob_end_clean();ob_end_clean();ob_end_clean();//stop buffering and discard anything output
6
- mailchimpSF_display_widget();
7
- exit;
8
- ?>
 
 
 
 
 
 
 
 
mailchimp_compat.php ADDED
@@ -0,0 +1,100 @@