Wistia.php in Video Filter 8        
                          
                  
                        
  
  
  
  
  
File
  src/Plugin/VideoFilter/Wistia.php
  
    View source  
  <?php
namespace Drupal\video_filter\Plugin\VideoFilter;
use Drupal\video_filter\VideoFilterBase;
class Wistia extends VideoFilterBase {
  
  
  public function html($video) {
    $video_code = $video['codec']['matches'][7];
    $matches = $video['codec']['matches'];
    $embed_type = $matches[4] == 'projects' || $matches[6] == 'playlists' ? 'playlists' : 'iframe';
    
    $endpoint = 'http://fast.wistia.com/oembed?url=http://fast.wistia.com/embed/' . $embed_type . '/' . $video_code . '&width=' . $video['width'] . '&height=' . $video['height'];
    $request = \Drupal::httpClient()
      ->get($endpoint, [
      'headers' => [
        'Accept' => 'application/json',
      ],
    ]);
    if ($request
      ->getStatusCode() == 200) {
      $response = json_decode($request
        ->getBody());
    }
    $html = !empty($response->html) ? $response->html : '';
    
    $pattern = '@https?://fast.wistia.(com|net)/embed/(iframe|playlists)/[a-zA-Z0-9]+\\?+.+@';
    $matches = [];
    if (preg_match($pattern, $video['source'], $matches)) {
      
      $pattern = '@https?://fast.wistia.(com|net)/embed/(iframe|playlists)/[a-zA-Z0-9]+\\?[^"]+@';
      $replacement = $matches[0];
      $html = preg_replace($pattern, $replacement, $html);
    }
    return $html;
  }
}
 
Classes
        
  
  
      
      
         
      
                  
            Name            | 
                  
            Description           | 
              
    
    
          
                  | 
            Wistia           | 
                  
            Provides Wistia codec for Video Filter.           |