function gen_buy_ppp_pack_button($pack_cost, $pack_id, $pack_title, $return = FALSE) { $test = apply_filters('ym_filter_gateway', $this->code, 'gen_buy_ppp_pack_button', $pack_id); if ($test != $this->code) { return; } $data = FALSE; if (method_exists($this, 'pay_per_post_bundle')) { $data = $this->pay_per_post_bundle($pack_cost, $pack_id, $pack_title); } if ($data) { if (method_exists($this, 'gen_buy_ppp_pack_button_override')) { $html = $this->gen_buy_ppp_pack_button_override($pack_cost, $pack_title, $return, $pack_id, $data); if ($return) { return $html; } else { echo $html; } } $button_code = $this->get_button_code($data, ym_get_user_id()); $button_code = apply_filters('ym_additional_code', $button_code, $this->code, 'buy_bundle_' . $pack_id . '_' . ym_get_user_id()); $button_code_html = ''; foreach ($button_code as $item => $val) { $button_code_html .= '<input type="hidden" name="' . $item . '" value="' . $val . '" />' . "\n"; } $html = ' <form action="' . $this->action_url . '" method="post" class="ym_form ' . $this->code . '_form form-table" name="' . $this->code . '_form" id="' . $this->code . '_form"><fieldset> ' . $button_code_html . ' <input type="image" class="' . $this->code . '_button" src="' . $this->logo . '" name="submit" alt="' . $this->bundle_purchase_words . '" /> </fieldset></form>'; if ($return) { return $html; } else { echo $html; } } }
/** Non Flow Register/Upgrade */ function ym_available_modules($username = false, $return = false, $coupon_type = 0) { // echo 'ym_available_modules: ' . $username . ', ' . $return . ', ' . $coupon_type . '<br />'; global $ym_active_modules, $ym_packs; //coupons $user_id = ym_get_user_id(); $ym_custom_fields = ym_get_custom_field_array($user_id); $ym_home = site_url(); $base = $ym_home . '/index.php?ym_subscribe=1&username='******''; if ($pack_id = ym_get('pack_id')) { // pack ID has been selected $pack = ym_get_pack_by_id($pack_id); // strip commas $cost = str_replace(',', '', $pack['cost']); $override = FALSE; $code_to_use = 'custom'; // coupon check if (isset($ym_custom_fields['coupon']) && $ym_custom_fields['coupon']) { $cost = ym_apply_coupon($ym_custom_fields['coupon'], $coupon_type, $cost); if (substr($cost, 0, 4) == 'pack') { $pack_id = substr($cost, 5); // apply new pack $pack = ym_get_pack($pack_id); // import data $cost = $pack['cost']; $duration = $pack['duration']; $duration_type = $pack['duration_type']; $account_type = $pack['account_type']; $num_cycles = $pack['num_cycles']; } else { // makre sure formatted ok $cost = number_format($cost, 2); $override = $cost; $code_to_use = 'freebie_code'; } ym_register_coupon_use($ym_custom_fields['coupon'], ym_get_user_id(), 'buy_subscription_' . $pack_id); } // is it free? if ($cost == 0) { // auto redirect $redirector = ym_get('redirector'); // attempt to redirect to the processor. // if attempt fails, we show the button $loc = $ym_home . '/index.php?ym_process=ym_free&' . (ym_get('ym_autologin') ? 'ym_autologin=1&' : '') . $code_to_use . '=buy_subscription_' . $pack['id'] . '_' . ym_get_user_id() . '&redirector=' . urlencode($redirector); if (!headers_sent()) { header('Location: ' . $loc); exit; } else { echo '<script type="text/javascript">window.location = "' . $loc . '";</script>'; } die; } // gateway selection BuyNow $shown = 0; $shown_name = ''; $shown_button = ''; foreach ($ym_active_modules as $module) { $get_button = FALSE; if ($module == 'ym_free') { continue; } else { // do pack gateway check $get_button = TRUE; } if ($get_button) { ${$module} = new $module(); $this_button = ${$module}->getButton($pack_id, $override, 'ym_available_modules'); // a button pay not be returned (pack restrict gateway) if ($this_button) { $shown_name = $module; $shown_button = $this_button; $shown++; $html .= $this_button; } } } if ($shown == 0) { $html .= __('There are no payment gateways available at this time.', 'ym'); } else { if ($shown == 1) { if (!method_exists(${$shown_name}, 'abort_auto')) { // TODO: Are we on a page where HTML has been outputted? // auto fire $html = '<html> <head> <title>Redirecting...</title> <script type="text/javascript"> function load() { document.forms["' . $shown_name . '_form"].submit(); } </script> </head> <body onload="load();">'; $html .= '<div style="display: none;">' . $shown_button . '</div>' . '<div style="color: #333333; font-size: 14px; margin: 180px 250px; font-family: tahoma; text-align: center; padding: 50px; border: 1px solid silver;" id="ym_pay_redirect">' . '<div>You are being redirected. If this page does not refresh in 5 seconds then click <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>' . '</div>' . '</body></html>'; echo $html; die; } else { // aborted the auto fire step $html .= ${$shown_name}->abort_auto(); } } } } else { if (!ym_get('sel', FALSE)) { $html .= '<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center" class="like_form">' . '<tr>' . '<th><h3 class="ym_register_heading">' . __('Select Payment Gateway', 'ym') . '</h3></th>' . '</tr>'; /** No Gateway Selected Show Gateway Selection */ $shown = 0; $shown_name = ''; foreach ($ym_active_modules as $module) { $pay = new $module(); $packs = $ym_packs->packs; $packs = apply_filters('ym_packs', $packs, $pay->code); if (count($packs)) { $html .= '<tr>' . '<td align="center" style="padding: 5px; text-align: center;">' . '<a href="' . $base . '&sel=' . $module . '">' . '<div class="ym_module_name"><strong>' . $pay->name . '</strong></div>' . '<img class="ym_module_logo" src="' . $pay->logo . '" alt="' . $pay->name . '" title="' . $pay->name . '" />' . '</a>' . '</td>' . '</tr>'; $shown++; $no_gateway = FALSE; $shown_name = $module; } unset($pay, $packs); } $html .= '</table>'; if ($shown == 0) { $html .= __('There are no payment gateways available at this time.', 'ym'); } else { if ($shown == 1) { // we only have one to show.... // auto fire $loc = $base . '&sel=' . $shown_name; if (!headers_sent()) { header('Location: ' . $loc); } else { echo '<script type="text/javascript">window.location="' . $loc . '";</script>'; } exit; } } } else { if ($selected = ym_get('sel')) { /** Gateway selected Show Buy Now Buttons for this gateway */ // user has selected a gateway if (!class_exists($selected)) { wp_die(sprintf(__('Unknown Module: %s', 'ym'), $selected)); } $pay = new $selected(); $html .= $pay->generateButtons(true); } else { /** Should not get here */ wp_die(__('An error Occured (Code: YM_AVAILABLE_MODULES')); } } } /** Return */ if ($return) { return $html; } else { echo $html; return; } }
function ym_register_flow_override_return($additional_code, $gateway, $item) { global $current_page, $next_page, $the_flow_id, $wpdb; $url = get_permalink(); if (!$next_page) { $query = 'SELECT complete_url FROM ' . $wpdb->prefix . 'ym_register_flows WHERE flow_id = ' . $the_flow_id; if ($newurl = $wpdb->get_var($query)) { $url = site_url($newurl); } } if (strpos($url, '?')) { $url .= '&'; } else { $url .= '?'; } $url .= 'gateway_return=' . $gateway; $url .= '&item=' . $item; $url .= '&ym_register_flow_page=' . $current_page; $url .= '&ym_register_flow_next_page=' . $next_page; $url .= '&user_id=' . ym_get_user_id(); switch ($gateway) { case 'ym_2checkout': $additional_code['custom_return_url'] = $url; break; case 'ym_authorize_net': $additional_code['x_custom_2'] = $url; break; case 'ym_free': case 'ym_paypal': case 'ym_paypal_pro': case 'ym_stripe': $additional_code['return'] = $url; break; case 'ym_skirll': $additional_code['return_url'] = $url; break; case 'ym_worldpay': $additional_code['M_return'] = $url; break; case 'ym_zombaio': $additional_code['return_url_approve'] = $url; } return $additional_code; }
function ym_update_custom_field_partial() { global $ym_res; $ID = ym_get_user_id(); $fld_obj = get_option('ym_custom_fields'); $old_data = get_user_meta('ym_custom_fields', $ID, TRUE); $entries = $fld_obj->entries; $order = $fld_obj->order; $return = false; if (strlen($order)) { if (strpos($order, ';') !== false) { $orders = explode(';', $order); } else { $orders = array($order); } $data = array(); $skip_array = array('terms_and_conditions', 'subscription_introduction', 'subscription_options'); foreach ($orders as $order) { foreach ($entries as $entry) { if ($order == $entry['id']) { if (isset($old_data[$entry['id']])) { $old = $old_data[$entry['id']]; if (in_array($entry['name'], $skip)) { 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') { $data[$entry['id']] = ym_post('ym_country', $old); } 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 (c)', '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 { $data[$entry['id']] = ym_post($entry['name'], ym_post('ym_field-' . $entry['id'], $old)); } } } } } } } } } $return = ym_update_user_custom_fields($ID, $data); } return $return; }
function ym_register_form($return = false, $page = 1, $pack_id = false, $hide_custom_fields = false, $hide_further_pages = false, $autologin = false) { global $duration_str, $ym_sys, $ym_res; $html = ''; $fld_obj = get_option('ym_custom_fields'); $hide = $ym_sys->hide_custom_fields; $user_id = ym_get_user_id(); $hide_custom_fields = explode(',', $hide_custom_fields); if (!is_array($hide_custom_fields)) { $hide_custom_fields = array($hide_custom_fields); } $entries = $fld_obj->entries; $order = $fld_obj->order; if (empty($order)) { return; } if (strpos($order, ';') !== false) { $orders = explode(';', $order); } else { $orders = array($order); } $html .= '<div style="clear:both; height: 1px;"> </div>'; if ($redirect_to = ym_get('ym_redirector')) { $html .= '<input type="hidden" name="ym_redirector" value="' . urlencode($redirect_to) . '" />'; } if ($autologin) { $html .= '<input type="hidden" name="ym_autologin" value="1" />'; } $another_page = false; $lowest_page = ym_get_last_custom_field_page() + 1; //must be higher than the highest page $values = array(); if ($username = ym_get('username')) { $values = ym_get_custom_fields_by_username($username); } foreach ($orders as $order) { foreach ($entries as $entry) { if ($order == $entry['id']) { if (in_array($entry['id'], $hide_custom_fields)) { continue; } $entry['page'] = !isset($entry['page']) ? 1 : $entry['page']; if ($page == $entry['page']) { if (isset($_POST['hide_ym_field-' . $entry['id']])) { $entry['type'] = 'hidden'; //will hide the field if the appropriate post data is present. //This is intended to go with hard coded signups where the register page will act as stage 2 } $value = false; $row = ''; $hide_label = false; if (isset($values[$entry['id']])) { if (trim($values[$entry['id']])) { $value = trim($values[$entry['id']]); } } else { $value = ym_post('ym_field-' . $entry['id']); } if ($value) { $entry['value'] = $value; } if ($value = $entry['value']) { if (strpos($value, ':') !== false) { $array = explode(':', $value); if (count($array)) { switch ($array[0]) { case 'cookie': $entry['value'] = ym_cookie($array[1], ''); break; case 'session': $entry['value'] = ym_session($array[1], ''); break; case 'get': $entry['value'] = ym_get($array[1], ''); break; case 'post': $entry['value'] = ym_post($array[1], ''); break; case 'request': case 'qs': $entry['value'] = ym_request($array[1], ''); break; default: $entry['value'] = ''; break; } } } } if ($entry['name'] == 'terms_and_conditions' && !empty($ym_res->tos)) { $row .= '<p> <textarea name="tos" cols="29" rows="5" readonly="readonly">' . $ym_res->tos . '</textarea>'; $row .= '</p>'; $row .= '<p> <label class="ym_label" for="ym_tos"> <div><input type="checkbox" class="checkbox" name="ym_tos" id="ym_tos" value="1" /> ' . __('I agree to the Terms and Conditions.', 'ym') . '</div> </label> </p>' . "\n"; } else { if ($entry['name'] == 'subscription_introduction' && !empty($ym_res->subs_intro)) { $row .= '<div class="ym_subs_intro">' . $ym_res->subs_intro . '</div>'; } else { if ($entry['name'] == 'subscription_options') { // $pack_restriction = false; // if (strpos(',', $pack_id)) { // $pack_restriction = explode(',', $pack_id); // } if (ym_request('ym_subscription', $pack_id)) { // pre selected! // could be from a ym_register and the reg is hidden so showing the selector here is bad $row .= '<input type="hidden" name="ym_subscription" value="' . ym_request('ym_subscription', $pack_id) . '" />'; $hide_label = TRUE; } else { global $ym_packs; $packs = $ym_packs->packs; $active_modules = get_option('ym_modules'); if (empty($active_modules)) { $row .= '<p>' . __('There are no payment gateways active. Please contact the administrator.', 'ym') . '</p>'; } else { // RENDER $packs_shown = 0; if ($existing_data = ym_request('ym_subscription')) { $default = $existing_data; } else { $default = ym_get_default_pack(); } $did_checked = FALSE; foreach ($packs as $pack) { /* if (count($pack_restriction)) { // has restiction if (in_array($pack['id'], $pack_restriction)) { // do not show aka hide $pack['hide_subscription'] = 1; } } */ if (!$pack['hide_subscription']) { $row .= '<div class="ym_register_form_subs_row"> <div class="ym_reg_form_pack_radio"> <input type="radio" '; if ($pack['id'] == $default && !$did_checked) { $row .= 'checked="checked"'; $did_checked = TRUE; } $packs_shown++; $row .= ' 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 ($entry['caption']) { $row = '<div class="ym_clear"> </div><div class="ym_register_form_caption">' . $entry['caption'] . '</div>' . $row; } } // END RENDER } } } else { if ($entry['name'] == 'birthdate' && !$hide) { $birthdate_fields = ym_birthdate_fields('ym_birthdate'); $row .= '<p>' . $birthdate_fields . '</p>'; } else { if ($entry['name'] == 'country' && !$hide) { $countries_sel = ym_countries_list('ym_country'); $row .= '<p>' . $countries_sel . '</p>'; } else { if ((!$entry['profile_only'] || $entry['profile_only'] == false) && !$hide) { $ro = $entry['readonly'] ? 'readonly="readonly"' : ''; if ($entry['type'] == 'text') { $fld = '<input type="text" name="ym_field-' . $entry['id'] . '" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; } else { if ($entry['type'] == 'hidden') { $fld = '<input type="hidden" name="ym_field-' . $entry['id'] . '" value="' . $entry['value'] . '" />'; $hide_label = true; } else { if ($entry['type'] == 'yesno') { $fld = '<select class="ym_reg_select" name="ym_field-' . $entry['id'] . '" ' . $ro . '>'; $options = array('Yes', 'No'); foreach ($options as $option) { $fld .= '<option value="' . $option . '" ' . (trim($option) == $value ? 'selected="selected"' : '') . '>' . $option . '</option>'; } $fld .= '</select>'; } else { if ($entry['type'] == 'password') { // primary use is ym_password if ($entry['name'] == 'ym_password') { $fld = '<input type="password" name="ym_password" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; ym_login_remove_password_string(); } else { // allow other password fields $fld = '<input type="password" name="' . $entry['name'] . '" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; } } else { if ($entry['type'] == 'html') { $fld = '<div class="ym_reg_html">' . $entry['value'] . '</div>'; } else { if ($entry['type'] == 'textarea') { $fld = '<textarea class="ym_reg_textarea" name="ym_field-' . $entry['id'] . '" cols="29" rows="5" ' . $ro . '>' . $entry['value'] . '</textarea>'; } else { if ($entry['type'] == 'select') { $fld = '<select class="ym_reg_select" name="ym_field-' . $entry['id'] . '" ' . $ro . '>'; $options = explode(';', $entry['available_values']); foreach ($options as $option) { if (strpos($option, ':')) { list($option, $val) = explode(':', $option); $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $val . '</option>'; } else { $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $option . '</option>'; } } $fld .= '</select>'; } else { if ($entry['type'] == 'multiselect') { $fld = '<select class="ym_reg_multiselect" name="ym_field-' . $entry['id'] . '[]" ' . $ro . ' multiple="multiple">'; $options = explode(';', $entry['available_values']); foreach ($options as $option) { if (strpos($option, ':')) { list($option, $val) = explode(':', $option); $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $val . '</option>'; } else { $fld .= '<option value="' . $option . '" ' . ($option == $value ? 'selected="selected"' : '') . '>' . $option . '</option>'; } } $fld .= '</select>'; } else { if ($entry['type'] == 'file') { $fld = '<input type="file" name="ym_field-' . $entry['id'] . '" />'; if ($entry['available_values'] == 'image') { $fld .= $entry['value']; } } else { if ($entry['type'] == 'callback') { $callback = 'ym_callback_custom_fields_' . $entry['name'] . '_editor'; if (function_exists($callback)) { $fld = $callback($entry['id']); } } else { if (!($fld = apply_filters('ym_generate_custom_field_type_' . $entry['type'], '', 'ym_field-' . $entry['id'], $entry, $value))) { $fld = '<input type="text" name="ym_field-' . $entry['id'] . '" value="' . $entry['value'] . '" ' . $ro . ' class="ym_reg_input" size="25" />'; } } } } } } } } } } } if ($entry['required']) { $fld .= '<div class="ym_clear"> </div><div class="ym_register_form_required">' . $ym_sys->required_custom_field_symbol . '</div>'; } if ($entry['caption']) { $fld .= '<div class="ym_clear"> </div><div class="ym_register_form_caption">' . $entry['caption'] . '</div>'; } $row .= '<p>' . $fld . '</p>'; } } } } } } ////Adding of the row if ((!$entry['profile_only'] || $entry['profile_only'] == false) && !$hide && !$hide_label) { $html .= '<div class="ym_register_form_row" id="' . str_replace(' ', '_', $entry['name']) . '_row">'; $label = $entry['label']; $html .= '<label class="ym_label">' . $label . '</label>'; } $html .= $row; if ((!$entry['profile_only'] || $entry['profile_only'] == false) && !$hide && !$hide_label) { $html .= '<div class="ym_clear"> </div>'; $html .= '</div>'; } ////End adding of the row } if (!$hide_further_pages) { if ($entry['page'] > $page) { if ($entry['page'] < $lowest_page) { $lowest_page = $entry['page']; } $another_page = true; } } } } } $html .= '<input type="hidden" name="ym_page" value="' . $page . '" />'; //so that the update function knows which pages to validate if ($another_page) { $html .= '<input type="hidden" name="another_page_needed" value="' . $lowest_page . '" />'; //so that the rendering function knows to add another page before sending off to the gateway } if ($return) { return $html; } else { echo $html; } }
function register_payment_action($return = TRUE) { global $post_data, $pack_data; $override_price = isset($pack_data['coupon_value']) ? $pack_data['cost'] : false; return $this->getButtonOverride($pack_data, ym_get_user_id(), $override_price); }
function gen_buy_now_button_override($post_cost, $post_title, $return, $post_id, $data) { // facebook test: if (!$_SESSION['in_facebook']) { return ''; } // bypass standard form generation $user_id = ym_get_user_id(); $function_name = 'ym_fbook_purchase_' . $user_id . '_' . $post_id; $cost = $data['cost']; list($pack, $cost) = $this->gen_buy_now_button_override_packcost($post_cost, $post_title, $return, $post_id, $data); $script = $this->gen_buy_now_button_override_script($function_name, $pack, $cost, $data); $form = $this->gen_buy_now_button_override_form($function_name, $cost, $data); return $script . $form; }