<?php
/**
 * Custom template tags for this theme.
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package leatherhouse
 */

if ( ! function_exists( 'leatherhouse_posted_on' ) ) :
	/**
	 * Prints HTML with meta information for the current post-date/time and author.
	 */
	function leatherhouse_posted_on() {
		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
		}

		$time_string = sprintf(
			$time_string,
			esc_attr( get_the_date( 'c' ) ),
			esc_html( get_the_date() ),
			esc_attr( get_the_modified_date( 'c' ) ),
			esc_html( get_the_modified_date() )
		);

		$posted_on = sprintf(
			esc_html_x( 'Posted on %s', 'post date', 'leather-house' ),
			'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
		);

		$byline = sprintf(
			esc_html_x( 'by %s', 'post author', 'leather-house' ),
			'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
		);
		echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
	}
endif;

if ( ! function_exists( 'leatherhouse_entry_footer' ) ) :
	/**
	 * Prints HTML with meta information for the categories, tags and comments.
	 */
	function leatherhouse_entry_footer() {
		// Hide category and tag text for pages.
		if ( 'post' === get_post_type() ) {
			/* translators: used between list items, there is a space after the comma */
			$categories_list = get_the_category_list( esc_html__( ', ', 'leather-house' ) );
			if ( $categories_list && leatherhouse_categorized_blog() ) {
				printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'leather-house' ) . '</span>', $categories_list ); // WPCS: XSS OK.
			}

			/* translators: used between list items, there is a space after the comma */
			$tags_list = get_the_tag_list( '', esc_html__( ', ', 'leather-house' ) );
			if ( $tags_list ) {
				printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'leather-house' ) . '</span>', $tags_list ); // WPCS: XSS OK.
			}
		}

		if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
			echo '<span class="comments-link">';
			/* translators: %s: post title */
			comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'leather-house' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) );
			echo '</span>';
		}

		edit_post_link(
			sprintf(
			/* translators: %s: Name of current post */
				esc_html__( 'Edit %s', 'leather-house' ),
				the_title( '<span class="screen-reader-text">"', '"</span>', false )
			),
			'<span class="edit-link">',
			'</span>'
		);
	}
endif;

/**
 * Returns true if a blog has more than 1 category.
 *
 * @return bool
 */
function leatherhouse_categorized_blog() {
	if ( false === ( $all_the_cool_cats = get_transient( 'leatherhouse_categories' ) ) ) {
		// Create an array of all the categories that are attached to posts.
		$all_the_cool_cats = get_categories(
			array(
				'fields'     => 'ids',
				'hide_empty' => 1,
				// We only need to know if there is more than one category.
				'number'     => 2,
			)
		);

		// Count the number of categories that are attached to the posts.
		$all_the_cool_cats = count( $all_the_cool_cats );

		set_transient( 'leatherhouse_categories', $all_the_cool_cats );
	}

	if ( $all_the_cool_cats > 1 ) {
		// This blog has more than 1 category so leatherhouse_categorized_blog should return true.
		return true;
	} else {
		// This blog has only 1 category so leatherhouse_categorized_blog should return false.
		return false;
	}
}

/**
 * Flush out the transients used in leatherhouse_categorized_blog.
 */
function leatherhouse_category_transient_flusher() {
	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
		return;
	}
	// Like, beat it. Dig?
	delete_transient( 'leatherhouse_categories' );
}
add_action( 'edit_category', 'leatherhouse_category_transient_flusher' );
add_action( 'save_post', 'leatherhouse_category_transient_flusher' );

/**
 * Function that returns if the menu is sticky
 */
if ( ! function_exists( 'leatherhouse_sticky_menu' ) ) :
	function leatherhouse_sticky_menu() {
		$leatherhouse_menu_style = get_theme_mod( 'leatherhouse_menu_style', 'static' );

		if ( $leatherhouse_menu_style == 'sticky' ) :
			return 'sticky-nav ';
		else :
			return 'not-sticky';
		endif;
	}
endif;

/**
 * Function that returns if the menu is sticky
 */
if ( ! function_exists( 'leatherhouse_menu_size' ) ) :
	function leatherhouse_menu_size() {
		$leatherhouse_menu_container_size = get_theme_mod( 'leatherhouse_menu_container_size', 'container-full' );

		if ( $leatherhouse_menu_container_size == 'container-full' ) :
			return 'container-full';
		else :
			return 'av-container';
		endif;
	}
endif;


/**
 * Register Google fonts for leatherhouse.
 */
