Completed
Pull Request — master (#378)
by Darren
19:13
created
core/libraries/form_sections/form_handlers/SequentialStepFormManager.php 2 patches
Indentation   +583 added lines, -583 removed lines patch added patch discarded remove patch
@@ -29,587 +29,587 @@
 block discarded – undo
29 29
 abstract class SequentialStepFormManager
30 30
 {
31 31
 
32
-    /**
33
-     * a simplified URL with no form related parameters
34
-     * that will be used to build the form's redirect URLs
35
-     *
36
-     * @var string $base_url
37
-     */
38
-    private $base_url = '';
39
-
40
-    /**
41
-     * the key used for the URL param that denotes the current form step
42
-     * defaults to 'ee-form-step'
43
-     *
44
-     * @var string $form_step_url_key
45
-     */
46
-    private $form_step_url_key = '';
47
-
48
-    /**
49
-     * @var string $default_form_step
50
-     */
51
-    private $default_form_step = '';
52
-
53
-    /**
54
-     * @var string $form_action
55
-     */
56
-    private $form_action;
57
-
58
-    /**
59
-     * value of one of the string constant above
60
-     *
61
-     * @var string $form_config
62
-     */
63
-    private $form_config;
64
-
65
-    /**
66
-     * @var string $progress_step_style
67
-     */
68
-    private $progress_step_style = '';
69
-
70
-    /**
71
-     * @var EE_Request $request
72
-     */
73
-    private $request;
74
-
75
-    /**
76
-     * @var Collection $form_steps
77
-     */
78
-    protected $form_steps;
79
-
80
-    /**
81
-     * @var ProgressStepManager $progress_step_manager
82
-     */
83
-    protected $progress_step_manager;
84
-
85
-
86
-    /**
87
-     * @return Collection|null
88
-     */
89
-    abstract protected function getFormStepsCollection();
90
-
91
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
92
-    /**
93
-     * StepsManager constructor
94
-     *
95
-     * @param string     $base_url
96
-     * @param string     $default_form_step
97
-     * @param string     $form_action
98
-     * @param string     $form_config
99
-     * @param EE_Request $request
100
-     * @param string     $progress_step_style
101
-     * @throws InvalidDataTypeException
102
-     * @throws InvalidArgumentException
103
-     */
104
-    public function __construct(
105
-        $base_url,
106
-        $default_form_step,
107
-        $form_action = '',
108
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
109
-        $progress_step_style = 'number_bubbles',
110
-        EE_Request $request
111
-    ) {
112
-        $this->setBaseUrl($base_url);
113
-        $this->setDefaultFormStep($default_form_step);
114
-        $this->setFormAction($form_action);
115
-        $this->setFormConfig($form_config);
116
-        $this->setProgressStepStyle($progress_step_style);
117
-        $this->request = $request;
118
-    }
119
-
120
-
121
-    /**
122
-     * @return string
123
-     * @throws InvalidFormHandlerException
124
-     */
125
-    public function baseUrl()
126
-    {
127
-        if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
128
-            add_query_arg(
129
-                array($this->form_step_url_key => $this->getCurrentStep()->slug()),
130
-                $this->base_url
131
-            );
132
-        }
133
-        return $this->base_url;
134
-    }
135
-
136
-
137
-    /**
138
-     * @param string $base_url
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidArgumentException
141
-     */
142
-    protected function setBaseUrl($base_url)
143
-    {
144
-        if (! is_string($base_url)) {
145
-            throw new InvalidDataTypeException('$base_url', $base_url, 'string');
146
-        }
147
-        if (empty($base_url)) {
148
-            throw new InvalidArgumentException(
149
-                esc_html__('The base URL can not be an empty string.', 'event_espresso')
150
-            );
151
-        }
152
-        $this->base_url = $base_url;
153
-    }
154
-
155
-
156
-    /**
157
-     * @return string
158
-     * @throws InvalidDataTypeException
159
-     */
160
-    public function formStepUrlKey()
161
-    {
162
-        if (empty($this->form_step_url_key)) {
163
-            $this->setFormStepUrlKey();
164
-        }
165
-        return $this->form_step_url_key;
166
-    }
167
-
168
-
169
-    /**
170
-     * @param string $form_step_url_key
171
-     * @throws InvalidDataTypeException
172
-     */
173
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
174
-    {
175
-        if (! is_string($form_step_url_key)) {
176
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
177
-        }
178
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
179
-    }
180
-
181
-
182
-    /**
183
-     * @return string
184
-     */
185
-    public function defaultFormStep()
186
-    {
187
-        return $this->default_form_step;
188
-    }
189
-
190
-
191
-    /**
192
-     * @param $default_form_step
193
-     * @throws InvalidDataTypeException
194
-     */
195
-    protected function setDefaultFormStep($default_form_step)
196
-    {
197
-        if (! is_string($default_form_step)) {
198
-            throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
199
-        }
200
-        $this->default_form_step = $default_form_step;
201
-    }
202
-
203
-
204
-    /**
205
-     * @return void
206
-     * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
207
-     * @throws InvalidDataTypeException
208
-     */
209
-    protected function setCurrentStepFromRequest()
210
-    {
211
-        $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
212
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
213
-            throw new InvalidIdentifierException(
214
-                $current_step_slug,
215
-                $this->defaultFormStep(),
216
-                $message = sprintf(
217
-                    esc_html__(
218
-                        'The "%1$s" form step could not be set.',
219
-                        'event_espresso'
220
-                    ),
221
-                    $current_step_slug
222
-                )
223
-            );
224
-        }
225
-    }
226
-
227
-
228
-    /**
229
-     * @return object|SequentialStepFormInterface
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 EE_Request
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 $progress_steps;
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 $this->getCurrentStep()->display();
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, so...
558
-            // if WP_DEBUG === true, display the Exception and stack trace right now
559
-            new ExceptionStackTraceDisplay($e);
560
-            // else convert the Exception to an EE_Error
561
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
562
-            // prevent redirect to next step or other if exception was thrown
563
-            if ($current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
564
-                || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
565
-            ) {
566
-                $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
567
-            }
568
-        }
569
-        // save notices to a transient so that when we redirect back
570
-        // to the display portion for this step
571
-        // those notices can be displayed
572
-        EE_Error::get_notices(false, true);
573
-        $this->redirectForm($current_step);
574
-    }
575
-
576
-
577
-    /**
578
-     * handles where to go to next
579
-     *
580
-     * @param SequentialStepFormInterface $current_step
581
-     * @throws InvalidArgumentException
582
-     * @throws InvalidDataTypeException
583
-     * @throws InvalidFormHandlerException
584
-     */
585
-    public function redirectForm(SequentialStepFormInterface $current_step)
586
-    {
587
-        $redirect_step = $current_step;
588
-        switch ($current_step->redirectTo()) {
589
-            case SequentialStepForm::REDIRECT_TO_OTHER:
590
-                // going somewhere else, so just check out now
591
-                wp_safe_redirect($redirect_step->redirectUrl());
592
-                exit();
593
-                break;
594
-            case SequentialStepForm::REDIRECT_TO_PREV_STEP:
595
-                $redirect_step = $this->form_steps->previous();
596
-                break;
597
-            case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
598
-                $this->form_steps->next();
599
-                if ($this->form_steps->valid()) {
600
-                    $redirect_step = $this->form_steps->current();
601
-                }
602
-                break;
603
-            case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
604
-            default:
605
-                // $redirect_step is already set
606
-        }
607
-        $current_step->setRedirectUrl($this->baseUrl());
608
-        $current_step->addRedirectArgs(
609
-            // use the slug for whatever step we are redirecting too
610
-            array($this->formStepUrlKey() => $redirect_step->slug())
611
-        );
612
-        wp_safe_redirect($current_step->redirectUrl());
613
-        exit();
614
-    }
32
+	/**
33
+	 * a simplified URL with no form related parameters
34
+	 * that will be used to build the form's redirect URLs
35
+	 *
36
+	 * @var string $base_url
37
+	 */
38
+	private $base_url = '';
39
+
40
+	/**
41
+	 * the key used for the URL param that denotes the current form step
42
+	 * defaults to 'ee-form-step'
43
+	 *
44
+	 * @var string $form_step_url_key
45
+	 */
46
+	private $form_step_url_key = '';
47
+
48
+	/**
49
+	 * @var string $default_form_step
50
+	 */
51
+	private $default_form_step = '';
52
+
53
+	/**
54
+	 * @var string $form_action
55
+	 */
56
+	private $form_action;
57
+
58
+	/**
59
+	 * value of one of the string constant above
60
+	 *
61
+	 * @var string $form_config
62
+	 */
63
+	private $form_config;
64
+
65
+	/**
66
+	 * @var string $progress_step_style
67
+	 */
68
+	private $progress_step_style = '';
69
+
70
+	/**
71
+	 * @var EE_Request $request
72
+	 */
73
+	private $request;
74
+
75
+	/**
76
+	 * @var Collection $form_steps
77
+	 */
78
+	protected $form_steps;
79
+
80
+	/**
81
+	 * @var ProgressStepManager $progress_step_manager
82
+	 */
83
+	protected $progress_step_manager;
84
+
85
+
86
+	/**
87
+	 * @return Collection|null
88
+	 */
89
+	abstract protected function getFormStepsCollection();
90
+
91
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
92
+	/**
93
+	 * StepsManager constructor
94
+	 *
95
+	 * @param string     $base_url
96
+	 * @param string     $default_form_step
97
+	 * @param string     $form_action
98
+	 * @param string     $form_config
99
+	 * @param EE_Request $request
100
+	 * @param string     $progress_step_style
101
+	 * @throws InvalidDataTypeException
102
+	 * @throws InvalidArgumentException
103
+	 */
104
+	public function __construct(
105
+		$base_url,
106
+		$default_form_step,
107
+		$form_action = '',
108
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
109
+		$progress_step_style = 'number_bubbles',
110
+		EE_Request $request
111
+	) {
112
+		$this->setBaseUrl($base_url);
113
+		$this->setDefaultFormStep($default_form_step);
114
+		$this->setFormAction($form_action);
115
+		$this->setFormConfig($form_config);
116
+		$this->setProgressStepStyle($progress_step_style);
117
+		$this->request = $request;
118
+	}
119
+
120
+
121
+	/**
122
+	 * @return string
123
+	 * @throws InvalidFormHandlerException
124
+	 */
125
+	public function baseUrl()
126
+	{
127
+		if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
128
+			add_query_arg(
129
+				array($this->form_step_url_key => $this->getCurrentStep()->slug()),
130
+				$this->base_url
131
+			);
132
+		}
133
+		return $this->base_url;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @param string $base_url
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidArgumentException
141
+	 */
142
+	protected function setBaseUrl($base_url)
143
+	{
144
+		if (! is_string($base_url)) {
145
+			throw new InvalidDataTypeException('$base_url', $base_url, 'string');
146
+		}
147
+		if (empty($base_url)) {
148
+			throw new InvalidArgumentException(
149
+				esc_html__('The base URL can not be an empty string.', 'event_espresso')
150
+			);
151
+		}
152
+		$this->base_url = $base_url;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @return string
158
+	 * @throws InvalidDataTypeException
159
+	 */
160
+	public function formStepUrlKey()
161
+	{
162
+		if (empty($this->form_step_url_key)) {
163
+			$this->setFormStepUrlKey();
164
+		}
165
+		return $this->form_step_url_key;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param string $form_step_url_key
171
+	 * @throws InvalidDataTypeException
172
+	 */
173
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
174
+	{
175
+		if (! is_string($form_step_url_key)) {
176
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
177
+		}
178
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return string
184
+	 */
185
+	public function defaultFormStep()
186
+	{
187
+		return $this->default_form_step;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param $default_form_step
193
+	 * @throws InvalidDataTypeException
194
+	 */
195
+	protected function setDefaultFormStep($default_form_step)
196
+	{
197
+		if (! is_string($default_form_step)) {
198
+			throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
199
+		}
200
+		$this->default_form_step = $default_form_step;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @return void
206
+	 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
207
+	 * @throws InvalidDataTypeException
208
+	 */
209
+	protected function setCurrentStepFromRequest()
210
+	{
211
+		$current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
212
+		if (! $this->form_steps->setCurrent($current_step_slug)) {
213
+			throw new InvalidIdentifierException(
214
+				$current_step_slug,
215
+				$this->defaultFormStep(),
216
+				$message = sprintf(
217
+					esc_html__(
218
+						'The "%1$s" form step could not be set.',
219
+						'event_espresso'
220
+					),
221
+					$current_step_slug
222
+				)
223
+			);
224
+		}
225
+	}
226
+
227
+
228
+	/**
229
+	 * @return object|SequentialStepFormInterface
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 EE_Request
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 $progress_steps;
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 $this->getCurrentStep()->display();
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, so...
558
+			// if WP_DEBUG === true, display the Exception and stack trace right now
559
+			new ExceptionStackTraceDisplay($e);
560
+			// else convert the Exception to an EE_Error
561
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
562
+			// prevent redirect to next step or other if exception was thrown
563
+			if ($current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
564
+				|| $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
565
+			) {
566
+				$current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
567
+			}
568
+		}
569
+		// save notices to a transient so that when we redirect back
570
+		// to the display portion for this step
571
+		// those notices can be displayed
572
+		EE_Error::get_notices(false, true);
573
+		$this->redirectForm($current_step);
574
+	}
575
+
576
+
577
+	/**
578
+	 * handles where to go to next
579
+	 *
580
+	 * @param SequentialStepFormInterface $current_step
581
+	 * @throws InvalidArgumentException
582
+	 * @throws InvalidDataTypeException
583
+	 * @throws InvalidFormHandlerException
584
+	 */
585
+	public function redirectForm(SequentialStepFormInterface $current_step)
586
+	{
587
+		$redirect_step = $current_step;
588
+		switch ($current_step->redirectTo()) {
589
+			case SequentialStepForm::REDIRECT_TO_OTHER:
590
+				// going somewhere else, so just check out now
591
+				wp_safe_redirect($redirect_step->redirectUrl());
592
+				exit();
593
+				break;
594
+			case SequentialStepForm::REDIRECT_TO_PREV_STEP:
595
+				$redirect_step = $this->form_steps->previous();
596
+				break;
597
+			case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
598
+				$this->form_steps->next();
599
+				if ($this->form_steps->valid()) {
600
+					$redirect_step = $this->form_steps->current();
601
+				}
602
+				break;
603
+			case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
604
+			default:
605
+				// $redirect_step is already set
606
+		}
607
+		$current_step->setRedirectUrl($this->baseUrl());
608
+		$current_step->addRedirectArgs(
609
+			// use the slug for whatever step we are redirecting too
610
+			array($this->formStepUrlKey() => $redirect_step->slug())
611
+		);
612
+		wp_safe_redirect($current_step->redirectUrl());
613
+		exit();
614
+	}
615 615
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     protected function setBaseUrl($base_url)
143 143
     {
144
-        if (! is_string($base_url)) {
144
+        if ( ! is_string($base_url)) {
145 145
             throw new InvalidDataTypeException('$base_url', $base_url, 'string');
146 146
         }
147 147
         if (empty($base_url)) {
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
174 174
     {
175
-        if (! is_string($form_step_url_key)) {
175
+        if ( ! is_string($form_step_url_key)) {
176 176
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
177 177
         }
178 178
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     protected function setDefaultFormStep($default_form_step)
196 196
     {
197
-        if (! is_string($default_form_step)) {
197
+        if ( ! is_string($default_form_step)) {
198 198
             throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
199 199
         }
200 200
         $this->default_form_step = $default_form_step;
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     protected function setCurrentStepFromRequest()
210 210
     {
211 211
         $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
212
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
212
+        if ( ! $this->form_steps->setCurrent($current_step_slug)) {
213 213
             throw new InvalidIdentifierException(
214 214
                 $current_step_slug,
215 215
                 $this->defaultFormStep(),
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public function getCurrentStep()
233 233
     {
234
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
234
+        if ( ! $this->form_steps->current() instanceof SequentialStepForm) {
235 235
             throw new InvalidFormHandlerException($this->form_steps->current());
236 236
         }
237 237
         return $this->form_steps->current();
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     public function formAction()
246 246
     {
247
-        if (! is_string($this->form_action) || empty($this->form_action)) {
247
+        if ( ! is_string($this->form_action) || empty($this->form_action)) {
248 248
             $this->form_action = $this->baseUrl();
249 249
         }
250 250
         return $this->form_action;
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
      */
258 258
     public function setFormAction($form_action)
259 259
     {
260
-        if (! is_string($form_action)) {
260
+        if ( ! is_string($form_action)) {
261 261
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
262 262
         }
263 263
         $this->form_action = $form_action;
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      */
272 272
     public function addFormActionArgs($form_action_args = array())
273 273
     {
274
-        if (! is_array($form_action_args)) {
274
+        if ( ! is_array($form_action_args)) {
275 275
             throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
276 276
         }
277 277
         $form_action_args = ! empty($form_action_args)
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     protected function getProgressStepsCollection()
337 337
     {
338 338
         static $collection = null;
339
-        if (! $collection instanceof ProgressStepCollection) {
339
+        if ( ! $collection instanceof ProgressStepCollection) {
340 340
             $collection = new ProgressStepCollection();
341 341
         }
342 342
         return $collection;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         /** @var SequentialStepForm $form_step */
359 359
         foreach ($this->form_steps as $form_step) {
360 360
             // is this step active ?
361
-            if (! $form_step->initialize()) {
361
+            if ( ! $form_step->initialize()) {
362 362
                 continue;
363 363
             }
364 364
             $progress_steps_collection->add(
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
     {
428 428
         $form_step = $this->buildCurrentStepForm();
429 429
         // no displayable content ? then skip straight to processing
430
-        if (! $form_step->displayable()) {
430
+        if ( ! $form_step->displayable()) {
431 431
             $this->addFormActionArgs();
432 432
             $form_step->setFormAction($this->formAction());
433 433
             wp_safe_redirect($form_step->formAction());
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
     public function displayProgressSteps($return_as_string = true)
504 504
     {
505 505
         $form_step = $this->getCurrentStep();
506
-        if (! $form_step->displayable()) {
506
+        if ( ! $form_step->displayable()) {
507 507
             return '';
508 508
         }
509 509
         $progress_steps = apply_filters(
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/InvalidFormHandlerException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -13,25 +13,25 @@
 block discarded – undo
13 13
 class InvalidFormHandlerException extends \UnexpectedValueException
14 14
 {
15 15
 
16
-    /**
17
-     * InvalidFormHandlerException constructor.
18
-     *
19
-     * @param string     $actual the FormHandler object that was received
20
-     * @param string     $message
21
-     * @param int        $code
22
-     * @param \Exception $previous
23
-     */
24
-    public function __construct($actual, $message = '', $code = 0, \Exception $previous = null)
25
-    {
26
-        if (empty($message)) {
27
-            $message = sprintf(
28
-                __(
29
-                    'A valid Form Handler was expected but instead "%1$s" was received.',
30
-                    'event_espresso'
31
-                ),
32
-                $actual
33
-            );
34
-        }
35
-        parent::__construct($message, $code, $previous);
36
-    }
16
+	/**
17
+	 * InvalidFormHandlerException constructor.
18
+	 *
19
+	 * @param string     $actual the FormHandler object that was received
20
+	 * @param string     $message
21
+	 * @param int        $code
22
+	 * @param \Exception $previous
23
+	 */
24
+	public function __construct($actual, $message = '', $code = 0, \Exception $previous = null)
25
+	{
26
+		if (empty($message)) {
27
+			$message = sprintf(
28
+				__(
29
+					'A valid Form Handler was expected but instead "%1$s" was received.',
30
+					'event_espresso'
31
+				),
32
+				$actual
33
+			);
34
+		}
35
+		parent::__construct($message, $code, $previous);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/strategies/filter/FormHtmlFilter.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@
 block discarded – undo
14 14
 abstract class FormHtmlFilter
15 15
 {
16 16
 
17
-    /**
18
-     * @param                             $html
19
-     * @param EE_Form_Section_Validatable $form_section
20
-     * @return string
21
-     */
22
-    abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section);
17
+	/**
18
+	 * @param                             $html
19
+	 * @param EE_Form_Section_Validatable $form_section
20
+	 * @return string
21
+	 */
22
+	abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section);
23 23
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/strategies/filter/VsprintfFilter.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,45 +19,45 @@
 block discarded – undo
19 19
 class VsprintfFilter extends FormHtmlFilter
20 20
 {
21 21
 
22
-    /**
23
-     * @var string $format
24
-     */
25
-    protected $format = '';
26
-
27
-
28
-    /**
29
-     * @var array $args
30
-     */
31
-    protected $args = array();
32
-
33
-
34
-    /**
35
-     * VsprintfFilter constructor.
36
-     *
37
-     * @param string $format
38
-     * @param array  $args
39
-     */
40
-    public function __construct($format, array $args)
41
-    {
42
-        $this->format = $format;
43
-        $this->args = $args;
44
-    }
45
-
46
-
47
-    /**
48
-     * @param                             $html
49
-     * @param EE_Form_Section_Validatable $form_section
50
-     * @return string
51
-     */
52
-    public function filterHtml($html, EE_Form_Section_Validatable $form_section)
53
-    {
54
-        $this->args[] = $html;
55
-        if ($form_section instanceof EE_Form_Section_Proper) {
56
-            $subsections = $form_section->subsections();
57
-            foreach ((array)$subsections as $subsection) {
58
-                $this->args[] = $subsection->get_html();
59
-            }
60
-        }
61
-        return vsprintf($this->format, $this->args);
62
-    }
22
+	/**
23
+	 * @var string $format
24
+	 */
25
+	protected $format = '';
26
+
27
+
28
+	/**
29
+	 * @var array $args
30
+	 */
31
+	protected $args = array();
32
+
33
+
34
+	/**
35
+	 * VsprintfFilter constructor.
36
+	 *
37
+	 * @param string $format
38
+	 * @param array  $args
39
+	 */
40
+	public function __construct($format, array $args)
41
+	{
42
+		$this->format = $format;
43
+		$this->args = $args;
44
+	}
45
+
46
+
47
+	/**
48
+	 * @param                             $html
49
+	 * @param EE_Form_Section_Validatable $form_section
50
+	 * @return string
51
+	 */
52
+	public function filterHtml($html, EE_Form_Section_Validatable $form_section)
53
+	{
54
+		$this->args[] = $html;
55
+		if ($form_section instanceof EE_Form_Section_Proper) {
56
+			$subsections = $form_section->subsections();
57
+			foreach ((array)$subsections as $subsection) {
58
+				$this->args[] = $subsection->get_html();
59
+			}
60
+		}
61
+		return vsprintf($this->format, $this->args);
62
+	}
63 63
 }
Please login to merge, or discard this patch.
core/libraries/iframe_display/Iframe.php 2 patches
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -18,371 +18,371 @@
 block discarded – undo
18 18
 class Iframe
19 19
 {
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() . DS
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 (apply_filters(
116
-            'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
117
-            false
118
-        )) {
119
-            $this->addStylesheets(
120
-                apply_filters(
121
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
122
-                    array('default_theme_stylesheet' => get_stylesheet_uri()),
123
-                    $this
124
-                )
125
-            );
126
-        }
127
-    }
128
-
129
-
130
-    /**
131
-     * @param string $title
132
-     * @throws DomainException
133
-     */
134
-    public function setTitle($title)
135
-    {
136
-        if (empty($title)) {
137
-            throw new DomainException(
138
-                esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso')
139
-            );
140
-        }
141
-        $this->title = $title;
142
-    }
143
-
144
-
145
-    /**
146
-     * @param string $content
147
-     * @throws DomainException
148
-     */
149
-    public function setContent($content)
150
-    {
151
-        if (empty($content)) {
152
-            throw new DomainException(
153
-                esc_html__('You must provide content in order to create an iframe.', 'event_espresso')
154
-            );
155
-        }
156
-        $this->content = $content;
157
-    }
158
-
159
-
160
-    /**
161
-     * @param boolean $enqueue_wp_assets
162
-     */
163
-    public function setEnqueueWpAssets($enqueue_wp_assets)
164
-    {
165
-        $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
166
-    }
167
-
168
-
169
-    /**
170
-     * @param array $stylesheets
171
-     * @throws DomainException
172
-     */
173
-    public function addStylesheets(array $stylesheets)
174
-    {
175
-        if (empty($stylesheets)) {
176
-            throw new DomainException(
177
-                esc_html__(
178
-                    'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
179
-                    'event_espresso'
180
-                )
181
-            );
182
-        }
183
-        foreach ($stylesheets as $handle => $stylesheet) {
184
-            $this->css[$handle] = $stylesheet;
185
-        }
186
-    }
187
-
188
-
189
-    /**
190
-     * @param array $scripts
191
-     * @param bool  $add_to_header
192
-     * @throws DomainException
193
-     */
194
-    public function addScripts(array $scripts, $add_to_header = false)
195
-    {
196
-        if (empty($scripts)) {
197
-            throw new DomainException(
198
-                esc_html__(
199
-                    'A non-empty array of URLs, is required to add Javascript to an iframe.',
200
-                    'event_espresso'
201
-                )
202
-            );
203
-        }
204
-        foreach ($scripts as $handle => $script) {
205
-            if ($add_to_header) {
206
-                $this->header_js[$handle] = $script;
207
-            } else {
208
-                $this->footer_js[$handle] = $script;
209
-            }
210
-        }
211
-    }
212
-
213
-
214
-    /**
215
-     * @param array $script_attributes
216
-     * @param bool  $add_to_header
217
-     * @throws DomainException
218
-     */
219
-    public function addScriptAttributes(array $script_attributes, $add_to_header = false)
220
-    {
221
-        if (empty($script_attributes)) {
222
-            throw new DomainException(
223
-                esc_html__(
224
-                    'A non-empty array of strings, is required to add attributes to iframe Javascript.',
225
-                    'event_espresso'
226
-                )
227
-            );
228
-        }
229
-        foreach ($script_attributes as $handle => $script_attribute) {
230
-            if ($add_to_header) {
231
-                $this->header_js_attributes[$handle] = $script_attribute;
232
-            } else {
233
-                $this->footer_js_attributes[$handle] = $script_attribute;
234
-            }
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * @param array  $vars
241
-     * @param string $var_name
242
-     * @throws DomainException
243
-     */
244
-    public function addLocalizedVars(array $vars, $var_name = 'eei18n')
245
-    {
246
-        if (empty($vars)) {
247
-            throw new DomainException(
248
-                esc_html__(
249
-                    'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
250
-                    'event_espresso'
251
-                )
252
-            );
253
-        }
254
-        foreach ($vars as $handle => $var) {
255
-            if ($var_name === 'eei18n') {
256
-                EE_Registry::$i18n_js_strings[$handle] = $var;
257
-            } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
258
-                $this->localized_vars[$var_name] = $var;
259
-            } else {
260
-                if (! isset($this->localized_vars[$var_name])) {
261
-                    $this->localized_vars[$var_name] = array();
262
-                }
263
-                $this->localized_vars[$var_name][$handle] = $var;
264
-            }
265
-        }
266
-    }
267
-
268
-
269
-    /**
270
-     * @param string $utm_content
271
-     * @throws DomainException
272
-     */
273
-    public function display($utm_content = '')
274
-    {
275
-        $this->content .= EEH_Template::powered_by_event_espresso(
276
-            '',
277
-            '',
278
-            ! empty($utm_content) ? array('utm_content' => $utm_content) : array()
279
-        );
280
-        EE_System::do_not_cache();
281
-        echo $this->getTemplate();
282
-        exit;
283
-    }
284
-
285
-
286
-    /**
287
-     * @return string
288
-     * @throws DomainException
289
-     */
290
-    public function getTemplate()
291
-    {
292
-        return EEH_Template::display_template(
293
-            __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
294
-            array(
295
-                'title'                => apply_filters(
296
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
297
-                    $this->title,
298
-                    $this
299
-                ),
300
-                'content'              => apply_filters(
301
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
302
-                    $this->content,
303
-                    $this
304
-                ),
305
-                'enqueue_wp_assets'    => apply_filters(
306
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
307
-                    $this->enqueue_wp_assets,
308
-                    $this
309
-                ),
310
-                'css'                  => (array)apply_filters(
311
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
312
-                    $this->css,
313
-                    $this
314
-                ),
315
-                'header_js'            => (array)apply_filters(
316
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
317
-                    $this->header_js,
318
-                    $this
319
-                ),
320
-                'header_js_attributes' => (array)apply_filters(
321
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
322
-                    $this->header_js_attributes,
323
-                    $this
324
-                ),
325
-                'footer_js'            => (array)apply_filters(
326
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
327
-                    $this->footer_js,
328
-                    $this
329
-                ),
330
-                'footer_js_attributes' => (array)apply_filters(
331
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
332
-                    $this->footer_js_attributes,
333
-                    $this
334
-                ),
335
-                'eei18n'               => apply_filters(
336
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
337
-                    EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
338
-                    $this
339
-                ),
340
-                'notices'              => EEH_Template::display_template(
341
-                    EE_TEMPLATES . 'espresso-ajax-notices.template.php',
342
-                    array(),
343
-                    true
344
-                ),
345
-            ),
346
-            true,
347
-            true
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * localizeJsonVars
354
-     *
355
-     * @return string
356
-     */
357
-    public function localizeJsonVars()
358
-    {
359
-        $JSON = '';
360
-        foreach ((array)$this->localized_vars as $var_name => $vars) {
361
-            $this->localized_vars[$var_name] = $this->encodeJsonVars($vars);
362
-            $JSON .= "/* <![CDATA[ */ var {$var_name} = ";
363
-            $JSON .= wp_json_encode($this->localized_vars[$var_name]);
364
-            $JSON .= '; /* ]]> */';
365
-        }
366
-        return $JSON;
367
-    }
368
-
369
-
370
-    /**
371
-     * @param bool|int|float|string|array $var
372
-     * @return array
373
-     */
374
-    public function encodeJsonVars($var)
375
-    {
376
-        if (is_array($var)) {
377
-            $localized_vars = array();
378
-            foreach ((array)$var as $key => $value) {
379
-                $localized_vars[$key] = $this->encodeJsonVars($value);
380
-            }
381
-            return $localized_vars;
382
-        }
383
-        if (is_scalar($var)) {
384
-            return html_entity_decode((string)$var, ENT_QUOTES, 'UTF-8');
385
-        }
386
-        return null;
387
-    }
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() . DS
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 (apply_filters(
116
+			'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
117
+			false
118
+		)) {
119
+			$this->addStylesheets(
120
+				apply_filters(
121
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
122
+					array('default_theme_stylesheet' => get_stylesheet_uri()),
123
+					$this
124
+				)
125
+			);
126
+		}
127
+	}
128
+
129
+
130
+	/**
131
+	 * @param string $title
132
+	 * @throws DomainException
133
+	 */
134
+	public function setTitle($title)
135
+	{
136
+		if (empty($title)) {
137
+			throw new DomainException(
138
+				esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso')
139
+			);
140
+		}
141
+		$this->title = $title;
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param string $content
147
+	 * @throws DomainException
148
+	 */
149
+	public function setContent($content)
150
+	{
151
+		if (empty($content)) {
152
+			throw new DomainException(
153
+				esc_html__('You must provide content in order to create an iframe.', 'event_espresso')
154
+			);
155
+		}
156
+		$this->content = $content;
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param boolean $enqueue_wp_assets
162
+	 */
163
+	public function setEnqueueWpAssets($enqueue_wp_assets)
164
+	{
165
+		$this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param array $stylesheets
171
+	 * @throws DomainException
172
+	 */
173
+	public function addStylesheets(array $stylesheets)
174
+	{
175
+		if (empty($stylesheets)) {
176
+			throw new DomainException(
177
+				esc_html__(
178
+					'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
179
+					'event_espresso'
180
+				)
181
+			);
182
+		}
183
+		foreach ($stylesheets as $handle => $stylesheet) {
184
+			$this->css[$handle] = $stylesheet;
185
+		}
186
+	}
187
+
188
+
189
+	/**
190
+	 * @param array $scripts
191
+	 * @param bool  $add_to_header
192
+	 * @throws DomainException
193
+	 */
194
+	public function addScripts(array $scripts, $add_to_header = false)
195
+	{
196
+		if (empty($scripts)) {
197
+			throw new DomainException(
198
+				esc_html__(
199
+					'A non-empty array of URLs, is required to add Javascript to an iframe.',
200
+					'event_espresso'
201
+				)
202
+			);
203
+		}
204
+		foreach ($scripts as $handle => $script) {
205
+			if ($add_to_header) {
206
+				$this->header_js[$handle] = $script;
207
+			} else {
208
+				$this->footer_js[$handle] = $script;
209
+			}
210
+		}
211
+	}
212
+
213
+
214
+	/**
215
+	 * @param array $script_attributes
216
+	 * @param bool  $add_to_header
217
+	 * @throws DomainException
218
+	 */
219
+	public function addScriptAttributes(array $script_attributes, $add_to_header = false)
220
+	{
221
+		if (empty($script_attributes)) {
222
+			throw new DomainException(
223
+				esc_html__(
224
+					'A non-empty array of strings, is required to add attributes to iframe Javascript.',
225
+					'event_espresso'
226
+				)
227
+			);
228
+		}
229
+		foreach ($script_attributes as $handle => $script_attribute) {
230
+			if ($add_to_header) {
231
+				$this->header_js_attributes[$handle] = $script_attribute;
232
+			} else {
233
+				$this->footer_js_attributes[$handle] = $script_attribute;
234
+			}
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * @param array  $vars
241
+	 * @param string $var_name
242
+	 * @throws DomainException
243
+	 */
244
+	public function addLocalizedVars(array $vars, $var_name = 'eei18n')
245
+	{
246
+		if (empty($vars)) {
247
+			throw new DomainException(
248
+				esc_html__(
249
+					'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
250
+					'event_espresso'
251
+				)
252
+			);
253
+		}
254
+		foreach ($vars as $handle => $var) {
255
+			if ($var_name === 'eei18n') {
256
+				EE_Registry::$i18n_js_strings[$handle] = $var;
257
+			} elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
258
+				$this->localized_vars[$var_name] = $var;
259
+			} else {
260
+				if (! isset($this->localized_vars[$var_name])) {
261
+					$this->localized_vars[$var_name] = array();
262
+				}
263
+				$this->localized_vars[$var_name][$handle] = $var;
264
+			}
265
+		}
266
+	}
267
+
268
+
269
+	/**
270
+	 * @param string $utm_content
271
+	 * @throws DomainException
272
+	 */
273
+	public function display($utm_content = '')
274
+	{
275
+		$this->content .= EEH_Template::powered_by_event_espresso(
276
+			'',
277
+			'',
278
+			! empty($utm_content) ? array('utm_content' => $utm_content) : array()
279
+		);
280
+		EE_System::do_not_cache();
281
+		echo $this->getTemplate();
282
+		exit;
283
+	}
284
+
285
+
286
+	/**
287
+	 * @return string
288
+	 * @throws DomainException
289
+	 */
290
+	public function getTemplate()
291
+	{
292
+		return EEH_Template::display_template(
293
+			__DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
294
+			array(
295
+				'title'                => apply_filters(
296
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
297
+					$this->title,
298
+					$this
299
+				),
300
+				'content'              => apply_filters(
301
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
302
+					$this->content,
303
+					$this
304
+				),
305
+				'enqueue_wp_assets'    => apply_filters(
306
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
307
+					$this->enqueue_wp_assets,
308
+					$this
309
+				),
310
+				'css'                  => (array)apply_filters(
311
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
312
+					$this->css,
313
+					$this
314
+				),
315
+				'header_js'            => (array)apply_filters(
316
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
317
+					$this->header_js,
318
+					$this
319
+				),
320
+				'header_js_attributes' => (array)apply_filters(
321
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
322
+					$this->header_js_attributes,
323
+					$this
324
+				),
325
+				'footer_js'            => (array)apply_filters(
326
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
327
+					$this->footer_js,
328
+					$this
329
+				),
330
+				'footer_js_attributes' => (array)apply_filters(
331
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
332
+					$this->footer_js_attributes,
333
+					$this
334
+				),
335
+				'eei18n'               => apply_filters(
336
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
337
+					EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
338
+					$this
339
+				),
340
+				'notices'              => EEH_Template::display_template(
341
+					EE_TEMPLATES . 'espresso-ajax-notices.template.php',
342
+					array(),
343
+					true
344
+				),
345
+			),
346
+			true,
347
+			true
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * localizeJsonVars
354
+	 *
355
+	 * @return string
356
+	 */
357
+	public function localizeJsonVars()
358
+	{
359
+		$JSON = '';
360
+		foreach ((array)$this->localized_vars as $var_name => $vars) {
361
+			$this->localized_vars[$var_name] = $this->encodeJsonVars($vars);
362
+			$JSON .= "/* <![CDATA[ */ var {$var_name} = ";
363
+			$JSON .= wp_json_encode($this->localized_vars[$var_name]);
364
+			$JSON .= '; /* ]]> */';
365
+		}
366
+		return $JSON;
367
+	}
368
+
369
+
370
+	/**
371
+	 * @param bool|int|float|string|array $var
372
+	 * @return array
373
+	 */
374
+	public function encodeJsonVars($var)
375
+	{
376
+		if (is_array($var)) {
377
+			$localized_vars = array();
378
+			foreach ((array)$var as $key => $value) {
379
+				$localized_vars[$key] = $this->encodeJsonVars($value);
380
+			}
381
+			return $localized_vars;
382
+		}
383
+		if (is_scalar($var)) {
384
+			return html_entity_decode((string)$var, ENT_QUOTES, 'UTF-8');
385
+		}
386
+		return null;
387
+	}
388 388
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
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);
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
             apply_filters(
93 93
                 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
94 94
                 array(
95
-                    'site_theme'       => get_stylesheet_directory_uri() . DS
96
-                                          . 'style.css?ver=' . EVENT_ESPRESSO_VERSION,
97
-                    'dashicons'        => includes_url('css/dashicons.min.css?ver=' . $wp_version),
95
+                    'site_theme'       => get_stylesheet_directory_uri().DS
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
 block discarded – undo
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
             )
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
             } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
258 258
                 $this->localized_vars[$var_name] = $var;
259 259
             } else {
260
-                if (! isset($this->localized_vars[$var_name])) {
260
+                if ( ! isset($this->localized_vars[$var_name])) {
261 261
                     $this->localized_vars[$var_name] = array();
262 262
                 }
263 263
                 $this->localized_vars[$var_name][$handle] = $var;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
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',
@@ -307,38 +307,38 @@  discard block
 block discarded – undo
307 307
                     $this->enqueue_wp_assets,
308 308
                     $this
309 309
                 ),
310
-                'css'                  => (array)apply_filters(
310
+                'css'                  => (array) apply_filters(
311 311
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
312 312
                     $this->css,
313 313
                     $this
314 314
                 ),
315
-                'header_js'            => (array)apply_filters(
315
+                'header_js'            => (array) apply_filters(
316 316
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
317 317
                     $this->header_js,
318 318
                     $this
319 319
                 ),
320
-                'header_js_attributes' => (array)apply_filters(
320
+                'header_js_attributes' => (array) apply_filters(
321 321
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
322 322
                     $this->header_js_attributes,
323 323
                     $this
324 324
                 ),
325
-                'footer_js'            => (array)apply_filters(
325
+                'footer_js'            => (array) apply_filters(
326 326
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
327 327
                     $this->footer_js,
328 328
                     $this
329 329
                 ),
330
-                'footer_js_attributes' => (array)apply_filters(
330
+                'footer_js_attributes' => (array) apply_filters(
331 331
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
332 332
                     $this->footer_js_attributes,
333 333
                     $this
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
                 ),
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
     public function localizeJsonVars()
358 358
     {
359 359
         $JSON = '';
360
-        foreach ((array)$this->localized_vars as $var_name => $vars) {
360
+        foreach ((array) $this->localized_vars as $var_name => $vars) {
361 361
             $this->localized_vars[$var_name] = $this->encodeJsonVars($vars);
362 362
             $JSON .= "/* <![CDATA[ */ var {$var_name} = ";
363 363
             $JSON .= wp_json_encode($this->localized_vars[$var_name]);
@@ -375,13 +375,13 @@  discard block
 block discarded – undo
375 375
     {
376 376
         if (is_array($var)) {
377 377
             $localized_vars = array();
378
-            foreach ((array)$var as $key => $value) {
378
+            foreach ((array) $var as $key => $value) {
379 379
                 $localized_vars[$key] = $this->encodeJsonVars($value);
380 380
             }
381 381
             return $localized_vars;
382 382
         }
383 383
         if (is_scalar($var)) {
384
-            return html_entity_decode((string)$var, ENT_QUOTES, 'UTF-8');
384
+            return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8');
385 385
         }
386 386
         return null;
387 387
     }
Please login to merge, or discard this patch.
core/libraries/iframe_display/IframeEmbedButton.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -13,274 +13,274 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @var string $iframe_name
18
-     */
19
-    private $iframe_name;
16
+	/**
17
+	 * @var string $iframe_name
18
+	 */
19
+	private $iframe_name;
20 20
 
21
-    /**
22
-     * @var string $route_name
23
-     */
24
-    private $route_name;
21
+	/**
22
+	 * @var string $route_name
23
+	 */
24
+	private $route_name;
25 25
 
26
-    /**
27
-     * @var string $slug
28
-     */
29
-    private $slug;
26
+	/**
27
+	 * @var string $slug
28
+	 */
29
+	private $slug;
30 30
 
31
-    /**
32
-     * @var boolean $append_filterable_content
33
-     */
34
-    private $append_filterable_content;
31
+	/**
32
+	 * @var boolean $append_filterable_content
33
+	 */
34
+	private $append_filterable_content;
35 35
 
36 36
 
37
-    /**
38
-     * IframeEmbedButton constructor.
39
-     *
40
-     * @param string $iframe_name i18n name for the iframe. This will be used in HTML
41
-     * @param string $route_name  the name of the registered route
42
-     * @param string $slug        URL slug used for the thing the iframe button is being embedded in.
43
-     *                            will most likely be "event" since that's the only usage atm
44
-     */
45
-    public function __construct($iframe_name, $route_name, $slug = 'event')
46
-    {
47
-        $this->iframe_name = $iframe_name;
48
-        $this->route_name = $route_name;
49
-        $this->slug = $slug;
50
-    }
37
+	/**
38
+	 * IframeEmbedButton constructor.
39
+	 *
40
+	 * @param string $iframe_name i18n name for the iframe. This will be used in HTML
41
+	 * @param string $route_name  the name of the registered route
42
+	 * @param string $slug        URL slug used for the thing the iframe button is being embedded in.
43
+	 *                            will most likely be "event" since that's the only usage atm
44
+	 */
45
+	public function __construct($iframe_name, $route_name, $slug = 'event')
46
+	{
47
+		$this->iframe_name = $iframe_name;
48
+		$this->route_name = $route_name;
49
+		$this->slug = $slug;
50
+	}
51 51
 
52 52
 
53
-    /**
54
-     * Adds an iframe embed code button to the Event editor.
55
-     */
56
-    public function addEventEditorIframeEmbedButtonFilter()
57
-    {
58
-        // add button for iframe code to event editor.
59
-        add_filter(
60
-            'get_sample_permalink_html',
61
-            array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'),
62
-            10,
63
-            2
64
-        );
65
-        add_action(
66
-            'admin_enqueue_scripts',
67
-            array($this, 'embedButtonAssets'),
68
-            10
69
-        );
70
-    }
53
+	/**
54
+	 * Adds an iframe embed code button to the Event editor.
55
+	 */
56
+	public function addEventEditorIframeEmbedButtonFilter()
57
+	{
58
+		// add button for iframe code to event editor.
59
+		add_filter(
60
+			'get_sample_permalink_html',
61
+			array($this, 'appendIframeEmbedButtonToSamplePermalinkHtml'),
62
+			10,
63
+			2
64
+		);
65
+		add_action(
66
+			'admin_enqueue_scripts',
67
+			array($this, 'embedButtonAssets'),
68
+			10
69
+		);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * @param $permalink_string
75
-     * @param $id
76
-     * @return string
77
-     */
78
-    public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id)
79
-    {
80
-        return $this->eventEditorIframeEmbedButton(
81
-            $permalink_string,
82
-            $id
83
-        );
84
-    }
73
+	/**
74
+	 * @param $permalink_string
75
+	 * @param $id
76
+	 * @return string
77
+	 */
78
+	public function appendIframeEmbedButtonToSamplePermalinkHtml($permalink_string, $id)
79
+	{
80
+		return $this->eventEditorIframeEmbedButton(
81
+			$permalink_string,
82
+			$id
83
+		);
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * iframe embed code button to the Event editor.
89
-     *
90
-     * @param string $permalink_string
91
-     * @param int    $id
92
-     * @return string
93
-     */
94
-    public function eventEditorIframeEmbedButton(
95
-        $permalink_string,
96
-        $id
97
-    ) {
98
-        // make sure this is ONLY when editing and the event id has been set.
99
-        if (! empty($id)) {
100
-            $post = get_post($id);
101
-            // if NOT event then let's get out.
102
-            if ($post->post_type !== 'espresso_events') {
103
-                return $permalink_string;
104
-            }
105
-            $permalink_string .= $this->embedButtonHtml(
106
-                array($this->slug => $id),
107
-                'button-small'
108
-            );
109
-        }
110
-        return $permalink_string;
111
-    }
87
+	/**
88
+	 * iframe embed code button to the Event editor.
89
+	 *
90
+	 * @param string $permalink_string
91
+	 * @param int    $id
92
+	 * @return string
93
+	 */
94
+	public function eventEditorIframeEmbedButton(
95
+		$permalink_string,
96
+		$id
97
+	) {
98
+		// make sure this is ONLY when editing and the event id has been set.
99
+		if (! empty($id)) {
100
+			$post = get_post($id);
101
+			// if NOT event then let's get out.
102
+			if ($post->post_type !== 'espresso_events') {
103
+				return $permalink_string;
104
+			}
105
+			$permalink_string .= $this->embedButtonHtml(
106
+				array($this->slug => $id),
107
+				'button-small'
108
+			);
109
+		}
110
+		return $permalink_string;
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * Adds an iframe embed code button via a WP do_action() as determined by the first parameter
116
-     *
117
-     * @param string $action name of the WP do_action() to hook into
118
-     */
119
-    public function addActionIframeEmbedButton($action)
120
-    {
121
-        // add button for iframe code to event editor.
122
-        add_action(
123
-            $action,
124
-            array($this, 'addActionIframeEmbedButtonCallback'),
125
-            10,
126
-            2
127
-        );
128
-    }
114
+	/**
115
+	 * Adds an iframe embed code button via a WP do_action() as determined by the first parameter
116
+	 *
117
+	 * @param string $action name of the WP do_action() to hook into
118
+	 */
119
+	public function addActionIframeEmbedButton($action)
120
+	{
121
+		// add button for iframe code to event editor.
122
+		add_action(
123
+			$action,
124
+			array($this, 'addActionIframeEmbedButtonCallback'),
125
+			10,
126
+			2
127
+		);
128
+	}
129 129
 
130 130
 
131
-    /**
132
-     * @return void
133
-     */
134
-    public function addActionIframeEmbedButtonCallback()
135
-    {
136
-        echo $this->embedButtonHtml();
137
-    }
131
+	/**
132
+	 * @return void
133
+	 */
134
+	public function addActionIframeEmbedButtonCallback()
135
+	{
136
+		echo $this->embedButtonHtml();
137
+	}
138 138
 
139 139
 
140
-    /**
141
-     * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter
142
-     *
143
-     * @param string $filter     name of the WP apply_filters() to hook into
144
-     * @param bool   $append     if true, will add iframe embed button to end of content,
145
-     *                           else if false, will add to the beginning of the content
146
-     */
147
-    public function addFilterIframeEmbedButton($filter, $append = true)
148
-    {
149
-        $this->append_filterable_content = $append;
150
-        // add button for iframe code to event editor.
151
-        add_filter(
152
-            $filter,
153
-            array($this, 'addFilterIframeEmbedButtonCallback'),
154
-            10
155
-        );
156
-    }
140
+	/**
141
+	 * Adds an iframe embed code button via a WP apply_filters() as determined by the first parameter
142
+	 *
143
+	 * @param string $filter     name of the WP apply_filters() to hook into
144
+	 * @param bool   $append     if true, will add iframe embed button to end of content,
145
+	 *                           else if false, will add to the beginning of the content
146
+	 */
147
+	public function addFilterIframeEmbedButton($filter, $append = true)
148
+	{
149
+		$this->append_filterable_content = $append;
150
+		// add button for iframe code to event editor.
151
+		add_filter(
152
+			$filter,
153
+			array($this, 'addFilterIframeEmbedButtonCallback'),
154
+			10
155
+		);
156
+	}
157 157
 
158 158
 
159
-    /**
160
-     * @param array|string $filterable_content
161
-     * @return array|string
162
-     */
163
-    public function addFilterIframeEmbedButtonCallback($filterable_content)
164
-    {
165
-        $embedButtonHtml = $this->embedButtonHtml();
166
-        if (is_array($filterable_content)) {
167
-            $filterable_content = $this->append_filterable_content
168
-                ? $filterable_content + array($this->route_name => $embedButtonHtml)
169
-                : array($this->route_name => $embedButtonHtml) + $filterable_content;
170
-        } else {
171
-            $filterable_content = $this->append_filterable_content
172
-                ? $filterable_content . $embedButtonHtml
173
-                : $embedButtonHtml . $filterable_content;
174
-        }
175
-        return $filterable_content;
176
-    }
159
+	/**
160
+	 * @param array|string $filterable_content
161
+	 * @return array|string
162
+	 */
163
+	public function addFilterIframeEmbedButtonCallback($filterable_content)
164
+	{
165
+		$embedButtonHtml = $this->embedButtonHtml();
166
+		if (is_array($filterable_content)) {
167
+			$filterable_content = $this->append_filterable_content
168
+				? $filterable_content + array($this->route_name => $embedButtonHtml)
169
+				: array($this->route_name => $embedButtonHtml) + $filterable_content;
170
+		} else {
171
+			$filterable_content = $this->append_filterable_content
172
+				? $filterable_content . $embedButtonHtml
173
+				: $embedButtonHtml . $filterable_content;
174
+		}
175
+		return $filterable_content;
176
+	}
177 177
 
178 178
 
179
-    /**
180
-     * iframe_embed_html
181
-     *
182
-     * @param array  $query_args
183
-     * @param string $button_class
184
-     * @return string
185
-     */
186
-    public function embedButtonHtml($query_args = array(), $button_class = '')
187
-    {
188
-        // incoming args will replace the defaults listed here in the second array (union preserves first array)
189
-        $query_args = (array)$query_args + array($this->route_name => 'iframe');
190
-        $query_args = (array)apply_filters(
191
-            'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args',
192
-            $query_args
193
-        );
194
-        // add this route to our localized vars
195
-        $iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes'])
196
-            ? \EE_Registry::$i18n_js_strings['iframe_module_routes']
197
-            : array();
198
-        $iframe_module_routes[$this->route_name] = $this->route_name;
199
-        \EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes;
200
-        $iframe_embed_html = \EEH_HTML::link(
201
-            '#',
202
-            sprintf(esc_html__('Embed %1$s', 'event_espresso'), $this->iframe_name),
203
-            sprintf(
204
-                esc_html__(
205
-                    'click here to generate code for embedding %1$s iframe into another site.',
206
-                    'event_espresso'
207
-                ),
208
-                \EEH_Inflector::add_indefinite_article($this->iframe_name)
209
-            ),
210
-            "{$this->route_name}-iframe-embed-trigger-js",
211
-            'iframe-embed-trigger-js button ' . $button_class,
212
-            '',
213
-            ' data-iframe_embed_button="#' . $this->route_name . '-iframe-js" tabindex="-1"'
214
-        );
215
-        $iframe_embed_html .= \EEH_HTML::div(
216
-            '',
217
-            "{$this->route_name}-iframe-js",
218
-            'iframe-embed-wrapper-js',
219
-            'display:none;'
220
-        );
221
-        $iframe_embed_html .= esc_html(
222
-            \EEH_HTML::div(
223
-                '<iframe src="' . add_query_arg($query_args, site_url()) . '" width="100%" height="100%"></iframe>',
224
-                '',
225
-                '',
226
-                'width:100%; height: 500px;'
227
-            )
228
-        );
229
-        $iframe_embed_html .= \EEH_HTML::divx();
230
-        return $iframe_embed_html;
231
-    }
179
+	/**
180
+	 * iframe_embed_html
181
+	 *
182
+	 * @param array  $query_args
183
+	 * @param string $button_class
184
+	 * @return string
185
+	 */
186
+	public function embedButtonHtml($query_args = array(), $button_class = '')
187
+	{
188
+		// incoming args will replace the defaults listed here in the second array (union preserves first array)
189
+		$query_args = (array)$query_args + array($this->route_name => 'iframe');
190
+		$query_args = (array)apply_filters(
191
+			'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args',
192
+			$query_args
193
+		);
194
+		// add this route to our localized vars
195
+		$iframe_module_routes = isset(\EE_Registry::$i18n_js_strings['iframe_module_routes'])
196
+			? \EE_Registry::$i18n_js_strings['iframe_module_routes']
197
+			: array();
198
+		$iframe_module_routes[$this->route_name] = $this->route_name;
199
+		\EE_Registry::$i18n_js_strings['iframe_module_routes'] = $iframe_module_routes;
200
+		$iframe_embed_html = \EEH_HTML::link(
201
+			'#',
202
+			sprintf(esc_html__('Embed %1$s', 'event_espresso'), $this->iframe_name),
203
+			sprintf(
204
+				esc_html__(
205
+					'click here to generate code for embedding %1$s iframe into another site.',
206
+					'event_espresso'
207
+				),
208
+				\EEH_Inflector::add_indefinite_article($this->iframe_name)
209
+			),
210
+			"{$this->route_name}-iframe-embed-trigger-js",
211
+			'iframe-embed-trigger-js button ' . $button_class,
212
+			'',
213
+			' data-iframe_embed_button="#' . $this->route_name . '-iframe-js" tabindex="-1"'
214
+		);
215
+		$iframe_embed_html .= \EEH_HTML::div(
216
+			'',
217
+			"{$this->route_name}-iframe-js",
218
+			'iframe-embed-wrapper-js',
219
+			'display:none;'
220
+		);
221
+		$iframe_embed_html .= esc_html(
222
+			\EEH_HTML::div(
223
+				'<iframe src="' . add_query_arg($query_args, site_url()) . '" width="100%" height="100%"></iframe>',
224
+				'',
225
+				'',
226
+				'width:100%; height: 500px;'
227
+			)
228
+		);
229
+		$iframe_embed_html .= \EEH_HTML::divx();
230
+		return $iframe_embed_html;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * enqueue iframe button js
236
-     */
237
-    public function embedButtonAssets()
238
-    {
239
-        \EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__(
240
-            'copy and paste the following into any other site\'s content to display this event:',
241
-            'event_espresso'
242
-        );
243
-        \EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__(
244
-            'click anywhere outside of this window to close it.',
245
-            'event_espresso'
246
-        );
247
-        wp_register_script(
248
-            'iframe_embed_button',
249
-            plugin_dir_url(__FILE__) . 'iframe-embed-button.js',
250
-            array('ee-dialog'),
251
-            EVENT_ESPRESSO_VERSION,
252
-            true
253
-        );
254
-        wp_enqueue_script('iframe_embed_button');
255
-    }
234
+	/**
235
+	 * enqueue iframe button js
236
+	 */
237
+	public function embedButtonAssets()
238
+	{
239
+		\EE_Registry::$i18n_js_strings['iframe_embed_title'] = esc_html__(
240
+			'copy and paste the following into any other site\'s content to display this event:',
241
+			'event_espresso'
242
+		);
243
+		\EE_Registry::$i18n_js_strings['iframe_embed_close_msg'] = esc_html__(
244
+			'click anywhere outside of this window to close it.',
245
+			'event_espresso'
246
+		);
247
+		wp_register_script(
248
+			'iframe_embed_button',
249
+			plugin_dir_url(__FILE__) . 'iframe-embed-button.js',
250
+			array('ee-dialog'),
251
+			EVENT_ESPRESSO_VERSION,
252
+			true
253
+		);
254
+		wp_enqueue_script('iframe_embed_button');
255
+	}
256 256
 
257 257
 
258
-    /**
259
-     * generates embed button sections for admin pages
260
-     *
261
-     * @param array $embed_buttons
262
-     * @return string
263
-     */
264
-    public function addIframeEmbedButtonsSection(array $embed_buttons)
265
-    {
266
-        $embed_buttons = (array)apply_filters(
267
-            'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons',
268
-            $embed_buttons
269
-        );
270
-        if (empty($embed_buttons)) {
271
-            return '';
272
-        }
273
-        // add button for iframe code to event editor.
274
-        $html = \EEH_HTML::br(2);
275
-        $html .= \EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso'));
276
-        $html .= \EEH_HTML::p(
277
-            esc_html__(
278
-                'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.',
279
-                'event_espresso'
280
-            )
281
-        );
282
-        $html .= ' &nbsp; ' . implode(' &nbsp; ', $embed_buttons) . ' ';
283
-        $html .= \EEH_HTML::br(2);
284
-        return $html;
285
-    }
258
+	/**
259
+	 * generates embed button sections for admin pages
260
+	 *
261
+	 * @param array $embed_buttons
262
+	 * @return string
263
+	 */
264
+	public function addIframeEmbedButtonsSection(array $embed_buttons)
265
+	{
266
+		$embed_buttons = (array)apply_filters(
267
+			'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons',
268
+			$embed_buttons
269
+		);
270
+		if (empty($embed_buttons)) {
271
+			return '';
272
+		}
273
+		// add button for iframe code to event editor.
274
+		$html = \EEH_HTML::br(2);
275
+		$html .= \EEH_HTML::h3(esc_html__('iFrame Embed Code', 'event_espresso'));
276
+		$html .= \EEH_HTML::p(
277
+			esc_html__(
278
+				'Click the following button(s) to generate iframe HTML that will allow you to embed your event content within the content of other websites.',
279
+				'event_espresso'
280
+			)
281
+		);
282
+		$html .= ' &nbsp; ' . implode(' &nbsp; ', $embed_buttons) . ' ';
283
+		$html .= \EEH_HTML::br(2);
284
+		return $html;
285
+	}
286 286
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $id
97 97
     ) {
98 98
         // make sure this is ONLY when editing and the event id has been set.
99
-        if (! empty($id)) {
99
+        if ( ! empty($id)) {
100 100
             $post = get_post($id);
101 101
             // if NOT event then let's get out.
102 102
             if ($post->post_type !== 'espresso_events') {
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
                 : array($this->route_name => $embedButtonHtml) + $filterable_content;
170 170
         } else {
171 171
             $filterable_content = $this->append_filterable_content
172
-                ? $filterable_content . $embedButtonHtml
173
-                : $embedButtonHtml . $filterable_content;
172
+                ? $filterable_content.$embedButtonHtml
173
+                : $embedButtonHtml.$filterable_content;
174 174
         }
175 175
         return $filterable_content;
176 176
     }
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
     public function embedButtonHtml($query_args = array(), $button_class = '')
187 187
     {
188 188
         // incoming args will replace the defaults listed here in the second array (union preserves first array)
189
-        $query_args = (array)$query_args + array($this->route_name => 'iframe');
190
-        $query_args = (array)apply_filters(
189
+        $query_args = (array) $query_args + array($this->route_name => 'iframe');
190
+        $query_args = (array) apply_filters(
191 191
             'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__embedButtonHtml__query_args',
192 192
             $query_args
193 193
         );
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
                 \EEH_Inflector::add_indefinite_article($this->iframe_name)
209 209
             ),
210 210
             "{$this->route_name}-iframe-embed-trigger-js",
211
-            'iframe-embed-trigger-js button ' . $button_class,
211
+            'iframe-embed-trigger-js button '.$button_class,
212 212
             '',
213
-            ' data-iframe_embed_button="#' . $this->route_name . '-iframe-js" tabindex="-1"'
213
+            ' data-iframe_embed_button="#'.$this->route_name.'-iframe-js" tabindex="-1"'
214 214
         );
215 215
         $iframe_embed_html .= \EEH_HTML::div(
216 216
             '',
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
         );
221 221
         $iframe_embed_html .= esc_html(
222 222
             \EEH_HTML::div(
223
-                '<iframe src="' . add_query_arg($query_args, site_url()) . '" width="100%" height="100%"></iframe>',
223
+                '<iframe src="'.add_query_arg($query_args, site_url()).'" width="100%" height="100%"></iframe>',
224 224
                 '',
225 225
                 '',
226 226
                 'width:100%; height: 500px;'
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         );
247 247
         wp_register_script(
248 248
             'iframe_embed_button',
249
-            plugin_dir_url(__FILE__) . 'iframe-embed-button.js',
249
+            plugin_dir_url(__FILE__).'iframe-embed-button.js',
250 250
             array('ee-dialog'),
251 251
             EVENT_ESPRESSO_VERSION,
252 252
             true
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public function addIframeEmbedButtonsSection(array $embed_buttons)
265 265
     {
266
-        $embed_buttons = (array)apply_filters(
266
+        $embed_buttons = (array) apply_filters(
267 267
             'FHEE__EventEspresso_core_libraries_iframe_display_IframeEmbedButton__addIframeEmbedButtonsSection__embed_buttons',
268 268
             $embed_buttons
269 269
         );
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                 'event_espresso'
280 280
             )
281 281
         );
282
-        $html .= ' &nbsp; ' . implode(' &nbsp; ', $embed_buttons) . ' ';
282
+        $html .= ' &nbsp; '.implode(' &nbsp; ', $embed_buttons).' ';
283 283
         $html .= \EEH_HTML::br(2);
284 284
         return $html;
285 285
     }
Please login to merge, or discard this patch.
core/libraries/iframe_display/EventListIframeEmbedButton.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -12,49 +12,49 @@
 block discarded – undo
12 12
 class EventListIframeEmbedButton extends IframeEmbedButton
13 13
 {
14 14
 
15
-    /**
16
-     * EventListIframeEmbedButton constructor.
17
-     */
18
-    public function __construct()
19
-    {
20
-        parent::__construct(
21
-            esc_html__('Upcoming Event List', 'event_espresso'),
22
-            'event_list'
23
-        );
24
-    }
15
+	/**
16
+	 * EventListIframeEmbedButton constructor.
17
+	 */
18
+	public function __construct()
19
+	{
20
+		parent::__construct(
21
+			esc_html__('Upcoming Event List', 'event_espresso'),
22
+			'event_list'
23
+		);
24
+	}
25 25
 
26 26
 
27
-    public function addEmbedButton()
28
-    {
29
-        add_filter(
30
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
31
-            array($this, 'addEventListIframeEmbedButtonSection')
32
-        );
33
-        add_action(
34
-            'admin_enqueue_scripts',
35
-            array($this, 'embedButtonAssets'),
36
-            10
37
-        );
38
-    }
27
+	public function addEmbedButton()
28
+	{
29
+		add_filter(
30
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
31
+			array($this, 'addEventListIframeEmbedButtonSection')
32
+		);
33
+		add_action(
34
+			'admin_enqueue_scripts',
35
+			array($this, 'embedButtonAssets'),
36
+			10
37
+		);
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * Adds an iframe embed code button to the Event editor.
43
-     * return string
44
-     *
45
-     * @param array $after_list_table
46
-     * @return array
47
-     */
48
-    public function addEventListIframeEmbedButtonSection(array $after_list_table)
49
-    {
50
-        return \EEH_Array::insert_into_array(
51
-            $after_list_table,
52
-            array(
53
-                'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
54
-                    array('event_list' => $this->embedButtonHtml())
55
-                ),
56
-            ),
57
-            'legend'
58
-        );
59
-    }
41
+	/**
42
+	 * Adds an iframe embed code button to the Event editor.
43
+	 * return string
44
+	 *
45
+	 * @param array $after_list_table
46
+	 * @return array
47
+	 */
48
+	public function addEventListIframeEmbedButtonSection(array $after_list_table)
49
+	{
50
+		return \EEH_Array::insert_into_array(
51
+			$after_list_table,
52
+			array(
53
+				'iframe_embed_buttons' => $this->addIframeEmbedButtonsSection(
54
+					array('event_list' => $this->embedButtonHtml())
55
+				),
56
+			),
57
+			'legend'
58
+		);
59
+	}
60 60
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/Capabilities.php 2 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -15,152 +15,152 @@
 block discarded – undo
15 15
 class Capabilities
16 16
 {
17 17
 
18
-    /**
19
-     * The current user can see at least SOME of these entities.
20
-     *
21
-     * @param EEM_Base $model
22
-     * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
23
-     * @return boolean
24
-     */
25
-    public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read)
26
-    {
27
-        if (apply_filters(
28
-            'FHEE__Capabilities__current_user_has_partial_access_to__override_begin',
29
-            false,
30
-            $model,
31
-            $model
32
-        )) {
33
-            return true;
34
-        }
35
-        foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) {
36
-            if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) {
37
-                return false;
38
-            }
39
-        }
40
-        if (apply_filters(
41
-            'FHEE__Capabilities__current_user_has_partial_access_to__override_end',
42
-            false,
43
-            $model,
44
-            $model
45
-        )) {
46
-            return false;
47
-        }
48
-        return true;
49
-    }
18
+	/**
19
+	 * The current user can see at least SOME of these entities.
20
+	 *
21
+	 * @param EEM_Base $model
22
+	 * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
23
+	 * @return boolean
24
+	 */
25
+	public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read)
26
+	{
27
+		if (apply_filters(
28
+			'FHEE__Capabilities__current_user_has_partial_access_to__override_begin',
29
+			false,
30
+			$model,
31
+			$model
32
+		)) {
33
+			return true;
34
+		}
35
+		foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) {
36
+			if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) {
37
+				return false;
38
+			}
39
+		}
40
+		if (apply_filters(
41
+			'FHEE__Capabilities__current_user_has_partial_access_to__override_end',
42
+			false,
43
+			$model,
44
+			$model
45
+		)) {
46
+			return false;
47
+		}
48
+		return true;
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * Gets an array of all the capabilities the current user is missing that affected
54
-     * the query
55
-     *
56
-     * @param EEM_Base $model
57
-     * @param string   $request_type one of the constants on WP_JSON_Server
58
-     * @return array
59
-     */
60
-    public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read)
61
-    {
62
-        return $model->caps_missing($request_type);
63
-    }
52
+	/**
53
+	 * Gets an array of all the capabilities the current user is missing that affected
54
+	 * the query
55
+	 *
56
+	 * @param EEM_Base $model
57
+	 * @param string   $request_type one of the constants on WP_JSON_Server
58
+	 * @return array
59
+	 */
60
+	public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read)
61
+	{
62
+		return $model->caps_missing($request_type);
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * Gets a string of all the capabilities the current user is missing that affected
68
-     * the query
69
-     *
70
-     * @param EEM_Base $model
71
-     * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
72
-     * @return string
73
-     */
74
-    public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read)
75
-    {
76
-        return implode(',', array_keys(self::getMissingPermissions($model, $model_context)));
77
-    }
66
+	/**
67
+	 * Gets a string of all the capabilities the current user is missing that affected
68
+	 * the query
69
+	 *
70
+	 * @param EEM_Base $model
71
+	 * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
72
+	 * @return string
73
+	 */
74
+	public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read)
75
+	{
76
+		return implode(',', array_keys(self::getMissingPermissions($model, $model_context)));
77
+	}
78 78
 
79 79
 
80
-    /**
81
-     * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access.
82
-     *
83
-     * @param array            $entity
84
-     * @param EEM_Base         $model
85
-     * @param string           $request_type         one of the return values from EEM_Base::valid_cap_contexts()
86
-     * @param ModelVersionInfo $model_version_info
87
-     * @param string           $primary_key_string   result of EEM_Base::get_index_primary_key_string(), so that we can
88
-     *                                               use this with models that have no primary key
89
-     * @return array ready for converting into json
90
-     */
91
-    public static function filterOutInaccessibleEntityFields(
92
-        $entity,
93
-        $model,
94
-        $request_type,
95
-        $model_version_info,
96
-        $primary_key_string = null
97
-    ) {
98
-        // if they didn't provide the primary key string, we'll just hope we can figure it out
99
-        // from the entity (although it's preferred client code does it, because the entity might be missing
100
-        // necessary fields for creating the primary key string, or they could be named differently)
101
-        if ($primary_key_string === null) {
102
-            $primary_key_string = $model->get_index_primary_key_string(
103
-                $model->deduce_fields_n_values_from_cols_n_values($entity)
104
-            );
105
-        }
106
-        // we only care to do this for frontend reads and when the user can't edit the item
107
-        if ($request_type !== EEM_Base::caps_read
108
-            || $model->exists(
109
-                $model->alter_query_params_to_restrict_by_ID(
110
-                    $primary_key_string,
111
-                    array(
112
-                        'default_where_conditions' => 'none',
113
-                        'caps'                     => EEM_Base::caps_edit,
114
-                    )
115
-                )
116
-            )
117
-        ) {
118
-            return $entity;
119
-        }
120
-        foreach ($model->field_settings() as $field_name => $field_obj) {
121
-            if ($model_version_info->fieldHasRenderedFormat($field_obj)
122
-                && isset($entity[$field_name])
123
-                && is_array($entity[$field_name])
124
-                && isset($entity[$field_name]['raw'])
125
-            ) {
126
-                unset($entity[$field_name]['raw']);
127
-            }
128
-        }
129
-        // theoretically we may want to filter out specific fields for specific models
130
-        return apply_filters(
131
-            'FHEE__Capabilities__filter_out_inaccessible_entity_fields',
132
-            $entity,
133
-            $model,
134
-            $request_type
135
-        );
136
-    }
80
+	/**
81
+	 * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access.
82
+	 *
83
+	 * @param array            $entity
84
+	 * @param EEM_Base         $model
85
+	 * @param string           $request_type         one of the return values from EEM_Base::valid_cap_contexts()
86
+	 * @param ModelVersionInfo $model_version_info
87
+	 * @param string           $primary_key_string   result of EEM_Base::get_index_primary_key_string(), so that we can
88
+	 *                                               use this with models that have no primary key
89
+	 * @return array ready for converting into json
90
+	 */
91
+	public static function filterOutInaccessibleEntityFields(
92
+		$entity,
93
+		$model,
94
+		$request_type,
95
+		$model_version_info,
96
+		$primary_key_string = null
97
+	) {
98
+		// if they didn't provide the primary key string, we'll just hope we can figure it out
99
+		// from the entity (although it's preferred client code does it, because the entity might be missing
100
+		// necessary fields for creating the primary key string, or they could be named differently)
101
+		if ($primary_key_string === null) {
102
+			$primary_key_string = $model->get_index_primary_key_string(
103
+				$model->deduce_fields_n_values_from_cols_n_values($entity)
104
+			);
105
+		}
106
+		// we only care to do this for frontend reads and when the user can't edit the item
107
+		if ($request_type !== EEM_Base::caps_read
108
+			|| $model->exists(
109
+				$model->alter_query_params_to_restrict_by_ID(
110
+					$primary_key_string,
111
+					array(
112
+						'default_where_conditions' => 'none',
113
+						'caps'                     => EEM_Base::caps_edit,
114
+					)
115
+				)
116
+			)
117
+		) {
118
+			return $entity;
119
+		}
120
+		foreach ($model->field_settings() as $field_name => $field_obj) {
121
+			if ($model_version_info->fieldHasRenderedFormat($field_obj)
122
+				&& isset($entity[$field_name])
123
+				&& is_array($entity[$field_name])
124
+				&& isset($entity[$field_name]['raw'])
125
+			) {
126
+				unset($entity[$field_name]['raw']);
127
+			}
128
+		}
129
+		// theoretically we may want to filter out specific fields for specific models
130
+		return apply_filters(
131
+			'FHEE__Capabilities__filter_out_inaccessible_entity_fields',
132
+			$entity,
133
+			$model,
134
+			$request_type
135
+		);
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * Verifies the current user has at least partial access to do this action on this model.
141
-     * If not, throws an exception (so we can define the code that sets up this error object
142
-     * once)
143
-     *
144
-     * @param EEM_Base $model
145
-     * @param string   $model_action_context
146
-     * @param string   $action_name
147
-     * @return void
148
-     * @throws RestException
149
-     */
150
-    public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
151
-    {
152
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
153
-            $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
154
-            throw new RestException(
155
-                sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
156
-                sprintf(
157
-                    __('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'),
158
-                    $action_name,
159
-                    $model_name_plural,
160
-                    Capabilities::getMissingPermissionsString($model, $model_action_context)
161
-                ),
162
-                array('status' => 403)
163
-            );
164
-        }
165
-    }
139
+	/**
140
+	 * Verifies the current user has at least partial access to do this action on this model.
141
+	 * If not, throws an exception (so we can define the code that sets up this error object
142
+	 * once)
143
+	 *
144
+	 * @param EEM_Base $model
145
+	 * @param string   $model_action_context
146
+	 * @param string   $action_name
147
+	 * @return void
148
+	 * @throws RestException
149
+	 */
150
+	public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
151
+	{
152
+		if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
153
+			$model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
154
+			throw new RestException(
155
+				sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
156
+				sprintf(
157
+					__('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'),
158
+					$action_name,
159
+					$model_name_plural,
160
+					Capabilities::getMissingPermissionsString($model, $model_action_context)
161
+				),
162
+				array('status' => 403)
163
+			);
164
+		}
165
+	}
166 166
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -149,7 +149,7 @@
 block discarded – undo
149 149
      */
150 150
     public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
151 151
     {
152
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
152
+        if ( ! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
153 153
             $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
154 154
             throw new RestException(
155 155
                 sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
Please login to merge, or discard this patch.
core/libraries/rest_api/ModelVersionInfo.php 2 patches
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -21,440 +21,440 @@
 block discarded – undo
21 21
 class ModelVersionInfo
22 22
 {
23 23
 
24
-    /**
25
-     * Constant used in the $_model_changes array to indicate that a model
26
-     * was completely new in this version
27
-     */
28
-    const MODEL_ADDED = 'model_added_in_this_version';
29
-
30
-    /**
31
-     * Top-level keys are versions (major and minor version numbers, eg "4.6")
32
-     * next-level keys are model names (eg "Event") that underwent some change in that version
33
-     * and the value is either Model_Version_Info::model_added (indicating the model is completely NEW in this version),
34
-     * or it's an array where the values are model field names,
35
-     * or API resource properties (ie, non-model fields that appear in REST API results)
36
-     * If a version is missing then we don't know anything about what changes it introduced from the previous version
37
-     *
38
-     * @var array
39
-     */
40
-    protected $model_changes = array();
41
-
42
-    /**
43
-     * top-level keys are version numbers,
44
-     * next-level keys are model CLASSNAMES (even parent classnames),
45
-     * and next-level keys are extra resource properties to attach to those models' resources,
46
-     * and next-level key-value pairs, where the keys are:
47
-     * 'raw', 'type', 'nullable', 'table_alias', 'table_column',  'always_available'
48
-     *
49
-     * @var array
50
-     */
51
-    protected $resource_changes = array();
52
-
53
-    /**
54
-     * @var string indicating what version of the API was requested
55
-     * (eg although core might be at version 4.8.11, they may have sent a request
56
-     * for 4.6)
57
-     */
58
-    protected $requested_version = null;
59
-
60
-    /**
61
-     * Keys are model names, values are their classnames.
62
-     * We cache this so we only need to calculate this once per request
63
-     *
64
-     * @var array
65
-     */
66
-    protected $cached_models_for_requested_version = null;
67
-
68
-    /**
69
-     * @var array
70
-     */
71
-    protected $cached_model_changes_between_requested_version_and_current = null;
72
-
73
-    /**
74
-     * @var array
75
-     */
76
-    protected $cached_resource_changes_between_requested_version_and_current = null;
77
-
78
-    /**
79
-     * 2d array where top-level keys are model names, 2nd-level keys are field names
80
-     * and values are the actual field objects
81
-     *
82
-     * @var array
83
-     */
84
-    protected $cached_fields_on_models = array();
85
-
86
-
87
-    /**
88
-     * Model_Version_Info constructor.
89
-     *
90
-     * @param string $requested_version
91
-     */
92
-    public function __construct($requested_version)
93
-    {
94
-        $this->requested_version = (string)$requested_version;
95
-        $this->model_changes = array(
96
-            '4.8.29' => array(
97
-                // first version where the REST API is in EE core, so no need
98
-                // to specify how its different from the previous
99
-            ),
100
-        );
101
-        // setup data for "extra" fields added onto resources which don't actually exist on models
102
-        $this->resource_changes = apply_filters(
103
-            'FHEE__Model_Version_Info___construct__extra_resource_properties_for_models',
104
-            array()
105
-        );
106
-        $defaults = array(
107
-            'raw'              => false,
108
-            'type'             => 'N/A',
109
-            'nullable'         => true,
110
-            'table_alias'      => 'N/A',
111
-            'table_column'     => 'N/A',
112
-            'always_available' => true,
113
-        );
114
-        foreach ($this->resource_changes as $version => $model_classnames) {
115
-            foreach ($model_classnames as $model_classname => $extra_fields) {
116
-                foreach ($extra_fields as $fieldname => $field_data) {
117
-                    $this->resource_changes[$model_classname][$fieldname]['name'] = $fieldname;
118
-                    foreach ($defaults as $attribute => $default_value) {
119
-                        if (! isset($this->resource_changes[$model_classname][$fieldname][$attribute])) {
120
-                            $this->resource_changes[$model_classname][$fieldname][$attribute] = $default_value;
121
-                        }
122
-                    }
123
-                }
124
-            }
125
-        }
126
-    }
127
-
128
-
129
-    /**
130
-     * Returns a slice of Model_Version_Info::model_changes()'s array
131
-     * indicating exactly what changes happened between the current core version,
132
-     * and the version requested
133
-     *
134
-     * @return array
135
-     */
136
-    public function modelChangesBetweenRequestedVersionAndCurrent()
137
-    {
138
-        if ($this->cached_model_changes_between_requested_version_and_current === null) {
139
-            $model_changes = array();
140
-            foreach ($this->modelChanges() as $version => $models_changed_in_version) {
141
-                if ($version <= EED_Core_Rest_Api::core_version() && $version > $this->requestedVersion()) {
142
-                    $model_changes[$version] = $models_changed_in_version;
143
-                }
144
-            }
145
-            $this->cached_model_changes_between_requested_version_and_current = $model_changes;
146
-        }
147
-        return $this->cached_model_changes_between_requested_version_and_current;
148
-    }
149
-
150
-
151
-    /**
152
-     * Returns a slice of Model_Version_Info::model_changes()'s array
153
-     * indicating exactly what changes happened between the current core version,
154
-     * and the version requested
155
-     *
156
-     * @return array
157
-     */
158
-    public function resourceChangesBetweenRequestedVersionAndCurrent()
159
-    {
160
-        if ($this->cached_resource_changes_between_requested_version_and_current === null) {
161
-            $resource_changes = array();
162
-            foreach ($this->resourceChanges() as $version => $model_classnames) {
163
-                if ($version <= EED_Core_Rest_Api::core_version() && $version > $this->requestedVersion()) {
164
-                    $resource_changes[$version] = $model_classnames;
165
-                }
166
-            }
167
-            $this->cached_resource_changes_between_requested_version_and_current = $resource_changes;
168
-        }
169
-        return $this->cached_resource_changes_between_requested_version_and_current;
170
-    }
171
-
172
-
173
-    /**
174
-     * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7'
175
-     *
176
-     * @return string like '4.6'
177
-     */
178
-    public function requestedVersion()
179
-    {
180
-        return $this->requested_version;
181
-    }
182
-
183
-
184
-    /**
185
-     * Returns an array describing how the models have changed in each version of core
186
-     * that supports the API (starting at 4.6)
187
-     * Top-level keys are versions (major and minor version numbers, eg "4.6")
188
-     * next-level keys are model names (eg "Event") that underwent some change in that version
189
-     * and the value is either NULL (indicating the model is completely NEW in this version),
190
-     * or it's an array where fields are value names.
191
-     * If a version is missing then we don't know anything about what changes it introduced from the previous version
192
-     *
193
-     * @return array
194
-     */
195
-    public function modelChanges()
196
-    {
197
-        return $this->model_changes;
198
-    }
199
-
200
-
201
-    /**
202
-     * Takes into account the requested version, and the current version, and
203
-     * what changed between the two, and tries to return.
204
-     * Analogous to EE_Registry::instance()->non_abstract_db_models
205
-     *
206
-     * @return array keys are model names, values are their classname
207
-     */
208
-    public function modelsForRequestedVersion()
209
-    {
210
-        if ($this->cached_models_for_requested_version === null) {
211
-            $all_models_in_current_version = EE_Registry::instance()->non_abstract_db_models;
212
-            foreach ($this->modelChangesBetweenRequestedVersionAndCurrent() as $version => $models_changed) {
213
-                foreach ($models_changed as $model_name => $new_indicator_or_fields_added) {
214
-                    if ($new_indicator_or_fields_added === ModelVersionInfo::MODEL_ADDED) {
215
-                        unset($all_models_in_current_version[$model_name]);
216
-                    }
217
-                }
218
-            }
219
-            $this->cached_models_for_requested_version = apply_filters(
220
-                'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version',
221
-                $all_models_in_current_version,
222
-                $this
223
-            );
224
-        }
225
-        return $this->cached_models_for_requested_version;
226
-    }
227
-
228
-
229
-    /**
230
-     * Determines if this is a valid model name in the requested version.
231
-     * Similar to EE_Registry::instance()->is_model_name(), but takes the requested
232
-     * version's models into account
233
-     *
234
-     * @param string $model_name eg 'Event'
235
-     * @return boolean
236
-     */
237
-    public function isModelNameInThisVersion($model_name)
238
-    {
239
-        $model_names = $this->modelsForRequestedVersion();
240
-        if (isset($model_names[$model_name])) {
241
-            return true;
242
-        } else {
243
-            return false;
244
-        }
245
-    }
246
-
247
-
248
-    /**
249
-     * Wrapper for EE_Registry::instance()->load_model(), but takes the requested
250
-     * version's models into account
251
-     *
252
-     * @param string $model_name
253
-     * @return \EEM_Base
254
-     * @throws \EE_Error
255
-     */
256
-    public function loadModel($model_name)
257
-    {
258
-        if ($this->isModelNameInThisVersion($model_name)) {
259
-            return EE_Registry::instance()->load_model($model_name);
260
-        } else {
261
-            throw new \EE_Error(
262
-                sprintf(
263
-                    __(
264
-                        'Cannot load model "%1$s" because it does not exist in version %2$s of Event Espresso',
265
-                        'event_espresso'
266
-                    ),
267
-                    $model_name,
268
-                    $this->requestedVersion()
269
-                )
270
-            );
271
-        }
272
-    }
273
-
274
-
275
-    /**
276
-     * Gets all the fields that should exist on this model right now
277
-     *
278
-     * @param \EEM_Base $model
279
-     * @return array|\EE_Model_Field_Base[]
280
-     */
281
-    public function fieldsOnModelInThisVersion($model)
282
-    {
283
-        if (! isset($this->cached_fields_on_models[$model->get_this_model_name()])) {
284
-            // get all model changes between the requested version and current core version
285
-            $changes = $this->modelChangesBetweenRequestedVersionAndCurrent();
286
-            // fetch all fields currently on this model
287
-            $current_fields = $model->field_settings();
288
-            // remove all fields that have been added since
289
-            foreach ($changes as $version => $changes_in_version) {
290
-                if (isset($changes_in_version[$model->get_this_model_name()])
291
-                    && $changes_in_version[$model->get_this_model_name()] !== ModelVersionInfo::MODEL_ADDED
292
-                ) {
293
-                    $current_fields = array_diff_key(
294
-                        $current_fields,
295
-                        array_flip($changes_in_version[$model->get_this_model_name()])
296
-                    );
297
-                }
298
-            }
299
-            $this->cached_fields_on_models = $current_fields;
300
-        }
301
-        return $this->cached_fields_on_models;
302
-    }
303
-
304
-
305
-    /**
306
-     * Determines if $object is of one of the classes of $classes. Similar to
307
-     * in_array(), except this checks if $object is a subclass of the classnames provided
308
-     * in $classnames
309
-     *
310
-     * @param object $object
311
-     * @param array  $classnames
312
-     * @return boolean
313
-     */
314
-    public function isSubclassOfOne($object, $classnames)
315
-    {
316
-        foreach ($classnames as $classname) {
317
-            if (is_a($object, $classname)) {
318
-                return true;
319
-            }
320
-        }
321
-        return false;
322
-    }
323
-
324
-
325
-    /**
326
-     * Returns the list of model field classes that that the API basically ignores
327
-     *
328
-     * @return array
329
-     */
330
-    public function fieldsIgnored()
331
-    {
332
-        return apply_filters(
333
-            'FHEE__Controller_Model_Read_fields_ignored',
334
-            array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field')
335
-        );
336
-    }
337
-
338
-
339
-    /**
340
-     * If this field one that should be ignored by the API?
341
-     *
342
-     * @param EE_Model_Field_Base
343
-     * @return boolean
344
-     */
345
-    public function fieldIsIgnored($field_obj)
346
-    {
347
-        return $this->isSubclassOfOne($field_obj, $this->fieldsIgnored());
348
-    }
349
-
350
-
351
-    /**
352
-     * Returns the list of model field classes that have a "raw" and non-raw formats.
353
-     * Normally the "raw" versions are only accessible to those who can edit them.
354
-     *
355
-     * @return array an array of EE_Model_Field_Base child classnames
356
-     */
357
-    public function fieldsThatHaveRenderedFormat()
358
-    {
359
-        return apply_filters(
360
-            'FHEE__Controller_Model_Read__fields_raw',
361
-            array('EE_Post_Content_Field', 'EE_Full_HTML_Field')
362
-        );
363
-    }
364
-
365
-
366
-    /**
367
-     * If this field one that has a raw format
368
-     *
369
-     * @param EE_Model_Field_Base
370
-     * @return boolean
371
-     */
372
-    public function fieldHasRenderedFormat($field_obj)
373
-    {
374
-        return $this->isSubclassOfOne($field_obj, $this->fieldsThatHaveRenderedFormat());
375
-    }
376
-
377
-
378
-    /**
379
-     * Returns the list of model field classes that have a "_pretty" and non-pretty versions.
380
-     * The pretty version of the field is NOT query-able or editable, but requires no extra permissions
381
-     * to view
382
-     *
383
-     * @return array an array of EE_Model_Field_Base child classnames
384
-     */
385
-    public function fieldsThatHavePrettyFormat()
386
-    {
387
-        return apply_filters(
388
-            'FHEE__Controller_Model_Read__fields_pretty',
389
-            array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field')
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * If this field one that has a pretty equivalent
396
-     *
397
-     * @param EE_Model_Field_Base
398
-     * @return boolean
399
-     */
400
-    public function fieldHasPrettyFormat($field_obj)
401
-    {
402
-        return $this->isSubclassOfOne($field_obj, $this->fieldsThatHavePrettyFormat());
403
-    }
404
-
405
-
406
-    /**
407
-     * Returns an array describing what extra API resource properties have been added through the versions
408
-     *
409
-     * @return array @see $this->_extra_resource_properties_for_models
410
-     */
411
-    public function resourceChanges()
412
-    {
413
-        return $this->resource_changes;
414
-    }
415
-
416
-
417
-    /**
418
-     * Returns an array where keys are extra resource properties in this version of the API,
419
-     * and values are key-value pairs describing the new properties. @see Model_Version::_resource_changes
420
-     *
421
-     * @param \EEM_Base $model
422
-     * @return array
423
-     */
424
-    public function extraResourcePropertiesForModel($model)
425
-    {
426
-        $extra_properties = array();
427
-        foreach ($this->resourceChangesBetweenRequestedVersionAndCurrent() as $version => $model_classnames) {
428
-            foreach ($model_classnames as $model_classname => $properties_added_in_this_version) {
429
-                if (is_subclass_of($model, $model_classname)) {
430
-                    $extra_properties = array_merge($extra_properties, $properties_added_in_this_version);
431
-                }
432
-            }
433
-        }
434
-        return $extra_properties;
435
-    }
436
-
437
-
438
-    /**
439
-     * Gets all the related models for the specified model. It's good to use this
440
-     * in case this model didn't exist for this version or something
441
-     *
442
-     * @param \EEM_Base $model
443
-     * @return \EE_Model_Relation_Base[]
444
-     */
445
-    public function relationSettings(\EEM_Base $model)
446
-    {
447
-        $relations = array();
448
-        foreach ($model->relation_settings() as $relation_name => $relation_obj) {
449
-            if ($this->isModelNameInThisVersion($relation_name)) {
450
-                $relations[$relation_name] = $relation_obj;
451
-            }
452
-        }
453
-        // filter the results, but use the old filter name
454
-        return apply_filters(
455
-            'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include',
456
-            $relations,
457
-            $model
458
-        );
459
-    }
24
+	/**
25
+	 * Constant used in the $_model_changes array to indicate that a model
26
+	 * was completely new in this version
27
+	 */
28
+	const MODEL_ADDED = 'model_added_in_this_version';
29
+
30
+	/**
31
+	 * Top-level keys are versions (major and minor version numbers, eg "4.6")
32
+	 * next-level keys are model names (eg "Event") that underwent some change in that version
33
+	 * and the value is either Model_Version_Info::model_added (indicating the model is completely NEW in this version),
34
+	 * or it's an array where the values are model field names,
35
+	 * or API resource properties (ie, non-model fields that appear in REST API results)
36
+	 * If a version is missing then we don't know anything about what changes it introduced from the previous version
37
+	 *
38
+	 * @var array
39
+	 */
40
+	protected $model_changes = array();
41
+
42
+	/**
43
+	 * top-level keys are version numbers,
44
+	 * next-level keys are model CLASSNAMES (even parent classnames),
45
+	 * and next-level keys are extra resource properties to attach to those models' resources,
46
+	 * and next-level key-value pairs, where the keys are:
47
+	 * 'raw', 'type', 'nullable', 'table_alias', 'table_column',  'always_available'
48
+	 *
49
+	 * @var array
50
+	 */
51
+	protected $resource_changes = array();
52
+
53
+	/**
54
+	 * @var string indicating what version of the API was requested
55
+	 * (eg although core might be at version 4.8.11, they may have sent a request
56
+	 * for 4.6)
57
+	 */
58
+	protected $requested_version = null;
59
+
60
+	/**
61
+	 * Keys are model names, values are their classnames.
62
+	 * We cache this so we only need to calculate this once per request
63
+	 *
64
+	 * @var array
65
+	 */
66
+	protected $cached_models_for_requested_version = null;
67
+
68
+	/**
69
+	 * @var array
70
+	 */
71
+	protected $cached_model_changes_between_requested_version_and_current = null;
72
+
73
+	/**
74
+	 * @var array
75
+	 */
76
+	protected $cached_resource_changes_between_requested_version_and_current = null;
77
+
78
+	/**
79
+	 * 2d array where top-level keys are model names, 2nd-level keys are field names
80
+	 * and values are the actual field objects
81
+	 *
82
+	 * @var array
83
+	 */
84
+	protected $cached_fields_on_models = array();
85
+
86
+
87
+	/**
88
+	 * Model_Version_Info constructor.
89
+	 *
90
+	 * @param string $requested_version
91
+	 */
92
+	public function __construct($requested_version)
93
+	{
94
+		$this->requested_version = (string)$requested_version;
95
+		$this->model_changes = array(
96
+			'4.8.29' => array(
97
+				// first version where the REST API is in EE core, so no need
98
+				// to specify how its different from the previous
99
+			),
100
+		);
101
+		// setup data for "extra" fields added onto resources which don't actually exist on models
102
+		$this->resource_changes = apply_filters(
103
+			'FHEE__Model_Version_Info___construct__extra_resource_properties_for_models',
104
+			array()
105
+		);
106
+		$defaults = array(
107
+			'raw'              => false,
108
+			'type'             => 'N/A',
109
+			'nullable'         => true,
110
+			'table_alias'      => 'N/A',
111
+			'table_column'     => 'N/A',
112
+			'always_available' => true,
113
+		);
114
+		foreach ($this->resource_changes as $version => $model_classnames) {
115
+			foreach ($model_classnames as $model_classname => $extra_fields) {
116
+				foreach ($extra_fields as $fieldname => $field_data) {
117
+					$this->resource_changes[$model_classname][$fieldname]['name'] = $fieldname;
118
+					foreach ($defaults as $attribute => $default_value) {
119
+						if (! isset($this->resource_changes[$model_classname][$fieldname][$attribute])) {
120
+							$this->resource_changes[$model_classname][$fieldname][$attribute] = $default_value;
121
+						}
122
+					}
123
+				}
124
+			}
125
+		}
126
+	}
127
+
128
+
129
+	/**
130
+	 * Returns a slice of Model_Version_Info::model_changes()'s array
131
+	 * indicating exactly what changes happened between the current core version,
132
+	 * and the version requested
133
+	 *
134
+	 * @return array
135
+	 */
136
+	public function modelChangesBetweenRequestedVersionAndCurrent()
137
+	{
138
+		if ($this->cached_model_changes_between_requested_version_and_current === null) {
139
+			$model_changes = array();
140
+			foreach ($this->modelChanges() as $version => $models_changed_in_version) {
141
+				if ($version <= EED_Core_Rest_Api::core_version() && $version > $this->requestedVersion()) {
142
+					$model_changes[$version] = $models_changed_in_version;
143
+				}
144
+			}
145
+			$this->cached_model_changes_between_requested_version_and_current = $model_changes;
146
+		}
147
+		return $this->cached_model_changes_between_requested_version_and_current;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Returns a slice of Model_Version_Info::model_changes()'s array
153
+	 * indicating exactly what changes happened between the current core version,
154
+	 * and the version requested
155
+	 *
156
+	 * @return array
157
+	 */
158
+	public function resourceChangesBetweenRequestedVersionAndCurrent()
159
+	{
160
+		if ($this->cached_resource_changes_between_requested_version_and_current === null) {
161
+			$resource_changes = array();
162
+			foreach ($this->resourceChanges() as $version => $model_classnames) {
163
+				if ($version <= EED_Core_Rest_Api::core_version() && $version > $this->requestedVersion()) {
164
+					$resource_changes[$version] = $model_classnames;
165
+				}
166
+			}
167
+			$this->cached_resource_changes_between_requested_version_and_current = $resource_changes;
168
+		}
169
+		return $this->cached_resource_changes_between_requested_version_and_current;
170
+	}
171
+
172
+
173
+	/**
174
+	 * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7'
175
+	 *
176
+	 * @return string like '4.6'
177
+	 */
178
+	public function requestedVersion()
179
+	{
180
+		return $this->requested_version;
181
+	}
182
+
183
+
184
+	/**
185
+	 * Returns an array describing how the models have changed in each version of core
186
+	 * that supports the API (starting at 4.6)
187
+	 * Top-level keys are versions (major and minor version numbers, eg "4.6")
188
+	 * next-level keys are model names (eg "Event") that underwent some change in that version
189
+	 * and the value is either NULL (indicating the model is completely NEW in this version),
190
+	 * or it's an array where fields are value names.
191
+	 * If a version is missing then we don't know anything about what changes it introduced from the previous version
192
+	 *
193
+	 * @return array
194
+	 */
195
+	public function modelChanges()
196
+	{
197
+		return $this->model_changes;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Takes into account the requested version, and the current version, and
203
+	 * what changed between the two, and tries to return.
204
+	 * Analogous to EE_Registry::instance()->non_abstract_db_models
205
+	 *
206
+	 * @return array keys are model names, values are their classname
207
+	 */
208
+	public function modelsForRequestedVersion()
209
+	{
210
+		if ($this->cached_models_for_requested_version === null) {
211
+			$all_models_in_current_version = EE_Registry::instance()->non_abstract_db_models;
212
+			foreach ($this->modelChangesBetweenRequestedVersionAndCurrent() as $version => $models_changed) {
213
+				foreach ($models_changed as $model_name => $new_indicator_or_fields_added) {
214
+					if ($new_indicator_or_fields_added === ModelVersionInfo::MODEL_ADDED) {
215
+						unset($all_models_in_current_version[$model_name]);
216
+					}
217
+				}
218
+			}
219
+			$this->cached_models_for_requested_version = apply_filters(
220
+				'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version',
221
+				$all_models_in_current_version,
222
+				$this
223
+			);
224
+		}
225
+		return $this->cached_models_for_requested_version;
226
+	}
227
+
228
+
229
+	/**
230
+	 * Determines if this is a valid model name in the requested version.
231
+	 * Similar to EE_Registry::instance()->is_model_name(), but takes the requested
232
+	 * version's models into account
233
+	 *
234
+	 * @param string $model_name eg 'Event'
235
+	 * @return boolean
236
+	 */
237
+	public function isModelNameInThisVersion($model_name)
238
+	{
239
+		$model_names = $this->modelsForRequestedVersion();
240
+		if (isset($model_names[$model_name])) {
241
+			return true;
242
+		} else {
243
+			return false;
244
+		}
245
+	}
246
+
247
+
248
+	/**
249
+	 * Wrapper for EE_Registry::instance()->load_model(), but takes the requested
250
+	 * version's models into account
251
+	 *
252
+	 * @param string $model_name
253
+	 * @return \EEM_Base
254
+	 * @throws \EE_Error
255
+	 */
256
+	public function loadModel($model_name)
257
+	{
258
+		if ($this->isModelNameInThisVersion($model_name)) {
259
+			return EE_Registry::instance()->load_model($model_name);
260
+		} else {
261
+			throw new \EE_Error(
262
+				sprintf(
263
+					__(
264
+						'Cannot load model "%1$s" because it does not exist in version %2$s of Event Espresso',
265
+						'event_espresso'
266
+					),
267
+					$model_name,
268
+					$this->requestedVersion()
269
+				)
270
+			);
271
+		}
272
+	}
273
+
274
+
275
+	/**
276
+	 * Gets all the fields that should exist on this model right now
277
+	 *
278
+	 * @param \EEM_Base $model
279
+	 * @return array|\EE_Model_Field_Base[]
280
+	 */
281
+	public function fieldsOnModelInThisVersion($model)
282
+	{
283
+		if (! isset($this->cached_fields_on_models[$model->get_this_model_name()])) {
284
+			// get all model changes between the requested version and current core version
285
+			$changes = $this->modelChangesBetweenRequestedVersionAndCurrent();
286
+			// fetch all fields currently on this model
287
+			$current_fields = $model->field_settings();
288
+			// remove all fields that have been added since
289
+			foreach ($changes as $version => $changes_in_version) {
290
+				if (isset($changes_in_version[$model->get_this_model_name()])
291
+					&& $changes_in_version[$model->get_this_model_name()] !== ModelVersionInfo::MODEL_ADDED
292
+				) {
293
+					$current_fields = array_diff_key(
294
+						$current_fields,
295
+						array_flip($changes_in_version[$model->get_this_model_name()])
296
+					);
297
+				}
298
+			}
299
+			$this->cached_fields_on_models = $current_fields;
300
+		}
301
+		return $this->cached_fields_on_models;
302
+	}
303
+
304
+
305
+	/**
306
+	 * Determines if $object is of one of the classes of $classes. Similar to
307
+	 * in_array(), except this checks if $object is a subclass of the classnames provided
308
+	 * in $classnames
309
+	 *
310
+	 * @param object $object
311
+	 * @param array  $classnames
312
+	 * @return boolean
313
+	 */
314
+	public function isSubclassOfOne($object, $classnames)
315
+	{
316
+		foreach ($classnames as $classname) {
317
+			if (is_a($object, $classname)) {
318
+				return true;
319
+			}
320
+		}
321
+		return false;
322
+	}
323
+
324
+
325
+	/**
326
+	 * Returns the list of model field classes that that the API basically ignores
327
+	 *
328
+	 * @return array
329
+	 */
330
+	public function fieldsIgnored()
331
+	{
332
+		return apply_filters(
333
+			'FHEE__Controller_Model_Read_fields_ignored',
334
+			array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field')
335
+		);
336
+	}
337
+
338
+
339
+	/**
340
+	 * If this field one that should be ignored by the API?
341
+	 *
342
+	 * @param EE_Model_Field_Base
343
+	 * @return boolean
344
+	 */
345
+	public function fieldIsIgnored($field_obj)
346
+	{
347
+		return $this->isSubclassOfOne($field_obj, $this->fieldsIgnored());
348
+	}
349
+
350
+
351
+	/**
352
+	 * Returns the list of model field classes that have a "raw" and non-raw formats.
353
+	 * Normally the "raw" versions are only accessible to those who can edit them.
354
+	 *
355
+	 * @return array an array of EE_Model_Field_Base child classnames
356
+	 */
357
+	public function fieldsThatHaveRenderedFormat()
358
+	{
359
+		return apply_filters(
360
+			'FHEE__Controller_Model_Read__fields_raw',
361
+			array('EE_Post_Content_Field', 'EE_Full_HTML_Field')
362
+		);
363
+	}
364
+
365
+
366
+	/**
367
+	 * If this field one that has a raw format
368
+	 *
369
+	 * @param EE_Model_Field_Base
370
+	 * @return boolean
371
+	 */
372
+	public function fieldHasRenderedFormat($field_obj)
373
+	{
374
+		return $this->isSubclassOfOne($field_obj, $this->fieldsThatHaveRenderedFormat());
375
+	}
376
+
377
+
378
+	/**
379
+	 * Returns the list of model field classes that have a "_pretty" and non-pretty versions.
380
+	 * The pretty version of the field is NOT query-able or editable, but requires no extra permissions
381
+	 * to view
382
+	 *
383
+	 * @return array an array of EE_Model_Field_Base child classnames
384
+	 */
385
+	public function fieldsThatHavePrettyFormat()
386
+	{
387
+		return apply_filters(
388
+			'FHEE__Controller_Model_Read__fields_pretty',
389
+			array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field')
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * If this field one that has a pretty equivalent
396
+	 *
397
+	 * @param EE_Model_Field_Base
398
+	 * @return boolean
399
+	 */
400
+	public function fieldHasPrettyFormat($field_obj)
401
+	{
402
+		return $this->isSubclassOfOne($field_obj, $this->fieldsThatHavePrettyFormat());
403
+	}
404
+
405
+
406
+	/**
407
+	 * Returns an array describing what extra API resource properties have been added through the versions
408
+	 *
409
+	 * @return array @see $this->_extra_resource_properties_for_models
410
+	 */
411
+	public function resourceChanges()
412
+	{
413
+		return $this->resource_changes;
414
+	}
415
+
416
+
417
+	/**
418
+	 * Returns an array where keys are extra resource properties in this version of the API,
419
+	 * and values are key-value pairs describing the new properties. @see Model_Version::_resource_changes
420
+	 *
421
+	 * @param \EEM_Base $model
422
+	 * @return array
423
+	 */
424
+	public function extraResourcePropertiesForModel($model)
425
+	{
426
+		$extra_properties = array();
427
+		foreach ($this->resourceChangesBetweenRequestedVersionAndCurrent() as $version => $model_classnames) {
428
+			foreach ($model_classnames as $model_classname => $properties_added_in_this_version) {
429
+				if (is_subclass_of($model, $model_classname)) {
430
+					$extra_properties = array_merge($extra_properties, $properties_added_in_this_version);
431
+				}
432
+			}
433
+		}
434
+		return $extra_properties;
435
+	}
436
+
437
+
438
+	/**
439
+	 * Gets all the related models for the specified model. It's good to use this
440
+	 * in case this model didn't exist for this version or something
441
+	 *
442
+	 * @param \EEM_Base $model
443
+	 * @return \EE_Model_Relation_Base[]
444
+	 */
445
+	public function relationSettings(\EEM_Base $model)
446
+	{
447
+		$relations = array();
448
+		foreach ($model->relation_settings() as $relation_name => $relation_obj) {
449
+			if ($this->isModelNameInThisVersion($relation_name)) {
450
+				$relations[$relation_name] = $relation_obj;
451
+			}
452
+		}
453
+		// filter the results, but use the old filter name
454
+		return apply_filters(
455
+			'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include',
456
+			$relations,
457
+			$model
458
+		);
459
+	}
460 460
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function __construct($requested_version)
93 93
     {
94
-        $this->requested_version = (string)$requested_version;
94
+        $this->requested_version = (string) $requested_version;
95 95
         $this->model_changes = array(
96 96
             '4.8.29' => array(
97 97
                 // first version where the REST API is in EE core, so no need
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
                 foreach ($extra_fields as $fieldname => $field_data) {
117 117
                     $this->resource_changes[$model_classname][$fieldname]['name'] = $fieldname;
118 118
                     foreach ($defaults as $attribute => $default_value) {
119
-                        if (! isset($this->resource_changes[$model_classname][$fieldname][$attribute])) {
119
+                        if ( ! isset($this->resource_changes[$model_classname][$fieldname][$attribute])) {
120 120
                             $this->resource_changes[$model_classname][$fieldname][$attribute] = $default_value;
121 121
                         }
122 122
                     }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      */
281 281
     public function fieldsOnModelInThisVersion($model)
282 282
     {
283
-        if (! isset($this->cached_fields_on_models[$model->get_this_model_name()])) {
283
+        if ( ! isset($this->cached_fields_on_models[$model->get_this_model_name()])) {
284 284
             // get all model changes between the requested version and current core version
285 285
             $changes = $this->modelChangesBetweenRequestedVersionAndCurrent();
286 286
             // fetch all fields currently on this model
Please login to merge, or discard this patch.