Completed
Pull Request — master (#813)
by
unknown
06:28 queued 03:03
created
lib/image/timber-image-operation-resize.php 2 patches
Spacing   +27 added lines, -27 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' );
25
-		if ( $crop !== false && !in_array( $crop, $allowed_crop_positions ) ) {
24
+		$allowed_crop_positions = array('default', 'center', 'top', 'bottom', 'left', 'right');
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,15 +42,15 @@  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
 	}
51 51
 
52
-	protected function run_animated_gif( $load_filename, $save_filename ) {
53
-		$image = wp_get_image_editor( $load_filename );
52
+	protected function run_animated_gif($load_filename, $save_filename) {
53
+		$image = wp_get_image_editor($load_filename);
54 54
 		$current_size = $image->get_size();
55 55
 		$src_w = $current_size['width'];
56 56
 		$src_h = $current_size['height'];
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		}
62 62
 		$image = new Imagick($load_filename);
63 63
 		$image = $image->coalesceImages();
64
-		$crop = self::get_target_sizes( $load_filename );
64
+		$crop = self::get_target_sizes($load_filename);
65 65
 		foreach ($image as $frame) {
66 66
 			$frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']);
67 67
 			$frame->thumbnailImage($w, $h);
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 		return $image->writeImages($save_filename, true);
72 72
 	}
73 73
 
74
-	protected function get_target_sizes( $load_filename ) {
75
-		$image = wp_get_image_editor( $load_filename );
74
+	protected function get_target_sizes($load_filename) {
75
+		$image = wp_get_image_editor($load_filename);
76 76
 		$w = $this->w;
77 77
 		$h = $this->h;
78 78
 		$crop = $this->crop;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 		$src_h = $current_size['height'];
83 83
 		$src_ratio = $src_w / $src_h;
84 84
 		if ( !$h ) {
85
-			$h = round( $w / $src_ratio );
85
+			$h = round($w / $src_ratio);
86 86
 		}
87 87
 		if ( !$w ) {
88 88
 			//the user wants to resize based on constant height
89
-			$w = round( $h * $src_ratio );
89
+			$w = round($h * $src_ratio);
90 90
 		}
91 91
 		if ( !$crop ) {
92 92
 			return array(
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 		$src_wt = $src_h * $dest_ratio;
101 101
 		$src_ht = $src_w / $dest_ratio;
102 102
 		$src_x = $src_w / 2 - $src_wt / 2;
103
-		$src_y = ( $src_h - $src_ht ) / 6;
103
+		$src_y = ($src_h - $src_ht) / 6;
104 104
 		//now specific overrides based on options:
105 105
 		if ( $crop == 'center' ) {
106 106
 			// Get source x and y
107
-			$src_x = round( ( $src_w - $src_wt ) / 2 );
108
-			$src_y = round( ( $src_h - $src_ht ) / 2 );
107
+			$src_x = round(($src_w - $src_wt) / 2);
108
+			$src_y = round(($src_h - $src_ht) / 2);
109 109
 		} else if ( $crop == 'top' ) {
110 110
 			$src_y = 0;
111 111
 		} else if ( $crop == 'bottom' ) {
@@ -147,35 +147,35 @@  discard block
 block discarded – undo
147 147
 			//return if successful
148 148
 			//proceed if not
149 149
 			$gif = self::run_animated_gif($load_filename, $save_filename);
150
-			if ($gif) {
150
+			if ( $gif ) {
151 151
 				return true;
152 152
 			}
153 153
 		}
154
-		$image = wp_get_image_editor( $load_filename );
155
-		if ( !is_wp_error( $image ) ) {
156
-			$crop = self::get_target_sizes( $load_filename );
157
-			$image->crop( 	$crop['x'],
154
+		$image = wp_get_image_editor($load_filename);
155
+		if ( !is_wp_error($image) ) {
156
+			$crop = self::get_target_sizes($load_filename);
157
+			$image->crop($crop['x'],
158 158
 							$crop['y'],
159 159
 							$crop['src_w'],
160 160
 							$crop['src_h'],
161 161
 							$crop['target_w'],
162 162
 							$crop['target_h']
163 163
 			);
164
-			$result = $image->save( $save_filename );
165
-			if ( is_wp_error( $result ) ) {
164
+			$result = $image->save($save_filename);
165
+			if ( is_wp_error($result) ) {
166 166
 				// @codeCoverageIgnoreStart
167
-				TimberHelper::error_log( 'Error resizing image' );
168
-				TimberHelper::error_log( $result );
167
+				TimberHelper::error_log('Error resizing image');
168
+				TimberHelper::error_log($result);
169 169
 				return false;
170 170
 				// @codeCoverageIgnoreEnd
171 171
 			} else {
172 172
 				return true;
173 173
 			}
174
-		} else if ( isset( $image->error_data['error_loading_image'] ) ) {
174
+		} else if ( isset($image->error_data['error_loading_image']) ) {
175 175
 			// @codeCoverageIgnoreStart
176
-			TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
176
+			TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']);
177 177
 		} else {
178
-			TimberHelper::error_log( $image );
178
+			TimberHelper::error_log($image);
179 179
 			// @codeCoverageIgnoreEnd
180 180
 		}
181 181
 	}
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,6 +75,9 @@  discard block
 block discarded – undo
75 75
 		return $image->writeImages($save_filename, true);
76 76
 	}
77 77
 
78
+	/**
79
+	 * @param string $load_filename
80
+	 */
78 81
 	protected function get_target_sizes( $load_filename ) {
79 82
 		$image = wp_get_image_editor( $load_filename );
80 83
 		$w = $this->w;
@@ -142,7 +145,7 @@  discard block
 block discarded – undo
142 145
 	 *                               (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
143 146
 	 * @param  string $save_filename filepath (not URL) where result file should be saved
144 147
 	 *                               (ex: /src/var/www/wp-content/uploads/my-pic-300x200-c-default.jpg)
145
-	 * @return bool                  true if everything went fine, false otherwise
148
+	 * @return boolean|null                  true if everything went fine, false otherwise
146 149
 	 */
147 150
 	public function run($load_filename, $save_filename) {
148 151
 		//should be resized by gif resizer
Please login to merge, or discard this patch.
lib/timber-comment.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	function init($cid) {
56 56
 		$comment_data = $cid;
57
-		if (is_integer($cid)) {
57
+		if ( is_integer($cid) ) {
58 58
 			$comment_data = get_comment($cid);
59 59
 		}
60 60
 		$this->import($comment_data);
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	 * @return TimberUser
87 87
 	 */
88 88
 	public function author() {
89
-		if ($this->user_id) {
89
+		if ( $this->user_id ) {
90 90
 			return new TimberUser($this->user_id);
91 91
 		} else {
92 92
 			$author = new TimberUser(0);
93
-			if (isset($this->comment_author) && $this->comment_author) {
93
+			if ( isset($this->comment_author) && $this->comment_author ) {
94 94
 				$author->name = $this->comment_author;
95 95
 			} else {
96 96
 				$author->name = 'Anonymous';
@@ -114,21 +114,21 @@  discard block
 block discarded – undo
114 114
 	 * @return bool|mixed|string
115 115
 	 */
116 116
 	public function avatar($size = 92, $default = '') {
117
-		if (!get_option('show_avatars')) {
117
+		if ( !get_option('show_avatars') ) {
118 118
 			return false;
119 119
 		}
120
-		if (!is_numeric($size)) {
120
+		if ( !is_numeric($size) ) {
121 121
 			$size = '92';
122 122
 		}
123 123
 
124 124
 		$email = $this->avatar_email();
125 125
 		$email_hash = '';
126
-		if (!empty($email)) {
126
+		if ( !empty($email) ) {
127 127
 			$email_hash = md5(strtolower(trim($email)));
128 128
 		}
129 129
 		$host = $this->avatar_host($email_hash);
130 130
 		$default = $this->avatar_default($default, $email, $size, $host);
131
-		if (!empty($email)) {
131
+		if ( !empty($email) ) {
132 132
 			$avatar = $this->avatar_out($default, $host, $email_hash, $size);
133 133
 		} else {
134 134
 			$avatar = $default;
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 	 * ```
180 180
 	 * @return string
181 181
 	 */
182
-	public function date( $date_format = '' ) {
182
+	public function date($date_format = '') {
183 183
 		$df = $date_format ? $date_format : get_option('date_format');
184
-		$the_date = (string)mysql2date($df, $this->comment_date);
184
+		$the_date = (string) mysql2date($df, $this->comment_date);
185 185
 		return apply_filters('get_comment_date ', $the_date, $df);
186 186
 	}
187 187
 
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 	 * ```
205 205
 	 * @return string
206 206
 	 */
207
-	public function time( $time_format = '' ) {
207
+	public function time($time_format = '') {
208 208
 		$tf = $time_format ? $time_format : get_option('time_format');
209
-		$the_time = (string)mysql2date($tf, $this->comment_date);
209
+		$the_time = (string) mysql2date($tf, $this->comment_date);
210 210
 		return apply_filters('get_comment_time', $the_time, $tf);
211 211
 	}
212 212
 
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
 	 * @return mixed
233 233
 	 */
234 234
 	protected function get_meta_fields($comment_id = null) {
235
-		if ($comment_id === null) {
235
+		if ( $comment_id === null ) {
236 236
 			$comment_id = $this->ID;
237 237
 		}
238 238
 		//Could not find a WP function to fetch all comment meta data, so I made one.
239 239
 		apply_filters('timber_comment_get_meta_pre', array(), $comment_id);
240 240
 		$comment_metas = get_comment_meta($comment_id);
241 241
 		foreach ($comment_metas as &$cm) {
242
-			if (is_array($cm) && count($cm) == 1) {
242
+			if ( is_array($cm) && count($cm) == 1 ) {
243 243
 				$cm = $cm[0];
244 244
 			}
245 245
 		}
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	 */
255 255
 	protected function get_meta_field($field_name) {
256 256
 		$value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this);
257
-		if ($value === null) {
257
+		if ( $value === null ) {
258 258
 			$value = get_comment_meta($this->ID, $field_name, true);
259 259
 		}
260 260
 		$value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this);
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
 	 * @api
268 268
 	 * @return string
269 269
 	 */
270
-	public function reply_link( $reply_text = 'Reply' ) {
270
+	public function reply_link($reply_text = 'Reply') {
271 271
 		if ( is_singular() && comments_open() && get_option('thread_comments') ) {
272
-			wp_enqueue_script( 'comment-reply' );
272
+			wp_enqueue_script('comment-reply');
273 273
 		}
274 274
 
275 275
 		// Get the comments depth option from the admin panel
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 			'max_depth' => $max_depth,
285 285
 		);
286 286
 
287
-		return get_comment_reply_link( $args, $this->ID, $this->post_id );
287
+		return get_comment_reply_link($args, $this->ID, $this->post_id);
288 288
 	}
289 289
 
290 290
 	/* AVATAR Stuff
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 	 * @return string
296 296
 	 */
297 297
 	protected function avatar_email() {
298
-		$id = (int)$this->user_id;
298
+		$id = (int) $this->user_id;
299 299
 		$user = get_userdata($id);
300
-		if ($user) {
300
+		if ( $user ) {
301 301
 			$email = $user->user_email;
302 302
 		} else {
303 303
 			$email = $this->comment_author_email;
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
 	 * @return string
312 312
 	 */
313 313
 	protected function avatar_host($email_hash) {
314
-		if (is_ssl()) {
314
+		if ( is_ssl() ) {
315 315
 			$host = 'https://secure.gravatar.com';
316 316
 		} else {
317
-			if (!empty($email_hash)) {
317
+			if ( !empty($email_hash) ) {
318 318
 				$host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2));
319 319
 			} else {
320 320
 				$host = 'http://0.gravatar.com';
@@ -333,28 +333,28 @@  discard block
 block discarded – undo
333 333
 	 * @return string
334 334
 	 */
335 335
 	protected function avatar_default($default, $email, $size, $host) {
336
-		if (substr($default, 0, 1) == '/') {
336
+		if ( substr($default, 0, 1) == '/' ) {
337 337
 			$default = home_url() . $default;
338 338
 		}
339 339
 
340
-		if (empty($default)) {
340
+		if ( empty($default) ) {
341 341
 			$avatar_default = get_option('avatar_default');
342
-			if (empty($avatar_default)) {
342
+			if ( empty($avatar_default) ) {
343 343
 				$default = 'mystery';
344 344
 			} else {
345 345
 				$default = $avatar_default;
346 346
 			}
347 347
 		}
348
-		if ('mystery' == $default) {
348
+		if ( 'mystery' == $default ) {
349 349
 			$default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size;
350 350
 			// ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]')
351
-		} else if ('blank' == $default) {
351
+		} else if ( 'blank' == $default ) {
352 352
 			$default = $email ? 'blank' : includes_url('images/blank.gif');
353
-		} else if (!empty($email) && 'gravatar_default' == $default) {
353
+		} else if ( !empty($email) && 'gravatar_default' == $default ) {
354 354
 			$default = '';
355
-		} else if ('gravatar_default' == $default) {
355
+		} else if ( 'gravatar_default' == $default ) {
356 356
 			$default = $host . '/avatar/?s=' . $size;
357
-		} else if (empty($email) && !strstr($default, 'http://')) {
357
+		} else if ( empty($email) && !strstr($default, 'http://') ) {
358 358
 			$default = $host . '/avatar/?d=' . $default . '&s=' . $size;
359 359
 		}
360 360
 		return $default;
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 	protected function avatar_out($default, $host, $email_hash, $size) {
372 372
 		$out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default);
373 373
 		$rating = get_option('avatar_rating');
374
-		if (!empty($rating)) {
374
+		if ( !empty($rating) ) {
375 375
 			$out .= '&r=' . $rating;
376 376
 		}
377 377
 		return str_replace('&', '&', esc_url($out));
Please login to merge, or discard this patch.
lib/image/timber-image-operation-tojpg.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
 	 * @return bool                  true if everything went fine, false otherwise
37 37
 	 */
38 38
 	function run($load_filename, $save_filename) {
39
-		$input = self::image_create( $load_filename );
40
-		list( $width, $height ) = getimagesize( $load_filename );
41
-		$output = imagecreatetruecolor( $width, $height );
42
-		$c = self::hexrgb( $this->color );
43
-		$color = imagecolorallocate( $output, $c['red'], $c['green'], $c['blue'] );
44
-		imagefilledrectangle( $output, 0, 0, $width, $height, $color );
45
-		imagecopy( $output, $input, 0, 0, 0, 0, $width, $height );
46
-		imagejpeg( $output, $save_filename );
39
+		$input = self::image_create($load_filename);
40
+		list($width, $height) = getimagesize($load_filename);
41
+		$output = imagecreatetruecolor($width, $height);
42
+		$c = self::hexrgb($this->color);
43
+		$color = imagecolorallocate($output, $c['red'], $c['green'], $c['blue']);
44
+		imagefilledrectangle($output, 0, 0, $width, $height, $color);
45
+		imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
46
+		imagejpeg($output, $save_filename);
47 47
 		return true;
48 48
 	}
49 49
 
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
 	 * @return resource an image identifier representing the image obtained from the given filename
53 53
 	 *                  will return the same data type regardless of whether the source is gif or png
54 54
 	 */
55
-	function image_create( $filename, $ext = 'auto' ) {
55
+	function image_create($filename, $ext = 'auto') {
56 56
 		if ( $ext == 'auto' ) {
57 57
 			$ext = wp_check_filetype($filename);
58
-			if (isset($ext['ext'])) {
58
+			if ( isset($ext['ext']) ) {
59 59
 				$ext = $ext['ext'];
60 60
 			}
61 61
 		}
@@ -69,6 +69,6 @@  discard block
 block discarded – undo
69 69
 		if ( $ext == 'jpg' || $ext == 'jpeg' ) {
70 70
 			return imagecreatefromjpeg($filename);
71 71
 		}
72
-		throw new InvalidArgumentException( 'image_create only accepts PNG, GIF and JPGs. File extension was: '.$ext );
72
+		throw new InvalidArgumentException('image_create only accepts PNG, GIF and JPGs. File extension was: ' . $ext);
73 73
 	}
74 74
 }
Please login to merge, or discard this patch.