Exemplo n.º 1
0
    function get_button_buypost($options = array(), $return = false)
    {
        global $user;
        // get post id
        if (isset($options['pack']['ppp_pack_id'])) {
            // get comma separated list of post ids
            $options['pack']['post_id'] = mgm_get_postpack_posts_csv($options['pack']['ppp_pack_id']);
        } else {
            // single post
            $options['pack']['post_id'] = get_the_ID();
        }
        // merge pack
        $options['pack'] = array_merge($options['pack'], array('duration' => 1, 'item_name' => 'Purchase Post - ' . $options['pack']['title'], 'buypost' => 1));
        $include_permalink = isset($options['widget']) ? false : true;
        // html
        $html = '<form action="' . $this->_get_endpoint('html_redirect', $include_permalink) . '" method="POST" class="mgm_form" name="' . $this->code . '_form">	
					<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" class="form-table"> 					
						<tr>
							<td align="center">
								<input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">						 								
								<input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" name="submit" alt="' . $this->name . '" border="0">
								<div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>	
							</td>
						</tr>
					</table>
				</form>';
        // return
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
    function get_button_buypost($options = array(), $return = false)
    {
        // get html
        $html = '<form action="' . $this->_get_endpoint('html_redirect') . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
					<input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">
					<input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->name . '">
					<div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>
			   </form>';
        // return or print
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
Exemplo n.º 3
0
    function get_button_buypost($options = array(), $return = false)
    {
        // html
        $html = '';
        // if dynamic_pricing is not enable do not allow PPP
        if (isset($this->setting['dynamic_pricing']) && $this->setting['dynamic_pricing'] == 'enabled') {
            // get html
            $html = '<form action="' . $this->_get_endpoint('html_redirect') . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
						<input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">
						<input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->name . '">
						<div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>
				   </form>';
        }
        // return or print
        if ($return) {
            return $html;
        }
        // print
        echo $html;
    }
Exemplo n.º 4
0
    function get_button_buypost($options = array(), $return = false)
    {
        // cb depends on product id, check for it before generating button
        if (!isset($options['pack']['product']['clickbank_product_id']) || empty($options['pack']['product']['clickbank_product_id'])) {
            return '<div class="mgm_button_subscribe_payment">
						<b>' . __('Error in ClickBank settings : No Product ID set.', 'mgm') . '</b>
					</div>';
            exit;
        }
        // get html
        $html = '<form action="' . $this->_get_endpoint('html_redirect') . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
					<input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">
					<input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->name . '">
					<div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>
			   </form>';
        // return or print
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
    /**
     * Callback for payment_gateways field
     * prints all active modules, javascript callback and json data shows per pack 
     * or filtered 
     *
     * @param array $field
     * @param string $name
     * @param string $value
     * @return string
     */
    function field_payment_gateways_callback($field, $name, $value)
    {
        // display as
        $dispaly_as_selectbox = $this->_get_subscription_options_as();
        //check subscription options custom_field is enabled:
        $continue = false;
        // cf
        $obj_customfields = mgm_get_class('member_custom_fields');
        // subo
        $arr_sub_options = $obj_customfields->get_field_by_name('subscription_options');
        // check
        if (isset($arr_sub_options['id']) && !empty($obj_customfields->sort_orders) && in_array($arr_sub_options['id'], $obj_customfields->sort_orders)) {
            $continue = true;
        }
        // return
        if (!$continue) {
            return '';
        }
        $system_obj = mgm_get_class('system');
        // args
        $args = $this->get_config('args', array());
        // selected_subscription
        $selected_subs = mgm_get_selected_subscription($args);
        // get active modules
        $a_payment_modules = $system_obj->get_active_modules('payment');
        /* @todo deprecate load here since gateways are loaded for post purchase also
        		// get modules for packs:
        		$allpacks = mgm_get_class('subscription_packs')->get_packs();		
        		// init
        		$pack_modules = array();		
        		// loop
        		foreach ($allpacks as $allp) {
        			// reset
        			$include = mgm_select_subscription($allp,$selected_subs);						
        			// skip other when a package sent as selected
        			if($selected_subs !== false){
        				if(empty($include)) continue;
        			}
        			//issue #1532
        			if(is_array($allp['modules'])){
        				$pack_modules = array_merge($pack_modules,$allp['modules']);
        			}
        		}
        		// pack
        		$pack_modules = array_unique($pack_modules);
        		
        		mgm_pr($pack_modules);*/
        // payment modules
        $payment_modules = array();
        // loop
        if (!empty($a_payment_modules)) {
            // loop
            foreach ($a_payment_modules as $payment_module) {
                // not trial
                if (in_array($payment_module, array('mgm_free', 'mgm_trial'))) {
                    continue;
                }
                // included modules
                // if( ! in_array($payment_module, $pack_modules) ) continue;
                // store
                $payment_modules[] = $payment_module;
            }
        }
        // make unique
        $payment_modules = apply_filters('mgm_payment_gateways_as_custom_field', array_unique($payment_modules));
        // check count
        $module_count = count($payment_modules);
        // one active
        $hide_div = $module_count === 1 ? 'style="display:none;"' : '';
        // NOTE: uncomment the below line to enable module display even if only one exists
        // $hide_div = "";
        // NOTE: do not change the id: mgm_payment_gateways_container
        $html = sprintf('<div id="mgm_payment_gateways_container" class="mgm_payment_wrapper" %s >', $hide_div);
        //loop through payment modules:
        if ($module_count == 0) {
            $html .= sprintf('<div>%s</div>', __('No active payment module', 'mgm'));
        } else {
            //print each module:
            foreach ($payment_modules as $payment_module) {
                //checked: if(selected/only one gateway exists)
                if (isset($_POST['mgm_payment_gateways'])) {
                    $checked = $payment_module == $_POST['mgm_payment_gateways'] ? 'checked="true"' : '';
                } else {
                    $checked = !empty($value) && $value == $field['value'] || $module_count === 1 ? 'checked="true"' : '';
                }
                // get obj
                $mod_obj = mgm_get_module($payment_module, 'payment');
                // html
                $img_url = mgm_site_url($mod_obj->logo);
                // desc
                $description = mgm_stripslashes_deep($mod_obj->description);
                //module description
                $html .= sprintf('<div id="%s_container" class="mgm_payment_opt_wrapper" %s>
						  	<input type="radio" %s class="checkbox" name="mgm_payment_gateways" value="%s" alt="%s" />
						 	<img class="mgm_payment_opt_customfield_image" src="%s" alt="%s" />
						  	<div class="mgm_paymod_description">%s</div>
						 </div>', $mod_obj->code, $hide_div, $checked, $mod_obj->code, $mod_obj->name, $img_url, $mod_obj->name, $description);
            }
            // scripts required for pack buttons:
            // $packs_obj = mgm_get_class('subscription_packs');
            // packs
            // $packs = $packs_obj->get_packs('register');
            // $lf = "\n";
            //script to show/hide appicable module buttons
            $html .= '<script type="text/javascript">jQuery(document).ready(function() {' . PHP_EOL;
            // bind as needed
            if ($dispaly_as_selectbox) {
                $html .= 'jQuery("select[rel=\'mgm_subscription_options\']").bind("change", function(){ mgm_select_pack_modules("select"); }).change();' . PHP_EOL;
            } else {
                $html .= 'jQuery(":input[rel=\'mgm_subscription_options\']").bind("click", function(){ mgm_select_pack_modules("radio"); });' . PHP_EOL;
                $html .= 'mgm_select_pack_modules("' . ($dispaly_as_selectbox ? 'select' : 'radio') . '");' . PHP_EOL;
                // @todo consider SELECT
            }
            // end
            $html .= '});</script>' . PHP_EOL;
        }
        // end
        $html .= '</div>';
        // return
        return $html;
    }
Exemplo n.º 6
0
    function get_button_subscribe($options = array())
    {
        // cb depends on product id, check for it before generating button
        if (!isset($options['pack']['product']['zombaio_price_id']) || intval($options['pack']['product']['zombaio_price_id']) == 0) {
            // return
            return '<div class="mgm_button_subscribe_payment">
						<b>' . __('Error in Zombaio settings : No Price ID set.', 'mgm') . '</b>
					</div>';
        }
        // get html
        $html = '<form action="' . $this->_get_endpoint('html_redirect') . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
				   <input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">
				   <input type="image" class="mgm_paymod_logo" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->name . '">
				   <div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>
			   </form>';
        // return
        return $html;
    }
    function get_button_buypost($options = array(), $return = false)
    {
        // get html
        $html = '<form action="' . $this->_get_endpoint('html_redirect') . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">

					<input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">

					<input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->name . '">

					<div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>
					<p class="paymill_payments_allowed">' . __('You can pay with:', 'paymill') . '</p>
					<p>';
        foreach ($GLOBALS['paymill_settings']->paymill_general_settings['payments_display'] as $name => $type) {
            if ($type == 1) {
                $html .= '<img src="' . plugins_url('', __FILE__) . '/../img/logos/' . $name . '.png" style="vertical-align:middle;" alt="' . $name . '" />';
            }
        }
        $html .= '</p>
			   </form>';
        // return or print
        if ($return) {
            return $html;
        } else {
            echo $html;
        }
    }
Exemplo n.º 8
0
    function get_button_subscribe($options = array())
    {
        // perm link
        $include_permalink = isset($options['widget']) ? false : true;
        // get trans id
        $tran_id = (int) $options['tran_id'];
        // get trans
        if (!($tran = mgm_get_transaction($tran_id))) {
            return __('Transaction invalid', 'mgm');
        }
        // generate
        $button_code = $this->_get_button_code($tran['data'], $tran_id);
        // extra code
        $additional_code = do_action('mgm_additional_code');
        // get html
        //modified the form to bypass process_html_redirect(issue#:514)
        //$html='<form action="'. $this->_get_endpoint('html_redirect',$include_permalink) .'" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
        $html = '<form action="' . $this->_get_endpoint('return') . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
					' . $button_code . '					
					' . $additional_code . '						
					<input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->name . '">	
					<div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>				
				</form>';
        // return
        return $html;
    }
/**
 * register post process
 *
 * @param int $user_id 
 * @return void or int $user_id
 */
function mgm_register($user_id)
{
    global $wpdb, $post;
    // check import in action and skip, tools->import calls mgm_register via "user_register" hook, this will help skip
    if (defined('MGM_DOING_USERS_IMPORT') && MGM_DOING_USERS_IMPORT == TRUE) {
        // return
        return $user_id;
    }
    // get mgm_system
    $system_obj = mgm_get_class('system');
    // hide
    $hide_custom_fields = $system_obj->get_setting('hide_custom_fields');
    // packs
    $packs = mgm_get_class('subscription_packs');
    // members object
    $member = mgm_get_member($user_id);
    // set status
    $member->set_field('status', MGM_STATUS_NULL);
    // get custom fields
    $cf_register_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true)));
    // mgm_subscription
    $mgm_subscription = mgm_post_var('mgm_subscription');
    // get subs
    $subs_pack = mgm_decode_package($mgm_subscription);
    // extract
    extract($subs_pack);
    // payment_gateways if set:
    $mgm_payment_gateways = mgm_post_var('mgm_payment_gateways');
    // Eg: $_POST['mgm_payment_gateways'] = mgm_paypal
    $cf_payment_gateways = !empty($mgm_payment_gateways) ? $mgm_payment_gateways : NULL;
    // init
    $member_custom_fields = array();
    // wordpress register
    $wordpres_form = mgm_check_wordpress_login();
    // system - issue #1237
    $short_format = !empty($system_obj->setting['date_format_short']) ? $system_obj->setting['date_format_short'] : MGM_DATE_FORMAT_SHORT;
    // loop
    foreach ($cf_register_page as $field) {
        // skip custom fields by settings call
        if ($hide_custom_fields == 'Y' || $hide_custom_fields == 'W' && $wordpres_form || $hide_custom_fields == 'C' && !$wordpres_form) {
            // if($hide_custom_fields && $field['name'] != 'subscription_options') continue;
            if (!in_array($field['name'], array('subscription_options', 'payment_gateways'))) {
                continue;
            }
        }
        //skip if payment_gateways custom field
        if ($field['name'] == 'payment_gateways') {
            continue;
        }
        //
        // do not save html
        if ($field['type'] == 'html' || $field['type'] == 'label') {
            continue;
        }
        // save
        switch ($field['name']) {
            case 'username':
                // #739
                if (isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['user_login'];
                }
                break;
            case 'email':
                // #739
                if (isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['user_email'];
                }
                break;
            case 'password':
                // #739
                // check
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    if (!empty($_POST[$field['attributes']['capture_field_alias']])) {
                        $user_password = @$_POST[$field['attributes']['capture_field_alias']];
                        $member_custom_fields[$field['name']] = mgm_encrypt_password($user_password, $user_id);
                    }
                } else {
                    if (!empty($_POST['user_password'])) {
                        $user_password = $_POST['user_password'];
                        $member_custom_fields[$field['name']] = mgm_encrypt_password($user_password, $user_id);
                    }
                }
                break;
            case 'autoresponder':
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    // checked issue #839
                    // if(in_array(strtolower($_POST[$field['attributes']['capture_field_alias']]), array('y','yes'))){
                    if (!empty($_POST[$field['attributes']['capture_field_alias']]) && $_POST['mgm_register_field'][$field['name']] == $field['value']) {
                        $member->subscribed = 'Y';
                        $member->autoresponder = $system_obj->active_modules['autoresponder'];
                    }
                } else {
                    // checked issue #839
                    // if(in_array(strtolower($_POST['mgm_register_field'][$field['name']]), array('y','yes'))){
                    if (!empty($_POST['mgm_register_field'][$field['name']]) && $_POST['mgm_register_field'][$field['name']] == $field['value']) {
                        // set to member, to be used on payment
                        $member->subscribed = 'Y';
                        $member->autoresponder = $system_obj->active_modules['autoresponder'];
                    }
                }
                break;
            case 'coupon':
                // #739
                // check alias
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    // check
                    if (!empty($_POST[$field['attributes']['capture_field_alias']])) {
                        // validate
                        if ($coupon = mgm_validate_coupon($_POST[$field['attributes']['capture_field_alias']], $cost)) {
                            // set
                            $member->coupon = $coupon;
                            // update coupon usage
                            mgm_update_coupon_usage($coupon['id'], 'register');
                        }
                    }
                } else {
                    // check primary
                    if (isset($_POST['mgm_register_field'][$field['name']]) && !empty($_POST['mgm_register_field'][$field['name']])) {
                        // validate
                        if ($coupon = mgm_validate_coupon($_POST['mgm_register_field'][$field['name']], $cost)) {
                            // set
                            $member->coupon = $coupon;
                            // update coupon usage
                            mgm_update_coupon_usage($coupon['id'], 'register');
                        }
                    }
                }
                break;
            case 'birthdate':
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    //issue #1237
                    $member_custom_fields[$field['name']] = mgm_format_inputdate_to_mysql($_POST[$field['attributes']['capture_field_alias']], $short_format);
                } else {
                    //convert from short date format to mysql format - issue #1237
                    $member_custom_fields[$field['name']] = mgm_format_inputdate_to_mysql($_POST['mgm_register_field'][$field['name']], $short_format);
                }
                break;
            default:
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } elseif ($field['type'] == 'checkbox' && is_array(@$_POST['mgm_register_field'][$field['name']])) {
                    //$member_custom_fields[$field['name']] = implode(" ", @$_POST['mgm_register_field'][$field['name']]);
                    //issue #1070
                    $val = @$_POST['mgm_register_field'][$field['name']];
                    $member_custom_fields[$field['name']] = serialize($val);
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['mgm_register_field'][$field['name']];
                }
                break;
        }
    }
    // end fields save
    // user password not provided
    /*
    	if (!isset( $user_password )){
    		$user_password = (isset($_POST['pass1']) && !empty($_POST['pass1'])) ? trim($_POST['pass1']) : substr(md5(uniqid(microtime())), 0, 7);		
    	}*/
    // user password not provided
    if (!isset($user_password)) {
        // take custom password fields, iss#717, consider BP custom password field
        $password_fields = array('pass1', 'signup_password');
        // loop
        foreach ($password_fields as $password_field) {
            // check if set
            if (isset($_POST[$password_field]) && !empty($_POST[$password_field])) {
                $user_password = trim($_POST[$password_field]);
                break;
            }
        }
    }
    // auto generate if still missing
    if (!isset($user_password)) {
        $user_password = substr(md5(uniqid(microtime())), 0, 7);
    }
    //encrypt password and save in
    $member->user_password = mgm_encrypt_password($user_password, $user_id);
    // md5
    $user_password_hash = wp_hash_password($user_password);
    // db update
    $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->users}` SET `user_pass` = %s WHERE ID = %d", $user_password_hash, $user_id));
    // unset label fields
    if (isset($member_custom_fields['password_conf'])) {
        unset($member_custom_fields['password_conf']);
    }
    // set custom
    $member->set_custom_fields($member_custom_fields);
    // set pack
    if ($pack_id) {
        // pack
        $pack = $packs->get_pack($pack_id);
        // set
        $member->amount = $pack['cost'];
        $member->duration = $pack['duration'];
        $member->duration_type = $pack['duration_type'];
        $member->active_num_cycles = $pack['num_cycles'];
        // set membership type
        $member->membership_type = $membership_type;
        // from mgm_subscription
        // set in member
        $member->pack_id = $pack_id;
        // from mgm_subscription
    }
    // set status
    $member->status = MGM_STATUS_NULL;
    // update option
    $member->save();
    // update user firstname/last name
    mgm_update_default_userdata($user_id);
    // admin check
    $is_admin = is_admin();
    //&& current_user_can('manage_options');
    // send
    $notify_user = true;
    // Block registration emails if Buddypress is enabled and disable_registration_email_bp value is Yes
    $block_reg_email = bool_from_yn(mgm_get_class('system')->get_setting('disable_registration_email_bp'));
    // send notification, bp active, do not send password, #739
    if (!isset($_POST['send_password']) && $is_admin || mgm_is_plugin_active('buddypress/bp-loader.php') && $block_reg_email) {
        $notify_user = false;
    }
    // send notification - issue #1468
    if ($system_obj->setting['enable_new_user_email_notifiction_after_user_active'] == 'N') {
        if ($notify_user) {
            mgm_new_user_notification($user_id, $user_password, $is_admin ? false : true);
        }
        $notify_user = false;
    }
    // hook for other plugin who wishes to use default "user_register"
    do_action('mgm_user_register', $user_id);
    // process payment only when registered from site, not when user added by admin
    if ($is_admin) {
        // unset
        unset($_POST['send_password']);
        //prevent sending user email again
        // assign default pack
        do_action('mgm_admin_user_register', $user_id, $notify_user);
        // return id
        return $user_id;
    }
    // if on wordpress page or custompage
    $post_id = get_the_ID();
    // post custom register
    if ($post_id > 0 && $post->post_type == 'post') {
        $redirect = get_permalink($post_id);
    } else {
        $redirect = mgm_get_custom_url('transactions');
    }
    // if buddypress url replace by register url : issue#: 791
    $redirect = apply_filters('mgm_bp_register_url', $redirect);
    // userdata
    $userdata = get_userdata($user_id);
    // note this fix VERY IMPORTANT, needed for PAYPAL PRO CC POST
    $redirect = add_query_arg(array('username' => urlencode($userdata->user_login)), $redirect);
    // add redirect
    if ($redirector = mgm_request_var('mgm_redirector', mgm_request_var('redirect_to', '', true), true)) {
        $redirect = add_query_arg(array('redirector' => $redirector), $redirect);
    }
    // with subscription
    if ($mgm_subscription) {
        $redirect = add_query_arg(array('subs' => $mgm_subscription, 'method' => 'payment_subscribe'), $redirect);
    }
    // bypass step2 if payment gateway is submitted: issue #: 469
    if (!is_null($cf_payment_gateways)) {
        // pack
        $packs_obj = mgm_get_class('subscription_packs');
        // validate
        $pack = $packs_obj->validate_pack($cost, $duration, $duration_type, $membership_type, $pack_id);
        // error
        if ($pack != false) {
            // get pack
            mgm_get_register_coupon_pack($member, $pack);
            // cost
            if ((double) $pack['cost'] > 0) {
                //get an object of the payment gateway:
                $mod_obj = mgm_get_module($cf_payment_gateways, 'payment');
                // tran options
                $tran_options = array('is_registration' => true, 'user_id' => $user_id, 'notify_user' => $notify_user);
                // is register & purchase
                if (isset($_POST['post_id'])) {
                    $tran_options['post_id'] = (int) $_POST['post_id'];
                }
                // is register & purchase postpack
                if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
                    $tran_options['postpack_post_id'] = (int) $_POST['postpack_post_id'];
                    $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
                }
                // create transaction
                // $tran_id = $mod_obj->_create_transaction($pack, $tran_options);
                $tran_id = mgm_add_transaction($pack, $tran_options);
                //bypass directly to process return if manual payment:
                if ($cf_payment_gateways == 'mgm_manualpay') {
                    // set
                    $_POST['custom'] = $tran_id;
                    // direct call to module return function:
                    $mod_obj->process_return();
                    // exit
                    exit;
                }
                // encode id:
                $tran_id = mgm_encode_id($tran_id);
                // redirect - if on wordpress page or custompage - issue #1648
                if ($post_id > 0 && $post->post_type == 'post') {
                    $redirect = $mod_obj->_get_endpoint('html_redirect', true);
                } else {
                    $redirect = $mod_obj->_get_endpoint('html_redirect', false);
                }
                // if buddypress url replace by register url : issue#: 791
                $redirect = add_query_arg(array('tran_id' => $tran_id), apply_filters('mgm_bp_register_url', $redirect));
            } else {
                // issue #1468
                $redirect = add_query_arg(array('notify_user' => $notify_user), $redirect);
            }
        }
    }
    // ends custom payment gateway bypassing
    // is register & purchase
    if (isset($_POST['post_id'])) {
        $redirect = add_query_arg(array('post_id' => (int) $_POST['post_id']), $redirect);
    }
    // is register & purchase postpack
    if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
        $redirect = add_query_arg(array('postpack_id' => (int) $_POST['postpack_id'], 'postpack_post_id' => (int) $_POST['postpack_post_id']), $redirect);
    }
    // redirect filter, returing a false can stop the redirect
    $redirect = apply_filters('mgm_after_regiter_redirect', mgm_site_url($redirect));
    // redirect
    if ($redirect !== FALSE) {
        // do the redirect to payment
        mgm_redirect($redirect);
        // this goes to subscribe, mgm_functions.php/mgm_get_subscription_buttons
        // exit
        exit;
    }
    // default
    return $user_id;
}
Exemplo n.º 10
0
    function get_button_buypost($options = array(), $return = false)
    {
        // get html
        $html = '<form action="' . $this->_get_endpoint('html_redirect') . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
					<input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">
					<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
					<input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->button_message . '">
					<div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>
			   </form>';
        // return or print
        if ($return) {
            return $html;
        }
        // print
        echo $html;
    }
Exemplo n.º 11
0
    function get_button_subscribe($options = array())
    {
        // permlink
        $include_permalink = isset($options['widget']) ? false : true;
        // get html
        $html = '<form action="' . $this->_get_endpoint('html_redirect', $include_permalink) . '" method="post" class="mgm_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
				   <input type="hidden" name="tran_id" value="' . $options['tran_id'] . '">
				   <input class="mgm_paymod_logo" type="image" src="' . mgm_site_url($this->logo) . '" border="0" name="submit" alt="' . $this->name . '">
				   <div class="mgm_paymod_description">' . mgm_stripslashes_deep($this->description) . '</div>
			   </form>';
        // return
        return $html;
    }
/**
 * get custom url, return default if not published
 *
 * @param string key/name of page
 * @param bool force default
 * @param array query string
 * @return string url 
 */
function mgm_get_custom_url($name, $load_default = false, $query_arg = array())
{
    // get system
    $system_obj = mgm_get_class('system');
    // is published page
    $is_published = mgm_is_custom_page_published($name == 'purchase_content' ? 'transactions' : $name);
    // on name
    switch ($name) {
        case 'login':
            // custom
            if (!$load_default && $is_published && ($login_url = mgm_get_setting('login_url'))) {
                $url = mgm_site_url($login_url);
            } else {
                // default
                $url = site_url('wp-login.php?action=login', 'login');
            }
            break;
        case 'register':
            // custom
            if (!$load_default && $is_published && ($register_url = mgm_get_setting('register_url'))) {
                $url = mgm_site_url($register_url);
            } elseif (!$load_default) {
                // old
                $url = add_query_arg(array('method' => 'register'), mgm_home_url('purchase_subscription'));
            } else {
                // default
                $url = site_url('wp-login.php?action=register', 'login');
            }
            break;
        case 'lostpassword':
            // custom
            if (!$load_default && $is_published && ($lostpassword_url = mgm_get_setting('lostpassword_url'))) {
                $url = mgm_site_url($lostpassword_url);
            } else {
                // default
                $url = site_url('wp-login.php?action=lostpassword');
            }
            break;
        case 'profile':
            // custom
            if (!$load_default && $is_published && ($profile_url = mgm_get_setting('profile_url'))) {
                $url = mgm_site_url($profile_url);
            } else {
                // default
                $url = admin_url('profile.php');
            }
            break;
        case 'userprofile':
            // custom
            if (!$load_default && $is_published && ($public_profile_url = mgm_get_setting('userprofile_url'))) {
                $url = mgm_site_url($public_profile_url);
            } else {
                // default
                $url = admin_url('profile.php');
            }
            break;
        case 'purchase_content':
            // reuse the same transactions url here: issue#: 756
            // $is_published = mgm_is_custom_page_published('transactions');
        // reuse the same transactions url here: issue#: 756
        // $is_published = mgm_is_custom_page_published('transactions');
        case 'transactions':
            // custom
            if ($is_published && ($transactions_url = mgm_get_setting('transactions_url'))) {
                $url = mgm_site_url($transactions_url, true);
            } else {
                // default
                $url = mgm_home_url($name == 'purchase_content' ? 'purchase_content' : 'purchase_subscription');
            }
            break;
        case 'membership_details':
            // custom
            if ($is_published && !$load_default && !is_super_admin() && ($membership_details_url = mgm_get_setting('membership_details_url'))) {
                $url = mgm_site_url($membership_details_url);
            } else {
                // default
                $url = admin_url(sprintf('%s.php?page=mgm/profile', is_super_admin() ? 'users' : 'profile'));
            }
            break;
        case 'membership_contents':
            // custom
            if ($is_published && !$load_default && !is_super_admin() && ($membership_contents_url = mgm_get_setting('membership_contents_url'))) {
                $url = mgm_site_url($membership_contents_url);
            } else {
                // default
                $url = admin_url(sprintf('%s.php?page=mgm/membership/content', is_super_admin() ? 'users' : 'profile'));
            }
            break;
        default:
            // default
            $url = mgm_home_url('purchase_subscription');
            break;
    }
    // @todo: add_query_arg urlencodes url with page=mgm/ need fix in some servers
    // add query arg
    if (!empty($query_arg)) {
        $url = add_query_arg($query_arg, $url);
    }
    // return
    return $url;
}
/**
 * custom register form, used in sidebar
 *
 * @param boolean $use_custom_fields
 * @param boolean $default_subscription_pack
 * @return string $form
 */
function mgm_sidebar_user_register_form($use_custom_fields, $default_subscription_pack)
{
    // registration disabled
    if (!get_option('users_can_register')) {
        // redirect
        return __('User registration is currently not allowed.', 'mgm');
    }
    // system
    $system_obj = mgm_get_class('system');
    // register button text
    $register_button_text = apply_filters('mgm_register_button_text', $system_obj->get_setting('register_text', __('Register', 'mgm')));
    // cf
    $cf_register_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true)));
    // html form
    $html = '<form name="registerform" id="registerform" action="' . mgm_get_custom_url('register') . '" method="post">';
    // email as username
    // if(bool_from_yn($system_obj->get_setting('enable_email_as_username'))){
    // 	$email_username_label = __('Email','mgm');
    // }else{
    // 	$email_username_label = __('Username','mgm');
    // }
    // username
    if (!bool_from_yn($system_obj->get_setting('enable_email_as_username'))) {
        if (!mgm_is_customfield_active(array('username'), $cf_register_page) || !$use_custom_fields) {
            $html .= '<p>
						<label>' . __('Username', 'mgm') . '<br />
						<input type="text" name="user_login" id="user_login" class="input" value="" size="20" tabindex="10" /></label>
					  </p>';
        }
    }
    // email
    if (!mgm_is_customfield_active(array('email'), $cf_register_page) || !$use_custom_fields) {
        $html .= '<p>
					<label>' . __('E-mail', 'mgm') . '<br />
					<input type="email" name="user_email" id="user_email" class="input" value="" size="20" tabindex="20" /></label>
				  </p>';
    }
    // custom
    if ($use_custom_fields) {
        // do_action('register_form');
        // custom
        $html .= apply_filters('mgm_register_form', $html);
        //Issue #777
    } elseif ($default_subscription_pack) {
        $obj_packs = mgm_get_class('subscription_packs');
        $packs = $obj_packs->get_packs('register');
        $subs_pack = mgm_decode_package($default_subscription_pack);
        $modules = array();
        foreach ($packs as $pack) {
            if ($pack['id'] == $subs_pack['pack_id']) {
                $modules = $pack['modules'];
            }
        }
        $cnt = count($modules);
        if ($cnt > 1) {
            for ($i = 0; $i < $cnt; $i++) {
                //issue #1298
                if (in_array($modules[$i], array('mgm_free', 'mgm_trial'))) {
                    continue;
                }
                //issue #1298
                if ($subs_pack['cost'] == 0 && mgm_get_module('mgm_free')->enabled == 'Y') {
                    continue;
                }
                $mod_obj = mgm_get_module($modules[$i], 'payment');
                $img_url = mgm_site_url($mod_obj->logo);
                $checked = $i === 0 ? 'checked="true"' : '';
                //module description
                $html .= sprintf('<div id="%s_container" class="mgm_payment_opt_wrapper" %s>', $mod_obj->code, $hide_div) . sprintf('<input type="radio" %s class="checkbox" name="mgm_payment_gateways" value="%s" alt="%s" />', $checked, $mod_obj->code, $mod_obj->name) . sprintf('<img class="mgm_payment_opt_customfield_image" src="%s" alt="%s" />', $img_url, $mod_obj->name) . sprintf('<div class="mgm_paymod_description">%s</div>', mgm_stripslashes_deep($mod_obj->description)) . '</div>';
            }
        } else {
            $html .= '<input type="hidden" name="mgm_payment_gateways" value="' . (isset($modules[0]) ? $modules[0] : '') . '" alt="Paypal Standard"/>';
            //@todo need actual first module
        }
        $html .= '<input type="hidden" class="checkbox" name="mgm_subscription" value="' . $default_subscription_pack . '"/>';
        $html .= '<input type="hidden" class="checkbox" name="mgm_custom_fields" value="' . $use_custom_fields . '"/>';
        $html .= '<input type="hidden" class="checkbox" name="mgm_widget_active" value="true"/>';
    }
    // nonce
    $nonce = wp_nonce_field('user_register', '_mgmnonce_user_register', true, false);
    // html
    $html .= '<p id="reg_passmail">' . __('A password will be e-mailed to you.') . '</p>
		 	  <p><input class="button mgm-register-button" type="submit" name="wp-submit" id="wp-submit" value="' . $register_button_text . '" tabindex="100" /></p>
		  	  <input type="hidden" name="method" value="create_user">
			 ' . $nonce . '
		  </form>';
    // apply filter and return
    return apply_filters('mgm_sidebar_register_form_html', $html);
}