<?php
/**
 * @package somalite
 */


/**
 * Get the page title
 */
if ( ! function_exists( 'somalite_get_page_title' ) ) :
function somalite_get_page_title($blogtitle=false,$shop=false) {
	if (!is_front_page() ){
		if ('color' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
			?>
				<section id="page-title" style="background:<?php echo sanitize_hex_color(get_theme_mod( 'sm_bg_color' )); ?>;"> 
			<?php
		}
		else if ('image' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
			?>
				<section id="page-title" style="background: url(<?php echo esc_url(get_theme_mod( 'sm_bg_image' )); ?>) no-repeat;background-attachment:fixed;background-size: cover;"> 
				<?php
				
					if(true ===  get_theme_mod( 'sm_bg_radio_overlay' ) ) {
						?>
							<div class="inner-overlay"> 
						<?php
					}
				?>
			<?php
		}
		else {
			?>
				<section id="page-title" style="background:#dd3333;"> 
			<?php	
		}

		?>
			<div class="container">
				<div class="row">
					<div class="col-md-12">
						<div class="page-heading">
		                    <?php                    
		                    	$page_id = get_the_ID();
		                    ?>    	            
		    	            <?php 
		    	            	if(false==$blogtitle && false==$shop){
		    	            		?><h1 class="wow fadeInDown" data-wow-delay="1s"><?php the_title(); ?></h1>
		    	            		<p class="wow fadeInUp" data-wow-delay="2s"><?php echo get_post_meta($page_id, 'page_description', true); ?></p>
		    	            		<?php
		    	            	}
		    	            	else if(true==$blogtitle && false==$shop){
			    	           		?><h1 class="wow fadeInDown" data-wow-delay="1s"><?php single_post_title(); ?></h1>
			    	           		<p class="wow fadeInUp" data-wow-delay="2s"><?php echo get_post_meta(get_queried_object_ID(), 'page_description', true); ?></p>
			    	           		<?php
		    	            	}
		    	            	else if(true==$shop){
		    	            		?><h1 class="wow fadeInDown" data-wow-delay="1s"><?php echo esc_html(get_theme_mod( 'sm_shop_name','SHOP' )) ?></h1>
		    	            		<p class="wow fadeInUp" data-wow-delay="1s"><?php echo get_post_meta(wc_get_page_id('shop'), 'page_description', true); ?></p>
		    	            		<?php
		    	            	}    	            	
		    	            ?>
						</div>						
						<div class="bread-crumb" typeof="BreadcrumbList" vocab="http://schema.org/">
						    <?php 
						    	if(function_exists('bcn_display')){
						        	bcn_display();
						    	}
						    ?>
						</div>
					</div>
				</div>
			</div>

			<?php 
				if ( 'image' === esc_html(get_theme_mod( 'sm_bg_radio' ))  &&  true === get_theme_mod( 'sm_bg_radio_overlay' ) ){
					?> 
						</div> 
					<?php
				}
			?>
		</section>
	<?php }
}
endif;



/**
 * Archive Page Title
 */
if ( ! function_exists( 'somalite_get_page_title_archives' ) ) :
function somalite_get_page_title_archives() {
	if ('color' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
	    ?>
	    	<section id="page-title" style="background:<?php echo sanitize_hex_color(get_theme_mod( 'sm_bg_color' )); ?>"> 
	    <?php
	 }
	 else if ('image' ===  esc_html(get_theme_mod( 'sm_bg_radio' ))) {
		?>
			<section id="page-title" style="background: url(<?php echo esc_url(get_theme_mod( 'sm_bg_image' )); ?>) no-repeat;background-attachment:fixed;background-size:cover;"> 
			<?php
				if( true === get_theme_mod( 'sm_bg_radio_overlay' ) ) {
					?>
						<div class="inner-overlay"> 
					<?php
				}
			?>
		<?php
	}
	else {
		?>
			<section id="page-title" style="background:#dd3333;"> 
		<?php	
	}

	?>
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="page-heading">                        
                        <h1 class="wow fadeInDown" data-wow-delay="1s"><?php the_archive_title(); ?></h1>
                    </div>
                    <div class="bread-crumb" typeof="BreadcrumbList" vocab="http://schema.org/">
						<?php 
						   	if(function_exists('bcn_display')){
						        bcn_display();
						    }
						?>
					</div>
                </div>
            </div>
        </div>
        <?php 
        	if ( 'image' === esc_html(get_theme_mod( 'sm_bg_radio' ))  &&  true === get_theme_mod( 'sm_bg_radio_overlay' ) ){
				?> 
					</div> 
				<?php
			}
		?>
    </section>
    <?php
}
endif;


/**
 * Search Title
 */
