MP_Calculator_Widgets

Class MP_Calculator_Widgets


Source Source

File: mortgage-platform/Inc/Calculators/MortgageCalculator/MP_Calculator_Widgets.php

class MP_Calculator_Widgets {


	/**
	 * Transfer calculator calculation data using the GET method from Calculator Form Widget.
	 * @since  1.0.0
	 * @access public
	 * @static
	 */
	public static function widget_form() {

        $mortgage_amount_input = '';
        $interest_rate_input = '';
        $down_payment_input = '';
        $termcycle = '';
        $term_input = '';

		if ( isset( $_GET ) ) {
			if ( isset( $_GET['MortgageAmountInput'] ) ) {
				$mortgage_amount_input = sanitize_text_field($_GET['MortgageAmountInput']);
			}
			if ( isset( $_GET['InterestRateInput'] ) ) {
				$interest_rate_input = sanitize_text_field($_GET['InterestRateInput']);
			}
			if ( isset( $_GET['DownPaymentInput'] ) ) {
				$down_payment_input = sanitize_text_field($_GET['DownPaymentInput']);
			}
			if ( isset( $_GET['termcycle'] ) ) {
				$termcycle = sanitize_text_field($_GET['termcycle']);
			}
			if ( isset( $_GET['TermInput'] ) ) {
				$term_input = sanitize_text_field($_GET['TermInput']);
			}
		}

        if(!wp_script_is(MortgagePlatform::$prefix . 'main','queue')){
            wp_enqueue_script(MortgagePlatform::$prefix . 'main');
        }
		if ( $mortgage_amount_input || $interest_rate_input || $down_payment_input || $termcycle || $term_input ) {
			wp_localize_script(
				MortgagePlatform::$prefix . 'main',
				'mortgageCalculator_widgetForm',
				array(
					'MortgageAmountInput' => esc_attr( $mortgage_amount_input ),
					'InterestRateInput'   => esc_attr( $interest_rate_input ),
					'DownPaymentInput'    => esc_attr( $down_payment_input ),
					'termcycle'           => esc_attr( $termcycle ),
					'TermInput'           => esc_attr( $term_input ),
				)
			);
		} else {
			wp_localize_script( MortgagePlatform::$prefix . 'main', 'mortgageCalculator_widgetForm', array() );
		}

	}


	/**
	 * Filter widget menu for constrictor.
	 * @since  1.0.0
	 * @access public
	 *
	 * @param string $list list of a menu
	 *
	 * @return string
	 */
	public function filter_constructor_menu( $list ) {

	    if(!isset($_GET['page'])) return '';

        if ( 'mortgage-widgets' === $_GET['page']) {
	        if ( isset( $_GET['tab'] ) && 'widget-constructor' === $_GET['tab'] ) {
		        $list .= '<li class="active"><a href="?page=mortgage-widgets&tab=widget-constructor" >' . esc_html__( 'Widget Constructor', 'mortgage_platform' ) . '</a></li>';
	        } else {
		        $list .= '<li ><a href="?page=mortgage-widgets&tab=widget-constructor" >' . esc_html__( 'Widget Constructor', 'mortgage_platform' ) . '</a></li>';
	        }
        }

		return $list;
	}


	/**
	 * Filter widget menu for calculators.
	 * @since  1.0.0
	 * @access public
	 *
	 * @param string $list list of a menu
	 *
	 * @return string
	 */
	public function filter_calculators_menu( $list ) {

	    if( 'mortgage-widgets' === $_GET['page']) {
		    if ( isset( $_GET['tab'] ) && 'widgets' === $_GET['tab'] ) {
			    $list .= '<li class="active"><a href="?page=mortgage-widgets&tab=widgets" >' . esc_html__( 'Widgets', 'mortgage_platform' ) . '</a></li>';
		    } else {
			    $list .= '<li ><a href="?page=mortgage-widgets&tab=widgets" >' . esc_html__( 'Widgets', 'mortgage_platform' ) . '</a></li>';
		    }
	    }

		return $list;
	}


	/**
	 * Constructor widget page.
	 * @since  1.0.0
	 * @access public
	 */
	public function constructor_widget_page() {

	    if ( 'mortgage-widgets' === $_GET['page']) {
		    if ( isset( $_GET['tab'] ) && 'widget-constructor' === $_GET['tab'] || !isset( $_GET['tab'])) {

			    ?>
                <div class="mp-settings__content tab-pane widget-constructor">
                    <div class="widget">
                        <h3><?php esc_html_e( 'Widget constructor', 'mortgage_platform' ); ?></h3>
                        <p><?php esc_html_e( 'Insert the following code in your web page.', 'mortgage_platform' ); ?></p>
                        <div class="widget_example">
						    <?php echo do_shortcode( '[' . MortgagePlatform::$shortcode_widget . '-constructor]' ); ?>
                        </div>
                        <div class="widget_code">
                            <pre id="widgetLink"><?php echo esc_html( htmlspecialchars( '[' . MortgagePlatform::$shortcode_widget . '-constructor]' ) ); ?></pre>
                        </div>
                    </div>
                </div>
			    <?php
		    }
	    }

	}


	/**
	 * Caclulators widget page.
	 * @since  1.0.0
	 * @access public
	 */
	public function calculators_widget_page() {

	    if ( 'mortgage-widgets' === $_GET['page']) {
		    if ( 'widgets' === $_GET['tab'] ) {

			    /**
			     * Widget template.
			     */
			    include_once plugin_dir_path( __FILE__ ) . 'templates/widgets.php';
		    }
	    }
	}


}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.