<?php 

if ( ! function_exists( 'gp_featured' ) ) {

	function gp_featured( $atts, $content = null ) {	
		
		extract( shortcode_atts( array(
			'widget_title' => '',
			'post_id' => '',
			'page_id' => '',
			'featured_image' => 'enabled',
			'image_width' => '264',
			'image_height' => '264',
			'hard_crop' => true,
			'image_alignment' => 'image-wrap-left',
			'title_position' => 'title-next-to-thumbnail',
			'content_display' => 'excerpt',
			'excerpt_length' => '440',
			'meta_author' => '',
			'meta_date' => '',
			'meta_comment_count' => '',
			'meta_views' => '',
			'meta_followers' => '',
			'meta_cats' => '',
			'meta_tags' => '',			
			'meta_hub_cats' => '',			
			'meta_hub_fields' => '',			
			'display_site_rating' => '',	
			'display_user_rating' => '',
			'read_more_link' => 'enabled',			
			'classes' => '',
			'css' => '',
			'text_color' => '',
			'background_overlay' => 'enabled',
		), $atts ) );

		// Detect shortcode
		$GLOBALS['gp_shortcode'] = 'featured';
		
		gp_shortcode_options( $atts );
		$GLOBALS['gp_format'] = 'blog-standard';
				
		// Unique Name	
		STATIC $i = 0;
		$i++;
		$name = 'gp_featured_wrapper_' . $i;
					
		// CSS Editor
		$css_class = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $classes . vc_shortcode_custom_css_class( $css, ' ' ), '', $atts );

		// Post IDs or slugs
		if ( preg_match( '/^[a-zA-Z\-]+/', $post_id ) OR preg_match( '/^[a-zA-Z\-]+/', $page_id ) ) {
			$post_slug = $post_id;
			$page_slug = $page_id;
		} else {
			$post_slug = '';
			$page_slug = '';		
		}
		
		$args = array(
			'post_status' => 'publish',
			'post_type' => array( 'post', 'page' ),
			'p' => $post_id,
			'page_id' => $page_id,
			'name' => $post_slug,
			'pagename' => $page_slug,
			'posts_per_page' => 1,
			'paged' => 1,
		);
		
		ob_start(); $gp_query = new wp_query( $args ); ?>

		<div id="<?php echo sanitize_html_class( $name ); ?>" class="featured-wrapper featured-shortcode blog-standard <?php echo sanitize_html_class( $css_class ); ?>">
		
			<div class="featured-title-overlay"><?php echo esc_attr( $widget_title ); ?></div>

			<?php if ( $background_overlay == 'enabled' ) { ?><div class="bg-overlay-dark"></div><?php } ?>
			
			<?php if ( $gp_query->have_posts() ) : ?>

				<div class="inner-loop"<?php if ( !empty( $text_color ) ) { ?> style="color: <?php echo esc_attr( $text_color ); ?>"<?php } ?>>
							
					<?php while ( $gp_query->have_posts() ) : $gp_query->the_post(); ?>

						<?php if ( get_post_meta( get_the_ID(), '_wp_page_template', true ) == 'review-template.php' OR get_post_meta( get_the_ID(), '_wp_page_template', true ) == 'hub-template.php' ) { 
							get_template_part( 'review', 'loop' );
						} else {
							get_template_part( 'post', 'loop' ); 
						} ?>
			
					<?php endwhile; ?>
		
				</div>

			<?php else : ?>

				<strong class="no-items-found"><?php _e( 'No items found.', 'gp_lang' ); ?></strong>
				
			<?php endif; wp_reset_postdata(); ?>

		</div><!-- END FEATURED WRAPPER -->

		<?php

		$output_string = ob_get_contents();
		ob_end_clean(); 				
		$GLOBALS['gp_shortcode'] = null;
		return $output_string;

	}

}

add_shortcode( 'featured', 'gp_featured' );
	
?>