
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

/* -----------------------------------------------------------------------------
 * Get Post Layout
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_get_post_layout' ) ) {
	function presso_get_post_layout() {
		global $post;
		$post_layout = '';
		
		if ( isset( $post->ID ) ) {
			$post_layout = get_post_meta( $post->ID, 'vw_post_layout', true );
		}

		if ( 'default' == $post_layout || empty( $post_layout ) ) {
			$post_layout = presso_get_theme_option( 'post_default_layout' );
		}

		return $post_layout;
	}
}


//******DEPRECATED
// if ( ! function_exists( 'presso_the_post_box_class' ) ) {
// 	function presso_the_post_box_class( $addition_class='' ) {
// 		$classes = array();

// 		if ( ! empty( $addition_class ) ) {
// 			$classes[] = $addition_class;
// 		}

// 		$format = get_post_format();
// 		if ( empty( $format ) ) $format = 'standard';

// 		$classes[] = sprintf( 'vw-post-format-%s', $format );
		
// 		echo esc_attr( implode( ' ', apply_filters( 'presso_filter_post_box_class' , $classes ) ) );
// 	}
// }


/* -----------------------------------------------------------------------------
 * The post format class
 * -------------------------------------------------------------------------- */

//******DEPRECATED
// if ( ! function_exists( 'presso_the_post_format_class' ) ) {
// 	function presso_the_post_format_class() {
// 		$format = get_post_format();
// 		if ( empty( $format ) ) $format = 'standard';

// 		$classes = sprintf( 'vw-post-format-%s', $format );
		
// 		echo esc_attr( $classes );
// 	}
// }

if ( ! function_exists( 'presso_the_post_format_icon' ) ) {
	function presso_the_post_format_icon() {
		$format = get_post_format();
		if ( empty( $format ) ) return;

		$icon = '';

		switch ( $format ) {
			case 'gallery':
				$icon = 'icon-entypo-picture';
				break;

			case 'video':
				$icon = 'icon-entypo-play';
				break;

			case 'audio':
				$icon = 'icon-entypo-note-beamed';
				break;
		}

		printf( '<span class="vw-post-box__format-icon"><i class="vw-icon %s"></i></span>', $icon );
	}
}


/* -----------------------------------------------------------------------------
 * The Title Attribute
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_title_attribute' ) ) {
	function presso_the_title_attribute() {
		printf( esc_attr__('Permalink to %s', 'presso'), the_title_attribute('echo=0') );
	}
}


/* -----------------------------------------------------------------------------
 * The Tagline
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_tagline' ) ) {
	function presso_the_tagline( $classes='', $id = '' ) {
		if ( empty( $id ) ) {
			$id = get_the_id();
		}

		$tagline = get_post_meta( $id, 'vw_tagline', true );

		if ( ! empty( $tagline ) ) {
			?>
			<div class="vw-tagline <?php echo esc_attr( $classes ); ?>"><span><?php echo do_shortcode( wp_kses_post( $tagline ) ); ?></span></div>
			<?php
		}
	}
}


/* -----------------------------------------------------------------------------
 * The category class
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_get_the_category_class' ) ) {
	function presso_get_the_category_class( $cat_ID = '' ) {
		if ( empty( $cat_ID ) ) {
			$cat_ID = presso_get_single_cat_id();
		}

		return esc_attr( sprintf( 'vw-cat-id-%s', $cat_ID ) );
	}
}

if ( ! function_exists( 'presso_the_category_class' ) ) {
	function presso_the_category_class( $cat_ID = '' ) {
		echo presso_get_the_category_class( $cat_ID );
	}
}


/* -----------------------------------------------------------------------------
 * The category links
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_category' ) ) {
	function presso_the_category( $classes='' ) {
		if ( 'product' == get_post_type() ) {
			$categories = get_the_terms( get_the_id(), 'product_cat' );

		} else {
			$categories = get_the_category();

		}

		if( $categories ){
			echo '<div class="vw-categories">';

			if ( is_sticky() ) {
				echo '<a class="vw-sticky-label">'.esc_html__( 'Sticky', 'presso' ).'</a>';
			}

			if ( presso_has_review() ) {
				echo '<a class="vw-review-label"><i class="vw-icon icon-entypo-star"></i>'.presso_get_average_score_text().'</a>';
			}

			if ( has_post_format( 'video' ) ) {
				echo '<a class="vw-video-link" href="'.esc_url( get_post_format_link( 'video' ) ).'"><i class="vw-icon icon-entypo-play"></i></a>';

			} elseif ( has_post_format( 'audio' ) ) {
				echo '<a class="vw-audio-link" href="'.esc_url( get_post_format_link( 'audio' ) ).'"><i class="vw-icon icon-entypo-note-beamed"></i></a>';

			} elseif ( has_post_format( 'gallery' ) ) {
				echo '<a class="vw-gallery-link" href="'.esc_url( get_post_format_link( 'gallery' ) ).'"><i class="vw-icon icon-entypo-picture"></i></a>';

			}

			foreach( $categories as $category ) {

				$classes .= ' '.presso_get_the_category_class( $category->term_id );
				echo '<a class="'.esc_attr( $classes ).'" href="'.esc_url( get_category_link( $category->term_id ) ).'" title="' . esc_attr( sprintf( esc_html__( 'View all posts in %s', 'presso' ), $category->name ) ) . '" rel="category">'.wp_strip_all_tags( $category->name ).'</a>';
			}
			echo '</div>';
		}
	}
}

if ( ! function_exists( 'presso_get_categories_attributes' ) ) {
	function presso_get_categories_attributes() {
		$list = array();

		// Get a category list
		$post_type = get_post_type( get_the_id() );

		if ( 'presso_portfolio' == $post_type ) {
			$categories = get_the_terms( get_the_id(), 'presso_portfolio_cat' );
			
		} else if ( 'presso_gallery' == $post_type ) {
			$categories = get_the_terms( get_the_id(), 'presso_gallery_cat' );

		} else {
			$categories = get_the_category();

		}

		// Build a list
		if ( ! empty( $categories ) ) {
			foreach( $categories as $category ) {
				$list[] = $category->slug;
			}
		}

		return implode( ' ', $list );
	}
}


if ( ! function_exists( 'presso_the_category_filter' ) ) {
	function presso_the_category_filter( $categories ) {

		if ( ! empty( $categories ) ) {

			echo '<div class="vw-category-filter">';
			
			echo ' <a href="#" class="vw-category-filter__item vw-button" data-slug="all">'.esc_html__( 'All', 'presso' ).'</a>';

			foreach( $categories as $category ) {
				echo ' <a href="#" class="vw-category-filter__item vw-button vw-button--white" data-slug="'.esc_attr( $category->slug ).'">'.$category->name.'</a>';
			}

			echo '</div>';
		}
	}
}




/* -----------------------------------------------------------------------------
 * The Post Meta Separator
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_post_meta_separator' ) ) {
	function presso_the_post_meta_separator() {
		?><span class="vw-post-meta__separator">&bull;</span><?php
	}
}


/* -----------------------------------------------------------------------------
 * The Post Date
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_post_date' ) ) {
	function presso_the_post_date() {
		?><a href="<?php the_permalink(); ?>" class="vw-post-date updated" title="<?php presso_the_title_attribute(); ?>" rel="bookmark"><time <?php presso_itemprop('datePublished'); ?> datetime="<?php echo esc_attr( get_the_time('c') ); ?>"><?php echo get_the_date(); ?></time></a><?php
	}
}

if ( ! function_exists( 'presso_the_post_date_text' ) ) {
	function presso_the_post_date_text() {
		?><span class="vw-post-date updated"><time <?php presso_itemprop('datePublished'); ?> datetime="<?php echo esc_attr( get_the_time('c') ); ?>"><?php echo get_the_date(); ?></time></span><?php
	}
}


/* -----------------------------------------------------------------------------
 * The Comment Link
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_comment_link' ) ) {
	function presso_the_comment_link() {
		if ( comments_open() ) : 
		?>
		<a class="vw-post-comment-count" href="<?php echo esc_url( get_comments_link() ); ?>" title="<?php echo esc_attr__( 'Comments', 'presso' ); ?>">
			<i class="vw-icon icon-entypo-comment"></i>
			<?php echo esc_html( get_comments_number() ); ?>
		</a>
		<?php
		
		presso_itemprop_meta_comment_count();

		endif;
	}
}





/* -----------------------------------------------------------------------------
 * The Featured Image
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_featured_image' ) ) {
	function presso_the_featured_image( $thumbnail_size = 'presso_thumbnail_full_width' ) {

		if ( has_post_thumbnail() || is_attachment() ) {
			
			$featured_image_id = presso_get_featured_image_id();
			$attachment = get_post( $featured_image_id );
			
			if ( empty( $featured_image_id ) || empty( $attachment ) ) return;

			$full_image_url = wp_get_attachment_image_src( $featured_image_id, 'full' );
			$image_caption = $attachment->post_excerpt;
			$has_caption = ! empty( $image_caption );

			if ( $has_caption ) {
				$figure_classes = 'wp-caption';

			} else {
				$figure_classes = '';
				$image_caption = get_the_title();
			}

			?>
			<figure class="vw-post-media vw-post-media--featured <?php echo esc_attr( $figure_classes ); ?>" <?php presso_itemprop( 'image' ); presso_itemtype( 'ImageObject' ); ?>>

				<a class="" href="<?php echo esc_url( $full_image_url[0] ); ?>" title="<?php echo esc_attr( $image_caption ); ?>" rel="bookmark" <?php presso_itemprop( 'image' ); ?>>
					<?php echo wp_get_attachment_image( $featured_image_id, $thumbnail_size, false, array( 'class' => "attachment-{$thumbnail_size} wp-post-image", 'itemprop'=>'thumbnail' ) ); ?>
				</a>

				<?php if ( $has_caption ) : ?>
					<figcaption class="vw-floating-caption" <?php presso_itemprop( 'caption' ); ?>>
						<span><?php echo wp_kses_data( $image_caption ); ?></span>
					</figcaption>
				<?php endif; ?>

			</figure>
			<?php
		}
	}
}

if ( ! function_exists( 'presso_get_featured_image_id' ) ) {
	function presso_get_featured_image_id( $post_id = '' ) {
		global $post;
		if ( empty( $post_id ) ) {
			$post_id = $post->ID;
		}

		if ( 'attachment' == get_post_type( $post_id ) ) {
			return $post_id;

		} else {
			return get_post_thumbnail_id( $post_id );

		}
	}
}

if ( ! function_exists( 'presso_get_featured_image_url' ) ) {
	function presso_get_featured_image_url( $size='presso_two_third_thumbnail', $post_id = '' ) {
		$featured_image_id = presso_get_featured_image_id( $post_id );

		$image_src = wp_get_attachment_image_src( $featured_image_id, $size );

		if ( ! empty( $image_src ) ) {
			return $image_src[0];
		} else {
			return '';
		}
	}
}

if ( ! function_exists( 'presso_the_fixed_post_thumbnail' ) ) {
	function presso_the_fixed_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) {
		presso_srcset_disable();
		the_post_thumbnail( $size, $attr );
		presso_srcset_enable();
	}
}




/* -----------------------------------------------------------------------------
 * The Post Media
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_post_media' ) ) {
	function presso_the_post_media( $formats=array( 'video', 'audio', 'gallery' ) ) {
		$format = get_post_format();
		$can_display = false;

		if ( in_array( 'gallery', $formats ) && 'gallery' == $format ) {
			$can_display = presso_the_post_gallery();
			
		} elseif ( in_array( 'video', $formats ) && 'video' == $format ) {
			$can_display = presso_the_post_video();

		} elseif ( in_array( 'audio', $formats ) && 'audio' == $format ) {
			$can_display = presso_the_post_audio();
			
		}

		if ( $format === false || ! $can_display ) {
			presso_the_featured_image();
		}
	}
}

if ( ! function_exists( 'presso_the_post_gallery' ) ) {
	function presso_the_post_gallery( $attachments='', $layout = '', $class = '' ) {
		if ( empty( $attachments ) ) {
			// Load gallery from post meta instead
			$attachments = get_post_meta( get_the_ID(), 'vw_gallery_images', true );
			$layout = get_post_meta( get_the_ID(), 'vw_gallery_layout', true );
		}

		// Exit when no attachment
		if ( empty( $attachments ) ) {
			return;
		}

		// Default layout
		if ( empty( $layout ) ) {
			$layout = 'slider';
		}

		// If has value but not an array
		if ( ! is_array( $attachments ) ) {
			$attachments = array( $attachments );
		}

		// Additional class
		$additional_class = array( $class );
		$additional_class[] = 'vw-gallery--'.$layout;

		// Gallery settings
		set_query_var( 'gallery_photos', $attachments );
		set_query_var( 'gallery_layout', $layout );
		set_query_var( 'gallery_class', $additional_class );

		// Load template
		if ( 0 === strpos( $layout, 'grid') ) {
			get_template_part( 'templates/gallery/grid', str_replace( 'grid-', '', $layout ) );
		} else {
			get_template_part( 'templates/gallery/'.$layout );
		}

		// Can display media
		return true;
	}
}


/*//////////////////////////////////////
// Post Video
//////////////////////////////////////*/

