<?php global $gp;

// Detect review loop
$GLOBALS['gp_review_loop'] = true;

// Loop options for search results page
if ( $post->post_type == 'gp_user_review' ) {
	if ( is_page_template( 'my-reviews-template.php' ) ) { 
		$GLOBALS['gp_display_site_rating'] = 0;
	} else {
		$GLOBALS['gp_display_site_rating'] = $gp['user_reviews_display_rating']['site_rating'];
	}
	$GLOBALS['gp_display_user_rating'] = 0;
}

gp_get_hub_id( get_the_ID() );

// Margin class
if ( $GLOBALS['gp_title_position'] == 'title-over-thumbnail' && $GLOBALS['gp_excerpt_length'] == '0' && $GLOBALS['gp_meta_author'] != '1' && $GLOBALS['gp_meta_date'] != '1' && $GLOBALS['gp_meta_comment_count'] != '1' && $GLOBALS['gp_meta_views'] != '1' && $GLOBALS['gp_meta_followers'] != '1' && $GLOBALS['gp_meta_tags'] != '1' && $GLOBALS['gp_meta_hub_cats'] != '1' && $GLOBALS['gp_meta_hub_fields'] != '1' && $GLOBALS['gp_meta_hub_award'] != '1' ) {
	$margin_class = 'no-post-margin';
} else {
	$margin_class = '';
}
	
gp_ratings( $GLOBALS['gp_hub_id'] );

?>

