Completed
Push — master ( 1fa612...adffc5 )
by Jared
02:46
created
lib/image/timber-image-operation-retina.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
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){
47
+    function run($load_filename, $save_filename) {
48 48
         $image = wp_get_image_editor( $load_filename );
49 49
         if ( !is_wp_error( $image ) ) {
50 50
             $current_size = $image->get_size();
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
lib/integrations/timber-command.php 2 patches
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class TimberCommand {
8 8
 
9
-    public static function clear_cache($mode = 'all'){
10
-        if (is_array($mode)){
9
+    public static function clear_cache($mode = 'all') {
10
+        if (is_array($mode)) {
11 11
             $mode = reset($mode);
12 12
         }
13 13
         if ($mode == 'all') {
14 14
             $twig_cache = self::clear_cache_twig();
15 15
             $timber_cache = self::clear_cache_timber();
16
-            if ($twig_cache && $timber_cache){
16
+            if ($twig_cache && $timber_cache) {
17 17
                 return true;
18 18
             }
19 19
         } else if ($mode == 'twig') {
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
         }
24 24
     }
25 25
 
26
-    static function clear_cache_timber(){
26
+    static function clear_cache_timber() {
27 27
         $loader = new TimberLoader();
28 28
         return $loader->clear_cache_timber();
29 29
     }
30 30
 
31
-    static function clear_cache_twig(){
31
+    static function clear_cache_twig() {
32 32
         $loader = new TimberLoader();
33 33
         return $loader->clear_cache_twig();
34 34
     }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
  */
7 7
 class TimberCommand {
8 8
 
9
-    public static function clear_cache($mode = 'all'){
10
-        if (is_array($mode)){
9
+    public static function clear_cache( $mode = 'all' ) {
10
+        if ( is_array($mode) ) {
11 11
             $mode = reset($mode);
12 12
         }
13
-        if ($mode == 'all') {
13
+        if ( $mode == 'all' ) {
14 14
             $twig_cache = self::clear_cache_twig();
15 15
             $timber_cache = self::clear_cache_timber();
16
-            if ($twig_cache && $timber_cache){
16
+            if ( $twig_cache && $timber_cache ) {
17 17
                 return true;
18 18
             }
19
-        } else if ($mode == 'twig') {
19
+        } else if ( $mode == 'twig' ) {
20 20
             return self::clear_cache_twig();
21
-        } else if ($mode == 'timber') {
21
+        } else if ( $mode == 'timber' ) {
22 22
             return self::clear_cache_timber();
23 23
         }
24 24
     }
25 25
 
26
-    static function clear_cache_timber(){
26
+    static function clear_cache_timber() {
27 27
         $loader = new TimberLoader();
28 28
         return $loader->clear_cache_timber();
29 29
     }
30 30
 
31
-    static function clear_cache_twig(){
31
+    static function clear_cache_twig() {
32 32
         $loader = new TimberLoader();
33 33
         return $loader->clear_cache_twig();
34 34
     }
Please login to merge, or discard this patch.
lib/integrations/wpcli-timber.php 2 patches
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
      *    wp timber clear_cache_twig
26 26
      *
27 27
      */
28
-    function clear_cache_twig(){
28
+    function clear_cache_twig() {
29 29
         $clear = TimberCommand::clear_cache_twig();
30
-        if ($clear){
30
+        if ($clear) {
31 31
             WP_CLI::success('Cleared contents of twig cache');
32 32
         } else {
33 33
             WP_CLI::warning('Failed to clear twig cache');
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     function clear_cache_timber() {
46 46
         $clear = TimberCommand::clear_cache_timber();
47 47
         $message = 'Failed to clear timber cache';
48
-        if ($clear){
48
+        if ($clear) {
49 49
             $message = "Cleared contents of Timber's Cache";
50 50
             WP_CLI::success($message);
51 51
         } else {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!class_exists('WP_CLI_Command')) {
2
+if ( !class_exists('WP_CLI_Command') ) {
3 3
 	return;
4 4
 }
5 5
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      *    wp timber clear_cache
14 14
      *
15 15
      */
16
-    public function clear_cache($mode = 'all') {
16
+    public function clear_cache( $mode = 'all' ) {
17 17
         TimberCommand::clear_cache($mode);
18 18
     }
19 19
 
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
      *    wp timber clear_cache_twig
26 26
      *
27 27
      */
28
-    function clear_cache_twig(){
28
+    function clear_cache_twig() {
29 29
         $clear = TimberCommand::clear_cache_twig();
30
-        if ($clear){
30
+        if ( $clear ) {
31 31
             WP_CLI::success('Cleared contents of twig cache');
32 32
         } else {
33 33
             WP_CLI::warning('Failed to clear twig cache');
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     function clear_cache_timber() {
46 46
         $clear = TimberCommand::clear_cache_timber();
47 47
         $message = 'Failed to clear timber cache';
48
-        if ($clear){
48
+        if ( $clear ) {
49 49
             $message = "Cleared contents of Timber's Cache";
50 50
             WP_CLI::success($message);
51 51
         } else {
Please login to merge, or discard this patch.
lib/timber-core.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
             foreach ( $info as $key => $value ) {
64 64
                 if ( !empty( $key ) && $force ) {
65 65
                     $this->$key = $value;
66
-                } else if ( !empty( $key ) && !method_exists($this, $key) ){
66
+                } else if ( !empty( $key ) && !method_exists($this, $key) ) {
67 67
                     $this->$key = $value;
68 68
                 }
69 69
             }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * @return boolean
13 13
      */
14 14
     function __isset( $field ) {
15
-        if ( isset( $this->$field ) ) {
15
+        if ( isset($this->$field) ) {
16 16
             return $this->$field;
17 17
         }
18 18
         return false;
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * @return mixed
24 24
      */
25 25
     function __call( $field, $args ) {
26
-        return $this->__get( $field );
26
+        return $this->__get($field);
27 27
     }
28 28
 
29 29
     /**
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     	if ( property_exists($this, $field) ) {
36 36
     		return $this->$field;
37 37
     	}
38
-        if ( method_exists($this, 'meta') && $meta_value = $this->meta( $field ) ) {
38
+        if ( method_exists($this, 'meta') && $meta_value = $this->meta($field) ) {
39 39
             return $this->$field = $meta_value;
40 40
         }
41 41
         if ( method_exists($this, $field) ) {
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
      * @param array|object $info an object or array you want to grab data from to attach to the Timber object
57 57
      */
58 58
     function import( $info, $force = false ) {
59
-        if ( is_object( $info ) ) {
60
-            $info = get_object_vars( $info );
59
+        if ( is_object($info) ) {
60
+            $info = get_object_vars($info);
61 61
         }
62
-        if ( is_array( $info ) ) {
62
+        if ( is_array($info) ) {
63 63
             foreach ( $info as $key => $value ) {
64
-                if ( !empty( $key ) && $force ) {
64
+                if ( !empty($key) && $force ) {
65 65
                     $this->$key = $value;
66
-                } else if ( !empty( $key ) && !method_exists($this, $key) ){
66
+                } else if ( !empty($key) && !method_exists($this, $key) ) {
67 67
                     $this->$key = $value;
68 68
                 }
69 69
             }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param mixed   $value
78 78
      */
79 79
     function update( $key, $value ) {
80
-        update_metadata( $this->object_type, $this->ID, $key, $value );
80
+        update_metadata($this->object_type, $this->ID, $key, $value);
81 81
     }
82 82
 
83 83
     /**
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
      * @return bool
95 95
      */
96 96
     function can_edit() {
97
-        if ( !function_exists( 'current_user_can' ) ) {
97
+        if ( !function_exists('current_user_can') ) {
98 98
             return false;
99 99
         }
100
-        if ( current_user_can( 'edit_post', $this->ID ) ) {
100
+        if ( current_user_can('edit_post', $this->ID) ) {
101 101
             return true;
102 102
         }
103 103
         return false;
Please login to merge, or discard this patch.
lib/timber-helper.php 2 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,8 +48,9 @@
 block discarded – undo
48 48
 
49 49
 			// lock timeout shouldn't be higher than 5 seconds, unless
50 50
 			// remote calls with high timeouts are made here
51
-			if ( $enable_transients )
52
-				self::_lock_transient( $slug, $lock_timeout );
51
+			if ( $enable_transients ) {
52
+							self::_lock_transient( $slug, $lock_timeout );
53
+			}
53 54
 
54 55
 			$data = $callback();
55 56
 
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -26,17 +26,17 @@  discard block
 block discarded – undo
26 26
 	 * @return mixed
27 27
 	 */
28 28
 	public static function transient( $slug, $callback, $transient_time = 0, $lock_timeout = 5, $force = false ) {
29
-		$slug = apply_filters( 'timber/transient/slug', $slug );
29
+		$slug = apply_filters('timber/transient/slug', $slug);
30 30
 
31
-		$enable_transients = ( $transient_time === false || ( defined( 'WP_DISABLE_TRANSIENTS' ) && WP_DISABLE_TRANSIENTS ) ) ? false : true;
32
-		$data = $enable_transients ? get_transient( $slug ) : false;
31
+		$enable_transients = ($transient_time === false || (defined('WP_DISABLE_TRANSIENTS') && WP_DISABLE_TRANSIENTS)) ? false : true;
32
+		$data = $enable_transients ? get_transient($slug) : false;
33 33
 
34 34
 		if ( false === $data ) {
35 35
 
36
-			if ( $enable_transients && self::_is_transient_locked( $slug ) ) {
36
+			if ( $enable_transients && self::_is_transient_locked($slug) ) {
37 37
 
38
-				$force = apply_filters( 'timber_force_transients', $force );
39
-				$force = apply_filters( 'timber_force_transient_' . $slug, $force );
38
+				$force = apply_filters('timber_force_transients', $force);
39
+				$force = apply_filters('timber_force_transient_' . $slug, $force);
40 40
 
41 41
 				if ( !$force ) {
42 42
 					//the server is currently executing the process.
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
 			// lock timeout shouldn't be higher than 5 seconds, unless
51 51
 			// remote calls with high timeouts are made here
52 52
 			if ( $enable_transients )
53
-				self::_lock_transient( $slug, $lock_timeout );
53
+				self::_lock_transient($slug, $lock_timeout);
54 54
 
55 55
 			$data = $callback();
56 56
 
57 57
 			if ( $enable_transients ) {
58
-				set_transient( $slug, $data, $transient_time );
59
-				self::_unlock_transient( $slug );
58
+				set_transient($slug, $data, $transient_time);
59
+				self::_unlock_transient($slug);
60 60
 			}
61 61
 
62 62
 		}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 * @param integer $lock_timeout
72 72
 	 */
73 73
 	static function _lock_transient( $slug, $lock_timeout ) {
74
-		set_transient( $slug . '_lock', true, $lock_timeout );
74
+		set_transient($slug . '_lock', true, $lock_timeout);
75 75
 	}
76 76
 
77 77
 	/**
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @param string $slug
80 80
 	 */
81 81
 	static function _unlock_transient( $slug ) {
82
-		delete_transient( $slug . '_lock', true );
82
+		delete_transient($slug . '_lock', true);
83 83
 	}
84 84
 
85 85
 	/**
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @param string $slug
88 88
 	 */
89 89
 	static function _is_transient_locked( $slug ) {
90
-		return (bool)get_transient( $slug . '_lock' );
90
+		return (bool) get_transient($slug . '_lock');
91 91
 	}
92 92
 
93 93
 	/* These are for measuring page render time */
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public static function start_timer() {
101 101
 		$time = microtime();
102
-		$time = explode( ' ', $time );
102
+		$time = explode(' ', $time);
103 103
 		$time = $time[1] + $time[0];
104 104
 		return $time;
105 105
 	}
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public static function stop_timer( $start ) {
119 119
 		$time = microtime();
120
-		$time = explode( ' ', $time );
120
+		$time = explode(' ', $time);
121 121
 		$time = $time[1] + $time[0];
122 122
 		$finish = $time;
123
-		$total_time = round( ( $finish - $start ), 4 );
123
+		$total_time = round(($finish - $start), 4);
124 124
 		return $total_time . ' seconds.';
125 125
 	}
126 126
 
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
 	 * @param array   $args
154 154
 	 * @return string
155 155
 	 */
156
-	public static function ob_function( $function, $args = array( null ) ) {
156
+	public static function ob_function( $function, $args = array(null) ) {
157 157
 		ob_start();
158
-		call_user_func_array( $function, $args );
158
+		call_user_func_array($function, $args);
159 159
 		$data = ob_get_contents();
160 160
 		ob_end_clean();
161 161
 		return $data;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @return TimberFunctionWrapper
171 171
 	 */
172 172
 	public static function function_wrapper( $function_name, $defaults = array(), $return_output_buffer = false ) {
173
-		return new TimberFunctionWrapper( $function_name, $defaults, $return_output_buffer );
173
+		return new TimberFunctionWrapper($function_name, $defaults, $return_output_buffer);
174 174
 	}
175 175
 
176 176
 	/**
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
 		if ( !WP_DEBUG ) {
184 184
 			return;
185 185
 		}
186
-		if ( is_object( $arg ) || is_array( $arg ) ) {
187
-			$arg = print_r( $arg, true );
186
+		if ( is_object($arg) || is_array($arg) ) {
187
+			$arg = print_r($arg, true);
188 188
 		}
189
-		return error_log( $arg );
189
+		return error_log($arg);
190 190
 	}
191 191
 
192 192
 	/**
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 	 * @return string
198 198
 	 */
199 199
 	public static function get_wp_title( $separator = ' ', $seplocation = 'left' ) {
200
-		$separator = apply_filters( 'timber_wp_title_seperator', $separator );
201
-		return trim( wp_title( $separator, false, $seplocation ) );
200
+		$separator = apply_filters('timber_wp_title_seperator', $separator);
201
+		return trim(wp_title($separator, false, $seplocation));
202 202
 	}
203 203
 
204 204
 	/* Text Utilities
@@ -215,33 +215,33 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	public static function trim_words( $text, $num_words = 55, $more = null, $allowed_tags = 'p a span b i br blockquote' ) {
217 217
 		if ( null === $more ) {
218
-			$more = __( '&hellip;' );
218
+			$more = __('&hellip;');
219 219
 		}
220 220
 		$original_text = $text;
221 221
 		$allowed_tag_string = '';
222
-		foreach ( explode( ' ', apply_filters( 'timber/trim_words/allowed_tags', $allowed_tags ) ) as $tag ) {
222
+		foreach ( explode(' ', apply_filters('timber/trim_words/allowed_tags', $allowed_tags)) as $tag ) {
223 223
 			$allowed_tag_string .= '<' . $tag . '>';
224 224
 		}
225
-		$text = strip_tags( $text, $allowed_tag_string );
225
+		$text = strip_tags($text, $allowed_tag_string);
226 226
 		/* translators: If your word count is based on single characters (East Asian characters), enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
227
-		if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
228
-			$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
229
-			preg_match_all( '/./u', $text, $words_array );
230
-			$words_array = array_slice( $words_array[0], 0, $num_words + 1 );
227
+		if ( 'characters' == _x('words', 'word count: words or characters?') && preg_match('/^utf\-?8$/i', get_option('blog_charset')) ) {
228
+			$text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' ');
229
+			preg_match_all('/./u', $text, $words_array);
230
+			$words_array = array_slice($words_array[0], 0, $num_words + 1);
231 231
 			$sep = '';
232 232
 		} else {
233
-			$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
233
+			$words_array = preg_split("/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY);
234 234
 			$sep = ' ';
235 235
 		}
236
-		if ( count( $words_array ) > $num_words ) {
237
-			array_pop( $words_array );
238
-			$text = implode( $sep, $words_array );
236
+		if ( count($words_array) > $num_words ) {
237
+			array_pop($words_array);
238
+			$text = implode($sep, $words_array);
239 239
 			$text = $text . $more;
240 240
 		} else {
241
-			$text = implode( $sep, $words_array );
241
+			$text = implode($sep, $words_array);
242 242
 		}
243
-		$text = self::close_tags( $text );
244
-		return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
243
+		$text = self::close_tags($text);
244
+		return apply_filters('wp_trim_words', $text, $num_words, $more, $original_text);
245 245
 	}
246 246
 
247 247
 	/**
@@ -252,27 +252,27 @@  discard block
 block discarded – undo
252 252
 	 */
253 253
 	public static function close_tags( $html ) {
254 254
 		//put all opened tags into an array
255
-		preg_match_all( '#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result );
255
+		preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
256 256
 		$openedtags = $result[1];
257 257
 		//put all closed tags into an array
258
-		preg_match_all( '#</([a-z]+)>#iU', $html, $result );
258
+		preg_match_all('#</([a-z]+)>#iU', $html, $result);
259 259
 		$closedtags = $result[1];
260
-		$len_opened = count( $openedtags );
260
+		$len_opened = count($openedtags);
261 261
 		// all tags are closed
262
-		if ( count( $closedtags ) == $len_opened ) {
262
+		if ( count($closedtags) == $len_opened ) {
263 263
 			return $html;
264 264
 		}
265
-		$openedtags = array_reverse( $openedtags );
265
+		$openedtags = array_reverse($openedtags);
266 266
 		// close tags
267 267
 		for ( $i = 0; $i < $len_opened; $i++ ) {
268
-			if ( !in_array( $openedtags[$i], $closedtags ) ) {
268
+			if ( !in_array($openedtags[$i], $closedtags) ) {
269 269
 				$html .= '</' . $openedtags[$i] . '>';
270 270
 			} else {
271
-				unset( $closedtags[array_search( $openedtags[$i], $closedtags )] );
271
+				unset($closedtags[array_search($openedtags[$i], $closedtags)]);
272 272
 			}
273 273
 		}
274
-		$html = str_replace(array('</br>','</hr>','</wbr>'), '', $html);
275
-		$html = str_replace(array('<br>','<hr>','<wbr>'), array('<br />','<hr />','<wbr />'), $html);
274
+		$html = str_replace(array('</br>', '</hr>', '</wbr>'), '', $html);
275
+		$html = str_replace(array('<br>', '<hr>', '<wbr>'), array('<br />', '<hr />', '<wbr />'), $html);
276 276
 		return $html;
277 277
 	}
278 278
 
@@ -287,15 +287,15 @@  discard block
 block discarded – undo
287 287
 	 */
288 288
 	public static function get_posts_by_meta( $key, $value ) {
289 289
 		global $wpdb;
290
-		$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value );
291
-		$results = $wpdb->get_col( $query );
290
+		$query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value);
291
+		$results = $wpdb->get_col($query);
292 292
 		$pids = array();
293 293
 		foreach ( $results as $result ) {
294
-			if ( get_post( $result ) ) {
294
+			if ( get_post($result) ) {
295 295
 				$pids[] = $result;
296 296
 			}
297 297
 		}
298
-		if ( count( $pids ) ) {
298
+		if ( count($pids) ) {
299 299
 			return $pids;
300 300
 		}
301 301
 		return 0;
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
 	 */
312 312
 	public static function get_post_by_meta( $key, $value ) {
313 313
 		global $wpdb;
314
-		$query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s ORDER BY post_id", $key, $value );
315
-		$results = $wpdb->get_col( $query );
314
+		$query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s ORDER BY post_id", $key, $value);
315
+		$results = $wpdb->get_col($query);
316 316
 		foreach ( $results as $result ) {
317
-			if ( $result && get_post( $result ) ) {
317
+			if ( $result && get_post($result) ) {
318 318
 				return $result;
319 319
 			}
320 320
 		}
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 	 */
330 330
 	public static function get_term_id_by_term_taxonomy_id( $ttid ) {
331 331
 		global $wpdb;
332
-		$query = $wpdb->prepare( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %s", $ttid );
333
-		return $wpdb->get_var( $query );
332
+		$query = $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %s", $ttid);
333
+		return $wpdb->get_var($query);
334 334
 	}
335 335
 
336 336
 	/* Object Utilities
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 * @return void
345 345
 	 */
346 346
 	public static function osort( &$array, $prop ) {
347
-		usort( $array, function ( $a, $b ) use ( $prop ) {
347
+		usort($array, function( $a, $b ) use ($prop) {
348 348
 				return $a->$prop > $b->$prop ? 1 : -1;
349 349
 			} );
350 350
 	}
@@ -356,10 +356,10 @@  discard block
 block discarded – undo
356 356
 	 * @return bool
357 357
 	 */
358 358
 	public static function is_array_assoc( $arr ) {
359
-		if ( !is_array( $arr ) ) {
359
+		if ( !is_array($arr) ) {
360 360
 			return false;
361 361
 		}
362
-		return (bool)count( array_filter( array_keys( $arr ), 'is_string' ) );
362
+		return (bool) count(array_filter(array_keys($arr), 'is_string'));
363 363
 	}
364 364
 
365 365
 	/**
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	public static function array_to_object( $array ) {
372 372
 		$obj = new stdClass;
373 373
 		foreach ( $array as $k => $v ) {
374
-			if ( is_array( $v ) ) {
375
-				$obj->{$k} = self::array_to_object( $v ); //RECURSION
374
+			if ( is_array($v) ) {
375
+				$obj->{$k} = self::array_to_object($v); //RECURSION
376 376
 			} else {
377 377
 				$obj->{$k} = $v;
378 378
 			}
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
 	 * @return bool|int
390 390
 	 */
391 391
 	public static function get_object_index_by_property( $array, $key, $value ) {
392
-		if ( is_array( $array ) ) {
392
+		if ( is_array($array) ) {
393 393
 			$i = 0;
394 394
 			foreach ( $array as $arr ) {
395
-				if ( is_array( $arr ) ) {
395
+				if ( is_array($arr) ) {
396 396
 					if ( $arr[$key] == $value ) {
397 397
 						return $i;
398 398
 					}
@@ -417,15 +417,15 @@  discard block
 block discarded – undo
417 417
 	 * @throws Exception
418 418
 	 */
419 419
 	public static function get_object_by_property( $array, $key, $value ) {
420
-		if ( is_array( $array ) ) {
420
+		if ( is_array($array) ) {
421 421
 			foreach ( $array as $arr ) {
422 422
 				if ( $arr->$key == $value ) {
423 423
 					return $arr;
424 424
 				}
425 425
 			}
426 426
 		} else {
427
-			throw new InvalidArgumentException( '$array is not an array, got:' );
428
-			TimberHelper::error_log( $array );
427
+			throw new InvalidArgumentException('$array is not an array, got:');
428
+			TimberHelper::error_log($array);
429 429
 		}
430 430
 	}
431 431
 
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 	 * @return array
438 438
 	 */
439 439
 	public static function array_truncate( $array, $len ) {
440
-		if ( sizeof( $array ) > $len ) {
441
-			$array = array_splice( $array, 0, $len );
440
+		if ( sizeof($array) > $len ) {
441
+			$array = array_splice($array, 0, $len);
442 442
 		}
443 443
 		return $array;
444 444
 	}
@@ -453,11 +453,11 @@  discard block
 block discarded – undo
453 453
 	 * @return bool
454 454
 	 */
455 455
 	public static function is_true( $value ) {
456
-		if ( isset( $value ) ) {
457
-			if (is_string($value)) {
456
+		if ( isset($value) ) {
457
+			if ( is_string($value) ) {
458 458
 				$value = strtolower($value);
459 459
 			}
460
-			if ( ($value == 'true' || $value === 1 || $value === '1' || $value == true) && $value !== false && $value !== 'false') {
460
+			if ( ($value == 'true' || $value === 1 || $value === '1' || $value == true) && $value !== false && $value !== 'false' ) {
461 461
 				return true;
462 462
 			}
463 463
 		}
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 	 * @return bool
472 472
 	 */
473 473
 	public static function iseven( $i ) {
474
-		return ( $i % 2 ) == 0;
474
+		return ($i % 2) == 0;
475 475
 	}
476 476
 
477 477
 	/**
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	 * @return bool
482 482
 	 */
483 483
 	public static function isodd( $i ) {
484
-		return ( $i % 2 ) != 0;
484
+		return ($i % 2) != 0;
485 485
 	}
486 486
 
487 487
 	/* Links, Forms, Etc. Utilities
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 	 * @return string
497 497
 	 */
498 498
 	public static function get_comment_form( $post_id = null, $args = array() ) {
499
-		return self::ob_function( 'comment_form', array( $args, $post_id ) );
499
+		return self::ob_function('comment_form', array($args, $post_id));
500 500
 	}
501 501
 
502 502
 	/**
@@ -513,28 +513,28 @@  discard block
 block discarded – undo
513 513
 			'current' => 0,
514 514
 			'show_all' => false,
515 515
 			'prev_next' => false,
516
-			'prev_text' => __( '&laquo; Previous' ),
517
-			'next_text' => __( 'Next &raquo;' ),
516
+			'prev_text' => __('&laquo; Previous'),
517
+			'next_text' => __('Next &raquo;'),
518 518
 			'end_size' => 1,
519 519
 			'mid_size' => 2,
520 520
 			'type' => 'array',
521 521
 			'add_args' => false, // array of query args to add
522 522
 			'add_fragment' => ''
523 523
 		);
524
-		$args = wp_parse_args( $args, $defaults );
524
+		$args = wp_parse_args($args, $defaults);
525 525
 		// Who knows what else people pass in $args
526
-		$args['total'] = intval( (int)$args['total'] );
526
+		$args['total'] = intval((int) $args['total']);
527 527
 		if ( $args['total'] < 2 ) {
528 528
 			return array();
529 529
 		}
530
-		$args['current'] = (int)$args['current'];
531
-		$args['end_size'] = 0 < (int)$args['end_size'] ? (int)$args['end_size'] : 1; // Out of bounds?  Make it the default.
532
-		$args['mid_size'] = 0 <= (int)$args['mid_size'] ? (int)$args['mid_size'] : 2;
533
-		$args['add_args'] = is_array( $args['add_args'] ) ? $args['add_args'] : false;
530
+		$args['current'] = (int) $args['current'];
531
+		$args['end_size'] = 0 < (int) $args['end_size'] ? (int) $args['end_size'] : 1; // Out of bounds?  Make it the default.
532
+		$args['mid_size'] = 0 <= (int) $args['mid_size'] ? (int) $args['mid_size'] : 2;
533
+		$args['add_args'] = is_array($args['add_args']) ? $args['add_args'] : false;
534 534
 		$page_links = array();
535 535
 		$dots = false;
536 536
 		for ( $n = 1; $n <= $args['total']; $n++ ) {
537
-			$n_display = number_format_i18n( $n );
537
+			$n_display = number_format_i18n($n);
538 538
 			if ( $n == $args['current'] ) {
539 539
 				$page_links[] = array(
540 540
 					'class' => 'page-number page-numbers current',
@@ -545,18 +545,18 @@  discard block
 block discarded – undo
545 545
 				);
546 546
 				$dots = true;
547 547
 			} else {
548
-				if ( $args['show_all'] || ( $n <= $args['end_size'] || ( $args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size'] ) || $n > $args['total'] - $args['end_size'] ) ) {
549
-					$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
550
-					$link = str_replace( '%#%', $n, $link );
551
-					$link = trailingslashit( $link ) . ltrim( $args['add_fragment'], '/' );
548
+				if ( $args['show_all'] || ($n <= $args['end_size'] || ($args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size']) || $n > $args['total'] - $args['end_size']) ) {
549
+					$link = str_replace('%_%', 1 == $n ? '' : $args['format'], $args['base']);
550
+					$link = str_replace('%#%', $n, $link);
551
+					$link = trailingslashit($link) . ltrim($args['add_fragment'], '/');
552 552
 					if ( $args['add_args'] ) {
553
-						$link = rtrim( add_query_arg( $args['add_args'], $link ), '/' );
553
+						$link = rtrim(add_query_arg($args['add_args'], $link), '/');
554 554
 					}
555 555
 					$link = str_replace(' ', '+', $link);
556
-					$link = untrailingslashit( $link );
556
+					$link = untrailingslashit($link);
557 557
 					$page_links[] = array(
558 558
 						'class' => 'page-number page-numbers',
559
-						'link' => esc_url( apply_filters( 'paginate_links', $link ) ),
559
+						'link' => esc_url(apply_filters('paginate_links', $link)),
560 560
 						'title' => $n_display,
561 561
 						'name' => $n_display,
562 562
 						'current' => $args['current'] == $n
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 				} elseif ( $dots && !$args['show_all'] ) {
566 566
 					$page_links[] = array(
567 567
 						'class' => 'dots',
568
-						'title' => __( '&hellip;' )
568
+						'title' => __('&hellip;')
569 569
 					);
570 570
 					$dots = false;
571 571
 				}
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 	 * @deprecated 0.18.0
586 586
 	 */
587 587
 	static function is_url( $url ) {
588
-		return TimberURLHelper::is_url( $url );
588
+		return TimberURLHelper::is_url($url);
589 589
 	}
590 590
 
591 591
 	/**
@@ -599,70 +599,70 @@  discard block
 block discarded – undo
599 599
 	 * @deprecated 0.18.0
600 600
 	 */
601 601
 	static function get_rel_url( $url, $force = false ) {
602
-		return TimberURLHelper::get_rel_url( $url, $force );
602
+		return TimberURLHelper::get_rel_url($url, $force);
603 603
 	}
604 604
 
605 605
 	/**
606 606
 	 * @deprecated 0.18.0
607 607
 	 */
608 608
 	static function is_local( $url ) {
609
-		return TimberURLHelper::is_local( $url );
609
+		return TimberURLHelper::is_local($url);
610 610
 	}
611 611
 
612 612
 	/**
613 613
 	 * @deprecated 0.18.0
614 614
 	 */
615 615
 	static function get_full_path( $src ) {
616
-		return TimberURLHelper::get_full_path( $src );
616
+		return TimberURLHelper::get_full_path($src);
617 617
 	}
618 618
 
619 619
 	/**
620 620
 	 * @deprecated 0.18.0
621 621
 	 */
622 622
 	static function get_rel_path( $src ) {
623
-		return TimberURLHelper::get_rel_path( $src );
623
+		return TimberURLHelper::get_rel_path($src);
624 624
 	}
625 625
 
626 626
 	/**
627 627
 	 * @deprecated 0.18.0
628 628
 	 */
629 629
 	static function remove_double_slashes( $url ) {
630
-		return TimberURLHelper::remove_double_slashes( $url );
630
+		return TimberURLHelper::remove_double_slashes($url);
631 631
 	}
632 632
 
633 633
 	/**
634 634
 	 * @deprecated 0.18.0
635 635
 	 */
636 636
 	static function prepend_to_url( $url, $path ) {
637
-		return TimberURLHelper::prepend_to_url( $url, $path );
637
+		return TimberURLHelper::prepend_to_url($url, $path);
638 638
 	}
639 639
 
640 640
 	/**
641 641
 	 * @deprecated 0.18.0
642 642
 	 */
643 643
 	static function preslashit( $path ) {
644
-		return TimberURLHelper::preslashit( $path );
644
+		return TimberURLHelper::preslashit($path);
645 645
 	}
646 646
 
647 647
 	/**
648 648
 	 * @deprecated 0.18.0
649 649
 	 */
650 650
 	static function is_external( $url ) {
651
-		return TimberURLHelper::is_external( $url );
651
+		return TimberURLHelper::is_external($url);
652 652
 	}
653 653
 
654 654
 	/**
655 655
 	 * @deprecated 0.18.0
656 656
 	 */
657 657
 	static function download_url( $url, $timeout = 300 ) {
658
-		return TimberURLHelper::download_url( $url, $timeout );
658
+		return TimberURLHelper::download_url($url, $timeout);
659 659
 	}
660 660
 
661 661
 	/**
662 662
 	 * @deprecated 0.18.0
663 663
 	 */
664 664
 	static function get_params( $i = -1 ) {
665
-		return TimberURLHelper::get_params( $i );
665
+		return TimberURLHelper::get_params($i);
666 666
 	}
667 667
 
668 668
 }
Please login to merge, or discard this patch.
lib/timber-image-helper.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,8 @@
 block discarded – undo
325 325
 		);
326 326
 		$upload_dir = wp_upload_dir();
327 327
 		$tmp = $url;
328
-		if ( 0 === strpos($tmp, ABSPATH) ) { // we've been given a dir, not an url
328
+		if ( 0 === strpos($tmp, ABSPATH) ) {
329
+// we've been given a dir, not an url
329 330
 			$result['absolute'] = true;
330 331
 			if ( 0 === strpos($tmp, $upload_dir['basedir']) ) {
331 332
 				$result['base']= self::BASE_UPLOADS; // upload based
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 			$w = $_wp_additional_image_sizes[$size]['width'];
73 73
 			$h = $_wp_additional_image_sizes[$size]['height'];
74 74
 		} else if ( in_array($size, array('thumbnail', 'medium', 'large')) ) {
75
-			$w = get_option($size.'_size_w');
76
-			$h = get_option($size.'_size_h');
75
+			$w = get_option($size . '_size_w');
76
+			$h = get_option($size . '_size_h');
77 77
 		}
78 78
 		if ( isset($w) && isset($h) && ($w || $h) ) {
79 79
 			return array('w' => $w, 'h' => $h);
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 	    }
@@ -159,13 +159,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 	 *	                            or: http://example.org/wp-content/uploads/2015/my-pic.jpg
202 202
 	 */
203 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 );
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
 	/**
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
 	 */
229 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
 	}
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 	 */
248 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
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
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;
@@ -283,27 +283,27 @@  discard block
 block discarded – undo
283 283
 	 * @return string the URL to the downloaded file
284 284
 	 */
285 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 ) );
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
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @param  string $url an URL (absolute or relative) pointing to an image
316 316
 	 * @return array       an array (see keys in code below)
317 317
 	 */
318
-	private static function analyze_url($url) {
318
+	private static function analyze_url( $url ) {
319 319
 		$result = array(
320 320
 			'url' => $url, // the initial url
321 321
 			'absolute' => TimberURLHelper::is_absolute($url), // is the url absolute or relative (to home_url)
@@ -330,23 +330,23 @@  discard block
 block discarded – undo
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
 		}
@@ -368,20 +368,20 @@  discard block
 block discarded – undo
368 368
 	 * @param  bool   $absolute should the returned URL be absolute (include protocol+host), or relative
369 369
 	 * @return string           the URL
370 370
 	 */
371
-	private static function _get_file_url($base, $subdir, $filename, $absolute) {
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);
@@ -396,19 +396,19 @@  discard block
 block discarded – undo
396 396
 	 * @param  string $filename file name, including extension (but no path)
397 397
 	 * @return string           the file location
398 398
 	 */
399
-	private static function _get_file_path($base, $subdir, $filename) {
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
 
@@ -427,14 +427,14 @@  discard block
 block discarded – undo
427 427
 	 *
428 428
 	 */
429 429
 	private static function _operate( $src, $op, $force = false ) {
430
-		if ( empty( $src ) ) {
430
+		if ( empty($src) ) {
431 431
 			return '';
432 432
 		}
433 433
 		$external = false;
434 434
 
435 435
 		// if external image, load it first
436
-		if ( TimberURLHelper::is_external_content( $src ) ) {
437
-			$src = self::sideload_image( $src );
436
+		if ( TimberURLHelper::is_external_content($src) ) {
437
+			$src = self::sideload_image($src);
438 438
 			$external = true;
439 439
 		}
440 440
 		// break down URL into components
@@ -457,19 +457,19 @@  discard block
 block discarded – undo
457 457
 			$au['basename']
458 458
 		);
459 459
 		// if already exists...
460
-		if ( file_exists( $new_server_path ) ) {
460
+		if ( file_exists($new_server_path) ) {
461 461
 			if ( $force ) {
462 462
 				// Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
463
-				unlink( $new_server_path );
463
+				unlink($new_server_path);
464 464
 			} else {
465 465
 				// return existing file (caching)
466 466
 				return $new_url;
467 467
 			}
468 468
 		}
469 469
 		// otherwise generate result file
470
-		if($op->run($old_server_path, $new_server_path)) {
471
-			if( get_class( $op ) === 'TimberImageOperationResize' && $external ) {
472
-				$new_url = strtolower( $new_url );
470
+		if ( $op->run($old_server_path, $new_server_path) ) {
471
+			if ( get_class($op) === 'TimberImageOperationResize' && $external ) {
472
+				$new_url = strtolower($new_url);
473 473
 			}
474 474
 			return $new_url;
475 475
 		} else {
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 
482 482
 // -- the below methods are just used for unit testing the URL generation code
483 483
 //
484
-	static function get_letterbox_file_url($url, $w, $h, $color) {
484
+	static function get_letterbox_file_url( $url, $w, $h, $color ) {
485 485
 		$au = self::analyze_url($url);
486 486
 		$op = new TimberImageOperationLetterbox($w, $h, $color);
487 487
 		$new_url = self::_get_file_url(
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 		);
493 493
 		return $new_url;
494 494
 	}
495
-	public static function get_letterbox_file_path($url, $w, $h, $color ) {
495
+	public static function get_letterbox_file_path( $url, $w, $h, $color ) {
496 496
 		$au = self::analyze_url($url);
497 497
 		$op = new TimberImageOperationLetterbox($w, $h, $color);
498 498
 		$new_path = self::_get_file_path(
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 		);
503 503
 		return $new_path;
504 504
 	}
505
-	static function get_resize_file_url($url, $w, $h, $crop) {
505
+	static function get_resize_file_url( $url, $w, $h, $crop ) {
506 506
 		$au = self::analyze_url($url);
507 507
 		$op = new TimberImageOperationResize($w, $h, $crop);
508 508
 		$new_url = self::_get_file_url(
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 		);
514 514
 		return $new_url;
515 515
 	}
516
-	static function get_resize_file_path($url, $w, $h, $crop) {
516
+	static function get_resize_file_path( $url, $w, $h, $crop ) {
517 517
 		$au = self::analyze_url($url);
518 518
 		$op = new TimberImageOperationResize($w, $h, $crop);
519 519
 		$new_path = self::_get_file_path(
Please login to merge, or discard this patch.
lib/timber-integrations.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
lib/timber-loader.php 2 patches
Braces   +20 added lines, -21 removed lines patch added patch discarded remove patch
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
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 264
 		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 			return true;
278 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
 block discarded – undo
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
 		}
@@ -348,14 +348,13 @@  discard block
 block discarded – undo
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)
352
-			$value = get_transient($trans_key);
353
-
354
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
355
-			$value = get_site_transient($trans_key);
356
-
357
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
358
-			$value = wp_cache_get($key, $group);
351
+		if (self::CACHE_TRANSIENT === $cache_mode) {
352
+					$value = get_transient($trans_key);
353
+		} elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) {
354
+					$value = get_site_transient($trans_key);
355
+		} elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) {
356
+					$value = wp_cache_get($key, $group);
357
+		}
359 358
 
360 359
 		return $value;
361 360
 	}
@@ -375,20 +374,20 @@  discard block
 block discarded – undo
375 374
 			$object_cache = true;
376 375
 		}
377 376
 
378
-		if ((int)$expires < 1)
379
-			$expires = 0;
377
+		if ((int)$expires < 1) {
378
+					$expires = 0;
379
+		}
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)
385
-			set_transient($trans_key, $value, $expires);
386
-
387
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
388
-			set_site_transient($trans_key, $value, $expires);
389
-
390
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
391
-			wp_cache_set($key, $value, $group, $expires);
384
+		if (self::CACHE_TRANSIENT === $cache_mode) {
385
+					set_transient($trans_key, $value, $expires);
386
+		} elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) {
387
+					set_site_transient($trans_key, $value, $expires);
388
+		} elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) {
389
+					wp_cache_set($key, $value, $group, $expires);
390
+		}
392 391
 
393 392
 		return $value;
394 393
 	}
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	/**
27 27
 	 * @param bool|string   $caller the calling directory or false
28 28
 	 */
29
-	function __construct($caller = false) {
29
+	function __construct( $caller = false ) {
30 30
 		$this->locations = $this->get_locations($caller);
31 31
 		$this->cache_mode = apply_filters('timber_cache_mode', $this->cache_mode);
32 32
 		$this->cache_mode = apply_filters('timber/cache/mode', $this->cache_mode);
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 	 * @param string        $cache_mode
40 40
 	 * @return bool|string
41 41
 	 */
42
-	function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) {
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
 block discarded – undo
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
 block discarded – undo
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);
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 * @param array $filenames
81 81
 	 * @return bool
82 82
 	 */
83
-	public function choose_template($filenames) {
84
-		if (is_array($filenames)) {
83
+	public function choose_template( $filenames ) {
84
+		if ( is_array($filenames) ) {
85 85
 			/* its an array so we have to figure out which one the dev wants */
86
-			foreach ($filenames as $filename) {
87
-				if (self::template_exists($filename)) {
86
+			foreach ( $filenames as $filename ) {
87
+				if ( self::template_exists($filename) ) {
88 88
 					return $filename;
89 89
 				}
90 90
 			}
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 	 * @param string $file
98 98
 	 * @return bool
99 99
 	 */
100
-	protected function template_exists($file) {
101
-		foreach ($this->locations as $dir) {
100
+	protected function template_exists( $file ) {
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,17 +114,17 @@  discard block
 block discarded – undo
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
 		}
121 121
 		$theme_locs[] = $child_loc;
122
-		foreach ($this->get_locations_theme_dir() as $dirname) {
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
-			foreach ($this->get_locations_theme_dir() as $dirname) {
127
+			foreach ( $this->get_locations_theme_dir() as $dirname ) {
128 128
 				$theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname);
129 129
 			}
130 130
 		}
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
-			foreach (Timber::$locations as $tloc) {
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
 			}
@@ -167,16 +167,16 @@  discard block
 block discarded – undo
167 167
 	 * @param bool|string   $caller the calling directory
168 168
 	 * @return array
169 169
 	 */
170
-	function get_locations_caller($caller = false) {
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
-			foreach ($this->get_locations_theme_dir() as $dirname) {
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
 			}
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @param bool|string   $caller the calling directory (or false)
189 189
 	 * @return array
190 190
 	 */
191
-	function get_locations($caller = false) {
191
+	function get_locations( $caller = false ) {
192 192
 		//prioirty: user locations, caller (but not theme), child theme, parent theme, caller
193 193
 		$locs = array();
194 194
 		$locs = array_merge($locs, $this->get_locations_user());
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	function get_loader() {
210 210
 		$paths = array();
211
-		foreach ($this->locations as $loc) {
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 	/**
300 300
 	 * @param string|false $dirPath
301 301
 	 */
302
-	public static function rrmdir($dirPath) {
303
-		if (! is_dir($dirPath)) {
302
+	public static function rrmdir( $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
-		foreach ($files as $file) {
311
-			if (is_dir($file)) {
310
+		foreach ( $files as $file ) {
311
+			if ( is_dir($file) ) {
312 312
 				self::rrmdir($file);
313 313
 			} else {
314 314
 				unlink($file);
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
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
 	}
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 	 * @param string $cache_mode
337 337
 	 * @return bool
338 338
 	 */
339
-	public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) {
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
 block discarded – undo
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;
@@ -368,26 +368,26 @@  discard block
 block discarded – undo
368 368
 	 * @param string $cache_mode
369 369
 	 * @return string|boolean
370 370
 	 */
371
-	public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) {
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;
@@ -397,13 +397,13 @@  discard block
 block discarded – undo
397 397
 	 * @param string $cache_mode
398 398
 	 * @return string
399 399
 	 */
400
-	private function _get_cache_mode($cache_mode) {
401
-		if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) {
400
+	private function _get_cache_mode( $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
 
Please login to merge, or discard this patch.
lib/timber-menu.php 2 patches
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		$menu = wp_get_nav_menu_items($menu_id);
102 102
 		if ($menu) {
103 103
 			_wp_menu_item_classes_by_context($menu);
104
-			if (is_array($menu)){
104
+			if (is_array($menu)) {
105 105
 				$menu = self::order_children($menu);
106 106
 			}
107 107
 			$this->items = $menu;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 				$mi->__title = $mi->post_title;
124 124
 			}
125 125
 			_wp_menu_item_classes_by_context($menu);
126
-			if (is_array($menu)){
126
+			if (is_array($menu)) {
127 127
 				$menu = self::order_children($menu);
128 128
 			}
129 129
 			$this->items = $menu;
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
 				$item->__title = $item->title;
202 202
 				unset($item->title);
203 203
 			}
204
-			if(isset($item->ID)){
205
-				if (is_object($item) && get_class($item) == 'WP_Post'){
204
+			if(isset($item->ID)) {
205
+				if (is_object($item) && get_class($item) == 'WP_Post') {
206 206
 					$old_menu_item = $item;
207 207
 					$item = new $this->PostClass($item);
208 208
 				}
209 209
 				$menu_item = new $this->MenuItemClass($item);
210
-				if (isset($old_menu_item)){
210
+				if (isset($old_menu_item)) {
211 211
 					$menu_item->import_classes($old_menu_item);
212 212
 				}
213 213
 				$index[$item->ID] = $menu_item;
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -75,18 +75,18 @@  discard block
 block discarded – undo
75 75
 	/**
76 76
 	 * @param int|string $slug
77 77
 	 */
78
-	function __construct($slug = 0) {
78
+	function __construct( $slug = 0 ) {
79 79
 		$locations = get_nav_menu_locations();
80
-		if ($slug != 0 && is_numeric($slug)) {
80
+		if ( $slug != 0 && is_numeric($slug) ) {
81 81
 			$menu_id = $slug;
82
-		} else if (is_array($locations) && count($locations)) {
82
+		} else if ( is_array($locations) && count($locations) ) {
83 83
 			$menu_id = $this->get_menu_id_from_locations($slug, $locations);
84
-		} else if ($slug === false) {
84
+		} else if ( $slug === false ) {
85 85
 			$menu_id = false;
86 86
 		} else {
87 87
 			$menu_id = $this->get_menu_id_from_terms($slug);
88 88
 		}
89
-		if ($menu_id) {
89
+		if ( $menu_id ) {
90 90
 			$this->init($menu_id);
91 91
 		} else {
92 92
 			$this->init_as_page_menu();
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * @internal
98 98
 	 * @param int $menu_id
99 99
 	 */
100
-	protected function init($menu_id) {
100
+	protected function init( $menu_id ) {
101 101
 		$menu = wp_get_nav_menu_items($menu_id);
102
-		if ($menu) {
102
+		if ( $menu ) {
103 103
 			_wp_menu_item_classes_by_context($menu);
104
-			if (is_array($menu)){
104
+			if ( is_array($menu) ) {
105 105
 				$menu = self::order_children($menu);
106 106
 			}
107 107
 			$this->items = $menu;
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	protected function init_as_page_menu() {
120 120
 		$menu = get_pages();
121
-		if ($menu) {
122
-			foreach($menu as $mi) {
121
+		if ( $menu ) {
122
+			foreach ( $menu as $mi ) {
123 123
 				$mi->__title = $mi->post_title;
124 124
 			}
125 125
 			_wp_menu_item_classes_by_context($menu);
126
-			if (is_array($menu)){
126
+			if ( is_array($menu) ) {
127 127
 				$menu = self::order_children($menu);
128 128
 			}
129 129
 			$this->items = $menu;
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
 	 * @param array $locations
137 137
 	 * @return integer
138 138
 	 */
139
-	protected function get_menu_id_from_locations($slug, $locations) {
140
-		if ($slug === 0) {
139
+	protected function get_menu_id_from_locations( $slug, $locations ) {
140
+		if ( $slug === 0 ) {
141 141
 			$slug = $this->get_menu_id_from_terms($slug);
142 142
 		}
143
-		if (is_numeric($slug)) {
143
+		if ( is_numeric($slug) ) {
144 144
 			$slug = array_search($slug, $locations);
145 145
 		}
146
-		if (isset($locations[$slug])) {
146
+		if ( isset($locations[$slug]) ) {
147 147
 			$menu_id = $locations[$slug];
148 148
 			return $menu_id;
149 149
 		}
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
 	 * @param int $slug
155 155
 	 * @return int
156 156
 	 */
157
-	protected function get_menu_id_from_terms($slug = 0) {
158
-		if (!is_numeric($slug) && is_string($slug)) {
157
+	protected function get_menu_id_from_terms( $slug = 0 ) {
158
+		if ( !is_numeric($slug) && is_string($slug) ) {
159 159
 			//we have a string so lets search for that
160 160
 			$menu_id = get_term_by('slug', $slug, 'nav_menu');
161
-			if ($menu_id) {
161
+			if ( $menu_id ) {
162 162
 				return $menu_id;
163 163
 			}
164 164
 			$menu_id = get_term_by('name', $slug, 'nav_menu');
165
-			if ($menu_id) {
165
+			if ( $menu_id ) {
166 166
 				return $menu_id;
167 167
 			}
168 168
 		}
169 169
 		$menus = get_terms('nav_menu', array('hide_empty' => true));
170
-		if (is_array($menus) && count($menus)) {
171
-			if (isset($menus[0]->term_id)) {
170
+		if ( is_array($menus) && count($menus) ) {
171
+			if ( isset($menus[0]->term_id) ) {
172 172
 				return $menus[0]->term_id;
173 173
 			}
174 174
 		}
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 * @param int $parent_id
181 181
 	 * @return TimberMenuItem|null
182 182
 	 */
183
-	function find_parent_item_in_menu($menu_items, $parent_id) {
184
-		foreach ($menu_items as &$item) {
185
-			if ($item->ID == $parent_id) {
183
+	function find_parent_item_in_menu( $menu_items, $parent_id ) {
184
+		foreach ( $menu_items as &$item ) {
185
+			if ( $item->ID == $parent_id ) {
186 186
 				return $item;
187 187
 			}
188 188
 		}
@@ -193,29 +193,29 @@  discard block
 block discarded – undo
193 193
 	 * @param array $items
194 194
 	 * @return array
195 195
 	 */
196
-	protected function order_children($items) {
196
+	protected function order_children( $items ) {
197 197
 		$index = array();
198 198
 		$menu = array();
199
-		foreach ($items as $item) {
200
-			if (isset($item->title)) {
199
+		foreach ( $items as $item ) {
200
+			if ( isset($item->title) ) {
201 201
 				//items from wp can come with a $title property which conflicts with methods
202 202
 				$item->__title = $item->title;
203 203
 				unset($item->title);
204 204
 			}
205
-			if(isset($item->ID)){
206
-				if (is_object($item) && get_class($item) == 'WP_Post'){
205
+			if ( isset($item->ID) ) {
206
+				if ( is_object($item) && get_class($item) == 'WP_Post' ) {
207 207
 					$old_menu_item = $item;
208 208
 					$item = new $this->PostClass($item);
209 209
 				}
210 210
 				$menu_item = new $this->MenuItemClass($item);
211
-				if (isset($old_menu_item)){
211
+				if ( isset($old_menu_item) ) {
212 212
 					$menu_item->import_classes($old_menu_item);
213 213
 				}
214 214
 				$index[$item->ID] = $menu_item;
215 215
 			}
216 216
 		}
217
-		foreach ($index as $item) {
218
-			if (isset($item->menu_item_parent) && $item->menu_item_parent && isset($index[$item->menu_item_parent])) {
217
+		foreach ( $index as $item ) {
218
+			if ( isset($item->menu_item_parent) && $item->menu_item_parent && isset($index[$item->menu_item_parent]) ) {
219 219
 				$index[$item->menu_item_parent]->add_child($item);
220 220
 			} else {
221 221
 				$menu[] = $item;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * @return array
229 229
 	 */
230 230
 	function get_items() {
231
-		if (is_array($this->items)) {
231
+		if ( is_array($this->items) ) {
232 232
 			return $this->items;
233 233
 		}
234 234
 		return array();
Please login to merge, or discard this patch.