<?php
add_action( 'vc_before_init', 'rockon_track_WITHVS' );
function rockon_track_WITHVS() {
   vc_map( array(
      "name" => __("Rockon Club Track",'rockon'),
      "base" => "rockon_track_post",
      "class" => "",
      "category" => __('Content','rockon'),
      'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
      'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
      "params" => array(
         array(
            "type" => "textfield",
            "holder" => "div",
            "class" => "",
            "heading" => __("Title",'rockon'),
            "param_name" => "title",
            "value" => __("Rockon Club Track",'rockon'),
            "description" => __("Title text Here.",'rockon')
         ),
		  array(
            "type" => "dropdown",
            "holder" => "div",
            "class" => "",
            "heading" => __("Number Of Post",'rockon'),
            "param_name" => "no_of_post",
            "value" => array('3','6','9'),
            "description" => __("Choose no of post.",'rockon')
         )
      )
   ) );
}
add_shortcode( 'rockon_track_post', 'rockon_track_post_func' );
function rockon_track_post_func( $atts ) { // New function parameter $content is added!
   extract( shortcode_atts( array(
      'title' => 'something',
	  'no_of_post' => '3'
   ), $atts ) );
   $result = '';
   $result .= '<div class="rock_audio_player_wrapper"><div class="col-lg-12 col-md-12 col-sm-12"><div class="col-lg-6 col-md-6 col-sm-6">';
   $args = array('post_type' => 'rockon_track','numberposts' => 1);
   $recent_postsresult = wp_get_recent_posts( $args, array() );
   global $post;
   $audio = $image = '';
   foreach( $recent_postsresult as $rst ){
		$result .= '<div class="rock_audio_player">
                    <div class="rock_audio_player_title">'.__(get_the_title($rst->ID),'rockon').'</div>
                    <div class="rock_audio_player_track_image">'; 
		$image = get_post_meta( $rst->ID, 'rockon_image_src', true );	
		if (!empty($image))
		{	
			$result .= '<img src="'.esc_url($image).'" alt="track 1" />';
		}else{
			$result .= '<img src="'.ROCKON_PATH.'/images/no_image.jpg" alt="track 1" />';
		}	
        $result .= '<div class="rock_audio_player_track_image_overlay">'.__(get_the_title($rst->ID),'rockon').'</div>
                    </div>
                    <div class="audio-player">';
		$audio = get_post_meta( $rst->ID, 'rockon_audio_src', true );
		if (!empty($audio))
		{	
        $result .= '<audio class="rock_player" controls><source  src="'.esc_url($audio).'"  type="audio/mpeg"></audio>';
        }       
		$result .= '</div>
                  </div>';
		$image = '';		  
   }
   $result .= '</div><div class="col-lg-6 col-md-6 col-sm-6">';
	$result .= '<div class="rock_track_playlist">
	<h1>'.__(esc_attr($title),'rockon').'</h1>
	<ul class="rock_track_playlist_slider">';
	$i = 0;
	$track_query = new WP_Query( array( 'post_type' => 'rockon_track', 'posts_per_page' => $no_of_post) );
	 if($track_query->have_posts()): 
		while($track_query->have_posts()) : $track_query->the_post();
		  $result .= '<li>';
		 $image = get_post_meta( $post->ID, 'rockon_image_src', true );	
		  if (!empty($image))
		  {	
			$result .= '<img src="'.esc_url($image).'" alt="track 1" />';
    	  }else{
			$image = ROCKON_PATH.'/images/no_image.jpg';
			$result .= '<img src="'.ROCKON_PATH.'/images/no_image.jpg" alt="track 1" />';	
		  }
		  $result .= '<div class="rock_track_detail"> <a href="#" class="rock_track_title">'.__(get_the_title($post->ID),'rockon').'</a><a data-toggle="modal" data-target=".rockon_myModal'.$i.'" class="rock_track_play btn btn-default btn-sm">Play</a>
			</div>
		  </li>';
		  $i++; 
		$image = '';
	  endwhile; 
	 endif;
	$result .= '</ul>
	<div class="rock_playlist_slider_control"> <span id="rock_track_playlist_slider_prev"></span> <span id="rock_track_playlist_slider_next"></span> </div>
	</div>';
	
	$i = 0;
	$track_query = new WP_Query( array( 'post_type' => 'rockon_track', 'posts_per_page' => $no_of_post) );
	 if($track_query->have_posts()): 
		while($track_query->have_posts()) : $track_query->the_post();
		
		  $result .= '<div class="modal animated fadeInDown rockon_myModal'.$i.'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel'.$i.'" aria-hidden="false">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title rock_audio_player_title" id="myModalLabel'.$i.'">'.__(get_the_title($post->ID),'rockon').'</h4>
                  </div>
                  <div class="modal-body">
                    <div class="rock_audio_player">
                      <div class="rock_audio_player_track_image">';
			$src = get_post_meta( $post->ID, 'rockon_image_src', true );;	
			if (!empty($src))
			{	
				$thumb_w = '558';
				$thumb_h = '280';
				$image = aq_resize($src, $thumb_w, $thumb_h, true);
				$result .= '<img src="'.esc_url($image).'" alt="">';
			}else{
				$image = ROCKON_PATH.'/images/no_image.jpg';
				$result .= '<img src="'.ROCKON_PATH.'/images/no_image.jpg" alt="" />';	
			}
            $result .= '<div class="rock_audio_player_track_image_overlay">'.__(get_the_title($post->ID),'rockon').'</div>
                      </div>
                      <div class="audio-player">';
			$audio = get_post_meta( $post->ID, 'rockon_audio_src', true );
			if (!empty($audio))
			{	
			$result .= '<audio class="rock_player" controls><source  src="'.esc_url($audio).'" type="audio/mpeg"></audio>';
			}
             $result .= '</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>';
		  $i++; 
	  
	  endwhile; 
	 endif;
	 $result .= '</div></div></div>';
	return $result;
   
}
?>