@@ -36,14 +36,14 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * } |
55 | 55 | * @param string $base any additional paths that need to be prepended to the URLs that are generated, for example: "tags" |
56 | 56 | */ |
57 | - function __construct( $args = null, $base = '' ) { |
|
57 | + function __construct($args = null, $base = '') { |
|
58 | 58 | $this->init($args, $base); |
59 | 59 | } |
60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param array|string $args |
64 | 64 | * @param string $base |
65 | 65 | */ |
66 | - function init( $args = null, $base = '' ) { |
|
66 | + function init($args = null, $base = '') { |
|
67 | 67 | $this->base = $base; |
68 | 68 | $this->items = $this->get_items($args); |
69 | 69 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param string $text |
75 | 75 | * @return mixed |
76 | 76 | */ |
77 | - protected function get_archives_link( $url, $text ) { |
|
77 | + protected function get_archives_link($url, $text) { |
|
78 | 78 | $ret = array(); |
79 | 79 | $ret['text'] = $ret['title'] = $ret['name'] = wptexturize($text); |
80 | 80 | $ret['url'] = $ret['link'] = esc_url(TimberURLHelper::prepend_to_url($url, $this->base)); |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | * @param string $limit |
92 | 92 | * @return array |
93 | 93 | */ |
94 | - protected function get_items_yearly( $args, $last_changed, $join, $where, $order, $limit ) { |
|
94 | + protected function get_items_yearly($args, $last_changed, $join, $where, $order, $limit) { |
|
95 | 95 | global $wpdb; |
96 | 96 | $output = array(); |
97 | 97 | $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit"; |
98 | 98 | $key = md5($query); |
99 | 99 | $key = "wp_get_archives:$key:$last_changed"; |
100 | - if (!$results = wp_cache_get($key, 'posts')) { |
|
100 | + if ( !$results = wp_cache_get($key, 'posts') ) { |
|
101 | 101 | $results = $wpdb->get_results($query); |
102 | 102 | wp_cache_set($key, $results, 'posts'); |
103 | 103 | } |
104 | - if ($results) { |
|
105 | - foreach ( (array)$results as $result ) { |
|
106 | - $url = get_year_link( $result->year ); |
|
104 | + if ( $results ) { |
|
105 | + foreach ((array) $results as $result) { |
|
106 | + $url = get_year_link($result->year); |
|
107 | 107 | $text = sprintf('%d', $result->year); |
108 | 108 | $output[] = $this->get_archives_link($url, $text); |
109 | 109 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @param bool $nested |
123 | 123 | * @return array |
124 | 124 | */ |
125 | - protected function get_items_monthly( $args, $last_changed, $join, $where, $order, $limit = 1000, $nested = true ) { |
|
125 | + protected function get_items_monthly($args, $last_changed, $join, $where, $order, $limit = 1000, $nested = true) { |
|
126 | 126 | global $wpdb, $wp_locale; |
127 | 127 | $output = array(); |
128 | 128 | $defaults = array( |
@@ -137,26 +137,26 @@ discard block |
||
137 | 137 | . "ORDER BY post_date $order $limit"; |
138 | 138 | $key = md5($query); |
139 | 139 | $key = "wp_get_archives:$key:$last_changed"; |
140 | - if (!$results = wp_cache_get($key, 'posts')) { |
|
140 | + if ( !$results = wp_cache_get($key, 'posts') ) { |
|
141 | 141 | $results = $wpdb->get_results($query); |
142 | 142 | wp_cache_set($key, $results, 'posts'); |
143 | 143 | } |
144 | - if ($results) { |
|
145 | - foreach ((array)$results as $result) { |
|
144 | + if ( $results ) { |
|
145 | + foreach ((array) $results as $result) { |
|
146 | 146 | $url = get_month_link($result->year, $result->month); |
147 | - if ($show_year && !$nested) { |
|
147 | + if ( $show_year && !$nested ) { |
|
148 | 148 | $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year); |
149 | 149 | } else { |
150 | 150 | $text = sprintf(__('%1$s'), $wp_locale->get_month($result->month)); |
151 | 151 | } |
152 | - if ($nested) { |
|
152 | + if ( $nested ) { |
|
153 | 153 | $output[$result->year][] = $this->get_archives_link($url, $text); |
154 | 154 | } else { |
155 | 155 | $output[] = $this->get_archives_link($url, $text); |
156 | 156 | } |
157 | 157 | } |
158 | 158 | } |
159 | - if ($nested) { |
|
159 | + if ( $nested ) { |
|
160 | 160 | $out2 = array(); |
161 | 161 | foreach ($output as $year => $months) { |
162 | 162 | $out2[] = array('name' => $year, 'children' => $months); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param array|string $args |
172 | 172 | * @return array|string |
173 | 173 | */ |
174 | - function get_items( $args = null ) { |
|
174 | + function get_items($args = null) { |
|
175 | 175 | global $wpdb; |
176 | 176 | |
177 | 177 | $defaults = array( |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $archive_week_start_date_format = 'Y/m/d'; |
221 | 221 | $archive_week_end_date_format = 'Y/m/d'; |
222 | 222 | |
223 | - if (!$archive_date_format_over_ride) { |
|
223 | + if ( !$archive_date_format_over_ride ) { |
|
224 | 224 | $archive_day_date_format = get_option('date_format'); |
225 | 225 | $archive_week_start_date_format = get_option('date_format'); |
226 | 226 | $archive_week_end_date_format = get_option('date_format'); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | $output = array(); |
234 | 234 | $last_changed = wp_cache_get('last_changed', 'posts'); |
235 | - if (!$last_changed) { |
|
235 | + if ( !$last_changed ) { |
|
236 | 236 | $last_changed = microtime(); |
237 | 237 | wp_cache_set('last_changed', $last_changed, 'posts'); |
238 | 238 | } |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit"; |
247 | 247 | $key = md5($query); |
248 | 248 | $key = "wp_get_archives:$key:$last_changed"; |
249 | - if (!$results = wp_cache_get($key, 'posts')) { |
|
249 | + if ( !$results = wp_cache_get($key, 'posts') ) { |
|
250 | 250 | $results = $wpdb->get_results($query); |
251 | 251 | $cache = array(); |
252 | 252 | $cache[$key] = $results; |
253 | 253 | wp_cache_set($key, $results, 'posts'); |
254 | 254 | } |
255 | 255 | if ( $results ) { |
256 | - foreach ( (array)$results as $result ) { |
|
256 | + foreach ((array) $results as $result) { |
|
257 | 257 | $url = get_day_link($result->year, $result->month, $result->dayofmonth); |
258 | 258 | $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth); |
259 | 259 | $text = mysql2date($archive_day_date_format, $date); |
@@ -266,13 +266,13 @@ discard block |
||
266 | 266 | . "count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit"; |
267 | 267 | $key = md5($query); |
268 | 268 | $key = "wp_get_archives:$key:$last_changed"; |
269 | - if (!$results = wp_cache_get($key, 'posts')) { |
|
269 | + if ( !$results = wp_cache_get($key, 'posts') ) { |
|
270 | 270 | $results = $wpdb->get_results($query); |
271 | 271 | wp_cache_set($key, $results, 'posts'); |
272 | 272 | } |
273 | 273 | $arc_w_last = ''; |
274 | 274 | if ( $results ) { |
275 | - foreach ( (array)$results as $result ) { |
|
275 | + foreach ((array) $results as $result) { |
|
276 | 276 | if ( $result->week != $arc_w_last ) { |
277 | 277 | $arc_year = $result->yr; |
278 | 278 | $arc_w_last = $result->week; |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | wp_cache_set($key, $results, 'posts'); |
296 | 296 | } |
297 | 297 | if ( $results ) { |
298 | - foreach ( (array)$results as $result ) { |
|
299 | - if ($result->post_date != '0000-00-00 00:00:00') { |
|
298 | + foreach ((array) $results as $result) { |
|
299 | + if ( $result->post_date != '0000-00-00 00:00:00' ) { |
|
300 | 300 | $url = get_permalink($result); |
301 | - if ($result->post_title) { |
|
301 | + if ( $result->post_title ) { |
|
302 | 302 | /** This filter is documented in wp-includes/post-template.php */ |
303 | 303 | $text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID)); |
304 | 304 | } else { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * (ex: my-awesome-pic-lbox-300x200-FF3366.jpg) |
31 | 31 | */ |
32 | 32 | public function filename($src_filename, $src_extension) { |
33 | - $color = str_replace( '#', '', $this->color ); |
|
33 | + $color = str_replace('#', '', $this->color); |
|
34 | 34 | $newbase = $src_filename . '-lbox-' . $this->w . 'x' . $this->h . '-' . $color; |
35 | 35 | $new_name = $newbase . '.' . $src_extension; |
36 | 36 | return $new_name; |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | $w = $this->w; |
51 | 51 | $h = $this->h; |
52 | 52 | |
53 | - $bg = imagecreatetruecolor( $w, $h ); |
|
54 | - $c = self::hexrgb( $this->color ); |
|
55 | - $bgColor = imagecolorallocate( $bg, $c['red'], $c['green'], $c['blue'] ); |
|
56 | - imagefill( $bg, 0, 0, $bgColor ); |
|
57 | - $image = wp_get_image_editor( $load_filename ); |
|
58 | - if ( !is_wp_error( $image ) ) { |
|
53 | + $bg = imagecreatetruecolor($w, $h); |
|
54 | + $c = self::hexrgb($this->color); |
|
55 | + $bgColor = imagecolorallocate($bg, $c['red'], $c['green'], $c['blue']); |
|
56 | + imagefill($bg, 0, 0, $bgColor); |
|
57 | + $image = wp_get_image_editor($load_filename); |
|
58 | + if ( !is_wp_error($image) ) { |
|
59 | 59 | $current_size = $image->get_size(); |
60 | 60 | $quality = $image->get_quality(); |
61 | 61 | $ow = $current_size['width']; |
@@ -69,38 +69,38 @@ discard block |
||
69 | 69 | $y = 0; |
70 | 70 | $x = $w / 2 - $owt / 2; |
71 | 71 | $oht = $h; |
72 | - $image->crop( 0, 0, $ow, $oh, $owt, $oht ); |
|
72 | + $image->crop(0, 0, $ow, $oh, $owt, $oht); |
|
73 | 73 | } else { |
74 | 74 | $w_scale = $w / $ow; |
75 | 75 | $oht = $oh * $w_scale; |
76 | 76 | $x = 0; |
77 | 77 | $y = $h / 2 - $oht / 2; |
78 | 78 | $owt = $w; |
79 | - $image->crop( 0, 0, $ow, $oh, $owt, $oht ); |
|
79 | + $image->crop(0, 0, $ow, $oh, $owt, $oht); |
|
80 | 80 | } |
81 | - $result = $image->save( $save_filename ); |
|
81 | + $result = $image->save($save_filename); |
|
82 | 82 | $func = 'imagecreatefromjpeg'; |
83 | 83 | $save_func = 'imagejpeg'; |
84 | - $ext = pathinfo( $save_filename, PATHINFO_EXTENSION ); |
|
84 | + $ext = pathinfo($save_filename, PATHINFO_EXTENSION); |
|
85 | 85 | if ( $ext == 'gif' ) { |
86 | 86 | $func = 'imagecreatefromgif'; |
87 | 87 | $save_func = 'imagegif'; |
88 | 88 | } else if ( $ext == 'png' ) { |
89 | 89 | $func = 'imagecreatefrompng'; |
90 | 90 | $save_func = 'imagepng'; |
91 | - if ($quality > 9) { |
|
92 | - $quality = $quality/10; |
|
91 | + if ( $quality > 9 ) { |
|
92 | + $quality = $quality / 10; |
|
93 | 93 | $quality = round(10 - $quality); |
94 | 94 | } |
95 | 95 | } |
96 | - $image = $func( $save_filename ); |
|
97 | - imagecopy( $bg, $image, $x, $y, 0, 0, $owt, $oht ); |
|
98 | - if ($save_func === 'imagegif') { |
|
99 | - return $save_func( $bg, $save_filename ); |
|
96 | + $image = $func($save_filename); |
|
97 | + imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht); |
|
98 | + if ( $save_func === 'imagegif' ) { |
|
99 | + return $save_func($bg, $save_filename); |
|
100 | 100 | } |
101 | - return $save_func( $bg, $save_filename, $quality ); |
|
101 | + return $save_func($bg, $save_filename, $quality); |
|
102 | 102 | } else { |
103 | - TimberHelper::error_log( $image ); |
|
103 | + TimberHelper::error_log($image); |
|
104 | 104 | } |
105 | 105 | return false; |
106 | 106 | } |