← All changes
|
modules/tiled-gallery/tiled-gallery/tiled-gallery-item.php
+18
-30
12.4.2
→
16.3
View file →
| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | 3 | use Automattic\Jetpack\Image_CDN\Image_CDN_Core; |
| 4 | 4 | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit( 0 ); | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | /** |
| 6 | 10 | * Jetpack Tiled Gallery Item class. |
| 7 | 11 | */ |
| 8 | 12 | abstract class Jetpack_Tiled_Gallery_Item { |
| @@ -13,15 +17,8 @@ | ||
| 13 | 17 | */ |
| 14 | 18 | public $grayscale; |
| 15 | 19 | |
| 16 | 20 | /** |
| 17 | - * The image URL, in grayscale. | |
| 18 | - * | |
| 19 | - * @var string | |
| 20 | - */ | |
| 21 | - public $img_src_grayscale; | |
| 22 | - | |
| 23 | - /** | |
| 24 | 21 | * The image title. |
| 25 | 22 | * |
| 26 | 23 | * @var string |
| 27 | 24 | */ |
| @@ -62,8 +59,15 @@ | ||
| 62 | 59 | */ |
| 63 | 60 | public $img_src; |
| 64 | 61 | |
| 65 | 62 | /** |
| 63 | + * The image srcset. | |
| 64 | + * | |
| 65 | + * @var string | |
| 66 | + */ | |
| 67 | + public $img_srcset; | |
| 68 | + | |
| 69 | + /** | |
| 66 | 70 | * The image data. |
| 67 | 71 | * |
| 68 | 72 | * @var object |
| 69 | 73 | */ |
| @@ -108,8 +112,13 @@ | ||
| 108 | 112 | } |
| 109 | 113 | // The function will always photonoize the URL (even if Photon is |
| 110 | 114 | // not active). We need to photonize the URL to set the width/height. |
| 111 | 115 | $this->img_src = Image_CDN_Core::cdn_url( $this->orig_file, $img_args ); |
| 116 | + | |
| 117 | + $image_meta = wp_get_attachment_metadata( $attachment_image->ID ); | |
| 118 | + $size_array = array( absint( $this->image->width ), absint( $this->image->height ) ); | |
| 119 | + | |
| 120 | + $this->img_srcset = wp_calculate_image_srcset( $size_array, $this->img_src, $image_meta, $attachment_image->ID ); | |
| 112 | 121 | } |
| 113 | 122 | |
| 114 | 123 | /** |
| 115 | 124 | * Handle the fuzzy image meta. |
| @@ -156,9 +165,9 @@ | ||
| 156 | 165 | * @return array|string |
| 157 | 166 | */ |
| 158 | 167 | public function medium_file() { |
| 159 | 168 | $medium_file_info = wp_get_attachment_image_src( $this->image->ID, 'medium' ); |
| 160 | - $medium_file = isset( $medium_file_info[0] ) ? $medium_file_info[0] : ''; | |
| 169 | + $medium_file = $medium_file_info[0] ?? ''; | |
| 161 | 170 | return $medium_file; |
| 162 | 171 | } |
| 163 | 172 | |
| 164 | 173 | /** |
| @@ -167,9 +176,9 @@ | ||
| 167 | 176 | * @return array|string |
| 168 | 177 | */ |
| 169 | 178 | public function large_file() { |
| 170 | 179 | $large_file_info = wp_get_attachment_image_src( $this->image->ID, 'large' ); |
| 171 | - $large_file = isset( $large_file_info[0] ) ? $large_file_info[0] : ''; | |
| 180 | + $large_file = $large_file_info[0] ?? ''; | |
| 172 | 181 | return $large_file; |
| 173 | 182 | } |
| 174 | 183 | } |
| 175 | 184 | |
| @@ -185,9 +194,8 @@ | ||
| 185 | 194 | * @param bool $grayscale - if the image is in grayscale. |
| 186 | 195 | */ |
| 187 | 196 | public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) { |
| 188 | 197 | parent::__construct( $attachment_image, $needs_attachment_link, $grayscale ); |
| 189 | - $this->img_src_grayscale = Image_CDN_Core::cdn_url( $this->img_src, array( 'filter' => 'grayscale' ) ); | |
| 190 | 198 | |
| 191 | 199 | $this->size = 'large'; |
| 192 | 200 | |
| 193 | 201 | if ( $this->image->width < 250 ) { |
| @@ -199,28 +207,8 @@ | ||
| 199 | 207 | /** |
| 200 | 208 | * Tiled gallery square item class. |
| 201 | 209 | */ |
| 202 | 210 | class Jetpack_Tiled_Gallery_Square_Item extends Jetpack_Tiled_Gallery_Item { // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace |
| 203 | - /** | |
| 204 | - * Constructor function. | |
| 205 | - * | |
| 206 | - * @param object $attachment_image - the attachment image. | |
| 207 | - * @param string $needs_attachment_link - the attachment link. | |
| 208 | - * @param bool $grayscale - if the image is in grayscale. | |
| 209 | - */ | |
| 210 | - public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) { | |
| 211 | - parent::__construct( $attachment_image, $needs_attachment_link, $grayscale ); | |
| 212 | - $this->img_src_grayscale = Image_CDN_Core::cdn_url( | |
| 213 | - $this->img_src, | |
| 214 | - array( | |
| 215 | - 'filter' => 'grayscale', | |
| 216 | - 'resize' => array( | |
| 217 | - $this->image->width, | |
| 218 | - $this->image->height, | |
| 219 | - ), | |
| 220 | - ) | |
| 221 | - ); | |
| 222 | - } | |
| 223 | 211 | } |
| 224 | 212 | |
| 225 | 213 | /** |
| 226 | 214 | * Tiled gallery circle item class. |