<?php
/**
 * The Portfolio template to display the content
 *
 * Used for index/archive/search.
 *
 * @package PANTRY
 * @since PANTRY 1.0
 */

$pantry_template_args = get_query_var( 'pantry_template_args' );
if ( is_array( $pantry_template_args ) ) {
	$pantry_columns    = empty( $pantry_template_args['columns'] ) ? 2 : max( 1, $pantry_template_args['columns'] );
	$pantry_blog_style = array( $pantry_template_args['type'], $pantry_columns );
    $pantry_columns_class = pantry_get_column_class( 1, $pantry_columns, ! empty( $pantry_template_args['columns_tablet']) ? $pantry_template_args['columns_tablet'] : '', ! empty($pantry_template_args['columns_mobile']) ? $pantry_template_args['columns_mobile'] : '' );
} else {
	$pantry_template_args = array();
	$pantry_blog_style = explode( '_', pantry_get_theme_option( 'blog_style' ) );
	$pantry_columns    = empty( $pantry_blog_style[1] ) ? 2 : max( 1, $pantry_blog_style[1] );
    $pantry_columns_class = pantry_get_column_class( 1, $pantry_columns );
}

$pantry_post_format = get_post_format();
$pantry_post_format = empty( $pantry_post_format ) ? 'standard' : str_replace( 'post-format-', '', $pantry_post_format );

?><div class="
<?php
if ( ! empty( $pantry_template_args['slider'] ) ) {
	echo ' slider-slide swiper-slide';
} else {
	echo ( pantry_is_blog_style_use_masonry( $pantry_blog_style[0] ) ? 'masonry_item masonry_item-1_' . esc_attr( $pantry_columns ) : esc_attr( $pantry_columns_class ));
}
?>
"><article id="post-<?php the_ID(); ?>" 
	<?php
	post_class(
		'post_item post_item_container post_format_' . esc_attr( $pantry_post_format )
		. ' post_layout_portfolio'
		. ' post_layout_portfolio_' . esc_attr( $pantry_columns )
		. ( 'portfolio' != $pantry_blog_style[0] ? ' ' . esc_attr( $pantry_blog_style[0] )  . '_' . esc_attr( $pantry_columns ) : '' )
	);
	pantry_add_blog_animation( $pantry_template_args );
	?>
>
<?php

	// Sticky label
	if ( is_sticky() && ! is_paged() ) {
		?>
		<span class="post_label label_sticky"></span>
		<?php
	}

	$pantry_hover   = ! empty( $pantry_template_args['hover'] ) && ! pantry_is_inherit( $pantry_template_args['hover'] )
								? $pantry_template_args['hover']
								: pantry_get_theme_option( 'image_hover' );

	if ( 'dots' == $pantry_hover ) {
		$pantry_post_link = empty( $pantry_template_args['no_links'] )
								? ( ! empty( $pantry_template_args['link'] )
									? $pantry_template_args['link']
									: get_permalink()
									)
								: '';
		$pantry_target    = ! empty( $pantry_post_link ) && false === strpos( $pantry_post_link, home_url() )
								? ' target="_blank" rel="nofollow"'
								: '';
	}
	
	// Meta parts
	$pantry_components = ! empty( $pantry_template_args['meta_parts'] )
							? ( is_array( $pantry_template_args['meta_parts'] )
								? $pantry_template_args['meta_parts']
								: explode( ',', $pantry_template_args['meta_parts'] )
								)
							: pantry_array_get_keys_by_value( pantry_get_theme_option( 'meta_parts' ) );

	// Featured image
	pantry_show_post_featured( apply_filters( 'pantry_filter_args_featured',
        array(
			'hover'         => $pantry_hover,
			'no_links'      => ! empty( $pantry_template_args['no_links'] ),
			'thumb_size'    => ! empty( $pantry_template_args['thumb_size'] )
								? $pantry_template_args['thumb_size']
								: pantry_get_thumb_size(
									pantry_is_blog_style_use_masonry( $pantry_blog_style[0] )
										? (	strpos( pantry_get_theme_option( 'body_style' ), 'full' ) !== false || $pantry_columns < 3
											? 'masonry-big'
											: 'masonry'
											)
										: (	strpos( pantry_get_theme_option( 'body_style' ), 'full' ) !== false || $pantry_columns < 3
											? 'square'
											: 'square'
											)
								),
			'thumb_bg' => pantry_is_blog_style_use_masonry( $pantry_blog_style[0] ) ? false : true,
			'show_no_image' => true,
			'meta_parts'    => $pantry_components,
			'class'         => 'dots' == $pantry_hover ? 'hover_with_info' : '',
			'post_info'     => 'dots' == $pantry_hover
										? '<div class="post_info"><h5 class="post_title">'
											. ( ! empty( $pantry_post_link )
												? '<a href="' . esc_url( $pantry_post_link ) . '"' . ( ! empty( $target ) ? $target : '' ) . '>'
												: ''
												)
												. esc_html( get_the_title() ) 
											. ( ! empty( $pantry_post_link )
												? '</a>'
												: ''
												)
											. '</h5></div>'
										: '',
            'thumb_ratio'   => 'info' == $pantry_hover ?  '100:102' : '',
        ),
        'content-portfolio',
        $pantry_template_args
    ) );
	?>
</article></div><?php
// Need opening PHP-tag above, because <article> is a inline-block element (used as column)!