<?php
/**
 * The template for displaying all single posts and attachments
 */

get_header();

global $post, $restorator_options;

$restorator_pf = get_post_format();

$restorator_custom_divider = $restorator_options['custom_divider']['url'];
$restorator_custom_divider_width = isset( $restorator_options['custom_divider_width'] ) ? $restorator_options['custom_divider_width'] : '48';

$restorator_blogsingle_layout = isset( $restorator_options['blogsingle_layout'] ) ? $restorator_options['blogsingle_layout'] : 'right-sidebar';

if( $restorator_blogsingle_layout == 'left-sidebar' ) {
	$restorator_sidebar_class = 'pull-left ';
	$restorator_blogsingle_wrap_class = 'left_sidebar ';
	$restorator_blogsingle_class = 'col-md-8 pull-right';
} elseif( $restorator_blogsingle_layout == 'right-sidebar' ) {
	$restorator_sidebar_class = 'pull-right';
	$restorator_blogsingle_wrap_class = 'right_sidebar ';
	$restorator_blogsingle_class = 'col-md-8 pull-left ';
} else {
	$restorator_sidebar_class = $restorator_blogsingle_class = '';
	$restorator_blogsingle_wrap_class = 'no_sidebar ';
}

$restorator_post_single_style = get_post_meta( $post->ID, 'restorator_post_single_style', true );
$restorator_single_post_sharebox = class_exists( 'ReduxFrameworkPlugin' ) ? $restorator_options['single_post_sharebox'] : 0;
$restorator_single_post_author = class_exists( 'ReduxFrameworkPlugin' ) ? $restorator_options['single_post_author'] : 1;
$restorator_single_post_navigation = class_exists( 'ReduxFrameworkPlugin' ) ? $restorator_options['single_post_navigation'] : 1;
$restorator_single_post_related_posts = class_exists( 'ReduxFrameworkPlugin' ) ? $restorator_options['single_post_related_posts'] : 1;
?>
		
	<div class="container">
		
		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
			<div id="blog-single-wrap" class="<?php echo 'format-' . esc_html( $restorator_pf ) . ' ' . esc_html( $restorator_blogsingle_wrap_class ) . ' ' . esc_html( $restorator_post_single_style ); ?> clearfix">
				
				<?php if( $restorator_post_single_style == 'fullscreen' ) { ?>
					
					<?php if( $restorator_blogsingle_layout != 'no-sidebar' ) { ?>
						<div class="row">
							<div class="<?php echo esc_html( $restorator_blogsingle_class ); ?>">
						<?php } ?>
								
								<?php if( $restorator_pf != 'image' && $restorator_pf != 'standard' ) { ?>
									<div class="post_format_content text-center">
										<?php get_template_part( 'templates/blog/post-format/post', $restorator_pf ); ?>
									</div>
								<?php } ?>

								<div class="single-post-content clearfix">
									
									<?php
										the_content(esc_html__('Read more!', 'restorator'));
										wp_link_pages(array('before' => '<div class="page-link mb20">' . esc_html__('Pages', 'restorator') . ': ', 'after' => '</div>'));
									?>
									
								</div>
								
								<div class="posts_nav_link"><?php posts_nav_link(); ?></div>
								
								<div class="single_post_meta_tags">
									<?php if( has_tag() ) {
										the_tags('','', '');
									} ?>
								</div>
							
						<?php if( $restorator_blogsingle_layout != 'no-sidebar' ) { ?>
							</div>
							
							<div class="col-md-4 <?php echo esc_html( $restorator_sidebar_class ); ?>">
								<?php get_sidebar(); ?>
							</div>
						</div>
					<?php } ?>
			
					<?php if( $restorator_single_post_sharebox != 0 ) {
						get_template_part( 'templates/blog/sharebox' );
					} ?>
					
					<?php if( $restorator_single_post_author != 0 ) {
						get_template_part( 'templates/blog/authorinfo' );
					} ?>
					
					<?php if( $restorator_single_post_navigation == 'show' ) { ?>
						<div class="single_post_nav clearfix">
							<?php
								$restorator_prev_post = get_adjacent_post(false, '', false);
								$restorator_next_post = get_adjacent_post(false, '', true);

								if($restorator_prev_post){
									$restorator_post_url = get_permalink($restorator_prev_post->ID);            
									echo '<div class="pull-left"><a href="' . esc_url( $restorator_post_url ) . '" title="' . $restorator_prev_post->post_title . '"><p class="heading_font"><i class="fa fa-chevron-left"></i>' . esc_html__('Previous','restorator') . '</p><b>' . $restorator_prev_post->post_title . '</b></a></div>';
								}

								if($restorator_next_post) {
									$restorator_post_url = get_permalink($restorator_next_post->ID);            
									echo '<div class="pull-right text-right"><a href="' . esc_url( $restorator_post_url ) . '" title="' . $restorator_next_post->post_title . '"><p class="heading_font">' . esc_html__('Next','restorator') . '<i class="fa fa-chevron-right"></i></p><b>' . $restorator_next_post->post_title . '</b></a></div>';
								} 
							?>
						</div>
					<?php } ?>
				
					<?php if( $restorator_single_post_related_posts != 0 ) {
						get_template_part('templates/blog/related-posts');
					} ?>
					
					<?php 
						if ( comments_open() || get_comments_number() ) :
							comments_template();
						endif;
					?>
					
				<?php } else { ?>
				
					<?php if( $restorator_blogsingle_layout != 'no-sidebar' ) { ?>
						<div class="row">
							<div class="<?php echo esc_html( $restorator_blogsingle_class ); ?>">
						<?php } ?>
							
								<div class="single_post_header">
									<h2 class="single-post-title"><?php the_title(); ?></h2>
									<div class="clearfix">
										<div class="post-meta pull-left">
											<div class="divider_active">
												<?php if( isset( $restorator_custom_divider ) && !empty( $restorator_custom_divider ) ){ ?>
													<img src="<?php echo esc_url( $restorator_custom_divider ); ?>" alt="" style="width:<?php echo esc_attr( $restorator_custom_divider_width ); ?>px !important;" />
												<?php } else { ?>
													<span class="bg_primary" style="width:<?php echo esc_attr( $restorator_custom_divider_width ); ?>px !important;"></span>
												<?php } ?>
											</div>
											<span class="post-meta-author"><?php echo esc_attr__('by','restorator'); ?><a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php echo get_the_author_meta('display_name'); ?></a></span>
											<span class="post_meta_category"><?php echo esc_attr__('in','restorator'); ?><?php the_category(', '); ?></span>
											<span class="post-meta-date"><?php echo esc_attr__('posted','restorator'); ?><i><?php the_time('j F, Y'); ?></i></span>
										</div>
										<div class="pull-right">
											<span class="post-meta-comments"><i class="icon Evatheme-Icon-Fonts-thin-0274_chat_message_comment_bubble"></i><?php echo get_comments_number('0', '1', '%'); ?></span>
											<div class="post_likes"><?php echo restorator_likes(); ?></div>
										</div>
									</div>
								</div>
								
								<div class="post_format_content text-center">
									<?php get_template_part( 'templates/blog/post-format/post', get_post_format() ); ?>
								</div>

								<div class="single-post-content clearfix">
									
									<?php
										the_content(esc_html__('Read more!', 'restorator'));
										wp_link_pages(array('before' => '<div class="page-link mb20">' . esc_html__('Pages', 'restorator') . ': ', 'after' => '</div>'));
									?>
									
								</div>
								
								<div class="posts_nav_link"><?php posts_nav_link(); ?></div>
								
								<div class="single_post_meta_tags">
									<?php if( has_tag() ) {
										the_tags('','', '');
									} ?>
								</div>
									
								<?php if( $restorator_single_post_sharebox != 0 ) {
									get_template_part( 'templates/blog/sharebox' );
								} ?>
								
								<?php if( $restorator_single_post_author != 0 ) {
									get_template_part( 'templates/blog/authorinfo' );
								} ?>
								
								<?php if( $restorator_single_post_navigation == 'show' ) { ?>
									<div class="single_post_nav clearfix">
										<?php
											$restorator_prev_post = get_adjacent_post(false, '', false);
											$restorator_next_post = get_adjacent_post(false, '', true);

											if($restorator_prev_post){
												$restorator_post_url = get_permalink($restorator_prev_post->ID);            
												echo '<div class="pull-left"><a href="' . esc_url( $restorator_post_url ) . '" title="' . $restorator_prev_post->post_title . '"><p><i class="fa fa-chevron-left"></i>' . esc_html__('Previous','restorator') . '</p><b>' . $restorator_prev_post->post_title . '</b></a></div>';
											}

											if($restorator_next_post) {
												$restorator_post_url = get_permalink($restorator_next_post->ID);            
												echo '<div class="pull-right text-right"><a href="' . esc_url( $restorator_post_url ) . '" title="' . $restorator_next_post->post_title . '"><p>' . esc_html__('Next','restorator') . '<i class="fa fa-chevron-right"></i></p><b>' . $restorator_next_post->post_title . '</b></a></div>';
											} 
										?>
									</div>
								<?php } ?>
							
								<?php if( $restorator_single_post_related_posts != 0 ) {
									get_template_part('templates/blog/related-posts');
								} ?>
								
								<?php 
									if ( comments_open() || get_comments_number() ) :
										comments_template();
									endif;
								?>
						
						<?php if( $restorator_blogsingle_layout != 'no-sidebar' ) { ?>
							</div>
							
							<div class="col-md-4 <?php echo esc_html( $restorator_sidebar_class ); ?>">
								<?php get_sidebar(); ?>
							</div>
						</div>
					<?php } ?>
				<?php } ?>
			</div>
		<?php endwhile; endif; ?>
		
	</div>

<?php get_footer(); ?>