if ( ! function_exists( 'presso_get_post_video_url' ) ) {
	function presso_get_post_video_url() {
		return get_post_meta( get_the_ID(), 'vw_video_oembed_url', true );
	}
}

if ( ! function_exists( 'presso_the_post_video' ) ) {
	function presso_the_post_video( $class='' ) {
		$video_oembed_url = presso_get_post_video_url();

		if ( ! empty( $video_oembed_url ) ) {

			echo '<div class="vw-post-media vw-post-media--video">';
			echo wp_oembed_get( $video_oembed_url );
			echo '</div>';

			// Can display media
			return true;

		}
	}
}



/*//////////////////////////////////////
// Post Audio
//////////////////////////////////////*/

if ( ! function_exists( 'presso_get_post_audio_url' ) ) {
	function presso_get_post_audio_url() {
		return get_post_meta( get_the_ID(), 'vw_audio_oembed_url', true );
	}
}

if ( ! function_exists( 'presso_the_post_audio' ) ) {
	function presso_the_post_audio() {
		$audio_oembed_url = presso_get_post_audio_url();
		
		if ( ! empty( $audio_oembed_url ) ) {

			echo '<div class="vw-post-media vw-post-media--audio">';
			echo wp_oembed_get( $audio_oembed_url );
			echo '</div>';

			// Can display media
			return true;

		}
	}
}





