]> _ Git - fluidbook_tools.git/commitdiff
wait #7050 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 22 Aug 2024 10:15:07 +0000 (12:15 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 22 Aug 2024 10:15:07 +0000 (12:15 +0200)
src/Links/Link.php
src/Links/WebVideoLink.php
src/Links/WebVideoPopupLink.php

index 3602b398f75878c7d83455814b25908f2845f421..fcd07a64efed196ae8ec2138eece3d96aa5be045 100644 (file)
@@ -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);
                 }
index 86d230fb06c416f6851e6184073313b2ab6f7481..742286775457c84e9181465b7bfea992a6963acc 100644 (file)
@@ -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 '<iframe width="' . $width . '" height="' . $height . '" src="' . self::getEmbedURL($link) . '" frameborder="0" allowfullscreen allow="autoplay; fullscreen"></iframe>';
     }
 
-    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);
     }
 }
index 0f16f6086d041b92fab450ebf8bc8317b6370a38..9ceddf5e64c16ebf037195620e63cf7503f401e1 100644 (file)
@@ -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);