
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

/* -----------------------------------------------------------------------------
 * Add Schema.org
 * -------------------------------------------------------------------------- */

add_action( 'after_setup_theme', 'presso_setup_schema_org' );
if ( ! function_exists( 'presso_setup_schema_org' ) ) {
	function presso_setup_schema_org() {
		if ( ! defined( 'PRESSO_CONST_DISABLE_SCHEMA_ORG' ) ) {
			add_filter( 'wp_get_attachment_image_attributes', 'presso_add_image_itemprop' );

			add_action( 'presso_action_post_schema', 'presso_itemprop_meta_post_date' );
			add_action( 'presso_action_post_schema', 'presso_itemprop_meta_author' );
			add_action( 'presso_action_post_schema', 'presso_itemprop_meta_comment_count' );
			add_action( 'presso_action_post_schema', 'presso_add_publisher_schema' );
			add_action( 'presso_action_post_schema', 'presso_add_main_entity_schema' );
		}
	}
}

if ( ! function_exists( 'presso_add_image_itemprop' ) ) {
	function presso_add_image_itemprop( $attr ) {
		$attr['itemprop'] = 'image';
		return $attr;
	}
}

if ( ! function_exists( 'presso_add_main_entity_schema' ) ) {
	function presso_add_main_entity_schema( $scope='') {
		if ( 'main-post' == $scope ) {
			?>
			<meta content="" itemscope itemprop="mainEntityOfPage"  itemType="https://schema.org/WebPage" itemid="<?php echo esc_url( get_permalink() ); ?>"/>
			<?php
		}
	}
}

if ( ! function_exists( 'presso_add_publisher_schema' ) ) {
	function presso_add_publisher_schema() {
		?>
		<div itemprop="publisher" itemscope itemtype="https://schema.org/Organization">
			<?php $logo = presso_get_theme_option( 'logo' ); ?>
			<?php if ( ! empty( $logo ) ) : ?>
			<div itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">
				<meta itemprop="url" content="<?php echo esc_url( $logo[ 'url' ] ); ?>">
				<meta itemprop="width" content="<?php echo esc_attr( $logo[ 'width' ] ) ?>">
				<meta itemprop="height" content="<?php echo esc_attr( $logo[ 'height' ] ) ?>">
			</div>
			<?php endif; ?>
			<meta itemprop="name" content="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
		</div>
		<?php
	}
}


/* -----------------------------------------------------------------------------
 * Template Tags
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_html_tag_schema' ) ) {
	function presso_html_tag_schema() {
		// Is single post
		if( is_single() ) {
			presso_itemtype( 'Article' );
		}

		// Is author page
		elseif( is_author() ) {
			presso_itemtype( 'ProfilePage' );
		}

		// Is search results page
		elseif( is_search() ) {
			presso_itemtype( 'SearchResultsPage' );
		}

		// Is archive
		elseif( is_archive() ) {
			presso_itemtype( 'CollectionPage' );
		}

		else {
			presso_itemtype( 'WebPage' );
		}

	}
}

if ( ! function_exists( 'presso_itemprop_meta_post_date' ) ) {
	function presso_itemprop_meta_post_date() {
		presso_itemprop_meta( 'datePublished', get_the_time('c') );
		presso_itemprop_meta( 'dateModified', get_the_modified_time('c') );
	}
}

if ( ! function_exists( 'presso_itemprop_meta_image' ) ) {
	function presso_itemprop_meta_image() {
		presso_itemprop_meta( 'image', presso_get_featured_image_url( 'full' ) );
	}
}

if ( ! function_exists( 'presso_itemprop_meta_comment_count' ) ) {
	function presso_itemprop_meta_comment_count() {
		presso_itemprop_meta( 'interactionCount', sprintf( 'UserComments:%s', get_comments_number() ) );
	}
}

if ( ! function_exists( 'presso_itemprop_meta_author' ) ) {
	function presso_itemprop_meta_author() {
		presso_itemprop_meta( 'author', get_the_author_meta( 'display_name' ) );
	}
}


/* -----------------------------------------------------------------------------
 * Schema Functions
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_itemtype' ) ) {
	function presso_itemtype( $type ) {
		if ( empty( $type ) ) return;
		
		if ( ! defined( 'PRESSO_CONST_DISABLE_SCHEMA_ORG' ) ) {
			echo ' itemscope itemtype="'.esc_url( 'https://schema.org/'.$type ).'" ';
		}
	}
}

if ( ! function_exists( 'presso_itemprop' ) ) {
	function presso_itemprop( $prop ) {
		if ( empty( $prop ) ) return;
		
		if ( ! defined( 'PRESSO_CONST_DISABLE_SCHEMA_ORG' ) ) {
			echo ' itemprop="'.esc_attr( $prop ).'" ';
		}
	}
}

if ( ! function_exists( 'presso_itemprop_meta' ) ) {
	function presso_itemprop_meta( $prop, $content ) {
		if ( empty( $prop ) ) return;
		
		if ( ! defined( 'PRESSO_CONST_DISABLE_SCHEMA_ORG' ) ) {
			printf( '<meta itemprop="%s" content="%s"/>', esc_attr( $prop ), esc_attr( $content ) );
		}
	}
}

if ( ! function_exists( 'presso_get_itemtype' ) ) {
	function presso_get_itemtype( $type ) {
		if ( empty( $type ) ) return;
		
		if ( ! defined( 'PRESSO_CONST_DISABLE_SCHEMA_ORG' ) ) {
			return ' itemscope itemtype="'.esc_url( 'https://schema.org/'.$type ).'" ';
		}
	}
}

if ( ! function_exists( 'presso_get_itemprop' ) ) {
	function presso_get_itemprop( $prop ) {
		if ( empty( $prop ) ) return;
		
		if ( ! defined( 'PRESSO_CONST_DISABLE_SCHEMA_ORG' ) ) {
			return ' itemprop="'.esc_attr( $prop ).'" ';
		}
	}
}