| @@ -14,8 +14,12 @@ | ||
| 14 | 14 | * |
| 15 | 15 | * @package automattic/jetpack |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 19 | + exit( 0 ); | |
| 20 | +} | |
| 21 | + | |
| 18 | 22 | /** |
| 19 | 23 | * Transform embed to shortcode on save. |
| 20 | 24 | * |
| 21 | 25 | * @param string $content Post content. |
| @@ -26,9 +30,9 @@ | ||
| 26 | 30 | if ( ! is_string( $content ) ) { |
| 27 | 31 | return $content; |
| 28 | 32 | } |
| 29 | 33 | |
| 30 | - if ( false !== strpos( $content, '<div class="flickr_video"' ) && false !== strpos( $content, '<video' ) ) { | |
| 34 | + if ( str_contains( $content, '<div class="flickr_video"' ) && str_contains( $content, '<video' ) ) { | |
| 31 | 35 | return jetpack_flickr_video_to_shortcode( $content ); |
| 32 | 36 | } elseif ( preg_match( '/<iframe src="(https?:)?\/\/([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)\/[^\"]+\"/', $content ) ) { |
| 33 | 37 | return jetpack_flickr_photo_to_shortcode( $content ); |
| 34 | 38 | } |
| @@ -37,9 +41,9 @@ | ||
| 37 | 41 | } |
| 38 | 42 | |
| 39 | 43 | /** |
| 40 | 44 | * Transforms embed to shortcode on save when the photo param is used. |
| 41 | - * If embed content can not be transformed to a valid shortcode, | |
| 45 | + * If embed content cannot be transformed to a valid shortcode, | |
| 42 | 46 | * the embed content itself is returned. |
| 43 | 47 | * |
| 44 | 48 | * @param string $content Embed output. |
| 45 | 49 | * |
| @@ -63,9 +67,9 @@ | ||
| 63 | 67 | } |
| 64 | 68 | |
| 65 | 69 | /** |
| 66 | 70 | * Transforms embed to shortcode on save when the video param is used. |
| 67 | - * If embed content can not be transformed to a valid shortcode, | |
| 71 | + * If embed content cannot be transformed to a valid shortcode, | |
| 68 | 72 | * the embed content itself is returned. |
| 69 | 73 | * |
| 70 | 74 | * @param string $content Embed output. |
| 71 | 75 | * |
| @@ -90,11 +94,11 @@ | ||
| 90 | 94 | $width = empty( $matches[2] ) ? '' : 'w=' . esc_attr( $matches[2] ); |
| 91 | 95 | |
| 92 | 96 | $height = empty( $matches[4] ) ? '' : 'h=' . esc_attr( $matches[4] ); |
| 93 | 97 | |
| 94 | - $controls = false !== strpos( $content, 'controls' ) ? 'yes' : 'no'; | |
| 98 | + $controls = str_contains( $content, 'controls' ) ? 'yes' : 'no'; | |
| 95 | 99 | |
| 96 | - $autoplay = false !== strpos( $content, 'autoplay' ) ? 'yes' : 'no'; | |
| 100 | + $autoplay = str_contains( $content, 'autoplay' ) ? 'yes' : 'no'; | |
| 97 | 101 | |
| 98 | 102 | /** This action is documented in modules/shortcodes/youtube.php */ |
| 99 | 103 | do_action( 'jetpack_embed_to_shortcode', 'flickr_video', $video_src ); |
| 100 | 104 | |
| @@ -100,9 +104,11 @@ | ||
| 100 | 104 | |
| 101 | 105 | return '[flickr video="' . $video_src . '" ' . $width . ' ' . $height . ' controls="' . $controls . '" autoplay="' . $autoplay . '"]'; |
| 102 | 106 | } |
| 103 | 107 | |
| 104 | -add_filter( 'pre_kses', 'flickr_embed_to_shortcode' ); | |
| 108 | +if ( jetpack_shortcodes_should_hook_pre_kses() ) { | |
| 109 | + add_filter( 'pre_kses', 'flickr_embed_to_shortcode' ); | |
| 110 | +} | |
| 105 | 111 | |
| 106 | 112 | /** |
| 107 | 113 | * Flickr Shortcode handler. |
| 108 | 114 | * |
| @@ -187,10 +193,9 @@ | ||
| 187 | 193 | if ( ! is_numeric( $video_param ) ) { |
| 188 | 194 | $video_url = $video_param; |
| 189 | 195 | } else { |
| 190 | 196 | // Get the URL of the video from the page of the video. |
| 191 | - $video_page_content = wp_remote_get( "http://flickr.com/photo.gne?id=$video_param" ); | |
| 192 | - | |
| 197 | + $video_page_content = wp_remote_get( "https://flickr.com/photo.gne?id=$video_param" ); | |
| 193 | 198 | // Bail if we do not get any info from Flickr. |
| 194 | 199 | if ( is_wp_error( $video_page_content ) ) { |
| 195 | 200 | return ''; |
| 196 | 201 | } |
| @@ -212,8 +217,11 @@ | ||
| 212 | 217 | |
| 213 | 218 | // Get the embed url. |
| 214 | 219 | preg_match( '/src=\"([^\"]+)\"/', $data['html'], $matches ); |
| 215 | 220 | |
| 221 | + if ( empty( $matches[1] ) ) { | |
| 222 | + return ''; | |
| 223 | + } | |
| 216 | 224 | $embed_url = $matches[1]; |
| 217 | 225 | |
| 218 | 226 | $embed_page = wp_remote_get( $embed_url ); |
| 219 | 227 | |
| @@ -224,12 +232,12 @@ | ||
| 224 | 232 | |
| 225 | 233 | // Get the video url from embed html markup. |
| 226 | 234 | |
| 227 | 235 | preg_match( '/video.+src=\"([^\"]+)\"/', $embed_page['body'], $matches ); |
| 228 | - | |
| 229 | - $video_src = $matches[1]; | |
| 230 | - | |
| 231 | - set_transient( $transient_name, $video_src, 2592000 ); // 30 days transient. | |
| 236 | + if ( ! empty( $matches[1] ) ) { | |
| 237 | + $video_src = $matches[1]; | |
| 238 | + set_transient( $transient_name, $video_src, 2592000 ); // 30 days transient. | |
| 239 | + } | |
| 232 | 240 | } |
| 233 | 241 | |
| 234 | 242 | $style = 'max-width: 100%;'; |
| 235 | 243 | |
| @@ -288,11 +296,11 @@ | ||
| 288 | 296 | * Callback to modify output of embedded Vimeo video using Jetpack's shortcode. |
| 289 | 297 | * |
| 290 | 298 | * @since 3.9 |
| 291 | 299 | * |
| 292 | - * @param array $matches Regex partial matches against the URL passed. | |
| 293 | - * @param array $attr Attributes received in embed response. | |
| 294 | - * @param array $url Requested URL to be embedded. | |
| 300 | + * @param array $matches Regex partial matches against the URL passed. | |
| 301 | + * @param array $attr Attributes received in embed response. | |
| 302 | + * @param string $url Requested URL to be embedded. | |
| 295 | 303 | * |
| 296 | 304 | * @return string Return output of Vimeo shortcode with the proper markup. |
| 297 | 305 | */ |
| 298 | 306 | function jetpack_flickr_oembed_handler( $matches, $attr, $url ) { |
| @@ -297,13 +305,13 @@ | ||
| 297 | 305 | */ |
| 298 | 306 | function jetpack_flickr_oembed_handler( $matches, $attr, $url ) { |
| 299 | 307 | /* |
| 300 | 308 | * Legacy slideshow embeds end with /show/ |
| 301 | - * e.g. http://www.flickr.com/photos/yarnaholic/sets/72157615194738969/show/ | |
| 309 | + * e.g. https://www.flickr.com/photos/yarnaholic/sets/72157615194738969/show/ | |
| 302 | 310 | */ |
| 303 | 311 | if ( '/show/' !== substr( $url, -strlen( '/show/' ) ) ) { |
| 304 | 312 | // These lookups need cached, as they don't use WP_Embed (which caches). |
| 305 | - $cache_key = md5( $url . wp_json_encode( $attr ) ); | |
| 313 | + $cache_key = md5( $url . wp_json_encode( $attr, JSON_UNESCAPED_SLASHES ) ); | |
| 306 | 314 | $cache_group = 'oembed_flickr'; |
| 307 | 315 | |
| 308 | 316 | $html = wp_cache_get( $cache_key, $cache_group ); |
| 309 | 317 | |