Version 1
[yaffs-website] / web / modules / contrib / video / src / Plugin / video / Provider / Vine.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\video\Plugin\video\Provider\Vine.
6  */
7
8 namespace Drupal\video\Plugin\video\Provider;
9
10 use Drupal\video\ProviderPluginBase;
11
12 /**
13  * @VideoEmbeddableProvider(
14  *   id = "vine",
15  *   label = @Translation("Vine"),
16  *   description = @Translation("Vine Video Provider"),
17  *   regular_expressions = {
18  *     "@(?<=vine.co/v/)(?<id>[0-9A-Za-z]+)@i",
19  *   },
20  *   mimetype = "video/vine",
21  *   stream_wrapper = "vine"
22  * )
23  */
24 class Vine extends ProviderPluginBase {
25   /**
26    * {@inheritdoc}
27    */
28   public function renderEmbedCode($settings) {
29     $file = $this->getVideoFile();
30     $data = $this->getVideoMetadata();
31     return [
32       '#type' => 'html_tag',
33       '#tag' => 'iframe',
34       '#attributes' => [
35         'width' => $settings['width'],
36         'height' => $settings['height'],
37         'frameborder' => '0',
38         'allowfullscreen' => 'allowfullscreen',
39         'src' => sprintf('https://vine.co/v/%s/embed/simple?autoPlay=%d', $data['id'], $settings['autoplay']),
40       ],
41     ];
42   }
43   
44   /**
45    * {@inheritdoc}
46    */
47   public function getRemoteThumbnailUrl() {
48     $data = $this->getVideoMetadata();
49     $id = $data['id'];
50     $vine = file_get_contents("http://vine.co/v/{$id}");
51       preg_match('/property="og:image" content="(.*?)"/', $vine, $matches);
52       return ($matches[1]) ? $matches[1] : false;
53   }
54 }