Completed
Push — master ( ee1e20...55345a )
by Jared
02:58
created
lib/timber-image.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -150,27 +150,27 @@  discard block
 block discarded – undo
150 150
 	 * @internal
151 151
 	 * @param  int $iid the id number of the image in the WP database
152 152
 	 */
153
-	protected function get_image_info( $iid ) {
153
+	protected function get_image_info($iid) {
154 154
 		$image_info = $iid;
155
-		if (is_numeric($iid)) {
155
+		if ( is_numeric($iid) ) {
156 156
 			$image_info = wp_get_attachment_metadata($iid);
157
-			if (!is_array($image_info)) {
157
+			if ( !is_array($image_info) ) {
158 158
 				$image_info = array();
159 159
 			}
160 160
 			$image_custom = get_post_custom($iid);
161 161
 			$basic = get_post($iid);
162
-			if ($basic) {
163
-				if (isset($basic->post_excerpt)) {
162
+			if ( $basic ) {
163
+				if ( isset($basic->post_excerpt) ) {
164 164
 					$this->caption = $basic->post_excerpt;
165 165
 				}
166 166
 				$image_custom = array_merge($image_custom, get_object_vars($basic));
167 167
 			}
168 168
 			return array_merge($image_info, $image_custom);
169 169
 		}
170
-		if (is_array($image_info) && isset($image_info['image'])) {
170
+		if ( is_array($image_info) && isset($image_info['image']) ) {
171 171
 			return $image_info['image'];
172 172
 		}
173
-		if (is_object($image_info)) {
173
+		if ( is_object($image_info) ) {
174 174
 		   return get_object_vars($image_info);
175 175
 		}
176 176
 		return $iid;
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 	 * @internal
203 203
 	 * @param int $iid
204 204
 	 */
205
-	function init( $iid = false ) {
206
-		if ( !is_numeric( $iid ) && is_string( $iid ) ) {
207
-			if (strstr($iid, '://')) {
205
+	function init($iid = false) {
206
+		if ( !is_numeric($iid) && is_string($iid) ) {
207
+			if ( strstr($iid, '://') ) {
208 208
 				$this->init_with_url($iid);
209 209
 				return;
210 210
 			}
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
 			
216 216
 			$relative = false;
217 217
 			$iid_lower = strtolower($iid);
218
-			foreach( $this->file_types as $type ) { if( strstr( $iid_lower, $type ) ) { $relative = true; break; } };
218
+			foreach ($this->file_types as $type) { if ( strstr($iid_lower, $type) ) { $relative = true; break; } };
219 219
 			if ( $relative ) {
220
-				$this->init_with_relative_path( $iid );
220
+				$this->init_with_relative_path($iid);
221 221
 				return;
222 222
 			}
223 223
 		} else if ( $iid instanceof WP_Post ) {
224 224
 			$ref = new ReflectionClass($this);
225 225
 			$post = $ref->getParentClass()->newInstance($iid->ID);
226
-			if (isset($post->_thumbnail_id) && $post->_thumbnail_id) {
226
+			if ( isset($post->_thumbnail_id) && $post->_thumbnail_id ) {
227 227
 				return $this->init((int) $post->_thumbnail_id);
228 228
 			}
229 229
 			return $this->init($post->ID);
@@ -265,9 +265,9 @@  discard block
 block discarded – undo
265 265
 	 * @internal
266 266
 	 * @param string $relative_path
267 267
 	 */
268
-	protected function init_with_relative_path( $relative_path ) {
269
-		$this->abs_url = home_url( $relative_path );
270
-		$file_path = TimberURLHelper::get_full_path( $relative_path );
268
+	protected function init_with_relative_path($relative_path) {
269
+		$this->abs_url = home_url($relative_path);
270
+		$file_path = TimberURLHelper::get_full_path($relative_path);
271 271
 		$this->file_loc = $file_path;
272 272
 		$this->file = $file_path;
273 273
 	}
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 	 * @internal
277 277
 	 * @param string $file_path
278 278
 	 */
279
-	protected function init_with_file_path( $file_path ) {
280
-		$url = TimberURLHelper::file_system_to_url( $file_path );
279
+	protected function init_with_file_path($file_path) {
280
+		$url = TimberURLHelper::file_system_to_url($file_path);
281 281
 		$this->abs_url = $url;
282 282
 		$this->file_loc = $file_path;
283 283
 		$this->file = $file_path;
@@ -476,8 +476,8 @@  discard block
 block discarded – undo
476 476
 	 * @param string $size
477 477
 	 * @return bool|string
478 478
 	 */
479
-	function get_src( $size = '' ) {
480
-		return $this->src( $size );
479
+	function get_src($size = '') {
480
+		return $this->src($size);
481 481
 	}
482 482
 
483 483
 	/**
Please login to merge, or discard this patch.
lib/timber-request.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,14 +21,14 @@
 block discarded – undo
21 21
 		$this->get = $_GET;
22 22
 	}
23 23
 
24
-	public function __call( $field, $args ) {}
24
+	public function __call($field, $args) {}
25 25
 
26
-	public function __get( $field ) {}
26
+	public function __get($field) {}
27 27
 
28 28
 	/**
29 29
 	 * @return boolean
30 30
 	 */
31
-	public function __isset( $field ) {}
31
+	public function __isset($field) {}
32 32
 
33
-	public function meta( $key ) {}
33
+	public function meta($key) {}
34 34
 }
Please login to merge, or discard this patch.
lib/timber-function-wrapper.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 	public function __toString() {
11 11
 		 try {
12
-			return (string)$this->call();
12
+			return (string) $this->call();
13 13
 		 } catch (Exception $e) {
14 14
 		 	return 'Caught exception: ' . $e->getMessage() . "\n";
15 15
 		 }
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
 	 * @param array   $args
23 23
 	 * @param bool    $return_output_buffer
24 24
 	 */
25
-	public function __construct( $function, $args = array(), $return_output_buffer = false ) {
26
-		if( is_array( $function ) ) {
27
-			if( (is_string( $function[0] ) && class_exists( $function[0] ) ) || gettype( $function[0] ) === 'object' ) {
25
+	public function __construct($function, $args = array(), $return_output_buffer = false) {
26
+		if ( is_array($function) ) {
27
+			if ( (is_string($function[0]) && class_exists($function[0])) || gettype($function[0]) === 'object' ) {
28 28
 				$this->_class = $function[0];
29 29
 			}
30 30
 			
31
-			if( is_string( $function[1] ) ) $this->_function = $function[1];
31
+			if ( is_string($function[1]) ) $this->_function = $function[1];
32 32
 		} else {
33 33
 			$this->_function = $function;
34 34
 		}
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 		$this->_args = $args;
37 37
 		$this->_use_ob = $return_output_buffer;
38 38
 
39
-		add_filter( 'get_twig', array( &$this, 'add_to_twig' ) );
39
+		add_filter('get_twig', array(&$this, 'add_to_twig'));
40 40
 	}
41 41
 
42 42
 	/**
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
 	 * @param Twig_Environment $twig
46 46
 	 * @return Twig_Environment
47 47
 	 */
48
-	public function add_to_twig( $twig ) {
48
+	public function add_to_twig($twig) {
49 49
 		$wrapper = $this;
50 50
 
51
-		$twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) {
52
-					return call_user_func_array( array( $wrapper, 'call' ), func_get_args() );
53
-				} ) );
51
+		$twig->addFunction(new Twig_SimpleFunction($this->_function, function() use ($wrapper) {
52
+					return call_user_func_array(array($wrapper, 'call'), func_get_args());
53
+				} ));
54 54
 
55 55
 		return $twig;
56 56
 	}
@@ -61,13 +61,13 @@  discard block
 block discarded – undo
61 61
 	 * @return string
62 62
 	 */
63 63
 	public function call() {
64
-		$args = $this->_parse_args( func_get_args(), $this->_args );
65
-		$callable = ( isset( $this->_class ) ) ? array( $this->_class, $this->_function ) : $this->_function;
64
+		$args = $this->_parse_args(func_get_args(), $this->_args);
65
+		$callable = (isset($this->_class)) ? array($this->_class, $this->_function) : $this->_function;
66 66
 
67 67
 		if ( $this->_use_ob ) {
68
-			return TimberHelper::ob_function( $callable, $args );
68
+			return TimberHelper::ob_function($callable, $args);
69 69
 		} else {
70
-			return call_user_func_array( $callable, $args );
70
+			return call_user_func_array($callable, $args);
71 71
 		}
72 72
 	}
73 73
 
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
 	 * @param array   $defaults
79 79
 	 * @return array
80 80
 	 */
81
-	private function _parse_args( $args, $defaults ) {
82
-		$_arg = reset( $defaults );
81
+	private function _parse_args($args, $defaults) {
82
+		$_arg = reset($defaults);
83 83
 
84
-		foreach ( $args as $index => $arg ) {
85
-			$defaults[$index] = is_null( $arg ) ? $_arg : $arg;
86
-			$_arg = next( $defaults );
84
+		foreach ($args as $index => $arg) {
85
+			$defaults[$index] = is_null($arg) ? $_arg : $arg;
86
+			$_arg = next($defaults);
87 87
 		}
88 88
 
89 89
 		return $defaults;
Please login to merge, or discard this patch.
lib/image/timber-image-operation-resize.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 		$this->w = $w;
22 22
 		$this->h = $h;
23 23
 		// Sanitize crop position
24
-		$allowed_crop_positions = array( 'default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center' );
25
-		if ( $crop !== false && !in_array( $crop, $allowed_crop_positions ) ) {
24
+		$allowed_crop_positions = array('default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center');
25
+		if ( $crop !== false && !in_array($crop, $allowed_crop_positions) ) {
26 26
 			$crop = $allowed_crop_positions[0];
27 27
 		}
28 28
 		$this->crop = $crop;
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 		if ( $this->h ) {
43 43
 			$h = $this->h;
44 44
 		}
45
-		$result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ( $this->crop ? $this->crop : 'f' ); // Crop will be either user named or f (false)
46
-		if($src_extension) {
47
-			$result .= '.'.$src_extension;
45
+		$result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ($this->crop ? $this->crop : 'f'); // Crop will be either user named or f (false)
46
+		if ( $src_extension ) {
47
+			$result .= '.' . $src_extension;
48 48
 		}
49 49
 		return $result;
50 50
 	}
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 * @param string $load_filename
54 54
 	 * @param string $save_filename
55 55
 	 */
56
-	protected function run_animated_gif( $load_filename, $save_filename ) {
57
-		$image = wp_get_image_editor( $load_filename );
56
+	protected function run_animated_gif($load_filename, $save_filename) {
57
+		$image = wp_get_image_editor($load_filename);
58 58
 		$current_size = $image->get_size();
59 59
 		$src_w = $current_size['width'];
60 60
 		$src_h = $current_size['height'];
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		}
66 66
 		$image = new Imagick($load_filename);
67 67
 		$image = $image->coalesceImages();
68
-		$crop = self::get_target_sizes( $load_filename );
68
+		$crop = self::get_target_sizes($load_filename);
69 69
 		foreach ($image as $frame) {
70 70
 			$frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']);
71 71
 			$frame->thumbnailImage($w, $h);
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 		return $image->writeImages($save_filename, true);
76 76
 	}
77 77
 
78
-	protected function get_target_sizes( $load_filename ) {
79
-		$image = wp_get_image_editor( $load_filename );
78
+	protected function get_target_sizes($load_filename) {
79
+		$image = wp_get_image_editor($load_filename);
80 80
 		$w = $this->w;
81 81
 		$h = $this->h;
82 82
 		$crop = $this->crop;
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 		$src_h = $current_size['height'];
87 87
 		$src_ratio = $src_w / $src_h;
88 88
 		if ( !$h ) {
89
-			$h = round( $w / $src_ratio );
89
+			$h = round($w / $src_ratio);
90 90
 		}
91 91
 		if ( !$w ) {
92 92
 			//the user wants to resize based on constant height
93
-			$w = round( $h * $src_ratio );
93
+			$w = round($h * $src_ratio);
94 94
 		}
95 95
 		if ( !$crop ) {
96 96
 			return array(
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 		$src_wt = $src_h * $dest_ratio;
105 105
 		$src_ht = $src_w / $dest_ratio;
106 106
 		$src_x = $src_w / 2 - $src_wt / 2;
107
-		$src_y = ( $src_h - $src_ht ) / 6;
107
+		$src_y = ($src_h - $src_ht) / 6;
108 108
 		//now specific overrides based on options:
109
-		switch ( $crop ) {
109
+		switch ($crop) {
110 110
 			case 'center':
111 111
 				// Get source x and y
112
-				$src_x = round( ( $src_w - $src_wt ) / 2 );
113
-				$src_y = round( ( $src_h - $src_ht ) / 2 );
112
+				$src_x = round(($src_w - $src_wt) / 2);
113
+				$src_y = round(($src_h - $src_ht) / 2);
114 114
 				break;
115 115
 
116 116
 			case 'top':
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
 				break;
123 123
 
124 124
 			case 'top-center':
125
-				$src_y = round( ( $src_h - $src_ht ) / 4 );
125
+				$src_y = round(($src_h - $src_ht) / 4);
126 126
 				break;
127 127
 
128 128
 			case 'bottom-center':
129
-				$src_y = $src_h - $src_ht - round( ( $src_h - $src_ht ) / 4 );
129
+				$src_y = $src_h - $src_ht - round(($src_h - $src_ht) / 4);
130 130
 				break;
131 131
 
132 132
 			case 'left':
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 				break;
139 139
 		}
140 140
 		// Crop the image
141
-		return ( $dest_ratio > $src_ratio )
141
+		return ($dest_ratio > $src_ratio)
142 142
 			? array(
143 143
 				'x' => 0, 'y' => $src_y,
144 144
 				'src_w' => $src_w, 'src_h' => $src_ht,
@@ -168,35 +168,35 @@  discard block
 block discarded – undo
168 168
 			//return if successful
169 169
 			//proceed if not
170 170
 			$gif = self::run_animated_gif($load_filename, $save_filename);
171
-			if ($gif) {
171
+			if ( $gif ) {
172 172
 				return true;
173 173
 			}
174 174
 		}
175
-		$image = wp_get_image_editor( $load_filename );
176
-		if ( !is_wp_error( $image ) ) {
177
-			$crop = self::get_target_sizes( $load_filename );
178
-			$image->crop( 	$crop['x'],
175
+		$image = wp_get_image_editor($load_filename);
176
+		if ( !is_wp_error($image) ) {
177
+			$crop = self::get_target_sizes($load_filename);
178
+			$image->crop($crop['x'],
179 179
 							$crop['y'],
180 180
 							$crop['src_w'],
181 181
 							$crop['src_h'],
182 182
 							$crop['target_w'],
183 183
 							$crop['target_h']
184 184
 			);
185
-			$result = $image->save( $save_filename );
186
-			if ( is_wp_error( $result ) ) {
185
+			$result = $image->save($save_filename);
186
+			if ( is_wp_error($result) ) {
187 187
 				// @codeCoverageIgnoreStart
188
-				TimberHelper::error_log( 'Error resizing image' );
189
-				TimberHelper::error_log( $result );
188
+				TimberHelper::error_log('Error resizing image');
189
+				TimberHelper::error_log($result);
190 190
 				return false;
191 191
 				// @codeCoverageIgnoreEnd
192 192
 			} else {
193 193
 				return true;
194 194
 			}
195
-		} else if ( isset( $image->error_data['error_loading_image'] ) ) {
195
+		} else if ( isset($image->error_data['error_loading_image']) ) {
196 196
 			// @codeCoverageIgnoreStart
197
-			TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
197
+			TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']);
198 198
 		} else {
199
-			TimberHelper::error_log( $image );
199
+			TimberHelper::error_log($image);
200 200
 			// @codeCoverageIgnoreEnd
201 201
 		}
202 202
 	}
Please login to merge, or discard this patch.
lib/timber-image-helper.php 1 patch
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * ```
44 44
 	 * @return string (ex: )
45 45
 	 */
46
-	public static function resize( $src, $w, $h = 0, $crop = 'default', $force = false ) {
47
-		if (!is_numeric($w) && is_string($w)) {
48
-			if ($sizes = self::find_wp_dimensions($w)) {
46
+	public static function resize($src, $w, $h = 0, $crop = 'default', $force = false) {
47
+		if ( !is_numeric($w) && is_string($w) ) {
48
+			if ( $sizes = self::find_wp_dimensions($w) ) {
49 49
 				$w = $sizes['w'];
50 50
 				$h = $sizes['h'];
51 51
 			} else {
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
 	 *     @type int h
67 67
 	 * }
68 68
 	 */
69
-	private static function find_wp_dimensions( $size ) {
69
+	private static function find_wp_dimensions($size) {
70 70
 		global $_wp_additional_image_sizes;
71
-		if (isset($_wp_additional_image_sizes[$size])) {
71
+		if ( isset($_wp_additional_image_sizes[$size]) ) {
72 72
 			$w = $_wp_additional_image_sizes[$size]['width'];
73 73
 			$h = $_wp_additional_image_sizes[$size]['height'];
74
-		} else if (in_array($size, array('thumbnail', 'medium', 'large'))) {
75
-			$w = get_option($size.'_size_w');
76
-			$h = get_option($size.'_size_h');
74
+		} else if ( in_array($size, array('thumbnail', 'medium', 'large')) ) {
75
+			$w = get_option($size . '_size_w');
76
+			$h = get_option($size . '_size_h');
77 77
 		}
78
-		if (isset($w) && isset($h) && ($w || $h)) {
78
+		if ( isset($w) && isset($h) && ($w || $h) ) {
79 79
 			return array('w' => $w, 'h' => $h);
80 80
 		}
81 81
 		return false;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return string url to the new image
92 92
 	 */
93
-	public static function retina_resize( $src, $multiplier = 2, $force = false ) {
93
+	public static function retina_resize($src, $multiplier = 2, $force = false) {
94 94
 		$op = new TimberImageOperationRetina($multiplier);
95 95
 		return self::_operate($src, $op, $force);
96 96
 	}
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 	 * @param  string  $file local filepath to a file, not a URL
101 101
 	 * @return boolean true if it's an animated gif, false if not
102 102
 	 */
103
-	public static function is_animated_gif( $file ) {
103
+	public static function is_animated_gif($file) {
104 104
 		if ( strpos(strtolower($file), '.gif') == -1 ) {
105 105
 			//doesn't have .gif, bail
106 106
 			return false;
107 107
 		}
108 108
 		//its a gif so test
109
-		if( !($fh = @fopen($file, 'rb')) ) {
109
+		if ( !($fh = @fopen($file, 'rb')) ) {
110 110
 		  	return false;
111 111
 	    }
112 112
 	    $count = 0;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 
119 119
 	    // We read through the file til we reach the end of the file, or we've found
120 120
 	    // at least 2 frame headers
121
-	    while(!feof($fh) && $count < 2) {
121
+	    while (!feof($fh) && $count < 2) {
122 122
 	        $chunk = fread($fh, 1024 * 100); //read 100kb at a time
123 123
 	        $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches);
124 124
 	    }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 * @param bool    $force
139 139
 	 * @return mixed|null|string
140 140
 	 */
141
-	public static function letterbox( $src, $w, $h, $color = '#000000', $force = false ) {
141
+	public static function letterbox($src, $w, $h, $color = '#000000', $force = false) {
142 142
 		$op = new TimberImageOperationLetterbox($w, $h, $color);
143 143
 		return self::_operate($src, $op, $force);
144 144
 	}
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @param string  $bghex
151 151
 	 * @return string
152 152
 	 */
153
-	public static function img_to_jpg( $src, $bghex = '#FFFFFF', $force = false ) {
153
+	public static function img_to_jpg($src, $bghex = '#FFFFFF', $force = false) {
154 154
 		$op = new TimberImageOperationToJpg($bghex);
155 155
 		return self::_operate($src, $op, $force);
156 156
 	}
@@ -159,13 +159,13 @@  discard block
 block discarded – undo
159 159
 	 * Deletes all resized versions of an image when the source is deleted
160 160
 	 */
161 161
 	protected static function add_actions() {
162
-		add_action( 'delete_attachment', function ( $post_id ) {
163
-			$post = get_post( $post_id );
164
-			$image_types = array( 'image/jpeg', 'image/png', 'image/gif', 'image/jpg' );
165
-			if ( in_array( $post->post_mime_type, $image_types ) ) {
166
-				$attachment = new TimberImage( $post_id );
162
+		add_action('delete_attachment', function($post_id) {
163
+			$post = get_post($post_id);
164
+			$image_types = array('image/jpeg', 'image/png', 'image/gif', 'image/jpg');
165
+			if ( in_array($post->post_mime_type, $image_types) ) {
166
+				$attachment = new TimberImage($post_id);
167 167
 				if ( $attachment->file_loc ) {
168
-					TimberImageHelper::delete_generated_files( $attachment->file_loc );
168
+					TimberImageHelper::delete_generated_files($attachment->file_loc);
169 169
 				}
170 170
 			}
171 171
 		} );
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 	 * for example /wp-content or /content
177 177
 	 */
178 178
 	protected static function add_constants() {
179
-		if ( !defined( 'WP_CONTENT_SUBDIR' ) ) {
180
-			$wp_content_path = str_replace( home_url(), '', WP_CONTENT_URL );
181
-			define( 'WP_CONTENT_SUBDIR', $wp_content_path );
179
+		if ( !defined('WP_CONTENT_SUBDIR') ) {
180
+			$wp_content_path = str_replace(home_url(), '', WP_CONTENT_URL);
181
+			define('WP_CONTENT_SUBDIR', $wp_content_path);
182 182
 		}
183 183
 	}
184 184
 
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 	 * @return void
189 189
 	 */
190 190
 	static function add_filters() {
191
-		add_filter( 'upload_dir', function ( $arr ) {
192
-			$arr['relative'] = str_replace( home_url(), '', $arr['baseurl'] );
191
+		add_filter('upload_dir', function($arr) {
192
+			$arr['relative'] = str_replace(home_url(), '', $arr['baseurl']);
193 193
 			return $arr;
194 194
 		} );
195 195
 	}
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
 	 * @param string  $local_file   ex: /var/www/wp-content/uploads/2015/my-pic.jpg
201 201
 	 *                              or: http://example.org/wp-content/uploads/2015/my-pic.jpg
202 202
 	 */
203
-	static function delete_generated_files( $local_file ) {
204
-		if (TimberURLHelper::is_absolute( $local_file ) ) {
205
-			$local_file = TimberURLHelper::url_to_file_system( $local_file );
203
+	static function delete_generated_files($local_file) {
204
+		if ( TimberURLHelper::is_absolute($local_file) ) {
205
+			$local_file = TimberURLHelper::url_to_file_system($local_file);
206 206
 		}
207
-		$info = pathinfo( $local_file );
207
+		$info = pathinfo($local_file);
208 208
 		$dir = $info['dirname'];
209 209
 		$ext = $info['extension'];
210 210
 		$filename = $info['filename'];
211
-		self::process_delete_generated_files( $filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.' );
212
-		self::process_delete_generated_files( $filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.' );
211
+		self::process_delete_generated_files($filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.');
212
+		self::process_delete_generated_files($filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.');
213 213
 	}
214 214
 
215 215
 	/**
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
 	 * @param string 	$search_pattern pattern of files to pluck from
227 227
 	 * @param string 	$match_pattern pattern of files to go forth and delete
228 228
 	 */
229
-	protected static function process_delete_generated_files( $filename, $ext, $dir, $search_pattern, $match_pattern ) {
229
+	protected static function process_delete_generated_files($filename, $ext, $dir, $search_pattern, $match_pattern) {
230 230
 		$searcher = '/' . $filename . $search_pattern;
231
-		foreach ( glob( $dir . $searcher ) as $found_file ) {
232
-			$regexdir = str_replace( '/', '\/', $dir );
233
-			$pattern = '/' . ( $regexdir ) . '\/' . $filename . $match_pattern . $ext . '/';
234
-			$match = preg_match( $pattern, $found_file );
231
+		foreach (glob($dir . $searcher) as $found_file) {
232
+			$regexdir = str_replace('/', '\/', $dir);
233
+			$pattern = '/' . ($regexdir) . '\/' . $filename . $match_pattern . $ext . '/';
234
+			$match = preg_match($pattern, $found_file);
235 235
 			if ( $match ) {
236
-				unlink( $found_file );
236
+				unlink($found_file);
237 237
 			}
238 238
 		}
239 239
 	}
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
 	 * @param string  $url
246 246
 	 * @return string
247 247
 	 */
248
-	public static function get_server_location( $url ) {
248
+	public static function get_server_location($url) {
249 249
 		// if we're already an absolute dir, just return
250
-		if ( 0 === strpos( $url, ABSPATH ) ) {
250
+		if ( 0 === strpos($url, ABSPATH) ) {
251 251
 			return $url;
252 252
 		}
253 253
 		// otherwise, analyze URL then build mapping path
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
 	 * @param string  $file
263 263
 	 * @return string
264 264
 	 */
265
-	public static function get_sideloaded_file_loc( $file ) {
265
+	public static function get_sideloaded_file_loc($file) {
266 266
 		$upload = wp_upload_dir();
267 267
 		$dir = $upload['path'];
268 268
 		$filename = $file;
269
-		$file = parse_url( $file );
270
-		$path_parts = pathinfo( $file['path'] );
271
-		$basename = md5( $filename );
269
+		$file = parse_url($file);
270
+		$path_parts = pathinfo($file['path']);
271
+		$basename = md5($filename);
272 272
 		$ext = 'jpg';
273
-		if ( isset( $path_parts['extension'] ) ) {
273
+		if ( isset($path_parts['extension']) ) {
274 274
 			$ext = $path_parts['extension'];
275 275
 		}
276 276
 		return $dir . '/' . $basename . '.' . $ext;
@@ -282,28 +282,28 @@  discard block
 block discarded – undo
282 282
 	 * @param string  $file the URL to the original file
283 283
 	 * @return string the URL to the downloaded file
284 284
 	 */
285
-	public static function sideload_image( $file ) {
286
-		$loc = self::get_sideloaded_file_loc( $file );
287
-		if ( file_exists( $loc ) ) {
288
-			return TimberURLHelper::preslashit( TimberURLHelper::get_rel_path( $loc ) );
285
+	public static function sideload_image($file) {
286
+		$loc = self::get_sideloaded_file_loc($file);
287
+		if ( file_exists($loc) ) {
288
+			return TimberURLHelper::preslashit(TimberURLHelper::get_rel_path($loc));
289 289
 		}
290 290
 		// Download file to temp location
291
-		if ( !function_exists( 'download_url' ) ) {
291
+		if ( !function_exists('download_url') ) {
292 292
 			require_once ABSPATH . '/wp-admin/includes/file.php';
293 293
 		}
294
-		$tmp = download_url( $file );
295
-		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
294
+		$tmp = download_url($file);
295
+		preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
296 296
 		$file_array = array();
297
-		$file_array['name'] = basename( $matches[0] );
297
+		$file_array['name'] = basename($matches[0]);
298 298
 		$file_array['tmp_name'] = $tmp;
299 299
 		// If error storing temporarily, unlink
300
-		if ( is_wp_error( $tmp ) ) {
301
-			@unlink( $file_array['tmp_name'] );
300
+		if ( is_wp_error($tmp) ) {
301
+			@unlink($file_array['tmp_name']);
302 302
 			$file_array['tmp_name'] = '';
303 303
 		}
304 304
 		// do the validation and storage stuff
305
-		$locinfo = pathinfo( $loc );
306
-		$file = wp_upload_bits( $locinfo['basename'], null, file_get_contents( $file_array['tmp_name'] ) );
305
+		$locinfo = pathinfo($loc);
306
+		$file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name']));
307 307
 		return $file['url'];
308 308
 	}
309 309
 
@@ -330,23 +330,23 @@  discard block
 block discarded – undo
330 330
 		if ( 0 === strpos($tmp, ABSPATH) ) { // we've been given a dir, not an url
331 331
 			$result['absolute'] = true;
332 332
 			if ( 0 === strpos($tmp, $upload_dir['basedir']) ) {
333
-				$result['base']= self::BASE_UPLOADS; // upload based
333
+				$result['base'] = self::BASE_UPLOADS; // upload based
334 334
 				$tmp = str_replace($upload_dir['basedir'], '', $tmp);
335 335
 			}
336 336
 			if ( 0 === strpos($tmp, WP_CONTENT_DIR) ) {
337
-				$result['base']= self::BASE_CONTENT; // content based
337
+				$result['base'] = self::BASE_CONTENT; // content based
338 338
 				$tmp = str_replace(WP_CONTENT_DIR, '', $tmp);
339 339
 			}
340 340
 		} else {
341
-			if (!$result['absolute']) {
342
-				$tmp = home_url().$tmp;
341
+			if ( !$result['absolute'] ) {
342
+				$tmp = home_url() . $tmp;
343 343
 			}
344
-			if (0 === strpos($tmp, $upload_dir['baseurl'])) {
345
-				$result['base']= self::BASE_UPLOADS; // upload based
344
+			if ( 0 === strpos($tmp, $upload_dir['baseurl']) ) {
345
+				$result['base'] = self::BASE_UPLOADS; // upload based
346 346
 				$tmp = str_replace($upload_dir['baseurl'], '', $tmp);
347 347
 			}
348
-			if (0 === strpos($tmp, content_url())) {
349
-				$result['base']= self::BASE_CONTENT; // content-based
348
+			if ( 0 === strpos($tmp, content_url()) ) {
349
+				$result['base'] = self::BASE_CONTENT; // content-based
350 350
 				$tmp = str_replace(content_url(), '', $tmp);
351 351
 			}
352 352
 		}
@@ -370,18 +370,18 @@  discard block
 block discarded – undo
370 370
 	 */
371 371
 	private static function _get_file_url($base, $subdir, $filename, $absolute) {
372 372
 		$url = '';
373
-		if( self::BASE_UPLOADS == $base ) {
373
+		if ( self::BASE_UPLOADS == $base ) {
374 374
 			$upload_dir = wp_upload_dir();
375 375
 			$url = $upload_dir['baseurl'];
376 376
 		}
377
-		if( self::BASE_CONTENT == $base ) {
377
+		if ( self::BASE_CONTENT == $base ) {
378 378
 			$url = content_url();
379 379
 		}
380
-		if(!empty($subdir)) {
380
+		if ( !empty($subdir) ) {
381 381
 			$url .= $subdir;
382 382
 		}
383
-		$url .= '/'.$filename;
384
-		if(!$absolute) {
383
+		$url .= '/' . $filename;
384
+		if ( !$absolute ) {
385 385
 			$url = str_replace(home_url(), '', $url);
386 386
 		}
387 387
 		// $url = TimberURLHelper::remove_double_slashes( $url);
@@ -398,17 +398,17 @@  discard block
 block discarded – undo
398 398
 	 */
399 399
 	private static function _get_file_path($base, $subdir, $filename) {
400 400
 		$path = '';
401
-		if(self::BASE_UPLOADS == $base) {
401
+		if ( self::BASE_UPLOADS == $base ) {
402 402
 			$upload_dir = wp_upload_dir();
403 403
 			$path = $upload_dir['basedir'];
404 404
 		}
405
-		if(self::BASE_CONTENT == $base) {
405
+		if ( self::BASE_CONTENT == $base ) {
406 406
 			$path = WP_CONTENT_DIR;
407 407
 		}
408
-		if(!empty($subdir)) {
408
+		if ( !empty($subdir) ) {
409 409
 			$path .= $subdir;
410 410
 		}
411
-		$path .= '/'.$filename;
411
+		$path .= '/' . $filename;
412 412
 		return $path;
413 413
 	}
414 414
 
@@ -426,15 +426,15 @@  discard block
 block discarded – undo
426 426
 	 * @return string         URL to the new image - or the source one if error
427 427
 	 *
428 428
 	 */
429
-	private static function _operate( $src, $op, $force = false ) {
430
-		if ( empty( $src ) ) {
429
+	private static function _operate($src, $op, $force = false) {
430
+		if ( empty($src) ) {
431 431
 			return '';
432 432
 		}
433 433
 		$external = false;
434 434
 
435 435
 		// if external image, load it first
436
-		if ( TimberURLHelper::is_external_content( $src ) ) {
437
-			$src = self::sideload_image( $src );
436
+		if ( TimberURLHelper::is_external_content($src) ) {
437
+			$src = self::sideload_image($src);
438 438
 			$external = true;
439 439
 		}
440 440
 		// break down URL into components
@@ -457,19 +457,19 @@  discard block
 block discarded – undo
457 457
 			$au['basename']
458 458
 		);
459 459
 		// if already exists...
460
-		if ( file_exists( $new_server_path ) ) {
460
+		if ( file_exists($new_server_path) ) {
461 461
 			if ( $force ) {
462 462
 				// Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
463
-				unlink( $new_server_path );
463
+				unlink($new_server_path);
464 464
 			} else {
465 465
 				// return existing file (caching)
466 466
 				return $new_url;
467 467
 			}
468 468
 		}
469 469
 		// otherwise generate result file
470
-		if($op->run($old_server_path, $new_server_path)) {
471
-			if( get_class( $op ) === 'TimberImageOperationResize' && $external ) {
472
-				$new_url = strtolower( $new_url );
470
+		if ( $op->run($old_server_path, $new_server_path) ) {
471
+			if ( get_class($op) === 'TimberImageOperationResize' && $external ) {
472
+				$new_url = strtolower($new_url);
473 473
 			}
474 474
 			return $new_url;
475 475
 		} else {
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 		);
493 493
 		return $new_url;
494 494
 	}
495
-	public static function get_letterbox_file_path($url, $w, $h, $color ) {
495
+	public static function get_letterbox_file_path($url, $w, $h, $color) {
496 496
 		$au = self::analyze_url($url);
497 497
 		$op = new TimberImageOperationLetterbox($w, $h, $color);
498 498
 		$new_path = self::_get_file_path(
Please login to merge, or discard this patch.