| 1 |
<?php |
| 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.3 |
| 7 |
Author: MailChimp and Crowd Favorite |
| 8 |
Author URI: http://mailchimp.com/api/ |
| 9 |
*/ |
| 10 |
/* Copyright 2008-2012 MailChimp.com (email : api@mailchimp.com) |
| 11 |
|
| 12 |
This program is free software; you can redistribute it and/or modify |
| 13 |
it under the terms of the GNU General Public License as published by |
| 14 |
the Free Software Foundation; either version 2 of the License, or |
| 15 |
(at your option) any later version. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, |
| 18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
GNU General Public License for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License |
| 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.3'); |
| 29 |
|
| 30 |
// What's our permission (capability) threshold |
| 31 |
define('MCSF_CAP_THRESHOLD', 'manage_options'); |
| 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('Sopresto_MailChimp')) { |
| 38 |
require_once(MCSF_DIR.'lib/sopresto/sopresto.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 |
* Do the following plugin setup steps here |
| 49 |
* |
| 50 |
* Internationalization |
| 51 |
* Resource (JS & CSS) enqueuing |
| 52 |
* |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
function mailchimpSF_plugin_init() { |
| 56 |
// Internationalize the plugin |
| 57 |
$textdomain = 'mailchimp_i18n'; |
| 58 |
$locale = apply_filters( 'plugin_locale', get_locale(), $textdomain); |
| 59 |
load_textdomain('mailchimp_i18n', MCSF_LANG_DIR.$textdomain.'-'.$locale.'.mo'); |
| 60 |
|
| 61 |
// Bring in our appropriate JS and CSS resources |
| 62 |
mailchimpSF_load_resources(); |
| 63 |
} |
| 64 |
add_action( 'init', 'mailchimpSF_plugin_init' ); |
| 65 |
|
| 66 |
|
| 67 |
/** |
| 68 |
* Add the settings link to the MailChimp plugin row |
| 69 |
* |
| 70 |
* @param array $links - Links for the plugin |
| 71 |
* @return array - Links |
| 72 |
*/ |
| 73 |
function mailchimpSD_plugin_action_links($links) { |
| 74 |
$settings_page = add_query_arg(array('page' => 'mailchimpSF_options'), admin_url('options-general.php')); |
| 75 |
$settings_link = '<a href="'.esc_url($settings_page).'">'.__('Settings', 'mailchimp_i18n' ).'</a>'; |
| 76 |
array_unshift($links, $settings_link); |
| 77 |
return $links; |
| 78 |
} |
| 79 |
add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'mailchimpSD_plugin_action_links', 10, 1); |
| 80 |
|
| 81 |
/** |
| 82 |
* Loads the appropriate JS and CSS resources depending on |
| 83 |
* settings and context (admin or not) |
| 84 |
* |
| 85 |
* @return void |
| 86 |
*/ |
| 87 |
function mailchimpSF_load_resources() { |
| 88 |
// JS |
| 89 |
if (get_option('mc_use_javascript') == 'on') { |
| 90 |
if (!is_admin()) { |
| 91 |
wp_enqueue_script('jquery_scrollto', MCSF_URL.'js/scrollTo.js', array('jquery'), MCSF_VER); |
| 92 |
wp_enqueue_script('mailchimpSF_main_js', MCSF_URL.'js/mailchimp.js', array('jquery', 'jquery-form'), MCSF_VER); |
| 93 |
// some javascript to get ajax version submitting to the proper location |
| 94 |
global $wp_scripts; |
| 95 |
$wp_scripts->localize('mailchimpSF_main_js', 'mailchimpSF', array( |
| 96 |
'ajax_url' => trailingslashit(home_url()), |
| 97 |
)); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
if (get_option('mc_use_datepicker') == 'on' && !is_admin()) { |
| 102 |
// Datepicker theme |
| 103 |
wp_enqueue_style('flick', MCSF_URL.'/css/flick/flick.css'); |
| 104 |
// Datepicker JS |
| 105 |
wp_enqueue_script('datepicker', MCSF_URL.'/js/datepicker.js', array('jquery','jquery-ui-core')); |
| 106 |
} |
| 107 |
|
| 108 |
wp_enqueue_style('mailchimpSF_main_css', home_url('?mcsf_action=main_css&ver='.MCSF_VER)); |
| 109 |
wp_enqueue_style('mailchimpSF_ie_css', MCSF_URL.'css/ie.css'); |
| 110 |
global $wp_styles; |
| 111 |
$wp_styles->add_data( 'mailchimpSF_ie_css', 'conditional', 'IE' ); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
/** |
| 116 |
* Loads resources for the MailChimp admin page |
| 117 |
* |
| 118 |
* @return void |
| 119 |
*/ |
| 120 |
function mc_admin_page_load_resources() { |
| 121 |
wp_enqueue_style('mailchimpSF_admin_css', MCSF_URL.'css/admin.css'); |
| 122 |
wp_enqueue_script('mailchimpSF_admin_js', MCSF_URL.'js/admin.js'); |
| 123 |
} |
| 124 |
add_action('load-settings_page_mailchimpSF_options', 'mc_admin_page_load_resources'); |
| 125 |
|
| 126 |
|
| 127 |
/** |
| 128 |
* Loads jQuery Datepicker for the date-pick class |
| 129 |
**/ |
| 130 |
function mc_datepicker_load() { |
| 131 |
?> |
| 132 |
<script type="text/javascript"> |
| 133 |
jQuery(function($) { |
| 134 |
$('.date-pick').each(function() { |
| 135 |
var format = $(this).data('format') || 'mm/dd/yyyy'; |
| 136 |
format = format.replace(/yyyy/i, 'yy'); |
| 137 |
$(this).datepicker({ |
| 138 |
autoFocusNextInput: true, |
| 139 |
constrainInput: false, |
| 140 |
changeMonth: true, |
| 141 |
changeYear: true, |
| 142 |
beforeShow: function(input, inst) { $('#ui-datepicker-div').addClass('show'); }, |
| 143 |
dateFormat: format.toLowerCase(), |
| 144 |
}); |
| 145 |
}); |
| 146 |
d = new Date(); |
| 147 |
$('.birthdate-pick').each(function() { |
| 148 |
var format = $(this).data('format') || 'mm/dd'; |
| 149 |
format = format.replace(/yyyy/i, 'yy'); |
| 150 |
$(this).datepicker({ |
| 151 |
autoFocusNextInput: true, |
| 152 |
constrainInput: false, |
| 153 |
changeMonth: true, |
| 154 |
changeYear: false, |
| 155 |
minDate: new Date(d.getFullYear(), 1-1, 1), |
| 156 |
maxDate: new Date(d.getFullYear(), 12-1, 31), |
| 157 |
beforeShow: function(input, inst) { $('#ui-datepicker-div').removeClass('show'); }, |
| 158 |
dateFormat: format.toLowerCase(), |
| 159 |
}); |
| 160 |
|
| 161 |
}); |
| 162 |
|
| 163 |
}); |
| 164 |
</script> |
| 165 |
<?php |
| 166 |
} |
| 167 |
if (get_option('mc_use_datepicker') == 'on' && !is_admin()) { |
| 168 |
add_action('wp_head', 'mc_datepicker_load'); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Handles requests that as light-weight a load as possible. |
| 173 |
* typically, JS or CSS |
| 174 |
**/ |
| 175 |
function mailchimpSF_early_request_handler() { |
| 176 |
if (isset($_GET['mcsf_action'])) { |
| 177 |
switch ($_GET['mcsf_action']) { |
| 178 |
case 'main_css': |
| 179 |
header("Content-type: text/css"); |
| 180 |
mailchimpSF_main_css(); |
| 181 |
exit; |
| 182 |
case 'authorize': |
| 183 |
mailchimpSF_authorize(); |
| 184 |
break; |
| 185 |
case 'authorized': |
| 186 |
mailchimpSF_authorized(); |
| 187 |
break; |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
add_action('init', 'mailchimpSF_early_request_handler', 0); |
| 192 |
|
| 193 |
/** |
| 194 |
* Outputs the front-end CSS. This checks several options, so it |
| 195 |
* was best to put it in a Request-handled script, as opposed to |
| 196 |
* a static file. |
| 197 |
*/ |
| 198 |
function mailchimpSF_main_css() { |
| 199 |
?> |
| 200 |
.mc_error_msg { |
| 201 |
color: red; |
| 202 |
margin-bottom: 1.0em; |
| 203 |
} |
| 204 |
.mc_success_msg { |
| 205 |
color: green; |
| 206 |
margin-bottom: 1.0em; |
| 207 |
} |
| 208 |
.mc_merge_var{ |
| 209 |
padding:0; |
| 210 |
margin:0; |
| 211 |
} |
| 212 |
<?php |
| 213 |
// If we're utilizing custom styles |
| 214 |
if (get_option('mc_custom_style')=='on'){ |
| 215 |
?> |
| 216 |
#mc_signup_form { |
| 217 |
padding:5px; |
| 218 |
border-width: <?php echo get_option('mc_form_border_width'); ?>px; |
| 219 |
border-style: <?php echo (get_option('mc_form_border_width')==0) ? 'none' : 'solid'; ?>; |
| 220 |
border-color: #<?php echo get_option('mc_form_border_color'); ?>; |
| 221 |
color: #<?php echo get_option('mc_form_text_color'); ?>; |
| 222 |
background-color: #<?php echo get_option('mc_form_background'); ?>; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
.mc_custom_border_hdr { |
| 227 |
border-width: <?php echo get_option('mc_header_border_width'); ?>px; |
| 228 |
border-style: <?php echo (get_option('mc_header_border_width')==0) ? 'none' : 'solid'; ?>; |
| 229 |
border-color: #<?php echo get_option('mc_header_border_color'); ?>; |
| 230 |
color: #<?php echo get_option('mc_header_text_color'); ?>; |
| 231 |
background-color: #<?php echo get_option('mc_header_background'); ?>; |
| 232 |
<!-- font-size: 1.2em;--> |
| 233 |
padding:5px 10px; |
| 234 |
width: 100%; |
| 235 |
} |
| 236 |
<?php |
| 237 |
} |
| 238 |
?> |
| 239 |
#mc_signup_container {} |
| 240 |
#mc_signup_form {} |
| 241 |
#mc_signup_form .mc_var_label {} |
| 242 |
#mc_signup_form .mc_input {} |
| 243 |
#mc-indicates-required { |
| 244 |
width:100%; |
| 245 |
} |
| 246 |
#mc_display_rewards {} |
| 247 |
.mc_interests_header { |
| 248 |
font-weight:bold; |
| 249 |
} |
| 250 |
div.mc_interest{ |
| 251 |
width:100%; |
| 252 |
} |
| 253 |
#mc_signup_form input.mc_interest {} |
| 254 |
#mc_signup_form select {} |
| 255 |
#mc_signup_form label.mc_interest_label { |
| 256 |
display:inline; |
| 257 |
} |
| 258 |
.mc_signup_submit { |
| 259 |
text-align:center; |
| 260 |
} |
| 261 |
ul.mc_list { |
| 262 |
list-style-type: none; |
| 263 |
} |
| 264 |
ul.mc_list li { |
| 265 |
font-size: 12px; |
| 266 |
} |
| 267 |
.ui-datepicker-year { |
| 268 |
display: none; |
| 269 |
} |
| 270 |
#ui-datepicker-div.show .ui-datepicker-year { |
| 271 |
display: inline; |
| 272 |
padding-left: 3px |
| 273 |
} |
| 274 |
<?php |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
/** |
| 279 |
* Add our settings page to the admin menu |
| 280 |
* |
| 281 |
* @return void |
| 282 |
*/ |
| 283 |
function mailchimpSF_add_pages(){ |
| 284 |
// Add settings page for users who can edit plugins |
| 285 |
add_options_page( __( 'MailChimp Setup', 'mailchimp_i18n' ), __( 'MailChimp Setup', 'mailchimp_i18n' ), MCSF_CAP_THRESHOLD, 'mailchimpSF_options', 'mailchimpSF_setup_page'); |
| 286 |
} |
| 287 |
add_action('admin_menu', 'mailchimpSF_add_pages'); |
| 288 |
|
| 289 |
function mailchimpSF_request_handler() { |
| 290 |
if (isset($_POST['mcsf_action'])) { |
| 291 |
switch ($_POST['mcsf_action']) { |
| 292 |
case 'logout': |
| 293 |
// Check capability & Verify nonce |
| 294 |
if (!current_user_can(MCSF_CAP_THRESHOLD) || !wp_verify_nonce($_POST['_mcsf_nonce_action'], 'mc_logout')) { |
| 295 |
wp_die('Cheatin’ huh?'); |
| 296 |
} |
| 297 |
|
| 298 |
// erase auth information |
| 299 |
delete_option('mc_sopresto_user'); |
| 300 |
delete_option('mc_sopresto_public_key'); |
| 301 |
delete_option('mc_sopresto_secret_key'); |
| 302 |
break; |
| 303 |
case 'reset_list': |
| 304 |
// Check capability & Verify nonce |
| 305 |
if (!current_user_can(MCSF_CAP_THRESHOLD) || !wp_verify_nonce($_POST['_mcsf_nonce_action'], 'reset_mailchimp_list')) { |
| 306 |
wp_die('Cheatin’ huh?'); |
| 307 |
} |
| 308 |
|
| 309 |
mailchimpSF_reset_list_settings(); |
| 310 |
break; |
| 311 |
case 'change_form_settings': |
| 312 |
if (!current_user_can(MCSF_CAP_THRESHOLD) || !wp_verify_nonce($_POST['_mcsf_nonce_action'], 'update_general_form_settings')) { |
| 313 |
wp_die('Cheatin’ huh?'); |
| 314 |
} |
| 315 |
|
| 316 |
// Update the form settings |
| 317 |
mailchimpSF_save_general_form_settings(); |
| 318 |
break; |
| 319 |
case 'mc_submit_signup_form': |
| 320 |
// Validate nonce |
| 321 |
if (!wp_verify_nonce($_POST['_mc_submit_signup_form_nonce'], 'mc_submit_signup_form')) { |
| 322 |
wp_die('Cheatin’ huh?'); |
| 323 |
} |
| 324 |
|
| 325 |
// Attempt the signup |
| 326 |
mailchimpSF_signup_submit(); |
| 327 |
|
| 328 |
// Do a different action for html vs. js |
| 329 |
switch ($_POST['mc_submit_type']) { |
| 330 |
case 'html': |
| 331 |
/* Allow to fall through. The widget will pick up the |
| 332 |
* global message left over from the signup_submit function */ |
| 333 |
break; |
| 334 |
case 'js': |
| 335 |
if (!headers_sent()){ //just in case... |
| 336 |
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT', true, 200); |
| 337 |
} |
| 338 |
echo mailchimpSF_global_msg(); // Don't esc_html this, b/c we've already escaped it |
| 339 |
exit; |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
add_action('init', 'mailchimpSF_request_handler'); |
| 345 |
|
| 346 |
function mailchimpSF_auth_nonce_key($salt = null) { |
| 347 |
if (is_null($salt)) { |
| 348 |
$salt = mailchimpSF_auth_nonce_salt(); |
| 349 |
} |
| 350 |
return md5('social_authentication'.AUTH_KEY.$salt); |
| 351 |
} |
| 352 |
|
| 353 |
function mailchimpSF_auth_nonce_salt() { |
| 354 |
return md5(microtime().$_SERVER['SERVER_ADDR']); |
| 355 |
} |
| 356 |
|
| 357 |
function mailchimpSF_authorize() { |
| 358 |
$api = mailchimpSF_get_api(true); |
| 359 |
$proxy = apply_filters('mailchimp_authorize_url', $api->getApiUrl('authorize')); |
| 360 |
if (strpos($proxy, 'socialize-this') !== false) { |
| 361 |
$salt = mailchimpSF_auth_nonce_salt(); |
| 362 |
$id = wp_create_nonce(mailchimpSF_auth_nonce_key($salt)); |
| 363 |
$url = home_url('index.php'); |
| 364 |
$args = array( |
| 365 |
'mcsf_action' => 'authorized', |
| 366 |
'salt' => $salt, |
| 367 |
'user_id' => get_current_user_id(), |
| 368 |
); |
| 369 |
|
| 370 |
$proxy = add_query_arg(array( |
| 371 |
'id' => $id, |
| 372 |
'response_url' => urlencode(add_query_arg($args, $url)) |
| 373 |
), $proxy); |
| 374 |
|
| 375 |
$proxy = apply_filters('mailchimp_proxy_url', $proxy); |
| 376 |
} |
| 377 |
|
| 378 |
wp_redirect($proxy); |
| 379 |
exit; |
| 380 |
} |
| 381 |
|
| 382 |
function mailchimpSF_authorized() { |
| 383 |
// User ID on the request? Must be set before nonce comparison |
| 384 |
$user_id = stripslashes($_GET['user_id']); |
| 385 |
if ($user_id !== null) { |
| 386 |
wp_set_current_user($user_id); |
| 387 |
} |
| 388 |
|
| 389 |
$nonce = stripslashes($_POST['id']); |
| 390 |
$salt = stripslashes($_GET['salt']); |
| 391 |
if (wp_verify_nonce($nonce, mailchimpSF_auth_nonce_key($salt)) === false) { |
| 392 |
wp_die('Cheatin’ huh?'); |
| 393 |
} |
| 394 |
|
| 395 |
$response = stripslashes_deep($_POST['response']); |
| 396 |
|
| 397 |
if (!isset($response['keys']) || !isset($response['user'])) { |
| 398 |
wp_die('Something went wrong, please try again'); |
| 399 |
} |
| 400 |
|
| 401 |
update_option('mc_sopresto_user', $response['user']); |
| 402 |
update_option('mc_sopresto_dc', $response['dc']); |
| 403 |
update_option('mc_sopresto_public_key', $response['keys']['public']); |
| 404 |
update_option('mc_sopresto_secret_key', $response['keys']['secret']); |
| 405 |
exit; |
| 406 |
} |
| 407 |
|
| 408 |
/** |
| 409 |
* Upgrades data if it needs to. Checks on admin_init |
| 410 |
* |
| 411 |
* @return void |
| 412 |
*/ |
| 413 |
function mailchimpSF_upgrade() { |
| 414 |
// See if we need an upgrade |
| 415 |
if (mailchimpSF_needs_upgrade()) { |
| 416 |
// remove password option if it's set (0.5) |
| 417 |
// Update interest group data |
| 418 |
mailchimpSF_do_upgrade(); |
| 419 |
} |
| 420 |
} |
| 421 |
add_action('admin_init', 'mailchimpSF_upgrade'); |
| 422 |
|
| 423 |
/** |
| 424 |
* Creates new Sopresto API object |
| 425 |
* |
| 426 |
* @return Sopresto_MailChimp|false |
| 427 |
*/ |
| 428 |
function mailchimpSF_get_api($force = false) { |
| 429 |
$public_key = get_option('mc_sopresto_public_key'); |
| 430 |
$secret_key = get_option('mc_sopresto_secret_key'); |
| 431 |
|
| 432 |
if ($public_key && $secret_key || $force) { |
| 433 |
return new Sopresto_MailChimp($public_key, $secret_key, '1.3'); |
| 434 |
} |
| 435 |
|
| 436 |
return false; |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Checks to see if we're storing a password, if so, we need |
| 441 |
* to upgrade to the API key |
| 442 |
* |
| 443 |
* @return bool |
| 444 |
**/ |
| 445 |
function mailchimpSF_needs_upgrade() { |
| 446 |
$igs = get_option('mc_interest_groups'); |
| 447 |
|
| 448 |
if ($igs !== false // we have an option |
| 449 |
&& ( |
| 450 |
empty($igs) || // it can be an empty array (no interest groups) |
| 451 |
(is_array($igs) && isset($igs[0]['id'])) // OR it should be a populated array that's well-formed |
| 452 |
)) { |
| 453 |
return false; // no need to upgrade |
| 454 |
} |
| 455 |
else { |
| 456 |
return true; // yeah, let's do it |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
/** |
| 461 |
* 1.2.4 -> 1.2.5 - Update to support multiple interest groups |
| 462 |
* MCAPIv1.2 -> MCAPIv1.3 - update interest groups |
| 463 |
* 2011-02-09 - old password upgrade code deleted as 0.5 is way old |
| 464 |
*/ |
| 465 |
function mailchimpSF_do_upgrade() { |
| 466 |
# TODO: reload this |
| 467 |
} |
| 468 |
|
| 469 |
/** |
| 470 |
* Deletes all mailchimp options |
| 471 |
**/ |
| 472 |
function mailchimpSF_delete_setup() { |
| 473 |
delete_option('mc_user_id'); |
| 474 |
delete_option('mc_sopresto_user'); |
| 475 |
delete_option('mc_sopresto_public_key'); |
| 476 |
delete_option('mc_sopresto_secret_key'); |
| 477 |
delete_option('mc_rewards'); |
| 478 |
delete_option('mc_use_javascript'); |
| 479 |
delete_option('mc_use_datepicker'); |
| 480 |
delete_option('mc_use_unsub_link'); |
| 481 |
delete_option('mc_list_id'); |
| 482 |
delete_option('mc_list_name'); |
| 483 |
$igs = get_option('mc_interest_groups'); |
| 484 |
if (is_array($igs)) { |
| 485 |
foreach ($igs as $ig) { |
| 486 |
$opt = 'mc_show_interest_groups_'.$ig['id']; |
| 487 |
delete_option($opt); |
| 488 |
} |
| 489 |
} |
| 490 |
delete_option('mc_interest_groups'); |
| 491 |
$mv = get_option('mc_merge_vars'); |
| 492 |
if (is_array($mv)){ |
| 493 |
foreach($mv as $var){ |
| 494 |
$opt = 'mc_mv_'.$var['tag']; |
| 495 |
delete_option($opt); |
| 496 |
} |
| 497 |
} |
| 498 |
delete_option('mc_merge_vars'); |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
* Resets the list settings, there's only one list |
| 503 |
* that can have settings at a time, so no list_id |
| 504 |
* parameter is necessary. |
| 505 |
**/ |
| 506 |
function mailchimpSF_reset_list_settings() { |
| 507 |
|
| 508 |
delete_option('mc_list_id'); |
| 509 |
delete_option('mc_list_name'); |
| 510 |
delete_option('mc_merge_vars'); |
| 511 |
delete_option('mc_interest_groups'); |
| 512 |
|
| 513 |
delete_option('mc_use_javascript'); |
| 514 |
delete_option('mc_use_unsub_link'); |
| 515 |
delete_option('mc_use_datepicker'); |
| 516 |
|
| 517 |
delete_option('mc_header_content'); |
| 518 |
delete_option('mc_subheader_content'); |
| 519 |
delete_option('mc_submit_text'); |
| 520 |
|
| 521 |
delete_option('mc_custom_style'); |
| 522 |
|
| 523 |
delete_option('mc_header_border_width'); |
| 524 |
delete_option('mc_header_border_color'); |
| 525 |
delete_option('mc_header_background'); |
| 526 |
delete_option('mc_header_text_color'); |
| 527 |
|
| 528 |
delete_option('mc_form_border_width'); |
| 529 |
delete_option('mc_form_border_color'); |
| 530 |
delete_option('mc_form_background'); |
| 531 |
delete_option('mc_form_text_color'); |
| 532 |
|
| 533 |
$msg = '<p class="success_msg">'.esc_html(__('Successfully Reset your List selection... Now you get to pick again!', 'mailchimp_i18n')).'</p>'; |
| 534 |
mailchimpSF_global_msg($msg); |
| 535 |
} |
| 536 |
|
| 537 |
/** |
| 538 |
* Gets or sets a global message based on parameter passed to it |
| 539 |
* |
| 540 |
* @return string/bool depending on get/set |
| 541 |
**/ |
| 542 |
function mailchimpSF_global_msg($msg = null) { |
| 543 |
global $mcsf_msgs; |
| 544 |
|
| 545 |
// Make sure we're formed properly |
| 546 |
if (!is_array($mcsf_msgs)) { |
| 547 |
$mcsf_msgs = array(); |
| 548 |
} |
| 549 |
|
| 550 |
// See if we're getting |
| 551 |
if (is_null($msg)) { |
| 552 |
return implode('', $mcsf_msgs); |
| 553 |
} |
| 554 |
|
| 555 |
// Must be setting |
| 556 |
$mcsf_msgs[] = $msg; |
| 557 |
return true; |
| 558 |
} |
| 559 |
|
| 560 |
/** |
| 561 |
* Sets the default options for the option form |
| 562 |
**/ |
| 563 |
function mailchimpSF_set_form_defaults($list_name = '') { |
| 564 |
update_option('mc_header_content',__( 'Sign up for', 'mailchimp_i18n' ).' '.$list_name); |
| 565 |
update_option('mc_submit_text',__( 'Subscribe', 'mailchimp_i18n' )); |
| 566 |
|
| 567 |
update_option('mc_use_datepicker', 'on'); |
| 568 |
update_option('mc_custom_style','off'); |
| 569 |
update_option('mc_use_javascript','on'); |
| 570 |
update_option('mc_use_unsub_link','off'); |
| 571 |
update_option('mc_header_border_width','1'); |
| 572 |
update_option('mc_header_border_color','E3E3E3'); |
| 573 |
update_option('mc_header_background','FFFFFF'); |
| 574 |
update_option('mc_header_text_color','CC6600'); |
| 575 |
|
| 576 |
update_option('mc_form_border_width','1'); |
| 577 |
update_option('mc_form_border_color','E0E0E0'); |
| 578 |
update_option('mc_form_background','FFFFFF'); |
| 579 |
update_option('mc_form_text_color','3F3F3f'); |
| 580 |
} |
| 581 |
|
| 582 |
/** |
| 583 |
* Saves the General Form settings on the options page |
| 584 |
* |
| 585 |
* @return void |
| 586 |
**/ |
| 587 |
function mailchimpSF_save_general_form_settings() { |
| 588 |
if (isset($_POST['mc_rewards'])){ |
| 589 |
update_option('mc_rewards', 'on'); |
| 590 |
$msg = '<p class="success_msg">'.__('Monkey Rewards turned On!', 'mailchimp_i18n').'</p>'; |
| 591 |
mailchimpSF_global_msg($msg); |
| 592 |
} else if (get_option('mc_rewards')!='off') { |
| 593 |
update_option('mc_rewards', 'off'); |
| 594 |
$msg = '<p class="success_msg">'.__('Monkey Rewards turned Off!', 'mailchimp_i18n').'</p>'; |
| 595 |
mailchimpSF_global_msg($msg); |
| 596 |
} |
| 597 |
if (isset($_POST['mc_use_javascript'])){ |
| 598 |
update_option('mc_use_javascript', 'on'); |
| 599 |
$msg = '<p class="success_msg">'.__('Fancy Javascript submission turned On!', 'mailchimp_i18n').'</p>'; |
| 600 |
mailchimpSF_global_msg($msg); |
| 601 |
} else if (get_option('mc_use_javascript')!='off') { |
| 602 |
update_option('mc_use_javascript', 'off'); |
| 603 |
$msg = '<p class="success_msg">'.__('Fancy Javascript submission turned Off!', 'mailchimp_i18n').'</p>'; |
| 604 |
mailchimpSF_global_msg($msg); |
| 605 |
} |
| 606 |
|
| 607 |
if (isset($_POST['mc_use_datepicker'])){ |
| 608 |
update_option('mc_use_datepicker', 'on'); |
| 609 |
$msg = '<p class="success_msg">'.__('Datepicker turned On!', 'mailchimp_i18n').'</p>'; |
| 610 |
mailchimpSF_global_msg($msg); |
| 611 |
} else if (get_option('mc_use_datepicker')!='off') { |
| 612 |
update_option('mc_use_datepicker', 'off'); |
| 613 |
$msg = '<p class="success_msg">'.__('Datepicker turned Off!', 'mailchimp_i18n').'</p>'; |
| 614 |
mailchimpSF_global_msg($msg); |
| 615 |
} |
| 616 |
|
| 617 |
if (isset($_POST['mc_use_unsub_link'])){ |
| 618 |
update_option('mc_use_unsub_link', 'on'); |
| 619 |
$msg = '<p class="success_msg">'.__('Unsubscribe link turned On!', 'mailchimp_i18n').'</p>'; |
| 620 |
mailchimpSF_global_msg($msg); |
| 621 |
} else if (get_option('mc_use_unsub_link')!='off') { |
| 622 |
update_option('mc_use_unsub_link', 'off'); |
| 623 |
$msg = '<p class="success_msg">'.__('Unsubscribe link turned Off!', 'mailchimp_i18n').'</p>'; |
| 624 |
mailchimpSF_global_msg($msg); |
| 625 |
} |
| 626 |
|
| 627 |
$content = stripslashes($_POST['mc_header_content']); |
| 628 |
$content = str_replace("\r\n","<br/>", $content); |
| 629 |
update_option('mc_header_content', $content ); |
| 630 |
|
| 631 |
$content = stripslashes($_POST['mc_subheader_content']); |
| 632 |
$content = str_replace("\r\n","<br/>", $content); |
| 633 |
update_option('mc_subheader_content', $content ); |
| 634 |
|
| 635 |
|
| 636 |
$submit_text = stripslashes($_POST['mc_submit_text']); |
| 637 |
$submit_text = str_replace("\r\n","", $submit_text); |
| 638 |
update_option('mc_submit_text', $submit_text); |
| 639 |
|
| 640 |
// Set Custom Style option |
| 641 |
update_option('mc_custom_style', isset($_POST['mc_custom_style']) ? 'on' : 'off'); |
| 642 |
|
| 643 |
//we told them not to put these things we are replacing in, but let's just make sure they are listening... |
| 644 |
update_option('mc_header_border_width',str_replace('px','',$_POST['mc_header_border_width']) ); |
| 645 |
update_option('mc_header_border_color', str_replace('#','',$_POST['mc_header_border_color'])); |
| 646 |
update_option('mc_header_background',str_replace('#','',$_POST['mc_header_background'])); |
| 647 |
update_option('mc_header_text_color', str_replace('#','',$_POST['mc_header_text_color'])); |
| 648 |
|
| 649 |
update_option('mc_form_border_width',str_replace('px','',$_POST['mc_form_border_width']) ); |
| 650 |
update_option('mc_form_border_color', str_replace('#','',$_POST['mc_form_border_color'])); |
| 651 |
update_option('mc_form_background',str_replace('#','',$_POST['mc_form_background'])); |
| 652 |
update_option('mc_form_text_color', str_replace('#','',$_POST['mc_form_text_color'])); |
| 653 |
|
| 654 |
$igs = get_option('mc_interest_groups'); |
| 655 |
if (is_array($igs)) { |
| 656 |
foreach($igs as $var){ |
| 657 |
$opt = 'mc_show_interest_groups_'.$var['id']; |
| 658 |
if (isset($_POST[$opt])){ |
| 659 |
update_option($opt,'on'); |
| 660 |
} else { |
| 661 |
update_option($opt,'off'); |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
$mv = get_option('mc_merge_vars'); |
| 667 |
if (is_array($mv)) { |
| 668 |
foreach($mv as $var){ |
| 669 |
$opt = 'mc_mv_'.$var['tag']; |
| 670 |
if (isset($_POST[$opt]) || $var['req']=='Y'){ |
| 671 |
update_option($opt,'on'); |
| 672 |
} else { |
| 673 |
update_option($opt,'off'); |
| 674 |
} |
| 675 |
} |
| 676 |
} |
| 677 |
$msg = '<p class="success_msg">'.esc_html(__('Successfully Updated your List Subscribe Form Settings!', 'mailchimp_i18n')).'</p>'; |
| 678 |
mailchimpSF_global_msg($msg); |
| 679 |
} |
| 680 |
|
| 681 |
/** |
| 682 |
* Sees if the user changed the list, and updates options accordingly |
| 683 |
**/ |
| 684 |
function mailchimpSF_change_list_if_necessary() { |
| 685 |
// Simple permission check before going through all this |
| 686 |
if (!current_user_can(MCSF_CAP_THRESHOLD)) { return; } |
| 687 |
|
| 688 |
$api = mailchimpSF_get_api(); |
| 689 |
if (!$api) { return; } |
| 690 |
|
| 691 |
//we *could* support paging, but few users have that many lists (and shouldn't) |
| 692 |
$lists = $api->lists(array(),0,100); |
| 693 |
$lists = $lists['data']; |
| 694 |
|
| 695 |
if (is_array($lists) && !empty($lists) && isset($_POST['mc_list_id'])) { |
| 696 |
|
| 697 |
/* If our incoming list ID (the one chosen in the select dropdown) |
| 698 |
is in our array of lists, the set it to be the active list */ |
| 699 |
foreach($lists as $key => $list) { |
| 700 |
if ($list['id'] == $_POST['mc_list_id']) { |
| 701 |
$list_id = $_POST['mc_list_id']; |
| 702 |
$list_name = $list['name']; |
| 703 |
$list_key = $key; |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
$orig_list = get_option('mc_list_id'); |
| 708 |
if ($list_id != '') { |
| 709 |
update_option('mc_list_id', $list_id); |
| 710 |
update_option('mc_list_name', $list_name); |
| 711 |
update_option('mc_email_type_option', $lists[$list_key]['email_type_option']); |
| 712 |
|
| 713 |
|
| 714 |
// See if the user changed the list |
| 715 |
if ($orig_list != $list_id){ |
| 716 |
// The user changed the list, Reset the Form Defaults |
| 717 |
mailchimpSF_set_form_defaults($list_name); |
| 718 |
} |
| 719 |
// email_type_option |
| 720 |
|
| 721 |
// Grab the merge vars and interest groups |
| 722 |
$mv = $api->listMergeVars($list_id); |
| 723 |
$igs = $api->listInterestGroupings($list_id); |
| 724 |
|
| 725 |
update_option('mc_merge_vars', $mv); |
| 726 |
foreach($mv as $var){ |
| 727 |
$opt = 'mc_mv_'.$var['tag']; |
| 728 |
//turn them all on by default |
| 729 |
if ($orig_list != $list_id) { |
| 730 |
update_option($opt, 'on' ); |
| 731 |
} |
| 732 |
} |
| 733 |
update_option('mc_interest_groups', $igs); |
| 734 |
if (is_array($igs)) { |
| 735 |
foreach ($igs as $var){ |
| 736 |
$opt = 'mc_show_interest_groups_'.$var['id']; |
| 737 |
//turn them all on by default |
| 738 |
if ($orig_list != $list_id) { |
| 739 |
update_option($opt, 'on' ); |
| 740 |
} |
| 741 |
} |
| 742 |
} |
| 743 |
$igs_text = ' '; |
| 744 |
if (is_array($igs)) { |
| 745 |
$igs_text .= sprintf(__('and %s Sets of Interest Groups', 'mailchimp_i18n'), count($igs)); |
| 746 |
} |
| 747 |
|
| 748 |
$msg = '<p class="success_msg">'. |
| 749 |
sprintf( |
| 750 |
__('<b>Success!</b> Loaded and saved the info for %d Merge Variables', 'mailchimp_i18n').$igs_text, |
| 751 |
count($mv) |
| 752 |
).' '. |
| 753 |
__('from your list').' "'.$list_name.'"<br/><br/>'. |
| 754 |
__('Now you should either Turn On the MailChimp Widget or change your options below, then turn it on.', 'mailchimp_i18n').'</p>'; |
| 755 |
mailchimpSF_global_msg($msg); |
| 756 |
} |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
/** |
| 762 |
* Outputs the Settings/Options page |
| 763 |
*/ |
| 764 |
function mailchimpSF_setup_page() { |
| 765 |
?> |
| 766 |
<div class="wrap"> |
| 767 |
|
| 768 |
<div class="mailchimp-header"> |
| 769 |
<h2><?php esc_html_e('MailChimp List Setup', 'mailchimp_i18n');?> </h2> |
| 770 |
</div> |
| 771 |
<?php |
| 772 |
$user = get_option('mc_sopresto_user'); |
| 773 |
|
| 774 |
// If we have an API Key, see if we need to change the lists and its options |
| 775 |
mailchimpSF_change_list_if_necessary(); |
| 776 |
|
| 777 |
// Display our success/error message(s) if have them |
| 778 |
if (mailchimpSF_global_msg() != ''){ |
| 779 |
// Message has already been html escaped, so we don't want to 2x escape it here |
| 780 |
?> |
| 781 |
<div id="mc_message" class=""><?php echo mailchimpSF_global_msg(); ?></div> |
| 782 |
<?php |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
// If we don't have an API Key, do a login form |
| 787 |
if (!$user) { |
| 788 |
?> |
| 789 |
<div> |
| 790 |
</div> |
| 791 |
<div> |
| 792 |
<h3 class="mc-h2"><?php esc_html_e('Log In', 'mailchimp_i18n');?></h3> |
| 793 |
<p class="mc-p" style="width: 40%;line-height: 21px;"><?php esc_html_e('To start using the MailChimp plugin, we first need to connect your MailChimp account. Click login below to connect.', 'mailchimp_i18n'); ?></p> |
| 794 |
<p class="mc-a"> |
| 795 |
<?php |
| 796 |
echo sprintf( |
| 797 |
'%1$s <a href="http://www.mailchimp.com/signup/" target="_blank">%2$s</a>', |
| 798 |
esc_html(__("Don't have a MailChimp account?", 'mailchimp_i18n')), |
| 799 |
esc_html(__('Try one for Free!', 'mailchimp_i18n')) |
| 800 |
); |
| 801 |
?> |
| 802 |
</p> |
| 803 |
|
| 804 |
<div style="width: 900px;"> |
| 805 |
<table class="widefat mc-widefat mc-api"> |
| 806 |
<tr valign="top"> |
| 807 |
<th scope="row" class="mailchimp-connect"><?php esc_html_e('Connect to MailChimp', 'mailchimp_i18n'); ?></th> |
| 808 |
<td> |
| 809 |
<a href="<?php echo add_query_arg(array("mcsf_action" => "authorize"), home_url('index.php')) ?>" class="mailchimp-login">Connect</a> |
| 810 |
</td> |
| 811 |
</tr> |
| 812 |
</table> |
| 813 |
</div> |
| 814 |
</div> |
| 815 |
<br/> |
| 816 |
<!--<div class="notes_msg"> |
| 817 |
<?php |
| 818 |
if ($user && $user['username'] != ''){ |
| 819 |
?> |
| 820 |
<strong><?php esc_html_e('Notes', 'mailchimp_i18n'); ?>:</strong> |
| 821 |
<ul> |
| 822 |
<li><?php esc_html_e('Changing your settings at MailChimp.com may cause this to stop working.', 'mailchimp_i18n'); ?></li> |
| 823 |
<li><?php esc_html_e('If you change your login to a different account, the info you have setup below will be erased.', 'mailchimp_i18n'); ?></li> |
| 824 |
<li><?php esc_html_e('If any of that happens, no biggie - just reconfigure your login and the items below...', 'mailchimp_i18n'); ?></li> |
| 825 |
</ul> |
| 826 |
</div>--> |
| 827 |
<?php |
| 828 |
} |
| 829 |
} // End of login form |
| 830 |
|
| 831 |
// Start logout form |
| 832 |
else { |
| 833 |
?> |
| 834 |
<table style="min-width:400px;" class="mc-user" cellspacing="0"> |
| 835 |
<tr> |
| 836 |
<td><h3><?php esc_html_e('Logged in as', 'mailchimp_i18n');?>: <?php echo esc_html($user['username']); ?></h3> |
| 837 |
</td> |
| 838 |
<td> |
| 839 |
<form method="post" action="options-general.php?page=mailchimpSF_options"> |
| 840 |
<input type="hidden" name="mcsf_action" value="logout"/> |
| 841 |
<input type="submit" name="Submit" value="<?php esc_attr_e('Logout', 'mailchimp_i18n');?>" class="button" /> |
| 842 |
<?php wp_nonce_field('mc_logout', '_mcsf_nonce_action'); ?> |
| 843 |
</form> |
| 844 |
</td> |
| 845 |
</tr> |
| 846 |
</table> |
| 847 |
<?php |
| 848 |
} // End Logout form |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
//Just get out if nothing else matters... |
| 853 |
$api = mailchimpSF_get_api(); |
| 854 |
if (!$api) { return; } |
| 855 |
|
| 856 |
if ($api){ |
| 857 |
?> |
| 858 |
<h3 class="mc-h2"><?php esc_html_e('Your Lists', 'mailchimp_i18n'); ?></h3> |
| 859 |
|
| 860 |
<div> |
| 861 |
|
| 862 |
<p class="mc-p"><?php esc_html_e('Please select the List you wish to create a Signup Form for.', 'mailchimp_i18n'); ?></p> |
| 863 |
<p class="mc-list-note"><strong><?php esc_html_e('Note:', 'mailchimp_i18n'); ?></strong> <?php esc_html_e('Updating your list will not cause settings below to be lost. Changing to a new list will.', 'mailchimp_i18n'); ?></p> |
| 864 |
|
| 865 |
<form method="post" action="options-general.php?page=mailchimpSF_options"> |
| 866 |
<?php |
| 867 |
//we *could* support paging, but few users have that many lists (and shouldn't) |
| 868 |
$lists = $api->lists(array(),0,100); |
| 869 |
$lists = $lists['data']; |
| 870 |
|
| 871 |
if (count($lists) == 0) { |
| 872 |
?> |
| 873 |
<span class='error_msg'> |
| 874 |
<?php |
| 875 |
echo sprintf( |
| 876 |
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')), |
| 877 |
"<a href='http://www.mailchimp.com/'>MailChimp</a>" |
| 878 |
); |
| 879 |
?> |
| 880 |
</span> |
| 881 |
<?php |
| 882 |
} |
| 883 |
else { |
| 884 |
?> |
| 885 |
<table style="min-width:400px" class="mc-list-select" cellspacing="0"> |
| 886 |
<tr class="mc-list-row"> |
| 887 |
<td> |
| 888 |
<select name="mc_list_id" style="min-width:200px;"> |
| 889 |
<option value=""> — <?php esc_html_e('Select A List','mailchimp_i18n'); ?> — </option> |
| 890 |
<?php |
| 891 |
foreach ($lists as $list) { |
| 892 |
$option = get_option('mc_list_id'); |
| 893 |
?> |
| 894 |
<option value="<?php echo esc_attr($list['id']); ?>"<?php selected($list['id'], $option); ?>><?php echo esc_html($list['name']); ?></option> |
| 895 |
<?php |
| 896 |
} |
| 897 |
?> |
| 898 |
</select> |
| 899 |
</td> |
| 900 |
<td> |
| 901 |
<input type="hidden" name="mcsf_action" value="update_mc_list_id" /> |
| 902 |
<input type="submit" name="Submit" value="<?php esc_attr_e('Update List', 'mailchimp_i18n'); ?>" class="button" /> |
| 903 |
</td> |
| 904 |
</tr> |
| 905 |
</table> |
| 906 |
<?php |
| 907 |
} //end select list |
| 908 |
?> |
| 909 |
</form> |
| 910 |
</div> |
| 911 |
|
| 912 |
<br/> |
| 913 |
|
| 914 |
<?php |
| 915 |
} |
| 916 |
else { |
| 917 |
//display the selected list... |
| 918 |
?> |
| 919 |
|
| 920 |
<p class="submit"> |
| 921 |
<form method="post" action="options-general.php?page=mailchimpSF_options"> |
| 922 |
<input type="hidden" name="mcsf_action" value="reset_list" /> |
| 923 |
<input type="submit" name="reset_list" value="<?php esc_attr_e('Reset List Options and Select again', 'mailchimp_i18n'); ?>" class="button" /> |
| 924 |
<?php wp_nonce_field('reset_mailchimp_list', '_mcsf_nonce_action'); ?> |
| 925 |
</form> |
| 926 |
</p> |
| 927 |
<h3><?php esc_html_e('Subscribe Form Widget Settings for this List', 'mailchimp_i18n'); ?>:</h3> |
| 928 |
<h4><?php esc_html_e('Selected MailChimp List', 'mailchimp_i18n'); ?>: <?php echo esc_html(get_option('mc_list_name')); ?></h4> |
| 929 |
<?php |
| 930 |
} |
| 931 |
|
| 932 |
//Just get out if nothing else matters... |
| 933 |
if (get_option('mc_list_id') == '') return; |
| 934 |
|
| 935 |
|
| 936 |
// The main Settings form |
| 937 |
?> |
| 938 |
|
| 939 |
<div> |
| 940 |
<form method="post" action="options-general.php?page=mailchimpSF_options"> |
| 941 |
<div style="width:900px;"> |
| 942 |
<input type="hidden" name="mcsf_action" value="change_form_settings"> |
| 943 |
<?php wp_nonce_field('update_general_form_settings', '_mcsf_nonce_action'); ?> |
| 944 |
<!--<input type="submit" value="<?php esc_attr_e('Update Subscribe Form Settings', 'mailchimp_i18n'); ?>" class="button" />--> |
| 945 |
<table class="widefat mc-widefat mc-label-options"> |
| 946 |
<tr><th colspan="2">Content Options</th></tr> |
| 947 |
<tr valign="top"> |
| 948 |
<th scope="row"><?php esc_html_e('Header', 'mailchimp_i18n'); ?></th> |
| 949 |
<td> |
| 950 |
<textarea name="mc_header_content" rows="2" cols="70"><?php echo esc_html(get_option('mc_header_content')); ?></textarea><br/> |
| 951 |
<?php esc_html_e('You can fill this with your own Text, HTML markup (including image links), or Nothing!', 'mailchimp_i18n'); ?> |
| 952 |
</td> |
| 953 |
</tr> |
| 954 |
|
| 955 |
<tr valign="top"> |
| 956 |
<th scope="row"><?php esc_html_e('Sub-header', 'mailchimp_i18n'); ?></th> |
| 957 |
<td> |
| 958 |
<textarea name="mc_subheader_content" rows="2" cols="70"><?php echo esc_html(get_option('mc_subheader_content')); ?></textarea><br/> |
| 959 |
<?php esc_html_e('You can fill this with your own Text, HTML markup (including image links), or Nothing!', 'mailchimp_i18n'); ?>.<br/> |
| 960 |
<?php esc_html_e('This will be displayed under the heading and above the form.', 'mailchimp_i18n'); ?> |
| 961 |
</td> |
| 962 |
</tr> |
| 963 |
|
| 964 |
<tr valign="top" class="last-row"> |
| 965 |
<th scope="row"><?php esc_html_e('Submit Button', 'mailchimp_i18n'); ?></th> |
| 966 |
<td> |
| 967 |
<input type="text" name="mc_submit_text" size="70" value="<?php echo esc_attr(get_option('mc_submit_text')); ?>"/> |
| 968 |
</td> |
| 969 |
</tr> |
| 970 |
</table> |
| 971 |
|
| 972 |
<input type="submit" value="<?php esc_attr_e('Update Subscribe Form Settings', 'mailchimp_i18n'); ?>" class="button mc-submit" /><br/> |
| 973 |
|
| 974 |
<table class="widefat mc-widefat mc-custom-styling"> |
| 975 |
<tr><th colspan="2">Custom Styling</th></tr> |
| 976 |
<tr class="mc-turned-on"><th><label for="mc_custom_style"><?php esc_html_e('Enabled?', 'mailchimp_i18n'); ?></label></th><td><span class="mc-pre-input"></span><input type="checkbox" name="mc_custom_style" id="mc_custom_style"<?php checked(get_option('mc_custom_style'), 'on'); ?> /></td></tr> |
| 977 |
|
| 978 |
<tr class="mc-internal-heading"><th colspan="2"><?php esc_html_e('Form Settings', 'mailchimp_i18n'); ?></th></tr> |
| 979 |
<tr><th><?php esc_html_e('Border Width', 'mailchimp_i18n'); ?></th><td><span class="mc-pre-input"></span><input type="text" name="mc_form_border_width" size="3" maxlength="3" value="<?php echo esc_attr(get_option('mc_form_border_width')); ?>"/> |
| 980 |
<em>px •<?php esc_html_e('Set to 0 for no border, do not enter', 'mailchimp_i18n'); ?> <strong>px</strong>!</em> |
| 981 |
</td></tr> |
| 982 |
<tr><th><?php esc_html_e('Border Color', 'mailchimp_i18n'); ?></th><td><span class="mc-pre-input">#</span><input type="text" name="mc_form_border_color" size="7" maxlength="6" value="<?php echo esc_attr(get_option('mc_form_border_color')); ?>"/> |
| 983 |
<em><?php esc_html_e('Do not enter initial', 'mailchimp_i18n'); ?> <strong>#</strong></em> |
| 984 |
</td></tr> |
| 985 |
<tr><th><?php esc_html_e('Text Color', 'mailchimp_i18n'); ?></th><td><span class="mc-pre-input">#</span><input type="text" name="mc_form_text_color" size="7" maxlength="6" value="<?php echo esc_attr(get_option('mc_form_text_color')); ?>"/> |
| 986 |
<em><?php esc_html_e('Do not enter initial', 'mailchimp_i18n'); ?> <strong>#</strong></em> |
| 987 |
</td></tr> |
| 988 |
<tr class="last-row"><th><?php esc_html_e('Background Color', 'mailchimp_i18n'); ?></th><td><span class="mc-pre-input">#</span><input type="text" name="mc_form_background" size="7" maxlength="6" value="<?php echo esc_attr(get_option('mc_form_background')); ?>"/> |
| 989 |
<em><?php esc_html_e('Do not enter initial', 'mailchimp_i18n'); ?> <strong>#</strong></em> |
| 990 |
</td></tr> |
| 991 |
</table> |
| 992 |
|
| 993 |
<input type="submit" value="<?php esc_attr_e('Update Subscribe Form Settings', 'mailchimp_i18n'); ?>" class="button mc-submit" /><br/> |
| 994 |
|
| 995 |
<table class="widefat mc-widefat"> |
| 996 |
<tr><th colspan="2">List Options</th></tr> |
| 997 |
<tr valign="top"> |
| 998 |
<th scope="row"><?php esc_html_e('Monkey Rewards', 'mailchimp_i18n'); ?>?</th> |
| 999 |
<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" /> |
| 1000 |
<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> |
| 1001 |
</td> |
| 1002 |
</tr> |
| 1003 |
|
| 1004 |
<tr valign="top"> |
| 1005 |
<th scope="row"><?php esc_html_e('Use Javascript Support?', 'mailchimp_i18n'); ?></th> |
| 1006 |
<td><input name="mc_use_javascript" type="checkbox" <?php checked(get_option('mc_use_javascript'), 'on'); ?> id="mc_use_javascript" class="code" /> |
| 1007 |
<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> |
| 1008 |
</td> |
| 1009 |
</tr> |
| 1010 |
|
| 1011 |
<tr valign="top"> |
| 1012 |
<th scope="row"><?php esc_html_e('Use Javascript Datepicker?', 'mailchimp_i18n'); ?></th> |
| 1013 |
<td><input name="mc_use_datepicker" type="checkbox" <?php checked(get_option('mc_use_datepicker'), 'on'); ?> id="mc_use_datepicker" class="code" /> |
| 1014 |
<em><label for="mc_use_datepicker"><?php esc_html_e('Turning this on will use the jQuery UI Datepicker for dates.', 'mailchimp_i18n'); ?></label></em> |
| 1015 |
</td> |
| 1016 |
</tr> |
| 1017 |
<tr valign="top" class="last-row"> |
| 1018 |
<th scope="row"><?php esc_html_e('Include Unsubscribe link?', 'mailchimp_i18n'); ?></th> |
| 1019 |
<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" /> |
| 1020 |
<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> |
| 1021 |
</td> |
| 1022 |
</tr> |
| 1023 |
|
| 1024 |
|
| 1025 |
</table> |
| 1026 |
|
| 1027 |
</div> |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
<?php |
| 1032 |
// Merge Variables Table |
| 1033 |
?> |
| 1034 |
<div style="width:900px;"> |
| 1035 |
|
| 1036 |
<input type="submit" value="<?php esc_attr_e('Update Subscribe Form Settings', 'mailchimp_i18n'); ?>" class="button mc-submit" /><br/> |
| 1037 |
|
| 1038 |
<table class='widefat mc-widefat'> |
| 1039 |
<tr> |
| 1040 |
<th colspan="4"> |
| 1041 |
<?php esc_html_e('Merge Variables Included', 'mailchimp_i18n'); ?> |
| 1042 |
|
| 1043 |
<?php |
| 1044 |
$mv = get_option('mc_merge_vars'); |
| 1045 |
|
| 1046 |
if (count($mv) == 0 || !is_array($mv)){ |
| 1047 |
?> |
| 1048 |
<em><?php esc_html_e('No Merge Variables found.', 'mailchimp_i18n'); ?></em> |
| 1049 |
<?php |
| 1050 |
} else { |
| 1051 |
?> |
| 1052 |
</th> |
| 1053 |
</tr> |
| 1054 |
<tr valign="top"> |
| 1055 |
<th><?php esc_html_e('Name', 'mailchimp_i18n');?></th> |
| 1056 |
<th><?php esc_html_e('Tag', 'mailchimp_i18n');?></th> |
| 1057 |
<th><?php esc_html_e('Required?', 'mailchimp_i18n');?></th> |
| 1058 |
<th><?php esc_html_e('Include?', 'mailchimp_i18n');?></th> |
| 1059 |
</tr> |
| 1060 |
<?php |
| 1061 |
foreach($mv as $var){ |
| 1062 |
?> |
| 1063 |
<tr valign="top"> |
| 1064 |
<td><?php echo esc_html($var['name']); ?></td> |
| 1065 |
<td><?php echo esc_html($var['tag']); ?></td> |
| 1066 |
<td><?php echo esc_html(($var['req'] == 1) ? 'Y' : 'N'); ?></td> |
| 1067 |
<td> |
| 1068 |
<?php |
| 1069 |
if (!$var['req']){ |
| 1070 |
$opt = 'mc_mv_'.$var['tag']; |
| 1071 |
?> |
| 1072 |
<input name="<?php echo esc_attr($opt); ?>" type="checkbox" id="<?php echo esc_attr($opt); ?>" class="code"<?php checked(get_option($opt), 'on'); ?> /> |
| 1073 |
<?php |
| 1074 |
} else { |
| 1075 |
?> |
| 1076 |
— |
| 1077 |
<?php |
| 1078 |
} |
| 1079 |
?> |
| 1080 |
</td> |
| 1081 |
</tr> |
| 1082 |
<?php |
| 1083 |
} |
| 1084 |
?> |
| 1085 |
</table> |
| 1086 |
<?php |
| 1087 |
} |
| 1088 |
|
| 1089 |
?> |
| 1090 |
|
| 1091 |
<input type="submit" value="<?php esc_attr_e('Update Subscribe Form Settings', 'mailchimp_i18n'); ?>" class="button mc-submit" /><br/> |
| 1092 |
|
| 1093 |
<?php |
| 1094 |
// Interest Groups Table |
| 1095 |
$igs = get_option('mc_interest_groups'); |
| 1096 |
if (is_array($igs) && !isset($igs['id'])) { ?> |
| 1097 |
<h3 class="mc-h3"><?php esc_html_e('Group Settings', 'mailchimp_i18n'); ?></h3> <?php |
| 1098 |
// Determines whether or not to continue processing. Only false if there was an error. |
| 1099 |
$continue = true; |
| 1100 |
foreach ($igs as $ig) { |
| 1101 |
if ($continue) { |
| 1102 |
if (!is_array($ig) || empty($ig) || $ig == 'N' ) { |
| 1103 |
?> |
| 1104 |
<em><?php esc_html_e('No Interest Groups Setup for this List', 'mailchimp_i18n'); ?></em> |
| 1105 |
<?php |
| 1106 |
$continue = false; |
| 1107 |
} |
| 1108 |
else { |
| 1109 |
?> |
| 1110 |
<table class='mc-widefat mc-blue' width="450px" cellspacing="0"> |
| 1111 |
<tr valign="top"> |
| 1112 |
<th colspan="2"><?php echo esc_html($ig['name']); ?></th> |
| 1113 |
</tr> |
| 1114 |
<tr valign="top"> |
| 1115 |
<th> |
| 1116 |
<label for="<?php echo esc_attr('mc_show_interest_groups_'.$ig['id']); ?>"><?php esc_html_e('Show?', 'mailchimp_i18n'); ?></label> |
| 1117 |
</th> |
| 1118 |
<th> |
| 1119 |
<input name="<?php echo esc_attr('mc_show_interest_groups_'.$ig['id']); ?>" id="<?php echo esc_attr('mc_show_interest_groups_'.$ig['id']); ?>" type="checkbox" class="code"<?php checked('on', get_option('mc_show_interest_groups_'.$ig['id'])); ?> /> |
| 1120 |
</th> |
| 1121 |
</tr> |
| 1122 |
<tr valign="top"> |
| 1123 |
<th><?php esc_html_e('Input Type', 'mailchimp_i18n'); ?></th> |
| 1124 |
<td><?php echo esc_html($ig['form_field']); ?></td> |
| 1125 |
</tr> |
| 1126 |
<tr valign="top" class="last-row"> |
| 1127 |
<th><?php esc_html_e('Options', 'mailchimp_i18n'); ?></th> |
| 1128 |
<td> |
| 1129 |
<ul> |
| 1130 |
<?php |
| 1131 |
foreach($ig['groups'] as $interest){ |
| 1132 |
?> |
| 1133 |
<li><?php echo esc_html($interest['name']); ?></li> |
| 1134 |
<?php |
| 1135 |
} |
| 1136 |
?> |
| 1137 |
</ul> |
| 1138 |
</td> |
| 1139 |
</tr> |
| 1140 |
</table> |
| 1141 |
<?php |
| 1142 |
} |
| 1143 |
} |
| 1144 |
} |
| 1145 |
} |
| 1146 |
?> |
| 1147 |
|
| 1148 |
<table class="widefat mc-widefat mc-yellow"> |
| 1149 |
<tr><th colspan="2">CSS Cheat Sheet</th></tr> |
| 1150 |
<tr valign="top"> |
| 1151 |
<th scope="row">.widget_mailchimpsf_widget </th> |
| 1152 |
<td>This targets the entire widget container.</td> |
| 1153 |
</tr> |
| 1154 |
<tr valign="top"> |
| 1155 |
<th scope="row">.widget-title</th> |
| 1156 |
<td>This styles the title of your MailChimp widget. <i>Modifying this class will affect your other widget titles.</i></td> |
| 1157 |
</tr> |
| 1158 |
<tr valign="top"> |
| 1159 |
<th scope="row">#mc_signup</th> |
| 1160 |
<td>This targets the entirity of the widget beneath the widget title.</td> |
| 1161 |
</tr> |
| 1162 |
<tr valign="top"> |
| 1163 |
<th scope="row">#mc_subheader</th> |
| 1164 |
<td>This styles the subheader text.</td> |
| 1165 |
</tr> |
| 1166 |
<tr valign="top"> |
| 1167 |
<th scope="row">.mc_form_inside</th> |
| 1168 |
<td>The guts and main container for the all of the form elements (the entirety of the widget minus the header and the sub header).</td> |
| 1169 |
</tr> |
| 1170 |
<tr valign="top"> |
| 1171 |
<th scope="row">.mc_header</th> |
| 1172 |
<td>This targets the label above the input fields.</td> |
| 1173 |
</tr> |
| 1174 |
<tr valign="top"> |
| 1175 |
<th scope="row">.mc_input</th> |
| 1176 |
<td>This attaches to the input fields.</td> |
| 1177 |
</tr> |
| 1178 |
<tr valign="top"> |
| 1179 |
<th scope="row">.mc_header_address</th> |
| 1180 |
<td>This is the label above an address group.</td> |
| 1181 |
</tr> |
| 1182 |
<tr valign="top"> |
| 1183 |
<th scope="row">.mc_radio_label</th> |
| 1184 |
<td>These are the labels associated with radio buttons.</td> |
| 1185 |
</tr> |
| 1186 |
<tr valign="top"> |
| 1187 |
<th scope="row">#mc-indicates-required</th> |
| 1188 |
<td>This targets the “Indicates Required Field” text.</td> |
| 1189 |
</tr> |
| 1190 |
<tr valign="top"> |
| 1191 |
<th scope="row">#mc_signup_submit</th> |
| 1192 |
<td>Use this to style the submit button.</td> |
| 1193 |
</tr> |
| 1194 |
|
| 1195 |
|
| 1196 |
</table> |
| 1197 |
|
| 1198 |
</div> |
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
</form> |
| 1203 |
</div> |
| 1204 |
</div><!--wrap--> |
| 1205 |
<?php |
| 1206 |
}//mailchimpSF_setup_page() |
| 1207 |
|
| 1208 |
|
| 1209 |
function mailchimpSF_register_widgets() { |
| 1210 |
if (mailchimpSF_get_api()) { |
| 1211 |
register_widget('mailchimpSF_Widget'); |
| 1212 |
} |
| 1213 |
} |
| 1214 |
add_action('widgets_init', 'mailchimpSF_register_widgets'); |
| 1215 |
|
| 1216 |
function mailchimpSF_shortcode($atts){ |
| 1217 |
ob_start(); |
| 1218 |
mailchimpSF_signup_form(); |
| 1219 |
return ob_get_clean(); |
| 1220 |
} |
| 1221 |
add_shortcode('mailchimpsf_form', 'mailchimpSF_shortcode'); |
| 1222 |
|
| 1223 |
/** |
| 1224 |
* Attempts to signup a user, per the $_POST args. |
| 1225 |
* |
| 1226 |
* This sets a global message, that is then used in the widget |
| 1227 |
* output to retrieve and display that message. |
| 1228 |
* |
| 1229 |
* @return bool |
| 1230 |
*/ |
| 1231 |
function mailchimpSF_signup_submit() { |
| 1232 |
$mv = get_option('mc_merge_vars', array()); |
| 1233 |
$mv_tag_keys = array(); |
| 1234 |
|
| 1235 |
$igs = get_option('mc_interest_groups', array()); |
| 1236 |
|
| 1237 |
$success = true; |
| 1238 |
$listId = get_option('mc_list_id'); |
| 1239 |
$email = isset($_POST['mc_mv_EMAIL']) ? strip_tags(stripslashes($_POST['mc_mv_EMAIL'])) : ''; |
| 1240 |
$merge = $errs = $html_errs = array(); // Set up some vars |
| 1241 |
|
| 1242 |
// Loop through our Merge Vars, and if they're empty, but required, then print an error, and mark as failed |
| 1243 |
foreach($mv as $var) { |
| 1244 |
$opt = 'mc_mv_'.$var['tag']; |
| 1245 |
|
| 1246 |
$opt_val = isset($_POST[$opt]) ? $_POST[$opt] : ''; |
| 1247 |
|
| 1248 |
if (is_array($opt_val) && isset($opt_val['area'])) { |
| 1249 |
$opt_val = implode('-', $opt_val); |
| 1250 |
} |
| 1251 |
else if (is_array($opt_val) && $var['field_type'] == 'address') { |
| 1252 |
if ($var['req'] == 'Y') { |
| 1253 |
if (empty($opt_val['addr1']) || empty($opt_val['city'])) { |
| 1254 |
$errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name'])); |
| 1255 |
$success = false; |
| 1256 |
} |
| 1257 |
} |
| 1258 |
$merge[$var['tag']] = $opt_val; |
| 1259 |
continue; |
| 1260 |
} |
| 1261 |
else if (is_array($opt_val)) { |
| 1262 |
$opt_val = implode($opt_val); |
| 1263 |
} |
| 1264 |
|
| 1265 |
if ($var['req'] == 'Y' && trim($opt_val) == '') { |
| 1266 |
$success = false; |
| 1267 |
$errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name'])); |
| 1268 |
} |
| 1269 |
else { |
| 1270 |
if ($var['tag'] != 'EMAIL') { |
| 1271 |
$merge[$var['tag']] = $opt_val; |
| 1272 |
} |
| 1273 |
} |
| 1274 |
|
| 1275 |
// We also want to create an array where the keys are the tags for easier validation later |
| 1276 |
$mv_tag_keys[$var['tag']] = $var; |
| 1277 |
|
| 1278 |
} |
| 1279 |
|
| 1280 |
// Head back to the beginning of the merge vars array |
| 1281 |
reset($mv); |
| 1282 |
|
| 1283 |
// Ensure we have an array |
| 1284 |
$igs = !is_array($igs) ? array() : $igs; |
| 1285 |
foreach ($igs as $ig) { |
| 1286 |
$groups = ''; |
| 1287 |
if (get_option('mc_show_interest_groups_'.$ig['id']) == 'on') { |
| 1288 |
$groupings = array(); |
| 1289 |
switch ($ig['form_field']) { |
| 1290 |
case 'select': |
| 1291 |
case 'dropdown': |
| 1292 |
case 'radio': |
| 1293 |
if (isset($_POST['group'][$ig['id']])) { |
| 1294 |
$groupings = array( |
| 1295 |
'id' => $ig['id'], |
| 1296 |
'groups' => str_replace(',', '\,', stripslashes($_POST['group'][$ig['id']])), |
| 1297 |
); |
| 1298 |
} |
| 1299 |
break; |
| 1300 |
case 'checkboxes': |
| 1301 |
case 'checkbox': |
| 1302 |
if (isset($_POST['group'][$ig['id']])) { |
| 1303 |
foreach ($_POST['group'][$ig['id']] as $i => $value) { |
| 1304 |
// Escape |
| 1305 |
$groups .= str_replace(',', '\,', stripslashes($value)).','; |
| 1306 |
} |
| 1307 |
$groupings = array( |
| 1308 |
'id' => $ig['id'], |
| 1309 |
'groups' => $groups, |
| 1310 |
); |
| 1311 |
} |
| 1312 |
break; |
| 1313 |
default: |
| 1314 |
// Nothing |
| 1315 |
break; |
| 1316 |
} |
| 1317 |
if (!isset($merge['GROUPINGS']) || !is_array($merge['GROUPINGS'])) { |
| 1318 |
$merge['GROUPINGS'] = array(); |
| 1319 |
} |
| 1320 |
if (!empty($groupings)) { |
| 1321 |
$merge['GROUPINGS'][] = $groupings; |
| 1322 |
} |
| 1323 |
} |
| 1324 |
} |
| 1325 |
|
| 1326 |
// If we're good |
| 1327 |
if ($success) { |
| 1328 |
// Clear out empty merge vars |
| 1329 |
foreach ($merge as $k => $v) { |
| 1330 |
if (is_array($v) && empty($v)) { |
| 1331 |
unset($merge[$k]); |
| 1332 |
} |
| 1333 |
else if (!is_array($v) && trim($v) === '') { |
| 1334 |
unset($merge[$k]); |
| 1335 |
} |
| 1336 |
} |
| 1337 |
|
| 1338 |
// If we have an empty $merge, then assign empty string. |
| 1339 |
if (count($merge) == 0 || $merge == '') { |
| 1340 |
$merge = ''; |
| 1341 |
} |
| 1342 |
|
| 1343 |
if (isset($_POST['email_type']) && in_array($_POST['email_type'], array('text', 'html', 'mobile'))) { |
| 1344 |
$email_type = $_POST['email_type']; |
| 1345 |
} |
| 1346 |
else { |
| 1347 |
$email_type = 'html'; |
| 1348 |
} |
| 1349 |
|
| 1350 |
// Custom validation based on type |
| 1351 |
if (is_array($merge) && !empty($merge)) { |
| 1352 |
foreach ($merge as $merge_key => $merge_value) { |
| 1353 |
if ($merge_key !== 'GROUPINGS') { |
| 1354 |
switch ($mv_tag_keys[$merge_key]['field_type']) { |
| 1355 |
case 'phone': |
| 1356 |
if ($mv_tag_keys[$merge_key]['phoneformat'] == 'US') { |
| 1357 |
$phone = $merge_value; |
| 1358 |
if (!empty($phone)) { |
| 1359 |
if (!preg_match('/[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,4}/', $phone)) { |
| 1360 |
$errs[] = sprintf(__("%s must consist of only numbers", 'mailchimp_i18n'), esc_html($mv_tag_keys[$merge_key]['name'])); |
| 1361 |
$success = false; |
| 1362 |
} |
| 1363 |
} |
| 1364 |
} |
| 1365 |
break; |
| 1366 |
|
| 1367 |
default: |
| 1368 |
break; |
| 1369 |
} |
| 1370 |
} |
| 1371 |
} |
| 1372 |
} |
| 1373 |
if ($success) { |
| 1374 |
$api = mailchimpSF_get_api(); |
| 1375 |
if (!$api) { return; } |
| 1376 |
|
| 1377 |
$retval = $api->listSubscribe( $listId, $email, $merge, $email_type); |
| 1378 |
if (!$retval) { |
| 1379 |
switch($api->errorCode) { |
| 1380 |
case '105' : |
| 1381 |
$errs[] = __("Please try again later", 'mailchimp_i18n').'.'; |
| 1382 |
break; |
| 1383 |
case '214' : |
| 1384 |
$msg = __("That email address is already subscribed to the list", 'mailchimp_i18n') . '.'; |
| 1385 |
|
| 1386 |
$account = $api->getAccountDetails(array("modules", "orders", "rewards-credits", "rewards-inspections", "rewards-referrals", "rewards-applied")); |
| 1387 |
if (!$api->errorCode) { |
| 1388 |
$dc = get_option('mc_sopresto_dc'); |
| 1389 |
$uid = $account['user_id']; |
| 1390 |
$username = preg_replace('/\s+/', '-', $account['username']); |
| 1391 |
$eid = base64_encode($email); |
| 1392 |
$msg .= ' ' . sprintf(__('<a href="%s">Click here to update your profile.</a>', 'mailchimp_i18n'), "http://$username.$dc.list-manage.com/subscribe/send-email?u=$uid&id=$listId&e=$eid"); |
| 1393 |
} |
| 1394 |
|
| 1395 |
$errs[] = $msg; |
| 1396 |
$html_errs[] = count($errs)-1; |
| 1397 |
break; |
| 1398 |
case '250' : |
| 1399 |
list($field, $rest) = explode(' ', $api->errorMessage, 2); |
| 1400 |
$errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($mv_tag_keys[$field]['name'])); |
| 1401 |
break; |
| 1402 |
case '254' : |
| 1403 |
list($i1, $i2, $i3, $field, $rest) = explode(' ',$api->errorMessage,5); |
| 1404 |
$errs[] = sprintf(__("%s has invalid content.", 'mailchimp_i18n'), esc_html($mv_tag_keys[$field]['name'])); |
| 1405 |
break; |
| 1406 |
case '270' : |
| 1407 |
$errs[] = __("An invalid Interest Group was selected", 'mailchimp_i18n').'.'; |
| 1408 |
break; |
| 1409 |
case '502' : |
| 1410 |
$errs[] = __("That email address is invalid", 'mailchimp_i18n').'.'; |
| 1411 |
break; |
| 1412 |
default: |
| 1413 |
$errs[] = $api->errorCode.":".$api->errorMessage; |
| 1414 |
break; |
| 1415 |
} |
| 1416 |
$success = false; |
| 1417 |
} |
| 1418 |
} |
| 1419 |
} |
| 1420 |
|
| 1421 |
// If we have errors, then show them |
| 1422 |
if (count($errs) > 0) { |
| 1423 |
$msg = '<span class="mc_error_msg">'; |
| 1424 |
foreach($errs as $error_index => $error){ |
| 1425 |
if (!in_array($error_index, $html_errs)) { |
| 1426 |
$error = esc_html($error); |
| 1427 |
} |
| 1428 |
$msg .= '» '.$error.'<br />'; |
| 1429 |
} |
| 1430 |
$msg .= '</span>'; |
| 1431 |
} |
| 1432 |
else { |
| 1433 |
$msg = "<strong class='mc_success_msg'>".esc_html(__("Success, you've been signed up! Please look for our confirmation email!", 'mailchimp_i18n'))."</strong>"; |
| 1434 |
} |
| 1435 |
|
| 1436 |
// Set our global message |
| 1437 |
mailchimpSF_global_msg($msg); |
| 1438 |
|
| 1439 |
return $success; |
| 1440 |
} |
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
/********************** |
| 1445 |
* Utility Functions * |
| 1446 |
**********************/ |
| 1447 |
/** |
| 1448 |
* Utility function to allow placement of plugin in plugins, mu-plugins, child or parent theme's plugins folders |
| 1449 |
* |
| 1450 |
* This function must be ran _very early_ in the load process, as it sets up important constants for the rest of the plugin |
| 1451 |
*/ |
| 1452 |
function mailchimpSF_where_am_i() { |
| 1453 |
$locations = array( |
| 1454 |
'plugins' => array( |
| 1455 |
'dir' => WP_PLUGIN_DIR, |
| 1456 |
'url' => plugins_url() |
| 1457 |
), |
| 1458 |
'mu_plugins' => array( |
| 1459 |
'dir' => WPMU_PLUGIN_DIR, |
| 1460 |
'url' => plugins_url(), |
| 1461 |
), |
| 1462 |
'template' => array( |
| 1463 |
'dir' => trailingslashit(get_template_directory()).'plugins/', |
| 1464 |
'url' => trailingslashit(get_template_directory_uri()).'plugins/', |
| 1465 |
), |
| 1466 |
'stylesheet' => array( |
| 1467 |
'dir' => trailingslashit(get_stylesheet_directory()).'plugins/', |
| 1468 |
'url' => trailingslashit(get_stylesheet_directory_uri()).'plugins/', |
| 1469 |
), |
| 1470 |
); |
| 1471 |
|
| 1472 |
// Set defaults |
| 1473 |
$mscf_dirbase = trailingslashit(basename(dirname(__FILE__))); // Typically wp-mailchimp/ or mailchimp/ |
| 1474 |
$mscf_dir = trailingslashit(WP_PLUGIN_DIR).$mscf_dirbase; |
| 1475 |
$mscf_url = trailingslashit(WP_PLUGIN_URL).$mscf_dirbase; |
| 1476 |
|
| 1477 |
// Try our hands at finding the real location |
| 1478 |
foreach ($locations as $key => $loc) { |
| 1479 |
$dir = trailingslashit($loc['dir']).$mscf_dirbase; |
| 1480 |
$url = trailingslashit($loc['url']).$mscf_dirbase; |
| 1481 |
if (is_file($dir.basename(__FILE__))) { |
| 1482 |
$mscf_dir = $dir; |
| 1483 |
$mscf_url = $url; |
| 1484 |
break; |
| 1485 |
} |
| 1486 |
} |
| 1487 |
|
| 1488 |
// Define our complete filesystem path |
| 1489 |
define('MCSF_DIR', $mscf_dir); |
| 1490 |
|
| 1491 |
/* Lang location needs to be relative *from* ABSPATH, |
| 1492 |
so strip it out of our language dir location */ |
| 1493 |
define('MCSF_LANG_DIR', trailingslashit(MCSF_DIR).'po/'); |
| 1494 |
|
| 1495 |
// Define our complete URL to the plugin folder |
| 1496 |
define('MCSF_URL', $mscf_url); |
| 1497 |
} |
| 1498 |
|
| 1499 |
|
| 1500 |
?> |
| 1501 |
|