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

get_header();
the_post();

global $post, $restorator_options;

$restorator_pf = get_post_format();
if (empty($restorator_pf)) $restorator_pf = "standard";

$restorator_portfolio_single_layout 			= get_post_meta( $post->ID, 'restorator_portfolio_single_layout', true );
$restorator_portfolio_single_client 			= get_post_meta( $post->ID, 'restorator_portfolio_single_client', true );
$restorator_portfolio_single_add_field_title 	= get_post_meta( $post->ID, 'restorator_portfolio_single_add_field_title', true );
$restorator_portfolio_single_add_field 			= get_post_meta( $post->ID, 'restorator_portfolio_single_add_field', true );
$restorator_portfolio_single_add_field_title2 	= get_post_meta( $post->ID, 'restorator_portfolio_single_add_field_title2', true );
$restorator_portfolio_single_add_field2 		= get_post_meta( $post->ID, 'restorator_portfolio_single_add_field2', true );
$restorator_portfolio_single_add_field_title3 	= get_post_meta( $post->ID, 'restorator_portfolio_single_add_field_title3', true );
$restorator_portfolio_single_add_field3 		= get_post_meta( $post->ID, 'restorator_portfolio_single_add_field3', true );
$restorator_portfolio_single_link 				= get_post_meta( $post->ID, 'restorator_portfolio_single_link', true );
$restorator_portfolio_single_link_name 			= get_post_meta( $post->ID, 'restorator_portfolio_single_link_name', true );

// Categories
$restorator_portfolio_category = get_the_term_list($post->ID, 'portfolio_category', '', ', ', '');

/* ADD 1 view for this post */
$restorator_post_views = (get_post_meta(get_the_ID(), "post_views", true) > 0 ? get_post_meta(get_the_ID(), "post_views", true) : "0");
update_post_meta(get_the_ID(), "post_views", (int)$restorator_post_views + 1);

$restorator_portfolio_single_sharebox = isset( $restorator_options['portfolio_single_sharebox'] ) ? $restorator_options['portfolio_single_sharebox'] : '1';
$restorator_portfolio_single_navigation = isset( $restorator_options['portfolio_single_navigation'] ) ? $restorator_options['portfolio_single_navigation'] : '1';

