You are here

public function Rutube::iframe in Video Filter 8

HTML5 video (iframe).

Overrides VideoFilterBase::iframe

File

src/Plugin/VideoFilter/Rutube.php, line 25

Class

Rutube
Provides Rutube codec for Video Filter.

Namespace

Drupal\video_filter\Plugin\VideoFilter

Code

public function iframe($video) {
  $attributes = [
    'skinColor' => isset($video['skinColor']) && !empty($video['standardColor']) ? 'skinColor=' . (string) $video['skinColor'] : '',
    'sTitle' => isset($video['sTitle']) && $video['sTitle'] == 1 ? 'sTitle=true' : 'sTitle=false',
    'sAuthor' => isset($video['sAuthor']) && $video['sAuthor'] == 1 ? 'sAuthor=true' : 'sAuthor=false',
    'bmstart' => isset($video['bmstart']) && $video['bmstart'] > 1 ? 'bmstart=' . (int) $video['bmstart'] : 'bmstart=false',
  ];
  $endpoint = 'http://rutube.ru/api/oembed/?url=' . $video['source'] . '&format=json';
  $request = \Drupal::httpClient()
    ->get($endpoint, [
    'headers' => [
      'Accept' => 'application/json',
    ],
  ]);
  if ($request
    ->getStatusCode() == 200) {
    $response = json_decode($request
      ->getBody());
  }
  if (!empty($response->html)) {
    if (preg_match('/src="([^"]+)"/', $response->html, $match)) {
      return [
        'src' => $match[1] . '?' . implode('&', $attributes),
        'properties' => [
          'webkitAllowFullScreen' => 'true',
          'mozallowfullscreen' => 'true',
          'allowfullscreen' => 'true',
        ],
      ];
    }
  }
}