localize('mailchimpSF_main_js', 'mailchimpSF', array( 'ajax_url' => trailingslashit(home_url()), )); } } // CSS if (is_admin() && $_GET['page'] == 'mailchimpSF_options') { wp_enqueue_style('mailchimpSF_admin_css', MCSF_URL.'css/admin.css'); } else { wp_enqueue_style('mailchimpSF_main_css', home_url('?mcsf_action=main_css&ver='.MCSF_VER)); wp_enqueue_style('mailchimpSF_ie_css', MCSF_URL.'css/ie.css'); global $wp_styles; $wp_styles->add_data( 'mailchimpSF_ie_css', 'conditional', 'IE' ); } } /** * Handles requests that as light-weight a load as possible. * typically, JS or CSS **/ function mailchimpSF_early_request_handler() { if (isset($_GET['mcsf_action'])) { switch ($_GET['mcsf_action']) { case 'main_css': header("Content-type: text/css"); mailchimpSF_main_css(); exit; } } } add_action('init', 'mailchimpSF_early_request_handler', 0); /** * Outputs the front-end CSS. This checks several options, so it * was best to put it in a Request-handled script, as opposed to * a static file. */ function mailchimpSF_main_css() { ?> .mc_error_msg { color: red; } .mc_success_msg { color: green; } .mc_merge_var{ padding:0; margin:0; } #mc_signup_form { padding:5px; border-width: px; border-style: ; border-color: #; color: #; background-color: #; } .mc_custom_border_hdr { border-width: px; border-style: ; border-color: #; color: #; background-color: #; font-size: 1.2em; padding:5px 10px; width: 100%; } #mc_signup_container {} #mc_signup_form {} #mc_signup_form .mc_var_label {} #mc_signup_form .mc_input {} #mc-indicates-required { width:100%; } #mc_display_rewards {} #mc_interests_header { font-weight:bold; } div.mc_interest{ width:100%; } #mc_signup_form input.mc_interest {} #mc_signup_form select {} #mc_signup_form label.mc_interest_label { display:inline; } .mc_signup_submit { text-align:center; } MCAPIv1.3 - update interest groups * 2011-02-09 - old password upgrade code deleted as 0.5 is way old */ function mailchimpSF_do_upgrade() { //left in just for good measure delete_option('mc_password'); $api = new mailchimpSF_MCAPI(get_option('mc_apikey')); $ig = $api->listInterestGroupings(get_option('mc_list_id')); $ig = $ig[0]; update_option('mc_interest_groups', $ig); } /** * Sets the API Key to whatever value was passed to this func * * @return array of vars **/ function mailchimpSF_set_api_key($api_key = '') { $delete_setup = false; $api = new mailchimpSF_MCAPI($api_key); $api->ping(); if (empty($api->errorCode)) { $msg = "

".esc_html(__("Success! We were able to verify your API Key! Let's continue, shall we?", 'mailchimp_i18n'))."

"; update_option('mc_apikey', $api_key); $req = $api->getAccountDetails(); update_option('mc_username', $req['username']); update_option('mc_user_id', $req['user_id']); $cur_list_id = get_option('mc_list_id'); if (!empty($cur_list_id)) { //we *could* support paging, but few users have that many lists (and shouldn't) $lists = $api->lists(array(),0,100); $lists = $lists['data']; //but don't delete if the list still exists... $delete_setup = true; foreach($lists as $list) { if ($list['id'] == $cur_list_id) { $list_id = $_POST['mc_list_id']; $delete_setup = false; } } } } else { $msg = "

".esc_html(__('Uh-oh, we were unable to verify your API Key. Please check them and try again!', 'mailchimp_i18n'))."
"; $msg .= __('The server said:', 'mailchimp_i18n')."".esc_html($api->errorMessage)."

