/**
Functions
*/
function ym_group_apply_package($pack_id, $user_id = FALSE)
{
    $vars_to_apply = array('role', 'account_type', 'hide_old_content', 'child_accounts_allowed', 'child_accounts_package_types', 'child_accounts_packages', 'hide_admin_bar');
    $pack = ym_get_pack_by_id($pack_id);
    foreach ($vars_to_apply as $value) {
        $vars_to_apply[$value] = $pack[$value];
    }
    if ($user_id) {
        $ym_user = new YourMember_User($user_id);
    } else {
        global $ym_user;
    }
    $ym_user->update($vars_to_apply);
    $ym_user->save();
    @ym_log_transaction(YM_PACKAGE_PURCHASED, $pack_id, $user_id);
    return;
}
function ym_import_users_from_csv()
{
    if (ym_post('ym_start_import')) {
        if ($_FILES['upload']['error'] != 4) {
            $time = time();
            // since we don't need to keep the file, may as well leave it in tmp!
            $file = $_FILES['upload']['tmp_name'];
            $data_check = TRUE;
            $data_valid = FALSE;
            $import_array = array();
            $headers = array();
            $row = 0;
            if (($handle = fopen($file, "r")) !== FALSE) {
                $data_valid = TRUE;
                while (($data = fgetcsv($handle)) !== FALSE) {
                    if ($data_check) {
                        $headers = $data;
                        $data_check = FALSE;
                    } else {
                        foreach ($data as $index => $item) {
                            $import_array[$row][$headers[$index]] = $item;
                        }
                        $row++;
                    }
                }
            }
            if (!$data_valid) {
                echo '<div id="message" class="error"><p>' . __('Not a Valid CSV File I can handle', 'ym') . '</p></div>';
                return;
            } else {
                $total_success = 0;
                $total_fail = 0;
                $messages = '';
                // user add loop
                foreach ($import_array as $index => $record) {
                    $user = new YourMember_User();
                    // pass it to the pre built create function
                    // no password is exported by the export function
                    $smflag = FALSE;
                    if ($record['smflag']) {
                        $smflag = $record['smflag'];
                    }
                    $package = array();
                    $pack_id = '';
                    if (!$record['pack_id'] || !$record['package_id']) {
                        $package = array('account_type' => $record['account_type'], 'duration' => $record['duration'], 'duration_type' => $record['duration_type']);
                        if ($record['expire_date']) {
                            $package['expire_date'] = $record['expire_date'];
                        }
                    } else {
                        if ($record['pack_id']) {
                            $pack_id = $record['pack_id'];
                        }
                        if ($record['package_id']) {
                            $pack_id = $record['package_id'];
                        }
                    }
                    $password = false;
                    if ($record['password'] || $record['ym_password']) {
                        if ($record['password']) {
                            $password = $record['password'];
                        }
                        if ($record['ym_password']) {
                            $password = $record['password'];
                        }
                    }
                    $expire_date = false;
                    if ($record['expire_date']) {
                        $expire_date = $record['expire_date'];
                    }
                    //Setting package expiry date outside of the package
                    /*
                     * must be true
                     * export does not export the password
                     * so a new one must be generated and sent to the user
                     */
                    // custom fields will ignore stuff that doens't match
                    // run it
                    if ($record['user_email']) {
                        $result = $user->create($record['user_email'], $record['pack_id'], $smflag, $record['user_login'], $password, $record, $package, $expire_date);
                        if (is_wp_error($result)) {
                            $total_fail++;
                            $messages .= $index . '-' . $record['user_login'] . ': ' . $result->get_error_message() . '<br />';
                        } else {
                            $total_success++;
                        }
                    } else {
                        $total_fail++;
                        $messages .= 'No Email address for user, skipping user <br />';
                    }
                    unset($user);
                }
                @ym_log_transaction(11, date(YM_DATE, $time) . ' User import began. added: ' . $total_success . ', failed to add: ' . $total_fail, get_current_user_id());
                echo '<div id="message" class="updated"><p><strong>' . date(YM_DATE, $time) . ' User import began. added: ' . $total_success . ', failed to add: ' . $total_fail . '</strong></p></div>';
                if ($messages) {
                    echo '<div id="message" class="error"><p>' . $messages . '</p></div>';
                }
            }
            // clean up
            unlink($file);
            return;
        }
    }
}
Beispiel #3
0
 function webhook($post)
 {
     if ($post['data']['list_id'] == $this->options->list) {
         // list id matches
         $email = $post['data']['email'];
         //$action = $post['type'];
         $user = get_user_by_email($email);
         $user_id = $user->ID;
         if (!$user_id) {
             // unable to ID
             exit;
         }
         // actions
         // subscribe unsubscribe profile cleaned upemail
         $task = $this->options->unsub_action;
         switch ($task) {
             case 'disable':
                 // disblae the account
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, 'Inactive', $user_id);
                 update_user_option($user_id, 'ym_status', 'Inactive', true);
                 break;
             case 'flag':
                 // mail admin
                 $sys = get_option('ym_sys');
                 $from_email = $sys->from_email != '' ? $sys->from_email : get_option('admin_email');
                 @wp_mail($from_email, __('YM MailManager: User Unsubcribed MailChimp'), 'The User ' . $email . ' User ID: ' . $user_id . ' has unsubscribed from MailChimp');
                 break;
             case 'nothing':
             default:
                 break;
         }
         // complete
         echo 'OK';
         exit;
     }
 }
 public function task($offset = 0)
 {
     global $ym_sys;
     if (!$ym_sys->email_reminder_enable) {
         echo 'Not Enabled in YM SYS';
         return;
     }
     $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : $offset;
     if (is_null($offset)) {
         $offset = 0;
     }
     if ($offset == -1) {
         // no pagination
         $offset = 0;
         $this->limit = null;
     }
     $this->limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : $this->limit;
     // use API Exposed Element for search
     $users = get_users(array('offset' => $offset, 'number' => $this->limit, 'meta_key' => 'ym_status', 'meta_value' => YM_STATUS_EXPIRED, 'meta_compare' => '!='));
     $current_time = time();
     // set to now + days so a future
     $limit_date = time() + $ym_sys->email_reminder_limit * 86400;
     $postarray = array();
     //Drip Feed Email
     if ($ym_sys->email_drip_reminder_enable) {
         global $wpdb;
         //Get all posts
         $args = array('meta_key' => '_ym_account_min_duration', 'post_status' => 'publish');
         $posts = get_posts($args);
         foreach ($posts as $post) {
             $drip = get_post_meta($post->ID, '_ym_account_min_duration', true);
             $new_array = array();
             if ($drip) {
                 $drip = explode(';', $drip);
                 if ($drip) {
                     foreach ($drip as $d) {
                         $array = explode('=', $d);
                         $new_array[$array[0]] = $array[1];
                     }
                 }
             }
             $postarray[$post->ID] = array_filter($new_array);
         }
         $postarray = array_filter($postarray);
     }
     $total = count($users);
     if ($total) {
         $counter = 0;
         foreach ($users as $user) {
             $counter++;
             $user = new YourMember_User($user->ID);
             $expire_date = $user->expire_date;
             // user has expire date
             // user has not been sent a reminder
             // expire_date is less that the limit date
             // expire date is in the future
             if ($user->expire_date && !$user->reminder_email_sent && $user->expire_date < $limit_date && $user->expire_date > $current_time) {
                 // lock
                 $user->update(array('reminder_email_sent' => true), true);
                 // send
                 $subject = $ym_sys->email_reminder_subject;
                 $message = $ym_sys->email_reminder_message;
                 $pack = ym_get_pack_by_id($user->pack_id);
                 if ($pack['num_cycles'] != 1) {
                     // so 0 or many ie recurring
                     $subject = $ym_sys->email_reminder_subject_recur;
                     $message = $ym_sys->email_reminder_message_recur;
                 }
                 $subject = str_replace('[site_name]', get_bloginfo(), $subject);
                 $message = ym_apply_filter_the_content($message);
                 ym_email($user->data->user_email, $subject, $message);
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Email Reminder Sent', 'ym'), $user->ID);
                 do_action('ym_cron_email_reminder_sent', $user->ID);
                 echo '1';
             } else {
                 echo '.';
             }
             if (substr($counter, -1, 1) == '0') {
                 echo ' ' . $counter . '/' . $total . "\n";
             }
             $reminders = array();
             foreach ($postarray as $post => $type) {
                 foreach ($type as $ac_type => $days) {
                     if ($ac_type == $act) {
                         $reminders[$post] = array('post_id' => $post, 'days' => $days);
                     }
                 }
             }
             if ($reminders) {
                 $users_reminders = unserialize(get_user_meta($user->ID, 'drip_email_reminders', true));
                 if (!$users_reminders || !is_array($users_reminders)) {
                     $users_reminders = array();
                 }
                 foreach ($reminders as $reminder) {
                     if (!in_array($reminder['post_id'], $users_reminders)) {
                         //The post ID is not marked as already sent so we may need to send it
                         //need to determine if we should send it.
                         $reg = $user->data->user_registered;
                         if ($sys->post_delay_start == 'pack_join') {
                             if ($pack_join = $user->account_type_join_date) {
                                 $reg = date('Y-m-d', $pack_join);
                             }
                         }
                         $reg = mktime(0, 0, 0, substr($reg, 5, 2), substr($reg, 8, 2), substr($reg, 0, 4));
                         $user_at = $reg + 86400 * $reminder['days'];
                         if ($user_at <= time() && $user_at >= time() - 86400 * 7) {
                             //If the time is not in the future, and no older then 10 days, we should send an email
                             //send email
                             $subject = $ym_sys->email_drip_subject;
                             $message = $ym_sys->email_drip_message;
                             $subject = str_replace('[site_name]', get_bloginfo(), $subject);
                             $message = ym_apply_filter_the_content($message);
                             ym_email($target, $subject, $message);
                             $users_reminders[] = $reminder['post_id'];
                             @ym_log_transaction(USER_STATUS_UPDATE, __('Drip Content Email for post' . $reminder['post_id'], 'ym'), $user->ID);
                             do_action('ym_cron_email_drip_sent', $user->ID, $reminder['post_id']);
                         }
                     }
                 }
                 update_user_meta($user->ID, 'drip_email_reminders', serialize($users_reminders));
             }
         }
         echo ' ' . $counter . '/' . $total . "\n";
         // loop
         echo 'Loop Complete From ' . $offset . "\n";
         if ($this->call_type == 'auto') {
             if ($this->limit != NULL) {
                 echo 'Schedule Next Step' . "\n";
                 wp_schedule_single_event(time(), 'ym_cron_email_reminder', array($offset + $this->limit));
             } else {
                 echo 'Full Call Occured' . "\n";
             }
         } else {
             // reload
             echo 'Sleeping' . "\n";
             echo '<form action="" method="post"><input type="hidden" name="run_cron_job" value="ym_cron_email_reminder" /><input type="hidden" name="offset" value="' . ($offset + $this->limit) . '" /></form>';
             echo '<script type="text/javascript">jQuery(document).ready(function() { setTimeout(\'ym_fire()\', 5000) }); function ym_fire() { jQuery(\'form\').submit(); }</script>';
         }
     } else {
         echo 'Nothing to do Job Complete' . "\n";
         do_action('ym_cron_email_reminder_complete');
     }
 }
