X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fvideo_embed_field%2Fsrc%2FPlugin%2Fvideo_embed_field%2FProvider%2FVimeo.php;fp=web%2Fmodules%2Fcontrib%2Fvideo_embed_field%2Fsrc%2FPlugin%2Fvideo_embed_field%2FProvider%2FVimeo.php;h=70c7f6beb58cea00090af568982d83bdfe2e48ad;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/video_embed_field/src/Plugin/video_embed_field/Provider/Vimeo.php b/web/modules/contrib/video_embed_field/src/Plugin/video_embed_field/Provider/Vimeo.php new file mode 100644 index 000000000..70c7f6beb --- /dev/null +++ b/web/modules/contrib/video_embed_field/src/Plugin/video_embed_field/Provider/Vimeo.php @@ -0,0 +1,84 @@ + 'video_embed_iframe', + '#provider' => 'vimeo', + '#url' => sprintf('https://player.vimeo.com/video/%s', $this->getVideoId()), + '#query' => [ + 'autoplay' => $autoplay, + ], + '#attributes' => [ + 'width' => $width, + 'height' => $height, + 'frameborder' => '0', + 'allowfullscreen' => 'allowfullscreen', + ], + ]; + if ($time_index = $this->getTimeIndex()) { + $iframe['#fragment'] = sprintf('t=%s', $time_index); + } + return $iframe; + } + + /** + * {@inheritdoc} + */ + public function getRemoteThumbnailUrl() { + return $this->oEmbedData()->thumbnail_url; + } + + /** + * Get the vimeo oembed data. + * + * @return array + * An array of data from the oembed endpoint. + */ + protected function oEmbedData() { + return json_decode(file_get_contents('http://vimeo.com/api/oembed.json?url=' . $this->getInput())); + } + + /** + * {@inheritdoc} + */ + public static function getIdFromInput($input) { + preg_match('/^https?:\/\/(www\.)?vimeo.com\/(channels\/[a-zA-Z0-9]*\/)?(?[0-9]*)(\/[a-zA-Z0-9]+)?(\#t=(\d+)s)?$/', $input, $matches); + return isset($matches['id']) ? $matches['id'] : FALSE; + } + + /** + * Get the time index from the URL. + * + * @return string|FALSE + * A time index parameter to pass to the frame or FALSE if none is found. + */ + protected function getTimeIndex() { + preg_match('/\#t=(?(\d+)s)$/', $this->input, $matches); + return isset($matches['time_index']) ? $matches['time_index'] : FALSE; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->oEmbedData()->title; + } + +}