Example #1
0
function invite_anyone_process_invitations($data)
{
    global $bp;
    $emails = false;
    // Parse out the individual email addresses
    if (!empty($data['invite_anyone_email_addresses'])) {
        $emails = invite_anyone_parse_addresses($data['invite_anyone_email_addresses']);
    }
    // Filter the email addresses so that plugins can have a field day
    $emails = apply_filters('invite_anyone_submitted_email_addresses', $emails, $data);
    // Set up a wrapper for any data to return to the Send Invites screen in case of error
    $returned_data = array('error_message' => false, 'error_emails' => array(), 'subject' => $data['invite_anyone_custom_subject'], 'message' => $data['invite_anyone_custom_message'], 'groups' => isset($data['invite_anyone_groups']) ? $data['invite_anyone_groups'] : '');
    // Check against the max number of invites. Send back right away if there are too many
    $options = invite_anyone_options();
    $max_invites = !empty($options['max_invites']) ? $options['max_invites'] : 5;
    if (count($emails) > $max_invites) {
        $returned_data['error_message'] = sprintf(__('You are only allowed to invite up to %s people at a time. Please remove some addresses and try again', 'invite-anyone'), $max_invites);
        $returned_data['error_emails'] = $emails;
        setcookie('invite-anyone', serialize($returned_data), 0, '/');
        $redirect = bp_loggedin_user_domain() . $bp->invite_anyone->slug . '/invite-new-members/';
        bp_core_redirect($redirect);
        die;
    }
    if (empty($emails)) {
        bp_core_add_message(__('You didn\'t include any email addresses!', 'invite-anyone'), 'error');
        bp_core_redirect($bp->loggedin_user->domain . $bp->invite_anyone->slug . '/invite-new-members');
        die;
    }
    // Max number of invites sent
    $limit_total_invites = !empty($options['email_limit_invites_toggle']) && 'no' != $options['email_limit_invites_toggle'];
    if ($limit_total_invites && !current_user_can('delete_others_pages')) {
        $sent_invites = invite_anyone_get_invitations_by_inviter_id(bp_loggedin_user_id());
        $sent_invites_count = (int) $sent_invites->post_count;
        $remaining_invites_count = (int) $options['limit_invites_per_user'] - $sent_invites_count;
        if (count($emails) > $remaining_invites_count) {
            $returned_data['error_message'] = sprintf(__('You are only allowed to invite %s more people. Please remove some addresses and try again', 'invite-anyone'), $remaining_invites_count);
            $returned_data['error_emails'] = $emails;
            setcookie('invite-anyone', serialize($returned_data), 0, '/');
            $redirect = bp_loggedin_user_domain() . $bp->invite_anyone->slug . '/invite-new-members/';
            bp_core_redirect($redirect);
            die;
        }
    }
    // Turn the CS emails into an array so that they can be matched against the main list
    if (isset($_POST['cloudsponge-emails'])) {
        $cs_emails = explode(',', $_POST['cloudsponge-emails']);
    }
    // validate email addresses
    foreach ($emails as $key => $email) {
        $check = invite_anyone_validate_email($email);
        switch ($check) {
            case 'opt_out':
                $returned_data['error_message'] .= sprintf(__('<strong>%s</strong> has opted out of email invitations from this site.', 'invite-anyone'), $email);
                break;
            case 'used':
                $returned_data['error_message'] .= sprintf(__("<strong>%s</strong> is already a registered user of the site.", 'invite-anyone'), $email);
                break;
            case 'unsafe':
                $returned_data['error_message'] .= sprintf(__('<strong>%s</strong> is not a permitted email address.', 'invite-anyone'), $email);
                break;
            case 'invalid':
                $returned_data['error_message'] .= sprintf(__('<strong>%s</strong> is not a valid email address. Please make sure that you have typed it correctly.', 'invite-anyone'), $email);
                break;
            case 'limited_domain':
                $returned_data['error_message'] .= sprintf(__('<strong>%s</strong> is not a permitted email address. Please make sure that you have typed the domain name correctly.', 'invite-anyone'), $email);
                break;
        }
        // If there was an error in validation, we won't process this email
        if ($check != 'okay') {
            $returned_data['error_message'] .= '<br />';
            $returned_data['error_emails'][] = $email;
            unset($emails[$key]);
        }
    }
    if (!empty($emails)) {
        unset($message, $to);
        /* send and record invitations */
        do_action('invite_anyone_process_addl_fields');
        $groups = !empty($data['invite_anyone_groups']) ? $data['invite_anyone_groups'] : array();
        $is_error = 0;
        foreach ($emails as $email) {
            $subject = stripslashes(strip_tags($data['invite_anyone_custom_subject']));
            $message = stripslashes(strip_tags($data['invite_anyone_custom_message']));
            $footer = invite_anyone_process_footer($email);
            $footer = invite_anyone_wildcard_replace($footer, $email);
            $message .= '

================
';
            $message .= $footer;
            $to = apply_filters('invite_anyone_invitee_email', $email);
            $subject = apply_filters('invite_anyone_invitation_subject', $subject);
            $message = apply_filters('invite_anyone_invitation_message', $message);
            wp_mail($to, $subject, $message);
            /* todo: isolate which email(s) cause problems, and send back to user */
            /*	if ( !invite_anyone_send_invitation( $bp->loggedin_user->id, $email, $message, $groups ) )
            			$is_error = 1; */
            // Determine whether this address came from CloudSponge
            $is_cloudsponge = isset($cs_emails) && in_array($email, $cs_emails) ? true : false;
            invite_anyone_record_invitation($bp->loggedin_user->id, $email, $message, $groups, $subject, $is_cloudsponge);
            do_action('sent_email_invite', $bp->loggedin_user->id, $email, $groups);
            unset($message, $to);
        }
        // Set a success message
        $success_message = sprintf(__("Invitations were sent successfully to the following email addresses: %s", 'invite-anyone'), implode(", ", $emails));
        bp_core_add_message($success_message);
        do_action('sent_email_invites', $bp->loggedin_user->id, $emails, $groups);
    } else {
        $success_message = sprintf(__("Please correct your errors and resubmit.", 'invite-anyone'));
        bp_core_add_message($success_message, 'error');
    }
    // If there are errors, redirect to the Invite New Members page
    if (!empty($returned_data['error_emails'])) {
        setcookie('invite-anyone', serialize($returned_data), 0, '/');
        $redirect = bp_loggedin_user_domain() . $bp->invite_anyone->slug . '/invite-new-members/';
        bp_core_redirect($redirect);
        die;
    }
    return true;
}
Example #2
0
function invite_anyone_settings_addl_invitation_message()
{
    ?>
	<textarea name='invite_anyone[addl_invitation_message]' cols=60 rows=5 ><?php 
    echo invite_anyone_process_footer('[email]');
    ?>
</textarea>
<?php 
}
Example #3
0
function invite_anyone_settings_addl_invitation_message()
{
    echo apply_filters('invite_anyone_settings_addl_invitation_message', "<textarea name='invite_anyone[addl_invitation_message]' cols=60 rows=5 >" . esc_html(invite_anyone_process_footer('[email]')) . "</textarea>");
}
Example #4
0
function invite_anyone_process_invitations($data)
{
    global $bp;
    $emails = array();
    if (is_array($data['invite_anyone_email'])) {
        foreach ($data['invite_anyone_email'] as $email) {
            if ($email != '') {
                $emails[] = trim($email);
            }
        }
    }
    if (empty($emails)) {
        bp_core_add_message(__('You didn\'t include any email addresses!', 'bp-invite-anyone'), 'error');
        bp_core_redirect($bp->loggedin_user->domain . $bp->invite_anyone->slug . '/invite-new-members');
    }
    /* validate email addresses */
    foreach ($emails as $email) {
        $check = invite_anyone_validate_email($email);
        switch ($check) {
            case 'opt_out':
                $error_message = sprintf(__('Sorry, %s has opted out of email invitations from this site.', 'bp-invite-anyone'), $email);
                $is_error = 1;
                break;
            case 'used':
                $error_message = sprintf(__('Sorry, %s is already a registered user of the site. ', 'bp-invite-anyone'), $email);
                $is_error = 1;
                break;
            case 'unsafe':
                $error_message = sprintf(__('Sorry, %s is not a permitted email address.', 'bp-invite-anyone'), $email);
                $is_error = 1;
                break;
            case 'invalid':
                $error_message = sprintf(__('Sorry, %s is not a valid email address. Please make sure that you have typed it correctly.', 'bp-invite-anyone'), $email);
                $is_error = 1;
                break;
            case 'limited_domain':
                $error_message = sprintf(__('Sorry, %s is not a permitted email address. Please make sure that you have typed the domain name correctly.', 'bp-invite-anyone'), $email);
                $is_error = 1;
                break;
        }
        if ($is_error) {
            $error_message .= " " . __('Please remove the email address and try again.', 'bp-invite-anyone');
            bp_core_add_message($error_message, 'error');
            $d = '';
            if ($emails) {
                foreach ($emails as $key => $email) {
                    $d .= "email{$key}=" . urlencode($email) . '&';
                }
            }
            if ($data['invite_anyone_groups']) {
                foreach ($data['invite_anyone_groups'] as $key => $group) {
                    $d .= "group{$key}=" . $group . '&';
                }
            }
            if ($data['invite_anyone_custom_subject']) {
                $d .= 'subject=' . urlencode(stripslashes($data['invite_anyone_custom_subject'])) . '&';
            }
            if ($data['invite_anyone_custom_message']) {
                $d .= 'message=' . urlencode(stripslashes($data['invite_anyone_custom_message']));
            }
            bp_core_redirect($bp->loggedin_user->domain . $bp->invite_anyone->slug . '/invite-new-members?' . $d);
        }
    }
    /* send and record invitations */
    do_action('invite_anyone_process_addl_fields');
    $groups = $data['invite_anyone_groups'];
    $is_error = 0;
    foreach ($emails as $email) {
        $subject = stripslashes(strip_tags($data['invite_anyone_custom_subject']));
        $message = stripslashes(strip_tags($data['invite_anyone_custom_message']));
        $footer = invite_anyone_process_footer($email);
        $footer = invite_anyone_wildcard_replace($footer, $email);
        $message .= '

================
';
        $message .= $footer;
        $to = apply_filters('invite_anyone_invitee_email', $email);
        $subject = apply_filters('invite_anyone_invitation_subject', $subject);
        $message = apply_filters('invite_anyone_invitation_message', $message, $accept_link);
        wp_mail($to, $subject, $message);
        /* todo: isolate which email(s) cause problems, and send back to user */
        /*	if ( !invite_anyone_send_invitation( $bp->loggedin_user->id, $email, $message, $groups ) )
        			$is_error = 1; */
        invite_anyone_record_invitation($bp->loggedin_user->id, $email, $message, $groups);
        do_action('sent_email_invite', $bp->loggedin_user->id, $email, $groups);
        unset($message, $to);
    }
    do_action('sent_email_invites', $bp->loggedin_user->id, $emails, $groups);
    return true;
}