"; $username = get_option('mc_username'); if (empty($username)) { $delete_setup = true; } } // Set a global message mailchimpSF_global_msg($msg); // If we need to delete our setup, do it if ($delete_setup){ mailchimpSF_delete_setup(); } //set these for the form fields below $user = $_REQUEST['mc_username']; // return compact('user', 'delete_setup', 'list_id') } /** * Deletes all mailchimp options **/ function mailchimpSF_delete_setup() { delete_option('mc_user_id'); delete_option('mc_rewards'); delete_option('mc_use_javascript'); delete_option('mc_use_unsub_link'); delete_option('mc_list_id'); delete_option('mc_list_name'); delete_option('mc_interest_groups'); delete_option('mc_show_interest_groups'); $mv = get_option('mc_merge_vars'); if (is_array($mv)){ foreach($mv as $var){ $opt = 'mc_mv_'.$var['tag']; delete_option($opt); } } delete_option('mc_merge_vars'); } /** * Resets the list settings, there's only one list * that can have settings at a time, so no list_id * parameter is necessary. **/ function mailchimpSF_reset_list_settings() { delete_option('mc_list_id'); delete_option('mc_list_name'); delete_option('mc_merge_vars'); delete_option('mc_interest_groups'); delete_option('mc_use_javascript'); delete_option('mc_use_unsub_link'); delete_option('mc_header_content'); delete_option('mc_subheader_content'); delete_option('mc_submit_text'); delete_option('mc_custom_style'); delete_option('mc_header_border_width'); delete_option('mc_header_border_color'); delete_option('mc_header_background'); delete_option('mc_header_text_color'); delete_option('mc_form_border_width'); delete_option('mc_form_border_color'); delete_option('mc_form_background'); delete_option('mc_form_text_color'); $msg = '

'.esc_html(__('Successfully Reset your List selection... Now you get to pick again!', 'mailchimp_i18n')).'

'; mailchimpSF_global_msg($msg); } /** * Gets or sets a global message based on parameter passed to it * * @return string/bool depending on get/set **/ function mailchimpSF_global_msg($msg = null) { global $mcsf_msgs; // Make sure we're formed properly if (!is_array($mcsf_msgs)) { $mcsf_msgs = array(); } // See if we're getting if (is_null($msg)) { return implode('', $mcsf_msgs); } // Must be setting $mcsf_msgs[] = $msg; return true; } /** * Sets the default options for the option form **/ function mailchimpSF_set_form_defaults($list_name = '') { update_option('mc_header_content',__( 'Sign up for', 'mailchimp_i18n' ).' '.$list_name); update_option('mc_submit_text',__( 'Subscribe', 'mailchimp_i18n' )); update_option('mc_custom_style','on'); update_option('mc_use_javascript','on'); update_option('mc_use_unsub_link','off'); update_option('mc_header_border_width','1'); update_option('mc_header_border_color','E3E3E3'); update_option('mc_header_background','FFFFFF'); update_option('mc_header_text_color','CC6600'); update_option('mc_form_border_width','1'); update_option('mc_form_border_color','C4D3EA'); update_option('mc_form_background','EEF3F8'); update_option('mc_form_text_color','555555'); update_option('mc_show_interest_groups', 'on' ); } /** * Saves the General Form settings on the options page * * @return void **/ function mailchimpSF_save_general_form_settings() { if (isset($_POST['mc_rewards'])){ update_option('mc_rewards', 'on'); $msg = '

'.__('Monkey Rewards turned On!', 'mailchimp_i18n').'

'; mailchimpSF_global_msg($msg); } else if (get_option('mc_rewards')!='off') { update_option('mc_rewards', 'off'); $msg = '

'.__('Monkey Rewards turned Off!', 'mailchimp_i18n').'

'; mailchimpSF_global_msg($msg); } if (isset($_POST['mc_use_javascript'])){ update_option('mc_use_javascript', 'on'); $msg = '

'.__('Fancy Javascript submission turned On!', 'mailchimp_i18n').'

'; mailchimpSF_global_msg($msg); } else if (get_option('mc_use_javascript')!='off') { update_option('mc_use_javascript', 'off'); $msg = '

'.__('Fancy Javascript submission turned Off!', 'mailchimp_i18n').'

'; mailchimpSF_global_msg($msg); } if (isset($_POST['mc_use_unsub_link'])){ update_option('mc_use_unsub_link', 'on'); $msg = '

'.__('Unsubscribe link turned On!', 'mailchimp_i18n').'

'; mailchimpSF_global_msg($msg); } else if (get_option('mc_use_unsub_link')!='off') { update_option('mc_use_unsub_link', 'off'); $msg = '

