@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | public function __toString() { |
| 11 | 11 | try { |
| 12 | - return (string)$this->call(); |
|
| 12 | + return (string) $this->call(); |
|
| 13 | 13 | } catch (Exception $e) { |
| 14 | 14 | return 'Caught exception: ' . $e->getMessage() . "\n"; |
| 15 | 15 | } |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | * @param array $args |
| 23 | 23 | * @param bool $return_output_buffer |
| 24 | 24 | */ |
| 25 | - public function __construct( $function, $args = array(), $return_output_buffer = false ) { |
|
| 26 | - if( is_array( $function ) ) { |
|
| 27 | - if( (is_string( $function[0] ) && class_exists( $function[0] ) ) || gettype( $function[0] ) === 'object' ) { |
|
| 25 | + public function __construct($function, $args = array(), $return_output_buffer = false) { |
|
| 26 | + if ( is_array($function) ) { |
|
| 27 | + if ( (is_string($function[0]) && class_exists($function[0])) || gettype($function[0]) === 'object' ) { |
|
| 28 | 28 | $this->_class = $function[0]; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
| 31 | + if ( is_string($function[1]) ) $this->_function = $function[1]; |
|
| 32 | 32 | } else { |
| 33 | 33 | $this->_function = $function; |
| 34 | 34 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $this->_args = $args; |
| 37 | 37 | $this->_use_ob = $return_output_buffer; |
| 38 | 38 | |
| 39 | - add_filter( 'get_twig', array( &$this, 'add_to_twig' ) ); |
|
| 39 | + add_filter('get_twig', array(&$this, 'add_to_twig')); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | * @param Twig_Environment $twig |
| 46 | 46 | * @return Twig_Environment |
| 47 | 47 | */ |
| 48 | - public function add_to_twig( $twig ) { |
|
| 48 | + public function add_to_twig($twig) { |
|
| 49 | 49 | $wrapper = $this; |
| 50 | 50 | |
| 51 | - $twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) { |
|
| 52 | - return call_user_func_array( array( $wrapper, 'call' ), func_get_args() ); |
|
| 53 | - } ) ); |
|
| 51 | + $twig->addFunction(new Twig_SimpleFunction($this->_function, function() use ($wrapper) { |
|
| 52 | + return call_user_func_array(array($wrapper, 'call'), func_get_args()); |
|
| 53 | + } )); |
|
| 54 | 54 | |
| 55 | 55 | return $twig; |
| 56 | 56 | } |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | public function call() { |
| 64 | - $args = $this->_parse_args( func_get_args(), $this->_args ); |
|
| 65 | - $callable = ( isset( $this->_class ) ) ? array( $this->_class, $this->_function ) : $this->_function; |
|
| 64 | + $args = $this->_parse_args(func_get_args(), $this->_args); |
|
| 65 | + $callable = (isset($this->_class)) ? array($this->_class, $this->_function) : $this->_function; |
|
| 66 | 66 | |
| 67 | 67 | if ( $this->_use_ob ) { |
| 68 | - return TimberHelper::ob_function( $callable, $args ); |
|
| 68 | + return TimberHelper::ob_function($callable, $args); |
|
| 69 | 69 | } else { |
| 70 | - return call_user_func_array( $callable, $args ); |
|
| 70 | + return call_user_func_array($callable, $args); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | * @param array $defaults |
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | - private function _parse_args( $args, $defaults ) { |
|
| 82 | - $_arg = reset( $defaults ); |
|
| 81 | + private function _parse_args($args, $defaults) { |
|
| 82 | + $_arg = reset($defaults); |
|
| 83 | 83 | |
| 84 | - foreach ( $args as $index => $arg ) { |
|
| 85 | - $defaults[$index] = is_null( $arg ) ? $_arg : $arg; |
|
| 86 | - $_arg = next( $defaults ); |
|
| 84 | + foreach ($args as $index => $arg) { |
|
| 85 | + $defaults[$index] = is_null($arg) ? $_arg : $arg; |
|
| 86 | + $_arg = next($defaults); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | return $defaults; |
@@ -28,7 +28,9 @@ |
||
| 28 | 28 | $this->_class = $function[0]; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
| 31 | + if( is_string( $function[1] ) ) { |
|
| 32 | + $this->_function = $function[1]; |
|
| 33 | + } |
|
| 32 | 34 | } else { |
| 33 | 35 | $this->_function = $function; |
| 34 | 36 | } |
@@ -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', '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; |
@@ -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 | } |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param string $load_filename |
| 54 | 54 | * @param string $save_filename |
| 55 | 55 | */ |
| 56 | - protected function run_animated_gif( $load_filename, $save_filename ) { |
|
| 57 | - $image = wp_get_image_editor( $load_filename ); |
|
| 56 | + protected function run_animated_gif($load_filename, $save_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,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | $image = new Imagick($load_filename); |
| 67 | 67 | $image = $image->coalesceImages(); |
| 68 | - $crop = self::get_target_sizes( $load_filename ); |
|
| 68 | + $crop = self::get_target_sizes($load_filename); |
|
| 69 | 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); |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | return $image->writeImages($save_filename, true); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - protected function get_target_sizes( $load_filename ) { |
|
| 79 | - $image = wp_get_image_editor( $load_filename ); |
|
| 78 | + protected function get_target_sizes($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 | - switch ( $crop ) { |
|
| 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, |
@@ -168,35 +168,35 @@ discard block |
||
| 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 | } |