function leatherhouse_google_font() {

	$get_fonts_url = '';

	$font_families = array();

	$font_families = array( 'Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900' );

		$query_args = array(
			'family' => urlencode( implode( '|', $font_families ) ),
			'subset' => urlencode( 'latin,latin-ext' ),
		);

		$get_fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );

		return $get_fonts_url;
}

function leatherhouse_scripts_styles() {
	wp_enqueue_style( 'leatherhouse-fonts', leatherhouse_google_font(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'leatherhouse_scripts_styles' );


/**
 * Register Breadcrumb for Multiple Variation
 */
function leatherhouse_breadcrumbs_style() {
	get_template_part( './template-parts/sections/section', 'breadcrumb' );
}


/**
 * Archive Post: This Function Check whether Sidebar active or Not
 */
if ( ! function_exists( 'leatherhouse_post_layout' ) ) :
	function leatherhouse_post_layout() {
		$leatherhouse_archive_blog_pages_layout = get_theme_mod( 'leatherhouse_archive_blog_pages_layout', 'leatherhouse_right_sidebar' );
		if ( 'leatherhouse_no_sidebar' !== $leatherhouse_archive_blog_pages_layout && is_active_sidebar( 'leatherhouse-sidebar-primary' ) ) {
			echo 'av-column-8';
		} else {
			echo 'av-column-12 mx-auto';
		}
	} endif;

/**
 * Single Post: This Function Check whether Sidebar active or Not
 */
if ( ! function_exists( 'leatherhouse_single_post_layout' ) ) :
	function leatherhouse_single_post_layout() {
		$leatherhouse_single_blog_pages_layout = get_theme_mod( 'leatherhouse_single_blog_pages_layout', 'leatherhouse_right_sidebar' );
		if ( 'leatherhouse_no_sidebar' !== $leatherhouse_single_blog_pages_layout && is_active_sidebar( 'leatherhouse-sidebar-primary' ) ) {
			echo 'av-column-8';
		} else {
			echo 'av-column-12 mx-auto';
		}
	} endif;

/**
 * Template Post: This Function Check whether Sidebar active or Not
 */
if ( ! function_exists( 'leatherhouse_template_layout' ) ) :
	function leatherhouse_template_layout() {
		if ( is_active_sidebar( 'leatherhouse-sidebar-primary' ) ) {
			echo 'av-column-8';
		} else {
			echo 'av-column-12 mx-auto';
		}
	} endif;



if ( ! function_exists( 'leatherhouse_dynamic_style' ) ) :
	function leatherhouse_dynamic_style() {

		$output_css = '';

		/**
		 *  Breadcrumb Style
		 */
		$leatherhouse_breadcrumb_height = get_theme_mod( 'leatherhouse_breadcrumb_height', '450' );

		if ( $leatherhouse_breadcrumb_height !== '' ) {
				$output_css .= '.breadcrumb-content {
					min-height: ' . esc_attr( $leatherhouse_breadcrumb_height ) . "px;
				}\n";
		}

		// Theme check
		$activate_theme_data = wp_get_theme(); // getting current theme data.
		$activate_theme      = $activate_theme_data->name;
		if ( 'Leather House' == $activate_theme ) {	
			$leatherhouse_breadcrumb_bg_img      = get_theme_mod( 'leatherhouse_breadcrumb_bg_img', esc_url( get_template_directory_uri() . '/assets/images/breadcrumb/breadcrumb.webp' ) );
		} elseif ( 'Modern House' == $activate_theme ) { 
			$leatherhouse_breadcrumb_bg_img      = get_theme_mod( 'leatherhouse_breadcrumb_bg_img', esc_url( get_template_directory_uri() . '/assets/images/mh-slider.webp' ) );
		} elseif ( 'NewsCraft' == $activate_theme ) {
			$leatherhouse_breadcrumb_bg_img      = get_theme_mod( 'leatherhouse_breadcrumb_bg_img', esc_url( get_template_directory_uri() . '/assets/images/breadcrumb/ncs-breadcrumb.webp' ) );
		} else {
			$leatherhouse_breadcrumb_bg_img      = get_theme_mod( 'leatherhouse_breadcrumb_bg_img', esc_url( get_template_directory_uri() . '/assets/images/breadcrumb/breadcrumb.webp' ) );
		}

		$leatherhouse_breadcrumb_back_attach = get_theme_mod( 'leatherhouse_breadcrumb_back_attach', 'scroll' );

		if ( $leatherhouse_breadcrumb_bg_img !== '' ) {
			$output_css .= '.breadcrumb-area {
					background-image: url(' . esc_url( $leatherhouse_breadcrumb_bg_img ) . ');
					background-attachment: ' . esc_attr( $leatherhouse_breadcrumb_back_attach ) . ";
				}\n";
		} else {
			$output_css .= ".breadcrumb-area {
				 background: var(--sp-gradient2);
			}\n";
		}

		if ( 'Leather House' == $activate_theme ) {	
			$leatherhouse_footer_bg_img        = get_theme_mod( 'leatherhouse_footer_bg_img', esc_url( get_template_directory_uri() . '/assets/images/footer.webp' ) );
		} elseif ( 'Modern House' == $activate_theme ) { 
			$leatherhouse_footer_bg_img        = get_theme_mod( 'leatherhouse_footer_bg_img', esc_url( get_template_directory_uri() . '/assets/images/mh-footer.webp' ) );
		} else {
			$leatherhouse_footer_bg_img        = get_theme_mod( 'leatherhouse_footer_bg_img', esc_url( get_template_directory_uri() . '/assets/images/footer.webp' ) );
		}
		

		if ( ! empty( $leatherhouse_footer_bg_img ) ) :
			$output_css .= '.footer-section.footer-one{ 
				background: url(' . esc_url( $leatherhouse_footer_bg_img ) . ") rgba(0, 0, 0, 0.15);
				background-blend-mode: multiply;
				background-size: cover;
			}
			.footer-section.footer-one:after{
				content: '';
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				opacity: 0.75;
				background: #000000 none repeat scroll 0 0;
				z-index: -1;
			}\n";
		endif;

		$leatherhouse_page_header_background_color = get_theme_mod( 'leatherhouse_page_header_background_color', 'rgba(0,0,0,0.6)' );
		$output_css                        .= ".breadcrumb-area:before {
			background-color: $leatherhouse_page_header_background_color !important;
		}\n";

		/**
		 * Logo Width
		 */
		$leatherhouse_custom_logo_size = get_theme_mod(
			'leatherhouse_custom_logo_size',
			array(
				'slider' => 200,
				'suffix' => 'px',
			)
		);
		if ( $leatherhouse_custom_logo_size['slider'] != null ) {
			$output_css .= '.logo img, .mobile-logo img {
				max-width: ' . esc_attr( $leatherhouse_custom_logo_size['slider'] ) . "px;
			}\n";
		}

		/**
		 * Slider Overlay Settings
		 */
		$leatherhouse_hero_overlay_disable = get_theme_mod( 'leatherhouse_hero_overlay_disable', true );
		$leatherhouse_hero_overlay_color   = get_theme_mod( 'leatherhouse_hero_overlay_color', 'rgba(0,0,0,0.2)' );
		if ( true === $leatherhouse_hero_overlay_disable ) {
			$output_css .= ".theme-slider {
				background: $leatherhouse_hero_overlay_color;
			}\n";
		}

		/**
		 * Slider Meta Color Settings
		 */
		$leatherhouse_hero_text_color_disable = get_theme_mod( 'leatherhouse_hero_text_color_disable', false );
		if ( true === $leatherhouse_hero_text_color_disable ) {
			$leatherhouse_hero_caption_title_color            = get_theme_mod( 'leatherhouse_hero_caption_title_color', '#fff' );
			$leatherhouse_hero_caption_title_bg_color         = get_theme_mod( 'leatherhouse_hero_caption_title_bg_color', '#11104d' );
			$leatherhouse_hero_caption_subtitle_title_color   = get_theme_mod( 'leatherhouse_hero_caption_subtitle_title_color', '#fff' );
			$leatherhouse_hero_caption_subtitle2_title_color  = get_theme_mod( 'leatherhouse_hero_caption_subtitle2_title_color', '#d81956' );
			$leatherhouse_hero_caption_descrption_title_color = get_theme_mod( 'leatherhouse_hero_caption_descrption_title_color', '#fff' );

			$output_css .= ".theme-slider .theme-content h1 {
				color: $leatherhouse_hero_caption_subtitle_title_color;
			}
			.theme-slider .theme-content h1 .primary-color {
				background: $leatherhouse_hero_caption_subtitle2_title_color;
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
				text-decoration: none;
			}
			.theme-slider .theme-content p {
				color: $leatherhouse_hero_caption_descrption_title_color;
			}\n";
		}

		/**
		 * Slider Text Bg overlay Color CSS
		 */
		$leatherhouse_hero_text_overlay_disable = get_theme_mod( 'leatherhouse_hero_text_overlay_disable', false );
		$leatherhouse_hero_text_overlay_color   = get_theme_mod( 'leatherhouse_hero_text_overlay_color', false );
		if ( true === $leatherhouse_hero_text_overlay_disable ) {
			$output_css .= ".theme-slider div.text-overlay {
				background: $leatherhouse_hero_text_overlay_color;
			}\n";
		}

		/**
		 * About Bg Image Settings
		 */
		$leatherhouse_about_background = get_theme_mod( 'leatherhouse_about_background' );
		if ( ! empty( $leatherhouse_about_background ) ) :
			$output_css .= '.about-section {
				background: url(' . esc_url( $leatherhouse_about_background ) . ") no-repeat scroll center center / cover rgba(0, 0, 0, 0.75);
				background-blend-mode: multiply;
			}\n";
		endif;

		/**
		 * Service Bg Image Settings
		 */
		$leatherhouse_service_background = get_theme_mod( 'leatherhouse_service_background' );
		if ( ! empty( $leatherhouse_service_background ) ) :
			$output_css .= '.service-section {
				background: url(' . esc_url( $leatherhouse_service_background ) . ") no-repeat scroll center center / cover rgba(0, 0, 0, 0.75);
				background-blend-mode: multiply;
			}\n";
		endif;

		/**
		 * Cta Bg Image Settings
		 */
		$leatherhouse_cta_background_image = get_theme_mod( 'leatherhouse_cta_background_image', get_template_directory_uri() . '/assets/images/callout-img.webp' );
		if ( ! empty( $leatherhouse_cta_background_image ) ) :
			$output_css .= '.cta-section {
				background: url(' . esc_url( $leatherhouse_cta_background_image ) . ") no-repeat scroll center center / cover;
				background-blend-mode: normal;
			}\n";
		endif;

		/**
		* Funfact Bg Image Settings
		*/
		$leatherhouse_funfact_background = get_theme_mod( 'leatherhouse_funfact_background', get_template_directory_uri() . '/assets/images/funfact-img.webp' );
		if ( ! empty( $leatherhouse_funfact_background ) ) :
			$output_css .= '.funfact-section {
				background: url(' . esc_url( $leatherhouse_funfact_background ) . ") no-repeat scroll center center / cover rgba(0, 0, 0, 0.75);
				background-blend-mode: multiply;
			}\n";
		endif;


		/**
		 *  Menu-header-3 Custom CSS For Container-full setting
		 */

		$leatherhouse_menu_container_size = get_theme_mod( 'leatherhouse_menu_container_size', 'container-full' );
		if ( 'container-full' === $leatherhouse_menu_container_size ) {
			$output_css .= '@media (min-width: 992px) {
				 .header.header-three {
					 max-width: 95.15%;
					 top: 45px;
				 }
			 }' . "\n";
		}

		/**
		 *  Parallax
		 */
		/*
		$footer_parallax_enable = get_theme_mod( 'footer_parallax_enable', '1' );
		$footer_parallax_margin = get_theme_mod( 'footer_parallax_margin', '775' );

		if ( $footer_parallax_enable == '1' ) :
			$output_css .= '@media (min-width: 992px){.footer-parallax .leatherhouse-content {
					margin-bottom: ' . esc_attr( $footer_parallax_margin ) . "px;
			}}\n";
		endif; */

		/* Css For Menu Design 2*/
		$leatherhouse_menu_design_layout = get_theme_mod( 'leatherhouse_menu_design_layout', 'menu-layout1' );
		if ( 'menu-layout1' !== $leatherhouse_menu_design_layout ) {
			$output_css .= '.breadcrumb-content {
				margin-top: 150px;
			}
			@media (max-width: 992px) {
				.breadcrumb-content {
					margin-top: 0px;
				}
			}' . "\n";
		}

		if ( is_admin() ) {
			$output_css .= 'body {
				margin-top: 32px;
			}\n';
		}

		wp_add_inline_style( 'leatherhouse-style', $output_css );
	}
