예제 #1
0
function M_Communication_process()
{
    // This function checks for any communication messages that need to be sent for this user and sends them
    $lastatid = M_get_option('membership_communication_last_user_processed', 0);
    if (empty($lastatid)) {
        $lastatid = 0;
    }
    $members = M_Communication_get_members($lastatid);
    if (empty($members)) {
        // do nothing
        if ($lastatid != 0) {
            M_update_option('membership_communication_last_user_processed', 0);
        }
    } else {
        // Our starting time
        $timestart = current_time('timestamp');
        //Or processing limit
        $timelimit = 3;
        // max seconds for processing
        foreach ((array) $members as $user_id) {
            // Makes sure that messages only takes 3 seconds of processing power. Prevents timeouts.
            if (current_time('timestamp') > $timestart + $timelimit) {
                M_update_option('membership_communication_last_user_processed', $user_id);
                break;
            }
            if (apply_filters('membership_prevent_communication', get_user_meta($user_id, 'membership_signup_gateway_can_communicate', true)) != 'yes') {
                $starts = M_Communication_get_startstamps($user_id);
                $comms = M_Communication_get_post_messages();
                if (!empty($starts) && !empty($comms)) {
                    foreach ($starts as $start) {
                        $starttime = $start->meta_value;
                        $now = current_time('timestamp');
                        $sub_id = str_replace('start_current_', '', $start->meta_key);
                        $sentalready = get_user_meta($user_id, 'sent_msgs_' . $sub_id, true);
                        if (empty($sentalready) || !is_array($sentalready)) {
                            $sentalready = array();
                        }
                        foreach ((array) $comms as $comm) {
                            if (in_array($comm->id, $sentalready) || $comm->sub_id != $sub_id && $comm->sub_id > 0) {
                                continue;
                            }
                            $withperiod = $starttime + $comm->periodstamp;
                            // Get 24 hour previous and after so we have a range in which to fit a communication
                            $onedaybefore = strtotime('-6 hours', $withperiod);
                            $onedayafter = strtotime('+6 hours', $withperiod);
                            if ($now > $onedaybefore && $now < $onedayafter) {
                                $message = new M_Communication($comm->id);
                                $sentalready[$comm->id] = $comm->id;
                                $message->send_message($user_id, $sub_id);
                                break;
                            }
                        }
                        update_user_meta($user_id, 'sent_msgs_' . $sub_id, $sentalready);
                    }
                }
                $ends = M_Communication_get_endstamps($user_id);
                $comms = M_Communication_get_pre_messages();
                if (!empty($ends) && !empty($comms)) {
                    foreach ($ends as $end) {
                        $endtime = $end->meta_value;
                        $now = current_time('timestamp');
                        $sub_id = str_replace('expire_current_', '', $end->meta_key);
                        $sentalready = get_user_meta($user_id, 'sent_msgs_' . $sub_id, true);
                        if (empty($sentalready) || !is_array($sentalready)) {
                            $sentalready = array();
                        }
                        foreach ((array) $comms as $comm) {
                            if (in_array($comm->id, $sentalready) || $comm->sub_id != $sub_id && $comm->sub_id > 0) {
                                continue;
                            }
                            $withperiod = $endtime + $comm->periodstamp;
                            // Get 24 hour previous and after so we have a range in which to fit a communication
                            $onedaybefore = strtotime('-6 hours', $withperiod);
                            $onedayafter = strtotime('+6 hours', $withperiod);
                            if ($now > $onedaybefore && $now < $onedayafter) {
                                $message = new M_Communication($comm->id);
                                $sentalready[$comm->id] = $comm->id;
                                $message->send_message($user_id, $sub_id);
                                break;
                            }
                        }
                        update_user_meta($user_id, 'sent_msgs_' . $sub_id, $sentalready);
                    }
                }
            }
        }
        M_update_option('membership_communication_last_user_processed', $user_id);
    }
}
예제 #2
0
function M_AddSimpleInviteFieldProcess($error)
{
    $Msi_options = M_get_option('membership_simpleinvite_options', array());
    if (empty($Msi_options['inviterequired']) || $Msi_options['inviterequired'] != 'yes') {
        return $error;
    }
    $thekey = $_POST['invitecode'];
    if (empty($thekey)) {
        if (empty($error->errors)) {
            $error = new WP_Error();
        }
        $error->add('enterinvitecode', __('You need to enter an invite code in order to register.', 'membership'));
    } else {
        $codes = explode("\n", $Msi_options['invitecodes']);
        $codes = array_map('trim', $codes);
        if (!in_array($thekey, $codes)) {
            if (empty($error->errors)) {
                $error = new WP_Error();
            }
            $error->add('incorrectinvitecode', __('Sorry, but we do not seem to have that code on file, please try another.', 'membership'));
        } else {
            if (empty($error->errors)) {
                if ($Msi_options['inviteremove'] == 'yes') {
                    $key = array_search($thekey, $codes);
                    if ($key !== false) {
                        unset($codes[$key]);
                        $Msi_options['invitecodes'] = implode("\n", $codes);
                        M_update_option('membership_simpleinvite_options', $Msi_options);
                    }
                }
            }
        }
    }
    return $error;
}
예제 #3
0
function M_RemoveSimpleInviteCode()
{
    $Msi_options = M_get_option('membership_simpleinvite_options', array());
    if (!isset($Msi_options['inviteremove']) || !filter_var($Msi_options['inviteremove'], FILTER_VALIDATE_BOOLEAN) || !isset($Msi_options['invitecodes'])) {
        return;
    }
    $thekey = filter_input(INPUT_POST, 'invitecode');
    $codes = array_map('trim', explode(PHP_EOL, $Msi_options['invitecodes']));
    $key = array_search($thekey, $codes);
    if ($key !== false) {
        unset($codes[$key]);
        $Msi_options['invitecodes'] = implode(PHP_EOL, $codes);
        M_update_option('membership_simpleinvite_options', $Msi_options);
    }
}