Completed
Push — master ( 1fa612...adffc5 )
by Jared
02:46
created
lib/timber-core.php 1 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-image-helper.php 1 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-twig.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 	 * @codeCoverageIgnore
16 16
 	 */
17 17
 	function __construct() {
18
-		add_action( 'timber/twig/filters', array( $this, 'add_timber_filters_deprecated' ) );
19
-		add_action( 'timber/twig/filters', array( $this, 'add_timber_filters' ) );
18
+		add_action('timber/twig/filters', array($this, 'add_timber_filters_deprecated'));
19
+		add_action('timber/twig/filters', array($this, 'add_timber_filters'));
20 20
 	}
21 21
 
22 22
 	/**
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
 	 * @return Twig_Environment
28 28
 	 */
29 29
 	function add_timber_filters_deprecated( $twig ) {
30
-		$twig->addFilter( new Twig_SimpleFilter( 'get_src_from_attachment_id', 'twig_get_src_from_attachment_id' ) );
31
-		$twig->addFilter( new Twig_SimpleFilter( 'wp_body_class', array( $this, 'body_class' ) ) );
32
-		$twig->addFilter( new Twig_SimpleFilter( 'twitterify', array( 'TimberHelper', 'twitterify' ) ) );
33
-		$twig->addFilter( new Twig_SimpleFilter( 'twitterfy', array( 'TimberHelper', 'twitterify' ) ) );
34
-		$twig->addFilter( new Twig_SimpleFilter( 'string', function($arr, $glue = ' '){
30
+		$twig->addFilter(new Twig_SimpleFilter('get_src_from_attachment_id', 'twig_get_src_from_attachment_id'));
31
+		$twig->addFilter(new Twig_SimpleFilter('wp_body_class', array($this, 'body_class')));
32
+		$twig->addFilter(new Twig_SimpleFilter('twitterify', array('TimberHelper', 'twitterify')));
33
+		$twig->addFilter(new Twig_SimpleFilter('twitterfy', array('TimberHelper', 'twitterify')));
34
+		$twig->addFilter(new Twig_SimpleFilter('string', function( $arr, $glue = ' ' ) {
35 35
 			return twig_join_filter($arr, $glue);
36
-		} ) );
36
+		} ));
37 37
 		return $twig;
38 38
 	}
39 39
 