if ( ! function_exists( 'somalite_get_page_title_search' ) ) :
function somalite_get_page_title_search() {
	if ( 'color' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
    	?>
    		<section id="page-title" style="background:<?php echo sanitize_hex_color(get_theme_mod( 'sm_bg_color' )); ?>"> 
    	<?php
  	}
  	else if ( 'image' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
		?>
			<section id="page-title" style="background: url(<?php echo esc_url(get_theme_mod( 'sm_bg_image' )); ?>) no-repeat;background-attachment:fixed;background-size:cover;"> 
			<?php
				if( true === get_theme_mod( 'sm_bg_radio_overlay' ) ){
					?>
						<div class="inner-overlay"> 
					<?php
				}
			?>
		<?php
	}
  	else {
		?>
			<section id="page-title" style="background:#dd3333;"> 
		<?php	
  	}
	
	?>
		<div class="container">
	    	<div class="row">
	            <div class="col-md-12">
	                <div class="page-heading">
	                    <h1 class="wow fadeInDown" data-wow-delay="1s"><?php printf( esc_html__( 'Search Results For: %s', 'somalite' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
	                </div>
	                <div class="bread-crumb" typeof="BreadcrumbList" vocab="http://schema.org/">
						<?php 
						   	if(function_exists('bcn_display')){
						        bcn_display();
						    }
						?>
					</div>
	            </div>
	        </div>
	    </div>
    	<?php 
    		if ( 'image' === esc_html(get_theme_mod( 'sm_bg_radio' ))  &&  true === get_theme_mod( 'sm_bg_radio_overlay' ) ){
				?> 
					</div> 
				<?php
			}
		?>
		</section>
	<?php
}
endif;


/**
 * 404 Title
 */
if ( ! function_exists( 'somalite_get_page_title_error' ) ) :
function somalite_get_page_title_error() {
	if ( 'color' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
    	?>
    		<section id="page-title" style="background:<?php echo sanitize_hex_color(get_theme_mod( 'sm_bg_color' )); ?>"> 
    	<?php
  	}
  	else if ( 'image' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
		?>
			<section id="page-title" style="background: url(<?php echo esc_url(get_theme_mod( 'sm_bg_image' )); ?>) no-repeat;background-attachment:fixed;background-size:cover;"> 
			<?php
				if( true === get_theme_mod( 'sm_bg_radio_overlay' ) ){
					?>
						<div class="inner-overlay"> 
					<?php
				}
			?>
		<?php
	}
  	else {
		?>
			<section id="page-title" style="background:#dd3333;"> 
		<?php	
  	}
	
	?>
		<div class="container">
	    	<div class="row">
	            <div class="col-md-12">
	                <div class="page-heading">
	                    <h1 class="wow fadeInDown" data-wow-delay="1s"><?php esc_html_e( 'PAGE NOT FOUND', 'somalite' ); ?></h1>
	                </div>
	                <div class="bread-crumb" typeof="BreadcrumbList" vocab="http://schema.org/">
						<?php 
						   	if(function_exists('bcn_display')){
						        bcn_display();
						    }
						?>
					</div>
	            </div>
	        </div>
	    </div>
    	<?php 
    		if ( 'image' === esc_html(get_theme_mod( 'sm_bg_radio' ))  &&  true === get_theme_mod( 'sm_bg_radio_overlay' ) ){
				?> 
					</div> 
				<?php
			}
		?>
		</section>
	<?php
}
endif;


/**
 *  Single Page Title
 */
if ( ! function_exists( 'somalite_get_page_title_single' ) ) :
function somalite_get_page_title_single() {
	if (!is_front_page() ){
		if ('color' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
			?>
				<section id="page-title" style="background:<?php echo sanitize_hex_color(get_theme_mod( 'sm_bg_color' )); ?>"> 
			<?php
		}
		else if ('image' === esc_html(get_theme_mod( 'sm_bg_radio' ))) {
			?>
				<section id="page-title" style="background: url(<?php echo esc_url(get_theme_mod( 'sm_bg_image' )); ?>) no-repeat;background-attachment:fixed;background-size:cover;"> 
				<?php
					if(true ===  get_theme_mod( 'sm_bg_radio_overlay' ) ) {
						?>
							<div class="inner-overlay"> 
						<?php
					}
				?>
			<?php
		}
		else {
			?><section id="page-title" style="background:#dd3333;"> <?php	
		}
	?>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<div class="page-heading">                    
    	            <h1 class="wow fadeInDown" data-wow-delay="1s"><?php the_title(); ?></h1>					
				</div>
				<div class="bread-crumb" typeof="BreadcrumbList" vocab="http://schema.org/">
					<?php 
						if(function_exists('bcn_display')){
						    bcn_display();
						}
					?>
				</div>
			</div>
		</div>
	</div>

	<?php 
		if ( 'image' === esc_html(get_theme_mod( 'sm_bg_radio' ))  &&  true === get_theme_mod( 'sm_bg_radio_overlay' ) ){
			?> </div> <?php
		}
	?>

	</section>
	<?php
	}	
}
endif;


/**
 * SiteOrigin Page Builder Content Check
 */
if ( ! function_exists( 'somalite_content_is_pagebuilder' ) ) :
function somalite_content_is_pagebuilder() {
    global $post;

    // consider empty content the WP editor
    if ( empty( $post ) ) 
        return false;

    // does pagebuilder content exist in custom fields?
    $panels_data = get_post_meta( $post->ID, 'panels_data', true );

    return ( empty( $panels_data ) ) ? false : true;
}
endif;


/**
 * Function for Minimizing dynamic CSS
 */
function somalite_minimize_css($css){
    $css = preg_replace('/\/\*((?!\*\/).)*\*\//', '', $css);
    $css = preg_replace('/\s{2,}/', ' ', $css);
    $css = preg_replace('/\s*([:;{}])\s*/', '$1', $css);
    $css = preg_replace('/;}/', '}', $css);
    return $css;
}


/** 
* Disable Plugin Redirect
*/
function somalite_prevent_plugins_redirect() {
    delete_transient( 'elementor_activation_redirect' );
}
add_action('admin_init', 'somalite_prevent_plugins_redirect');
