@@ -3,180 +3,180 @@ |
||
3 | 3 | class TimberTermGetter |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param string|array $args |
|
8 | - * @param array $maybe_args |
|
9 | - * @param string $TermClass |
|
10 | - * @return mixed |
|
11 | - */ |
|
12 | - public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){ |
|
13 | - if (is_string($maybe_args) && !strstr($maybe_args, '=')){ |
|
14 | - //the user is sending the $TermClass in the second argument |
|
15 | - $TermClass = $maybe_args; |
|
16 | - } |
|
17 | - if (is_string($maybe_args) && strstr($maybe_args, '=')){ |
|
18 | - parse_str($maybe_args, $maybe_args); |
|
19 | - } |
|
20 | - if (is_string($args) && strstr($args, '=')){ |
|
21 | - //a string and a query string! |
|
22 | - $parsed = TimberTermGetter::get_term_query_from_query_string($args); |
|
23 | - if (is_array($maybe_args)){ |
|
24 | - $parsed->args = array_merge($parsed->args, $maybe_args); |
|
25 | - } |
|
26 | - return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
27 | - } else if (is_string($args)){ |
|
28 | - //its just a string with a single taxonomy |
|
29 | - $parsed = TimberTermGetter::get_term_query_from_string($args); |
|
30 | - if (is_array($maybe_args)){ |
|
31 | - $parsed->args = array_merge($parsed->args, $maybe_args); |
|
32 | - } |
|
33 | - return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
34 | - } else if (is_array($args) && TimberHelper::is_array_assoc($args)){ |
|
35 | - //its an associative array, like a good ole query |
|
36 | - $parsed = TimberTermGetter::get_term_query_from_assoc_array($args); |
|
37 | - return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
38 | - } else if (is_array($args)){ |
|
39 | - //its just an array of strings or IDs (hopefully) |
|
40 | - $parsed = TimberTermGetter::get_term_query_from_array($args); |
|
41 | - if (is_array($maybe_args)){ |
|
42 | - $parsed->args = array_merge($parsed->args, $maybe_args); |
|
43 | - } |
|
44 | - return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
45 | - } else if (is_null($args)) { |
|
46 | - return self::handle_term_query(get_taxonomies(), array(), $TermClass); |
|
47 | - } |
|
48 | - return null; |
|
49 | - } |
|
6 | + /** |
|
7 | + * @param string|array $args |
|
8 | + * @param array $maybe_args |
|
9 | + * @param string $TermClass |
|
10 | + * @return mixed |
|
11 | + */ |
|
12 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){ |
|
13 | + if (is_string($maybe_args) && !strstr($maybe_args, '=')){ |
|
14 | + //the user is sending the $TermClass in the second argument |
|
15 | + $TermClass = $maybe_args; |
|
16 | + } |
|
17 | + if (is_string($maybe_args) && strstr($maybe_args, '=')){ |
|
18 | + parse_str($maybe_args, $maybe_args); |
|
19 | + } |
|
20 | + if (is_string($args) && strstr($args, '=')){ |
|
21 | + //a string and a query string! |
|
22 | + $parsed = TimberTermGetter::get_term_query_from_query_string($args); |
|
23 | + if (is_array($maybe_args)){ |
|
24 | + $parsed->args = array_merge($parsed->args, $maybe_args); |
|
25 | + } |
|
26 | + return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
27 | + } else if (is_string($args)){ |
|
28 | + //its just a string with a single taxonomy |
|
29 | + $parsed = TimberTermGetter::get_term_query_from_string($args); |
|
30 | + if (is_array($maybe_args)){ |
|
31 | + $parsed->args = array_merge($parsed->args, $maybe_args); |
|
32 | + } |
|
33 | + return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
34 | + } else if (is_array($args) && TimberHelper::is_array_assoc($args)){ |
|
35 | + //its an associative array, like a good ole query |
|
36 | + $parsed = TimberTermGetter::get_term_query_from_assoc_array($args); |
|
37 | + return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
38 | + } else if (is_array($args)){ |
|
39 | + //its just an array of strings or IDs (hopefully) |
|
40 | + $parsed = TimberTermGetter::get_term_query_from_array($args); |
|
41 | + if (is_array($maybe_args)){ |
|
42 | + $parsed->args = array_merge($parsed->args, $maybe_args); |
|
43 | + } |
|
44 | + return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
|
45 | + } else if (is_null($args)) { |
|
46 | + return self::handle_term_query(get_taxonomies(), array(), $TermClass); |
|
47 | + } |
|
48 | + return null; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string|array $taxonomies |
|
53 | - * @param string|array $args |
|
54 | - * @param string $TermClass |
|
55 | - * @return mixed |
|
56 | - */ |
|
57 | - public static function handle_term_query($taxonomies, $args, $TermClass){ |
|
58 | - if (!isset($args['hide_empty'])){ |
|
59 | - $args['hide_empty'] = false; |
|
60 | - } |
|
61 | - if (isset($args['term_id']) && is_int($args['term_id'])){ |
|
62 | - $args['term_id'] = array($args['term_id']); |
|
63 | - } |
|
64 | - if (isset($args['term_id'])){ |
|
65 | - $args['include'] = $args['term_id']; |
|
66 | - } |
|
67 | - $terms = get_terms($taxonomies, $args); |
|
68 | - foreach($terms as &$term){ |
|
69 | - $term = new $TermClass($term->term_id, $term->taxonomy); |
|
70 | - } |
|
71 | - return $terms; |
|
72 | - } |
|
51 | + /** |
|
52 | + * @param string|array $taxonomies |
|
53 | + * @param string|array $args |
|
54 | + * @param string $TermClass |
|
55 | + * @return mixed |
|
56 | + */ |
|
57 | + public static function handle_term_query($taxonomies, $args, $TermClass){ |
|
58 | + if (!isset($args['hide_empty'])){ |
|
59 | + $args['hide_empty'] = false; |
|
60 | + } |
|
61 | + if (isset($args['term_id']) && is_int($args['term_id'])){ |
|
62 | + $args['term_id'] = array($args['term_id']); |
|
63 | + } |
|
64 | + if (isset($args['term_id'])){ |
|
65 | + $args['include'] = $args['term_id']; |
|
66 | + } |
|
67 | + $terms = get_terms($taxonomies, $args); |
|
68 | + foreach($terms as &$term){ |
|
69 | + $term = new $TermClass($term->term_id, $term->taxonomy); |
|
70 | + } |
|
71 | + return $terms; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $query_string |
|
76 | - * @return stdClass |
|
77 | - */ |
|
78 | - public static function get_term_query_from_query_string($query_string) { |
|
79 | - $args = array(); |
|
80 | - parse_str($query_string, $args); |
|
81 | - $ret = self::get_term_query_from_assoc_array($args); |
|
82 | - return $ret; |
|
83 | - } |
|
74 | + /** |
|
75 | + * @param string $query_string |
|
76 | + * @return stdClass |
|
77 | + */ |
|
78 | + public static function get_term_query_from_query_string($query_string) { |
|
79 | + $args = array(); |
|
80 | + parse_str($query_string, $args); |
|
81 | + $ret = self::get_term_query_from_assoc_array($args); |
|
82 | + return $ret; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param string $taxs |
|
87 | - * @return stdClass |
|
88 | - */ |
|
89 | - public static function get_term_query_from_string($taxs) { |
|
90 | - $ret = new stdClass(); |
|
91 | - $ret->args = array(); |
|
92 | - if (is_string($taxs)) { |
|
93 | - $taxs = array($taxs); |
|
94 | - } |
|
95 | - $ret->taxonomies = self::correct_taxonomy_names($taxs); |
|
96 | - return $ret; |
|
97 | - } |
|
85 | + /** |
|
86 | + * @param string $taxs |
|
87 | + * @return stdClass |
|
88 | + */ |
|
89 | + public static function get_term_query_from_string($taxs) { |
|
90 | + $ret = new stdClass(); |
|
91 | + $ret->args = array(); |
|
92 | + if (is_string($taxs)) { |
|
93 | + $taxs = array($taxs); |
|
94 | + } |
|
95 | + $ret->taxonomies = self::correct_taxonomy_names($taxs); |
|
96 | + return $ret; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param array $args |
|
101 | - * @return stdClass |
|
102 | - */ |
|
103 | - public static function get_term_query_from_assoc_array($args) { |
|
104 | - $ret = new stdClass(); |
|
105 | - $ret->args = $args; |
|
106 | - if (isset($ret->args['tax'])) { |
|
107 | - $ret->taxonomies = $ret->args['tax']; |
|
108 | - } else if (isset($ret->args['taxonomies'])) { |
|
109 | - $ret->taxonomies = $ret->args['taxonomies']; |
|
110 | - } else if (isset($ret->args['taxs'])) { |
|
111 | - $ret->taxonomies = $ret->args['taxs']; |
|
112 | - } else if (isset($ret->args['taxonomy'])) { |
|
113 | - $ret->taxonomies = $ret->args['taxonomy']; |
|
114 | - } |
|
115 | - if (isset($ret->taxonomies)) { |
|
116 | - if (is_string($ret->taxonomies)) { |
|
117 | - $ret->taxonomies = array($ret->taxonomies); |
|
118 | - } |
|
119 | - $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies); |
|
120 | - } else { |
|
121 | - $ret->taxonomies = get_taxonomies(); |
|
122 | - } |
|
123 | - return $ret; |
|
124 | - } |
|
99 | + /** |
|
100 | + * @param array $args |
|
101 | + * @return stdClass |
|
102 | + */ |
|
103 | + public static function get_term_query_from_assoc_array($args) { |
|
104 | + $ret = new stdClass(); |
|
105 | + $ret->args = $args; |
|
106 | + if (isset($ret->args['tax'])) { |
|
107 | + $ret->taxonomies = $ret->args['tax']; |
|
108 | + } else if (isset($ret->args['taxonomies'])) { |
|
109 | + $ret->taxonomies = $ret->args['taxonomies']; |
|
110 | + } else if (isset($ret->args['taxs'])) { |
|
111 | + $ret->taxonomies = $ret->args['taxs']; |
|
112 | + } else if (isset($ret->args['taxonomy'])) { |
|
113 | + $ret->taxonomies = $ret->args['taxonomy']; |
|
114 | + } |
|
115 | + if (isset($ret->taxonomies)) { |
|
116 | + if (is_string($ret->taxonomies)) { |
|
117 | + $ret->taxonomies = array($ret->taxonomies); |
|
118 | + } |
|
119 | + $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies); |
|
120 | + } else { |
|
121 | + $ret->taxonomies = get_taxonomies(); |
|
122 | + } |
|
123 | + return $ret; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param array $args |
|
128 | - * @return stdClass |
|
129 | - */ |
|
130 | - public static function get_term_query_from_array($args) { |
|
131 | - if (is_array($args) && !empty($args)) { |
|
132 | - //okay its an array with content |
|
133 | - if (is_int($args[0])) { |
|
134 | - return self::get_term_query_from_array_of_ids($args); |
|
135 | - } else if (is_string($args[0])) { |
|
136 | - return self::get_term_query_from_array_of_strings($args); |
|
137 | - } |
|
138 | - } |
|
139 | - return null; |
|
140 | - } |
|
126 | + /** |
|
127 | + * @param array $args |
|
128 | + * @return stdClass |
|
129 | + */ |
|
130 | + public static function get_term_query_from_array($args) { |
|
131 | + if (is_array($args) && !empty($args)) { |
|
132 | + //okay its an array with content |
|
133 | + if (is_int($args[0])) { |
|
134 | + return self::get_term_query_from_array_of_ids($args); |
|
135 | + } else if (is_string($args[0])) { |
|
136 | + return self::get_term_query_from_array_of_strings($args); |
|
137 | + } |
|
138 | + } |
|
139 | + return null; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @param integer[] $args |
|
144 | - * @return stdClass |
|
145 | - */ |
|
146 | - public static function get_term_query_from_array_of_ids($args) { |
|
147 | - $ret = new stdClass(); |
|
148 | - $ret->taxonomies = get_taxonomies(); |
|
149 | - $ret->args['include'] = $args; |
|
150 | - return $ret; |
|
151 | - } |
|
142 | + /** |
|
143 | + * @param integer[] $args |
|
144 | + * @return stdClass |
|
145 | + */ |
|
146 | + public static function get_term_query_from_array_of_ids($args) { |
|
147 | + $ret = new stdClass(); |
|
148 | + $ret->taxonomies = get_taxonomies(); |
|
149 | + $ret->args['include'] = $args; |
|
150 | + return $ret; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string[] $args |
|
155 | - * @return stdClass |
|
156 | - */ |
|
157 | - public static function get_term_query_from_array_of_strings($args) { |
|
158 | - $ret = new stdClass(); |
|
159 | - $ret->taxonomies = self::correct_taxonomy_names($args); |
|
160 | - $ret->args = array(); |
|
161 | - return $ret; |
|
162 | - } |
|
153 | + /** |
|
154 | + * @param string[] $args |
|
155 | + * @return stdClass |
|
156 | + */ |
|
157 | + public static function get_term_query_from_array_of_strings($args) { |
|
158 | + $ret = new stdClass(); |
|
159 | + $ret->taxonomies = self::correct_taxonomy_names($args); |
|
160 | + $ret->args = array(); |
|
161 | + return $ret; |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * @param string|array $taxs |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - private static function correct_taxonomy_names($taxs) { |
|
169 | - if (is_string($taxs)) { |
|
170 | - $taxs = array($taxs); |
|
171 | - } |
|
172 | - foreach ($taxs as &$tax) { |
|
173 | - if ($tax == 'tags' || $tax == 'tag') { |
|
174 | - $tax = 'post_tag'; |
|
175 | - } else if ($tax == 'categories') { |
|
176 | - $tax = 'category'; |
|
177 | - } |
|
178 | - } |
|
179 | - return $taxs; |
|
180 | - } |
|
164 | + /** |
|
165 | + * @param string|array $taxs |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + private static function correct_taxonomy_names($taxs) { |
|
169 | + if (is_string($taxs)) { |
|
170 | + $taxs = array($taxs); |
|
171 | + } |
|
172 | + foreach ($taxs as &$tax) { |
|
173 | + if ($tax == 'tags' || $tax == 'tag') { |
|
174 | + $tax = 'post_tag'; |
|
175 | + } else if ($tax == 'categories') { |
|
176 | + $tax = 'category'; |
|
177 | + } |
|
178 | + } |
|
179 | + return $taxs; |
|
180 | + } |
|
181 | 181 | |
182 | 182 | } |
@@ -9,40 +9,40 @@ discard block |
||
9 | 9 | * @param string $TermClass |
10 | 10 | * @return mixed |
11 | 11 | */ |
12 | - public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){ |
|
13 | - if (is_string($maybe_args) && !strstr($maybe_args, '=')){ |
|
12 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
13 | + if ( is_string($maybe_args) && !strstr($maybe_args, '=') ) { |
|
14 | 14 | //the user is sending the $TermClass in the second argument |
15 | 15 | $TermClass = $maybe_args; |
16 | 16 | } |
17 | - if (is_string($maybe_args) && strstr($maybe_args, '=')){ |
|
17 | + if ( is_string($maybe_args) && strstr($maybe_args, '=') ) { |
|
18 | 18 | parse_str($maybe_args, $maybe_args); |
19 | 19 | } |
20 | - if (is_string($args) && strstr($args, '=')){ |
|
20 | + if ( is_string($args) && strstr($args, '=') ) { |
|
21 | 21 | //a string and a query string! |
22 | 22 | $parsed = TimberTermGetter::get_term_query_from_query_string($args); |
23 | - if (is_array($maybe_args)){ |
|
23 | + if ( is_array($maybe_args) ) { |
|
24 | 24 | $parsed->args = array_merge($parsed->args, $maybe_args); |
25 | 25 | } |
26 | 26 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
27 | - } else if (is_string($args)){ |
|
27 | + } else if ( is_string($args) ) { |
|
28 | 28 | //its just a string with a single taxonomy |
29 | 29 | $parsed = TimberTermGetter::get_term_query_from_string($args); |
30 | - if (is_array($maybe_args)){ |
|
30 | + if ( is_array($maybe_args) ) { |
|
31 | 31 | $parsed->args = array_merge($parsed->args, $maybe_args); |
32 | 32 | } |
33 | 33 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
34 | - } else if (is_array($args) && TimberHelper::is_array_assoc($args)){ |
|
34 | + } else if ( is_array($args) && TimberHelper::is_array_assoc($args) ) { |
|
35 | 35 | //its an associative array, like a good ole query |
36 | 36 | $parsed = TimberTermGetter::get_term_query_from_assoc_array($args); |
37 | 37 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
38 | - } else if (is_array($args)){ |
|
38 | + } else if ( is_array($args) ) { |
|
39 | 39 | //its just an array of strings or IDs (hopefully) |
40 | 40 | $parsed = TimberTermGetter::get_term_query_from_array($args); |
41 | - if (is_array($maybe_args)){ |
|
41 | + if ( is_array($maybe_args) ) { |
|
42 | 42 | $parsed->args = array_merge($parsed->args, $maybe_args); |
43 | 43 | } |
44 | 44 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
45 | - } else if (is_null($args)) { |
|
45 | + } else if ( is_null($args) ) { |
|
46 | 46 | return self::handle_term_query(get_taxonomies(), array(), $TermClass); |
47 | 47 | } |
48 | 48 | return null; |
@@ -54,18 +54,18 @@ discard block |
||
54 | 54 | * @param string $TermClass |
55 | 55 | * @return mixed |
56 | 56 | */ |
57 | - public static function handle_term_query($taxonomies, $args, $TermClass){ |
|
58 | - if (!isset($args['hide_empty'])){ |
|
57 | + public static function handle_term_query($taxonomies, $args, $TermClass) { |
|
58 | + if ( !isset($args['hide_empty']) ) { |
|
59 | 59 | $args['hide_empty'] = false; |
60 | 60 | } |
61 | - if (isset($args['term_id']) && is_int($args['term_id'])){ |
|
61 | + if ( isset($args['term_id']) && is_int($args['term_id']) ) { |
|
62 | 62 | $args['term_id'] = array($args['term_id']); |
63 | 63 | } |
64 | - if (isset($args['term_id'])){ |
|
64 | + if ( isset($args['term_id']) ) { |
|
65 | 65 | $args['include'] = $args['term_id']; |
66 | 66 | } |
67 | 67 | $terms = get_terms($taxonomies, $args); |
68 | - foreach($terms as &$term){ |
|
68 | + foreach ($terms as &$term) { |
|
69 | 69 | $term = new $TermClass($term->term_id, $term->taxonomy); |
70 | 70 | } |
71 | 71 | return $terms; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public static function get_term_query_from_string($taxs) { |
90 | 90 | $ret = new stdClass(); |
91 | 91 | $ret->args = array(); |
92 | - if (is_string($taxs)) { |
|
92 | + if ( is_string($taxs) ) { |
|
93 | 93 | $taxs = array($taxs); |
94 | 94 | } |
95 | 95 | $ret->taxonomies = self::correct_taxonomy_names($taxs); |
@@ -103,17 +103,17 @@ discard block |
||
103 | 103 | public static function get_term_query_from_assoc_array($args) { |
104 | 104 | $ret = new stdClass(); |
105 | 105 | $ret->args = $args; |
106 | - if (isset($ret->args['tax'])) { |
|
106 | + if ( isset($ret->args['tax']) ) { |
|
107 | 107 | $ret->taxonomies = $ret->args['tax']; |
108 | - } else if (isset($ret->args['taxonomies'])) { |
|
108 | + } else if ( isset($ret->args['taxonomies']) ) { |
|
109 | 109 | $ret->taxonomies = $ret->args['taxonomies']; |
110 | - } else if (isset($ret->args['taxs'])) { |
|
110 | + } else if ( isset($ret->args['taxs']) ) { |
|
111 | 111 | $ret->taxonomies = $ret->args['taxs']; |
112 | - } else if (isset($ret->args['taxonomy'])) { |
|
112 | + } else if ( isset($ret->args['taxonomy']) ) { |
|
113 | 113 | $ret->taxonomies = $ret->args['taxonomy']; |
114 | 114 | } |
115 | - if (isset($ret->taxonomies)) { |
|
116 | - if (is_string($ret->taxonomies)) { |
|
115 | + if ( isset($ret->taxonomies) ) { |
|
116 | + if ( is_string($ret->taxonomies) ) { |
|
117 | 117 | $ret->taxonomies = array($ret->taxonomies); |
118 | 118 | } |
119 | 119 | $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies); |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | * @return stdClass |
129 | 129 | */ |
130 | 130 | public static function get_term_query_from_array($args) { |
131 | - if (is_array($args) && !empty($args)) { |
|
131 | + if ( is_array($args) && !empty($args) ) { |
|
132 | 132 | //okay its an array with content |
133 | - if (is_int($args[0])) { |
|
133 | + if ( is_int($args[0]) ) { |
|
134 | 134 | return self::get_term_query_from_array_of_ids($args); |
135 | - } else if (is_string($args[0])) { |
|
135 | + } else if ( is_string($args[0]) ) { |
|
136 | 136 | return self::get_term_query_from_array_of_strings($args); |
137 | 137 | } |
138 | 138 | } |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | * @return array |
167 | 167 | */ |
168 | 168 | private static function correct_taxonomy_names($taxs) { |
169 | - if (is_string($taxs)) { |
|
169 | + if ( is_string($taxs) ) { |
|
170 | 170 | $taxs = array($taxs); |
171 | 171 | } |
172 | 172 | foreach ($taxs as &$tax) { |
173 | - if ($tax == 'tags' || $tax == 'tag') { |
|
173 | + if ( $tax == 'tags' || $tax == 'tag' ) { |
|
174 | 174 | $tax = 'post_tag'; |
175 | - } else if ($tax == 'categories') { |
|
175 | + } else if ( $tax == 'categories' ) { |
|
176 | 176 | $tax = 'category'; |
177 | 177 | } |
178 | 178 | } |
@@ -1,7 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class TimberTermGetter |
|
4 | -{ |
|
3 | +class TimberTermGetter { |
|
5 | 4 | |
6 | 5 | /** |
7 | 6 | * @param string|array $args |
@@ -9,36 +8,36 @@ discard block |
||
9 | 8 | * @param string $TermClass |
10 | 9 | * @return mixed |
11 | 10 | */ |
12 | - public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){ |
|
13 | - if (is_string($maybe_args) && !strstr($maybe_args, '=')){ |
|
11 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
12 | + if (is_string($maybe_args) && !strstr($maybe_args, '=')) { |
|
14 | 13 | //the user is sending the $TermClass in the second argument |
15 | 14 | $TermClass = $maybe_args; |
16 | 15 | } |
17 | - if (is_string($maybe_args) && strstr($maybe_args, '=')){ |
|
16 | + if (is_string($maybe_args) && strstr($maybe_args, '=')) { |
|
18 | 17 | parse_str($maybe_args, $maybe_args); |
19 | 18 | } |
20 | - if (is_string($args) && strstr($args, '=')){ |
|
19 | + if (is_string($args) && strstr($args, '=')) { |
|
21 | 20 | //a string and a query string! |
22 | 21 | $parsed = TimberTermGetter::get_term_query_from_query_string($args); |
23 | - if (is_array($maybe_args)){ |
|
22 | + if (is_array($maybe_args)) { |
|
24 | 23 | $parsed->args = array_merge($parsed->args, $maybe_args); |
25 | 24 | } |
26 | 25 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
27 | - } else if (is_string($args)){ |
|
26 | + } else if (is_string($args)) { |
|
28 | 27 | //its just a string with a single taxonomy |
29 | 28 | $parsed = TimberTermGetter::get_term_query_from_string($args); |
30 | - if (is_array($maybe_args)){ |
|
29 | + if (is_array($maybe_args)) { |
|
31 | 30 | $parsed->args = array_merge($parsed->args, $maybe_args); |
32 | 31 | } |
33 | 32 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
34 | - } else if (is_array($args) && TimberHelper::is_array_assoc($args)){ |
|
33 | + } else if (is_array($args) && TimberHelper::is_array_assoc($args)) { |
|
35 | 34 | //its an associative array, like a good ole query |
36 | 35 | $parsed = TimberTermGetter::get_term_query_from_assoc_array($args); |
37 | 36 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
38 | - } else if (is_array($args)){ |
|
37 | + } else if (is_array($args)) { |
|
39 | 38 | //its just an array of strings or IDs (hopefully) |
40 | 39 | $parsed = TimberTermGetter::get_term_query_from_array($args); |
41 | - if (is_array($maybe_args)){ |
|
40 | + if (is_array($maybe_args)) { |
|
42 | 41 | $parsed->args = array_merge($parsed->args, $maybe_args); |
43 | 42 | } |
44 | 43 | return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass); |
@@ -54,18 +53,18 @@ discard block |
||
54 | 53 | * @param string $TermClass |
55 | 54 | * @return mixed |
56 | 55 | */ |
57 | - public static function handle_term_query($taxonomies, $args, $TermClass){ |
|
58 | - if (!isset($args['hide_empty'])){ |
|
56 | + public static function handle_term_query($taxonomies, $args, $TermClass) { |
|
57 | + if (!isset($args['hide_empty'])) { |
|
59 | 58 | $args['hide_empty'] = false; |
60 | 59 | } |
61 | - if (isset($args['term_id']) && is_int($args['term_id'])){ |
|
60 | + if (isset($args['term_id']) && is_int($args['term_id'])) { |
|
62 | 61 | $args['term_id'] = array($args['term_id']); |
63 | 62 | } |
64 | - if (isset($args['term_id'])){ |
|
63 | + if (isset($args['term_id'])) { |
|
65 | 64 | $args['include'] = $args['term_id']; |
66 | 65 | } |
67 | 66 | $terms = get_terms($taxonomies, $args); |
68 | - foreach($terms as &$term){ |
|
67 | + foreach($terms as &$term) { |
|
69 | 68 | $term = new $TermClass($term->term_id, $term->taxonomy); |
70 | 69 | } |
71 | 70 | return $terms; |
@@ -333,7 +333,7 @@ |
||
333 | 333 | $suffix = '</p>'; |
334 | 334 | $desc = term_description( $this->ID, $this->taxonomy ); |
335 | 335 | if (substr($desc, 0, strlen($prefix)) == $prefix) { |
336 | - $desc = substr($desc, strlen($prefix)); |
|
336 | + $desc = substr($desc, strlen($prefix)); |
|
337 | 337 | } |
338 | 338 | $desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc); |
339 | 339 | return trim($desc); |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * @param int $tid |
55 | 55 | * @param string $tax |
56 | 56 | */ |
57 | - public function __construct( $tid = null, $tax = '' ) { |
|
58 | - if ($tid === null) { |
|
57 | + public function __construct($tid = null, $tax = '') { |
|
58 | + if ( $tid === null ) { |
|
59 | 59 | $tid = $this->get_term_from_query(); |
60 | 60 | } |
61 | - if (strlen($tax)) { |
|
61 | + if ( strlen($tax) ) { |
|
62 | 62 | $this->taxonomy = $tax; |
63 | 63 | } |
64 | 64 | $this->init($tid); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return static |
79 | 79 | */ |
80 | - public static function from( $tid, $taxonomy ) { |
|
80 | + public static function from($tid, $taxonomy) { |
|
81 | 81 | return new static($tid, $taxonomy); |
82 | 82 | } |
83 | 83 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | global $wp_query; |
94 | 94 | if ( isset($wp_query->queried_object) ) { |
95 | 95 | $qo = $wp_query->queried_object; |
96 | - if (isset($qo->term_id)) { |
|
96 | + if ( isset($qo->term_id) ) { |
|
97 | 97 | return $qo->term_id; |
98 | 98 | } |
99 | 99 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @internal |
107 | 107 | * @param int $tid |
108 | 108 | */ |
109 | - protected function init( $tid ) { |
|
109 | + protected function init($tid) { |
|
110 | 110 | $term = $this->get_term($tid); |
111 | 111 | if ( isset($term->id) ) { |
112 | 112 | $term->ID = $term->id; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | //echo 'bad call using '.$tid; |
117 | 117 | //TimberHelper::error_log(debug_backtrace()); |
118 | 118 | } |
119 | - if ( isset($term->ID) ){ |
|
119 | + if ( isset($term->ID) ) { |
|
120 | 120 | $term->id = $term->ID; |
121 | 121 | $this->import($term); |
122 | 122 | if ( isset($term->term_id) ) { |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param int $tid |
143 | 143 | * @return mixed |
144 | 144 | */ |
145 | - protected function get_term( $tid ) { |
|
145 | + protected function get_term($tid) { |
|
146 | 146 | if ( is_object($tid) || is_array($tid) ) { |
147 | 147 | return $tid; |
148 | 148 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | global $wpdb; |
155 | 155 | $query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid); |
156 | 156 | $tax = $wpdb->get_var($query); |
157 | - if (isset($tax) && strlen($tax)) { |
|
157 | + if ( isset($tax) && strlen($tax) ) { |
|
158 | 158 | $this->taxonomy = $tax; |
159 | 159 | return get_term($tid, $tax); |
160 | 160 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param int $tid |
168 | 168 | * @return int |
169 | 169 | */ |
170 | - protected function get_tid( $tid ) { |
|
170 | + protected function get_tid($tid) { |
|
171 | 171 | global $wpdb; |
172 | 172 | if ( is_numeric($tid) ) { |
173 | 173 | return $tid; |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | * @param string $field_name |
206 | 206 | * @return string |
207 | 207 | */ |
208 | - public function get_meta_field( $field_name ) { |
|
209 | - if (!isset($this->$field_name)) { |
|
208 | + public function get_meta_field($field_name) { |
|
209 | + if ( !isset($this->$field_name) ) { |
|
210 | 210 | $field_value = ''; |
211 | 211 | $field_value = apply_filters('timber_term_get_meta_field', $field_value, $this->ID, $field_name, $this); |
212 | 212 | $field_value = apply_filters('timber/term/meta/field', $field_value, $this->ID, $field_name, $this); |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param string $PostClass |
245 | 245 | * @return array|bool|null |
246 | 246 | */ |
247 | - public function get_posts( $numberposts = 10, $post_type = 'any', $PostClass = '' ) { |
|
248 | - if (!strlen($PostClass)) { |
|
247 | + public function get_posts($numberposts = 10, $post_type = 'any', $PostClass = '') { |
|
248 | + if ( !strlen($PostClass) ) { |
|
249 | 249 | $PostClass = $this->PostClass; |
250 | 250 | } |
251 | 251 | $default_tax_query = array(array( |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | parse_str($args, $new_args); |
260 | 260 | $args = $new_args; |
261 | 261 | $args['tax_query'] = $default_tax_query; |
262 | - if (!isset($args['post_type'])) { |
|
262 | + if ( !isset($args['post_type']) ) { |
|
263 | 263 | $args['post_type'] = 'any'; |
264 | 264 | } |
265 | - if (class_exists($post_type)) { |
|
265 | + if ( class_exists($post_type) ) { |
|
266 | 266 | $PostClass = $post_type; |
267 | 267 | } |
268 | 268 | } else if ( is_array($numberposts) ) { |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | * @param string $key |
309 | 309 | * @param mixed $value |
310 | 310 | */ |
311 | - function update( $key, $value ) { |
|
312 | - $value = apply_filters( 'timber_term_set_meta', $value, $key, $this->ID, $this ); |
|
311 | + function update($key, $value) { |
|
312 | + $value = apply_filters('timber_term_set_meta', $value, $key, $this->ID, $this); |
|
313 | 313 | $this->$key = $value; |
314 | 314 | } |
315 | 315 | |
@@ -331,11 +331,11 @@ discard block |
||
331 | 331 | public function description() { |
332 | 332 | $prefix = '<p>'; |
333 | 333 | $suffix = '</p>'; |
334 | - $desc = term_description( $this->ID, $this->taxonomy ); |
|
335 | - if (substr($desc, 0, strlen($prefix)) == $prefix) { |
|
334 | + $desc = term_description($this->ID, $this->taxonomy); |
|
335 | + if ( substr($desc, 0, strlen($prefix)) == $prefix ) { |
|
336 | 336 | $desc = substr($desc, strlen($prefix)); |
337 | 337 | } |
338 | - $desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc); |
|
338 | + $desc = preg_replace('/' . preg_quote('</p>', '/') . '$/', '', $desc); |
|
339 | 339 | return trim($desc); |
340 | 340 | } |
341 | 341 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @param string $field_name |
370 | 370 | * @return string |
371 | 371 | */ |
372 | - public function meta( $field_name ) { |
|
372 | + public function meta($field_name) { |
|
373 | 373 | return $this->get_meta_field($field_name); |
374 | 374 | } |
375 | 375 | |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | * ``` |
398 | 398 | * @return array|bool|null |
399 | 399 | */ |
400 | - public function posts( $numberposts_or_args = 10, $post_type_or_class = 'any', $post_class = '' ) { |
|
400 | + public function posts($numberposts_or_args = 10, $post_type_or_class = 'any', $post_class = '') { |
|
401 | 401 | return $this->get_posts($numberposts_or_args, $post_type_or_class, $post_class); |
402 | 402 | } |
403 | 403 | |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * @param int $i |
423 | 423 | * @return string |
424 | 424 | */ |
425 | - function get_page( $i ) { |
|
425 | + function get_page($i) { |
|
426 | 426 | return $this->get_path() . '/page/' . $i; |
427 | 427 | } |
428 | 428 |
@@ -116,7 +116,7 @@ |
||
116 | 116 | //echo 'bad call using '.$tid; |
117 | 117 | //TimberHelper::error_log(debug_backtrace()); |
118 | 118 | } |
119 | - if ( isset($term->ID) ){ |
|
119 | + if ( isset($term->ID) ) { |
|
120 | 120 | $term->id = $term->ID; |
121 | 121 | $this->import($term); |
122 | 122 | if ( isset($term->term_id) ) { |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $ss = $data->get_stylesheet(); |
77 | 77 | $this->slug = $ss; |
78 | 78 | |
79 | - if ( ! function_exists( 'get_home_path' ) ) { |
|
79 | + if ( !function_exists('get_home_path') ) { |
|
80 | 80 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
81 | 81 | } |
82 | 82 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
104 | 104 | */ |
105 | 105 | public function path() { |
106 | - return TimberURLHelper::get_rel_url( $this->link() ); |
|
106 | + return TimberURLHelper::get_rel_url($this->link()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | } |
13 | 13 | |
14 | 14 | function __construct() { |
15 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters_deprecated' ) ); |
|
16 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters' ) ); |
|
15 | + add_action('timber/twig/filters', array($this, 'add_timber_filters_deprecated')); |
|
16 | + add_action('timber/twig/filters', array($this, 'add_timber_filters')); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | * @deprecated since 0.20.7 |
24 | 24 | * @return Twig_Environment |
25 | 25 | */ |
26 | - function add_timber_filters_deprecated( $twig ) { |
|
27 | - $twig->addFilter( new Twig_SimpleFilter( 'get_src_from_attachment_id', 'twig_get_src_from_attachment_id' ) ); |
|
28 | - $twig->addFilter( new Twig_SimpleFilter( 'wp_body_class', array( $this, 'body_class' ) ) ); |
|
29 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterify', array( 'TimberHelper', 'twitterify' ) ) ); |
|
30 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterfy', array( 'TimberHelper', 'twitterify' ) ) ); |
|
31 | - $twig->addFilter( new Twig_SimpleFilter( 'string', function($arr, $glue = ' '){ |
|
26 | + function add_timber_filters_deprecated($twig) { |
|
27 | + $twig->addFilter(new Twig_SimpleFilter('get_src_from_attachment_id', 'twig_get_src_from_attachment_id')); |
|
28 | + $twig->addFilter(new Twig_SimpleFilter('wp_body_class', array($this, 'body_class'))); |
|
29 | + $twig->addFilter(new Twig_SimpleFilter('twitterify', array('TimberHelper', 'twitterify'))); |
|
30 | + $twig->addFilter(new Twig_SimpleFilter('twitterfy', array('TimberHelper', 'twitterify'))); |
|
31 | + $twig->addFilter(new Twig_SimpleFilter('string', function($arr, $glue = ' ') { |
|
32 | 32 | return twig_join_filter($arr, $glue); |
33 | - } ) ); |
|
33 | + } )); |
|
34 | 34 | return $twig; |
35 | 35 | } |
36 | 36 | |
@@ -40,151 +40,151 @@ discard block |
||
40 | 40 | * @param Twig_Environment $twig |
41 | 41 | * @return Twig_Environment |
42 | 42 | */ |
43 | - function add_timber_filters( $twig ) { |
|
43 | + function add_timber_filters($twig) { |
|
44 | 44 | /* image filters */ |
45 | - $twig->addFilter( new Twig_SimpleFilter( 'resize', array( 'TimberImageHelper', 'resize' ) ) ); |
|
46 | - $twig->addFilter( new Twig_SimpleFilter( 'retina', array( 'TimberImageHelper', 'retina_resize' ) ) ); |
|
47 | - $twig->addFilter( new Twig_SimpleFilter( 'letterbox', array( 'TimberImageHelper', 'letterbox' ) ) ); |
|
48 | - $twig->addFilter( new Twig_SimpleFilter( 'tojpg', array( 'TimberImageHelper', 'img_to_jpg' ) ) ); |
|
45 | + $twig->addFilter(new Twig_SimpleFilter('resize', array('TimberImageHelper', 'resize'))); |
|
46 | + $twig->addFilter(new Twig_SimpleFilter('retina', array('TimberImageHelper', 'retina_resize'))); |
|
47 | + $twig->addFilter(new Twig_SimpleFilter('letterbox', array('TimberImageHelper', 'letterbox'))); |
|
48 | + $twig->addFilter(new Twig_SimpleFilter('tojpg', array('TimberImageHelper', 'img_to_jpg'))); |
|
49 | 49 | |
50 | 50 | /* debugging filters */ |
51 | - $twig->addFilter( new Twig_SimpleFilter( 'docs', 'twig_object_docs' ) ); |
|
52 | - $twig->addFilter( new Twig_SimpleFilter( 'get_class', 'get_class' ) ); |
|
53 | - $twig->addFilter( new Twig_SimpleFilter( 'get_type', 'get_type' ) ); |
|
54 | - $twig->addFilter( new Twig_SimpleFilter( 'print_r', function( $arr ) { |
|
55 | - return print_r( $arr, true ); |
|
56 | - } ) ); |
|
57 | - $twig->addFilter( new Twig_SimpleFilter( 'print_a', function( $arr ) { |
|
58 | - return '<pre>' . self::object_docs( $arr, true ) . '</pre>'; |
|
59 | - } ) ); |
|
51 | + $twig->addFilter(new Twig_SimpleFilter('docs', 'twig_object_docs')); |
|
52 | + $twig->addFilter(new Twig_SimpleFilter('get_class', 'get_class')); |
|
53 | + $twig->addFilter(new Twig_SimpleFilter('get_type', 'get_type')); |
|
54 | + $twig->addFilter(new Twig_SimpleFilter('print_r', function($arr) { |
|
55 | + return print_r($arr, true); |
|
56 | + } )); |
|
57 | + $twig->addFilter(new Twig_SimpleFilter('print_a', function($arr) { |
|
58 | + return '<pre>' . self::object_docs($arr, true) . '</pre>'; |
|
59 | + } )); |
|
60 | 60 | |
61 | 61 | /* other filters */ |
62 | - $twig->addFilter( new Twig_SimpleFilter( 'stripshortcodes', 'strip_shortcodes' ) ); |
|
63 | - $twig->addFilter( new Twig_SimpleFilter( 'array', array( $this, 'to_array' ) ) ); |
|
64 | - $twig->addFilter( new Twig_SimpleFilter( 'excerpt', 'wp_trim_words' ) ); |
|
65 | - $twig->addFilter( new Twig_SimpleFilter( 'function', array( $this, 'exec_function' ) ) ); |
|
66 | - $twig->addFilter( new Twig_SimpleFilter( 'pretags', array( $this, 'twig_pretags' ) ) ); |
|
67 | - $twig->addFilter( new Twig_SimpleFilter( 'sanitize', 'sanitize_title' ) ); |
|
68 | - $twig->addFilter( new Twig_SimpleFilter( 'shortcodes', 'do_shortcode' ) ); |
|
69 | - $twig->addFilter( new Twig_SimpleFilter( 'time_ago', array( $this, 'time_ago' ) ) ); |
|
70 | - $twig->addFilter( new Twig_SimpleFilter( 'wpautop', 'wpautop' ) ); |
|
71 | - $twig->addFilter( new Twig_SimpleFilter( 'list', array( $this, 'add_list_separators' ) ) ); |
|
72 | - |
|
73 | - $twig->addFilter( new Twig_SimpleFilter( 'relative', function ( $link ) { |
|
74 | - return TimberURLHelper::get_rel_url( $link, true ); |
|
75 | - } ) ); |
|
76 | - |
|
77 | - $twig->addFilter( new Twig_SimpleFilter( 'date', array( $this, 'intl_date' ) ) ); |
|
78 | - |
|
79 | - $twig->addFilter( new Twig_SimpleFilter( 'truncate', function ( $text, $len ) { |
|
80 | - return TimberHelper::trim_words( $text, $len ); |
|
81 | - } ) ); |
|
62 | + $twig->addFilter(new Twig_SimpleFilter('stripshortcodes', 'strip_shortcodes')); |
|
63 | + $twig->addFilter(new Twig_SimpleFilter('array', array($this, 'to_array'))); |
|
64 | + $twig->addFilter(new Twig_SimpleFilter('excerpt', 'wp_trim_words')); |
|
65 | + $twig->addFilter(new Twig_SimpleFilter('function', array($this, 'exec_function'))); |
|
66 | + $twig->addFilter(new Twig_SimpleFilter('pretags', array($this, 'twig_pretags'))); |
|
67 | + $twig->addFilter(new Twig_SimpleFilter('sanitize', 'sanitize_title')); |
|
68 | + $twig->addFilter(new Twig_SimpleFilter('shortcodes', 'do_shortcode')); |
|
69 | + $twig->addFilter(new Twig_SimpleFilter('time_ago', array($this, 'time_ago'))); |
|
70 | + $twig->addFilter(new Twig_SimpleFilter('wpautop', 'wpautop')); |
|
71 | + $twig->addFilter(new Twig_SimpleFilter('list', array($this, 'add_list_separators'))); |
|
72 | + |
|
73 | + $twig->addFilter(new Twig_SimpleFilter('relative', function($link) { |
|
74 | + return TimberURLHelper::get_rel_url($link, true); |
|
75 | + } )); |
|
76 | + |
|
77 | + $twig->addFilter(new Twig_SimpleFilter('date', array($this, 'intl_date'))); |
|
78 | + |
|
79 | + $twig->addFilter(new Twig_SimpleFilter('truncate', function($text, $len) { |
|
80 | + return TimberHelper::trim_words($text, $len); |
|
81 | + } )); |
|
82 | 82 | |
83 | 83 | /* actions and filters */ |
84 | - $twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) { |
|
84 | + $twig->addFunction(new Twig_SimpleFunction('action', function($context) { |
|
85 | 85 | $args = func_get_args(); |
86 | - array_shift( $args ); |
|
86 | + array_shift($args); |
|
87 | 87 | $args[] = $context; |
88 | - call_user_func_array( 'do_action', $args ); |
|
89 | - }, array( 'needs_context' => true ) ) ); |
|
88 | + call_user_func_array('do_action', $args); |
|
89 | + }, array('needs_context' => true))); |
|
90 | 90 | |
91 | - $twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () { |
|
91 | + $twig->addFilter(new Twig_SimpleFilter('apply_filters', function() { |
|
92 | 92 | $args = func_get_args(); |
93 | - $tag = current( array_splice( $args, 1, 1 ) ); |
|
93 | + $tag = current(array_splice($args, 1, 1)); |
|
94 | 94 | |
95 | - return apply_filters_ref_array( $tag, $args ); |
|
96 | - } ) ); |
|
97 | - $twig->addFunction( new Twig_SimpleFunction( 'function', array( &$this, 'exec_function' ) ) ); |
|
98 | - $twig->addFunction( new Twig_SimpleFunction( 'fn', array( &$this, 'exec_function' ) ) ); |
|
95 | + return apply_filters_ref_array($tag, $args); |
|
96 | + } )); |
|
97 | + $twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function'))); |
|
98 | + $twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function'))); |
|
99 | 99 | |
100 | - $twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) ); |
|
100 | + $twig->addFunction(new Twig_SimpleFunction('shortcode', 'do_shortcode')); |
|
101 | 101 | |
102 | 102 | /* TimberObjects */ |
103 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) { |
|
104 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
105 | - foreach ( $pid as &$p ) { |
|
106 | - $p = new $PostClass( $p ); |
|
103 | + $twig->addFunction(new Twig_SimpleFunction('TimberPost', function($pid, $PostClass = 'TimberPost') { |
|
104 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
105 | + foreach ($pid as &$p) { |
|
106 | + $p = new $PostClass($p); |
|
107 | 107 | } |
108 | 108 | return $pid; |
109 | 109 | } |
110 | - return new $PostClass( $pid ); |
|
111 | - } ) ); |
|
112 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberImage', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
113 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
114 | - foreach ( $pid as &$p ) { |
|
115 | - $p = new $ImageClass( $p ); |
|
110 | + return new $PostClass($pid); |
|
111 | + } )); |
|
112 | + $twig->addFunction(new Twig_SimpleFunction('TimberImage', function($pid, $ImageClass = 'TimberImage') { |
|
113 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
114 | + foreach ($pid as &$p) { |
|
115 | + $p = new $ImageClass($p); |
|
116 | 116 | } |
117 | 117 | return $pid; |
118 | 118 | } |
119 | - return new $ImageClass( $pid ); |
|
120 | - } ) ); |
|
121 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberTerm', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
122 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
123 | - foreach ( $pid as &$p ) { |
|
124 | - $p = new $TermClass( $p ); |
|
119 | + return new $ImageClass($pid); |
|
120 | + } )); |
|
121 | + $twig->addFunction(new Twig_SimpleFunction('TimberTerm', function($pid, $TermClass = 'TimberTerm') { |
|
122 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
123 | + foreach ($pid as &$p) { |
|
124 | + $p = new $TermClass($p); |
|
125 | 125 | } |
126 | 126 | return $pid; |
127 | 127 | } |
128 | - return new $TermClass( $pid ); |
|
129 | - } ) ); |
|
130 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberUser', function ( $pid, $UserClass = 'TimberUser' ) { |
|
131 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
132 | - foreach ( $pid as &$p ) { |
|
133 | - $p = new $UserClass( $p ); |
|
128 | + return new $TermClass($pid); |
|
129 | + } )); |
|
130 | + $twig->addFunction(new Twig_SimpleFunction('TimberUser', function($pid, $UserClass = 'TimberUser') { |
|
131 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
132 | + foreach ($pid as &$p) { |
|
133 | + $p = new $UserClass($p); |
|
134 | 134 | } |
135 | 135 | return $pid; |
136 | 136 | } |
137 | - return new $UserClass( $pid ); |
|
138 | - } ) ); |
|
137 | + return new $UserClass($pid); |
|
138 | + } )); |
|
139 | 139 | |
140 | 140 | /* TimberObjects Alias */ |
141 | - $twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) { |
|
142 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
143 | - foreach ( $pid as &$p ) { |
|
144 | - $p = new $PostClass( $p ); |
|
141 | + $twig->addFunction(new Twig_SimpleFunction('Post', function($pid, $PostClass = 'TimberPost') { |
|
142 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
143 | + foreach ($pid as &$p) { |
|
144 | + $p = new $PostClass($p); |
|
145 | 145 | } |
146 | 146 | return $pid; |
147 | 147 | } |
148 | - return new $PostClass( $pid ); |
|
149 | - } ) ); |
|
150 | - $twig->addFunction( new Twig_SimpleFunction( 'Image', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
151 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
152 | - foreach ( $pid as &$p ) { |
|
153 | - $p = new $ImageClass( $p ); |
|
148 | + return new $PostClass($pid); |
|
149 | + } )); |
|
150 | + $twig->addFunction(new Twig_SimpleFunction('Image', function($pid, $ImageClass = 'TimberImage') { |
|
151 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
152 | + foreach ($pid as &$p) { |
|
153 | + $p = new $ImageClass($p); |
|
154 | 154 | } |
155 | 155 | return $pid; |
156 | 156 | } |
157 | - return new $ImageClass( $pid ); |
|
158 | - } ) ); |
|
159 | - $twig->addFunction( new Twig_SimpleFunction( 'Term', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
160 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
161 | - foreach ( $pid as &$p ) { |
|
162 | - $p = new $TermClass( $p ); |
|
157 | + return new $ImageClass($pid); |
|
158 | + } )); |
|
159 | + $twig->addFunction(new Twig_SimpleFunction('Term', function($pid, $TermClass = 'TimberTerm') { |
|
160 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
161 | + foreach ($pid as &$p) { |
|
162 | + $p = new $TermClass($p); |
|
163 | 163 | } |
164 | 164 | return $pid; |
165 | 165 | } |
166 | - return new $TermClass( $pid ); |
|
167 | - } ) ); |
|
168 | - $twig->addFunction( new Twig_SimpleFunction( 'User', function ( $pid, $UserClass = 'TimberUser' ) { |
|
169 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
170 | - foreach ( $pid as &$p ) { |
|
171 | - $p = new $UserClass( $p ); |
|
166 | + return new $TermClass($pid); |
|
167 | + } )); |
|
168 | + $twig->addFunction(new Twig_SimpleFunction('User', function($pid, $UserClass = 'TimberUser') { |
|
169 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
170 | + foreach ($pid as &$p) { |
|
171 | + $p = new $UserClass($p); |
|
172 | 172 | } |
173 | 173 | return $pid; |
174 | 174 | } |
175 | - return new $UserClass( $pid ); |
|
176 | - } ) ); |
|
175 | + return new $UserClass($pid); |
|
176 | + } )); |
|
177 | 177 | |
178 | 178 | /* bloginfo and translate */ |
179 | - $twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) { |
|
180 | - return get_bloginfo( $show, $filter ); |
|
181 | - } ) ); |
|
182 | - $twig->addFunction( '__', new Twig_SimpleFunction( '__', function ( $text, $domain = 'default' ) { |
|
183 | - return __( $text, $domain ); |
|
184 | - } ) ); |
|
179 | + $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw') { |
|
180 | + return get_bloginfo($show, $filter); |
|
181 | + } )); |
|
182 | + $twig->addFunction('__', new Twig_SimpleFunction('__', function($text, $domain = 'default') { |
|
183 | + return __($text, $domain); |
|
184 | + } )); |
|
185 | 185 | /* get_twig is deprecated, use timber/twig */ |
186 | - $twig = apply_filters( 'get_twig', $twig ); |
|
187 | - $twig = apply_filters( 'timber/twig', $twig ); |
|
186 | + $twig = apply_filters('get_twig', $twig); |
|
187 | + $twig = apply_filters('timber/twig', $twig); |
|
188 | 188 | return $twig; |
189 | 189 | } |
190 | 190 | |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | * @param mixed $arr |
195 | 195 | * @return array |
196 | 196 | */ |
197 | - function to_array( $arr ) { |
|
198 | - if ( is_array( $arr ) ) { |
|
197 | + function to_array($arr) { |
|
198 | + if ( is_array($arr) ) { |
|
199 | 199 | return $arr; |
200 | 200 | } |
201 | - $arr = array( $arr ); |
|
201 | + $arr = array($arr); |
|
202 | 202 | return $arr; |
203 | 203 | } |
204 | 204 | |
@@ -208,13 +208,13 @@ discard block |
||
208 | 208 | * @param string $function_name |
209 | 209 | * @return mixed |
210 | 210 | */ |
211 | - function exec_function( $function_name ) { |
|
211 | + function exec_function($function_name) { |
|
212 | 212 | $args = func_get_args(); |
213 | - array_shift( $args ); |
|
213 | + array_shift($args); |
|
214 | 214 | if ( is_string($function_name) ) { |
215 | - $function_name = trim( $function_name ); |
|
215 | + $function_name = trim($function_name); |
|
216 | 216 | } |
217 | - return call_user_func_array( $function_name, ( $args ) ); |
|
217 | + return call_user_func_array($function_name, ($args)); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param string $content |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - function twig_pretags( $content ) { |
|
227 | - return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content ); |
|
226 | + function twig_pretags($content) { |
|
227 | + return preg_replace_callback('|<pre.*>(.*)</pre|isU', array(&$this, 'convert_pre_entities'), $content); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @param array $matches |
234 | 234 | * @return string |
235 | 235 | */ |
236 | - function convert_pre_entities( $matches ) { |
|
237 | - return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] ); |
|
236 | + function convert_pre_entities($matches) { |
|
237 | + return str_replace($matches[1], htmlentities($matches[1]), $matches[0]); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | * @deprecated 0.20.7 |
243 | 243 | * @return string |
244 | 244 | */ |
245 | - function body_class( $body_classes ) { |
|
245 | + function body_class($body_classes) { |
|
246 | 246 | ob_start(); |
247 | - if ( is_array( $body_classes ) ) { |
|
248 | - $body_classes = explode( ' ', $body_classes ); |
|
247 | + if ( is_array($body_classes) ) { |
|
248 | + $body_classes = explode(' ', $body_classes); |
|
249 | 249 | } |
250 | - body_class( $body_classes ); |
|
250 | + body_class($body_classes); |
|
251 | 251 | $return = ob_get_contents(); |
252 | 252 | ob_end_clean(); |
253 | 253 | return $return; |
@@ -260,20 +260,20 @@ discard block |
||
260 | 260 | * @param string $format (optional) |
261 | 261 | * @return string |
262 | 262 | */ |
263 | - function intl_date( $date, $format = null ) { |
|
263 | + function intl_date($date, $format = null) { |
|
264 | 264 | if ( $format === null ) { |
265 | - $format = get_option( 'date_format' ); |
|
265 | + $format = get_option('date_format'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | if ( $date instanceof DateTime ) { |
269 | 269 | $timestamp = $date->getTimestamp(); |
270 | - } else if (is_numeric( $date ) && strtotime( $date ) === false ) { |
|
271 | - $timestamp = intval( $date ); |
|
270 | + } else if ( is_numeric($date) && strtotime($date) === false ) { |
|
271 | + $timestamp = intval($date); |
|
272 | 272 | } else { |
273 | - $timestamp = strtotime( $date ); |
|
273 | + $timestamp = strtotime($date); |
|
274 | 274 | } |
275 | 275 | |
276 | - return date_i18n( $format, $timestamp ); |
|
276 | + return date_i18n($format, $timestamp); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | //debug |
@@ -285,17 +285,17 @@ discard block |
||
285 | 285 | * @param bool $methods |
286 | 286 | * @return string |
287 | 287 | */ |
288 | - function object_docs( $obj, $methods = true ) { |
|
289 | - $class = get_class( $obj ); |
|
290 | - $properties = (array)$obj; |
|
288 | + function object_docs($obj, $methods = true) { |
|
289 | + $class = get_class($obj); |
|
290 | + $properties = (array) $obj; |
|
291 | 291 | if ( $methods ) { |
292 | 292 | /** @var array $methods */ |
293 | 293 | $methods = $obj->get_method_values(); |
294 | 294 | } |
295 | - $rets = array_merge( $properties, $methods ); |
|
296 | - ksort( $rets ); |
|
297 | - $str = print_r( $rets, true ); |
|
298 | - $str = str_replace( 'Array', $class . ' Object', $str ); |
|
295 | + $rets = array_merge($properties, $methods); |
|
296 | + ksort($rets); |
|
297 | + $str = print_r($rets, true); |
|
298 | + $str = str_replace('Array', $class . ' Object', $str); |
|
299 | 299 | return $str; |
300 | 300 | } |
301 | 301 | |
@@ -306,15 +306,15 @@ discard block |
||
306 | 306 | * @param string $format_future |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) { |
|
309 | + function time_ago($from, $to = null, $format_past = '%s ago', $format_future = '%s from now') { |
|
310 | 310 | $to = $to === null ? time() : $to; |
311 | - $to = is_int( $to ) ? $to : strtotime( $to ); |
|
312 | - $from = is_int( $from ) ? $from : strtotime( $from ); |
|
311 | + $to = is_int($to) ? $to : strtotime($to); |
|
312 | + $from = is_int($from) ? $from : strtotime($from); |
|
313 | 313 | |
314 | 314 | if ( $from < $to ) { |
315 | - return sprintf( $format_past, human_time_diff( $from, $to ) ); |
|
315 | + return sprintf($format_past, human_time_diff($from, $to)); |
|
316 | 316 | } else { |
317 | - return sprintf( $format_future, human_time_diff( $to, $from ) ); |
|
317 | + return sprintf($format_future, human_time_diff($to, $from)); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
@@ -324,18 +324,18 @@ discard block |
||
324 | 324 | * @param string $second_delimiter |
325 | 325 | * @return string |
326 | 326 | */ |
327 | - function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) { |
|
328 | - $length = count( $arr ); |
|
327 | + function add_list_separators($arr, $first_delimiter = ',', $second_delimiter = 'and') { |
|
328 | + $length = count($arr); |
|
329 | 329 | $list = ''; |
330 | - foreach( $arr as $index => $item ) { |
|
330 | + foreach ($arr as $index => $item) { |
|
331 | 331 | if ( $index < $length - 2 ) { |
332 | - $delimiter = $first_delimiter.' '; |
|
332 | + $delimiter = $first_delimiter . ' '; |
|
333 | 333 | } elseif ( $index == $length - 2 ) { |
334 | - $delimiter = ' '.$second_delimiter.' '; |
|
334 | + $delimiter = ' ' . $second_delimiter . ' '; |
|
335 | 335 | } else { |
336 | 336 | $delimiter = ''; |
337 | 337 | } |
338 | - $list = $list.$item.$delimiter; |
|
338 | + $list = $list . $item . $delimiter; |
|
339 | 339 | } |
340 | 340 | return $list; |
341 | 341 | } |