461c78eeba927a99d184545af88926b3941a3c3a
[yaffs-website] / web / modules / contrib / video / src / Plugin / video / Provider / Instagram.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\video\Plugin\video\Provider\Instagram.
6  */
7
8 namespace Drupal\video\Plugin\video\Provider;
9
10 use Drupal\video\ProviderPluginBase;
11
12 /**
13  * @VideoEmbeddableProvider(
14  *   id = "instagram",
15  *   label = @Translation("Instagram"),
16  *   description = @Translation("Instagram Video Provider"),
17  *   regular_expressions = {
18  *     "@^.*?instagram\.com\/p\/(?<id>(.*?))[\/]?$@i",
19  *   },
20  *   mimetype = "video/instagram",
21  *   stream_wrapper = "instagram"
22  * )
23  */
24 class Instagram 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' => '100%',
37         'frameborder' => '0',
38         'allowfullscreen' => 'allowfullscreen',
39         'src' => sprintf('//instagram.com/p/%s/embed/?autoplay=%d', $data['id'], $settings['autoplay']),
40       ],
41       '0' => array(
42         '#type' => 'html_tag',
43         '#tag' => 'script',
44         '#attributes' => array(
45              'type' => 'text/javascript',
46              'src' => '//platform.instagram.com/en_US/embeds.js',
47              'async',
48              'defer'
49         ),
50         '#value' => '',
51       ),
52     ];
53   }
54   
55   /**
56    * {@inheritdoc}
57    */
58   public function getRemoteThumbnailUrl() {
59     $data = $this->getVideoMetadata();
60     return 'http://instagr.am/p/' . $data['id'] . '/media/?size=l';
61   }
62 }