<?php
/**
 * Page Title
 */

	global $post, $wp_query, $restorator_options;
	
	$restorator_postId = ( isset( $post->ID ) ? get_the_ID() : NULL );
	
	$restorator_custom_divider = isset( $restorator_options['custom_divider']['url'] ) ? $restorator_options['custom_divider']['url'] : '';
	$restorator_custom_divider_width = isset( $restorator_options['custom_divider_width'] ) ? $restorator_options['custom_divider_width'] : '48';
	
	$restorator_options_pagetitle = isset( $restorator_options['pagetitle'] ) ? $restorator_options['pagetitle'] : 'show';
	$restorator_pagetitle = get_post_meta( $restorator_postId, 'restorator_pagetitle', true ) ? get_post_meta( $post->ID, 'restorator_pagetitle', true ) : $restorator_options_pagetitle;
	if ( is_home() || is_singular('post') || is_category() || is_tag() || is_day() || is_month() || is_year() ) {
		$restorator_pagetitle = isset( $restorator_options['blog_pagetitle'] ) ? $restorator_options['blog_pagetitle'] : 'hide';
	} elseif ( is_search() ) {
		$restorator_pagetitle = 'show';
	} else if ( is_singular('portfolio') ) {
		$restorator_pagetitle = isset( $restorator_options['portfolio_single_pagetitle'] ) ? $restorator_options['portfolio_single_pagetitle'] : 'show';
	} else if( class_exists('WooCommerce') && ( is_shop() || is_product_category() || is_product_tag() || is_cart() || is_checkout() || is_account_page() ) ) {
		$restorator_pagetitle = isset( $restorator_options['shop_pagetitle'] ) ? $restorator_options['shop_pagetitle'] : 'show';
	} else if( class_exists('WooCommerce') && is_singular('product') ) {
		$restorator_pagetitle = 'hide';
	}
	
	
	$restorator_pagetitle_text			= get_post_meta( $restorator_postId, 'restorator_pagetitle_text', true );
	$restorator_blog_pagetitle_text		= isset( $restorator_options['blog_pagetitle_text'] ) ? $restorator_options['blog_pagetitle_text'] : esc_html__('Recent Posts', 'restorator');
	$restorator_pagetitle_subtext		= get_post_meta( $restorator_postId, 'restorator_pagetitle_subtext', true );
	$restorator_blog_pagetitle_subtext	= isset( $restorator_options['blog_pagetitle_subtext'] ) ? $restorator_options['blog_pagetitle_subtext'] : '';


	if ( $restorator_pagetitle_subtext != '' ) {
		$restorator_pagetitle_subtext = $restorator_pagetitle_subtext;
	} else if ( ( isset( $restorator_options['blog_pagetitle_subtext'] ) && $restorator_options['blog_pagetitle_subtext'] != '' ) && ( is_home() ) ) {
		$restorator_pagetitle_subtext = $restorator_blog_pagetitle_subtext;
	} elseif ( is_search() ) {
		$restorator_pagetitle_subtext = 'This is your custom search page';
	}
	
	if ( $restorator_pagetitle_text != '' ) {
		$restorator_pagetitle_text = $restorator_pagetitle_text;
	} else if (is_home()) {
		$restorator_pagetitle_text = $restorator_blog_pagetitle_text;
	} else if ( is_singular('post') ) {
		if( isset( $restorator_options['blogsingle_pagetitle_text'] ) && $restorator_options['blogsingle_pagetitle_text'] != '' ){
			$restorator_blogsingle_pagetitle_text = $restorator_options['blogsingle_pagetitle_text'];
			$restorator_pagetitle_text = $restorator_blogsingle_pagetitle_text;
		} else {
			$restorator_pagetitle_text = esc_html__( 'Single Post', 'restorator' );
		}
		if( isset( $restorator_options['blogsingle_pagetitle_subtext'] ) && $restorator_options['blogsingle_pagetitle_subtext'] != '' ){
			$restorator_blogsingle_pagetitle_subtext 	= $restorator_options['blogsingle_pagetitle_subtext'];
			$restorator_pagetitle_subtext  = esc_attr( $restorator_blogsingle_pagetitle_subtext );
		}
	} else if ( is_singular('portfolio') ) {
		if( isset( $restorator_options['portfolio_single_pagetitle_subtext'] ) && $restorator_options['portfolio_single_pagetitle_subtext'] != '' ) {
			$restorator_pagetitle_subtext  = $restorator_options['portfolio_single_pagetitle_subtext'];
		}
		if( isset( $restorator_options['portfolio_single_pagetitle_text'] ) && $restorator_options['portfolio_single_pagetitle_text'] != '' ) {
			$restorator_pagetitle_text = $restorator_options['portfolio_single_pagetitle_text'];
		}
	} else if( class_exists('WooCommerce') && is_shop() ) {
		if( isset( $restorator_options['shop_pagetitle_subtext'] ) && $restorator_options['shop_pagetitle_subtext'] != '' ){
			$restorator_pagetitle_subtext  = $restorator_options['shop_pagetitle_subtext'];
		}
		if( isset( $restorator_options['shop_pagetitle_text'] ) && $restorator_options['shop_pagetitle_text'] != '' ){
			$restorator_pagetitle_text = $restorator_options['shop_pagetitle_text'];
		}
	} else if (is_category()) {
		$restorator_pagetitle_text = esc_attr__( 'Category Archive for :', 'restorator' ) . ' &#8216;' . single_cat_title( '', false ) . '&#8217 ';
	} else if( is_tag() ) {
		$restorator_pagetitle_text = esc_attr__( 'Posts Tagged', 'restorator' ) . ' &#8216;' . single_tag_title() . '&#8217;';
	} else if( is_search() ) {
		$restorator_pagetitle_text = $wp_query->found_posts . ' ' . esc_attr__( 'search results for', 'restorator' ) . ': \'' . esc_attr( get_search_query() ) . '\'';
	} else if ( is_day() || is_month() || is_year() ) {
		$restorator_pagetitle_text = esc_attr__( 'Archive for', 'restorator' ) . ' ' . get_the_time( get_option( 'date_format' ) ) . '</span>';
	} else if (is_author()) {
		$restorator_pagetitle_text = esc_attr__( 'Author Archive', 'restorator' );
	} else if (is_404()) {
		$restorator_pagetitle_text = esc_attr__( 'Error 404', 'restorator' );
	} else if (isset($_GET['paged']) && !empty($_GET['paged'])) {
		$restorator_pagetitle_text = esc_attr__( 'Blog Archives', 'restorator' );
	} else {
		$restorator_pagetitle_text = get_the_title();
	}
	
	/* Parallax Effect */
	$restorator_pagetitle_bg_image_parallax = $restorator_pagetitle_bg_image_parallax_theme = $restorator_pagetitle_bg_image_parallax_page = $restorator_pagetitle_class = '';
	$restorator_pagetitle_bg_image_parallax_theme = get_post_meta( $restorator_postId, 'restorator_pagetitle_bg_image_parallax', true );
	if( isset( $restorator_options['pagetitle_bg_image_parallax'] ) ){
		$restorator_pagetitle_bg_image_parallax_page 	= $restorator_options['pagetitle_bg_image_parallax'];
	}
	$restorator_pagetitle_bg_image_parallax = ! empty( $restorator_pagetitle_bg_image_parallax_theme ) ? $restorator_pagetitle_bg_image_parallax_theme : $restorator_pagetitle_bg_image_parallax_page;
	if ( $restorator_pagetitle_bg_image_parallax == 'enable' ) {
		$restorator_pagetitle_class .= ' restorator_parallax';
	}
	
	/* If Single Post Fullscreen */
	$restorator_post_single_style = '';
	$restorator_post_single_style = get_post_meta( $restorator_postId, 'restorator_post_single_style', true );
	if ( is_singular('post') && $restorator_post_single_style == 'fullscreen' ) {
		$restorator_pagetitle_class .= ' pagetitle_fullscreen';
	}
	
