MortgageRates_Shortcodes

Class MortgageRates_Shortcodes


Source Source

File: mortgage-rates-widget/inc/MortgageRates_Shortcodes.php

class MortgageRates_Shortcodes {


	/**
	 * Shortcode type.
	 *
	 * @access public
	 * @since 1.0.0
	 *
	 * @param array $atts shortcode attributes
	 *
	 * @return string html
	 */
	public function shortcode($atts){

	    $type = $atts['type'] ?? 'table';
        switch ($type){
            case 'table':
                return $this->table_shortcode($atts);
            case 'chart':
                return $this->chart_shortcode($atts);
            case 'scroller':
                return $this->scroller_shortcode($atts);
            case 'text':
                return $this->text_shortcode($atts);
            default:
                return $this->table_shortcode($atts);
        }

	}


	/**
	 * Table shortcode.
	 *
	 * @access public
	 * @since 1.0.0
	 *
	 * @param array $atts shortcode attributes
	 *
	 * @return string
	 */
	public function table_shortcode($atts) {

		$embedded = new MortgageRates_Embedded();
		$enqueue = new MortgageRates_Enqueue();

		ob_start();
		$embedded->table_html();
		$enqueue->enqueue_table();

		return ob_get_clean();
	}


	/**
	 * Chart Shortcode.
	 *
	 * @access public
	 * @since 1.0.0
	 *
	 * @param array $atts shortcode attributes
	 *
	 * @return string
	 */
	public function chart_shortcode($atts) {

		$embedded = new MortgageRates_Embedded();

		ob_start();
		if (isset($atts['option'])){
			switch ($atts['option']){
				case 'fusion':
					 $embedded->display_fusion_chart();
					 break;
				case 'amchart':
					 $embedded->display_amchart();
					 break;
				default:
					 $embedded->display_fusion_chart();
					 break;
			}
		} else {
			$embedded->display_fusion_chart();
		}

		return ob_get_clean();
	}


	/**
	 * Scroller shortcode.
	 *
	 * @access public
	 * @since 1.0.0
	 *
	 * @param array $atts shortcode attributes
	 *
	 * @return string
	 */
	public function scroller_shortcode($atts) {
		//$quandl = new MortgageRates_Quandl();

		ob_start();
		//$scroller = $quandl->get_rates();

		$embedded = new MortgageRates_Embedded();
		$scroller = $embedded->get_scroller_data();
		$scroller_type =  $atts['option'] ?? "scroller-1";
        $this->enqueue_scroller_js($scroller_type);

        switch ($scroller_type){
            case 'scroller-1':
                $embedded->scroller_html_type1($scroller);
                wp_enqueue_style( 'mortgage-rates-scroller-1', plugins_url( '../assets/css/mortgage-rates-scroller-1.css', __FILE__ ), array(), '1.0.0' );
                break;
            case 'scroller-2':
                $embedded->scroller_html_type2($scroller);
                wp_enqueue_style( 'mortgage-rates-scroller-2', plugins_url( '../assets/css/mortgage-rates-scroller-2.css', __FILE__ ), array(), '1.0.0' );
                break;
            case 'scroller-3':
                $embedded->scroller_html_type3($scroller);
                wp_enqueue_style( 'mortgage-rates-scroller-3', plugins_url( '../assets/css/mortgage-rates-scroller-3.css', __FILE__ ), array(), '1.0.0' );
                break;
            case 'scroller-4':
                $embedded->scroller_html_type4($scroller);
                wp_enqueue_style( 'mortgage-rates-scroller-4', plugins_url( '../assets/css/mortgage-rates-scroller-4.css', __FILE__ ), array(), '1.0.0' );
                break;
            default :
                $embedded->scroller_html_type1($scroller);
                wp_enqueue_style( 'mortgage-rates-scroller-1', plugins_url( '../assets/css/mortgage-rates-scroller-1.css', __FILE__ ), array(), '1.0.0' );
                break;

        }

		return ob_get_clean();
	}


    /**
     * Enqueue scroller JS Script.
     *
     * @access private
     * @since 1.0.0
     *
     * @param string $scroller_type Scroller type
     */
    private function enqueue_scroller_js($scroller_type){

        wp_enqueue_script( 'breakingNews-scroller', plugins_url( '../assets/js/breakingNews-scroller.js', __FILE__ ), array( 'jquery' ), '1.0.0', true );
        $data = ' if (jQuery(".newsTicker-' . $scroller_type . '").length) {
                                jQuery(".newsTicker-' . $scroller_type . '").breakingNews()
                            }';
        wp_add_inline_script( 'breakingNews-scroller', $data, 'after' );
    }


    /**
	 * Text shortcode.
	 *
	 * @access public
	 * @since 1.0.0
	 *
	 * @param array $atts shortcode attributes
	 *
	 * @return string
	 */
	public function text_shortcode($atts) {
		$embedded = new MortgageRates_Embedded();
		//$quandl = new MortgageRates_Quandl();

		ob_start();
		$output = isset($atts['option']) ?? 'list';
		//$data =  $quandl->get_rates();
		$data = $embedded->get_scroller_data();
		$embedded->plain_text($data, $output);
		return ob_get_clean();
	}

}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.