Skip to content

Commit

Permalink
feat: Added support for events on vimeo provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mpratt committed Nov 16, 2023
1 parent c3deacc commit b4a590c
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/Embera/Provider/Vimeo.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Vimeo.php
*
Expand Down Expand Up @@ -30,7 +31,7 @@ class Vimeo extends ProviderAdapter implements ProviderInterface
protected static $hosts = [
'vimeo.com'
];

/** inline {@inheritdoc} */
protected $allowedParams = [
'autopause', 'autopip', 'autoplay', 'background', 'byline', 'color',
Expand All @@ -45,9 +46,9 @@ class Vimeo extends ProviderAdapter implements ProviderInterface
/** inline {@inheritdoc} */
public function validateUrl(Url $url)
{
return (bool) (
preg_match('~vimeo\.com/(?:[0-9]{5,})$~i', (string) $url) ||
return (bool) (preg_match('~vimeo\.com/(?:[0-9]{5,})$~i', (string) $url) ||
preg_match('~vimeo\.com/channels/(?:[^/]+)/(?:[^/]+)~i', (string) $url) ||
preg_match('~vimeo\.com/event/(?:[^/]+)/(?:[^/]+)~i', (string) $url) ||
preg_match('~vimeo\.com/groups/(?:[^/]+)/videos/(?:[^/]+)~i', (string) $url) ||
preg_match('~vimeo\.com/ondemand/(?:[^/]+)/(?:[^/]+)~i', (string) $url) ||
preg_match('~vimeo\.com/(?:[0-9]{5,})/(?:[0-9a-z]+)$~i', (string) $url) ||
Expand All @@ -62,34 +63,33 @@ public function normalizeUrl(Url $url)
$url->removeQueryString();
$url->removeLastSlash();

if (preg_match('~(?:vimeo\.com/|player\.vimeo\.com/video/)(\d+)~i', (string) $url, $matches)) {
$url->overwrite('https://player.vimeo.com/video/' . $matches[1]);
}
if (preg_match('~(?:vimeo\.com/|player\.vimeo\.com/video/)(\d+)~i', (string) $url, $matches)) {
$url->overwrite('https://player.vimeo.com/video/' . $matches[1]);
}

return $url;
}

/** inline {@inheritdoc} */
public function getFakeResponse()
{
/** inline {@inheritdoc} */
public function getFakeResponse()
{
preg_match('/(?:https?:\/\/)?(?:www\.)?(?:vimeo\.com\/(?:video\/)?)?([0-9]+)(?:[a-zA-Z0-9_-]+)?/', (string) $this->url, $matches);
$embedUrl = 'https://player.vimeo.com/video/' . $matches['1'];

$attr = [];
$attr[] = 'src="' . $embedUrl . '"';
$attr[] = 'width="{width}"';
$attr[] = 'height="{height}"';
$attr[] = 'frameborder="0"';
$attr[] = 'allow="autoplay; fullscreen; picture-in-picture"';
$attr[] = 'allowfullscreen';

return [
'type' => 'video',
'provider_name' => 'Vimeo',
'provider_url' => 'https://vimeo.com',
'title' => 'Unknown title',
'html' => '<iframe ' . implode(' ', $attr). '></iframe>',
];
}
$attr = [];
$attr[] = 'src="' . $embedUrl . '"';
$attr[] = 'width="{width}"';
$attr[] = 'height="{height}"';
$attr[] = 'frameborder="0"';
$attr[] = 'allow="autoplay; fullscreen; picture-in-picture"';
$attr[] = 'allowfullscreen';

return [
'type' => 'video',
'provider_name' => 'Vimeo',
'provider_url' => 'https://vimeo.com',
'title' => 'Unknown title',
'html' => '<iframe ' . implode(' ', $attr) . '></iframe>',
];
}
}

0 comments on commit b4a590c

Please sign in to comment.