<article <?php post_class( 'post-item ' . $margin_class . ' ' . $GLOBALS['gp_rated_item_class'] ); ?>>

	<?php if ( has_post_thumbnail() && $GLOBALS['gp_featured_image'] == 'enabled' ) { ?>

		<div class="post-thumbnail featured-content <?php echo sanitize_html_class( $GLOBALS['gp_image_alignment'] ); ?>">

			<?php $image = aq_resize( wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) ), $GLOBALS['gp_image_width'], $GLOBALS['gp_image_height'], $GLOBALS['gp_hard_crop'], false, true ); ?>
			<?php if ( $gp['retina'] == 'gp-retina' ) {
				$retina = aq_resize( wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) ), $GLOBALS['gp_image_width'] * 2, $GLOBALS['gp_image_height'] * 2, $GLOBALS['gp_hard_crop'], true, true );
			} else {
				$retina = '';
			} ?>
							
			<a href="<?php the_permalink(); ?>" title="<?php echo gp_prefix_hub_title( get_the_ID() ); ?>">

				<?php if ( $GLOBALS['gp_title_position'] == 'title-over-thumbnail' OR ( ( $GLOBALS['gp_site_rating_enabled'] == true OR $GLOBALS['gp_user_rating_enabled'] == true ) && ( $GLOBALS['gp_format'] != 'blog-standard' ) ) ) { ?>
					<div class="bottom-bg-gradient-overlay"></div>
				<?php } ?>
						
				<?php if ( ( $GLOBALS['gp_site_rating_enabled'] == true OR $GLOBALS['gp_user_rating_enabled'] == true ) && ( $GLOBALS['gp_format'] != 'blog-standard' ) ) { ?>
					<div class="rating-wrapper">
						<?php if ( $GLOBALS['gp_site_rating_enabled'] == true ) { get_template_part( 'lib/sections/site', 'rating' ); } ?>
						<?php if ( $GLOBALS['gp_user_rating_enabled'] == true ) { get_template_part( 'lib/sections/user', 'rating' ); } ?>
					</div><!-- END RATING WRAPPER -->
				<?php } ?>
	
				<?php if ( $GLOBALS['gp_title_position'] == 'title-over-thumbnail' ) { ?>
					<div class="loop-header thumbnail-header">
						<h2 class="entry-title loop-title">
							<?php echo gp_prefix_hub_title( get_the_ID() ); ?>
						</h2>
					</div><!-- END ENTRY HEADER -->
				<?php } ?>
		
				<img src="<?php echo esc_url( $image[0] ); ?>" data-rel="<?php echo esc_url( $retina ); ?>" width="<?php echo absint( $image[1] ); ?>" height="<?php echo absint( $image[2] ); ?>" alt="<?php if ( get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ) ) { echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); } else { echo gp_prefix_hub_title( get_the_ID() ); } ?>" class="wp-post-image" />
				
			</a>
											
		</div>
	
	<?php } ?>
	
	<?php if ( function_exists( 'gp_remove_follow_button' ) ) { echo gp_remove_follow_button( get_the_ID() ); } ?>
							
	<div class="post-item-content <?php if ( isset( $GLOBALS['gp_image_alignment'] ) ) { echo sanitize_html_class( $GLOBALS['gp_image_alignment'] ); } ?>">
		
		<?php if ( ( $GLOBALS['gp_site_rating_enabled'] == true OR $GLOBALS['gp_user_rating_enabled'] == true ) && $GLOBALS['gp_format'] == 'blog-standard' ) { ?>
			<div class="rating-wrapper">
				<?php if ( $GLOBALS['gp_site_rating_enabled'] == true ) { get_template_part( 'lib/sections/site', 'rating' ); } ?>
				<?php if ( $GLOBALS['gp_user_rating_enabled'] == true ) { get_template_part( 'lib/sections/user', 'rating' ); } ?>				
			</div><!-- END RATING WRAPPER -->
		<?php } ?>
		
		<?php if ( $GLOBALS['gp_title_position'] == 'title-next-to-thumbnail' ) { ?>
			<div class="loop-header">
				<h2 class="entry-title loop-title">
					<a href="<?php the_permalink(); ?>" title="<?php echo gp_prefix_hub_title( get_the_ID() ); ?>"><?php echo gp_prefix_hub_title( get_the_ID() ); ?></a> 
				</h2>
			</div><!-- END ENTRY HEADER -->
		<?php } ?>

		<?php gp_my_review_links(); ?> 
	
		<?php if ( get_post_meta( get_the_ID(), 'hub_award', true ) == '1' && ( isset( $GLOBALS['gp_meta_hub_award'] ) && $GLOBALS['gp_meta_hub_award'] == '1' ) ) { ?>
			<span class="hub-award"><i class="fa <?php if ( get_post_meta( get_the_ID(), 'hub_award_icon', true ) ) { echo get_post_meta( get_the_ID(), 'hub_award_icon', true ); } else { ?>fa-trophy<?php } ?>"></i><?php echo get_post_meta( get_the_ID(), 'hub_award_title', true ); ?></span>
		<?php } ?>
							
		<?php if ( ( isset( $GLOBALS['gp_meta_hub_cats'] ) && $GLOBALS['gp_meta_hub_cats'] == '1' ) && ( ! empty( $GLOBALS['gp_hub_cats_selected'][0] ) ) ) { ?>

			<div class="hub-cats">

				<?php foreach( $GLOBALS['gp_hub_cats_selected'] as $gp_hub_cat ) {
					if ( has_term( $gp_hub_cat, 'gp_hubs', $GLOBALS['gp_hub_id'] ) ) {
						$term = get_term( $gp_hub_cat, 'gp_hubs' );
						$t_ID = $term->term_id;
						$term_data = get_option( "taxonomy_$t_ID" );											
						$term_link = get_term_link( $term, 'gp_hubs' );
						if ( ! $term_link OR is_wp_error( $term_link ) ) {
							continue;
						}
						?>
						<a href="<?php echo esc_url( $term_link ); ?>"><span<?php if ( $term_data['color'] ) { ?> style="background-color: <?php echo esc_attr( $term_data['color'] ); ?>"<?php } ?>><?php echo esc_attr( $term->name ); ?></span></a>
					<?php } ?>	

				<?php } ?>

			</div><!-- END HUB CATEGORIES -->

		<?php } ?>

		<?php if ( $GLOBALS['gp_content_display'] == 'full_content' ) { ?>

			<div class="entry-content">
				<?php global $more; $more = 0; the_content( '[' . __( 'Read More', 'gp_lang' ) . ']' ); ?>
			</div><!-- END ENTRY CONTENT -->

		<?php } else { ?>

			<?php if ( $GLOBALS['gp_excerpt_length'] != '0' ) { ?>
				<div class="entry-content">
					<p><?php echo gp_excerpt( $GLOBALS['gp_excerpt_length'] ); ?></p>
				</div><!-- END ENTRY CONTENT -->
			<?php } ?>

		<?php } ?>

		<?php if ( ( isset( $GLOBALS['gp_meta_hub_fields'] ) && $GLOBALS['gp_meta_hub_fields'] == '1' ) && ( ! empty( $GLOBALS['gp_hub_fields'][0] ) ) ) { ?>

			<div class="entry-meta">
				<?php foreach( $GLOBALS['gp_hub_fields'] as $gp_hub_field ) {
					$taxonomy = get_taxonomy( $gp_hub_field );
					if ( ! $taxonomy ) {
						continue;
					}
					$name = $taxonomy->labels->singular_name;
					$term_list = get_the_term_list( $GLOBALS['gp_hub_id'], $gp_hub_field, '<span>' . $name . ': ', ', ', '</span>' );		
					if ( ! $term_list OR is_wp_error( $term_list ) ) {
						continue;
					}	
					echo wp_kses_post( $term_list );
				} ?>
			</div><!-- END HUB FIELDS -->

		<?php } ?>

		<?php get_template_part( 'lib/sections/entry', 'meta' ); ?>
		
		<?php if ( isset( $GLOBALS['gp_meta_tags'] ) && $GLOBALS['gp_meta_tags'] == '1' ) { the_tags( '<div class="entry-meta meta-tags">', ' ', '</div>' ); } ?>
			
	</div>
	
	<?php if ( isset( $GLOBALS['gp_size'] ) && $GLOBALS['gp_size'] == 'blog-large-size' ) { ?>
		<div class="post-divider"></div>
	<?php } ?>	
								
</article><!-- END POST -->

<?php $GLOBALS['gp_review_loop'] = null; ?>