2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2012-09-23 21:18:12 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class VideoFileHandlerTheme extends Themelet
|
|
|
|
{
|
|
|
|
public function display_image(Page $page, Image $image)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$ilink = $image->get_image_link();
|
|
|
|
$thumb_url = make_http($image->get_thumb_link()); //used as fallback image
|
|
|
|
$ext = strtolower($image->get_ext());
|
|
|
|
$full_url = make_http($ilink);
|
2020-06-02 23:03:28 +00:00
|
|
|
$autoplay = $config->get_bool(VideoFileHandlerConfig::PLAYBACK_AUTOPLAY);
|
|
|
|
$loop = $config->get_bool(VideoFileHandlerConfig::PLAYBACK_LOOP);
|
2020-06-24 13:14:24 +00:00
|
|
|
$mute = $config->get_bool(VideoFileHandlerConfig::PLAYBACK_MUTE);
|
2019-05-28 16:59:38 +00:00
|
|
|
$player = make_link('vendor/bower-asset/mediaelement/build/flashmediaelement.swf');
|
2016-05-14 22:14:29 +00:00
|
|
|
|
2020-06-02 22:49:35 +00:00
|
|
|
$width="auto";
|
|
|
|
if ($image->width>1) {
|
|
|
|
$width = $image->width."px";
|
|
|
|
}
|
|
|
|
$height="auto";
|
|
|
|
if ($image->height>1) {
|
|
|
|
$height = $image->height."px";
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$html = "Video not playing? <a href='$ilink'>Click here</a> to download the file.<br/>";
|
2016-05-14 22:14:29 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
//Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
|
2020-05-28 15:05:20 +00:00
|
|
|
$mime = get_mime_for_extension($ext);
|
|
|
|
|
2020-06-02 23:03:28 +00:00
|
|
|
if (in_array($mime, VideoFileHandler::SUPPORTED_MIME)) {
|
2019-05-28 16:59:38 +00:00
|
|
|
//FLV isn't supported by <video>, but it should always fallback to the flash-based method.
|
2020-05-28 15:05:20 +00:00
|
|
|
if ($mime == MIME_TYPE_WEBM) {
|
2020-03-25 11:47:00 +00:00
|
|
|
//Several browsers still lack WebM support sadly: https://caniuse.com/#feat=webm
|
2019-05-28 16:59:38 +00:00
|
|
|
$html .= "<!--[if IE]><p>To view webm files with IE, please <a href='https://tools.google.com/dlpage/webmmf/' target='_blank'>download this plugin</a>.</p><![endif]-->";
|
|
|
|
}
|
2016-05-14 22:14:29 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$html_fallback = "
|
2017-06-01 19:44:02 +00:00
|
|
|
<object width=\"100%\" height=\"480px\" type=\"application/x-shockwave-flash\" data=\"$player\">
|
|
|
|
<param name=\"movie\" value=\"$player\" />
|
2016-05-14 22:14:29 +00:00
|
|
|
|
|
|
|
<param name=\"allowFullScreen\" value=\"true\" />
|
|
|
|
<param name=\"wmode\" value=\"opaque\" />
|
|
|
|
|
2016-08-20 00:03:55 +00:00
|
|
|
<param name=\"flashVars\" value=\""
|
2019-05-28 16:59:38 +00:00
|
|
|
. "controls=true"
|
|
|
|
. "&autoplay=" . ($autoplay ? 'true' : 'false')
|
|
|
|
. "&poster={$thumb_url}"
|
|
|
|
. "&file={$full_url}"
|
|
|
|
. "&loop=" . ($loop ? 'true' : 'false') . "\" />
|
2020-03-13 09:23:54 +00:00
|
|
|
<img alt='thumb' src=\"{$thumb_url}\" />
|
2016-05-14 22:14:29 +00:00
|
|
|
</object>";
|
|
|
|
|
2020-05-28 15:05:20 +00:00
|
|
|
if ($mime == MIME_TYPE_FLASH_VIDEO) {
|
2019-05-28 16:59:38 +00:00
|
|
|
//FLV doesn't support <video>.
|
|
|
|
$html .= $html_fallback;
|
|
|
|
} else {
|
|
|
|
$autoplay = ($autoplay ? ' autoplay' : '');
|
|
|
|
$loop = ($loop ? ' loop' : '');
|
2020-06-24 13:14:24 +00:00
|
|
|
$mute = ($mute ? ' muted' : '');
|
2016-09-02 01:57:53 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$html .= "
|
2020-06-24 13:14:24 +00:00
|
|
|
<video controls class='shm-main-image' id='main_image' alt='main image' poster='$thumb_url' {$autoplay} {$loop} {$mute}
|
2020-06-02 22:49:35 +00:00
|
|
|
style='height: $height; width: $width; max-width: 100%'>
|
2020-05-28 15:05:20 +00:00
|
|
|
<source src='{$ilink}' type='{$mime}'>
|
2016-05-14 22:14:29 +00:00
|
|
|
|
|
|
|
<!-- If browser doesn't support filetype, fallback to flash -->
|
|
|
|
{$html_fallback}
|
2017-03-10 19:12:01 +00:00
|
|
|
</video>
|
|
|
|
<script>$('#main_image').prop('volume', 0.25);</script>
|
|
|
|
";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//This should never happen, but just in case let's have a fallback..
|
2020-05-28 15:05:20 +00:00
|
|
|
$html = "Video type '$mime' not recognised";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
$page->add_block(new Block("Video", $html, "main", 10));
|
|
|
|
}
|
2012-09-23 21:18:12 +00:00
|
|
|
}
|