public static function getInstance($args)
 {
     if (!isset(self::$instance)) {
         $className = __CLASS__;
         self::$instance = new $className($args);
     }
     return self::$instance;
 }
Esempio n. 2
0
	function checkout_grid( $blog_id, $domain = '' ) {

		global $wpdb;
		$curr = '';

		$use_plans_table    = $this->get_setting( 'plans_table_enabled', 'enabled' );
		$show_pricing_table = $this->get_setting( 'comparison_table_enabled' ) ? $this->get_setting( 'comparison_table_enabled' ) : $this->get_setting( 'co_pricing' );
		$content            = "";
		include_once $this->plugin_dir . 'lib/psts_pricing_table.php';
		$pricing_table = ProSites_Pricing_Table::getInstance( array(
			'blog_id' => $blog_id
		) );

		if ( $show_pricing_table === "enabled" ) {
			$content .= $pricing_table->display_plans_table( 'include-pricing' );

			return apply_filters( 'psts_checkout_grid_output', $content );
		}

		if ( $use_plans_table === "enabled" ) {
			$content .= $pricing_table->display_plans_table();

			return apply_filters( 'psts_checkout_grid_output', $content );
		}

		if( 'enabled' === $use_plans_table || 'enabled' === $show_pricing_table ) {
			return false;
		}


		// DO IT THE OLD WAY

		$levels    = (array) get_site_option( 'psts_levels' );
		$recurring = $this->get_setting( 'recurring_subscriptions', 1 );

		//if you want to display the lowest level first on checkout grid add define('PSTS_DONT_REVERSE_LEVELS', true); to your wp-config.php file
		if ( ! ( defined( 'PSTS_DONT_REVERSE_LEVELS' ) && PSTS_DONT_REVERSE_LEVELS ) ) {
			$levels = array_reverse( $levels, true );
		}

		//remove levels that are hidden
		foreach ( $levels as $level_id => $level ) {
			$is_visible = isset( $level['is_visible'] ) ? (bool) $level['is_visible'] : true;
			if ( $is_visible ) {
				continue;
			}
			unset( $levels[ $level_id ] );
		}

		$periods = (array) $this->get_setting( 'enabled_periods' );
		if ( ! empty( $blog_id ) ) {
			$curr = $wpdb->get_row( $wpdb->prepare( "SELECT term, level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = %d", $blog_id ) );
		}

		if ( $curr ) {
			$curr->term = ( $curr->term && ! is_numeric( $curr->term ) ) ? $periods[0] : $curr->term; //if term not numeric
			$sel_period = isset( $_POST['period'] ) ? $_POST['period'] : $curr->term;
			$sel_level  = isset( $_POST['level'] ) ? $_POST['level'] : $curr->level;
		} else {
			@$curr->term = null;
			$curr->level = null;
			$sel_period  = isset( $_POST['period'] ) ? $_POST['period'] : ( defined( 'PSTS_DEFAULT_PERIOD' ) ? PSTS_DEFAULT_PERIOD : null );
			$sel_level   = isset( $_POST['level'] ) ? $_POST['level'] : ( defined( 'PSTS_DEFAULT_LEVEL' ) ? PSTS_DEFAULT_LEVEL : null );
		}

		if ( count( $periods ) >= 3 ) {
			$width      = '23%';
			$free_width = '95%';
		} else if ( count( $periods ) == 2 ) {
			$width      = '30%';
			$free_width = '92.5%';
		} else {
			$width      = '40%';
			$free_width = '85%';
		}

		$content = '';

		/*
		//show chosen blog
		$content .= '<div id="psts-chosen-blog">'.sprintf(__('You have chosen to upgrade <strong>%1$s</strong> (%2$s).', 'psts'), get_blog_option($blog_id, 'blogname'), get_blog_option($blog_id, 'siteurl')).'
								 <a id="psts-change-blog" href="'.$this->checkout_url().'">'.__('Change &raquo;', 'psts').'</a><br>
								</div>';
		*/

		$content = apply_filters( 'psts_before_checkout_gridcoupon-submit', $content, $blog_id );

		//add coupon line
		if ( $session_coupon = ProSites_Helper_Session::session( 'COUPON_CODE' ) ) {
			$coupon_value = $this->coupon_value( $session_coupon, 100 );
			$content .= '<div id="psts-coupon-msg">' . sprintf( __( 'Your coupon code <strong>%1$s</strong> has been applied for a discount of %2$s off the first payment. <a href="%3$s">Remove it &raquo;</a>', 'psts' ), esc_html( $session_coupon ), $coupon_value['discount'], get_permalink() . "?bid=$blog_id&remove_coupon=1" ) . '</div>';
		} else if ( $errmsg = $this->errors->get_error_message( 'coupon' ) ) {
			$content .= '<div id="psts-coupon-error" class="psts-error">' . $errmsg . '</div>';
		}

		$content = apply_filters( 'psts_before_checkout_grid', $content, $blog_id );

		$content .= '<table id="psts_checkout_grid" width="100%">';

		if ( $recurring ) {
			$content .= '<tr class="psts_level_head">
					<th>' . __( 'Level', 'psts' ) . '</th>';
			if ( in_array( 1, $periods ) ) {
				$content .= '<th>' . __( 'Monthly', 'psts' ) . '</th>';
			}
			if ( in_array( 3, $periods ) ) {
				$content .= '<th>' . __( 'Every 3 Months', 'psts' ) . '</th>';
			}
			if ( in_array( 12, $periods ) ) {
				$content .= '<th>' . __( 'Every 12 Months', 'psts' ) . '</th>';
			}
			$content .= '</tr>';
		} else {
			$content .= '<tr class="psts_level_head">
					<th>' . __( 'Level', 'psts' ) . '</th>';
			if ( in_array( 1, $periods ) ) {
				$content .= '<th>' . __( '1 Month', 'psts' ) . '</th>';
			}
			if ( in_array( 3, $periods ) ) {
				$content .= '<th>' . __( '3 Months', 'psts' ) . '</th>';
			}
			if ( in_array( 12, $periods ) ) {
				$content .= '<th>' . __( '12 Months', 'psts' ) . '</th>';
			}
			$content .= '</tr>';
		}

		$equiv         = '';
		$coupon_price  = '';
		$setup_fee_amt = $this->get_setting( 'setup_fee', 0 );

		foreach ( $levels as $level => $data ) {
			$content .= '<tr class="psts_level level-' . $level . '">
				<td valign="middle" class="level-name">';
			$content .= apply_filters( 'psts_checkout_grid_levelname', '<h3>' . $data['name'] . '</h3>', $level, $blog_id );
			$content .= '</td>';
			if ( in_array( 1, $periods ) ) {
				$current       = ( $curr->term == 1 && $curr->level == $level ) ? ' opt-current' : '';
				$selected      = ( $sel_period == 1 && $sel_level == $level ) ? ' opt-selected' : '';
				$upgrade_price = ( $recurring ) ? $data['price_1'] : $this->calc_upgrade_cost( $blog_id, $level, 1, $data['price_1'] );

				$session_coupon = ProSites_Helper_Session::session( 'COUPON_CODE' );
				if ( isset( $session_coupon ) && $this->check_coupon( $session_coupon, $blog_id, $level, 1 ) && $coupon_value = $this->coupon_value( $session_coupon, $data['price_1'] ) ) {
					$coupon_price = '<span class="pblg-old-price">' . $this->format_currency( false, $data['price_1'] ) . '</span> <span class="pblg-price">' . $this->format_currency( false, $coupon_value['new_total'] ) . '</span>';
				} elseif ( $upgrade_price != $data['price_1'] ) {
					$coupon_price = '<span class="pblg-old-price">' . $this->format_currency( false, $data['price_1'] ) . '</span> <span class="pblg-price">' . $this->format_currency( false, $upgrade_price ) . '</span>';
				} else {
					$coupon_price = '<span class="pblg-price">' . $this->format_currency( false, $data['price_1'] ) . '</span>';
				}

				//setup fees?
				$setup_fee = '';
				if ( $this->has_setup_fee( $blog_id, $level ) ) {
					$setup_fee = '<span class="psts-setup-fee">+ a one time ' . $this->format_currency( false, $setup_fee_amt ) . ' setup fee</span>';
				}

				if ( in_array( 3, $periods ) || in_array( 12, $periods ) ) {
					$equiv = '<span class="psts-equiv">' . __( 'Try it out!', 'psts' ) . '</span>
	                  <span class="psts-equiv">' . __( 'You can easily switch to a better value plan at any time.', 'psts' ) . '</span>';
				}
				$content .= '<td class="level-option" style="width: ' . $width . '"><div class="pblg-checkout-opt' . $current . $selected . '">
										<input type="hidden" value="' . $level . ':1"/>
										<input type="radio" name="psts-radio" class="psts-radio" id="psts-radio-1-' . $level . '" value="' . $level . ':1" />
										<label for="psts-radio-1-' . $level . '">
										' . $coupon_price . '
										' . $setup_fee . '
										' . $equiv . '
										</label>
										</div></td>';
			}

			if ( in_array( 3, $periods ) ) {
				$current       = ( $curr->term == 3 && $curr->level == $level ) ? ' opt-current' : '';
				$selected      = ( $sel_period == 3 && $sel_level == $level ) ? ' opt-selected' : '';
				$upgrade_price = ( $recurring ) ? $data['price_3'] : $this->calc_upgrade_cost( $blog_id, $level, 3, $data['price_3'] );

				$session_coupon = ProSites_Helper_Session::session( 'COUPON_CODE' );
				if ( isset( $session_coupon ) && $this->check_coupon( $session_coupon, $blog_id, $level, 3 ) && $coupon_value = $this->coupon_value( $session_coupon, $data['price_3'] ) ) {
					$coupon_price = '<span class="pblg-old-price">' . $this->format_currency( false, $data['price_3'] ) . '</span> <span class="pblg-price">' . $this->format_currency( false, $coupon_value['new_total'] ) . '</span>';
					$price        = $coupon_value['new_total'];
				} elseif ( $upgrade_price != $data['price_3'] ) {
					$coupon_price = '<span class="pblg-old-price">' . $this->format_currency( false, $data['price_3'] ) . '</span> <span class="pblg-price">' . $this->format_currency( false, $upgrade_price ) . '</span>';
					$price        = $upgrade_price;
				} else {
					$coupon_price = '<span class="pblg-price">' . $this->format_currency( false, $data['price_3'] ) . '</span>';
					$price        = $data['price_3'];
				}

				$equiv = '<span class="psts-equiv">' . sprintf( __( 'Equivalent to only %s monthly', 'psts' ), $this->format_currency( false, $price / 3 ) ) . '</span>';
				if ( in_array( 1, $periods ) && ( ( $data['price_1'] * 3 ) - $price ) > 0 ) {
					$equiv .= '<span class="psts-equiv">' . sprintf( __( 'Save %s by paying for 3 months in advance!', 'psts' ), $this->format_currency( false, ( $data['price_1'] * 3 ) - $price ) ) . '</span>';
				}

				$content .= '<td class="level-option" style="width: ' . $width . '"><div class="pblg-checkout-opt' . $current . $selected . '">
										<input type="hidden" value="' . $level . ':3"/>
										<input type="radio" name="psts-radio" class="psts-radio" id="psts-radio-3-' . $level . '" value="' . $level . ':3" />
										<label for="psts-radio-3-' . $level . '">
										' . $coupon_price . '
										' . $setup_fee . '
										' . $equiv . '
										</label>
										</div></td>';
			}

			if ( in_array( 12, $periods ) ) {
				$current       = ( $curr->term == 12 && $curr->level == $level ) ? ' opt-current' : '';
				$selected      = ( $sel_period == 12 && $sel_level == $level ) ? ' opt-selected' : '';
				$upgrade_price = ( $recurring ) ? $data['price_12'] : $this->calc_upgrade_cost( $blog_id, $level, 12, $data['price_12'] );

				$session_coupon = ProSites_Helper_Session::session( 'COUPON_CODE' );
				if ( isset( $session_coupon ) && $this->check_coupon( $session_coupon, $blog_id, $level, 12 ) && $coupon_value = $this->coupon_value( $session_coupon, $data['price_12'] ) ) {
					$coupon_price = '<span class="pblg-old-price">' . $this->format_currency( false, $data['price_12'] ) . '</span> <span class="pblg-price">' . $this->format_currency( false, $coupon_value['new_total'] ) . '</span>';
					$price        = $coupon_value['new_total'];
				} elseif ( $upgrade_price != $data['price_12'] ) {
					$coupon_price = '<span class="pblg-old-price">' . $this->format_currency( false, $data['price_12'] ) . '</span> <span class="pblg-price">' . $this->format_currency( false, $upgrade_price ) . '</span>';
					$price        = $upgrade_price;
				} else {
					$coupon_price = '<span class="pblg-price">' . $this->format_currency( false, $data['price_12'] ) . '</span>';
					$price        = $data['price_12'];
				}

				$equiv = '<span class="psts-equiv">' . sprintf( __( 'Equivalent to only %s monthly', 'psts' ), $this->format_currency( false, $price / 12 ) ) . '</span>';
				if ( in_array( 1, $periods ) && ( ( $data['price_1'] * 12 ) - $price ) > 0 ) {
					$equiv .= '<span class="psts-equiv">' . sprintf( __( 'Save %s by paying for a year in advance!', 'psts' ), $this->format_currency( false, ( $data['price_1'] * 12 ) - $price ) ) . '</span>';
				}

				$content .= '<td class="level-option" style="width: ' . $width . '"><div class="pblg-checkout-opt' . $current . $selected . '">
								<input type="hidden" value="' . $level . ':12"/>
								<input type="radio" name="psts-radio" class="psts-radio" id="psts-radio-12-' . $level . '" value="' . $level . ':12" />
								<label for="psts-radio-12-' . $level . '">
								' . $coupon_price . '
								' . $setup_fee . '
								' . $equiv . '
								</label>
								</div></td>';
			}

			$content .= '</tr>';
		}

		$content = apply_filters( 'psts_checkout_grid_before_free', $content, $blog_id, $periods, $free_width );
		// Displays a option for free level, member can continue trial without being redirected to checkout page every time

		if ( ! $this->prevent_dismiss() && ( ! empty ( $domain ) || get_blog_option( $blog_id, 'psts_signed_up' ) ) ) {

			$content .= '<tr class="psts_level level-free">
				<td valign="middle" class="level-name"><h3>' . $this->get_setting( 'free_name', __( 'Free', 'psts' ) ) . '</h3></td>';
			$content .= '<td class="level-option" colspan="' . count( $periods ) . '">';

			if ( is_user_logged_in() && empty ( $domain ) ) {

				$content .= '<a class="pblg-checkout-opt" style="width: ' . $free_width . '" id="psts-free-option" href="' . get_admin_url( $blog_id, 'index.php?psts_dismiss=1', 'http' ) . '" title="' . __( 'Dismiss', 'psts' ) . '">' . $this->get_setting( 'free_msg', __( 'No thank you, I will continue with a basic site for now', 'psts' ) ) . '</a>';

			} else {

				//Checkout With free trial blog
				$content .= '<div class="pblg-checkout-opt" style="width: ' . $free_width . '" id="psts-free-option">
								<input type="hidden" value="0:0"/>
								<input type="radio" name="psts-radio" class="psts-radio" id="psts-radio-0-0" value="0:0" />
								<label for="psts-radio-0-0">' . $this->get_setting( 'free_msg', __( 'No thank you, I will continue with a basic site for now', 'psts' ) ) . '</label>
							</div>';

			}
			$content .= '</td></tr>';
		}

		$content = apply_filters( 'psts_checkout_grid_after_free', $content, $blog_id, $periods, $free_width );

		$content .= '</table>
    						<input type="hidden" id="psts_period" name="period" value="' . $sel_period . '"/>
			      		<input type="hidden" id="psts_level" name="level" value="' . $sel_level . '"/>';

		//allow gateways to add accepted logos on the initial screen
		$content = apply_filters( 'psts_checkout_method_image', $content );

		//coupon form - if you want to hide the coupon box add define('PSTS_DISABLE_COUPON_FORM', true); to your wp-config.php file
		if ( ! ( defined( 'PSTS_DISABLE_COUPON_FORM' ) && PSTS_DISABLE_COUPON_FORM ) ) {
			$coupons = get_site_option( 'psts_coupons' );
			$session_coupon = ProSites_Helper_Session::session( 'COUPON_CODE' );
			if ( is_array( $coupons ) && count( $coupons ) && ! isset( $session_coupon ) ) {
				$content .= '<div id="psts-coupon-block">
		      <small><a id="psts-coupon-link" href="#">' . __( 'Have a coupon code?', 'psts' ) . '</a></small>
		      <div id="psts-coupon-code" class="alignright" style="display: none;">
		        <label for="coupon_code">' . __( 'Enter your code:', 'psts' ) . '</label>
		        <input type="text" name="coupon_code" id="coupon_code" class="cctext" />&nbsp;
		        <input type="submit" name="coupon-submit" class="regbutton" value="' . __( 'Apply &raquo;', 'psts' ) . '" />
		      </div>
		     </div>';
			}
		}

		//display checkout free trial/cancellation message
		$trial_days = $this->get_setting( 'trial_days', 0 );
		if ( $this->is_trial_allowed( $blog_id ) ) {
			$content .= '<p style="padding-top:24px">' . str_replace( 'DAYS', $trial_days, $this->get_setting( 'cancel_message' ) ) . '</p>';
		}

		return $content;
	}