@@ -45,149 +45,149 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	function add_timber_filters( $twig ) {
47 47
 		/* image filters */
48
-		$twig->addFilter( new Twig_SimpleFilter( 'resize', array( 'TimberImageHelper', 'resize' ) ) );
49
-		$twig->addFilter( new Twig_SimpleFilter( 'retina', array( 'TimberImageHelper', 'retina_resize' ) ) );
50
-		$twig->addFilter( new Twig_SimpleFilter( 'letterbox', array( 'TimberImageHelper', 'letterbox' ) ) );
51
-		$twig->addFilter( new Twig_SimpleFilter( 'tojpg', array( 'TimberImageHelper', 'img_to_jpg' ) ) );
48
+		$twig->addFilter(new Twig_SimpleFilter('resize', array('TimberImageHelper', 'resize')));
49
+		$twig->addFilter(new Twig_SimpleFilter('retina', array('TimberImageHelper', 'retina_resize')));
50
+		$twig->addFilter(new Twig_SimpleFilter('letterbox', array('TimberImageHelper', 'letterbox')));
51
+		$twig->addFilter(new Twig_SimpleFilter('tojpg', array('TimberImageHelper', 'img_to_jpg')));
52 52
 
53 53
 		/* debugging filters */
54
-		$twig->addFilter( new Twig_SimpleFilter( 'docs', 'twig_object_docs' ) );
55
-		$twig->addFilter( new Twig_SimpleFilter( 'get_class',  'get_class' ) );
56
-		$twig->addFilter( new Twig_SimpleFilter( 'get_type', 'get_type' ) );
57
-		$twig->addFilter( new Twig_SimpleFilter( 'print_r', function( $arr ) {
58
-					return print_r( $arr, true );
59
-				} ) );
60
-		$twig->addFilter( new Twig_SimpleFilter( 'print_a', function( $arr ) {
61
-					return '<pre>' . self::object_docs( $arr, true ) . '</pre>';
62
-				} ) );
54
+		$twig->addFilter(new Twig_SimpleFilter('docs', 'twig_object_docs'));
55
+		$twig->addFilter(new Twig_SimpleFilter('get_class', 'get_class'));
56
+		$twig->addFilter(new Twig_SimpleFilter('get_type', 'get_type'));
57
+		$twig->addFilter(new Twig_SimpleFilter('print_r', function( $arr ) {
58
+					return print_r($arr, true);
59
+				} ));
60
+		$twig->addFilter(new Twig_SimpleFilter('print_a', function( $arr ) {
61
+					return '<pre>' . self::object_docs($arr, true) . '</pre>';
62
+				} ));
63 63
 
64 64
 		/* other filters */
65
-		$twig->addFilter( new Twig_SimpleFilter( 'stripshortcodes', 'strip_shortcodes' ) );
66
-		$twig->addFilter( new Twig_SimpleFilter( 'array', array( $this, 'to_array' ) ) );
67
-		$twig->addFilter( new Twig_SimpleFilter( 'excerpt', 'wp_trim_words' ) );
68
-		$twig->addFilter( new Twig_SimpleFilter( 'function', array( $this, 'exec_function' ) ) );
69
-		$twig->addFilter( new Twig_SimpleFilter( 'pretags', array( $this, 'twig_pretags' ) ) );
70
-		$twig->addFilter( new Twig_SimpleFilter( 'sanitize', 'sanitize_title' ) );
71
-		$twig->addFilter( new Twig_SimpleFilter( 'shortcodes', 'do_shortcode' ) );
72
-		$twig->addFilter( new Twig_SimpleFilter( 'time_ago', array( $this, 'time_ago' ) ) );
73
-		$twig->addFilter( new Twig_SimpleFilter( 'wpautop', 'wpautop' ) );
74
-		$twig->addFilter( new Twig_SimpleFilter( 'list', array( $this, 'add_list_separators' ) ) );
75
-
76
-		$twig->addFilter( new Twig_SimpleFilter( 'relative', function ( $link ) {
77
-					return TimberURLHelper::get_rel_url( $link, true );
78
-				} ) );
79
-
80
-		$twig->addFilter( new Twig_SimpleFilter( 'date', array( $this, 'intl_date' ) ) );
81
-
82
-		$twig->addFilter( new Twig_SimpleFilter( 'truncate', function ( $text, $len ) {
83
-					return TimberHelper::trim_words( $text, $len );
84
-				} ) );
65
+		$twig->addFilter(new Twig_SimpleFilter('stripshortcodes', 'strip_shortcodes'));
66
+		$twig->addFilter(new Twig_SimpleFilter('array', array($this, 'to_array')));
67
+		$twig->addFilter(new Twig_SimpleFilter('excerpt', 'wp_trim_words'));
68
+		$twig->addFilter(new Twig_SimpleFilter('function', array($this, 'exec_function')));
69
+		$twig->addFilter(new Twig_SimpleFilter('pretags', array($this, 'twig_pretags')));
70
+		$twig->addFilter(new Twig_SimpleFilter('sanitize', 'sanitize_title'));
71
+		$twig->addFilter(new Twig_SimpleFilter('shortcodes', 'do_shortcode'));
72
+		$twig->addFilter(new Twig_SimpleFilter('time_ago', array($this, 'time_ago')));
73
+		$twig->addFilter(new Twig_SimpleFilter('wpautop', 'wpautop'));
74
+		$twig->addFilter(new Twig_SimpleFilter('list', array($this, 'add_list_separators')));
75
+
76
+		$twig->addFilter(new Twig_SimpleFilter('relative', function( $link ) {
77
+					return TimberURLHelper::get_rel_url($link, true);
78
+				} ));
79
+
80
+		$twig->addFilter(new Twig_SimpleFilter('date', array($this, 'intl_date')));
81
+
82
+		$twig->addFilter(new Twig_SimpleFilter('truncate', function( $text, $len ) {
83
+					return TimberHelper::trim_words($text, $len);
84
+				} ));
85 85
 
86 86
 		/* actions and filters */
87
-		$twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) {
87
+		$twig->addFunction(new Twig_SimpleFunction('action', function( $context ) {
88 88
 					$args = func_get_args();
89
-					array_shift( $args );
89
+					array_shift($args);
90 90
 					$args[] = $context;
91
-					call_user_func_array( 'do_action', $args );
92
-				}, array( 'needs_context' => true ) ) );
91
+					call_user_func_array('do_action', $args);
92
+				}, array('needs_context' => true)));
93 93
 
94
-		$twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () {
94
+		$twig->addFilter(new Twig_SimpleFilter('apply_filters', function() {
95 95
 					$args = func_get_args();
96
-					$tag = current( array_splice( $args, 1, 1 ) );
96
+					$tag = current(array_splice($args, 1, 1));
97 97
 
98
-					return apply_filters_ref_array( $tag, $args );
99
-				} ) );
100
-		$twig->addFunction( new Twig_SimpleFunction( 'function', array( &$this, 'exec_function' ) ) );
101
-		$twig->addFunction( new Twig_SimpleFunction( 'fn', array( &$this, 'exec_function' ) ) );
98
+					return apply_filters_ref_array($tag, $args);
99
+				} ));
100
+		$twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function')));
101
+		$twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function')));
102 102
 
