| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Thumbnail |
| 5 |
* |
| 6 |
* @link https://plugins360.com |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package Automatic_YouTube_Gallery |
| 10 |
*/ |
| 11 |
|
| 12 |
$single_url = ayg_get_single_video_url( $video, $attributes ); |
| 13 |
|
| 14 |
$image_url = ''; |
| 15 |
$thumb = null; |
| 16 |
$thumb_width = 320; |
| 17 |
$thumb_height = 180; |
| 18 |
$thumb_ratio = isset( $attributes['thumb_ratio'] ) ? (float) $attributes['thumb_ratio'] : 56.25; |
| 19 |
$aspect_ratio = '16 / 9'; |
| 20 |
|
| 21 |
if ( $thumb_ratio >= 170 ) { // Shorts / Vertical |
| 22 |
if ( isset( $video->thumbnails->maxres ) ) { |
| 23 |
$thumb = $video->thumbnails->maxres; |
| 24 |
} elseif ( isset( $video->thumbnails->medium ) ) { |
| 25 |
$thumb = $video->thumbnails->medium; |
| 26 |
} elseif ( isset( $video->thumbnails->high ) ) { |
| 27 |
$thumb = $video->thumbnails->high; |
| 28 |
} |
| 29 |
|
| 30 |
$aspect_ratio = '9 / 16'; |
| 31 |
} elseif ( $thumb_ratio >= 70 ) { // Classic 4:3 |
| 32 |
if ( isset( $video->thumbnails->standard ) ) { |
| 33 |
$thumb = $video->thumbnails->standard; |
| 34 |
} elseif ( isset( $video->thumbnails->high ) ) { |
| 35 |
$thumb = $video->thumbnails->high; |
| 36 |
} |
| 37 |
|
| 38 |
$aspect_ratio = '4 / 3'; |
| 39 |
} else { // Standard 16:9 |
| 40 |
if ( isset( $video->thumbnails->maxres ) ) { |
| 41 |
$thumb = $video->thumbnails->maxres; |
| 42 |
} elseif ( isset( $video->thumbnails->medium ) ) { |
| 43 |
$thumb = $video->thumbnails->medium; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
if ( empty( $thumb ) && isset( $video->thumbnails->default ) ) { |
| 48 |
$thumb = $video->thumbnails->default; |
| 49 |
} |
| 50 |
|
| 51 |
if ( isset( $thumb ) ) { |
| 52 |
$image_url = $thumb->url; |
| 53 |
$thumb_width = isset( $thumb->width ) ? (int) $thumb->width : $thumb_width; |
| 54 |
$thumb_height = isset( $thumb->height ) ? (int) $thumb->height : $thumb_height; |
| 55 |
} |
| 56 |
|
| 57 |
$image_url = apply_filters( 'ayg_thumbnail_image_url', $image_url, $video, $attributes ); |
| 58 |
?> |
| 59 |
<div class="ayg-thumbnail" data-id="<?php echo esc_attr( $video->id ); ?>" data-title="<?php echo esc_attr( $video->title ); ?>" data-url="<?php echo esc_attr( $single_url ); ?>"> |
| 60 |
<div class="ayg-thumbnail-media" style="--ayg-image-ratio: <?php echo esc_attr( $aspect_ratio ); ?>"> |
| 61 |
<?php |
| 62 |
// Image |
| 63 |
echo sprintf( |
| 64 |
'<img src="%s" class="ayg-thumbnail-image" width="%d" height="%d" alt="%s" %s/>', |
| 65 |
esc_url( $image_url ), |
| 66 |
$thumb_width, |
| 67 |
$thumb_height, |
| 68 |
esc_attr( $video->title ), |
| 69 |
! empty( $attributes['lazyload'] ) ? 'loading="lazy" decoding="async"' : 'decoding="async"' |
| 70 |
); |
| 71 |
|
| 72 |
// Now Playing |
| 73 |
echo sprintf( |
| 74 |
'<div class="ayg-thumbnail-now-playing" style="display: none;">%s</div>', |
| 75 |
esc_html__( 'Now Playing', 'automatic-youtube-gallery' ) |
| 76 |
); |
| 77 |
|
| 78 |
// Play Icon |
| 79 |
echo sprintf( |
| 80 |
'<svg xmlns="http://www.w3.org/2000/svg" fill="white" width="40" height="40" viewBox="0 0 24 24" class="ayg-icon ayg-thumbnail-icon-play" title="%1$s" aria-label="%1$s"><path fill-rule="evenodd" d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12Zm14.024-.983a1.125 1.125 0 0 1 0 1.966l-5.603 3.113A1.125 1.125 0 0 1 9 15.113V8.887c0-.857.921-1.4 1.671-.983l5.603 3.113Z" clip-rule="evenodd" /></svg>', |
| 81 |
esc_attr__( 'Play', 'automatic-youtube-gallery' ) |
| 82 |
); |
| 83 |
?> |
| 84 |
</div> |
| 85 |
<div class="ayg-thumbnail-caption"> |
| 86 |
<?php if ( ! empty( $attributes['thumb_title'] ) ) : ?> |
| 87 |
<div class="ayg-thumbnail-title"><?php echo esc_html( ayg_trim_words( $video->title, (int) $attributes['thumb_title_length'] ) ); ?></div> |
| 88 |
<?php endif; ?> |
| 89 |
<?php if ( ! empty( $attributes['thumb_excerpt'] ) && ! empty( $video->description ) ) : ?> |
| 90 |
<div class="ayg-thumbnail-excerpt"><?php echo wp_kses_post( ayg_trim_words( $video->description, (int) $attributes['thumb_excerpt_length'] ) ); ?></div> |
| 91 |
<?php endif; ?> |
| 92 |
<?php if ( ! empty( $attributes['player_description'] ) && ! empty( $video->description ) ) : ?> |
| 93 |
<div class="ayg-thumbnail-description" style="display: none;"><?php echo wp_kses_post( ayg_get_player_description( $video, $attributes ) ); ?></div> |
| 94 |
<?php endif; ?> |
| 95 |
</div> |
| 96 |
</div> |