Beispiel #5
0
 function ym10_legacy($failed, $item_field, $cost_field, $complete, $exit)
 {
     // catch a YM 10 packet, customs only come with YM10
     if (isset($_POST['custom']) && $_POST['custom']) {
         $id = FALSE;
         list($duration, $amount, $currency, $user_id, $account_type, $duration_type, $role, $client_ip, $hide_old_content) = explode('_', $_POST['custom']);
         global $ym_packs;
         foreach ($ym_packs->packs as $pack) {
             if ((md5($pack['account_type']) == strtolower($account_type) || md5(strtolower($pack['account_type'])) == strtolower($account_type)) && ($pack['cost'] == $amount || number_format($pack['cost'], 2) == number_format($amount, 2)) && $pack['duration'] == $duration && strtolower($pack['duration_type']) == strtolower($duration_type)) {
                 $id = $pack['id'];
                 break;
             }
         }
     }
     if ($id && $user_id) {
         //run the code to process a new/extended membership
         $cost = ym_post('amount', ym_post('mc_gross'));
         @ym_log_transaction(YM_PAYMENT, $cost, $user_id);
         $this->do_buy_subscription($id, $user_id, $complete);
         $failed = FALSE;
     } else {
         $failed = TRUE;
         $admin = get_userdata(1);
         $admin_email = $admin->user_email;
         ym_email($admin_email, 'YM 10 Packet failed', 'Could not determine what the user is buying after looping thru all packets Debug: <pre>' . print_r($_POST, TRUE)) . "\n\n\n" . print_r($ym_packs, TRUE) . '</pre>';
     }
     return $failed;
 }
