function ymind_block_edit()
{
    $id = ym_request('id');
    $row = ymind_get_block($id);
    echo '
	<form action="" method="post" enctype="multipart/form-data">
	<input type="hidden" name="id" value="' . $row->id . '"/>

	<table class="form-table"><tbody>
	
	<tr class="form-field">
		<td>' . __('IP Address', 'ymind') . '</td>
		<td>
			<input style="width: 150px;" name="ip" value="' . $row->ip . '"/>
			<span style="color: gray; font-style: italic;">' . __('Please enter an IP address to block.', 'ymind') . '</span>
		</td>
	</tr>	

	</tbody>
	</table>

	<div style="margin-top: 5px; float: left;">
		<input type="submit" name="block_save" value="' . __('Save', 'ymind') . '" class="button"/>
	</div>
	</form>
	
	<div style="margin-top:5px; float: left;">
		<form method="post">
			<input type="submit" value="&laquo; ' . __('Back to block list', 'ymind') . '" class="button"/>
		</form>
	</div>
	
	<div style="clear: both;">&nbsp;</div>
	';
}
function ym_register_flow($flow_id, $pack_id = false, $widget = false)
{
    global $current_page, $next_page, $the_flow_id, $wpdb, $ym_res, $ym_sys;
    global $post_data, $pack_data;
    $html = $form_top = '';
    $payment_gateway_detected = false;
    if (!is_singular() && !$widget) {
        return __('A Register Flow Error Occurred (Type 0) Not on a Flow Page', 'ym');
    }
    if (!$flow_id) {
        return __('A Register Flow Error Occurred (Type 1) No Flow Selected', 'ym');
    }
    if (ym_post('flowcomplete')) {
        // complete
        $query = 'SELECT complete_text FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id;
        $complete_text = $wpdb->get_var($query);
        if ($complete_text) {
            return '<p>' . $complete_text . '</p>';
        } else {
            return '<p>' . __('Registration/Upgrade is complete', 'ym') . '</p>';
        }
    }
    $flow_pages = 'SELECT flow_pages, complete_button FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id;
    $flow_pages = $wpdb->get_row($flow_pages);
    if (!$flow_pages) {
        return __('A Register Flow Error Occurred (Type 2) Flow Not Found', 'ym');
    }
    $complete_button = $flow_pages->complete_button;
    $the_flow_id = $flow_id;
    // have a flow
    $flow_pages = unserialize($flow_pages->flow_pages);
    $last_page = ym_post('ym_register_flow_page', 0);
    $current_page = ym_post('ym_register_flow_next_page', 0);
    $flowcomplete = ym_post('flowcomplete', 0);
    if (!$current_page) {
        $copy = $flow_pages;
        $current_page = array_shift($copy);
    }
    $next_page = 0;
    while ($next_page == 0 && count($flow_pages)) {
        $page = array_shift($flow_pages);
        if ($page == $current_page) {
            $next_page = array_shift($flow_pages);
        }
    }
    //$permalink = get_permalink();
    $permalink = '';
    if (ym_superuser()) {
        echo '<div class="ym_message"><p class="ym_message_liner">' . __('Warning, entering this flow may change your WordPress role', 'ym') . '</p></div>';
    }
    echo '
<style type="text/css">
	label {
		display: block;
	}
</style>
';
    $form = '
<form action="' . $permalink . '" method="post" enctype="multipart/form-data" id="ym_register_flow_form">
';
    $html .= $form;
    $form_top .= $form;
    $custom_data = get_option('ym_custom_fields');
    $custom_data = $custom_data->entries;
    // required?
    $required_data = isset($_POST['required']) ? $_POST['required'] : array();
    $ok = true;
    $email = true;
    $useremail = true;
    $username = true;
    $coupon = true;
    $dupepassword = true;
    $dont_hidden = array('email_address', 'username', 'signed_request');
    // maintaint
    $post_data = array();
    foreach ($_POST as $field => $entry) {
        if ($field != 'ym_register_flow_page' && $field != 'ym_register_flow_next_page' && $field != 'required' && $field != 'flowcomplete') {
            if (isset($required_data[$field]) && $required_data[$field] == 1 && !$entry) {
                $ok = false;
            }
            if ($field == 'email_address' && !is_email($entry)) {
                $email = false;
                $entry = '';
            } else {
                if ($field == 'email_address') {
                    // verify unique
                    if (email_exists($entry)) {
                        $useremail = false;
                    }
                }
            }
            if ($field == 'username') {
                if (username_exists($entry)) {
                    $username = false;
                }
            }
            if ($field == 'coupon' && $entry) {
                $type = ym_post('coupon_type');
                if ($type == 'coupon_register') {
                    $type = array(0);
                } else {
                    if ($type == 'coupon_upgrade') {
                        $type = array(1);
                    } else {
                        if (!is_int($type)) {
                            // both
                            $type = array(0, 1);
                        }
                    }
                }
                $value = false;
                $coupon_type = '';
                foreach ($type as $t) {
                    $value = ym_validate_coupon($entry, $t);
                    if ($value) {
                        $coupon_type = $t;
                        // TODO: register coupon use
                        break;
                    }
                }
                if ($value) {
                    //valid
                    $post_data['coupon_value'] = $value;
                    $form = '<input type="hidden" name="coupon_value" value="' . $value . '" />';
                    $post_data['coupon_type'] = $coupon_type;
                    $form = '<input type="hidden" name="coupon_type" value="' . $coupon_type . '" />';
                    $coupon = true;
                } else {
                    // not valid
                    $coupon = false;
                }
            }
            //YM duplicate password check
            if ($field == 'ym_password') {
                if (ym_post('ym_password_check') || ym_post('ym_password_dupe')) {
                    $dupepassword = false;
                    if (ym_post('ym_password') == ym_post('ym_password_check')) {
                        $dupepassword = true;
                    }
                }
            }
            if (!isset($post_data[$field])) {
                $post_data[$field] = ym_post($field);
                //$entry;
                if (!in_array($field, $dont_hidden)) {
                    $form = '<input type="hidden" name="' . $field . '" value="' . $entry . '" />
';
                    $html .= $form;
                    $form_top .= $form;
                }
            }
        }
    }
    $call_login = 0;
    if ($_POST) {
        if (!$ok || !$email || !$useremail || !$username || !$coupon || !$dupepassword) {
            $next_page = $current_page;
            $current_page = $last_page;
            if (!$email) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_invalid . '</p></div>';
            }
            if (!$useremail) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_inuse . '</p></div>';
            }
            if (!$username) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_username_inuse . '</p></div>';
            }
            if (!$ok) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_required_fields . '</p></div>';
            }
            if (!$coupon) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_invalid_coupon . '</p></div>';
            }
            if (!$dupepassword) {
                $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_invalid_password . '</p></div>';
            }
            $ok = false;
        }
        global $current_user;
        get_currentuserinfo();
        $username = $password = $fb_widget_ok = false;
        // check registation
        if ($ok) {
            if (!$current_user->ID) {
                $email = isset($post_data['email_address']) ? $post_data['email_address'] : '';
                $username = isset($post_data['username']) ? $post_data['username'] : '';
                $password = isset($post_data['password']) ? $post_data['password'] : '';
                if ($email) {
                    // minimum for registeration
                    if (!$username) {
                        $username = $email;
                    }
                    if (username_exists($username)) {
                        // register failed
                        $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_username_inuse . '</p></div>';
                    } else {
                        // able to registers
                        $ym_user = new YourMember_User();
                        $user_id = $ym_user->create($email, false, true, $username, $password);
                        wp_set_current_user($user_id);
                        $call_login = 1;
                    }
                } else {
                    if (ym_post('signed_request')) {
                        $data = ym_facebook_uncode(ym_post('signed_request'));
                        if ($data) {
                            if ($data->registration) {
                                // register!
                                if (email_exists($data->registration->email) || username_exists($data->registration->email)) {
                                    $html .= '<div class="ym_message"><p class="ym_message_liner">' . $ym_res->registration_flow_email_inuse . '</p></div>';
                                } else {
                                    $ym_user = new YourMember_User();
                                    $user_id = $ym_user->create($data->registration->email, false, true, $data->registration->email, $data->registration->password, array('first_name' => $data->registration->first_name, 'last_name' => $data->registration->last_name));
                                    wp_set_current_user($user_id);
                                    $call_login = 1;
                                    $fb_widget_ok = true;
                                }
                            } else {
                                $html .= '<div class="ym_message"><p class="ym_message_liner">' . __('Faecbook Registration Error (2)', 'ym') . '</p></div>';
                            }
                        } else {
                            $html .= '<div class="ym_message"><p class="ym_message_liner">' . __('Faecbook Registration Error (1)', 'ym') . '</p></div>';
                        }
                    }
                }
            } else {
                // update key user entries
                if (isset($post_data['username'])) {
                    if ($username = $post_data['username']) {
                        $query = 'UPDATE ' . $wpdb->users . ' SET user_login = \'' . $username . '\' WHERE ID = ' . $current_user->ID;
                        $wpdb->query($query);
                    }
                }
                if (isset($post_data['password'])) {
                    if ($password = $post_data['password']) {
                        $pw_hash = wp_hash_password($password);
                        $query = 'UPDATE ' . $wpdb->users . ' SET user_pass = \'' . $pw_hash . '\' WHERE ID = ' . $current_user->ID;
                        $wpdb->query($query);
                        $call_login = 1;
                    }
                }
            }
            // customs
            ym_update_custom_fields();
        }
    }
    $gateway_return = ym_request('gateway_return', false);
    if ($gateway_return) {
        // return from gateway into flow
        // all details dropped :-(
        $to_remove = array('gateway_return', 'item', 'ym_register_flow_page', 'ym_register_flow_next_page', 'user_id');
        $query = $_SERVER['QUERY_STRING'];
        foreach ($to_remove as $remove) {
            $query = preg_replace('/' . $remove . '\\=' . "([a-zA-Z0-9_]+)/", '', $query);
        }
        while (substr($query, -1, 1) == '&') {
            $query = substr($query, 0, -1);
        }
        $html = str_replace('<form action=""', '<form action="?' . $query . '"', $html);
        $user_id = ym_request('user_id', false);
        if ($user_id) {
            $call_login = 1;
        }
    }
    $ym_register_user_id = ym_request('ym_register_user_id', false);
    if ($ym_register_user_id) {
        $call_login = 1;
        $user_id = $ym_register_user_id;
    }
    if ($call_login) {
        // temp login
        wp_set_current_user($user_id);
        $html .= '<input type="hidden" name="ym_register_user_id" value="' . $user_id . '" />';
    }
    unset($username);
    unset($password);
    $form = '
	<input type="hidden" name="ym_register_flow_page" value="' . $current_page . '" />
	<input type="hidden" name="ym_register_flow_next_page" value="' . $next_page . '" />
	';
    $html .= $form;
    $form_top .= $form;
    // data maintain whats left
    foreach ($post_data as $key => $item) {
        if (!in_array($key, $dont_hidden)) {
            $form = '
	<input type="hidden" name="' . $key . '" value="' . $item . '" />
	';
            $html .= $form;
            $form_top .= $form;
        }
    }
    // load
    $page = 'SELECT page_fields, button_text FROM ' . $wpdb->prefix . 'ym_register_pages WHERE page_id = ' . $current_page;
    $page = $wpdb->get_row($page);
    if (!$page) {
        return __('A Register Flow Error Occurred (Type 3) Page Not Found', 'ym');
    }
    $page_data = $page->page_fields;
    $next_button = $page->button_text;
    $page_data = unserialize($page_data);
    foreach ($page_data as $item => $field) {
        foreach ($field as $i => $f) {
            $page_data[$item][$i] = stripslashes(urldecode($f));
        }
    }
    $block_logic = array();
    // parse pack data
    $pack_data = false;
    if (isset($post_data['pack_id'])) {
        // load from form
        $pack_id = $post_data['pack_id'];
        // pass thru....
    }
    if ($pack_id) {
        $pack_data = ym_get_pack_by_id($pack_id);
    } else {
        // no pack id :-(
        // default
        $pack_order = ym_get_packs();
        $pack_data = array_shift($pack_order);
    }
    $first_button = true;
    foreach ($page_data as $index => $field_data) {
        $display = true;
        if ($field_data['iflogic']) {
            // block has logic
            $display = false;
            // evaulate the block logic result
            // is it a then or a else?
            switch ($field_data['iflogic']) {
                case 'loggedin':
                    $match = $field_data['iflogic_quantity_loggedin'];
                    $logged_in = is_user_logged_in();
                    if ($logged_in && $match) {
                        // user is logged on and the match is for logged in
                        $this_logic = 'then';
                    } else {
                        if (!$logged_in && !$match) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    }
                    break;
                case 'buying':
                    $match = $field_data['iflogic_quantity_pack'];
                    if (isset($post_data['pack_id']) && $post_data['pack_id'] == $match) {
                        $this_logic = 'then';
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'currentlyon':
                    $match = $field_data['iflogic_quantity_pack'];
                    if (is_user_logged_in()) {
                        global $ym_user;
                        $pack_id = $ym_user->pack_id ? $ym_user->pack_id : 0;
                        if ($pack_id == $match) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'accounttype':
                    $match = $field_data['iflogic_quantity_pack'];
                    $match = strtolower($match);
                    if (is_user_logged_in()) {
                        global $ym_user;
                        $account_type = $ym_user->account_type ? $ym_user->account_type : '';
                        $account_type = strtolower($account_type);
                        if ($account_type == $match) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'filledin':
                    // custom field
                    $field = $field_data['iflogic_quantity_custom'];
                    $value = $field_data['iflogic_quantity_custom_compare'];
                    if (is_user_logged_in()) {
                        $customs = get_user_meta($current_user->ID, 'ym_custom_fields', true);
                        $test = $customs->{$field};
                        if ($test == $value) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'servervar':
                case 'getvar':
                case 'postvar':
                case 'cookievar':
                    $source = '_' . substr($field_data['iflogic'], 0, -3);
                    $match_name = $field_data['iflogic_quantity_field'];
                    $match_value = $field_data['iflogic_quantity_entry'];
                    $current_value = $source[$match_name];
                    if ($current_value == $match_value) {
                        $this_logic = 'then';
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                case 'registeredfor':
                    //				case 'memberfor':
                //				case 'memberfor':
                case 'expiresin':
                    $match_value = $field_data['iflogic_quantity_memberfor_value'];
                    $match_unit = $field_data['iflogic_quantity_memberfor_unit'];
                    if (is_user_logged_in()) {
                        global $ym_user;
                        if ($field_data['iflogic'] == 'registeredfor') {
                            $math_date = strtotime($current_user->user_registered);
                        } else {
                            if ($field_data['iflogic'] == 'expiresin') {
                                $math_data = $ym_user->expire_date;
                            } else {
                                $math_date = '';
                            }
                        }
                        $seconds = ym_register_flow_date_math($match_value, $match_unit);
                        $diff = time() - $math_date;
                        if ($diff > $seconds) {
                            $this_logic = 'then';
                        } else {
                            $this_logic = 'else';
                        }
                    } else {
                        $this_logic = 'else';
                    }
                    break;
                default:
                    $this_logic = 'else';
            }
            if ($this_logic == 'then' && $field_data['iflogic_showhide'] == 'show' || $this_logic == 'else' && $field_data['iflogic_showhide'] == 'hide') {
                $display = true;
            } else {
                $display = false;
            }
        }
        if ($field_data['label'] == 'page_logic' && ($this_logic == 'then' && $field_data['iflogic_showhide'] == 'hide' || $this_logic == 'else' && $field_data['iflogic_showhide'] == 'hide')) {
            $html .= '
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery(\'#ym_register_flow_form\').submit();
	});
</script>
';
            $html .= '</form>';
            return $html;
        } else {
            if ($field_data['label'] == 'page_logic') {
                // skip the IF and just skip the whole loop if should?
                continue;
            }
        }
        /**
         output render
        */
        $html .= '<span class="' . $field_data['classes'] . '">';
        //open class span
        if ($field_data['types'] == 'freetext' && $display) {
            $html .= '<p>' . nl2br($field_data['names']) . '</p>';
            //names o.0 lol
            /**
            Customs Processor
            */
        } else {
            if ($field_data['types'] == 'custom' && $display) {
                // LIFTED FROM ym.php line 642
                // modded tooooo!
                if ($field_data['names'] == 'terms_and_conditions' && !empty($ym_res->tos)) {
                    $html .= '<p>
						<textarea name="tos" cols="29" rows="5" readonly="readonly">' . $ym_res->tos . '</textarea>';
                    $html .= '</p>';
                    $html .= '<p>
						<label class="ym_label" for="terms_and_conditions">
							<div><input type="checkbox" class="checkbox" name="terms_and_conditions" id="terms_and_conditions" value="1" />
							' . __('I agree to the Terms and Conditions.', 'ym') . '</div>
						</label>
					</p>' . "\n";
                } else {
                    if ($field_data['names'] == 'ym_password') {
                        $html .= '<label for="ym_password">' . $field_data['label'];
                        $html .= '<input type="password" name="' . $field_data['names'] . '" value="" />';
                        $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />';
                        if ($field_data['required']) {
                            $html .= $ym_sys->required_custom_field_symbol;
                        }
                        $html .= '</label>';
                        if (!empty($field_data['options'])) {
                            $html .= '<label for="ym_password_check">' . __('Confirm Password', 'ym');
                            $html .= '<input type="password" name="ym_password_check" value="" />';
                            $html .= '<input type="hidden" name="ym_password_dupe" value="1" />';
                            if ($field_data['required']) {
                                $html .= $ym_sys->required_custom_field_symbol;
                            }
                            $html .= '</label>';
                        }
                    } else {
                        if ($field_data['names'] == 'subscription_introduction' && !empty($ym_res->subs_intro)) {
                            $html .= '<div class="ym_subs_intro">' . $ym_res->subs_intro . '</div>';
                        } else {
                            if ($field_data['names'] == 'subscription_options') {
                                global $ym_packs;
                                $upsell_from = ym_request('gateway_return', false) ? $pack_id : false;
                                // TO DO
                                $pack_data = false;
                                if ($pack_id && !ym_request('gateway_return', false)) {
                                    $pack_data = ym_get_pack_by_id($pack_id);
                                    if ($pack_data) {
                                        $label = ym_get_pack_label($pack_id);
                                        $html .= '<p>' . sprintf(__('You are subscribing to <b>%s</b>', 'ym'), $label) . '</p>';
                                        $html .= '<input type="hidden" name="pack_id" value="' . $pack_id . '" />';
                                    } else {
                                        return __('A Register Flow Error Occurred (Type 4) Specified Pack Not Found', 'ym');
                                    }
                                } else {
                                    $ym_packs->packs = apply_filters('ym_packs', $ym_packs->packs);
                                    foreach ($ym_packs->packs as $pack) {
                                        if ($upsell_from == $pack['id']) {
                                            continue;
                                        }
                                        $label = ym_get_pack_label($pack['id']);
                                        $html .= '<label for="pack_id_' . $pack['id'] . '">';
                                        $html .= '<input type="radio" name="pack_id" id="pack_id_' . $pack['id'] . '" value="' . $pack['id'] . '" />';
                                        $html .= ' ' . $label . ' ';
                                        $html .= '</label>';
                                    }
                                }
                            } else {
                                if ($field_data['names'] == 'birthdate') {
                                    $html .= '<label for="ym_birthdate_month">' . $field_data['label'];
                                    $birthdate_fields = ym_birthdate_fields('ym_birthdate', ym_post('ym_birthdate_month', ''), ym_post('ym_birthdate_day', ''), ym_post('ym_birthdate_year', ''));
                                    $html .= $birthdate_fields;
                                    $html .= '<input type="hidden" name="required[ym_birthdate_month]" value="' . $field_data['required'] . '" />';
                                    $html .= '<input type="hidden" name="required[ym_birthdate_day]" value="' . $field_data['required'] . '" />';
                                    $html .= '<input type="hidden" name="required[ym_birthdate_year]" value="' . $field_data['required'] . '" />';
                                    if ($field_data['required']) {
                                        $html .= $ym_sys->required_custom_field_symbol;
                                    }
                                    $html .= '</label>';
                                } else {
                                    if ($field_data['names'] == 'country') {
                                        $html .= '<label for="ym_country">' . $field_data['label'];
                                        $countries_sel = ym_countries_list('ym_country', ym_post('ym_country', false));
                                        $html .= $countries_sel;
                                        $html .= '<input type="hidden" name="required[ym_country]" value="' . $field_data['required'] . '" />';
                                        if ($field_data['required']) {
                                            $html .= $ym_sys->required_custom_field_symbol;
                                        }
                                        $html .= '</label>';
                                    } else {
                                        // HERE
                                        $this_custom = '';
                                        foreach ($custom_data as $custom) {
                                            $label = $custom['label'];
                                            if (!$label) {
                                                $label = strtolower(str_replace(' ', '_', $custom['name']));
                                            }
                                            if ($label == $field_data['label']) {
                                                // found
                                                $this_custom = $custom;
                                                break;
                                            }
                                        }
                                        if ($this_custom) {
                                            $ro = $this_custom['readonly'] ? 'readonly="readonly"' : '';
                                            // check for special
                                            $value = $this_custom['value'];
                                            if (strpos($value, ':') !== false) {
                                                $array = explode(':', $value);
                                                if (count($array)) {
                                                    switch ($array[0]) {
                                                        case 'cookie':
                                                            $value = ym_cookie($array[1]);
                                                            break;
                                                        case 'session':
                                                            $value = ym_session($array[1]);
                                                            break;
                                                        case 'get':
                                                            $value = ym_get($array[1]);
                                                            break;
                                                        case 'post':
                                                            $value = ym_post($array[1]);
                                                            break;
                                                        case 'request':
                                                        case 'qs':
                                                            $value = ym_request($array[1]);
                                                            break;
                                                        default:
                                                            $value = '';
                                                            break;
                                                    }
                                                    $this_custom['value'] = ym_post($this_custom['name'], $value);
                                                }
                                            } else {
                                                if (is_user_logged_in()) {
                                                    $this_custom['value'] = ym_custom_value($this_custom['id']);
                                                } else {
                                                    $this_custom['value'] = ym_post($this_custom['name'], $this_custom['value']);
                                                }
                                            }
                                            // ro adjust for fields that should not be changed
                                            switch ($this_custom['type']) {
                                                case 'password':
                                                case 'text':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<input type="' . $this_custom['type'] . '" name="' . $this_custom['name'] . '" value="' . $this_custom['value'] . '" ' . $ro . ' />';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'hidden':
                                                    $html .= '<input type="hidden" name="' . $this_custom['name'] . '" value="' . $this_custom['value'] . '" ' . $ro . ' />';
                                                    break;
                                                case 'yesnocheckbox':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<input type="checkbox" name="' . $this_custom['name'] . '" value="1" ' . ($this_custom['value'] ? 'checked="checked"' : '') . ' ' . $ro . ' />';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'yesno':
                                                case 'select':
                                                case 'multiselect':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    if ($this_custom['type'] == 'multiselect') {
                                                        $html .= '<select name="' . $this_custom['name'] . '[]" multiple="multiple"';
                                                    } else {
                                                        $html .= '<select name="' . $this_custom['name'] . '" ';
                                                    }
                                                    $html .= '>';
                                                    if ($this_custom['type'] == 'select' || $this_custom['type'] == 'multiselect') {
                                                        $options = explode(';', $this_custom['available_values']);
                                                    } else {
                                                        $options = array(__('Yes', 'ym'), __('No', 'ym'));
                                                    }
                                                    foreach ($options as $option) {
                                                        if (strpos($option, ':')) {
                                                            list($option, $val) = explode(':', $option);
                                                            $html .= '<option value="' . $option . '" ' . ($option == $this_custom['value'] ? 'selected="selected"' : '') . '>' . $val . '</option>';
                                                        } else {
                                                            $html .= '<option value="' . $option . '" ' . ($option == $this_custom['value'] ? 'selected="selected"' : '') . '>' . $option . '</option>';
                                                        }
                                                    }
                                                    $html .= '
</select>
';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'textarea':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<textarea name="' . $this_custom['name'] . '" cols="29" rows="5" ' . $ro . '>' . $this_custom['value'] . '</textarea>';
                                                    $html .= '<input type="hidden" name="required[' . $this_custom['name'] . ']" value="' . $field_data['required'] . '" />';
                                                    if ($field_data['required'] && !$ro) {
                                                        $html .= $ym_sys->required_custom_field_symbol;
                                                    }
                                                    $html .= '</label>';
                                                    break;
                                                case 'file':
                                                    $html .= '<label for="' . $this_custom['name'] . '">' . $this_custom['label'];
                                                    $html .= '<input type="file" name="' . $this_custom['name'] . '" />';
                                                    $html .= '</label>';
                                                    break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // END LIFT
                /**
                Buttons
                */
            } else {
                if (($field_data['types'] == 'payment_button' || $field_data['types'] == 'payment_action') && $display) {
                    $payment_gateway_detected = true;
                    add_filter('ym_additional_code', 'ym_register_flow_override_return', 10, 3);
                    $enabled = get_option('ym_modules');
                    // use the ym user id function
                    if (ym_get_user_id()) {
                        if (in_array($field_data['names'], $enabled)) {
                            // register flow
                            $class = $field_data['names'];
                            $pay = new $class();
                            if ($first_button) {
                                $html .= '</form>';
                                $first_button = false;
                            }
                            $this_pack = $pack_data;
                            // coupon check
                            if (isset($post_data['coupon_value']) && $post_data['coupon_value']) {
                                // stop
                                // stash
                                $value = ym_apply_coupon($post_data['coupon'], $post_data['coupon_type'], $this_pack['cost']);
                                $type = ym_get_coupon_type($value);
                                if ($type == 'percent') {
                                    // percent cost change
                                    $this_pack['cost'] = $this_pack['cost'] / 100 * $value;
                                } else {
                                    if ($type == 'sub_pack') {
                                        // diff pack
                                        $this_pack = ym_get_pack_by_id($value);
                                    } else {
                                        // other
                                        // new cost
                                        $this_pack['cost'] = $value;
                                    }
                                }
                                ym_register_coupon_use($post_data['coupon'], ym_get_user_id(), 'buy_subscription_' . $pack_data['id']);
                                if (!$this_pack['cost']) {
                                    // change to free
                                    //							$field_data['names'] = 'ym_free';
                                    // lifted from 135 of ym-register.include.php
                                    $code_to_use = 'freebie_code';
                                    // attempt to redirect to the processor.
                                    $loc = $ym_home . '/index.php?ym_process=ym_free&' . $code_to_use . '=buy_subscription_' . $this_pack['id'] . '_' . ym_get_user_id();
                                    if (!headers_sent()) {
                                        header('Location: ' . $loc);
                                        exit;
                                    } else {
                                        echo '<script type="text/javascript">window.location = "' . $loc . '";</script>';
                                    }
                                    die;
                                }
                            }
                            // there will always be pack data becuase I picked the default one earlier
                            // but it will default to the default pack anyway
                            if ($this_pack['cost']) {
                                // && $field_data['names'] != 'ym_free') {
                                //						$gw_button_form = $pay->getButton($this_pack['id'], (isset($post_data['coupon_value']) ? $this_pack['cost'] : false));
                                //						$html .= $gw_button_form;
                                $gw_button_form = $pay->getButton($this_pack['id'], isset($post_data['coupon_value']) ? $this_pack['cost'] : false);
                                if ($field_data['types'] == 'payment_action') {
                                    if (method_exists($pay, 'register_auto_payment_action')) {
                                        $html .= $pay->register_auto_payment_action($this_pack['id'], isset($post_data['coupon_value']) ? $this_pack['cost'] : false, true);
                                    } else {
                                        if ($gw_button_form) {
                                            $html .= $gw_button_form . '
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery(\'.' . $field_data['names'] . '_form\').submit();
	});
</script>
';
                                        }
                                    }
                                } else {
                                    if (method_exists($pay, 'register_payment_action')) {
                                        $html .= $pay->register_payment_action(true);
                                    } else {
                                        $html .= $gw_button_form;
                                    }
                                }
                            } else {
                                if (!$this_pack['cost'] && $field_data['names'] == 'ym_free') {
                                    // free
                                    $gw_button_form = $pay->getButton($this_pack['id'], false);
                                    $html .= $gw_button_form;
                                    if ($field_data['types'] == 'payment_action') {
                                        if (method_exists($pay, 'register_auto_payment_action')) {
                                            $html .= $pay->register_auto_payment_action($this_pack['id'], false, true);
                                        } else {
                                            if ($gw_button_form) {
                                                $html .= '
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery(\'.ym_free_form\').submit();
	});
</script>
';
                                            }
                                        }
                                    } else {
                                        if (method_exists($pay, 'register_payment_action')) {
                                            $html .= $pay->register_payment_action(true);
                                        }
                                    }
                                } else {
                                    if (isset($post_data['coupon_value']) && $post_data['coupon_value']) {
                                        return __('A Register Flow Error Occurred (Type 5) Pack/Coupon Error', 'ym');
                                    }
                                }
                            }
                        }
                    } else {
                        // user not logged in // No User ID Determined
                        return __('In order to continue you need to Register or Login', 'ym');
                    }
                    /**
                    Widgets
                    */
                } else {
                    if ($field_data['types'] == 'widget' && $display) {
                        if ($field_data['names'] == 'login') {
                            // login form
                            $html .= '
	<input type="hidden" name="ym_register_flow_page" value="' . $current_page . '" />
	<input type="hidden" name="ym_register_flow_next_page" value="' . $current_page . '" />
	';
                            //	<input type="hidden" name="ym_register_flow_do_login" value="1" />';
                            $html .= ym_login_form();
                        } else {
                            if ($field_data['names'] == 'register_facebook') {
                                // check for and handle a signed request
                                if ($fb_widget_ok) {
                                    // skippy
                                    $html .= '
					<script type="text/javascript">
						jQuery(document).ready(function() {
							jQuery(\'#ym_register_flow_form\').submit();
						});
					</script>
					';
                                } else {
                                    $html .= '
<iframe src="https://www.facebook.com/plugins/registration?
             client_id=' . get_option('ym_register_flow_fb_app_id') . '&
             redirect_uri=' . get_permalink() . '&
             fields=name,email,first_name,last_name,password"
        scrolling="auto"
        frameborder="no"
        style="border:none"
        allowTransparency="true"
        width="100%"
        height="550">
</iframe>
';
                                    // no next/complete please
                                }
                                $payment_gateway_detected = true;
                            } else {
                                $html .= 'Undefined Widget: (' . $field_data['names'] . ')';
                            }
                        }
                        /**
                        Coupon
                        */
                    } else {
                        if ($field_data['names'] == 'coupon' && $display) {
                            $value = isset($post_data[$field_data['names']]) ? $post_data[$field_data['names']] : '';
                            $html .= '<label for="' . $field_data['names'] . '">' . $field_data['label'];
                            $html .= '<input type="text" name="' . $field_data['names'] . '" id="' . $field_data['names'] . '" value="' . $value . '" />';
                            $html .= '<input type="hidden" name="coupon_type" value="' . $field_data['types'] . '" />';
                            $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />';
                            if ($field_data['required']) {
                                $html .= $ym_sys->required_custom_field_symbol;
                            }
                            $html .= '</label>';
                            /**
                            Display everything else
                            */
                        } else {
                            if ($display) {
                                $value = isset($post_data[$field_data['names']]) ? $post_data[$field_data['names']] : '';
                                $html .= '<label for="' . $field_data['names'] . '">' . $field_data['label'];
                                $html .= '<input type="' . $field_data['types'] . '" name="' . $field_data['names'] . '" id="' . $field_data['names'] . '" value="' . $value . '" />';
                                $html .= '<input type="hidden" name="required[' . $field_data['names'] . ']" value="' . $field_data['required'] . '" />';
                                if ($field_data['required']) {
                                    $html .= $ym_sys->required_custom_field_symbol;
                                }
                                $html .= '</label>';
                            }
                        }
                    }
                }
            }
        }
        $html .= '</span>';
        //closes class span
    }
    if (!$first_button) {
        // kill id
        $html = str_replace('id="ym_register_flow_form"', '', $html);
        // complete?
        if (!$next_page) {
            $query = 'SELECT complete_url FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $flow_id;
            if ($url = $wpdb->get_var($query)) {
                $url = site_url($url);
                $form_top = str_replace('<form action=""', '<form action="' . $url . '"', $form_top);
            }
        }
        // append the form top
        $html .= $form_top;
        // end it
    }
    // payment gateway?
    if (!$payment_gateway_detected) {
        $html .= '<p>';
        if ($next_page) {
            $html .= '<input type="submit" value="' . $next_button . '" />';
        } else {
            $html .= '
<input type="hidden" name="flowcomplete" value="1" />
<input type="submit" value="' . $complete_button . '" />';
        }
        $html .= '</p>';
    }
    $html .= '</form>';
    return $html;
}
    private function _failedBraintree($result = false, $ajax = false)
    {
        // see if its something we can catch
        if ($result) {
            if (get_class($result) == 'Braintree_Result_Successful') {
                if ($ajax) {
                    return array('code' => $error->code, 'message' => 'Successful Error', 'ok' => false);
                }
            }
            foreach ($result->errors->deepAll() as $error) {
                if ($ajax) {
                    return array('code' => $error->code, 'message' => $error->message, 'ok' => false);
                }
                $url = $_SERVER['HTTP_REFERER'];
                if (strpos($url, '?')) {
                    $url .= '&';
                } else {
                    $url .= '?';
                }
                $url .= 'code=' . ym_request('code');
                $url .= '&errorcode=' . $error->code . '&errormessage=' . $error->message;
                header('Location: ' . $url);
                exit;
                echo $error->code . ' ' . $error->message;
            }
        }
        // default crash
        echo '<p>
		An Error Has Occured
		<br />
		And the Payment Flow has exited abnormally
		</p><p>Debug Information</p>';
        echo '<pre>';
        print_r($_REQUEST);
        print_r($_SERVER);
        if ($result) {
            print_r($result->errors->deepAll());
        }
        echo '</pre>';
        exit;
    }
/**
* Additional login messages
*/
function ym_login_message($message)
{
    global $ym_res;
    if (ym_request('checkemail') == 'subscribed') {
        $message = '<p class="message">' . $ym_res->checkemail_subscribed . '</p>';
    }
    if (ym_request('checkemail') == 'bundle') {
        $message = '<p class="message">' . $ym_res->checkemail_bundle . '</p>';
    }
    if (ym_request('checkemail') == 'post') {
        $message = '<p class="message">' . $ym_res->checkemail_post . '</p>';
    }
    if (ym_request('checkemail') == 'loginneeded') {
        $message = '<p id="login_error">' . $ym_res->checkemail_loginneeded . '</p>';
    }
    if (ym_request('checkemail') == 'noaccess') {
        $message = '<p id="login_error">' . $ym_res->checkemail_noacccess . '</p>';
    }
    $message = apply_filters('ym_login_message', $message);
    return $message;
}
Exemple #5
0
 function ym_login_message($message)
 {
     if (ym_request('checkemail') == 'subscribed' && ym_request('from_gateway') == 'ym_invoice') {
         $invoice = new ym_invoice();
         $message = '<p class="message">' . $invoice->subscribed . '</p>';
     }
     return $message;
 }
function ym_fbook_init()
{
    global $facebook_settings, $location;
    //	session_start();// wp does this
    if (ym_request('destroy')) {
        session_destroy();
        header('Location: ' . site_url());
        exit;
    }
    $location = get_permalink() ? get_permalink() : 'http' . (is_ssl() ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    /********************************************/
    /* AWAKE?
    	/********************************************/
    if (!ym_facebook_settings()) {
        // no settings
        // iframe break out if iframe present
        add_action('wp_head', 'ym_fbook_init_iframe_breakout');
        // abort
        return;
    }
    if (!$facebook_settings->enabled) {
        // not enabled
        // iframe break out if iframe present
        add_action('wp_head', 'ym_fbook_init_iframe_breakout');
        // abort
        return;
    }
    /********************************************/
    /* Aborts
    	/********************************************/
    if (is_admin()) {
        // in the admin system
        return;
    }
    // abort login
    if (FALSE !== strpos($_SERVER['REQUEST_URI'], 'wp-login')) {
        return;
    }
    // IPN
    if (ym_request('ym_process')) {
        return;
    }
    // Cron
    if (ym_request('doing_wp_cron')) {
        return;
    }
    /********************************************/
    /* basic defines
    	/********************************************/
    define('YM_FBOOK_APPID', $facebook_settings->app_id);
    define('YM_FBOOK_SECRET', $facebook_settings->app_secret);
    $Location = str_replace('?logged_out=1', '', $location);
    define('YM_FBOOK_IN_HERE', $location);
    // app target
    define('YM_FBOOK_APP_TARGET', 'https://apps.facebook.com/' . $facebook_settings->canvas_url . str_replace(site_url(), '', $location));
    define('YM_FBOOK_PAGE_TARGET', 'https://facebook.com/' . $facebook_settings->page_url . '?sk=app_' . YM_FBOOK_APPID);
    // can't take args
    if (isset($_SESSION['facebook_last_page']) && $_SESSION['facebook_last_page']) {
        define('YM_FBOOK_LAST_PAGE', $_SESSION['facebook_last_page']);
    } else {
        // TODO: use location for now, but should be defined FB Root URL based on page/app
        define('YM_FBOOK_LAST_PAGE', $location);
    }
    $_SESSION['facebook_last_page'] = $location;
    /********************************************/
    /* Linter
    	/********************************************/
    // come back to this if needed
    $test = 'facebookexternalhit';
    if (substr($_SERVER['HTTP_USER_AGENT'], 0, strlen($test)) == $test) {
        return;
    }
    /********************************************/
    /* Scope
    	/********************************************/
    $scope = array();
    global $scopes;
    foreach ($scopes as $fbsetting => $entry) {
        if (isset($facebook_settings->{$fbsetting}) && $facebook_settings->{$fbsetting}) {
            $scope[] = $entry;
        }
    }
    if (count($scope)) {
        $scope = '&scope=' . implode(',', $scope);
    } else {
        $scope = '';
    }
    /********************************************/
    /* Defines
    	/********************************************/
    // oauth target
    $base = 'http://www.facebook.com/dialog/oauth/?client_id=' . YM_FBOOK_APPID . $scope . '&redirect_uri=';
    define('YM_FBOOK_AUTH_APP', $base . urlencode(YM_FBOOK_APP_TARGET));
    define('YM_FBOOK_AUTH_PAGE', $base . urlencode(YM_FBOOK_PAGE_TARGET));
    define('YM_FBOOK_AUTH_NO', $base . urlencode($location));
    /********************************************/
    /* Exceptions
    	/********************************************/
    if (isset($_SESSION['in_facebook']) && $_SESSION['in_facebook'] == 1 && ym_request('leavefacebook') == 1 && $facebook_settings->enable_leave_facebook) {
        // leaving :-(
        unset($_SESSION['in_facebook']);
        // route to last page, not current page (aka location)
        // as that is leavefacebook = 1
        echo '<script type="text/javascript">top.location.href="' . $_SESSION['facebook_last_page'] . '";</script>';
        exit;
    }
    if (ym_request('loggedout') == 1) {
        wp_logout();
        $in_facebook = isset($_SESSION['in_facebook']) ? $_SESSION['in_facebook'] : FALSE;
        $in_facebook_page = isset($_SESSION['in_facebook_page']) ? $_SESSION['in_facebook_page'] : FALSE;
        session_destroy();
        session_start();
        $_SESSION['in_facebook'] = $in_facebook;
        $_SESSION['in_facebook_page'] = $in_facebook_page;
        $r = ym_fbook_oauth_go();
        //		echo $r . '<br />';
        $r = str_replace(array('loggedout=1&', 'loggedout=1'), '', $r);
        $r = str_replace(array(urlencode('loggedout=1&'), urlencode('loggedout=1')), '', $r);
        //		$_SESSION['ym_fb_auth_target'] = $r;
        $_SESSION['ym_fb_auth_target'] = str_replace(array(urlencode('loggedout=1&'), urlencode('loggedout=1'), 'loggedout=1'), '', $_SESSION['ym_fb_auth_target']);
        //		echo $r;
        //echo $_SESSION['ym_fb_auth_target'];
        //echo '<script type="text/javascript">top.location.href="' . $_SESSION['ym_fb_auth_target'] . '";</script>';
        echo '<script type="text/javascript">top.location.href="' . $r . '";</script>';
        exit;
    }
    // Ping check to see if facebook exists and is alive
    // Most commonly analytics
    if (ym_get('ymfbook')) {
        $_SESSION['in_facebook'] = 1;
    }
    if ($_SESSION['in_facebook']) {
        wp_enqueue_script('ym-fb', site_url('wp-content/plugins/ym_facebook/js/fb.js'), array('jquery'), YM_FB_PLUGIN_VERSION);
        wp_enqueue_style('ym-fb-login', site_url('wp-content/plugins/ym_facebook/css/ym_fbook_login.css'), array(), YM_FB_PLUGIN_VERSION);
    }
    // height controls
    if ($facebook_settings->iframe_size == 'scrollbars') {
        if ($facebook_settings->iframe_size_height) {
            define('YM_FBOOK_HEIGHT', 'FB.Canvas.setSize({height: ' . $facebook_settings->iframe_size_height . '});');
        } else {
            define('YM_FBOOK_HEIGHT', '');
            // height of window-ish
        }
    } else {
        define('YM_FBOOK_HEIGHT', 'FB.Canvas.setAutoResize();');
    }
    // width controls
    if (isset($_SESSION['in_facebook_page']) && $_SESSION['in_facebook_page']) {
        $width = 450;
    } else {
        $width = 600;
    }
    define('YM_FBOOK_WIDTH', $width);
    /********************************************/
    /* post or session
    	/********************************************/
    if (ym_post('signed_request', false)) {
        // landed in facebook from the outside world
        // store the request
        $_SESSION['facebook_signed_request'] = $_POST['signed_request'];
        // set in facebook here as we are defo. in facebook
        // cant do it on data uncode as we could be on the main site
        // using a wordpress side facebook like wall
        // for example
        $_SESSION['in_facebook'] = TRUE;
        // if in_facebook then redirect there
        // if in_facebook and in_facebook_page then go to page
        // if in_facebook_page only do nothing (as not in facebook)
        $_SESSION['facebook_signed_request'] = $_POST['signed_request'];
    }
    /********************************************/
    /* force
    	/********************************************/
    if ($facebook_settings->force_facebook && !$_SESSION['in_facebook']) {
        // force
        $_SESSION['in_facebook'] = 1;
        if ($facebook_settings->page_url) {
            $_SESSION['in_facebook_page'] = 1;
        }
        header('Location: ' . ym_fbook_oauth_go());
        //header('Location: ' . ($facebook_settings->page_url ? YM_FBOOK_PAGE_TARGET : YM_FBOOK_APP_TARGET));
        exit;
    }
    /********************************************/
    /* interupt for auth
    	/********************************************/
    // check for a get code
    if (ym_get('code')) {
        // landed with a code
        // oAuth return, validate
        // get token
        if ($_SESSION['in_facebook_page'] && $facebook_settings->page_url) {
            $url = 'https://facebook.com/' . $facebook_settings->page_url . '/';
        } else {
            $url = 'https://apps.facebook.com/' . $facebook_settings->canvas_url . '/';
        }
        if (!$_SESSION['ym_fb_auth_target']) {
            // no target
            ym_fbook_oauth_go();
        }
        // generate auth code
        //		$_SESSION['ym_fb_auth_target'] = str_replace(array(urlencode('loggedout=1&'), urlencode('loggedout=1'), 'loggedout=1&', 'loggedout=1'), '', $_SESSION['ym_fb_auth_target']);
        //			'&redirect_uri=' . urlencode($_SESSION['ym_fb_auth_target']) .
        $auth_code = '?client_id=' . YM_FBOOK_APPID . '&redirect_uri=' . urlencode($url) . '&client_secret=' . YM_FBOOK_SECRET . '&code=' . $_GET['code'];
        //		echo $auth_code;//exit;
        // exchange
        $facebook_auth = new Facebook('', $auth_code);
        // decode
        $auth = $facebook_auth->auth;
        $test = json_decode($auth);
        if ($test->error->message) {
            echo $test->error->message;
            ym_fbook_add_message(str_replace('_', ' ', $test->error->message));
            return;
        }
        parse_str($auth, $query);
        $_SESSION['facebook_oauth_token'] = $query['access_token'];
        $_SESSION['facebook_oauth_start'] = time();
        $_SESSION['facebook_oauth_expires'] = $query['expires'];
        // clean
        $_SESSION['ym_fb_auth_target'] = str_replace('code=' . ym_get('code'), '', $_SESSION['ym_fb_auth_target']);
        echo '<script type="text/javascript">top.location.href="' . $_SESSION['ym_fb_auth_target'] . '"</script>';
        unset($_SESSION['ym_fb_auth_target']);
        // and GO BABY GO!!!!!!!!!!!
        exit;
    }
    /********************************************/
    /* munch
    	/********************************************/
    if (isset($_SESSION['facebook_signed_request']) && $_SESSION['facebook_signed_request']) {
        // exisiting session
        // validate
        $data = facebook_uncode($_SESSION['facebook_signed_request']);
        if ($data) {
            // last control
            if (isset($_SESSION['facebook_use_last_page']) && $_SESSION['facebook_use_last_page']) {
                unset($_SESSION['facebook_use_last_page']);
                header('Location: ' . YM_FBOOK_LAST_PAGE);
                exit;
            }
            if (isset($data->page) && $data->page) {
                $_SESSION['facebook_page'] = $data->page;
                // defo in a page
                // should only occur on landing on the page
                $_SESSION['in_facebook_page'] = TRUE;
                // ALERT LANDING TRIGGER LANDING CONTROLLER
                if ($facebook_settings->page_landing && $_SERVER['REQUEST_URI'] != $facebook_settings->page_landing && $_POST['signed_request']) {
                    // somewhere to land
                    header('Location: /' . $facebook_settings->page_landing);
                    exit;
                }
                define('ym_fbphp_dev_in_page', TRUE);
            } else {
                define('ym_fbphp_dev_in_page', TRUE);
            }
            // landing control needed?
            if ($facebook_settings->canvas_landing && $_SERVER['REQUEST_URI'] != $facebook_settings->canvas_landing && $_POST['signed_request'] && !$_SESSION['facebook_has_landed'] && !$_SESSION['in_facebook_page']) {
                // landing control if the Root Page is requested
                header('Location: /' . $facebook_settings->canvas_landing);
                exit;
            }
            $_SESSION['facebook_has_landed'] = TRUE;
            // oauth
            $_SESSION['facebook_oauth_token'] = $data->oauth_token;
            $_SESSION['facebook_oauth_start'] = $data->issued_at;
            $_SESSION['facebook_oauth_expires'] = $data->expires;
        }
    } else {
        if (isset($_SESSION['facebook_oauth_token']) && $_SESSION['facebook_oauth_token']) {
            // we have a facebook session
        } else {
            // no session
            ym_fbook_do_template();
            return;
        }
    }
    // GIVE ME A CLIENT
    global $facebook_client;
    $facebook_client = new Facebook($_SESSION['facebook_oauth_token']);
    if (!$facebook_client->initok) {
        $facebook_client = FALSE;
    } else {
        // permissions check
        // check oauth granted match what we need
        // in case the game has changed.
        $permissions = $facebook_client->permissions();
        global $scopes;
        $scope_copy = $scopes;
        foreach ($scope_copy as $fbsetting => $entry) {
            if (isset($facebook_settings->{$fbsetting}) && $facebook_settings->{$fbsetting}) {
                // check presence
                if (isset($permissions->data[0]->{$entry}) && $permissions->data[0]->{$entry} == 1) {
                    unset($scope_copy[$fbsetting]);
                }
            } else {
                // not requested
                unset($scope_copy[$fbsetting]);
            }
        }
        if (count($scope_copy)) {
            add_action('ym_fbook_messages', 'ym_fbook_messages');
            add_action('template_redirect', 'ym_fbook_template');
            define('FBOOK_TEMPLATE_OVERRIDE', 'login');
            return;
        }
    }
    if ($facebook_client && !$data) {
        // build data
        $data = new stdClass();
        $data->user_id = $facebook_client->user_data->id;
        $data->locale = $facebook_client->user_data->locale;
    }
    // facebook user ID
    $_SESSION['facebook_user_id'] = $data->user_id;
    $_SESSION['locale'] = isset($data->locale) ? $data->locale : 'en_GB';
    // check facebook login
    if ($facebook_settings->force_facebook_auth && !$data->user_id) {
        // require login
        // redirect to facebook login
        // use template login template
        add_action('ym_fbook_messages', 'ym_fbook_messages');
        add_action('template_redirect', 'ym_fbook_template');
        define('FBOOK_TEMPLATE_OVERRIDE', 'login');
        return;
    }
    if (isset($data->id) && $data->id) {
        ym_fbook_has_oauth_expired();
    }
    // check wordpress login
    ym_fbook_maintain_wordpress();
    /*
    if ($_REQUEST['register'] == 1 && !$_SESSION['facebook_registering']) {
    	// need login.....
    	$_SESSION['facebook_use_last_page'] = 1;
    	$_SESSION['facebook_registering'] = 1;
    	unset($_SESSION['ym_facebook_me_cache']);
    	echo '<script type="text/javascript">top.location.href="' . ym_fbook_oauth_go() . '"</script>';
    	exit;
    }
    if ($_REQUEST['register'] == 1 && $_SESSION['facebook_registering']) {
    	// go register dammit
    	add_action('ym_fbook_messages', 'ym_fbook_messages');
    	add_action('template_redirect', 'ym_fbook_template');
    	define('FBOOK_TEMPLATE_OVERRIDE', 'register');
    	return;
    }
    */
    // Hidden Reg
    if ($facebook_settings->register_with_facebook_hidden && $_SESSION['facebook_user_id'] && !$_SESSION['wordpress_user_id']) {
        // not logged into WP
        // go hidden reg
        ym_fbook_hidden_register();
    }
    // action cases
    if (ym_request('dolink', false)) {
        // go for link
        $_SESSION['dolink'] = 1;
        echo '<script type="text/javascript">top.location.href="' . ym_fbook_oauth_go() . '"</script>';
        exit;
    }
    if (ym_session('dolink')) {
        if (!$_SESSION['facebook_user_id']) {
            header('Location: ' . ym_fbook_oauth_go());
            exit;
        }
        ym_fbook_dolink();
    }
    if (ym_request('dounlink')) {
        // unlink
        ym_fbook_dounlink();
    }
    ym_fbook_do_template();
}
Exemple #7
0
function ym_upgrade_buttons($return = false, $pack_id = false, $user_id = false)
{
    global $wpdb, $duration_str, $current_user, $ym_res, $ym_sys, $ym_packs;
    get_currentuserinfo();
    if (!$user_id) {
        $user_id = $current_user->ID;
    }
    if ($pack_id == 'all') {
        global $ym_packs;
        $html = '';
        foreach ($ym_packs->packs as $pack) {
            if (!$pack['hide_subscription']) {
                $html .= ym_upgrade_buttons(TRUE, $pack['id']);
            }
        }
        if ($return) {
            return $html;
        } else {
            echo $html;
            return;
        }
    }
    $html = '';
    $ym_home = get_option('siteurl');
    if (!$user_id) {
        $html = $ym_res->msg_header . __('Sorry but you must be logged in to upgrade your account', 'ym') . $ym_res->msg_footer;
    } else {
        $user_data = new YourMember_User($user_id);
        $account_type = ym_get_user_account_type(false, true);
        $packs = $ym_packs->packs;
        $trial_taken = get_user_meta($user_id, 'ym_trial_taken', TRUE);
        $active_modules = get_option('ym_modules');
        $modules_dir = YM_MODULES_DIR;
        $base = add_query_arg(array('ym_subscribe' => 1, 'ud' => 1, 'username' => $current_user->user_login), $ym_home);
        if ((!isset($_POST['submit']) || !isset($_POST['subs_opt'])) && !$pack_id) {
            // TODO: Does this code even run?
            $html = '<p class="message register">' . __('Choose an Account Type', 'ym') . '</p>';
            $html .= '<form action="" method="post" class="ym"><div style="clear: both; overflow: auto; padding-bottom: 10px;">';
            // RENDER2
            $packs_shown = 0;
            if ($existing_data = ym_request('ym_subscription')) {
                $default = $existing_data;
            } else {
                //				$default = ym_get_default_pack();
                $default = $user_data->pack_id;
            }
            $did_checked = FALSE;
            foreach ($packs as $pack) {
                if (!$pack['hide_subscription']) {
                    $html .= '<div class="ym_register_form_subs_row">
								<div class="ym_reg_form_pack_radio">
									<input type="radio" ';
                    if ($pack['id'] == $default && !$did_checked) {
                        $html .= 'checked="checked"';
                        $did_checked = TRUE;
                    }
                    $packs_shown++;
                    $html .= ' class="checkbox" id="ym_subscription_' . $pack['id'] . '" name="ym_subscription" value="' . $pack['id'] . '" />
							</div>
							<label for="ym_subscription_' . $pack['id'] . '" class="ym_subs_opt_label ym_reg_form_pack_name">' . ym_get_pack_label($pack['id']) . '</label>
						</div>';
                }
            }
            if (!$packs_shown) {
                $hide_label = true;
            } else {
                if (isset($entry['caption']) && $entry['caption']) {
                    $html .= '<div class="ym_clear">&nbsp;</div><div class="ym_register_form_caption">' . $entry['caption'] . '</div>' . $row;
                }
            }
            // END RENDER2
            if ($packs_shown) {
                //				$html .= '</div><input type="hidden" name="ref" value="'. md5($user_data->amount .'_'. $user_data->duration .'_'. $user_data->duration_type .'_'. $user_data->account_type) .'" />';
                $html .= '<p class="submit"><input type="submit" name="submit" value="' . __('Next &raquo;', 'ym') . '" /></p>';
            } else {
                $html .= '<p>' . __('Sorry there are currently no upgrade/downgrade options available to you.', 'ym') . '</p>';
            }
            $html .= '</form>';
        } else {
            if (!ym_post('subs_opt') && $pack_id != ym_post('ym_subscription')) {
                global $ym_res;
                $html = '<form action="" method="post" class="ym_upgrade_shortcode">';
                $html .= '<input type="hidden" name="ym_subscription" value="' . $pack_id . '" />';
                //				$html .= '<input type="hidden" name="ref" value="'. md5($user_data->amount .'_'. $user_data->duration .'_'. $user_data->duration_type .'_'. $user_data->account_type) .'" />';
                $html .= ym_get_pack_label($pack_id);
                $html .= '&nbsp;<a href="#nowhere" onClick="jQuery(this).parents(\'form\').submit();">Upgrade</a>';
                $html .= '</form>';
                return $html;
            } else {
                $pack = ym_get_pack_by_id($pack_id);
                $cost = $pack['cost'];
                if (!$pack_id) {
                    $html .= '<br /><table width="100%" cellpadding="3" cellspacing="0" border="0" align="center" class="form-table">';
                    if ($cost == 0 || $account_type == 'free') {
                        $html .= '<tr><th>' . __('Create a free account: ', 'ym') . ucwords($account_type) . '</th></tr>';
                    } else {
                        $html .= '<tr><th>' . __('Select Payment Gateway', 'ym') . '</th></tr>';
                        $html .= '<tr><th>' . ym_get_pack_label($pack['id']) . '</th></tr>';
                    }
                }
                if (count($active_modules)) {
                    $buttons_shown = array();
                    foreach ($active_modules as $module) {
                        if ($module == 'ym_free' && $pack['cost'] > 0) {
                            continue;
                        }
                        require_once $modules_dir . $module . '.php';
                        $obj = new $module();
                        $string = $obj->getButton($pack['id']);
                        if ($string) {
                            $buttons_shown[] = $module;
                            $html .= $string;
                        }
                        $string = false;
                        $obj = null;
                    }
                    if (count($buttons_shown) == 1) {
                        $module = array_pop($buttons_shown);
                        $form_code = '<div style="display:none;">' . $html . '</div>';
                        $js = 'document.forms["' . $module . '_form"].submit();';
                        $html = '  <html>
													<head>
														<title>Redirecting...</title>
														<script type="text/javascript">
															function load() {
																' . $js . '
															}
														</script>
													</head>
													<body onload="load();">';
                        $html .= '  <div style="color: #333333; font-size: 14px; margin: 30px 10px; font-family: tahoma; text-align: center; padding: 50px; border: 1px solid silver;">';
                        $html .= '  <div>' . __('You are being redirected. If this page does not refresh in 5 seconds then click', 'ym') . ' <a onclick="document.forms[\'' . $module . '_form\'].submit();">here</a>.</div>
											   <div style="margin-top: 10px;"><img alt="" src="' . YM_IMAGES_DIR_URL . 'loading.gif" /></div>';
                        $html .= '  </div>';
                        $html .= $form_code;
                        $html .= '	  </body>
												</html>';
                        echo $html;
                        die;
                    }
                } else {
                    $html .= __('There are no gateways available at this time.', 'ym');
                }
            }
        }
    }
    if ($return) {
        return $html;
    } else {
        echo $html;
    }
}
/*
* $Id: yss_content.php 1842 2012-02-01 14:26:14Z BarryCarlyon $
* $Revision: 1842 $
* $Date: 2012-02-01 14:26:14 +0000 (Wed, 01 Feb 2012) $
*/
$action = ym_request('task');
$date_format = get_option('date_format');
if (!get_option('yss_user_key') || !get_option('yss_secret_key')) {
    echo ym_start_box('Error');
    echo '<p>You need to provide your S3 User and Secret Keys, please visit the the Settings tab to do so.</p>';
    echo ym_end_box();
} else {
    if (in_array($action, array('stream', 'dload'))) {
        // distro select
        yss_s3_distribution($action, ym_request('id'));
    } else {
        if (in_array($action, array('add', 'edit'))) {
            yss_s3_edit($_REQUEST['id']);
        } else {
            if ($action == 'delete') {
                yss_s3_delete();
            }
            if (ym_post('submit_edit_s3')) {
                yss_s3_save();
            }
            yss_s3_list();
        }
    }
}
function yss_s3_distribution($type, $id)
Exemple #9
0
    function do_process()
    {
        $action = ym_request('action');
        if ($action == 'js') {
            header('Content-Type: text/javascript');
            ?>
jQuery(document).ready(function() {
	jQuery('.ym_stripe_button').click(function(event) {
		event.preventDefault();

		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="purchase_code"]').val(jQuery(this).parents('form').find('input[name="item_number"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="email"]').val(jQuery(this).parents('form').find('input[name="email"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="cost"]').val(jQuery(this).parents('form').find('input[name="cost"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="return_to"]').val(jQuery(this).parents('form').find('input[name="return_to"]').val());
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').find('input[name="coupon"]').val(jQuery(this).parents('form').find('input[name="coupon"]').val());

		jQuery('.ym_form').slideUp();
		jQuery('#ym_stripe_cc_form').slideDown();
	});

	Stripe.setPublishableKey('<?php 
            echo $this->api_key;
            ?>
');
	jQuery('#<?php 
            echo $this->code;
            ?>
_cc_form').live('submit', function(event) {
		event.preventDefault();
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_button').attr('disabled', 'disabled');
		jQuery('#<?php 
            echo $this->code;
            ?>
_error_handler').slideUp();
		Stripe.createToken({
			number: jQuery('#credit_card_number').val(),
			cvc: jQuery('#credit_card_cvc').val(),
			exp_month: jQuery('#expire_number_month').val(),
			exp_year: jQuery('#expire_number_year').val()
		}, stripeResponseHandler);
	});
});
function stripeResponseHandler(status, response) {
	if (response.error) {
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_button').removeAttr('disabled');
		jQuery('#<?php 
            echo $this->code;
            ?>
_error_handler').html(response.error.message + '<br />').slideDown();
	} else {
		var token = response['id'];
		jQuery('.ym_wipeme').each(function() {
			jQuery(this).val('');
		});
		jQuery('#<?php 
            echo $this->code;
            ?>
_cc_form').slideUp();
		jQuery('#<?php 
            echo $this->code;
            ?>
_status').slideDown();
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_button').attr('disabled', 'disabled');
		jQuery('<input type="hidden" name="stripeToken" value="' + token + '" />').appendTo('#<?php 
            echo $this->code;
            ?>
_submit_form');
		jQuery('#<?php 
            echo $this->code;
            ?>
_submit_form').submit();
	}
}

jQuery(document).ready(function() {
	var stripebuynowtarget = '.<?php 
            echo $this->code;
            ?>
_post_purchase_button';
	var stripedoforms = false;
	if (!jQuery(stripebuynowtarget).size()) {
		stripebuynowtarget = '.<?php 
            echo $this->code;
            ?>
_bundle_purchase_button';
		stripedoforms = true;
	}
	jQuery(stripebuynowtarget).click(function(event) {
		event.preventDefault();

		if (stripedoforms) {
			jQuery('.ym_form').slideUp();
		}

		jQuery('<?php 
            echo $this->code;
            ?>
_cc_form').slideUp(function() {
			jQuery(this).remove();
		});

		var purchase_code = jQuery(this).parents('form').find('input[name="item_number"]').val();
		var email = jQuery(this).parents('form').find('input[name="email"]').val();
		var cost = jQuery(this).parents('form').find('input[name="cost"]').val();
		var return_to = jQuery(this).parents('form').find('input[name="return_to"]').val();

		jQuery(this).parents('.<?php 
            echo $this->code;
            ?>
_ppp_holder').slideUp(function() {
			jQuery(this).html(
				'<form action="" method="post" id="<?php 
            echo $this->code;
            ?>
_cc_form" class="like_form" autocomplete="off">'
				+ '<fieldset>'
				+ '<div id="<?php 
            echo $this->code;
            ?>
_error_handler" style="display: none;"></div>'
				+ '<label for="credit_card_number"><?php 
            _e('Credit Card Number', 'ym');
            ?>
<br /><input type="text" name="credit_card_number" id="credit_card_number" class="ym_wipeme" /></label><br />'
				+ '<label for="credit_card_cvc"><?php 
            _e('Credit Card CCV', 'ym');
            ?>
<br /><input type="text" name="credit_card_cvc" id="credit_card_cvc" class="ym_wipeme" /></label><br />'
				+ '<label for="expiration">Expiration (MM/YYYY)<br /><input type="text" size="2" maxlength="2" name="expire_number_month" id="expire_number_month" class="ym_wipeme" /> / <input type="text" size="4" maxlength="4" name="expire_number_year" id="expire_number_year" class="ym_wipeme" /></label><br />'
				+ '<br /><input type="submit" id="<?php 
            echo $this->code;
            ?>
_submit_button" value="<?php 
            _e('Pay', 'ym');
            ?>
" />'
				+ '</fieldset>'
				+ '</form>'
				+ '<form action="<?php 
            echo site_url('?ym_process=' . $this->code . '&action=start');
            ?>
" method="post" id="<?php 
            echo $this->code;
            ?>
_submit_form" style="display: none;">'
				+ '<input type="hidden" name="purchase_code" value="' + purchase_code + '" />'
				+ '<input type="hidden" name="email" value="' + email + '" />'
				+ '<input type="hidden" name="cost" value="' + cost + '" />'
				+ '<input type="hidden" name="return_to" value="' + return_to + '" />'
				+ '<div id="<?php 
            echo $this->code;
            ?>
_status" style="display: none;"><?php 
            _e('Loading', 'ym');
            ?>
</div>'
				).slideDown();
		});
	});
});
<?php 
            exit;
        } else {
            if ($action == 'start') {
                $charge = FALSE;
                $code = ym_post('purchase_code', FALSE);
                $token = ym_post('stripeToken', FALSE);
                $email = ym_post('email');
                if (!$token || !$code) {
                    echo '<p>An Error Occurred (a)</p>';
                    exit;
                } else {
                    list($buy, $what, $id, $user_id) = explode('_', $code);
                    // plan ID Not to contain user ID
                    $plan_id = $buy . '_' . $what . '_' . $id;
                    if ($what == 'subscription') {
                        $pack = ym_get_pack_by_id($id);
                        if ($pack['num_cycles'] != 1) {
                            // test plan exist
                            $r = $this->sync_packages($plan_id);
                            if (!$r) {
                                echo '<p>An Error Occurred in Sync</p>';
                                exit;
                            }
                            // got this far Go for Subscribe
                            $subscribe = array('card' => $token, 'plan' => $plan_id, 'email' => $email);
                            // trial check
                            if ($pack['trial_on'] == 1) {
                                // trial
                                $cost_check = $pack['trial_cost'] * 100;
                                if ($cost_check) {
                                    // paid for trial
                                    // issue charge
                                    $charge = array('amount' => $cost_check, 'currency' => 'usd', 'description' => 'Trial: ' . $plan_id);
                                }
                            }
                            // coupon?
                            if ($pack['cost'] != ym_post('cost')) {
                                // coupon in use
                                // nasty
                                $coupon = ym_post('coupon', FALSE);
                                if ($coupon) {
                                    $test = $this->sync_coupons(substr($coupon, 3));
                                    if ($test) {
                                        $subscribe['coupon'] = $coupon;
                                    } else {
                                        echo '<p>Coupon Sync Failed</p>';
                                        exit;
                                    }
                                } else {
                                    // or hacking attempt
                                    echo '<p>Unable to Match Coupon</p>';
                                    exit;
                                }
                            }
                            // check for customer exist
                            $create = TRUE;
                            $customer_id = get_user_meta($user_id, 'ym_stripe_customer_id', TRUE);
                            if ($customer_id) {
                                list($r_code, $response) = $this->stripe_api_request('customers/' . $customer_id);
                                if ($r_code == 200) {
                                    // check response
                                    if (isset($response->deleted) && $response->deleted == 1) {
                                        // deleted
                                    } else {
                                        // exists
                                        $create = FALSE;
                                    }
                                }
                            }
                            if ($create) {
                                list($r_code, $response) = $this->stripe_api_request('customers', 'POST', $subscribe);
                                // store ID
                                if ($r_code == 200) {
                                    update_user_meta($user_id, 'ym_stripe_customer_id', $response->id);
                                }
                            } else {
                                // update
                                $subscribe['prorate'] = $this->prorate;
                                unset($subscribe['email']);
                                //email not accepted for sub change
                                list($r_code, $response) = $this->stripe_api_request('customers/' . $customer_id . '/subscription', 'POST', $subscribe);
                            }
                            if ($r_code == 200) {
                                // leave to IPN for Prorate and/or start
                                if (ym_post('return_to', FALSE)) {
                                    header('Location: ' . ym_post('return_to'));
                                    exit;
                                }
                                $this->redirectlogic($pack, TRUE);
                                exit;
                            } else {
                                echo '<p>An Error Occurred (d: ' . $r_code . ': ' . $response->error->message . ')</p>';
                            }
                            exit;
                        } else {
                            // single occurrence subscription
                            $charge = array('amount' => ym_post('cost', 0) * 100, 'currency' => 'usd', 'description' => $plan_id);
                        }
                    } else {
                        //if ($what == 'post' || $what == 'bundle') {
                        // post
                        // TODO: temporary hack
                        $charge = array('amount' => ym_post('cost', 0) * 100, 'currency' => 'usd', 'description' => $plan_id);
                        //				} else {
                        // unknown purchase!!!!
                    }
                    // single charge
                    if ($charge) {
                        // customer exist?
                        $create = TRUE;
                        $customer_id = get_user_meta($user_id, 'ym_stripe_customer_id', TRUE);
                        if ($customer_id) {
                            list($r_code, $response) = $this->stripe_api_request('customers/' . $customer_id);
                            if ($r_code == 200) {
                                // check response
                                if (isset($response->deleted) && $response->deleted == 1) {
                                    // deleted
                                } else {
                                    // exists
                                    $create = FALSE;
                                }
                            }
                        }
                        if ($create) {
                            $customer = array('card' => $token, 'email' => $email);
                            list($r_code, $response) = $this->stripe_api_request('customers', 'POST', $customer);
                            // store ID
                            if ($r_code == 200) {
                                update_user_meta($user_id, 'ym_stripe_customer_id', $response->id);
                                $customer_id = $response->id;
                            }
                        }
                        if ($customer_id) {
                            // commence charge
                            $charge['customer'] = $customer_id;
                            list($r_code, $response) = $this->stripe_api_request('charges', 'POST', $charge);
                            if ($r_code == 200) {
                                if ($response->paid == 1) {
                                    $this->common_process($code, $charge['amount'], TRUE, FALSE);
                                    if ($what == 'post') {
                                        $pack = array('ppp' => 1, 'post_id' => $id);
                                    } else {
                                        if ($what == 'bundle') {
                                            $pack = array('ppp' => 1, 'ppp_pack_id' => $id);
                                        } else {
                                            $pack = $id;
                                        }
                                    }
                                    if (ym_post('return_to', FALSE)) {
                                        header('Location: ' . ym_post('return_to'));
                                        exit;
                                    }
                                    $this->redirectlogic($pack, TRUE);
                                } else {
                                    echo 'Failed';
                                }
                            } else {
                                echo '<p>An Error Occurred (f: ' . $r_code . ': ' . $response->error->message . ')</p>';
                            }
                        } else {
                            echo '<p>An Error Occurred (e: ' . $r_code . ': ' . $response->error->message . ')</p>';
                        }
                    }
                }
                exit;
            } else {
                if ($action == 'process') {
                    // process a web hook
                    if (function_exists('http_get_request_body')) {
                        $payload = http_get_request_body();
                    } else {
                        $payload = @file_get_contents('php://input');
                    }
                    $_REQUEST = json_decode($payload, TRUE);
                    // stash for YM_IPN Array
                    $payload = json_decode($payload);
                    if (!$payload) {
                        header('HTTP/1.1 400 Bad Request');
                        echo 'Error in IPN. No Data Recieved';
                    } else {
                        $this->packet = $payload;
                        list($type, $result) = explode('.', $payload->type, 2);
                        $escape_types = array('ping', 'plan');
                        $escape_results = array('created', 'customer.updated');
                        if (in_array($type, $escape_types) || in_array($result, $escape_results)) {
                            echo 'ohai';
                            exit;
                        }
                        $complete = FALSE;
                        $customer_id = isset($payload->data->object->customer) ? $payload->data->object->customer : '';
                        $email = isset($payload->data->object->email) ? $payload->data->object->email : '';
                        $code = isset($payload->data->object->lines->subscriptions[0]->plan->id) ? $payload->data->object->lines->subscriptions[0]->plan->id : '';
                        $cost = isset($payload->data->object->lines->subscriptions[0]->amount) ? $payload->data->object->lines->subscriptions[0]->amount : '';
                        global $wpdb;
                        $user_id = $wpdb->get_var('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key = \'ym_stripe_customer_id\' AND meta_value = \'' . $customer_id . '\'');
                        if (!$user_id && $email) {
                            $user = get_user_by('email', $email);
                            $user_id = $user->ID;
                        }
                        if (!$user_id) {
                            // fail user match
                            echo 'OK';
                            exit;
                        }
                        if ($type == 'invoice') {
                            $cost = $payload->data->object->lines->subscriptions[0]->amount / 100;
                            //fron cents to dollars
                            $invoice_id = $payload->data->object->id;
                            if ($result == 'payment_succeeded') {
                                $complete = TRUE;
                            }
                            if ($complete) {
                                $code = $payload->data->object->lines->subscriptions[0]->plan->id;
                                list($buy, $what, $id) = explode('_', $code);
                                $last_invoice_id = get_user_meta($user_id, 'ym_last_stripe_id', TRUE);
                                if ($last_invoice_id == $invoice_id) {
                                    // double complete packet.....
                                    header('HTTP/1.1 200 OK');
                                    echo 'Double Packet';
                                    exit;
                                }
                                update_user_meta($user_id, 'ym_last_stripe_id', $invoice_id);
                                update_user_meta($user_id, 'ym_stripe_customer_id', $customer_id);
                            }
                            // append User ID to the code
                            $code .= '_' . $user_id;
                        } else {
                            if ($type == 'customer' && $result == 'deleted') {
                                // customer deleted
                                $cost = 0;
                                $complete = FALSE;
                                $code = $code ? $code . '_' . $user_id : 'buy_subscription_cancel_' . $user_id;
                                delete_user_meta($user_id, 'ym_stripe_customer_id');
                            }
                        }
                        // ignore anything else
                        if ($code && strlen($cost)) {
                            $this->common_process($code, $cost, $complete);
                        } else {
                            // skippy the bush kagaroo
                            header('HTTP/1.1 200 OK');
                            echo 'ok';
                            exit;
                        }
                    }
                } else {
                    echo '<p>
			An Error Has Occured
			<br />
			And the Payment Flow has exited abnormally
			</p><p>Debug Information</p>';
                    echo '<pre>' . print_r($_REQUEST) . '</pre>';
                    exit;
                }
            }
        }
    }
<?php

if (ym_request('do_munch') && ym_request('offset')) {
    $max = ym_request('max');
    $offset = ym_request('offset');
    $post_ids = explode(',', ym_request('post_ids'));
    $posts = ym_bundle_get_some_posts($offset, $post_ids, $max);
    $total = count($posts);
    if (!$total) {
        echo '<tr><td>' . __('No Posts', 'ym') . '</td></tr>';
    }
    $more = array();
    foreach ($posts as $post) {
        $line = '<tr>';
        $line .= '<td>(' . $post->ID . ' - ' . $post->post_type . ') ' . addslashes($post->post_title) . '</td>';
        $line .= '<td><input type="checkbox" name="post_ids[]" value="' . $post->ID . '" /></td>';
        $line .= '</tr>';
        $more[] = $line;
    }
    echo json_encode($more);
    exit;
}
echo '<div class="wrap" id="poststuff">';
ym_bundle_update();
echo __('<p>Bundles are groups of purchasable posts which can be sold as one item. Previously known as Pay Per Post Packs</p>', 'ym');
if ($bundle_id = ym_post('bundle_id')) {
    $bundle = ym_get_bundle($bundle_id);
    if (ym_post('edit')) {
        echo ym_start_box(__('Edit Bundle: "', 'ym') . $bundle->name . '"');
        ym_bundle_form($bundle, __('Update Bundle', 'ym'));
        echo '<form action="" method="post"><input class="button-secondary" type="submit" name="submit" value="' . __('Cancel Edit Bundle', 'ym') . '" /></form>';
            } else {
                if ($data) {
                    // error
                    echo $data;
                } else {
                    echo '<p>No Distributions Found</p>';
                }
            }
            break;
        default:
            echo 'Nothing to do: ' . $task;
    }
    exit;
}
global $yss_cloudfront;
$task = ym_request('cloudfronttask');
if ($task) {
    switch ($task) {
        case 'createdistribution':
            $type = ym_post('dist_type');
            $oai = ym_post('oai');
            $origin = ym_post('origin');
            //bucket
            if ($oai == 'new') {
                // make a new OAI
                $data = $yss_cloudfront->create_oai();
                if (is_array($data)) {
                    $oai = $data['id'];
                } else {
                    echo '<div id="message" class="error"><p>OIA: ' . $data . '</p></div>';
                    return;
 function fail_process()
 {
     $action = ym_request('action');
     $state = ym_get('state');
     if ($action == 'confirm' && $state) {
         list($buy, $what, $id, $user_id) = explode('_', $state);
         // get reg data
         $info = get_userdata($user_id);
         $reg_date = strtotime($info->user_registered);
         $new = FALSE;
         if ($reg_date > time() - 86400) {
             // reg today
             $new = TRUE;
         }
         // return from gateway
         // go pending
         if ($this->new_grace && $new || !$new) {
             // apply subscription
             $data['new_status'] = YM_STATUS_GRACE;
             $data['status_str'] = __('Grace Entered, GoCardless Payment Pending', 'ym');
             $data['expire_date'] = time() + 86400 * $this->grace_limit;
         } else {
             $data['new_status'] = YM_STATUS_PENDING;
             $data['status_str'] = __('GoCardless Payment Pending', 'ym');
         }
         return $data;
     }
 }
function ym_download_list()
{
    get_currentuserinfo();
    global $ym_dl_db, $wpdb, $date_format, $current_user, $ym_upload_root;
    if (!is_dir($ym_upload_root)) {
        if (@mkdir($ym_upload_root, 0664)) {
            ym_display_message(__('The uploads directory did not exist so it was created and the permissions set to 664. Please make sure to update these permissions if you are not happy with them.'));
        } else {
            ym_display_message(__('The uploads directory does not exist and it could not be created. Please make sure that "' . $ym_upload_root . '" is present and writeable by PHP before adding any downloads.', 'ym'), 'error');
        }
    }
    $header_style = 'border-bottom: 1px solid silver; font-weight: bold;';
    $downloadurl = get_option('ym_dl_url');
    $downloadtype = get_option('ym_dl_type');
    $sort = ym_request('sort', "title");
    $sql = 'SELECT *
			FROM ' . $ym_dl_db . ' 
			ORDER BY ' . $sort;
    $download = $wpdb->get_results($sql);
    echo '<p>' . __('Downloads can be associated with pages and posts. When associated, they take on the page or post permissions including post purchased. Non associated downloads are accessible by all.', 'ym') . '</p>';
    echo ym_start_box('All Downloads');
    if (!is_writeable($ym_upload_root)) {
        ym_display_message(__('The uploads directory is not writeable by PHP and therefore anything uploaded using this tool will fail. Please set the permissions and then refresh this page to see if you have been successful.', 'ym'), 'error');
    }
    echo '			<table style="width: 100%;" cellspacing="0" class="ym_table">
						<tr>
							<th><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=id">' . __('ID', "ym") . '</a></td>
							<th><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=title">' . __('Title', "ym") . '</a></td>
							<th><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=filename">' . __('File', "ym") . '</a></td>
							<th style="width: 150px; text-align: center;">' . __('Limited Access', "ym") . '</td>
							<th style="width: 140px; text-align: center;">' . __('File Exists?', "ym") . '</td>
							<th style="width: 200px;"><a href="' . YM_ADMIN_URL . '&ym_page=ym-content-downloads&sort=postDate">' . __('Posted', "ym") . '</a></td>
							<th style="width: 130px;">' . __('Action', "ym") . '</td>
						</tr>';
    if ($download) {
        foreach ($download as $d) {
            $date = date($date_format, strtotime($d->postDate));
            $path = get_option('siteurl') . "/wp-content/uploads/";
            $file = str_replace($path, "", $d->filename);
            $links = explode("/", $file);
            $file = end($links);
            $user = get_userdata($d->user);
            $abs_file = ym_get_abs_file($d->filename);
            $edit_link = YM_ADMIN_URL . '&ym_page=ym-content-downloads&action=edit&id=' . $d->id . '&sort=' . $sort;
            $delete_link = YM_ADMIN_URL . '&ym_page=ym-content-downloads&action=delete&id=' . $d->id . '&sort=' . $sort;
            echo '	<tr>
						<td>' . $d->id . '</td>
						<td>' . $d->title . '</td>
						<td>' . $file . '</td>
						<td style="text-align:center; font-weight: bold;">
							' . ($d->members ? __('<span style="color: green;">Yes</span>', 'ym') : __('<span style="color: red;">No</span>', 'ym')) . '
						</td>
						<td style="text-align:center; font-weight: bold;">
							' . (file_exists($abs_file) ? __('<span style="color: green;">Yes</span>', 'ym') : __('<span style="color: red;">No</span>', 'ym')) . '
						</td>
						<td>' . $date . ' by ' . $current_user->user_login . '</td>
						<td style="line-height: 2em;">
							<a class="button" href="' . $edit_link . '">' . __('Edit', 'ym') . '</a>
							<a class="button" href="' . $delete_link . '">' . __('Delete', 'ym') . '</a>
						</td>
					</tr>';
        }
    } else {
        echo '	<tr>
					<td colspan="6">' . __('No downloads have been added yet.', "ym") . '</td>
				</tr>';
    }
    echo '			</table>';
    echo '	<p class="submit">
				<form action=""	method="post" id="ym_dl_add" name="add_download">
					<input type="hidden" name="action" value="add" />
					<input type="submit" class="button" name="" value="' . __('Add New Download', "ym") . '" />
				</form>
			</p>';
    echo ym_end_box();
}
Exemple #14
0
<?php

$user_id = ym_request('user_id');
$user_ID = $user_id;
$action = ym_request('action');
global $_wp_admin_css_colors;
wp_reset_vars(array('action', 'redirect', 'profile', 'user_id'));
$user_id = (int) $user_id;
$current_user = wp_get_current_user();
if (!defined('IS_PROFILE_PAGE')) {
    define('IS_PROFILE_PAGE', $user_id == $current_user->ID);
}
if (!$user_id && IS_PROFILE_PAGE) {
    $user_id = $current_user->ID;
} elseif (!$user_id && !IS_PROFILE_PAGE) {
    wp_die(__('Invalid user ID.'));
} elseif (!get_userdata($user_id)) {
    wp_die(__('Invalid user ID.'));
}
wp_enqueue_script('user-profile');
$title = IS_PROFILE_PAGE ? __('Profile') : __('Edit User');
$user_can_edit = current_user_can('edit_posts') || current_user_can('edit_pages');
/**
 * Optional SSL preference that can be turned on by hooking to the 'personal_options' action.
 *
 * @since 2.7.0
 *
 * @param object $user User data object
 */
if (!function_exists('use_ssl_preference')) {
    function use_ssl_preference($user)
Exemple #15
0
                        if ($results_count > 0) {
                            $result_message = $result_message ? $result_message : __('%s Users Updated', 'ym');
                            $result_message = sprintf($result_message, $results_count);
                        }
                        if ($result_message) {
                            echo ym_display_message($result_message);
                        }
                    }
                }
            }
        }
    }
}
// security alert
wp_set_current_user($admin_user->ID);
$ym_admin_ym_members_page_limit = ym_request('ym_page_limit', get_option('ym_admin_ym_members_page_limit', 50));
// load filters
$filters = get_option('ym_admin_ym_members_filters', array());
$filters['by_option'] = isset($filters['by_option']) ? $filters['by_option'] : '';
$filters['by_text'] = isset($filters['by_text']) ? $filters['by_text'] : '';
$filters['order_by'] = isset($filters['order_by']) ? $filters['order_by'] : 'login';
$filters['order_by_direction'] = isset($filters['order_by_direction']) ? $filters['order_by_direction'] : 'ASC';
if ($task == 'forward_a_page') {
    $page++;
} else {
    if ($task == 'back_a_page' && $page > 0) {
        $page--;
    }
}
$offset = $page * $ym_admin_ym_members_page_limit;
$args = array('number' => $ym_admin_ym_members_page_limit, 'offset' => $offset, 'exclude' => array($admin_user->ID, 1), 'orderby' => str_replace('exposed_', '', $filters['order_by']), 'order' => $filters['order_by_direction']);
Exemple #16
0
function ymfire_admin_page()
{
    global $wpdb, $firetypes, $saletypes, $ym_formgen;
    $firesale = ym_request('firesale');
    $months = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    echo '<div class="wrap" id="poststuff">';
    $fire_id = ym_request('fire_id');
    $tier_id = ym_request('tier_id');
    if ($firesale == 'toggle') {
        $firesale = '';
        if ($fire_id) {
            $sql = 'SELECT fire_enable FROM ' . $wpdb->ym_app_models . ' WHERE fire_id = ' . $fire_id;
            $enabled = $wpdb->get_var($sql);
            $enabled = $enabled ? 0 : 1;
            $sql = 'UPDATE ' . $wpdb->ym_app_models . ' SET fire_enable = ' . $enabled . ' WHERE fire_id = ' . $fire_id;
            $wpdb->query($sql);
        }
    } else {
        if ($firesale == 'delete') {
            $firesale = '';
            if ($fire_id) {
                $wpdb->query('DELETE FROM ' . $wpdb->ym_app_models . ' WHERE fire_id = ' . $fire_id);
                $wpdb->query('DELETE FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_id = ' . $fire_id);
            }
            if ($tier_id) {
                $wpdb->query('DELETE FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_tier_id = ' . $tier_id);
            }
        } else {
            if ($firesale == 'enable') {
                // enabling a tier
                $sql = 'SELECT * FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_tier_id = ' . $tier_id;
                $thetier = $wpdb->get_results($sql);
                $thetier = $thetier[0];
                $fire_id = $thetier->fire_id;
                $tier_order = $thetier->fire_order;
                // reoder (order by)
                $tiers = array();
                foreach (ym_firesale_get_all_tiers($fire_id) as $tier) {
                    $tiers[$tier->fire_order] = $tier;
                }
                unset($tiers[$tier_order]);
                array_unshift($tiers, $thetier);
                foreach ($tiers as $order => $tier) {
                    $sql = 'UPDATE ' . $wpdb->ym_app_models_tiers . ' SET fire_order = ' . $order . ' WHERE fire_tier_id = ' . $tier->fire_tier_id;
                    $wpdb->query($sql);
                }
                echo '<p>Tier Order was updated, if the Pricing Model is not active, it has not been activated yet</p>';
                $firesale = '';
            }
        }
    }
    if ($firesale == 'newtier') {
        $fire_id = ym_post('ym_firesale_add_post_tiers_fire_id');
        $fire_id = str_replace('firesale_', '', $fire_id);
        // put to end
        $sql = 'SELECT fire_order FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_id = ' . $fire_id . ' ORDER BY fire_order DESC LIMIT 1';
        $order = $wpdb->get_var($sql);
        if ($order) {
            $order++;
        } else {
            $order = 0;
        }
        $fire_tiers = array();
        $limit_bys = ym_post('ym_new_firesale_limit_by');
        $limit_sales = ym_post('ym_new_firesale_limit_sales');
        $limit_dates = ym_post('ym_date_ym_new_firesale_limit_time');
        $limit_months = ym_post('ym_month_ym_new_firesale_limit_time');
        $limit_years = ym_post('ym_year_ym_new_firesale_limit_time');
        $limit_hours = ym_post('ym_hour_ym_new_firesale_limit_time');
        $limit_mins = ym_post('ym_min_ym_new_firesale_limit_time');
        $limit_by_hours = ym_post('ym_new_firesale_limit_hours');
        foreach (ym_post('ym_new_firesale_price') as $tier_price) {
            $fire_tiers[] = array('tier_price' => $tier_price, 'tier_limit_by' => $limit_bys[0], 'tier_limit_sales' => $limit_sales[0], 'tier_limit_time' => strtotime($limit_dates[0] . ' ' . $months[$limit_months[0]] . ' ' . $limit_years[0] . ' ' . $limit_hours[0] . ':' . $limit_mins[0]), 'tier_limit_hours' => $limit_by_hours[0]);
        }
        foreach ($fire_tiers as $tier) {
            $limit_var = 0;
            switch ($tier['tier_limit_by']) {
                case 2:
                    // hours
                    $limit_by = 2;
                    $limit_var = $tier['tier_limit_hours'];
                    break;
                case 1:
                    // time
                    $limit_by = 1;
                    $limit_var = $tier['tier_limit_time'];
                    break;
                case 0:
                default:
                    //sales
                    $limit_by = 0;
                    $limit_var = $tier['tier_limit_sales'];
            }
            $sql = 'INSERT INTO ' . $wpdb->ym_app_models_tiers . '(fire_id, fire_price, fire_limit_by, fire_limit_var, fire_order)
					VALUES (
						' . $fire_id . ',
						\'' . $tier['tier_price'] . '\',
						' . $limit_by . ',
						' . $limit_var . ',
						' . $order . '
					)';
            $wpdb->query($sql);
            echo ym_start_box('Pricing Models');
            if ($wpdb->insert_id) {
                echo '<div class="message" id="success"><p>Tier Added</p></div>';
            } else {
                echo '<div class="message" id="error"><p>Tier was not added</p></div>';
            }
            echo ym_end_box();
        }
        echo '<meta http-equiv="refresh" content="3;' . YM_PPP_ADMIN_URL . '" />';
    }
    if ($firesale == 'edit') {
        echo ym_start_box('Pricing Models');
        $tier_data = 'SELECT * FROM ' . $wpdb->ym_app_models_tiers . ' WHERE fire_tier_id = ' . $tier_id;
        $tier_data = $wpdb->get_results($tier_data);
        if ($tier_data[0]) {
            $tier_data = $tier_data[0];
            //editing a tier
            echo '<form action="" method="post">
					<fieldset>';
            echo '
<input type="hidden" name="firesale" value="edittier" />
<input type="hidden" name="tier_id" value="' . $tier_id . '"/>
';
            echo '<table>';
            $ym_formgen->render_form_table_text_row('Price', 'ym_new_firesale_price[]', $tier_data->fire_price, 'Price for this Tier');
            $ym_formgen->render_combo_from_array_row('Limit By', 'ym_new_firesale_limit_by[]', $saletypes, $tier_data->fire_limit_by, 'What kind of Tier');
            $ym_formgen->render_form_table_text_row('Limit By Sales', 'ym_new_firesale_limit_sales[]', !$tier_data->fire_limit_by ? $tier_data->fire_limit_var : '', 'Tier ends after this many sales of this Tier');
            $ym_formgen->render_form_table_datetime_picker_row('Limit By Time', 'ym_new_firesale_limit_time[]', $tier_data->fire_limit_by ? $tier_data->fire_limit_var : '', 'Tier ends at this date');
            $ym_formgen->render_form_table_text_row('Hours', 'ym_new_firesale_limit_hours[]', $tier_data->fire_limit_by == 2 ? $tier_data->fire_limit_var : '', 'Expire Tier this many hours after it starts');
            echo '<tr><td colspan="5" style="border-top: 1px solid grey;">&nbsp;</td></tr>';
            echo '</table>';
            echo '
				<p class="submit" style="text-align: right;">
					<input type="submit" value="' . __('Update Pricing Model Tier', 'ym') . ' &raquo;" />
				</p>';
            echo '</fieldset></form>';
        } else {
            echo '<p>Could not find that Tier</p>';
            $firesale = '';
        }
        echo ym_end_box();
    }
    if ($firesale == 'edittier') {
        $fire_tiers = array();
        $limit_bys = ym_post('ym_new_firesale_limit_by');
        $limit_sales = ym_post('ym_new_firesale_limit_sales');
        $limit_dates = ym_post('ym_date_ym_new_firesale_limit_time');
        $limit_months = ym_post('ym_month_ym_new_firesale_limit_time');
        $limit_years = ym_post('ym_year_ym_new_firesale_limit_time');
        $limit_hours = ym_post('ym_hour_ym_new_firesale_limit_time');
        $limit_mins = ym_post('ym_min_ym_new_firesale_limit_time');
        $limit_by_hours = ym_post('ym_new_firesale_limit_hours');
        foreach (ym_post('ym_new_firesale_price') as $tier_price) {
            $fire_tiers[] = array('tier_price' => $tier_price, 'tier_limit_by' => $limit_bys[0], 'tier_limit_sales' => $limit_sales[0], 'tier_limit_time' => strtotime($limit_dates[0] . ' ' . $months[$limit_months[0]] . ' ' . $limit_years[0] . ' ' . $limit_hours[0] . ':' . $limit_mins[0]), 'tier_limit_hours' => $limit_by_hours[0]);
        }
        foreach ($fire_tiers as $tier) {
            $limit_var = 0;
            switch ($tier['tier_limit_by']) {
                case 2:
                    // hours
                    $limit_by = 2;
                    $limit_var = $tier['tier_limit_hours'];
                    break;
                case 1:
                    // time
                    $limit_by = 1;
                    $limit_var = $tier['tier_limit_time'];
                    break;
                case 0:
                default:
                    //sales
                    $limit_by = 0;
                    $limit_var = $tier['tier_limit_sales'];
            }
            $data = array('fire_price' => $tier['tier_price'], 'fire_limit_by' => $limit_by, 'fire_limit_var' => $limit_var);
            $wpdb->update($wpdb->ym_app_models_tiers, $data, array('fire_tier_id' => $tier_id));
            echo ym_start_box('Pricing Models');
            if ($wpdb->rows_affected) {
                echo '<p>Tier Updated</p>';
            } else {
                echo '<p>Tier was not updated</p>';
            }
            echo ym_end_box();
        }
        echo '<meta http-equiv="refresh" content="3;' . YM_PPP_ADMIN_URL . '" />';
    }
    if (empty($firesale)) {
        echo '<div style="width: 43%; float: left;">';
        echo ym_start_box('Pricing Models');
        $firesales = ym_firesale_get_all();
        echo '<h2>All Pricing Models</h2>';
        echo '<p>Click the Link to enable/disable</p>';
        echo '<table style="width: 100%;">';
        echo '<tr><th>Pricing Model Name</th><th>Type</th><th>Tiers</th><th>Enabled</th><th>Edit</th><th>Delete</th></tr>';
        foreach ($firesales as $firesale) {
            if ($firesale->fire_id) {
                echo '<tr>';
                echo '<td>(' . $firesale->fire_id . ')' . $firesale->fire_name . '</td>';
                echo '<td style="text-align: center;">' . $firetypes[$firesale->fire_type] . '</td>';
                echo '<td style="text-align: center;"><a href="#showtiers" class="ym_showtiers" id="tiers_' . $firesale->fire_id . '">' . $firesale->tiers . '</a></td>';
                echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=toggle&fire_id=' . $firesale->fire_id . '">' . ($firesale->fire_enable ? 'Yes' : 'No') . '</a></td>';
                //					echo '<td style="text-align: center;"><a href="admin.php?page=' . YM_ADMIN_DIR . 'ym-index.php&ym_page=ym-other&action=ym_app&firesale=edit&fire_id=' . $firesale->fire_id . '">E</a></td>';
                echo '<td style="text-align: center;"><a href="#addtier" class="ym_firesale_add_post_tier" id="firesale_' . $firesale->fire_id . '">Add Tier</a></td>';
                echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=delete&fire_id=' . $firesale->fire_id . '">X</a></td>';
                echo '</tr>';
                foreach (ym_firesale_get_all_tiers($firesale->fire_id) as $tier) {
                    echo '<tr style="display: none;" class="tiers_' . $firesale->fire_id . '">';
                    echo '<td style="text-align: center;">ID: ' . $tier->fire_tier_id . ' Tier: ' . $tier->fire_order . '</td>';
                    echo '<td style="text-align: center;">' . $saletypes[$tier->fire_limit_by] . '(' . ($tier->fire_limit_by == 1 ? date('r', $tier->fire_limit_var) : $tier->fire_limit_var) . ')</td>';
                    echo '<td></td>';
                    //						echo '<td style="text-align: center;">' . ($tier->fire_tier_started ? 'Yes' : '<a href="admin.php?page=' . YM_ADMIN_DIR . 'ym-index.php&ym_page=ym-other&action=ym_app&firesale=enable&tier_id=' . $tier->fire_tier_id . '">No</a>') . '</td>';
                    echo '<td style="text-align: center;">' . ($tier->fire_tier_started ? 'Yes' : 'No') . '</td>';
                    echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=edit&tier_id=' . $tier->fire_tier_id . '">E</a></td>';
                    echo '<td style="text-align: center;"><a href="' . YM_PPP_ADMIN_URL . '&firesale=delete&tier_id=' . $tier->fire_tier_id . '">X</a></td>';
                    echo '</tr>';
                }
            }
        }
        echo '</table>';
        echo ym_end_box();
        echo '</div>';
        echo '<div style="width: 55%; float: right;">';
        echo ym_start_box('New Pricing Model');
        echo '
<form action="" method="post">
	<fieldset>
		<legend>Create a new Pricing Model</legend>
		<input type="hidden" name="firesale" value="new" />
		<table class="form-table">
		';
        $ym_formgen->render_form_table_text_row('Pricing Model Name', 'ym_new_firesale_name', '', 'A handy name to Remember');
        $ym_formgen->render_combo_from_array_row('Pricing Model Type', 'ym_new_firesale_type', $firetypes, '', 'What type of Pricing Model');
        echo '
		</table>
		<p class="submit" style="text-align: right;">
			<input type="submit" value="' . __('Create Pricing Model', 'ym') . ' &raquo;" />
		</p>
	</fieldset>
</form>';
        echo ym_end_box();
        echo '</div>';
    } else {
        if ($firesale == 'new') {
            echo ym_start_box('Pricing Model');
            echo '<form action="" method="post">
				<fieldset>
					<input type="hidden" name="firesale" value="create" />
			';
            $firesale = array('fire_name' => ym_post('ym_new_firesale_name') ? ym_post('ym_new_firesale_name') : 'pricing_model_' . date('dMY_His', time()), 'fire_type' => ym_post('ym_new_firesale_type'));
            echo '<p>Creating a new Pricing Model: <strong>' . $firesale['fire_name'] . '</strong> of Type: <strong>' . $firetypes[$firesale['fire_type']] . '</strong></p>';
            echo '<input type="hidden" name="ym_new_firesale_name" value="' . $firesale['fire_name'] . '" />';
            echo '<input type="hidden" name="ym_new_firesale_type" value="' . $firesale['fire_type'] . '" />';
            echo '<table class="form-table">';
            switch ($firesale['fire_type']) {
                case 2:
                    // pppp pack
                    $packs = array();
                    foreach (ym_get_ppp_packs() as $pack) {
                        $packs[$pack->id] = $pack->name . ' (' . number_format($pack->cost, 2) . ')';
                    }
                    $ym_formgen->render_combo_from_array_row('Post Pack', 'ym_new_firesale_target_id', $packs, '', 'Which post pack to apply this Model to?');
                    $ym_formgen->render_form_table_radio_row('End Sale', 'ym_end_firesale_ppp', 0, 'Take Post Pack off Sale after Last Tier');
                    break;
                case 1:
                    // subsc
                    $packs = array();
                    foreach (ym_get_packs() as $pack) {
                        $packs[$pack['id']] = $pack['account_type'] . ' (' . $pack['duration'] . ' ' . $pack['duration_type'] . ') ' . $pack['cost'];
                    }
                    $ym_formgen->render_combo_from_array_row('Pack', 'ym_new_firesale_target_id', $packs, '', 'Which pack to apply this Model to?');
                    break;
                case 0:
                default:
                    // get all ppp's
                    $posts = array();
                    foreach (ym_get_all_ppp_posts() as $post) {
                        $posts[$post->ID] = $post->post_title;
                    }
                    $ym_formgen->render_combo_from_array_row('Post', 'ym_new_firesale_target_id', $posts, '', 'Which post to apply this Model to?');
                    $ym_formgen->render_form_table_radio_row('End Sale', 'ym_end_firesale_ppp', 0, 'Take Post off Sale after Last Tier');
                    break;
            }
            echo '<tr><td colspan="2"><p>Tiers</p></td></tr>';
            echo '<tr><td><a href="#addtier" id="ym_firesale_addtier">Click to Add Tier</a></td></tr>';
            echo '</table>';
            echo '<p class="submit" style="text-align: right;">
				<input type="submit" value="' . __('Create Pricing Model', 'ym') . ' &raquo;" />
			</p>';
            echo '</fieldset></form>';
            echo ym_end_box();
        } else {
            if ($firesale == 'create') {
                echo ym_start_box('Pricing Models');
                $firesale = array('fire_name' => ym_post('ym_new_firesale_name') ? ym_post('ym_new_firesale_name') : 'pricing_model_' . date('dMY_His', time()), 'fire_type' => ym_post('ym_new_firesale_type'), 'fire_type_id' => ym_post('ym_new_firesale_target_id'), 'fire_end_action' => ym_post('ym_end_firesale_ppp') ? ym_post('ym_end_firesale_ppp') : 0);
                // get tiers
                $fire_tiers = array();
                $limit_bys = ym_post('ym_new_firesale_limit_by');
                $limit_sales = ym_post('ym_new_firesale_limit_sales');
                $limit_dates = ym_post('ym_date_ym_new_firesale_limit_time');
                $limit_months = ym_post('ym_month_ym_new_firesale_limit_time');
                $limit_years = ym_post('ym_year_ym_new_firesale_limit_time');
                $limit_hours = ym_post('ym_hour_ym_new_firesale_limit_time');
                $limit_mins = ym_post('ym_min_ym_new_firesale_limit_time');
                $limit_by_hours = ym_post('ym_new_firesale_limit_hours');
                foreach (ym_post('ym_new_firesale_price') as $key => $tier_price) {
                    $fire_tiers[] = array('tier_price' => $tier_price, 'tier_limit_by' => $limit_bys[$key], 'tier_limit_sales' => $limit_sales[$key], 'tier_limit_time' => strtotime($limit_dates[$key] . ' ' . $months[$limit_months[$key]] . ' ' . $limit_years[$key] . ' ' . $limit_hours[$key] . ':' . $limit_mins[$key]), 'tier_limit_hours' => $limit_by_hours[$key]);
                }
                // DATABASE!
                $sql = 'INSERT INTO ' . $wpdb->ym_app_models . '(fire_name, fire_type, fire_type_id, fire_end_option) VALUES (\'' . $firesale['fire_name'] . '\', \'' . $firesale['fire_type'] . '\', \'' . $firesale['fire_type_id'] . '\', \'' . $firesale['fire_end_action'] . '\')';
                $wpdb->query($sql);
                if (FALSE !== ($firesale_id = $wpdb->insert_id)) {
                    echo '<p>Added the Pricing Models ' . $firesale['fire_name'];
                    // tiers
                    foreach ($fire_tiers as $key => $tier) {
                        $limit_var = 0;
                        switch ($tier['tier_limit_by']) {
                            case 2:
                                // hours
                                $limit_by = 2;
                                $limit_var = $tier['tier_limit_hours'];
                                break;
                            case 1:
                                // time
                                $limit_by = 1;
                                $limit_var = $tier['tier_limit_time'];
                                break;
                            case 0:
                            default:
                                //sales
                                $limit_by = 0;
                                $limit_var = $tier['tier_limit_sales'];
                        }
                        $sql = 'INSERT INTO ' . $wpdb->ym_app_models_tiers . '(fire_id, fire_price, fire_limit_by, fire_limit_var, fire_order)
						VALUES (
							' . $firesale_id . ',
							\'' . $tier['tier_price'] . '\',
							' . $limit_by . ',
							' . $limit_var . ',
							' . $key . '
						)';
                        $wpdb->query($sql);
                        if ($wpdb->insert_id) {
                            echo '<br />Tier Added';
                        }
                    }
                    echo '</p>';
                    echo '<meta http-equiv="refresh" content="3;' . YM_PPP_ADMIN_URL . '" />';
                } else {
                    echo '<p>There was a problem adding the Pricing Model: ' . $firesale['fire_name'] . '</p>';
                }
                echo ym_end_box();
            } else {
                // bad firesale function
            }
        }
    }
    echo '
		<div id="ym_firesale_add_post_tiers_form" style="display: none; clear: both;">';
    echo ym_start_box('Adding a Tier');
    echo '
		<form method="post" action="">
			<fieldset>
				<legend>Add a Tier to the selected Pricing Model</legend>
				<input type="hidden" name="ym_firesale_add_post_tiers_fire_id" id="ym_firesale_add_post_tiers_fire_id" />
				<input type="hidden" name="firesale" value="newtier" />
				
				<table id="ym_firesale_add_post_tiers">
				</table>
				
				<p class="submit" style="text-align: right;">
					<input type="submit" value="' . __('Add New Pricing Model Tier', 'ym') . ' &raquo;" />
				</p>
			</fieldset>
		</form>
		';
    echo ym_end_box();
    echo '
		</div>';
    echo '</div>';
    echo '<table id="ym_firesale_tier_source">';
    ym_fire_tier_form();
    echo '</table>';
}
            $html .= ym_upgrade_buttons(true, $pack_id, $user_id);
            $html .= $footer;
        } else {
            if (ym_request('username')) {
                $errors = false;
                $html = $header;
                if ($page > 1) {
                    $wp_error = new WP_Error();
                    ym_register_post(ym_request('username'), '', $wp_error, $page);
                    //error checking
                    if ($wp_error->get_error_code()) {
                        $errors = true;
                        $additional_page_needed = $page + 1;
                        $html .= ym_get_additional_registration_form_page($additional_page_needed, $page);
                    }
                }
                if (!$errors) {
                    $html .= ym_available_modules(ym_request('username'), true);
                }
                $html .= $footer;
            } else {
                if ($user_status == YM_STATUS_PENDING) {
                    $html = $header . '<p>' . __('Error - Your subscription status is pending. Please contact an administrator for more information.', 'ym') . '</p>' . $footer;
                } else {
                    $html = $header . '<p>' . __('You are already subscribed or an error occurred. Please contact an administrator for more information.', 'ym') . '</p>' . $footer;
                }
            }
        }
    }
}
echo $html;
Exemple #18
0
 function do_process()
 {
     $freebie_code = ym_request('freebie_code');
     if ($freebie_code) {
         $this->common_process($freebie_code, 'Free/Coupon', TRUE, FALSE);
         list($buy, $what, $id, $user_id) = explode('_', $freebie_code);
         if ($what == 'subscription') {
             $data = array('id' => $id, 'cost' => 'Free/Coupon', 'duration' => 1, 'item_name' => get_bloginfo() . ' ' . __('Subscription Purchase:', 'ym') . ' ' . $post_title);
         } else {
             if ($what == 'post') {
                 $data = array('post_id' => $id, 'ppp' => true, 'cost' => 'Free/Coupon', 'duration' => 1, 'item_name' => get_bloginfo() . ' ' . __('Post Purchase:', 'ym') . ' ' . get_post_title($id));
             } else {
                 // assume bundle
                 $bundle = ym_get_bundle($id);
                 $data = array('ppp_pack_id' => $id, 'ppp' => true, 'cost' => 'Free/Coupon', 'duration' => 1, 'item_name' => get_bloginfo() . ' ' . __('Bundle Purchase:', 'ym') . ' ' . $bundle->name);
             }
         }
         $this->redirectlogic($data, TRUE);
     }
     $custom = ym_request('custom');
     if (!$custom) {
         echo 'No Data Passed';
         return;
     }
     list($buy, $what, $pack_id, $user_id) = explode('_', $custom);
     // verify
     $safe = FALSE;
     global $ym_packs;
     foreach ($ym_packs->packs as $pack) {
         if ($pack['id'] == $pack_id) {
             $cost_test = $pack['cost'];
             if (strpos($cost_test, '.')) {
                 $cost_test = $cost_test * 100;
             }
             if ($cost_test == 0) {
                 $safe = TRUE;
             }
         }
     }
     if (!$safe) {
         // error
         print_r($_POST);
         echo 'Could not Find a pack match';
         return;
     }
     $this->do_buy_subscription($pack_id, $user_id, TRUE);
 }
Exemple #19
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);
        }
    }
Exemple #20
0
echo '<div class="wrap" id="poststuff">';
echo ym_start_box(__('Logs', 'ym'));
if (!$_POST && !$user_id) {
    echo '<p>' . __('You can select a user below to get their log, or one of the tabs above to get specific log information', 'ym') . '</p>';
} else {
    if (!$user_id) {
        $user_id = get_user_by('login', $search_user_name);
        if ($user_id) {
            $user_id = $user_id->ID;
        } else {
            $user_id = FALSE;
            echo '<div class="error" id="message"><p>' . __('User Not Found', 'ym') . '</p></div>';
        }
    }
}
if (!ym_request('user_id', false)) {
    // get user specific log
    echo '<form action="" method="post">';
    echo '<label for="user_id">' . __('Search for a User', 'ym');
    echo ' <input type="text" name="search_user_name" id="search_user_name" value="' . $search_user_name . '">';
    echo '</label>';
    echo '<input type="submit" value="' . __('Get User Log', 'ym') . '" />';
    echo '</form>';
    echo '<form action="" method="post">';
    global $wpdb;
    $query = 'SELECT DISTINCT(transaction_id) FROM ' . $wpdb->prefix . 'ym_transaction ORDER BY transaction_id DESC';
    echo '<label for="group_log_id">' . __('Select a Log Group ID', 'ym');
    echo ' <select name="group_log_id" id="group_log_id">';
    foreach ($wpdb->get_results($query) as $row) {
        echo '<option value="' . $row->transaction_id . '" ';
        if ($row->transaction_id == $transaction_id) {
Exemple #21
0
function ym_loaded()
{
    // last globals
    global $current_user, $ym_user;
    get_currentuserinfo();
    if (is_user_logged_in()) {
        // as the user is logged in....
        $ym_user = new YourMember_User($current_user->ID);
    } else {
        // blank one
        $ym_user = new YourMember_User();
    }
    global $wpdb, $ym_auth, $ym_dl_db, $ym_dl_post_assoc, $ym_sys, $plugin_file;
    global $wp_upload, $ym_upload_root, $ym_upload_url;
    if (ym_get('ym_go') == 'support') {
        header('Location: ' . YM_SUPPORT_LINK);
        exit;
    }
    // TODO: tidy all these calls up again
    //Localization
    add_action('init', 'ym_load_lang');
    // admin bar
    add_action('init', 'ym_admin_nav');
    add_action('admin_bar_menu', 'ym_admin_bar', 90);
    // context help (help in the top right)
    if (is_admin()) {
        add_action('ym_pre_admin_loader', 'ym_database_updater', 10, 1);
        // interrupt?
        if (ym_request('do_munch')) {
            ym_admin_loader();
            exit;
        }
        // main drag
        add_action('admin_menu', 'ym_admin_page');
        //Plugin Panel Hooks
        add_filter('plugin_action_links', 'ym_action_link', 10, 2);
        // user edit
        add_action('user_edit_form_tag', 'ym_form_enctype');
        // conf bypasses
        ym_conf_bypass();
        //		add_action('load-toplevel_page_ym/admin/ym-index', 'ym_context_help');
        add_action('load-toplevel_page_' . YM_ADMIN_FUNCTION, 'ym_context_help');
        add_action('load-your-members_page_' . YM_ADMIN_DIR . 'ym-about', 'ym_context_help');
    } else {
        // SSL
        add_action('init', 'ym_go_ssl');
        add_action('posts_selection', 'ym_go_ssl_pages');
        if ($ym_sys->enable_metered) {
            add_action('init', 'ym_check_metered_access');
        }
        add_action('get_footer', 'ym_affiliate_link');
    }
    // call version check
    ym_check_version();
    if ($ym_auth->ym_check_key()) {
        $wp_upload = wp_upload_dir();
        if ($wp_upload['error']) {
            if (is_admin() && ym_get('page') == YM_ADMIN_FUNCTION && !ym_request('ym_page')) {
                echo '<div id="message" class="error"><p>' . $wp_upload['error'] . '</p></div>';
            }
        } else {
            $ym_upload_root = $wp_upload['path'];
            $ym_upload_url = $wp_upload['url'];
        }
        ym_create_log_constants();
        //Must be first for any logging that occurs from hereonin
        ym_suppress_enclosure_check();
        add_action('mod_rewrite_rules', 'ym_block_wp_login_action_register');
        add_action('admin_init', 'ym_block_wp_login_action_register_flush');
        if (!is_admin()) {
            ym_download_response();
            //checks for a download id in the url
            global $ym_manage_access;
            $ym_manage_access = new YourMember_Manage_Access();
            if ($ym_sys->protect_mode) {
                add_action('template_redirect', array($ym_manage_access, 'exit_check'));
            }
            add_shortcode('private', 'ym_shortcode_parse');
            add_shortcode('no_access', 'ym_shortcode_parse');
            add_shortcode('user_has_access', 'ym_shortcode_parse');
            add_shortcode('ym_user_profile', 'ym_edit_custom_field_standalone');
            add_shortcode('ym_rss_token', 'ym_get_rss_token');
            add_shortcode('ym_upgrade', 'ym_shortcode_parse');
            add_shortcode('ym_packs', 'ym_shortcode_parse');
            add_shortcode('private_or', 'ym_shortcode_parse');
            add_shortcode('private_and', 'ym_shortcode_parse');
            add_shortcode('ym_membership_content', 'ym_membership_content_shortcode');
            // TODO: Deprecate 11.0.6
            add_shortcode('user_account_is', 'ym_shortcode_parse');
            add_shortcode('private_username_is', 'ym_shortcode_parse');
            // Replace with
            add_shortcode('ym_user_is', 'ym_user_is');
            add_shortcode('ym_user_is_not', 'ym_user_is_not');
            add_shortcode('ym_user_custom_is', 'ym_user_custom_is');
            add_shortcode('ym_user_custom_is_not', 'ym_user_custom_is_not');
            add_shortcode('ym_profile', 'ym_get_user_profile');
            add_shortcode('ym_purchase_history', 'ym_get_user_purchase_history_shortcode');
            add_shortcode('ym_gateway_cancel', 'ym_get_user_unsub_button_gateway');
            add_shortcode('ym_gravatar', 'ym_gravatar_render');
            // start content
            // buy now
            add_shortcode('ym_buy_content', 'ym_buy_button_content');
            add_filter('the_content', 'ym_buy_button_content_filter', 1, 1);
            add_shortcode('ym_buy_bundle', 'ym_buy_button_bundle');
            add_filter('the_content', 'ym_buy_button_bundle_filter', 1, 1);
            // end buy now
            // indexy
            add_shortcode('ym_all_content', 'ym_get_all_content_buttons');
            add_shortcode('ym_all_bundles', 'ym_get_all_bundle_buttons');
            add_shortcode('ym_featured_content', 'ym_get_featured_content_buttons');
            // end indexy
            add_shortcode('ym_content_units_left', 'ym_content_units_left');
            add_shortcode('ym_bundle_units_left', 'ym_bundle_units_left');
            //pass ID
            add_shortcode('ym_content_units_sold', 'ym_content_units_sold');
            add_shortcode('ym_bundle_units_sold', 'ym_bundle_units_sold');
            //pass ID
            add_shortcode('ym_content_units_limit', 'ym_content_units_limit');
            add_shortcode('ym_bundle_units_limit', 'ym_bundle_units_limit');
            //pass ID
            add_shortcode('ym_content_expiry_date', 'ym_post_purchased_expiry');
            // so that an expiry date can be shown once a post has been purchased
            add_shortcode('ym_content_purchase_date', 'ym_post_last_purchased_date');
            //so that a purchase date can be shown once a post has been purchased
            add_shortcode('ym_bundle_expiry_date', 'ym_bundle_purchased_expiry');
            add_shortcode('ym_bundle_purchase_date', 'ym_bundle_last_purchased_date');
            // end content
            add_shortcode('ym_register', 'ym_shortcode_parse');
            add_shortcode('ym_login', 'ym_shortcode_parse');
            add_shortcode('ym_drip_date', 'ym_shortcode_parse');
            add_shortcode('ym_user_password_form', 'ym_user_password_form');
            add_shortcode('ym_user_profile_form', 'ym_user_profile_form');
            add_shortcode('ym_user_unsubscribe', 'ym_user_unsubscribe');
            add_shortcode('ym_promote', 'ym_shortcode_aff_link');
            $hook = $ym_sys->download_hook ? $ym_sys->download_hook : 'download';
            add_shortcode($hook, 'ym_dl_ins');
            //Profile Data
            add_shortcode('ym_user_register_date', 'ym_shortcode_user');
            add_shortcode('ym_user_email', 'ym_shortcode_user');
            add_shortcode('ym_user_first_name', 'ym_shortcode_user');
            add_shortcode('ym_user_last_name', 'ym_shortcode_user');
            add_shortcode('ym_user_username', 'ym_shortcode_user');
            add_shortcode('ym_user_description', 'ym_shortcode_user');
            add_shortcode('ym_user_custom', 'ym_shortcode_user');
        }
        //CSS
        add_action('wp_enqueue_scripts', 'ym_styles');
        add_action('login_enqueue_scripts', 'ym_login_styles');
        //	if ($ym_auth->ym_check_key()) {
        add_action('init', array('ym_cron', 'init'), 20);
        // run manual cron if needed, check schedules if not
        add_filter('wp_authenticate_user', 'ym_authenticate');
        if ($ym_sys->modified_registration) {
            add_action('user_register', 'ym_register', 10, 1);
            add_action('register_form', 'ym_register_form', 10, 6);
            add_action('register_post', 'ym_register_post', 10, 3);
        } else {
            add_action('user_register', 'ym_register_default', 10, 1);
        }
        /**
        WP Admin block/login redirect
        Logout redirect
        */
        add_action('login_head', 'ym_login_redirect');
        add_action('wp_login', 'ym_wp_login', 1, 2);
        add_action('admin_head', 'ym_stop_wp_admin', 1);
        add_action('wp_logout', 'ym_wp_logout', 1);
        /**
        Loginism
        */
        add_action('login_head', 'ym_login_js');
        // fire on non login page
        add_action('wp_head', 'ym_login_js');
        /**
        Login Register
        */
        // custom messages for login form
        add_filter('login_message', 'ym_login_message');
        // remove password string?
        //		add_action('login_head', 'ym_login_remove_password_string');
        /**
        Login themeing
        */
        // login page overrides
        if ($ym_sys->wp_login_header_url) {
            add_filter('login_headerurl', 'ym_login_headerurl');
            add_filter('login_headertitle', 'ym_login_headertitle');
        }
        if ($ym_sys->wp_login_header_logo) {
            add_action('login_head', 'ym_login_header_logo');
        }
        add_action('init', 'ym_subscribe_response');
        add_action('init', 'ym_upgrade_response');
        add_action('init', 'ym_register_catch_gateway');
        add_action('admin_enqueue_scripts', 'ym_admin_script_init');
        add_action('wp_head', 'ym_js_varibles');
        add_action('init', 'ym_process_response');
        add_action('parse_query', 'ym_thank_you_response');
        add_action('init', 'ym_init');
        /**
        		custom fields
        		**/
        if (is_admin()) {
            // hook for catching core fields and updating out own (wp-admin)
            add_action('profile_update', 'ym_update_custom_fields');
        }
        add_action('show_user_profile', 'ym_edit_custom_fields');
        add_action('edit_user_profile', 'ym_edit_custom_fields');
        //		add_filter('print_scripts_array', 'ym_fix_tinymce_conflict');
        add_filter('rewrite_rules_array', 'ym_rewrite_rule');
        /**
        widgets
        */
        add_action('init', 'ym_widget_init');
        add_action('init', 'ym_sidebar_init');
        add_action('init', 'ym_register_sidebar_init');
        add_filter('widget_text', 'do_shortcode');
        /**
        Email
        */
        // Replaces the From Name and Address with custom info
        if ($ym_sys->filter_all_emails) {
            add_filter('wp_mail_from', 'ym_mail_from');
            add_filter('wp_mail_from_name', 'ym_mail_from_name');
        }
        /**
        RSS Repair
        */
        add_action('atom_head', 'ym_rss_stop_payments');
        add_action('rdf_head', 'ym_rss_stop_payments');
        add_action('rss_head', 'ym_rss_stop_payments');
        add_action('rss2_head', 'ym_rss_stop_payments');
        if (is_admin()) {
            // new data export/import
            if (ym_post('ym_exporting_users')) {
                ym_export_users(ym_post('offset', 0), ym_post('limit', 300), ym_post('bkpackagetype', 'all'), ym_post('bkpackage', 'all'), ym_post('bkinactive', 0));
                exit;
            }
            ym_import_users_from_csv();
            //check for CSV import request in post
            //			add_action('after_plugin_row','ym_info_note', 10, 3);
            // only add TinyMCE buttons to Post/Page/Custom Post Type new Content/Edit Content WP Editor Field
            // if user has access to admin
            // and if the request_uri matches a known post editor location
            if (ym_admin_user_has_access(true) && strpos($_SERVER['REQUEST_URI'], 'wp-admin/post')) {
                add_action('add_meta_boxes', 'ym_meta_box_setup');
                add_action('save_post', 'ym_account_save');
                add_action('init', 'ym_tinymce_addbuttons');
            }
            // tos check
            //			ym_tos_check();
            // hooks that can result in a dialog/iframe
            add_action('admin_notices', 'ym_get_advert');
            $ym_upgrade_action = ym_check_upgrade();
            // lightbox and message hook
            if (ym_get(YM_ADMIN_FUNCTION . '_activated')) {
                add_action('admin_notices', 'ym_do_welcome_box');
                add_action('admin_notices', 'ym_activated_thanks_box');
            } else {
                if ($ym_upgrade_action) {
                    add_action('admin_notices', 'ym_do_welcome_box');
                    add_action('admin_notices', 'ym_upgrade_nag_box');
                }
            }
        }
    }
    do_action('ym_loaded_complete');
}
 function do_process()
 {
     if ($_REQUEST['credit_card_processed']) {
         // yellow button hit
         // echo __('One Moment... Processing', 'ym');
         if (ym_request('sid') != $this->merchant_sid) {
             header('HTTP/1.1 400 Bad Request');
             echo 'Error in IPN. Invalid Vendor ID.';
             exit;
         }
         if ($this->secret_word && !$_REQUEST['demo']) {
             if (!ym_request('key')) {
                 header('HTTP/1.1 401 Unauthorized');
                 echo 'Error In IPN. Security Check Failed, no sig';
                 exit;
             }
             $md5_hash = ym_request('key');
             $secret_word = $this->secret_word;
             $vendor_id = $this->merchant_sid;
             $order_number = ym_request('order_number');
             $total = ym_request('total');
             if (strtolower(ym_request('demo')) == 'y') {
                 $order_number = 1;
             }
             $calculated = strtoupper(md5($secret_word . $vendor_id . $order_number . $total));
             if ($calculated != $md5_hash) {
                 header('HTTP/1.1 401 Unauthorized');
                 echo 'Error In IPN. Security Check Failed, invalid sig';
                 exit;
             }
         }
         $complete = FALSE;
         if ($_REQUEST['credit_card_processed'] == 'Y') {
             $complete = TRUE;
         }
         $data = ym_request('li_0_product_id', ym_request('li_1_product_id'));
         if (ym_request('li_0_recurrence', FALSE) && ym_request('invoice_id', FALSE)) {
             // it recurs
             list($buy, $what, $id, $user_id) = explode('_', $data);
             if ($what == 'subscription') {
                 // its a sub
                 // store invoice ID to allow cancel
                 update_user_meta($user_id, 'ym_2_checkout_invoice_id', ym_request('invoice_id'));
             }
         }
         $r = $this->common_process($data, ym_request('total'), $complete, FALSE);
         if ($r) {
             header('Location: ' . ym_request('custom_return_url'));
         } else {
             echo '<p>' . __('An Error Occured Completing the Transaction', 'ym') . '</p>';
         }
         exit;
     }
     echo 'IPN Processor';
     if (!ym_post('message_type') || !ym_post('item_id_1')) {
         // Did not find expected POST variables. Possible access attempt from a non PayPal site.
         header('HTTP/1.1 400 Bad Request');
         echo 'Error in IPN. Missing message_type or item_id.';
         exit;
     }
     if (ym_post('vendor_id') != $this->merchant_sid) {
         header('HTTP/1.1 400 Bad Request');
         echo 'Error in IPN. Invalid Vendor ID.';
         exit;
     }
     if ($this->secret_word) {
         if (!ym_post('md5_hash')) {
             header('HTTP/1.1 400 Bad Request');
             echo 'Error In IPN. Security Check Failed';
             exit;
         }
         //UPPERCASE(MD5_ENCRYPTED(sale_id + vendor_id + invoice_id + Secret Word))
         $md5_hash = ym_post('md5_hash');
         $sale_id = ym_post('sale_id');
         $vendor_id = $this->merchant_sid;
         $invoice_id = ym_post('invoice_id');
         $secret_word = $this->secret_word;
         if (strtolower(ym_post('demo')) == 'y') {
             $order_number = 1;
         }
         $calculated = strtoupper(md5($sale_id . $vendor_id . $invoice_id . $secret_word));
         if ($calculated != $md5_hash) {
             header('HTTP/1.1 400 Bad Request');
             echo 'Error In IPN. Security Check Failed (b)';
             exit;
         }
     }
     //(ORDER_CREATED, FRAUD_STATUS_CHANGED, SHIP_STATUS_CHANGED, INVOICE_STATUS_CHANGED, REFUND_ISSUED, RECURRING_INSTALLMENT_SUCCESS, RECURRING_INSTALLMENT_FAILED, RECURRING_STOPPED, RECURRING_COMPLETE, or RECURRING_RESTARTED )
     $exit_statuses = array('ORDER_CREATED', 'FRAUD_STATUS_CHANGED', 'SHIP_STATUS_CHANGED', 'RECURRING_STOPPED', 'RECURRING_COMPLETE', 'RECURRING_RESTARTED');
     // handle cases that the system must ignore
     if (ym_post('message_type') && in_array($_POST['message_type'], $exit_statuses)) {
         header('HTTP/1.1 200 OK');
         exit;
     }
     // adjust addition message types
     //approved, pending, deposited, or refunded/declined
     switch ($_POST['message_type']) {
         case 'RECURRING_INSTALLMENT_FAILED':
             $_POST['invoice_status'] = 'declined';
             break;
         case 'RECURRING_INSTALLMENT_SUCCESS':
             $_POST['invoice_status'] = 'deposited';
             break;
         case 'REFUND_ISSUED':
             $_POST['invoice_status'] = 'refunded';
             break;
         case 'INVOICE_STATUS_CHANGED':
         default:
             // no change
     }
     $complete = FALSE;
     switch ($_POST['invoice_status']) {
         case 'deposited':
             $complete = TRUE;
     }
     $data = ym_request('item_id_1');
     if (ym_request('item_recurrence_1', FALSE) && ym_request('invoice_id', FALSE)) {
         // it recurs
         list($buy, $what, $id, $user_id) = explode('_', $data);
         if ($what == 'subscription' && ym_request('invoice_id')) {
             // its a sub
             // store invoice ID to allow cancel
             update_user_meta($user_id, 'ym_2_checkout_invoice_id', ym_request('invoice_id'));
         }
     }
     $this->common_process(ym_post('item_id_1'), ym_post('item_list_amount_1'), $complete, TRUE);
 }
function ym_register_sidebar_widget($args = false, $pack_id = false, $hide_custom_fields = false, $hide_further_pages = false, $autologin = false)
{
    global $wpdb, $user_ID, $current_user;
    $html = '';
    if (!function_exists('register_sidebar_widget')) {
        return;
    }
    if ($args) {
        extract($args);
        $options = get_option('ym_register_sidebar_widget');
    } else {
        $args = array();
    }
    $title = isset($options['ym_register_sidebar_widget_title']) ? $options['ym_register_sidebar_widget_title'] : __('Your Members - Register', 'ym');
    $intro = isset($options['ym_register_sidebar_widget_intro']) ? $options['ym_register_sidebar_widget_intro'] : '';
    $custom_fields = isset($options['ym_register_sidebar_widget_use_custom_fields']) ? $options['ym_register_sidebar_widget_use_custom_fields'] : true;
    if (!$user_ID) {
        if ($args) {
            $html .= $before_widget;
        } else {
            $html .= '<div id="ym_page_register_form">';
        }
        if (trim($title) && $args) {
            $html .= $before_title . $title . $after_title;
        }
        if ($intro) {
            $html .= $intro;
        }
        $user_email = ym_request('user_email');
        //register_new_user($userlogin, useremail);
        global $errors;
        if (is_wp_error($errors)) {
            login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
        }
        $html .= '<form ' . (!$args ? 'class="ym_register_form"' : '') . ' name="registerform" id="registerform" action="' . site_url('wp-login.php?action=register', 'login_post') . '" method="post" enctype="multipart/form-data">';
        //		$html .= '<form ' . (!$args ? 'class="ym_register_form"':'') . ' name="registerform" id="registerform" action="" method="post">
        //		<input type="hidden" name="ym_register_form_posting" value="1" />';
        if (!ym_post('user_login')) {
            $html .= '<div class="ym_register_form_row">
				<label class="ym_label">' . __('Username') . '</label>
				<p>
					<input type="text" name="user_login" id="user_login" class="ym_reg_input input" value="" size="20" />
				</p>
				<div class="ym_clear">&nbsp;</div>
			</div>';
        } else {
            $html .= '<input type="hidden" name="user_login" value="' . esc_attr(stripslashes($user_login)) . '" />';
        }
        if (!ym_post('user_email')) {
            $html .= '<div class="ym_register_form_row">
				<label class="ym_label">' . __('Email') . '</label>
				<p>				
					<input type="text" name="user_email" id="user_email" class="ym_reg_input input" value="' . esc_attr(stripslashes($user_email)) . '" size="25" />
				</p>
				<div class="ym_clear">&nbsp;</div>
			</div>';
        } else {
            $html .= '<input type="hidden" name="user_email" value="' . esc_attr(stripslashes($user_email)) . '" />';
        }
        if ($custom_fields) {
            ob_start();
            $html .= do_action('register_form', false, 1, $pack_id, $hide_custom_fields, $hide_further_pages, $autologin);
            $html .= ob_get_clean();
        }
        $html .= '<p id="reg_passmail">' . __('A password will be e-mailed to you.') . '</p>
			<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="' . __('Register') . '" /></p>
		</form>';
        if ($args) {
            $html .= $after_widget;
        } else {
            $html .= '</div>';
        }
    } else {
        $html .= '<div class="ym_message" id="ym_page_register_form_already_registered"><div class="ym_message_liner">' . __('You are already registered for the site and can\'t do so again.', 'ym') . '</div></div>';
    }
    if ($args) {
        echo $html;
    } else {
        return $html;
    }
}
Exemple #24
0
 function fail_process()
 {
     $data = array();
     switch (strtolower(ym_request('Action'))) {
         case 'user.add':
         case 'rebill':
             // just in case
             return;
         case 'user.delete':
             $data['new_status'] = YM_STATUS_CANCEL;
             $data['status_str'] = __('Zombaio user deleted', 'ym');
             break;
         case 'declined':
             $data['new_status'] = YM_STATUS_ERROR;
             $data['status_str'] = sprintf(__('Zombaio card declined, Code %s', 'ym'), ym_request('ReasonCode'));
             break;
         case 'user.addcredits':
             echo 'ERROR';
             exit;
             break;
         default:
             $data['new_status'] = YM_STATUS_NULL;
             $data['status_str'] = sprintf(__('Zombaio Unknown Action: %s', 'ym'), $ym_request('Action'));
     }
     return $data;
 }
function ym_update_custom_fields_by_page()
{
    $page = ym_request('page', 1);
    if (isset($_REQUEST['page'])) {
        return;
    }
    $fld_obj = get_option('ym_custom_fields');
    $entries = $fld_obj->entries;
    $order = $fld_obj->order;
    $user_id = ym_get_user_id();
    $cf = get_user_meta($user_id, 'ym_custom_fields', true);
    $skip_array = array('terms_and_conditions', 'subscription_introduction', 'subscription_options');
    if (!empty($order)) {
        if (strpos($order, ';') !== false) {
            $orders = explode(';', $order);
        } else {
            $orders = array($order);
        }
        $data = array();
        foreach ($orders as $order) {
            foreach ($entries as $entry) {
                if (!$entry['page']) {
                    $entry['page'] = 1;
                }
                if ($page == $entry['page']) {
                    if ($order == $entry['id']) {
                        if (in_array($entry['name'], $skip_array)) {
                            continue;
                        } else {
                            if ($entry['name'] == 'birthdate') {
                                if (!empty($_POST['ym_birthdate_month']) && !empty($_POST['ym_birthdate_day']) && !empty($_POST['ym_birthdate_year'])) {
                                    $data[$entry['id']] = $_POST['ym_birthdate_month'] . '-' . $_POST['ym_birthdate_day'] . '-' . $_POST['ym_birthdate_year'];
                                }
                            } else {
                                if ($entry['name'] == 'country') {
                                    if (!empty($_POST['ym_country'])) {
                                        $data[$entry['id']] = $_POST['ym_country'];
                                    }
                                } else {
                                    if ($entry['type'] == 'file') {
                                        $ok = FALSE;
                                        $name = 'ym_field-' . $entry['id'];
                                        global $ym_upload_root;
                                        if ($ym_upload_root) {
                                            $dir = trailingslashit(trailingslashit($ym_upload_root) . 'ym_custom_field_' . $entry['name']);
                                            if (!is_dir($dir)) {
                                                mkdir($dir);
                                            }
                                            if (is_dir($dir)) {
                                                // all good
                                                if ($_FILES[$name]['error'] == UPLOAD_ERR_OK) {
                                                    $tmp = $_FILES[$name]['tmp_name'];
                                                    $target = $dir . ym_get_user_id() . '_' . $_FILES[$name]['name'];
                                                    if (move_uploaded_file($tmp, $target)) {
                                                        global $ym_upload_url;
                                                        $data[$entry['id']] = trailingslashit($ym_upload_url) . 'ym_custom_field_' . $entry['name'] . '/' . ym_get_user_id() . '_' . $_FILES[$name]['name'];
                                                        $ok = TRUE;
                                                    }
                                                }
                                            }
                                        }
                                        if (!$ok && isset($_FILES[$name])) {
                                            echo '<div id="message" class="error"><p>' . __('An Error Occured whilst Uploading (a)', 'ym') . '</p></div>';
                                        }
                                    } else {
                                        if ($entry['type'] == 'callback') {
                                            $callback = 'ym_callback_custom_fields_' . $entry['name'] . '_save';
                                            if (function_exists($callback)) {
                                                $data[$entry['id']] = $callback($entry);
                                            }
                                        } else {
                                            $field_name = 'ym_field-' . $entry['id'];
                                            // also update core profile
                                            if (in_array($entry['name'], array('first_name', 'last_name'))) {
                                                update_user_meta($user_id, $entry['name'], $_POST[$field_name]);
                                            }
                                            if (isset($_POST[$field_name])) {
                                                if ($entry['type'] == 'multiselect') {
                                                    $_POST[$field_name] = implode(';', $_POST[$field_name]);
                                                }
                                                $data[$entry['id']] = $_POST[$field_name];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (is_array($cf)) {
            foreach ($cf as $key => $value) {
                if (!isset($data[$key])) {
                    $data[$key] = $value;
                }
            }
        }
        ym_update_user_custom_fields(ym_get_user_id(), $data);
    }
}
Exemple #26
0
/*
* $Id: ym-about.php 2452 2012-12-03 11:12:24Z bcarlyon $
* $Revision: 2452 $
* $Date: 2012-12-03 11:12:24 +0000 (Mon, 03 Dec 2012) $
*/
if (ym_request('do_munch') && ym_request('download')) {
    ym_check_version();
    global $ym_update_checker;
    $ym_update_checker->checkForUpdates();
    $state = get_option($ym_update_checker->optionName);
    $download_url = $state->update->download_url;
    header('Location: ' . $download_url);
    exit;
}
if (ym_request('do_munch') && ym_request('download_beta')) {
    ym_check_version();
    global $ym_update_checker, $ym_version_resp;
    $ym_update_checker->checkForUpdates();
    if ($ym_version_resp->version->beta_download_url) {
        header('Location: ' . $ym_version_resp->version->beta_download_url);
        exit;
    }
}
global $wp_version, $ym_version_resp, $wpdb, $ym_update_checker;
$do_check = ym_post('ym_do_version_check');
$check_step = ym_post('ym_do_version_check_step');
$do_beta_toggle = ym_post('ym_do_toggle_beta');
if ($do_beta_toggle) {
    $beta_enable = get_option('ym_beta_notify');
    if ($beta_enable) {
/**
YourMember admin page loading methods
*/
function ym_admin_loader()
{
    global $ym_auth;
    $page = ym_request('page');
    $ym_page = ym_request('ym_page');
    $auth_exclude = array(YM_ADMIN_FUNCTION . '_about' => 'ym-about.php');
    $ym_target = str_replace(YM_ADMIN_DIR, '', $page);
    if (array_key_exists($ym_target, $auth_exclude)) {
        $page = YM_PLUGIN_DIR_PATH . 'admin/' . $auth_exclude[$ym_target];
        require_once $page;
    } else {
        if (ym_request('do_munch') && $ym_auth->ym_check_key() && $ym_page) {
            $page = YM_PLUGIN_DIR_PATH . 'admin/' . $ym_page . '.php';
            require_once $page;
        }
    }
}