From 000761e150f0a2f6c66abe605d64abc43f34ed79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Wed, 13 Jan 2016 13:59:40 +0100 Subject: [PATCH 1/3] Fixed query_images() for compatibility with Plugin "WP-Offload-S3" --- models/attachment.php | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/models/attachment.php b/models/attachment.php index 1dd0c28..d8a3d41 100644 --- a/models/attachment.php +++ b/models/attachment.php @@ -34,7 +34,7 @@ function import_wp_object($wp_attachment) { function is_image() { return (substr($this->mime_type, 0, 5) == 'image'); } - + function query_images() { $sizes = array('thumbnail', 'medium', 'large', 'full'); if (function_exists('get_intermediate_image_sizes')) { @@ -42,19 +42,39 @@ function query_images() { } $this->images = array(); $home = get_bloginfo('url'); + $hostOfHome = parse_url($home, PHP_URL_HOST); foreach ($sizes as $size) { + list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size); - $filename = ABSPATH . substr($url, strlen($home) + 1); - if (file_exists($filename)) { - list($measured_width, $measured_height) = getimagesize($filename); - if ($measured_width == $width && - $measured_height == $height) { - $this->images[$size] = (object) array( + + // changelog 2016-01-13 from @itinance https://github.com/itinance: + // + // if plugin "WP-Offload-S3" is installed, the attachments are stored at s3/cloudfront and not necessarily + // hosted on the server beeing available at ABSPATH. In this case, let us trust the result + // of wp_get_attachment_image_src() and renounce calls to file_exists() and getimagesize() + + $hostOfAttachment = parse_url($url, PHP_URL_HOST); + if($hostOfAttachment === $hostOfHome) { + $filename = ABSPATH . substr($url, strlen($home) + 1); + if (file_exists($filename)) { + list($measured_width, $measured_height) = getimagesize($filename); + if ($measured_width == $width && + $measured_height == $height) { + $this->images[$size] = (object) array( + 'url' => $url, + 'width' => $width, + 'height' => $height + ); + } + } + } else { + + $this->images[$size] = (object) array( 'url' => $url, 'width' => $width, 'height' => $height - ); - } + ); + } } } From 04c40263fb0d5494152879f43d0426fe53bea241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Wed, 13 Jan 2016 14:01:44 +0100 Subject: [PATCH 2/3] Revert "Fixed query_images() for compatibility with Plugin "WP-Offload-S3"" This reverts commit 000761e150f0a2f6c66abe605d64abc43f34ed79. --- models/attachment.php | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/models/attachment.php b/models/attachment.php index d8a3d41..1dd0c28 100644 --- a/models/attachment.php +++ b/models/attachment.php @@ -34,7 +34,7 @@ function import_wp_object($wp_attachment) { function is_image() { return (substr($this->mime_type, 0, 5) == 'image'); } - + function query_images() { $sizes = array('thumbnail', 'medium', 'large', 'full'); if (function_exists('get_intermediate_image_sizes')) { @@ -42,39 +42,19 @@ function query_images() { } $this->images = array(); $home = get_bloginfo('url'); - $hostOfHome = parse_url($home, PHP_URL_HOST); foreach ($sizes as $size) { - list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size); - - // changelog 2016-01-13 from @itinance https://github.com/itinance: - // - // if plugin "WP-Offload-S3" is installed, the attachments are stored at s3/cloudfront and not necessarily - // hosted on the server beeing available at ABSPATH. In this case, let us trust the result - // of wp_get_attachment_image_src() and renounce calls to file_exists() and getimagesize() - - $hostOfAttachment = parse_url($url, PHP_URL_HOST); - if($hostOfAttachment === $hostOfHome) { - $filename = ABSPATH . substr($url, strlen($home) + 1); - if (file_exists($filename)) { - list($measured_width, $measured_height) = getimagesize($filename); - if ($measured_width == $width && - $measured_height == $height) { - $this->images[$size] = (object) array( - 'url' => $url, - 'width' => $width, - 'height' => $height - ); - } - } - } else { - - $this->images[$size] = (object) array( + $filename = ABSPATH . substr($url, strlen($home) + 1); + if (file_exists($filename)) { + list($measured_width, $measured_height) = getimagesize($filename); + if ($measured_width == $width && + $measured_height == $height) { + $this->images[$size] = (object) array( 'url' => $url, 'width' => $width, 'height' => $height - ); - + ); + } } } } From fce11ea594f7abbdc850ab787c31394aca145751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Wed, 13 Jan 2016 14:03:06 +0100 Subject: [PATCH 3/3] Fixed query_images() for compatibility with Plugin "WP-Offload-S3" --- models/attachment.php | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/models/attachment.php b/models/attachment.php index 1dd0c28..d8a3d41 100644 --- a/models/attachment.php +++ b/models/attachment.php @@ -34,7 +34,7 @@ function import_wp_object($wp_attachment) { function is_image() { return (substr($this->mime_type, 0, 5) == 'image'); } - + function query_images() { $sizes = array('thumbnail', 'medium', 'large', 'full'); if (function_exists('get_intermediate_image_sizes')) { @@ -42,19 +42,39 @@ function query_images() { } $this->images = array(); $home = get_bloginfo('url'); + $hostOfHome = parse_url($home, PHP_URL_HOST); foreach ($sizes as $size) { + list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size); - $filename = ABSPATH . substr($url, strlen($home) + 1); - if (file_exists($filename)) { - list($measured_width, $measured_height) = getimagesize($filename); - if ($measured_width == $width && - $measured_height == $height) { - $this->images[$size] = (object) array( + + // changelog 2016-01-13 from @itinance https://github.com/itinance: + // + // if plugin "WP-Offload-S3" is installed, the attachments are stored at s3/cloudfront and not necessarily + // hosted on the server beeing available at ABSPATH. In this case, let us trust the result + // of wp_get_attachment_image_src() and renounce calls to file_exists() and getimagesize() + + $hostOfAttachment = parse_url($url, PHP_URL_HOST); + if($hostOfAttachment === $hostOfHome) { + $filename = ABSPATH . substr($url, strlen($home) + 1); + if (file_exists($filename)) { + list($measured_width, $measured_height) = getimagesize($filename); + if ($measured_width == $width && + $measured_height == $height) { + $this->images[$size] = (object) array( + 'url' => $url, + 'width' => $width, + 'height' => $height + ); + } + } + } else { + + $this->images[$size] = (object) array( 'url' => $url, 'width' => $width, 'height' => $height - ); - } + ); + } } }