Completed
Pull Request — master (#783)
by Jared
03:14
created
timber.php 1 patch
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
 // we look for Composer files first in the plugins dir.
15 15
 // then in the wp-content dir (site install).
16 16
 // and finally in the current themes directories.
17
-if (   file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* check in self */
18
-	|| file_exists( $composer_autoload = WP_CONTENT_DIR.'/vendor/autoload.php') /* check in wp-content */
19
-	|| file_exists( $composer_autoload = plugin_dir_path( __FILE__ ).'vendor/autoload.php') /* check in plugin directory */
20
-	|| file_exists( $composer_autoload = get_stylesheet_directory().'/vendor/autoload.php') /* check in child theme */
21
-	|| file_exists( $composer_autoload = get_template_directory().'/vendor/autoload.php') /* check in parent theme */
17
+if ( file_exists($composer_autoload = __DIR__ . '/vendor/autoload.php') /* check in self */
18
+	|| file_exists($composer_autoload = WP_CONTENT_DIR . '/vendor/autoload.php') /* check in wp-content */
19
+	|| file_exists($composer_autoload = plugin_dir_path(__FILE__) . 'vendor/autoload.php') /* check in plugin directory */
20
+	|| file_exists($composer_autoload = get_stylesheet_directory() . '/vendor/autoload.php') /* check in child theme */
21
+	|| file_exists($composer_autoload = get_template_directory() . '/vendor/autoload.php') /* check in parent theme */
22 22
 	) {
23 23
 	require_once $composer_autoload;
24 24
 }
@@ -71,16 +71,16 @@  discard block
 block discarded – undo
71 71
 		if ( is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php' ) {
72 72
 			return;
73 73
 		}
74
-		if ( version_compare( phpversion(), '5.3.0', '<' ) && !is_admin() ) {
75
-			trigger_error( 'Timber requires PHP 5.3.0 or greater. You have '.phpversion(), E_USER_ERROR );
74
+		if ( version_compare(phpversion(), '5.3.0', '<') && !is_admin() ) {
75
+			trigger_error('Timber requires PHP 5.3.0 or greater. You have ' . phpversion(), E_USER_ERROR);
76 76
 		}
77
-		if ( !class_exists( 'Twig_Autoloader' ) ) {
78
-			trigger_error( 'You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR );
77
+		if ( !class_exists('Twig_Autoloader') ) {
78
+			trigger_error('You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR);
79 79
 		}
80 80
 	}
81 81
 
82 82
 	function init_constants() {
83
-		defined( "TIMBER_LOC" ) or define( "TIMBER_LOC", realpath( __DIR__ ) );
83
+		defined("TIMBER_LOC") or define("TIMBER_LOC", realpath(__DIR__));
84 84
 	}
85 85
 
86 86
 	/**
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	protected function init() {
90 90
 		TimberTwig::init();
91
-		TimberRoutes::init( $this );
91
+		TimberRoutes::init($this);
92 92
 		TimberImageHelper::init();
93 93
 		TimberAdmin::init();
94 94
 		TimberIntegrations::init();
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 * @param string  $PostClass
105 105
 	 * @return array|bool|null
106 106
 	 */
107
-	public static function get_post( $query = false, $PostClass = 'TimberPost' ) {
108
-		return TimberPostGetter::get_post( $query, $PostClass );
107
+	public static function get_post($query = false, $PostClass = 'TimberPost') {
108
+		return TimberPostGetter::get_post($query, $PostClass);
109 109
 	}
110 110
 
111 111
 	/**
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	 * @param string  $PostClass
116 116
 	 * @return array|bool|null
117 117
 	 */
118
-	public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
119
-		return TimberPostGetter::get_posts( $query, $PostClass, $return_collection );
118
+	public static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) {
119
+		return TimberPostGetter::get_posts($query, $PostClass, $return_collection);
120 120
 	}
121 121
 
122 122
 	/**
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 	 * @param string  $PostClass
127 127
 	 * @return array|bool|null
128 128
 	 */
129
-	public static function query_post( $query = false, $PostClass = 'TimberPost' ) {
130
-		return TimberPostGetter::query_post( $query, $PostClass );
129
+	public static function query_post($query = false, $PostClass = 'TimberPost') {
130
+		return TimberPostGetter::query_post($query, $PostClass);
131 131
 	}
132 132
 
133 133
 	/**
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 	 * @param string  $PostClass
138 138
 	 * @return array|bool|null
139 139
 	 */
140
-	public static function query_posts( $query = false, $PostClass = 'TimberPost' ) {
141
-		return TimberPostGetter::query_posts( $query, $PostClass );
140
+	public static function query_posts($query = false, $PostClass = 'TimberPost') {
141
+		return TimberPostGetter::query_posts($query, $PostClass);
142 142
 	}
143 143
 
144 144
 	/**
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 	 * @return array
149 149
 	 * @deprecated since 0.20.0
150 150
 	 */
151
-	static function get_pids( $query = null ) {
152
-		return TimberPostGetter::get_pids( $query );
151
+	static function get_pids($query = null) {
152
+		return TimberPostGetter::get_pids($query);
153 153
 	}
154 154
 
155 155
 	/**
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
 	 * @return array
160 160
 	 * @deprecated since 0.20.0
161 161
 	 */
162
-	static function get_posts_from_loop( $PostClass ) {
163
-		return TimberPostGetter::get_posts( $PostClass );
162
+	static function get_posts_from_loop($PostClass) {
163
+		return TimberPostGetter::get_posts($PostClass);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
 	 * @return array
172 172
 	 * @deprecated since 0.20.0
173 173
 	 */
174
-	static function get_posts_from_slug( $slug, $PostClass = 'TimberPost' ) {
175
-		return TimberPostGetter::get_posts( $slug, $PostClass );
174
+	static function get_posts_from_slug($slug, $PostClass = 'TimberPost') {
175
+		return TimberPostGetter::get_posts($slug, $PostClass);
176 176
 	}
177 177
 
178 178
 	/**
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 	 * @return array
184 184
 	 * @deprecated since 0.20.0
185 185
 	 */
186
-	static function get_posts_from_wp_query( $query = array(), $PostClass = 'TimberPost' ) {
187
-		return TimberPostGetter::query_posts( $query, $PostClass );
186
+	static function get_posts_from_wp_query($query = array(), $PostClass = 'TimberPost') {
187
+		return TimberPostGetter::query_posts($query, $PostClass);
188 188
 	}
189 189
 
190 190
 	/**
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 * @return array|null
196 196
 	 * @deprecated since 0.20.0
197 197
 	 */
198
-	static function get_posts_from_array_of_ids( $query = array(), $PostClass = 'TimberPost' ) {
199
-		return TimberPostGetter::get_posts( $query, $PostClass );
198
+	static function get_posts_from_array_of_ids($query = array(), $PostClass = 'TimberPost') {
199
+		return TimberPostGetter::get_posts($query, $PostClass);
200 200
 	}
201 201
 
202 202
 	/**
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 	 * @return int
207 207
 	 * @deprecated since 0.20.0
208 208
 	 */
209
-	static function get_pid( $query ) {
210
-		$pids = TimberPostGetter::get_pids( $query );
211
-		if ( is_array( $pids ) && count( $pids ) ) {
209
+	static function get_pid($query) {
210
+		$pids = TimberPostGetter::get_pids($query);
211
+		if ( is_array($pids) && count($pids) ) {
212 212
 			return $pids[0];
213 213
 		}
214 214
 	}
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 	 * @param string  $TermClass
235 235
 	 * @return mixed
236 236
 	 */
237
-	public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) {
238
-		return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass );
237
+	public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') {
238
+		return TimberTermGetter::get_terms($args, $maybe_args, $TermClass);
239 239
 	}
240 240
 
241 241
 	/* Site Retrieval
@@ -247,14 +247,14 @@  discard block
 block discarded – undo
247 247
 	 * @param array|bool $blog_ids
248 248
 	 * @return array
249 249
 	 */
250
-	public static function get_sites( $blog_ids = false ) {
251
-		if ( !is_array( $blog_ids ) ) {
250
+	public static function get_sites($blog_ids = false) {
251
+		if ( !is_array($blog_ids) ) {
252 252
 			global $wpdb;
253
-			$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" );
253
+			$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC");
254 254
 		}
255 255
 		$return = array();
256
-		foreach ( $blog_ids as $blog_id ) {
257
-			$return[] = new TimberSite( $blog_id );
256
+		foreach ($blog_ids as $blog_id) {
257
+			$return[] = new TimberSite($blog_id);
258 258
 		}
259 259
 		return $return;
260 260
 	}
@@ -272,29 +272,29 @@  discard block
 block discarded – undo
272 272
 		$data = array();
273 273
 		$data['http_host'] = 'http://' . TimberURLHelper::get_host();
274 274
 		$data['wp_title'] = TimberHelper::get_wp_title();
275
-		$data['wp_head'] = TimberHelper::function_wrapper( 'wp_head' );
276
-		$data['wp_footer'] = TimberHelper::function_wrapper( 'wp_footer' );
277
-		$data['body_class'] = implode( ' ', get_body_class() );
275
+		$data['wp_head'] = TimberHelper::function_wrapper('wp_head');
276
+		$data['wp_footer'] = TimberHelper::function_wrapper('wp_footer');
277
+		$data['body_class'] = implode(' ', get_body_class());
278 278
 
279 279
 		$data['site'] = new TimberSite();
280 280
 		$data['theme'] = $data['site']->theme;
281 281
 		//deprecated, these should be fetched via TimberSite or TimberTheme
282
-		$data['theme_dir'] = WP_CONTENT_SUBDIR.str_replace( WP_CONTENT_DIR, '', get_stylesheet_directory() );
283
-		$data['language_attributes'] = TimberHelper::function_wrapper( 'language_attributes' );
282
+		$data['theme_dir'] = WP_CONTENT_SUBDIR . str_replace(WP_CONTENT_DIR, '', get_stylesheet_directory());
283
+		$data['language_attributes'] = TimberHelper::function_wrapper('language_attributes');
284 284
 		$data['stylesheet_uri'] = get_stylesheet_uri();
285 285
 		$data['template_uri'] = get_template_directory_uri();
286 286
 
287 287
 		$data['posts'] = Timber::query_posts();
288 288
 
289 289
 		//deprecated, this should be fetched via TimberMenu
290
-		if ( function_exists( 'wp_nav_menu' ) ) {
290
+		if ( function_exists('wp_nav_menu') ) {
291 291
 			$locations = get_nav_menu_locations();
292
-			if ( count( $locations ) ) {
293
-				$data['wp_nav_menu'] = wp_nav_menu( array( 'container_class' => 'menu-header', 'echo' => false, 'menu_class' => 'nav-menu' ) );
292
+			if ( count($locations) ) {
293
+				$data['wp_nav_menu'] = wp_nav_menu(array('container_class' => 'menu-header', 'echo' => false, 'menu_class' => 'nav-menu'));
294 294
 			}
295 295
 		}
296
-		$data = apply_filters( 'timber_context', $data );
297
-		$data = apply_filters( 'timber/context', $data );
296
+		$data = apply_filters('timber_context', $data);
297
+		$data = apply_filters('timber/context', $data);
298 298
 		return $data;
299 299
 	}
300 300
 
@@ -308,27 +308,27 @@  discard block
 block discarded – undo
308 308
 	 * @param bool    $via_render
309 309
 	 * @return bool|string
310 310
 	 */
311
-	public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) {
311
+	public static function compile($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false) {
312 312
 		$caller = self::get_calling_script_dir();
313 313
 		$caller_file = self::get_calling_script_file();
314
-		$caller_file = apply_filters( 'timber_calling_php_file', $caller_file );
315
-		$loader = new TimberLoader( $caller );
316
-		$file = $loader->choose_template( $filenames );
314
+		$caller_file = apply_filters('timber_calling_php_file', $caller_file);
315
+		$loader = new TimberLoader($caller);
316
+		$file = $loader->choose_template($filenames);
317 317
 		$output = '';
318
-		if ( is_null( $data ) ) {
318
+		if ( is_null($data) ) {
319 319
 			$data = array();
320 320
 		}
321
-		if ( strlen( $file ) ) {
321
+		if ( strlen($file) ) {
322 322
 			if ( $via_render ) {
323
-				$file = apply_filters( 'timber_render_file', $file );
324
-				$data = apply_filters( 'timber_render_data', $data );
323
+				$file = apply_filters('timber_render_file', $file);
324
+				$data = apply_filters('timber_render_data', $data);
325 325
 			} else {
326
-				$file = apply_filters( 'timber_compile_file', $file );
327
-				$data = apply_filters( 'timber_compile_data', $data );
326
+				$file = apply_filters('timber_compile_file', $file);
327
+				$data = apply_filters('timber_compile_data', $data);
328 328
 			}
329
-			$output = $loader->render( $file, $data, $expires, $cache_mode );
329
+			$output = $loader->render($file, $data, $expires, $cache_mode);
330 330
 		}
331
-		do_action( 'timber_compile_done' );
331
+		do_action('timber_compile_done');
332 332
 		return $output;
333 333
 	}
334 334
 
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
 	 * @param array   $data   an array with data in it.
340 340
 	 * @return  bool|string
341 341
 	 */
342
-	public static function compile_string( $string, $data = array() ) {
342
+	public static function compile_string($string, $data = array()) {
343 343
 		$dummy_loader = new TimberLoader();
344 344
 		$dummy_loader->get_twig();
345 345
 		$loader = new Twig_Loader_String();
346
-		$twig = new Twig_Environment( $loader );
347
-		$twig = apply_filters( 'timber/twig/filters', $twig );
348
-		$twig = apply_filters( 'twig_apply_filters', $twig );
349
-		return $twig->render( $string, $data );
346
+		$twig = new Twig_Environment($loader);
347
+		$twig = apply_filters('timber/twig/filters', $twig);
348
+		$twig = apply_filters('twig_apply_filters', $twig);
349
+		return $twig->render($string, $data);
350 350
 	}
351 351
 
352 352
 	/**
@@ -358,15 +358,15 @@  discard block
 block discarded – undo
358 358
 	 * @param string  $cache_mode
359 359
 	 * @return bool|string
360 360
 	 */
361
-	public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) {
361
+	public static function fetch($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) {
362 362
 		if ( $expires === true ) {
363 363
 			//if this is reading as true; the user probably is using the old $echo param
364 364
 			//so we should move all vars up by a spot
365 365
 			$expires = $cache_mode;
366 366
 			$cache_mode = TimberLoader::CACHE_USE_DEFAULT;
367 367
 		}
368
-		$output = self::compile( $filenames, $data, $expires, $cache_mode, true );
369
-		$output = apply_filters( 'timber_compile_result', $output );
368
+		$output = self::compile($filenames, $data, $expires, $cache_mode, true);
369
+		$output = apply_filters('timber_compile_result', $output);
370 370
 		return $output;
371 371
 	}
372 372
 
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 	 * @param string  $cache_mode
380 380
 	 * @return bool|string
381 381
 	 */
382
-	public static function render( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) {
383
-		$output = static::fetch( $filenames, $data, $expires, $cache_mode );
382
+	public static function render($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) {
383
+		$output = static::fetch($filenames, $data, $expires, $cache_mode);
384 384
 		echo $output;
385 385
 		return $output;
386 386
 	}
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
 	 * @param array   $data   an array with data in it.
393 393
 	 * @return  bool|string
394 394
 	 */
395
-	public static function render_string( $string, $data = array() ) {
396
-		$compiled = self::compile_string( $string, $data );
395
+	public static function render_string($string, $data = array()) {
396
+		$compiled = self::compile_string($string, $data);
397 397
 		echo $compiled;
398 398
 		return $compiled;
399 399
 	}
@@ -409,14 +409,14 @@  discard block
 block discarded – undo
409 409
 	 * @param array   $data
410 410
 	 * @return bool|string
411 411
 	 */
412
-	public static function get_sidebar( $sidebar = '', $data = array() ) {
412
+	public static function get_sidebar($sidebar = '', $data = array()) {
413 413
 		if ( $sidebar == '' ) {
414 414
 			$sidebar = 'sidebar.php';
415 415
 		}
416
-		if ( strstr( strtolower( $sidebar ), '.php' ) ) {
417
-			return self::get_sidebar_from_php( $sidebar, $data );
416
+		if ( strstr(strtolower($sidebar), '.php') ) {
417
+			return self::get_sidebar_from_php($sidebar, $data);
418 418
 		}
419
-		return self::compile( $sidebar, $data );
419
+		return self::compile($sidebar, $data);
420 420
 	}
421 421
 
422 422
 	/**
@@ -426,21 +426,21 @@  discard block
 block discarded – undo
426 426
 	 * @param array   $data
427 427
 	 * @return string
428 428
 	 */
429
-	public static function get_sidebar_from_php( $sidebar = '', $data ) {
429
+	public static function get_sidebar_from_php($sidebar = '', $data) {
430 430
 		$caller = self::get_calling_script_dir();
431 431
 		$loader = new TimberLoader();
432
-		$uris = $loader->get_locations( $caller );
432
+		$uris = $loader->get_locations($caller);
433 433
 		ob_start();
434 434
 		$found = false;
435
-		foreach ( $uris as $uri ) {
436
-			if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) {
437
-				include trailingslashit( $uri ) . $sidebar;
435
+		foreach ($uris as $uri) {
436
+			if ( file_exists(trailingslashit($uri) . $sidebar) ) {
437
+				include trailingslashit($uri) . $sidebar;
438 438
 				$found = true;
439 439
 				break;
440 440
 			}
441 441
 		}
442 442
 		if ( !$found ) {
443
-			TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' );
443
+			TimberHelper::error_log('error loading your sidebar, check to make sure the file exists');
444 444
 		}
445 445
 		$ret = ob_get_contents();
446 446
 		ob_end_clean();
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	 * @param int     $widget_id
457 457
 	 * @return TimberFunctionWrapper
458 458
 	 */
459
-	public static function get_widgets( $widget_id ) {
460
-		return TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true );
459
+	public static function get_widgets($widget_id) {
460
+		return TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true);
461 461
 	}
462 462
 
463 463
 
@@ -472,15 +472,15 @@  discard block
 block discarded – undo
472 472
 	 * @param array   $args
473 473
 	 * @deprecated since 0.20.0
474 474
 	 */
475
-	public static function add_route( $route, $callback, $args = array() ) {
476
-		Routes::map( $route, $callback, $args );
475
+	public static function add_route($route, $callback, $args = array()) {
476
+		Routes::map($route, $callback, $args);
477 477
 	}
478 478
 
479 479
 	/**
480 480
 	 * @deprecated since 0.22.2
481 481
 	 */
482 482
 	public function cancel_query() {
483
-		add_action( 'posts_request', array( $this, 'cancel_query_posts_request' ) );
483
+		add_action('posts_request', array($this, 'cancel_query_posts_request'));
484 484
 	}
485 485
 
486 486
 	/**
@@ -497,8 +497,8 @@  discard block
 block discarded – undo
497 497
 	 *
498 498
 	 * @deprecated since 0.20.0
499 499
 	 */
500
-	public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
501
-		return Routes::load( $template, $tparams, $query, $status_code );
500
+	public static function load_template($template, $query = false, $status_code = 200, $tparams = false) {
501
+		return Routes::load($template, $tparams, $query, $status_code);
502 502
 	}
503 503
 
504 504
 	/**
@@ -506,8 +506,8 @@  discard block
 block discarded – undo
506 506
 	 *
507 507
 	 * @deprecated since 0.20.2
508 508
 	 */
509
-	public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
510
-		return Routes::load( $template, $tparams, $query, $status_code );
509
+	public static function load_view($template, $query = false, $status_code = 200, $tparams = false) {
510
+		return Routes::load($template, $tparams, $query, $status_code);
511 511
 	}
512 512
 
513 513
 
@@ -520,43 +520,43 @@  discard block
 block discarded – undo
520 520
 	 * @param array   $prefs
521 521
 	 * @return array mixed
522 522
 	 */
523
-	public static function get_pagination( $prefs = array() ) {
523
+	public static function get_pagination($prefs = array()) {
524 524
 		global $wp_query;
525 525
 		global $paged;
526 526
 		global $wp_rewrite;
527 527
 		$args = array();
528
-		$args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] );
528
+		$args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
529 529
 		if ( $wp_rewrite->using_permalinks() ) {
530
-			$url = explode( '?', get_pagenum_link( 0 ) );
531
-			if ( isset( $url[1] ) ) {
532
-				parse_str( $url[1], $query );
530
+			$url = explode('?', get_pagenum_link(0));
531
+			if ( isset($url[1]) ) {
532
+				parse_str($url[1], $query);
533 533
 				$args['add_args'] = $query;
534 534
 			}
535 535
 			$args['format'] = 'page/%#%';
536
-			$args['base'] = trailingslashit( $url[0] ).'%_%';
536
+			$args['base'] = trailingslashit($url[0]) . '%_%';
537 537
 		} else {
538 538
 			$big = 999999999;
539
-			$args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) );
539
+			$args['base'] = str_replace($big, '%#%', esc_url(get_pagenum_link($big)));
540 540
 		}
541 541
 		$args['type'] = 'array';
542
-		$args['current'] = max( 1, get_query_var( 'paged' ) );
543
-		$args['mid_size'] = max( 9 - $args['current'], 3 );
544
-		if ( is_int( $prefs ) ) {
542
+		$args['current'] = max(1, get_query_var('paged'));
543
+		$args['mid_size'] = max(9 - $args['current'], 3);
544
+		if ( is_int($prefs) ) {
545 545
 			$args['mid_size'] = $prefs - 2;
546 546
 		} else {
547
-			$args = array_merge( $args, $prefs );
547
+			$args = array_merge($args, $prefs);
548 548
 		}
549 549
 		$data = array();
550 550
 		$data['current'] = $args['current'];
551 551
 		$data['total'] = $args['total'];
552
-		$data['pages'] = TimberHelper::paginate_links( $args );
553
-		$next = get_next_posts_page_link( $args['total'] );
552
+		$data['pages'] = TimberHelper::paginate_links($args);
553
+		$next = get_next_posts_page_link($args['total']);
554 554
 		if ( $next ) {
555
-			$data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' );
555
+			$data['next'] = array('link' => untrailingslashit($next), 'class' => 'page-numbers next');
556 556
 		}
557
-		$prev = previous_posts( false );
557
+		$prev = previous_posts(false);
558 558
 		if ( $prev ) {
559
-			$data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' );
559
+			$data['prev'] = array('link' => untrailingslashit($prev), 'class' => 'page-numbers prev');
560 560
 		}
561 561
 		if ( $paged < 2 ) {
562 562
 			$data['prev'] = '';
@@ -574,9 +574,9 @@  discard block
 block discarded – undo
574 574
 	 * @return string
575 575
 	 * @deprecated since 0.20.0
576 576
 	 */
577
-	public static function get_calling_script_path( $offset = 0 ) {
578
-		$dir = self::get_calling_script_dir( $offset );
579
-		return str_replace( ABSPATH, '', realpath( $dir ) );
577
+	public static function get_calling_script_path($offset = 0) {
578
+		$dir = self::get_calling_script_dir($offset);
579
+		return str_replace(ABSPATH, '', realpath($dir));
580 580
 	}
581 581
 
582 582
 	/**
@@ -584,10 +584,10 @@  discard block
 block discarded – undo
584 584
 	 *
585 585
 	 * @return string
586 586
 	 */
587
-	public static function get_calling_script_dir( $offset = 0 ) {
588
-		$caller = self::get_calling_script_file( $offset );
589
-		if ( !is_null( $caller ) ) {
590
-			$pathinfo = pathinfo( $caller );
587
+	public static function get_calling_script_dir($offset = 0) {
588
+		$caller = self::get_calling_script_file($offset);
589
+		if ( !is_null($caller) ) {
590
+			$pathinfo = pathinfo($caller);
591 591
 			$dir = $pathinfo['dirname'];
592 592
 			return $dir;
593 593
 		}
@@ -600,11 +600,11 @@  discard block
 block discarded – undo
600 600
 	 * @return string|null
601 601
 	 * @deprecated since 0.20.0
602 602
 	 */
603
-	public static function get_calling_script_file( $offset = 0 ) {
603
+	public static function get_calling_script_file($offset = 0) {
604 604
 		$caller = null;
605 605
 		$backtrace = debug_backtrace();
606 606
 		$i = 0;
607
-		foreach ( $backtrace as $trace ) {
607
+		foreach ($backtrace as $trace) {
608 608
 			if ( $trace['file'] != __FILE__ ) {
609 609
 				$caller = $trace['file'];
610 610
 				break;
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
 	 * @return bool
625 625
 	 * @deprecated since 0.20.0
626 626
 	 */
627
-	public static function is_post_class_or_class_map( $args ) {
628
-		return TimberPostGetter::is_post_class_or_class_map( $args );
627
+	public static function is_post_class_or_class_map($args) {
628
+		return TimberPostGetter::is_post_class_or_class_map($args);
629 629
 	}
630 630
 
631 631
 }
Please login to merge, or discard this patch.
lib/timber-post.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @param mixed $pid
169 169
 	 */
170 170
 	public function __construct($pid = null) {
171
-		$pid = $this->determine_id( $pid );
171
+		$pid = $this->determine_id($pid);
172 172
 		$this->init($pid);
173 173
 	}
174 174
 
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
 			&& get_class($wp_query->queried_object) == 'WP_Post'
189 189
 			) {
190 190
 			$pid = $wp_query->queried_object_id;
191
-		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id )  {
191
+		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) {
192 192
 			//hack for static page as home page
193 193
 			$pid = $wp_query->queried_object_id;
194 194
 		} else if ( $pid === null ) {
195 195
 			$gtid = false;
196 196
 			$maybe_post = get_post();
197
-			if ( isset($maybe_post->ID) ){
197
+			if ( isset($maybe_post->ID) ) {
198 198
 				$gtid = true;
199 199
 			}
200 200
 			if ( $gtid ) {
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * @param string $field
261 261
 	 * @param mixed $value
262 262
 	 */
263
-	public function update( $field, $value ) {
263
+	public function update($field, $value) {
264 264
 		if ( isset($this->ID) ) {
265 265
 			update_post_meta($this->ID, $field, $value);
266 266
 			$this->$field = $value;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 * @param mixed $pid
276 276
 	 * @return WP_Post on success
277 277
 	 */
278
-	protected function prepare_post_info( $pid = 0 ) {
278
+	protected function prepare_post_info($pid = 0) {
279 279
 		if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) {
280 280
 			$pid = self::check_post_id($pid);
281 281
 			$post = get_post($pid);
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 	 * @internal
298 298
 	 * @return integer ID number of a post
299 299
 	 */
300
-	protected function check_post_id( $pid ) {
300
+	protected function check_post_id($pid) {
301 301
 		if ( is_numeric($pid) && $pid === 0 ) {
302 302
 			$pid = get_the_ID();
303 303
 			return $pid;
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 		global $wpdb;
324 324
 		$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
325 325
 		$result = $wpdb->get_row($query);
326
-		if (!$result) {
326
+		if ( !$result ) {
327 327
 			return null;
328 328
 		}
329 329
 		return $result->ID;
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 				$text = TimberHelper::trim_words($text, $len, false);
363 363
 				$trimmed = true;
364 364
 			}
365
-			$text = do_shortcode( $text );
365
+			$text = do_shortcode($text);
366 366
 		}
367 367
 		if ( !strlen($text) ) {
368 368
 			$text = TimberHelper::trim_words($this->get_content(), $len, false);
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 			}
392 392
 			$read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more");
393 393
 			if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) {
394
-				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>';
394
+				$text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>';
395 395
 			} elseif ( $readmore ) {
396
-				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>';
396
+				$text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore) . '</a>';
397 397
 			}
398
-			if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) {
398
+			if ( !$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p ')) ) {
399 399
 				$text .= '</p>';
400 400
 			}
401 401
 		}
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	 * @internal
408 408
 	 * @param bool|int $pid a post ID number
409 409
 	 */
410
-	function import_custom( $pid = false ) {
410
+	function import_custom($pid = false) {
411 411
 		if ( !$pid ) {
412 412
 			$pid = $this->ID;
413 413
 		}
@@ -422,13 +422,13 @@  discard block
 block discarded – undo
422 422
 	 * @param int $pid
423 423
 	 * @return array
424 424
 	 */
425
-	protected function get_post_custom( $pid ) {
425
+	protected function get_post_custom($pid) {
426 426
 		apply_filters('timber_post_get_meta_pre', array(), $pid, $this);
427 427
 		$customs = get_post_custom($pid);
428 428
 		if ( !is_array($customs) || empty($customs) ) {
429 429
 			return array();
430 430
 		}
431
-		foreach ( $customs as $key => $value ) {
431
+		foreach ($customs as $key => $value) {
432 432
 			if ( is_array($value) && count($value) == 1 && isset($value[0]) ) {
433 433
 				$value = $value[0];
434 434
 			}
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 	 * @param bool $taxonomy
483 483
 	 * @return TimberPost|boolean
484 484
 	 */
485
-	function get_next( $taxonomy = false ) {
485
+	function get_next($taxonomy = false) {
486 486
 		if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) {
487 487
 			global $post;
488 488
 			$this->_next = array();
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 		$post = $this;
514 514
 		$ret = array();
515 515
 		if ( $multipage ) {
516
-			for ( $i = 1; $i <= $numpages; $i++ ) {
516
+			for ($i = 1; $i <= $numpages; $i++) {
517 517
 				$link = self::get_wp_link_page($i);
518 518
 				$data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link);
519 519
 				if ( $i == $page ) {
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	 * @param bool $taxonomy
566 566
 	 * @return TimberPost|boolean
567 567
 	 */
568
-	function get_prev( $taxonomy = false ) {
568
+	function get_prev($taxonomy = false) {
569 569
 		if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) {
570 570
 			return $this->_prev[$taxonomy];
571 571
 		}
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 		$post->slug = $post->post_name;
633 633
 		$customs = $this->get_post_custom($post->ID);
634 634
 		$post->custom = $customs;
635
-		$post = (object) array_merge((array)$customs, (array)$post);
635
+		$post = (object) array_merge((array) $customs, (array) $post);
636 636
 		return $post;
637 637
 	}
638 638
 
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 	 * @param string $use
644 644
 	 * @return string
645 645
 	 */
646
-	function get_display_date( $use = 'post_date' ) {
646
+	function get_display_date($use = 'post_date') {
647 647
 		return date(get_option('date_format'), strtotime($this->$use));
648 648
 	}
649 649
 
@@ -653,9 +653,9 @@  discard block
 block discarded – undo
653 653
 	 * @param  string $date_format
654 654
 	 * @return string
655 655
 	 */
656
-	function get_date( $date_format = '' ) {
656
+	function get_date($date_format = '') {
657 657
 		$df = $date_format ? $date_format : get_option('date_format');
658
-		$the_date = (string)mysql2date($df, $this->post_date);
658
+		$the_date = (string) mysql2date($df, $this->post_date);
659 659
 		return apply_filters('get_the_date', $the_date, $df);
660 660
 	}
661 661
 
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 	 * @param  string $date_format
665 665
 	 * @return string
666 666
 	 */
667
-	function get_modified_date( $date_format = '' ) {
667
+	function get_modified_date($date_format = '') {
668 668
 		$df = $date_format ? $date_format : get_option('date_format');
669 669
 		$the_time = $this->get_modified_time($df);
670 670
 		return apply_filters('get_the_modified_date', $the_time, $date_format);
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 	 * @param  string $time_format
676 676
 	 * @return string
677 677
 	 */
678
-	function get_modified_time( $time_format = '' ) {
678
+	function get_modified_time($time_format = '') {
679 679
 		$tf = $time_format ? $time_format : get_option('time_format');
680 680
 		$the_time = get_post_modified_time($tf, false, $this->ID, true);
681 681
 		return apply_filters('get_the_modified_time', $the_time, $time_format);
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 	 * @param bool|string 	$childPostClass
689 689
 	 * @return array
690 690
 	 */
691
-	function get_children( $post_type = 'any', $childPostClass = false ) {
691
+	function get_children($post_type = 'any', $childPostClass = false) {
692 692
 		if ( $childPostClass === false ) {
693 693
 			$childPostClass = $this->PostClass;
694 694
 		}
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 			$post_type = $this->post_type;
697 697
 		}
698 698
 		$children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC');
699
-		foreach ( $children as &$child ) {
699
+		foreach ($children as &$child) {
700 700
 			$child = new $childPostClass($child->ID);
701 701
 		}
702 702
 		$children = array_values($children);
@@ -732,20 +732,20 @@  discard block
 block discarded – undo
732 732
 		}
733 733
 
734 734
 		if ( $user_ID ) {
735
-			$args['include_unapproved'] = array( $user_ID );
736
-		} elseif ( ! empty( $comment_author_email ) ) {
737
-			$args['include_unapproved'] = array( $comment_author_email );
735
+			$args['include_unapproved'] = array($user_ID);
736
+		} elseif ( !empty($comment_author_email) ) {
737
+			$args['include_unapproved'] = array($comment_author_email);
738 738
 		}
739 739
 
740 740
 		$comments = get_comments($args);
741 741
 		$timber_comments = array();
742 742
 
743 743
 		if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
744
-			set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
744
+			set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1);
745 745
 			$overridden_cpage = true;
746 746
 		}
747 747
 
748
-		foreach($comments as $key => &$comment) {
748
+		foreach ($comments as $key => &$comment) {
749 749
 			$timber_comment = new $CommentClass($comment);
750 750
 			$timber_comment->reply_link = $this->TimberComment_reply_link($comment->comment_ID, $this->ID);
751 751
 			$timber_comments[$timber_comment->id] = $timber_comment;
@@ -753,22 +753,22 @@  discard block
 block discarded – undo
753 753
 
754 754
 		// Build a flattened (depth=1) comment tree
755 755
 		$comments_tree = array();
756
-		foreach( $timber_comments as $key => $comment ) {
757
-			if ( ! $comment->is_child() ) {
756
+		foreach ($timber_comments as $key => $comment) {
757
+			if ( !$comment->is_child() ) {
758 758
 				continue;
759 759
 			}
760 760
 
761 761
 			$tree_element = $comment;
762 762
 			do {
763 763
 				$tree_element = $timber_comments[$tree_element->comment_parent];
764
-			} while( $tree_element->is_child() );
764
+			} while ($tree_element->is_child());
765 765
 
766 766
 			$comments_tree[$tree_element->id][] = $comment->id;
767 767
 		}
768 768
 
769 769
 		// Add child comments to the relative "super parents"
770
-		foreach($comments_tree as $comment_parent => $comment_children) {
771
-			foreach($comment_children as $comment_child) {
770
+		foreach ($comments_tree as $comment_parent => $comment_children) {
771
+			foreach ($comment_children as $comment_child) {
772 772
 				$timber_comments[$comment_parent]->children[] = $timber_comments[$comment_child];
773 773
 				unset($timber_comments[$comment_child]);
774 774
 			}
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 	 * @param string $TermClass
809 809
 	 * @return array
810 810
 	 */
811
-	function get_terms( $tax = '', $merge = true, $TermClass = '' ) {
811
+	function get_terms($tax = '', $merge = true, $TermClass = '') {
812 812
 
813 813
 		$TermClass = $TermClass ?: $this->TermClass;
814 814
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 			$taxonomies = $tax;
820 820
 		}
821 821
 		if ( is_string($tax) ) {
822
-			if ( in_array($tax, array('all','any','')) ) {
822
+			if ( in_array($tax, array('all', 'any', '')) ) {
823 823
 				$taxonomies = get_object_taxonomies($this->post_type);
824 824
 			} else {
825 825
 				$taxonomies = array($tax);
@@ -828,8 +828,8 @@  discard block
 block discarded – undo
828 828
 
829 829
 		$term_class_objects = array();
830 830
 
831
-		foreach ( $taxonomies as $taxonomy ) {
832
-			if ( in_array($taxonomy, array('tag','tags')) ) {
831
+		foreach ($taxonomies as $taxonomy) {
832
+			if ( in_array($taxonomy, array('tag', 'tags')) ) {
833 833
 				$taxonomy = 'post_tag';
834 834
 			}
835 835
 			if ( $taxonomy == 'categories' ) {
@@ -866,11 +866,11 @@  discard block
 block discarded – undo
866 866
 	 * @param string $taxonomy
867 867
 	 * @return bool
868 868
 	 */
869
-	function has_term( $term_name_or_id, $taxonomy = 'all' ) {
869
+	function has_term($term_name_or_id, $taxonomy = 'all') {
870 870
 		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
871 871
 			$taxes = get_object_taxonomies($this->post_type, 'names');
872 872
 			$ret = false;
873
-			foreach ( $taxes as $tax ) {
873
+			foreach ($taxes as $tax) {
874 874
 				if ( has_term($term_name_or_id, $tax, $this->ID) ) {
875 875
 					$ret = true;
876 876
 					break;
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 	 * @param string $field
886 886
 	 * @return TimberImage
887 887
 	 */
888
-	function get_image( $field ) {
888
+	function get_image($field) {
889 889
 		return new $this->ImageClass($this->$field);
890 890
 	}
891 891
 
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
 	 * @param int $page
936 936
 	 * @return string
937 937
 	 */
938
-	function get_content( $len = 0, $page = 0 ) {
938
+	function get_content($len = 0, $page = 0) {
939 939
 		if ( $len == 0 && $page == 0 && $this->_content ) {
940 940
 			return $this->_content;
941 941
 		}
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 	 * @param string $field_name
993 993
 	 * @return mixed
994 994
 	 */
995
-	public function get_field( $field_name ) {
995
+	public function get_field($field_name) {
996 996
 		$value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
997 997
 		if ( $value === null ) {
998 998
 			$value = get_post_meta($this->ID, $field_name);
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 	/**
1011 1011
 	 * @param string $field_name
1012 1012
 	 */
1013
-	function import_field( $field_name ) {
1013
+	function import_field($field_name) {
1014 1014
 		$this->$field_name = $this->get_field($field_name);
1015 1015
 	}
1016 1016
 
@@ -1041,13 +1041,13 @@  discard block
 block discarded – undo
1041 1041
 	 * ```
1042 1042
 	 * @return string a space-seperated list of classes
1043 1043
 	 */
1044
-	public function post_class( $class='' ) {
1044
+	public function post_class($class = '') {
1045 1045
 		global $post;
1046 1046
 		$old_global_post = $post;
1047 1047
 		$post = $this;
1048 1048
 		$class_array = get_post_class($class, $this->ID);
1049 1049
 		$post = $old_global_post;
1050
-		if ( is_array($class_array) ){
1050
+		if ( is_array($class_array) ) {
1051 1051
 			return implode(' ', $class_array);
1052 1052
 		}
1053 1053
 		return $class_array;
@@ -1149,8 +1149,8 @@  discard block
 block discarded – undo
1149 1149
 	 * @param string|bool $childPostClass _optional_ a custom post class (ex: 'MyTimberPost') to return the objects as. By default (false) it will use TimberPost::$post_class value.
1150 1150
 	 * @return array
1151 1151
 	 */
1152
-	public function children( $post_type = 'any', $childPostClass = false ) {
1153
-		return $this->get_children( $post_type, $childPostClass );
1152
+	public function children($post_type = 'any', $childPostClass = false) {
1153
+		return $this->get_children($post_type, $childPostClass);
1154 1154
 	}
1155 1155
 
1156 1156
 	/**
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
 	 * ```
1175 1175
 	 * @return bool|array
1176 1176
 	 */
1177
-	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1177
+	public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') {
1178 1178
 		return $this->get_comments($count, $order, $type, $status, $CommentClass);
1179 1179
 	}
1180 1180
 
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 	 * @param int $page
1192 1192
 	 * @return string
1193 1193
 	 */
1194
-	public function content( $page = 0 ) {
1194
+	public function content($page = 0) {
1195 1195
 		return $this->get_content(0, $page);
1196 1196
 	}
1197 1197
 
@@ -1220,7 +1220,7 @@  discard block
 block discarded – undo
1220 1220
 	 * @param string $date_format
1221 1221
 	 * @return string
1222 1222
 	 */
1223
-	public function date( $date_format = '' ) {
1223
+	public function date($date_format = '') {
1224 1224
 		return $this->get_date($date_format);
1225 1225
 	}
1226 1226
 
@@ -1242,9 +1242,9 @@  discard block
 block discarded – undo
1242 1242
 	 * @param string $time_format
1243 1243
 	 * @return string
1244 1244
 	 */
1245
-	public function time( $time_format = '' ) {
1245
+	public function time($time_format = '') {
1246 1246
 		$tf = $time_format ? $time_format : get_option('time_format');
1247
-	 	$the_time = (string)mysql2date($tf, $this->post_date);
1247
+	 	$the_time = (string) mysql2date($tf, $this->post_date);
1248 1248
 	 	return apply_filters('get_the_time', $the_time, $tf);
1249 1249
 	}
1250 1250
 
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
 	 * @param string $field_name
1281 1281
 	 * @return mixed
1282 1282
 	 */
1283
-	public function meta( $field_name = null ) {
1283
+	public function meta($field_name = null) {
1284 1284
 		if ( $field_name === null ) {
1285 1285
 			//on the off-chance the field is actually named meta
1286 1286
 			$field_name = 'meta';
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
 	/**
1292 1292
 	 * @return string
1293 1293
 	 */
1294
-	public function name(){
1294
+	public function name() {
1295 1295
 		return $this->title();
1296 1296
 	}
1297 1297
 
@@ -1299,7 +1299,7 @@  discard block
 block discarded – undo
1299 1299
 	 * @param string $date_format
1300 1300
 	 * @return string
1301 1301
 	 */
1302
-	public function modified_date( $date_format = '' ) {
1302
+	public function modified_date($date_format = '') {
1303 1303
 		return $this->get_modified_date($date_format);
1304 1304
 	}
1305 1305
 
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 	 * @param string $time_format
1308 1308
 	 * @return string
1309 1309
 	 */
1310
-	public function modified_time( $time_format = '' ) {
1310
+	public function modified_time($time_format = '') {
1311 1311
 		return $this->get_modified_time($time_format);
1312 1312
 	}
1313 1313
 
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
 	 * @param bool $in_same_cat
1317 1317
 	 * @return mixed
1318 1318
 	 */
1319
-	public function next( $in_same_cat = false ) {
1319
+	public function next($in_same_cat = false) {
1320 1320
 		return $this->get_next($in_same_cat);
1321 1321
 	}
1322 1322
 
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 	 * @param bool $in_same_cat
1375 1375
 	 * @return mixed
1376 1376
 	 */
1377
-	public function prev( $in_same_cat = false ) {
1377
+	public function prev($in_same_cat = false) {
1378 1378
 		return $this->get_prev($in_same_cat);
1379 1379
 	}
1380 1380
 
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 	 * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
1387 1387
 	 * @return array
1388 1388
 	 */
1389
-	public function terms( $tax = '', $merge = true ) {
1389
+	public function terms($tax = '', $merge = true) {
1390 1390
 		return $this->get_terms($tax, $merge);
1391 1391
 	}
1392 1392
 
Please login to merge, or discard this patch.
lib/timber-loader.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) {
43 43
 		// Different $expires if user is anonymous or logged in
44
-		if (is_array($expires)) {
45
-			if (is_user_logged_in() && isset($expires[1])) {
44
+		if ( is_array($expires) ) {
45
+			if ( is_user_logged_in() && isset($expires[1]) ) {
46 46
 				$expires = $expires[1];
47 47
 			} else {
48 48
 				$expires = $expires[0];
@@ -51,15 +51,15 @@  discard block
 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);
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 	 * @return bool
82 82
 	 */
83 83
 	public function choose_template($filenames) {
84
-		if (is_array($filenames)) {
84
+		if ( is_array($filenames) ) {
85 85
 			/* its an array so we have to figure out which one the dev wants */
86 86
 			foreach ($filenames as $filename) {
87
-				if (self::template_exists($filename)) {
87
+				if ( self::template_exists($filename) ) {
88 88
 					return $filename;
89 89
 				}
90 90
 			}
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	protected function template_exists($file) {
101 101
 		foreach ($this->locations as $dir) {
102 102
 			$look_for = trailingslashit($dir) . $file;
103
-			if (file_exists($look_for)) {
103
+			if ( file_exists($look_for) ) {
104 104
 				return true;
105 105
 			}
106 106
 		}
@@ -114,7 +114,7 @@  discard block
 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
 		}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		foreach ($this->get_locations_theme_dir() as $dirname) {
123 123
 			$theme_locs[] = trailingslashit($child_loc) . trailingslashit($dirname);
124 124
 		}
125
-		if ($child_loc != $parent_loc) {
125
+		if ( $child_loc != $parent_loc ) {
126 126
 			$theme_locs[] = $parent_loc;
127 127
 			foreach ($this->get_locations_theme_dir() as $dirname) {
128 128
 				$theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname);
@@ -138,7 +138,7 @@  discard block
 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 156
 			foreach (Timber::$locations as $tloc) {
157 157
 				$tloc = realpath($tloc);
158
-				if (is_dir($tloc)) {
158
+				if ( is_dir($tloc) ) {
159 159
 					$locs[] = $tloc;
160 160
 				}
161 161
 			}
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	 */
170 170
 	function get_locations_caller($caller = false) {
171 171
 		$locs = array();
172
-		if ($caller && is_string($caller)) {
172
+		if ( $caller && is_string($caller) ) {
173 173
 			$caller = trailingslashit($caller);
174
-			if (is_dir($caller)) {
174
+			if ( is_dir($caller) ) {
175 175
 				$locs[] = $caller;
176 176
 			}
177 177
 			foreach ($this->get_locations_theme_dir() as $dirname) {
178 178
 				$caller_sub = $caller . trailingslashit($dirname);
179
-				if (is_dir($caller_sub)) {
179
+				if ( is_dir($caller_sub) ) {
180 180
 					$locs[] = $caller_sub;
181 181
 				}
182 182
 			}
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
 		$paths = array();
211 211
 		foreach ($this->locations as $loc) {
212 212
 			$loc = realpath($loc);
213
-			if (is_dir($loc)) {
213
+			if ( is_dir($loc) ) {
214 214
 				$loc = realpath($loc);
215 215
 				$paths[] = $loc;
216 216
 			} else {
217 217
 				//error_log($loc.' is not a directory');
218 218
 			}
219 219
 		}
220
-		if (!ini_get('open_basedir')) {
220
+		if ( !ini_get('open_basedir') ) {
221 221
 			$paths[] = '/';
222 222
 		} else {
223 223
 			$paths[] = ABSPATH;
@@ -233,15 +233,15 @@  discard block
 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
 		}
@@ -300,15 +300,15 @@  discard block
 block discarded – undo
300 300
 	 * @param string|false $dirPath
301 301
 	 */
302 302
 	public static function rrmdir($dirPath) {
303
-		if (! is_dir($dirPath)) {
303
+		if ( !is_dir($dirPath) ) {
304 304
 			throw new InvalidArgumentException("$dirPath must be a directory");
305 305
 		}
306
-		if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
306
+		if ( substr($dirPath, strlen($dirPath) - 1, 1) != '/' ) {
307 307
 			$dirPath .= '/';
308 308
 		}
309 309
 		$files = glob($dirPath . '*', GLOB_MARK);
310 310
 		foreach ($files as $file) {
311
-			if (is_dir($file)) {
311
+			if ( is_dir($file) ) {
312 312
 				self::rrmdir($file);
313 313
 			} else {
314 314
 				unlink($file);
@@ -323,9 +323,9 @@  discard block
 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
 	}
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 	public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) {
340 340
 		$object_cache = false;
341 341
 
342
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
342
+		if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) {
343 343
 			$object_cache = true;
344 344
 		}
345 345
 
@@ -348,13 +348,13 @@  discard block
 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;
@@ -371,23 +371,23 @@  discard block
 block discarded – undo
371 371
 	public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) {
372 372
 		$object_cache = false;
373 373
 
374
-		if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
374
+		if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) {
375 375
 			$object_cache = true;
376 376
 		}
377 377
 
378
-		if ((int)$expires < 1)
378
+		if ( (int) $expires < 1 )
379 379
 			$expires = 0;
380 380
 
381 381
 		$cache_mode = self::_get_cache_mode($cache_mode);
382 382
 		$trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN);
383 383
 
384
-		if (self::CACHE_TRANSIENT === $cache_mode)
384
+		if ( self::CACHE_TRANSIENT === $cache_mode )
385 385
 			set_transient($trans_key, $value, $expires);
386 386
 
387
-		elseif (self::CACHE_SITE_TRANSIENT === $cache_mode)
387
+		elseif ( self::CACHE_SITE_TRANSIENT === $cache_mode )
388 388
 			set_site_transient($trans_key, $value, $expires);
389 389
 
390
-		elseif (self::CACHE_OBJECT === $cache_mode && $object_cache)
390
+		elseif ( self::CACHE_OBJECT === $cache_mode && $object_cache )
391 391
 			wp_cache_set($key, $value, $group, $expires);
392 392
 
393 393
 		return $value;
@@ -398,12 +398,12 @@  discard block
 block discarded – undo
398 398
 	 * @return string
399 399
 	 */
400 400
 	private function _get_cache_mode($cache_mode) {
401
-		if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) {
401
+		if ( empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode ) {
402 402
 			$cache_mode = $this->cache_mode;
403 403
 		}
404 404
 
405 405
 		// Fallback if self::$cache_mode did not get a valid value
406
-		if (!in_array($cache_mode, self::$cache_modes)) {
406
+		if ( !in_array($cache_mode, self::$cache_modes) ) {
407 407
 			$cache_mode = self::CACHE_OBJECT;
408 408
 		}
409 409
 
Please login to merge, or discard this patch.
lib/timber-image-helper.php 1 patch
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * ```
44 44
 	 * @return string (ex: )
45 45
 	 */
46
-	public static function resize( $src, $w, $h = 0, $crop = 'default', $force = false ) {
47
-		if (!is_numeric($w) && is_string($w)) {
48
-			if ($sizes = self::find_wp_dimensions($w)) {
46
+	public static function resize($src, $w, $h = 0, $crop = 'default', $force = false) {
47
+		if ( !is_numeric($w) && is_string($w) ) {
48
+			if ( $sizes = self::find_wp_dimensions($w) ) {
49 49
 				$w = $sizes['w'];
50 50
 				$h = $sizes['h'];
51 51
 			} else {
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
 	 *     @type int h
67 67
 	 * }
68 68
 	 */
69
-	private static function find_wp_dimensions( $size ) {
69
+	private static function find_wp_dimensions($size) {
70 70
 		global $_wp_additional_image_sizes;
71
-		if (isset($_wp_additional_image_sizes[$size])) {
71
+		if ( isset($_wp_additional_image_sizes[$size]) ) {
72 72
 			$w = $_wp_additional_image_sizes[$size]['width'];
73 73
 			$h = $_wp_additional_image_sizes[$size]['height'];
74
-		} else if (in_array($size, array('thumbnail', 'medium', 'large'))) {
75
-			$w = get_option($size.'_size_w');
76
-			$h = get_option($size.'_size_h');
74
+		} else if ( in_array($size, array('thumbnail', 'medium', 'large')) ) {
75
+			$w = get_option($size . '_size_w');
76
+			$h = get_option($size . '_size_h');
77 77
 		}
78
-		if (isset($w) && isset($h) && ($w || $h)) {
78
+		if ( isset($w) && isset($h) && ($w || $h) ) {
79 79
 			return array('w' => $w, 'h' => $h);
80 80
 		}
81 81
 		return false;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @return string url to the new image
92 92
 	 */
93
-	public static function retina_resize( $src, $multiplier = 2, $force = false ) {
93
+	public static function retina_resize($src, $multiplier = 2, $force = false) {
94 94
 		$op = new TimberImageOperationRetina($multiplier);
95 95
 		return self::_operate($src, $op, $force);
96 96
 	}
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 	 * @param  string  $file local filepath to a file, not a URL
101 101
 	 * @return boolean true if it's an animated gif, false if not
102 102
 	 */
103
-	public static function is_animated_gif( $file ) {
103
+	public static function is_animated_gif($file) {
104 104
 		if ( strpos(strtolower($file), '.gif') == -1 ) {
105 105
 			//doesn't have .gif, bail
106 106
 			return false;
107 107
 		}
108 108
 		//its a gif so test
109
-		if( !($fh = @fopen($file, 'rb')) ) {
109
+		if ( !($fh = @fopen($file, 'rb')) ) {
110 110
 		  	return false;
111 111
 	    }
112 112
 	    $count = 0;
@@ -118,7 +118,7 @@  discard block
 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
 	    }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 * @param bool    $force
139 139
 	 * @return mixed|null|string
140 140
 	 */
141
-	public static function letterbox( $src, $w, $h, $color = '#000000', $force = false ) {
141
+	public static function letterbox($src, $w, $h, $color = '#000000', $force = false) {
142 142
 		$op = new TimberImageOperationLetterbox($w, $h, $color);
143 143
 		return self::_operate($src, $op, $force);
144 144
 	}
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @param string  $bghex
151 151
 	 * @return string
152 152
 	 */
153
-	public static function img_to_jpg( $src, $bghex = '#FFFFFF', $force = false ) {
153
+	public static function img_to_jpg($src, $bghex = '#FFFFFF', $force = false) {
154 154
 		$op = new TimberImageOperationToJpg($bghex);
155 155
 		return self::_operate($src, $op, $force);
156 156
 	}
@@ -159,13 +159,13 @@  discard block
 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
 	}
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
 	 * @param string  $local_file   ex: /var/www/wp-content/uploads/2015/my-pic.jpg
201 201
 	 *                              or: http://example.org/wp-content/uploads/2015/my-pic.jpg
202 202
 	 */
203
-	static function delete_generated_files( $local_file ) {
204
-		if (TimberURLHelper::is_absolute( $local_file ) ) {
205
-			$local_file = TimberURLHelper::url_to_file_system( $local_file );
203
+	static function delete_generated_files($local_file) {
204
+		if ( TimberURLHelper::is_absolute($local_file) ) {
205
+			$local_file = TimberURLHelper::url_to_file_system($local_file);
206 206
 		}
207
-		$info = pathinfo( $local_file );
207
+		$info = pathinfo($local_file);
208 208
 		$dir = $info['dirname'];
209 209
 		$ext = $info['extension'];
210 210
 		$filename = $info['filename'];
211
-		self::process_delete_generated_files( $filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.' );
212
-		self::process_delete_generated_files( $filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.' );
211
+		self::process_delete_generated_files($filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.');
212
+		self::process_delete_generated_files($filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.');
213 213
 	}
214 214
 
215 215
 	/**
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
 	 * @param string 	$search_pattern pattern of files to pluck from
227 227
 	 * @param string 	$match_pattern pattern of files to go forth and delete
228 228
 	 */
229
-	protected static function process_delete_generated_files( $filename, $ext, $dir, $search_pattern, $match_pattern ) {
229
+	protected static function process_delete_generated_files($filename, $ext, $dir, $search_pattern, $match_pattern) {
230 230
 		$searcher = '/' . $filename . $search_pattern;
231
-		foreach ( glob( $dir . $searcher ) as $found_file ) {
232
-			$regexdir = str_replace( '/', '\/', $dir );
233
-			$pattern = '/' . ( $regexdir ) . '\/' . $filename . $match_pattern . $ext . '/';
234
-			$match = preg_match( $pattern, $found_file );
231
+		foreach (glob($dir . $searcher) as $found_file) {
232
+			$regexdir = str_replace('/', '\/', $dir);
233
+			$pattern = '/' . ($regexdir) . '\/' . $filename . $match_pattern . $ext . '/';
234
+			$match = preg_match($pattern, $found_file);
235 235
 			if ( $match ) {
236
-				unlink( $found_file );
236
+				unlink($found_file);
237 237
 			}
238 238
 		}
239 239
 	}
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
 	 * @param string  $url
246 246
 	 * @return string
247 247
 	 */
248
-	public static function get_server_location( $url ) {
248
+	public static function get_server_location($url) {
249 249
 		// if we're already an absolute dir, just return
250
-		if ( 0 === strpos( $url, ABSPATH ) ) {
250
+		if ( 0 === strpos($url, ABSPATH) ) {
251 251
 			return $url;
252 252
 		}
253 253
 		// otherwise, analyze URL then build mapping path
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
 	 * @param string  $file
263 263
 	 * @return string
264 264
 	 */
265
-	public static function get_sideloaded_file_loc( $file ) {
265
+	public static function get_sideloaded_file_loc($file) {
266 266
 		$upload = wp_upload_dir();
267 267
 		$dir = $upload['path'];
268 268
 		$filename = $file;
269
-		$file = parse_url( $file );
270
-		$path_parts = pathinfo( $file['path'] );
271
-		$basename = md5( $filename );
269
+		$file = parse_url($file);
270
+		$path_parts = pathinfo($file['path']);
271
+		$basename = md5($filename);
272 272
 		$ext = 'jpg';
273
-		if ( isset( $path_parts['extension'] ) ) {
273
+		if ( isset($path_parts['extension']) ) {
274 274
 			$ext = $path_parts['extension'];
275 275
 		}
276 276
 		return $dir . '/' . $basename . '.' . $ext;
@@ -282,28 +282,28 @@  discard block
 block discarded – undo
282 282
 	 * @param string  $file the URL to the original file
283 283
 	 * @return string the URL to the downloaded file
284 284
 	 */
285
-	public static function sideload_image( $file ) {
286
-		$loc = self::get_sideloaded_file_loc( $file );
287
-		if ( file_exists( $loc ) ) {
288
-			return TimberURLHelper::preslashit( TimberURLHelper::get_rel_path( $loc ) );
285
+	public static function sideload_image($file) {
286
+		$loc = self::get_sideloaded_file_loc($file);
287
+		if ( file_exists($loc) ) {
288
+			return TimberURLHelper::preslashit(TimberURLHelper::get_rel_path($loc));
289 289
 		}
290 290
 		// Download file to temp location
291
-		if ( !function_exists( 'download_url' ) ) {
291
+		if ( !function_exists('download_url') ) {
292 292
 			require_once ABSPATH . '/wp-admin/includes/file.php';
293 293
 		}
294
-		$tmp = download_url( $file );
295
-		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
294
+		$tmp = download_url($file);
295
+		preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
296 296
 		$file_array = array();
297
-		$file_array['name'] = basename( $matches[0] );
297
+		$file_array['name'] = basename($matches[0]);
298 298
 		$file_array['tmp_name'] = $tmp;
299 299
 		// If error storing temporarily, unlink
300
-		if ( is_wp_error( $tmp ) ) {
301
-			@unlink( $file_array['tmp_name'] );
300
+		if ( is_wp_error($tmp) ) {
301
+			@unlink($file_array['tmp_name']);
302 302
 			$file_array['tmp_name'] = '';
303 303
 		}
304 304
 		// do the validation and storage stuff
305
-		$locinfo = pathinfo( $loc );
306
-		$file = wp_upload_bits( $locinfo['basename'], null, file_get_contents( $file_array['tmp_name'] ) );
305
+		$locinfo = pathinfo($loc);
306
+		$file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name']));
307 307
 		return $file['url'];
308 308
 	}
309 309
 
@@ -330,23 +330,23 @@  discard block
 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
 		}
@@ -370,18 +370,18 @@  discard block
 block discarded – undo
370 370
 	 */
371 371
 	private static function _get_file_url($base, $subdir, $filename, $absolute) {
372 372
 		$url = '';
373
-		if( self::BASE_UPLOADS == $base ) {
373
+		if ( self::BASE_UPLOADS == $base ) {
374 374
 			$upload_dir = wp_upload_dir();
375 375
 			$url = $upload_dir['baseurl'];
376 376
 		}
377
-		if( self::BASE_CONTENT == $base ) {
377
+		if ( self::BASE_CONTENT == $base ) {
378 378
 			$url = content_url();
379 379
 		}
380
-		if(!empty($subdir)) {
380
+		if ( !empty($subdir) ) {
381 381
 			$url .= $subdir;
382 382
 		}
383
-		$url .= '/'.$filename;
384
-		if(!$absolute) {
383
+		$url .= '/' . $filename;
384
+		if ( !$absolute ) {
385 385
 			$url = str_replace(home_url(), '', $url);
386 386
 		}
387 387
 		// $url = TimberURLHelper::remove_double_slashes( $url);
@@ -398,17 +398,17 @@  discard block
 block discarded – undo
398 398
 	 */
399 399
 	private static function _get_file_path($base, $subdir, $filename) {
400 400
 		$path = '';
401
-		if(self::BASE_UPLOADS == $base) {
401
+		if ( self::BASE_UPLOADS == $base ) {
402 402
 			$upload_dir = wp_upload_dir();
403 403
 			$path = $upload_dir['basedir'];
404 404
 		}
405
-		if(self::BASE_CONTENT == $base) {
405
+		if ( self::BASE_CONTENT == $base ) {
406 406
 			$path = WP_CONTENT_DIR;
407 407
 		}
408
-		if(!empty($subdir)) {
408
+		if ( !empty($subdir) ) {
409 409
 			$path .= $subdir;
410 410
 		}
411
-		$path .= '/'.$filename;
411
+		$path .= '/' . $filename;
412 412
 		return $path;
413 413
 	}
414 414
 
@@ -426,13 +426,13 @@  discard block
 block discarded – undo
426 426
 	 * @return string         URL to the new image - or the source one if error
427 427
 	 *
428 428
 	 */
429
-	private static function _operate( $src, $op, $force = false ) {
430
-		if ( empty( $src ) ) {
429
+	private static function _operate($src, $op, $force = false) {
430
+		if ( empty($src) ) {
431 431
 			return '';
432 432
 		}
433 433
 		// if external image, load it first
434
-		if ( TimberURLHelper::is_external_content( $src ) ) {
435
-			$src = self::sideload_image( $src );
434
+		if ( TimberURLHelper::is_external_content($src) ) {
435
+			$src = self::sideload_image($src);
436 436
 		}
437 437
 		// break down URL into components
438 438
 		$au = self::analyze_url($src);
@@ -454,17 +454,17 @@  discard block
 block discarded – undo
454 454
 			$au['basename']
455 455
 		);
456 456
 		// if already exists...
457
-		if ( file_exists( $new_server_path ) ) {
457
+		if ( file_exists($new_server_path) ) {
458 458
 			if ( $force ) {
459 459
 				// Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
460
-				unlink( $new_server_path );
460
+				unlink($new_server_path);
461 461
 			} else {
462 462
 				// return existing file (caching)
463 463
 				return $new_url;
464 464
 			}
465 465
 		}
466 466
 		// otherwise generate result file
467
-		if($op->run($old_server_path, $new_server_path)) {
467
+		if ( $op->run($old_server_path, $new_server_path) ) {
468 468
 			return $new_url;
469 469
 		} else {
470 470
 			// in case of error, we return source file itself
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
 		);
487 487
 		return $new_url;
488 488
 	}
489
-	public static function get_letterbox_file_path($url, $w, $h, $color ) {
489
+	public static function get_letterbox_file_path($url, $w, $h, $color) {
490 490
 		$au = self::analyze_url($url);
491 491
 		$op = new TimberImageOperationLetterbox($w, $h, $color);
492 492
 		$new_path = self::_get_file_path(
Please login to merge, or discard this patch.