103
-		$twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) );
103
+		$twig->addFunction(new Twig_SimpleFunction('shortcode', 'do_shortcode'));
104 104
 
105 105
 		/* TimberObjects */
106
-		$twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) {
107
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
106
+		$twig->addFunction(new Twig_SimpleFunction('TimberPost', function( $pid, $PostClass = 'TimberPost' ) {
107
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
108 108
 						foreach ( $pid as &$p ) {
109
-							$p = new $PostClass( $p );
109
+							$p = new $PostClass($p);
110 110
 						}
111 111
 						return $pid;
112 112
 					}
113
-					return new $PostClass( $pid );
114
-				} ) );
115
-		$twig->addFunction( new Twig_SimpleFunction( 'TimberImage', function ( $pid, $ImageClass = 'TimberImage' ) {
116
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
113
+					return new $PostClass($pid);
114
+				} ));
115
+		$twig->addFunction(new Twig_SimpleFunction('TimberImage', function( $pid, $ImageClass = 'TimberImage' ) {
116
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
117 117
 						foreach ( $pid as &$p ) {
118
-							$p = new $ImageClass( $p );
118
+							$p = new $ImageClass($p);
119 119
 						}
120 120
 						return $pid;
121 121
 					}
122
-					return new $ImageClass( $pid );
123
-				} ) );
124
-		$twig->addFunction( new Twig_SimpleFunction( 'TimberTerm', function ( $pid, $TermClass = 'TimberTerm' ) {
125
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
122
+					return new $ImageClass($pid);
123
+				} ));
124
+		$twig->addFunction(new Twig_SimpleFunction('TimberTerm', function( $pid, $TermClass = 'TimberTerm' ) {
125
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
126 126
 						foreach ( $pid as &$p ) {
127
-							$p = new $TermClass( $p );
127
+							$p = new $TermClass($p);
128 128
 						}
129 129
 						return $pid;
130 130
 					}
131
-					return new $TermClass( $pid );
132
-				} ) );
133
-		$twig->addFunction( new Twig_SimpleFunction( 'TimberUser', function ( $pid, $UserClass = 'TimberUser' ) {
134
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
131
+					return new $TermClass($pid);
132
+				} ));
133
+		$twig->addFunction(new Twig_SimpleFunction('TimberUser', function( $pid, $UserClass = 'TimberUser' ) {
134
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
135 135
 						foreach ( $pid as &$p ) {
136
-							$p = new $UserClass( $p );
136
+							$p = new $UserClass($p);
137 137
 						}
138 138
 						return $pid;
139 139
 					}
140
-					return new $UserClass( $pid );
141
-				} ) );
140
+					return new $UserClass($pid);
141
+				} ));
142 142
 
143 143
 		/* TimberObjects Alias */
144
-		$twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) {
145
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
144
+		$twig->addFunction(new Twig_SimpleFunction('Post', function( $pid, $PostClass = 'TimberPost' ) {
145
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
146 146
 						foreach ( $pid as &$p ) {
147
-							$p = new $PostClass( $p );
147
+							$p = new $PostClass($p);
148 148
 						}
149 149
 						return $pid;
150 150
 					}
151
-					return new $PostClass( $pid );
152
-				} ) );
153
-		$twig->addFunction( new Twig_SimpleFunction( 'Image', function ( $pid, $ImageClass = 'TimberImage' ) {
154
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
151
+					return new $PostClass($pid);
152
+				} ));
153
+		$twig->addFunction(new Twig_SimpleFunction('Image', function( $pid, $ImageClass = 'TimberImage' ) {
154
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
155 155
 						foreach ( $pid as &$p ) {
156
-							$p = new $ImageClass( $p );
156
+							$p = new $ImageClass($p);
157 157
 						}
158 158
 						return $pid;
159 159
 					}
160
-					return new $ImageClass( $pid );
161
-				} ) );
162
-		$twig->addFunction( new Twig_SimpleFunction( 'Term', function ( $pid, $TermClass = 'TimberTerm' ) {
163
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
160
+					return new $ImageClass($pid);
161
+				} ));
162
+		$twig->addFunction(new Twig_SimpleFunction('Term', function( $pid, $TermClass = 'TimberTerm' ) {
163
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
164 164
 						foreach ( $pid as &$p ) {
165
-							$p = new $TermClass( $p );
165
+							$p = new $TermClass($p);
166 166
 						}
167 167
 						return $pid;
168 168
 					}
169
-					return new $TermClass( $pid );
170
-				} ) );
171
-		$twig->addFunction( new Twig_SimpleFunction( 'User', function ( $pid, $UserClass = 'TimberUser' ) {
172
-					if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) {
169
+					return new $TermClass($pid);
170
+				} ));
171
+		$twig->addFunction(new Twig_SimpleFunction('User', function( $pid, $UserClass = 'TimberUser' ) {
172
+					if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) {
173 173
 						foreach ( $pid as &$p ) {
174
-							$p = new $UserClass( $p );
174
+							$p = new $UserClass($p);
175 175
 						}
176 176
 						return $pid;
177 177
 					}
178
-					return new $UserClass( $pid );
179
-				} ) );
178
+					return new $UserClass($pid);
179
+				} ));
180 180
 