Beispiel #6
0
    function ym_profile_unsubscribe_button($return = FALSE, $text = '', $button = '')
    {
        if (!$this->api_user || !$this->api_pass) {
            return '';
        }
        // last invoice ID
        global $ym_user;
        $last_invoice_id = get_user_meta($ym_user->ID, 'ym_2_checkout_invoice_id', TRUE);
        if (!$last_invoice_id) {
            // no recurrring
            return '';
        }
        if (ym_post('2checkout_cancel')) {
            $data = array('invoice_id' => $last_invoice_id);
            $result = $this->curl_it('detail_sale', $data);
            if ($lineitem_id = $result->sale->invoices[0]->lineitems[0]->lineitem_id) {
                $data = array('lineitem_id' => $lineitem_id);
                $result = $this->curl_it('stop_lineitem_recurring', $data, 'POST');
                // done
                $html = '<div style="margin-bottom: 10px;">
					<h4>' . __('2Checkout Unsubscribe', 'ym') . '</h4>
					<div style="margin-bottom: 10px;">';
                if ($result->response_code == 'OK') {
                    $html .= '<p>' . __('You have unsubscribed successfully and your Recurring subscription has been Cancelled', 'ym') . '</p>';
                    // fire expire
                    // set time to now
                    $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_CANCEL);
                    $ym_user->update($data);
                    $ym_user->save();
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID);
                } else {
                    $html .= '<p>' . sprintf(__('An error occured unsubscribing you: %s', 'ym'), $result->error[0]->message) . '</p>';
                }
            } else {
                $html .= '<p>' . sprintf(__('An error occured unsubscribing you: %s', 'ym'), $result->errors[0]->message) . '</p>';
            }
            $html .= '</div></div>';
        } else {
            $text = $text ? $text : __('If you wish to unsubscribe you can click the following link.', 'ym');
            $button = $button ? $button : __('Cancel Subscription', 'ym');
            $html = '<div style="margin-bottom: 10px;">
				<h4>' . __('2Checkout Unsubscribe', 'ym') . '</h4>
				<div style="margin-bottom: 10px;">' . $text . '</div>
				<div>
					<form action="" method="post">
						<input type="submit" name="2checkout_cancel" value="' . $button . '" class="button-secondary" />
					</form>
				</div>
			</div>';
        }
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
Beispiel #7
0
 function expire_interrupt($data, $ymuser)
 {
     // interrupt and send to grace?
     // this is fired the moment they expire (ish)
     global $ym_sys;
     if (!$ym_sys->grace_enable) {
         // grace not on
         return $data;
     }
     // instantiate
     $invoice = new ym_invoice();
     if ($ymuser->gateway_used != $invoice->code) {
         return $data;
     }
     // check package
     $package = ym_get_pack_by_id($ymuser->pack_id);
     if ($package->num_cycles == 1) {
         // single occurance
         return $data;
     }
     // lets put them into grace
     $data = array('status' => YM_STATUS_GRACE, 'status_str' => __('User is entering Invoice Grace', 'ym'), 'expire_date' => time() + 86400 * $invoice->invoice_limit);
     @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expire_date'], $ymuser->userId);
     @ym_log_transaction(YM_USER_STATUS_UPDATE, YM_STATUS_GRACE, $ymuser->userId);
     // trigger invoice email
     $this->generate_invoice($ymuser, $invoice);
     // notify admin
     if ($invoice->notify_admin_on_grace) {
         $email = get_bloginfo('admin_email');
         $subject = '[' . get_bloginfo() . '] ' . __('Invoice notification', 'ym');
         $message = __('The user ' . $ymuser->data->user_login . ' is entering Invoice Grace and has been sent a invoice', 'ym');
         ym_email($email, $subject, $message);
     }
     return $data;
 }
