<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $post;

$petition_id = $post->ID;
$gallery = get_post_meta($petition_id, 'petition_gallery', true);
$images = conikal_get_gallery_images($gallery);
$thumb_id = get_post_thumbnail_id($petition_id);
$thumbnail = wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
$thumbnail_large = wp_get_attachment_image_src($thumb_id, 'large', true);
$video = get_post_meta($petition_id, 'petition_video', true);
$thumb_placeholder = get_post_meta($petition_id, 'petition_thumb', true);
$thumb = get_post_meta($petition_id, 'petition_thumb_small', true);
$title = get_the_title($petition_id);
$lazy_placeholder = conikal_lazy_load_placeholder('thumbnail');
?>

<?php
if (has_post_thumbnail($petition_id)) { ?>
    <img class="ui fluid rounded image lazy" data-src="<?php echo esc_url($thumbnail_large[0]) ?>" src="<?php echo esc_url($lazy_placeholder) ?>" alt="<?php echo esc_attr($title) ?>">
<?php } elseif ($video) { ?>
    <div class="ui embed media-embed" id="media-embed<?php echo esc_attr($petition_id) ?>"></div>
    <input type="hidden" class="video-url" id="video-url<?php echo esc_attr($petition_id) ?>" value="<?php echo esc_attr($video) ?>">
    <input type="hidden" class="thumb-url" id="thumb-url<?php echo esc_attr($petition_id) ?>" value="<?php echo esc_attr($thumb_placeholder) ?>">
<?php } elseif ($gallery) { ?>
    <img class="ui fluid rounded image" data-src="<?php echo esc_url($images[1]) ?>" src="<?php echo esc_url($lazy_placeholder) ?>" alt="<?php echo esc_attr($title) ?>">
<?php } ?>