181 181
 		/* bloginfo and translate */
182
-		$twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) {
183
-					return get_bloginfo( $show, $filter );
184
-				} ) );
185
-		$twig->addFunction( '__', new Twig_SimpleFunction( '__', function ( $text, $domain = 'default' ) {
186
-					return __( $text, $domain );
187
-				} ) );
182
+		$twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function( $show = '', $filter = 'raw' ) {
183
+					return get_bloginfo($show, $filter);
184
+				} ));
185
+		$twig->addFunction('__', new Twig_SimpleFunction('__', function( $text, $domain = 'default' ) {
186
+					return __($text, $domain);
187
+				} ));
188 188
 		/* get_twig is deprecated, use timber/twig */
189
-		$twig = apply_filters( 'get_twig', $twig );
190
-		$twig = apply_filters( 'timber/twig', $twig );
189
+		$twig = apply_filters('get_twig', $twig);
190
+		$twig = apply_filters('timber/twig', $twig);
191 191
 		return $twig;
192 192
 	}
193 193
 
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
 	 * @return array
199 199
 	 */
200 200
 	function to_array( $arr ) {
201
-		if ( is_array( $arr ) ) {
201
+		if ( is_array($arr) ) {
202 202
 			return $arr;
203 203
 		}
204
-		$arr = array( $arr );
204
+		$arr = array($arr);
205 205
 		return $arr;
206 206
 	}
207 207
 
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 	 */
214 214
 	function exec_function( $function_name ) {
215 215
 		$args = func_get_args();
216
-		array_shift( $args );
216
+		array_shift($args);
217 217
 		if ( is_string($function_name) ) {
218
-			$function_name = trim( $function_name );
218
+			$function_name = trim($function_name);
219 219
 		}
220
-		return call_user_func_array( $function_name, ( $args ) );
220
+		return call_user_func_array($function_name, ($args));
221 221
 	}
222 222
 
223 223
 	/**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * @return string
228 228
 	 */
229 229
 	function twig_pretags( $content ) {
230
-		return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content );
230
+		return preg_replace_callback('|<pre.*>(.*)</pre|isU', array(&$this, 'convert_pre_entities'), $content);
231 231
 	}
232 232
 
233 233
 	/**
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	 * @return string
238 238
 	 */
239 239
 	function convert_pre_entities( $matches ) {
240
-		return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] );
240
+		return str_replace($matches[1], htmlentities($matches[1]), $matches[0]);
241 241
 	}
242 242
 
