@@ -345,7 +345,7 @@ |
||
345 | 345 | * Get widgets. |
346 | 346 | * |
347 | 347 | * @param int $widget_id |
348 | - * @return TimberFunctionWrapper |
|
348 | + * @return string |
|
349 | 349 | */ |
350 | 350 | public static function get_widgets( $widget_id ) { |
351 | 351 | return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) ); |
@@ -45,16 +45,16 @@ discard block |
||
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 |
||
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(); |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @param string $PostClass |
79 | 79 | * @return array|bool|null |
80 | 80 | */ |
81 | - public static function get_post( $query = false, $PostClass = 'TimberPost' ) { |
|
82 | - return TimberPostGetter::get_post( $query, $PostClass ); |
|
81 | + public static function get_post($query = false, $PostClass = 'TimberPost') { |
|
82 | + return TimberPostGetter::get_post($query, $PostClass); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | * @param string $PostClass |
90 | 90 | * @return array|bool|null |
91 | 91 | */ |
92 | - public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
|
93 | - return TimberPostGetter::get_posts( $query, $PostClass, $return_collection ); |
|
92 | + public static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) { |
|
93 | + return TimberPostGetter::get_posts($query, $PostClass, $return_collection); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param string $PostClass |
101 | 101 | * @return array|bool|null |
102 | 102 | */ |
103 | - public static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
|
104 | - return TimberPostGetter::query_post( $query, $PostClass ); |
|
103 | + public static function query_post($query = false, $PostClass = 'TimberPost') { |
|
104 | + return TimberPostGetter::query_post($query, $PostClass); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | * @param string $PostClass |
112 | 112 | * @return array|bool|null |
113 | 113 | */ |
114 | - public static function query_posts( $query = false, $PostClass = 'TimberPost' ) { |
|
115 | - return TimberPostGetter::query_posts( $query, $PostClass ); |
|
114 | + public static function query_posts($query = false, $PostClass = 'TimberPost') { |
|
115 | + return TimberPostGetter::query_posts($query, $PostClass); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string $TermClass |
137 | 137 | * @return mixed |
138 | 138 | */ |
139 | - public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) { |
|
140 | - return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass ); |
|
139 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
140 | + return TimberTermGetter::get_terms($args, $maybe_args, $TermClass); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /* Site Retrieval |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | * @param array|bool $blog_ids |
150 | 150 | * @return array |
151 | 151 | */ |
152 | - public static function get_sites( $blog_ids = false ) { |
|
153 | - if ( !is_array( $blog_ids ) ) { |
|
152 | + public static function get_sites($blog_ids = false) { |
|
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 | - foreach ( $blog_ids as $blog_id ) { |
|
159 | - $return[] = new TimberSite( $blog_id ); |
|
158 | + foreach ($blog_ids as $blog_id) { |
|
159 | + $return[] = new TimberSite($blog_id); |
|
160 | 160 | } |
161 | 161 | return $return; |
162 | 162 | } |
@@ -174,9 +174,9 @@ discard block |
||
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 |
||
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 | |
@@ -199,27 +199,27 @@ discard block |
||
199 | 199 | * @param bool $via_render |
200 | 200 | * @return bool|string |
201 | 201 | */ |
202 | - public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) { |
|
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 | |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | * @param array $data an array with data in it. |
231 | 231 | * @return bool|string |
232 | 232 | */ |
233 | - public static function compile_string( $string, $data = array() ) { |
|
233 | + public static function compile_string($string, $data = array()) { |
|
234 | 234 | $dummy_loader = new TimberLoader(); |
235 | 235 | $dummy_loader->get_twig(); |
236 | 236 | $loader = new Twig_Loader_String(); |
237 | - $twig = new Twig_Environment( $loader ); |
|
238 | - $twig = apply_filters( 'timber/twig/filters', $twig ); |
|
239 | - $twig = apply_filters( 'twig_apply_filters', $twig ); |
|
240 | - return $twig->render( $string, $data ); |
|
237 | + $twig = new Twig_Environment($loader); |
|
238 | + $twig = apply_filters('timber/twig/filters', $twig); |
|
239 | + $twig = apply_filters('twig_apply_filters', $twig); |
|
240 | + return $twig->render($string, $data); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | * @param string $cache_mode |
250 | 250 | * @return bool|string |
251 | 251 | */ |
252 | - public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
252 | + public static function fetch($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
253 | 253 | if ( $expires === true ) { |
254 | 254 | //if this is reading as true; the user probably is using the old $echo param |
255 | 255 | //so we should move all vars up by a spot |
256 | 256 | $expires = $cache_mode; |
257 | 257 | $cache_mode = TimberLoader::CACHE_USE_DEFAULT; |
258 | 258 | } |
259 | - $output = self::compile( $filenames, $data, $expires, $cache_mode, true ); |
|
260 | - $output = apply_filters( 'timber_compile_result', $output ); |
|
259 | + $output = self::compile($filenames, $data, $expires, $cache_mode, true); |
|
260 | + $output = apply_filters('timber_compile_result', $output); |
|
261 | 261 | return $output; |
262 | 262 | } |
263 | 263 | |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param string $cache_mode |
271 | 271 | * @return bool|string |
272 | 272 | */ |
273 | - public static function render( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
274 | - $output = static::fetch( $filenames, $data, $expires, $cache_mode ); |
|
273 | + public static function render($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
274 | + $output = static::fetch($filenames, $data, $expires, $cache_mode); |
|
275 | 275 | echo $output; |
276 | 276 | return $output; |
277 | 277 | } |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param array $data an array with data in it. |
284 | 284 | * @return bool|string |
285 | 285 | */ |
286 | - public static function render_string( $string, $data = array() ) { |
|
287 | - $compiled = self::compile_string( $string, $data ); |
|
286 | + public static function render_string($string, $data = array()) { |
|
287 | + $compiled = self::compile_string($string, $data); |
|
288 | 288 | echo $compiled; |
289 | 289 | return $compiled; |
290 | 290 | } |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | * @param array $data |
301 | 301 | * @return bool|string |
302 | 302 | */ |
303 | - public static function get_sidebar( $sidebar = '', $data = array() ) { |
|
303 | + public static function get_sidebar($sidebar = '', $data = array()) { |
|
304 | 304 | if ( $sidebar == '' ) { |
305 | 305 | $sidebar = 'sidebar.php'; |
306 | 306 | } |
307 | - if ( strstr( strtolower( $sidebar ), '.php' ) ) { |
|
308 | - return self::get_sidebar_from_php( $sidebar, $data ); |
|
307 | + if ( strstr(strtolower($sidebar), '.php') ) { |
|
308 | + return self::get_sidebar_from_php($sidebar, $data); |
|
309 | 309 | } |
310 | - return self::compile( $sidebar, $data ); |
|
310 | + return self::compile($sidebar, $data); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -317,21 +317,21 @@ discard block |
||
317 | 317 | * @param array $data |
318 | 318 | * @return string |
319 | 319 | */ |
320 | - public static function get_sidebar_from_php( $sidebar = '', $data ) { |
|
320 | + public static function get_sidebar_from_php($sidebar = '', $data) { |
|
321 | 321 | $caller = self::get_calling_script_dir(); |
322 | 322 | $loader = new TimberLoader(); |
323 | - $uris = $loader->get_locations( $caller ); |
|
323 | + $uris = $loader->get_locations($caller); |
|
324 | 324 | ob_start(); |
325 | 325 | $found = false; |
326 | - foreach ( $uris as $uri ) { |
|
327 | - if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) { |
|
328 | - include trailingslashit( $uri ) . $sidebar; |
|
326 | + foreach ($uris as $uri) { |
|
327 | + if ( file_exists(trailingslashit($uri) . $sidebar) ) { |
|
328 | + include trailingslashit($uri) . $sidebar; |
|
329 | 329 | $found = true; |
330 | 330 | break; |
331 | 331 | } |
332 | 332 | } |
333 | 333 | if ( !$found ) { |
334 | - TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' ); |
|
334 | + TimberHelper::error_log('error loading your sidebar, check to make sure the file exists'); |
|
335 | 335 | } |
336 | 336 | $ret = ob_get_contents(); |
337 | 337 | ob_end_clean(); |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * @param int $widget_id |
348 | 348 | * @return TimberFunctionWrapper |
349 | 349 | */ |
350 | - public static function get_widgets( $widget_id ) { |
|
351 | - return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) ); |
|
350 | + public static function get_widgets($widget_id) { |
|
351 | + return trim(TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true)); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | * @param array $args |
364 | 364 | * @deprecated since 0.20.0 |
365 | 365 | */ |
366 | - public static function add_route( $route, $callback, $args = array() ) { |
|
367 | - Routes::map( $route, $callback, $args ); |
|
366 | + public static function add_route($route, $callback, $args = array()) { |
|
367 | + Routes::map($route, $callback, $args); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @deprecated since 0.20.0 |
374 | 374 | */ |
375 | - public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
376 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
375 | + public static function load_template($template, $query = false, $status_code = 200, $tparams = false) { |
|
376 | + return Routes::load($template, $tparams, $query, $status_code); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | * |
382 | 382 | * @deprecated since 0.20.2 |
383 | 383 | */ |
384 | - public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
385 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
384 | + public static function load_view($template, $query = false, $status_code = 200, $tparams = false) { |
|
385 | + return Routes::load($template, $tparams, $query, $status_code); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -395,43 +395,43 @@ discard block |
||
395 | 395 | * @param array $prefs |
396 | 396 | * @return array mixed |
397 | 397 | */ |
398 | - public static function get_pagination( $prefs = array() ) { |
|
398 | + public static function get_pagination($prefs = array()) { |
|
399 | 399 | global $wp_query; |
400 | 400 | global $paged; |
401 | 401 | global $wp_rewrite; |
402 | 402 | $args = array(); |
403 | - $args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] ); |
|
403 | + $args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']); |
|
404 | 404 | if ( $wp_rewrite->using_permalinks() ) { |
405 | - $url = explode( '?', get_pagenum_link( 0 ) ); |
|
406 | - if ( isset( $url[1] ) ) { |
|
407 | - parse_str( $url[1], $query ); |
|
405 | + $url = explode('?', get_pagenum_link(0)); |
|
406 | + if ( isset($url[1]) ) { |
|
407 | + parse_str($url[1], $query); |
|
408 | 408 | $args['add_args'] = $query; |
409 | 409 | } |
410 | 410 | $args['format'] = 'page/%#%'; |
411 | - $args['base'] = trailingslashit( $url[0] ).'%_%'; |
|
411 | + $args['base'] = trailingslashit($url[0]) . '%_%'; |
|
412 | 412 | } else { |
413 | 413 | $big = 999999999; |
414 | - $args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ); |
|
414 | + $args['base'] = str_replace($big, '%#%', esc_url(get_pagenum_link($big))); |
|
415 | 415 | } |
416 | 416 | $args['type'] = 'array'; |
417 | - $args['current'] = max( 1, get_query_var( 'paged' ) ); |
|
418 | - $args['mid_size'] = max( 9 - $args['current'], 3 ); |
|
419 | - if ( is_int( $prefs ) ) { |
|
417 | + $args['current'] = max(1, get_query_var('paged')); |
|
418 | + $args['mid_size'] = max(9 - $args['current'], 3); |
|
419 | + if ( is_int($prefs) ) { |
|
420 | 420 | $args['mid_size'] = $prefs - 2; |
421 | 421 | } else { |
422 | - $args = array_merge( $args, $prefs ); |
|
422 | + $args = array_merge($args, $prefs); |
|
423 | 423 | } |
424 | 424 | $data = array(); |
425 | 425 | $data['current'] = $args['current']; |
426 | 426 | $data['total'] = $args['total']; |
427 | - $data['pages'] = TimberHelper::paginate_links( $args ); |
|
428 | - $next = get_next_posts_page_link( $args['total'] ); |
|
427 | + $data['pages'] = TimberHelper::paginate_links($args); |
|
428 | + $next = get_next_posts_page_link($args['total']); |
|
429 | 429 | if ( $next ) { |
430 | - $data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' ); |
|
430 | + $data['next'] = array('link' => untrailingslashit($next), 'class' => 'page-numbers next'); |
|
431 | 431 | } |
432 | - $prev = previous_posts( false ); |
|
432 | + $prev = previous_posts(false); |
|
433 | 433 | if ( $prev ) { |
434 | - $data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' ); |
|
434 | + $data['prev'] = array('link' => untrailingslashit($prev), 'class' => 'page-numbers prev'); |
|
435 | 435 | } |
436 | 436 | if ( $paged < 2 ) { |
437 | 437 | $data['prev'] = ''; |
@@ -447,10 +447,10 @@ discard block |
||
447 | 447 | * |
448 | 448 | * @return string |
449 | 449 | */ |
450 | - public static function get_calling_script_dir( $offset = 0 ) { |
|
451 | - $caller = self::get_calling_script_file( $offset ); |
|
452 | - if ( !is_null( $caller ) ) { |
|
453 | - $pathinfo = pathinfo( $caller ); |
|
450 | + public static function get_calling_script_dir($offset = 0) { |
|
451 | + $caller = self::get_calling_script_file($offset); |
|
452 | + if ( !is_null($caller) ) { |
|
453 | + $pathinfo = pathinfo($caller); |
|
454 | 454 | $dir = $pathinfo['dirname']; |
455 | 455 | return $dir; |
456 | 456 | } |
@@ -463,11 +463,11 @@ discard block |
||
463 | 463 | * @return string|null |
464 | 464 | * @deprecated since 0.20.0 |
465 | 465 | */ |
466 | - public static function get_calling_script_file( $offset = 0 ) { |
|
466 | + public static function get_calling_script_file($offset = 0) { |
|
467 | 467 | $caller = null; |
468 | 468 | $backtrace = debug_backtrace(); |
469 | 469 | $i = 0; |
470 | - foreach ( $backtrace as $trace ) { |
|
470 | + foreach ($backtrace as $trace) { |
|
471 | 471 | if ( array_key_exists('file', $trace) && $trace['file'] != __FILE__ ) { |
472 | 472 | $caller = $trace['file']; |
473 | 473 | break; |