Completed
Pull Request — master (#893)
by
unknown
02:38
created
lib/timber.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
45 45
 		if ( is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php' ) {
46 46
 			return;
47 47
 		}
48
-		if ( version_compare( phpversion(), '5.3.0', '<' ) && !is_admin() ) {
49
-			trigger_error( 'Timber requires PHP 5.3.0 or greater. You have '.phpversion(), E_USER_ERROR );
48
+		if ( version_compare(phpversion(), '5.3.0', '<') && !is_admin() ) {
49
+			trigger_error('Timber requires PHP 5.3.0 or greater. You have ' . phpversion(), E_USER_ERROR);
50 50
 		}
51
-		if ( !class_exists( 'Twig_Autoloader' ) ) {
52
-			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 );
51
+		if ( !class_exists('Twig_Autoloader') ) {
52
+			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);
53 53
 		}
54 54
 	}
55 55
 
56 56
 	function init_constants() {
57
-		defined( "TIMBER_LOC" ) or define( "TIMBER_LOC", realpath( dirname(__DIR__) ) );
57
+		defined("TIMBER_LOC") or define("TIMBER_LOC", realpath(dirname(__DIR__)));
58 58
 	}
59 59
 
60 60
 	/**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	protected function init() {
64 64
 		TimberTwig::init();
65
-		TimberRoutes::init( $this );
65
+		TimberRoutes::init($this);
66 66
 		TimberImageHelper::init();
67 67
 		TimberAdmin::init();
68 68
 		TimberIntegrations::init();
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @return array|bool|null
80 80
 	 */
81 81
 	public static function get_post( $query = false, $PostClass = 'TimberPost' ) {
82
-		return TimberPostGetter::get_post( $query, $PostClass );
82
+		return TimberPostGetter::get_post($query, $PostClass);
83 83
 	}
84 84
 
85 85
 	/**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @return array|bool|null
91 91
 	 */
92 92
 	public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) {
93
-		return TimberPostGetter::get_posts( $query, $PostClass, $return_collection );
93
+		return TimberPostGetter::get_posts($query, $PostClass, $return_collection);
94 94
 	}
95 95
 
96 96
 	/**
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * @return array|bool|null
102 102
 	 */
103 103
 	public static function query_post( $query = false, $PostClass = 'TimberPost' ) {
104
-		return TimberPostGetter::query_post( $query, $PostClass );
104
+		return TimberPostGetter::query_post($query, $PostClass);
105 105
 	}
106 106
 
107 107
 	/**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @return array|bool|null
113 113
 	 */
114 114
 	public static function query_posts( $query = false, $PostClass = 'TimberPost' ) {
115
-		return TimberPostGetter::query_posts( $query, $PostClass );
115
+		return TimberPostGetter::query_posts($query, $PostClass);
116 116
 	}
117 117
 
118 118
 	/**
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * @return mixed
138 138
 	 */
139 139
 	public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) {
140
-		return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass );
140
+		return TimberTermGetter::get_terms($args, $maybe_args, $TermClass);
141 141
 	}
142 142
 
143 143
 	/* Site Retrieval
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 	 * @return array
151 151
 	 */
152 152
 	public static function get_sites( $blog_ids = false ) {
153
-		if ( !is_array( $blog_ids ) ) {
153
+		if ( !is_array($blog_ids) ) {
154 154
 			global $wpdb;
155
-			$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" );
155
+			$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC");
156 156
 		}
157 157
 		$return = array();
158 158
 		foreach ( $blog_ids as $blog_id ) {
159
-			$return[] = new TimberSite( $blog_id );
159
+			$return[] = new TimberSite($blog_id);
160 160
 		}
161 161
 		return $return;
162 162
 	}
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 		$data = array();
175 175
 		$data['http_host'] = 'http://' . TimberURLHelper::get_host();
176 176
 		$data['wp_title'] = TimberHelper::get_wp_title();
177
-		$data['wp_head'] = TimberHelper::function_wrapper( 'wp_head' );
178
-		$data['wp_footer'] = TimberHelper::function_wrapper( 'wp_footer' );
179
-		$data['body_class'] = implode( ' ', get_body_class() );
177
+		$data['wp_head'] = TimberHelper::function_wrapper('wp_head');
178
+		$data['wp_footer'] = TimberHelper::function_wrapper('wp_footer');
179
+		$data['body_class'] = implode(' ', get_body_class());
180 180
 
181 181
 		$data['site'] = new TimberSite();
182 182
 		$data['request'] = new TimberRequest();
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 
185 185
 		$data['posts'] = Timber::query_posts();
186 186
 
187
-		$data = apply_filters( 'timber_context', $data );
188
-		$data = apply_filters( 'timber/context', $data );
187
+		$data = apply_filters('timber_context', $data);
188
+		$data = apply_filters('timber/context', $data);
189 189
 		return $data;
190 190
 	}