243 243
 	/**
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 	 */
248 248
 	function body_class( $body_classes ) {
249 249
 		ob_start();
250
-		if ( is_array( $body_classes ) ) {
251
-			$body_classes = explode( ' ', $body_classes );
250
+		if ( is_array($body_classes) ) {
251
+			$body_classes = explode(' ', $body_classes);
252 252
 		}
253
-		body_class( $body_classes );
253
+		body_class($body_classes);
254 254
 		$return = ob_get_contents();
255 255
 		ob_end_clean();
256 256
 		return $return;
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 	 */
266 266
 	function intl_date( $date, $format = null ) {
267 267
 		if ( $format === null ) {
268
-			$format = get_option( 'date_format' );
268
+			$format = get_option('date_format');
269 269
 		}
270 270
 
271 271
 		if ( $date instanceof DateTime ) {
272 272
 			$timestamp = $date->getTimestamp() + $date->getOffset();
273
-		} else if (is_numeric( $date ) && strtotime( $date ) === false ) {
274
-			$timestamp = intval( $date );
273
+		} else if ( is_numeric($date) && strtotime($date) === false ) {
274
+			$timestamp = intval($date);
275 275
 		} else {
276
-			$timestamp = strtotime( $date );
276
+			$timestamp = strtotime($date);
277 277
 		}
278 278
 
279
-		return date_i18n( $format, $timestamp );
279
+		return date_i18n($format, $timestamp);
280 280
 	}
281 281
 
282 282
 	//debug
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
 	 * @return string
291 291
 	 */
292 292
 	function object_docs( $obj, $methods = true ) {
293
-		$class = get_class( $obj );
294
-		$properties = (array)$obj;
293
+		$class = get_class($obj);
294
+		$properties = (array) $obj;
295 295
 		if ( $methods ) {
296 296
 			/** @var array $methods */
297 297
 			$methods = $obj->get_method_values();
298 298
 		}
299
-		$rets = array_merge( $properties, $methods );
300
-		ksort( $rets );
301
-		$str = print_r( $rets, true );
302
-		$str = str_replace( 'Array', $class . ' Object', $str );
299
+		$rets = array_merge($properties, $methods);
300
+		ksort($rets);
301
+		$str = print_r($rets, true);
302
+		$str = str_replace('Array', $class . ' Object', $str);
303 303
 		return $str;
304 304
 	}
305 305
 
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
 	 */
313 313
 	function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) {
314 314
 		$to = $to === null ? time() : $to;
315
-		$to = is_int( $to ) ? $to : strtotime( $to );
316
-		$from = is_int( $from ) ? $from : strtotime( $from );
315
+		$to = is_int($to) ? $to : strtotime($to);
316
+		$from = is_int($from) ? $from : strtotime($from);
317 317
 
318 318
 		if ( $from < $to ) {
319
-			return sprintf( $format_past, human_time_diff( $from, $to ) );
319
+			return sprintf($format_past, human_time_diff($from, $to));
320 320
 		} else {
321
-			return sprintf( $format_future, human_time_diff( $to, $from ) );
321
+			return sprintf($format_future, human_time_diff($to, $from));
322 322
 		}
323 323
 	}
324 324
 
@@ -329,17 +329,17 @@  discard block
 block discarded – undo
329 329
 	 * @return string
330 330
 	 */
331 331
 	function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) {
332
-		$length = count( $arr );
332
+		$length = count($arr);
333 333
 		$list = '';
334
-		foreach( $arr as $index => $item ) {
334
+		foreach ( $arr as $index => $item ) {
335 335
 			if ( $index < $length - 2 ) {
336
-				$delimiter = $first_delimiter.' ';
336
+				$delimiter = $first_delimiter . ' ';
337 337
 			} elseif ( $index == $length - 2 ) {
338
-				$delimiter = ' '.$second_delimiter.' ';
338
+				$delimiter = ' ' . $second_delimiter . ' ';
339 339
 			} else {
340 340
 				$delimiter = '';
341 341
 			}
342
-			$list = $list.$item.$delimiter;
342
+			$list = $list . $item . $delimiter;
343 343
 		}
344 344
 		return $list;
345 345
 	}
Please login to merge, or discard this patch.
lib/timber-admin.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 class TimberAdmin {
4 4
 
5 5
     public static function init() {
6
-        return add_filter( 'plugin_row_meta', array( __CLASS__, 'meta_links' ), 10, 2 );
6
+        return add_filter('plugin_row_meta', array(__CLASS__, 'meta_links'), 10, 2);
7 7
     }
8 8
 
9 9
 	/**
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	 * @return array
13 13
 	 */
14 14
 	public static function meta_links( $links, $file ) {
15
-		if ( strstr( $file, '/timber.php' ) ) {
15
+		if ( strstr($file, '/timber.php') ) {
16 16
 			unset($links[2]);
17 17
 			$links[] = '<a href="/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=timber-library&amp;TB_iframe=true&amp;width=600&amp;height=550" class="thickbox" aria-label="More information about Timber" data-title="Timber">View details</a>';
18 18
 			$links[] = '<a href="http://upstatement.com/timber" target="_blank">Homepage</a>';
Please login to merge, or discard this patch.
lib/timber-image.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * ```
89 89
 	 * @param int|string $iid
90 90
 	 */
91
-	public function __construct($iid) {
91
+	public function __construct( $iid ) {
92 92
 		$this->init($iid);
93 93
 	}
94 94
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @param string $dim
116 116
 	 * @return array|int
117 117
 	 */
118
-	protected function get_dimensions($dim = null) {
118
+	protected function get_dimensions( $dim = null ) {
119 119
 		if ( isset($this->_dimensions) ) {
120 120
 			return $this->get_dimensions_loaded($dim);
121 121
 		}
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 * @param string|null $dim
134 134
 	 * @return array|int
135 135
 	 */
136
-	protected function get_dimensions_loaded($dim) {
136
+	protected function get_dimensions_loaded( $dim ) {
137 137
 		if ( $dim === null ) {
138 138
 			return $this->_dimensions;
139 139
 		}
@@ -152,25 +152,25 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	protected function get_image_info( $iid ) {
154 154
 		$image_info = $iid;
155
-		if (is_numeric($iid)) {
155
+		if ( is_numeric($iid) ) {
156 156
 			$image_info = wp_get_attachment_metadata($iid);
157
-			if (!is_array($image_info)) {
157
+			if ( !is_array($image_info) ) {
158 158
 				$image_info = array();
159 159
 			}
160 160
 			$image_custom = get_post_custom($iid);
161 161
 			$basic = get_post($iid);
162
-			if ($basic) {
163
-				if (isset($basic->post_excerpt)) {
162
+			if ( $basic ) {
163
+				if ( isset($basic->post_excerpt) ) {
164 164
 					$this->caption = $basic->post_excerpt;
165 165
 				}
166 166
 				$image_custom = array_merge($image_custom, get_object_vars($basic));
167 167
 			}
168 168
 			return array_merge($image_info, $image_custom);
169 169
 		}
170
-		if (is_array($image_info) && isset($image_info['image'])) {
170
+		if ( is_array($image_info) && isset($image_info['image']) ) {
171 171
 			return $image_info['image'];
172 172
 		}
173
-		if (is_object($image_info)) {
173
+		if ( is_object($image_info) ) {
174 174
 		   return get_object_vars($image_info);
175 175
 		}
176 176
 		return $iid;
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * @param  string $url for evaluation
182 182
 	 * @return string with http/https corrected depending on what's appropriate for server
183 183
 	 */
184
-	protected static function _maybe_secure_url($url) {
184
+	protected static function _maybe_secure_url( $url ) {
185 185
 		if ( is_ssl() && strpos($url, 'https') !== 0 && strpos($url, 'http') === 0 ) {
186 186
 			$url = 'https' . substr($url, strlen('http'));
187 187
 		}
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
 	 * @param int $iid
204 204
 	 */
205 205
 	function init( $iid = false ) {
206
-		if ( !is_numeric( $iid ) && is_string( $iid ) ) {
207
-			if (strstr($iid, '://')) {
206
+		if ( !is_numeric($iid) && is_string($iid) ) {
207
+			if ( strstr($iid, '://') ) {
208 208
 				$this->init_with_url($iid);
209 209
 				return;
210 210
 			}
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
 
216 216
 			$relative = false;
217 217
 			$iid_lower = strtolower($iid);
218
-			foreach( $this->file_types as $type ) { if( strstr( $iid_lower, $type ) ) { $relative = true; break; } };
218
+			foreach ( $this->file_types as $type ) { if ( strstr($iid_lower, $type) ) { $relative = true; break; } };
219 219
 			if ( $relative ) {
220
-				$this->init_with_relative_path( $iid );
220
+				$this->init_with_relative_path($iid);
221 221
 				return;
222 222
 			}
223 223
 		} else if ( $iid instanceof WP_Post ) {
224 224
 			$ref = new ReflectionClass($this);
225 225
 			$post = $ref->getParentClass()->newInstance($iid->ID);
226
-			if (isset($post->_thumbnail_id) && $post->_thumbnail_id) {
226
+			if ( isset($post->_thumbnail_id) && $post->_thumbnail_id ) {
227 227
 				return $this->init((int) $post->_thumbnail_id);
228 228
 			}
229 229
 			return $this->init($iid->ID);
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		}
255 255
 		if ( isset($this->ID) ) {
256 256
 			$custom = get_post_custom($this->ID);
257
-			foreach ($custom as $key => $value) {
257
+			foreach ( $custom as $key => $value ) {
258 258
 				$this->$key = $value[0];
259 259
 			}
260 260
 			$this->id = $this->ID;
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	 * @param string $relative_path
274 274
 	 */
275 275
 	protected function init_with_relative_path( $relative_path ) {
276
-		$this->abs_url = home_url( $relative_path );
277
-		$file_path = TimberURLHelper::get_full_path( $relative_path );
276
+		$this->abs_url = home_url($relative_path);
277
+		$file_path = TimberURLHelper::get_full_path($relative_path);
278 278
 		$this->file_loc = $file_path;
279 279
 		$this->file = $file_path;
280 280
 	}
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	 * @param string $file_path
285 285
 	 */
286 286
 	protected function init_with_file_path( $file_path ) {
287
-		$url = TimberURLHelper::file_system_to_url( $file_path );
287
+		$url = TimberURLHelper::file_system_to_url($file_path);
288 288
 		$this->abs_url = $url;
289 289
 		$this->file_loc = $file_path;
290 290
 		$this->file = $file_path;
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	 * @internal
295 295
 	 * @param string $url
296 296
 	 */
297
-	protected function init_with_url($url) {
297
+	protected function init_with_url( $url ) {
298 298
 		$this->abs_url = $url;
299 299
 		if ( TimberURLHelper::is_local($url) ) {
300 300
 			$this->file = ABSPATH . TimberURLHelper::get_rel_url($url);
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 	 * ```
410 410
 	 * @return bool|string
411 411
 	 */
412
-	public function src($size = '') {
412
+	public function src( $size = '' ) {
413 413
 		if ( isset($this->abs_url) ) {
414 414
 			return $this->_maybe_secure_url($this->abs_url);
415 415
 		}
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 	 * @return bool|string
485 485
 	 */
486 486
 	function get_src( $size = '' ) {
487
-		return $this->src( $size );
487
+		return $this->src($size);
488 488
 	}
489 489
 
490 490
 	/**
Please login to merge, or discard this patch.
lib/timber-archives.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 		$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
98 98
 		$key = md5($query);
99 99
 		$key = "wp_get_archives:$key:$last_changed";
100
-		if (!$results = wp_cache_get($key, 'posts')) {
100
+		if ( !$results = wp_cache_get($key, 'posts') ) {
101 101
 			$results = $wpdb->get_results($query);
102 102
 			wp_cache_set($key, $results, 'posts');
103 103
 		}
104
-		if ($results) {
105
-			foreach ( (array)$results as $result ) {
106
-				$url = get_year_link( $result->year );
104
+		if ( $results ) {
105
+			foreach ( (array) $results as $result ) {
106
+				$url = get_year_link($result->year);
107 107
 				$text = sprintf('%d', $result->year);
108 108
 				$output[] = $this->get_archives_link($url, $text);
109 109
 			}
@@ -137,28 +137,28 @@  discard block
 block discarded – undo
137 137
 			. "ORDER BY post_date $order $limit";
138 138
 		$key = md5($query);
139 139
 		$key = "wp_get_archives:$key:$last_changed";
140
-		if (!$results = wp_cache_get($key, 'posts')) {
140
+		if ( !$results = wp_cache_get($key, 'posts') ) {
141 141
 			$results = $wpdb->get_results($query);
142 142
 			wp_cache_set($key, $results, 'posts');
143 143
 		}
144
-		if ($results) {
145
-			foreach ((array)$results as $result) {
144
+		if ( $results ) {
145
+			foreach ( (array) $results as $result ) {
146 146
 				$url = get_month_link($result->year, $result->month);
147
-				if ($show_year && !$nested) {
147
+				if ( $show_year && !$nested ) {
148 148
 					$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
149 149
 				} else {
150 150
 					$text = sprintf(__('%1$s'), $wp_locale->get_month($result->month));
151 151
 				}
152
-				if ($nested) {
152
+				if ( $nested ) {
153 153
 					$output[$result->year][] = $this->get_archives_link($url, $text);
154 154
 				} else {
155 155
 					$output[] = $this->get_archives_link($url, $text);
156 156
 				}
157 157
 			}
158 158
 		}
159
-		if ($nested) {
159
+		if ( $nested ) {
160 160
 			$out2 = array();
161
-			foreach ($output as $year => $months) {
161
+			foreach ( $output as $year => $months ) {
162 162
 				$out2[] = array('name' => $year, 'children' => $months);
163 163
 			}
164 164
 			return $out2;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		$archive_week_start_date_format = 'Y/m/d';
221 221
 		$archive_week_end_date_format = 'Y/m/d';
222 222
 
223
-		if (!$archive_date_format_over_ride) {
223
+		if ( !$archive_date_format_over_ride ) {
224 224
 			$archive_day_date_format = get_option('date_format');
225 225
 			$archive_week_start_date_format = get_option('date_format');
226 226
 			$archive_week_end_date_format = get_option('date_format');
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 
233 233
 		$output = array();
234 234
 		$last_changed = wp_cache_get('last_changed', 'posts');
235
-		if (!$last_changed) {
235
+		if ( !$last_changed ) {
236 236
 			$last_changed = microtime();
237 237
 			wp_cache_set('last_changed', $last_changed, 'posts');
238 238
 		}
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 246
 			$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
247 247
 			$key = md5($query);
248 248
 			$key = "wp_get_archives:$key:$last_changed";
249
-			if (!$results = wp_cache_get($key, 'posts')) {
249
+			if ( !$results = wp_cache_get($key, 'posts') ) {
250 250
 				$results = $wpdb->get_results($query);
251 251
 				$cache = array();
252 252
 				$cache[$key] = $results;
253 253
 				wp_cache_set($key, $results, 'posts');
254 254
 			}
255 255
 			if ( $results ) {
256
-				foreach ( (array)$results as $result ) {
256
+				foreach ( (array) $results as $result ) {
257 257
 					$url = get_day_link($result->year, $result->month, $result->dayofmonth);
258 258
 					$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
259 259
 					$text = mysql2date($archive_day_date_format, $date);
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
 				. "count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
267 267
 			$key = md5($query);
268 268
 			$key = "wp_get_archives:$key:$last_changed";
269
-			if (!$results = wp_cache_get($key, 'posts')) {
269
+			if ( !$results = wp_cache_get($key, 'posts') ) {
270 270
 				$results = $wpdb->get_results($query);
271 271
 				wp_cache_set($key, $results, 'posts');
272 272
 			}
273 273
 			$arc_w_last = '';
274 274
 			if ( $results ) {
275
-				foreach ( (array)$results as $result ) {
275
+				foreach ( (array) $results as $result ) {
276 276
 					if ( $result->week != $arc_w_last ) {
277 277
 						$arc_year = $result->yr;
278 278
 						$arc_w_last = $result->week;
@@ -295,10 +295,10 @@  discard block
 block discarded – undo
295 295
 				wp_cache_set($key, $results, 'posts');
296 296
 			}
297 297
 			if ( $results ) {
298
-				foreach ( (array)$results as $result ) {
299
-					if ($result->post_date != '0000-00-00 00:00:00') {
298
+				foreach ( (array) $results as $result ) {
299
+					if ( $result->post_date != '0000-00-00 00:00:00' ) {
300 300
 						$url = get_permalink($result);
301
-						if ($result->post_title) {
301
+						if ( $result->post_title ) {
302 302
 							/** This filter is documented in wp-includes/post-template.php */
303 303
 							$text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID));
304 304
 						} else {
Please login to merge, or discard this patch.
lib/integrations/acf-timber.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@  discard block
 block discarded – undo
3 3
 class ACFTimber {
4 4
 
5 5
     function __construct() {
6
-        add_filter( 'timber_post_get_meta', array( $this, 'post_get_meta' ), 10, 2 );
7
-        add_filter( 'timber_post_get_meta_field', array( $this, 'post_get_meta_field' ), 10, 3 );
8
-        add_filter( 'timber_term_get_meta', array( $this, 'term_get_meta' ), 10, 3 );
9
-        add_filter( 'timber_term_get_meta_field', array( $this, 'term_get_meta_field' ), 10, 4 );
10
-        add_filter( 'timber_user_get_meta_field_pre', array( $this, 'user_get_meta_field' ), 10, 3 );
11
-        add_filter( 'timber_term_set_meta', array( $this, 'term_set_meta'), 10, 4 );
6
+        add_filter('timber_post_get_meta', array($this, 'post_get_meta'), 10, 2);
7
+        add_filter('timber_post_get_meta_field', array($this, 'post_get_meta_field'), 10, 3);
8
+        add_filter('timber_term_get_meta', array($this, 'term_get_meta'), 10, 3);
9
+        add_filter('timber_term_get_meta_field', array($this, 'term_get_meta_field'), 10, 4);
10
+        add_filter('timber_user_get_meta_field_pre', array($this, 'user_get_meta_field'), 10, 3);
11
+        add_filter('timber_term_set_meta', array($this, 'term_set_meta'), 10, 4);
12 12
     }
13 13
 
14 14
     function post_get_meta( $customs, $post_id ) {
@@ -16,32 +16,32 @@  discard block
 block discarded – undo
16 16
     }
17 17
 
18 18
     function post_get_meta_field( $value, $post_id, $field_name ) {
19
-        return get_field( $field_name, $post_id );
19
+        return get_field($field_name, $post_id);
20 20
     }
21 21
 
22 22
     function term_get_meta_field( $value, $term_id, $field_name, $term ) {
23 23
         $searcher = $term->taxonomy . "_" . $term->ID;
24
-        return get_field( $field_name, $searcher );
24
+        return get_field($field_name, $searcher);
25 25
     }
26 26
 
27 27
     function term_set_meta( $value, $field, $term_id, $term ) {
28 28
         $searcher = $term->taxonomy . "_" . $term->ID;
29
-        update_field( $field, $value, $searcher );
29
+        update_field($field, $value, $searcher);
30 30
         return $value;
31 31
     }
32 32
 
33 33
     function term_get_meta( $fields, $term_id, $term ) {
34 34
         $searcher = $term->taxonomy . "_" . $term->ID; // save to a specific category
35
-        $fds = get_fields( $searcher );
36
-        if ( is_array( $fds ) ) {
35
+        $fds = get_fields($searcher);
36
+        if ( is_array($fds) ) {
37 37
             foreach ( $fds as $key => $value ) {
38
-                $key = preg_replace( '/_/', '', $key, 1 );
39
-                $key = str_replace( $searcher, '', $key );
40
-                $key = preg_replace( '/_/', '', $key, 1 );
41
-                $field = get_field( $key, $searcher );
38
+                $key = preg_replace('/_/', '', $key, 1);
39
+                $key = str_replace($searcher, '', $key);
40
+                $key = preg_replace('/_/', '', $key, 1);
41
+                $field = get_field($key, $searcher);
42 42
                 $fields[$key] = $field;
43 43
             }
44
-            $fields = array_merge( $fields, $fds );
44
+            $fields = array_merge($fields, $fds);
45 45
         }
46 46
         return $fields;
47 47
     }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     }
52 52
 
53 53
     function user_get_meta_field( $value, $uid, $field ) {
54
-        return get_field( $field, 'user_' . $uid );
54
+        return get_field($field, 'user_' . $uid);
55 55
     }
56 56
 }
57 57
 
Please login to merge, or discard this patch.
lib/integrations/wpcli-timber.php 1 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/integrations/timber-command.php 1 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.