diff options
Diffstat (limited to 'plugins/jetpack/class.jetpack-post-images.php')
-rw-r--r-- | plugins/jetpack/class.jetpack-post-images.php | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/plugins/jetpack/class.jetpack-post-images.php b/plugins/jetpack/class.jetpack-post-images.php index 784d193a..ddfd77d9 100644 --- a/plugins/jetpack/class.jetpack-post-images.php +++ b/plugins/jetpack/class.jetpack-post-images.php @@ -232,7 +232,7 @@ class Jetpack_PostImages { * format to the other images?_from_*() methods. * * @param int $post_id The post ID to check - * @return Array containing details of the Featured Image, or empty array if none. + * @return array containing details of the Featured Image, or empty array if none. */ static function from_thumbnail( $post_id, $width = 200, $height = 200 ) { $images = array(); @@ -385,7 +385,7 @@ class Jetpack_PostImages { * * @uses DOMDocument * - * @return Array containing images + * @return array containing images */ static function from_html( $html_or_id, $width = 200, $height = 200 ) { $images = array(); @@ -472,7 +472,7 @@ class Jetpack_PostImages { /** * @param int $post_id The post ID to check * @param int $size - * @return Array containing details of the image, or empty array if none. + * @return array containing details of the image, or empty array if none. */ static function from_blavatar( $post_id, $size = 96 ) { @@ -512,7 +512,7 @@ class Jetpack_PostImages { * @param int $post_id The post ID to check. * @param int $size The size of the avatar to get. * @param string $default The default image to use. - * @return Array containing details of the image, or empty array if none. + * @return array containing details of the image, or empty array if none. */ static function from_gravatar( $post_id, $size = 96, $default = false ) { $post = get_post( $post_id ); @@ -552,7 +552,7 @@ class Jetpack_PostImages { * * @param int $post_id * @param array $args Other arguments (currently width and height required for images where possible to determine) - * @return Array containing details of the best image to be used + * @return array containing details of the best image to be used */ static function get_image( $post_id, $args = array() ) { $image = ''; @@ -594,7 +594,7 @@ class Jetpack_PostImages { * * @param int $post_id * @param array $args Optional args, see defaults list for details - * @return Array containing images that would be good for representing this post + * @return array containing images that would be good for representing this post */ static function get_images( $post_id, $args = array() ) { // Figure out which image to attach to this post. @@ -778,29 +778,51 @@ class Jetpack_PostImages { * @param int $height Minimum Image height. * @return array|bool Image data or false if unavailable. */ - public static function get_attachment_data( $attachment_id, $post_url = '', $width, $height ) { + public static function get_attachment_data( $attachment_id, $post_url, $width, $height ) { if ( empty( $attachment_id ) ) { return false; } $meta = wp_get_attachment_metadata( $attachment_id ); - // The image must be larger than 200x200. - if ( ! isset( $meta['width'] ) || $meta['width'] < $width ) { + if ( empty( $meta ) ) { return false; } - if ( ! isset( $meta['height'] ) || $meta['height'] < $height ) { + + if ( ! empty( $meta['videopress'] ) ) { + // Use poster image for VideoPress videos. + $url = $meta['videopress']['poster']; + $meta_width = $meta['videopress']['width']; + $meta_height = $meta['videopress']['height']; + } elseif ( ! empty( $meta['thumb'] ) ) { + // On WordPress.com, VideoPress videos have a 'thumb' property with the + // poster image filename instead. + $media_url = wp_get_attachment_url( $attachment_id ); + $url = str_replace( wp_basename( $media_url ), $meta['thumb'], $media_url ); + $meta_width = $meta['width']; + $meta_height = $meta['height']; + } elseif ( wp_attachment_is( 'video', $attachment_id ) ) { + // We don't have thumbnail images for non-VideoPress videos - skip them. return false; + } else { + if ( ! isset( $meta['width'] ) || ! isset( $meta['height'] ) ) { + return false; + } + $url = wp_get_attachment_url( $attachment_id ); + $meta_width = $meta['width']; + $meta_height = $meta['height']; } - $url = wp_get_attachment_url( $attachment_id ); + if ( $meta_width < $width || $meta_height < $height ) { + return false; + } return array( 'type' => 'image', 'from' => 'attachment', 'src' => $url, - 'src_width' => $meta['width'], - 'src_height' => $meta['height'], + 'src_width' => $meta_width, + 'src_height' => $meta_height, 'href' => $post_url, 'alt_text' => self::get_alt_text( $attachment_id ), ); @@ -812,10 +834,10 @@ class Jetpack_PostImages { * @since 7.1 * * @param int $attachment_id The Post ID of the media. - * @return string The alt text value or an emptry string. + * @return string The alt text value or an empty string. */ public static function get_alt_text( $attachment_id ) { - return get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); + return (string) get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); } /** @@ -859,6 +881,18 @@ class Jetpack_PostImages { foreach ( $block['attrs']['ids'] as $img_id ) { $images[] = self::get_attachment_data( $img_id, $html_info['post_url'], $width, $height ); } + } elseif ( + /** + * Parse content from Jetpack's Story block. + */ + 'jetpack/story' === $block['blockName'] + && ! empty( $block['attrs']['mediaFiles'] ) + ) { + foreach ( $block['attrs']['mediaFiles'] as $media_file ) { + if ( ! empty( $media_file['id'] ) ) { + $images[] = self::get_attachment_data( $media_file['id'], $html_info['post_url'], $width, $height ); + } + } } return $images; |