/**
  * Check nonce value
  * @return bool
  */
 public static function check_nonce()
 {
     $_psts_nonce = ProSites_Helper_Session::session('_psts_nonce');
     if (empty($_psts_nonce)) {
         return false;
     }
     if ($_POST['_psts_nonce'] == $_psts_nonce) {
         ProSites_Helper_Session::unset_session('_psts_nonce');
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 public static function apply_coupon_to_checkout()
 {
     $doing_ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false;
     $ajax_response = array();
     if ($doing_ajax) {
         $coupon_code = sanitize_text_field($_POST['coupon_code']);
         $valid_coupon = self::check_coupon($coupon_code);
         if (!empty($valid_coupon)) {
             $ajax_response['valid'] = true;
             ProSites_Helper_Session::session('COUPON_CODE', $coupon_code);
         } else {
             $ajax_response['valid'] = false;
             ProSites_Helper_Session::unset_session('COUPON_CODE');
         }
         //				$ajax_response['value'] = self::coupon_value( $coupon_code, '200' );
         $first_periods = array('price_1' => __('first month only', 'psts'), 'price_3' => __('first 3 months only', 'psts'), 'price_12' => __('first 12 months only', 'psts'));
         // New pricing
         if ($valid_coupon) {
             $original_levels = get_site_option('psts_levels');
             $level_list = self::get_adjusted_level_amounts($coupon_code);
             $coupon_obj = self::get_coupon($coupon_code);
             foreach ($level_list as $key => $level) {
                 unset($level_list[$key]['is_visible']);
                 unset($level_list[$key]['name']);
                 unset($level_list[$key]['setup_fee']);
                 if ($original_levels[$key]['price_1'] == $level['price_1']) {
                     $level_list[$key]['price_1_adjust'] = false;
                     unset($level_list[$key]['price_1']);
                 } else {
                     $level_list[$key]['price_1'] = '<div class="plan-price coupon-amount">' . ProSites_Helper_UI::rich_currency_format($level['price_1']) . '</div>';
                     if ('first' == $coupon_obj['lifetime']) {
                         $level_list[$key]['price_1_period'] = '<div class="period coupon-period">' . $first_periods['price_1'] . '</div>';
                     } else {
                         $level_list[$key]['price_1_period'] = '';
                     }
                     $level_list[$key]['price_1_adjust'] = true;
                 }
                 if ($original_levels[$key]['price_3'] == $level['price_3']) {
                     $level_list[$key]['price_3_adjust'] = false;
                     unset($level_list[$key]['price_3']);
                 } else {
                     $level_list[$key]['price_3'] = '<div class="plan-price coupon-amount">' . ProSites_Helper_UI::rich_currency_format($level['price_3']) . '</div>';
                     $total_1 = $original_levels[$key]['price_1'] * 3;
                     $total_3 = $level['price_3'];
                     $monthly = $level['price_3'] / 3;
                     $saving = $total_1 - $total_3;
                     $level_list[$key]['price_3_monthly'] = '<div class="monthly-price coupon-amount">' . ProSites_Helper_UI::rich_currency_format($monthly) . '</div>';
                     $level_list[$key]['price_3_savings'] = '<div class="savings-price coupon-amount">' . ProSites_Helper_UI::rich_currency_format($saving) . '</div>';
                     if ('first' == $coupon_obj['lifetime']) {
                         $level_list[$key]['price_3_period'] = '<div class="period coupon-period">' . $first_periods['price_3'] . '</div>';
                     } else {
                         $level_list[$key]['price_3_period'] = '';
                     }
                     $level_list[$key]['price_3_adjust'] = true;
                 }
                 if ($original_levels[$key]['price_12'] == $level['price_12']) {
                     $level_list[$key]['price_12_adjust'] = false;
                     unset($level_list[$key]['price_12']);
                 } else {
                     $level_list[$key]['price_12'] = '<div class="plan-price coupon-amount">' . ProSites_Helper_UI::rich_currency_format($level['price_12']) . '</div>';
                     $total_1 = $original_levels[$key]['price_1'] * 12;
                     $total_12 = $level['price_12'];
                     $monthly = $level['price_12'] / 12;
                     $saving = $total_1 - $total_12;
                     $level_list[$key]['price_12_monthly'] = '<div class="monthly-price coupon-amount">' . ProSites_Helper_UI::rich_currency_format($monthly) . '</div>';
                     $level_list[$key]['price_12_savings'] = '<div class="savings-price coupon-amount">' . ProSites_Helper_UI::rich_currency_format($saving) . '</div>';
                     if ('first' == $coupon_obj['lifetime']) {
                         $level_list[$key]['price_12_period'] = '<div class="period coupon-period">' . $first_periods['price_12'] . '</div>';
                     } else {
                         $level_list[$key]['price_12_period'] = '';
                     }
                     $level_list[$key]['price_12_adjust'] = true;
                 }
             }
             $ajax_response['levels'] = $level_list;
         }
         $response = array('what' => 'response', 'action' => 'apply_coupon_to_checkout', 'id' => 1, 'data' => json_encode($ajax_response));
         // Buffer used to isolate AJAX response from unexpected output
         ob_end_clean();
         ob_start();
         $xmlResponse = new WP_Ajax_Response($response);
         $xmlResponse->send();
         ob_end_flush();
     }
 }
Example #3
0
 public static function render_account_modified($content, $blog_id, $domain)
 {
     global $psts;
     $render_data['plan_updated'] = ProSites_Helper_Session::session('plan_updated');
     // Exit as if this never happened
     if (!isset($render_data['plan_updated']) || false == $render_data['plan_updated']['render']) {
         return $content;
     }
     $level_list = get_site_option('psts_levels');
     $periods = array(1 => __('monthly', 'psts'), 3 => __('quarterly', 'psts'), 12 => __('anually', 'psts'));
     $previous = '<strong>' . $level_list[$render_data['plan_updated']['prev_level']]['name'] . '</strong> (' . $periods[$render_data['plan_updated']['prev_period']] . ')';
     $current = '<strong>' . $level_list[$render_data['plan_updated']['level']]['name'] . '</strong> (' . $periods[$render_data['plan_updated']['period']] . ')';
     $blog_id = (int) $render_data['plan_updated']['blog_id'];
     $content = '<div id="psts-payment-info-received">';
     $user = wp_get_current_user();
     $email = $user->user_email;
     $content .= '<h2>' . esc_html__('Plan updated...', 'psts') . '</h2>';
     $content .= '<p>' . sprintf(esc_html__('Your plan was successfully modified from %s to %s. You will receive a receipt email shortly to confirm this action.', 'psts'), $previous, $current) . '</p>';
     $content .= '<p>' . esc_html__('If you did not receive an email please try the following:', 'psts') . '</p>';
     $content .= '<ul>' . '<li>' . esc_html__('Wait a little bit longer.', 'psts') . '</li>' . '<li>' . esc_html__('Check your spam folder just in case it ended up in there.', 'psts') . '</li>' . '<li>' . esc_html__('Make sure that your email address is correct (' . $email . ')', 'psts') . '</li>' . '</ul>';
     $content .= '<p>' . esc_html__('If your email address is incorrect or you noticed a problem, please contact us to resolve the issue.', 'psts') . '</p>';
     $content .= '<a href="' . $psts->checkout_url($blog_id) . '">' . esc_html__('Go back to your account.', 'psts') . '</a>';
     $content .= '</div>';
     ProSites_Helper_Session::unset_session('plan_updated');
     return $content;
 }
Example #4
0
	/**
	 * Activates the user blog if a domain is specified and if the blog is not already active
	 *
	 * @param bool $domain
	 * @param bool $trial
	 * @param bool $period
	 * @param bool $level
	 *
	 * @return bool
	 */
	function activate_user_blog( $domain = false, $trial = true, $period = false, $level = false ) {
		global $wpdb, $path;

		$trial_days = $this->get_setting( 'trial_days', 0 );
		if ( ! $domain ) {
			return false;
		}

		//Get activation key from db
		$signup         = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s", $domain ) );
		$activation_key = ! empty( $signup->activation_key ) ? $signup->activation_key : '';
		if ( ! $activation_key || $signup->active ) {
			//get blog id
			$fields = array(
				'domain' => $domain,
				'path'   => '/'
			);
			$blog   = get_blog_details( $fields );

			return ! empty( $blog->blog_id ) ? $blog->blog_id : false;
		}
		$result = wpmu_activate_signup( $activation_key );

		if ( empty( $result['user_id'] ) ) {
			return false;
		}
		//Get user login by user id
		$user = get_user_by( 'id', $result['user_id'] );

		if ( empty( $user ) || is_wp_error( $user ) ) {
			return false;
		}

		//Login user to follow up the rest of Pro Site process
		$creds = array(
			'user_login'    => $user->user_login,
			'user_password' => $result['password']
		);
		$user  = wp_signon( $creds, true );
		wp_set_current_user( $user->ID );

		//Set Trial
		if ( $trial ) {
			$this->extend( $result['blog_id'], $period, 'Trial', $level, '', strtotime( '+ ' . $trial_days . ' days' ) );
			//Redirect to checkout on next signup
			update_blog_option( $result['blog_id'], 'psts_signed_up', 1 );
		}

		// Unset Domain name from session if its still there
		ProSites_Helper_Session::unset_session( 'domain' );

		if ( isset( $result['blog_id'] ) ) {
			return $result['blog_id'];
		} else {
			return false;
		}
	}
Example #5
0
 public static function ajax_check_prosite_blog()
 {
     global $psts, $current_site;
     $blog_data = array();
     // Add ajax session var
     ProSites_Helper_Session::session('psts_ajax_session_activated', true);
     // Introduce a fake error because we don't want to actually create the blog yet.
     add_filter('registration_errors', array('ProSites_Model_Registration', 'prosite_blog_check_only'), 10, 3);
     // replace $_POST with array data
     $params = array();
     parse_str($_POST['data'], $params);
     $period = (int) $_POST['period'];
     $level = 'free' == $_POST['level'] ? $_POST['level'] : (int) $_POST['level'];
     $_POST = $params;
     $doing_ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false;
     $ajax_response = array();
     if ($doing_ajax) {
         $user_name = sanitize_text_field($_POST['user_name']);
         $user_email = sanitize_email($_POST['user_email']);
         $blogname = sanitize_text_field($_POST['blogname']);
         $blog_title = sanitize_text_field(urldecode($_POST['blog_title']));
         // Process some cleaning up if needed
         do_action('prosite_register_blog_pre_validation', $user_name, $user_email, $blogname);
         $blog_validation = wpmu_validate_blog_signup($blogname, $blog_title);
         // Attempt to create a new user (knowing that it will fail, but it should only have our error)
         if (!isset($_POST['new_blog'])) {
             $validation = wpmu_validate_user_signup($user_name, $user_email);
             // nicer errors, but doesn't deal with custom fields
             $user_check = register_new_user($user_name, $user_email);
             // checks custom fields, but ugly errors
             $user_check->errors = array_merge($user_check->errors, $validation['errors']->errors);
             $user_check->errors = array_merge($user_check->errors, $blog_validation['errors']->errors);
         } else {
             $user_check = new WP_Error();
             $user_check->errors = array_merge($user_check->errors, $blog_validation['errors']->errors);
         }
         // Replaced session vars to make it semi-stateless, will pick these up in a session later
         $blog_data['new_blog_details'] = array();
         $blog_data['new_blog_details']['username'] = $user_name;
         $blog_data['new_blog_details']['email'] = $user_email;
         $blog_data['new_blog_details']['blogname'] = $blogname;
         $blog_data['new_blog_details']['title'] = $blog_title;
         $blog_data['new_blog_details']['level'] = $level;
         $blog_data['new_blog_details']['period'] = $period;
         $username_available = true;
         $email_available = true;
         $blogname_available = true;
         $blogtitle_available = true;
         // Checking passed...
         if (!empty($user_check->errors) && 1 == count($user_check->errors) && !isset($_POST['new_blog']) || 0 == count($user_check->errors) && isset($_POST['new_blog'])) {
             $keys = array_keys($user_check->errors);
             if ($keys && !in_array('availability_check_only', $keys) && !isset($_POST['new_blog'])) {
                 // Something went wrong!
                 $ajax_response['user_available'] = false;
             } else {
                 // All good!  We're ready to create the user/site
                 /** User is validated using register_new_user so that we can use the hooks and make them available,
                  * but we still need to actually create and activate the signup to get the $user_id. */
                 $blog = $blog_validation;
                 $domain = $blog['domain'];
                 $path = $blog['path'];
                 $blogname = $blog['blogname'];
                 $blog_title = $blog['blog_title'];
                 $errors = $blog['errors'];
                 // Privacy setting
                 $public = (int) $_POST['blog_public'];
                 $signup_meta = array('lang_id' => 1, 'public' => $public);
                 // Create the signup
                 $meta = apply_filters('add_signup_meta', $signup_meta);
                 $result = ProSites_Helper_Registration::signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);
                 $blog_data['activation_key'] = $result['activation_key'];
                 if (isset($result['user_pass']) && !empty($result['user_pass'])) {
                     $blog_data['new_blog_details']['user_pass'] = $result['user_pass'];
                 }
                 $trial_days = $psts->get_setting('trial_days', 0);
                 $trial_active = !empty($trial_days);
                 $site_name = '';
                 if (!is_subdomain_install()) {
                     $site_name = $current_site->domain . $current_site->path . $blogname;
                 } else {
                     $site_name = $blogname . '.' . ($site_domain = preg_replace('|^www\\.|', '', $current_site->domain));
                 }
                 if ($trial_active) {
                     $recurring = $psts->get_setting('recurring_subscriptions', 1);
                     if ($recurring) {
                         $blog_data['new_blog_details']['reserved_message'] = sprintf('<div class="reserved_msg"><h2>' . __('Activate your site', 'psts') . '</h2>' . __('<p>Your site <strong>(%s)</strong> has been reserved but is not yet activated.</p><p>Once payment information has been verified your trial period will begin. When your trial ends you will be automatically upgraded to your chosen plan. Your reservation only last for 48 hours upon which your site name will become available again.</p><p>Please use the form below to setup your payment information.</p>', 'psts') . '</div>', $site_name);
                     } else {
                         // Non-recurring sites really should not do anything at checkout other than activate.
                         $result = ProSites_Helper_Registration::activate_blog($blog_data, true, $period, $level);
                         $blog_id = $result['blog_id'];
                         if (isset($result['password'])) {
                             $blog_data['new_blog_details']['user_pass'] = $result['password'];
                         }
                         ProSites_Helper_Registration::set_trial($blog_id, 1);
                         //Update Activation Key for blog
                         ProSites_Helper_Registration::update_activation_key($blog_id, $blog_data['activation_key']);
                         $psts->record_stat($blog_id, 'signup');
                         $ajax_response['show_finish'] = true;
                         $ajax_response['finish_content'] = ProSites_View_Front_Gateway::render_payment_submitted($blog_data, true);
                     }
                 } else {
                     $blog_data['new_blog_details']['reserved_message'] = sprintf('<div class="reserved_msg"><h2>' . __('Activate your site', 'psts') . '</h2>' . __('<p>Your site <strong>(%s)</strong> has been reserved but is not yet activated.</p><p>Once payment has been processed your site will become active with your chosen plan. Your reservation only last for 48 hours upon which your site name will become available again.</p><p>Please use the form below to setup your payment information.</p>', 'psts') . '</div>', $site_name);
                 }
                 // FREE basic site
                 if ('free' == $blog_data['new_blog_details']['level']) {
                     if (isset($blog_data['new_blog_details']['reserved_message'])) {
                         unset($blog_data['new_blog_details']['reserved_message']);
                     }
                     $result = ProSites_Helper_Registration::activate_blog($blog_data, false, false, false);
                     $blog_data['new_blog_details']['blog_id'] = $result['blog_id'];
                     if (isset($result['password'])) {
                         $blog_data['new_blog_details']['user_pass'] = $result['password'];
                     }
                     $ajax_response['show_finish'] = true;
                     $ajax_response['finish_content'] = ProSites_View_Front_Gateway::render_free_confirmation($blog_data);
                 }
                 if (isset($blog_data['new_blog_details']['reserved_message'])) {
                     $ajax_response['reserved_message'] = $blog_data['new_blog_details']['reserved_message'];
                 }
             }
             // If WP 4.0+ and user is logged in it will use WP_Session_Tokens, else $_SESSION
             ProSites_Helper_Session::session('new_blog_details', $blog_data['new_blog_details']);
             ProSites_Helper_Session::session('activation_key', $blog_data['activation_key']);
             $ajax_response['gateways_form'] = ProSites_View_Front_Gateway::render_checkout($blog_data);
         } else {
             // We had registration errors, redraw the form displaying errors
             if (!empty($user_check) && isset($user_check->errors)) {
                 $ajax_response['form'] = ProSites_View_Front_Registration::render_signup_form($blog_data, $user_check);
                 $ajax_response['user_available'] = false;
             }
             // Isolate which standard fields are valid
             $error_keys = array_keys($user_check->errors);
             foreach ($error_keys as $key) {
                 if (preg_match('/username|user_name/', $key)) {
                     $username_available = false;
                 }
                 if (preg_match('/email/', $key)) {
                     $email_available = false;
                 }
                 if (preg_match('/blogname/', $key)) {
                     $blogname_available = false;
                 }
                 if (preg_match('/blog_title/', $key)) {
                     $blogtitle_available = false;
                 }
             }
         }
         $ajax_response['username_available'] = $username_available;
         $ajax_response['email_available'] = $email_available;
         $ajax_response['blogname_available'] = $blogname_available;
         $ajax_response['blog_title_available'] = $blogtitle_available;
         $response = array('what' => 'response', 'action' => 'check_prosite_blog', 'id' => 1, 'data' => json_encode($ajax_response));
         // No longer need ajax session
         ProSites_Helper_Session::unset_session('psts_ajax_session_activated');
         // Buffer used to isolate AJAX response from unexpected output
         @ob_end_clean();
         ob_start();
         $xmlResponse = new WP_Ajax_Response($response);
         $xmlResponse->send();
         ob_end_flush();
     }
 }