From ec290d86768b9b53626e94a85f992f192f7f6d87 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Tue, 2 Jun 2020 18:03:28 -0500 Subject: [PATCH] Added additional optional video formats to the video handler --- ext/handle_video/main.php | 69 +++++++++++++++++++++++++++++++++----- ext/handle_video/theme.php | 9 ++--- 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index cd3d5453..53e65ad6 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -1,29 +1,55 @@ set_default_bool('video_playback_autoplay', true); - $config->set_default_bool('video_playback_loop', true); + $config->set_default_bool(VideoFileHandlerConfig::PLAYBACK_AUTOPLAY, true); + $config->set_default_bool(VideoFileHandlerConfig::PLAYBACK_LOOP, true); + $config->set_default_array( + VideoFileHandlerConfig::ENABLED_FORMATS, + [MIME_TYPE_FLASH_VIDEO, MIME_TYPE_MP4_VIDEO, MIME_TYPE_OGG_VIDEO, MIME_TYPE_WEBM] + ); + } + + private function get_options(): array + { + $output = []; + foreach ($this->SUPPORTED_MIME as $format) { + $output[MIME_TYPE_MAP[$format][MIME_TYPE_MAP_NAME]] = $format; + } + return $output; } public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Video Options"); - $sb->add_bool_option("video_playback_autoplay", "Autoplay: "); + $sb->add_bool_option(VideoFileHandlerConfig::PLAYBACK_AUTOPLAY, "Autoplay: "); $sb->add_label("
"); - $sb->add_bool_option("video_playback_loop", "Loop: "); + $sb->add_bool_option(VideoFileHandlerConfig::PLAYBACK_LOOP, "Loop: "); + $sb->add_label("
Enabled Formats:"); + $sb->add_multichoice_option(VideoFileHandlerConfig::ENABLED_FORMATS, $this->get_options()); $event->panel->add_block($sb); } @@ -79,6 +105,19 @@ class VideoFileHandler extends DataHandlerExtension } } + protected function supported_ext(string $ext): bool + { + global $config; + + $enabled_formats = $config->get_array(VideoFileHandlerConfig::ENABLED_FORMATS); + foreach ($enabled_formats as $format) { + if (in_array($ext, MIME_TYPE_MAP[$format][MIME_TYPE_MAP_EXT])) { + return true; + } + } + return false; + } + protected function create_thumb(string $hash, string $type): bool { return Media::create_thumbnail_ffmpeg($hash); @@ -86,6 +125,18 @@ class VideoFileHandler extends DataHandlerExtension protected function check_contents(string $tmpname): bool { - return in_array(get_mime($tmpname), $this->SUPPORTED_MIME); + global $config; + + if (file_exists($tmpname)) { + $mime = get_mime($tmpname); + + $enabled_formats = $config->get_array(VideoFileHandlerConfig::ENABLED_FORMATS); + foreach ($enabled_formats as $format) { + if (in_array($mime, MIME_TYPE_MAP[$format][MIME_TYPE_MAP_MIME])) { + return true; + } + } + } + return false; } } diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php index 5f6dbbcd..6149131b 100644 --- a/ext/handle_video/theme.php +++ b/ext/handle_video/theme.php @@ -2,9 +2,6 @@ class VideoFileHandlerTheme extends Themelet { - - const SUPPORTED_TYPES = [MIME_TYPE_MP4_VIDEO, MIME_TYPE_OGG_VIDEO, MIME_TYPE_WEBM, MIME_TYPE_FLASH_VIDEO]; - public function display_image(Page $page, Image $image) { global $config; @@ -12,8 +9,8 @@ class VideoFileHandlerTheme extends Themelet $thumb_url = make_http($image->get_thumb_link()); //used as fallback image $ext = strtolower($image->get_ext()); $full_url = make_http($ilink); - $autoplay = $config->get_bool("video_playback_autoplay"); - $loop = $config->get_bool("video_playback_loop"); + $autoplay = $config->get_bool(VideoFileHandlerConfig::PLAYBACK_AUTOPLAY); + $loop = $config->get_bool(VideoFileHandlerConfig::PLAYBACK_LOOP); $player = make_link('vendor/bower-asset/mediaelement/build/flashmediaelement.swf'); $width="auto"; @@ -30,7 +27,7 @@ class VideoFileHandlerTheme extends Themelet //Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats $mime = get_mime_for_extension($ext); - if (in_array($mime, self::SUPPORTED_TYPES)) { + if (in_array($mime, VideoFileHandler::SUPPORTED_MIME)) { //FLV isn't supported by