From 7b044fd43b7c3b66a297d2f6dc87e220a145f0c4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 22 Aug 2024 12:15:07 +0200 Subject: [PATCH] wait #7050 @2 --- src/Links/Link.php | 4 ++- src/Links/WebVideoLink.php | 50 +++++++++++++++++++++++++-------- src/Links/WebVideoPopupLink.php | 2 +- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/Links/Link.php b/src/Links/Link.php index 3602b39..fcd07a6 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -12,6 +12,7 @@ use Cubist\Util\Graphics\Lottie; use Cubist\Util\Json; use Cubist\Util\ObjectUtil; use Cubist\Util\Text; +use Cubist\Util\WebVideo; use Cubist\Util\Xml; use Fluidbook\Tools\Compiler\CompilerInterface; use Illuminate\Support\Facades\Cache; @@ -127,7 +128,7 @@ class Link public $transition; public $polygon = ''; public $cursor = ''; - public $blinkdelay=0; + public $blinkdelay = 0; protected $role = 'button'; @@ -203,6 +204,7 @@ class Link return CustomLink::getCustomInstance($id, $init, $compiler); case static::WEBVIDEO: $init['inline'] = self::normalizeInlineIntegration($init['inline']); + $init['to'] = WebVideoLink::cleanID($init['to']); if ($init['inline'] === 'popup') { return new WebVideoPopupLink($id, $init, $compiler); } diff --git a/src/Links/WebVideoLink.php b/src/Links/WebVideoLink.php index 86d230f..7422867 100644 --- a/src/Links/WebVideoLink.php +++ b/src/Links/WebVideoLink.php @@ -2,11 +2,21 @@ namespace Fluidbook\Tools\Links; -class WebVideoLink extends VideoLink { +class WebVideoLink extends VideoLink +{ - protected static $_useVideoJS = ['youtube', 'dailymotion', 'vimeo']; + protected static $_useVideoJS = ['youtube', 'dailymotion']; - public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) { + public static function cleanID($id) + { + $id = str_replace('https://vimeo.com/', '', $id); + $id = str_replace('https://player.vimeo.com/video/', '', $id); + $id = trim($id, '/ '); + return $id; + } + + public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) + { $attributes = parent::getVideoAttributes($data, $w, $h, $compiler); // Since the admin interface doesn't offer options for setting controls or sound, we will set some defaults here @@ -19,7 +29,8 @@ class WebVideoLink extends VideoLink { return $attributes; } - protected static function _normalizeVideoService($vs) { + protected static function _normalizeVideoService($vs) + { if ($vs == 0) { return 'youtube'; } else if ($vs == 1) { @@ -33,7 +44,8 @@ class WebVideoLink extends VideoLink { /** * @throws \JsonException */ - public static function getVideoSetup($data, $compiler) { + public static function getVideoSetup($data, $compiler) + { if (!self::supportVideoJS($data->video_service)) { return '[]'; } @@ -85,7 +97,8 @@ class WebVideoLink extends VideoLink { } - public function getHTMLContent() { + public function getHTMLContent() + { if (!self::supportVideoJS($this->video_service)) { return self::getEmbed($this); } @@ -96,7 +109,8 @@ class WebVideoLink extends VideoLink { return self::makeVideoTag($this, $w, $h, $this->compiler); } - public static function getEmbed($link, $width = null, $height = null) { + public static function getEmbed($link, $width = null, $height = null) + { if (null === $width) { $width = $link->width; } @@ -106,7 +120,8 @@ class WebVideoLink extends VideoLink { return ''; } - public static function getEmbedURL($data) { + public static function getEmbedURL($data) + { $muted = (!$data->video_sound_on) ? '1' : '0'; $autoplay = $data->video_auto_start ? '1' : '0'; $loop = $data->video_loop ? '1' : '0'; @@ -116,13 +131,25 @@ class WebVideoLink extends VideoLink { case 'dailymotion': return 'https://www.dailymotion.com/embed/video/' . $data->to; case 'vimeo': - return 'https://player.vimeo.com/video/' . $data->to . '?autoplay=' . $autoplay . '&loop=' . $loop . '&muted=' . $muted; + $u = parse_url($data->to); + $id = $u['path']; + $url = 'https://player.vimeo.com/video/' . $id; + parse_str($u['query'], $params); + $params['autoplay'] = $autoplay; + $params['loop'] = $loop; + $params['muted'] = $muted; + $url .= '?' . http_build_query($params); + if (isset($u['fragment']) && $u['fragment'] != '') { + $url .= '#' . $u['fragment']; + } + return $url; default: return $data->to; } } - public static function makeVideoTag($link, $width = null, $height = null, $compiler = null) { + public static function makeVideoTag($link, $width = null, $height = null, $compiler = null) + { if (self::supportVideoJS($link->video_service)) { return parent::makeVideoTag($link, $width, $height, $compiler); @@ -130,7 +157,8 @@ class WebVideoLink extends VideoLink { return self::getEmbed($link); } - protected static function supportVideoJS($service) { + protected static function supportVideoJS($service) + { return in_array(self::_normalizeVideoService($service), self::$_useVideoJS); } } diff --git a/src/Links/WebVideoPopupLink.php b/src/Links/WebVideoPopupLink.php index 0f16f60..9ceddf5 100644 --- a/src/Links/WebVideoPopupLink.php +++ b/src/Links/WebVideoPopupLink.php @@ -16,7 +16,7 @@ class WebVideoPopupLink extends VideoPopupLink return '#/webvideo/dailymotion/' . $this->to; case 2: // Vimeo case 'vimeo': - return '#/webvideo/vimeo/' . $this->to; + return '#/webvideo/vimeo/' . md5($this->to); case 3: // Brightcove case 'brightcove': return '#/webvideo/brightcove/' . md5($this->to); -- 2.39.5