@@ -7,16 +7,16 @@ |
||
7 | 7 | class TimberIntegrations { |
8 | 8 | public static function init() { |
9 | 9 | |
10 | - add_action( 'init', array( __CLASS__, 'maybe_init_acftimber' ) ); |
|
10 | + add_action('init', array(__CLASS__, 'maybe_init_acftimber')); |
|
11 | 11 | |
12 | - if ( class_exists( 'WP_CLI_Command' ) ) { |
|
13 | - WP_CLI::add_command( 'timber', 'Timber_WP_CLI_Command' ); |
|
12 | + if ( class_exists('WP_CLI_Command') ) { |
|
13 | + WP_CLI::add_command('timber', 'Timber_WP_CLI_Command'); |
|
14 | 14 | } |
15 | 15 | } |
16 | 16 | |
17 | 17 | public static function maybe_init_acftimber() { |
18 | 18 | |
19 | - if ( class_exists( 'ACF' ) ) { |
|
19 | + if ( class_exists('ACF') ) { |
|
20 | 20 | new ACFTimber(); |
21 | 21 | } |
22 | 22 |
@@ -14,11 +14,11 @@ |
||
14 | 14 | // we look for Composer files first in the plugins dir. |
15 | 15 | // then in the wp-content dir (site install). |
16 | 16 | // and finally in the current themes directories. |
17 | -if ( file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* check in self */ |
|
18 | - || file_exists( $composer_autoload = WP_CONTENT_DIR.'/vendor/autoload.php') /* check in wp-content */ |
|
19 | - || file_exists( $composer_autoload = plugin_dir_path( __FILE__ ).'vendor/autoload.php') /* check in plugin directory */ |
|
20 | - || file_exists( $composer_autoload = get_stylesheet_directory().'/vendor/autoload.php') /* check in child theme */ |
|
21 | - || file_exists( $composer_autoload = get_template_directory().'/vendor/autoload.php') /* check in parent theme */ |
|
17 | +if ( file_exists($composer_autoload = __DIR__ . '/vendor/autoload.php') /* check in self */ |
|
18 | + || file_exists($composer_autoload = WP_CONTENT_DIR . '/vendor/autoload.php') /* check in wp-content */ |
|
19 | + || file_exists($composer_autoload = plugin_dir_path(__FILE__) . 'vendor/autoload.php') /* check in plugin directory */ |
|
20 | + || file_exists($composer_autoload = get_stylesheet_directory() . '/vendor/autoload.php') /* check in child theme */ |
|
21 | + || file_exists($composer_autoload = get_template_directory() . '/vendor/autoload.php') /* check in parent theme */ |
|
22 | 22 | ) { |
23 | 23 | require_once $composer_autoload; |
24 | 24 | } |
@@ -1,50 +1,50 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( !defined( 'ABSPATH' ) ) |
|
4 | +if ( !defined('ABSPATH') ) |
|
5 | 5 | exit; |
6 | 6 | |
7 | 7 | class TimberPostsCollection extends ArrayObject { |
8 | 8 | |
9 | 9 | public function __construct( $posts = array(), $post_class = 'TimberPost' ) { |
10 | 10 | $returned_posts = array(); |
11 | - if ( is_null( $posts ) ){ |
|
11 | + if ( is_null($posts) ) { |
|
12 | 12 | $posts = array(); |
13 | 13 | } |
14 | 14 | foreach ( $posts as $post_object ) { |
15 | 15 | $post_class_use = $post_class; |
16 | 16 | |
17 | - if ( is_array( $post_class ) ) { |
|
18 | - $post_type = get_post_type( $post_object ); |
|
17 | + if ( is_array($post_class) ) { |
|
18 | + $post_type = get_post_type($post_object); |
|
19 | 19 | $post_class_use = 'TimberPost'; |
20 | 20 | |
21 | - if ( isset( $post_class[$post_type] ) ) { |
|
21 | + if ( isset($post_class[$post_type]) ) { |
|
22 | 22 | $post_class_use = $post_class[$post_type]; |
23 | 23 | |
24 | 24 | } else { |
25 | - if ( is_array( $post_class ) ) { |
|
26 | - TimberHelper::error_log( $post_type . ' of ' . $post_object->ID . ' not found in ' . print_r( $post_class, true ) ); |
|
25 | + if ( is_array($post_class) ) { |
|
26 | + TimberHelper::error_log($post_type . ' of ' . $post_object->ID . ' not found in ' . print_r($post_class, true)); |
|
27 | 27 | } else { |
28 | - TimberHelper::error_log( $post_type . ' not found in ' . $post_class ); |
|
28 | + TimberHelper::error_log($post_type . ' not found in ' . $post_class); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | 33 | // Don't create yet another object if $post_object is already of the right type |
34 | - if ( is_a( $post_object, $post_class_use ) ) { |
|
34 | + if ( is_a($post_object, $post_class_use) ) { |
|
35 | 35 | $post = $post_object; |
36 | 36 | } else { |
37 | - $post = new $post_class_use( $post_object ); |
|
37 | + $post = new $post_class_use($post_object); |
|
38 | 38 | } |
39 | 39 | |
40 | - if ( isset( $post->ID ) ) { |
|
40 | + if ( isset($post->ID) ) { |
|
41 | 41 | $returned_posts[] = $post; |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | $returned_posts = self::maybe_set_preview($returned_posts); |
46 | 46 | |
47 | - parent::__construct( $returned_posts, $flags = 0, 'TimberPostsIterator' ); |
|
47 | + parent::__construct($returned_posts, $flags = 0, 'TimberPostsIterator'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public function get_posts() { |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | * @return array |
57 | 57 | */ |
58 | 58 | static function maybe_set_preview( $posts ) { |
59 | - if ( is_array( $posts ) && isset( $_GET['preview'] ) && $_GET['preview'] |
|
60 | - && isset( $_GET['preview_id'] ) && $_GET['preview_id'] |
|
61 | - && current_user_can( 'edit_post', $_GET['preview_id'] ) ) { |
|
59 | + if ( is_array($posts) && isset($_GET['preview']) && $_GET['preview'] |
|
60 | + && isset($_GET['preview_id']) && $_GET['preview_id'] |
|
61 | + && current_user_can('edit_post', $_GET['preview_id']) ) { |
|
62 | 62 | // No need to check the nonce, that already happened in _show_post_preview on init |
63 | 63 | |
64 | 64 | $preview_id = $_GET['preview_id']; |
65 | - foreach( $posts as &$post ) { |
|
66 | - if ( is_object( $post ) && $post->ID == $preview_id ) { |
|
65 | + foreach ( $posts as &$post ) { |
|
66 | + if ( is_object($post) && $post->ID == $preview_id ) { |
|
67 | 67 | // Based on _set_preview( $post ), but adds import_custom |
68 | - $preview = wp_get_post_autosave( $preview_id ); |
|
68 | + $preview = wp_get_post_autosave($preview_id); |
|
69 | 69 | if ( is_object($preview) ) { |
70 | 70 | |
71 | 71 | $preview = sanitize_post($preview); |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | $post->post_content = $preview->post_content; |
74 | 74 | $post->post_title = $preview->post_title; |
75 | 75 | $post->post_excerpt = $preview->post_excerpt; |
76 | - $post->import_custom( $preview_id ); |
|
76 | + $post->import_custom($preview_id); |
|
77 | 77 | |
78 | - add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); |
|
78 | + add_filter('get_the_terms', '_wp_preview_terms_filter', 10, 3); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | } |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | */ |
10 | 10 | public static function get_current_url() { |
11 | 11 | $pageURL = "http://"; |
12 | - if ( isset( $_SERVER['HTTPS'] ) && $_SERVER["HTTPS"] == "on" ) { |
|
13 | - $pageURL = "https://";; |
|
12 | + if ( isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on" ) { |
|
13 | + $pageURL = "https://"; ; |
|
14 | 14 | } |
15 | 15 | if ( isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] && $_SERVER["SERVER_PORT"] != "80" ) { |
16 | 16 | $pageURL .= self::get_host() . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | * @return bool |
28 | 28 | */ |
29 | 29 | public static function is_url( $url ) { |
30 | - if ( !is_string( $url ) ) { |
|
30 | + if ( !is_string($url) ) { |
|
31 | 31 | return false; |
32 | 32 | } |
33 | - $url = strtolower( $url ); |
|
34 | - if ( strstr( $url, '://' ) ) { |
|
33 | + $url = strtolower($url); |
|
34 | + if ( strstr($url, '://') ) { |
|
35 | 35 | return true; |
36 | 36 | } |
37 | 37 | return false; |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | * @return string |
44 | 44 | */ |
45 | 45 | public static function get_path_base() { |
46 | - $struc = get_option( 'permalink_structure' ); |
|
47 | - $struc = explode( '/', $struc ); |
|
46 | + $struc = get_option('permalink_structure'); |
|
47 | + $struc = explode('/', $struc); |
|
48 | 48 | $p = '/'; |
49 | 49 | foreach ( $struc as $s ) { |
50 | - if ( !strstr( $s, '%' ) && strlen( $s ) ) { |
|
50 | + if ( !strstr($s, '%') && strlen($s) ) { |
|
51 | 51 | $p .= $s . '/'; |
52 | 52 | } |
53 | 53 | } |
@@ -62,21 +62,21 @@ discard block |
||
62 | 62 | * @return string |
63 | 63 | */ |
64 | 64 | public static function get_rel_url( $url, $force = false ) { |
65 | - $url_info = parse_url( $url ); |
|
66 | - if ( isset( $url_info['host'] ) && $url_info['host'] != self::get_host() && !$force ) { |
|
65 | + $url_info = parse_url($url); |
|
66 | + if ( isset($url_info['host']) && $url_info['host'] != self::get_host() && !$force ) { |
|
67 | 67 | return $url; |
68 | 68 | } |
69 | 69 | $link = ''; |
70 | - if ( isset( $url_info['path'] ) ) { |
|
70 | + if ( isset($url_info['path']) ) { |
|
71 | 71 | $link = $url_info['path']; |
72 | 72 | } |
73 | - if ( isset( $url_info['query'] ) && strlen( $url_info['query'] ) ) { |
|
73 | + if ( isset($url_info['query']) && strlen($url_info['query']) ) { |
|
74 | 74 | $link .= '?' . $url_info['query']; |
75 | 75 | } |
76 | - if ( isset( $url_info['fragment'] ) && strlen( $url_info['fragment'] ) ) { |
|
76 | + if ( isset($url_info['fragment']) && strlen($url_info['fragment']) ) { |
|
77 | 77 | $link .= '#' . $url_info['fragment']; |
78 | 78 | } |
79 | - $link = TimberURLHelper::remove_double_slashes( $link ); |
|
79 | + $link = TimberURLHelper::remove_double_slashes($link); |
|
80 | 80 | return $link; |
81 | 81 | } |
82 | 82 | |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | * @return string the HTTP_HOST or SERVER_NAME |
87 | 87 | */ |
88 | 88 | public static function get_host() { |
89 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
89 | + if ( isset($_SERVER['HTTP_HOST']) ) { |
|
90 | 90 | return $_SERVER['HTTP_HOST']; |
91 | 91 | } |
92 | - if (isset($_SERVER['SERVER_NAME'])) { |
|
92 | + if ( isset($_SERVER['SERVER_NAME']) ) { |
|
93 | 93 | return $_SERVER['SERVER_NAME']; |
94 | 94 | } |
95 | 95 | return ''; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @return bool |
103 | 103 | */ |
104 | 104 | public static function is_local( $url ) { |
105 | - if ( strstr( $url, self::get_host() ) ) { |
|
105 | + if ( strstr($url, self::get_host()) ) { |
|
106 | 106 | return true; |
107 | 107 | } |
108 | 108 | return false; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | public static function get_full_path( $src ) { |
118 | 118 | $root = ABSPATH; |
119 | 119 | $old_root_path = $root . $src; |
120 | - $old_root_path = str_replace( '//', '/', $old_root_path ); |
|
120 | + $old_root_path = str_replace('//', '/', $old_root_path); |
|
121 | 121 | return $old_root_path; |
122 | 122 | } |
123 | 123 | |
@@ -130,15 +130,15 @@ discard block |
||
130 | 130 | * @return string |
131 | 131 | */ |
132 | 132 | public static function url_to_file_system( $url ) { |
133 | - $url_parts = parse_url( $url ); |
|
133 | + $url_parts = parse_url($url); |
|
134 | 134 | $path = ABSPATH . $url_parts['path']; |
135 | - $path = str_replace( '//', '/', $path ); |
|
135 | + $path = str_replace('//', '/', $path); |
|
136 | 136 | return $path; |
137 | 137 | } |
138 | 138 | |
139 | 139 | public static function file_system_to_url( $fs ) { |
140 | - $relative_path = self::get_rel_path( $fs ); |
|
141 | - $home = home_url( '/'.$relative_path ); |
|
140 | + $relative_path = self::get_rel_path($fs); |
|
141 | + $home = home_url('/' . $relative_path); |
|
142 | 142 | return $home; |
143 | 143 | } |
144 | 144 | |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | public static function get_rel_path( $src ) { |
152 | - if ( strstr( $src, ABSPATH ) ) { |
|
153 | - return str_replace( ABSPATH, '', $src ); |
|
152 | + if ( strstr($src, ABSPATH) ) { |
|
153 | + return str_replace(ABSPATH, '', $src); |
|
154 | 154 | } |
155 | 155 | //its outside the wordpress directory, alternate setups: |
156 | - $src = str_replace( WP_CONTENT_DIR, '', $src ); |
|
156 | + $src = str_replace(WP_CONTENT_DIR, '', $src); |
|
157 | 157 | return WP_CONTENT_SUBDIR . $src; |
158 | 158 | } |
159 | 159 | |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | * @return string |
165 | 165 | */ |
166 | 166 | public static function remove_double_slashes( $url ) { |
167 | - $url = str_replace( '//', '/', $url ); |
|
168 | - if ( strstr( $url, 'http:' ) && !strstr( $url, 'http://' ) ) { |
|
169 | - $url = str_replace( 'http:/', 'http://', $url ); |
|
167 | + $url = str_replace('//', '/', $url); |
|
168 | + if ( strstr($url, 'http:') && !strstr($url, 'http://') ) { |
|
169 | + $url = str_replace('http:/', 'http://', $url); |
|
170 | 170 | } |
171 | 171 | return $url; |
172 | 172 | } |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | * @return string |
180 | 180 | */ |
181 | 181 | public static function prepend_to_url( $url, $path ) { |
182 | - if ( strstr( strtolower( $url ), 'http' ) ) { |
|
183 | - $url_parts = parse_url( $url ); |
|
182 | + if ( strstr(strtolower($url), 'http') ) { |
|
183 | + $url_parts = parse_url($url); |
|
184 | 184 | $url = $url_parts['scheme'] . '://' . $url_parts['host'] . $path . $url_parts['path']; |
185 | - if ( isset( $url_parts['query'] ) ) { |
|
185 | + if ( isset($url_parts['query']) ) { |
|
186 | 186 | $url .= $url_parts['query']; |
187 | 187 | } |
188 | - if ( isset( $url_parts['fragment'] ) ) { |
|
188 | + if ( isset($url_parts['fragment']) ) { |
|
189 | 189 | $url .= $url_parts['fragment']; |
190 | 190 | } |
191 | 191 | } else { |
192 | 192 | $url = $url . $path; |
193 | 193 | } |
194 | - return self::remove_double_slashes( $url ); |
|
194 | + return self::remove_double_slashes($url); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @return string |
202 | 202 | */ |
203 | 203 | public static function preslashit( $path ) { |
204 | - if ( strpos( $path, '/' ) != 0 ) { |
|
204 | + if ( strpos($path, '/') != 0 ) { |
|
205 | 205 | $path = '/' . $path; |
206 | 206 | } |
207 | 207 | return $path; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @return boolean true if $path is an absolute url, false if relative. |
214 | 214 | */ |
215 | 215 | public static function is_absolute( $path ) { |
216 | - return (boolean) ( strstr( $path, 'http' ) ); |
|
216 | + return (boolean) (strstr($path, 'http')); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -225,21 +225,21 @@ discard block |
||
225 | 225 | * @return boolean if $url points to an external location returns true |
226 | 226 | */ |
227 | 227 | public static function is_external_content( $url ) { |
228 | - $is_external = TimberURLHelper::is_absolute( $url ) && ! TimberURLHelper::is_internal_content( $url ); |
|
228 | + $is_external = TimberURLHelper::is_absolute($url) && !TimberURLHelper::is_internal_content($url); |
|
229 | 229 | |
230 | 230 | return $is_external; |
231 | 231 | } |
232 | 232 | |
233 | - private static function is_internal_content($url) { |
|
233 | + private static function is_internal_content( $url ) { |
|
234 | 234 | // using content_url() instead of site_url or home_url is IMPORTANT |
235 | 235 | // otherwise you run into errors with sites that: |
236 | 236 | // 1. use WPML plugin |
237 | 237 | // 2. or redefine content directory |
238 | - $is_content_url = strstr( $url, content_url() ); |
|
238 | + $is_content_url = strstr($url, content_url()); |
|
239 | 239 | |
240 | 240 | // this case covers when the upload directory has been redefined |
241 | 241 | $upload_dir = wp_upload_dir(); |
242 | - $is_upload_url = strstr( $url, $upload_dir['baseurl'] ); |
|
242 | + $is_upload_url = strstr($url, $upload_dir['baseurl']); |
|
243 | 243 | |
244 | 244 | return $is_content_url || $is_upload_url; |
245 | 245 | } |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * true if it's a subdomain (http://cdn.example.org = true) |
253 | 253 | */ |
254 | 254 | public static function is_external( $url ) { |
255 | - $has_http = strstr( strtolower( $url ), 'http' ); |
|
256 | - $on_domain = strstr( $url, self::get_host() ); |
|
255 | + $has_http = strstr(strtolower($url), 'http'); |
|
256 | + $on_domain = strstr($url, self::get_host()); |
|
257 | 257 | if ( $has_http && !$on_domain ) { |
258 | 258 | return true; |
259 | 259 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | public static function remove_trailing_slash( $link ) { |
270 | 270 | if ( $link != "/" ) |
271 | - $link = untrailingslashit( $link ); |
|
271 | + $link = untrailingslashit($link); |
|
272 | 272 | return $link; |
273 | 273 | } |
274 | 274 | |
@@ -282,23 +282,23 @@ discard block |
||
282 | 282 | */ |
283 | 283 | static function download_url( $url, $timeout = 300 ) { |
284 | 284 | if ( !$url ) { |
285 | - return new WP_Error( 'http_no_url', __( 'Invalid URL Provided.' ) ); |
|
285 | + return new WP_Error('http_no_url', __('Invalid URL Provided.')); |
|
286 | 286 | } |
287 | 287 | |
288 | - $tmpfname = wp_tempnam( $url ); |
|
288 | + $tmpfname = wp_tempnam($url); |
|
289 | 289 | if ( !$tmpfname ) { |
290 | - return new WP_Error( 'http_no_file', __( 'Could not create Temporary file.' ) ); |
|
290 | + return new WP_Error('http_no_file', __('Could not create Temporary file.')); |
|
291 | 291 | } |
292 | 292 | |
293 | - $response = wp_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) ); |
|
293 | + $response = wp_remote_get($url, array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname)); |
|
294 | 294 | |
295 | - if ( is_wp_error( $response ) ) { |
|
296 | - unlink( $tmpfname ); |
|
295 | + if ( is_wp_error($response) ) { |
|
296 | + unlink($tmpfname); |
|
297 | 297 | return $response; |
298 | 298 | } |
299 | - if ( 200 != wp_remote_retrieve_response_code( $response ) ) { |
|
300 | - unlink( $tmpfname ); |
|
301 | - return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) ); |
|
299 | + if ( 200 != wp_remote_retrieve_response_code($response) ) { |
|
300 | + unlink($tmpfname); |
|
301 | + return new WP_Error('http_404', trim(wp_remote_retrieve_response_message($response))); |
|
302 | 302 | } |
303 | 303 | return $tmpfname; |
304 | 304 | } |
@@ -312,10 +312,10 @@ discard block |
||
312 | 312 | * @return array|string |
313 | 313 | */ |
314 | 314 | public static function get_params( $i = false ) { |
315 | - $args = explode( '/', trim( strtolower( $_SERVER['REQUEST_URI'] ) ) ); |
|
315 | + $args = explode('/', trim(strtolower($_SERVER['REQUEST_URI']))); |
|
316 | 316 | $newargs = array(); |
317 | 317 | foreach ( $args as $arg ) { |
318 | - if ( strlen( $arg ) ) { |
|
318 | + if ( strlen($arg) ) { |
|
319 | 319 | $newargs[] = $arg; |
320 | 320 | } |
321 | 321 | } |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | } |
325 | 325 | if ( $i < 0 ) { |
326 | 326 | //count from end |
327 | - $i = count( $newargs ) + $i; |
|
327 | + $i = count($newargs) + $i; |
|
328 | 328 | } |
329 | - if ( isset( $newargs[$i] ) ) { |
|
329 | + if ( isset($newargs[$i]) ) { |
|
330 | 330 | return $newargs[$i]; |
331 | 331 | } |
332 | 332 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | function __construct( $site_name_or_id = null ) { |
105 | 105 | $this->init(); |
106 | 106 | if ( is_multisite() ) { |
107 | - $this->init_as_multisite( $site_name_or_id ); |
|
107 | + $this->init_as_multisite($site_name_or_id); |
|
108 | 108 | } else { |
109 | 109 | $this->init_as_singlesite(); |
110 | 110 | } |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | $site_name_or_id = get_current_blog_id(); |
123 | 123 | } |
124 | 124 | } |
125 | - $info = get_blog_details( $site_name_or_id ); |
|
126 | - $this->import( $info ); |
|
125 | + $info = get_blog_details($site_name_or_id); |
|
126 | + $this->import($info); |
|
127 | 127 | $this->ID = $info->blog_id; |
128 | 128 | $this->id = $this->ID; |
129 | 129 | $this->name = $this->blogname; |
130 | 130 | $this->title = $this->blogname; |
131 | 131 | $this->url = $this->siteurl; |
132 | - $theme_slug = get_blog_option( $info->blog_id, 'stylesheet' ); |
|
133 | - $this->theme = new TimberTheme( $theme_slug ); |
|
134 | - $this->description = get_blog_option( $info->blog_id, 'blogdescription' ); |
|
135 | - $this->admin_email = get_blog_option( $info->blog_id, 'admin_email' ); |
|
132 | + $theme_slug = get_blog_option($info->blog_id, 'stylesheet'); |
|
133 | + $this->theme = new TimberTheme($theme_slug); |
|
134 | + $this->description = get_blog_option($info->blog_id, 'blogdescription'); |
|
135 | + $this->admin_email = get_blog_option($info->blog_id, 'admin_email'); |
|
136 | 136 | $this->multisite = true; |
137 | 137 | } |
138 | 138 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @internal |
142 | 142 | */ |
143 | 143 | protected function init_as_singlesite() { |
144 | - $this->admin_email = get_bloginfo( 'admin_email' ); |
|
145 | - $this->name = get_bloginfo( 'name' ); |
|
144 | + $this->admin_email = get_bloginfo('admin_email'); |
|
145 | + $this->name = get_bloginfo('name'); |
|
146 | 146 | $this->title = $this->name; |
147 | - $this->description = get_bloginfo( 'description' ); |
|
148 | - $this->url = get_bloginfo( 'url' ); |
|
147 | + $this->description = get_bloginfo('description'); |
|
148 | + $this->url = get_bloginfo('url'); |
|
149 | 149 | $this->theme = new TimberTheme(); |
150 | - $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' ); |
|
150 | + $this->language_attributes = TimberHelper::function_wrapper('language_attributes'); |
|
151 | 151 | $this->multisite = false; |
152 | 152 | } |
153 | 153 | |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | * @internal |
157 | 157 | */ |
158 | 158 | protected function init() { |
159 | - $this->rdf = get_bloginfo( 'rdf_url' ); |
|
160 | - $this->rss = get_bloginfo( 'rss_url' ); |
|
161 | - $this->rss2 = get_bloginfo( 'rss2_url' ); |
|
162 | - $this->atom = get_bloginfo( 'atom_url' ); |
|
163 | - $this->language = get_bloginfo( 'language' ); |
|
164 | - $this->charset = get_bloginfo( 'charset' ); |
|
165 | - $this->pingback = get_bloginfo( 'pingback_url' ); |
|
166 | - $this->language_attributes = TimberHelper::function_wrapper( 'language_attributes' ); |
|
159 | + $this->rdf = get_bloginfo('rdf_url'); |
|
160 | + $this->rss = get_bloginfo('rss_url'); |
|
161 | + $this->rss2 = get_bloginfo('rss2_url'); |
|
162 | + $this->atom = get_bloginfo('atom_url'); |
|
163 | + $this->language = get_bloginfo('language'); |
|
164 | + $this->charset = get_bloginfo('charset'); |
|
165 | + $this->pingback = get_bloginfo('pingback_url'); |
|
166 | + $this->language_attributes = TimberHelper::function_wrapper('language_attributes'); |
|
167 | 167 | /* deprecated benath this comment */ |
168 | - $this->pingback_url = get_bloginfo( 'pingback_url' ); |
|
168 | + $this->pingback_url = get_bloginfo('pingback_url'); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | * @return mixed |
176 | 176 | */ |
177 | 177 | function __get( $field ) { |
178 | - if ( !isset( $this->$field ) ) { |
|
178 | + if ( !isset($this->$field) ) { |
|
179 | 179 | if ( is_multisite() ) { |
180 | - $this->$field = get_blog_option( $this->ID, $field ); |
|
180 | + $this->$field = get_blog_option($this->ID, $field); |
|
181 | 181 | } else { |
182 | - $this->$field = get_option( $field ); |
|
182 | + $this->$field = get_option($field); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | return $this->$field; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @ignore |
228 | 228 | */ |
229 | 229 | public function meta( $field ) { |
230 | - return $this->__get( $field ); |
|
230 | + return $this->__get($field); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,11 +237,11 @@ discard block |
||
237 | 237 | * @param mixed $value |
238 | 238 | */ |
239 | 239 | public function update( $key, $value ) { |
240 | - $value = apply_filters( 'timber_site_set_meta', $value, $key, $this->ID, $this ); |
|
240 | + $value = apply_filters('timber_site_set_meta', $value, $key, $this->ID, $this); |
|
241 | 241 | if ( is_multisite() ) { |
242 | - update_blog_option( $this->ID, $key, $value ); |
|
242 | + update_blog_option($this->ID, $key, $value); |
|
243 | 243 | } else { |
244 | - update_option( $key, $value ); |
|
244 | + update_option($key, $value); |
|
245 | 245 | } |
246 | 246 | $this->$key = $value; |
247 | 247 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * Construct our operation |
18 | 18 | * @param float $factor to multiply original dimensions by |
19 | 19 | */ |
20 | - function __construct($factor) { |
|
20 | + function __construct( $factor ) { |
|
21 | 21 | $this->factor = $factor; |
22 | 22 | } |
23 | 23 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param string $src_extension the extension (ex: .jpg) |
29 | 29 | * @return string the final filename to be used (ex: [email protected]) |
30 | 30 | */ |
31 | - function filename($src_filename, $src_extension) { |
|
31 | + function filename( $src_filename, $src_extension ) { |
|
32 | 32 | $newbase = $src_filename . '@' . $this->factor . 'x'; // add @2x, @3x, @1.5x, etc. |
33 | 33 | $new_name = $newbase . '.' . $src_extension; |
34 | 34 | return $new_name; |
@@ -44,30 +44,30 @@ discard block |
||
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 | } |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | * @param int $h height of new image |
18 | 18 | * @param string $crop cropping method, one of: 'default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center'. |
19 | 19 | */ |
20 | - function __construct($w, $h, $crop) { |
|
20 | + function __construct( $w, $h, $crop ) { |
|
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; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param string $src_extension the extension (ex: .jpg) |
34 | 34 | * @return string the final filename to be used (ex: my-awesome-pic-300x200-c-default.jpg) |
35 | 35 | */ |
36 | - public function filename($src_filename, $src_extension) { |
|
36 | + public function filename( $src_filename, $src_extension ) { |
|
37 | 37 | $w = 0; |
38 | 38 | $h = 0; |
39 | 39 | if ( $this->w ) { |
@@ -42,9 +42,9 @@ 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 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param string $save_filename |
55 | 55 | */ |
56 | 56 | protected function run_animated_gif( $load_filename, $save_filename ) { |
57 | - $image = wp_get_image_editor( $load_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,8 +65,8 @@ discard block |
||
65 | 65 | } |
66 | 66 | $image = new Imagick($load_filename); |
67 | 67 | $image = $image->coalesceImages(); |
68 | - $crop = self::get_target_sizes( $load_filename ); |
|
69 | - foreach ($image as $frame) { |
|
68 | + $crop = self::get_target_sizes($load_filename); |
|
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); |
72 | 72 | $frame->setImagePage($w, $h, 0, 0); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | protected function get_target_sizes( $load_filename ) { |
79 | - $image = wp_get_image_editor( $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 |
||
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 |
||
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 | 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 |
||
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 |
||
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, |
@@ -161,42 +161,42 @@ discard block |
||
161 | 161 | * (ex: /src/var/www/wp-content/uploads/my-pic-300x200-c-default.jpg) |
162 | 162 | * @return bool true if everything went fine, false otherwise |
163 | 163 | */ |
164 | - public function run($load_filename, $save_filename) { |
|
164 | + public function run( $load_filename, $save_filename ) { |
|
165 | 165 | //should be resized by gif resizer |
166 | 166 | if ( TimberImageHelper::is_animated_gif($load_filename) ) { |
167 | 167 | //attempt to resize |
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 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @param int $h height |
18 | 18 | * @param string $color hex string, for color of padding bands |
19 | 19 | */ |
20 | - function __construct($w, $h, $color) { |
|
20 | + function __construct( $w, $h, $color ) { |
|
21 | 21 | $this->w = $w; |
22 | 22 | $this->h = $h; |
23 | 23 | $this->color = $color; |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * @return string the final filename to be used |
30 | 30 | * (ex: my-awesome-pic-lbox-300x200-FF3366.jpg) |
31 | 31 | */ |
32 | - public function filename($src_filename, $src_extension) { |
|
33 | - $color = str_replace( '#', '', $this->color ); |
|
32 | + public function filename( $src_filename, $src_extension ) { |
|
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; |
@@ -46,16 +46,16 @@ discard block |
||
46 | 46 | * (ex: /src/var/www/wp-content/uploads/my-pic-lbox-300x200-FF3366.jpg) |
47 | 47 | * @return bool true if everything went fine, false otherwise |
48 | 48 | */ |
49 | - public function run($load_filename, $save_filename) { |
|
49 | + public function run( $load_filename, $save_filename ) { |
|
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 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * @param string $color hex string of color to use for transparent zones |
14 | 14 | */ |
15 | - function __construct($color) { |
|
15 | + function __construct( $color ) { |
|
16 | 16 | $this->color = $color; |
17 | 17 | } |
18 | 18 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param string $src_extension ignored |
22 | 22 | * @return string the final filename to be used (ex: my-awesome-pic.jpg) |
23 | 23 | */ |
24 | - function filename($src_filename, $src_extension = 'jpg') { |
|
24 | + function filename( $src_filename, $src_extension = 'jpg' ) { |
|
25 | 25 | $new_name = $src_filename . '.jpg'; |
26 | 26 | return $new_name; |
27 | 27 | } |
@@ -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 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 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 | } |