예제 #1
0
파일: mailchimp.php 프로젝트: josh73/docker
/**
 * Attempts to signup a user, per the $_POST args.
 * 
 * This sets a global message, that is then used in the widget 
 * output to retrieve and display that message.
 *
 * @return bool
 */
function mailchimpSF_signup_submit()
{
    $mv = get_option('mc_merge_vars', array());
    $mv_tag_keys = array();
    $igs = get_option('mc_interest_groups', array());
    $success = true;
    $listId = get_option('mc_list_id');
    $email = isset($_POST['mc_mv_EMAIL']) ? strip_tags(stripslashes($_POST['mc_mv_EMAIL'])) : '';
    $merge = $errs = array();
    // Set up some vars
    // Loop through our Merge Vars, and if they're empty, but required, then print an error, and mark as failed
    foreach ($mv as $var) {
        $opt = 'mc_mv_' . $var['tag'];
        $opt_val = isset($_POST[$opt]) ? $_POST[$opt] : '';
        if (is_array($opt_val) && isset($opt_val['area'])) {
            $opt_val = implode('-', $opt_val);
        } else {
            if (is_array($opt_val) && $var['field_type'] == 'address') {
                if ($var['req'] == 'Y') {
                    if (empty($opt_val['addr1']) || empty($opt_val['city'])) {
                        $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name']));
                        $success = false;
                    }
                }
                $merge[$var['tag']] = $opt_val;
                continue;
            } else {
                if (is_array($opt_val)) {
                    $opt_val = implode($opt_val);
                }
            }
        }
        if ($var['req'] == 'Y' && trim($opt_val) == '') {
            $success = false;
            $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name']));
        } else {
            if ($var['tag'] != 'EMAIL') {
                $merge[$var['tag']] = $opt_val;
            }
        }
        // We also want to create an array where the keys are the tags for easier validation later
        $mv_tag_keys[$var['tag']] = $var;
    }
    // Head back to the beginning of the merge vars array
    reset($mv);
    // Ensure we have an array
    $igs = !is_array($igs) ? array() : $igs;
    foreach ($igs as $ig) {
        $groups = '';
        if (get_option('mc_show_interest_groups_' . $ig['id']) == 'on') {
            $groupings = array();
            switch ($ig['form_field']) {
                case 'select':
                case 'dropdown':
                case 'radio':
                    if (isset($_POST['group'][$ig['id']])) {
                        $groupings = array('id' => $ig['id'], 'groups' => str_replace(',', '\\,', stripslashes($_POST['group'][$ig['id']])));
                    }
                    break;
                case 'checkboxes':
                case 'checkbox':
                    if (isset($_POST['group'][$ig['id']])) {
                        foreach ($_POST['group'][$ig['id']] as $i => $value) {
                            // Escape
                            $groups .= str_replace(',', '\\,', stripslashes($value)) . ',';
                        }
                        $groupings = array('id' => $ig['id'], 'groups' => $groups);
                    }
                    break;
                default:
                    // Nothing
                    break;
            }
            if (!isset($merge['GROUPINGS']) || !is_array($merge['GROUPINGS'])) {
                $merge['GROUPINGS'] = array();
            }
            if (!empty($groupings)) {
                $merge['GROUPINGS'][] = $groupings;
            }
        }
    }
    // If we're good
    if ($success) {
        // Clear out empty merge vars
        foreach ($merge as $k => $v) {
            if (is_array($v) && empty($v)) {
                unset($merge[$k]);
            } else {
                if (!is_array($v) && trim($v) === '') {
                    unset($merge[$k]);
                }
            }
        }
        // If we have an empty $merge, then assign empty string.
        if (count($merge) == 0 || $merge == '') {
            $merge = '';
        }
        if (isset($_POST['email_type']) && in_array($_POST['email_type'], array('text', 'html', 'mobile'))) {
            $email_type = $_POST['email_type'];
        } else {
            $email_type = 'html';
        }
        // Custom validation based on type
        if (is_array($merge) && !empty($merge)) {
            foreach ($merge as $merge_key => $merge_value) {
                if ($merge_key !== 'GROUPINGS') {
                    switch ($mv_tag_keys[$merge_key]['field_type']) {
                        case 'phone':
                            $phone = $merge_value;
                            if (!empty($phone)) {
                                if (!preg_match('/[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,4}/', $phone)) {
                                    $errs[] = sprintf(__("%s must consist of only numbers", 'mailchimp_i18n'), esc_html($mv_tag_keys[$merge_key]['name']));
                                    $success = false;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        if ($success) {
            $api = new mailchimpSF_MCAPI(get_option('mc_apikey'));
            $retval = $api->listSubscribe($listId, $email, $merge, $email_type);
            if (!$retval) {
                switch ($api->errorCode) {
                    case '105':
                        $errs[] = __("Please try again later", 'mailchimp_i18n') . '.';
                        break;
                    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($mv_tag_keys[$field]['name']));
                        break;
                    case '254':
                        list($i1, $i2, $i3, $field, $rest) = explode(' ', $api->errorMessage, 5);
                        $errs[] = sprintf(__("%s has invalid content.", 'mailchimp_i18n'), esc_html($mv_tag_keys[$field]['name']));
                        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;
            }
        }
    }
    // If we have errors, then show them
    if (count($errs) > 0) {
        $msg = '<span class="mc_error_msg">';
        foreach ($errs as $error) {
            $msg .= '&raquo; ' . esc_html($error) . '<br />';
        }
        $msg .= '</span>';
    } else {
        $msg = "<strong class='mc_success_msg'>" . esc_html(__("Success, you've been signed up! Please look for our confirmation email!", 'mailchimp_i18n')) . "</strong>";
    }
    // Set our global message
    mailchimpSF_global_msg($msg);
    return $success;
}
예제 #2
0
/**
 * Displays a MailChimp Signup Form
 **/
function mailchimpSF_signup_form($args = array())
{
    extract($args);
    $mv = get_option('mc_merge_vars');
    $igs = get_option('mc_interest_groups');
    // See if we have valid Merge Vars
    if (!is_array($mv) && MAILCHIMP_DEV_MODE == false) {
        echo $before_widget;
        ?>
		<div class="mc_error_msg">
			<?php 
        esc_html_e('There was a problem loading your MailChimp details. Please re-run the setup process under Settings->MailChimp Setup', 'mailchimp_i18n');
        ?>
		</div>
		<?php 
        echo $after_widget;
        return;
    }
    if (!is_array($mv) && MAILCHIMP_DEV_MODE == true) {
        $mv = mailchimp_get_kitchen_sink_fields();
        $igs = mailchimp_get_kitchen_sink_groups();
    }
    if (!empty($before_widget)) {
        echo $before_widget;
    }
    $header = get_option('mc_header_content');
    if (!$header && MAILCHIMP_DEV_MODE == true) {
        $header = apply_filters('mailchimp_dev_mode_header_text', 'MailChimp Developer');
    }
    // See if we have custom header content
    if (!empty($header)) {
        // See if we need to wrap the header content in our own div
        if (strlen($header) == strlen(strip_tags($header))) {
            echo !empty($before_title) ? $before_title : '<div class="mc_custom_border_hdr">';
            echo $header;
            // don't escape $header b/c it may have HTML allowed
            echo !empty($after_title) ? $after_title : '</div><!-- /mc_custom_border_hdr -->';
        } else {
            echo $header;
            // don't escape $header b/c it may have HTML allowed
        }
    }
    $sub_heading = trim(get_option('mc_subheader_content'));
    if (!$sub_heading && MAILCHIMP_DEV_MODE == true) {
        $sub_heading = apply_filters('mailchimp_dev_mode_subheading_text', 'This is the subheading text.');
    }
    ?>

<style>
	.widget_mailchimpsf_widget .widget-title {
		line-height: 1.4em;
		margin-bottom: 0.75em;
	}
	#mc_subheader {
		line-height: 1.25em;
		margin-bottom: 18px;
	}
	.mc_merge_var {
		margin-bottom: 1.0em;
	}
	.mc_var_label,
	.mc_interest_label {
		display: block;
		margin-bottom: 0.5em;
	}
	.mc_input {
		-moz-box-sizing: border-box;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		width: 100%;
	}
	.mc_input.mc_phone {
		width: auto;
	}
	select.mc_select {
		margin-top: 0.5em;
		width: 100%;
	}
	.mc_address_label {
		margin-top: 1.0em;
		margin-bottom: 0.5em;
		display: block;
	}
	.mc_address_label ~ select {
		width: 100%;		
	}
	.mc_list li {
		list-style: none;
		background: none !important;
	}
	.mc_interests_header {
		margin-top: 1.0em;
		margin-bottom: 0.5em;
	}
	.mc_interest label,
	.mc_interest input {
		margin-bottom: 0.4em;
	}
	#mc_signup_submit {
		margin-top: 1.5em;
		width: 80%;
	}
	#mc_unsub_link a {
		font-size: 0.75em;
	}
	#mc_unsub_link {
		margin-top: 1.0em;
	}
	.mc_header_address,
	.mc_email_format {
		display: block;
		font-weight: bold;
		margin-top: 1.0em;
		margin-bottom: 0.5em;
	}
	.mc_email_options {
		margin-top: 0.5em;
	}
	.mc_email_type {
		padding-left: 4px;
	}
</style>

<div id="mc_signup">
	<form method="post" action="#mc_signup" id="mc_signup_form">
		<input type="hidden" id="mc_submit_type" name="mc_submit_type" value="html" />
		<input type="hidden" name="mcsf_action" value="mc_submit_signup_form" />
		<?php 
    wp_nonce_field('mc_submit_signup_form', '_mc_submit_signup_form_nonce', false);
    ?>
		
	<?php 
    if ($sub_heading) {
        ?>
		<div id="mc_subheader">
			<?php 
        echo $sub_heading;
        ?>
		</div><!-- /mc_subheader -->
		<?php 
    }
    ?>
	
	<div class="mc_form_inside">
		
		<div class="updated" id="mc_message">
			<?php 
    echo mailchimpSF_global_msg();
    ?>
		</div><!-- /mc_message -->

		<?php 
    //don't show the "required" stuff if there's only 1 field to display.
    $num_fields = 0;
    foreach ((array) $mv as $var) {
        $opt = 'mc_mv_' . $var['tag'];
        if ($var['req'] || get_option($opt) == 'on') {
            $num_fields++;
        }
    }
    if (is_array($mv)) {
        // head on back to the beginning of the array
        reset($mv);
    }
    // Loop over our vars, and output the ones that are set to display
    foreach ($mv as $var) {
        if (!$var['public']) {
            echo '<div style="display:none;">' . mailchimp_form_field($var, $num_fields) . '</div>';
        } else {
            echo mailchimp_form_field($var, $num_fields);
        }
    }
    // Show an explanation of the * if there's more than one field
    if ($num_fields > 1) {
        ?>
			<div id="mc-indicates-required">
				* = <?php 
        esc_html_e('required field', 'mailchimp_i18n');
        ?>
			</div><!-- /mc-indicates-required -->
			<?php 
    }
    // Show our Interest groups fields if we have them, and they're set to on
    if (is_array($igs) && !empty($igs)) {
        foreach ($igs as $ig) {
            if (is_array($ig) && isset($ig['id'])) {
                if ($igs && get_option('mc_show_interest_groups_' . $ig['id']) == 'on' || MAILCHIMP_DEV_MODE == true) {
                    if ($ig['form_field'] != 'hidden') {
                        ?>
				
							<div class="mc_interests_header">
								<?php 
                        echo esc_html($ig['name']);
                        ?>
							</div><!-- /mc_interests_header -->
							<div class="mc_interest">
						<?php 
                    } else {
                        ?>
							<div class="mc_interest" style="display: none;">
						<?php 
                    }
                    ?>
			

					<?php 
                    mailchimp_interest_group_field($ig);
                    ?>
				
					</div><!-- /mc_interest -->
			
					<?php 
                }
            }
        }
    }
    if (get_option('mc_email_type_option') || MAILCHIMP_DEV_MODE == true) {
        ?>
		<div class="mergeRow">
			<label class="mc_email_format"><?php 
        _e('Preferred Format', 'mailchimp_i18n');
        ?>
</label>
		    <div class="field-group groups mc_email_options">
		        <ul class="mc_list">
			        <li><input type="radio" name="email_type" id="email_type_html" value="html" checked="checked"><label for="email_type_html" class="mc_email_type"><?php 
        _e('HTML', 'mailchimp_i18n');
        ?>
</label></li>
			        <li><input type="radio" name="email_type" id="email_type_text" value="text"><label for="email_type_text" class="mc_email_type"><?php 
        _e('Text', 'mailchimp_i18n');
        ?>
</label></li>
		        </ul>
			</div>
		</div>	

		<?php 
    }
    $submit_text = get_option('mc_submit_text');
    if (!$submit_text && MAILCHIMP_DEV_MODE == true) {
        $submit_text = apply_filters('mailchimp_dev_mode_submit_text', 'Subscribe');
    }
    ?>

		<div class="mc_signup_submit">
			<input type="submit" name="mc_signup_submit" id="mc_signup_submit" value="<?php 
    echo esc_attr($submit_text);
    ?>
" class="button" />
		</div><!-- /mc_signup_submit -->
	
	
		<?php 
    $user = get_option('mc_sopresto_user');
    if ($user && get_option('mc_use_unsub_link') == 'on') {
        $dc = get_option('mc_sopresto_dc', 'us1');
        $host = 'http://' . $dc . '.list-manage.com';
        ?>
			<div id="mc_unsub_link" align="center">
				<a href="<?php 
        echo esc_url($host . '/unsubscribe/?u=' . $user['user_id'] . '&amp;id=' . get_option('mc_list_id'));
        ?>
" target="_blank"><?php 
        esc_html_e('unsubscribe from list', 'mailchimp_i18n');
        ?>
</a>
			</div><!-- /mc_unsub_link -->
			<?php 
    }
    if ($user && get_option('mc_rewards') == 'on') {
        ?>
			<br/>
			<div id="mc_display_rewards" align="center">
				<?php 
        esc_html_e('powered by', 'mailchimp_i18n');
        ?>
 <a href="<?php 
        echo esc_url('http://www.mailchimp.com/affiliates/?aid=' . $user['user_id'] . '&amp;afl=1');
        ?>
">MailChimp</a>!
			</div><!-- /mc_display_rewards -->
			<?php 
    }
    ?>
		
	</div><!-- /mc_form_inside -->
	</form><!-- /mc_signup_form -->
</div><!-- /mc_signup_container -->
	<?php 
    if (!empty($after_widget)) {
        echo $after_widget;
    }
}
예제 #3
0
/**
 * Attempts to signup a user, per the $_POST args.
 *
 * This sets a global message, that is then used in the widget
 * output to retrieve and display that message.
 *
 * @return bool
 */
function mailchimpSF_signup_submit()
{
    $mv = get_option('mc_merge_vars', array());
    $mv_tag_keys = array();
    $igs = get_option('mc_interest_groups', array());
    $listId = get_option('mc_list_id');
    $email = isset($_POST['mc_mv_EMAIL']) ? strip_tags(stripslashes($_POST['mc_mv_EMAIL'])) : '';
    $merge = $errs = $html_errs = array();
    // Set up some vars
    $merge = mailchimpSF_merge_submit($mv);
    //Catch errors and fail early.
    if (is_wp_error($merge)) {
        $msg = "<strong class='mc_error_msg'>" . $merge->get_error_message() . "</strong>";
        mailchimpSF_global_msg($msg);
        return false;
    }
    // Head back to the beginning of the merge vars array
    reset($mv);
    // Ensure we have an array
    $igs = !is_array($igs) ? array() : $igs;
    $igs = mailchimpSF_groups_submit($igs);
    // Clear out empty merge vars
    $merge = mailchimpSF_merge_remove_empty($merge);
    if (isset($_POST['email_type']) && in_array($_POST['email_type'], array('text', 'html', 'mobile'))) {
        $email_type = $_POST['email_type'];
    } else {
        $email_type = 'html';
    }
    $api = mailchimpSF_get_api();
    if (!$api) {
        $url = mailchimpSF_signup_form_url();
        $error = '<strong class="mc_error_msg">' . __('We encountered a problem adding ' . $email . ' to the list. Please <a href="' . $url . '">sign up here.</a>') . '</strong>';
        mailchimpSF_global_msg($error);
        return false;
    }
    $url = 'lists/' . $listId . '/members/' . md5(strtolower($email));
    $status = mailchimpSF_check_status($url);
    // If update existing is turned off and the subscriber exists, error out.
    if (get_option('mc_update_existing') == false && $status === 'subscribed') {
        $msg = 'This email address is already subscribed to the list.';
        $error = new WP_Error('mailchimp-update-existing', $msg);
        mailchimpSF_global_msg('<strong class="mc_error_msg">' . $msg . '</strong>');
        return false;
    }
    $body = mailchimpSF_subscribe_body($merge, $igs, $email_type, $email, $status, get_option('mc_double_optin'));
    $retval = $api->post($url, $body, 'PUT');
    // If we have errors, then show them
    if (is_wp_error($retval)) {
        $msg = "<strong class='mc_error_msg'>" . $retval->get_error_message() . "</strong>";
        mailchimpSF_global_msg($msg);
        return false;
    }
    if ($retval['status'] == 'subscribed') {
        $esc = __("Success, you've been signed up.", 'mailchimp_i18n');
        $msg = "<strong class='mc_success_msg'>{$esc}</strong>";
    } else {
        $esc = __("Success, you've been signed up! Please look for our confirmation email.", 'mailchimp_i18n');
        $msg = "<strong class='mc_success_msg'>{$esc}</strong>";
    }
    // Set our global message
    mailchimpSF_global_msg($msg);
    return true;
}
예제 #4
0
        <h2><?php 
esc_html_e('MailChimp List Setup', 'mailchimp_i18n');
?>
 </h2>
    </div>
<?php 
$user = get_option('mc_user');
/* TODO MC SOPRESTO USER INFO */
// If we have an API Key, see if we need to change the lists and its options
mailchimpSF_change_list_if_necessary();
// Display our success/error message(s) if have them
if (mailchimpSF_global_msg() != '') {
    // Message has already been html escaped, so we don't want to 2x escape it here
    ?>
    <div id="mc_message" class=""><?php 
    echo mailchimpSF_global_msg();
    ?>
</div>
    <?php 
}
// If we don't have an API Key, do a login form
if (!$user || !get_option('mc_api_key')) {
    ?>
    <div>
        <h3 class="mc-h2"><?php 
    esc_html_e('Log In', 'mailchimp_i18n');
    ?>
</h3>
        <p class="mc-p" style="width: 40%;line-height: 21px;"><?php 
    echo __('To get started, we’ll need to access your MailChimp account with an <a href="http://kb.mailchimp.com/integrations/api-integrations/about-api-keys">API Key</a>. Paste your MailChimp API key, and click <strong>Connect</strong> to continue.
', 'mailchimp_i18n');
예제 #5
0
/**
 * Displays a MailChimp Signup Form
 * */
function mailchimpSF_signup_form($args = array())
{
    extract($args);
    $mv = get_option('mc_merge_vars');
    $igs = get_option('mc_interest_groups');
    // See if we have valid Merge Vars
    if (!is_array($mv)) {
        echo $before_widget;
        ?>
        <div class="mc_error_msg">
            <?php 
        esc_html_e('There was a problem loading your MailChimp details. Please re-run the setup process under Settings->MailChimp Setup', 'mailchimp_i18n');
        ?>
        </div>
        <?php 
        echo $after_widget;
        return;
    }
    // Get some options
    $uid = get_option('mc_user_id');
    $list_name = get_option('mc_list_name');
    if (!empty($before_widget)) {
        echo $before_widget;
    }
    ?>
    <style type="text/css">
        #join_revolution .main_content .content h1{
    font-family: futurabold;
    font-size: <?php 
    echo $args['headline_font_size'];
    ?>
;
    color: <?php 
    echo $args['headline_font_color'];
    ?>
;
    text-align: left;
    padding-bottom: 0px;
}
    </style>
    <div id="join_revolution">
        <div class="main_content">
            <div class="content">
                <form method="post" action="#mc_signup" id="mc_signup_form">
                    <input type="hidden" id="mc_submit_type" name="mc_submit_type" value="html" />
                    <input type="hidden" name="mcsf_action" value="mc_submit_signup_form" />
                    <?php 
    wp_nonce_field('mc_submit_signup_form', '_mc_submit_signup_form_nonce', false);
    ?>

                    <h1><?php 
    echo $args['headline'];
    ?>
</h1>
                    <p class="content"><?php 
    echo $args['content'];
    ?>
</p>
                    <div class="form">

                        <div class="updated" id="mc_message">
                            <?php 
    echo mailchimpSF_global_msg();
    ?>
                        </div><!-- /mc_message -->

                        <?php 
    //don't show the "required" stuff if there's only 1 field to display.
    $num_fields = 0;
    foreach ((array) $mv as $var) {
        $opt = 'mc_mv_' . $var['tag'];
        if ($var['req'] || get_option($opt) == 'on') {
            $num_fields++;
        }
    }
    if (is_array($mv)) {
        // head on back to the beginning of the array
        reset($mv);
    }
    // Loop over our vars, and output the ones that are set to display
    foreach ($mv as $var) {
        if (!$var['public']) {
            echo '<div style="display:none;">' . mailchimp_form_field($var, $num_fields) . '</div>';
        } else {
            echo mailchimp_form_field($var, $num_fields);
        }
    }
    // Show an explanation of the * if there's more than one field
    if ($num_fields > 1) {
        ?>
                            <div id="mc-indicates-required">
                                * = <?php 
        esc_html_e('required field', 'mailchimp_i18n');
        ?>
                            </div><!-- /mc-indicates-required -->
                            <?php 
    }
    if (is_array($igs) && !empty($igs)) {
        foreach ($igs as $ig) {
            if (is_array($ig) && isset($ig['id'])) {
                if ($igs && get_option('mc_show_interest_groups_' . $ig['id']) == 'on') {
                    if ($ig['form_field'] != 'hidden') {
                        ?>
				

                                            <div class="send_info">
                                                <span class="send_me">send me information about...</span>
                                                <?php 
                        mailchimp_interest_group_field($ig);
                        ?>
                                            </div>
                                            <?php 
                    }
                }
            }
        }
    }
    // Show our Interest groups fields if we have them, and they're set to on
    if (get_option('mc_email_type_option')) {
        ?>
                            <div class="mergeRow">
                                <label><?php 
        _e('Preferred Format', 'mailchimp_i18n');
        ?>
</label>
                                <div class="field-group groups">
                                    <ul class="mc_list">
                                        <li><input type="radio" name="email_type" id="email_type_html" value="html" checked="checked"><label for="email_type_html"><?php 
        _e('HTML', 'mailchimp_i18n');
        ?>
</label></li>
                                        <li><input type="radio" name="email_type" id="email_type_text" value="text"><label for="email_type_text"><?php 
        _e('Text', 'mailchimp_i18n');
        ?>
</label></li>
                                        <li><input type="radio" name="email_type" id="email_type_mobile" value="mobile"><label for="email_type_mobile"><?php 
        _e('Mobile', 'mailchimp_i18n');
        ?>
</label></li>
                                    </ul>
                                </div>
                            </div>	

                            <?php 
    }
    ?>

                        <a href="javascript:void(0)" onclick="jQuery('form#mc_signup_form').submit()">sign up</a>


                        <?php 
    if (get_option('mc_use_unsub_link') == 'on') {
        list($key, $dc) = explode("-", get_option('mc_apikey'), 2);
        if (!$dc) {
            $dc = "us1";
        }
        $host = 'http://' . $dc . '.list-manage.com';
        ?>
                            <div id="mc_unsub_link" align="center">
                                <a href="<?php 
        echo esc_url($host . '/unsubscribe/?u=' . get_option('mc_user_id') . '&amp;id=' . get_option('mc_list_id'));
        ?>
" target="_blank"><?php 
        esc_html_e('unsubscribe from list', 'mailchimp_i18n');
        ?>
</a>
                            </div><!-- /mc_unsub_link -->
                            <?php 
    }
    ?>

                    </div><!-- /mc_form_inside -->
                </form><!-- /mc_signup_form -->
            </div><!-- /mc_signup_container -->
        </div><!-- /mc_signup_container -->
    </div><!-- /mc_signup_container -->
    <div class="clear"></div>
    <?php 
    if (!empty($before_widget)) {
        echo $after_widget;
    }
}
/**
 * Displays a MailChimp Signup Form
 **/
function mailchimpSF_signup_form($args = array())
{
    extract($args);
    $mv = get_option('mc_merge_vars');
    $ig = get_option('mc_interest_groups');
    // See if we have valid Merge Vars
    if (!is_array($mv)) {
        echo $before_widget;
        ?>
		<div class="mc_error_msg">
			<?php 
        esc_html_e('There was a problem loading your MailChimp details. Please re-run the setup process under Settings->MailChimp Setup', 'mailchimp_i18n');
        ?>
		</div>
		<?php 
        echo $after_widget;
        return;
    }
    // Get some options
    $uid = get_option('mc_user_id');
    $list_name = get_option('mc_list_name');
    echo $before_widget;
    $header = get_option('mc_header_content');
    // See if we have custom header content
    if (!empty($header)) {
        // See if we need to wrap the header content in our own div
        if (strlen($header) == strlen(strip_tags($header))) {
            echo $before_title ? $before_title : '<div class="mc_custom_border_hdr">';
            echo $header;
            // don't escape $header b/c it may have HTML allowed
            echo $after_title ? $after_title : '</div><!-- /mc_custom_border_hdr -->';
        } else {
            echo $header;
            // don't escape $header b/c it may have HTML allowed
        }
    }
    $sub_heading = trim(get_option('mc_subheader_content'));
    ?>
	
<div id="mc_signup">
	<form method="post" action="#mc_signup" id="mc_signup_form">
		<input type="hidden" id="mc_submit_type" name="mc_submit_type" value="html" />
		<input type="hidden" name="mcsf_action" value="mc_submit_signup_form" />
		<?php 
    wp_nonce_field('mc_submit_signup_form', '_mc_submit_signup_form_nonce', false);
    ?>
		
	<?php 
    if ($sub_heading) {
        ?>
		<div id="mc_subheader">
			<?php 
        echo $sub_heading;
        ?>
		</div><!-- /mc_subheader -->
		<?php 
    }
    ?>
	
	<div class="mc_form_inside">
		
		<div class="updated" id="mc_message">
			<?php 
    echo mailchimpSF_global_msg();
    ?>
		</div><!-- /mc_message -->

		<?php 
    //don't show the "required" stuff if there's only 1 field to display.
    $num_fields = 0;
    foreach ((array) $mv as $var) {
        $opt = 'mc_mv_' . $var['tag'];
        if ($var['req'] || get_option($opt) == 'on') {
            $num_fields++;
        }
    }
    if (is_array($mv)) {
        // head on back to the beginning of the array
        reset($mv);
    }
    // Loop over our vars, and output the ones that are set to display
    foreach ($mv as $var) {
        $opt = 'mc_mv_' . $var['tag'];
        // See if that var is set as required, or turned on (for display)
        if ($var['req'] || get_option($opt) == 'on') {
            ?>
				<div class="mc_merge_var">
					<label for="<?php 
            echo esc_attr($opt);
            ?>
" class="mc_var_label"><?php 
            echo esc_html($var['name']);
            ?>
				<?php 
            if ($var['req'] && $num_fields > 1) {
                ?>
					<span class="mc_required">*</span>
					<?php 
            }
            ?>
					</label>
					
					<br />
					
					<input type="text" size="18" value="" name="<?php 
            echo esc_attr($opt);
            ?>
" id="<?php 
            echo esc_attr($opt);
            ?>
" class="mc_input"/>
				</div><!-- /mc_merge_var -->
				<?php 
        }
    }
    // Show an explanation of the * if there's more than one field
    if ($num_fields > 1) {
        ?>
			<div id="mc-indicates-required">
				* = <?php 
        esc_html_e('required field', 'mailchimp_i18n');
        ?>
			</div><!-- /mc-indicates-required -->
			<?php 
    }
    // Show our Interest groups fields if we have them, and they're set to on
    if ($ig && get_option('mc_show_interest_groups') == 'on') {
        ?>
			
			<div id="mc_interests_header">
				<?php 
        echo esc_html($ig['name']);
        ?>
			</div><!-- /mc_interests_header -->
			
			<div class="mc_interest">

				<?php 
        $i = 0;
        // Set our counter
        switch ($ig['form_field']) {
            case 'checkbox':
            case 'checkboxes':
                foreach ($ig['groups'] as $interest) {
                    $interest = $interest['name'];
                    ?>
							<input type="checkbox" name="<?php 
                    echo esc_attr('interests[' . $interest . ']');
                    ?>
" id="<?php 
                    echo esc_attr('mc_interest_' . $i);
                    ?>
" class="mc_interest"/>
							<label for="<?php 
                    echo esc_attr('mc_interest_' . $i);
                    ?>
" class="mc_interest_label"> <?php 
                    echo esc_html($interest);
                    ?>
</label>
							<br/>
							<?php 
                    $i++;
                }
                break;
            case 'radio':
                foreach ($ig['groups'] as $interest) {
                    $interest = $interest['name'];
                    ?>
							<input type="radio" name="interests" id="<?php 
                    echo esc_attr('mc_interest_' . $i);
                    ?>
" class="mc_interest" value="<?php 
                    echo esc_attr($interest);
                    ?>
"/>
							<label for="<?php 
                    echo esc_attr('mc_interest_' . $i);
                    ?>
" class="mc_interest_label"> <?php 
                    echo esc_html($interest);
                    ?>
</label>
							<br/>
							<?php 
                    $i++;
                }
                break;
            case 'select':
            case 'dropdown':
                ?>
						<select name="interests">
							<option value=""></option>
							<?php 
                foreach ($ig['groups'] as $interest) {
                    $interest = $interest['name'];
                    ?>
								<option value="<?php 
                    echo esc_attr($interest);
                    ?>
"><?php 
                    echo esc_html($interest);
                    ?>
</option>
								<?php 
                }
                ?>
						</select>
						<?php 
                break;
        }
        ?>
				
			</div><!-- /mc_interest -->
			
			<?php 
    }
    ?>

		<div class="mc_signup_submit">
			<input type="submit" name="mc_signup_submit" id="mc_signup_submit" value="<?php 
    echo esc_attr(get_option('mc_submit_text'));
    ?>
" class="button" />
		</div><!-- /mc_signup_submit -->
	
	
		<?php 
    if (get_option('mc_use_unsub_link') == 'on') {
        list($key, $dc) = explode("-", get_option('mc_apikey'), 2);
        if (!$dc) {
            $dc = "us1";
        }
        $host = 'http://' . $dc . '.list-manage.com';
        ?>
			<div id="mc_unsub_link" align="center">
				<a href="<?php 
        echo esc_url($host . '/unsubscribe/?u=' . get_option('mc_user_id') . '&amp;id=' . get_option('mc_list_id'));
        ?>
" target="_blank"><?php 
        esc_html_e('unsubscribe from list', 'mailchimp_i18n');
        ?>
</a>
			</div><!-- /mc_unsub_link -->
			<?php 
    }
    if (get_option('mc_rewards') == 'on') {
        ?>
			<br/>
			<div id="mc_display_rewards" align="center">
				<?php 
        esc_html_e('powered by', 'mailchimp_i18n');
        ?>
 <a href="<?php 
        echo esc_url('http://www.mailchimp.com/affiliates/?aid=' . get_option('mc_user_id') . '&amp;afl=1');
        ?>
">MailChimp</a>!
			</div><!-- /mc_display_rewards -->
			<?php 
    }
    ?>
	</div><!-- /mc_form_inside -->
	</form><!-- /mc_signup_form -->
</div><!-- /mc_signup_container -->
	<?php 
    echo $after_widget;
}
예제 #7
0
/**
 * Displays a MailChimp Signup Form
 **/
function mailchimpSF_signup_form($args = array())
{
    extract($args);
    $mv = get_option('mc_merge_vars');
    $igs = get_option('mc_interest_groups');
    // See if we have valid Merge Vars
    if (!is_array($mv)) {
        echo $before_widget;
        ?>
		<div class="mc_error_msg">
			<?php 
        esc_html_e('There was a problem loading your MailChimp details. Please re-run the setup process under Settings->MailChimp Setup', 'mailchimp_i18n');
        ?>
		</div>
		<?php 
        echo $after_widget;
        return;
    }
    // Get some options
    $uid = get_option('mc_user_id');
    $list_name = get_option('mc_list_name');
    if (!empty($before_widget)) {
        echo $before_widget;
    }
    $header = get_option('mc_header_content');
    // See if we have custom header content
    if (!empty($header)) {
        // See if we need to wrap the header content in our own div
        if (strlen($header) == strlen(strip_tags($header))) {
            echo !empty($before_title) ? $before_title : '<div class="mc_custom_border_hdr">';
            echo $header;
            // don't escape $header b/c it may have HTML allowed
            echo !empty($after_title) ? $after_title : '</div><!-- /mc_custom_border_hdr -->';
        } else {
            echo $header;
            // don't escape $header b/c it may have HTML allowed
        }
    }
    $sub_heading = trim(get_option('mc_subheader_content'));
    ?>
	
<div id="mc_signup">
	<form method="post" action="#mc_signup" id="mc_signup_form">
		<input type="hidden" id="mc_submit_type" name="mc_submit_type" value="html" />
		<input type="hidden" name="mcsf_action" value="mc_submit_signup_form" />
		<?php 
    wp_nonce_field('mc_submit_signup_form', '_mc_submit_signup_form_nonce', false);
    ?>
		
	<?php 
    if ($sub_heading) {
        ?>
		<div id="mc_subheader">
			<?php 
        echo $sub_heading;
        ?>
		</div><!-- /mc_subheader -->
		<?php 
    }
    ?>
	
	<div class="mc_form_inside">
		
		<div class="updated" id="mc_message">
			<?php 
    echo mailchimpSF_global_msg();
    ?>
		</div><!-- /mc_message -->

		<?php 
    //don't show the "required" stuff if there's only 1 field to display.
    $num_fields = 0;
    foreach ((array) $mv as $var) {
        $opt = 'mc_mv_' . $var['tag'];
        if ($var['req'] || get_option($opt) == 'on') {
            $num_fields++;
        }
    }
    if (is_array($mv)) {
        // head on back to the beginning of the array
        reset($mv);
    }
    // Loop over our vars, and output the ones that are set to display
    foreach ($mv as $var) {
        if (!$var['public']) {
            echo '<div style="display:none;">' . mailchimp_form_field($var, $num_fields) . '</div>';
        } else {
            echo mailchimp_form_field($var, $num_fields);
        }
    }
    // Show an explanation of the * if there's more than one field
    if ($num_fields > 1) {
        ?>
			<div id="mc-indicates-required">
				* = <?php 
        esc_html_e('required field', 'mailchimp_i18n');
        ?>
			</div><!-- /mc-indicates-required -->
			<?php 
    }
    // Show our Interest groups fields if we have them, and they're set to on
    if (is_array($igs) && !empty($igs)) {
        foreach ($igs as $ig) {
            if (is_array($ig) && isset($ig['id'])) {
                if ($igs && get_option('mc_show_interest_groups_' . $ig['id']) == 'on') {
                    if ($ig['form_field'] != 'hidden') {
                        ?>
				
							<div class="mc_interests_header">
								<?php 
                        echo esc_html($ig['name']);
                        ?>
							</div><!-- /mc_interests_header -->
							<div class="mc_interest">
						<?php 
                    } else {
                        ?>
							<div class="mc_interest" style="display: none;">
						<?php 
                    }
                    ?>
			

					<?php 
                    mailchimp_interest_group_field($ig);
                    ?>
				
					</div><!-- /mc_interest -->
			
					<?php 
                }
            }
        }
    }
    if (get_option('mc_email_type_option')) {
        ?>
		<div class="mergeRow">
			<label><?php 
        _e('Preferred Format', 'mailchimp_i18n');
        ?>
</label>
		    <div class="field-group groups">
		        <ul class="mc_list">
			        <li><input type="radio" name="email_type" id="email_type_html" value="html" checked="checked"><label for="email_type_html"><?php 
        _e('HTML', 'mailchimp_i18n');
        ?>
</label></li>
			        <li><input type="radio" name="email_type" id="email_type_text" value="text"><label for="email_type_text"><?php 
        _e('Text', 'mailchimp_i18n');
        ?>
</label></li>
			        <li><input type="radio" name="email_type" id="email_type_mobile" value="mobile"><label for="email_type_mobile"><?php 
        _e('Mobile', 'mailchimp_i18n');
        ?>
</label></li>
		        </ul>
			</div>
		</div>	

		<?php 
    }
    ?>

		<div class="mc_signup_submit">
			<input type="submit" name="mc_signup_submit" id="mc_signup_submit" value="<?php 
    echo esc_attr(get_option('mc_submit_text'));
    ?>
" class="button" />
		</div><!-- /mc_signup_submit -->
	
	
		<?php 
    if (get_option('mc_use_unsub_link') == 'on') {
        list($key, $dc) = explode("-", get_option('mc_apikey'), 2);
        if (!$dc) {
            $dc = "us1";
        }
        $host = 'http://' . $dc . '.list-manage.com';
        ?>
			<div id="mc_unsub_link" align="center">
				<a href="<?php 
        echo esc_url($host . '/unsubscribe/?u=' . get_option('mc_user_id') . '&amp;id=' . get_option('mc_list_id'));
        ?>
" target="_blank"><?php 
        esc_html_e('unsubscribe from list', 'mailchimp_i18n');
        ?>
</a>
			</div><!-- /mc_unsub_link -->
			<?php 
    }
    if (get_option('mc_rewards') == 'on') {
        ?>
			<br/>
			<div id="mc_display_rewards" align="center">
				<?php 
        esc_html_e('powered by', 'mailchimp_i18n');
        ?>
 <a href="<?php 
        echo esc_url('http://www.mailchimp.com/affiliates/?aid=' . get_option('mc_user_id') . '&amp;afl=1');
        ?>
">MailChimp</a>!
			</div><!-- /mc_display_rewards -->
			<?php 
    }
    ?>
		
	</div><!-- /mc_form_inside -->
	</form><!-- /mc_signup_form -->
</div><!-- /mc_signup_container -->
	<?php 
    if (!empty($before_widget)) {
        echo $after_widget;
    }
}
예제 #8
0
/**
 * Attempts to signup a user, per the $_POST args.
 *
 * This sets a global message, that is then used in the widget
 * output to retrieve and display that message.
 *
 * @return bool
 */
function mailchimpSF_signup_submit()
{
    $mv = get_option('mc_merge_vars', array());
    $mv_tag_keys = array();
    $igs = get_option('mc_interest_groups', array());
    $success = true;
    $listId = get_option('mc_list_id');
    $email = isset($_POST['mc_mv_EMAIL']) ? strip_tags(stripslashes($_POST['mc_mv_EMAIL'])) : '';
    $merge = $errs = $html_errs = array();
    // Set up some vars
    // Loop through our Merge Vars, and if they're empty, but required, then print an error, and mark as failed
    foreach ($mv as $var) {
        $opt = 'mc_mv_' . $var['tag'];
        $opt_val = isset($_POST[$opt]) ? $_POST[$opt] : '';
        // WordPress auto adds slashes to everything (in plugins)
        $opt_val = stripslashes_deep($opt_val);
        if (is_array($opt_val) && isset($opt_val['area'])) {
            // This filters out all 'falsey' elements
            $opt_val = array_filter($opt_val);
            // If they weren't all empty
            if ($opt_val) {
                $opt_val = implode('-', $opt_val);
                if (strlen($opt_val) < 12) {
                    $opt_val = '';
                }
            } else {
                $opt_val = '';
            }
        } else {
            if (is_array($opt_val) && $var['field_type'] == 'address') {
                if ($var['req'] == 'Y') {
                    if (empty($opt_val['addr1']) || empty($opt_val['city'])) {
                        $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name']));
                        $success = false;
                    }
                }
                $merge[$var['tag']] = $opt_val;
                continue;
            } else {
                if (is_array($opt_val)) {
                    $opt_val = implode($opt_val);
                }
            }
        }
        if ($var['req'] == 'Y' && trim($opt_val) == '') {
            $success = false;
            $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name']));
        } else {
            if ($var['tag'] != 'EMAIL') {
                $merge[$var['tag']] = $opt_val;
            }
        }
        // We also want to create an array where the keys are the tags for easier validation later
        $mv_tag_keys[$var['tag']] = $var;
    }
    // Head back to the beginning of the merge vars array
    reset($mv);
    // Ensure we have an array
    $igs = !is_array($igs) ? array() : $igs;
    foreach ($igs as $ig) {
        $groups = '';
        if (get_option('mc_show_interest_groups_' . $ig['id']) == 'on') {
            $groupings = array();
            switch ($ig['form_field']) {
                case 'select':
                case 'dropdown':
                case 'radio':
                    if (isset($_POST['group'][$ig['id']])) {
                        $groupings = array('id' => $ig['id'], 'groups' => str_replace(',', '\\,', stripslashes($_POST['group'][$ig['id']])));
                    }
                    break;
                case 'checkboxes':
                case 'checkbox':
                    if (isset($_POST['group'][$ig['id']])) {
                        foreach ($_POST['group'][$ig['id']] as $i => $value) {
                            // Escape
                            $groups .= str_replace(',', '\\,', stripslashes($value)) . ',';
                        }
                        $groupings = array('id' => $ig['id'], 'groups' => $groups);
                    }
                    break;
                default:
                    // Nothing
                    break;
            }
            if (!isset($merge['GROUPINGS']) || !is_array($merge['GROUPINGS'])) {
                $merge['GROUPINGS'] = array();
            }
            if (!empty($groupings)) {
                $merge['GROUPINGS'][] = $groupings;
            }
        }
    }
    // If we're good
    if ($success) {
        // Clear out empty merge vars
        foreach ($merge as $k => $v) {
            if (is_array($v) && empty($v)) {
                unset($merge[$k]);
            } else {
                if (!is_array($v) && trim($v) === '') {
                    unset($merge[$k]);
                }
            }
        }
        // If we have an empty $merge, then assign empty string.
        if (count($merge) == 0 || $merge == '') {
            $merge = '';
        }
        if (isset($_POST['email_type']) && in_array($_POST['email_type'], array('text', 'html', 'mobile'))) {
            $email_type = $_POST['email_type'];
        } else {
            $email_type = 'html';
        }
        // Custom validation based on type
        if (is_array($merge) && !empty($merge)) {
            foreach ($merge as $merge_key => $merge_value) {
                if ($merge_key !== 'GROUPINGS' && isset($mv_tag_keys[$merge_key])) {
                    switch ($mv_tag_keys[$merge_key]['field_type']) {
                        case 'phone':
                            if ($mv_tag_keys[$merge_key]['phoneformat'] == 'US') {
                                $phone = $merge_value;
                                if (!empty($phone)) {
                                    if (!preg_match('/[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,4}/', $phone)) {
                                        $errs[] = sprintf(__("%s must consist of only numbers", 'mailchimp_i18n'), esc_html($mv_tag_keys[$merge_key]['name']));
                                        $success = false;
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        if ($success) {
            $api = mailchimpSF_get_api();
            if (!$api) {
                return;
            }
            $retval = $api->listSubscribe($listId, $email, $merge, $email_type);
            if (!$retval) {
                switch ($api->errorCode) {
                    case '105':
                        $errs[] = __("Please try again later", 'mailchimp_i18n') . '.';
                        break;
                    case '214':
                        $msg = __("That email address is already subscribed to the list", 'mailchimp_i18n') . '.';
                        $account = $api->getAccountDetails(array("modules", "orders", "rewards-credits", "rewards-inspections", "rewards-referrals", "rewards-applied"));
                        if (!$api->errorCode) {
                            $dc = get_option('mc_sopresto_dc');
                            $uid = $account['user_id'];
                            $username = preg_replace('/\\s+/', '-', $account['username']);
                            $eid = base64_encode($email);
                            $msg .= ' ' . sprintf(__('<a href="%s">Click here to update your profile.</a>', 'mailchimp_i18n'), "http://{$dc}.list-manage.com/subscribe/send-email?u={$uid}&id={$listId}&e={$eid}");
                        }
                        $errs[] = $msg;
                        $html_errs[] = count($errs) - 1;
                        break;
                    case '250':
                        list($field, $rest) = explode(' ', $api->errorMessage, 2);
                        $errs[] = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($mv_tag_keys[$field]['name']));
                        break;
                    case '254':
                        list($i1, $i2, $i3, $field, $rest) = explode(' ', $api->errorMessage, 5);
                        $errs[] = sprintf(__("%s has invalid content.", 'mailchimp_i18n'), esc_html($mv_tag_keys[$field]['name']));
                        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;
            }
        }
    }
    // If we have errors, then show them
    if (count($errs) > 0) {
        $msg = '<span class="mc_error_msg">';
        foreach ($errs as $error_index => $error) {
            if (!in_array($error_index, $html_errs)) {
                $error = esc_html($error);
            }
            $msg .= '&raquo; ' . $error . '<br />';
        }
        $msg .= '</span>';
    } else {
        $msg = "<strong class='mc_success_msg'>" . esc_html(__("Success, you've been signed up! Please look for our confirmation email!", 'mailchimp_i18n')) . "</strong>";
    }
    // Set our global message
    mailchimpSF_global_msg($msg);
    return $success;
}