function ym_group_membership_create_child($email_address, $username, $password, $c_password, $sub_id, $package_type = false, $message = FALSE, $parent_id = FALSE)
{
    if ($parent_id) {
        $ym_user = new YourMember_User($parent_id);
    } else {
        global $ym_user;
    }
    $current_counts = ym_group_membership_get_counts($ym_user);
    if (count($ym_user->child_ids) >= $ym_user->child_accounts_allowed) {
        if ($message) {
            ym_display_message(__('You are out of Child Accounts', 'ym'), 'error');
        }
        return FALSE;
    } else {
        if ($email_address && is_email($email_address)) {
            if (!empty($password) && $password != $c_password) {
                ym_display_message(__('Passwords do not match', 'ym'), 'error');
            }
            if ($sub_id) {
                if (!in_array($sub_id, $ym_user->child_accounts_packages)) {
                    if ($message) {
                        ym_display_message(__('You do not have access to this pacakge', 'ym'), 'error');
                    }
                    return FALSE;
                }
                $pack = ym_get_pack_by_id($sub_id);
            } else {
                if ($package_type) {
                    $pack = array();
                    $pack['account_type'] = $package_type;
                } else {
                    // inherit mode
                    $pack = array();
                    $pack['account_type'] = $ym_user->account_type;
                }
            }
            $inherit = true;
            foreach ($ym_user->child_accounts_package_types as $type => $type_count) {
                if ($type_count) {
                    $inherit = false;
                }
            }
            //			if ($inherit) {
            //				$pack['account_type'] = '';
            //			}
            if ($pack['account_type'] && $ym_user->child_accounts_package_types[$pack['account_type']] > $current_counts[$pack['account_type']] || $inherit && $ym_user->child_accounts_allowed > count($ym_user->child_ids)) {
                $new_user = new YourMember_User();
                $result = $new_user->create($email_address, $sub_id, FALSE, $username, $password);
                if (is_wp_error($result)) {
                    ym_display_message($result->get_error_message(), 'error');
                } else {
                    // apply child
                    $data = array('parent_id' => $ym_user->ID, 'account_type' => $pack['account_type'], 'status_str' => __('Child Account', 'ym'));
                    if (!$sub_id) {
                        // the child has inherited they won't have a role!
                        $new_user->updaterole('subscriber');
                    }
                    $new_user->update($data);
                    $new_user->save();
                    unset($new_user);
                    //garbage collect
                    $child_ids = $ym_user->child_ids;
                    $child_ids[] = $result;
                    $ym_user->update(array('child_ids' => $child_ids));
                    $ym_user->save();
                    @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, __('Child', 'ym') . ' ' . $data['account_type'], $result);
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, YM_STATUS_ACTIVE . ' - ' . $data['status_str'], $result);
                    // all done
                    if ($message) {
                        ym_display_message(__('Child User was created successfully', 'ym'));
                    }
                    return TRUE;
                }
            } else {
                if ($message) {
                    ym_display_message(__('Total for this package type has been reached', 'ym'), 'error');
                }
                return FALSE;
            }
        } else {
            if ($message) {
                ym_display_message(__('The Email Address was Blank or Invalid', 'ym'), 'error');
            }
            return FALSE;
        }
    }
}
function ym_firesale_tier_log($tier_id)
{
    @ym_log_transaction(YM_APP_TIERCHANGE, $tier_id, 1);
}
 function do_buy_subscription($subId, $userId, $complete = FALSE)
 {
     global $ym_sys;
     // assumes complete
     @ym_log_transaction(YM_IPN, $_REQUEST, $userId);
     if ($complete) {
         @ym_log_transaction(YM_PACKAGE_PURCHASED, $subId, $userId);
         $pack = ym_get_pack_by_id($subId);
         if (!$pack) {
             // unknown pack
             $complete = 'FALSE';
         } else {
             $user = new YourMember_User($userId);
             // get current
             $current = $user->pack_id;
             $extend = FALSE;
             // extend
             // ONLY extend if same package type (ie better pack for the same type)
             //   SO different Pack IDs
             // - like a switch from a monthly sub to a yearly sub
             // and current status is active
             // if been set inactivate then new sub
             if ($user->account_type == $pack['account_type'] && $user->pack_id != $subId && ($user->status == YM_STATUS_ACTIVE || $user->status == YM_STATUS_GRACE)) {
                 $extend = $user->expire_date;
             }
             // check for pack ID's the same
             // and extend allow
             // make sure expire date in the future
             if ($user->pack_id == $subId && $ym_sys->allow_upgrade_to_same && $user->expire_date > time()) {
                 $extend = $user->expire_date;
             }
             // patch :-P
             $pack['amount'] = $pack['cost'];
             // use magic
             // use an array so can pass to update
             // other wise direct calls to object....
             $data = array();
             // this is crap
             // TODO: takes the whole pack and stores it in the user object.....
             foreach ($user as $key => $value) {
                 if (isset($pack[$key])) {
                     $data[$key] = $pack[$key];
                 }
             }
             // end crap
             // additonal
             $data['pack_id'] = $subId;
             $data['status'] = YM_STATUS_ACTIVE;
             $data['reminder_email_sent'] = FALSE;
             if ($this->code == 'ym_gift') {
                 $data['status_str'] = __('Gift Giving was Successful', 'ym');
             } else {
                 if ($this->code == 'ym_dropdown') {
                     $data['status_str'] = __('DropDown was Successful', 'ym');
                 } else {
                     if ($extend) {
                         $data['status_str'] = __('Subscription Extension Successful', 'ym');
                     } else {
                         $data['status_str'] = __('Last payment was successful', 'ym');
                     }
                 }
             }
             $data['account_type'] = ucwords($pack['account_type']);
             $data['reminder_email_sent'] = FALSE;
             $data['gateway_used'] = $this->code;
             if (!$extend) {
                 $data['account_type_join_date'] = time();
             }
             $data['last_pay_date'] = time();
             // log
             @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $data['account_type'], $userId);
             @ym_log_transaction(YM_USER_STATUS_UPDATE, YM_STATUS_ACTIVE . ' - ' . $data['status_str'], $userId);
             // apply trial?
             $apply = FALSE;
             // if trial enabled and user not taken
             if ($pack['trial_on'] && $user->trial_taken != $subId) {
                 // trial not taken yet then apply trial
                 // does the Gateway Used Support a Trial?
                 if (method_exists($this, 'enable_trial')) {
                     $apply = TRUE;
                 }
             }
             if ($apply) {
                 $data['trial_on'] = TRUE;
                 $data['expire_date'] = $user->expiry_time($data['trial_duration'], $data['trial_duration_type']);
                 $data['trial_taken'] = $subId;
             } else {
                 $data['trial_on'] = FALSE;
                 // most important
                 $data['expire_date'] = $user->expiry_time($data['duration'], $data['duration_type'], $extend);
             }
             @ym_log_transaction(YM_ACCESS_EXTENSION, $data['expire_date'], $userId);
             // check for force end
             if (isset($pack['force_end_date'])) {
                 $force_end_date = $pack['force_end_date'];
                 if ($force_end_date > time()) {
                     // greater than now
                     @ym_log_transaction(YM_ACCESS_EXTENSION, 'Adjustment (Force End Date): ' . $force_end_date, $userId);
                     $data['expire_date'] = $force_end_date;
                 }
             }
             // group membership
             $data['child_accounts_allowed'] = $pack['child_accounts_allowed'];
             $data['child_accounts_package_types'] = $pack['child_accounts_package_types'];
             $data['child_accounts_packages'] = $pack['child_accounts_packages'];
             // admin bar control
             $data['hide_admin_bar'] = $pack['hide_admin_bar'];
             $user->update($data);
             $user->save();
             $user->updaterole($pack['role']);
         }
     }
     if (!$complete) {
         $data = array('new_status' => FALSE);
         if (method_exists($this, 'fail_process')) {
             $data = $this->fail_process();
         } else {
             $new_status = YM_STATUS_ERROR;
             $status_str = sprintf(__('Last Payment Errored and No Handler Found for the Payment Gateway Response', 'ym'));
             $data = array('new_status' => $new_status, 'status_str' => $status_str);
         }
         if (isset($data['new_status']) && $data['new_status']) {
             @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['new_status'] . ' - ' . $data['status_str'], $userId);
             if (isset($data['expiry']) && $data['expiry']) {
                 @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expiry'], $userId);
             }
             $data['status'] = $data['new_status'];
             unset($data['new_status']);
             $user = new YourMember_User($userId);
             $user->update($data);
             $user->save();
         }
     }
     $packet = array('user_id' => $userId, 'pack_id' => $subId, 'status' => $complete);
     if ($complete) {
         do_action('ym_membership_transaction_success', $packet);
         do_action('ym_membership_transaction_success_' . $this->code, $packet);
     } else {
         do_action('ym_membership_transaction_failed', $packet);
         do_action('ym_membership_transaction_failed_' . $this->code, $packet);
     }
     do_action('ym_gateway_return', $packet);
     do_action('ym_gateway_return_' . $this->code, $packet);
     $this->notify_user($packet);
 }