endif;
add_action( 'wp_enqueue_scripts', 'leatherhouse_dynamic_style' );


/**
 * Admin notice
 */
class leatherhouse_screen {
	public function __construct() {
		/* notice  Lines*/
		add_action( 'switch_theme', array( $this, 'flush_dismiss_status' ) );
		add_action( 'admin_init', array( $this, 'getting_started_notice_dismissed' ) );
		add_action( 'load-themes.php', array( $this, 'leatherhouse_activation_admin_notice' ) );
	}
	public function leatherhouse_activation_admin_notice() {
		global $pagenow;

		if ( is_admin() && ( 'themes.php' == $pagenow ) ) {
            add_action( 'admin_notices', array( $this, 'leatherhouse_admin_notice' ), 99 );
        }
	}
	/**
	 * Display an admin notice linking to the welcome screen
	 *
	 * @sfunctionse 1.8.2.4
	 */
	public function leatherhouse_admin_notice() {
		if ( is_admin() && ! get_user_meta( get_current_user_id(), 'gs_notice_dismissed' ) ){ ?>
			<div class="updated notice notice-get-started-class is-dismissible" data-notice="get_started">
					<?php
						echo '<div><a href="' . esc_url( wp_nonce_url( add_query_arg( 'gs-notice-dismissed', 'dismiss_admin_notices' ) ) ) . '" class="getting-started-notice-dismiss"> Dismiss this notice </a></div>';
					?>
					<div class="leatherhouse-getting-started-notice clearfix">
						<div class="leatherhouse-theme-screenshot">
							<img src="<?php echo esc_url( get_stylesheet_directory_uri() ); ?>/screenshot.webp" class="screenshot" alt="<?php esc_attr_e( 'Theme Screenshot', 'leather-house' ); ?>" />
						</div><!-- /.leatherhouse-theme-screenshot -->
						<div class="leatherhouse-theme-notice-content">
							<h2 class="leatherhouse-notice-h2">
								<?php
								printf(
								/* translators: 1: welcome page link starting html tag, 2: welcome page link ending html tag. */
									esc_html__( 'Welcome to %1$s Free Theme! 🎉', 'leather-house' ),
									'<strong>' . wp_get_theme()->get( 'Name' ) . '</strong>'
								);
								?>
							</h2>

							<p class="plugin-install-notice">
								<?php 
									printf( 
										__( 'Thank you for choosing <b>%s</b> – a stylish, lightweight, and fully responsive theme designed for elegance and performance. Whether you\'re creating a blog, portfolio, or business website, this theme provides a clean and modern design to showcase your content beautifully.', 'leather-house' ),
										wp_get_theme()->get( 'Name' ) 
									); 
								?>
							</p>


							<a class="leatherhouse-btn-get-started button button-primary button-hero leatherhouse-button-padding" href="#" data-name="" data-slug="">
							<?php
							printf(
							/* translators: 1: welcome page link starting html tag, 2: welcome page link ending html tag. */
								esc_html__( 'Get started with %1$s', 'leather-house' ),
								'<strong>' . wp_get_theme()->get( 'Name' ) . '</strong>'
							);
							?>

							</a><!--<span class="leatherhouse-push-down">
							<?php
								/* translators: %1$s: Anchor link start %2$s: Anchor link end */
								printf(
									'or %1$sCustomize theme%2$s</a></span>',
									'<a target="_blank" href="' . esc_url( admin_url( 'customize.php' ) ) . '">',
									'</a>'
								);
							?>-->
						</div><!-- /.leatherhouse-theme-notice-content -->
					</div>
				</div>
			<?php
		}
	}