/* -----------------------------------------------------------------------------
 * Post Location
 * -------------------------------------------------------------------------- */

if ( ! function_exists( 'presso_the_location_link' ) ) {
	function presso_the_location_link( $id = '', $layout = '' ) {
		if ( empty( $id ) ) {
			$id = get_the_id();
		}

		$label = get_post_meta( $id, 'vw_location_label', true );
		$map = get_post_meta( $id, 'vw_location_map', true );

		if ( empty( $label ) && empty( $map ) ) return;

		if ( empty( $label ) ) {
			$label = $map[ 'address' ];
		}

		if ( $layout == 'icon' ) {

			if ( ! empty( $map ) ) {
				$url = sprintf( 'https://maps.google.com/maps?q=%s,%s', $map['lat'], $map['lng'] );
				printf( '<a class="vw-location" href="%s" target="_blank" original-title="%s"><i class="vw-location__icon vw-icon icon-entypo-location"></i></a>', esc_attr( $url ), wp_strip_all_tags( $label ) );
			} else {
				printf( '<span class="vw-location" original-title="%s"><i class="vw-location__icon vw-icon icon-entypo-location"></i></span>', wp_strip_all_tags( $label ) );
			}

		} else {
			?>
			<span class="vw-location" original-title="<?php echo esc_attr( wp_strip_all_tags( $label ) ); ?>">
				<i class="vw-location__icon vw-icon icon-entypo-location"></i>
				<?php
				if ( ! empty( $map ) ) {
					$url = sprintf( 'https://maps.google.com/maps?q=%s,%s', $map['lat'], $map['lng'] );
					printf( '<a class="vw-location__title" href="%s" target="_blank">%s</a>', esc_attr( $url ), wp_strip_all_tags( $label ) );
				} else {
					printf( '<span class="vw-location__title">%s</span>', wp_strip_all_tags( $label ) );
				}
				?>
			</span>
			<?php
		}
	}
}

