<?php global $gp; 

if ( is_page_template( 'review-template.php' ) && $post->post_parent > 0 ) { 
	$GLOBALS['gp_post_id'] = $post->post_parent;
} else {
	$GLOBALS['gp_post_id'] = get_the_ID();
}

?>

<?php if ( get_post_meta( get_the_ID(), 'review_title_text', true ) != 'disabled' ) { ?>
	<h1 class="entry-title"><?php if ( ! empty( $gp['review_custom_title'] ) ) { echo esc_attr( $gp['review_custom_title'] ); } else { echo gp_prefix_hub_title( get_the_ID() ); } ?></h1>
<?php } ?>
	
<?php if ( $gp['review_meta']['avatar'] == '1' OR $gp['review_meta']['author_date'] == '1' ) { ?>	
	<div class="author-meta">
		<?php if ( $gp['review_meta']['avatar'] == '1' ) { ?>
			<?php echo get_avatar( get_the_author_meta( 'ID', $post->post_author ), 40 ); ?>
		<?php } ?>	
		<?php if ( $gp['review_meta']['author_date'] == '1' ) { ?>						
			<h3 class="subtitle"><?php _e( 'By', 'gp_lang' ); ?> <span class="fn"><?php echo the_author_meta( 'display_name', $post->post_author ); ?></span> <?php _e( 'on', 'gp_lang' ); ?> <span class="date updated"><?php the_time( get_option( 'date_format' ) ); ?></span></h3>
		<?php } ?>
	</div>
<?php } ?>

<?php if ( isset( $gp['review_header_cats'] ) && ! empty( $gp['review_header_cats'][0] ) ) { ?>
	
	<div class="hub-header-cats">

		<?php foreach( $gp['review_header_cats'] as $gp_hub_cat ) {
			if ( has_term( $gp_hub_cat, 'gp_hubs', $GLOBALS['gp_post_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 REVIEW HEADER CATEGORIES -->

<?php } ?>

<?php if ( ! empty( $gp['review_header_fields'][0] ) ) { ?>

	<div class="hub-header-fields">

		<?php foreach( $gp['review_header_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_post_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 REVIEW HEADER FIELDS -->

<?php } ?>