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

$hygia_template_args = get_query_var( 'hygia_template_args' );

if ( is_array( $hygia_template_args ) ) {
	$hygia_columns    = empty( $hygia_template_args['columns'] ) ? 2 : max( 1, $hygia_template_args['columns'] );
	$hygia_blog_style = array( $hygia_template_args['type'], $hygia_columns );
    $hygia_columns_class = hygia_get_column_class( 1, $hygia_columns, ! empty( $hygia_template_args['columns_tablet']) ? $hygia_template_args['columns_tablet'] : '', ! empty($hygia_template_args['columns_mobile']) ? $hygia_template_args['columns_mobile'] : '' );
} else {
	$hygia_template_args = array();
	$hygia_blog_style = explode( '_', hygia_get_theme_option( 'blog_style' ) );
	$hygia_columns    = empty( $hygia_blog_style[1] ) ? 2 : max( 1, $hygia_blog_style[1] );
    $hygia_columns_class = hygia_get_column_class( 1, $hygia_columns );
}
$hygia_expanded   = ! hygia_sidebar_present() && hygia_get_theme_option( 'expand_content' ) == 'expand';

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

?><div class="<?php
	if ( ! empty( $hygia_template_args['slider'] ) ) {
		echo ' slider-slide swiper-slide';
	} else {
		echo ( hygia_is_blog_style_use_masonry( $hygia_blog_style[0] ) ? 'masonry_item masonry_item-1_' . esc_attr( $hygia_columns ) : esc_attr( $hygia_columns_class ) );
	}
?>"><article id="post-<?php the_ID(); ?>" data-post-id="<?php the_ID(); ?>"
	<?php
	post_class(
		'post_item post_item_container post_format_' . esc_attr( $hygia_post_format )
				. ' post_layout_classic post_layout_classic_' . esc_attr( $hygia_columns )
				. ' post_layout_' . esc_attr( $hygia_blog_style[0] )
				. ' post_layout_' . esc_attr( $hygia_blog_style[0] ) . '_' . esc_attr( $hygia_columns )
	);
	hygia_add_blog_animation( $hygia_template_args );
	?>
>
	<?php

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

	// Featured image
	$hygia_hover      = ! empty( $hygia_template_args['hover'] ) && ! hygia_is_inherit( $hygia_template_args['hover'] )
							? $hygia_template_args['hover']
							: hygia_get_theme_option( 'image_hover' );

	$hygia_components = ! empty( $hygia_template_args['meta_parts'] )
							? ( is_array( $hygia_template_args['meta_parts'] )
								? $hygia_template_args['meta_parts']
								: explode( ',', $hygia_template_args['meta_parts'] )
								)
							: hygia_array_get_keys_by_value( hygia_get_theme_option( 'meta_parts' ) );

	hygia_show_post_featured( apply_filters( 'hygia_filter_args_featured',
		array(
			'thumb_size' => ! empty( $hygia_template_args['thumb_size'] )
				? $hygia_template_args['thumb_size']
				: hygia_get_thumb_size(
					'classic' == $hygia_blog_style[0]
						? ( strpos( hygia_get_theme_option( 'body_style' ), 'full' ) !== false
								? ( $hygia_columns > 2 ? 'big' : 'huge' )
								: ( $hygia_columns > 2
									? ( $hygia_expanded ? 'square' : 'square' )
									: ($hygia_columns > 1 ? 'square' : ( $hygia_expanded ? 'huge' : 'big' ))
									)
							)
						: ( strpos( hygia_get_theme_option( 'body_style' ), 'full' ) !== false
								? ( $hygia_columns > 2 ? 'masonry-big' : 'full' )
								: ($hygia_columns === 1 ? ( $hygia_expanded ? 'huge' : 'big' ) : ( $hygia_columns <= 2 && $hygia_expanded ? 'masonry-big' : 'masonry' ))
							)
			),
			'hover'      => $hygia_hover,
			'meta_parts' => $hygia_components,
			'no_links'   => ! empty( $hygia_template_args['no_links'] ),
        ),
        'content-classic',
        $hygia_template_args
    ) );

	// Title and post meta
	$hygia_show_title = get_the_title() != '';
	$hygia_show_meta  = count( $hygia_components ) > 0 && ! in_array( $hygia_hover, array( 'border', 'pull', 'slide', 'fade', 'info' ) );

	if ( $hygia_show_title ) {
		?>
		<div class="post_header entry-header">
			<?php

			// Post meta
			if ( apply_filters( 'hygia_filter_show_blog_meta', $hygia_show_meta, $hygia_components, 'classic' ) ) {
				if ( count( $hygia_components ) > 0 ) {
					do_action( 'hygia_action_before_post_meta' );
					hygia_show_post_meta(
						apply_filters(
							'hygia_filter_post_meta_args', array(
							'components' => join( ',', $hygia_components ),
							'seo'        => false,
							'echo'       => true,
						), $hygia_blog_style[0], $hygia_columns
						)
					);
					do_action( 'hygia_action_after_post_meta' );
				}
			}

			// Post title
			if ( apply_filters( 'hygia_filter_show_blog_title', true, 'classic' ) ) {
				do_action( 'hygia_action_before_post_title' );
				if ( empty( $hygia_template_args['no_links'] ) ) {
					the_title( sprintf( '<h4 class="post_title entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h4>' );
				} else {
					the_title( '<h4 class="post_title entry-title">', '</h4>' );
				}
				do_action( 'hygia_action_after_post_title' );
			}

			if( !in_array( $hygia_post_format, array( 'quote', 'aside', 'link', 'status' ) ) ) {
				// More button
				if ( apply_filters( 'hygia_filter_show_blog_readmore', ! $hygia_show_title || ! empty( $hygia_template_args['more_button'] ), 'classic' ) ) {
					if ( empty( $hygia_template_args['no_links'] ) ) {
						do_action( 'hygia_action_before_post_readmore' );
						hygia_show_post_more_link( $hygia_template_args, '<div class="more-wrap">', '</div>' );
						do_action( 'hygia_action_after_post_readmore' );
					}
				}
			}
			?>
		</div><!-- .entry-header -->
		<?php
	}

	// Post content
	if( in_array( $hygia_post_format, array( 'quote', 'aside', 'link', 'status' ) ) ) {
		ob_start();
		if (apply_filters('hygia_filter_show_blog_excerpt', empty($hygia_template_args['hide_excerpt']) && hygia_get_theme_option('excerpt_length') > 0, 'classic')) {
			hygia_show_post_content($hygia_template_args, '<div class="post_content_inner">', '</div>');
		}
		// More button
		if(! empty( $hygia_template_args['more_button'] )) {
			if ( empty( $hygia_template_args['no_links'] ) ) {
				do_action( 'hygia_action_before_post_readmore' );
				hygia_show_post_more_link( $hygia_template_args, '<div class="more-wrap">', '</div>' );
				do_action( 'hygia_action_after_post_readmore' );
			}
		}
		$hygia_content = ob_get_contents();
		ob_end_clean();
		hygia_show_layout($hygia_content, '<div class="post_content entry-content">', '</div><!-- .entry-content -->');
	}
	?>

</article></div><?php
// Need opening PHP-tag above, because <div> is a inline-block element (used as column)!
