
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
/**
 * The public-facing functionality of the plugin.
 *
 * @link       https://codesupply.co/plugins/basic-shortcodes/
 * @since      1.0.0
 *
 * @package    Basic Shortcodes
 * @subpackage Public
 */

/**
 * The public-facing functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the admin-specific stylesheet and JavaScript.
 *
 * @package    Basic Shortcodes
 * @subpackage Basic_Shortcodes/public
 * @author     Code Supply Co. <hello@codesupply.co>
 */
class Basic_Shortcodes_Public {

	/**
	 * The ID of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $plugin_name    The ID of this plugin.
	 */
	private $plugin_name;

	/**
	 * The version of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $version    The current version of this plugin.
	 */
	private $version;

	/**
	 * Initialize the class and set its properties.
	 *
	 * @since 1.0.0
	 * @param string $plugin_name  The name of the plugin.
	 * @param string $version      The version of this plugin.
	 */
	public function __construct( $plugin_name, $version ) {

		$this->plugin_name = $plugin_name;
		$this->version = $version;
	}

	/**
	 * Register the stylesheets for the public-facing side of the site.
	 *
	 * @since    1.0.0
	 */
	public function enqueue_styles() {

		// Bootstrap Styles.
		if ( apply_filters( 'bsc_enqueue_bootstrap_styles', true ) ) {
			wp_register_style( 'bootstrap', plugin_dir_url( __FILE__ ) . 'css/bootstrap.min.css', false, '4.0.0', 'screen' );
			wp_enqueue_style( 'bootstrap' );
		}

		// Basic Shortcodes Styles.
		if ( apply_filters( 'bsc_enqueue_styles', true ) ) {
			wp_register_style( 'bsc-css', plugin_dir_url( __FILE__ ) . 'css/basic-shortcodes.css', false, $this->version, 'screen' );
			wp_enqueue_style( 'bsc-css' );
		}
	}

	/**
	 * Register the JavaScript for the public-facing side of the site.
	 *
	 * @since    1.0.0
	 */
	public function enqueue_scripts() {

		// Bootstrap Scripts.
		if ( apply_filters( 'bsc_enqueue_bootstrap_scripts', true ) ) {
			wp_enqueue_script( 'tether', plugin_dir_url( __FILE__ ) . 'js/tether.min.js', array( 'jquery' ), '1.3.3', false );
			wp_enqueue_script( 'bootstrap', plugin_dir_url( __FILE__ ) . 'js/bootstrap.min.js', array( 'jquery' ), '4.0.0', false );
		}

		// Basic Shortcodes Scripts.
		if ( apply_filters( 'bsc_enqueue_scripts', true ) ) {
			wp_enqueue_script( 'bsc-js', plugin_dir_url( __FILE__ ) . 'js/basic-shortcodes.js', array( 'jquery' ), $this->version, false );
		}
	}

	/**
	 * Shortcode Public Display
	 *
	 * @param array  $atts      User defined attributes in shortcode tag.
	 * @param string $content   Shorcode Content.
	 * @param string $shortcode The name of the shortcode.
	 * @return string           Shortcode result HTML.
	 */
	public function shortcode_display( $atts, $content = false, $shortcode ) {
		// Get all shortcodes.
		$sections = apply_filters( 'bsc_ui_args', array() );

		// Get Default Attrs.
		$default_attrs = array();
		foreach ( $sections as $section ) {
			if ( is_array( $section['fields'] ) ) {
				foreach ( $section['fields'] as $field ) {
					switch ( $field['type'] ) {
						case 'section' : break;
						case 'repeater' :
							if ( $field['base'] === $shortcode ) {
								foreach ( $field['fields'] as $repeater_field ) {
									$default_attrs[ $repeater_field['name'] ] = $repeater_field['default'] ? $repeater_field['default'] : '';
								}
							}
							break;
						default :
							if ( $section['base'] === $shortcode ) {
								$default_attrs[ $field['name'] ] = $field['default'] ? $field['default'] : '';
							}
							break;
					}
				}
			}
		}

		// Merge Attrs.
		$atts = shortcode_atts( $default_attrs, $atts );

		// Content.
		$content = do_shortcode( $content );

		/**
		 * Filters a shortcode's HTML.
		 *
		 * @param array  $output    Shortcode HTML.
		 * @param array  $atts      User defined attributes in shortcode tag.
		 * @param string $content   Shorcode tag content.
		 * @return string           Shortcode result HTML.
		 */
		$output = apply_filters( $shortcode . '_shortcode', '', $atts, $content );

		return $output;
	}
}
