1
|
|
|
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Class EE_SPCO_JSON_Response |
5
|
|
|
* |
6
|
|
|
* Description |
7
|
|
|
* |
8
|
|
|
* @package Event Espresso |
9
|
|
|
* @subpackage core |
10
|
|
|
* @author Brent Christensen |
11
|
|
|
* |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
class EE_SPCO_JSON_Response { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $_errors = ''; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $_unexpected_errors = ''; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $_attention = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $_success = ''; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $_plz_select_method_of_payment = ''; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $_redirect_url = ''; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected $_registration_time_limit = ''; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $_redirect_form = ''; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
protected $_reg_step_html = ''; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
protected $_method_of_payment = ''; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var float |
68
|
|
|
*/ |
69
|
|
|
protected $_payment_amount; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var array |
73
|
|
|
*/ |
74
|
|
|
protected $_return_data = array(); |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var array |
79
|
|
|
*/ |
80
|
|
|
protected $_validation_rules = array(); |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* class constructor |
87
|
|
|
*/ |
88
|
|
|
public function __construct( ) { |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* __toString |
96
|
|
|
* |
97
|
|
|
* allows you to simply echo or print an EE_SPCO_JSON_Response object to produce a JSON encoded string |
98
|
|
|
* ie: $json_response = new EE_SPCO_JSON_Response(); |
99
|
|
|
* echo $json_response; |
100
|
|
|
* |
101
|
|
|
* @access public |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function __toString() { |
105
|
|
|
$JSON_response = array(); |
106
|
|
|
// grab notices |
107
|
|
|
$notices = EE_Error::get_notices( FALSE ); |
108
|
|
|
$this->set_attention( isset( $notices['attention'] ) ? $notices['attention'] : '' ); |
109
|
|
|
$this->set_errors( isset( $notices['errors'] ) ? $notices['errors'] : '' ); |
110
|
|
|
$this->set_success( isset( $notices['success'] ) ? $notices['success'] : '' ); |
111
|
|
|
// add notices to JSON response, but only if they exist |
112
|
|
|
if ( $this->attention() ) { |
113
|
|
|
$JSON_response['attention'] = $this->attention(); |
114
|
|
|
} |
115
|
|
|
if ( $this->errors() ) { |
116
|
|
|
$JSON_response['errors'] = $this->errors(); |
117
|
|
|
} |
118
|
|
|
if ( $this->unexpected_errors() ) { |
119
|
|
|
$JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
120
|
|
|
} |
121
|
|
|
if ( $this->success() ) { |
122
|
|
|
$JSON_response['success'] = $this->success(); |
123
|
|
|
} |
124
|
|
|
// but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
125
|
|
|
if ( ! isset( $JSON_response[ 'attention' ] ) && ! isset( $JSON_response[ 'errors' ] ) && ! isset( $JSON_response[ 'success' ] ) ) { |
126
|
|
|
$JSON_response['success'] = null; |
127
|
|
|
} |
128
|
|
|
// set redirect_url, IF it exists |
129
|
|
|
if ( $this->redirect_url() ) { |
130
|
|
|
$JSON_response['redirect_url'] = $this->redirect_url(); |
131
|
|
|
} |
132
|
|
|
// set registration_time_limit, IF it exists |
133
|
|
|
if ( $this->registration_time_limit() ) { |
134
|
|
|
$JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
135
|
|
|
} |
136
|
|
|
// set payment_amount, IF it exists |
137
|
|
|
if ( $this->payment_amount() !== null ) { |
138
|
|
|
$JSON_response[ 'payment_amount' ] = $this->payment_amount(); |
139
|
|
|
} |
140
|
|
|
// grab generic return data |
141
|
|
|
$return_data = $this->return_data(); |
142
|
|
|
// add billing form validation rules |
143
|
|
|
if ( $this->validation_rules() ) { |
144
|
|
|
$return_data['validation_rules'] = $this->validation_rules(); |
145
|
|
|
} |
146
|
|
|
// set reg_step_html, IF it exists |
147
|
|
|
if ( $this->reg_step_html() ) { |
148
|
|
|
$return_data['reg_step_html'] = $this->reg_step_html(); |
149
|
|
|
} |
150
|
|
|
// set method of payment, IF it exists |
151
|
|
|
if ( $this->method_of_payment() ) { |
152
|
|
|
$return_data['method_of_payment'] = $this->method_of_payment(); |
153
|
|
|
} |
154
|
|
|
// set "plz_select_method_of_payment" message, IF it exists |
155
|
|
|
if ( $this->plz_select_method_of_payment() ) { |
156
|
|
|
$return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
157
|
|
|
} |
158
|
|
|
// set redirect_form, IF it exists |
159
|
|
|
if ( $this->redirect_form() ) { |
|
|
|
|
160
|
|
|
$return_data['redirect_form'] = $this->redirect_form(); |
161
|
|
|
} |
162
|
|
|
// and finally, add return_data array to main JSON response array, IF it contains anything |
163
|
|
|
// why did we add some of the above properties to the return data array? |
164
|
|
|
// because it is easier and cleaner in the Javascript to deal with this way |
165
|
|
|
if ( ! empty( $return_data )) { |
166
|
|
|
$JSON_response['return_data'] = $return_data; |
167
|
|
|
} |
168
|
|
|
// filter final array |
169
|
|
|
$JSON_response = apply_filters( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response ); |
170
|
|
|
// return encoded array |
171
|
|
|
return (string) wp_json_encode( $JSON_response ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param string $attention |
178
|
|
|
*/ |
179
|
|
|
public function set_attention( $attention ) { |
180
|
|
|
$this->_attention = $attention; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function attention() { |
189
|
|
|
return $this->_attention; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param string $errors |
196
|
|
|
*/ |
197
|
|
|
public function set_errors( $errors ) { |
198
|
|
|
$this->_errors = $errors; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
|
|
public function errors() { |
207
|
|
|
return $this->_errors; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
public function unexpected_errors() { |
216
|
|
|
return $this->_unexpected_errors; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param string $unexpected_errors |
223
|
|
|
*/ |
224
|
|
|
public function set_unexpected_errors( $unexpected_errors ) { |
225
|
|
|
$this->_unexpected_errors = $unexpected_errors; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param string $success |
232
|
|
|
*/ |
233
|
|
|
public function set_success( $success ) { |
234
|
|
|
$this->_success = $success; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @return string |
241
|
|
|
*/ |
242
|
|
|
public function success() { |
243
|
|
|
return $this->_success; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
|
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param string $method_of_payment |
250
|
|
|
*/ |
251
|
|
|
public function set_method_of_payment( $method_of_payment ) { |
252
|
|
|
$this->_method_of_payment = $method_of_payment; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @return string |
259
|
|
|
*/ |
260
|
|
|
public function method_of_payment() { |
261
|
|
|
return $this->_method_of_payment; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return float |
268
|
|
|
*/ |
269
|
|
|
public function payment_amount() { |
270
|
|
|
return $this->_payment_amount; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param float $payment_amount |
276
|
|
|
* @throws EE_Error |
277
|
|
|
*/ |
278
|
|
|
public function set_payment_amount( $payment_amount ) { |
279
|
|
|
$this->_payment_amount = (float)$payment_amount; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param string $next_step_html |
286
|
|
|
*/ |
287
|
|
|
public function set_reg_step_html( $next_step_html ) { |
288
|
|
|
$this->_reg_step_html = $next_step_html; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @return string |
295
|
|
|
*/ |
296
|
|
|
public function reg_step_html() { |
297
|
|
|
return $this->_reg_step_html; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
|
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @param string $redirect_form |
304
|
|
|
*/ |
305
|
|
|
public function set_redirect_form( $redirect_form ) { |
306
|
|
|
$this->_redirect_form = $redirect_form; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
|
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @return string |
313
|
|
|
*/ |
314
|
|
|
public function redirect_form() { |
315
|
|
|
return ! empty( $this->_redirect_form ) ? $this->_redirect_form : FALSE; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
|
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @param string $plz_select_method_of_payment |
322
|
|
|
*/ |
323
|
|
|
public function set_plz_select_method_of_payment( $plz_select_method_of_payment ) { |
324
|
|
|
$this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @return string |
331
|
|
|
*/ |
332
|
|
|
public function plz_select_method_of_payment() { |
333
|
|
|
return $this->_plz_select_method_of_payment; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
|
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @param string $redirect_url |
340
|
|
|
*/ |
341
|
|
|
public function set_redirect_url( $redirect_url ) { |
342
|
|
|
$this->_redirect_url = $redirect_url; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
|
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @return string |
349
|
|
|
*/ |
350
|
|
|
public function redirect_url() { |
351
|
|
|
return $this->_redirect_url; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @return string |
358
|
|
|
*/ |
359
|
|
|
public function registration_time_limit() { |
360
|
|
|
return $this->_registration_time_limit; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* @param string $registration_time_limit |
367
|
|
|
*/ |
368
|
|
|
public function set_registration_time_limit( $registration_time_limit ) { |
369
|
|
|
$this->_registration_time_limit = $registration_time_limit; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
|
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* @param array $return_data |
376
|
|
|
*/ |
377
|
|
|
public function set_return_data( $return_data ) { |
378
|
|
|
$this->_return_data = array_merge( $this->_return_data, $return_data ); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
|
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @return array |
385
|
|
|
*/ |
386
|
|
|
public function return_data() { |
387
|
|
|
return $this->_return_data; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
|
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @param array $validation_rules |
394
|
|
|
*/ |
395
|
|
|
public function add_validation_rules(array $validation_rules = array()) { |
396
|
|
|
if ( is_array( $validation_rules ) && ! empty( $validation_rules )) { |
397
|
|
|
$this->_validation_rules = array_merge( $this->_validation_rules, $validation_rules ); |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
|
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @return array | bool |
405
|
|
|
*/ |
406
|
|
|
public function validation_rules() { |
407
|
|
|
return ! empty( $this->_validation_rules ) ? $this->_validation_rules : FALSE; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
|
411
|
|
|
public function echoAndExit() |
412
|
|
|
{ |
413
|
|
|
echo $this; |
414
|
|
|
exit(); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
} |
418
|
|
|
// End of file EE_SPCO_JSON_Response.php |
419
|
|
|
// Location: /EE_SPCO_JSON_Response.php |
420
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: