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

$tourimo_template_args = get_query_var( 'tourimo_template_args' );

if ( is_array( $tourimo_template_args ) ) {
	$tourimo_columns    = empty( $tourimo_template_args['columns'] ) ? 2 : max( 1, $tourimo_template_args['columns'] );
	$tourimo_blog_style = array( $tourimo_template_args['type'], $tourimo_columns );
} else {
	$tourimo_blog_style = explode( '_', tourimo_get_theme_option( 'blog_style' ) );
	$tourimo_columns    = empty( $tourimo_blog_style[1] ) ? 2 : max( 1, $tourimo_blog_style[1] );
}
$tourimo_expanded   = ! tourimo_sidebar_present() && tourimo_get_theme_option( 'expand_content' ) == 'expand';

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

?><div class="<?php
	if ( ! empty( $tourimo_template_args['slider'] ) ) {
		echo ' slider-slide swiper-slide';
	} else {
		echo ( tourimo_is_blog_style_use_masonry( $tourimo_blog_style[0] ) ? 'masonry_item masonry_item' : 'column' ) . '-1_' . esc_attr( $tourimo_columns );
	}
?>"><article id="post-<?php the_ID(); ?>" data-post-id="<?php the_ID(); ?>"
	<?php
	post_class(
		'post_item post_item_container post_format_' . esc_attr( $tourimo_post_format )
				. ' post_layout_classic post_layout_classic_' . esc_attr( $tourimo_columns )
				. ' post_layout_' . esc_attr( $tourimo_blog_style[0] )
				. ' post_layout_' . esc_attr( $tourimo_blog_style[0] ) . '_' . esc_attr( $tourimo_columns )
	);
	tourimo_add_blog_animation( $tourimo_template_args );
	?>
>
	<?php

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

	// Featured image
	$tourimo_hover      = ! empty( $tourimo_template_args['hover'] ) && ! tourimo_is_inherit( $tourimo_template_args['hover'] )
							? $tourimo_template_args['hover']
							: tourimo_get_theme_option( 'image_hover' );

	$tourimo_components = ! empty( $tourimo_template_args['meta_parts'] )
							? ( is_array( $tourimo_template_args['meta_parts'] )
								? $tourimo_template_args['meta_parts']
								: explode( ',', $tourimo_template_args['meta_parts'] )
								)
							: tourimo_array_get_keys_by_value( tourimo_get_theme_option( 'meta_parts' ) );

	tourimo_show_post_featured(
		array(
			'thumb_size' => tourimo_get_thumb_size(
				'classic' == $tourimo_blog_style[0]
						? ( strpos( tourimo_get_theme_option( 'body_style' ), 'full' ) !== false
								? ( $tourimo_columns > 2 ? 'big' : 'huge' )
								: ( $tourimo_columns > 2
									? ( $tourimo_expanded ? 'med' : 'small' )
									: ( $tourimo_expanded ? 'big' : 'med' )
									)
							)
						: ( strpos( tourimo_get_theme_option( 'body_style' ), 'full' ) !== false
								? ( $tourimo_columns > 2 ? 'masonry-big' : 'full' )
								: ( $tourimo_columns <= 2 && $tourimo_expanded ? 'masonry-big' : 'masonry' )
							)
			),
			'hover'      => $tourimo_hover,
			'meta_parts' => $tourimo_components,
			'no_links'   => ! empty( $tourimo_template_args['no_links'] ),
		)
	);

	// Title and post meta
	$tourimo_show_title = get_the_title() != '';
	$tourimo_show_meta  = count( $tourimo_components ) > 0 && ! in_array( $tourimo_hover, array( 'border', 'pull', 'slide', 'fade', 'info' ) );

	if ( $tourimo_show_title ) {
		?>
		<div class="post_header entry-header">
			<?php
			// Categories
			if ( apply_filters( 'tourimo_filter_show_blog_categories', $tourimo_show_meta && in_array( 'categories', $tourimo_components ), array( 'categories' ), 'classic' ) ) {
				do_action( 'tourimo_action_before_post_category' );
				?>
				<div class="post_category">
					<?php
					tourimo_show_post_meta( apply_filters(
														'tourimo_filter_post_meta_args',
														array(
															'components' => 'categories',
															'seo'        => false,
															'echo'       => true,
															),
														'hover_' . $tourimo_hover, 1
														)
										);
					?>
				</div>
				<?php
				$tourimo_components = tourimo_array_delete_by_value( $tourimo_components, 'categories' );
				do_action( 'tourimo_action_after_post_category' );
			}
			// Post title
			if ( apply_filters( 'tourimo_filter_show_blog_title', true, 'classic' ) ) {
				do_action( 'tourimo_action_before_post_title' );
				if ( empty( $tourimo_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( 'tourimo_action_after_post_title' );
			}
			?>
		</div><!-- .entry-header -->
		<?php
	}

	// Post content
	ob_start();
	if ( apply_filters( 'tourimo_filter_show_blog_excerpt', empty( $tourimo_template_args['hide_excerpt'] ) && tourimo_get_theme_option( 'excerpt_length' ) > 0, 'classic' ) ) {
		tourimo_show_post_content( $tourimo_template_args, '<div class="post_content_inner">', '</div>' );
	}
	$tourimo_content = ob_get_contents();
	ob_end_clean();

	tourimo_show_layout( $tourimo_content, '<div class="post_content entry-content">', '</div><!-- .entry-content -->' );

	// Post meta
	if ( apply_filters( 'tourimo_filter_show_blog_meta', $tourimo_show_meta, $tourimo_components, 'classic' ) ) {
		if ( count( $tourimo_components ) > 0 ) {
			do_action( 'tourimo_action_before_post_meta' );
			tourimo_show_post_meta(
				apply_filters(
					'tourimo_filter_post_meta_args', array(
						'components' => join( ',', $tourimo_components ),
						'seo'        => false,
						'echo'       => true,
					), $tourimo_blog_style[0], $tourimo_columns
				)
			);
			do_action( 'tourimo_action_after_post_meta' );
		}
	}
		
	// More button
	if ( apply_filters( 'tourimo_filter_show_blog_readmore', ! $tourimo_show_title, 'classic' ) ) {
		if ( empty( $tourimo_template_args['no_links'] ) ) {
			do_action( 'tourimo_action_before_post_readmore' );
			tourimo_show_post_more_link( $tourimo_template_args, '<p>', '</p>' );
			do_action( 'tourimo_action_after_post_readmore' );
		}
	}
	?>

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