Beispiel #11
0
    function ym_profile_unsubscribe_button($return = FALSE, $text = '', $button = '')
    {
        if (!$this->remotePW || !$this->iadmin_inst_id) {
            return;
        }
        global $ym_user;
        $id = get_user_meta($ym_user->ID, 'ym_worldpay_futurepay_id', TRUE);
        if (!$id) {
            return;
        }
        $text = $text ? $text : __('If you wish to unsubscribe you can click the following link.', 'ym');
        $button = $button ? $button : __('Cancel Subscription', 'ym');
        if (ym_post('worldpay_cancel')) {
            $fields = array('instId' => $this->iadmin_inst_id, 'authPW' => $this->remotePW, 'futurePayId' => $id, 'op-cancelFP' => 1, 'cancel' => 1);
            $url = 'https://secure';
            if ($this->status == 'test') {
                $url .= '-test';
            }
            $url .= '.wp3.rbsworldpay.com/wcc/iadmin';
            // request
            $request = new WP_Http();
            $result = $request->request($url, array('method' => 'POST', 'body' => $fields));
            $html = '<div style="margin-bottom: 10px;">
				<h4>' . __('WorldPay Unsubscribe', 'ym') . '</h4>
				<div style="margin-bottom: 10px;">';
            if ($result['body'] == 'Y,Agreement cancelled') {
                $html .= '<p>' . __('You have unsubscribed successfully and Future Payments have been Cancelled', 'ym') . '</p>';
                // fire expire
                // set time to now
                $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_CANCEL);
                $ym_user->update($data);
                // do expire check (for drop down)
                $ym_user->expire_check();
                $ym_user->save();
                @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID);
            } else {
                $html .= '<p>' . sprintf(__('An error occured unsubscribing you: %s', 'ym'), $result['body']) . '</p>';
            }
            $html .= '</div></div>';
        } else {
            $html = '<div style="margin-bottom: 10px;">
				<h4>' . __('WorldPay Unsubscribe', 'ym') . '</h4>
				<div style="margin-bottom: 10px;">' . $text . '</div>
				<div>
					<form action="" method="post">
						<input type="submit" name="worldpay_cancel" value="' . $button . '" class="button-secondary" />
					</form>
				</div>
			</div>';
        }
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
Beispiel #12
0
    function do_process()
    {
        // IPN Handler
        $eventType = ym_request('eventType');
        $acc_num = ym_request('clientAccnum');
        $sub_num = ym_request('clientSubacc');
        if (!$eventType) {
            header('HTTP/1.1 403 Forbidden');
            echo 'Error in IPN. No Idea what the hell your trying to do';
            exit;
        }
        if ($acc_num != $this->clientAccnum || $sub_num != $this->clientSubacc) {
            header('HTTP/1.1 403 Forbidden');
            echo 'Error in IPN. Client Account Numbers';
            exit;
        }
        global $wpdb;
        $subscriptionId = ym_post('subscriptionId');
        switch ($eventType) {
            case 'NewSaleSuccess':
            case 'NewSaleFailure':
                $digest = ym_post('dynamicPricingValidationDigest', false);
                // got something to validate?
                if (ym_post('failureCode')) {
                    // failed
                    $validate = md5(ym_post('subscriptionId') . 0 . $this->md5salt);
                    $complete = false;
                } else {
                    // complete
                    $validate = md5(ym_post('subscriptionId') . 1 . $this->md5salt);
                    $complete = true;
                }
                // validate
                if ($digest != $validate) {
                    header('HTTP/1.1 403 Forbidden');
                    echo 'Error in IPN. Bad Digest';
                    exit;
                }
                // initial purchase
                list($buy, $what, $id, $user_id) = explode('_', ym_post('X-custom'));
                update_user_meta($user_id, 'ym_ccbill_subscription_id', ym_post('subscriptionId'));
                $this->common_process(ym_post('X-custom'), ym_post('billedInitialPrice'), $complete);
                break;
            case 'Cancellation':
                // cancellation
                // load user by sub id
                $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . '
				WHERE meta_key = \'ym_ccbill_subscription_id\'
				AND meta_value = \'' . $subscriptionId . '\'');
                if ($user_id) {
                    $ym_user = new YourMember_User($user_id);
                    $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_CANCEL, 'status_str' => ym_post('reason'));
                    $ym_user->update($data);
                    // do expire check (for drop down)
                    $ym_user->expire_check();
                    $ym_user->save();
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID);
                } else {
                    // ought to error but the ccbill does nothing with the response
                    @ym_log_transaction(YM_IPN, $_REQUEST, 0);
                }
                break;
            case 'RenewalSuccess':
                // success renewal
                // load user by sub id
                $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . '
				WHERE meta_key = \'ym_ccbill_subscription_id\'
				AND meta_value = \'' . $subscriptionId . '\'');
                if ($user_id) {
                    $pack = new YourMember_User($user_id);
                    $code = 'buy_subscription_' . $pack->pack_id . '_' . $user_id;
                    $this->common_process($code, ym_post('billedRecurringPrice'), true);
                } else {
                    // ought to error but the ccbill does nothing with the response
                    @ym_log_transaction(YM_IPN, $_REQUEST, 0);
                }
                break;
            case 'RenewalFailure':
                // fail renewal
                $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . '
				WHERE meta_key = \'ym_ccbill_subscription_id\'
				AND meta_value = \'' . $subscriptionId . '\'');
                if ($user_id) {
                    $ym_user = new YourMember_User($user_id);
                    $data = array('expire_date' => time() - 1, 'status' => YM_STATUS_ERROR, 'status_str' => ym_post('failureReason'));
                    $ym_user->update($data);
                    // do expire check (for drop down)
                    $ym_user->expire_check();
                    $ym_user->save();
                    @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'] . ' - ' . $data['status_str'] . ' - ' . __('User Unsubscribe', 'ym'), $ym_user->ID);
                } else {
                    // ought to error but the ccbill does nothing with the response
                    @ym_log_transaction(YM_IPN, $_REQUEST, 0);
                }
                break;
            default:
                // something we dont want to handle
                @ym_log_transaction(YM_IPN, $_REQUEST, 0);
        }
    }