191 191
 
@@ -202,24 +202,24 @@  discard block
 block discarded – undo
202 202
 	public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) {
203 203
 		$caller = self::get_calling_script_dir();
204 204
 		$caller_file = self::get_calling_script_file();
205
-		$caller_file = apply_filters( 'timber_calling_php_file', $caller_file );
206
-		$loader = new TimberLoader( $caller );
207
-		$file = $loader->choose_template( $filenames );
205
+		$caller_file = apply_filters('timber_calling_php_file', $caller_file);
206
+		$loader = new TimberLoader($caller);
207
+		$file = $loader->choose_template($filenames);
208 208
 		$output = '';
209
-		if ( is_null( $data ) ) {
209
+		if ( is_null($data) ) {
210 210
 			$data = array();
211 211
 		}
212
-		if ( strlen( $file ) ) {
212
+		if ( strlen($file) ) {
213 213
 			if ( $via_render ) {
214
-				$file = apply_filters( 'timber_render_file', $file );
215
-				$data = apply_filters( 'timber_render_data', $data );
214
+				$file = apply_filters('timber_render_file', $file);
215
+				$data = apply_filters('timber_render_data', $data);
216 216
 			} else {
217
-				$file = apply_filters( 'timber_compile_file', $file );
218
-				$data = apply_filters( 'timber_compile_data', $data );
217
+				$file = apply_filters('timber_compile_file', $file);
218
+				$data = apply_filters('timber_compile_data', $data);
219 219
 			}
220
-			$output = $loader->render( $file, $data, $expires, $cache_mode );
220
+			$output = $loader->render($file, $data, $expires, $cache_mode);
221 221
 		}
222
-		do_action( 'timber_compile_done' );
222
+		do_action('timber_compile_done');
223 223
 		return $output;
224 224
 	}
225 225
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		$dummy_loader = new TimberLoader();
235 235
 		$twig = $dummy_loader->get_twig();
236 236
 		$template = $twig->createTemplate($string);
237
-		return $template->render( $data );
237
+		return $template->render($data);
238 238
 	}
239 239
 
240 240
 	/**
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 			$expires = $cache_mode;
254 254
 			$cache_mode = TimberLoader::CACHE_USE_DEFAULT;
255 255
 		}
256
-		$output = self::compile( $filenames, $data, $expires, $cache_mode, true );
257
-		$output = apply_filters( 'timber_compile_result', $output );
256
+		$output = self::compile($filenames, $data, $expires, $cache_mode, true);
257
+		$output = apply_filters('timber_compile_result', $output);
258 258
 		return $output;
259 259
 	}
260 260
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @return bool|string
269 269
 	 */
270 270
 	public static function render( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) {
271
-		$output = static::fetch( $filenames, $data, $expires, $cache_mode );
271
+		$output = static::fetch($filenames, $data, $expires, $cache_mode);
272 272
 		echo $output;
273 273
 		return $output;
274 274
 	}
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @return  bool|string
282 282
 	 */
283 283
 	public static function render_string( $string, $data = array() ) {
284
-		$compiled = self::compile_string( $string, $data );
284
+		$compiled = self::compile_string($string, $data);
285 285
 		echo $compiled;
286 286
 		return $compiled;
287 287
 	}
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
 		if ( $sidebar == '' ) {
302 302
 			$sidebar = 'sidebar.php';
303 303
 		}
304
-		if ( strstr( strtolower( $sidebar ), '.php' ) ) {
305
-			return self::get_sidebar_from_php( $sidebar, $data );
304
+		if ( strstr(strtolower($sidebar), '.php') ) {
305
+			return self::get_sidebar_from_php($sidebar, $data);
306 306
 		}
307
-		return self::compile( $sidebar, $data );
307
+		return self::compile($sidebar, $data);
308 308
 	}
309 309
 
310 310
 	/**
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
 	public static function get_sidebar_from_php( $sidebar = '', $data ) {
318 318
 		$caller = self::get_calling_script_dir();
319 319
 		$loader = new TimberLoader();
320
-		$uris = $loader->get_locations( $caller );
320
+		$uris = $loader->get_locations($caller);
321 321
 		ob_start();
322 322
 		$found = false;
323 323
 		foreach ( $uris as $uri ) {
324
-			if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) {
325
-				include trailingslashit( $uri ) . $sidebar;
324
+			if ( file_exists(trailingslashit($uri) . $sidebar) ) {
325
+				include trailingslashit($uri) . $sidebar;
326 326
 				$found = true;
327 327
 				break;
328 328
 			}
329 329
 		}
330 330
 		if ( !$found ) {
331
-			TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' );
331
+			TimberHelper::error_log('error loading your sidebar, check to make sure the file exists');
332 332
 		}
333 333
 		$ret = ob_get_contents();
334 334
 		ob_end_clean();
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 * @return TimberFunctionWrapper
346 346
 	 */
347 347
 	public static function get_widgets( $widget_id ) {
348
-		return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) );
348
+		return trim(TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true));
349 349
 	}
