@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function setBaseUrl($base_url) |
142 | 142 | { |
143 | - if (! is_string($base_url)) { |
|
143 | + if ( ! is_string($base_url)) { |
|
144 | 144 | throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
145 | 145 | } |
146 | 146 | if (empty($base_url)) { |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
173 | 173 | { |
174 | - if (! is_string($form_step_url_key)) { |
|
174 | + if ( ! is_string($form_step_url_key)) { |
|
175 | 175 | throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
176 | 176 | } |
177 | 177 | $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | protected function setDefaultFormStep($default_form_step) |
195 | 195 | { |
196 | - if (! is_string($default_form_step)) { |
|
196 | + if ( ! is_string($default_form_step)) { |
|
197 | 197 | throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
198 | 198 | } |
199 | 199 | $this->default_form_step = $default_form_step; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | protected function setCurrentStepFromRequest() |
209 | 209 | { |
210 | 210 | $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
211 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
211 | + if ( ! $this->form_steps->setCurrent($current_step_slug)) { |
|
212 | 212 | throw new InvalidIdentifierException( |
213 | 213 | $current_step_slug, |
214 | 214 | $this->defaultFormStep(), |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function getCurrentStep() |
229 | 229 | { |
230 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
230 | + if ( ! $this->form_steps->current() instanceof SequentialStepForm) { |
|
231 | 231 | throw new InvalidFormHandlerException($this->form_steps->current()); |
232 | 232 | } |
233 | 233 | return $this->form_steps->current(); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function formAction() |
242 | 242 | { |
243 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
243 | + if ( ! is_string($this->form_action) || empty($this->form_action)) { |
|
244 | 244 | $this->form_action = $this->baseUrl(); |
245 | 245 | } |
246 | 246 | return $this->form_action; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function setFormAction($form_action) |
255 | 255 | { |
256 | - if (! is_string($form_action)) { |
|
256 | + if ( ! is_string($form_action)) { |
|
257 | 257 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
258 | 258 | } |
259 | 259 | $this->form_action = $form_action; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function addFormActionArgs($form_action_args = array()) |
269 | 269 | { |
270 | - if (! is_array($form_action_args)) { |
|
270 | + if ( ! is_array($form_action_args)) { |
|
271 | 271 | throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
272 | 272 | } |
273 | 273 | $form_action_args = ! empty($form_action_args) |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | protected function getProgressStepsCollection() |
333 | 333 | { |
334 | 334 | static $collection = null; |
335 | - if (! $collection instanceof ProgressStepCollection) { |
|
335 | + if ( ! $collection instanceof ProgressStepCollection) { |
|
336 | 336 | $collection = new ProgressStepCollection(); |
337 | 337 | } |
338 | 338 | return $collection; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | /** @var SequentialStepForm $form_step */ |
355 | 355 | foreach ($this->form_steps as $form_step) { |
356 | 356 | // is this step active ? |
357 | - if (! $form_step->initialize()) { |
|
357 | + if ( ! $form_step->initialize()) { |
|
358 | 358 | continue; |
359 | 359 | } |
360 | 360 | $progress_steps_collection->add( |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | { |
424 | 424 | $form_step = $this->buildCurrentStepForm(); |
425 | 425 | // no displayable content ? then skip straight to processing |
426 | - if (! $form_step->displayable()) { |
|
426 | + if ( ! $form_step->displayable()) { |
|
427 | 427 | $this->addFormActionArgs(); |
428 | 428 | $form_step->setFormAction($this->formAction()); |
429 | 429 | wp_safe_redirect($form_step->formAction()); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | public function displayProgressSteps($return_as_string = true) |
500 | 500 | { |
501 | 501 | $form_step = $this->getCurrentStep(); |
502 | - if (! $form_step->displayable()) { |
|
502 | + if ( ! $form_step->displayable()) { |
|
503 | 503 | return ''; |
504 | 504 | } |
505 | 505 | $progress_steps = apply_filters( |
@@ -30,583 +30,583 @@ |
||
30 | 30 | */ |
31 | 31 | abstract class SequentialStepFormManager |
32 | 32 | { |
33 | - /** |
|
34 | - * a simplified URL with no form related parameters |
|
35 | - * that will be used to build the form's redirect URLs |
|
36 | - * |
|
37 | - * @var string $base_url |
|
38 | - */ |
|
39 | - private $base_url = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * the key used for the URL param that denotes the current form step |
|
43 | - * defaults to 'ee-form-step' |
|
44 | - * |
|
45 | - * @var string $form_step_url_key |
|
46 | - */ |
|
47 | - private $form_step_url_key = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string $default_form_step |
|
51 | - */ |
|
52 | - private $default_form_step = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string $form_action |
|
56 | - */ |
|
57 | - private $form_action; |
|
58 | - |
|
59 | - /** |
|
60 | - * value of one of the string constant above |
|
61 | - * |
|
62 | - * @var string $form_config |
|
63 | - */ |
|
64 | - private $form_config; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $progress_step_style |
|
68 | - */ |
|
69 | - private $progress_step_style = ''; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var RequestInterface $request |
|
73 | - */ |
|
74 | - private $request; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var Collection $form_steps |
|
78 | - */ |
|
79 | - protected $form_steps; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var ProgressStepManager $progress_step_manager |
|
83 | - */ |
|
84 | - protected $progress_step_manager; |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return Collection|null |
|
89 | - */ |
|
90 | - abstract protected function getFormStepsCollection(); |
|
91 | - |
|
92 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
93 | - /** |
|
94 | - * StepsManager constructor |
|
95 | - * |
|
96 | - * @param string $base_url |
|
97 | - * @param string $default_form_step |
|
98 | - * @param string $form_action |
|
99 | - * @param string $form_config |
|
100 | - * @param EE_Request|RequestInterface|null $request |
|
101 | - * @param string $progress_step_style |
|
102 | - * @throws InvalidDataTypeException |
|
103 | - * @throws InvalidArgumentException |
|
104 | - */ |
|
105 | - public function __construct( |
|
106 | - $base_url, |
|
107 | - $default_form_step, |
|
108 | - $form_action = '', |
|
109 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
110 | - $progress_step_style = 'number_bubbles', |
|
111 | - $request = null |
|
112 | - ) { |
|
113 | - $this->setBaseUrl($base_url); |
|
114 | - $this->setDefaultFormStep($default_form_step); |
|
115 | - $this->setFormAction($form_action); |
|
116 | - $this->setFormConfig($form_config); |
|
117 | - $this->setProgressStepStyle($progress_step_style); |
|
118 | - $this->request = $request instanceof RequestInterface |
|
119 | - ? $request |
|
120 | - : LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - * @throws InvalidFormHandlerException |
|
127 | - */ |
|
128 | - public function baseUrl() |
|
129 | - { |
|
130 | - if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
131 | - add_query_arg( |
|
132 | - array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
133 | - $this->base_url |
|
134 | - ); |
|
135 | - } |
|
136 | - return $this->base_url; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $base_url |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - * @throws InvalidArgumentException |
|
144 | - */ |
|
145 | - protected function setBaseUrl($base_url) |
|
146 | - { |
|
147 | - if (! is_string($base_url)) { |
|
148 | - throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
149 | - } |
|
150 | - if (empty($base_url)) { |
|
151 | - throw new InvalidArgumentException( |
|
152 | - esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
153 | - ); |
|
154 | - } |
|
155 | - $this->base_url = $base_url; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string |
|
161 | - * @throws InvalidDataTypeException |
|
162 | - */ |
|
163 | - public function formStepUrlKey() |
|
164 | - { |
|
165 | - if (empty($this->form_step_url_key)) { |
|
166 | - $this->setFormStepUrlKey(); |
|
167 | - } |
|
168 | - return $this->form_step_url_key; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param string $form_step_url_key |
|
174 | - * @throws InvalidDataTypeException |
|
175 | - */ |
|
176 | - public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
177 | - { |
|
178 | - if (! is_string($form_step_url_key)) { |
|
179 | - throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
180 | - } |
|
181 | - $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function defaultFormStep() |
|
189 | - { |
|
190 | - return $this->default_form_step; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @param $default_form_step |
|
196 | - * @throws InvalidDataTypeException |
|
197 | - */ |
|
198 | - protected function setDefaultFormStep($default_form_step) |
|
199 | - { |
|
200 | - if (! is_string($default_form_step)) { |
|
201 | - throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
202 | - } |
|
203 | - $this->default_form_step = $default_form_step; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * @return void |
|
209 | - * @throws InvalidIdentifierException |
|
210 | - * @throws InvalidDataTypeException |
|
211 | - */ |
|
212 | - protected function setCurrentStepFromRequest() |
|
213 | - { |
|
214 | - $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
|
215 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
216 | - throw new InvalidIdentifierException( |
|
217 | - $current_step_slug, |
|
218 | - $this->defaultFormStep(), |
|
219 | - sprintf( |
|
220 | - esc_html__('The "%1$s" form step could not be set.', 'event_espresso'), |
|
221 | - $current_step_slug |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @return SequentialStepFormInterface|object |
|
230 | - * @throws InvalidFormHandlerException |
|
231 | - */ |
|
232 | - public function getCurrentStep() |
|
233 | - { |
|
234 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
235 | - throw new InvalidFormHandlerException($this->form_steps->current()); |
|
236 | - } |
|
237 | - return $this->form_steps->current(); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return string |
|
243 | - * @throws InvalidFormHandlerException |
|
244 | - */ |
|
245 | - public function formAction() |
|
246 | - { |
|
247 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
248 | - $this->form_action = $this->baseUrl(); |
|
249 | - } |
|
250 | - return $this->form_action; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param string $form_action |
|
256 | - * @throws InvalidDataTypeException |
|
257 | - */ |
|
258 | - public function setFormAction($form_action) |
|
259 | - { |
|
260 | - if (! is_string($form_action)) { |
|
261 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
262 | - } |
|
263 | - $this->form_action = $form_action; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @param array $form_action_args |
|
269 | - * @throws InvalidDataTypeException |
|
270 | - * @throws InvalidFormHandlerException |
|
271 | - */ |
|
272 | - public function addFormActionArgs($form_action_args = array()) |
|
273 | - { |
|
274 | - if (! is_array($form_action_args)) { |
|
275 | - throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
276 | - } |
|
277 | - $form_action_args = ! empty($form_action_args) |
|
278 | - ? $form_action_args |
|
279 | - : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
280 | - $this->getCurrentStep()->setFormAction( |
|
281 | - add_query_arg($form_action_args, $this->formAction()) |
|
282 | - ); |
|
283 | - $this->form_action = $this->getCurrentStep()->formAction(); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @return string |
|
289 | - */ |
|
290 | - public function formConfig() |
|
291 | - { |
|
292 | - return $this->form_config; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param string $form_config |
|
298 | - */ |
|
299 | - public function setFormConfig($form_config) |
|
300 | - { |
|
301 | - $this->form_config = $form_config; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - public function progressStepStyle() |
|
309 | - { |
|
310 | - return $this->progress_step_style; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $progress_step_style |
|
316 | - */ |
|
317 | - public function setProgressStepStyle($progress_step_style) |
|
318 | - { |
|
319 | - $this->progress_step_style = $progress_step_style; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @return RequestInterface |
|
325 | - */ |
|
326 | - public function request() |
|
327 | - { |
|
328 | - return $this->request; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * @return Collection|null |
|
334 | - * @throws InvalidInterfaceException |
|
335 | - */ |
|
336 | - protected function getProgressStepsCollection() |
|
337 | - { |
|
338 | - static $collection = null; |
|
339 | - if (! $collection instanceof ProgressStepCollection) { |
|
340 | - $collection = new ProgressStepCollection(); |
|
341 | - } |
|
342 | - return $collection; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param Collection $progress_steps_collection |
|
348 | - * @return ProgressStepManager |
|
349 | - * @throws InvalidInterfaceException |
|
350 | - * @throws InvalidClassException |
|
351 | - * @throws InvalidDataTypeException |
|
352 | - * @throws InvalidEntityException |
|
353 | - * @throws InvalidFormHandlerException |
|
354 | - */ |
|
355 | - protected function generateProgressSteps(Collection $progress_steps_collection) |
|
356 | - { |
|
357 | - $current_step = $this->getCurrentStep(); |
|
358 | - /** @var SequentialStepForm $form_step */ |
|
359 | - foreach ($this->form_steps as $form_step) { |
|
360 | - // is this step active ? |
|
361 | - if (! $form_step->initialize()) { |
|
362 | - continue; |
|
363 | - } |
|
364 | - $progress_steps_collection->add( |
|
365 | - new ProgressStep( |
|
366 | - $form_step->order(), |
|
367 | - $form_step->slug(), |
|
368 | - $form_step->slug(), |
|
369 | - $form_step->formName() |
|
370 | - ), |
|
371 | - $form_step->slug() |
|
372 | - ); |
|
373 | - } |
|
374 | - // set collection pointer back to current step |
|
375 | - $this->form_steps->setCurrentUsingObject($current_step); |
|
376 | - return new ProgressStepManager( |
|
377 | - $this->progressStepStyle(), |
|
378 | - $this->defaultFormStep(), |
|
379 | - $this->formStepUrlKey(), |
|
380 | - $progress_steps_collection |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @throws InvalidClassException |
|
387 | - * @throws InvalidDataTypeException |
|
388 | - * @throws InvalidEntityException |
|
389 | - * @throws InvalidIdentifierException |
|
390 | - * @throws InvalidInterfaceException |
|
391 | - * @throws InvalidArgumentException |
|
392 | - * @throws InvalidFormHandlerException |
|
393 | - */ |
|
394 | - public function buildForm() |
|
395 | - { |
|
396 | - $this->buildCurrentStepFormForDisplay(); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * @param array $form_data |
|
402 | - * @throws InvalidArgumentException |
|
403 | - * @throws InvalidClassException |
|
404 | - * @throws InvalidDataTypeException |
|
405 | - * @throws InvalidEntityException |
|
406 | - * @throws InvalidFormHandlerException |
|
407 | - * @throws InvalidIdentifierException |
|
408 | - * @throws InvalidInterfaceException |
|
409 | - */ |
|
410 | - public function processForm($form_data = array()) |
|
411 | - { |
|
412 | - $this->buildCurrentStepFormForProcessing(); |
|
413 | - $this->processCurrentStepForm($form_data); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * @throws InvalidClassException |
|
419 | - * @throws InvalidDataTypeException |
|
420 | - * @throws InvalidEntityException |
|
421 | - * @throws InvalidInterfaceException |
|
422 | - * @throws InvalidIdentifierException |
|
423 | - * @throws InvalidArgumentException |
|
424 | - * @throws InvalidFormHandlerException |
|
425 | - */ |
|
426 | - public function buildCurrentStepFormForDisplay() |
|
427 | - { |
|
428 | - $form_step = $this->buildCurrentStepForm(); |
|
429 | - // no displayable content ? then skip straight to processing |
|
430 | - if (! $form_step->displayable()) { |
|
431 | - $this->addFormActionArgs(); |
|
432 | - $form_step->setFormAction($this->formAction()); |
|
433 | - wp_safe_redirect($form_step->formAction()); |
|
434 | - } |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @throws InvalidClassException |
|
440 | - * @throws InvalidDataTypeException |
|
441 | - * @throws InvalidEntityException |
|
442 | - * @throws InvalidInterfaceException |
|
443 | - * @throws InvalidIdentifierException |
|
444 | - * @throws InvalidArgumentException |
|
445 | - * @throws InvalidFormHandlerException |
|
446 | - */ |
|
447 | - public function buildCurrentStepFormForProcessing() |
|
448 | - { |
|
449 | - $this->buildCurrentStepForm(false); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * @param bool $for_display |
|
455 | - * @return SequentialStepFormInterface |
|
456 | - * @throws InvalidArgumentException |
|
457 | - * @throws InvalidClassException |
|
458 | - * @throws InvalidDataTypeException |
|
459 | - * @throws InvalidEntityException |
|
460 | - * @throws InvalidFormHandlerException |
|
461 | - * @throws InvalidIdentifierException |
|
462 | - * @throws InvalidInterfaceException |
|
463 | - */ |
|
464 | - private function buildCurrentStepForm($for_display = true) |
|
465 | - { |
|
466 | - $this->form_steps = $this->getFormStepsCollection(); |
|
467 | - $this->setCurrentStepFromRequest(); |
|
468 | - $form_step = $this->getCurrentStep(); |
|
469 | - if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
470 | - $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
471 | - } |
|
472 | - if ($for_display && $form_step->displayable()) { |
|
473 | - $this->progress_step_manager = $this->generateProgressSteps( |
|
474 | - $this->getProgressStepsCollection() |
|
475 | - ); |
|
476 | - $this->progress_step_manager->setCurrentStep( |
|
477 | - $form_step->slug() |
|
478 | - ); |
|
479 | - // mark all previous progress steps as completed |
|
480 | - $this->progress_step_manager->setPreviousStepsCompleted(); |
|
481 | - $this->progress_step_manager->enqueueStylesAndScripts(); |
|
482 | - $this->addFormActionArgs(); |
|
483 | - $form_step->setFormAction($this->formAction()); |
|
484 | - } else { |
|
485 | - $form_step->setRedirectUrl($this->baseUrl()); |
|
486 | - $form_step->addRedirectArgs( |
|
487 | - array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
488 | - ); |
|
489 | - } |
|
490 | - $form_step->generate(); |
|
491 | - if ($for_display) { |
|
492 | - $form_step->enqueueStylesAndScripts(); |
|
493 | - } |
|
494 | - return $form_step; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * @param bool $return_as_string |
|
500 | - * @return string |
|
501 | - * @throws InvalidFormHandlerException |
|
502 | - */ |
|
503 | - public function displayProgressSteps($return_as_string = true) |
|
504 | - { |
|
505 | - $form_step = $this->getCurrentStep(); |
|
506 | - if (! $form_step->displayable()) { |
|
507 | - return ''; |
|
508 | - } |
|
509 | - $progress_steps = apply_filters( |
|
510 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
511 | - '' |
|
512 | - ); |
|
513 | - $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
514 | - $progress_steps .= apply_filters( |
|
515 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
516 | - '' |
|
517 | - ); |
|
518 | - if ($return_as_string) { |
|
519 | - return $progress_steps; |
|
520 | - } |
|
521 | - echo wp_kses($progress_steps, AllowedTags::getWithFormTags()); |
|
522 | - return ''; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * @param bool $return_as_string |
|
528 | - * @return string |
|
529 | - * @throws InvalidFormHandlerException |
|
530 | - */ |
|
531 | - public function displayCurrentStepForm($return_as_string = true) |
|
532 | - { |
|
533 | - if ($return_as_string) { |
|
534 | - return $this->getCurrentStep()->display(); |
|
535 | - } |
|
536 | - echo wp_kses($this->getCurrentStep()->display(), AllowedTags::getWithFormTags()); |
|
537 | - return ''; |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @param array $form_data |
|
543 | - * @return void |
|
544 | - * @throws InvalidArgumentException |
|
545 | - * @throws InvalidDataTypeException |
|
546 | - * @throws InvalidFormHandlerException |
|
547 | - */ |
|
548 | - public function processCurrentStepForm($form_data = array()) |
|
549 | - { |
|
550 | - // grab instance of current step because after calling next() below, |
|
551 | - // any calls to getCurrentStep() will return the "next" step because we advanced |
|
552 | - $current_step = $this->getCurrentStep(); |
|
553 | - try { |
|
554 | - // form processing should either throw exceptions or return true |
|
555 | - $current_step->process($form_data); |
|
556 | - } catch (Exception $e) { |
|
557 | - // something went wrong, convert the Exception to an EE_Error |
|
558 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
559 | - // prevent redirect to next step or other if exception was thrown |
|
560 | - if ( |
|
561 | - $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
562 | - || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
563 | - ) { |
|
564 | - $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
565 | - } |
|
566 | - } |
|
567 | - // save notices to a transient so that when we redirect back |
|
568 | - // to the display portion for this step |
|
569 | - // those notices can be displayed |
|
570 | - EE_Error::get_notices(false, true); |
|
571 | - $this->redirectForm($current_step); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * handles where to go to next |
|
577 | - * |
|
578 | - * @param SequentialStepFormInterface $current_step |
|
579 | - * @throws InvalidArgumentException |
|
580 | - * @throws InvalidDataTypeException |
|
581 | - * @throws InvalidFormHandlerException |
|
582 | - */ |
|
583 | - public function redirectForm(SequentialStepFormInterface $current_step) |
|
584 | - { |
|
585 | - $redirect_step = $current_step; |
|
586 | - switch ($current_step->redirectTo()) { |
|
587 | - case SequentialStepForm::REDIRECT_TO_OTHER: |
|
588 | - // going somewhere else, so just check out now |
|
589 | - wp_safe_redirect($redirect_step->redirectUrl()); |
|
590 | - exit(); |
|
591 | - case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
592 | - $redirect_step = $this->form_steps->previous(); |
|
593 | - break; |
|
594 | - case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
595 | - $this->form_steps->next(); |
|
596 | - if ($this->form_steps->valid()) { |
|
597 | - $redirect_step = $this->form_steps->current(); |
|
598 | - } |
|
599 | - break; |
|
600 | - case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
601 | - default: |
|
602 | - // $redirect_step is already set |
|
603 | - } |
|
604 | - $current_step->setRedirectUrl($this->baseUrl()); |
|
605 | - $current_step->addRedirectArgs( |
|
606 | - // use the slug for whatever step we are redirecting too |
|
607 | - array($this->formStepUrlKey() => $redirect_step->slug()) |
|
608 | - ); |
|
609 | - wp_safe_redirect($current_step->redirectUrl()); |
|
610 | - exit(); |
|
611 | - } |
|
33 | + /** |
|
34 | + * a simplified URL with no form related parameters |
|
35 | + * that will be used to build the form's redirect URLs |
|
36 | + * |
|
37 | + * @var string $base_url |
|
38 | + */ |
|
39 | + private $base_url = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * the key used for the URL param that denotes the current form step |
|
43 | + * defaults to 'ee-form-step' |
|
44 | + * |
|
45 | + * @var string $form_step_url_key |
|
46 | + */ |
|
47 | + private $form_step_url_key = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string $default_form_step |
|
51 | + */ |
|
52 | + private $default_form_step = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string $form_action |
|
56 | + */ |
|
57 | + private $form_action; |
|
58 | + |
|
59 | + /** |
|
60 | + * value of one of the string constant above |
|
61 | + * |
|
62 | + * @var string $form_config |
|
63 | + */ |
|
64 | + private $form_config; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $progress_step_style |
|
68 | + */ |
|
69 | + private $progress_step_style = ''; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var RequestInterface $request |
|
73 | + */ |
|
74 | + private $request; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var Collection $form_steps |
|
78 | + */ |
|
79 | + protected $form_steps; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var ProgressStepManager $progress_step_manager |
|
83 | + */ |
|
84 | + protected $progress_step_manager; |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return Collection|null |
|
89 | + */ |
|
90 | + abstract protected function getFormStepsCollection(); |
|
91 | + |
|
92 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
93 | + /** |
|
94 | + * StepsManager constructor |
|
95 | + * |
|
96 | + * @param string $base_url |
|
97 | + * @param string $default_form_step |
|
98 | + * @param string $form_action |
|
99 | + * @param string $form_config |
|
100 | + * @param EE_Request|RequestInterface|null $request |
|
101 | + * @param string $progress_step_style |
|
102 | + * @throws InvalidDataTypeException |
|
103 | + * @throws InvalidArgumentException |
|
104 | + */ |
|
105 | + public function __construct( |
|
106 | + $base_url, |
|
107 | + $default_form_step, |
|
108 | + $form_action = '', |
|
109 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
110 | + $progress_step_style = 'number_bubbles', |
|
111 | + $request = null |
|
112 | + ) { |
|
113 | + $this->setBaseUrl($base_url); |
|
114 | + $this->setDefaultFormStep($default_form_step); |
|
115 | + $this->setFormAction($form_action); |
|
116 | + $this->setFormConfig($form_config); |
|
117 | + $this->setProgressStepStyle($progress_step_style); |
|
118 | + $this->request = $request instanceof RequestInterface |
|
119 | + ? $request |
|
120 | + : LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + * @throws InvalidFormHandlerException |
|
127 | + */ |
|
128 | + public function baseUrl() |
|
129 | + { |
|
130 | + if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
131 | + add_query_arg( |
|
132 | + array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
133 | + $this->base_url |
|
134 | + ); |
|
135 | + } |
|
136 | + return $this->base_url; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $base_url |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + * @throws InvalidArgumentException |
|
144 | + */ |
|
145 | + protected function setBaseUrl($base_url) |
|
146 | + { |
|
147 | + if (! is_string($base_url)) { |
|
148 | + throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
149 | + } |
|
150 | + if (empty($base_url)) { |
|
151 | + throw new InvalidArgumentException( |
|
152 | + esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
153 | + ); |
|
154 | + } |
|
155 | + $this->base_url = $base_url; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string |
|
161 | + * @throws InvalidDataTypeException |
|
162 | + */ |
|
163 | + public function formStepUrlKey() |
|
164 | + { |
|
165 | + if (empty($this->form_step_url_key)) { |
|
166 | + $this->setFormStepUrlKey(); |
|
167 | + } |
|
168 | + return $this->form_step_url_key; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param string $form_step_url_key |
|
174 | + * @throws InvalidDataTypeException |
|
175 | + */ |
|
176 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
177 | + { |
|
178 | + if (! is_string($form_step_url_key)) { |
|
179 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
180 | + } |
|
181 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function defaultFormStep() |
|
189 | + { |
|
190 | + return $this->default_form_step; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @param $default_form_step |
|
196 | + * @throws InvalidDataTypeException |
|
197 | + */ |
|
198 | + protected function setDefaultFormStep($default_form_step) |
|
199 | + { |
|
200 | + if (! is_string($default_form_step)) { |
|
201 | + throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
202 | + } |
|
203 | + $this->default_form_step = $default_form_step; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * @return void |
|
209 | + * @throws InvalidIdentifierException |
|
210 | + * @throws InvalidDataTypeException |
|
211 | + */ |
|
212 | + protected function setCurrentStepFromRequest() |
|
213 | + { |
|
214 | + $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
|
215 | + if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
216 | + throw new InvalidIdentifierException( |
|
217 | + $current_step_slug, |
|
218 | + $this->defaultFormStep(), |
|
219 | + sprintf( |
|
220 | + esc_html__('The "%1$s" form step could not be set.', 'event_espresso'), |
|
221 | + $current_step_slug |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @return SequentialStepFormInterface|object |
|
230 | + * @throws InvalidFormHandlerException |
|
231 | + */ |
|
232 | + public function getCurrentStep() |
|
233 | + { |
|
234 | + if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
235 | + throw new InvalidFormHandlerException($this->form_steps->current()); |
|
236 | + } |
|
237 | + return $this->form_steps->current(); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return string |
|
243 | + * @throws InvalidFormHandlerException |
|
244 | + */ |
|
245 | + public function formAction() |
|
246 | + { |
|
247 | + if (! is_string($this->form_action) || empty($this->form_action)) { |
|
248 | + $this->form_action = $this->baseUrl(); |
|
249 | + } |
|
250 | + return $this->form_action; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param string $form_action |
|
256 | + * @throws InvalidDataTypeException |
|
257 | + */ |
|
258 | + public function setFormAction($form_action) |
|
259 | + { |
|
260 | + if (! is_string($form_action)) { |
|
261 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
262 | + } |
|
263 | + $this->form_action = $form_action; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @param array $form_action_args |
|
269 | + * @throws InvalidDataTypeException |
|
270 | + * @throws InvalidFormHandlerException |
|
271 | + */ |
|
272 | + public function addFormActionArgs($form_action_args = array()) |
|
273 | + { |
|
274 | + if (! is_array($form_action_args)) { |
|
275 | + throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
276 | + } |
|
277 | + $form_action_args = ! empty($form_action_args) |
|
278 | + ? $form_action_args |
|
279 | + : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
280 | + $this->getCurrentStep()->setFormAction( |
|
281 | + add_query_arg($form_action_args, $this->formAction()) |
|
282 | + ); |
|
283 | + $this->form_action = $this->getCurrentStep()->formAction(); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @return string |
|
289 | + */ |
|
290 | + public function formConfig() |
|
291 | + { |
|
292 | + return $this->form_config; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param string $form_config |
|
298 | + */ |
|
299 | + public function setFormConfig($form_config) |
|
300 | + { |
|
301 | + $this->form_config = $form_config; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + public function progressStepStyle() |
|
309 | + { |
|
310 | + return $this->progress_step_style; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $progress_step_style |
|
316 | + */ |
|
317 | + public function setProgressStepStyle($progress_step_style) |
|
318 | + { |
|
319 | + $this->progress_step_style = $progress_step_style; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @return RequestInterface |
|
325 | + */ |
|
326 | + public function request() |
|
327 | + { |
|
328 | + return $this->request; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * @return Collection|null |
|
334 | + * @throws InvalidInterfaceException |
|
335 | + */ |
|
336 | + protected function getProgressStepsCollection() |
|
337 | + { |
|
338 | + static $collection = null; |
|
339 | + if (! $collection instanceof ProgressStepCollection) { |
|
340 | + $collection = new ProgressStepCollection(); |
|
341 | + } |
|
342 | + return $collection; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param Collection $progress_steps_collection |
|
348 | + * @return ProgressStepManager |
|
349 | + * @throws InvalidInterfaceException |
|
350 | + * @throws InvalidClassException |
|
351 | + * @throws InvalidDataTypeException |
|
352 | + * @throws InvalidEntityException |
|
353 | + * @throws InvalidFormHandlerException |
|
354 | + */ |
|
355 | + protected function generateProgressSteps(Collection $progress_steps_collection) |
|
356 | + { |
|
357 | + $current_step = $this->getCurrentStep(); |
|
358 | + /** @var SequentialStepForm $form_step */ |
|
359 | + foreach ($this->form_steps as $form_step) { |
|
360 | + // is this step active ? |
|
361 | + if (! $form_step->initialize()) { |
|
362 | + continue; |
|
363 | + } |
|
364 | + $progress_steps_collection->add( |
|
365 | + new ProgressStep( |
|
366 | + $form_step->order(), |
|
367 | + $form_step->slug(), |
|
368 | + $form_step->slug(), |
|
369 | + $form_step->formName() |
|
370 | + ), |
|
371 | + $form_step->slug() |
|
372 | + ); |
|
373 | + } |
|
374 | + // set collection pointer back to current step |
|
375 | + $this->form_steps->setCurrentUsingObject($current_step); |
|
376 | + return new ProgressStepManager( |
|
377 | + $this->progressStepStyle(), |
|
378 | + $this->defaultFormStep(), |
|
379 | + $this->formStepUrlKey(), |
|
380 | + $progress_steps_collection |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @throws InvalidClassException |
|
387 | + * @throws InvalidDataTypeException |
|
388 | + * @throws InvalidEntityException |
|
389 | + * @throws InvalidIdentifierException |
|
390 | + * @throws InvalidInterfaceException |
|
391 | + * @throws InvalidArgumentException |
|
392 | + * @throws InvalidFormHandlerException |
|
393 | + */ |
|
394 | + public function buildForm() |
|
395 | + { |
|
396 | + $this->buildCurrentStepFormForDisplay(); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * @param array $form_data |
|
402 | + * @throws InvalidArgumentException |
|
403 | + * @throws InvalidClassException |
|
404 | + * @throws InvalidDataTypeException |
|
405 | + * @throws InvalidEntityException |
|
406 | + * @throws InvalidFormHandlerException |
|
407 | + * @throws InvalidIdentifierException |
|
408 | + * @throws InvalidInterfaceException |
|
409 | + */ |
|
410 | + public function processForm($form_data = array()) |
|
411 | + { |
|
412 | + $this->buildCurrentStepFormForProcessing(); |
|
413 | + $this->processCurrentStepForm($form_data); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * @throws InvalidClassException |
|
419 | + * @throws InvalidDataTypeException |
|
420 | + * @throws InvalidEntityException |
|
421 | + * @throws InvalidInterfaceException |
|
422 | + * @throws InvalidIdentifierException |
|
423 | + * @throws InvalidArgumentException |
|
424 | + * @throws InvalidFormHandlerException |
|
425 | + */ |
|
426 | + public function buildCurrentStepFormForDisplay() |
|
427 | + { |
|
428 | + $form_step = $this->buildCurrentStepForm(); |
|
429 | + // no displayable content ? then skip straight to processing |
|
430 | + if (! $form_step->displayable()) { |
|
431 | + $this->addFormActionArgs(); |
|
432 | + $form_step->setFormAction($this->formAction()); |
|
433 | + wp_safe_redirect($form_step->formAction()); |
|
434 | + } |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @throws InvalidClassException |
|
440 | + * @throws InvalidDataTypeException |
|
441 | + * @throws InvalidEntityException |
|
442 | + * @throws InvalidInterfaceException |
|
443 | + * @throws InvalidIdentifierException |
|
444 | + * @throws InvalidArgumentException |
|
445 | + * @throws InvalidFormHandlerException |
|
446 | + */ |
|
447 | + public function buildCurrentStepFormForProcessing() |
|
448 | + { |
|
449 | + $this->buildCurrentStepForm(false); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * @param bool $for_display |
|
455 | + * @return SequentialStepFormInterface |
|
456 | + * @throws InvalidArgumentException |
|
457 | + * @throws InvalidClassException |
|
458 | + * @throws InvalidDataTypeException |
|
459 | + * @throws InvalidEntityException |
|
460 | + * @throws InvalidFormHandlerException |
|
461 | + * @throws InvalidIdentifierException |
|
462 | + * @throws InvalidInterfaceException |
|
463 | + */ |
|
464 | + private function buildCurrentStepForm($for_display = true) |
|
465 | + { |
|
466 | + $this->form_steps = $this->getFormStepsCollection(); |
|
467 | + $this->setCurrentStepFromRequest(); |
|
468 | + $form_step = $this->getCurrentStep(); |
|
469 | + if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
470 | + $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
471 | + } |
|
472 | + if ($for_display && $form_step->displayable()) { |
|
473 | + $this->progress_step_manager = $this->generateProgressSteps( |
|
474 | + $this->getProgressStepsCollection() |
|
475 | + ); |
|
476 | + $this->progress_step_manager->setCurrentStep( |
|
477 | + $form_step->slug() |
|
478 | + ); |
|
479 | + // mark all previous progress steps as completed |
|
480 | + $this->progress_step_manager->setPreviousStepsCompleted(); |
|
481 | + $this->progress_step_manager->enqueueStylesAndScripts(); |
|
482 | + $this->addFormActionArgs(); |
|
483 | + $form_step->setFormAction($this->formAction()); |
|
484 | + } else { |
|
485 | + $form_step->setRedirectUrl($this->baseUrl()); |
|
486 | + $form_step->addRedirectArgs( |
|
487 | + array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
488 | + ); |
|
489 | + } |
|
490 | + $form_step->generate(); |
|
491 | + if ($for_display) { |
|
492 | + $form_step->enqueueStylesAndScripts(); |
|
493 | + } |
|
494 | + return $form_step; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * @param bool $return_as_string |
|
500 | + * @return string |
|
501 | + * @throws InvalidFormHandlerException |
|
502 | + */ |
|
503 | + public function displayProgressSteps($return_as_string = true) |
|
504 | + { |
|
505 | + $form_step = $this->getCurrentStep(); |
|
506 | + if (! $form_step->displayable()) { |
|
507 | + return ''; |
|
508 | + } |
|
509 | + $progress_steps = apply_filters( |
|
510 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
511 | + '' |
|
512 | + ); |
|
513 | + $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
514 | + $progress_steps .= apply_filters( |
|
515 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
516 | + '' |
|
517 | + ); |
|
518 | + if ($return_as_string) { |
|
519 | + return $progress_steps; |
|
520 | + } |
|
521 | + echo wp_kses($progress_steps, AllowedTags::getWithFormTags()); |
|
522 | + return ''; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * @param bool $return_as_string |
|
528 | + * @return string |
|
529 | + * @throws InvalidFormHandlerException |
|
530 | + */ |
|
531 | + public function displayCurrentStepForm($return_as_string = true) |
|
532 | + { |
|
533 | + if ($return_as_string) { |
|
534 | + return $this->getCurrentStep()->display(); |
|
535 | + } |
|
536 | + echo wp_kses($this->getCurrentStep()->display(), AllowedTags::getWithFormTags()); |
|
537 | + return ''; |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @param array $form_data |
|
543 | + * @return void |
|
544 | + * @throws InvalidArgumentException |
|
545 | + * @throws InvalidDataTypeException |
|
546 | + * @throws InvalidFormHandlerException |
|
547 | + */ |
|
548 | + public function processCurrentStepForm($form_data = array()) |
|
549 | + { |
|
550 | + // grab instance of current step because after calling next() below, |
|
551 | + // any calls to getCurrentStep() will return the "next" step because we advanced |
|
552 | + $current_step = $this->getCurrentStep(); |
|
553 | + try { |
|
554 | + // form processing should either throw exceptions or return true |
|
555 | + $current_step->process($form_data); |
|
556 | + } catch (Exception $e) { |
|
557 | + // something went wrong, convert the Exception to an EE_Error |
|
558 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
559 | + // prevent redirect to next step or other if exception was thrown |
|
560 | + if ( |
|
561 | + $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
562 | + || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
563 | + ) { |
|
564 | + $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
565 | + } |
|
566 | + } |
|
567 | + // save notices to a transient so that when we redirect back |
|
568 | + // to the display portion for this step |
|
569 | + // those notices can be displayed |
|
570 | + EE_Error::get_notices(false, true); |
|
571 | + $this->redirectForm($current_step); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * handles where to go to next |
|
577 | + * |
|
578 | + * @param SequentialStepFormInterface $current_step |
|
579 | + * @throws InvalidArgumentException |
|
580 | + * @throws InvalidDataTypeException |
|
581 | + * @throws InvalidFormHandlerException |
|
582 | + */ |
|
583 | + public function redirectForm(SequentialStepFormInterface $current_step) |
|
584 | + { |
|
585 | + $redirect_step = $current_step; |
|
586 | + switch ($current_step->redirectTo()) { |
|
587 | + case SequentialStepForm::REDIRECT_TO_OTHER: |
|
588 | + // going somewhere else, so just check out now |
|
589 | + wp_safe_redirect($redirect_step->redirectUrl()); |
|
590 | + exit(); |
|
591 | + case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
592 | + $redirect_step = $this->form_steps->previous(); |
|
593 | + break; |
|
594 | + case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
595 | + $this->form_steps->next(); |
|
596 | + if ($this->form_steps->valid()) { |
|
597 | + $redirect_step = $this->form_steps->current(); |
|
598 | + } |
|
599 | + break; |
|
600 | + case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
601 | + default: |
|
602 | + // $redirect_step is already set |
|
603 | + } |
|
604 | + $current_step->setRedirectUrl($this->baseUrl()); |
|
605 | + $current_step->addRedirectArgs( |
|
606 | + // use the slug for whatever step we are redirecting too |
|
607 | + array($this->formStepUrlKey() => $redirect_step->slug()) |
|
608 | + ); |
|
609 | + wp_safe_redirect($current_step->redirectUrl()); |
|
610 | + exit(); |
|
611 | + } |
|
612 | 612 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function setNotice($key, $value) |
56 | 56 | { |
57 | - $this->notice[ $key ] = $value; |
|
57 | + $this->notice[$key] = $value; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function getNotice($key) |
66 | 66 | { |
67 | - return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
67 | + return isset($this->notice[$key]) ? $this->notice[$key] : null; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function getOutput($as_string = true, $separator = PHP_EOL) |
100 | 100 | { |
101 | - return $as_string ? implode($separator, $this->output) : $this->output ; |
|
101 | + return $as_string ? implode($separator, $this->output) : $this->output; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 |
@@ -14,125 +14,125 @@ |
||
14 | 14 | */ |
15 | 15 | class Response implements ResponseInterface, ReservedInstanceInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * @var array $notice |
|
19 | - */ |
|
20 | - protected $notice = []; |
|
21 | - |
|
22 | - /** |
|
23 | - * rendered output to be returned to WP |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $output = []; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var bool |
|
31 | - */ |
|
32 | - protected $request_terminated = false; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var bool $deactivate_plugin |
|
36 | - */ |
|
37 | - protected $deactivate_plugin = false; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * EE_Response constructor. |
|
42 | - */ |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - $this->terminateRequest(false); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param $key |
|
51 | - * @param $value |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function setNotice($key, $value) |
|
55 | - { |
|
56 | - $this->notice[ $key ] = $value; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param $key |
|
62 | - * @return mixed |
|
63 | - */ |
|
64 | - public function getNotice($key) |
|
65 | - { |
|
66 | - return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function getNotices() |
|
74 | - { |
|
75 | - return $this->notice; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $string |
|
81 | - * @param bool $append |
|
82 | - */ |
|
83 | - public function addOutput($string, $append = true) |
|
84 | - { |
|
85 | - if ($append) { |
|
86 | - $this->output[] = $string; |
|
87 | - return; |
|
88 | - } |
|
89 | - array_unshift($this->output, $string); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param bool $as_string |
|
95 | - * @param string $separator |
|
96 | - * @return array|string |
|
97 | - */ |
|
98 | - public function getOutput($as_string = true, $separator = PHP_EOL) |
|
99 | - { |
|
100 | - return $as_string ? implode($separator, $this->output) : $this->output ; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return boolean |
|
106 | - */ |
|
107 | - public function requestTerminated() |
|
108 | - { |
|
109 | - return $this->request_terminated; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @param boolean $request_terminated |
|
115 | - */ |
|
116 | - public function terminateRequest($request_terminated = true) |
|
117 | - { |
|
118 | - $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return boolean |
|
124 | - */ |
|
125 | - public function pluginDeactivated() |
|
126 | - { |
|
127 | - return $this->deactivate_plugin; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * sets $deactivate_plugin to true |
|
133 | - */ |
|
134 | - public function deactivatePlugin() |
|
135 | - { |
|
136 | - $this->deactivate_plugin = true; |
|
137 | - } |
|
17 | + /** |
|
18 | + * @var array $notice |
|
19 | + */ |
|
20 | + protected $notice = []; |
|
21 | + |
|
22 | + /** |
|
23 | + * rendered output to be returned to WP |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $output = []; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var bool |
|
31 | + */ |
|
32 | + protected $request_terminated = false; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var bool $deactivate_plugin |
|
36 | + */ |
|
37 | + protected $deactivate_plugin = false; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * EE_Response constructor. |
|
42 | + */ |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + $this->terminateRequest(false); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param $key |
|
51 | + * @param $value |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function setNotice($key, $value) |
|
55 | + { |
|
56 | + $this->notice[ $key ] = $value; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param $key |
|
62 | + * @return mixed |
|
63 | + */ |
|
64 | + public function getNotice($key) |
|
65 | + { |
|
66 | + return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function getNotices() |
|
74 | + { |
|
75 | + return $this->notice; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $string |
|
81 | + * @param bool $append |
|
82 | + */ |
|
83 | + public function addOutput($string, $append = true) |
|
84 | + { |
|
85 | + if ($append) { |
|
86 | + $this->output[] = $string; |
|
87 | + return; |
|
88 | + } |
|
89 | + array_unshift($this->output, $string); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param bool $as_string |
|
95 | + * @param string $separator |
|
96 | + * @return array|string |
|
97 | + */ |
|
98 | + public function getOutput($as_string = true, $separator = PHP_EOL) |
|
99 | + { |
|
100 | + return $as_string ? implode($separator, $this->output) : $this->output ; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return boolean |
|
106 | + */ |
|
107 | + public function requestTerminated() |
|
108 | + { |
|
109 | + return $this->request_terminated; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @param boolean $request_terminated |
|
115 | + */ |
|
116 | + public function terminateRequest($request_terminated = true) |
|
117 | + { |
|
118 | + $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return boolean |
|
124 | + */ |
|
125 | + public function pluginDeactivated() |
|
126 | + { |
|
127 | + return $this->deactivate_plugin; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * sets $deactivate_plugin to true |
|
133 | + */ |
|
134 | + public function deactivatePlugin() |
|
135 | + { |
|
136 | + $this->deactivate_plugin = true; |
|
137 | + } |
|
138 | 138 | } |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getReflectionClass($class_name) |
62 | 62 | { |
63 | - if (! is_string($class_name)) { |
|
63 | + if ( ! is_string($class_name)) { |
|
64 | 64 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
65 | 65 | } |
66 | - if (! isset($this->classes[ $class_name ])) { |
|
67 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
66 | + if ( ! isset($this->classes[$class_name])) { |
|
67 | + $this->classes[$class_name] = new ReflectionClass($class_name); |
|
68 | 68 | } |
69 | - return $this->classes[ $class_name ]; |
|
69 | + return $this->classes[$class_name]; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function getConstructor($class_name) |
80 | 80 | { |
81 | - if (! is_string($class_name)) { |
|
81 | + if ( ! is_string($class_name)) { |
|
82 | 82 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
83 | 83 | } |
84 | - if (! isset($this->constructors[ $class_name ])) { |
|
84 | + if ( ! isset($this->constructors[$class_name])) { |
|
85 | 85 | $reflection_class = $this->getReflectionClass($class_name); |
86 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
86 | + $this->constructors[$class_name] = $reflection_class->getConstructor(); |
|
87 | 87 | } |
88 | - return $this->constructors[ $class_name ]; |
|
88 | + return $this->constructors[$class_name]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getParameters($class_name) |
111 | 111 | { |
112 | - if (! isset($this->parameters[ $class_name ])) { |
|
112 | + if ( ! isset($this->parameters[$class_name])) { |
|
113 | 113 | $constructor = $this->getConstructor($class_name); |
114 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
114 | + $this->parameters[$class_name] = $constructor->getParameters(); |
|
115 | 115 | } |
116 | - return $this->parameters[ $class_name ]; |
|
116 | + return $this->parameters[$class_name]; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
151 | 151 | { |
152 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
152 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) { |
|
153 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
154 | 154 | } |
155 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | - $this->parameter_classes[ $class_name ] = []; |
|
155 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
156 | + $this->parameter_classes[$class_name] = []; |
|
157 | 157 | } |
158 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
158 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
159 | + $this->parameter_classes[$class_name][$index] = []; |
|
160 | 160 | } |
161 | 161 | // ReflectionParameter::getClass() is deprecated in PHP 8+ |
162 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 70100 |
|
162 | + $this->parameter_classes[$class_name][$index]['param_class_name'] = PHP_VERSION_ID < 70100 |
|
163 | 163 | ? $this->getParameterClassNameLegacy($param) |
164 | 164 | : $this->getParameterClassNamePhp8($param); |
165 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
165 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -215,19 +215,19 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
217 | 217 | { |
218 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
219 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
218 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) { |
|
219 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
220 | 220 | } |
221 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
222 | - $this->parameter_classes[ $class_name ] = []; |
|
221 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
222 | + $this->parameter_classes[$class_name] = []; |
|
223 | 223 | } |
224 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
225 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
224 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
225 | + $this->parameter_classes[$class_name][$index] = []; |
|
226 | 226 | } |
227 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
227 | + $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable() |
|
228 | 228 | ? $param->getDefaultValue() |
229 | 229 | : null; |
230 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
230 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function getProperties($class_name) |
241 | 241 | { |
242 | - if (! isset($this->properties[ $class_name ])) { |
|
242 | + if ( ! isset($this->properties[$class_name])) { |
|
243 | 243 | $reflection_class = $this->getReflectionClass($class_name); |
244 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
244 | + $this->properties[$class_name] = $reflection_class->getProperties(); |
|
245 | 245 | } |
246 | - return $this->properties[ $class_name ]; |
|
246 | + return $this->properties[$class_name]; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
@@ -267,11 +267,11 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function getMethods($class_name) |
269 | 269 | { |
270 | - if (! isset($this->methods[ $class_name ])) { |
|
270 | + if ( ! isset($this->methods[$class_name])) { |
|
271 | 271 | $reflection_class = $this->getReflectionClass($class_name); |
272 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
272 | + $this->methods[$class_name] = $reflection_class->getMethods(); |
|
273 | 273 | } |
274 | - return $this->methods[ $class_name ]; |
|
274 | + return $this->methods[$class_name]; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 |
@@ -20,268 +20,268 @@ |
||
20 | 20 | */ |
21 | 21 | class Mirror |
22 | 22 | { |
23 | - /** |
|
24 | - * @var ReflectionClass[] $classes |
|
25 | - */ |
|
26 | - private $classes = []; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var ReflectionMethod[] $constructors |
|
30 | - */ |
|
31 | - private $constructors = []; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var ReflectionParameter[][] $parameters |
|
35 | - */ |
|
36 | - private $parameters = []; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var ReflectionParameter[][] $parameters |
|
40 | - */ |
|
41 | - private $parameter_classes = []; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var ReflectionProperty[][] $properties |
|
45 | - */ |
|
46 | - private $properties = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var ReflectionMethod[][] $methods |
|
50 | - */ |
|
51 | - private $methods = []; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $class_name |
|
56 | - * @return ReflectionClass |
|
57 | - * @throws ReflectionException |
|
58 | - * @throws InvalidDataTypeException |
|
59 | - */ |
|
60 | - public function getReflectionClass($class_name) |
|
61 | - { |
|
62 | - if (! is_string($class_name)) { |
|
63 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
64 | - } |
|
65 | - if (! isset($this->classes[ $class_name ])) { |
|
66 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
67 | - } |
|
68 | - return $this->classes[ $class_name ]; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $class_name |
|
74 | - * @return ReflectionMethod |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws ReflectionException |
|
77 | - */ |
|
78 | - public function getConstructor($class_name) |
|
79 | - { |
|
80 | - if (! is_string($class_name)) { |
|
81 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
82 | - } |
|
83 | - if (! isset($this->constructors[ $class_name ])) { |
|
84 | - $reflection_class = $this->getReflectionClass($class_name); |
|
85 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
86 | - } |
|
87 | - return $this->constructors[ $class_name ]; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @param ReflectionClass $reflection_class |
|
93 | - * @return ReflectionMethod |
|
94 | - * @throws InvalidDataTypeException |
|
95 | - * @throws ReflectionException |
|
96 | - */ |
|
97 | - public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
98 | - { |
|
99 | - return $this->getConstructor($reflection_class->getName()); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $class_name |
|
105 | - * @return ReflectionParameter[] |
|
106 | - * @throws InvalidDataTypeException |
|
107 | - * @throws ReflectionException |
|
108 | - */ |
|
109 | - public function getParameters($class_name) |
|
110 | - { |
|
111 | - if (! isset($this->parameters[ $class_name ])) { |
|
112 | - $constructor = $this->getConstructor($class_name); |
|
113 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
114 | - } |
|
115 | - return $this->parameters[ $class_name ]; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param ReflectionClass $reflection_class |
|
121 | - * @return ReflectionParameter[] |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
126 | - { |
|
127 | - return $this->getParameters($reflection_class->getName()); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @param ReflectionMethod $constructor |
|
133 | - * @return ReflectionParameter[] |
|
134 | - * @throws InvalidDataTypeException |
|
135 | - * @throws ReflectionException |
|
136 | - */ |
|
137 | - public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
138 | - { |
|
139 | - return $this->getParameters($constructor->getDeclaringClass()); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param ReflectionParameter $param |
|
145 | - * @param string $class_name |
|
146 | - * @param string $index |
|
147 | - * @return string|null |
|
148 | - */ |
|
149 | - public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
150 | - { |
|
151 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
152 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
153 | - } |
|
154 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
155 | - $this->parameter_classes[ $class_name ] = []; |
|
156 | - } |
|
157 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
158 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
159 | - } |
|
160 | - // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
161 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 70100 |
|
162 | - ? $this->getParameterClassNameLegacy($param) |
|
163 | - : $this->getParameterClassNamePhp8($param); |
|
164 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @param ReflectionParameter $param |
|
170 | - * @return string|null |
|
171 | - * @since 4.10.13.p |
|
172 | - */ |
|
173 | - private function getParameterClassNameLegacy(ReflectionParameter $param) |
|
174 | - { |
|
175 | - $reflection_class = $param->getClass(); |
|
176 | - return $reflection_class instanceof ReflectionClass |
|
177 | - ? $reflection_class->getName() |
|
178 | - : null; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * ReflectionParameter::getClass() is deprecated in PHP 8+, |
|
184 | - * so the class name for a parameter needs to be extracted from the ReflectionType, |
|
185 | - * which can either be a ReflectionNamedType or ReflectionUnionType |
|
186 | - * |
|
187 | - * @param ReflectionParameter $param |
|
188 | - * @return null |
|
189 | - * @since 4.10.13.p |
|
190 | - */ |
|
191 | - private function getParameterClassNamePhp8(ReflectionParameter $param) |
|
192 | - { |
|
193 | - $reflection_type = $param->getType(); |
|
194 | - if ($reflection_type instanceof \ReflectionNamedType) { |
|
195 | - return $reflection_type->getName(); |
|
196 | - } |
|
197 | - if ($reflection_type instanceof \ReflectionUnionType) { |
|
198 | - $reflection_types = $reflection_type->getTypes(); |
|
199 | - if (is_array($reflection_types)) { |
|
200 | - $first = reset($reflection_types); |
|
201 | - return $first->getName(); |
|
202 | - } |
|
203 | - } |
|
204 | - return null; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * @param ReflectionParameter $param |
|
210 | - * @param string $class_name |
|
211 | - * @param string $index |
|
212 | - * @return string|null |
|
213 | - * @throws ReflectionException |
|
214 | - */ |
|
215 | - public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
216 | - { |
|
217 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
218 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
219 | - } |
|
220 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
221 | - $this->parameter_classes[ $class_name ] = []; |
|
222 | - } |
|
223 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
224 | - $this->parameter_classes[ $class_name ][ $index ] = []; |
|
225 | - } |
|
226 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
227 | - ? $param->getDefaultValue() |
|
228 | - : null; |
|
229 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $class_name |
|
235 | - * @return ReflectionProperty[] |
|
236 | - * @throws InvalidDataTypeException |
|
237 | - * @throws ReflectionException |
|
238 | - */ |
|
239 | - public function getProperties($class_name) |
|
240 | - { |
|
241 | - if (! isset($this->properties[ $class_name ])) { |
|
242 | - $reflection_class = $this->getReflectionClass($class_name); |
|
243 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
244 | - } |
|
245 | - return $this->properties[ $class_name ]; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param ReflectionClass $reflection_class |
|
251 | - * @return ReflectionProperty[] |
|
252 | - * @throws InvalidDataTypeException |
|
253 | - * @throws ReflectionException |
|
254 | - */ |
|
255 | - public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
256 | - { |
|
257 | - return $this->getProperties($reflection_class->getName()); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * @param string $class_name |
|
263 | - * @return ReflectionMethod[] |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - * @throws ReflectionException |
|
266 | - */ |
|
267 | - public function getMethods($class_name) |
|
268 | - { |
|
269 | - if (! isset($this->methods[ $class_name ])) { |
|
270 | - $reflection_class = $this->getReflectionClass($class_name); |
|
271 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
272 | - } |
|
273 | - return $this->methods[ $class_name ]; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @param ReflectionClass $reflection_class ) |
|
279 | - * @return ReflectionMethod[] |
|
280 | - * @throws InvalidDataTypeException |
|
281 | - * @throws ReflectionException |
|
282 | - */ |
|
283 | - public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
284 | - { |
|
285 | - return $this->getMethods($reflection_class->getName()); |
|
286 | - } |
|
23 | + /** |
|
24 | + * @var ReflectionClass[] $classes |
|
25 | + */ |
|
26 | + private $classes = []; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var ReflectionMethod[] $constructors |
|
30 | + */ |
|
31 | + private $constructors = []; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var ReflectionParameter[][] $parameters |
|
35 | + */ |
|
36 | + private $parameters = []; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var ReflectionParameter[][] $parameters |
|
40 | + */ |
|
41 | + private $parameter_classes = []; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var ReflectionProperty[][] $properties |
|
45 | + */ |
|
46 | + private $properties = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var ReflectionMethod[][] $methods |
|
50 | + */ |
|
51 | + private $methods = []; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $class_name |
|
56 | + * @return ReflectionClass |
|
57 | + * @throws ReflectionException |
|
58 | + * @throws InvalidDataTypeException |
|
59 | + */ |
|
60 | + public function getReflectionClass($class_name) |
|
61 | + { |
|
62 | + if (! is_string($class_name)) { |
|
63 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
64 | + } |
|
65 | + if (! isset($this->classes[ $class_name ])) { |
|
66 | + $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
67 | + } |
|
68 | + return $this->classes[ $class_name ]; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $class_name |
|
74 | + * @return ReflectionMethod |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws ReflectionException |
|
77 | + */ |
|
78 | + public function getConstructor($class_name) |
|
79 | + { |
|
80 | + if (! is_string($class_name)) { |
|
81 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
82 | + } |
|
83 | + if (! isset($this->constructors[ $class_name ])) { |
|
84 | + $reflection_class = $this->getReflectionClass($class_name); |
|
85 | + $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
86 | + } |
|
87 | + return $this->constructors[ $class_name ]; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @param ReflectionClass $reflection_class |
|
93 | + * @return ReflectionMethod |
|
94 | + * @throws InvalidDataTypeException |
|
95 | + * @throws ReflectionException |
|
96 | + */ |
|
97 | + public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
98 | + { |
|
99 | + return $this->getConstructor($reflection_class->getName()); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $class_name |
|
105 | + * @return ReflectionParameter[] |
|
106 | + * @throws InvalidDataTypeException |
|
107 | + * @throws ReflectionException |
|
108 | + */ |
|
109 | + public function getParameters($class_name) |
|
110 | + { |
|
111 | + if (! isset($this->parameters[ $class_name ])) { |
|
112 | + $constructor = $this->getConstructor($class_name); |
|
113 | + $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
114 | + } |
|
115 | + return $this->parameters[ $class_name ]; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param ReflectionClass $reflection_class |
|
121 | + * @return ReflectionParameter[] |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
126 | + { |
|
127 | + return $this->getParameters($reflection_class->getName()); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @param ReflectionMethod $constructor |
|
133 | + * @return ReflectionParameter[] |
|
134 | + * @throws InvalidDataTypeException |
|
135 | + * @throws ReflectionException |
|
136 | + */ |
|
137 | + public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
138 | + { |
|
139 | + return $this->getParameters($constructor->getDeclaringClass()); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param ReflectionParameter $param |
|
145 | + * @param string $class_name |
|
146 | + * @param string $index |
|
147 | + * @return string|null |
|
148 | + */ |
|
149 | + public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
150 | + { |
|
151 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
152 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
153 | + } |
|
154 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
155 | + $this->parameter_classes[ $class_name ] = []; |
|
156 | + } |
|
157 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
158 | + $this->parameter_classes[ $class_name ][ $index ] = []; |
|
159 | + } |
|
160 | + // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
161 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = PHP_VERSION_ID < 70100 |
|
162 | + ? $this->getParameterClassNameLegacy($param) |
|
163 | + : $this->getParameterClassNamePhp8($param); |
|
164 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @param ReflectionParameter $param |
|
170 | + * @return string|null |
|
171 | + * @since 4.10.13.p |
|
172 | + */ |
|
173 | + private function getParameterClassNameLegacy(ReflectionParameter $param) |
|
174 | + { |
|
175 | + $reflection_class = $param->getClass(); |
|
176 | + return $reflection_class instanceof ReflectionClass |
|
177 | + ? $reflection_class->getName() |
|
178 | + : null; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * ReflectionParameter::getClass() is deprecated in PHP 8+, |
|
184 | + * so the class name for a parameter needs to be extracted from the ReflectionType, |
|
185 | + * which can either be a ReflectionNamedType or ReflectionUnionType |
|
186 | + * |
|
187 | + * @param ReflectionParameter $param |
|
188 | + * @return null |
|
189 | + * @since 4.10.13.p |
|
190 | + */ |
|
191 | + private function getParameterClassNamePhp8(ReflectionParameter $param) |
|
192 | + { |
|
193 | + $reflection_type = $param->getType(); |
|
194 | + if ($reflection_type instanceof \ReflectionNamedType) { |
|
195 | + return $reflection_type->getName(); |
|
196 | + } |
|
197 | + if ($reflection_type instanceof \ReflectionUnionType) { |
|
198 | + $reflection_types = $reflection_type->getTypes(); |
|
199 | + if (is_array($reflection_types)) { |
|
200 | + $first = reset($reflection_types); |
|
201 | + return $first->getName(); |
|
202 | + } |
|
203 | + } |
|
204 | + return null; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * @param ReflectionParameter $param |
|
210 | + * @param string $class_name |
|
211 | + * @param string $index |
|
212 | + * @return string|null |
|
213 | + * @throws ReflectionException |
|
214 | + */ |
|
215 | + public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
216 | + { |
|
217 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
218 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
219 | + } |
|
220 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
221 | + $this->parameter_classes[ $class_name ] = []; |
|
222 | + } |
|
223 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
224 | + $this->parameter_classes[ $class_name ][ $index ] = []; |
|
225 | + } |
|
226 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
227 | + ? $param->getDefaultValue() |
|
228 | + : null; |
|
229 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $class_name |
|
235 | + * @return ReflectionProperty[] |
|
236 | + * @throws InvalidDataTypeException |
|
237 | + * @throws ReflectionException |
|
238 | + */ |
|
239 | + public function getProperties($class_name) |
|
240 | + { |
|
241 | + if (! isset($this->properties[ $class_name ])) { |
|
242 | + $reflection_class = $this->getReflectionClass($class_name); |
|
243 | + $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
244 | + } |
|
245 | + return $this->properties[ $class_name ]; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param ReflectionClass $reflection_class |
|
251 | + * @return ReflectionProperty[] |
|
252 | + * @throws InvalidDataTypeException |
|
253 | + * @throws ReflectionException |
|
254 | + */ |
|
255 | + public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
256 | + { |
|
257 | + return $this->getProperties($reflection_class->getName()); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * @param string $class_name |
|
263 | + * @return ReflectionMethod[] |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + * @throws ReflectionException |
|
266 | + */ |
|
267 | + public function getMethods($class_name) |
|
268 | + { |
|
269 | + if (! isset($this->methods[ $class_name ])) { |
|
270 | + $reflection_class = $this->getReflectionClass($class_name); |
|
271 | + $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
272 | + } |
|
273 | + return $this->methods[ $class_name ]; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @param ReflectionClass $reflection_class ) |
|
279 | + * @return ReflectionMethod[] |
|
280 | + * @throws InvalidDataTypeException |
|
281 | + * @throws ReflectionException |
|
282 | + */ |
|
283 | + public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
284 | + { |
|
285 | + return $this->getMethods($reflection_class->getName()); |
|
286 | + } |
|
287 | 287 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function getShortcodes() |
83 | 83 | { |
84 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
84 | + if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
85 | 85 | $this->shortcodes = $this->loadShortcodesCollection(); |
86 | 86 | } |
87 | 87 | return $this->shortcodes; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
139 | 139 | $this->getShortcodes() |
140 | 140 | ); |
141 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
141 | + if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
142 | 142 | throw new InvalidEntityException( |
143 | 143 | $this->shortcodes, |
144 | 144 | 'CollectionInterface', |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | add_action('wp_enqueue_scripts', [$shortcode, 'enqueueStylesheets'], 11); |
173 | 173 | } |
174 | 174 | // add_shortcode() if it has not already been added |
175 | - if (! shortcode_exists($shortcode->getTag())) { |
|
175 | + if ( ! shortcode_exists($shortcode->getTag())) { |
|
176 | 176 | add_shortcode($shortcode->getTag(), [$shortcode, 'processShortcodeCallback']); |
177 | 177 | } |
178 | 178 | } |
@@ -29,210 +29,210 @@ |
||
29 | 29 | */ |
30 | 30 | class ShortcodesManager |
31 | 31 | { |
32 | - /** |
|
33 | - * @type CurrentPage |
|
34 | - */ |
|
35 | - protected $current_page; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
39 | - */ |
|
40 | - private $legacy_shortcodes_manager; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var ShortcodeInterface[] $shortcodes |
|
44 | - */ |
|
45 | - private $shortcodes; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * ShortcodesManager constructor |
|
50 | - * |
|
51 | - * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
52 | - * @param CurrentPage $current_page |
|
53 | - */ |
|
54 | - public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager, CurrentPage $current_page) |
|
55 | - { |
|
56 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
57 | - $this->current_page = $current_page; |
|
58 | - // assemble a list of installed and active shortcodes |
|
59 | - add_action( |
|
60 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
61 | - [$this, 'registerShortcodes'], |
|
62 | - 999 |
|
63 | - ); |
|
64 | - // call add_shortcode() for all installed shortcodes |
|
65 | - add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'addShortcodes']); |
|
66 | - // check content for shortcodes the old way |
|
67 | - add_action('parse_query', [$this->legacy_shortcodes_manager, 'initializeShortcodes'], 5); |
|
68 | - // check content for shortcodes the NEW more efficient way |
|
69 | - add_action('template_redirect', [$this, 'templateRedirect'], 999); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return CollectionInterface|ShortcodeInterface[] |
|
75 | - * @throws InvalidIdentifierException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - * @throws InvalidFilePathException |
|
78 | - * @throws InvalidEntityException |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws InvalidClassException |
|
81 | - */ |
|
82 | - public function getShortcodes() |
|
83 | - { |
|
84 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
85 | - $this->shortcodes = $this->loadShortcodesCollection(); |
|
86 | - } |
|
87 | - return $this->shortcodes; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return CollectionInterface|ShortcodeInterface[] |
|
93 | - * @throws InvalidIdentifierException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws InvalidFilePathException |
|
96 | - * @throws InvalidEntityException |
|
97 | - * @throws InvalidDataTypeException |
|
98 | - * @throws InvalidClassException |
|
99 | - */ |
|
100 | - protected function loadShortcodesCollection() |
|
101 | - { |
|
102 | - $loader = new CollectionLoader( |
|
103 | - new CollectionDetails( |
|
104 | - // collection name |
|
105 | - 'shortcodes', |
|
106 | - // collection interface |
|
107 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
108 | - // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
109 | - ['EventEspresso\core\domain\entities\shortcodes'], |
|
110 | - // filepaths to classes to add |
|
111 | - [], |
|
112 | - // file mask to use if parsing folder for files to add |
|
113 | - '', |
|
114 | - // what to use as identifier for collection entities |
|
115 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
116 | - CollectionDetails::ID_CLASS_NAME |
|
117 | - ) |
|
118 | - ); |
|
119 | - return $loader->getCollection(); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return void |
|
125 | - * @throws DomainException |
|
126 | - * @throws InvalidInterfaceException |
|
127 | - * @throws InvalidIdentifierException |
|
128 | - * @throws InvalidFilePathException |
|
129 | - * @throws InvalidEntityException |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - * @throws InvalidClassException |
|
132 | - * @throws Exception |
|
133 | - */ |
|
134 | - public function registerShortcodes() |
|
135 | - { |
|
136 | - try { |
|
137 | - $this->shortcodes = apply_filters( |
|
138 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
139 | - $this->getShortcodes() |
|
140 | - ); |
|
141 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
142 | - throw new InvalidEntityException( |
|
143 | - $this->shortcodes, |
|
144 | - 'CollectionInterface', |
|
145 | - sprintf( |
|
146 | - esc_html__( |
|
147 | - 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
148 | - 'event_espresso' |
|
149 | - ), |
|
150 | - is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
151 | - ) |
|
152 | - ); |
|
153 | - } |
|
154 | - $this->legacy_shortcodes_manager->registerShortcodes(); |
|
155 | - } catch (Exception $exception) { |
|
156 | - new ExceptionStackTraceDisplay($exception); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return void |
|
163 | - * @throws Exception |
|
164 | - */ |
|
165 | - public function addShortcodes() |
|
166 | - { |
|
167 | - try { |
|
168 | - // cycle thru shortcode folders |
|
169 | - foreach ($this->shortcodes as $shortcode) { |
|
170 | - if ($shortcode instanceof EnqueueAssetsInterface) { |
|
171 | - add_action('wp_enqueue_scripts', [$shortcode, 'registerScriptsAndStylesheets'], 10); |
|
172 | - add_action('wp_enqueue_scripts', [$shortcode, 'enqueueStylesheets'], 11); |
|
173 | - } |
|
174 | - // add_shortcode() if it has not already been added |
|
175 | - if (! shortcode_exists($shortcode->getTag())) { |
|
176 | - add_shortcode($shortcode->getTag(), [$shortcode, 'processShortcodeCallback']); |
|
177 | - } |
|
178 | - } |
|
179 | - $this->legacy_shortcodes_manager->addShortcodes(); |
|
180 | - } catch (Exception $exception) { |
|
181 | - new ExceptionStackTraceDisplay($exception); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * callback for the "template_redirect" hook point |
|
188 | - * checks posts for EE shortcodes, and initializes them, |
|
189 | - * then toggles filter switch that loads core default assets |
|
190 | - * |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function templateRedirect() |
|
194 | - { |
|
195 | - global $wp_query; |
|
196 | - if (empty($wp_query->posts)) { |
|
197 | - return; |
|
198 | - } |
|
199 | - $load_assets = false; |
|
200 | - // array of posts displayed in current request |
|
201 | - $posts = is_array($wp_query->posts) ? $wp_query->posts : [$wp_query->posts]; |
|
202 | - foreach ($posts as $post) { |
|
203 | - // now check post content and excerpt for EE shortcodes |
|
204 | - $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
205 | - ? true |
|
206 | - : $load_assets; |
|
207 | - } |
|
208 | - if ($load_assets) { |
|
209 | - $this->current_page->setEspressoPage(true); |
|
210 | - add_filter('FHEE_load_css', '__return_true'); |
|
211 | - add_filter('FHEE_load_js', '__return_true'); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * checks supplied content against list of shortcodes, |
|
218 | - * then initializes any found shortcodes, and returns true. |
|
219 | - * returns false if no shortcodes found. |
|
220 | - * |
|
221 | - * @param string $content |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - public function parseContentForShortcodes($content) |
|
225 | - { |
|
226 | - if (empty($this->shortcodes)) { |
|
227 | - return false; |
|
228 | - } |
|
229 | - $has_shortcode = false; |
|
230 | - foreach ($this->shortcodes as $shortcode) { |
|
231 | - if (has_shortcode($content, $shortcode->getTag())) { |
|
232 | - $shortcode->initializeShortcode(); |
|
233 | - $has_shortcode = true; |
|
234 | - } |
|
235 | - } |
|
236 | - return $has_shortcode; |
|
237 | - } |
|
32 | + /** |
|
33 | + * @type CurrentPage |
|
34 | + */ |
|
35 | + protected $current_page; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
39 | + */ |
|
40 | + private $legacy_shortcodes_manager; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var ShortcodeInterface[] $shortcodes |
|
44 | + */ |
|
45 | + private $shortcodes; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * ShortcodesManager constructor |
|
50 | + * |
|
51 | + * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
52 | + * @param CurrentPage $current_page |
|
53 | + */ |
|
54 | + public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager, CurrentPage $current_page) |
|
55 | + { |
|
56 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
57 | + $this->current_page = $current_page; |
|
58 | + // assemble a list of installed and active shortcodes |
|
59 | + add_action( |
|
60 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
61 | + [$this, 'registerShortcodes'], |
|
62 | + 999 |
|
63 | + ); |
|
64 | + // call add_shortcode() for all installed shortcodes |
|
65 | + add_action('AHEE__EE_System__core_loaded_and_ready', [$this, 'addShortcodes']); |
|
66 | + // check content for shortcodes the old way |
|
67 | + add_action('parse_query', [$this->legacy_shortcodes_manager, 'initializeShortcodes'], 5); |
|
68 | + // check content for shortcodes the NEW more efficient way |
|
69 | + add_action('template_redirect', [$this, 'templateRedirect'], 999); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return CollectionInterface|ShortcodeInterface[] |
|
75 | + * @throws InvalidIdentifierException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + * @throws InvalidFilePathException |
|
78 | + * @throws InvalidEntityException |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws InvalidClassException |
|
81 | + */ |
|
82 | + public function getShortcodes() |
|
83 | + { |
|
84 | + if (! $this->shortcodes instanceof CollectionInterface) { |
|
85 | + $this->shortcodes = $this->loadShortcodesCollection(); |
|
86 | + } |
|
87 | + return $this->shortcodes; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return CollectionInterface|ShortcodeInterface[] |
|
93 | + * @throws InvalidIdentifierException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws InvalidFilePathException |
|
96 | + * @throws InvalidEntityException |
|
97 | + * @throws InvalidDataTypeException |
|
98 | + * @throws InvalidClassException |
|
99 | + */ |
|
100 | + protected function loadShortcodesCollection() |
|
101 | + { |
|
102 | + $loader = new CollectionLoader( |
|
103 | + new CollectionDetails( |
|
104 | + // collection name |
|
105 | + 'shortcodes', |
|
106 | + // collection interface |
|
107 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
108 | + // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
109 | + ['EventEspresso\core\domain\entities\shortcodes'], |
|
110 | + // filepaths to classes to add |
|
111 | + [], |
|
112 | + // file mask to use if parsing folder for files to add |
|
113 | + '', |
|
114 | + // what to use as identifier for collection entities |
|
115 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
116 | + CollectionDetails::ID_CLASS_NAME |
|
117 | + ) |
|
118 | + ); |
|
119 | + return $loader->getCollection(); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return void |
|
125 | + * @throws DomainException |
|
126 | + * @throws InvalidInterfaceException |
|
127 | + * @throws InvalidIdentifierException |
|
128 | + * @throws InvalidFilePathException |
|
129 | + * @throws InvalidEntityException |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + * @throws InvalidClassException |
|
132 | + * @throws Exception |
|
133 | + */ |
|
134 | + public function registerShortcodes() |
|
135 | + { |
|
136 | + try { |
|
137 | + $this->shortcodes = apply_filters( |
|
138 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
139 | + $this->getShortcodes() |
|
140 | + ); |
|
141 | + if (! $this->shortcodes instanceof CollectionInterface) { |
|
142 | + throw new InvalidEntityException( |
|
143 | + $this->shortcodes, |
|
144 | + 'CollectionInterface', |
|
145 | + sprintf( |
|
146 | + esc_html__( |
|
147 | + 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
148 | + 'event_espresso' |
|
149 | + ), |
|
150 | + is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
151 | + ) |
|
152 | + ); |
|
153 | + } |
|
154 | + $this->legacy_shortcodes_manager->registerShortcodes(); |
|
155 | + } catch (Exception $exception) { |
|
156 | + new ExceptionStackTraceDisplay($exception); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + * @throws Exception |
|
164 | + */ |
|
165 | + public function addShortcodes() |
|
166 | + { |
|
167 | + try { |
|
168 | + // cycle thru shortcode folders |
|
169 | + foreach ($this->shortcodes as $shortcode) { |
|
170 | + if ($shortcode instanceof EnqueueAssetsInterface) { |
|
171 | + add_action('wp_enqueue_scripts', [$shortcode, 'registerScriptsAndStylesheets'], 10); |
|
172 | + add_action('wp_enqueue_scripts', [$shortcode, 'enqueueStylesheets'], 11); |
|
173 | + } |
|
174 | + // add_shortcode() if it has not already been added |
|
175 | + if (! shortcode_exists($shortcode->getTag())) { |
|
176 | + add_shortcode($shortcode->getTag(), [$shortcode, 'processShortcodeCallback']); |
|
177 | + } |
|
178 | + } |
|
179 | + $this->legacy_shortcodes_manager->addShortcodes(); |
|
180 | + } catch (Exception $exception) { |
|
181 | + new ExceptionStackTraceDisplay($exception); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * callback for the "template_redirect" hook point |
|
188 | + * checks posts for EE shortcodes, and initializes them, |
|
189 | + * then toggles filter switch that loads core default assets |
|
190 | + * |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function templateRedirect() |
|
194 | + { |
|
195 | + global $wp_query; |
|
196 | + if (empty($wp_query->posts)) { |
|
197 | + return; |
|
198 | + } |
|
199 | + $load_assets = false; |
|
200 | + // array of posts displayed in current request |
|
201 | + $posts = is_array($wp_query->posts) ? $wp_query->posts : [$wp_query->posts]; |
|
202 | + foreach ($posts as $post) { |
|
203 | + // now check post content and excerpt for EE shortcodes |
|
204 | + $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
205 | + ? true |
|
206 | + : $load_assets; |
|
207 | + } |
|
208 | + if ($load_assets) { |
|
209 | + $this->current_page->setEspressoPage(true); |
|
210 | + add_filter('FHEE_load_css', '__return_true'); |
|
211 | + add_filter('FHEE_load_js', '__return_true'); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * checks supplied content against list of shortcodes, |
|
218 | + * then initializes any found shortcodes, and returns true. |
|
219 | + * returns false if no shortcodes found. |
|
220 | + * |
|
221 | + * @param string $content |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + public function parseContentForShortcodes($content) |
|
225 | + { |
|
226 | + if (empty($this->shortcodes)) { |
|
227 | + return false; |
|
228 | + } |
|
229 | + $has_shortcode = false; |
|
230 | + foreach ($this->shortcodes as $shortcode) { |
|
231 | + if (has_shortcode($content, $shortcode->getTag())) { |
|
232 | + $shortcode->initializeShortcode(); |
|
233 | + $has_shortcode = true; |
|
234 | + } |
|
235 | + } |
|
236 | + return $has_shortcode; |
|
237 | + } |
|
238 | 238 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function __construct($title, $content) |
84 | 84 | { |
85 | 85 | global $wp_version; |
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
86 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
87 | 87 | define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
88 | 88 | } |
89 | 89 | $this->setContent($content); |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
94 | 94 | array( |
95 | 95 | 'site_theme' => get_stylesheet_directory_uri() |
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
96 | + . '/style.css?ver='.EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
98 | 98 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
99 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
100 | 100 | ), |
101 | 101 | $this |
102 | 102 | ) |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | apply_filters( |
106 | 106 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
107 | 107 | array( |
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
109 | 109 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
110 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
111 | 111 | ), |
112 | 112 | $this |
113 | 113 | ) |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | foreach ($stylesheets as $handle => $stylesheet) { |
184 | - $this->css[ $handle ] = $stylesheet; |
|
184 | + $this->css[$handle] = $stylesheet; |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | } |
204 | 204 | foreach ($scripts as $handle => $script) { |
205 | 205 | if ($add_to_header) { |
206 | - $this->header_js[ $handle ] = $script; |
|
206 | + $this->header_js[$handle] = $script; |
|
207 | 207 | } else { |
208 | - $this->footer_js[ $handle ] = $script; |
|
208 | + $this->footer_js[$handle] = $script; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | } |
229 | 229 | foreach ($script_attributes as $handle => $script_attribute) { |
230 | 230 | if ($add_to_header) { |
231 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
231 | + $this->header_js_attributes[$handle] = $script_attribute; |
|
232 | 232 | } else { |
233 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
233 | + $this->footer_js_attributes[$handle] = $script_attribute; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | } |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | } |
254 | 254 | foreach ($vars as $handle => $var) { |
255 | 255 | if ($var_name === 'eei18n') { |
256 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
256 | + EE_Registry::$i18n_js_strings[$handle] = $var; |
|
257 | 257 | } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
258 | - $this->localized_vars[ $var_name ] = $var; |
|
258 | + $this->localized_vars[$var_name] = $var; |
|
259 | 259 | } else { |
260 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | - $this->localized_vars[ $var_name ] = array(); |
|
260 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
261 | + $this->localized_vars[$var_name] = array(); |
|
262 | 262 | } |
263 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
263 | + $this->localized_vars[$var_name][$handle] = $var; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | public function getTemplate() |
291 | 291 | { |
292 | 292 | return EEH_Template::display_template( |
293 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
293 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
294 | 294 | array( |
295 | 295 | 'title' => apply_filters( |
296 | 296 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | ), |
335 | 335 | 'eei18n' => apply_filters( |
336 | 336 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
337 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
337 | + EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
338 | 338 | $this |
339 | 339 | ), |
340 | 340 | 'notices' => EEH_Template::display_template( |
341 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
341 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
342 | 342 | array(), |
343 | 343 | true |
344 | 344 | ), |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | { |
359 | 359 | $JSON = ''; |
360 | 360 | foreach ($this->localized_vars as $var_name => $vars) { |
361 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
361 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($vars); |
|
362 | 362 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
363 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
363 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
364 | 364 | $JSON .= '; /* ]]> */'; |
365 | 365 | } |
366 | 366 | return $JSON; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | if (is_array($var)) { |
377 | 377 | $localized_vars = array(); |
378 | 378 | foreach ((array) $var as $key => $value) { |
379 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
379 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
380 | 380 | } |
381 | 381 | return $localized_vars; |
382 | 382 | } |
@@ -18,373 +18,373 @@ |
||
18 | 18 | */ |
19 | 19 | class Iframe |
20 | 20 | { |
21 | - /* |
|
21 | + /* |
|
22 | 22 | * HTML for notices and ajax gif |
23 | 23 | * @var string $title |
24 | 24 | */ |
25 | - protected $title = ''; |
|
25 | + protected $title = ''; |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | * HTML for the content being displayed |
29 | 29 | * @var string $content |
30 | 30 | */ |
31 | - protected $content = ''; |
|
31 | + protected $content = ''; |
|
32 | 32 | |
33 | - /* |
|
33 | + /* |
|
34 | 34 | * whether or not to call wp_head() and wp_footer() |
35 | 35 | * @var boolean $enqueue_wp_assets |
36 | 36 | */ |
37 | - protected $enqueue_wp_assets = false; |
|
37 | + protected $enqueue_wp_assets = false; |
|
38 | 38 | |
39 | - /* |
|
39 | + /* |
|
40 | 40 | * an array of CSS URLs |
41 | 41 | * @var array $css |
42 | 42 | */ |
43 | - protected $css = array(); |
|
43 | + protected $css = array(); |
|
44 | 44 | |
45 | - /* |
|
45 | + /* |
|
46 | 46 | * an array of JS URLs to be set in the HTML header. |
47 | 47 | * @var array $header_js |
48 | 48 | */ |
49 | - protected $header_js = array(); |
|
49 | + protected $header_js = array(); |
|
50 | 50 | |
51 | - /* |
|
51 | + /* |
|
52 | 52 | * an array of additional attributes to be added to <script> tags for header JS |
53 | 53 | * @var array $footer_js |
54 | 54 | */ |
55 | - protected $header_js_attributes = array(); |
|
55 | + protected $header_js_attributes = array(); |
|
56 | 56 | |
57 | - /* |
|
57 | + /* |
|
58 | 58 | * an array of JS URLs to be displayed before the HTML </body> tag |
59 | 59 | * @var array $footer_js |
60 | 60 | */ |
61 | - protected $footer_js = array(); |
|
61 | + protected $footer_js = array(); |
|
62 | 62 | |
63 | - /* |
|
63 | + /* |
|
64 | 64 | * an array of additional attributes to be added to <script> tags for footer JS |
65 | 65 | * @var array $footer_js_attributes |
66 | 66 | */ |
67 | - protected $footer_js_attributes = array(); |
|
67 | + protected $footer_js_attributes = array(); |
|
68 | 68 | |
69 | - /* |
|
69 | + /* |
|
70 | 70 | * an array of JSON vars to be set in the HTML header. |
71 | 71 | * @var array $localized_vars |
72 | 72 | */ |
73 | - protected $localized_vars = array(); |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Iframe constructor |
|
78 | - * |
|
79 | - * @param string $title |
|
80 | - * @param string $content |
|
81 | - * @throws DomainException |
|
82 | - */ |
|
83 | - public function __construct($title, $content) |
|
84 | - { |
|
85 | - global $wp_version; |
|
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | - define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | - } |
|
89 | - $this->setContent($content); |
|
90 | - $this->setTitle($title); |
|
91 | - $this->addStylesheets( |
|
92 | - apply_filters( |
|
93 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | - array( |
|
95 | - 'site_theme' => get_stylesheet_directory_uri() |
|
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | - ), |
|
101 | - $this |
|
102 | - ) |
|
103 | - ); |
|
104 | - $this->addScripts( |
|
105 | - apply_filters( |
|
106 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | - array( |
|
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | - ), |
|
112 | - $this |
|
113 | - ) |
|
114 | - ); |
|
115 | - if ( |
|
116 | - apply_filters( |
|
117 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
118 | - false |
|
119 | - ) |
|
120 | - ) { |
|
121 | - $this->addStylesheets( |
|
122 | - apply_filters( |
|
123 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
124 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
125 | - $this |
|
126 | - ) |
|
127 | - ); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $title |
|
134 | - * @throws DomainException |
|
135 | - */ |
|
136 | - public function setTitle($title) |
|
137 | - { |
|
138 | - if (empty($title)) { |
|
139 | - throw new DomainException( |
|
140 | - esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
141 | - ); |
|
142 | - } |
|
143 | - $this->title = $title; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $content |
|
149 | - * @throws DomainException |
|
150 | - */ |
|
151 | - public function setContent($content) |
|
152 | - { |
|
153 | - if (empty($content)) { |
|
154 | - throw new DomainException( |
|
155 | - esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
156 | - ); |
|
157 | - } |
|
158 | - $this->content = $content; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param boolean $enqueue_wp_assets |
|
164 | - */ |
|
165 | - public function setEnqueueWpAssets($enqueue_wp_assets) |
|
166 | - { |
|
167 | - $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param array $stylesheets |
|
173 | - * @throws DomainException |
|
174 | - */ |
|
175 | - public function addStylesheets(array $stylesheets) |
|
176 | - { |
|
177 | - if (empty($stylesheets)) { |
|
178 | - throw new DomainException( |
|
179 | - esc_html__( |
|
180 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
181 | - 'event_espresso' |
|
182 | - ) |
|
183 | - ); |
|
184 | - } |
|
185 | - foreach ($stylesheets as $handle => $stylesheet) { |
|
186 | - $this->css[ $handle ] = $stylesheet; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param array $scripts |
|
193 | - * @param bool $add_to_header |
|
194 | - * @throws DomainException |
|
195 | - */ |
|
196 | - public function addScripts(array $scripts, $add_to_header = false) |
|
197 | - { |
|
198 | - if (empty($scripts)) { |
|
199 | - throw new DomainException( |
|
200 | - esc_html__( |
|
201 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
202 | - 'event_espresso' |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - foreach ($scripts as $handle => $script) { |
|
207 | - if ($add_to_header) { |
|
208 | - $this->header_js[ $handle ] = $script; |
|
209 | - } else { |
|
210 | - $this->footer_js[ $handle ] = $script; |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @param array $script_attributes |
|
218 | - * @param bool $add_to_header |
|
219 | - * @throws DomainException |
|
220 | - */ |
|
221 | - public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
222 | - { |
|
223 | - if (empty($script_attributes)) { |
|
224 | - throw new DomainException( |
|
225 | - esc_html__( |
|
226 | - 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
227 | - 'event_espresso' |
|
228 | - ) |
|
229 | - ); |
|
230 | - } |
|
231 | - foreach ($script_attributes as $handle => $script_attribute) { |
|
232 | - if ($add_to_header) { |
|
233 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
234 | - } else { |
|
235 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param array $vars |
|
243 | - * @param string $var_name |
|
244 | - * @throws DomainException |
|
245 | - */ |
|
246 | - public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
247 | - { |
|
248 | - if (empty($vars)) { |
|
249 | - throw new DomainException( |
|
250 | - esc_html__( |
|
251 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
252 | - 'event_espresso' |
|
253 | - ) |
|
254 | - ); |
|
255 | - } |
|
256 | - foreach ($vars as $handle => $var) { |
|
257 | - if ($var_name === 'eei18n') { |
|
258 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
259 | - } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
260 | - $this->localized_vars[ $var_name ] = $var; |
|
261 | - } else { |
|
262 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
263 | - $this->localized_vars[ $var_name ] = array(); |
|
264 | - } |
|
265 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @param string $utm_content |
|
273 | - * @throws DomainException |
|
274 | - */ |
|
275 | - public function display($utm_content = '') |
|
276 | - { |
|
277 | - $this->content .= EEH_Template::powered_by_event_espresso( |
|
278 | - '', |
|
279 | - '', |
|
280 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
281 | - ); |
|
282 | - EE_System::do_not_cache(); |
|
283 | - echo ($this->getTemplate()); |
|
284 | - exit; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return string |
|
290 | - * @throws DomainException |
|
291 | - */ |
|
292 | - public function getTemplate() |
|
293 | - { |
|
294 | - return EEH_Template::display_template( |
|
295 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
296 | - array( |
|
297 | - 'title' => apply_filters( |
|
298 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
299 | - $this->title, |
|
300 | - $this |
|
301 | - ), |
|
302 | - 'content' => apply_filters( |
|
303 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
304 | - $this->content, |
|
305 | - $this |
|
306 | - ), |
|
307 | - 'enqueue_wp_assets' => apply_filters( |
|
308 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
309 | - $this->enqueue_wp_assets, |
|
310 | - $this |
|
311 | - ), |
|
312 | - 'css' => (array) apply_filters( |
|
313 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
314 | - $this->css, |
|
315 | - $this |
|
316 | - ), |
|
317 | - 'header_js' => (array) apply_filters( |
|
318 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
319 | - $this->header_js, |
|
320 | - $this |
|
321 | - ), |
|
322 | - 'header_js_attributes' => (array) apply_filters( |
|
323 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
324 | - $this->header_js_attributes, |
|
325 | - $this |
|
326 | - ), |
|
327 | - 'footer_js' => (array) apply_filters( |
|
328 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
329 | - $this->footer_js, |
|
330 | - $this |
|
331 | - ), |
|
332 | - 'footer_js_attributes' => (array) apply_filters( |
|
333 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
334 | - $this->footer_js_attributes, |
|
335 | - $this |
|
336 | - ), |
|
337 | - 'eei18n' => apply_filters( |
|
338 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
339 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
340 | - $this |
|
341 | - ), |
|
342 | - 'notices' => EEH_Template::display_template( |
|
343 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
344 | - array(), |
|
345 | - true |
|
346 | - ), |
|
347 | - ), |
|
348 | - true, |
|
349 | - true |
|
350 | - ); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * localizeJsonVars |
|
356 | - * |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function localizeJsonVars() |
|
360 | - { |
|
361 | - $JSON = ''; |
|
362 | - foreach ($this->localized_vars as $var_name => $vars) { |
|
363 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
364 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
365 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
366 | - $JSON .= '; /* ]]> */'; |
|
367 | - } |
|
368 | - return $JSON; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @param bool|int|float|string|array $var |
|
374 | - * @return array|string|null |
|
375 | - */ |
|
376 | - public function encodeJsonVars($var) |
|
377 | - { |
|
378 | - if (is_array($var)) { |
|
379 | - $localized_vars = array(); |
|
380 | - foreach ((array) $var as $key => $value) { |
|
381 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
382 | - } |
|
383 | - return $localized_vars; |
|
384 | - } |
|
385 | - if (is_scalar($var)) { |
|
386 | - return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
387 | - } |
|
388 | - return null; |
|
389 | - } |
|
73 | + protected $localized_vars = array(); |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Iframe constructor |
|
78 | + * |
|
79 | + * @param string $title |
|
80 | + * @param string $content |
|
81 | + * @throws DomainException |
|
82 | + */ |
|
83 | + public function __construct($title, $content) |
|
84 | + { |
|
85 | + global $wp_version; |
|
86 | + if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | + } |
|
89 | + $this->setContent($content); |
|
90 | + $this->setTitle($title); |
|
91 | + $this->addStylesheets( |
|
92 | + apply_filters( |
|
93 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | + array( |
|
95 | + 'site_theme' => get_stylesheet_directory_uri() |
|
96 | + . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | + ), |
|
101 | + $this |
|
102 | + ) |
|
103 | + ); |
|
104 | + $this->addScripts( |
|
105 | + apply_filters( |
|
106 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | + array( |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | + ), |
|
112 | + $this |
|
113 | + ) |
|
114 | + ); |
|
115 | + if ( |
|
116 | + apply_filters( |
|
117 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
118 | + false |
|
119 | + ) |
|
120 | + ) { |
|
121 | + $this->addStylesheets( |
|
122 | + apply_filters( |
|
123 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
124 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
125 | + $this |
|
126 | + ) |
|
127 | + ); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $title |
|
134 | + * @throws DomainException |
|
135 | + */ |
|
136 | + public function setTitle($title) |
|
137 | + { |
|
138 | + if (empty($title)) { |
|
139 | + throw new DomainException( |
|
140 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
141 | + ); |
|
142 | + } |
|
143 | + $this->title = $title; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $content |
|
149 | + * @throws DomainException |
|
150 | + */ |
|
151 | + public function setContent($content) |
|
152 | + { |
|
153 | + if (empty($content)) { |
|
154 | + throw new DomainException( |
|
155 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
156 | + ); |
|
157 | + } |
|
158 | + $this->content = $content; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param boolean $enqueue_wp_assets |
|
164 | + */ |
|
165 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
166 | + { |
|
167 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param array $stylesheets |
|
173 | + * @throws DomainException |
|
174 | + */ |
|
175 | + public function addStylesheets(array $stylesheets) |
|
176 | + { |
|
177 | + if (empty($stylesheets)) { |
|
178 | + throw new DomainException( |
|
179 | + esc_html__( |
|
180 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
181 | + 'event_espresso' |
|
182 | + ) |
|
183 | + ); |
|
184 | + } |
|
185 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
186 | + $this->css[ $handle ] = $stylesheet; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param array $scripts |
|
193 | + * @param bool $add_to_header |
|
194 | + * @throws DomainException |
|
195 | + */ |
|
196 | + public function addScripts(array $scripts, $add_to_header = false) |
|
197 | + { |
|
198 | + if (empty($scripts)) { |
|
199 | + throw new DomainException( |
|
200 | + esc_html__( |
|
201 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
202 | + 'event_espresso' |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + foreach ($scripts as $handle => $script) { |
|
207 | + if ($add_to_header) { |
|
208 | + $this->header_js[ $handle ] = $script; |
|
209 | + } else { |
|
210 | + $this->footer_js[ $handle ] = $script; |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @param array $script_attributes |
|
218 | + * @param bool $add_to_header |
|
219 | + * @throws DomainException |
|
220 | + */ |
|
221 | + public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
222 | + { |
|
223 | + if (empty($script_attributes)) { |
|
224 | + throw new DomainException( |
|
225 | + esc_html__( |
|
226 | + 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
227 | + 'event_espresso' |
|
228 | + ) |
|
229 | + ); |
|
230 | + } |
|
231 | + foreach ($script_attributes as $handle => $script_attribute) { |
|
232 | + if ($add_to_header) { |
|
233 | + $this->header_js_attributes[ $handle ] = $script_attribute; |
|
234 | + } else { |
|
235 | + $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param array $vars |
|
243 | + * @param string $var_name |
|
244 | + * @throws DomainException |
|
245 | + */ |
|
246 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
247 | + { |
|
248 | + if (empty($vars)) { |
|
249 | + throw new DomainException( |
|
250 | + esc_html__( |
|
251 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
252 | + 'event_espresso' |
|
253 | + ) |
|
254 | + ); |
|
255 | + } |
|
256 | + foreach ($vars as $handle => $var) { |
|
257 | + if ($var_name === 'eei18n') { |
|
258 | + EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
259 | + } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
260 | + $this->localized_vars[ $var_name ] = $var; |
|
261 | + } else { |
|
262 | + if (! isset($this->localized_vars[ $var_name ])) { |
|
263 | + $this->localized_vars[ $var_name ] = array(); |
|
264 | + } |
|
265 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @param string $utm_content |
|
273 | + * @throws DomainException |
|
274 | + */ |
|
275 | + public function display($utm_content = '') |
|
276 | + { |
|
277 | + $this->content .= EEH_Template::powered_by_event_espresso( |
|
278 | + '', |
|
279 | + '', |
|
280 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
281 | + ); |
|
282 | + EE_System::do_not_cache(); |
|
283 | + echo ($this->getTemplate()); |
|
284 | + exit; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return string |
|
290 | + * @throws DomainException |
|
291 | + */ |
|
292 | + public function getTemplate() |
|
293 | + { |
|
294 | + return EEH_Template::display_template( |
|
295 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
296 | + array( |
|
297 | + 'title' => apply_filters( |
|
298 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
299 | + $this->title, |
|
300 | + $this |
|
301 | + ), |
|
302 | + 'content' => apply_filters( |
|
303 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
304 | + $this->content, |
|
305 | + $this |
|
306 | + ), |
|
307 | + 'enqueue_wp_assets' => apply_filters( |
|
308 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
309 | + $this->enqueue_wp_assets, |
|
310 | + $this |
|
311 | + ), |
|
312 | + 'css' => (array) apply_filters( |
|
313 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
314 | + $this->css, |
|
315 | + $this |
|
316 | + ), |
|
317 | + 'header_js' => (array) apply_filters( |
|
318 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
319 | + $this->header_js, |
|
320 | + $this |
|
321 | + ), |
|
322 | + 'header_js_attributes' => (array) apply_filters( |
|
323 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
324 | + $this->header_js_attributes, |
|
325 | + $this |
|
326 | + ), |
|
327 | + 'footer_js' => (array) apply_filters( |
|
328 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
329 | + $this->footer_js, |
|
330 | + $this |
|
331 | + ), |
|
332 | + 'footer_js_attributes' => (array) apply_filters( |
|
333 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
334 | + $this->footer_js_attributes, |
|
335 | + $this |
|
336 | + ), |
|
337 | + 'eei18n' => apply_filters( |
|
338 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
339 | + EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
340 | + $this |
|
341 | + ), |
|
342 | + 'notices' => EEH_Template::display_template( |
|
343 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
344 | + array(), |
|
345 | + true |
|
346 | + ), |
|
347 | + ), |
|
348 | + true, |
|
349 | + true |
|
350 | + ); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * localizeJsonVars |
|
356 | + * |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function localizeJsonVars() |
|
360 | + { |
|
361 | + $JSON = ''; |
|
362 | + foreach ($this->localized_vars as $var_name => $vars) { |
|
363 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
364 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
365 | + $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
366 | + $JSON .= '; /* ]]> */'; |
|
367 | + } |
|
368 | + return $JSON; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @param bool|int|float|string|array $var |
|
374 | + * @return array|string|null |
|
375 | + */ |
|
376 | + public function encodeJsonVars($var) |
|
377 | + { |
|
378 | + if (is_array($var)) { |
|
379 | + $localized_vars = array(); |
|
380 | + foreach ((array) $var as $key => $value) { |
|
381 | + $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
382 | + } |
|
383 | + return $localized_vars; |
|
384 | + } |
|
385 | + if (is_scalar($var)) { |
|
386 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
387 | + } |
|
388 | + return null; |
|
389 | + } |
|
390 | 390 | } |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | apply_filters( |
48 | 48 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
49 | 49 | [ |
50 | - 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
51 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
52 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
50 | + 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
51 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION |
|
52 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
53 | 53 | ], |
54 | 54 | $this |
55 | 55 | ) |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | EE_Registry::instance()->CFG->map_settings->google_map_api_key |
66 | 66 | ) |
67 | 67 | ), |
68 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
68 | + 'ee_gmap' => EE_HELPERS_ASSETS.'ee_gmap.js?ver=1.0', |
|
69 | 69 | ], |
70 | 70 | $this |
71 | 71 | ) |
@@ -21,58 +21,58 @@ |
||
21 | 21 | */ |
22 | 22 | class EventsArchiveIframe extends Iframe |
23 | 23 | { |
24 | - /** |
|
25 | - * EventsArchiveIframe constructor. |
|
26 | - * |
|
27 | - * @param EED_Events_Archive $EED_Events_Archive |
|
28 | - * @throws EE_Error |
|
29 | - * @throws ReflectionException |
|
30 | - */ |
|
31 | - public function __construct($EED_Events_Archive) |
|
32 | - { |
|
33 | - /** @var CurrentPage $current_page */ |
|
34 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
35 | - $current_page->setEspressoPage(true); |
|
36 | - add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
37 | - $EED_Events_Archive->event_list(); |
|
38 | - /** @var EspressoEvents $event_list */ |
|
39 | - $event_list = EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
40 | - parent::__construct( |
|
41 | - esc_html__('Event List', 'event_espresso'), |
|
42 | - $event_list->processShortcode() |
|
43 | - ); |
|
44 | - $this->addStylesheets( |
|
45 | - apply_filters( |
|
46 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
47 | - [ |
|
48 | - 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
49 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
50 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
51 | - ], |
|
52 | - $this |
|
53 | - ) |
|
54 | - ); |
|
55 | - $this->addScripts( |
|
56 | - apply_filters( |
|
57 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
58 | - [ |
|
59 | - 'gmap_api' => sprintf( |
|
60 | - 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
61 | - apply_filters( |
|
62 | - 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
63 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
64 | - ) |
|
65 | - ), |
|
66 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
67 | - ], |
|
68 | - $this |
|
69 | - ) |
|
70 | - ); |
|
71 | - $this->addLocalizedVars( |
|
72 | - [ |
|
73 | - 'ee_gmap' => EEH_Maps::$gmap_vars, |
|
74 | - ], |
|
75 | - 'ee_gmap_vars' |
|
76 | - ); |
|
77 | - } |
|
24 | + /** |
|
25 | + * EventsArchiveIframe constructor. |
|
26 | + * |
|
27 | + * @param EED_Events_Archive $EED_Events_Archive |
|
28 | + * @throws EE_Error |
|
29 | + * @throws ReflectionException |
|
30 | + */ |
|
31 | + public function __construct($EED_Events_Archive) |
|
32 | + { |
|
33 | + /** @var CurrentPage $current_page */ |
|
34 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
35 | + $current_page->setEspressoPage(true); |
|
36 | + add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
37 | + $EED_Events_Archive->event_list(); |
|
38 | + /** @var EspressoEvents $event_list */ |
|
39 | + $event_list = EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
40 | + parent::__construct( |
|
41 | + esc_html__('Event List', 'event_espresso'), |
|
42 | + $event_list->processShortcode() |
|
43 | + ); |
|
44 | + $this->addStylesheets( |
|
45 | + apply_filters( |
|
46 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
47 | + [ |
|
48 | + 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
49 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
50 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
51 | + ], |
|
52 | + $this |
|
53 | + ) |
|
54 | + ); |
|
55 | + $this->addScripts( |
|
56 | + apply_filters( |
|
57 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
58 | + [ |
|
59 | + 'gmap_api' => sprintf( |
|
60 | + 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
61 | + apply_filters( |
|
62 | + 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
63 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
64 | + ) |
|
65 | + ), |
|
66 | + 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
67 | + ], |
|
68 | + $this |
|
69 | + ) |
|
70 | + ); |
|
71 | + $this->addLocalizedVars( |
|
72 | + [ |
|
73 | + 'ee_gmap' => EEH_Maps::$gmap_vars, |
|
74 | + ], |
|
75 | + 'ee_gmap_vars' |
|
76 | + ); |
|
77 | + } |
|
78 | 78 | } |
@@ -72,6 +72,6 @@ |
||
72 | 72 | } |
73 | 73 | $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription(); |
74 | 74 | $this->template_args['template_path'] = |
75 | - TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
75 | + TICKET_SELECTOR_TEMPLATES_PATH.'simple_ticket_selector.template.php'; |
|
76 | 76 | } |
77 | 77 | } |
@@ -19,59 +19,59 @@ |
||
19 | 19 | */ |
20 | 20 | class TicketSelectorSimple extends TicketSelector |
21 | 21 | { |
22 | - /** |
|
23 | - * @var EE_Ticket $ticket |
|
24 | - */ |
|
25 | - protected $ticket; |
|
22 | + /** |
|
23 | + * @var EE_Ticket $ticket |
|
24 | + */ |
|
25 | + protected $ticket; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * TicketSelectorSimple constructor. |
|
30 | - * |
|
31 | - * @param EE_Event $event |
|
32 | - * @param EE_Ticket $ticket |
|
33 | - * @param int $max_attendees |
|
34 | - * @param array $template_args |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - public function __construct(EE_Event $event, EE_Ticket $ticket, $max_attendees, array $template_args) |
|
38 | - { |
|
39 | - $this->ticket = $ticket; |
|
40 | - parent::__construct( |
|
41 | - $event, |
|
42 | - [$this->ticket], |
|
43 | - $max_attendees, |
|
44 | - $template_args |
|
45 | - ); |
|
46 | - } |
|
28 | + /** |
|
29 | + * TicketSelectorSimple constructor. |
|
30 | + * |
|
31 | + * @param EE_Event $event |
|
32 | + * @param EE_Ticket $ticket |
|
33 | + * @param int $max_attendees |
|
34 | + * @param array $template_args |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + public function __construct(EE_Event $event, EE_Ticket $ticket, $max_attendees, array $template_args) |
|
38 | + { |
|
39 | + $this->ticket = $ticket; |
|
40 | + parent::__construct( |
|
41 | + $event, |
|
42 | + [$this->ticket], |
|
43 | + $max_attendees, |
|
44 | + $template_args |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * sets any and all template args that are required for this Ticket Selector |
|
51 | - * |
|
52 | - * @return void |
|
53 | - * @throws UnexpectedEntityException |
|
54 | - * @throws EE_Error |
|
55 | - */ |
|
56 | - protected function addTemplateArgs() |
|
57 | - { |
|
58 | - $this->ticket_rows = 1; |
|
59 | - unset($this->template_args['tickets']); |
|
60 | - $this->template_args['ticket'] = $this->ticket; |
|
61 | - $ticket_selector_row = new TicketSelectorRowSimple( |
|
62 | - $this->ticket, |
|
63 | - $this->max_attendees, |
|
64 | - $this->template_args['date_format'], |
|
65 | - $this->template_args['event_status'] |
|
66 | - ); |
|
67 | - $this->template_args['TKT_ID'] = $this->ticket->ID(); |
|
68 | - $ticket_selector_row->setupTicketStatusDisplay(); |
|
69 | - $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay(); |
|
70 | - if (empty($this->template_args['ticket_status_display'])) { |
|
71 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
72 | - } |
|
73 | - $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription(); |
|
74 | - $this->template_args['template_path'] = |
|
75 | - TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
76 | - } |
|
49 | + /** |
|
50 | + * sets any and all template args that are required for this Ticket Selector |
|
51 | + * |
|
52 | + * @return void |
|
53 | + * @throws UnexpectedEntityException |
|
54 | + * @throws EE_Error |
|
55 | + */ |
|
56 | + protected function addTemplateArgs() |
|
57 | + { |
|
58 | + $this->ticket_rows = 1; |
|
59 | + unset($this->template_args['tickets']); |
|
60 | + $this->template_args['ticket'] = $this->ticket; |
|
61 | + $ticket_selector_row = new TicketSelectorRowSimple( |
|
62 | + $this->ticket, |
|
63 | + $this->max_attendees, |
|
64 | + $this->template_args['date_format'], |
|
65 | + $this->template_args['event_status'] |
|
66 | + ); |
|
67 | + $this->template_args['TKT_ID'] = $this->ticket->ID(); |
|
68 | + $ticket_selector_row->setupTicketStatusDisplay(); |
|
69 | + $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay(); |
|
70 | + if (empty($this->template_args['ticket_status_display'])) { |
|
71 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
72 | + } |
|
73 | + $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription(); |
|
74 | + $this->template_args['template_path'] = |
|
75 | + TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
76 | + } |
|
77 | 77 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $request = self::getRequest(); |
84 | 84 | if ($request->requestParamIsSet('post_type')) { |
85 | 85 | // define path to templates |
86 | - define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
86 | + define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
87 | 87 | // what kinda post_type are we dealing with ? |
88 | 88 | switch ($request->getRequestParam('post_type')) { |
89 | 89 | case 'espresso_events': |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public static function the_event_feed($content) |
157 | 157 | { |
158 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) { |
|
158 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH.'espresso_events_feed.template.php')) { |
|
159 | 159 | global $post; |
160 | 160 | $template_args = array( |
161 | 161 | 'EVT_ID' => $post->ID, |
162 | 162 | 'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
163 | 163 | ); |
164 | 164 | $content = EEH_Template::display_template( |
165 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php', |
|
165 | + RSS_FEEDS_TEMPLATES_PATH.'espresso_events_feed.template.php', |
|
166 | 166 | $template_args, |
167 | 167 | true |
168 | 168 | ); |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public static function the_venue_feed($content) |
198 | 198 | { |
199 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) { |
|
199 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH.'espresso_venues_feed.template.php')) { |
|
200 | 200 | global $post; |
201 | 201 | $template_args = array( |
202 | 202 | 'VNU_ID' => $post->ID, |
203 | 203 | 'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
204 | 204 | ); |
205 | 205 | $content = EEH_Template::display_template( |
206 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php', |
|
206 | + RSS_FEEDS_TEMPLATES_PATH.'espresso_venues_feed.template.php', |
|
207 | 207 | $template_args, |
208 | 208 | true |
209 | 209 | ); |
@@ -11,218 +11,218 @@ |
||
11 | 11 | */ |
12 | 12 | class EED_Feeds extends EED_Module |
13 | 13 | { |
14 | - /** |
|
15 | - * @return EED_Feeds |
|
16 | - */ |
|
17 | - public static function instance() |
|
18 | - { |
|
19 | - return parent::get_instance(__CLASS__); |
|
20 | - } |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
25 | - * |
|
26 | - * @access public |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public static function set_hooks() |
|
30 | - { |
|
31 | - add_action('parse_request', array('EED_Feeds', 'parse_request'), 10); |
|
32 | - add_filter('default_feed', array('EED_Feeds', 'default_feed'), 10, 1); |
|
33 | - add_filter('comment_feed_join', array('EED_Feeds', 'comment_feed_join'), 10, 2); |
|
34 | - add_filter('comment_feed_where', array('EED_Feeds', 'comment_feed_where'), 10, 2); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
39 | - * |
|
40 | - * @access public |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public static function set_hooks_admin() |
|
44 | - { |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * run - initial module setup |
|
50 | - * |
|
51 | - * @access public |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function run($WP) |
|
55 | - { |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * default_feed |
|
61 | - * |
|
62 | - * @access public |
|
63 | - * @param type rss2, atom, rss, rdf, rssjs |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public static function default_feed($type = 'rss2') |
|
67 | - { |
|
68 | - // rss2, atom, rss, rdf, rssjs |
|
69 | - $type = 'rss2'; |
|
70 | - return $type; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * parse_request |
|
76 | - * |
|
77 | - * @access public |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public static function parse_request() |
|
81 | - { |
|
82 | - $request = self::getRequest(); |
|
83 | - if ($request->requestParamIsSet('post_type')) { |
|
84 | - // define path to templates |
|
85 | - define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
86 | - // what kinda post_type are we dealing with ? |
|
87 | - switch ($request->getRequestParam('post_type')) { |
|
88 | - case 'espresso_events': |
|
89 | - // for rss2, atom, rss, rdf |
|
90 | - add_filter('the_excerpt_rss', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
91 | - add_filter('the_content_feed', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
92 | - // for json ( also uses the above filter ) |
|
93 | - add_filter('rssjs_feed_item', array('EED_Feeds', 'the_event_rssjs_feed'), 10, 1); |
|
94 | - break; |
|
95 | - case 'espresso_venues': |
|
96 | - // for rss2, atom, rss, rdf |
|
97 | - add_filter('the_excerpt_rss', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
98 | - add_filter('the_content_feed', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
99 | - // for json ( also uses the above filter ) |
|
100 | - add_filter('rssjs_feed_item', array('EED_Feeds', 'the_venue_rssjs_feed'), 10, 1); |
|
101 | - break; |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * comment_feed_join - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
109 | - * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
110 | - * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
111 | - * espresso_attendees post_type |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param string $SQL the JOIN clause for the comment feed query |
|
115 | - * @return void |
|
116 | - */ |
|
117 | - public static function comment_feed_join($SQL) |
|
118 | - { |
|
119 | - global $wpdb; |
|
120 | - // check for wp_posts table in JOIN clause |
|
121 | - if (strpos($SQL, $wpdb->posts) !== false) { |
|
122 | - add_filter('EED_Feeds__comment_feed_where__espresso_attendees', '__return_true'); |
|
123 | - } |
|
124 | - return $SQL; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * comment_feed_where - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
130 | - * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
131 | - * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
132 | - * espresso_attendees post_type |
|
133 | - * |
|
134 | - * @access public |
|
135 | - * @param string $SQL the WHERE clause for the comment feed query |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - public static function comment_feed_where($SQL) |
|
139 | - { |
|
140 | - global $wp_query, $wpdb; |
|
141 | - if ($wp_query->is_comment_feed && apply_filters('EED_Feeds__comment_feed_where__espresso_attendees', false)) { |
|
142 | - $SQL .= " AND $wpdb->posts.post_type != 'espresso_attendees'"; |
|
143 | - } |
|
144 | - return $SQL; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * the_event_feed |
|
150 | - * |
|
151 | - * @access public |
|
152 | - * @param string $content |
|
153 | - * @return void |
|
154 | - */ |
|
155 | - public static function the_event_feed($content) |
|
156 | - { |
|
157 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) { |
|
158 | - global $post; |
|
159 | - $template_args = array( |
|
160 | - 'EVT_ID' => $post->ID, |
|
161 | - 'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
162 | - ); |
|
163 | - $content = EEH_Template::display_template( |
|
164 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php', |
|
165 | - $template_args, |
|
166 | - true |
|
167 | - ); |
|
168 | - } |
|
169 | - return $content; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * the_event_rssjs_feed |
|
175 | - * |
|
176 | - * @access public |
|
177 | - * @param object $item |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public static function the_event_rssjs_feed($item) |
|
181 | - { |
|
182 | - if (is_feed() && isset($item->description)) { |
|
183 | - $item->description = EED_Feeds::the_event_feed($item->description); |
|
184 | - } |
|
185 | - return $item; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * the_venue_feed |
|
191 | - * |
|
192 | - * @access public |
|
193 | - * @param string $content |
|
194 | - * @return void |
|
195 | - */ |
|
196 | - public static function the_venue_feed($content) |
|
197 | - { |
|
198 | - if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) { |
|
199 | - global $post; |
|
200 | - $template_args = array( |
|
201 | - 'VNU_ID' => $post->ID, |
|
202 | - 'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
203 | - ); |
|
204 | - $content = EEH_Template::display_template( |
|
205 | - RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php', |
|
206 | - $template_args, |
|
207 | - true |
|
208 | - ); |
|
209 | - } |
|
210 | - return $content; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * the_venue_rssjs_feed |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @param object $item |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - public static function the_venue_rssjs_feed($item) |
|
222 | - { |
|
223 | - if (is_feed() && isset($item->description)) { |
|
224 | - $item->description = EED_Feeds::the_venue_feed($item->description); |
|
225 | - } |
|
226 | - return $item; |
|
227 | - } |
|
14 | + /** |
|
15 | + * @return EED_Feeds |
|
16 | + */ |
|
17 | + public static function instance() |
|
18 | + { |
|
19 | + return parent::get_instance(__CLASS__); |
|
20 | + } |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
25 | + * |
|
26 | + * @access public |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public static function set_hooks() |
|
30 | + { |
|
31 | + add_action('parse_request', array('EED_Feeds', 'parse_request'), 10); |
|
32 | + add_filter('default_feed', array('EED_Feeds', 'default_feed'), 10, 1); |
|
33 | + add_filter('comment_feed_join', array('EED_Feeds', 'comment_feed_join'), 10, 2); |
|
34 | + add_filter('comment_feed_where', array('EED_Feeds', 'comment_feed_where'), 10, 2); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
39 | + * |
|
40 | + * @access public |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public static function set_hooks_admin() |
|
44 | + { |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * run - initial module setup |
|
50 | + * |
|
51 | + * @access public |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function run($WP) |
|
55 | + { |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * default_feed |
|
61 | + * |
|
62 | + * @access public |
|
63 | + * @param type rss2, atom, rss, rdf, rssjs |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public static function default_feed($type = 'rss2') |
|
67 | + { |
|
68 | + // rss2, atom, rss, rdf, rssjs |
|
69 | + $type = 'rss2'; |
|
70 | + return $type; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * parse_request |
|
76 | + * |
|
77 | + * @access public |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public static function parse_request() |
|
81 | + { |
|
82 | + $request = self::getRequest(); |
|
83 | + if ($request->requestParamIsSet('post_type')) { |
|
84 | + // define path to templates |
|
85 | + define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
86 | + // what kinda post_type are we dealing with ? |
|
87 | + switch ($request->getRequestParam('post_type')) { |
|
88 | + case 'espresso_events': |
|
89 | + // for rss2, atom, rss, rdf |
|
90 | + add_filter('the_excerpt_rss', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
91 | + add_filter('the_content_feed', array('EED_Feeds', 'the_event_feed'), 10, 1); |
|
92 | + // for json ( also uses the above filter ) |
|
93 | + add_filter('rssjs_feed_item', array('EED_Feeds', 'the_event_rssjs_feed'), 10, 1); |
|
94 | + break; |
|
95 | + case 'espresso_venues': |
|
96 | + // for rss2, atom, rss, rdf |
|
97 | + add_filter('the_excerpt_rss', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
98 | + add_filter('the_content_feed', array('EED_Feeds', 'the_venue_feed'), 10, 1); |
|
99 | + // for json ( also uses the above filter ) |
|
100 | + add_filter('rssjs_feed_item', array('EED_Feeds', 'the_venue_rssjs_feed'), 10, 1); |
|
101 | + break; |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * comment_feed_join - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
109 | + * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
110 | + * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
111 | + * espresso_attendees post_type |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param string $SQL the JOIN clause for the comment feed query |
|
115 | + * @return void |
|
116 | + */ |
|
117 | + public static function comment_feed_join($SQL) |
|
118 | + { |
|
119 | + global $wpdb; |
|
120 | + // check for wp_posts table in JOIN clause |
|
121 | + if (strpos($SQL, $wpdb->posts) !== false) { |
|
122 | + add_filter('EED_Feeds__comment_feed_where__espresso_attendees', '__return_true'); |
|
123 | + } |
|
124 | + return $SQL; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * comment_feed_where - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC |
|
130 | + * WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT |
|
131 | + * so this little snippet of SQL taps into the comment feed query and removes comments for the |
|
132 | + * espresso_attendees post_type |
|
133 | + * |
|
134 | + * @access public |
|
135 | + * @param string $SQL the WHERE clause for the comment feed query |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + public static function comment_feed_where($SQL) |
|
139 | + { |
|
140 | + global $wp_query, $wpdb; |
|
141 | + if ($wp_query->is_comment_feed && apply_filters('EED_Feeds__comment_feed_where__espresso_attendees', false)) { |
|
142 | + $SQL .= " AND $wpdb->posts.post_type != 'espresso_attendees'"; |
|
143 | + } |
|
144 | + return $SQL; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * the_event_feed |
|
150 | + * |
|
151 | + * @access public |
|
152 | + * @param string $content |
|
153 | + * @return void |
|
154 | + */ |
|
155 | + public static function the_event_feed($content) |
|
156 | + { |
|
157 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) { |
|
158 | + global $post; |
|
159 | + $template_args = array( |
|
160 | + 'EVT_ID' => $post->ID, |
|
161 | + 'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
162 | + ); |
|
163 | + $content = EEH_Template::display_template( |
|
164 | + RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php', |
|
165 | + $template_args, |
|
166 | + true |
|
167 | + ); |
|
168 | + } |
|
169 | + return $content; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * the_event_rssjs_feed |
|
175 | + * |
|
176 | + * @access public |
|
177 | + * @param object $item |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public static function the_event_rssjs_feed($item) |
|
181 | + { |
|
182 | + if (is_feed() && isset($item->description)) { |
|
183 | + $item->description = EED_Feeds::the_event_feed($item->description); |
|
184 | + } |
|
185 | + return $item; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * the_venue_feed |
|
191 | + * |
|
192 | + * @access public |
|
193 | + * @param string $content |
|
194 | + * @return void |
|
195 | + */ |
|
196 | + public static function the_venue_feed($content) |
|
197 | + { |
|
198 | + if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) { |
|
199 | + global $post; |
|
200 | + $template_args = array( |
|
201 | + 'VNU_ID' => $post->ID, |
|
202 | + 'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content, |
|
203 | + ); |
|
204 | + $content = EEH_Template::display_template( |
|
205 | + RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php', |
|
206 | + $template_args, |
|
207 | + true |
|
208 | + ); |
|
209 | + } |
|
210 | + return $content; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * the_venue_rssjs_feed |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @param object $item |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + public static function the_venue_rssjs_feed($item) |
|
222 | + { |
|
223 | + if (is_feed() && isset($item->description)) { |
|
224 | + $item->description = EED_Feeds::the_venue_feed($item->description); |
|
225 | + } |
|
226 | + return $item; |
|
227 | + } |
|
228 | 228 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function set_submit_button_text($submit_button_text = '') |
230 | 230 | { |
231 | - if (! empty($submit_button_text)) { |
|
231 | + if ( ! empty($submit_button_text)) { |
|
232 | 232 | $this->_submit_button_text = $submit_button_text; |
233 | 233 | } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
234 | 234 | if ($this->checkout->revisit) { |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | public function reg_form_name() |
389 | 389 | { |
390 | 390 | if (empty($this->_reg_form_name)) { |
391 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
391 | + $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form'); |
|
392 | 392 | } |
393 | 393 | return $this->_reg_form_name; |
394 | 394 | } |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | public function reg_step_url($action = '') |
413 | 413 | { |
414 | 414 | $query_args = ['step' => $this->slug()]; |
415 | - if (! empty($action)) { |
|
415 | + if ( ! empty($action)) { |
|
416 | 416 | $query_args['action'] = $action; |
417 | 417 | } |
418 | 418 | // final step has no display |
@@ -442,12 +442,12 @@ discard block |
||
442 | 442 | return new EE_Form_Section_Proper( |
443 | 443 | [ |
444 | 444 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
445 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
445 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
446 | 446 | 'subsections' => [ |
447 | 447 | 'next_step' => new EE_Fixed_Hidden_Input( |
448 | 448 | [ |
449 | 449 | 'html_name' => 'next_step', |
450 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
450 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
451 | 451 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
452 | 452 | ? $this->checkout->next_step->slug() |
453 | 453 | : '', |
@@ -461,12 +461,12 @@ discard block |
||
461 | 461 | return new EE_Form_Section_Proper( |
462 | 462 | [ |
463 | 463 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
464 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
464 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
465 | 465 | 'subsections' => [ |
466 | 466 | 'action' => new EE_Fixed_Hidden_Input( |
467 | 467 | [ |
468 | 468 | 'html_name' => 'action', |
469 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
469 | + 'html_id' => 'spco-'.$this->slug().'-action', |
|
470 | 470 | 'default' => apply_filters( |
471 | 471 | 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
472 | 472 | empty($this->checkout->reg_url_link) |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | 'next_step' => new EE_Fixed_Hidden_Input( |
480 | 480 | [ |
481 | 481 | 'html_name' => 'next_step', |
482 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
482 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
483 | 483 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
484 | 484 | ? $this->checkout->next_step->slug() |
485 | 485 | : '', |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | */ |
514 | 514 | public function generate_reg_form_for_actions($actions = []) |
515 | 515 | { |
516 | - $actions = array_merge( |
|
516 | + $actions = array_merge( |
|
517 | 517 | [ |
518 | 518 | 'generate_reg_form', |
519 | 519 | 'display_spco_reg_step', |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | */ |
557 | 557 | public function reg_step_submit_button() |
558 | 558 | { |
559 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
559 | + if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
560 | 560 | return ''; |
561 | 561 | } |
562 | 562 | ob_start(); |
@@ -570,18 +570,18 @@ discard block |
||
570 | 570 | // generate submit button |
571 | 571 | $submit_btn = new EE_Submit_Input( |
572 | 572 | [ |
573 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
574 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
573 | + 'html_name' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
574 | + 'html_id' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
575 | 575 | 'html_class' => 'spco-next-step-btn', |
576 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
576 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
577 | 577 | 'default' => $this->submit_button_text(), |
578 | 578 | ] |
579 | 579 | ); |
580 | 580 | $submit_btn->set_button_css_attributes(true, 'large'); |
581 | 581 | $submit_btn_html = $submit_btn->get_html_for_input(); |
582 | - $html .= EEH_HTML::div( |
|
582 | + $html .= EEH_HTML::div( |
|
583 | 583 | apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this), |
584 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
584 | + 'spco-'.$this->slug().'-whats-next-buttons-dv', |
|
585 | 585 | 'spco-whats-next-buttons' |
586 | 586 | ); |
587 | 587 | return $html; |
@@ -13,648 +13,648 @@ |
||
13 | 13 | */ |
14 | 14 | abstract class EE_SPCO_Reg_Step |
15 | 15 | { |
16 | - /** |
|
17 | - * $_completed - TRUE if this step has fully completed it's duties |
|
18 | - * |
|
19 | - * @access protected |
|
20 | - * @type bool $_completed |
|
21 | - */ |
|
22 | - protected $_completed = false; |
|
23 | - |
|
24 | - /** |
|
25 | - * $_is_current_step - TRUE if this is the current step |
|
26 | - * |
|
27 | - * @access protected |
|
28 | - * @type bool $_is_current_step |
|
29 | - */ |
|
30 | - protected $_is_current_step = false; |
|
31 | - |
|
32 | - /** |
|
33 | - * $_order - when the reg step should be run relative to other steps |
|
34 | - * |
|
35 | - * @access protected |
|
36 | - * @type int $_template |
|
37 | - */ |
|
38 | - protected $_order = 0; |
|
39 | - |
|
40 | - /** |
|
41 | - * $_slug - URL param for this step |
|
42 | - * |
|
43 | - * @access protected |
|
44 | - * @type string $_slug |
|
45 | - */ |
|
46 | - protected $_slug; |
|
47 | - |
|
48 | - /** |
|
49 | - * $_name - Step Name - translatable string |
|
50 | - * |
|
51 | - * @access protected |
|
52 | - * @type string $_slug |
|
53 | - */ |
|
54 | - protected $_name; |
|
55 | - |
|
56 | - /** |
|
57 | - * $_submit_button_text - translatable string that appears on this step's submit button |
|
58 | - * |
|
59 | - * @access protected |
|
60 | - * @type string $_slug |
|
61 | - */ |
|
62 | - protected $_submit_button_text; |
|
63 | - |
|
64 | - /** |
|
65 | - * $_template - template name |
|
66 | - * |
|
67 | - * @access protected |
|
68 | - * @type string $_template |
|
69 | - */ |
|
70 | - protected $_template; |
|
71 | - |
|
72 | - /** |
|
73 | - * $_reg_form_name - the form input name and id attribute |
|
74 | - * |
|
75 | - * @access protected |
|
76 | - * @var string $_reg_form_name |
|
77 | - */ |
|
78 | - protected $_reg_form_name; |
|
79 | - |
|
80 | - /** |
|
81 | - * $_success_message - text to display upon successful form submission |
|
82 | - * |
|
83 | - * @access private |
|
84 | - * @var string $_success_message |
|
85 | - */ |
|
86 | - protected $_success_message; |
|
87 | - |
|
88 | - /** |
|
89 | - * $_instructions - a brief description of how to complete the reg step. |
|
90 | - * Usually displayed in conjunction with the previous step's success message. |
|
91 | - * |
|
92 | - * @access private |
|
93 | - * @var string $_instructions |
|
94 | - */ |
|
95 | - protected $_instructions; |
|
96 | - |
|
97 | - /** |
|
98 | - * $_valid_data - the normalized and validated data for this step |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @var array $_valid_data |
|
102 | - */ |
|
103 | - protected $_valid_data = []; |
|
104 | - |
|
105 | - /** |
|
106 | - * $reg_form - the registration form for this step |
|
107 | - * |
|
108 | - * @access public |
|
109 | - * @var EE_Form_Section_Proper $reg_form |
|
110 | - */ |
|
111 | - public $reg_form; |
|
112 | - |
|
113 | - /** |
|
114 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
115 | - * |
|
116 | - * @access public |
|
117 | - * @var EE_Checkout $checkout |
|
118 | - */ |
|
119 | - public $checkout; |
|
120 | - |
|
121 | - /** |
|
122 | - * @var RequestInterface $request |
|
123 | - */ |
|
124 | - protected $request; |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - abstract public function translate_js_strings(); |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - abstract public function enqueue_styles_and_scripts(); |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return boolean |
|
141 | - */ |
|
142 | - abstract public function initialize_reg_step(); |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - abstract public function generate_reg_form(); |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return boolean |
|
153 | - */ |
|
154 | - abstract public function process_reg_step(); |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return boolean |
|
159 | - */ |
|
160 | - abstract public function update_reg_step(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @return boolean |
|
165 | - */ |
|
166 | - public function completed() |
|
167 | - { |
|
168 | - return $this->_completed; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * set_completed - toggles $_completed to TRUE |
|
174 | - */ |
|
175 | - public function set_completed() |
|
176 | - { |
|
177 | - // DEBUG LOG |
|
178 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
179 | - $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * set_completed - toggles $_completed to FALSE |
|
185 | - */ |
|
186 | - public function set_not_completed() |
|
187 | - { |
|
188 | - $this->_completed = false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - public function name() |
|
196 | - { |
|
197 | - return $this->_name; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function slug() |
|
205 | - { |
|
206 | - return $this->_slug; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * submit_button_text |
|
212 | - * the text that appears on the reg step form submit button |
|
213 | - * |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public function submit_button_text() |
|
217 | - { |
|
218 | - return $this->_submit_button_text; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * set_submit_button_text |
|
224 | - * sets the text that appears on the reg step form submit button |
|
225 | - * |
|
226 | - * @param string $submit_button_text |
|
227 | - */ |
|
228 | - public function set_submit_button_text($submit_button_text = '') |
|
229 | - { |
|
230 | - if (! empty($submit_button_text)) { |
|
231 | - $this->_submit_button_text = $submit_button_text; |
|
232 | - } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
233 | - if ($this->checkout->revisit) { |
|
234 | - $this->_submit_button_text = sprintf( |
|
235 | - esc_html__('Update %s', 'event_espresso'), |
|
236 | - $this->checkout->current_step->name() |
|
237 | - ); |
|
238 | - } else { |
|
239 | - $this->_submit_button_text = sprintf( |
|
240 | - esc_html__('Proceed to %s', 'event_espresso'), |
|
241 | - $this->checkout->next_step->name() |
|
242 | - ); |
|
243 | - } |
|
244 | - } |
|
245 | - // filters the submit button text |
|
246 | - $this->_submit_button_text = apply_filters( |
|
247 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
248 | - $this->_submit_button_text, |
|
249 | - $this->checkout |
|
250 | - ); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param boolean $is_current_step |
|
256 | - */ |
|
257 | - public function set_is_current_step($is_current_step) |
|
258 | - { |
|
259 | - $this->_is_current_step = $is_current_step; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @return boolean |
|
265 | - */ |
|
266 | - public function is_current_step() |
|
267 | - { |
|
268 | - return $this->_is_current_step; |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @return boolean |
|
274 | - */ |
|
275 | - public function is_final_step() |
|
276 | - { |
|
277 | - return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @param int $order |
|
283 | - */ |
|
284 | - public function set_order($order) |
|
285 | - { |
|
286 | - $this->_order = $order; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @return int |
|
292 | - */ |
|
293 | - public function order() |
|
294 | - { |
|
295 | - return $this->_order; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function template() |
|
303 | - { |
|
304 | - return $this->_template; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @return string |
|
310 | - */ |
|
311 | - public function success_message() |
|
312 | - { |
|
313 | - return $this->_success_message; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * _set_success_message |
|
319 | - * |
|
320 | - * @param string $success_message |
|
321 | - */ |
|
322 | - protected function _set_success_message($success_message) |
|
323 | - { |
|
324 | - $this->_success_message = $success_message; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * _reset_success_message |
|
330 | - * |
|
331 | - * @return void |
|
332 | - */ |
|
333 | - protected function _reset_success_message() |
|
334 | - { |
|
335 | - $this->_success_message = ''; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function _instructions() |
|
343 | - { |
|
344 | - return $this->_instructions; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @param string $instructions |
|
350 | - */ |
|
351 | - public function set_instructions($instructions) |
|
352 | - { |
|
353 | - $this->_instructions = apply_filters( |
|
354 | - 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
355 | - $instructions, |
|
356 | - $this |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * @param array $valid_data |
|
363 | - */ |
|
364 | - public function set_valid_data($valid_data) |
|
365 | - { |
|
366 | - $this->_valid_data = $valid_data; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @return array |
|
372 | - * @throws EE_Error |
|
373 | - * @throws EE_Error |
|
374 | - */ |
|
375 | - public function valid_data() |
|
376 | - { |
|
377 | - if (empty($this->_valid_data)) { |
|
378 | - $this->_valid_data = $this->reg_form->valid_data(); |
|
379 | - } |
|
380 | - return $this->_valid_data; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @return string |
|
386 | - */ |
|
387 | - public function reg_form_name() |
|
388 | - { |
|
389 | - if (empty($this->_reg_form_name)) { |
|
390 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
391 | - } |
|
392 | - return $this->_reg_form_name; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @param string $reg_form_name |
|
398 | - */ |
|
399 | - protected function set_reg_form_name($reg_form_name) |
|
400 | - { |
|
401 | - $this->_reg_form_name = $reg_form_name; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * reg_step_url |
|
407 | - * |
|
408 | - * @param string $action |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public function reg_step_url($action = '') |
|
412 | - { |
|
413 | - $query_args = ['step' => $this->slug()]; |
|
414 | - if (! empty($action)) { |
|
415 | - $query_args['action'] = $action; |
|
416 | - } |
|
417 | - // final step has no display |
|
418 | - if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
419 | - $query_args['action'] = 'process_reg_step'; |
|
420 | - } |
|
421 | - if ($this->checkout->revisit) { |
|
422 | - $query_args['revisit'] = true; |
|
423 | - } |
|
424 | - if ($this->checkout->reg_url_link) { |
|
425 | - $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
426 | - } |
|
427 | - return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * creates the default hidden inputs section |
|
433 | - * |
|
434 | - * @return EE_Form_Section_Proper |
|
435 | - * @throws EE_Error |
|
436 | - */ |
|
437 | - public function reg_step_hidden_inputs() |
|
438 | - { |
|
439 | - // hidden inputs for admin registrations |
|
440 | - if ($this->checkout->admin_request) { |
|
441 | - return new EE_Form_Section_Proper( |
|
442 | - [ |
|
443 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
444 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
445 | - 'subsections' => [ |
|
446 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
447 | - [ |
|
448 | - 'html_name' => 'next_step', |
|
449 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
450 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
451 | - ? $this->checkout->next_step->slug() |
|
452 | - : '', |
|
453 | - ] |
|
454 | - ), |
|
455 | - ], |
|
456 | - ] |
|
457 | - ); |
|
458 | - } |
|
459 | - // hidden inputs for frontend registrations |
|
460 | - return new EE_Form_Section_Proper( |
|
461 | - [ |
|
462 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
463 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
464 | - 'subsections' => [ |
|
465 | - 'action' => new EE_Fixed_Hidden_Input( |
|
466 | - [ |
|
467 | - 'html_name' => 'action', |
|
468 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
469 | - 'default' => apply_filters( |
|
470 | - 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
471 | - empty($this->checkout->reg_url_link) |
|
472 | - ? 'process_reg_step' |
|
473 | - : 'update_reg_step', |
|
474 | - $this |
|
475 | - ), |
|
476 | - ] |
|
477 | - ), |
|
478 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
479 | - [ |
|
480 | - 'html_name' => 'next_step', |
|
481 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
482 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
483 | - ? $this->checkout->next_step->slug() |
|
484 | - : '', |
|
485 | - ] |
|
486 | - ), |
|
487 | - 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
488 | - [ |
|
489 | - 'html_name' => 'e_reg_url_link', |
|
490 | - 'html_id' => 'spco-reg_url_link', |
|
491 | - 'default' => $this->checkout->reg_url_link, |
|
492 | - ] |
|
493 | - ), |
|
494 | - 'revisit' => new EE_Fixed_Hidden_Input( |
|
495 | - [ |
|
496 | - 'html_name' => 'revisit', |
|
497 | - 'html_id' => 'spco-revisit', |
|
498 | - 'default' => $this->checkout->revisit, |
|
499 | - ] |
|
500 | - ), |
|
501 | - ], |
|
502 | - ] |
|
503 | - ); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * generate_reg_form_for_actions |
|
509 | - * |
|
510 | - * @param array $actions |
|
511 | - * @return void |
|
512 | - */ |
|
513 | - public function generate_reg_form_for_actions($actions = []) |
|
514 | - { |
|
515 | - $actions = array_merge( |
|
516 | - [ |
|
517 | - 'generate_reg_form', |
|
518 | - 'display_spco_reg_step', |
|
519 | - 'process_reg_step', |
|
520 | - 'update_reg_step', |
|
521 | - ], |
|
522 | - $actions |
|
523 | - ); |
|
524 | - $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true); |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * @return string |
|
530 | - * @throws EE_Error |
|
531 | - */ |
|
532 | - public function display_reg_form() |
|
533 | - { |
|
534 | - $html = ''; |
|
535 | - if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
536 | - do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
537 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
538 | - if ($this->request->isAjax()) { |
|
539 | - $this->reg_form->localize_validation_rules(); |
|
540 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
541 | - } |
|
542 | - $html .= $this->reg_form->get_html(); |
|
543 | - $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
544 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
545 | - } |
|
546 | - return $html; |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
552 | - * |
|
553 | - * @return string |
|
554 | - * @throws EE_Error |
|
555 | - */ |
|
556 | - public function reg_step_submit_button() |
|
557 | - { |
|
558 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
559 | - return ''; |
|
560 | - } |
|
561 | - ob_start(); |
|
562 | - do_action( |
|
563 | - 'AHEE__before_spco_whats_next_buttons', |
|
564 | - $this->slug(), |
|
565 | - $this->checkout->next_step->slug(), |
|
566 | - $this->checkout |
|
567 | - ); |
|
568 | - $html = ob_get_clean(); |
|
569 | - // generate submit button |
|
570 | - $submit_btn = new EE_Submit_Input( |
|
571 | - [ |
|
572 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
573 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
574 | - 'html_class' => 'spco-next-step-btn', |
|
575 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
576 | - 'default' => $this->submit_button_text(), |
|
577 | - ] |
|
578 | - ); |
|
579 | - $submit_btn->set_button_css_attributes(true, 'large'); |
|
580 | - $submit_btn_html = $submit_btn->get_html_for_input(); |
|
581 | - $html .= EEH_HTML::div( |
|
582 | - apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this), |
|
583 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
584 | - 'spco-whats-next-buttons' |
|
585 | - ); |
|
586 | - return $html; |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
592 | - * |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - public function div_class() |
|
596 | - { |
|
597 | - return $this->is_current_step() ? '' : ' hidden'; |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
603 | - * |
|
604 | - * @return string |
|
605 | - */ |
|
606 | - public function edit_lnk_url() |
|
607 | - { |
|
608 | - return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
614 | - * |
|
615 | - * @return string |
|
616 | - */ |
|
617 | - public function edit_link_class() |
|
618 | - { |
|
619 | - return $this->is_current_step() ? ' hidden' : ''; |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - /** |
|
624 | - * update_checkout with changes that have been made to the cart |
|
625 | - * |
|
626 | - * @return void |
|
627 | - * @throws EE_Error |
|
628 | - * @throws ReflectionException |
|
629 | - */ |
|
630 | - public function update_checkout() |
|
631 | - { |
|
632 | - // grab the cart grand total and reset TXN total |
|
633 | - $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
634 | - $this->checkout->stash_transaction_and_checkout(); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * __sleep |
|
640 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
641 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
642 | - * reg form, because if needed, it will be regenerated anyways |
|
643 | - * |
|
644 | - * @return array |
|
645 | - */ |
|
646 | - public function __sleep() |
|
647 | - { |
|
648 | - // remove the reg form and the checkout |
|
649 | - return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * @param RequestInterface $request |
|
655 | - */ |
|
656 | - public function setRequest(RequestInterface $request) |
|
657 | - { |
|
658 | - $this->request = $request; |
|
659 | - } |
|
16 | + /** |
|
17 | + * $_completed - TRUE if this step has fully completed it's duties |
|
18 | + * |
|
19 | + * @access protected |
|
20 | + * @type bool $_completed |
|
21 | + */ |
|
22 | + protected $_completed = false; |
|
23 | + |
|
24 | + /** |
|
25 | + * $_is_current_step - TRUE if this is the current step |
|
26 | + * |
|
27 | + * @access protected |
|
28 | + * @type bool $_is_current_step |
|
29 | + */ |
|
30 | + protected $_is_current_step = false; |
|
31 | + |
|
32 | + /** |
|
33 | + * $_order - when the reg step should be run relative to other steps |
|
34 | + * |
|
35 | + * @access protected |
|
36 | + * @type int $_template |
|
37 | + */ |
|
38 | + protected $_order = 0; |
|
39 | + |
|
40 | + /** |
|
41 | + * $_slug - URL param for this step |
|
42 | + * |
|
43 | + * @access protected |
|
44 | + * @type string $_slug |
|
45 | + */ |
|
46 | + protected $_slug; |
|
47 | + |
|
48 | + /** |
|
49 | + * $_name - Step Name - translatable string |
|
50 | + * |
|
51 | + * @access protected |
|
52 | + * @type string $_slug |
|
53 | + */ |
|
54 | + protected $_name; |
|
55 | + |
|
56 | + /** |
|
57 | + * $_submit_button_text - translatable string that appears on this step's submit button |
|
58 | + * |
|
59 | + * @access protected |
|
60 | + * @type string $_slug |
|
61 | + */ |
|
62 | + protected $_submit_button_text; |
|
63 | + |
|
64 | + /** |
|
65 | + * $_template - template name |
|
66 | + * |
|
67 | + * @access protected |
|
68 | + * @type string $_template |
|
69 | + */ |
|
70 | + protected $_template; |
|
71 | + |
|
72 | + /** |
|
73 | + * $_reg_form_name - the form input name and id attribute |
|
74 | + * |
|
75 | + * @access protected |
|
76 | + * @var string $_reg_form_name |
|
77 | + */ |
|
78 | + protected $_reg_form_name; |
|
79 | + |
|
80 | + /** |
|
81 | + * $_success_message - text to display upon successful form submission |
|
82 | + * |
|
83 | + * @access private |
|
84 | + * @var string $_success_message |
|
85 | + */ |
|
86 | + protected $_success_message; |
|
87 | + |
|
88 | + /** |
|
89 | + * $_instructions - a brief description of how to complete the reg step. |
|
90 | + * Usually displayed in conjunction with the previous step's success message. |
|
91 | + * |
|
92 | + * @access private |
|
93 | + * @var string $_instructions |
|
94 | + */ |
|
95 | + protected $_instructions; |
|
96 | + |
|
97 | + /** |
|
98 | + * $_valid_data - the normalized and validated data for this step |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @var array $_valid_data |
|
102 | + */ |
|
103 | + protected $_valid_data = []; |
|
104 | + |
|
105 | + /** |
|
106 | + * $reg_form - the registration form for this step |
|
107 | + * |
|
108 | + * @access public |
|
109 | + * @var EE_Form_Section_Proper $reg_form |
|
110 | + */ |
|
111 | + public $reg_form; |
|
112 | + |
|
113 | + /** |
|
114 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
115 | + * |
|
116 | + * @access public |
|
117 | + * @var EE_Checkout $checkout |
|
118 | + */ |
|
119 | + public $checkout; |
|
120 | + |
|
121 | + /** |
|
122 | + * @var RequestInterface $request |
|
123 | + */ |
|
124 | + protected $request; |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + abstract public function translate_js_strings(); |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + abstract public function enqueue_styles_and_scripts(); |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return boolean |
|
141 | + */ |
|
142 | + abstract public function initialize_reg_step(); |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + abstract public function generate_reg_form(); |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return boolean |
|
153 | + */ |
|
154 | + abstract public function process_reg_step(); |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return boolean |
|
159 | + */ |
|
160 | + abstract public function update_reg_step(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @return boolean |
|
165 | + */ |
|
166 | + public function completed() |
|
167 | + { |
|
168 | + return $this->_completed; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * set_completed - toggles $_completed to TRUE |
|
174 | + */ |
|
175 | + public function set_completed() |
|
176 | + { |
|
177 | + // DEBUG LOG |
|
178 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
179 | + $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * set_completed - toggles $_completed to FALSE |
|
185 | + */ |
|
186 | + public function set_not_completed() |
|
187 | + { |
|
188 | + $this->_completed = false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + public function name() |
|
196 | + { |
|
197 | + return $this->_name; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function slug() |
|
205 | + { |
|
206 | + return $this->_slug; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * submit_button_text |
|
212 | + * the text that appears on the reg step form submit button |
|
213 | + * |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public function submit_button_text() |
|
217 | + { |
|
218 | + return $this->_submit_button_text; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * set_submit_button_text |
|
224 | + * sets the text that appears on the reg step form submit button |
|
225 | + * |
|
226 | + * @param string $submit_button_text |
|
227 | + */ |
|
228 | + public function set_submit_button_text($submit_button_text = '') |
|
229 | + { |
|
230 | + if (! empty($submit_button_text)) { |
|
231 | + $this->_submit_button_text = $submit_button_text; |
|
232 | + } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
233 | + if ($this->checkout->revisit) { |
|
234 | + $this->_submit_button_text = sprintf( |
|
235 | + esc_html__('Update %s', 'event_espresso'), |
|
236 | + $this->checkout->current_step->name() |
|
237 | + ); |
|
238 | + } else { |
|
239 | + $this->_submit_button_text = sprintf( |
|
240 | + esc_html__('Proceed to %s', 'event_espresso'), |
|
241 | + $this->checkout->next_step->name() |
|
242 | + ); |
|
243 | + } |
|
244 | + } |
|
245 | + // filters the submit button text |
|
246 | + $this->_submit_button_text = apply_filters( |
|
247 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
248 | + $this->_submit_button_text, |
|
249 | + $this->checkout |
|
250 | + ); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param boolean $is_current_step |
|
256 | + */ |
|
257 | + public function set_is_current_step($is_current_step) |
|
258 | + { |
|
259 | + $this->_is_current_step = $is_current_step; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @return boolean |
|
265 | + */ |
|
266 | + public function is_current_step() |
|
267 | + { |
|
268 | + return $this->_is_current_step; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @return boolean |
|
274 | + */ |
|
275 | + public function is_final_step() |
|
276 | + { |
|
277 | + return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @param int $order |
|
283 | + */ |
|
284 | + public function set_order($order) |
|
285 | + { |
|
286 | + $this->_order = $order; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @return int |
|
292 | + */ |
|
293 | + public function order() |
|
294 | + { |
|
295 | + return $this->_order; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function template() |
|
303 | + { |
|
304 | + return $this->_template; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @return string |
|
310 | + */ |
|
311 | + public function success_message() |
|
312 | + { |
|
313 | + return $this->_success_message; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * _set_success_message |
|
319 | + * |
|
320 | + * @param string $success_message |
|
321 | + */ |
|
322 | + protected function _set_success_message($success_message) |
|
323 | + { |
|
324 | + $this->_success_message = $success_message; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * _reset_success_message |
|
330 | + * |
|
331 | + * @return void |
|
332 | + */ |
|
333 | + protected function _reset_success_message() |
|
334 | + { |
|
335 | + $this->_success_message = ''; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function _instructions() |
|
343 | + { |
|
344 | + return $this->_instructions; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @param string $instructions |
|
350 | + */ |
|
351 | + public function set_instructions($instructions) |
|
352 | + { |
|
353 | + $this->_instructions = apply_filters( |
|
354 | + 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
355 | + $instructions, |
|
356 | + $this |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * @param array $valid_data |
|
363 | + */ |
|
364 | + public function set_valid_data($valid_data) |
|
365 | + { |
|
366 | + $this->_valid_data = $valid_data; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @return array |
|
372 | + * @throws EE_Error |
|
373 | + * @throws EE_Error |
|
374 | + */ |
|
375 | + public function valid_data() |
|
376 | + { |
|
377 | + if (empty($this->_valid_data)) { |
|
378 | + $this->_valid_data = $this->reg_form->valid_data(); |
|
379 | + } |
|
380 | + return $this->_valid_data; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @return string |
|
386 | + */ |
|
387 | + public function reg_form_name() |
|
388 | + { |
|
389 | + if (empty($this->_reg_form_name)) { |
|
390 | + $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
391 | + } |
|
392 | + return $this->_reg_form_name; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @param string $reg_form_name |
|
398 | + */ |
|
399 | + protected function set_reg_form_name($reg_form_name) |
|
400 | + { |
|
401 | + $this->_reg_form_name = $reg_form_name; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * reg_step_url |
|
407 | + * |
|
408 | + * @param string $action |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public function reg_step_url($action = '') |
|
412 | + { |
|
413 | + $query_args = ['step' => $this->slug()]; |
|
414 | + if (! empty($action)) { |
|
415 | + $query_args['action'] = $action; |
|
416 | + } |
|
417 | + // final step has no display |
|
418 | + if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
419 | + $query_args['action'] = 'process_reg_step'; |
|
420 | + } |
|
421 | + if ($this->checkout->revisit) { |
|
422 | + $query_args['revisit'] = true; |
|
423 | + } |
|
424 | + if ($this->checkout->reg_url_link) { |
|
425 | + $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
426 | + } |
|
427 | + return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * creates the default hidden inputs section |
|
433 | + * |
|
434 | + * @return EE_Form_Section_Proper |
|
435 | + * @throws EE_Error |
|
436 | + */ |
|
437 | + public function reg_step_hidden_inputs() |
|
438 | + { |
|
439 | + // hidden inputs for admin registrations |
|
440 | + if ($this->checkout->admin_request) { |
|
441 | + return new EE_Form_Section_Proper( |
|
442 | + [ |
|
443 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
444 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
445 | + 'subsections' => [ |
|
446 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
447 | + [ |
|
448 | + 'html_name' => 'next_step', |
|
449 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
450 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
451 | + ? $this->checkout->next_step->slug() |
|
452 | + : '', |
|
453 | + ] |
|
454 | + ), |
|
455 | + ], |
|
456 | + ] |
|
457 | + ); |
|
458 | + } |
|
459 | + // hidden inputs for frontend registrations |
|
460 | + return new EE_Form_Section_Proper( |
|
461 | + [ |
|
462 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
463 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
464 | + 'subsections' => [ |
|
465 | + 'action' => new EE_Fixed_Hidden_Input( |
|
466 | + [ |
|
467 | + 'html_name' => 'action', |
|
468 | + 'html_id' => 'spco-' . $this->slug() . '-action', |
|
469 | + 'default' => apply_filters( |
|
470 | + 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
471 | + empty($this->checkout->reg_url_link) |
|
472 | + ? 'process_reg_step' |
|
473 | + : 'update_reg_step', |
|
474 | + $this |
|
475 | + ), |
|
476 | + ] |
|
477 | + ), |
|
478 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
479 | + [ |
|
480 | + 'html_name' => 'next_step', |
|
481 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
482 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
483 | + ? $this->checkout->next_step->slug() |
|
484 | + : '', |
|
485 | + ] |
|
486 | + ), |
|
487 | + 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
488 | + [ |
|
489 | + 'html_name' => 'e_reg_url_link', |
|
490 | + 'html_id' => 'spco-reg_url_link', |
|
491 | + 'default' => $this->checkout->reg_url_link, |
|
492 | + ] |
|
493 | + ), |
|
494 | + 'revisit' => new EE_Fixed_Hidden_Input( |
|
495 | + [ |
|
496 | + 'html_name' => 'revisit', |
|
497 | + 'html_id' => 'spco-revisit', |
|
498 | + 'default' => $this->checkout->revisit, |
|
499 | + ] |
|
500 | + ), |
|
501 | + ], |
|
502 | + ] |
|
503 | + ); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * generate_reg_form_for_actions |
|
509 | + * |
|
510 | + * @param array $actions |
|
511 | + * @return void |
|
512 | + */ |
|
513 | + public function generate_reg_form_for_actions($actions = []) |
|
514 | + { |
|
515 | + $actions = array_merge( |
|
516 | + [ |
|
517 | + 'generate_reg_form', |
|
518 | + 'display_spco_reg_step', |
|
519 | + 'process_reg_step', |
|
520 | + 'update_reg_step', |
|
521 | + ], |
|
522 | + $actions |
|
523 | + ); |
|
524 | + $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true); |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * @return string |
|
530 | + * @throws EE_Error |
|
531 | + */ |
|
532 | + public function display_reg_form() |
|
533 | + { |
|
534 | + $html = ''; |
|
535 | + if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
536 | + do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
537 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
538 | + if ($this->request->isAjax()) { |
|
539 | + $this->reg_form->localize_validation_rules(); |
|
540 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
541 | + } |
|
542 | + $html .= $this->reg_form->get_html(); |
|
543 | + $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
544 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
545 | + } |
|
546 | + return $html; |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
552 | + * |
|
553 | + * @return string |
|
554 | + * @throws EE_Error |
|
555 | + */ |
|
556 | + public function reg_step_submit_button() |
|
557 | + { |
|
558 | + if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
559 | + return ''; |
|
560 | + } |
|
561 | + ob_start(); |
|
562 | + do_action( |
|
563 | + 'AHEE__before_spco_whats_next_buttons', |
|
564 | + $this->slug(), |
|
565 | + $this->checkout->next_step->slug(), |
|
566 | + $this->checkout |
|
567 | + ); |
|
568 | + $html = ob_get_clean(); |
|
569 | + // generate submit button |
|
570 | + $submit_btn = new EE_Submit_Input( |
|
571 | + [ |
|
572 | + 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
573 | + 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
574 | + 'html_class' => 'spco-next-step-btn', |
|
575 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
576 | + 'default' => $this->submit_button_text(), |
|
577 | + ] |
|
578 | + ); |
|
579 | + $submit_btn->set_button_css_attributes(true, 'large'); |
|
580 | + $submit_btn_html = $submit_btn->get_html_for_input(); |
|
581 | + $html .= EEH_HTML::div( |
|
582 | + apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this), |
|
583 | + 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
584 | + 'spco-whats-next-buttons' |
|
585 | + ); |
|
586 | + return $html; |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
592 | + * |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + public function div_class() |
|
596 | + { |
|
597 | + return $this->is_current_step() ? '' : ' hidden'; |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
603 | + * |
|
604 | + * @return string |
|
605 | + */ |
|
606 | + public function edit_lnk_url() |
|
607 | + { |
|
608 | + return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
614 | + * |
|
615 | + * @return string |
|
616 | + */ |
|
617 | + public function edit_link_class() |
|
618 | + { |
|
619 | + return $this->is_current_step() ? ' hidden' : ''; |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + /** |
|
624 | + * update_checkout with changes that have been made to the cart |
|
625 | + * |
|
626 | + * @return void |
|
627 | + * @throws EE_Error |
|
628 | + * @throws ReflectionException |
|
629 | + */ |
|
630 | + public function update_checkout() |
|
631 | + { |
|
632 | + // grab the cart grand total and reset TXN total |
|
633 | + $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
634 | + $this->checkout->stash_transaction_and_checkout(); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * __sleep |
|
640 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
641 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
642 | + * reg form, because if needed, it will be regenerated anyways |
|
643 | + * |
|
644 | + * @return array |
|
645 | + */ |
|
646 | + public function __sleep() |
|
647 | + { |
|
648 | + // remove the reg form and the checkout |
|
649 | + return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * @param RequestInterface $request |
|
655 | + */ |
|
656 | + public function setRequest(RequestInterface $request) |
|
657 | + { |
|
658 | + $this->request = $request; |
|
659 | + } |
|
660 | 660 | } |