?>
		
		<?php if ( $restorator_pagetitle == 'show' ) { ?>
			<div id="pagetitle" class="<?php echo esc_html( $restorator_pagetitle_class ); ?>">
				<div class="container text-center">
					
					<?php if ( is_singular('post') && $restorator_post_single_style == 'fullscreen' ) { ?>
						
						<div class="single_post_header">
							<?php echo restorator_likes(); ?>
							<h2 class="single-post-title"><?php the_title(); ?></h2>
							<div class="post-meta">
								<span class="post-meta-author"><?php echo esc_attr__('by','restorator'); ?><i><?php echo the_author_meta( 'display_name' , $post->post_author ); ?></i></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>
								<span class="post-meta-comments"><?php echo restorator_comment_count(); ?></span>
							</div>
						</div>
						
					<?php } else {
					
						if( !empty( $restorator_pagetitle_subtext ) ) {
							echo '<p>'. esc_html( $restorator_pagetitle_subtext ) . '</p>';
						}
						if( !empty( $restorator_pagetitle_text ) ) {
							echo '<h2>'. esc_html( $restorator_pagetitle_text ) .'</h2>';
						}
						
					} ?>
					<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>
			</div>
		<?php } ?>
		
		<?php $restorator_options_breadcrumbs = isset( $restorator_options['breadcrumbs'] ) ? $restorator_options['breadcrumbs'] : 'show'; ?>
		<?php $restorator_breadcrumbs = ( get_post_meta( $restorator_postId, 'restorator_breadcrumbs', true ) ? get_post_meta( $post->ID, 'restorator_breadcrumbs', true ) : $restorator_options_breadcrumbs ); ?>
		<?php if ( is_singular('portfolio') ) {
			$restorator_breadcrumbs = isset( $restorator_options['portfolio_single_breadcrumbs'] ) ? $restorator_options['portfolio_single_breadcrumbs'] : 'show';
		} ?>
		
		<?php if ( $restorator_breadcrumbs == 'show' ) { ?>
			<div id="breadcrumbs">
				<div class="container">
					<div class="row">
						<div class="col-sm-8">
							<?php restorator_breadcrumbs(); ?>
						</div>
						<?php if ( ! is_front_page() ) { ?>
							<div class="col-sm-4 text-right">
								<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><i class="fa fa-chevron-left"></i><?php echo esc_attr__( 'Back Home', 'restorator' ); ?></a>
							</div>
						<?php } ?>
					</div>
				</div>
			</div>
		<?php } ?>