'.__('Unsubscribe link turned Off!', 'mailchimp_i18n').'

'; mailchimpSF_global_msg($msg); } $content = stripslashes($_POST['mc_header_content']); $content = str_replace("\r\n","
", $content); update_option('mc_header_content', $content ); $content = stripslashes($_POST['mc_subheader_content']); $content = str_replace("\r\n","
", $content); update_option('mc_subheader_content', $content ); $submit_text = stripslashes($_POST['mc_submit_text']); $submit_text = str_replace("\r\n","", $submit_text); update_option('mc_submit_text', $submit_text); // Set Custom Style option update_option('mc_custom_style', (isset($_POST['mc_custom_style'])) ? 'on' : 'off'); //we told them not to put these things we are replacing in, but let's just make sure they are listening... update_option('mc_header_border_width',str_replace('px','',$_POST['mc_header_border_width']) ); update_option('mc_header_border_color', str_replace('#','',$_POST['mc_header_border_color'])); update_option('mc_header_background',str_replace('#','',$_POST['mc_header_background'])); update_option('mc_header_text_color', str_replace('#','',$_POST['mc_header_text_color'])); update_option('mc_form_border_width',str_replace('px','',$_POST['mc_form_border_width']) ); update_option('mc_form_border_color', str_replace('#','',$_POST['mc_form_border_color'])); update_option('mc_form_background',str_replace('#','',$_POST['mc_form_background'])); update_option('mc_form_text_color', str_replace('#','',$_POST['mc_form_text_color'])); update_option('mc_show_interest_groups', (isset($_POST['mc_show_interest_groups'])) ? 'on' : 'off'); $mv = get_option('mc_merge_vars'); if (is_array($mv)) { foreach($mv as $var){ $opt = 'mc_mv_'.$var['tag']; if (isset($_POST[$opt]) || $var['req']=='Y'){ update_option($opt,'on'); } else { update_option($opt,'off'); } } } $msg = '

'.esc_html(__('Successfully Updated your List Subscribe Form Settings!', 'mailchimp_i18n')).'

'; mailchimpSF_global_msg($msg); } /** * Sees if the user changed the list, and updates options accordingly **/ function mailchimpSF_change_list_if_necessary($api_key) { // Simple permission check before going through all this if (!current_user_can(MCSF_CAP_THRESHOLD)) { return; } $api = new mailchimpSF_MCAPI($api_key); //we *could* support paging, but few users have that many lists (and shouldn't) $lists = $api->lists(array(),0,100); $lists = $lists['data']; /* If our incoming list ID (the one chosen in the select dropdown) is in our array of lists, the set it to be the active list */ foreach($lists as $list) { if ($list['id'] == $_POST['mc_list_id']) { $list_id = $_POST['mc_list_id']; $list_name = $list['name']; } } $orig_list = get_option('mc_list_id'); if ($list_id != '') { update_option('mc_list_id', $list_id); update_option('mc_list_name', $list_name); // See if the user changed the list if ($orig_list != $list_id){ // The user changed the list, Reset the Form Defaults mailchimpSF_set_form_defaults($list_name); } // Grab the merge vars and interest groups $mv = $api->listMergeVars($list_id); $ig = $api->listInterestGroupings($list_id); $ig = $ig[0]; update_option('mc_merge_vars', $mv); foreach($mv as $var){ $opt = 'mc_mv_'.$var['tag']; //turn them all on by default if ($orig_list != $list_id){ update_option($opt, 'on' ); } } update_option('mc_interest_groups', $ig); $msg = '

'. sprintf( __('Success! Loaded and saved the info for %d Merge Variables and %d Interest Groups from your list', 'mailchimp_i18n'), count($mv), count($ig['groups']) ). ' "'.$list_name.'"

'. __('Now you should either Turn On the MailChimp Widget or change your options below, then turn it on.', 'mailchimp_i18n').'

'; mailchimpSF_global_msg($msg); } } /** * Outputs the Settings/Options page */ function mailchimpSF_setup_page() { // See if we need an upgrade if (mailchimpSF_needs_upgrade()) { // remove password option if it's set mailchimpSF_do_upgrade(); } ?>