$restorator_custom_divider = $restorator_options['custom_divider']['url'];
$restorator_custom_divider_width = isset( $restorator_options['custom_divider_width'] ) ? $restorator_options['custom_divider_width'] : '48';
?>
		
		<div class="container">
			<div id="portfolio_single_wrap" class="<?php echo 'format-' . esc_html( $restorator_pf ) . ' ' . esc_html( $restorator_portfolio_single_layout ); ?> clearfix mb50">
				<div class="row">
					
					<?php if( $restorator_portfolio_single_layout == 'full_width' ) { ?>
						
						<div class="col-md-12">
							<div class="row">
								<div class="col-lg-8 col-md-7">
									<div class="portfolio_single_content clearfix">
										<div class="portfolio_single_title_wrap">
											<h3 class="portfolio_single_title"><?php the_title(); ?></h3>
											<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>
											<div class="post_likes"><?php echo restorator_likes(); ?></div>
										</div>
										<?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>
								<div class="col-lg-4 col-md-5">
									<div class="portfolio_single_details_wrap">
										<?php if( isset( $restorator_portfolio_single_client ) && $restorator_portfolio_single_client != '' ) { ?>
											<div class="portfolio_single_det">
												<p><i><strong><?php esc_html_e('Client', 'restorator') ?></strong></i>
												<span class="portfolio-client">
													<?php echo esc_attr( $restorator_portfolio_single_client ); ?>
												</span></p>
											</div>
										<?php } ?>
										<?php if( !empty( $restorator_portfolio_category ) ) { ?>
											<div class="portfolio_single_det">
												<p><i><strong><?php esc_html_e('Category', 'restorator') ?></strong></i>
												<span class="portfolio-category">
													<?php echo strip_tags($restorator_portfolio_category) ?>
												</span></p>
											</div>
										<?php } ?>
										<?php if(get_the_term_list($post->ID, 'portfolio_tag', '', ',', '')) { ?>
											<div class="portfolio_single_det">
												<p><i><strong><?php esc_html_e('Tags', 'restorator') ?></strong></i>
												<span class="portfolio-tag">
													<?php echo get_the_term_list($post->ID, 'portfolio_tag', '', ', ', ''); ?>
												</span></p>
											</div>
										<?php } ?>
										<div class="portfolio_single_det">
											<p><i><strong><?php esc_html_e('Date', 'restorator') ?></strong></i>
											<span class="portfolio-date">
												<?php the_date('j F Y'); ?>
											</span></p>
										</div>
										<?php if( isset( $restorator_portfolio_single_add_field_title ) && $restorator_portfolio_single_add_field_title != '' ) { ?>
											<div class="portfolio_single_det">
												<p><i><strong><?php echo esc_attr( $restorator_portfolio_single_add_field_title ); ?></strong></i>
												<span class="portfolio-add_field">
													<?php echo esc_attr( $restorator_portfolio_single_add_field ); ?>
												</span></p>
											</div>
										<?php } ?>
										<?php if( isset( $restorator_portfolio_single_add_field_title2 ) && $restorator_portfolio_single_add_field_title2 != '' ) { ?>
											<div class="portfolio_single_det">
												<p><i><strong><?php echo esc_attr( $restorator_portfolio_single_add_field_title2 ); ?></strong></i>
												<span class="portfolio-add_field">
													<?php echo esc_attr( $restorator_portfolio_single_add_field2 ); ?>
												</span></p>
											</div>
										<?php } ?>
										<?php if( isset( $restorator_portfolio_single_add_field_title3 ) && $restorator_portfolio_single_add_field_title3 != '' ) { ?>
											<div class="portfolio_single_det">
												<p><i><strong><?php echo esc_attr( $restorator_portfolio_single_add_field_title3 ); ?></strong></i>
												<span class="portfolio-add_field">
													<?php echo esc_attr( $restorator_portfolio_single_add_field3 ); ?>
												</span></p>
											</div>
										<?php } ?>
										<?php if( isset( $restorator_portfolio_single_link ) && $restorator_portfolio_single_link != '' ) { ?>
											<div class="portfolio_single_det">
												<p><i><strong><?php esc_html_e('Link', 'restorator') ?></strong></i>
												<span class="portfolio-custom-link">
													<a class="theme_color" href="<?php echo esc_url( $restorator_portfolio_single_link ); ?>" target="_blank">
														<?php echo esc_attr( ( $restorator_portfolio_single_link_name != '' ) ? $restorator_portfolio_single_link_name : $restorator_portfolio_single_link ); ?>
													</a>
												</span></p>
											</div>
										<?php } ?>
										<?php if( $restorator_portfolio_single_sharebox != 0 ) { ?>
											<div class="portfolio_single_sharebox">
												<?php get_template_part( 'templates/portfolio/sharebox' ); ?>
											</div>
										<?php } ?>
									</div>
								</div>
							</div>
						</div>
						<div class="col-md-12">
							<div class="portfolio_format_content">
								<?php get_template_part( 'templates/portfolio/post-format/post', $restorator_pf ); ?>
							</div>
						</div>
					
					<?php } elseif ( $restorator_portfolio_single_layout == 'half_width' ) { ?>
						
						<div class="col-lg-8 col-md-7 mb50">
							<div class="portfolio_format_content">
								<?php get_template_part( 'templates/portfolio/post-format/post', $restorator_pf ); ?>
							</div>
						</div>
						<div class="col-lg-4 col-md-5 mb50">
							<div class="portfolio_single_content clearfix">
								<div class="portfolio_single_title_wrap">
									<h3 class="portfolio_single_title"><?php the_title(); ?></h3>
									<div class="divider_active"><img width="<?php echo esc_attr( $restorator_custom_divider_width ); ?>px" src="<?php echo esc_url( $restorator_custom_divider ); ?>" alt="" /></div>
									<div class="post_likes"><?php echo restorator_likes(); ?></div>
								</div>
								<?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="portfolio_single_details_wrap">
								<?php if( isset( $restorator_portfolio_single_client ) && $restorator_portfolio_single_client != '' ) { ?>
									<div class="portfolio_single_det">
										<p><i><strong><?php esc_html_e('Client', 'restorator') ?></strong></i>
										<span class="portfolio-client">
											<?php echo esc_attr( $restorator_portfolio_single_client ); ?>
										</span></p>
									</div>
								<?php } ?>
								<?php if( !empty( $restorator_portfolio_category ) ) { ?>
									<div class="portfolio_single_det">
										<p><i><strong><?php esc_html_e('Category', 'restorator') ?></strong></i>
										<span class="portfolio-category">
											<?php echo strip_tags($restorator_portfolio_category) ?>
										</span></p>
									</div>
								<?php } ?>
								<?php if(get_the_term_list($post->ID, 'portfolio_tag', '', ',', '')) { ?>
									<div class="portfolio_single_det">
										<p><i><strong><?php esc_html_e('Tags', 'restorator') ?></strong></i>
										<span class="portfolio-tag">
											<?php echo get_the_term_list($post->ID, 'portfolio_tag', '', ', ', ''); ?>
										</span></p>
									</div>
								<?php } ?>
								<div class="portfolio_single_det">
									<p><i><strong><?php esc_html_e('Date', 'restorator') ?></strong></i>
									<span class="portfolio-date">
										<?php the_date('j F Y'); ?>
									</span></p>
								</div>
								<?php if( isset( $restorator_portfolio_single_add_field_title ) && $restorator_portfolio_single_add_field_title != '' ) { ?>
									<div class="portfolio_single_det">
										<p><i><strong><?php echo esc_attr( $restorator_portfolio_single_add_field_title ); ?></strong></i>
										<span class="portfolio-add_field">
											<?php echo esc_attr( $restorator_portfolio_single_add_field ); ?>
										</span></p>
									</div>
								<?php } ?>
								<?php if( isset( $restorator_portfolio_single_add_field_title2 ) && $restorator_portfolio_single_add_field_title2 != '' ) { ?>
									<div class="portfolio_single_det">
										<p><i><strong><?php echo esc_attr( $restorator_portfolio_single_add_field_title2 ); ?></strong></i>
										<span class="portfolio-add_field">
											<?php echo esc_attr( $restorator_portfolio_single_add_field2 ); ?>
										</span></p>
									</div>
								<?php } ?>
								<?php if( isset( $restorator_portfolio_single_add_field_title3 ) && $restorator_portfolio_single_add_field_title3 != '' ) { ?>
									<div class="portfolio_single_det">
										<p><i><strong><?php echo esc_attr( $restorator_portfolio_single_add_field_title3 ); ?></strong></i>
										<span class="portfolio-add_field">
											<?php echo esc_attr( $restorator_portfolio_single_add_field3 ); ?>
										</span></p>
									</div>
								<?php } ?>
								<?php if( isset( $restorator_portfolio_single_link ) && $restorator_portfolio_single_link != '' ) { ?>
									<div class="portfolio_single_det">
										<p><i><strong><?php esc_html_e('Link', 'restorator') ?></strong></i>
										<span class="portfolio-custom-link">
											<a class="theme_color" href="<?php echo esc_url( $restorator_portfolio_single_link ); ?>" target="_blank">
												<?php echo esc_attr( ( $restorator_portfolio_single_link_name != '' ) ? $restorator_portfolio_single_link_name : $restorator_portfolio_single_link ); ?>
											</a>
										</span></p>
									</div>
								<?php } ?>
								<?php if( $restorator_portfolio_single_sharebox != 0 ) { ?>
									<div class="portfolio_single_sharebox">
										<?php get_template_part( 'templates/portfolio/sharebox' ); ?>
									</div>
								<?php } ?>
							</div>
						</div>
						
					<?php } ?>
					
				</div>
			</div>
		</div>
		
		<?php if( $restorator_portfolio_single_navigation != 0) { ?>
			<div class="portfolio_single_nav">
					
				<?php $restorator_options_header_layout = isset( $restorator_options['header-layout'] ) ? $restorator_options['header-layout'] : 'full_width'; ?>
				<?php $restorator_header_layout = get_post_meta( $post->ID, 'restorator_header_layout', true ) ? get_post_meta( $post->ID, 'restorator_header_layout', true ) : $restorator_options_header_layout; ?>
				<div class="<?php if( $restorator_header_layout != 'full_width' ) { echo 'container'; } ?> clearfix">
					
					<?php
						
						$restorator_prev_post = get_adjacent_post(false, '', false);
						$restorator_next_post = get_adjacent_post(false, '', true);
						if( isset( $restorator_options['portfolio_single_navigation_backbtn'] ) && $restorator_options['portfolio_single_navigation_backbtn'] != '' ){
							$restorator_portfolio_single_navigation_backbtn = $restorator_options['portfolio_single_navigation_backbtn'];
						}
						
						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 . '"><i class="first fa fa-angle-left"></i><i class="last fa fa-angle-left"></i><span>' . $restorator_prev_post->post_title . '</span></a></div>';
						}
						
						if( isset( $restorator_options['portfolio_single_navigation_backbtn'] ) && $restorator_options['portfolio_single_navigation_backbtn'] != '' ){
							echo '<a class="back-to-portfolio" href="' . esc_url( $restorator_portfolio_single_navigation_backbtn ) . '"><i class="icon Evatheme-Icon-Fonts-thin-0208_grid_view"></i></a>';
						}
						
						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 . '"><i class="first fa fa-angle-right"></i><i class="last fa fa-angle-right"></i><span>' . $restorator_next_post->post_title . '</span></a></div>';
						} 
					?>
					
				</div>
			</div>
		<?php } ?>

<?php get_footer(); ?>
