| @@ -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 { |
| @@ -27,15 +27,11 @@ | ||
| 27 | 27 | * |
| 28 | 28 | * @var array Provider URL structure regex. |
| 29 | 29 | */ |
| 30 | 30 | private static $provider_match_masks = [ |
| 31 | - '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)\/))([^\?&\"\'>]+)/', | |
| 32 | 32 | 'vimeo' => '/^.*vimeo\.com\/(?:[a-z]*\/)*([0-9]{6,11})[?]?.*/', |
| 33 | 33 | 'dailymotion' => '/^.*dailymotion.com\/(?:video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/', |
| 34 | - 'videopress' => [ | |
| 35 | - '/^(?:http(?:s)?:\/\/)?videos\.files\.wordpress\.com\/([a-zA-Z\d]{8,})\//i', | |
| 36 | - '/^(?:http(?:s)?:\/\/)?(?:www\.)?video(?:\.word)?press\.com\/(?:v|embed)\/([a-zA-Z\d]{8,})(.+)?/i', | |
| 37 | - ], | |
| 38 | 34 | ]; |
| 39 | 35 | |
| 40 | 36 | /** |
| 41 | 37 | * Embed patterns. |
| @@ -51,9 +47,8 @@ | ||
| 51 | 47 | private static $embed_patterns = [ |
| 52 | 48 | 'youtube' => 'https://www.youtube{NO_COOKIE}.com/embed/{VIDEO_ID}?feature=oembed', |
| 53 | 49 | 'vimeo' => 'https://player.vimeo.com/video/{VIDEO_ID}#t={TIME}', |
| 54 | 50 | 'dailymotion' => 'https://dailymotion.com/embed/video/{VIDEO_ID}', |
| 55 | - 'videopress' => 'https://videopress.com/embed/{VIDEO_ID}', | |
| 56 | 51 | ]; |
| 57 | 52 | |
| 58 | 53 | /** |
| 59 | 54 | * Get video properties. |
| @@ -69,19 +64,15 @@ | ||
| 69 | 64 | * @return null|array The video properties, or null. |
| 70 | 65 | */ |
| 71 | 66 | public static function get_video_properties( $video_url ) { |
| 72 | 67 | foreach ( self::$provider_match_masks as $provider => $match_mask ) { |
| 73 | - if ( ! is_array( $match_mask ) ) { | |
| 74 | - $match_mask = [ $match_mask ]; | |
| 75 | - } | |
| 68 | + preg_match( $match_mask, $video_url, $matches ); | |
| 76 | 69 | |
| 77 | - foreach ( $match_mask as $mask ) { | |
| 78 | - if ( preg_match( $mask, $video_url, $matches ) ) { | |
| 79 | - return [ | |
| 80 | - 'provider' => $provider, | |
| 81 | - 'video_id' => $matches[1], | |
| 82 | - ]; | |
| 83 | - } | |
| 70 | + if ( $matches ) { | |
| 71 | + return [ | |
| 72 | + 'provider' => $provider, | |
| 73 | + 'video_id' => $matches[1], | |
| 74 | + ]; | |
| 84 | 75 | } |
| 85 | 76 | } |
| 86 | 77 | |
| 87 | 78 | return null; |
| @@ -126,28 +117,8 @@ | ||
| 126 | 117 | $time_text = date( 'H\hi\ms\s', $options['start'] ); // PHPCS:Ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 127 | 118 | } |
| 128 | 119 | |
| 129 | 120 | $replacements['{TIME}'] = $time_text; |
| 130 | - | |
| 131 | - /** | |
| 132 | - * Handle Vimeo private videos | |
| 133 | - * | |
| 134 | - * Vimeo requires an additional parameter when displaying private/unlisted videos. It has two ways of | |
| 135 | - * passing that parameter: | |
| 136 | - * * as an endpoint - vimeo.com/{video_id}/{privacy_token} | |
| 137 | - * OR | |
| 138 | - * * as a GET parameter named `h` - vimeo.com/{video_id}?h={privacy_token} | |
| 139 | - * | |
| 140 | - * The following regex match looks for either of these methods in the Vimeo URL, and if it finds a privacy | |
| 141 | - * token, it adds it to the embed params array as the `h` parameter (which is how Vimeo can receive it when | |
| 142 | - * using Oembed). | |
| 143 | - */ | |
| 144 | - $h_param = []; | |
| 145 | - preg_match( '/(?|(?:[\?|\&]h={1})([\w]+)|\d\/([\w]+))/', $video_url, $h_param ); | |
| 146 | - | |
| 147 | - if ( ! empty( $h_param ) ) { | |
| 148 | - $embed_url_params['h'] = $h_param[1]; | |
| 149 | - } | |
| 150 | 121 | } |
| 151 | 122 | |
| 152 | 123 | $embed_pattern = str_replace( array_keys( $replacements ), $replacements, $embed_pattern ); |
| 153 | 124 | |
| @@ -178,9 +149,8 @@ | ||
| 178 | 149 | |
| 179 | 150 | $default_frame_attributes = [ |
| 180 | 151 | 'class' => 'elementor-video-iframe', |
| 181 | 152 | 'allowfullscreen', |
| 182 | - 'allow' => 'clipboard-write', | |
| 183 | 153 | 'title' => sprintf( |
| 184 | 154 | /* translators: %s: Video provider */ |
| 185 | 155 | __( '%s Video Player', 'elementor' ), |
| 186 | 156 | $video_properties['provider'] |
| @@ -190,18 +160,14 @@ | ||
| 190 | 160 | $video_embed_url = self::get_embed_url( $video_url, $embed_url_params, $options ); |
| 191 | 161 | if ( ! $video_embed_url ) { |
| 192 | 162 | return null; |
| 193 | 163 | } |
| 194 | - if ( ! isset( $options['lazy_load'] ) || ! $options['lazy_load'] ) { | |
| 164 | + if ( ! $options['lazy_load'] ) { | |
| 195 | 165 | $default_frame_attributes['src'] = $video_embed_url; |
| 196 | 166 | } else { |
| 197 | 167 | $default_frame_attributes['data-lazy-load'] = $video_embed_url; |
| 198 | 168 | } |
| 199 | 169 | |
| 200 | - if ( isset( $embed_url_params['autoplay'] ) ) { | |
| 201 | - $default_frame_attributes['allow'] = 'autoplay'; | |
| 202 | - } | |
| 203 | - | |
| 204 | 170 | $frame_attributes = array_merge( $default_frame_attributes, $frame_attributes ); |
| 205 | 171 | |
| 206 | 172 | $attributes_for_print = []; |
| 207 | 173 | |
| @@ -226,10 +192,10 @@ | ||
| 226 | 192 | /** |
| 227 | 193 | * Get oembed data from the cache. |
| 228 | 194 | * if not exists in the cache it will fetch from provider and then save to the cache. |
| 229 | 195 | * |
| 230 | - * @param string $oembed_url | |
| 231 | - * @param string $cached_post_id | |
| 196 | + * @param $oembed_url | |
| 197 | + * @param $cached_post_id | |
| 232 | 198 | * |
| 233 | 199 | * @return array|null |
| 234 | 200 | */ |
| 235 | 201 | public static function get_oembed_data( $oembed_url, $cached_post_id ) { |
| @@ -257,9 +223,10 @@ | ||
| 257 | 223 | |
| 258 | 224 | /** |
| 259 | 225 | * Fetch oembed data from oembed provider. |
| 260 | 226 | * |
| 261 | - * @param string $oembed_url | |
| 227 | + * @param $oembed_url | |
| 228 | + * | |
| 262 | 229 | * @return array|null |
| 263 | 230 | */ |
| 264 | 231 | public static function fetch_oembed_data( $oembed_url ) { |
| 265 | 232 | $oembed_data = _wp_oembed_get_object()->get_data( $oembed_url ); |
| @@ -274,9 +241,9 @@ | ||
| 274 | 241 | ]; |
| 275 | 242 | } |
| 276 | 243 | |
| 277 | 244 | /** |
| 278 | - * @param string $oembed_url | |
| 245 | + * @param $oembed_url | |
| 279 | 246 | * @param null|string|int $cached_post_id |
| 280 | 247 | * |
| 281 | 248 | * @return string|null |
| 282 | 249 | */ |
| @@ -286,7 +253,7 @@ | ||
| 286 | 253 | if ( ! $oembed_data ) { |
| 287 | 254 | return null; |
| 288 | 255 | } |
| 289 | 256 | |
| 290 | - 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>'; | |
| 291 | 258 | } |
| 292 | 259 | } |