| 1 |
<?php |
| 2 |
|
| 3 |
namespace Photonic_Plugin\Lightboxes\Features; |
| 4 |
|
| 5 |
use Photonic_Plugin\Components\Photo; |
| 6 |
use Photonic_Plugin\Platforms\Base; |
| 7 |
|
| 8 |
trait Show_Videos_Inline { |
| 9 |
public function get_video_id(Photo $photo, Base $module): string { |
| 10 |
return $module->provider . '-' . $module->gallery_index . '-' . $photo->id; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* {@inheritDoc} |
| 15 |
*/ |
| 16 |
public function get_video_markup(Photo $photo, Base $module, string $indent): string { |
| 17 |
$ret = ''; |
| 18 |
if (!empty($photo->video)) { |
| 19 |
$video_id = $this->get_video_id($photo, $module); |
| 20 |
$width = !empty($photo->main_size) ? ('width="' . $photo->main_size['w'] . '"') : ''; |
| 21 |
$height = !empty($photo->main_size) ? ('height="' . $photo->main_size['h'] . '"') : ''; |
| 22 |
$poster = !empty($photo->main_image) ? ('poster="' . $photo->main_image . '"') : ''; |
| 23 |
$ret .= $indent . "\t\t" . '<div class="photonic-html5-external" id="photonic-video-' . $video_id . '">' . "\n"; |
| 24 |
$ret .= $indent . "\t\t\t" . '<video class="photonic" controls preload="none" ' . $width . ' ' . $height . ' ' . $poster . '>' . "\n"; |
| 25 |
$ret .= $indent . "\t\t\t\t" . '<source src="' . $photo->video . '" type="' . ($photo->mime ?: 'video/mp4') . '">' . "\n"; |
| 26 |
$ret .= $indent . "\t\t\t\t" . esc_html__('Your browser does not support HTML5 videos.', 'photonic') . "\n"; |
| 27 |
$ret .= $indent . "\t\t\t" . '</video>' . "\n"; |
| 28 |
$ret .= $indent . "\t\t" . '</div>' . "\n"; |
| 29 |
} |
| 30 |
return $ret; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* {@inheritDoc} |
| 35 |
*/ |
| 36 |
public function get_grid_link(Photo $photo, array $short_code, Base $module): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter |
| 37 |
if (!empty($photo->video)) { |
| 38 |
return esc_attr('#photonic-video-' . $this->get_video_id($photo, $module)); |
| 39 |
} |
| 40 |
else { |
| 41 |
return esc_url($photo->main_image); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|