@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) { |
| 43 | 43 | // Different $expires if user is anonymous or logged in |
| 44 | - if (is_array($expires)) { |
|
| 45 | - if (is_user_logged_in() && isset($expires[1])) { |
|
| 44 | + if ( is_array($expires) ) { |
|
| 45 | + if ( is_user_logged_in() && isset($expires[1]) ) { |
|
| 46 | 46 | $expires = $expires[1]; |
| 47 | 47 | } else { |
| 48 | 48 | $expires = $expires[0]; |
@@ -51,15 +51,15 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | $key = null; |
| 53 | 53 | $output = false; |
| 54 | - if (false !== $expires) { |
|
| 54 | + if ( false !== $expires ) { |
|
| 55 | 55 | ksort($data); |
| 56 | 56 | $key = md5($file . json_encode($data)); |
| 57 | 57 | $output = $this->get_cache($key, self::CACHEGROUP, $cache_mode); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if (false === $output || null === $output) { |
|
| 60 | + if ( false === $output || null === $output ) { |
|
| 61 | 61 | $twig = $this->get_twig(); |
| 62 | - if (strlen($file)) { |
|
| 62 | + if ( strlen($file) ) { |
|
| 63 | 63 | $loader = $this->get_loader(); |
| 64 | 64 | $result = $loader->getCacheKey($file); |
| 65 | 65 | do_action('timber_loader_render_file', $result); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $output = $twig->render($file, $data); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if (false !== $output && false !== $expires && null !== $key) { |
|
| 72 | + if ( false !== $output && false !== $expires && null !== $key ) { |
|
| 73 | 73 | $this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode); |
| 74 | 74 | } |
| 75 | 75 | $output = apply_filters('timber_output', $output); |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | * @return bool |
| 82 | 82 | */ |
| 83 | 83 | public function choose_template($filenames) { |
| 84 | - if (is_array($filenames)) { |
|
| 84 | + if ( is_array($filenames) ) { |
|
| 85 | 85 | /* its an array so we have to figure out which one the dev wants */ |
| 86 | 86 | foreach ($filenames as $filename) { |
| 87 | - if (self::template_exists($filename)) { |
|
| 87 | + if ( self::template_exists($filename) ) { |
|
| 88 | 88 | return $filename; |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | protected function template_exists($file) { |
| 101 | 101 | foreach ($this->locations as $dir) { |
| 102 | 102 | $look_for = trailingslashit($dir) . $file; |
| 103 | - if (file_exists($look_for)) { |
|
| 103 | + if ( file_exists($look_for) ) { |
|
| 104 | 104 | return true; |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $theme_locs = array(); |
| 115 | 115 | $child_loc = get_stylesheet_directory(); |
| 116 | 116 | $parent_loc = get_template_directory(); |
| 117 | - if (DIRECTORY_SEPARATOR == '\\') { |
|
| 117 | + if ( DIRECTORY_SEPARATOR == '\\' ) { |
|
| 118 | 118 | $child_loc = str_replace('/', '\\', $child_loc); |
| 119 | 119 | $parent_loc = str_replace('/', '\\', $parent_loc); |
| 120 | 120 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | foreach ($this->get_locations_theme_dir() as $dirname) { |
| 123 | 123 | $theme_locs[] = trailingslashit($child_loc) . trailingslashit($dirname); |
| 124 | 124 | } |
| 125 | - if ($child_loc != $parent_loc) { |
|
| 125 | + if ( $child_loc != $parent_loc ) { |
|
| 126 | 126 | $theme_locs[] = $parent_loc; |
| 127 | 127 | foreach ($this->get_locations_theme_dir() as $dirname) { |
| 128 | 128 | $theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @return string[] the names of directores, ie: array('templats', 'views'); |
| 139 | 139 | */ |
| 140 | 140 | private function get_locations_theme_dir() { |
| 141 | - if (is_string(Timber::$dirname)) { |
|
| 141 | + if ( is_string(Timber::$dirname) ) { |
|
| 142 | 142 | return array(Timber::$dirname); |
| 143 | 143 | } |
| 144 | 144 | return Timber::$dirname; |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | function get_locations_user() { |
| 151 | 151 | $locs = array(); |
| 152 | - if (isset(Timber::$locations)) { |
|
| 153 | - if (is_string(Timber::$locations)) { |
|
| 152 | + if ( isset(Timber::$locations) ) { |
|
| 153 | + if ( is_string(Timber::$locations) ) { |
|
| 154 | 154 | Timber::$locations = array(Timber::$locations); |
| 155 | 155 | } |
| 156 | 156 | foreach (Timber::$locations as $tloc) { |
| 157 | 157 | $tloc = realpath($tloc); |
| 158 | - if (is_dir($tloc)) { |
|
| 158 | + if ( is_dir($tloc) ) { |
|
| 159 | 159 | $locs[] = $tloc; |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -169,14 +169,14 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function get_locations_caller($caller = false) { |
| 171 | 171 | $locs = array(); |
| 172 | - if ($caller && is_string($caller)) { |
|
| 172 | + if ( $caller && is_string($caller) ) { |
|
| 173 | 173 | $caller = trailingslashit($caller); |
| 174 | - if (is_dir($caller)) { |
|
| 174 | + if ( is_dir($caller) ) { |
|
| 175 | 175 | $locs[] = $caller; |
| 176 | 176 | } |
| 177 | 177 | foreach ($this->get_locations_theme_dir() as $dirname) { |
| 178 | 178 | $caller_sub = $caller . trailingslashit($dirname); |
| 179 | - if (is_dir($caller_sub)) { |
|
| 179 | + if ( is_dir($caller_sub) ) { |
|
| 180 | 180 | $locs[] = $caller_sub; |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -210,14 +210,14 @@ discard block |
||
| 210 | 210 | $paths = array(); |
| 211 | 211 | foreach ($this->locations as $loc) { |
| 212 | 212 | $loc = realpath($loc); |
| 213 | - if (is_dir($loc)) { |
|
| 213 | + if ( is_dir($loc) ) { |
|
| 214 | 214 | $loc = realpath($loc); |
| 215 | 215 | $paths[] = $loc; |
| 216 | 216 | } else { |
| 217 | 217 | //error_log($loc.' is not a directory'); |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | - if (!ini_get('open_basedir')) { |
|
| 220 | + if ( !ini_get('open_basedir') ) { |
|
| 221 | 221 | $paths[] = '/'; |
| 222 | 222 | } else { |
| 223 | 223 | $paths[] = ABSPATH; |
@@ -233,15 +233,15 @@ discard block |
||
| 233 | 233 | function get_twig() { |
| 234 | 234 | $loader = $this->get_loader(); |
| 235 | 235 | $params = array('debug' => WP_DEBUG, 'autoescape' => false); |
| 236 | - if (isset(Timber::$autoescape)) { |
|
| 236 | + if ( isset(Timber::$autoescape) ) { |
|
| 237 | 237 | $params['autoescape'] = Timber::$autoescape; |
| 238 | 238 | } |
| 239 | - if (Timber::$cache === true) { |
|
| 239 | + if ( Timber::$cache === true ) { |
|
| 240 | 240 | Timber::$twig_cache = true; |
| 241 | 241 | } |
| 242 | - if (Timber::$twig_cache) { |
|
| 243 | - $twig_cache_loc = apply_filters( 'timber/cache/location', TIMBER_LOC . '/cache/twig' ); |
|
| 244 | - if (!file_exists($twig_cache_loc)) { |
|
| 242 | + if ( Timber::$twig_cache ) { |
|
| 243 | + $twig_cache_loc = apply_filters('timber/cache/location', TIMBER_LOC . '/cache/twig'); |
|
| 244 | + if ( !file_exists($twig_cache_loc) ) { |
|
| 245 | 245 | mkdir($twig_cache_loc, 0777, true); |
| 246 | 246 | } |
| 247 | 247 | $params['cache'] = $twig_cache_loc; |
@@ -258,26 +258,26 @@ discard block |
||
| 258 | 258 | return $twig; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT){ |
|
| 261 | + public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT) { |
|
| 262 | 262 | //_transient_timberloader |
| 263 | 263 | $object_cache = false; |
| 264 | - if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) { |
|
| 264 | + if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) { |
|
| 265 | 265 | $object_cache = true; |
| 266 | 266 | } |
| 267 | 267 | $cache_mode = $this->_get_cache_mode($cache_mode); |
| 268 | - if (self::CACHE_TRANSIENT === $cache_mode) { |
|
| 268 | + if ( self::CACHE_TRANSIENT === $cache_mode ) { |
|
| 269 | 269 | global $wpdb; |
| 270 | 270 | $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%'); |
| 271 | - $wpdb->query( $query ); |
|
| 271 | + $wpdb->query($query); |
|
| 272 | 272 | return true; |
| 273 | - } else if (self::CACHE_SITE_TRANSIENT === $cache_mode) { |
|
| 273 | + } else if ( self::CACHE_SITE_TRANSIENT === $cache_mode ) { |
|
| 274 | 274 | global $wpdb; |
| 275 | 275 | $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%'); |
| 276 | - $wpdb->query( $query ); |
|
| 276 | + $wpdb->query($query); |
|
| 277 | 277 | return true; |
| 278 | - } else if (self::CACHE_OBJECT === $cache_mode && $object_cache) { |
|
| 278 | + } else if ( self::CACHE_OBJECT === $cache_mode && $object_cache ) { |
|
| 279 | 279 | global $wp_object_cache; |
| 280 | - if (isset($wp_object_cache->cache[self::CACHEGROUP])){ |
|
| 280 | + if ( isset($wp_object_cache->cache[self::CACHEGROUP]) ) { |
|
| 281 | 281 | unset($wp_object_cache->cache[self::CACHEGROUP]); |
| 282 | 282 | return true; |
| 283 | 283 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $twig = $this->get_twig(); |
| 290 | 290 | $twig->clearCacheFiles(); |
| 291 | 291 | $cache = $twig->getCache(); |
| 292 | - if ($cache){ |
|
| 292 | + if ( $cache ) { |
|
| 293 | 293 | self::rrmdir($twig->getCache()); |
| 294 | 294 | return true; |
| 295 | 295 | } |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | * @param string|false $dirPath |
| 301 | 301 | */ |
| 302 | 302 | public static function rrmdir($dirPath) { |
| 303 | - if (! is_dir($dirPath)) { |
|
| 303 | + if ( !is_dir($dirPath) ) { |
|
| 304 | 304 | throw new InvalidArgumentException("$dirPath must be a directory"); |
| 305 | 305 | } |
| 306 | - if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { |
|
| 306 | + if ( substr($dirPath, strlen($dirPath) - 1, 1) != '/' ) { |
|
| 307 | 307 | $dirPath .= '/'; |
| 308 | 308 | } |
| 309 | 309 | $files = glob($dirPath . '*', GLOB_MARK); |
| 310 | 310 | foreach ($files as $file) { |
| 311 | - if (is_dir($file)) { |
|
| 311 | + if ( is_dir($file) ) { |
|
| 312 | 312 | self::rrmdir($file); |
| 313 | 313 | } else { |
| 314 | 314 | unlink($file); |
@@ -323,9 +323,9 @@ discard block |
||
| 323 | 323 | private function _get_cache_extension() { |
| 324 | 324 | |
| 325 | 325 | $key_generator = new \Timber\Cache\KeyGenerator(); |
| 326 | - $cache_provider = new \Timber\Cache\WPObjectCacheAdapter( $this ); |
|
| 327 | - $cache_strategy = new \Asm89\Twig\CacheExtension\CacheStrategy\GenerationalCacheStrategy( $cache_provider, $key_generator ); |
|
| 328 | - $cache_extension = new \Asm89\Twig\CacheExtension\Extension( $cache_strategy ); |
|
| 326 | + $cache_provider = new \Timber\Cache\WPObjectCacheAdapter($this); |
|
| 327 | + $cache_strategy = new \Asm89\Twig\CacheExtension\CacheStrategy\GenerationalCacheStrategy($cache_provider, $key_generator); |
|
| 328 | + $cache_extension = new \Asm89\Twig\CacheExtension\Extension($cache_strategy); |
|
| 329 | 329 | |
| 330 | 330 | return $cache_extension; |
| 331 | 331 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) { |
| 340 | 340 | $object_cache = false; |
| 341 | 341 | |
| 342 | - if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) { |
|
| 342 | + if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) { |
|
| 343 | 343 | $object_cache = true; |
| 344 | 344 | } |
| 345 | 345 | |
@@ -348,13 +348,13 @@ discard block |
||
| 348 | 348 | $value = false; |
| 349 | 349 | |
| 350 | 350 | $trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN); |
| 351 | - if (self::CACHE_TRANSIENT === $cache_mode) |
|
| 351 | + if ( self::CACHE_TRANSIENT === $cache_mode ) |
|
| 352 | 352 | $value = get_transient($trans_key); |
| 353 | 353 | |
| 354 | - elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) |
|
| 354 | + elseif ( self::CACHE_SITE_TRANSIENT === $cache_mode ) |
|
| 355 | 355 | $value = get_site_transient($trans_key); |
| 356 | 356 | |
| 357 | - elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) |
|
| 357 | + elseif ( self::CACHE_OBJECT === $cache_mode && $object_cache ) |
|
| 358 | 358 | $value = wp_cache_get($key, $group); |
| 359 | 359 | |
| 360 | 360 | return $value; |
@@ -371,23 +371,23 @@ discard block |
||
| 371 | 371 | public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) { |
| 372 | 372 | $object_cache = false; |
| 373 | 373 | |
| 374 | - if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) { |
|
| 374 | + if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) { |
|
| 375 | 375 | $object_cache = true; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if ((int)$expires < 1) |
|
| 378 | + if ( (int) $expires < 1 ) |
|
| 379 | 379 | $expires = 0; |
| 380 | 380 | |
| 381 | 381 | $cache_mode = self::_get_cache_mode($cache_mode); |
| 382 | 382 | $trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN); |
| 383 | 383 | |
| 384 | - if (self::CACHE_TRANSIENT === $cache_mode) |
|
| 384 | + if ( self::CACHE_TRANSIENT === $cache_mode ) |
|
| 385 | 385 | set_transient($trans_key, $value, $expires); |
| 386 | 386 | |
| 387 | - elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) |
|
| 387 | + elseif ( self::CACHE_SITE_TRANSIENT === $cache_mode ) |
|
| 388 | 388 | set_site_transient($trans_key, $value, $expires); |
| 389 | 389 | |
| 390 | - elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) |
|
| 390 | + elseif ( self::CACHE_OBJECT === $cache_mode && $object_cache ) |
|
| 391 | 391 | wp_cache_set($key, $value, $group, $expires); |
| 392 | 392 | |
| 393 | 393 | return $value; |
@@ -398,12 +398,12 @@ discard block |
||
| 398 | 398 | * @return string |
| 399 | 399 | */ |
| 400 | 400 | private function _get_cache_mode($cache_mode) { |
| 401 | - if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) { |
|
| 401 | + if ( empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode ) { |
|
| 402 | 402 | $cache_mode = $this->cache_mode; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // Fallback if self::$cache_mode did not get a valid value |
| 406 | - if (!in_array($cache_mode, self::$cache_modes)) { |
|
| 406 | + if ( !in_array($cache_mode, self::$cache_modes) ) { |
|
| 407 | 407 | $cache_mode = self::CACHE_OBJECT; |
| 408 | 408 | } |
| 409 | 409 | |
@@ -43,9 +43,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,13 +426,13 @@ discard block |
||
| 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 | // if external image, load it first |
| 434 | - if ( TimberURLHelper::is_external_content( $src ) ) { |
|
| 435 | - $src = self::sideload_image( $src ); |
|
| 434 | + if ( TimberURLHelper::is_external_content($src) ) { |
|
| 435 | + $src = self::sideload_image($src); |
|
| 436 | 436 | } |
| 437 | 437 | // break down URL into components |
| 438 | 438 | $au = self::analyze_url($src); |
@@ -454,17 +454,17 @@ discard block |
||
| 454 | 454 | $au['basename'] |
| 455 | 455 | ); |
| 456 | 456 | // if already exists... |
| 457 | - if ( file_exists( $new_server_path ) ) { |
|
| 457 | + if ( file_exists($new_server_path) ) { |
|
| 458 | 458 | if ( $force ) { |
| 459 | 459 | // Force operation - warning: will regenerate the image on every pageload, use for testing purposes only! |
| 460 | - unlink( $new_server_path ); |
|
| 460 | + unlink($new_server_path); |
|
| 461 | 461 | } else { |
| 462 | 462 | // return existing file (caching) |
| 463 | 463 | return $new_url; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | // otherwise generate result file |
| 467 | - if($op->run($old_server_path, $new_server_path)) { |
|
| 467 | + if ( $op->run($old_server_path, $new_server_path) ) { |
|
| 468 | 468 | return $new_url; |
| 469 | 469 | } else { |
| 470 | 470 | // in case of error, we return source file itself |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | ); |
| 487 | 487 | return $new_url; |
| 488 | 488 | } |
| 489 | - public static function get_letterbox_file_path($url, $w, $h, $color ) { |
|
| 489 | + public static function get_letterbox_file_path($url, $w, $h, $color) { |
|
| 490 | 490 | $au = self::analyze_url($url); |
| 491 | 491 | $op = new TimberImageOperationLetterbox($w, $h, $color); |
| 492 | 492 | $new_path = self::_get_file_path( |
@@ -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; |
@@ -34,15 +34,15 @@ discard block |
||
| 34 | 34 | * @return string the final filename to be used (ex: my-awesome-pic-300x200-c-default.jpg) |
| 35 | 35 | */ |
| 36 | 36 | public function filename($src_filename, $src_extension) { |
| 37 | - $result = $src_filename . '-' . $this->w . 'x' . $this->h . '-c-' . ( $this->crop ? $this->crop : 'f' ); // Crop will be either user named or f (false) |
|
| 38 | - if($src_extension) { |
|
| 39 | - $result .= '.'.$src_extension; |
|
| 37 | + $result = $src_filename . '-' . $this->w . 'x' . $this->h . '-c-' . ($this->crop ? $this->crop : 'f'); // Crop will be either user named or f (false) |
|
| 38 | + if ( $src_extension ) { |
|
| 39 | + $result .= '.' . $src_extension; |
|
| 40 | 40 | } |
| 41 | 41 | return $result; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - protected function run_animated_gif( $load_filename, $save_filename ) { |
|
| 45 | - $image = wp_get_image_editor( $load_filename ); |
|
| 44 | + protected function run_animated_gif($load_filename, $save_filename) { |
|
| 45 | + $image = wp_get_image_editor($load_filename); |
|
| 46 | 46 | $current_size = $image->get_size(); |
| 47 | 47 | $src_w = $current_size['width']; |
| 48 | 48 | $src_h = $current_size['height']; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | $image = new Imagick($load_filename); |
| 55 | 55 | $image = $image->coalesceImages(); |
| 56 | - $crop = self::get_target_sizes( $load_filename ); |
|
| 56 | + $crop = self::get_target_sizes($load_filename); |
|
| 57 | 57 | foreach ($image as $frame) { |
| 58 | 58 | $frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']); |
| 59 | 59 | $frame->thumbnailImage($w, $h); |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | return $image->writeImages($save_filename, true); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - protected function get_target_sizes( $load_filename ) { |
|
| 67 | - $image = wp_get_image_editor( $load_filename ); |
|
| 66 | + protected function get_target_sizes($load_filename) { |
|
| 67 | + $image = wp_get_image_editor($load_filename); |
|
| 68 | 68 | $w = $this->w; |
| 69 | 69 | $h = $this->h; |
| 70 | 70 | $crop = $this->crop; |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | $src_h = $current_size['height']; |
| 75 | 75 | $src_ratio = $src_w / $src_h; |
| 76 | 76 | if ( !$h ) { |
| 77 | - $h = round( $w / $src_ratio ); |
|
| 77 | + $h = round($w / $src_ratio); |
|
| 78 | 78 | } |
| 79 | 79 | if ( !$w ) { |
| 80 | 80 | //the user wants to resize based on constant height |
| 81 | - $w = round( $h * $src_ratio ); |
|
| 81 | + $w = round($h * $src_ratio); |
|
| 82 | 82 | } |
| 83 | 83 | if ( !$crop ) { |
| 84 | 84 | return array( |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | $src_wt = $src_h * $dest_ratio; |
| 93 | 93 | $src_ht = $src_w / $dest_ratio; |
| 94 | 94 | $src_x = $src_w / 2 - $src_wt / 2; |
| 95 | - $src_y = ( $src_h - $src_ht ) / 6; |
|
| 95 | + $src_y = ($src_h - $src_ht) / 6; |
|
| 96 | 96 | //now specific overrides based on options: |
| 97 | 97 | if ( $crop == 'center' ) { |
| 98 | 98 | // Get source x and y |
| 99 | - $src_x = round( ( $src_w - $src_wt ) / 2 ); |
|
| 100 | - $src_y = round( ( $src_h - $src_ht ) / 2 ); |
|
| 99 | + $src_x = round(($src_w - $src_wt) / 2); |
|
| 100 | + $src_y = round(($src_h - $src_ht) / 2); |
|
| 101 | 101 | } else if ( $crop == 'top' ) { |
| 102 | 102 | $src_y = 0; |
| 103 | 103 | } else if ( $crop == 'bottom' ) { |
@@ -139,35 +139,35 @@ discard block |
||
| 139 | 139 | //return if successful |
| 140 | 140 | //proceed if not |
| 141 | 141 | $gif = self::run_animated_gif($load_filename, $save_filename); |
| 142 | - if ($gif) { |
|
| 142 | + if ( $gif ) { |
|
| 143 | 143 | return true; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | - $image = wp_get_image_editor( $load_filename ); |
|
| 147 | - if ( !is_wp_error( $image ) ) { |
|
| 148 | - $crop = self::get_target_sizes( $load_filename ); |
|
| 149 | - $image->crop( $crop['x'], |
|
| 146 | + $image = wp_get_image_editor($load_filename); |
|
| 147 | + if ( !is_wp_error($image) ) { |
|
| 148 | + $crop = self::get_target_sizes($load_filename); |
|
| 149 | + $image->crop($crop['x'], |
|
| 150 | 150 | $crop['y'], |
| 151 | 151 | $crop['src_w'], |
| 152 | 152 | $crop['src_h'], |
| 153 | 153 | $crop['target_w'], |
| 154 | 154 | $crop['target_h'] |
| 155 | 155 | ); |
| 156 | - $result = $image->save( $save_filename ); |
|
| 157 | - if ( is_wp_error( $result ) ) { |
|
| 156 | + $result = $image->save($save_filename); |
|
| 157 | + if ( is_wp_error($result) ) { |
|
| 158 | 158 | // @codeCoverageIgnoreStart |
| 159 | - TimberHelper::error_log( 'Error resizing image' ); |
|
| 160 | - TimberHelper::error_log( $result ); |
|
| 159 | + TimberHelper::error_log('Error resizing image'); |
|
| 160 | + TimberHelper::error_log($result); |
|
| 161 | 161 | return false; |
| 162 | 162 | // @codeCoverageIgnoreEnd |
| 163 | 163 | } else { |
| 164 | 164 | return true; |
| 165 | 165 | } |
| 166 | - } else if ( isset( $image->error_data['error_loading_image'] ) ) { |
|
| 166 | + } else if ( isset($image->error_data['error_loading_image']) ) { |
|
| 167 | 167 | // @codeCoverageIgnoreStart |
| 168 | - TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] ); |
|
| 168 | + TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']); |
|
| 169 | 169 | } else { |
| 170 | - TimberHelper::error_log( $image ); |
|
| 170 | + TimberHelper::error_log($image); |
|
| 171 | 171 | // @codeCoverageIgnoreEnd |
| 172 | 172 | } |
| 173 | 173 | } |