<?php

/**
 *  Inspirelite - Schema
 */

/**
 * Schema for <body> tag.
 */
if ( ! function_exists( 'inspirelite_schema_body' ) ) :

	/**
	 * Adds schema tags to the body classes.
	 *
	 * @since 1.0.0
	 */
	function inspirelite_schema_body() {

		// Check conditions.
		$is_blog = ( is_home() || is_archive() || is_attachment() || is_tax() || is_single() ) ? true : false;

		// Set up default itemtype.
		$itemtype = 'WebPage';

		// Get itemtype for the blog.
		$itemtype = ( $is_blog ) ? 'Blog' : $itemtype;

		// Get itemtype for search results.
		$itemtype = ( is_search() ) ? 'SearchResultsPage' : $itemtype;

		// Get the result.
		$result = apply_filters( 'inspirelite_schema_body_itemtype', $itemtype );

		// Return our HTML.
		echo apply_filters( 'inspirelite_schema_body', " itemtype='https://schema.org/" . esc_attr( $result ) . "' itemscope='itemscope' " );
	}
endif;

/**
 *  Header Markup
 */
if( ! function_exists( 'inspirelite_head_markup' ) ){

	/**
	 * [inspirelite_head_markup description]
	 * @return [header_meta] [get header meta]
	 */
	function inspirelite_head_markup(){

		?>

		<meta charset="<?php bloginfo( 'charset' ); ?>">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="profile" href="http://gmpg.org/xfn/11">

		<?php

		/**
		 * Add a pingback url auto-discovery header for singularly identifiable articles.
		 */
		if ( is_singular() && pings_open() ) {
			
			printf( '<link rel="pingback" href="%s">' . "\n", esc_url( get_bloginfo( 'pingback_url' ) ) );
		}
	}

	add_action( 'inspirelite_head', 'inspirelite_head_markup' );
}


/**
 * Adds custom classes to the array of body classes.
 */
if ( ! function_exists( 'inspirelite_body_classes' ) ) {

	/**
	 * Adds custom classes to the array of body classes.
	 *
	 * @since 1.0.0
	 * @param array $classes Classes for the body element.
	 * @return array
	 */
	function inspirelite_body_classes( $classes ) {

		/**
		 * Is mobile or desktop
		 */
		if ( function_exists( 'wp_get_theme' ) ) {

			$classes[] = esc_html( wp_get_theme() );
		}

		/**
		 * Is mobile or desktop
		 */
		if ( wp_is_mobile() ) {

			$classes[] = sanitize_html_class( 'inspirelite-mobile' );

		} else {

			$classes[] = sanitize_html_class( 'inspirelite-desktop' );
		}

		// Adds a class of hfeed to non-singular pages.
		if ( ! is_singular() ) {
			$classes[] = sanitize_html_class( 'hfeed' );
		}

		// Adds a class of no-sidebar when there is no sidebar present.
		if ( ! is_active_sidebar( 'sidebar-1' ) ) {
			$classes[] = sanitize_html_class( 'no-sidebar' );
		}

		// Current Inspirelite verion.
		$classes[] = esc_attr( 'inspirelite-' . INSPIRELITE_VERSION );

	   if( is_rtl() ){
	   	
	   		$classes[] = sanitize_html_class('easetemplate-rtl');
	   }

	   	if( class_exists( 'WooCommerce' ) ){

	   		$classes[] = sanitize_html_class('easetemplate-woocommerce');
	   	}

	   	/**
	   	 * Debug is on
	   	 */
	   	if( INSPIRELITE_DEV_ON ){

	   		$classes[] = sanitize_html_class('inspirelite-debug-on');
	   	}

		return $classes;
	}

	add_filter( 'body_class', 'inspirelite_body_classes' );
}

if( ! function_exists( 'inspirelite_body_markup' ) ){

	/**
	 * [get number of resource in body tag]
	 * @return [return] [schema, body class, style of page]
	 */
	function inspirelite_body_markup(){

		/**
		 *  Body Schema Included
		 */
		inspirelite_schema_body();

		/**
		 *  Number of body class
		 */
		body_class();
	}

	add_action( 'inspirelite_body', 'inspirelite_body_markup' );
}