Beispiel #13
0
 if ($package_type) {
     $data['account_type'] = $package_type == '-' ? '' : $package_type;
     @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $data['account_type'], $user_id);
     if ($data['account_type'] != $ym_updating_a_user->account_type) {
         $data['account_type_join_date'] = time();
     }
 }
 if (strlen($trial_on)) {
     $data['trial_on'] = $trial_on;
 }
 if ($trial_taken) {
     $data['trial_taken'] = $trial_taken == '-' ? '' : $trial_taken;
 }
 if ($expire_date) {
     $data['expire_date'] = strtotime(str_replace('/', '-', $expire_date));
     @ym_log_transaction(YM_ACCESS_EXTENSION, $data['expire_date'], $user_id);
 }
 if ($status) {
     $data['status'] = $status;
 }
 if ($hide_old_content) {
     $data['hide_old_content'] = $hide_old_content;
 }
 if ($parent_id) {
     if ($parent_id == 'Leave Alone') {
         $data['parent_id'] = '';
     } else {
         $user = get_user_by('login', $parent_id);
         $data['parent_id'] = $user->ID;
     }
 }
Beispiel #14
0
 function expire_check()
 {
     global $ym_sys;
     if (!isset($this->ID)) {
         return;
     }
     $ID = $this->ID;
     // check for parent
     if ($this->parent_id != FALSE) {
         // has a parent account
         $parent_user = new YourMember_User($this->parent_id);
         $not_expired = $parent_user->expire_check();
         if ($not_expired) {
             // check special case expires
             if ($this->status == YM_STATUS_PARENT_CANCEL) {
                 return FALSE;
             }
             // check user is is in parents child account list ie is orphaned
             if (!in_array($ID, $parent_user->child_ids)) {
                 // orphaned transistion to a normal account
                 // which is pending a sub payment
                 $this->status = YM_STATUS_EXPIRED;
                 //explict active set to clear child account status
                 $this->parent_id = false;
                 $this->save();
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Child Account Orphaned: Expired', 'ym'), $ID);
                 return FALSE;
             }
             // if the account type is blank
             // and parent only allows a single package type
             // set the child to that package type
             if (!$this->account_type) {
                 $allowed_types = count($parent_user->child_accounts_package_types);
                 $allowed_packs = count($parent_user->child_accounts_packages);
                 $error = FALSE;
                 if ($allowed_types >= 1 && $allowed_packs >= 1) {
                     // well f**k
                     $error = TRUE;
                 } else {
                     if ($allowed_types == 1) {
                         $this->account_type = $parent_user->child_accounts_package_types[0];
                         @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $this->account_type, $ID);
                     } else {
                         if ($allowed_packs == 1) {
                             ym_group_apply_package($parent_user->child_accounts_packages[0]);
                             // go drop for status check.....
                         } else {
                             // if drop thru well deny. Account not configured
                             $error = TRUE;
                         }
                     }
                 }
                 if ($error) {
                     $this->status = YM_STATUS_PARENT_CONFIG;
                     $this->save();
                     return FALSE;
                 }
             }
             if ($this->status != $parent_user->status) {
                 $this->status = $parent_user->status;
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID);
             }
             // if expose expire date to child
             // update expiry
             $this->save();
             return TRUE;
         }
         // check for status update at this point the child account should be expired
         // but the parent account can be of any status (such as pending)
         if ($this->account_type != YM_STATUS_PARENT_EXPIRED) {
             $this->status = YM_STATUS_PARENT_EXPIRED;
             @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID);
             $this->save();
         }
         return FALSE;
     }
     if (ym_superuser($ID)) {
         return TRUE;
     }
     $current_status = $this->status;
     if ($current_status === false) {
         return TRUE;
     }
     if ($current_status == YM_STATUS_EXPIRED || $current_status == YM_STATUS_TRIAL_EXPIRED) {
         return FALSE;
     }
     $grace_limit_user = $ym_sys->grace_limit;
     $grace_limit_user = apply_filters('ym_user_grace_limit_adjust', $grace_limit_user, $this);
     $new = FALSE;
     $reg_date = get_userdata($ID);
     $reg_date = strtotime($reg_date->user_registered);
     if ($reg_date > time() - 86400 * $grace_limit_user) {
         $new = TRUE;
     }
     if ($current_status == YM_STATUS_ACTIVE || $current_status == YM_STATUS_GRACE) {
         // time
         $expire = $this->expire_date;
         if ($expire > time()) {
             // expire is in the future
             // safe/not expired
             return TRUE;
         }
         // expired
         if ($this->ym_expiry_sub_dropdown_check()) {
             return;
         }
         if ($this->trial_on) {
             $user_status = YM_STATUS_TRIAL_EXPIRED;
         } else {
             $user_status = YM_STATUS_EXPIRED;
         }
         @ym_log_transaction(YM_ACCESS_EXPIRY, time(), $ID);
         @ym_log_transaction(YM_USER_STATUS_UPDATE, $user_status, $ID);
         $data = array('status' => $user_status, 'status_str' => __('User has expired', 'ym'));
         $data = apply_filters('ym_user_expire_check_into_expire', $data, $this);
         $this->update($data);
         $this->save();
         do_action('ym_user_is_expired', $ID, $data);
         return FALSE;
     } else {
         if ($current_status == YM_STATUS_PENDING && $ym_sys->grace_enable && !$new) {
             // grace is only applied to pending users
             // eligable
             $last_pay_date = $this->last_pay_date;
             $limit = time() - 86400 * $grace_limit_user;
             if ($last_pay_date > $limit) {
                 // lets put them into grace
                 $data = array('status' => YM_STATUS_GRACE, 'status_str' => __('User is entering Grace', 'ym'), 'expire_date' => time() + 86400 * $grace_limit_user);
                 @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expire_date'], $ID);
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'], $ID);
                 $data = apply_filters('ym_user_expire_check_into_grace', $data, $this);
                 $this->update($data);
                 $this->save();
                 do_action('ym_user_is_in_grace', $ID, $data);
                 // recheck
                 return $this->expire_check();
             } else {
                 // not eligable
                 return FALSE;
             }
         }
     }
     return FALSE;
 }
     update_option('ym_packs', $obj);
     // find all users on this pack and move to new pack
     // get all users
     $sql = 'SELECT u.id AS user_id FROM ' . $wpdb->users . ' u LEFT JOIN ' . $wpdb->usermeta . ' m ON m.user_id = u.id WHERE m.meta_key = \'ym_user\'';
     foreach ($wpdb->get_results($sql) as $row) {
         $user_id = $row->user_id;
         if (!($user_data = (object) get_user_option('ym_user', $user_id))) {
             // should never hit here
             $user_data = new YourMember_User($user_id);
             $user_data->save();
         }
         // only update is user is on the deleted pack
         if (isset($user_data->pack_id) && $user_data->pack_id == $id) {
             $user_data->pack_id = $new_pack_id;
             $user_data->account_type = $pack['account_type'];
             @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $user_data->account_type, $user_id);
             update_user_option($user_id, 'ym_user', $user_data, true);
             update_user_meta($user_id, 'ym_account_type', $user_data->account_type);
         }
     }
     echo '<meta http-equiv="refresh" content="3;' . $link . '&message=deleted" />';
 } else {
     ym_box_top(__('Deleting a Pack', 'ym'));
     echo '<p>' . __('Which pack would you like to put current pack members on', 'ym') . '</p>';
     echo '<form action="" method="post">';
     echo '<input type="hidden" name="id" value="' . $id . '" />';
     echo '<table class="form-table">';
     $obj = get_option('ym_packs');
     $packs = array();
     foreach ($obj->packs as $pack) {
         if ($pack['id'] != $id) {
function ym_user_unsubscribe($atts = array())
{
    get_currentuserinfo();
    global $current_user, $ym_res, $ym_user;
    if (!$current_user->ID) {
        return;
    }
    if (!$ym_user) {
        $ym_user = new YourMember_User($current_user->ID);
    }
    //var_dump($ym_user);
    $unsubscribe_text = isset($atts['unsubscribe_text']) ? $atts['unsubscribe_text'] : __('Are you sure you Wish to Unsubscribe', 'ym');
    $sure_button = isset($atts['sure_button']) ? $atts['sure_button'] : __('Yes', 'ym');
    $unsubscribe_button = isset($atts['unsubscribe_button']) ? $atts['unsubscribe_button'] : __('Unsubscribe', 'ym');
    $action = ym_post('ym_action');
    if ($action == 'unsubscribeyes') {
        // set user to inactive
        $user_status = YM_STATUS_EXPIRED;
        $ym_user->status_str = __('Manual UnSubscribe', 'ym');
        $ym_user->status = $user_status;
        //update_user_meta($current_user->ID, 'ym_user', $user_data);
        $ym_user->save();
        update_user_option($current_user->ID, 'ym_status', $user_status, true);
        @ym_log_transaction(YM_ACCESS_EXPIRY, time(), $current_user->ID);
        @ym_log_transaction(YM_USER_STATUS_UPDATE, $user_status . ' Manual Unsubscribe', $current_user->ID);
        // logout
        $html = '<p>' . $ym_res->unsubscribe_left_msg . '</p>';
        $html .= '<meta http-equiv="refresh" content="5;' . site_url() . ' " />';
        do_action('ym_user_self_unsubscribe');
        return $html;
    } else {
        if ($action == 'unsubscribe') {
            $html = '<form action="" method="post">
	<p>' . $unsubscribe_text . '</p>
	<input type="hidden" name="ym_action" value="unsubscribeyes" />
	<input type="submit" value="' . $sure_button . '" />
	</form>';
        } else {
            $html = '<form action="" method="post">
	<input type="hidden" name="ym_action" value="unsubscribe" />
	<input type="submit" value="' . $unsubscribe_button . '" />
	</form>';
        }
    }
    return $html;
}
function ym_download_file($download_id)
{
    get_currentuserinfo();
    global $wpdb, $current_user, $ym_upload_root;
    $allow_download = true;
    if ($download = ym_get_download($download_id)) {
        if ($download->members) {
            $allow_download = false;
            if ($current_user->ID) {
                if (!isset($current_user->caps['administrator'])) {
                    $posts = ym_get_download_posts($download_id);
                    foreach ($posts as $post) {
                        if (ym_user_has_access($post->post_id)) {
                            $allow_download = true;
                            break;
                        }
                    }
                } else {
                    $allow_download = true;
                }
            }
        }
        if ($allow_download) {
            $abs_file = ym_get_abs_file($download->filename);
            if (file_exists($abs_file)) {
                set_time_limit(0);
                ini_set('memory_limit', -1);
                $file_name = strrpos($download->filename, '/');
                $loc = substr($download->filename, 0, $file_name);
                $file_name = substr($download->filename, $file_name + 1);
                @ym_log_transaction(YM_DOWNLOAD_STARTED, $download->filename, $current_user->ID);
                header("Pragma: public");
                // required
                header("Expires: 0");
                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                header("Cache-Control: private", false);
                // required for certain browsers
                header("Content-type: application/force-download");
                header("Content-Transfer-Encoding: Binary");
                header("Content-length: " . @filesize($abs_file));
                header("Content-disposition: attachment; filename=\"" . $file_name . "\"");
                //readfile($abs_file);
                flush();
                $file = fopen($abs_file, "rb");
                while (!feof($file)) {
                    // send the current file part to the browser
                    print fread($file, 8192);
                    flush();
                }
                fclose($file);
                @ym_log_transaction(YM_DOWNLOAD_COMPLETED, $download->filename, $current_user->ID);
                exit;
            } else {
                echo __('You can not download this file because it does not exist. Please notify the Administrator.', 'ym');
                exit;
            }
        } else {
            echo __('You can not download this file because you do not have access', 'ym');
            exit;
        }
    } else {
        die;
    }
}