350 350
 
351 351
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	 * @deprecated since 0.20.0
362 362
 	 */
363 363
 	public static function add_route( $route, $callback, $args = array() ) {
364
-		Routes::map( $route, $callback, $args );
364
+		Routes::map($route, $callback, $args);
365 365
 	}
366 366
 
367 367
 	/**
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 * @deprecated since 0.20.0
371 371
 	 */
372 372
 	public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) {
373
-		return Routes::load( $template, $tparams, $query, $status_code );
373
+		return Routes::load($template, $tparams, $query, $status_code);
374 374
 	}
375 375
 
376 376
 	/**
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 	 * @deprecated since 0.20.2
380 380
 	 */
381 381
 	public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) {
382
-		return Routes::load( $template, $tparams, $query, $status_code );
382
+		return Routes::load($template, $tparams, $query, $status_code);
383 383
 	}
384 384
 
385 385
 
@@ -397,38 +397,38 @@  discard block
 block discarded – undo
397 397
 		global $paged;
398 398
 		global $wp_rewrite;
399 399
 		$args = array();
400
-		$args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] );
400
+		$args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
401 401
 		if ( $wp_rewrite->using_permalinks() ) {
402
-			$url = explode( '?', get_pagenum_link( 0 ) );
403
-			if ( isset( $url[1] ) ) {
404
-				parse_str( $url[1], $query );
402
+			$url = explode('?', get_pagenum_link(0));
403
+			if ( isset($url[1]) ) {
404
+				parse_str($url[1], $query);
405 405
 				$args['add_args'] = $query;
406 406
 			}
407 407
 			$args['format'] = 'page/%#%';
408
-			$args['base'] = trailingslashit( $url[0] ).'%_%';
408
+			$args['base'] = trailingslashit($url[0]) . '%_%';
409 409
 		} else {
410 410
 			$big = 999999999;
411
-			$args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) );
411
+			$args['base'] = str_replace($big, '%#%', esc_url(get_pagenum_link($big)));
412 412
 		}
413 413
 		$args['type'] = 'array';
414
-		$args['current'] = max( 1, get_query_var( 'paged' ) );
415
-		$args['mid_size'] = max( 9 - $args['current'], 3 );
416
-		if ( is_int( $prefs ) ) {
414
+		$args['current'] = max(1, get_query_var('paged'));
415
+		$args['mid_size'] = max(9 - $args['current'], 3);
416
+		if ( is_int($prefs) ) {
417 417
 			$args['mid_size'] = $prefs - 2;
418 418
 		} else {
419
-			$args = array_merge( $args, $prefs );
419
+			$args = array_merge($args, $prefs);
420 420
 		}
421 421
 		$data = array();
422 422
 		$data['current'] = $args['current'];
423 423
 		$data['total'] = $args['total'];
424
-		$data['pages'] = TimberHelper::paginate_links( $args );
425
-		$next = get_next_posts_page_link( $args['total'] );
424
+		$data['pages'] = TimberHelper::paginate_links($args);
425
+		$next = get_next_posts_page_link($args['total']);
426 426
 		if ( $next ) {
427
-			$data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' );
427
+			$data['next'] = array('link' => untrailingslashit($next), 'class' => 'page-numbers next');
428 428
 		}
429
-		$prev = previous_posts( false );
429
+		$prev = previous_posts(false);
430 430
 		if ( $prev ) {
431
-			$data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' );
431
+			$data['prev'] = array('link' => untrailingslashit($prev), 'class' => 'page-numbers prev');
432 432
 		}
433 433
 		if ( $paged < 2 ) {
434 434
 			$data['prev'] = '';
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
 	 * @return string
446 446
 	 */
447 447
 	public static function get_calling_script_dir( $offset = 0 ) {
448
-		$caller = self::get_calling_script_file( $offset );
449
-		if ( !is_null( $caller ) ) {
450
-			$pathinfo = pathinfo( $caller );
448
+		$caller = self::get_calling_script_file($offset);
449
+		if ( !is_null($caller) ) {
450
+			$pathinfo = pathinfo($caller);
451 451
 			$dir = $pathinfo['dirname'];
452 452
 			return $dir;
453 453
 		}
Please login to merge, or discard this patch.