Example #1
0
function mbudm_format_value($val, $with_currency = false)
{
    $csymbol = mbudm_get_option(THEMEPREFIX . "_currency_symbol");
    $cpos = mbudm_get_option(THEMEPREFIX . "_currency_symbol_position");
    $cs = $cpos == "before" ? $csymbol : '';
    $ca = $cpos == "after" ? $csymbol : '';
    $dsep = mbudm_get_option(THEMEPREFIX . "_decimal_separator");
    $tsep = mbudm_get_option(THEMEPREFIX . "_thousand_separator");
    $cflag = $with_currency ? '<span class="currency-flag" >' . mbudm_get_option(THEMEPREFIX . "_currency") . '</span>' : '';
    return $cs . number_format($val, 2, $dsep, $tsep) . $ca . $cflag;
}
Example #2
0
    /**
     * How to display the widget on the screen.
     */
    function widget($args, $instance)
    {
        extract($args);
        /* Our variables from the widget settings. */
        $signup_title = apply_filters('widget_title', $instance['signup_title']);
        $signup_message = $instance['signup_message'];
        $signup_btn_label = $instance['signup_btn_label'];
        $signup_thankyou_message = $instance['signup_thankyou_message'];
        $unsubscribe_title = $instance['unsubscribe_title'];
        $unsubscribe_message = $instance['unsubscribe_message'];
        $unsubscribe_thankyou_message = $instance['unsubscribe_thankyou_message'];
        $unsubscribe_btn_label = $instance['unsubscribe_btn_label'];
        $email_label = $instance['email_label'];
        $name_label = $instance['name_label'];
        /* Before widget (defined by themes). */
        echo $before_widget;
        /* handle any form submits */
        if (isset($_POST['mbudm_mailing_list_signup']) || isset($_POST['mbudm_mailing_list_unsubscribe']) || isset($_POST['mbudm_mailing_list_manage'])) {
            $ml_errors = array();
            $ml_alerts = array();
            // check email and username vars
            if (isset($_POST['useremail'])) {
                // does user exist for this email?
                $post_email = strip_tags($_POST['useremail']);
                $post_email_valid = filter_var($post_email, FILTER_VALIDATE_EMAIL);
                if ($post_email_valid) {
                    // is email subscribed?
                    $email_user_id = email_exists($post_email);
                    $is_email_signedup = get_user_meta($email_user_id, MBUDM_UMK_MAILING_LIST, true);
                }
            }
            if (isset($_POST['username'])) {
                $post_name = strip_tags($_POST['username']);
                $post_name_valid = !empty($post_name);
            }
            if (isset($_POST['mbudm_mailing_list_signup']) && !$is_email_signedup) {
                if ($post_email_valid) {
                    $message = "Thanks for signing up to the Linguaposta mailing list. To confirm your subscription click on this link:\r\n";
                    // add user if doesn't exist
                    if (!$email_user_id) {
                        //create account and log them in
                        $random_password = wp_generate_password(12, false);
                        $creds = array();
                        $creds['user_login'] = $post_email;
                        $creds['user_password'] = $random_password;
                        $creds['remember'] = true;
                        $signup_user = wp_signon($creds, false);
                        if (is_wp_error($signup_user)) {
                            echo $signup_user->get_error_message();
                        }
                        $signup_user_id = $signup_user->ID;
                        $message .= "To cancel your subscription just log in to our memeber area. Here are your new login details that we have created for you:\r\nUser name: " . $creds['user_login'] . "\r\n Password: "******"\r\n";
                    } else {
                        $signup_user_id = $email_user_id;
                        $message .= "You have an account with us already but since you were not logged in, we ask that you confirm your email address before we add you to out list.\r\n";
                    }
                    // set mailing list status for user to pending
                    update_user_meta($signup_user_id, MBUDM_UMK_MAILING_LIST, MBUDM_MAILING_LIST_PENDING);
                    // send confirmation email
                    $subject = __("Confirm your Linguaposta mailing list subscription", TEMPLATE_DOMAIN);
                    $headers = 'From: ' . mbudm_get_option(THEMEPREFIX . "_mail_name") . ' <' . mbudm_get_option(THEMEPREFIX . "_mail_address") . '>' . "\r\n";
                    wp_mail($post_email, $subject, $message, $headers);
                    /* replace any instances of #name# or #email# with the form values */
                    $ml_alerts[] = str_replace(array('#name#', '#email#'), array($post_name, $post_email), $signup_thankyou_message);
                } else {
                    //invalid email
                    $ml_errors[] = __("That email doesn't look valid", TEMPLATE_DOMAIN);
                }
            }
            if (isset($_POST['mbudm_mailing_list_unsubscribe'])) {
                if ($post_email_valid) {
                    if ($is_email_signedup) {
                        // is email  subscribed? remove subscription
                        update_user_meta($email_user_id, MBUDM_UMK_MAILING_LIST, MBUDM_MAILING_LIST_UNSUBSCRIBED);
                        /* replace any instances of #name# or #email# with the form values */
                        $ml_alerts[] = str_replace('#email#', $post_email, $unsubscribe_thankyou_message);
                    }
                } else {
                    //invalid email
                    $ml_errors[] = __("That email doesn't look valid", TEMPLATE_DOMAIN);
                }
            }
        }
        // end  handlers for any form submits
        // is logged in and signed up to the mailing list?
        if (is_user_logged_in()) {
            global $current_user;
            get_currentuserinfo();
            $is_signedup = get_user_meta($current_user->ID, MBUDM_UMK_MAILING_LIST, true);
            if (isset($_POST['mbudm_mailing_list_manage'])) {
                if ($is_signedup == MBUDM_MAILING_LIST_SUBSCRIBED) {
                    // is user subscribed? remove subscription
                    update_user_meta($current_user->ID, MBUDM_UMK_MAILING_LIST, MBUDM_MAILING_LIST_UNSUBSCRIBED, $is_signedup);
                } else {
                    // user unsubscribed? add subscription
                    update_user_meta($current_user->ID, MBUDM_UMK_MAILING_LIST, MBUDM_MAILING_LIST_SUBSCRIBED, $is_signedup);
                }
                $is_signedup = get_user_meta($current_user->ID, MBUDM_UMK_MAILING_LIST, true);
            }
            $user_manage_title = $is_signedup == MBUDM_MAILING_LIST_SUBSCRIBED ? $unsubscribe_title : $signup_title;
            $user_manage_message = $is_signedup == MBUDM_MAILING_LIST_SUBSCRIBED ? $unsubscribe_message : $signup_message;
            $btn_label = $is_signedup == MBUDM_MAILING_LIST_SUBSCRIBED ? $unsubscribe_btn_label : $signup_btn_label;
        }
        //format error/alert strings
        $ml_alerts_msg = '';
        $ml_errors_msg = '';
        if (!empty($ml_alerts)) {
            $ml_alerts_msg = '<div class="alerts" >';
            foreach ($ml_alerts as $ml_alert) {
                $ml_alerts_msg .= '<p>' . $ml_alert . '</p>';
            }
            $ml_alerts_msg .= '</div>';
        }
        if (!empty($ml_errors)) {
            $ml_errors_msg = '<div class="errors" >';
            foreach ($ml_errors as $ml_error) {
                $ml_errors_msg .= '<p>' . $ml_error . '</p>';
            }
            $ml_errors_msg .= '</div>';
        }
        $submit_url = $_SERVER['REQUEST_URI'];
        /* print out forms */
        if (is_user_logged_in()) {
            $submit_class = $is_signedup ? 'info-btn' : 'submit-btn';
            ?>
		<h2><?php 
            echo $user_manage_title;
            ?>
</h2>
		<form action='<?php 
            echo $submit_url;
            ?>
' METHOD='POST' id="mailinglist-usermanage">
				<p><?php 
            echo $user_manage_message;
            ?>
</p>
				<?php 
            echo $ml_alerts_msg;
            ?>
				<?php 
            echo $ml_errors_msg;
            ?>
				<ul>
					<li>
						<input type="submit" class="btn <?php 
            echo $submit_class;
            ?>
" value="<?php 
            echo $btn_label;
            ?>
" />
						<input type="hidden" name="mbudm_mailing_list_manage" value="1"/>
					</li>
				</ul>
			</form>
		<?php 
        } else {
            ?>
			<h2><?php 
            echo $signup_title;
            ?>
</h2>
			<form action='<?php 
            echo $submit_url;
            ?>
' METHOD='POST' id="mailinglist">
				<p><?php 
            echo $signup_message;
            ?>
</p>
				<?php 
            echo $ml_alerts_msg;
            ?>
				<?php 
            echo $ml_errors_msg;
            ?>
				<ul>
					<li>
						<label for="mailinglist-username" ><?php 
            echo $name_label;
            ?>
</label>
						<input type="text" id="mailinglist-username" name="username" value="" placeholder="<?php 
            echo $name_label;
            ?>
" />
					</li>
					<li>
						<label for="mailinglist-useremail" ><?php 
            echo $email_label;
            ?>
</label>
						<input type="text" id="mailinglist-useremail" name="useremail" value="" placeholder = "<?php 
            echo $email_label;
            ?>
" />				
					</li>
					<li>
						<input type="submit" class="btn submit-btn" value="<?php 
            echo $signup_btn_label;
            ?>
" />
						<input type="hidden" name="mbudm_mailing_list_signup" value="1"/>
					</li>
				</ul>
			</form>
			<form action='<?php 
            echo $submit_url;
            ?>
' METHOD='POST' id="mailinglist-unsubscribe" class="minimisable">
				<h3><?php 
            echo $unsubscribe_title;
            ?>
</h3>
				<p><?php 
            echo $unsubscribe_message;
            ?>
</p>
				<ul>
					<li>
						<label for="mailinglist-unsubscribe-useremail" ><?php 
            echo $email_label;
            ?>
</label>
						<input type="text" id="mailinglist-unsubscribe-useremail" name="useremail" value="" placeholder = "<?php 
            echo $email_label;
            ?>
" />				
					</li>
					<li>
						<input type="submit" class="btn info-btn" value="<?php 
            echo $unsubscribe_btn_label;
            ?>
" />
						<input type="hidden" name="mbudm_mailing_list_unsubscribe" value="1"/>
					</li>
				</ul>
			</form>
		<?php 
        }
        /* After widget (defined by themes). */
        echo $after_widget;
    }