<?php
/**
 * Post template: Image
 */

?>
<?php

$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'cookandmeal-blog-thumb-grid');

if (has_post_thumbnail($post->ID)) {
    $image_bg ='background-image: url('.esc_url($image[0]).');';
    $post_class = '';
} else {
    $image_bg = '';
    $post_class = ' cookandmeal-post-no-image';
}

$categories_list = cookandmeal_get_the_category_list($post->ID);

// Show post format
$current_post_format = get_post_format($post->ID) ? get_post_format($post->ID) : 'standard';
$post_format_icon = '';

if (in_array($current_post_format, cookandmeal_get_mediaformats())) {
    $post_format_icon = '<div class="cookandmeal-post-format-icon"></div>';
}

$post_class .= ' format-'.$current_post_format;

echo '<div class="cookandmeal-post cookandmeal-post-image-only cookandmeal-post'.esc_attr($post_class).'"'.cookandmeal_add_aos(false).'>';

if (has_post_thumbnail($post->ID)) {
    echo '<div class="cookandmeal-post-image-wrapper">';

    // Background video
    if($current_post_format == 'video' && get_theme_mod('blog_posts_video_bg', true)) {

        $post_embed_video = get_post_meta( $post->ID, '_cookandmeal_video_embed', true );

        if(!empty($post_embed_video) && strpos($post_embed_video, 'youtu') !== false) {
            echo '<div class="cookandmeal-youtube-video-bg" data-youtube="'.esc_url($post_embed_video).'"></div>';

            $image_bg = '';
        }
    }

    if(get_theme_mod('blog_posts_review', true)) {
        do_action('cookandmeal_post_review_rating'); // this action called from plugin
    }

    echo '<a href="'.esc_url(get_permalink($post->ID)).'"><div class="cookandmeal-post-image" data-style="'.esc_attr($image_bg).'">'.wp_kses_post($post_format_icon).'</div></a></div>';
}
?>

</div>
