<?php

/**
 * The public-facing functionality of the plugin.
 *
 * @link       #
 * @since      1.0.0
 *
 * @package    Advanced_Portfolio
 * @subpackage Advanced_Portfolio/public
 */

/**
 * The public-facing functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the public-facing stylesheet and JavaScript.
 *
 * @package    Advanced_Portfolio
 * @subpackage Advanced_Portfolio/public
 * @author     Iqbal Hussain <k.iqbal.r@gmail.com>
 */
class Advanced_Portfolio_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;
	private $posttype;
	/**
	 * 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;
		
		add_shortcode( 'advanced-portfolio', array($this, 'advanced_portfolio_shortcode_callback' ));
		add_action('wp_head',array($this, 'lightbox_options'));

	}
	public function advanced_portfolio_shortcode_callback($atts){
		$atts= shortcode_atts(
			array(
			'id'=>''
			),$atts,'advanced-portfolio');
		if(empty($atts['id']) || !is_numeric($atts['id']))
		{
			echo __('It seems portfolio shortcode id is missing.','advanced-portfolio');
		}
		else{
		wp_enqueue_script( 'html5lightbox');
			$type=get_post_meta($atts['id'],'portfolio_type',true);
			switch ($type) {
				case 'filterable':
					$this->filterable_portfolio($atts['id']);
					break;
				case 'simple':
					$this->simple_portfolio($atts['id']);
					break;
				case 'slider_single':
					$this->slider_single_portfolio($atts['id']);
					break;
				default:
					$this->filterable_portfolio($atts['id']);
					break;
			}
			
		}
	}
	public function manage_options($options)
	{
		 switch ($options['style']) {
      	case 'style-1':
      		$options['style']='modern-style';
      		break;
      	case 'style-2':
      		$options['style']='iq_portfolio_filter';
      		break;
      	case 'style-3':
      		$options['style']='full-overlay-style ';
      		break;	
      	default:
      		$options['style']='iq_portfolio_filter';
      		break;
      }  
      return $options;
	}
	public function filterable_portfolio($id){
		$options= $this->manage_options(get_post_meta($id,'portfolio_options',true));
		$lightbox=get_post_meta($id,'portfolio_lightbox_options',true);
		include( dirname(__FILE__).'/portfolio/filterable.php' );
	}
	public function simple_portfolio($id){
		$options= $this->manage_options(get_post_meta($id,'portfolio_options',true));
		$lightbox=get_post_meta($id,'portfolio_lightbox_options',true);

		include( dirname(__FILE__).'/portfolio/simple.php' );
	}
	public function slider_single_portfolio($id){
		wp_enqueue_script( 'slick');
		$options= $this->manage_options(get_post_meta($id,'portfolio_options',true));
		$lightbox=get_post_meta($id,'portfolio_lightbox_options',true);

		include( dirname(__FILE__).'/portfolio/one_row_slider.php' );
	}
	
		public function lightbox_options(){
			?>
			<script type="text/javascript">
			var html5lightbox_options = {
			        showplaybutton: false,
			        fullscreenmode: true,
			        titlestyle: "inside",
			        showsocial: true,
			        socialdirection: "vertical",
			        socialposition: "position:absolute;top:0;right:0;",
			        shownavigation: true

			};
			</script>
			<?php
		}
	/**
	 * Register the stylesheets for the public-facing side of the site.
	 *
	 * @since    1.0.0
	 */
	public function enqueue_styles() {

		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the run() function
		 * defined in Advanced_Portfolio_Loader as all of the hooks are defined
		 * in that particular class.
		 *
		 * The Advanced_Portfolio_Loader will then create the relationship
		 * between the defined hooks and the functions defined in this
		 * class.
		 */
		wp_enqueue_style( 'slick', plugin_dir_url( __FILE__ ) . 'css/slick.css', array(), $this->version, 'all' );
		wp_enqueue_style( 'slick-theme', plugin_dir_url( __FILE__ ) . 'css/slick-theme.css', array(), $this->version, 'all' );
		wp_enqueue_style( 'fontawesome', plugin_dir_url( __FILE__ ) . 'css/font-awesome.min.css', array(), $this->version, 'all' );
		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/advanced-portfolio-public.css', array(), $this->version, 'all',1000);

	}

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

		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the run() function
		 * defined in Advanced_Portfolio_Loader as all of the hooks are defined
		 * in that particular class.
		 *
		 * The Advanced_Portfolio_Loader will then create the relationship
		 * between the defined hooks and the functions defined in this
		 * class.
		 */
		wp_enqueue_script( 'isotope', plugin_dir_url( __FILE__ ) . 'js/isotope.min.js', array( 'jquery' ), $this->version, false );
		wp_register_script( 'slick', plugin_dir_url( __FILE__ ) . 'js/slick.min.js', array( 'jquery' ), $this->version, false );
		wp_register_script( 'html5lightbox', plugin_dir_url( __FILE__ ) . 'js/html5lightbox.js', array( 'jquery' ), $this->version, false );
		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/advanced-portfolio-public.js', array( 'jquery' ), $this->version, false );
		wp_localize_script($this->plugin_name, 'ajax_var', array(
		    'url' => admin_url('admin-ajax.php'),
		    'nonce' => wp_create_nonce('ajax-nonce')
		));
	}

}