if ( ! function_exists( 'presso_has_location' ) ) {
	function presso_has_location() {
		$location = get_post_meta( get_the_id(), 'vw_post_location_label', true );
		return ! empty( $location );
	}
}





/* -----------------------------------------------------------------------------
 * Post pagination (from wp_link_pages)
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_the_link_pages' ) ) {
	function presso_the_link_pages() {
		wp_link_pages( array(
			'before'      => '<div class="vw-page-links"><span class="vw-page-links__title">' . esc_html__( 'Pages:', 'presso' ) . '</span>',
			'after'       => '</div>',
			'link_before' => '<span class="vw-page-links__link">',
			'link_after'  => '</span>',
			'separator'   => '',
		) );
	}
}





/* -----------------------------------------------------------------------------
 * Render Post Footer Sections
 * -------------------------------------------------------------------------- */

if ( ! function_exists( 'presso_the_post_footer_sections' ) ) {
	function presso_the_post_footer_sections() {
		$sections = presso_get_theme_option( 'post_footer_sections' );
		if ( empty( $sections ) || empty( $sections['enabled'] ) ) return;

		foreach ( $sections['enabled'] as $slug => $label ) {
			if ( 'post-navigation' == $slug && ! is_attachment() ) {
				get_template_part( 'templates/single/post-navigation' );

			} elseif ( 'about-author' == $slug && ! is_attachment() ) {
				get_template_part( 'templates/single/about-author' );

			} elseif ( 'related-posts' == $slug && ! is_attachment() ) {
				get_template_part( 'templates/single/related-posts' );

			} elseif ( 'suggested-posts' == $slug && ! is_attachment() ) {
				get_template_part( 'templates/single/suggested-posts' );

			} elseif ( 'comments' == $slug ) {
				comments_template();

			} else {
				// For 'custom-1', 'custom-2' or else
				get_template_part( 'templates/post/post-footer-section-'.$slug );

			}
		}
	}
}


/* -----------------------------------------------------------------------------
 * Get Related Posts
 * -------------------------------------------------------------------------- */
if ( ! function_exists( 'presso_get_related_posts' ) ) {
	function presso_get_related_posts( $count = 3, $post_ID = null ) {
		if ( empty( $post_ID ) ) {
			$post_ID = get_the_ID();
		}

		// Prepare query args
		$query_args = presso_build_query( array(
			'post__not_in' => array($post_ID),  
			'posts_per_page'=> $count, 
		) );

		$tags = wp_get_post_tags( $post_ID, array( 'fields' => 'ids' ) );
		if ( $tags ) {
			// Find the related posts by tag
			$query_args[ 'tag__in' ] = $tags;

		} else {
			// Find the related posts by category when no tag.
			$cats = wp_get_post_categories( $post_ID, array('fields' => 'ids') );

			if ( $cats ) {
				$query_args[ 'category__in' ]= $cats;

			} else {
				// Get random post when no category and tag assigned
				$query_args[ 'orderby' ] = 'rand';
			}
		}

		return new WP_Query( apply_filters( 'presso_filter_related_post_query_args', $query_args ) );
	}
}




