<?php global $gp; ?>

<?php if ( $GLOBALS['gp_hub_header'] == true OR is_page_template( 'review-template.php' ) ) {

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

	$args = array(
		'depth'     => -1,
		'child_of'  => $GLOBALS['gp_post_id'],
		'sort_column' => 'menu_order',
	);

	$gp_hub_tabs = get_pages( $args ); 

	if ( $gp_hub_tabs ) { ?>

		<div id="hub-tabs">
		
			<div class="gp-container">
			
				<a id="hub-tabs-mobile-nav-button"><span><?php _e( 'More Info', 'gp_lang' ); ?></span><i class="fa fa-bars"></i></a>
			
				<ul>

					<?php
				
					// Trim tab title
					$tab_title = the_title_attribute( array( 'post' => $GLOBALS['gp_post_id'], 'echo' => 0 ) );
					$max_length = 30;
					if ( strlen( $tab_title ) > $max_length ) {
						$trimmed_tab_title = substr( $tab_title, 0, $max_length ) . '...';
					} else {
						$trimmed_tab_title = $tab_title;
					}
				
					?>
							
					<li<?php if ( get_the_ID() == $GLOBALS['gp_post_id'] ) { ?> class="current_page_item"<?php } ?>><a href="<?php echo get_permalink( $GLOBALS['gp_post_id'] ); ?>" title="<?php echo esc_attr( $trimmed_tab_title ); ?>"><?php echo esc_attr( $trimmed_tab_title ); ?></a></li>
							
					<?php foreach ( $gp_hub_tabs as $gp_hub_tab ) {
				
						// Tab title settings
						if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'review-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'review_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'review_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'news-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'news_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'news_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'images-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'images_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'images_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'videos-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'videos_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'videos_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'write-a-review-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'write_a_review_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'write_a_review_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'user-reviews-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'user_reviews_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'user_reviews_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'blog-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'blog_template_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'blog_template_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'portfolio-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'portfolio_template_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'portfolio_template_tab_title' );
							$tab_link = '';
							$tab_target = '';
						} else if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'link-template.php' ) {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_tab_title' );
							$tab_link = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_link' );
							$tab_target = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_link_target' );
						} else {
							$tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'page_tab' );
							$tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'page_tab_title' );
							$tab_link = '';
							$tab_target = '';
						}

						// Trim tab title
						if ( empty( $tab_title ) ) {
							$tab_title = $gp_hub_tab->post_title;
						}	
						$max_length = 30;
						if ( strlen( $tab_title ) > $max_length ) {
							$trimmed_tab_title = substr( $tab_title, 0, $max_length ) . '...';
						} else {
							$trimmed_tab_title = $tab_title;
						}
					
						?>

						<?php if ( $tab == 'enabled' ) { ?>
							<li<?php if ( get_the_ID() == $gp_hub_tab->ID ) { ?> class="current_page_item"<?php } ?>><a href="<?php if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'link-template.php' && ! empty( $tab_link ) ) { echo esc_url( $tab_link ); } else { echo get_page_link( $gp_hub_tab->ID ); } ?>" title="<?php echo esc_attr( $tab_title ); ?>"<?php if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'link-template.php' ) { ?> target="<?php echo esc_attr( $tab_target ); ?>"<?php } ?>><?php echo esc_attr( $trimmed_tab_title ); ?></a></li>
						<?php } ?>
					
					<?php } ?>

				</ul>
			
			</div>
		
		</div><!-- END HUB TABS -->
	
	<?php

		// Reset rich snippets
		$GLOBALS['gp_site_rich_snippets'] = false;
		$GLOBALS['gp_user_rich_snippets'] = false;	
	
	} 
	
} ?>