%2$s', esc_html(__("Don't have a MailChimp account?", 'mailchimp_i18n')), esc_html(__('Try one for Free!', 'mailchimp_i18n')) ); ?>
:
get your API Key here
:

:

lists(array(),0,100); $lists = $lists['data']; if (count($lists) == 0) { ?> MailChimp" ); ?>

:

:

: id="mc_rewards" class="code" />
: id="mc_use_javascript" class="code" />
: id="mc_use_unsub_link" class="code" />
:
:
.
:
:
/>
:
: px
px!
:#
#
:#
#
:#
#
:
: px
px!
:#
#
:#
#
:#
#

/>  — 

/>
:
:
:

$nothing) { $merge['INTERESTS'] .= str_replace(',', '\,', $i).','; } } break; default: // Nothing break; } } // If we're good if ($success) { // Clear out empty merge vars foreach ($merge as $k => $v) { if (trim($v) === '') { unset($merge[$k]); } } // If we have an empty $merge, then assign empty string. if (count($merge) == 0 || $merge == '') { $merge = ''; } $api = new mailchimpSF_MCAPI(get_option('mc_apikey')); $retval = $api->listSubscribe( $listId, $email, $merge); if (!$retval) { switch($api->errorCode) { case '214' : $errs[] = __("That email address is already subscribed to the list", 'mailchimp_i18n').'.'; break; case '250' : list($field, $rest) = explode(' ', $api->errorMessage, 2); $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($field)); break; case '254' : list($i1, $i2, $i3, $field, $rest) = explode(' ',$api->errorMessage,5); $errs[] = sprintf(__("%s has invalid content.", 'mailchimp_i18n'), esc_html($field)); break; case '270' : $errs[] = __("An invalid Interest Group was selected", 'mailchimp_i18n').'.'; break; case '502' : $errs[] = __("That email address is invalid", 'mailchimp_i18n').'.'; break; default: $errs[] = $api->errorCode.":".$api->errorMessage; break; } $success = false; } else { $msg = "".esc_html(__("Success, you've been signed up! Please look for our confirmation email!", 'mailchimp_i18n')).""; } } // If we have errors, then show them if (count($errs) > 0) { $msg = ''; foreach($errs as $error){ $msg .= '» '.esc_html($error).'
'; } $msg .= '
'; } // Set our global message mailchimpSF_global_msg($msg); return $success; } /********************** * Utility Functions * **********************/ /** * Utility function to allow placement of plugin in plugins, mu-plugins, child or parent theme's plugins folders * * This function must be ran _very early_ in the load process, as it sets up important constants for the rest of the plugin */ function mailchimpSF_where_am_i() { $locations = array( 'plugins' => array( 'dir' => WP_PLUGIN_DIR, 'url' => plugins_url() ), 'mu_plugins' => array( 'dir' => WPMU_PLUGIN_DIR, 'url' => plugins_url(), ), 'template' => array( 'dir' => trailingslashit(get_template_directory()).'plugins/', 'url' => trailingslashit(get_template_directory_uri()).'plugins/', ), 'stylesheet' => array( 'dir' => trailingslashit(get_stylesheet_directory()).'plugins/', 'url' => trailingslashit(get_stylesheet_directory_uri()).'plugins/', ), ); // Set defaults $mscf_dir = trailingslashit(WP_PLUGIN_DIR).'mailchimp/'; $mscf_url = trailingslashit(WP_PLUGIN_URL).'mailchimp/'; // Try our hands at finding the real location foreach ($locations as $key => $loc) { $dir = trailingslashit($loc['dir']).'mailchimp/'; $url = trailingslashit($loc['url']).'mailchimp/'; if (is_file($dir.basename(__FILE__))) { $mscf_dir = $dir; $mscf_url = $url; break; } } // Define our complete filesystem path define('MCSF_DIR', $mscf_dir); /* Lang location needs to be relative *from* ABSPATH, so strip it out of our language dir location */ define('MCSF_LANG_DIR', str_replace(ABSPATH, '', MCSF_DIR)); // Define our complete URL to the plugin folder define('MCSF_URL', $mscf_url); } ?>