/* -----------------------------------------------------------------------------
 * Show Post Box
 * -------------------------------------------------------------------------- */

if ( ! function_exists( 'presso_the_post_loop' ) ) {
	function presso_the_post_loop( $args=array() ) {
		global $presso_secondary_query;

		$query_args = presso_build_query( $args );

		if ( 'slider-xlarge-2' == $args['layout'] ) {
			$query_args['posts_per_page'] += 4; // Additional 4 posts
			
		} elseif ( 'slider-multi-1' == $args['layout'] ) {
			$query_args['posts_per_page'] *= 3; // 3 posts per slide

		} elseif ( 'slider-multi-2' == $args['layout'] ) {
			$query_args['posts_per_page'] *= 4; // 4 posts per slide

		} elseif ( 'slider-multi-3' == $args['layout'] ) {
			$query_args['posts_per_page'] *= 5; // 5 posts per slide

		}

		$presso_secondary_query = new WP_Query( apply_filters( 'presso_filter_the_post_loop_query', $query_args, $args ) );

		if ( $presso_secondary_query->have_posts() ) {
			if ( ! empty( $args['before'] ) ) {
				echo wp_kses_post( $args['before'] );
			}

			if ( ! empty( $args['lead_layout'] ) && 'none' != $args['lead_layout'] && ! empty( $args['lead_layout_number'] ) ) {
				presso_set_lead_layout_limit( $args['lead_layout_number'] );
				get_template_part( 'templates/loop/loop', $args['lead_layout'] );
			}

			get_template_part( 'templates/loop/loop', $args['layout'] );

			if ( ! empty( $args['after'] ) ) {
				echo wp_kses_post( $args['after'] );
			}
		}

		wp_reset_postdata();
	}
}





/* -----------------------------------------------------------------------------
 * Change Thumbnail Size
 * -------------------------------------------------------------------------- */
global $presso_thumb_size_filters;
$presso_thumb_size_filters = array();

if ( ! function_exists( 'presso_set_thumb_size' ) ) {
	function presso_set_thumb_size( $filter, $size, $priority=10 ) {
		global $presso_thumb_size_filters;

		$presso_thumb_size_filters[ $filter ][ $priority ][] = $size;
	}
}

if ( ! function_exists( 'presso_reset_thumb_size' ) ) {
	function presso_reset_thumb_size( $filter='' ) {
		global $presso_thumb_size_filters;
		
		if ( ! empty( $filter ) ) {
			unset( $presso_thumb_size_filters[ $filter ] );

		} else {
			$presso_thumb_size_filters = array();

		}
	}
}

add_filter( 'presso_filter_post_box_thumb', 'presso_apply_thumb_size', 10, 2 );
if ( ! function_exists( 'presso_apply_thumb_size' ) ) {
	function presso_apply_thumb_size( $size, $filter ) {
		global $presso_thumb_size_filters;
		
		if ( ! empty( $presso_thumb_size_filters[ $filter ] ) ) {
			ksort( $presso_thumb_size_filters[ $filter ] );
			$last_priority = end( $presso_thumb_size_filters[ $filter ] );

			$size = is_array( $last_priority ) ? end( $last_priority ) : $last_priority;
		}

		return $size;
	}
}





/* -----------------------------------------------------------------------------
 * Read More Text
 * -------------------------------------------------------------------------- */

if ( ! function_exists( 'presso_the_read_more_label' ) ) {
	function presso_the_read_more_label() {
		$label = '';

		if ( 'presso_gallery' == get_post_type() ) {
			$label = esc_html_x( 'View Gallery', 'Label of read more button for gallery', 'presso' );

		} elseif ( 'presso_portfolio' == get_post_type() ) {
			$label = esc_html_x( 'View Portfolio', ' Label of read more button for portfolio', 'presso' );
				
		} else {
			$label = esc_html__( 'Read More', 'presso' );

		}

		echo apply_filters( 'presso_filter_read_more_label', $label );
	}
}