@@ -44,30 +44,30 @@ |
||
44 | 44 | * (ex: /src/var/www/wp-content/uploads/[email protected]) |
45 | 45 | * @return bool true if everything went fine, false otherwise |
46 | 46 | */ |
47 | - function run($load_filename, $save_filename){ |
|
48 | - $image = wp_get_image_editor( $load_filename ); |
|
49 | - if ( !is_wp_error( $image ) ) { |
|
47 | + function run($load_filename, $save_filename) { |
|
48 | + $image = wp_get_image_editor($load_filename); |
|
49 | + if ( !is_wp_error($image) ) { |
|
50 | 50 | $current_size = $image->get_size(); |
51 | 51 | $src_w = $current_size['width']; |
52 | 52 | $src_h = $current_size['height']; |
53 | 53 | // Get ratios |
54 | 54 | $w = $src_w * $this->factor; |
55 | 55 | $h = $src_h * $this->factor; |
56 | - $image->crop( 0, 0, $src_w, $src_h, $w, $h ); |
|
57 | - $result = $image->save( $save_filename ); |
|
58 | - if ( is_wp_error( $result ) ) { |
|
56 | + $image->crop(0, 0, $src_w, $src_h, $w, $h); |
|
57 | + $result = $image->save($save_filename); |
|
58 | + if ( is_wp_error($result) ) { |
|
59 | 59 | // @codeCoverageIgnoreStart |
60 | - TimberHelper::error_log( 'Error resizing image' ); |
|
61 | - TimberHelper::error_log( $result ); |
|
60 | + TimberHelper::error_log('Error resizing image'); |
|
61 | + TimberHelper::error_log($result); |
|
62 | 62 | return false; |
63 | 63 | // @codeCoverageIgnoreEnd |
64 | 64 | } else { |
65 | 65 | return true; |
66 | 66 | } |
67 | - } else if ( isset( $image->error_data['error_loading_image'] ) ) { |
|
68 | - TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] ); |
|
67 | + } else if ( isset($image->error_data['error_loading_image']) ) { |
|
68 | + TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']); |
|
69 | 69 | } else { |
70 | - TimberHelper::error_log( $image ); |
|
70 | + TimberHelper::error_log($image); |
|
71 | 71 | } |
72 | 72 | return false; |
73 | 73 | } |
@@ -21,8 +21,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -35,15 +35,15 @@ discard block |
||
35 | 35 | * (ex: /src/var/www/wp-content/uploads/my-pic.png) |
36 | 36 | * @return bool true if everything went fine, false otherwise |
37 | 37 | */ |
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 ); |
|
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); |
|
47 | 47 | return true; |
48 | 48 | } |
49 | 49 | |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * @return resource an image identifier representing the image obtained from the given filename |
52 | 52 | * will return the same data type regardless of whether the source is gif or png |
53 | 53 | */ |
54 | - function image_create( $filename, $ext = 'auto' ) { |
|
54 | + function image_create($filename, $ext = 'auto') { |
|
55 | 55 | if ( $ext == 'auto' ) { |
56 | 56 | $ext = wp_check_filetype($filename); |
57 | - if (isset($ext['ext'])) { |
|
57 | + if ( isset($ext['ext']) ) { |
|
58 | 58 | $ext = $ext['ext']; |
59 | 59 | } |
60 | 60 | } |
@@ -68,6 +68,6 @@ discard block |
||
68 | 68 | if ( $ext == 'jpg' || $ext == 'jpeg' ) { |
69 | 69 | return imagecreatefromjpeg($filename); |
70 | 70 | } |
71 | - throw new InvalidArgumentException( 'image_create only accepts PNG, GIF and JPGs. File extension was: '.$ext ); |
|
71 | + throw new InvalidArgumentException('image_create only accepts PNG, GIF and JPGs. File extension was: ' . $ext); |
|
72 | 72 | } |
73 | 73 | } |
@@ -8,40 +8,40 @@ discard block |
||
8 | 8 | * @param string $TermClass |
9 | 9 | * @return mixed |
10 | 10 | */ |
11 | - public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){ |
|
12 | - if (is_string($maybe_args) && !strstr($maybe_args, '=')){ |
|
11 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
12 | + if ( is_string($maybe_args) && !strstr($maybe_args, '=') ) { |
|
13 | 13 | //the user is sending the $TermClass in the second argument |
14 | 14 | $TermClass = $maybe_args; |
15 | 15 | } |
16 | - if (is_string($maybe_args) && strstr($maybe_args, '=')){ |
|
16 | + if ( is_string($maybe_args) && strstr($maybe_args, '=') ) { |
|
17 | 17 | parse_str($maybe_args, $maybe_args); |
18 | 18 | } |
19 | - if (is_string($args) && strstr($args, '=')){ |
|
19 | + if ( is_string($args) && strstr($args, '=') ) { |
|
20 | 20 | //a string and a query string! |
21 | 21 | $parsed = self::get_term_query_from_query_string($args); |
22 | - if (is_array($maybe_args)){ |
|
22 | + if ( is_array($maybe_args) ) { |
|
23 | 23 | $parsed->args = array_merge($parsed->args, $maybe_args); |
24 | 24 | } |
25 | 25 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
26 | - } else if (is_string($args)){ |
|
26 | + } else if ( is_string($args) ) { |
|
27 | 27 | //its just a string with a single taxonomy |
28 | 28 | $parsed = self::get_term_query_from_string($args); |
29 | - if (is_array($maybe_args)){ |
|
29 | + if ( is_array($maybe_args) ) { |
|
30 | 30 | $parsed->args = array_merge($parsed->args, $maybe_args); |
31 | 31 | } |
32 | 32 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
33 | - } else if (is_array($args) && TimberHelper::is_array_assoc($args)){ |
|
33 | + } else if ( is_array($args) && TimberHelper::is_array_assoc($args) ) { |
|
34 | 34 | //its an associative array, like a good ole query |
35 | 35 | $parsed = self::get_term_query_from_assoc_array($args); |
36 | 36 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
37 | - } else if (is_array($args)){ |
|
37 | + } else if ( is_array($args) ) { |
|
38 | 38 | //its just an array of strings or IDs (hopefully) |
39 | 39 | $parsed = self::get_term_query_from_array($args); |
40 | - if (is_array($maybe_args)){ |
|
40 | + if ( is_array($maybe_args) ) { |
|
41 | 41 | $parsed->args = array_merge($parsed->args, $maybe_args); |
42 | 42 | } |
43 | 43 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
44 | - } else if (is_null($args)) { |
|
44 | + } else if ( is_null($args) ) { |
|
45 | 45 | return self::handle_term_query(get_taxonomies(), array(), $TermClass); |
46 | 46 | } |
47 | 47 | return null; |
@@ -53,18 +53,18 @@ discard block |
||
53 | 53 | * @param string $TermClass |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public static function handle_term_query($taxonomies, $args, $TermClass){ |
|
57 | - if (!isset($args['hide_empty'])){ |
|
56 | + public static function handle_term_query($taxonomies, $args, $TermClass) { |
|
57 | + if ( !isset($args['hide_empty']) ) { |
|
58 | 58 | $args['hide_empty'] = false; |
59 | 59 | } |
60 | - if (isset($args['term_id']) && is_int($args['term_id'])){ |
|
60 | + if ( isset($args['term_id']) && is_int($args['term_id']) ) { |
|
61 | 61 | $args['term_id'] = array($args['term_id']); |
62 | 62 | } |
63 | - if (isset($args['term_id'])){ |
|
63 | + if ( isset($args['term_id']) ) { |
|
64 | 64 | $args['include'] = $args['term_id']; |
65 | 65 | } |
66 | 66 | $terms = get_terms($taxonomies, $args); |
67 | - foreach($terms as &$term){ |
|
67 | + foreach ($terms as &$term) { |
|
68 | 68 | $term = new $TermClass($term->term_id, $term->taxonomy); |
69 | 69 | } |
70 | 70 | return $terms; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | protected static function get_term_query_from_string($taxs) { |
89 | 89 | $ret = new stdClass(); |
90 | 90 | $ret->args = array(); |
91 | - if (is_string($taxs)) { |
|
91 | + if ( is_string($taxs) ) { |
|
92 | 92 | $taxs = array($taxs); |
93 | 93 | } |
94 | 94 | $ret->taxonomies = self::correct_taxonomy_names($taxs); |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | public static function get_term_query_from_assoc_array($args) { |
103 | 103 | $ret = new stdClass(); |
104 | 104 | $ret->args = $args; |
105 | - if (isset($ret->args['tax'])) { |
|
105 | + if ( isset($ret->args['tax']) ) { |
|
106 | 106 | $ret->taxonomies = $ret->args['tax']; |
107 | - } else if (isset($ret->args['taxonomies'])) { |
|
107 | + } else if ( isset($ret->args['taxonomies']) ) { |
|
108 | 108 | $ret->taxonomies = $ret->args['taxonomies']; |
109 | - } else if (isset($ret->args['taxs'])) { |
|
109 | + } else if ( isset($ret->args['taxs']) ) { |
|
110 | 110 | $ret->taxonomies = $ret->args['taxs']; |
111 | - } else if (isset($ret->args['taxonomy'])) { |
|
111 | + } else if ( isset($ret->args['taxonomy']) ) { |
|
112 | 112 | $ret->taxonomies = $ret->args['taxonomy']; |
113 | 113 | } |
114 | - if (isset($ret->taxonomies)) { |
|
115 | - if (is_string($ret->taxonomies)) { |
|
114 | + if ( isset($ret->taxonomies) ) { |
|
115 | + if ( is_string($ret->taxonomies) ) { |
|
116 | 116 | $ret->taxonomies = array($ret->taxonomies); |
117 | 117 | } |
118 | 118 | $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies); |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | * @return stdClass |
128 | 128 | */ |
129 | 129 | public static function get_term_query_from_array($args) { |
130 | - if (is_array($args) && !empty($args)) { |
|
130 | + if ( is_array($args) && !empty($args) ) { |
|
131 | 131 | //okay its an array with content |
132 | - if (is_int($args[0])) { |
|
132 | + if ( is_int($args[0]) ) { |
|
133 | 133 | return self::get_term_query_from_array_of_ids($args); |
134 | - } else if (is_string($args[0])) { |
|
134 | + } else if ( is_string($args[0]) ) { |
|
135 | 135 | return self::get_term_query_from_array_of_strings($args); |
136 | 136 | } |
137 | 137 | } |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | * @return array |
166 | 166 | */ |
167 | 167 | private static function correct_taxonomy_names($taxs) { |
168 | - if (is_string($taxs)) { |
|
168 | + if ( is_string($taxs) ) { |
|
169 | 169 | $taxs = array($taxs); |
170 | 170 | } |
171 | 171 | foreach ($taxs as &$tax) { |
172 | - if ($tax == 'tags' || $tax == 'tag') { |
|
172 | + if ( $tax == 'tags' || $tax == 'tag' ) { |
|
173 | 173 | $tax = 'post_tag'; |
174 | - } else if ($tax == 'categories') { |
|
174 | + } else if ( $tax == 'categories' ) { |
|
175 | 175 | $tax = 'category'; |
176 | 176 | } |
177 | 177 | } |