@@ -28,7 +28,7 @@ |
||
28 | 28 | * @since 1.0.0 |
29 | 29 | */ |
30 | 30 | public function get_title() { |
31 | - return _x( 'Name', 'post type', 'wordpoints' ); |
|
31 | + return _x('Name', 'post type', 'wordpoints'); |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @since 1.0.0 |
35 | 35 | */ |
36 | 36 | public function get_title() { |
37 | - return __( 'Post Type', 'wordpoints' ); |
|
37 | + return __('Post Type', 'wordpoints'); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | 37 | public function get_title() { |
38 | - return __( 'Site', 'wordpoints' ); |
|
38 | + return __('Site', 'wordpoints'); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 |
@@ -9,15 +9,15 @@ discard block |
||
9 | 9 | |
10 | 10 | interface WordPoints_HierarchyI { |
11 | 11 | public function get(); |
12 | - public function push( $field, $data ); |
|
12 | + public function push($field, $data); |
|
13 | 13 | public function pop(); |
14 | - public function set_field( $field, $value ); |
|
15 | - public function get_field( $field, $sub = null, $sub_2 = null ); |
|
14 | + public function set_field($field, $value); |
|
15 | + public function get_field($field, $sub = null, $sub_2 = null); |
|
16 | 16 | public function get_id(); |
17 | - public function go_to( $id ); |
|
18 | - public function push_to( $field, $value ); |
|
17 | + public function go_to($id); |
|
18 | + public function push_to($field, $value); |
|
19 | 19 | public function ascend(); |
20 | - public function descend( $to = null ); |
|
20 | + public function descend($to = null); |
|
21 | 21 | public function is_main(); |
22 | 22 | public function next(); |
23 | 23 | public function reset(); |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | protected $descendant_index; |
32 | 32 | |
33 | 33 | public function __construct() { |
34 | - $this->current =& $this->hierarchy; |
|
34 | + $this->current = & $this->hierarchy; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function get() { |
38 | 38 | return $this->hierarchy; |
39 | 39 | } |
40 | 40 | |
41 | - public function push( $field, $data ) { |
|
41 | + public function push($field, $data) { |
|
42 | 42 | |
43 | - if ( ! isset( $this->current['slug'] ) || $this->current['slug'] !== $field ) { |
|
43 | + if ( ! isset($this->current['slug']) || $this->current['slug'] !== $field) { |
|
44 | 44 | |
45 | - if ( ! empty( $this->hierarchy ) ) { |
|
46 | - $this->current[ $this->descendant_index ][ $field ] = $data; |
|
47 | - $this->current =& $this->current[ $this->descendant_index ][ $field ]; |
|
45 | + if ( ! empty($this->hierarchy)) { |
|
46 | + $this->current[$this->descendant_index][$field] = $data; |
|
47 | + $this->current = & $this->current[$this->descendant_index][$field]; |
|
48 | 48 | } else { |
49 | 49 | $this->current = $this->stack[0] = $data; |
50 | 50 | } |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | |
58 | 58 | public function pop() { |
59 | 59 | |
60 | - unset( $this->current ); |
|
60 | + unset($this->current); |
|
61 | 61 | |
62 | - $this->current = array_pop( $this->stack ); |
|
62 | + $this->current = array_pop($this->stack); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function reset() { |
66 | 66 | // unset( $this->current_arg ); |
67 | - $this->current =& $this->hierarchy; |
|
67 | + $this->current = & $this->hierarchy; |
|
68 | 68 | $this->stack = array(); |
69 | 69 | } |
70 | 70 | |
@@ -80,30 +80,30 @@ discard block |
||
80 | 80 | // return $this->current[ $field ]; |
81 | 81 | // } |
82 | 82 | |
83 | - public function push_to( $field, $value ) { |
|
83 | + public function push_to($field, $value) { |
|
84 | 84 | |
85 | - if ( ! isset( $this->current[ $field ] ) ) { |
|
85 | + if ( ! isset($this->current[$field])) { |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | //var_dump( $field, $value,$this->current[ $field ] ); |
89 | - $this->current[ $field ][] = $value; |
|
89 | + $this->current[$field][] = $value; |
|
90 | 90 | } |
91 | 91 | |
92 | - public function set_sub_field( $slug, $field, $value ) { |
|
93 | - $this->current[ $this->descendant_index ][ $slug ][ $field ] = $value; |
|
92 | + public function set_sub_field($slug, $field, $value) { |
|
93 | + $this->current[$this->descendant_index][$slug][$field] = $value; |
|
94 | 94 | } |
95 | 95 | |
96 | - public function get_sub_field( $slug, $field ) { |
|
97 | - return $this->current[ $this->descendant_index ][ $slug ][ $field ]; |
|
96 | + public function get_sub_field($slug, $field) { |
|
97 | + return $this->current[$this->descendant_index][$slug][$field]; |
|
98 | 98 | } |
99 | 99 | |
100 | - public function get_sub_data( $slug ) { |
|
101 | - return $this->current[ $this->descendant_index ][ $slug ]; |
|
100 | + public function get_sub_data($slug) { |
|
101 | + return $this->current[$this->descendant_index][$slug]; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | public function ascend() { |
105 | 105 | |
106 | - if ( ! $this->stack ) { |
|
106 | + if ( ! $this->stack) { |
|
107 | 107 | return false; |
108 | 108 | } |
109 | 109 | |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - public function descend( $to = null ) { |
|
115 | + public function descend($to = null) { |
|
116 | 116 | |
117 | - if ( ! isset( $this->hierarchy[ $this->descendant_index ] ) ) { |
|
117 | + if ( ! isset($this->hierarchy[$this->descendant_index])) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - reset( $this->current[ $this->descendant_index ] ); |
|
122 | - $field = key( $this->current[ $this->descendant_index ] ); |
|
123 | - $this->current =& $this->current[ $this->descendant_index ][ $field ]; |
|
121 | + reset($this->current[$this->descendant_index]); |
|
122 | + $field = key($this->current[$this->descendant_index]); |
|
123 | + $this->current = & $this->current[$this->descendant_index][$field]; |
|
124 | 124 | |
125 | 125 | $this->stack[] = $this->current; |
126 | 126 | |
@@ -134,52 +134,52 @@ discard block |
||
134 | 134 | protected $current = 0; |
135 | 135 | protected $i = 0; |
136 | 136 | |
137 | - public function __construct( $descendant_index ) { |
|
137 | + public function __construct($descendant_index) { |
|
138 | 138 | $this->descendant_index = $descendant_index; |
139 | 139 | } |
140 | 140 | |
141 | 141 | public function get() { |
142 | 142 | // var_dump( $this->hierarchy ); |
143 | 143 | |
144 | - if ( empty( $this->hierarchy ) ) { |
|
144 | + if (empty($this->hierarchy)) { |
|
145 | 145 | return array(); |
146 | 146 | } |
147 | 147 | |
148 | - return $this->build_hierarchy( $this->hierarchy[0] ); |
|
148 | + return $this->build_hierarchy($this->hierarchy[0]); |
|
149 | 149 | } |
150 | 150 | |
151 | - protected function build_hierarchy( $arg ) { |
|
151 | + protected function build_hierarchy($arg) { |
|
152 | 152 | |
153 | - if ( isset( $arg[ $this->descendant_index ] ) ) { |
|
153 | + if (isset($arg[$this->descendant_index])) { |
|
154 | 154 | |
155 | - foreach ( $arg[ $this->descendant_index ] as $sub_arg => $i ) { |
|
156 | - $arg[ $this->descendant_index ][ $sub_arg ] = $this->build_hierarchy( $this->hierarchy[ $i ] ); |
|
155 | + foreach ($arg[$this->descendant_index] as $sub_arg => $i) { |
|
156 | + $arg[$this->descendant_index][$sub_arg] = $this->build_hierarchy($this->hierarchy[$i]); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - if ( isset( $arg['_parent'] ) ) { |
|
161 | - unset( $arg['_parent'] ); |
|
160 | + if (isset($arg['_parent'])) { |
|
161 | + unset($arg['_parent']); |
|
162 | 162 | } |
163 | 163 | |
164 | - unset( $arg['_i'] ); |
|
164 | + unset($arg['_i']); |
|
165 | 165 | |
166 | 166 | return $arg; |
167 | 167 | } |
168 | 168 | |
169 | - public function push( $field, $data ) { |
|
169 | + public function push($field, $data) { |
|
170 | 170 | |
171 | - if ( ! isset( $this->hierarchy[ $this->current ]['slug'] ) || $this->hierarchy[ $this->current ]['slug'] !== $field ) { |
|
171 | + if ( ! isset($this->hierarchy[$this->current]['slug']) || $this->hierarchy[$this->current]['slug'] !== $field) { |
|
172 | 172 | |
173 | 173 | $i = $this->i++; |
174 | 174 | |
175 | - if ( ! empty( $this->hierarchy ) ) { |
|
176 | - $this->hierarchy[ $this->current ][ $this->descendant_index ][ $field ] = $i; |
|
175 | + if ( ! empty($this->hierarchy)) { |
|
176 | + $this->hierarchy[$this->current][$this->descendant_index][$field] = $i; |
|
177 | 177 | $data['_parent'] = $this->current; |
178 | 178 | } |
179 | 179 | |
180 | - $this->hierarchy[ $i ] = $data; |
|
181 | - $this->hierarchy[ $i ]['slug'] = $field; |
|
182 | - $this->hierarchy[ $i ]['_i'] = $i; |
|
180 | + $this->hierarchy[$i] = $data; |
|
181 | + $this->hierarchy[$i]['slug'] = $field; |
|
182 | + $this->hierarchy[$i]['_i'] = $i; |
|
183 | 183 | |
184 | 184 | $this->current = $i; |
185 | 185 | } |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | |
188 | 188 | public function pop() { |
189 | 189 | |
190 | - $this->current = isset( $this->hierarchy[ $this->current ]['_parent'] ) |
|
191 | - ? $this->hierarchy[ $this->current ]['_parent'] |
|
190 | + $this->current = isset($this->hierarchy[$this->current]['_parent']) |
|
191 | + ? $this->hierarchy[$this->current]['_parent'] |
|
192 | 192 | : 0; |
193 | 193 | } |
194 | 194 | |
@@ -196,95 +196,95 @@ discard block |
||
196 | 196 | $this->current = 0; |
197 | 197 | } |
198 | 198 | |
199 | - public function set_field( $field, $value ) { |
|
200 | - $this->hierarchy[ $this->current ][ $field ] = $value; |
|
199 | + public function set_field($field, $value) { |
|
200 | + $this->hierarchy[$this->current][$field] = $value; |
|
201 | 201 | } |
202 | 202 | |
203 | - public function get_field( $field, $sub = null, $sub_2 = null ) { |
|
203 | + public function get_field($field, $sub = null, $sub_2 = null) { |
|
204 | 204 | |
205 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ] ) ) { |
|
205 | + if ( ! isset($this->hierarchy[$this->current][$field])) { |
|
206 | 206 | return null; |
207 | 207 | } |
208 | 208 | |
209 | - if ( isset( $sub ) ) { |
|
210 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ][ $sub ] ) ) { |
|
209 | + if (isset($sub)) { |
|
210 | + if ( ! isset($this->hierarchy[$this->current][$field][$sub])) { |
|
211 | 211 | return null; |
212 | 212 | } |
213 | 213 | |
214 | - if ( isset( $sub_2 ) ) { |
|
215 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ][ $sub ][ $sub_2 ] ) ) { |
|
214 | + if (isset($sub_2)) { |
|
215 | + if ( ! isset($this->hierarchy[$this->current][$field][$sub][$sub_2])) { |
|
216 | 216 | return null; |
217 | 217 | } else { |
218 | - return $this->hierarchy[ $this->current ][ $field ][ $sub ][ $sub_2 ]; |
|
218 | + return $this->hierarchy[$this->current][$field][$sub][$sub_2]; |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - return $this->hierarchy[ $this->current ][ $field ][ $sub ]; |
|
222 | + return $this->hierarchy[$this->current][$field][$sub]; |
|
223 | 223 | } |
224 | 224 | |
225 | - return $this->hierarchy[ $this->current ][ $field ]; |
|
225 | + return $this->hierarchy[$this->current][$field]; |
|
226 | 226 | } |
227 | 227 | |
228 | - public function push_to( $field, $value ) { |
|
228 | + public function push_to($field, $value) { |
|
229 | 229 | |
230 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ] ) ) { |
|
230 | + if ( ! isset($this->hierarchy[$this->current][$field])) { |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | //var_dump( $field, $value,$this->current[ $field ] ); |
234 | - $this->hierarchy[ $this->current ][ $field ][] = $value; |
|
234 | + $this->hierarchy[$this->current][$field][] = $value; |
|
235 | 235 | } |
236 | 236 | |
237 | - public function set_sub_field( $slug, $field, $value ) { |
|
238 | - $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ][ $field ] = $value; |
|
237 | + public function set_sub_field($slug, $field, $value) { |
|
238 | + $this->hierarchy[$this->current][$this->descendant_index][$slug][$field] = $value; |
|
239 | 239 | } |
240 | 240 | |
241 | - public function get_sub_field( $slug, $field ) { |
|
241 | + public function get_sub_field($slug, $field) { |
|
242 | 242 | |
243 | - return $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ][ $field ]; |
|
243 | + return $this->hierarchy[$this->current][$this->descendant_index][$slug][$field]; |
|
244 | 244 | } |
245 | 245 | |
246 | - public function get_sub_data( $slug ) { |
|
247 | - return $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ]; |
|
246 | + public function get_sub_data($slug) { |
|
247 | + return $this->hierarchy[$this->current][$this->descendant_index][$slug]; |
|
248 | 248 | } |
249 | 249 | |
250 | - public function has_child( $slug ) { |
|
251 | - return isset( $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ] ); |
|
250 | + public function has_child($slug) { |
|
251 | + return isset($this->hierarchy[$this->current][$this->descendant_index][$slug]); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | public function get_children() { |
255 | - return isset( $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ] ); |
|
255 | + return isset($this->hierarchy[$this->current][$this->descendant_index][$slug]); |
|
256 | 256 | |
257 | 257 | } |
258 | 258 | |
259 | 259 | public function ascend() { |
260 | 260 | |
261 | - if ( ! isset( $this->hierarchy[ $this->current ]['_parent'] ) ) { |
|
261 | + if ( ! isset($this->hierarchy[$this->current]['_parent'])) { |
|
262 | 262 | return false; |
263 | 263 | } |
264 | 264 | |
265 | - $this->current = $this->hierarchy[ $this->current ]['_parent']; |
|
265 | + $this->current = $this->hierarchy[$this->current]['_parent']; |
|
266 | 266 | |
267 | 267 | return true; |
268 | 268 | } |
269 | 269 | |
270 | - public function descend( $to = null ) { |
|
270 | + public function descend($to = null) { |
|
271 | 271 | |
272 | - if ( ! isset( $this->hierarchy[ $this->current ][ $this->descendant_index ] ) ) { |
|
272 | + if ( ! isset($this->hierarchy[$this->current][$this->descendant_index])) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | - if ( isset( $to ) ) { |
|
276 | + if (isset($to)) { |
|
277 | 277 | |
278 | - if ( ! isset( $this->hierarchy[ $this->current ][ $this->descendant_index ][ $to ] ) ) { |
|
278 | + if ( ! isset($this->hierarchy[$this->current][$this->descendant_index][$to])) { |
|
279 | 279 | return false; |
280 | 280 | } |
281 | 281 | |
282 | - $this->current = $this->hierarchy[ $this->current ][ $this->descendant_index ][ $to ]; |
|
282 | + $this->current = $this->hierarchy[$this->current][$this->descendant_index][$to]; |
|
283 | 283 | |
284 | 284 | } else { |
285 | 285 | |
286 | 286 | $this->current = reset( |
287 | - $this->hierarchy[ $this->current ][ $this->descendant_index ] |
|
287 | + $this->hierarchy[$this->current][$this->descendant_index] |
|
288 | 288 | ); |
289 | 289 | } |
290 | 290 | |
@@ -293,29 +293,29 @@ discard block |
||
293 | 293 | |
294 | 294 | public function next() { |
295 | 295 | |
296 | - if ( ! isset( $this->hierarchy[ $this->current ]['_parent'] ) ) { |
|
296 | + if ( ! isset($this->hierarchy[$this->current]['_parent'])) { |
|
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | - $parent = $this->hierarchy[ $this->current ]['_parent']; |
|
300 | + $parent = $this->hierarchy[$this->current]['_parent']; |
|
301 | 301 | |
302 | - if ( ! isset( $this->hierarchy[ $parent ][ $this->descendant_index ] ) ) { |
|
302 | + if ( ! isset($this->hierarchy[$parent][$this->descendant_index])) { |
|
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | |
306 | - $sub_args = $this->hierarchy[ $parent ][ $this->descendant_index ]; |
|
306 | + $sub_args = $this->hierarchy[$parent][$this->descendant_index]; |
|
307 | 307 | |
308 | - reset( $sub_args ); |
|
308 | + reset($sub_args); |
|
309 | 309 | |
310 | - while ( current( $sub_args ) !== $this->current ) { |
|
311 | - next( $sub_args ); |
|
310 | + while (current($sub_args) !== $this->current) { |
|
311 | + next($sub_args); |
|
312 | 312 | } |
313 | 313 | |
314 | - if ( ! next( $sub_args ) ) { |
|
314 | + if ( ! next($sub_args)) { |
|
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | |
318 | - $this->current = current( $sub_args ); |
|
318 | + $this->current = current($sub_args); |
|
319 | 319 | |
320 | 320 | return true; |
321 | 321 | } |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | return $this->current; |
325 | 325 | } |
326 | 326 | |
327 | - public function go_to( $id ) { |
|
327 | + public function go_to($id) { |
|
328 | 328 | |
329 | - if ( false === wordpoints_posint( $id ) || $id < 0 ) { |
|
329 | + if (false === wordpoints_posint($id) || $id < 0) { |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @since 1.0.0 |
19 | 19 | */ |
20 | 20 | public function get_title() { |
21 | - return __( 'Current Post', 'wordpoints' ); // TODO better title? |
|
21 | + return __('Current Post', 'wordpoints'); // TODO better title? |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function get_value() { |
28 | 28 | |
29 | - if ( ! is_main_query() ) { |
|
29 | + if ( ! is_main_query()) { |
|
30 | 30 | return false; |
31 | 31 | } |
32 | 32 | |
33 | 33 | $object = get_queried_object(); |
34 | 34 | |
35 | - if ( $object instanceof WP_Post ) { |
|
35 | + if ($object instanceof WP_Post) { |
|
36 | 36 | return $object; |
37 | 37 | } else { |
38 | 38 | return false; |
@@ -8,7 +8,7 @@ |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | interface WordPoints_Hook_Retroactive_Query_ModifierI { |
11 | - public function modify_retroactive_query( WordPoints_Hook_Retroactive_QueryI $query ); |
|
11 | + public function modify_retroactive_query(WordPoints_Hook_Retroactive_QueryI $query); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | // EOF |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | interface WordPoints_Hook_Retroactive_QueryI { |
52 | 52 | |
53 | - public function __construct( WordPoints_Hook_ReactionI $reaction ); |
|
53 | + public function __construct(WordPoints_Hook_ReactionI $reaction); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | public function get_reaction(); |
62 | 62 | public function get_validator(); |
63 | 63 | |
64 | - public function arg_hierarchy_push( $slug ); |
|
64 | + public function arg_hierarchy_push($slug); |
|
65 | 65 | public function arg_hierarchy_pop(); |
66 | 66 | public function get_arg(); |
67 | 67 | |
68 | - public function set_target( $target_arg ); |
|
68 | + public function set_target($target_arg); |
|
69 | 69 | public function select_value(); |
70 | - public function add_condition( array $condition ); |
|
70 | + public function add_condition(array $condition); |
|
71 | 71 | |
72 | 72 | public function get_results(); |
73 | 73 | } |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | |
10 | 10 | |
11 | 11 | interface WordPoints_Query_BuilderI { |
12 | - public function set_fields( $fields ); |
|
13 | - public function add_field( $field ); |
|
14 | - public function set_table( $table_name ); |
|
12 | + public function set_fields($fields); |
|
13 | + public function add_field($field); |
|
14 | + public function set_table($table_name); |
|
15 | 15 | public function get_table(); |
16 | - public function enter_join( $join ); |
|
16 | + public function enter_join($join); |
|
17 | 17 | public function exit_join(); |
18 | - public function where( $condition ); |
|
18 | + public function where($condition); |
|
19 | 19 | public function get_query(); |
20 | 20 | } |
21 | 21 | |
@@ -33,55 +33,55 @@ discard block |
||
33 | 33 | protected $aliases = array(); |
34 | 34 | |
35 | 35 | public function __construct() { |
36 | - $this->query = new WordPoints_Hierarchy( 'joins' ); |
|
37 | - $this->query->push( '', array() ); |
|
36 | + $this->query = new WordPoints_Hierarchy('joins'); |
|
37 | + $this->query->push('', array()); |
|
38 | 38 | } |
39 | 39 | |
40 | - public function set_fields( $fields ) { |
|
41 | - $this->query->set_field( 'fields', $fields ); |
|
40 | + public function set_fields($fields) { |
|
41 | + $this->query->set_field('fields', $fields); |
|
42 | 42 | } |
43 | 43 | |
44 | - public function add_field( $field ) { |
|
45 | - $this->query->push_to( 'fields', $field ); |
|
44 | + public function add_field($field) { |
|
45 | + $this->query->push_to('fields', $field); |
|
46 | 46 | } |
47 | 47 | |
48 | - public function set_table( $table_name ) { |
|
49 | - $this->query->set_field( 'table_name', $table_name ); |
|
48 | + public function set_table($table_name) { |
|
49 | + $this->query->set_field('table_name', $table_name); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function get_table() { |
53 | - return $this->query->get_field( 'table_name' ); |
|
53 | + return $this->query->get_field('table_name'); |
|
54 | 54 | } |
55 | 55 | |
56 | - protected function get_alias( $data ) { |
|
56 | + protected function get_alias($data) { |
|
57 | 57 | |
58 | - if ( ! isset( $this->aliases[ $data['table_name'] ] ) ) { |
|
59 | - $this->aliases[ $data['table_name'] ] = 0; |
|
58 | + if ( ! isset($this->aliases[$data['table_name']])) { |
|
59 | + $this->aliases[$data['table_name']] = 0; |
|
60 | 60 | } |
61 | 61 | |
62 | - return $data['table_name'] . '_' . ++$this->aliases[ $data['table_name'] ]; |
|
62 | + return $data['table_name'].'_'.++$this->aliases[$data['table_name']]; |
|
63 | 63 | } |
64 | 64 | |
65 | - public function enter_join( $join ) { |
|
66 | - $alias = $this->get_alias( $join ); |
|
67 | - $this->query->push( $alias, $join ); |
|
65 | + public function enter_join($join) { |
|
66 | + $alias = $this->get_alias($join); |
|
67 | + $this->query->push($alias, $join); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | public function exit_join() { |
71 | 71 | $this->query->pop(); |
72 | 72 | } |
73 | 73 | |
74 | - public function where( $condition ) { |
|
74 | + public function where($condition) { |
|
75 | 75 | |
76 | - $where = $this->query->get_field( 'where' ); |
|
76 | + $where = $this->query->get_field('where'); |
|
77 | 77 | |
78 | - if ( ! is_array( $where ) ) { |
|
78 | + if ( ! is_array($where)) { |
|
79 | 79 | $where = array(); |
80 | 80 | } |
81 | 81 | |
82 | 82 | $where[] = $condition; |
83 | 83 | |
84 | - $this->query->set_field( 'where', $where ); |
|
84 | + $this->query->set_field('where', $where); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -101,64 +101,64 @@ discard block |
||
101 | 101 | |
102 | 102 | var_dump($this->query); |
103 | 103 | try { |
104 | - $this->build_query( $this->query->get() ); |
|
105 | - } catch ( WordPoints_Query_Builder_Exception $e ) { |
|
106 | - return new WP_Error( $e->getMessage(), $e->getTraceAsString() ); |
|
104 | + $this->build_query($this->query->get()); |
|
105 | + } catch (WordPoints_Query_Builder_Exception $e) { |
|
106 | + return new WP_Error($e->getMessage(), $e->getTraceAsString()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | return $this->sql; |
110 | 110 | } |
111 | 111 | |
112 | - protected function build_query( $query ) { |
|
112 | + protected function build_query($query) { |
|
113 | 113 | |
114 | - var_dump( __METHOD__, $query ); |
|
114 | + var_dump(__METHOD__, $query); |
|
115 | 115 | |
116 | - $this->alias = $this->get_alias( $query ); |
|
116 | + $this->alias = $this->get_alias($query); |
|
117 | 117 | |
118 | - $this->build_fields( $query ); |
|
119 | - $this->build_from( $query ); |
|
120 | - $this->build_joins( $query ); |
|
121 | - $this->build_where( $query ); |
|
118 | + $this->build_fields($query); |
|
119 | + $this->build_from($query); |
|
120 | + $this->build_joins($query); |
|
121 | + $this->build_where($query); |
|
122 | 122 | $this->build_select(); |
123 | 123 | } |
124 | 124 | |
125 | 125 | protected function build_select() { |
126 | 126 | |
127 | - if ( empty( $this->fields ) ) { |
|
128 | - throw new WordPoints_Query_Builder_Exception( 'no fields' ); |
|
127 | + if (empty($this->fields)) { |
|
128 | + throw new WordPoints_Query_Builder_Exception('no fields'); |
|
129 | 129 | } |
130 | 130 | |
131 | - $this->sql = 'SELECT' . $this->fields . $this->sql; |
|
131 | + $this->sql = 'SELECT'.$this->fields.$this->sql; |
|
132 | 132 | } |
133 | 133 | |
134 | - protected function build_fields( $query ) { |
|
134 | + protected function build_fields($query) { |
|
135 | 135 | |
136 | - if ( empty( $query['fields'] ) ) { |
|
136 | + if (empty($query['fields'])) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
140 | - foreach ( $query['fields'] as $field ) { |
|
140 | + foreach ($query['fields'] as $field) { |
|
141 | 141 | |
142 | - if ( ! is_array( $field ) ) { |
|
143 | - $field = array( 'field' => $field ); |
|
142 | + if ( ! is_array($field)) { |
|
143 | + $field = array('field' => $field); |
|
144 | 144 | } |
145 | 145 | |
146 | - if ( ! isset( $field['field'] ) ) { |
|
147 | - throw new WordPoints_Query_Builder_Exception( 'invalid field' ); |
|
146 | + if ( ! isset($field['field'])) { |
|
147 | + throw new WordPoints_Query_Builder_Exception('invalid field'); |
|
148 | 148 | } |
149 | 149 | |
150 | - if ( ! empty( $this->fields ) ) { |
|
150 | + if ( ! empty($this->fields)) { |
|
151 | 151 | $this->fields .= ','; |
152 | 152 | } |
153 | 153 | |
154 | - $this->fields .= ' ' . $this->build_field( $field['field'] ); |
|
154 | + $this->fields .= ' '.$this->build_field($field['field']); |
|
155 | 155 | |
156 | 156 | $as = $field['field']; |
157 | - if ( isset( $field['as'] ) ) { |
|
157 | + if (isset($field['as'])) { |
|
158 | 158 | $as = $field['as']; |
159 | 159 | } |
160 | 160 | |
161 | - $this->fields .= ' AS `' . $this->escape_identifier( $as ) . '`'; |
|
161 | + $this->fields .= ' AS `'.$this->escape_identifier($as).'`'; |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -171,118 +171,118 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @throws WordPoints_Query_Builder_Exception |
173 | 173 | */ |
174 | - protected function build_field( $field ) { |
|
174 | + protected function build_field($field) { |
|
175 | 175 | |
176 | - $field_name = $this->get_field_name( $field ); |
|
176 | + $field_name = $this->get_field_name($field); |
|
177 | 177 | |
178 | - $sql = '`' . $this->escape_identifier( $this->alias ) . '`'; |
|
179 | - $sql .= '.`' . $this->escape_identifier( $field_name ) . '`'; |
|
178 | + $sql = '`'.$this->escape_identifier($this->alias).'`'; |
|
179 | + $sql .= '.`'.$this->escape_identifier($field_name).'`'; |
|
180 | 180 | |
181 | 181 | return $sql; |
182 | 182 | } |
183 | 183 | |
184 | - protected function build_from( $query ) { |
|
184 | + protected function build_from($query) { |
|
185 | 185 | |
186 | - if ( ! isset( $query['table_name'] ) ) { |
|
187 | - throw new WordPoints_Query_Builder_Exception( 'table_name' ); |
|
186 | + if ( ! isset($query['table_name'])) { |
|
187 | + throw new WordPoints_Query_Builder_Exception('table_name'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $this->sql .= "\n"; |
191 | - $this->sql .= 'FROM `' . $this->escape_identifier( $query['table_name'] ) . '`'; |
|
192 | - $this->sql .= ' AS `' . $this->escape_identifier( $this->alias ) . '`'; |
|
191 | + $this->sql .= 'FROM `'.$this->escape_identifier($query['table_name']).'`'; |
|
192 | + $this->sql .= ' AS `'.$this->escape_identifier($this->alias).'`'; |
|
193 | 193 | } |
194 | 194 | |
195 | - protected function build_joins( $query ) { |
|
195 | + protected function build_joins($query) { |
|
196 | 196 | |
197 | - if ( ! isset( $query['joins'] ) ) { |
|
197 | + if ( ! isset($query['joins'])) { |
|
198 | 198 | return; |
199 | 199 | } |
200 | 200 | |
201 | - foreach ( $query['joins'] as $join ) { |
|
202 | - $this->build_join( $join ); |
|
201 | + foreach ($query['joins'] as $join) { |
|
202 | + $this->build_join($join); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - protected function build_join( $join ) { |
|
206 | + protected function build_join($join) { |
|
207 | 207 | |
208 | - if ( ! isset( $join['table_name'] ) ) { |
|
209 | - throw new WordPoints_Query_Builder_Exception( 'join table_name' ); |
|
208 | + if ( ! isset($join['table_name'])) { |
|
209 | + throw new WordPoints_Query_Builder_Exception('join table_name'); |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( ! isset( $join['on'] ) ) { |
|
213 | - throw new WordPoints_Query_Builder_Exception( 'join on' ); |
|
212 | + if ( ! isset($join['on'])) { |
|
213 | + throw new WordPoints_Query_Builder_Exception('join on'); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( ! isset( $join['on']['join_field'] ) ) { |
|
217 | - throw new WordPoints_Query_Builder_Exception( 'join on join_field' ); |
|
216 | + if ( ! isset($join['on']['join_field'])) { |
|
217 | + throw new WordPoints_Query_Builder_Exception('join on join_field'); |
|
218 | 218 | } |
219 | 219 | |
220 | - if ( ! isset( $join['on']['primary_field'] ) ) { |
|
221 | - throw new WordPoints_Query_Builder_Exception( 'join on primary_field' ); |
|
220 | + if ( ! isset($join['on']['primary_field'])) { |
|
221 | + throw new WordPoints_Query_Builder_Exception('join on primary_field'); |
|
222 | 222 | } |
223 | 223 | |
224 | - $alias = $this->get_alias( $join ); |
|
224 | + $alias = $this->get_alias($join); |
|
225 | 225 | |
226 | 226 | $this->sql .= "\n"; |
227 | - $this->sql .= 'INNER JOIN `' . $this->escape_identifier( $join['table_name'] ) . '`'; |
|
228 | - $this->sql .= ' AS `' . $this->escape_identifier( $alias ) . '`'; |
|
229 | - $this->sql .= "\n\t" . 'ON ' . $this->build_field( $join['on']['primary_field'] ); |
|
227 | + $this->sql .= 'INNER JOIN `'.$this->escape_identifier($join['table_name']).'`'; |
|
228 | + $this->sql .= ' AS `'.$this->escape_identifier($alias).'`'; |
|
229 | + $this->sql .= "\n\t".'ON '.$this->build_field($join['on']['primary_field']); |
|
230 | 230 | |
231 | 231 | $old_alias = $this->alias; |
232 | 232 | $this->alias = $alias; |
233 | 233 | |
234 | - $this->sql .= ' = ' . $this->build_field( $join['on']['join_field'] ); |
|
234 | + $this->sql .= ' = '.$this->build_field($join['on']['join_field']); |
|
235 | 235 | |
236 | - $this->build_fields( $join ); |
|
236 | + $this->build_fields($join); |
|
237 | 237 | |
238 | - if ( isset( $join['where'] ) ) { |
|
239 | - foreach ( $join['where'] as $condition ) { |
|
240 | - $this->build_condition( $condition ); |
|
238 | + if (isset($join['where'])) { |
|
239 | + foreach ($join['where'] as $condition) { |
|
240 | + $this->build_condition($condition); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - $this->build_joins( $join ); |
|
244 | + $this->build_joins($join); |
|
245 | 245 | |
246 | 246 | $this->alias = $old_alias; |
247 | 247 | } |
248 | 248 | |
249 | - protected function build_where( $query ) { |
|
249 | + protected function build_where($query) { |
|
250 | 250 | |
251 | - if ( empty( $query['where'] ) ) { |
|
251 | + if (empty($query['where'])) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | $this->sql .= "\n"; |
256 | 256 | $this->sql .= 'WHERE 1=1'; |
257 | 257 | |
258 | - foreach ( $query['where'] as $condition ) { |
|
259 | - $this->build_condition( $condition ); |
|
258 | + foreach ($query['where'] as $condition) { |
|
259 | + $this->build_condition($condition); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - protected function build_condition( $condition ) { |
|
263 | + protected function build_condition($condition) { |
|
264 | 264 | |
265 | 265 | global $wpdb; |
266 | 266 | |
267 | - if ( ! isset( $condition['field'], $condition['value'] ) ) { |
|
267 | + if ( ! isset($condition['field'], $condition['value'])) { |
|
268 | 268 | var_dump($condition); |
269 | - throw new WordPoints_Query_Builder_Exception( 'bad condition' ); |
|
269 | + throw new WordPoints_Query_Builder_Exception('bad condition'); |
|
270 | 270 | } |
271 | 271 | |
272 | - if ( ! isset( $condition['compare'] ) ) { |
|
272 | + if ( ! isset($condition['compare'])) { |
|
273 | 273 | $condition['compare'] = '='; |
274 | 274 | } |
275 | 275 | |
276 | 276 | $this->sql .= "\n\t"; |
277 | 277 | |
278 | - $this->build_condition_type( $condition ); |
|
278 | + $this->build_condition_type($condition); |
|
279 | 279 | |
280 | - $field_type = $this->get_field_type( $condition['field'] ); |
|
281 | - if ( 'serialized_array' === $field_type ) { |
|
282 | - if ( is_array( $condition['value'] ) ) { |
|
283 | - if ( isset( $condition['compare'] ) && 'in' === $condition['compare'] ) { |
|
280 | + $field_type = $this->get_field_type($condition['field']); |
|
281 | + if ('serialized_array' === $field_type) { |
|
282 | + if (is_array($condition['value'])) { |
|
283 | + if (isset($condition['compare']) && 'in' === $condition['compare']) { |
|
284 | 284 | $this->sql .= '( 1=0 '; |
285 | - foreach ( $condition['value'] as $index => $value ) { |
|
285 | + foreach ($condition['value'] as $index => $value) { |
|
286 | 286 | $this->build_condition( |
287 | 287 | array( |
288 | 288 | 'type' => 'or', |
@@ -296,13 +296,13 @@ discard block |
||
296 | 296 | return; |
297 | 297 | } |
298 | 298 | } else { |
299 | - $condition['value'] = $this->serialize_value( $condition['value'] ); |
|
299 | + $condition['value'] = $this->serialize_value($condition['value']); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - $this->sql .= $this->build_field( $condition['field'] ); |
|
303 | + $this->sql .= $this->build_field($condition['field']); |
|
304 | 304 | |
305 | - switch ( $condition['compare'] ) { |
|
305 | + switch ($condition['compare']) { |
|
306 | 306 | |
307 | 307 | case '=': |
308 | 308 | $this->sql .= ' = '; |
@@ -313,18 +313,18 @@ discard block |
||
313 | 313 | break; |
314 | 314 | |
315 | 315 | case 'in': |
316 | - $this->sql .= ' IN (' . wordpoints_prepare__in( $condition['value'] ) . ')'; |
|
316 | + $this->sql .= ' IN ('.wordpoints_prepare__in($condition['value']).')'; |
|
317 | 317 | return; |
318 | 318 | |
319 | 319 | default: |
320 | - throw new WordPoints_Query_Builder_Exception( 'bad condition comparison' ); |
|
320 | + throw new WordPoints_Query_Builder_Exception('bad condition comparison'); |
|
321 | 321 | } |
322 | 322 | |
323 | - if ( ! is_scalar( $condition['value'] ) ) { |
|
324 | - throw new WordPoints_Query_Builder_Exception( 'bad condition value' ); |
|
323 | + if ( ! is_scalar($condition['value'])) { |
|
324 | + throw new WordPoints_Query_Builder_Exception('bad condition value'); |
|
325 | 325 | } |
326 | 326 | |
327 | - $this->sql .= $wpdb->prepare( '%s', $condition['value'] ); |
|
327 | + $this->sql .= $wpdb->prepare('%s', $condition['value']); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -336,13 +336,13 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @throws WordPoints_Query_Builder_Exception |
338 | 338 | */ |
339 | - protected function build_condition_type( $condition ) { |
|
339 | + protected function build_condition_type($condition) { |
|
340 | 340 | |
341 | - if ( ! isset( $condition['type'] ) ) { |
|
341 | + if ( ! isset($condition['type'])) { |
|
342 | 342 | $condition['type'] = 'and'; |
343 | 343 | } |
344 | 344 | |
345 | - switch ( $condition['type'] ) { |
|
345 | + switch ($condition['type']) { |
|
346 | 346 | |
347 | 347 | case 'and': |
348 | 348 | $this->sql .= 'AND '; |
@@ -353,21 +353,21 @@ discard block |
||
353 | 353 | break; |
354 | 354 | |
355 | 355 | default: |
356 | - throw new WordPoints_Query_Builder_Exception( 'bad condition type' ); |
|
356 | + throw new WordPoints_Query_Builder_Exception('bad condition type'); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
360 | - protected function escape_identifier( $identifier ) { |
|
360 | + protected function escape_identifier($identifier) { |
|
361 | 361 | |
362 | - return str_replace( '`', '``', $identifier ); |
|
362 | + return str_replace('`', '``', $identifier); |
|
363 | 363 | } |
364 | 364 | |
365 | - protected function get_field_name( $field ) { |
|
365 | + protected function get_field_name($field) { |
|
366 | 366 | |
367 | - if ( is_array( $field ) ) { |
|
367 | + if (is_array($field)) { |
|
368 | 368 | |
369 | - if ( ! isset( $field['name'] ) ) { |
|
370 | - throw new WordPoints_Query_Builder_Exception( 'field name' ); |
|
369 | + if ( ! isset($field['name'])) { |
|
370 | + throw new WordPoints_Query_Builder_Exception('field name'); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | $field = $field['name']; |
@@ -376,22 +376,22 @@ discard block |
||
376 | 376 | return $field; |
377 | 377 | } |
378 | 378 | |
379 | - protected function get_field_type( $field ) { |
|
379 | + protected function get_field_type($field) { |
|
380 | 380 | |
381 | - if ( is_array( $field ) && isset( $field['type'] ) ) { |
|
381 | + if (is_array($field) && isset($field['type'])) { |
|
382 | 382 | return $field['type']; |
383 | 383 | } |
384 | 384 | |
385 | 385 | return 'string'; |
386 | 386 | } |
387 | 387 | |
388 | - protected function serialize_value( $value ) { |
|
388 | + protected function serialize_value($value) { |
|
389 | 389 | |
390 | - if ( is_string( $value ) ) { |
|
391 | - $value = '"' . $value . '"'; |
|
390 | + if (is_string($value)) { |
|
391 | + $value = '"'.$value.'"'; |
|
392 | 392 | } |
393 | 393 | |
394 | - return '%:' . $value . ';%'; |
|
394 | + return '%:'.$value.';%'; |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function get_value() { |
26 | 26 | |
27 | - if ( wordpoints_is_network_context() ) { |
|
27 | + if (wordpoints_is_network_context()) { |
|
28 | 28 | return false; |
29 | 29 | } |
30 | 30 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | 37 | public function get_title() { |
38 | - return __( 'Site', 'wordpoints' ); |
|
38 | + return __('Site', 'wordpoints'); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 |