	/**
	 * Register dismissal of the getting started notification.
	 * Acts on the dismiss link.
	 * If clicked, the admin notice disappears and will no longer be visible to this user.
	 */
	public function getting_started_notice_dismissed() {

		if ( isset( $_GET['gs-notice-dismissed'] ) ) {
			add_user_meta( get_current_user_id(), 'gs_notice_dismissed', 'true' );
		}
	}

	/**
	 * Deletes the getting started notice's dismiss status upon theme switch.
	 */
	public function flush_dismiss_status() {
		delete_user_meta( get_current_user_id(), 'gs_notice_dismissed', 'true' );
	}

}
$GLOBALS['leatherhouse_screen'] = new leatherhouse_screen();

/**
* Plugin installer
*/

add_action( 'wp_ajax_install_act_plugin', 'leatherhouse_admin_install_plugin' );

function leatherhouse_admin_install_plugin() {
	/**
	 * Install Plugin.
	 */
	include_once ABSPATH . '/wp-admin/includes/file.php';
	include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
	include_once ABSPATH . 'wp-admin/includes/plugin-install.php';

	if ( ! file_exists( WP_PLUGIN_DIR . '/one-click-demo-import' ) ) {
		$api = plugins_api(
			'plugin_information',
			array(
				'slug'   => sanitize_key( wp_unslash( 'one-click-demo-import' ) ),
				'fields' => array(
					'sections' => false,
				),
			)
		);

		$skin     = new WP_Ajax_Upgrader_Skin();
		$upgrader = new Plugin_Upgrader( $skin );
		$result   = $upgrader->install( $api->download_link );
	}

	// Activate plugin.
	if ( current_user_can( 'activate_plugin' ) ) {
		$result = activate_plugin( 'one-click-demo-import/one-click-demo-import.php' );
	}
}
