@@ -136,7 +136,7 @@ |
||
136 | 136 | /** |
137 | 137 | * @param string $template |
138 | 138 | * |
139 | - * @return string|bool |
|
139 | + * @return false|string |
|
140 | 140 | */ |
141 | 141 | public function template_include( $template ) { |
142 | 142 |
@@ -11,12 +11,12 @@ discard block |
||
11 | 11 | /** |
12 | 12 | * @param array $values |
13 | 13 | */ |
14 | - public function __construct( $values = array() ) { |
|
14 | + public function __construct($values = array()) { |
|
15 | 15 | |
16 | 16 | $defaults['twig.options'] = array(); |
17 | 17 | $defaults['twig.directories'] = array(); |
18 | 18 | |
19 | - $defaults['twig.loader'] = function ( $meadow ) { |
|
19 | + $defaults['twig.loader'] = function($meadow) { |
|
20 | 20 | |
21 | 21 | // this needs to be lazy or theme switchers and alike explode it |
22 | 22 | |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | $calculated_dirs = array( |
26 | 26 | $stylesheet_dir, |
27 | 27 | $template_dir, |
28 | - plugin_dir_path( __DIR__ ) . 'twig', |
|
28 | + plugin_dir_path(__DIR__) . 'twig', |
|
29 | 29 | ); |
30 | 30 | |
31 | 31 | // enables explicit inheritance from parent theme in child |
32 | - if ( $stylesheet_dir !== $template_dir ) { |
|
33 | - $calculated_dirs[] = dirname( $template_dir ); |
|
32 | + if ($stylesheet_dir !== $template_dir) { |
|
33 | + $calculated_dirs[] = dirname($template_dir); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $directories = array_unique( |
@@ -40,33 +40,33 @@ discard block |
||
40 | 40 | ) |
41 | 41 | ); |
42 | 42 | |
43 | - return new \Twig_Loader_Filesystem( $directories ); |
|
43 | + return new \Twig_Loader_Filesystem($directories); |
|
44 | 44 | }; |
45 | 45 | |
46 | - $defaults['twig.undefined_function'] = array( __CLASS__, 'undefined_function' ); |
|
47 | - $defaults['twig.undefined_filter'] = array( __CLASS__, 'undefined_filter' ); |
|
46 | + $defaults['twig.undefined_function'] = array(__CLASS__, 'undefined_function'); |
|
47 | + $defaults['twig.undefined_filter'] = array(__CLASS__, 'undefined_filter'); |
|
48 | 48 | |
49 | - $defaults['twig.environment'] = function ( $meadow ) { |
|
50 | - $environment = new \Twig_Environment( $meadow['twig.loader'], $meadow['twig.options'] ); |
|
49 | + $defaults['twig.environment'] = function($meadow) { |
|
50 | + $environment = new \Twig_Environment($meadow['twig.loader'], $meadow['twig.options']); |
|
51 | 51 | $meadow_extension = new Extension(); |
52 | - $environment->addExtension( $meadow_extension ); |
|
53 | - $environment->registerUndefinedFunctionCallback( $meadow['twig.undefined_function'] ); |
|
54 | - $environment->registerUndefinedFilterCallback( $meadow['twig.undefined_filter'] ); |
|
52 | + $environment->addExtension($meadow_extension); |
|
53 | + $environment->registerUndefinedFunctionCallback($meadow['twig.undefined_function']); |
|
54 | + $environment->registerUndefinedFilterCallback($meadow['twig.undefined_filter']); |
|
55 | 55 | |
56 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
56 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
57 | 57 | $debug_extension = new \Twig_Extension_Debug(); |
58 | - $environment->addExtension( $debug_extension ); |
|
58 | + $environment->addExtension($debug_extension); |
|
59 | 59 | $environment->enableDebug(); |
60 | 60 | } |
61 | 61 | |
62 | 62 | return $environment; |
63 | 63 | }; |
64 | 64 | |
65 | - $defaults['hierarchy'] = function () { |
|
65 | + $defaults['hierarchy'] = function() { |
|
66 | 66 | return new Template_Hierarchy(); |
67 | 67 | }; |
68 | 68 | |
69 | - parent::__construct( array_merge( $defaults, $values ) ); |
|
69 | + parent::__construct(array_merge($defaults, $values)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return bool|\Twig_SimpleFunction |
78 | 78 | */ |
79 | - static function undefined_function( $function_name ) { |
|
79 | + static function undefined_function($function_name) { |
|
80 | 80 | |
81 | - if ( function_exists( $function_name ) ) { |
|
81 | + if (function_exists($function_name)) { |
|
82 | 82 | return new \Twig_SimpleFunction( |
83 | 83 | $function_name, |
84 | - function () use ( $function_name ) { |
|
84 | + function() use ($function_name) { |
|
85 | 85 | |
86 | 86 | ob_start(); |
87 | - $return = call_user_func_array( $function_name, func_get_args() ); |
|
87 | + $return = call_user_func_array($function_name, func_get_args()); |
|
88 | 88 | $echo = ob_get_clean(); |
89 | 89 | |
90 | - return empty( $echo ) ? $return : $echo; |
|
90 | + return empty($echo) ? $return : $echo; |
|
91 | 91 | }, |
92 | - array( 'is_safe' => array( 'all' ) ) |
|
92 | + array('is_safe' => array('all')) |
|
93 | 93 | ); |
94 | 94 | } |
95 | 95 | |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return bool|\Twig_SimpleFilter |
105 | 105 | */ |
106 | - static function undefined_filter( $filter_name ) { |
|
106 | + static function undefined_filter($filter_name) { |
|
107 | 107 | |
108 | 108 | return new \Twig_SimpleFilter( |
109 | 109 | $filter_name, |
110 | - function () use ( $filter_name ) { |
|
110 | + function() use ($filter_name) { |
|
111 | 111 | |
112 | - return apply_filters( $filter_name, func_get_arg( 0 ) ); |
|
112 | + return apply_filters($filter_name, func_get_arg(0)); |
|
113 | 113 | }, |
114 | - array( 'is_safe' => array( 'all' ) ) |
|
114 | + array('is_safe' => array('all')) |
|
115 | 115 | ); |
116 | 116 | } |
117 | 117 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | /** @var Template_Hierarchy $hierarchy */ |
121 | 121 | $hierarchy = $this['hierarchy']; |
122 | 122 | $hierarchy->enable(); |
123 | - add_filter( 'template_include', array( $this, 'template_include' ) ); |
|
124 | - add_filter( 'get_search_form', array( $this, 'get_search_form' ), 9 ); |
|
123 | + add_filter('template_include', array($this, 'template_include')); |
|
124 | + add_filter('get_search_form', array($this, 'get_search_form'), 9); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | public function disable() { |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | /** @var Template_Hierarchy $hierarchy */ |
130 | 130 | $hierarchy = $this['hierarchy']; |
131 | 131 | $hierarchy->disable(); |
132 | - remove_filter( 'template_include', array( $this, 'template_include' ) ); |
|
133 | - remove_filter( 'get_search_form', array( $this, 'get_search_form' ), 9 ); |
|
132 | + remove_filter('template_include', array($this, 'template_include')); |
|
133 | + remove_filter('get_search_form', array($this, 'get_search_form'), 9); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return string|bool |
140 | 140 | */ |
141 | - public function template_include( $template ) { |
|
141 | + public function template_include($template) { |
|
142 | 142 | |
143 | - if ( '.twig' === substr( $template, - 5 ) ) { |
|
143 | + if ('.twig' === substr($template, - 5)) { |
|
144 | 144 | /** @var \Twig_Environment $twig */ |
145 | 145 | $twig = $this['twig.environment']; |
146 | 146 | |
147 | - echo $twig->render( basename( $template ), apply_filters( 'meadow_context', array() ) ); |
|
147 | + echo $twig->render(basename($template), apply_filters('meadow_context', array())); |
|
148 | 148 | |
149 | 149 | return false; |
150 | 150 | } |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - public function get_search_form( $form ) { |
|
160 | + public function get_search_form($form) { |
|
161 | 161 | |
162 | 162 | // because first time it's action |
163 | - if ( ! empty( $form ) ) { |
|
163 | + if ( ! empty($form)) { |
|
164 | 164 | /** @var \Twig_Environment $twig */ |
165 | 165 | $twig = $this['twig.environment']; |
166 | 166 | |
167 | - return $twig->render( 'searchform.twig', array() ); |
|
167 | + return $twig->render('searchform.twig', array()); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return $form; |
@@ -11,13 +11,13 @@ |
||
11 | 11 | /** |
12 | 12 | * @param Twig_Compiler $compiler |
13 | 13 | */ |
14 | - public function compile( Twig_Compiler $compiler ) { |
|
14 | + public function compile(Twig_Compiler $compiler) { |
|
15 | 15 | |
16 | 16 | $compiler |
17 | - ->addDebugInfo( $this ) |
|
18 | - ->write( '$callback = function() {' ) |
|
19 | - ->subcompile( $this->getNode( 'callback' ) ) |
|
20 | - ->write( '};' ) |
|
21 | - ->write( 'wp_list_comments( array( \'callback\' => $callback ) );' ); |
|
17 | + ->addDebugInfo($this) |
|
18 | + ->write('$callback = function() {') |
|
19 | + ->subcompile($this->getNode('callback')) |
|
20 | + ->write('};') |
|
21 | + ->write('wp_list_comments( array( \'callback\' => $callback ) );'); |
|
22 | 22 | } |
23 | 23 | } |
24 | 24 | \ No newline at end of file |
@@ -13,23 +13,23 @@ |
||
13 | 13 | /** |
14 | 14 | * @param Twig_Compiler $compiler |
15 | 15 | */ |
16 | - public function compile( Twig_Compiler $compiler ) { |
|
16 | + public function compile(Twig_Compiler $compiler) { |
|
17 | 17 | |
18 | - $compiler->addDebugInfo( $this ); |
|
18 | + $compiler->addDebugInfo($this); |
|
19 | 19 | |
20 | - if ( $this->hasNode( 'query' ) ) { |
|
20 | + if ($this->hasNode('query')) { |
|
21 | 21 | $compiler |
22 | - ->write( '$loop = new WP_Query(' ) |
|
23 | - ->subcompile( $this->getNode( 'query' ) ) |
|
24 | - ->raw( ");\n" ) |
|
25 | - ->write( 'while( $loop->have_posts() ) : $loop->the_post();' . "\n" ); // TODO nested loops |
|
22 | + ->write('$loop = new WP_Query(') |
|
23 | + ->subcompile($this->getNode('query')) |
|
24 | + ->raw(");\n") |
|
25 | + ->write('while( $loop->have_posts() ) : $loop->the_post();' . "\n"); // TODO nested loops |
|
26 | 26 | } |
27 | 27 | else { |
28 | - $compiler->write( 'while( have_posts() ) : the_post();' . "\n" ); |
|
28 | + $compiler->write('while( have_posts() ) : the_post();' . "\n"); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | $compiler |
32 | - ->subcompile( $this->getNode( 'body' ) ) |
|
33 | - ->write( 'endwhile;' . "\n" ); |
|
32 | + ->subcompile($this->getNode('body')) |
|
33 | + ->write('endwhile;' . "\n"); |
|
34 | 34 | } |
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -23,8 +23,7 @@ |
||
23 | 23 | ->subcompile( $this->getNode( 'query' ) ) |
24 | 24 | ->raw( ");\n" ) |
25 | 25 | ->write( 'while( $loop->have_posts() ) : $loop->the_post();' . "\n" ); // TODO nested loops |
26 | - } |
|
27 | - else { |
|
26 | + } else { |
|
28 | 27 | $compiler->write( 'while( have_posts() ) : the_post();' . "\n" ); |
29 | 28 | } |
30 | 29 |
@@ -56,8 +56,9 @@ |
||
56 | 56 | |
57 | 57 | $templates = array(); |
58 | 58 | |
59 | - if ( ! empty( $name ) ) |
|
60 | - $templates[] = "{$slug}-{$name}.twig"; |
|
59 | + if ( ! empty( $name ) ) { |
|
60 | + $templates[] = "{$slug}-{$name}.twig"; |
|
61 | + } |
|
61 | 62 | |
62 | 63 | $templates[] = "{$slug}.twig"; |
63 | 64 |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | $options = array( |
17 | 17 | 'needs_environment' => true, |
18 | 18 | 'needs_context' => true, |
19 | - 'is_safe' => array( 'all' ) |
|
19 | + 'is_safe' => array('all') |
|
20 | 20 | ); |
21 | 21 | |
22 | 22 | $functions = array(); |
23 | 23 | |
24 | - foreach ( array( 'get_header', 'get_footer', 'get_sidebar', 'get_template_part', 'get_search_form', 'comments_template' ) as $function ) { |
|
25 | - $functions[] = new \Twig_SimpleFunction( $function, array( $this, $function ), $options ); |
|
24 | + foreach (array('get_header', 'get_footer', 'get_sidebar', 'get_template_part', 'get_search_form', 'comments_template') as $function) { |
|
25 | + $functions[] = new \Twig_SimpleFunction($function, array($this, $function), $options); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | return $functions; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | global $wp_query; |
34 | 34 | |
35 | - return compact( 'wp_query' ); |
|
35 | + return compact('wp_query'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getTokenParsers( ) { |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | ); |
44 | 44 | } |
45 | 45 | |
46 | - public function get_header( \Twig_Environment $env, $context, $name = null ) { |
|
46 | + public function get_header(\Twig_Environment $env, $context, $name = null) { |
|
47 | 47 | |
48 | - return $this->get_template( $env, $context, 'header', $name ); |
|
48 | + return $this->get_template($env, $context, 'header', $name); |
|
49 | 49 | } |
50 | 50 | |
51 | - public function get_templates( $slug, $name = null ) { |
|
51 | + public function get_templates($slug, $name = null) { |
|
52 | 52 | |
53 | 53 | $templates = array(); |
54 | 54 | |
55 | - if ( ! empty( $name ) ) |
|
55 | + if ( ! empty($name)) |
|
56 | 56 | $templates[] = "{$slug}-{$name}.twig"; |
57 | 57 | |
58 | 58 | $templates[] = "{$slug}.twig"; |
@@ -60,24 +60,24 @@ discard block |
||
60 | 60 | return $templates; |
61 | 61 | } |
62 | 62 | |
63 | - public function get_footer( \Twig_Environment $env, $context, $name = null ) { |
|
63 | + public function get_footer(\Twig_Environment $env, $context, $name = null) { |
|
64 | 64 | |
65 | - return $this->get_template( $env, $context, 'footer', $name ); |
|
65 | + return $this->get_template($env, $context, 'footer', $name); |
|
66 | 66 | } |
67 | 67 | |
68 | - public function get_sidebar( \Twig_Environment $env, $context, $name = null ) { |
|
68 | + public function get_sidebar(\Twig_Environment $env, $context, $name = null) { |
|
69 | 69 | |
70 | - return $this->get_template( $env, $context, 'sidebar', $name ); |
|
70 | + return $this->get_template($env, $context, 'sidebar', $name); |
|
71 | 71 | } |
72 | 72 | |
73 | - public function get_template_part( \Twig_Environment $env, $context, $slug, $name = null ) { |
|
73 | + public function get_template_part(\Twig_Environment $env, $context, $slug, $name = null) { |
|
74 | 74 | |
75 | 75 | try { |
76 | - $return = twig_include( $env, $context, $this->get_templates( $slug, $name ) ); |
|
77 | - do_action( "get_template_part_{$slug}", $slug, $name ); |
|
78 | - } catch ( \Twig_Error_Loader $e ) { |
|
76 | + $return = twig_include($env, $context, $this->get_templates($slug, $name)); |
|
77 | + do_action("get_template_part_{$slug}", $slug, $name); |
|
78 | + } catch (\Twig_Error_Loader $e) { |
|
79 | 79 | ob_start(); |
80 | - get_template_part( $slug, $name ); |
|
80 | + get_template_part($slug, $name); |
|
81 | 81 | $return = ob_get_clean(); |
82 | 82 | } |
83 | 83 | |
@@ -91,39 +91,39 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function get_search_form() { |
93 | 93 | |
94 | - return apply_filters( 'get_search_form', true ); |
|
94 | + return apply_filters('get_search_form', true); |
|
95 | 95 | } |
96 | 96 | |
97 | - protected function get_template( \Twig_Environment $env, $context, $type, $name = null ) { |
|
97 | + protected function get_template(\Twig_Environment $env, $context, $type, $name = null) { |
|
98 | 98 | |
99 | 99 | try { |
100 | - $return = twig_include( $env, $context, $this->get_templates( $type, $name ) ); |
|
101 | - do_action( 'get_' . $type, $name ); |
|
102 | - } catch ( \Twig_Error_Loader $e ) { |
|
100 | + $return = twig_include($env, $context, $this->get_templates($type, $name)); |
|
101 | + do_action('get_' . $type, $name); |
|
102 | + } catch (\Twig_Error_Loader $e) { |
|
103 | 103 | ob_start(); |
104 | - call_user_func( 'get_' . $type, $name ); |
|
104 | + call_user_func('get_' . $type, $name); |
|
105 | 105 | $return = ob_get_clean(); |
106 | 106 | } |
107 | 107 | |
108 | 108 | return $return; |
109 | 109 | } |
110 | 110 | |
111 | - public function comments_template( \Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false ) { |
|
111 | + public function comments_template(\Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false) { |
|
112 | 112 | |
113 | 113 | try { |
114 | - $env->loadTemplate( $file ); |
|
115 | - } catch ( \Twig_Error_Loader $e ) { |
|
114 | + $env->loadTemplate($file); |
|
115 | + } catch (\Twig_Error_Loader $e) { |
|
116 | 116 | ob_start(); |
117 | - comments_template( '/comments.php', $separate_comments ); |
|
117 | + comments_template('/comments.php', $separate_comments); |
|
118 | 118 | |
119 | 119 | return ob_get_clean(); |
120 | 120 | } |
121 | 121 | |
122 | - add_filter( 'comments_template', array( $this, 'return_blank_template' ) ); |
|
123 | - comments_template( '/comments.php', $separate_comments ); |
|
124 | - remove_filter( 'comments_template', array( $this, 'return_blank_template' ) ); |
|
122 | + add_filter('comments_template', array($this, 'return_blank_template')); |
|
123 | + comments_template('/comments.php', $separate_comments); |
|
124 | + remove_filter('comments_template', array($this, 'return_blank_template')); |
|
125 | 125 | |
126 | - return twig_include( $env, $context, $file ); |
|
126 | + return twig_include($env, $context, $file); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | public function return_blank_template() { |
@@ -12,17 +12,17 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @return Loop_Node |
14 | 14 | */ |
15 | - public function parse( Twig_Token $token ) { |
|
15 | + public function parse(Twig_Token $token) { |
|
16 | 16 | |
17 | 17 | $nodes = array(); |
18 | 18 | $parser = $this->parser; |
19 | 19 | $stream = $parser->getStream(); |
20 | 20 | |
21 | - $stream->expect( Twig_Token::BLOCK_END_TYPE ); |
|
22 | - $nodes['callback'] = $parser->subparse( array( $this, 'decide_comments_end' ), true ); |
|
23 | - $stream->expect( Twig_Token::BLOCK_END_TYPE ); |
|
21 | + $stream->expect(Twig_Token::BLOCK_END_TYPE); |
|
22 | + $nodes['callback'] = $parser->subparse(array($this, 'decide_comments_end'), true); |
|
23 | + $stream->expect(Twig_Token::BLOCK_END_TYPE); |
|
24 | 24 | |
25 | - return new Comments_Node( $nodes, array(), $token->getLine(), $this->getTag() ); |
|
25 | + return new Comments_Node($nodes, array(), $token->getLine(), $this->getTag()); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return bool |
40 | 40 | */ |
41 | - public function decide_comments_end( Twig_Token $token ) { |
|
42 | - return $token->test( 'endcomments' ); |
|
41 | + public function decide_comments_end(Twig_Token $token) { |
|
42 | + return $token->test('endcomments'); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | \ No newline at end of file |
@@ -13,20 +13,20 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @return Loop_Node |
15 | 15 | */ |
16 | - public function parse( Twig_Token $token ) { |
|
16 | + public function parse(Twig_Token $token) { |
|
17 | 17 | |
18 | 18 | $nodes = array(); |
19 | 19 | $parser = $this->parser; |
20 | 20 | $stream = $parser->getStream(); |
21 | 21 | |
22 | - if ( ! $stream->getCurrent()->test( Twig_Token::BLOCK_END_TYPE ) ) |
|
22 | + if ( ! $stream->getCurrent()->test(Twig_Token::BLOCK_END_TYPE)) |
|
23 | 23 | $nodes['query'] = $parser->getExpressionParser()->parseExpression(); |
24 | 24 | |
25 | - $stream->expect( Twig_Token::BLOCK_END_TYPE ); |
|
26 | - $nodes['body'] = $parser->subparse( array( $this, 'decide_loop_end' ), true ); |
|
27 | - $stream->expect( Twig_Token::BLOCK_END_TYPE ); |
|
25 | + $stream->expect(Twig_Token::BLOCK_END_TYPE); |
|
26 | + $nodes['body'] = $parser->subparse(array($this, 'decide_loop_end'), true); |
|
27 | + $stream->expect(Twig_Token::BLOCK_END_TYPE); |
|
28 | 28 | |
29 | - return new Loop_Node( $nodes, array(), $token->getLine(), $this->getTag() ); |
|
29 | + return new Loop_Node($nodes, array(), $token->getLine(), $this->getTag()); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function decide_loop_end( Twig_Token $token ) { |
|
46 | - return $token->test( 'endloop' ); |
|
45 | + public function decide_loop_end(Twig_Token $token) { |
|
46 | + return $token->test('endloop'); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -19,8 +19,9 @@ |
||
19 | 19 | $parser = $this->parser; |
20 | 20 | $stream = $parser->getStream(); |
21 | 21 | |
22 | - if ( ! $stream->getCurrent()->test( Twig_Token::BLOCK_END_TYPE ) ) |
|
23 | - $nodes['query'] = $parser->getExpressionParser()->parseExpression(); |
|
22 | + if ( ! $stream->getCurrent()->test( Twig_Token::BLOCK_END_TYPE ) ) { |
|
23 | + $nodes['query'] = $parser->getExpressionParser()->parseExpression(); |
|
24 | + } |
|
24 | 25 | |
25 | 26 | $stream->expect( Twig_Token::BLOCK_END_TYPE ); |
26 | 27 | $nodes['body'] = $parser->subparse( array( $this, 'decide_loop_end' ), true ); |
@@ -56,8 +56,9 @@ discard block |
||
56 | 56 | if ( is_attachment() ) { |
57 | 57 | global $posts; |
58 | 58 | |
59 | - if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) |
|
60 | - $this->mime_type = explode( '/', $posts[0]->post_mime_type ); |
|
59 | + if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) { |
|
60 | + $this->mime_type = explode( '/', $posts[0]->post_mime_type ); |
|
61 | + } |
|
61 | 62 | |
62 | 63 | add_filter( "{$this->mime_type[0]}_template", array( $this, 'query_template' ) ); |
63 | 64 | add_filter( "{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
@@ -99,8 +100,9 @@ discard block |
||
99 | 100 | case 'single': |
100 | 101 | $object = get_queried_object(); |
101 | 102 | |
102 | - if ( $object ) |
|
103 | - $templates[] = "single-{$object->post_type}.twig"; |
|
103 | + if ( $object ) { |
|
104 | + $templates[] = "single-{$object->post_type}.twig"; |
|
105 | + } |
|
104 | 106 | |
105 | 107 | $templates[] = 'single.twig'; |
106 | 108 | break; |
@@ -120,11 +122,13 @@ discard block |
||
120 | 122 | // if ( $template && 0 === validate_file( $template ) ) |
121 | 123 | // $templates[] = $template; |
122 | 124 | |
123 | - if ( $pagename ) |
|
124 | - $templates[] = "page-{$pagename}.twig"; |
|
125 | + if ( $pagename ) { |
|
126 | + $templates[] = "page-{$pagename}.twig"; |
|
127 | + } |
|
125 | 128 | |
126 | - if ( $page_id ) |
|
127 | - $templates[] = "page-{$page_id}.twig"; |
|
129 | + if ( $page_id ) { |
|
130 | + $templates[] = "page-{$page_id}.twig"; |
|
131 | + } |
|
128 | 132 | |
129 | 133 | $templates[] = 'page.twig'; |
130 | 134 | break; |
@@ -30,39 +30,39 @@ discard block |
||
30 | 30 | |
31 | 31 | public function enable() { |
32 | 32 | |
33 | - add_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
|
33 | + add_action('template_redirect', array($this, 'template_redirect')); |
|
34 | 34 | |
35 | - foreach ( $this->template_types as $type ) { |
|
36 | - add_filter( "{$type}_template", array( $this, 'query_template' ) ); |
|
35 | + foreach ($this->template_types as $type) { |
|
36 | + add_filter("{$type}_template", array($this, 'query_template')); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function disable() { |
41 | 41 | |
42 | - remove_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
|
42 | + remove_action('template_redirect', array($this, 'template_redirect')); |
|
43 | 43 | |
44 | - foreach ( $this->template_types as $type ) { |
|
45 | - remove_filter( "{$type}_template", array( $this, 'query_template' ) ); |
|
44 | + foreach ($this->template_types as $type) { |
|
45 | + remove_filter("{$type}_template", array($this, 'query_template')); |
|
46 | 46 | } |
47 | 47 | |
48 | - if ( ! empty($this->mime_type) ) { |
|
49 | - remove_filter( "{$this->mime_type[0]}_template", array( $this, 'query_template' ) ); |
|
50 | - remove_filter( "{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
51 | - remove_filter( "{$this->mime_type[0]}{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
48 | + if ( ! empty($this->mime_type)) { |
|
49 | + remove_filter("{$this->mime_type[0]}_template", array($this, 'query_template')); |
|
50 | + remove_filter("{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
51 | + remove_filter("{$this->mime_type[0]}{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | 55 | public function template_redirect() { |
56 | 56 | |
57 | - if ( is_attachment() ) { |
|
57 | + if (is_attachment()) { |
|
58 | 58 | global $posts; |
59 | 59 | |
60 | - if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) |
|
61 | - $this->mime_type = explode( '/', $posts[0]->post_mime_type ); |
|
60 | + if ( ! empty($posts) && isset($posts[0]->post_mime_type)) |
|
61 | + $this->mime_type = explode('/', $posts[0]->post_mime_type); |
|
62 | 62 | |
63 | - add_filter( "{$this->mime_type[0]}_template", array( $this, 'query_template' ) ); |
|
64 | - add_filter( "{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
65 | - add_filter( "{$this->mime_type[0]}{$this->mime_type[1]}_template", array( $this, 'query_template' ) ); |
|
63 | + add_filter("{$this->mime_type[0]}_template", array($this, 'query_template')); |
|
64 | + add_filter("{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
65 | + add_filter("{$this->mime_type[0]}{$this->mime_type[1]}_template", array($this, 'query_template')); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
@@ -71,16 +71,16 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - public function query_template( $fallback ) { |
|
74 | + public function query_template($fallback) { |
|
75 | 75 | |
76 | - $type = substr( current_filter(), 0, - 9 ); // trim '_template' from end |
|
76 | + $type = substr(current_filter(), 0, - 9); // trim '_template' from end |
|
77 | 77 | $templates = array(); |
78 | 78 | |
79 | - switch ( $type ) { |
|
79 | + switch ($type) { |
|
80 | 80 | case 'taxonomy': |
81 | 81 | $term = get_queried_object(); |
82 | 82 | |
83 | - if ( $term ) { |
|
83 | + if ($term) { |
|
84 | 84 | $taxonomy = $term->taxonomy; |
85 | 85 | $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.twig"; |
86 | 86 | $templates[] = "taxonomy-{$taxonomy}.twig"; |
@@ -90,17 +90,17 @@ discard block |
||
90 | 90 | break; |
91 | 91 | |
92 | 92 | case 'frontpage': |
93 | - $templates = array( 'front-page.twig' ); |
|
93 | + $templates = array('front-page.twig'); |
|
94 | 94 | break; |
95 | 95 | |
96 | 96 | case 'home': |
97 | - $templates = array( 'home.twig', 'index.twig' ); |
|
97 | + $templates = array('home.twig', 'index.twig'); |
|
98 | 98 | break; |
99 | 99 | |
100 | 100 | case 'single': |
101 | 101 | $object = get_queried_object(); |
102 | 102 | |
103 | - if ( $object ) |
|
103 | + if ($object) |
|
104 | 104 | $templates[] = "single-{$object->post_type}.twig"; |
105 | 105 | |
106 | 106 | $templates[] = 'single.twig'; |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | case 'page': |
110 | 110 | $page_id = get_queried_object_id(); |
111 | 111 | // $template = get_page_template_slug(); |
112 | - $pagename = get_query_var( 'pagename' ); |
|
112 | + $pagename = get_query_var('pagename'); |
|
113 | 113 | |
114 | - if ( ! $pagename && $page_id ) { |
|
114 | + if ( ! $pagename && $page_id) { |
|
115 | 115 | // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object |
116 | 116 | $post = get_queried_object(); |
117 | 117 | $pagename = $post->post_name; |
@@ -121,24 +121,24 @@ discard block |
||
121 | 121 | // if ( $template && 0 === validate_file( $template ) ) |
122 | 122 | // $templates[] = $template; |
123 | 123 | |
124 | - if ( $pagename ) |
|
124 | + if ($pagename) |
|
125 | 125 | $templates[] = "page-{$pagename}.twig"; |
126 | 126 | |
127 | - if ( $page_id ) |
|
127 | + if ($page_id) |
|
128 | 128 | $templates[] = "page-{$page_id}.twig"; |
129 | 129 | |
130 | 130 | $templates[] = 'page.twig'; |
131 | 131 | break; |
132 | 132 | |
133 | 133 | case 'singular': |
134 | - $templates = [ 'singular.twig' ]; |
|
134 | + $templates = ['singular.twig']; |
|
135 | 135 | break; |
136 | 136 | |
137 | 137 | case 'category': |
138 | 138 | case 'tag': |
139 | 139 | $term = get_queried_object(); |
140 | 140 | |
141 | - if ( $term ) { |
|
141 | + if ($term) { |
|
142 | 142 | $templates[] = "{$type}-{$term->slug}.twig"; |
143 | 143 | $templates[] = "{$type}-{$term->term_id}.twig"; |
144 | 144 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | case 'author': |
150 | 150 | $author = get_queried_object(); |
151 | 151 | |
152 | - if ( $author ) { |
|
152 | + if ($author) { |
|
153 | 153 | $templates[] = "author-{$author->user_nicename}.twig"; |
154 | 154 | $templates[] = "author-{$author->ID}.twig"; |
155 | 155 | } |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | break; |
159 | 159 | |
160 | 160 | case 'archive': |
161 | - $post_types = array_filter( (array) get_query_var( 'post_type' ) ); |
|
161 | + $post_types = array_filter((array) get_query_var('post_type')); |
|
162 | 162 | |
163 | - if ( count( $post_types ) == 1 ) { |
|
164 | - $post_type = reset( $post_types ); |
|
163 | + if (count($post_types) == 1) { |
|
164 | + $post_type = reset($post_types); |
|
165 | 165 | $templates[] = "archive-{$post_type}.twig"; |
166 | 166 | } |
167 | 167 | |
@@ -169,16 +169,16 @@ discard block |
||
169 | 169 | break; |
170 | 170 | |
171 | 171 | default: |
172 | - $templates = array( "{$type}.twig" ); |
|
172 | + $templates = array("{$type}.twig"); |
|
173 | 173 | } |
174 | 174 | |
175 | - $template = $this->locate_template( $templates ); |
|
175 | + $template = $this->locate_template($templates); |
|
176 | 176 | |
177 | - if ( empty( $template ) ) { |
|
177 | + if (empty($template)) { |
|
178 | 178 | $template = $fallback; |
179 | 179 | } |
180 | 180 | |
181 | - return apply_filters( 'meadow_query_template', $template, $type ); |
|
181 | + return apply_filters('meadow_query_template', $template, $type); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - public function locate_template( $templates ) { |
|
191 | + public function locate_template($templates) { |
|
192 | 192 | |
193 | - return locate_template( $templates ); |
|
193 | + return locate_template($templates); |
|
194 | 194 | } |
195 | 195 | } |