Пример #1
0
 /**
  * Generates a random password
  * Sends the pasword to a user's email
  *
  * @param obj $user
  * @param str $email
  * @return bool
  */
 private function new_password($user, $email)
 {
     $raw = Str::random(8);
     $user->password = Hash::make($raw);
     $user->save();
     $html = "Your new password: " . $raw;
     return Mailer::send($email, 'Title', $html);
 }
Пример #2
0
/**
 * Catch mentions in saved activity items
 *
 * @since 1.5.0
 *
 * @param obj $activity
 *
 * @uses remove_filter() To remove the 'bp_activity_at_name_filter_updates' hook.
 * @uses bp_activity_at_name_filter()
 * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
 */
function bp_activity_at_name_filter_updates($activity)
{
    // Only run this function once for a given activity item
    remove_filter('bp_activity_after_save', 'bp_activity_at_name_filter_updates');
    // Run the content through the linking filter, making sure to increment mention count
    $activity->content = bp_activity_at_name_filter($activity->content, $activity->id);
    // Resave the activity with the new content
    $activity->save();
}
/**
 * Reassign member's pack to a specified pack[as per pack setting: move_members_pack value](issue#: 535)
 * This will be invoked in Expiry/User initiated Cancellation
 *
 * @param int $user_id
 * @param obj $member
 * @param string $type
 * @param boolean $return
 * @return obj depending on $return value
 */
function mgm_reassign_member_subscription($user_id, $member, $type, $return = true)
{
    if (isset($member->pack_id) && is_numeric($member->pack_id)) {
        $obj_pack = mgm_get_class('subscription_packs');
        $prev_pack = $obj_pack->get_pack($member->pack_id);
        //if move_members_pack (id) is set:
        if (isset($prev_pack['move_members_pack']) && is_numeric($prev_pack['move_members_pack'])) {
            $system_obj = mgm_get_class('system');
            $current_time = time();
            $subs_pack = $obj_pack->get_pack($prev_pack['move_members_pack']);
            //assign new pack:
            // if trial on
            $member->trial_on = $subs_pack['trial_on'] ? $subs_pack['trial_on'] : 0;
            $member->trial_cost = $subs_pack['trial_on'] ? $subs_pack['trial_cost'] : 0;
            $member->trial_duration = $subs_pack['trial_on'] ? $subs_pack['trial_duration'] : 0;
            $member->trial_duration_type = $subs_pack['trial_on'] ? $subs_pack['trial_duration_type'] : 'd';
            $member->trial_num_cycles = $subs_pack['trial_on'] ? $subs_pack['trial_num_cycles'] : 0;
            // duration
            $member->duration = $subs_pack['duration'];
            $member->duration_type = strtolower($subs_pack['duration_type']);
            $member->amount = $subs_pack['cost'];
            //issue #1602
            if (!isset($subs_pack['currency']) || empty($subs_pack['currency'])) {
                $currency = $system_obj->setting['currency'];
            } else {
                $currency = $subs_pack['currency'];
            }
            if (!isset($member->currency)) {
                $member->currency = $currency;
            }
            $member->membership_type = $subs_pack['membership_type'];
            //set new pack id
            $member->pack_id = $subs_pack['id'];
            $member->active_num_cycles = $subs_pack['num_cycles'];
            $member->payment_type = (int) $subs_pack['num_cycles'] == 1 ? 'one-time' : 'subscription';
            //reset joining date as current time
            $member->join_date = $current_time;
            // duration_exprs
            $duration_exprs = mgm_get_class('subscription_packs')->get_duration_exprs();
            // check
            if (in_array($member->duration_type, array_keys($duration_exprs))) {
                // take only date exprs
                // time
                $time = strtotime("+{$member->duration} {$duration_exprs[$member->duration_type]}", $current_time);
                // formatted
                $time_str = date('Y-m-d', $time);
                $member->expire_date = $time_str;
            } else {
                $member->expire_date = '';
            }
            // set last pay
            $member->last_pay_date = date('Y-m-d', $current_time);
            //reset as active
            $member->status = MGM_STATUS_ACTIVE;
            $member->status_str = sprintf('%s (%s)', $member->status_str, sprintf(__('Reassigned new pack on [%s]', 'mgm'), $type));
            //unset vars:
            if (isset($member->rebilled)) {
                unset($member->rebilled);
            }
            // payment info for unsubscribe
            if (isset($member->payment_info)) {
                unset($member->payment_info);
            }
            //unset transaction id - let's keep the old for ref.
            //if(isset($member->transaction_id)) unset($member->transaction_id);
            //add new role/remove old role
            if ($prev_pack['role'] != $subs_pack['role']) {
                $obj_role = mgm_get_class('roles');
                $obj_role->add_user_role($user_id, $subs_pack['role'], true, false);
                //remove user role:
                $obj_role->remove_userrole($user_id, $prev_pack['role']);
            }
            //done
        }
    }
    if ($return) {
        return $member;
    } else {
        $member->save();
    }
}