Completed
Pull Request — master (#18)
by Rasmus
02:14
created
includes/compability.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @package imgix
6 6
  */
7 7
 
8
-if ( ! function_exists( 'http_build_url' ) ) {
8
+if ( ! function_exists('http_build_url')) {
9 9
 	/**
10 10
 	 * This is a simplified version of http_build_url if pecl_http is missing
11 11
 	 *
@@ -13,22 +13,22 @@  discard block
 block discarded – undo
13 13
 	 *
14 14
 	 * @return string
15 15
 	 */
16
-	function http_build_url( $parsed_url ) {
17
-		$scheme   = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
18
-		$host     = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
19
-		$port     = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
20
-		$user     = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
21
-		$pass     = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
22
-		$pass     = ( $user || $pass ) ? "$pass@" : '';
23
-		$path     = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
24
-		$query    = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
25
-		$fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
16
+	function http_build_url($parsed_url) {
17
+		$scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
18
+		$host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
19
+		$port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
20
+		$user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
21
+		$pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
22
+		$pass     = ($user || $pass) ? "$pass@" : '';
23
+		$path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
24
+		$query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
25
+		$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
26 26
 
27 27
 		return "$scheme$user$pass$host$port$path$query$fragment";
28 28
 	}
29 29
 }
30 30
 
31
-if ( ! function_exists( 'wp_get_additional_image_sizes' ) ) {
31
+if ( ! function_exists('wp_get_additional_image_sizes')) {
32 32
 	/**
33 33
 	 * Retrieve additional image sizes.
34 34
 	 *
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	function wp_get_additional_image_sizes() {
42 42
 		global $_wp_additional_image_sizes;
43
-		if ( ! $_wp_additional_image_sizes ) {
43
+		if ( ! $_wp_additional_image_sizes) {
44 44
 			$_wp_additional_image_sizes = [];
45 45
 		}
46 46
 
Please login to merge, or discard this patch.
includes/class-images-via-imgix.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -27,20 +27,20 @@  discard block
 block discarded – undo
27 27
 	 * ImagesViaImgix constructor.
28 28
 	 */
29 29
 	public function __construct() {
30
-		$this->options = get_option( 'imgix_settings', [] );
30
+		$this->options = get_option('imgix_settings', []);
31 31
 
32
-		add_filter( 'wp_get_attachment_url', [ $this, 'replace_image_url' ] );
33
-		add_filter( 'imgix/add-image-url', [ $this, 'replace_image_url' ] );
32
+		add_filter('wp_get_attachment_url', [$this, 'replace_image_url']);
33
+		add_filter('imgix/add-image-url', [$this, 'replace_image_url']);
34 34
 
35
-		add_filter( 'image_downsize', [ $this, 'image_downsize' ], 10, 3 );
35
+		add_filter('image_downsize', [$this, 'image_downsize'], 10, 3);
36 36
 
37
-		add_filter( 'wp_calculate_image_srcset', [ $this, 'calculate_image_srcset' ], 10, 3 );
37
+		add_filter('wp_calculate_image_srcset', [$this, 'calculate_image_srcset'], 10, 3);
38 38
 
39
-		add_filter( 'the_content', [ $this, 'replace_images_in_content' ] );
40
-		add_action( 'wp_head', [ $this, 'prefetch_cdn' ], 1 );
39
+		add_filter('the_content', [$this, 'replace_images_in_content']);
40
+		add_action('wp_head', [$this, 'prefetch_cdn'], 1);
41 41
 
42
-		add_action( 'after_setup_theme', [ $this, 'buffer_start_for_retina' ] );
43
-		add_action( 'shutdown', [ $this, 'buffer_end_for_retina' ] );
42
+		add_action('after_setup_theme', [$this, 'buffer_start_for_retina']);
43
+		add_action('shutdown', [$this, 'buffer_end_for_retina']);
44 44
 	}
45 45
 
46 46
 	/**
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 * @return Images_Via_Imgix
50 50
 	 */
51 51
 	public static function instance() {
52
-		if ( ! isset( self::$instance ) ) {
52
+		if ( ! isset(self::$instance)) {
53 53
 			self::$instance = new self;
54 54
 		}
55 55
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @param array $options
64 64
 	 */
65
-	public function set_options( $options ) {
65
+	public function set_options($options) {
66 66
 		$this->options = $options;
67 67
 	}
68 68
 
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return string Content with retina-enriched image tags.
77 77
 	 */
78
-	public function add_retina( $content ) {
78
+	public function add_retina($content) {
79 79
 		$pattern = '/<img((?![^>]+srcset )([^>]*)';
80 80
 		$pattern .= 'src=[\'"]([^\'"]*imgix.net[^\'"]*\?[^\'"]*w=[^\'"]*)[\'"]([^>]*)*?)>/i';
81 81
 		$repl    = '<img$2src="$3" srcset="${3}, ${3}&amp;dpr=2 2x, ${3}&amp;dpr=3 3x,"$4>';
82
-		$content = preg_replace( $pattern, $repl, $content );
82
+		$content = preg_replace($pattern, $repl, $content);
83 83
 
84
-		return preg_replace( $pattern, $repl, $content );
84
+		return preg_replace($pattern, $repl, $content);
85 85
 	}
86 86
 
87 87
 	/**
@@ -91,39 +91,39 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @return string
93 93
 	 */
94
-	public function replace_image_url( $url ) {
95
-		if ( ! empty ( $this->options['cdn_link'] ) ) {
96
-			$pathinfo = pathinfo( $url );
94
+	public function replace_image_url($url) {
95
+		if ( ! empty ($this->options['cdn_link'])) {
96
+			$pathinfo = pathinfo($url);
97 97
 
98
-			if ( isset( $pathinfo['extension'] ) && in_array( $pathinfo['extension'], [
98
+			if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], [
99 99
 					'jpg',
100 100
 					'gif',
101 101
 					'png',
102 102
 					'jpeg'
103
-				] )
103
+				])
104 104
 			) {
105
-				$parsed_url = parse_url( $url );
106
-				if ( isset( $parsed_url['host'] ) && $parsed_url['host'] === parse_url( home_url( '/' ), PHP_URL_HOST ) ) {
107
-					$cdn = parse_url( $this->options['cdn_link'] );
108
-					foreach ( [ 'scheme', 'host', 'port' ] as $url_part ) {
109
-						if ( isset( $cdn[ $url_part ] ) ) {
110
-							$parsed_url[ $url_part ] = $cdn[ $url_part ];
105
+				$parsed_url = parse_url($url);
106
+				if (isset($parsed_url['host']) && $parsed_url['host'] === parse_url(home_url('/'), PHP_URL_HOST)) {
107
+					$cdn = parse_url($this->options['cdn_link']);
108
+					foreach (['scheme', 'host', 'port'] as $url_part) {
109
+						if (isset($cdn[$url_part])) {
110
+							$parsed_url[$url_part] = $cdn[$url_part];
111 111
 						} else {
112
-							unset( $parsed_url[ $url_part ] );
112
+							unset($parsed_url[$url_part]);
113 113
 						}
114 114
 					}
115 115
 
116 116
 					$arguments = [];
117
-					if ( ! empty( $parsed_url['query'] ) ) {
118
-						parse_str( $parsed_url['query'], $arguments );
117
+					if ( ! empty($parsed_url['query'])) {
118
+						parse_str($parsed_url['query'], $arguments);
119 119
 					}
120
-					$arguments = array_merge( $arguments, $this->get_global_params() );
120
+					$arguments = array_merge($arguments, $this->get_global_params());
121 121
 
122
-					if ( ! empty( $arguments ) ) {
123
-						$parsed_url['query'] = build_query( urlencode_deep( $arguments ) );
122
+					if ( ! empty($arguments)) {
123
+						$parsed_url['query'] = build_query(urlencode_deep($arguments));
124 124
 					}
125 125
 
126
-					$url = http_build_url( $parsed_url );
126
+					$url = http_build_url($parsed_url);
127 127
 				}
128 128
 			}
129 129
 		}
@@ -140,35 +140,35 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @return false|array
142 142
 	 */
143
-	public function image_downsize( $return, $attachment_id, $size ) {
144
-		if ( ! empty ( $this->options['cdn_link'] ) ) {
145
-			$img_url = wp_get_attachment_url( $attachment_id );
143
+	public function image_downsize($return, $attachment_id, $size) {
144
+		if ( ! empty ($this->options['cdn_link'])) {
145
+			$img_url = wp_get_attachment_url($attachment_id);
146 146
 
147 147
 			$params = [];
148
-			if ( is_array( $size ) ) {
149
-				$params['w'] = $width = isset( $size[0] ) ? $size[0] : 0;
150
-				$params['h'] = $height = isset( $size[1] ) ? $size[1] : 0;
148
+			if (is_array($size)) {
149
+				$params['w'] = $width = isset($size[0]) ? $size[0] : 0;
150
+				$params['h'] = $height = isset($size[1]) ? $size[1] : 0;
151 151
 			} else {
152 152
 				$available_sizes = $this->get_all_defined_sizes();
153
-				if ( isset( $available_sizes[ $size ] ) ) {
154
-					$size        = $available_sizes[ $size ];
153
+				if (isset($available_sizes[$size])) {
154
+					$size        = $available_sizes[$size];
155 155
 					$params['w'] = $width = $size['width'];
156 156
 					$params['h'] = $height = $size['height'];
157 157
 				}
158 158
 			}
159 159
 
160
-			$params = array_filter( $params );
160
+			$params = array_filter($params);
161 161
 
162
-			$img_url = add_query_arg( $params, $img_url );
162
+			$img_url = add_query_arg($params, $img_url);
163 163
 
164
-			if ( ! isset( $width ) || ! isset( $height ) ) {
164
+			if ( ! isset($width) || ! isset($height)) {
165 165
 				// any other type: use the real image
166
-				$meta   = wp_get_attachment_metadata( $attachment_id );
167
-				$width  = isset( $width ) ? $width : $meta['width'];
168
-				$height = isset( $height ) ? $height : $meta['height'];
166
+				$meta   = wp_get_attachment_metadata($attachment_id);
167
+				$width  = isset($width) ? $width : $meta['width'];
168
+				$height = isset($height) ? $height : $meta['height'];
169 169
 			}
170 170
 
171
-			$return = [ $img_url, $width, $height, true ];
171
+			$return = [$img_url, $width, $height, true];
172 172
 		}
173 173
 
174 174
 		return $return;
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @return array
185 185
 	 */
186
-	public function calculate_image_srcset( $image_meta, $size_array, $image_src ) {
187
-		foreach ( $image_meta as $i => $image_size ) {
188
-			if ( $image_size['descriptor'] === 'w' ) {
189
-				$image_meta[ $i ]['url'] = add_query_arg( 'w', $image_size['value'], $image_src );
186
+	public function calculate_image_srcset($image_meta, $size_array, $image_src) {
187
+		foreach ($image_meta as $i => $image_size) {
188
+			if ($image_size['descriptor'] === 'w') {
189
+				$image_meta[$i]['url'] = add_query_arg('w', $image_size['value'], $image_src);
190 190
 			}
191 191
 		}
192 192
 
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 *
201 201
 	 * @return string
202 202
 	 */
203
-	public function replace_images_in_content( $content ) {
204
-		if ( ! empty ( $this->options['cdn_link'] ) ) {
205
-			$content = preg_replace_callback( '/(?<=\shref="|\ssrc="|\shref=\'|\ssrc=\').*(?=\'|")/', function ( $match ) {
206
-				return esc_url( apply_filters( 'imgix/add-image-url', $match[0] ) );
207
-			}, $content );
203
+	public function replace_images_in_content($content) {
204
+		if ( ! empty ($this->options['cdn_link'])) {
205
+			$content = preg_replace_callback('/(?<=\shref="|\ssrc="|\shref=\'|\ssrc=\').*(?=\'|")/', function($match) {
206
+				return esc_url(apply_filters('imgix/add-image-url', $match[0]));
207
+			}, $content);
208 208
 
209 209
 		}
210 210
 
@@ -215,12 +215,12 @@  discard block
 block discarded – undo
215 215
 	 * Add tag to dns prefetch cdn host
216 216
 	 */
217 217
 	public function prefetch_cdn() {
218
-		if ( ! empty ( $this->options['cdn_link'] ) ) {
219
-			$host = parse_url( $this->options['cdn_link'], PHP_URL_HOST );
218
+		if ( ! empty ($this->options['cdn_link'])) {
219
+			$host = parse_url($this->options['cdn_link'], PHP_URL_HOST);
220 220
 
221 221
 			printf(
222 222
 				'<link rel="dns-prefetch" href="%s"/>',
223
-				esc_attr( '//' . $host )
223
+				esc_attr('//' . $host)
224 224
 			);
225 225
 		}
226 226
 	}
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
 	 * Start output buffer if auto retina is enabled
230 230
 	 */
231 231
 	public function buffer_start_for_retina() {
232
-		if ( ! empty ( $this->options['add_dpi2_srcset'] ) ) {
232
+		if ( ! empty ($this->options['add_dpi2_srcset'])) {
233 233
 			$this->buffer_started = true;
234
-			ob_start( [ $this, 'add_retina' ] );
234
+			ob_start([$this, 'add_retina']);
235 235
 		}
236 236
 	}
237 237
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	 * Stop output buffer if it was enabled by the plugin
240 240
 	 */
241 241
 	public function buffer_end_for_retina() {
242
-		if ( $this->buffer_started === true ) {
242
+		if ($this->buffer_started === true) {
243 243
 			ob_end_flush();
244 244
 		}
245 245
 	}
@@ -255,16 +255,16 @@  discard block
 block discarded – undo
255 255
 
256 256
 		// For now, only "auto" is supported.
257 257
 		$auto = [];
258
-		if ( ! empty ( $this->options['auto_format'] ) ) {
259
-			array_push( $auto, 'format' );
258
+		if ( ! empty ($this->options['auto_format'])) {
259
+			array_push($auto, 'format');
260 260
 		}
261 261
 
262
-		if ( ! empty ( $this->options['auto_enhance'] ) ) {
263
-			array_push( $auto, 'enhance' );
262
+		if ( ! empty ($this->options['auto_enhance'])) {
263
+			array_push($auto, 'enhance');
264 264
 		}
265 265
 
266
-		if ( ! empty( $auto ) ) {
267
-			$params['auto'] = implode( '%2C', $auto );
266
+		if ( ! empty($auto)) {
267
+			$params['auto'] = implode('%2C', $auto);
268 268
 		}
269 269
 
270 270
 		return $params;
@@ -280,18 +280,18 @@  discard block
 block discarded – undo
280 280
 		$theme_image_sizes = wp_get_additional_image_sizes();
281 281
 
282 282
 		$sizes = [];
283
-		foreach ( get_intermediate_image_sizes() as $s ) {
284
-			$sizes[ $s ] = [ 'width' => '', 'height' => '', 'crop' => false ];
285
-			if ( isset( $theme_image_sizes[ $s ] ) ) {
283
+		foreach (get_intermediate_image_sizes() as $s) {
284
+			$sizes[$s] = ['width' => '', 'height' => '', 'crop' => false];
285
+			if (isset($theme_image_sizes[$s])) {
286 286
 				// For theme-added sizes
287
-				$sizes[ $s ]['width']  = intval( $theme_image_sizes[ $s ]['width'] );
288
-				$sizes[ $s ]['height'] = intval( $theme_image_sizes[ $s ]['height'] );
289
-				$sizes[ $s ]['crop']   = $theme_image_sizes[ $s ]['crop'];
287
+				$sizes[$s]['width']  = intval($theme_image_sizes[$s]['width']);
288
+				$sizes[$s]['height'] = intval($theme_image_sizes[$s]['height']);
289
+				$sizes[$s]['crop']   = $theme_image_sizes[$s]['crop'];
290 290
 			} else {
291 291
 				// For default sizes set in options
292
-				$sizes[ $s ]['width']  = get_option( "{$s}_size_w" );
293
-				$sizes[ $s ]['height'] = get_option( "{$s}_size_h" );
294
-				$sizes[ $s ]['crop']   = get_option( "{$s}_crop" );
292
+				$sizes[$s]['width']  = get_option("{$s}_size_w");
293
+				$sizes[$s]['height'] = get_option("{$s}_size_h");
294
+				$sizes[$s]['crop']   = get_option("{$s}_crop");
295 295
 			}
296 296
 		}
297 297
 
Please login to merge, or discard this patch.