| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * Elementor embed. |
| 10 | 10 | * |
| 11 | 11 | * Elementor embed handler class is responsible for Elementor embed functionality. |
| 12 | 12 | * The class holds the supported providers with their embed patters, and handles |
| 13 | - * their custom properties to create custom HTML with the embedded content. | |
| 13 | + * their custom properties to create custom HTML with the embeded content. | |
| 14 | 14 | * |
| 15 | 15 | * @since 1.5.0 |
| 16 | 16 | */ |
| 17 | 17 | class Embed { |
| @@ -16,25 +16,8 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | class Embed { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Embeddable background video providers. | |
| 21 | - * | |
| 22 | - * Holds the list of providers whose background video is rendered as an embedded | |
| 23 | - * iframe player (.elementor-background-video-embed) rather than a hosted <video> | |
| 24 | - * element. This is intentionally a SUBSET of the providers recognized by | |
| 25 | - * get_video_properties() — the frontend background-video handler only mounts | |
| 26 | - * YouTube/Vimeo players, so other providers must fall through to hosted rendering. | |
| 27 | - * | |
| 28 | - * @access private | |
| 29 | - * @static | |
| 30 | - * | |
| 31 | - * @var array Embeddable background video provider slugs. | |
| 32 | - */ | |
| 33 | - private static $video_embed_providers = [ 'youtube', 'vimeo' ]; | |
| 34 | - | |
| 35 | - | |
| 36 | - /** | |
| 37 | 20 | * Provider match masks. |
| 38 | 21 | * |
| 39 | 22 | * Holds a list of supported providers with their URL structure in a regex format. |
| 40 | 23 | * |
| @@ -44,15 +27,11 @@ | ||
| 44 | 27 | * |
| 45 | 28 | * @var array Provider URL structure regex. |
| 46 | 29 | */ |
| 47 | 30 | private static $provider_match_masks = [ |
| 48 | - 'youtube' => '/^.*(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/(?:(?:watch)?\?(?:.*&)?vi?=|(?:embed|v|vi|user|shorts)\/))([^\?&\"\'>]+)/', | |
| 31 | + 'youtube' => '/^.*(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/(?:(?:watch)?\?(?:.*&)?vi?=|(?:embed|v|vi|user)\/))([^\?&\"\'>]+)/', | |
| 49 | 32 | 'vimeo' => '/^.*vimeo\.com\/(?:[a-z]*\/)*([0-9]{6,11})[?]?.*/', |
| 50 | 33 | 'dailymotion' => '/^.*dailymotion.com\/(?:video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/', |
| 51 | - 'videopress' => [ | |
| 52 | - '/^(?:http(?:s)?:\/\/)?videos\.files\.wordpress\.com\/([a-zA-Z\d]{8,})\//i', | |
| 53 | - '/^(?:http(?:s)?:\/\/)?(?:www\.)?video(?:\.word)?press\.com\/(?:v|embed)\/([a-zA-Z\d]{8,})(.+)?/i', | |
| 54 | - ], | |
| 55 | 34 | ]; |
| 56 | 35 | |
| 57 | 36 | /** |
| 58 | 37 | * Embed patterns. |
| @@ -68,9 +47,8 @@ | ||
| 68 | 47 | private static $embed_patterns = [ |
| 69 | 48 | 'youtube' => 'https://www.youtube{NO_COOKIE}.com/embed/{VIDEO_ID}?feature=oembed', |
| 70 | 49 | 'vimeo' => 'https://player.vimeo.com/video/{VIDEO_ID}#t={TIME}', |
| 71 | 50 | 'dailymotion' => 'https://dailymotion.com/embed/video/{VIDEO_ID}', |
| 72 | - 'videopress' => 'https://videopress.com/embed/{VIDEO_ID}', | |
| 73 | 51 | ]; |
| 74 | 52 | |
| 75 | 53 | /** |
| 76 | 54 | * Get video properties. |
| @@ -86,19 +64,15 @@ | ||
| 86 | 64 | * @return null|array The video properties, or null. |
| 87 | 65 | */ |
| 88 | 66 | public static function get_video_properties( $video_url ) { |
| 89 | 67 | foreach ( self::$provider_match_masks as $provider => $match_mask ) { |
| 90 | - if ( ! is_array( $match_mask ) ) { | |
| 91 | - $match_mask = [ $match_mask ]; | |
| 92 | - } | |
| 68 | + preg_match( $match_mask, $video_url, $matches ); | |
| 93 | 69 | |
| 94 | - foreach ( $match_mask as $mask ) { | |
| 95 | - if ( preg_match( $mask, $video_url, $matches ) ) { | |
| 96 | - return [ | |
| 97 | - 'provider' => $provider, | |
| 98 | - 'video_id' => $matches[1], | |
| 99 | - ]; | |
| 100 | - } | |
| 70 | + if ( $matches ) { | |
| 71 | + return [ | |
| 72 | + 'provider' => $provider, | |
| 73 | + 'video_id' => $matches[1], | |
| 74 | + ]; | |
| 101 | 75 | } |
| 102 | 76 | } |
| 103 | 77 | |
| 104 | 78 | return null; |
| @@ -104,24 +78,8 @@ | ||
| 104 | 78 | return null; |
| 105 | 79 | } |
| 106 | 80 | |
| 107 | 81 | /** |
| 108 | - * Is embeddable background video. | |
| 109 | - * | |
| 110 | - * Whether a given video URL belongs to a provider that the frontend | |
| 111 | - * background-video handler renders as an embedded iframe player. | |
| 112 | - * | |
| 113 | - * @param string $video_url Video URL. | |
| 114 | - * | |
| 115 | - * @return bool | |
| 116 | - **/ | |
| 117 | - public static function is_embed_video( $video_url ) { | |
| 118 | - $video_properties = self::get_video_properties( $video_url ); | |
| 119 | - | |
| 120 | - return null !== $video_properties && in_array( $video_properties['provider'], self::$video_embed_providers, true ); | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | 82 | * Get embed URL. |
| 125 | 83 | * |
| 126 | 84 | * Retrieve the embed URL for a given video. |
| 127 | 85 | * |
| @@ -159,28 +117,8 @@ | ||
| 159 | 117 | $time_text = date( 'H\hi\ms\s', $options['start'] ); // PHPCS:Ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 160 | 118 | } |
| 161 | 119 | |
| 162 | 120 | $replacements['{TIME}'] = $time_text; |
| 163 | - | |
| 164 | - /** | |
| 165 | - * Handle Vimeo private videos | |
| 166 | - * | |
| 167 | - * Vimeo requires an additional parameter when displaying private/unlisted videos. It has two ways of | |
| 168 | - * passing that parameter: | |
| 169 | - * * as an endpoint - vimeo.com/{video_id}/{privacy_token} | |
| 170 | - * OR | |
| 171 | - * * as a GET parameter named `h` - vimeo.com/{video_id}?h={privacy_token} | |
| 172 | - * | |
| 173 | - * The following regex match looks for either of these methods in the Vimeo URL, and if it finds a privacy | |
| 174 | - * token, it adds it to the embed params array as the `h` parameter (which is how Vimeo can receive it when | |
| 175 | - * using Oembed). | |
| 176 | - */ | |
| 177 | - $h_param = []; | |
| 178 | - preg_match( '/(?|(?:[\?|\&]h={1})([\w]+)|\d\/([\w]+))/', $video_url, $h_param ); | |
| 179 | - | |
| 180 | - if ( ! empty( $h_param ) ) { | |
| 181 | - $embed_url_params['h'] = $h_param[1]; | |
| 182 | - } | |
| 183 | 121 | } |
| 184 | 122 | |
| 185 | 123 | $embed_pattern = str_replace( array_keys( $replacements ), $replacements, $embed_pattern ); |
| 186 | 124 | |
| @@ -211,9 +149,8 @@ | ||
| 211 | 149 | |
| 212 | 150 | $default_frame_attributes = [ |
| 213 | 151 | 'class' => 'elementor-video-iframe', |
| 214 | 152 | 'allowfullscreen', |
| 215 | - 'allow' => 'clipboard-write', | |
| 216 | 153 | 'title' => sprintf( |
| 217 | 154 | /* translators: %s: Video provider */ |
| 218 | 155 | __( '%s Video Player', 'elementor' ), |
| 219 | 156 | $video_properties['provider'] |
| @@ -223,18 +160,14 @@ | ||
| 223 | 160 | $video_embed_url = self::get_embed_url( $video_url, $embed_url_params, $options ); |
| 224 | 161 | if ( ! $video_embed_url ) { |
| 225 | 162 | return null; |
| 226 | 163 | } |
| 227 | - if ( ! isset( $options['lazy_load'] ) || ! $options['lazy_load'] ) { | |
| 164 | + if ( ! $options['lazy_load'] ) { | |
| 228 | 165 | $default_frame_attributes['src'] = $video_embed_url; |
| 229 | 166 | } else { |
| 230 | 167 | $default_frame_attributes['data-lazy-load'] = $video_embed_url; |
| 231 | 168 | } |
| 232 | 169 | |
| 233 | - if ( isset( $embed_url_params['autoplay'] ) ) { | |
| 234 | - $default_frame_attributes['allow'] = 'autoplay'; | |
| 235 | - } | |
| 236 | - | |
| 237 | 170 | $frame_attributes = array_merge( $default_frame_attributes, $frame_attributes ); |
| 238 | 171 | |
| 239 | 172 | $attributes_for_print = []; |
| 240 | 173 | |
| @@ -259,10 +192,10 @@ | ||
| 259 | 192 | /** |
| 260 | 193 | * Get oembed data from the cache. |
| 261 | 194 | * if not exists in the cache it will fetch from provider and then save to the cache. |
| 262 | 195 | * |
| 263 | - * @param string $oembed_url | |
| 264 | - * @param string $cached_post_id | |
| 196 | + * @param $oembed_url | |
| 197 | + * @param $cached_post_id | |
| 265 | 198 | * |
| 266 | 199 | * @return array|null |
| 267 | 200 | */ |
| 268 | 201 | public static function get_oembed_data( $oembed_url, $cached_post_id ) { |
| @@ -290,9 +223,10 @@ | ||
| 290 | 223 | |
| 291 | 224 | /** |
| 292 | 225 | * Fetch oembed data from oembed provider. |
| 293 | 226 | * |
| 294 | - * @param string $oembed_url | |
| 227 | + * @param $oembed_url | |
| 228 | + * | |
| 295 | 229 | * @return array|null |
| 296 | 230 | */ |
| 297 | 231 | public static function fetch_oembed_data( $oembed_url ) { |
| 298 | 232 | $oembed_data = _wp_oembed_get_object()->get_data( $oembed_url ); |
| @@ -307,9 +241,9 @@ | ||
| 307 | 241 | ]; |
| 308 | 242 | } |
| 309 | 243 | |
| 310 | 244 | /** |
| 311 | - * @param string $oembed_url | |
| 245 | + * @param $oembed_url | |
| 312 | 246 | * @param null|string|int $cached_post_id |
| 313 | 247 | * |
| 314 | 248 | * @return string|null |
| 315 | 249 | */ |
| @@ -319,7 +253,7 @@ | ||
| 319 | 253 | if ( ! $oembed_data ) { |
| 320 | 254 | return null; |
| 321 | 255 | } |
| 322 | 256 | |
| 323 | - return '<div class="elementor-image">' . sprintf( '<img src="%1$s" alt="%2$s" title="%2$s" width="%3$s" loading="lazy" />', $oembed_data['thumbnail_url'], esc_attr( $oembed_data['title'] ), '100%' ) . '</div>'; | |
| 257 | + return '<div class="elementor-image">' . sprintf( '<img src="%1$s" alt="%2$s" title="%2$s" width="%3$s" />', $oembed_data['thumbnail_url'], esc_attr( $oembed_data['title'] ), '100%' ) . '</div>'; | |
| 324 | 258 | } |
| 325 | 259 | } |