Skip to content

VimeoVanisher does not work together with EmbeddedVideoVanisher (PHP 8) #50

@josarnold

Description

@josarnold

The problem are the paths.The vimeo-path of the video is not generated properly and so no video can be displayed.

Steps to reproduce:

  1. Use the video_embed_field module to insert a Vimeo-Video via a field
  2. Add a Vimeo-URL like https://vimeo.com/123456789
  3. Enable VimeoVanisher and EmbeddedVideoVanisher in the gdpr_cookies module

Expected result:
The video resources should be loaded if allowed by the user.

Current result:
The video is not loadable because the vimeo-path is broken – actually the Video-ID is the problem.

Cause:
The URL is run through RegEx, and then put together again for the embedding, but the particular parts of the path are not calculated and combined together reliable in these two files. The result is an empty or incomplete url-path.

Files: gdpr_cookies/src/Service/VimeoVanisher.php and gdpr_cookies/src/Service/EmbeddedVideoVanisher.php

My solution:

I changed line 18 in the VimeoVanisher.php from
const VIMEO_VIDEO_ID_REGEX = '~^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$~i';

to
const VIMEO_VIDEO_ID_REGEX = '~https?:\/\/(?:www\.|player\.)?vimeo\.com\/(?:video\/)?(?<id>\d+)(?:$|[\/?])~i';

and line 45 to 57 in the EmbeddedVideoVanisher.php from

  protected function getVideoData($markup) {
    $data = array();
    $matches = array();

    $ret = preg_match_all(ThirdPartyServicesVanisher::FIND_MARKUP_ATTRIBUTES_REGEX, $markup, $matches);
    if ($ret !== FALSE && $ret > 0) {
      $data = array_combine($matches[1], $matches[4]);

      unset($data['iframe']);
    }

    return $data;
  }

to

protected function getVideoData($markup) {
  $data = array();
  $matches = array();

  $ret = preg_match_all(ThirdPartyServicesVanisher::FIND_MARKUP_ATTRIBUTES_REGEX, $markup, $matches);
  if ($ret !== FALSE && $ret > 0) {
    $data = array_combine($matches[1], $matches[4]);

    unset($data['iframe']);

    // Add https: if src only with //
    if (!empty($data['src']) && strpos($data['src'], '//') === 0) {
      $data['src'] = 'https:' . $data['src'];
    }

    // Set default values
    if (!isset($data['width'])) {
      $data['width'] = '640';
    }
    if (!isset($data['height'])) {
      $data['height'] = '360';
    }
  }

  return $data;
}

That does the trick.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions