Completed
Branch master (7421d0)
by
unknown
11:25 queued 06:55
created
core/libraries/form_sections/inputs/EE_Year_Input.input.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -9,17 +9,17 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Year_Input extends EE_Select_Input
11 11
 {
12
-    public function __construct(
13
-        $input_settings = [],
14
-        bool $four_digit_year = true,
15
-        int $years_behind = 100,
16
-        int $years_ahead = 0
17
-    ) {
18
-        $answer_options = [];
19
-        $current_year   = $four_digit_year ? (int) date('Y') : (int) date('y');
20
-        for ($start = $current_year - $years_behind; $start <= ($current_year + $years_ahead); $start++) {
21
-            $answer_options[ $start ] = $start;
22
-        }
23
-        parent::__construct($answer_options, $input_settings);
24
-    }
12
+	public function __construct(
13
+		$input_settings = [],
14
+		bool $four_digit_year = true,
15
+		int $years_behind = 100,
16
+		int $years_ahead = 0
17
+	) {
18
+		$answer_options = [];
19
+		$current_year   = $four_digit_year ? (int) date('Y') : (int) date('y');
20
+		for ($start = $current_year - $years_behind; $start <= ($current_year + $years_ahead); $start++) {
21
+			$answer_options[ $start ] = $start;
22
+		}
23
+		parent::__construct($answer_options, $input_settings);
24
+	}
25 25
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
         $answer_options = [];
19 19
         $current_year   = $four_digit_year ? (int) date('Y') : (int) date('y');
20 20
         for ($start = $current_year - $years_behind; $start <= ($current_year + $years_ahead); $start++) {
21
-            $answer_options[ $start ] = $start;
21
+            $answer_options[$start] = $start;
22 22
         }
23 23
         parent::__construct($answer_options, $input_settings);
24 24
     }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Password_Input.input.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Password_Input extends EE_Text_Input
11 11
 {
12
-    /**
13
-     * @param array $input_settings
14
-     */
15
-    public function __construct($input_settings = array())
16
-    {
17
-        parent::__construct($input_settings, 'password');
18
-        $this->set_html_class($this->html_class() . 'password');
19
-    }
12
+	/**
13
+	 * @param array $input_settings
14
+	 */
15
+	public function __construct($input_settings = array())
16
+	{
17
+		parent::__construct($input_settings, 'password');
18
+		$this->set_html_class($this->html_class() . 'password');
19
+	}
20 20
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,6 +15,6 @@
 block discarded – undo
15 15
     public function __construct($input_settings = array())
16 16
     {
17 17
         parent::__construct($input_settings, 'password');
18
-        $this->set_html_class($this->html_class() . 'password');
18
+        $this->set_html_class($this->html_class().'password');
19 19
     }
20 20
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Text_Input.input.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -11,22 +11,22 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Text_Input extends EE_Form_Input_Base
13 13
 {
14
-    /**
15
-     * @param array $options
16
-     */
17
-    public function __construct($options = [], string $input_type = 'text')
18
-    {
19
-        $this->_set_display_strategy(new EE_Text_Input_Display_Strategy($input_type));
20
-        // if the input hasn't set a normalization strategy, apply text normalization strategy
21
-        if (! $this->get_normalization_strategy()) {
22
-            $this->_set_normalization_strategy(new EE_Text_Normalization());
23
-        }
24
-        // if the input hasn't set a validation strategy, apply plaintext validation strategy
25
-        if (! $this->get_validation_strategies()) {
26
-            // by default we use the plaintext validation. If you want something else,
27
-            // just remove it after the input is constructed :P using EE_Form_Input_Base::remove_validation_strategy()
28
-            $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy());
29
-        }
30
-        parent::__construct($options);
31
-    }
14
+	/**
15
+	 * @param array $options
16
+	 */
17
+	public function __construct($options = [], string $input_type = 'text')
18
+	{
19
+		$this->_set_display_strategy(new EE_Text_Input_Display_Strategy($input_type));
20
+		// if the input hasn't set a normalization strategy, apply text normalization strategy
21
+		if (! $this->get_normalization_strategy()) {
22
+			$this->_set_normalization_strategy(new EE_Text_Normalization());
23
+		}
24
+		// if the input hasn't set a validation strategy, apply plaintext validation strategy
25
+		if (! $this->get_validation_strategies()) {
26
+			// by default we use the plaintext validation. If you want something else,
27
+			// just remove it after the input is constructed :P using EE_Form_Input_Base::remove_validation_strategy()
28
+			$this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy());
29
+		}
30
+		parent::__construct($options);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@
 block discarded – undo
18 18
     {
19 19
         $this->_set_display_strategy(new EE_Text_Input_Display_Strategy($input_type));
20 20
         // if the input hasn't set a normalization strategy, apply text normalization strategy
21
-        if (! $this->get_normalization_strategy()) {
21
+        if ( ! $this->get_normalization_strategy()) {
22 22
             $this->_set_normalization_strategy(new EE_Text_Normalization());
23 23
         }
24 24
         // if the input hasn't set a validation strategy, apply plaintext validation strategy
25
-        if (! $this->get_validation_strategies()) {
25
+        if ( ! $this->get_validation_strategies()) {
26 26
             // by default we use the plaintext validation. If you want something else,
27 27
             // just remove it after the input is constructed :P using EE_Form_Input_Base::remove_validation_strategy()
28 28
             $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy());
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Currency_Input.input.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -11,27 +11,27 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Currency_Input extends EE_Select_Input
13 13
 {
14
-    /**
15
-     *
16
-     * @param array $only_specific_currency_codes numerically-indexed array of allowed currency codes.
17
-     *                                            By default, all are allowed
18
-     * @param array $input_settings
19
-     * @throws EE_Error
20
-     * @throws ReflectionException
21
-     */
22
-    public function __construct($only_specific_currency_codes = [], $input_settings = [])
23
-    {
24
-        $query_params = ['order_by' => ['CNT_name' => 'asc']];
25
-        if ($only_specific_currency_codes) {
26
-            $query_params[0]['CNT_cur_code'] = ['IN', $only_specific_currency_codes];
27
-        }
28
-        $all_countries   = EEM_Country::instance()->get_all($query_params);
29
-        $country_options = [];
30
-        foreach ($all_countries as $country) {
31
-            /* @var $country EE_Country */
32
-            $country_options[ $country->currency_code() ] =
33
-                $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
34
-        }
35
-        parent::__construct($country_options, $input_settings);
36
-    }
14
+	/**
15
+	 *
16
+	 * @param array $only_specific_currency_codes numerically-indexed array of allowed currency codes.
17
+	 *                                            By default, all are allowed
18
+	 * @param array $input_settings
19
+	 * @throws EE_Error
20
+	 * @throws ReflectionException
21
+	 */
22
+	public function __construct($only_specific_currency_codes = [], $input_settings = [])
23
+	{
24
+		$query_params = ['order_by' => ['CNT_name' => 'asc']];
25
+		if ($only_specific_currency_codes) {
26
+			$query_params[0]['CNT_cur_code'] = ['IN', $only_specific_currency_codes];
27
+		}
28
+		$all_countries   = EEM_Country::instance()->get_all($query_params);
29
+		$country_options = [];
30
+		foreach ($all_countries as $country) {
31
+			/* @var $country EE_Country */
32
+			$country_options[ $country->currency_code() ] =
33
+				$country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
34
+		}
35
+		parent::__construct($country_options, $input_settings);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@
 block discarded – undo
29 29
         $country_options = [];
30 30
         foreach ($all_countries as $country) {
31 31
             /* @var $country EE_Country */
32
-            $country_options[ $country->currency_code() ] =
33
-                $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
32
+            $country_options[$country->currency_code()] =
33
+                $country->name().": ".$country->currency_name_single()." (".$country->currency_sign().")";
34 34
         }
35 35
         parent::__construct($country_options, $input_settings);
36 36
     }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Form_Input_Base.input.php 2 patches
Indentation   +1262 added lines, -1262 removed lines patch added patch discarded remove patch
@@ -14,1266 +14,1266 @@
 block discarded – undo
14 14
  */
15 15
 abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable
16 16
 {
17
-    /**
18
-     * the input's name attribute
19
-     *
20
-     * @var string
21
-     */
22
-    protected $_html_name;
23
-
24
-    /**
25
-     * id for the html label tag
26
-     *
27
-     * @var string
28
-     */
29
-    protected $_html_label_id;
30
-
31
-    /**
32
-     * class for teh html label tag
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_html_label_class;
37
-
38
-    /**
39
-     * style for teh html label tag
40
-     *
41
-     * @var string
42
-     */
43
-    protected $_html_label_style;
44
-
45
-    /**
46
-     * text to be placed in the html label
47
-     *
48
-     * @var string
49
-     */
50
-    protected $_html_label_text;
51
-
52
-    /**
53
-     * the full html label. If used, all other html_label_* properties are invalid
54
-     *
55
-     * @var string
56
-     */
57
-    protected $_html_label;
58
-
59
-    /**
60
-     * HTML to use for help text (normally placed below form input), in a span which normally
61
-     * has a class of 'description'
62
-     *
63
-     * @var string
64
-     */
65
-    protected $_html_help_text;
66
-
67
-    /**
68
-     * CSS classes for displaying the help span
69
-     *
70
-     * @var string
71
-     */
72
-    protected $_html_help_class = 'description';
73
-
74
-    /**
75
-     * CSS to put in the style attribute on the help span
76
-     *
77
-     * @var string
78
-     */
79
-    protected $_html_help_style;
80
-
81
-    /**
82
-     * Stores whether or not this input's response is required.
83
-     * Because certain styling elements may also want to know that this
84
-     * input is required etc.
85
-     *
86
-     * @var boolean
87
-     */
88
-    protected $_required;
89
-
90
-    /**
91
-     * css class added to required inputs
92
-     *
93
-     * @var string
94
-     */
95
-    protected $_required_css_class = 'ee-required';
96
-
97
-    /**
98
-     * css styles applied to button type inputs
99
-     *
100
-     * @var string
101
-     */
102
-    protected $_button_css_attributes;
103
-
104
-    /**
105
-     * The raw post data submitted for this
106
-     * Generally unsafe for usage in client code
107
-     *
108
-     * @var mixed string or array
109
-     */
110
-    protected $_raw_value;
111
-
112
-    /**
113
-     * Value normalized according to the input's normalization strategy.
114
-     * The normalization strategy dictates whether this is a string, int, float,
115
-     * boolean, or array of any of those.
116
-     *
117
-     * @var mixed
118
-     */
119
-    protected $_normalized_value;
120
-
121
-
122
-    /**
123
-     * Normalized default value either initially set on the input, or provided by calling
124
-     * set_default().
125
-     *
126
-     * @var mixed
127
-     */
128
-    protected $_default;
129
-
130
-    /**
131
-     * Strategy used for displaying this field.
132
-     * Child classes must use _get_display_strategy to access it.
133
-     *
134
-     * @var EE_Display_Strategy_Base
135
-     */
136
-    private $_display_strategy;
137
-
138
-    /**
139
-     * Gets all the validation strategies used on this field
140
-     *
141
-     * @var EE_Validation_Strategy_Base[]
142
-     */
143
-    private $_validation_strategies = [];
144
-
145
-    /**
146
-     * The normalization strategy for this field
147
-     *
148
-     * @var EE_Normalization_Strategy_Base
149
-     */
150
-    private $_normalization_strategy;
151
-
152
-    /**
153
-     * Strategy for removing sensitive data after we're done with the form input
154
-     *
155
-     * @var EE_Sensitive_Data_Removal_Base
156
-     */
157
-    protected $_sensitive_data_removal_strategy;
158
-
159
-    /**
160
-     * Whether this input has been disabled or not.
161
-     * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
162
-     * (Client-side code that wants to dynamically disable it must also add this hidden input).
163
-     * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored.
164
-     * If the input is missing from the request data but the hidden input indicating the input is disabled, then the
165
-     * input is again ignored.
166
-     *
167
-     * @var boolean
168
-     */
169
-    protected $disabled = false;
170
-
171
-    protected array $_data_attributes = [];
172
-
173
-    protected bool $_no_label = false; // if true, then no hrml label will be displayed for this input
174
-
175
-    /**
176
-     * adds a class to the input's container
177
-     *
178
-     * @var string
179
-     */
180
-    protected string $_layout_container_class = '';
181
-
182
-    /**
183
-     * additional HTML to inject into the input's container
184
-     *
185
-     * @var string
186
-     */
187
-    protected string $_extra_container_html = '';
188
-
189
-
190
-    /**
191
-     * @param array                         $input_args       {
192
-     * @type string                         $html_name        the html name for the input
193
-     * @type string                         $html_label_id    the id attribute to give to the html label tag
194
-     * @type string                         $html_label_class the class attribute to give to the html label tag
195
-     * @type string                         $html_label_style the style attribute to give ot teh label tag
196
-     * @type string                         $html_label_text  the text to put in the label tag
197
-     * @type string                         $html_label       the full html label. If used,
198
-     *                                                        all other html_label_* args are invalid
199
-     * @type string                         $html_help_text   text to put in help element
200
-     * @type string                         $html_help_style  style attribute to give to teh help element
201
-     * @type string                         $html_help_class  class attribute to give to the help element
202
-     * @type string                         $default          default value NORMALIZED (eg, if providing the default
203
-     *                                                        for a Yes_No_Input, you should provide TRUE or FALSE, not
204
-     *                                                        '1' or '0')
205
-     * @type EE_Display_Strategy_Base       $display          strategy
206
-     * @type EE_Normalization_Strategy_Base $normalization_strategy
207
-     * @type EE_Validation_Strategy_Base[]  $validation_strategies
208
-     * @type boolean                        $ignore_input     special argument which can be used to avoid adding any
209
-     *                                                        validation strategies, and sets the normalization
210
-     *                                                        strategy to the Null normalization. This is good when you
211
-     *                                                        want the input to be totally ignored server-side (like
212
-     *                                                        when using React.js form inputs)
213
-     *                                                        }
214
-     */
215
-    public function __construct($input_args = [])
216
-    {
217
-        $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
218
-        // the following properties must be cast as arrays
219
-        if (isset($input_args['validation_strategies'])) {
220
-            foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
221
-                if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
222
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
223
-                }
224
-            }
225
-            unset($input_args['validation_strategies']);
226
-        }
227
-        if (isset($input_args['ignore_input'])) {
228
-            $this->_validation_strategies = [];
229
-        }
230
-        // loop thru incoming options
231
-        foreach ($input_args as $key => $value) {
232
-            if ($key === 'disabled') {
233
-                $this->disable($value);
234
-                continue;
235
-            }
236
-            $setter = 'set_' . $key;
237
-            if (method_exists($this, $setter)) {
238
-                $this->$setter($value);
239
-                unset($input_args[$key]);
240
-                continue;
241
-            }
242
-            // add underscore to $key to match property names
243
-            $_key = "_$key";
244
-            if (property_exists($this, $_key)) {
245
-                $this->{$_key} = $value;
246
-                unset($input_args[$key]);
247
-            }
248
-        }
249
-        // ensure that "required" is set correctly
250
-        $this->set_required(
251
-            $this->_required,
252
-            $input_args['required_validation_error_message'] ?? null
253
-        );
254
-        // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
255
-        $this->_display_strategy->_construct_finalize($this);
256
-        foreach ($this->_validation_strategies as $validation_strategy) {
257
-            $validation_strategy->_construct_finalize($this);
258
-        }
259
-        if (isset($input_args['ignore_input'])) {
260
-            $this->_normalization_strategy = new EE_Null_Normalization();
261
-        }
262
-        if (! $this->_normalization_strategy) {
263
-            $this->_normalization_strategy = new EE_Text_Normalization();
264
-        }
265
-        $this->_normalization_strategy->_construct_finalize($this);
266
-        // at least we can use the normalization strategy to populate the default
267
-        if (isset($input_args['default'])) {
268
-            $this->set_default($input_args['default']);
269
-            unset($input_args['default']);
270
-        }
271
-        if (! $this->_sensitive_data_removal_strategy) {
272
-            $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
273
-        }
274
-        $this->_sensitive_data_removal_strategy->_construct_finalize($this);
275
-        parent::__construct($input_args);
276
-    }
277
-
278
-
279
-    /**
280
-     * Sets the html_name to its default value, if none was specified in teh constructor.
281
-     * Calculation involves using the name and the parent's html_name
282
-     *
283
-     * @throws EE_Error
284
-     */
285
-    protected function _set_default_html_name_if_empty()
286
-    {
287
-        if (! $this->_html_name) {
288
-            $this->_html_name = $this->name();
289
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
290
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
291
-            }
292
-        }
293
-    }
294
-
295
-
296
-    /**
297
-     * @param $parent_form_section
298
-     * @param $name
299
-     * @throws EE_Error
300
-     */
301
-    public function _construct_finalize($parent_form_section, $name)
302
-    {
303
-        parent::_construct_finalize($parent_form_section, $name);
304
-        if ($this->_html_label === null && $this->_html_label_text === null && ! $this->_no_label) {
305
-            $this->_html_label_text = ucwords(str_replace("_", " ", $name));
306
-        }
307
-        do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
308
-    }
309
-
310
-
311
-    /**
312
-     * Returns the strategy for displaying this form input. If none is set, throws an exception.
313
-     *
314
-     * @return EE_Display_Strategy_Base
315
-     * @throws EE_Error
316
-     */
317
-    protected function _get_display_strategy()
318
-    {
319
-        $this->ensure_construct_finalized_called();
320
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
321
-            throw new EE_Error(
322
-                sprintf(
323
-                    esc_html__(
324
-                        "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
325
-                        "event_espresso"
326
-                    ),
327
-                    $this->html_name(),
328
-                    $this->html_id()
329
-                )
330
-            );
331
-        } else {
332
-            return $this->_display_strategy;
333
-        }
334
-    }
335
-
336
-
337
-    /**
338
-     * Sets the display strategy.
339
-     *
340
-     * @param EE_Display_Strategy_Base $strategy
341
-     */
342
-    protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
343
-    {
344
-        $this->_display_strategy = $strategy;
345
-    }
346
-
347
-
348
-    /**
349
-     * Sets the sanitization strategy
350
-     *
351
-     * @param EE_Normalization_Strategy_Base $strategy
352
-     */
353
-    protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
354
-    {
355
-        $this->_normalization_strategy = $strategy;
356
-    }
357
-
358
-
359
-    /**
360
-     * Gets sensitive_data_removal_strategy
361
-     *
362
-     * @return EE_Sensitive_Data_Removal_Base
363
-     */
364
-    public function get_sensitive_data_removal_strategy()
365
-    {
366
-        return $this->_sensitive_data_removal_strategy;
367
-    }
368
-
369
-
370
-    /**
371
-     * Sets sensitive_data_removal_strategy
372
-     *
373
-     * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
374
-     * @return void
375
-     */
376
-    public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
377
-    {
378
-        $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
379
-    }
380
-
381
-
382
-    /**
383
-     * Gets the display strategy for this input
384
-     *
385
-     * @return EE_Display_Strategy_Base
386
-     */
387
-    public function get_display_strategy()
388
-    {
389
-        return $this->_display_strategy;
390
-    }
391
-
392
-
393
-    /**
394
-     * Overwrites the display strategy
395
-     *
396
-     * @param EE_Display_Strategy_Base $display_strategy
397
-     */
398
-    public function set_display_strategy($display_strategy)
399
-    {
400
-        $this->_display_strategy = $display_strategy;
401
-        $this->_display_strategy->_construct_finalize($this);
402
-    }
403
-
404
-
405
-    /**
406
-     * Gets the normalization strategy set on this input
407
-     *
408
-     * @return EE_Normalization_Strategy_Base
409
-     */
410
-    public function get_normalization_strategy()
411
-    {
412
-        return $this->_normalization_strategy;
413
-    }
414
-
415
-
416
-    /**
417
-     * Overwrites the normalization strategy
418
-     *
419
-     * @param EE_Normalization_Strategy_Base $normalization_strategy
420
-     */
421
-    public function set_normalization_strategy($normalization_strategy)
422
-    {
423
-        $this->_normalization_strategy = $normalization_strategy;
424
-        $this->_normalization_strategy->_construct_finalize($this);
425
-    }
426
-
427
-
428
-    /**
429
-     * Returns all teh validation strategies which apply to this field, numerically indexed
430
-     *
431
-     * @return EE_Validation_Strategy_Base[]
432
-     */
433
-    public function get_validation_strategies()
434
-    {
435
-        return $this->_validation_strategies;
436
-    }
437
-
438
-
439
-    /**
440
-     * Adds this strategy to the field so it will be used in both JS validation and server-side validation
441
-     *
442
-     * @param EE_Validation_Strategy_Base $validation_strategy
443
-     * @return void
444
-     */
445
-    protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
446
-    {
447
-        $validation_strategy->_construct_finalize($this);
448
-        $this->_validation_strategies[] = $validation_strategy;
449
-    }
450
-
451
-
452
-    /**
453
-     * Adds a new validation strategy onto the form input
454
-     *
455
-     * @param EE_Validation_Strategy_Base $validation_strategy
456
-     * @return void
457
-     */
458
-    public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
459
-    {
460
-        $this->_add_validation_strategy($validation_strategy);
461
-    }
462
-
463
-
464
-    /**
465
-     * The classname of the validation strategy to remove
466
-     *
467
-     * @param string $validation_strategy_classname
468
-     */
469
-    public function remove_validation_strategy($validation_strategy_classname)
470
-    {
471
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
472
-            if (
473
-                $validation_strategy instanceof $validation_strategy_classname
474
-                || is_subclass_of($validation_strategy, $validation_strategy_classname)
475
-            ) {
476
-                unset($this->_validation_strategies[ $key ]);
477
-            }
478
-        }
479
-    }
480
-
481
-
482
-    /**
483
-     * returns true if input employs any of the validation strategy defined by the supplied array of classnames
484
-     *
485
-     * @param array $validation_strategy_classnames
486
-     * @return bool
487
-     */
488
-    public function has_validation_strategy($validation_strategy_classnames)
489
-    {
490
-        $validation_strategy_classnames = is_array($validation_strategy_classnames)
491
-            ? $validation_strategy_classnames
492
-            : [$validation_strategy_classnames];
493
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
494
-            if (in_array($key, $validation_strategy_classnames)) {
495
-                return true;
496
-            }
497
-        }
498
-        return false;
499
-    }
500
-
501
-
502
-    /**
503
-     * Gets the HTML
504
-     *
505
-     * @return string
506
-     */
507
-    public function get_html()
508
-    {
509
-        return $this->_parent_section->get_html_for_input($this);
510
-    }
511
-
512
-
513
-    /**
514
-     * Gets the HTML for the input itself (no label or errors) according to the
515
-     * input's display strategy
516
-     * Makes sure the JS and CSS are enqueued for it
517
-     *
518
-     * @return string
519
-     * @throws EE_Error
520
-     */
521
-    public function get_html_for_input()
522
-    {
523
-        return $this->_form_html_filter
524
-            ? $this->_form_html_filter->filterHtml(
525
-                $this->_get_display_strategy()->display(),
526
-                $this
527
-            )
528
-            : $this->_get_display_strategy()->display();
529
-    }
530
-
531
-
532
-    /**
533
-     * @return string
534
-     */
535
-    public function html_other_attributes()
536
-    {
537
-        EE_Error::doing_it_wrong(
538
-            __METHOD__,
539
-            sprintf(
540
-                esc_html__(
541
-                    'This method is no longer in use. You should replace it by %s',
542
-                    'event_espresso'
543
-                ),
544
-                'EE_Form_Section_Base::other_html_attributes()'
545
-            ),
546
-            '4.10.2.p'
547
-        );
548
-
549
-        return $this->other_html_attributes();
550
-    }
551
-
552
-
553
-    /**
554
-     * @param string $html_other_attributes
555
-     */
556
-    public function set_html_other_attributes($html_other_attributes)
557
-    {
558
-        EE_Error::doing_it_wrong(
559
-            __METHOD__,
560
-            sprintf(
561
-                esc_html__(
562
-                    'This method is no longer in use. You should replace it by %s',
563
-                    'event_espresso'
564
-                ),
565
-                'EE_Form_Section_Base::set_other_html_attributes()'
566
-            ),
567
-            '4.10.2.p'
568
-        );
569
-
570
-        $this->set_other_html_attributes($html_other_attributes);
571
-    }
572
-
573
-
574
-    /**
575
-     * Gets the HTML for displaying the label for this form input
576
-     * according to the form section's layout strategy
577
-     *
578
-     * @return string
579
-     * @throws EE_Error
580
-     */
581
-    public function get_html_for_label()
582
-    {
583
-        return $this->_parent_section->get_layout_strategy()->display_label($this);
584
-    }
585
-
586
-
587
-    /**
588
-     * Gets the HTML for displaying the errors section for this form input
589
-     * according to the form section's layout strategy
590
-     *
591
-     * @return string
592
-     * @throws EE_Error
593
-     */
594
-    public function get_html_for_errors()
595
-    {
596
-        return $this->_parent_section->get_layout_strategy()->display_errors($this);
597
-    }
598
-
599
-
600
-    /**
601
-     * Gets the HTML for displaying the help text for this form input
602
-     * according to the form section's layout strategy
603
-     *
604
-     * @return string
605
-     * @throws EE_Error
606
-     */
607
-    public function get_html_for_help()
608
-    {
609
-        return $this->_parent_section->get_layout_strategy()->display_help_text($this);
610
-    }
611
-
612
-
613
-    /**
614
-     * Validates the input's sanitized value (assumes _sanitize() has already been called)
615
-     * and returns whether or not the form input's submitted value is value
616
-     *
617
-     * @return boolean
618
-     */
619
-    protected function _validate()
620
-    {
621
-        if ($this->isDisabled()) {
622
-            return true;
623
-        }
624
-        foreach ($this->_validation_strategies as $validation_strategy) {
625
-            if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
626
-                try {
627
-                    $validation_strategy->validate($this->normalized_value());
628
-                } catch (EE_Validation_Error $e) {
629
-                    $this->add_validation_error($e);
630
-                }
631
-            }
632
-        }
633
-        if ($this->get_validation_errors()) {
634
-            return false;
635
-        } else {
636
-            return true;
637
-        }
638
-    }
639
-
640
-
641
-    /**
642
-     * Performs basic sanitization on this value. But what sanitization can be performed anyways?
643
-     * This value MIGHT be allowed to have tags, so we can't really remove them.
644
-     *
645
-     * @param string $value
646
-     * @return null|string
647
-     */
648
-    protected function _sanitize($value)
649
-    {
650
-        return $value !== null
651
-            ? stripslashes(html_entity_decode(trim((string) $value)))
652
-            : null;
653
-    }
654
-
655
-
656
-    /**
657
-     * Picks out the form value that relates to this form input,
658
-     * and stores it as the sanitized value on the form input, and sets the normalized value.
659
-     * Returns whether or not any validation errors occurred
660
-     *
661
-     * @param array $req_data
662
-     * @return boolean whether or not there was an error
663
-     * @throws EE_Error
664
-     */
665
-    protected function _normalize($req_data)
666
-    {
667
-        // any existing validation errors don't apply so clear them
668
-        $this->_validation_errors = [];
669
-        // if the input is disabled, ignore whatever input was sent in
670
-        if ($this->isDisabled()) {
671
-            $this->_set_raw_value(null);
672
-            $this->_set_normalized_value($this->get_default());
673
-            return false;
674
-        }
675
-        try {
676
-            $raw_input = $this->find_form_data_for_this_section($req_data);
677
-            // super simple sanitization for now
678
-            if (is_array($raw_input)) {
679
-                $raw_value = [];
680
-                foreach ($raw_input as $key => $value) {
681
-                    $raw_value[ $key ] = $this->_sanitize($value);
682
-                }
683
-                $this->_set_raw_value($raw_value);
684
-            } else {
685
-                $this->_set_raw_value($this->_sanitize($raw_input));
686
-            }
687
-            // we want to mostly leave the input alone in case we need to re-display it to the user
688
-            $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
689
-            return false;
690
-        } catch (EE_Validation_Error $e) {
691
-            $this->add_validation_error($e);
692
-            return true;
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * @return string
699
-     * @throws EE_Error
700
-     */
701
-    public function html_name()
702
-    {
703
-        $this->_set_default_html_name_if_empty();
704
-        return $this->_html_name ?? '';
705
-    }
706
-
707
-
708
-    /**
709
-     * @return string
710
-     * @throws EE_Error
711
-     */
712
-    public function html_label_id()
713
-    {
714
-        return ! empty($this->_html_label_id)
715
-            ? $this->_html_label_id
716
-            : $this->html_id() . '-lbl';
717
-    }
718
-
719
-
720
-    /**
721
-     * @return string
722
-     */
723
-    public function html_label_class()
724
-    {
725
-        return $this->_html_label_class ?? '';
726
-    }
727
-
728
-
729
-    /**
730
-     * @param string $html_class
731
-     */
732
-    public function add_html_label_class(string $html_class)
733
-    {
734
-        $this->_html_label_class .= ' ' . trim($html_class);
735
-    }
736
-
737
-
738
-    /**
739
-     * @return string
740
-     */
741
-    public function html_label_style()
742
-    {
743
-        return $this->_html_label_style ?? '';
744
-    }
745
-
746
-
747
-    /**
748
-     * @return string
749
-     */
750
-    public function html_label_text()
751
-    {
752
-        return $this->_html_label_text ?? '';
753
-    }
754
-
755
-
756
-    /**
757
-     * @return string
758
-     */
759
-    public function html_help_text()
760
-    {
761
-        return $this->_html_help_text ?? '';
762
-    }
763
-
764
-
765
-    /**
766
-     * @return string
767
-     */
768
-    public function html_help_class()
769
-    {
770
-        return $this->_html_help_class ?? '';
771
-    }
772
-
773
-
774
-    /**
775
-     * @return string
776
-     */
777
-    public function html_help_style()
778
-    {
779
-        return $this->_html_style ?? '';
780
-    }
781
-
782
-
783
-    /**
784
-     * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
785
-     * Please note that almost all client code should instead use the normalized_value;
786
-     * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
787
-     * mostly by escaping quotes)
788
-     * Note, we do not store the exact original value sent in the user's request because
789
-     * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
790
-     * in which case, we would have stored the malicious content to our database.
791
-     *
792
-     * @return mixed
793
-     */
794
-    public function raw_value()
795
-    {
796
-        return $this->_raw_value;
797
-    }
798
-
799
-
800
-    /**
801
-     * Returns a string safe to usage in form inputs when displaying, because
802
-     * it escapes all html entities
803
-     *
804
-     * @return string
805
-     */
806
-    public function raw_value_in_form(): string
807
-    {
808
-        return htmlentities((string) $this->raw_value(), ENT_QUOTES, 'UTF-8');
809
-    }
810
-
811
-
812
-    /**
813
-     * returns the value after it's been sanitized, and then converted into it's proper type
814
-     * in PHP. Eg, a string, an int, an array,
815
-     *
816
-     * @return mixed
817
-     */
818
-    public function normalized_value()
819
-    {
820
-        return $this->_normalized_value;
821
-    }
822
-
823
-
824
-    /**
825
-     * Returns the normalized value is a presentable way. By default this is just
826
-     * the normalized value by itself, but it can be overridden for when that's not
827
-     * the best thing to display
828
-     *
829
-     * @return mixed
830
-     */
831
-    public function pretty_value()
832
-    {
833
-        return $this->_normalized_value;
834
-    }
835
-
836
-
837
-    /**
838
-     * When generating the JS for the jquery validation rules like<br>
839
-     * <code>$( "#myform" ).validate({
840
-     * rules: {
841
-     * password: "required",
842
-     * password_again: {
843
-     * equalTo: "#password"
844
-     * }
845
-     * }
846
-     * });</code>
847
-     * if this field had the name 'password_again', it should return
848
-     * <br><code>password_again: {
849
-     * equalTo: "#password"
850
-     * }</code>
851
-     *
852
-     * @return array
853
-     * @throws EE_Error
854
-     */
855
-    public function get_jquery_validation_rules(): array
856
-    {
857
-        $jquery_validation_js    = [];
858
-        $jquery_validation_rules = [];
859
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
860
-            $jquery_validation_rules = array_replace_recursive(
861
-                $jquery_validation_rules,
862
-                $validation_strategy->get_jquery_validation_rule_array()
863
-            );
864
-        }
865
-        if (! empty($jquery_validation_rules)) {
866
-            foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
867
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
868
-            }
869
-        }
870
-        return $jquery_validation_js;
871
-    }
872
-
873
-
874
-    /**
875
-     * Sets the input's default value for use in displaying in the form. Note: value should be
876
-     * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
877
-     *
878
-     * @param mixed $value
879
-     * @return void
880
-     */
881
-    public function set_default($value)
882
-    {
883
-        $this->_default = $value;
884
-        $this->_set_normalized_value($value);
885
-        $this->_set_raw_value($value);
886
-    }
887
-
888
-
889
-    /**
890
-     * Sets the normalized value on this input
891
-     *
892
-     * @param mixed $value
893
-     */
894
-    protected function _set_normalized_value($value)
895
-    {
896
-        $this->_normalized_value = $value;
897
-    }
898
-
899
-
900
-    /**
901
-     * Sets the raw value on this input (ie, exactly as the user submitted it)
902
-     *
903
-     * @param mixed $value
904
-     */
905
-    protected function _set_raw_value($value)
906
-    {
907
-        $this->_raw_value = $this->_normalization_strategy->unnormalize($value);
908
-    }
909
-
910
-
911
-    /**
912
-     * Sets the HTML label text after it has already been defined
913
-     *
914
-     * @param string $label
915
-     * @return void
916
-     */
917
-    public function set_html_label_text($label)
918
-    {
919
-        $this->_html_label_text = $label;
920
-    }
921
-
922
-
923
-    /**
924
-     * Sets whether or not this field is required, and adjusts the validation strategy.
925
-     * If you want to use the EE_Conditionally_Required_Validation_Strategy,
926
-     * please add it as a validation strategy using add_validation_strategy as normal
927
-     *
928
-     * @param boolean $required boolean
929
-     * @param null    $required_text
930
-     */
931
-    public function set_required($required = true, $required_text = null)
932
-    {
933
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
934
-        // whether $required is a string or a boolean, we want to add a required validation strategy
935
-        if ($required) {
936
-            $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
937
-        } else {
938
-            $this->remove_validation_strategy('EE_Required_Validation_Strategy');
939
-        }
940
-        $this->_required = $required;
941
-    }
942
-
943
-
944
-    /**
945
-     * Returns whether or not this field is required
946
-     *
947
-     * @return boolean
948
-     */
949
-    public function required()
950
-    {
951
-        return $this->_required;
952
-    }
953
-
954
-
955
-    /**
956
-     * @param string $required_css_class
957
-     */
958
-    public function set_required_css_class($required_css_class)
959
-    {
960
-        $this->_required_css_class = $required_css_class;
961
-    }
962
-
963
-
964
-    /**
965
-     * @return string
966
-     */
967
-    public function required_css_class()
968
-    {
969
-        return $this->_required_css_class;
970
-    }
971
-
972
-
973
-    /**
974
-     * @param bool $add_required
975
-     * @return string
976
-     */
977
-    public function html_class($add_required = false)
978
-    {
979
-        return $add_required && $this->required()
980
-            ? $this->required_css_class() . ' ' . $this->_html_class
981
-            : $this->_html_class;
982
-    }
983
-
984
-
985
-    /**
986
-     * Sets the help text, in case
987
-     *
988
-     * @param string $text
989
-     */
990
-    public function set_html_help_text($text)
991
-    {
992
-        $this->_html_help_text = $text;
993
-    }
994
-
995
-
996
-    /**
997
-     * Uses the sensitive data removal strategy to remove the sensitive data from this
998
-     * input. If there is any kind of sensitive data removal on this input, we clear
999
-     * out the raw value completely
1000
-     *
1001
-     * @return void
1002
-     */
1003
-    public function clean_sensitive_data()
1004
-    {
1005
-        // if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1006
-        // if we need more logic than this we'll make a strategy for it
1007
-        if (
1008
-            $this->_sensitive_data_removal_strategy
1009
-            && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1010
-        ) {
1011
-            $this->_set_raw_value(null);
1012
-        }
1013
-        // and clean the normalized value according to the appropriate strategy
1014
-        $this->_set_normalized_value(
1015
-            $this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1016
-                $this->_normalized_value
1017
-            )
1018
-        );
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     * @param bool   $primary
1024
-     * @param string $button_size
1025
-     * @param string $other_attributes
1026
-     */
1027
-    public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1028
-    {
1029
-        $button_css_attributes = 'button';
1030
-        $button_css_attributes .= $primary === true
1031
-            ? ' button--primary'
1032
-            : ' button--secondary';
1033
-        switch ($button_size) {
1034
-            case 'xs':
1035
-            case 'extra-small':
1036
-                $button_css_attributes .= ' button-xs';
1037
-                break;
1038
-            case 'sm':
1039
-            case 'small':
1040
-                $button_css_attributes .= ' button-sm';
1041
-                break;
1042
-            case 'lg':
1043
-            case 'large':
1044
-                $button_css_attributes .= ' button-lg';
1045
-                break;
1046
-            case 'block':
1047
-                $button_css_attributes .= ' button-block';
1048
-                break;
1049
-            case 'md':
1050
-            case 'medium':
1051
-            default:
1052
-                $button_css_attributes .= '';
1053
-        }
1054
-        $this->_button_css_attributes .= ! empty($other_attributes)
1055
-            ? $button_css_attributes . ' ' . $other_attributes
1056
-            : $button_css_attributes;
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * @return string
1062
-     */
1063
-    public function button_css_attributes()
1064
-    {
1065
-        if (empty($this->_button_css_attributes)) {
1066
-            $this->set_button_css_attributes();
1067
-        }
1068
-        return $this->_button_css_attributes;
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * find_form_data_for_this_section
1074
-     * using this section's name and its parents, finds the value of the form data that corresponds to it.
1075
-     * For example, if this form section's HTML name is my_form[subform][form_input_1],
1076
-     * then it's value should be in request at request['my_form']['subform']['form_input_1'].
1077
-     * (If that doesn't exist, we also check for this subsection's name
1078
-     * at the TOP LEVEL of the request data. Eg request['form_input_1'].)
1079
-     * This function finds its value in the form.
1080
-     *
1081
-     * @param array $req_data
1082
-     * @return mixed whatever the raw value of this form section is in the request data
1083
-     * @throws EE_Error
1084
-     */
1085
-    public function find_form_data_for_this_section($req_data)
1086
-    {
1087
-        $name_parts = $this->getInputNameParts();
1088
-        // now get the value for the input
1089
-        $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1090
-        // check if this thing's name is at the TOP level of the request data
1091
-        if ($value === null && isset($req_data[ $this->name() ])) {
1092
-            $value = $req_data[ $this->name() ];
1093
-        }
1094
-        return $value;
1095
-    }
1096
-
1097
-
1098
-    /**
1099
-     * If this input's name is something like "foo[bar][baz]"
1100
-     * returns an array like `array('foo','bar',baz')`
1101
-     *
1102
-     * @return array
1103
-     * @throws EE_Error
1104
-     */
1105
-    protected function getInputNameParts()
1106
-    {
1107
-        // break up the html name by "[]"
1108
-        if (strpos($this->html_name(), '[') !== false) {
1109
-            $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1110
-        } else {
1111
-            $before_any_brackets = $this->html_name();
1112
-        }
1113
-        // grab all of the segments
1114
-        preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1115
-        if (isset($matches[1]) && is_array($matches[1])) {
1116
-            $name_parts = $matches[1];
1117
-            array_unshift($name_parts, $before_any_brackets);
1118
-        } else {
1119
-            $name_parts = [$before_any_brackets];
1120
-        }
1121
-        return $name_parts;
1122
-    }
1123
-
1124
-
1125
-    /**
1126
-     * @param array $html_name_parts
1127
-     * @param array $req_data
1128
-     * @return array | NULL
1129
-     */
1130
-    public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1131
-    {
1132
-        $first_part_to_consider = array_shift($html_name_parts);
1133
-        if (isset($req_data[ $first_part_to_consider ])) {
1134
-            if (empty($html_name_parts)) {
1135
-                return $req_data[ $first_part_to_consider ];
1136
-            } else {
1137
-                return $this->findRequestForSectionUsingNameParts(
1138
-                    $html_name_parts,
1139
-                    $req_data[ $first_part_to_consider ]
1140
-                );
1141
-            }
1142
-        }
1143
-        return null;
1144
-    }
1145
-
1146
-
1147
-    /**
1148
-     * Checks if this form input's data is in the request data
1149
-     *
1150
-     * @param array $req_data
1151
-     * @return boolean
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function form_data_present_in($req_data = null)
1155
-    {
1156
-        if ($req_data === null) {
1157
-            /** @var RequestInterface $request */
1158
-            $request  = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1159
-            $req_data = $request->postParams();
1160
-        }
1161
-
1162
-        return $this->find_form_data_for_this_section($req_data) !== null;
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * Overrides parent to add js data from validation and display strategies
1168
-     *
1169
-     * @param array $form_other_js_data
1170
-     * @return array
1171
-     */
1172
-    public function get_other_js_data($form_other_js_data = [])
1173
-    {
1174
-        return $this->get_other_js_data_from_strategies($form_other_js_data);
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * Gets other JS data for localization from this input's strategies, like
1180
-     * the validation strategies and the display strategy
1181
-     *
1182
-     * @param array $form_other_js_data
1183
-     * @return array
1184
-     */
1185
-    public function get_other_js_data_from_strategies($form_other_js_data = [])
1186
-    {
1187
-        $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1188
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1189
-            $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1190
-        }
1191
-        return $form_other_js_data;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1197
-     *
1198
-     * @return void
1199
-     */
1200
-    public function enqueue_js()
1201
-    {
1202
-        // ask our display strategy and validation strategies if they have js to enqueue
1203
-        $this->enqueue_js_from_strategies();
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * Tells strategies when its ok to enqueue their js and css
1209
-     *
1210
-     * @return void
1211
-     */
1212
-    public function enqueue_js_from_strategies()
1213
-    {
1214
-        $this->get_display_strategy()->enqueue_js();
1215
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1216
-            $validation_strategy->enqueue_js();
1217
-        }
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * Gets the default value set on the input (not the current value, which may have been
1223
-     * changed because of a form submission). If no default was set, this us null.
1224
-     *
1225
-     * @return mixed
1226
-     */
1227
-    public function get_default()
1228
-    {
1229
-        return $this->_default;
1230
-    }
1231
-
1232
-
1233
-    /**
1234
-     * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1235
-     * and server-side if any input was received it will be ignored
1236
-     */
1237
-    public function disable($disable = true)
1238
-    {
1239
-        $disabled_attribute = ' disabled="disabled"';
1240
-        $this->disabled     = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1241
-        if ($this->disabled) {
1242
-            if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1243
-                $this->_other_html_attributes .= $disabled_attribute;
1244
-            }
1245
-            $this->_set_normalized_value($this->get_default());
1246
-        } else {
1247
-            $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1248
-        }
1249
-    }
1250
-
1251
-
1252
-    /**
1253
-     * Returns whether this input is currently disabled.
1254
-     *
1255
-     * @return bool
1256
-     */
1257
-    public function isDisabled(): bool
1258
-    {
1259
-        return $this->disabled;
1260
-    }
1261
-
1262
-
1263
-    public function dataAttributes(): array
1264
-    {
1265
-        return $this->_data_attributes;
1266
-    }
1267
-
1268
-
1269
-    public function layoutContainerClass(): string
1270
-    {
1271
-        return $this->_layout_container_class;
1272
-    }
1273
-
1274
-
1275
-    public function extraContainerHtml(): string
1276
-    {
1277
-        return $this->_extra_container_html;
1278
-    }
17
+	/**
18
+	 * the input's name attribute
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected $_html_name;
23
+
24
+	/**
25
+	 * id for the html label tag
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $_html_label_id;
30
+
31
+	/**
32
+	 * class for teh html label tag
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_html_label_class;
37
+
38
+	/**
39
+	 * style for teh html label tag
40
+	 *
41
+	 * @var string
42
+	 */
43
+	protected $_html_label_style;
44
+
45
+	/**
46
+	 * text to be placed in the html label
47
+	 *
48
+	 * @var string
49
+	 */
50
+	protected $_html_label_text;
51
+
52
+	/**
53
+	 * the full html label. If used, all other html_label_* properties are invalid
54
+	 *
55
+	 * @var string
56
+	 */
57
+	protected $_html_label;
58
+
59
+	/**
60
+	 * HTML to use for help text (normally placed below form input), in a span which normally
61
+	 * has a class of 'description'
62
+	 *
63
+	 * @var string
64
+	 */
65
+	protected $_html_help_text;
66
+
67
+	/**
68
+	 * CSS classes for displaying the help span
69
+	 *
70
+	 * @var string
71
+	 */
72
+	protected $_html_help_class = 'description';
73
+
74
+	/**
75
+	 * CSS to put in the style attribute on the help span
76
+	 *
77
+	 * @var string
78
+	 */
79
+	protected $_html_help_style;
80
+
81
+	/**
82
+	 * Stores whether or not this input's response is required.
83
+	 * Because certain styling elements may also want to know that this
84
+	 * input is required etc.
85
+	 *
86
+	 * @var boolean
87
+	 */
88
+	protected $_required;
89
+
90
+	/**
91
+	 * css class added to required inputs
92
+	 *
93
+	 * @var string
94
+	 */
95
+	protected $_required_css_class = 'ee-required';
96
+
97
+	/**
98
+	 * css styles applied to button type inputs
99
+	 *
100
+	 * @var string
101
+	 */
102
+	protected $_button_css_attributes;
103
+
104
+	/**
105
+	 * The raw post data submitted for this
106
+	 * Generally unsafe for usage in client code
107
+	 *
108
+	 * @var mixed string or array
109
+	 */
110
+	protected $_raw_value;
111
+
112
+	/**
113
+	 * Value normalized according to the input's normalization strategy.
114
+	 * The normalization strategy dictates whether this is a string, int, float,
115
+	 * boolean, or array of any of those.
116
+	 *
117
+	 * @var mixed
118
+	 */
119
+	protected $_normalized_value;
120
+
121
+
122
+	/**
123
+	 * Normalized default value either initially set on the input, or provided by calling
124
+	 * set_default().
125
+	 *
126
+	 * @var mixed
127
+	 */
128
+	protected $_default;
129
+
130
+	/**
131
+	 * Strategy used for displaying this field.
132
+	 * Child classes must use _get_display_strategy to access it.
133
+	 *
134
+	 * @var EE_Display_Strategy_Base
135
+	 */
136
+	private $_display_strategy;
137
+
138
+	/**
139
+	 * Gets all the validation strategies used on this field
140
+	 *
141
+	 * @var EE_Validation_Strategy_Base[]
142
+	 */
143
+	private $_validation_strategies = [];
144
+
145
+	/**
146
+	 * The normalization strategy for this field
147
+	 *
148
+	 * @var EE_Normalization_Strategy_Base
149
+	 */
150
+	private $_normalization_strategy;
151
+
152
+	/**
153
+	 * Strategy for removing sensitive data after we're done with the form input
154
+	 *
155
+	 * @var EE_Sensitive_Data_Removal_Base
156
+	 */
157
+	protected $_sensitive_data_removal_strategy;
158
+
159
+	/**
160
+	 * Whether this input has been disabled or not.
161
+	 * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
162
+	 * (Client-side code that wants to dynamically disable it must also add this hidden input).
163
+	 * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored.
164
+	 * If the input is missing from the request data but the hidden input indicating the input is disabled, then the
165
+	 * input is again ignored.
166
+	 *
167
+	 * @var boolean
168
+	 */
169
+	protected $disabled = false;
170
+
171
+	protected array $_data_attributes = [];
172
+
173
+	protected bool $_no_label = false; // if true, then no hrml label will be displayed for this input
174
+
175
+	/**
176
+	 * adds a class to the input's container
177
+	 *
178
+	 * @var string
179
+	 */
180
+	protected string $_layout_container_class = '';
181
+
182
+	/**
183
+	 * additional HTML to inject into the input's container
184
+	 *
185
+	 * @var string
186
+	 */
187
+	protected string $_extra_container_html = '';
188
+
189
+
190
+	/**
191
+	 * @param array                         $input_args       {
192
+	 * @type string                         $html_name        the html name for the input
193
+	 * @type string                         $html_label_id    the id attribute to give to the html label tag
194
+	 * @type string                         $html_label_class the class attribute to give to the html label tag
195
+	 * @type string                         $html_label_style the style attribute to give ot teh label tag
196
+	 * @type string                         $html_label_text  the text to put in the label tag
197
+	 * @type string                         $html_label       the full html label. If used,
198
+	 *                                                        all other html_label_* args are invalid
199
+	 * @type string                         $html_help_text   text to put in help element
200
+	 * @type string                         $html_help_style  style attribute to give to teh help element
201
+	 * @type string                         $html_help_class  class attribute to give to the help element
202
+	 * @type string                         $default          default value NORMALIZED (eg, if providing the default
203
+	 *                                                        for a Yes_No_Input, you should provide TRUE or FALSE, not
204
+	 *                                                        '1' or '0')
205
+	 * @type EE_Display_Strategy_Base       $display          strategy
206
+	 * @type EE_Normalization_Strategy_Base $normalization_strategy
207
+	 * @type EE_Validation_Strategy_Base[]  $validation_strategies
208
+	 * @type boolean                        $ignore_input     special argument which can be used to avoid adding any
209
+	 *                                                        validation strategies, and sets the normalization
210
+	 *                                                        strategy to the Null normalization. This is good when you
211
+	 *                                                        want the input to be totally ignored server-side (like
212
+	 *                                                        when using React.js form inputs)
213
+	 *                                                        }
214
+	 */
215
+	public function __construct($input_args = [])
216
+	{
217
+		$input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
218
+		// the following properties must be cast as arrays
219
+		if (isset($input_args['validation_strategies'])) {
220
+			foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
221
+				if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
222
+					$this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
223
+				}
224
+			}
225
+			unset($input_args['validation_strategies']);
226
+		}
227
+		if (isset($input_args['ignore_input'])) {
228
+			$this->_validation_strategies = [];
229
+		}
230
+		// loop thru incoming options
231
+		foreach ($input_args as $key => $value) {
232
+			if ($key === 'disabled') {
233
+				$this->disable($value);
234
+				continue;
235
+			}
236
+			$setter = 'set_' . $key;
237
+			if (method_exists($this, $setter)) {
238
+				$this->$setter($value);
239
+				unset($input_args[$key]);
240
+				continue;
241
+			}
242
+			// add underscore to $key to match property names
243
+			$_key = "_$key";
244
+			if (property_exists($this, $_key)) {
245
+				$this->{$_key} = $value;
246
+				unset($input_args[$key]);
247
+			}
248
+		}
249
+		// ensure that "required" is set correctly
250
+		$this->set_required(
251
+			$this->_required,
252
+			$input_args['required_validation_error_message'] ?? null
253
+		);
254
+		// $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
255
+		$this->_display_strategy->_construct_finalize($this);
256
+		foreach ($this->_validation_strategies as $validation_strategy) {
257
+			$validation_strategy->_construct_finalize($this);
258
+		}
259
+		if (isset($input_args['ignore_input'])) {
260
+			$this->_normalization_strategy = new EE_Null_Normalization();
261
+		}
262
+		if (! $this->_normalization_strategy) {
263
+			$this->_normalization_strategy = new EE_Text_Normalization();
264
+		}
265
+		$this->_normalization_strategy->_construct_finalize($this);
266
+		// at least we can use the normalization strategy to populate the default
267
+		if (isset($input_args['default'])) {
268
+			$this->set_default($input_args['default']);
269
+			unset($input_args['default']);
270
+		}
271
+		if (! $this->_sensitive_data_removal_strategy) {
272
+			$this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
273
+		}
274
+		$this->_sensitive_data_removal_strategy->_construct_finalize($this);
275
+		parent::__construct($input_args);
276
+	}
277
+
278
+
279
+	/**
280
+	 * Sets the html_name to its default value, if none was specified in teh constructor.
281
+	 * Calculation involves using the name and the parent's html_name
282
+	 *
283
+	 * @throws EE_Error
284
+	 */
285
+	protected function _set_default_html_name_if_empty()
286
+	{
287
+		if (! $this->_html_name) {
288
+			$this->_html_name = $this->name();
289
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
290
+				$this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
291
+			}
292
+		}
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param $parent_form_section
298
+	 * @param $name
299
+	 * @throws EE_Error
300
+	 */
301
+	public function _construct_finalize($parent_form_section, $name)
302
+	{
303
+		parent::_construct_finalize($parent_form_section, $name);
304
+		if ($this->_html_label === null && $this->_html_label_text === null && ! $this->_no_label) {
305
+			$this->_html_label_text = ucwords(str_replace("_", " ", $name));
306
+		}
307
+		do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Returns the strategy for displaying this form input. If none is set, throws an exception.
313
+	 *
314
+	 * @return EE_Display_Strategy_Base
315
+	 * @throws EE_Error
316
+	 */
317
+	protected function _get_display_strategy()
318
+	{
319
+		$this->ensure_construct_finalized_called();
320
+		if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
321
+			throw new EE_Error(
322
+				sprintf(
323
+					esc_html__(
324
+						"Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
325
+						"event_espresso"
326
+					),
327
+					$this->html_name(),
328
+					$this->html_id()
329
+				)
330
+			);
331
+		} else {
332
+			return $this->_display_strategy;
333
+		}
334
+	}
335
+
336
+
337
+	/**
338
+	 * Sets the display strategy.
339
+	 *
340
+	 * @param EE_Display_Strategy_Base $strategy
341
+	 */
342
+	protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
343
+	{
344
+		$this->_display_strategy = $strategy;
345
+	}
346
+
347
+
348
+	/**
349
+	 * Sets the sanitization strategy
350
+	 *
351
+	 * @param EE_Normalization_Strategy_Base $strategy
352
+	 */
353
+	protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
354
+	{
355
+		$this->_normalization_strategy = $strategy;
356
+	}
357
+
358
+
359
+	/**
360
+	 * Gets sensitive_data_removal_strategy
361
+	 *
362
+	 * @return EE_Sensitive_Data_Removal_Base
363
+	 */
364
+	public function get_sensitive_data_removal_strategy()
365
+	{
366
+		return $this->_sensitive_data_removal_strategy;
367
+	}
368
+
369
+
370
+	/**
371
+	 * Sets sensitive_data_removal_strategy
372
+	 *
373
+	 * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
374
+	 * @return void
375
+	 */
376
+	public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
377
+	{
378
+		$this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
379
+	}
380
+
381
+
382
+	/**
383
+	 * Gets the display strategy for this input
384
+	 *
385
+	 * @return EE_Display_Strategy_Base
386
+	 */
387
+	public function get_display_strategy()
388
+	{
389
+		return $this->_display_strategy;
390
+	}
391
+
392
+
393
+	/**
394
+	 * Overwrites the display strategy
395
+	 *
396
+	 * @param EE_Display_Strategy_Base $display_strategy
397
+	 */
398
+	public function set_display_strategy($display_strategy)
399
+	{
400
+		$this->_display_strategy = $display_strategy;
401
+		$this->_display_strategy->_construct_finalize($this);
402
+	}
403
+
404
+
405
+	/**
406
+	 * Gets the normalization strategy set on this input
407
+	 *
408
+	 * @return EE_Normalization_Strategy_Base
409
+	 */
410
+	public function get_normalization_strategy()
411
+	{
412
+		return $this->_normalization_strategy;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Overwrites the normalization strategy
418
+	 *
419
+	 * @param EE_Normalization_Strategy_Base $normalization_strategy
420
+	 */
421
+	public function set_normalization_strategy($normalization_strategy)
422
+	{
423
+		$this->_normalization_strategy = $normalization_strategy;
424
+		$this->_normalization_strategy->_construct_finalize($this);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Returns all teh validation strategies which apply to this field, numerically indexed
430
+	 *
431
+	 * @return EE_Validation_Strategy_Base[]
432
+	 */
433
+	public function get_validation_strategies()
434
+	{
435
+		return $this->_validation_strategies;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Adds this strategy to the field so it will be used in both JS validation and server-side validation
441
+	 *
442
+	 * @param EE_Validation_Strategy_Base $validation_strategy
443
+	 * @return void
444
+	 */
445
+	protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
446
+	{
447
+		$validation_strategy->_construct_finalize($this);
448
+		$this->_validation_strategies[] = $validation_strategy;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Adds a new validation strategy onto the form input
454
+	 *
455
+	 * @param EE_Validation_Strategy_Base $validation_strategy
456
+	 * @return void
457
+	 */
458
+	public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
459
+	{
460
+		$this->_add_validation_strategy($validation_strategy);
461
+	}
462
+
463
+
464
+	/**
465
+	 * The classname of the validation strategy to remove
466
+	 *
467
+	 * @param string $validation_strategy_classname
468
+	 */
469
+	public function remove_validation_strategy($validation_strategy_classname)
470
+	{
471
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
472
+			if (
473
+				$validation_strategy instanceof $validation_strategy_classname
474
+				|| is_subclass_of($validation_strategy, $validation_strategy_classname)
475
+			) {
476
+				unset($this->_validation_strategies[ $key ]);
477
+			}
478
+		}
479
+	}
480
+
481
+
482
+	/**
483
+	 * returns true if input employs any of the validation strategy defined by the supplied array of classnames
484
+	 *
485
+	 * @param array $validation_strategy_classnames
486
+	 * @return bool
487
+	 */
488
+	public function has_validation_strategy($validation_strategy_classnames)
489
+	{
490
+		$validation_strategy_classnames = is_array($validation_strategy_classnames)
491
+			? $validation_strategy_classnames
492
+			: [$validation_strategy_classnames];
493
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
494
+			if (in_array($key, $validation_strategy_classnames)) {
495
+				return true;
496
+			}
497
+		}
498
+		return false;
499
+	}
500
+
501
+
502
+	/**
503
+	 * Gets the HTML
504
+	 *
505
+	 * @return string
506
+	 */
507
+	public function get_html()
508
+	{
509
+		return $this->_parent_section->get_html_for_input($this);
510
+	}
511
+
512
+
513
+	/**
514
+	 * Gets the HTML for the input itself (no label or errors) according to the
515
+	 * input's display strategy
516
+	 * Makes sure the JS and CSS are enqueued for it
517
+	 *
518
+	 * @return string
519
+	 * @throws EE_Error
520
+	 */
521
+	public function get_html_for_input()
522
+	{
523
+		return $this->_form_html_filter
524
+			? $this->_form_html_filter->filterHtml(
525
+				$this->_get_display_strategy()->display(),
526
+				$this
527
+			)
528
+			: $this->_get_display_strategy()->display();
529
+	}
530
+
531
+
532
+	/**
533
+	 * @return string
534
+	 */
535
+	public function html_other_attributes()
536
+	{
537
+		EE_Error::doing_it_wrong(
538
+			__METHOD__,
539
+			sprintf(
540
+				esc_html__(
541
+					'This method is no longer in use. You should replace it by %s',
542
+					'event_espresso'
543
+				),
544
+				'EE_Form_Section_Base::other_html_attributes()'
545
+			),
546
+			'4.10.2.p'
547
+		);
548
+
549
+		return $this->other_html_attributes();
550
+	}
551
+
552
+
553
+	/**
554
+	 * @param string $html_other_attributes
555
+	 */
556
+	public function set_html_other_attributes($html_other_attributes)
557
+	{
558
+		EE_Error::doing_it_wrong(
559
+			__METHOD__,
560
+			sprintf(
561
+				esc_html__(
562
+					'This method is no longer in use. You should replace it by %s',
563
+					'event_espresso'
564
+				),
565
+				'EE_Form_Section_Base::set_other_html_attributes()'
566
+			),
567
+			'4.10.2.p'
568
+		);
569
+
570
+		$this->set_other_html_attributes($html_other_attributes);
571
+	}
572
+
573
+
574
+	/**
575
+	 * Gets the HTML for displaying the label for this form input
576
+	 * according to the form section's layout strategy
577
+	 *
578
+	 * @return string
579
+	 * @throws EE_Error
580
+	 */
581
+	public function get_html_for_label()
582
+	{
583
+		return $this->_parent_section->get_layout_strategy()->display_label($this);
584
+	}
585
+
586
+
587
+	/**
588
+	 * Gets the HTML for displaying the errors section for this form input
589
+	 * according to the form section's layout strategy
590
+	 *
591
+	 * @return string
592
+	 * @throws EE_Error
593
+	 */
594
+	public function get_html_for_errors()
595
+	{
596
+		return $this->_parent_section->get_layout_strategy()->display_errors($this);
597
+	}
598
+
599
+
600
+	/**
601
+	 * Gets the HTML for displaying the help text for this form input
602
+	 * according to the form section's layout strategy
603
+	 *
604
+	 * @return string
605
+	 * @throws EE_Error
606
+	 */
607
+	public function get_html_for_help()
608
+	{
609
+		return $this->_parent_section->get_layout_strategy()->display_help_text($this);
610
+	}
611
+
612
+
613
+	/**
614
+	 * Validates the input's sanitized value (assumes _sanitize() has already been called)
615
+	 * and returns whether or not the form input's submitted value is value
616
+	 *
617
+	 * @return boolean
618
+	 */
619
+	protected function _validate()
620
+	{
621
+		if ($this->isDisabled()) {
622
+			return true;
623
+		}
624
+		foreach ($this->_validation_strategies as $validation_strategy) {
625
+			if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
626
+				try {
627
+					$validation_strategy->validate($this->normalized_value());
628
+				} catch (EE_Validation_Error $e) {
629
+					$this->add_validation_error($e);
630
+				}
631
+			}
632
+		}
633
+		if ($this->get_validation_errors()) {
634
+			return false;
635
+		} else {
636
+			return true;
637
+		}
638
+	}
639
+
640
+
641
+	/**
642
+	 * Performs basic sanitization on this value. But what sanitization can be performed anyways?
643
+	 * This value MIGHT be allowed to have tags, so we can't really remove them.
644
+	 *
645
+	 * @param string $value
646
+	 * @return null|string
647
+	 */
648
+	protected function _sanitize($value)
649
+	{
650
+		return $value !== null
651
+			? stripslashes(html_entity_decode(trim((string) $value)))
652
+			: null;
653
+	}
654
+
655
+
656
+	/**
657
+	 * Picks out the form value that relates to this form input,
658
+	 * and stores it as the sanitized value on the form input, and sets the normalized value.
659
+	 * Returns whether or not any validation errors occurred
660
+	 *
661
+	 * @param array $req_data
662
+	 * @return boolean whether or not there was an error
663
+	 * @throws EE_Error
664
+	 */
665
+	protected function _normalize($req_data)
666
+	{
667
+		// any existing validation errors don't apply so clear them
668
+		$this->_validation_errors = [];
669
+		// if the input is disabled, ignore whatever input was sent in
670
+		if ($this->isDisabled()) {
671
+			$this->_set_raw_value(null);
672
+			$this->_set_normalized_value($this->get_default());
673
+			return false;
674
+		}
675
+		try {
676
+			$raw_input = $this->find_form_data_for_this_section($req_data);
677
+			// super simple sanitization for now
678
+			if (is_array($raw_input)) {
679
+				$raw_value = [];
680
+				foreach ($raw_input as $key => $value) {
681
+					$raw_value[ $key ] = $this->_sanitize($value);
682
+				}
683
+				$this->_set_raw_value($raw_value);
684
+			} else {
685
+				$this->_set_raw_value($this->_sanitize($raw_input));
686
+			}
687
+			// we want to mostly leave the input alone in case we need to re-display it to the user
688
+			$this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
689
+			return false;
690
+		} catch (EE_Validation_Error $e) {
691
+			$this->add_validation_error($e);
692
+			return true;
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * @return string
699
+	 * @throws EE_Error
700
+	 */
701
+	public function html_name()
702
+	{
703
+		$this->_set_default_html_name_if_empty();
704
+		return $this->_html_name ?? '';
705
+	}
706
+
707
+
708
+	/**
709
+	 * @return string
710
+	 * @throws EE_Error
711
+	 */
712
+	public function html_label_id()
713
+	{
714
+		return ! empty($this->_html_label_id)
715
+			? $this->_html_label_id
716
+			: $this->html_id() . '-lbl';
717
+	}
718
+
719
+
720
+	/**
721
+	 * @return string
722
+	 */
723
+	public function html_label_class()
724
+	{
725
+		return $this->_html_label_class ?? '';
726
+	}
727
+
728
+
729
+	/**
730
+	 * @param string $html_class
731
+	 */
732
+	public function add_html_label_class(string $html_class)
733
+	{
734
+		$this->_html_label_class .= ' ' . trim($html_class);
735
+	}
736
+
737
+
738
+	/**
739
+	 * @return string
740
+	 */
741
+	public function html_label_style()
742
+	{
743
+		return $this->_html_label_style ?? '';
744
+	}
745
+
746
+
747
+	/**
748
+	 * @return string
749
+	 */
750
+	public function html_label_text()
751
+	{
752
+		return $this->_html_label_text ?? '';
753
+	}
754
+
755
+
756
+	/**
757
+	 * @return string
758
+	 */
759
+	public function html_help_text()
760
+	{
761
+		return $this->_html_help_text ?? '';
762
+	}
763
+
764
+
765
+	/**
766
+	 * @return string
767
+	 */
768
+	public function html_help_class()
769
+	{
770
+		return $this->_html_help_class ?? '';
771
+	}
772
+
773
+
774
+	/**
775
+	 * @return string
776
+	 */
777
+	public function html_help_style()
778
+	{
779
+		return $this->_html_style ?? '';
780
+	}
781
+
782
+
783
+	/**
784
+	 * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
785
+	 * Please note that almost all client code should instead use the normalized_value;
786
+	 * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
787
+	 * mostly by escaping quotes)
788
+	 * Note, we do not store the exact original value sent in the user's request because
789
+	 * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
790
+	 * in which case, we would have stored the malicious content to our database.
791
+	 *
792
+	 * @return mixed
793
+	 */
794
+	public function raw_value()
795
+	{
796
+		return $this->_raw_value;
797
+	}
798
+
799
+
800
+	/**
801
+	 * Returns a string safe to usage in form inputs when displaying, because
802
+	 * it escapes all html entities
803
+	 *
804
+	 * @return string
805
+	 */
806
+	public function raw_value_in_form(): string
807
+	{
808
+		return htmlentities((string) $this->raw_value(), ENT_QUOTES, 'UTF-8');
809
+	}
810
+
811
+
812
+	/**
813
+	 * returns the value after it's been sanitized, and then converted into it's proper type
814
+	 * in PHP. Eg, a string, an int, an array,
815
+	 *
816
+	 * @return mixed
817
+	 */
818
+	public function normalized_value()
819
+	{
820
+		return $this->_normalized_value;
821
+	}
822
+
823
+
824
+	/**
825
+	 * Returns the normalized value is a presentable way. By default this is just
826
+	 * the normalized value by itself, but it can be overridden for when that's not
827
+	 * the best thing to display
828
+	 *
829
+	 * @return mixed
830
+	 */
831
+	public function pretty_value()
832
+	{
833
+		return $this->_normalized_value;
834
+	}
835
+
836
+
837
+	/**
838
+	 * When generating the JS for the jquery validation rules like<br>
839
+	 * <code>$( "#myform" ).validate({
840
+	 * rules: {
841
+	 * password: "required",
842
+	 * password_again: {
843
+	 * equalTo: "#password"
844
+	 * }
845
+	 * }
846
+	 * });</code>
847
+	 * if this field had the name 'password_again', it should return
848
+	 * <br><code>password_again: {
849
+	 * equalTo: "#password"
850
+	 * }</code>
851
+	 *
852
+	 * @return array
853
+	 * @throws EE_Error
854
+	 */
855
+	public function get_jquery_validation_rules(): array
856
+	{
857
+		$jquery_validation_js    = [];
858
+		$jquery_validation_rules = [];
859
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
860
+			$jquery_validation_rules = array_replace_recursive(
861
+				$jquery_validation_rules,
862
+				$validation_strategy->get_jquery_validation_rule_array()
863
+			);
864
+		}
865
+		if (! empty($jquery_validation_rules)) {
866
+			foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
867
+				$jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
868
+			}
869
+		}
870
+		return $jquery_validation_js;
871
+	}
872
+
873
+
874
+	/**
875
+	 * Sets the input's default value for use in displaying in the form. Note: value should be
876
+	 * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
877
+	 *
878
+	 * @param mixed $value
879
+	 * @return void
880
+	 */
881
+	public function set_default($value)
882
+	{
883
+		$this->_default = $value;
884
+		$this->_set_normalized_value($value);
885
+		$this->_set_raw_value($value);
886
+	}
887
+
888
+
889
+	/**
890
+	 * Sets the normalized value on this input
891
+	 *
892
+	 * @param mixed $value
893
+	 */
894
+	protected function _set_normalized_value($value)
895
+	{
896
+		$this->_normalized_value = $value;
897
+	}
898
+
899
+
900
+	/**
901
+	 * Sets the raw value on this input (ie, exactly as the user submitted it)
902
+	 *
903
+	 * @param mixed $value
904
+	 */
905
+	protected function _set_raw_value($value)
906
+	{
907
+		$this->_raw_value = $this->_normalization_strategy->unnormalize($value);
908
+	}
909
+
910
+
911
+	/**
912
+	 * Sets the HTML label text after it has already been defined
913
+	 *
914
+	 * @param string $label
915
+	 * @return void
916
+	 */
917
+	public function set_html_label_text($label)
918
+	{
919
+		$this->_html_label_text = $label;
920
+	}
921
+
922
+
923
+	/**
924
+	 * Sets whether or not this field is required, and adjusts the validation strategy.
925
+	 * If you want to use the EE_Conditionally_Required_Validation_Strategy,
926
+	 * please add it as a validation strategy using add_validation_strategy as normal
927
+	 *
928
+	 * @param boolean $required boolean
929
+	 * @param null    $required_text
930
+	 */
931
+	public function set_required($required = true, $required_text = null)
932
+	{
933
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
934
+		// whether $required is a string or a boolean, we want to add a required validation strategy
935
+		if ($required) {
936
+			$this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
937
+		} else {
938
+			$this->remove_validation_strategy('EE_Required_Validation_Strategy');
939
+		}
940
+		$this->_required = $required;
941
+	}
942
+
943
+
944
+	/**
945
+	 * Returns whether or not this field is required
946
+	 *
947
+	 * @return boolean
948
+	 */
949
+	public function required()
950
+	{
951
+		return $this->_required;
952
+	}
953
+
954
+
955
+	/**
956
+	 * @param string $required_css_class
957
+	 */
958
+	public function set_required_css_class($required_css_class)
959
+	{
960
+		$this->_required_css_class = $required_css_class;
961
+	}
962
+
963
+
964
+	/**
965
+	 * @return string
966
+	 */
967
+	public function required_css_class()
968
+	{
969
+		return $this->_required_css_class;
970
+	}
971
+
972
+
973
+	/**
974
+	 * @param bool $add_required
975
+	 * @return string
976
+	 */
977
+	public function html_class($add_required = false)
978
+	{
979
+		return $add_required && $this->required()
980
+			? $this->required_css_class() . ' ' . $this->_html_class
981
+			: $this->_html_class;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Sets the help text, in case
987
+	 *
988
+	 * @param string $text
989
+	 */
990
+	public function set_html_help_text($text)
991
+	{
992
+		$this->_html_help_text = $text;
993
+	}
994
+
995
+
996
+	/**
997
+	 * Uses the sensitive data removal strategy to remove the sensitive data from this
998
+	 * input. If there is any kind of sensitive data removal on this input, we clear
999
+	 * out the raw value completely
1000
+	 *
1001
+	 * @return void
1002
+	 */
1003
+	public function clean_sensitive_data()
1004
+	{
1005
+		// if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1006
+		// if we need more logic than this we'll make a strategy for it
1007
+		if (
1008
+			$this->_sensitive_data_removal_strategy
1009
+			&& ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1010
+		) {
1011
+			$this->_set_raw_value(null);
1012
+		}
1013
+		// and clean the normalized value according to the appropriate strategy
1014
+		$this->_set_normalized_value(
1015
+			$this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1016
+				$this->_normalized_value
1017
+			)
1018
+		);
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 * @param bool   $primary
1024
+	 * @param string $button_size
1025
+	 * @param string $other_attributes
1026
+	 */
1027
+	public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1028
+	{
1029
+		$button_css_attributes = 'button';
1030
+		$button_css_attributes .= $primary === true
1031
+			? ' button--primary'
1032
+			: ' button--secondary';
1033
+		switch ($button_size) {
1034
+			case 'xs':
1035
+			case 'extra-small':
1036
+				$button_css_attributes .= ' button-xs';
1037
+				break;
1038
+			case 'sm':
1039
+			case 'small':
1040
+				$button_css_attributes .= ' button-sm';
1041
+				break;
1042
+			case 'lg':
1043
+			case 'large':
1044
+				$button_css_attributes .= ' button-lg';
1045
+				break;
1046
+			case 'block':
1047
+				$button_css_attributes .= ' button-block';
1048
+				break;
1049
+			case 'md':
1050
+			case 'medium':
1051
+			default:
1052
+				$button_css_attributes .= '';
1053
+		}
1054
+		$this->_button_css_attributes .= ! empty($other_attributes)
1055
+			? $button_css_attributes . ' ' . $other_attributes
1056
+			: $button_css_attributes;
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * @return string
1062
+	 */
1063
+	public function button_css_attributes()
1064
+	{
1065
+		if (empty($this->_button_css_attributes)) {
1066
+			$this->set_button_css_attributes();
1067
+		}
1068
+		return $this->_button_css_attributes;
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * find_form_data_for_this_section
1074
+	 * using this section's name and its parents, finds the value of the form data that corresponds to it.
1075
+	 * For example, if this form section's HTML name is my_form[subform][form_input_1],
1076
+	 * then it's value should be in request at request['my_form']['subform']['form_input_1'].
1077
+	 * (If that doesn't exist, we also check for this subsection's name
1078
+	 * at the TOP LEVEL of the request data. Eg request['form_input_1'].)
1079
+	 * This function finds its value in the form.
1080
+	 *
1081
+	 * @param array $req_data
1082
+	 * @return mixed whatever the raw value of this form section is in the request data
1083
+	 * @throws EE_Error
1084
+	 */
1085
+	public function find_form_data_for_this_section($req_data)
1086
+	{
1087
+		$name_parts = $this->getInputNameParts();
1088
+		// now get the value for the input
1089
+		$value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1090
+		// check if this thing's name is at the TOP level of the request data
1091
+		if ($value === null && isset($req_data[ $this->name() ])) {
1092
+			$value = $req_data[ $this->name() ];
1093
+		}
1094
+		return $value;
1095
+	}
1096
+
1097
+
1098
+	/**
1099
+	 * If this input's name is something like "foo[bar][baz]"
1100
+	 * returns an array like `array('foo','bar',baz')`
1101
+	 *
1102
+	 * @return array
1103
+	 * @throws EE_Error
1104
+	 */
1105
+	protected function getInputNameParts()
1106
+	{
1107
+		// break up the html name by "[]"
1108
+		if (strpos($this->html_name(), '[') !== false) {
1109
+			$before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1110
+		} else {
1111
+			$before_any_brackets = $this->html_name();
1112
+		}
1113
+		// grab all of the segments
1114
+		preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1115
+		if (isset($matches[1]) && is_array($matches[1])) {
1116
+			$name_parts = $matches[1];
1117
+			array_unshift($name_parts, $before_any_brackets);
1118
+		} else {
1119
+			$name_parts = [$before_any_brackets];
1120
+		}
1121
+		return $name_parts;
1122
+	}
1123
+
1124
+
1125
+	/**
1126
+	 * @param array $html_name_parts
1127
+	 * @param array $req_data
1128
+	 * @return array | NULL
1129
+	 */
1130
+	public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1131
+	{
1132
+		$first_part_to_consider = array_shift($html_name_parts);
1133
+		if (isset($req_data[ $first_part_to_consider ])) {
1134
+			if (empty($html_name_parts)) {
1135
+				return $req_data[ $first_part_to_consider ];
1136
+			} else {
1137
+				return $this->findRequestForSectionUsingNameParts(
1138
+					$html_name_parts,
1139
+					$req_data[ $first_part_to_consider ]
1140
+				);
1141
+			}
1142
+		}
1143
+		return null;
1144
+	}
1145
+
1146
+
1147
+	/**
1148
+	 * Checks if this form input's data is in the request data
1149
+	 *
1150
+	 * @param array $req_data
1151
+	 * @return boolean
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function form_data_present_in($req_data = null)
1155
+	{
1156
+		if ($req_data === null) {
1157
+			/** @var RequestInterface $request */
1158
+			$request  = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1159
+			$req_data = $request->postParams();
1160
+		}
1161
+
1162
+		return $this->find_form_data_for_this_section($req_data) !== null;
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * Overrides parent to add js data from validation and display strategies
1168
+	 *
1169
+	 * @param array $form_other_js_data
1170
+	 * @return array
1171
+	 */
1172
+	public function get_other_js_data($form_other_js_data = [])
1173
+	{
1174
+		return $this->get_other_js_data_from_strategies($form_other_js_data);
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * Gets other JS data for localization from this input's strategies, like
1180
+	 * the validation strategies and the display strategy
1181
+	 *
1182
+	 * @param array $form_other_js_data
1183
+	 * @return array
1184
+	 */
1185
+	public function get_other_js_data_from_strategies($form_other_js_data = [])
1186
+	{
1187
+		$form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1188
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1189
+			$form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1190
+		}
1191
+		return $form_other_js_data;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1197
+	 *
1198
+	 * @return void
1199
+	 */
1200
+	public function enqueue_js()
1201
+	{
1202
+		// ask our display strategy and validation strategies if they have js to enqueue
1203
+		$this->enqueue_js_from_strategies();
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * Tells strategies when its ok to enqueue their js and css
1209
+	 *
1210
+	 * @return void
1211
+	 */
1212
+	public function enqueue_js_from_strategies()
1213
+	{
1214
+		$this->get_display_strategy()->enqueue_js();
1215
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1216
+			$validation_strategy->enqueue_js();
1217
+		}
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * Gets the default value set on the input (not the current value, which may have been
1223
+	 * changed because of a form submission). If no default was set, this us null.
1224
+	 *
1225
+	 * @return mixed
1226
+	 */
1227
+	public function get_default()
1228
+	{
1229
+		return $this->_default;
1230
+	}
1231
+
1232
+
1233
+	/**
1234
+	 * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1235
+	 * and server-side if any input was received it will be ignored
1236
+	 */
1237
+	public function disable($disable = true)
1238
+	{
1239
+		$disabled_attribute = ' disabled="disabled"';
1240
+		$this->disabled     = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1241
+		if ($this->disabled) {
1242
+			if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1243
+				$this->_other_html_attributes .= $disabled_attribute;
1244
+			}
1245
+			$this->_set_normalized_value($this->get_default());
1246
+		} else {
1247
+			$this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1248
+		}
1249
+	}
1250
+
1251
+
1252
+	/**
1253
+	 * Returns whether this input is currently disabled.
1254
+	 *
1255
+	 * @return bool
1256
+	 */
1257
+	public function isDisabled(): bool
1258
+	{
1259
+		return $this->disabled;
1260
+	}
1261
+
1262
+
1263
+	public function dataAttributes(): array
1264
+	{
1265
+		return $this->_data_attributes;
1266
+	}
1267
+
1268
+
1269
+	public function layoutContainerClass(): string
1270
+	{
1271
+		return $this->_layout_container_class;
1272
+	}
1273
+
1274
+
1275
+	public function extraContainerHtml(): string
1276
+	{
1277
+		return $this->_extra_container_html;
1278
+	}
1279 1279
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
         if (isset($input_args['validation_strategies'])) {
220 220
             foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
221 221
                 if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
222
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
222
+                    $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
223 223
                 }
224 224
             }
225 225
             unset($input_args['validation_strategies']);
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
                 $this->disable($value);
234 234
                 continue;
235 235
             }
236
-            $setter = 'set_' . $key;
236
+            $setter = 'set_'.$key;
237 237
             if (method_exists($this, $setter)) {
238 238
                 $this->$setter($value);
239 239
                 unset($input_args[$key]);
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         if (isset($input_args['ignore_input'])) {
260 260
             $this->_normalization_strategy = new EE_Null_Normalization();
261 261
         }
262
-        if (! $this->_normalization_strategy) {
262
+        if ( ! $this->_normalization_strategy) {
263 263
             $this->_normalization_strategy = new EE_Text_Normalization();
264 264
         }
265 265
         $this->_normalization_strategy->_construct_finalize($this);
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
             $this->set_default($input_args['default']);
269 269
             unset($input_args['default']);
270 270
         }
271
-        if (! $this->_sensitive_data_removal_strategy) {
271
+        if ( ! $this->_sensitive_data_removal_strategy) {
272 272
             $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
273 273
         }
274 274
         $this->_sensitive_data_removal_strategy->_construct_finalize($this);
@@ -284,10 +284,10 @@  discard block
 block discarded – undo
284 284
      */
285 285
     protected function _set_default_html_name_if_empty()
286 286
     {
287
-        if (! $this->_html_name) {
287
+        if ( ! $this->_html_name) {
288 288
             $this->_html_name = $this->name();
289 289
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
290
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
290
+                $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]";
291 291
             }
292 292
         }
293 293
     }
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
     protected function _get_display_strategy()
318 318
     {
319 319
         $this->ensure_construct_finalized_called();
320
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
320
+        if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
321 321
             throw new EE_Error(
322 322
                 sprintf(
323 323
                     esc_html__(
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
                 $validation_strategy instanceof $validation_strategy_classname
474 474
                 || is_subclass_of($validation_strategy, $validation_strategy_classname)
475 475
             ) {
476
-                unset($this->_validation_strategies[ $key ]);
476
+                unset($this->_validation_strategies[$key]);
477 477
             }
478 478
         }
479 479
     }
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
             if (is_array($raw_input)) {
679 679
                 $raw_value = [];
680 680
                 foreach ($raw_input as $key => $value) {
681
-                    $raw_value[ $key ] = $this->_sanitize($value);
681
+                    $raw_value[$key] = $this->_sanitize($value);
682 682
                 }
683 683
                 $this->_set_raw_value($raw_value);
684 684
             } else {
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
     {
714 714
         return ! empty($this->_html_label_id)
715 715
             ? $this->_html_label_id
716
-            : $this->html_id() . '-lbl';
716
+            : $this->html_id().'-lbl';
717 717
     }
718 718
 
719 719
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
      */
732 732
     public function add_html_label_class(string $html_class)
733 733
     {
734
-        $this->_html_label_class .= ' ' . trim($html_class);
734
+        $this->_html_label_class .= ' '.trim($html_class);
735 735
     }
736 736
 
737 737
 
@@ -862,9 +862,9 @@  discard block
 block discarded – undo
862 862
                 $validation_strategy->get_jquery_validation_rule_array()
863 863
             );
864 864
         }
865
-        if (! empty($jquery_validation_rules)) {
865
+        if ( ! empty($jquery_validation_rules)) {
866 866
             foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
867
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
867
+                $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
868 868
             }
869 869
         }
870 870
         return $jquery_validation_js;
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
     public function html_class($add_required = false)
978 978
     {
979 979
         return $add_required && $this->required()
980
-            ? $this->required_css_class() . ' ' . $this->_html_class
980
+            ? $this->required_css_class().' '.$this->_html_class
981 981
             : $this->_html_class;
982 982
     }
983 983
 
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
                 $button_css_attributes .= '';
1053 1053
         }
1054 1054
         $this->_button_css_attributes .= ! empty($other_attributes)
1055
-            ? $button_css_attributes . ' ' . $other_attributes
1055
+            ? $button_css_attributes.' '.$other_attributes
1056 1056
             : $button_css_attributes;
1057 1057
     }
1058 1058
 
@@ -1088,8 +1088,8 @@  discard block
 block discarded – undo
1088 1088
         // now get the value for the input
1089 1089
         $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1090 1090
         // check if this thing's name is at the TOP level of the request data
1091
-        if ($value === null && isset($req_data[ $this->name() ])) {
1092
-            $value = $req_data[ $this->name() ];
1091
+        if ($value === null && isset($req_data[$this->name()])) {
1092
+            $value = $req_data[$this->name()];
1093 1093
         }
1094 1094
         return $value;
1095 1095
     }
@@ -1130,13 +1130,13 @@  discard block
 block discarded – undo
1130 1130
     public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1131 1131
     {
1132 1132
         $first_part_to_consider = array_shift($html_name_parts);
1133
-        if (isset($req_data[ $first_part_to_consider ])) {
1133
+        if (isset($req_data[$first_part_to_consider])) {
1134 1134
             if (empty($html_name_parts)) {
1135
-                return $req_data[ $first_part_to_consider ];
1135
+                return $req_data[$first_part_to_consider];
1136 1136
             } else {
1137 1137
                 return $this->findRequestForSectionUsingNameParts(
1138 1138
                     $html_name_parts,
1139
-                    $req_data[ $first_part_to_consider ]
1139
+                    $req_data[$first_part_to_consider]
1140 1140
                 );
1141 1141
             }
1142 1142
         }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_CVV_Input.input.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,38 +11,38 @@
 block discarded – undo
11 11
  */
12 12
 class EE_CVV_Input extends EE_Text_Input
13 13
 {
14
-    /**
15
-     * @param array  $input_settings          {
16
-     * @type boolean $include_whats_this_link defaults to true
17
-     *                                        }
18
-     */
19
-    public function __construct($input_settings = [])
20
-    {
21
-        $this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal());
22
-        $this->_add_validation_strategy(
23
-            new EE_Text_Validation_Strategy(
24
-                $input_settings['validation_error_message'] ?? esc_html__(
25
-                'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
26
-                'event_espresso'
27
-            ),
28
-                '~^\d{3,4}$~'
29
-            )
30
-        );
31
-        parent::__construct($input_settings);
32
-        if (
33
-            ! isset($input_settings['include_whats_this_link'])
34
-            || $input_settings['include_whats_this_link'] === true
35
-        ) {
36
-            $this->_html_label_text = sprintf(
37
-                esc_html_x(
38
-                    '%1$s %2$s(What\'s this?)%3$s',
39
-                    'CVV (What\'s this?)',
40
-                    'event_espresso'
41
-                ),
42
-                $this->_html_label_text,
43
-                '<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
44
-                '</a>'
45
-            );
46
-        }
47
-    }
14
+	/**
15
+	 * @param array  $input_settings          {
16
+	 * @type boolean $include_whats_this_link defaults to true
17
+	 *                                        }
18
+	 */
19
+	public function __construct($input_settings = [])
20
+	{
21
+		$this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal());
22
+		$this->_add_validation_strategy(
23
+			new EE_Text_Validation_Strategy(
24
+				$input_settings['validation_error_message'] ?? esc_html__(
25
+				'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
26
+				'event_espresso'
27
+			),
28
+				'~^\d{3,4}$~'
29
+			)
30
+		);
31
+		parent::__construct($input_settings);
32
+		if (
33
+			! isset($input_settings['include_whats_this_link'])
34
+			|| $input_settings['include_whats_this_link'] === true
35
+		) {
36
+			$this->_html_label_text = sprintf(
37
+				esc_html_x(
38
+					'%1$s %2$s(What\'s this?)%3$s',
39
+					'CVV (What\'s this?)',
40
+					'event_espresso'
41
+				),
42
+				$this->_html_label_text,
43
+				'<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
44
+				'</a>'
45
+			);
46
+		}
47
+	}
48 48
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 2 patches
Indentation   +483 added lines, -483 removed lines patch added patch discarded remove patch
@@ -14,488 +14,488 @@
 block discarded – undo
14 14
  */
15 15
 abstract class EE_Form_Section_Base
16 16
 {
17
-    /**
18
-     * the URL the form is submitted to
19
-     *
20
-     * @var string
21
-     */
22
-    protected $_action = '';
23
-
24
-    /**
25
-     * POST (default) or GET
26
-     *
27
-     * @var string
28
-     */
29
-    protected $_method = '';
30
-
31
-    /**
32
-     * html_id and html_name are derived from this by default
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_name = '';
37
-
38
-    /**
39
-     * $_html_id
40
-     * @var string
41
-     */
42
-    protected $_html_id = '';
43
-
44
-    /**
45
-     * $_html_class
46
-     * @var string
47
-     */
48
-    protected $_html_class = '';
49
-
50
-    /**
51
-     * $_html_style
52
-     * @var string
53
-     */
54
-    protected $_html_style = '';
55
-
56
-    /**
57
-     * $_other_html_attributes
58
-     * @var string
59
-     */
60
-    protected $_other_html_attributes = '';
61
-
62
-    /**
63
-     * The form section of which this form section is a part
64
-     *
65
-     * @var EE_Form_Section_Proper
66
-     */
67
-    protected $_parent_section;
68
-
69
-    /**
70
-     * flag indicating that _construct_finalize has been called.
71
-     * If it has not been called and we try to use functions which require it, we call it
72
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
73
-     *
74
-     * @var bool
75
-     */
76
-    protected $_construction_finalized = false;
77
-
78
-    /**
79
-     * Strategy for parsing the form HTML upon display
80
-     *
81
-     * @var FormHtmlFilter
82
-     */
83
-    protected $_form_html_filter;
84
-
85
-
86
-    /**
87
-     * @param array $options_array {
88
-     * @type        $name          string the name for this form section, if you want to explicitly define it
89
-     *                             }
90
-     * @throws InvalidDataTypeException
91
-     */
92
-    public function __construct($options_array = [])
93
-    {
94
-        // set parser which allows the form section's rendered HTML to be filtered
95
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
96
-            $this->_form_html_filter = $options_array['form_html_filter'];
97
-            unset($options_array['form_html_filter']);
98
-        }
99
-        // used by display strategies
100
-        // assign incoming values to properties
101
-        foreach ($options_array as $key => $value) {
102
-            $setter = 'set_' . $key;
103
-            if (method_exists($this, $setter)) {
104
-                $this->$setter($value);
105
-                continue;
106
-            }
107
-            $_key = "_$key";
108
-            if (property_exists($this, $_key) && empty($this->{$_key})) {
109
-                if ($_key === '_subsections' && ! is_array($value)) {
110
-                    throw new InvalidDataTypeException($_key, $value, 'array');
111
-                }
112
-                $this->{$_key} = $value;
113
-            }
114
-        }
115
-    }
116
-
117
-
118
-    /**
119
-     * @param EE_Form_Section_Base|null $parent_form_section
120
-     * @param $name
121
-     */
122
-    protected function _construct_finalize($parent_form_section, $name)
123
-    {
124
-        $this->_construction_finalized = true;
125
-        $this->_parent_section         = $parent_form_section;
126
-        if ($name !== null) {
127
-            $this->_name = $name;
128
-        }
129
-    }
130
-
131
-
132
-    /**
133
-     * make sure construction finalized was called, otherwise children might not be ready
134
-     *
135
-     * @return void
136
-     */
137
-    public function ensure_construct_finalized_called()
138
-    {
139
-        if (! $this->_construction_finalized) {
140
-            $this->_construct_finalize($this->_parent_section, $this->_name);
141
-        }
142
-    }
143
-
144
-
145
-    /**
146
-     * @return string
147
-     */
148
-    public function action()
149
-    {
150
-        return $this->_action;
151
-    }
152
-
153
-
154
-    /**
155
-     * @param string $action
156
-     */
157
-    public function set_action($action)
158
-    {
159
-        $this->_action = $action;
160
-    }
161
-
162
-
163
-    /**
164
-     * @return string
165
-     */
166
-    public function method()
167
-    {
168
-        return ! empty($this->_method) ? $this->_method : 'POST';
169
-    }
170
-
171
-
172
-    /**
173
-     * @param string $method
174
-     */
175
-    public function set_method($method)
176
-    {
177
-        switch ($method) {
178
-            case 'get':
179
-            case 'GET':
180
-                $this->_method = 'GET';
181
-                break;
182
-            default:
183
-                $this->_method = 'POST';
184
-        }
185
-    }
186
-
187
-
188
-    /**
189
-     * Sets the html_id to its default value, if none was specified in the constructor.
190
-     * Calculation involves using the name and the parent's html id
191
-     * return void
192
-     *
193
-     * @throws \EE_Error
194
-     */
195
-    protected function _set_default_html_id_if_empty()
196
-    {
197
-        if (! $this->_html_id) {
198
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
199
-                $this->_html_id = $this->_parent_section->html_id()
200
-                                  . '-'
201
-                                  . $this->_prep_name_for_html_id($this->name());
202
-            } else {
203
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
204
-            }
205
-        }
206
-    }
207
-
208
-
209
-    /**
210
-     * _prep_name_for_html_id
211
-     *
212
-     * @param $name
213
-     * @return string
214
-     */
215
-    private function _prep_name_for_html_id($name)
216
-    {
217
-        return sanitize_key(str_replace(['&nbsp;', ' ', '_'], '-', $name));
218
-    }
219
-
220
-
221
-    /**
222
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
223
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
224
-     * and call get_html when you want to output the html. Calling get_html_and_js after
225
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
226
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
227
-     * and so might stop working anytime.
228
-     *
229
-     * @return string
230
-     */
231
-    public function get_html_and_js()
232
-    {
233
-        return $this->get_html();
234
-    }
235
-
236
-
237
-    /**
238
-     * Gets the HTML for displaying this form section
239
-     *
240
-     * @return string
241
-     */
242
-    abstract public function get_html();
243
-
244
-
245
-    /**
246
-     * @param bool $add_pound_sign
247
-     * @return string
248
-     * @throws EE_Error
249
-     */
250
-    public function html_id($add_pound_sign = false)
251
-    {
252
-        $this->_set_default_html_id_if_empty();
253
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
254
-    }
255
-
256
-
257
-    /**
258
-     * @return string
259
-     */
260
-    public function html_class()
261
-    {
262
-        return $this->_html_class;
263
-    }
264
-
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function html_style()
270
-    {
271
-        return $this->_html_style;
272
-    }
273
-
274
-
275
-    /**
276
-     * @param string $html_class
277
-     */
278
-    public function add_html_class(string $html_class)
279
-    {
280
-        $this->_html_class .= ' ' . trim($html_class);
281
-    }
282
-
283
-
284
-    /**
285
-     * @param string $html_class
286
-     */
287
-    public function set_html_class(string $html_class)
288
-    {
289
-        $this->_html_class = trim($html_class);
290
-    }
291
-
292
-
293
-    /**
294
-     * @param mixed $html_id
295
-     */
296
-    public function set_html_id($html_id)
297
-    {
298
-        $this->_html_id = $html_id;
299
-    }
300
-
301
-
302
-    /**
303
-     * @param mixed $html_style
304
-     */
305
-    public function set_html_style($html_style)
306
-    {
307
-        $this->_html_style = $html_style;
308
-    }
309
-
310
-
311
-    /**
312
-     * @param string $other_html_attributes
313
-     */
314
-    public function set_other_html_attributes($other_html_attributes)
315
-    {
316
-        if (empty($other_html_attributes)) {
317
-            return;
318
-        }
319
-        // make sure attributes are separated by a space
320
-        $other_html_attributes = strpos($other_html_attributes, ' ') !== 0
321
-            ? " $other_html_attributes"
322
-            : $other_html_attributes;
323
-        $this->_other_html_attributes .= $other_html_attributes;
324
-    }
325
-
326
-
327
-    /**
328
-     * @return string
329
-     */
330
-    public function other_html_attributes()
331
-    {
332
-        return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
333
-    }
334
-
335
-
336
-    /**
337
-     * Gets the name of the form section. This is not the same as the HTML name.
338
-     *
339
-     * @return string
340
-     * @throws EE_Error
341
-     */
342
-    public function name()
343
-    {
344
-        if (! $this->_construction_finalized) {
345
-            throw new EE_Error(
346
-                sprintf(
347
-                    esc_html__(
348
-                        'You cannot use the form section\'s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
349
-                        'event_espresso'
350
-                    ),
351
-                    get_class($this)
352
-                )
353
-            );
354
-        }
355
-        return $this->_name;
356
-    }
357
-
358
-
359
-    /**
360
-     * Gets the parent section
361
-     *
362
-     * @return EE_Form_Section_Proper
363
-     */
364
-    public function parent_section()
365
-    {
366
-        return $this->_parent_section;
367
-    }
368
-
369
-
370
-    /**
371
-     * returns HTML for generating the opening form HTML tag (<form>)
372
-     *
373
-     * @param string $action           the URL the form is submitted to
374
-     * @param string $method           POST (default) or GET
375
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
376
-     * @return string
377
-     * @throws EE_Error
378
-     */
379
-    public function form_open($action = '', $method = '', $other_attributes = '')
380
-    {
381
-        if (! empty($action)) {
382
-            $this->set_action($action);
383
-        }
384
-        if (! empty($method)) {
385
-            $this->set_method($method);
386
-        }
387
-        $html = EEH_HTML::nl(1, 'form') . '<form';
388
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
389
-        $html .= ' action="' . esc_url_raw($this->action()) . '"';
390
-        $html .= ' method="' . $this->method() . '"';
391
-        $html .= ' name="' . $this->name() . '"';
392
-        $html .= ' ' . $other_attributes . '>';
393
-        return $html;
394
-    }
395
-
396
-
397
-    /**
398
-     * ensures that html id for form either ends in "-form" or "-frm"
399
-     * so that id doesn't conflict/collide with other elements
400
-     *
401
-     * @param string $html_id
402
-     * @return string
403
-     */
404
-    protected function get_html_id_for_form($html_id)
405
-    {
406
-        $strlen  = strlen($html_id);
407
-        $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
408
-            ? $html_id
409
-            : $html_id . '-frm';
410
-        return $html_id;
411
-    }
412
-
413
-
414
-    /**
415
-     * returns HTML for generating the closing form HTML tag (</form>)
416
-     *
417
-     * @return string
418
-     * @throws EE_Error
419
-     */
420
-    public function form_close()
421
-    {
422
-        return EEH_HTML::nl(-1, 'form')
423
-               . '</form>'
424
-               . EEH_HTML::nl()
425
-               . '<!-- end of ee-'
426
-               . $this->html_id()
427
-               . '-form -->'
428
-               . EEH_HTML::nl();
429
-    }
430
-
431
-
432
-    /**
433
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
434
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
435
-     * Default does nothing, but child classes can override
436
-     *
437
-     * @return void
438
-     */
439
-    public function enqueue_js()
440
-    {
441
-        // defaults to enqueue NO js or css
442
-    }
443
-
444
-
445
-    /**
446
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
447
-     * with it, and it will be on each form section's 'other_data' property.
448
-     * By default nothing is added, but child classes can extend this method to add something.
449
-     * Eg, if you have an input that will cause a modal dialog to appear,
450
-     * here you could add an entry like 'modal_dialog_inputs' to this array
451
-     * to map between the input's html ID and the modal dialogue's ID, so that
452
-     * your JS code will know where to find the modal dialog when the input is pressed.
453
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
454
-     *
455
-     * @param array $form_other_js_data
456
-     * @return array
457
-     */
458
-    public function get_other_js_data($form_other_js_data = [])
459
-    {
460
-        return $form_other_js_data;
461
-    }
462
-
463
-
464
-    /**
465
-     * This isn't just the name of an input, it's a path pointing to an input. The
466
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
467
-     * dot-dot-slash (../) means to ascend into the parent section.
468
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
469
-     * which will be returned.
470
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
471
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
472
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
473
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
474
-     * Etc
475
-     *
476
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
477
-     * @return EE_Form_Section_Base
478
-     */
479
-    public function find_section_from_path($form_section_path)
480
-    {
481
-        if (strpos($form_section_path, '/') === 0) {
482
-            $form_section_path = substr($form_section_path, strlen('/'));
483
-        }
484
-        if (empty($form_section_path)) {
485
-            return $this;
486
-        }
487
-        if (strpos($form_section_path, '../') === 0) {
488
-            $parent            = $this->parent_section();
489
-            $form_section_path = substr($form_section_path, strlen('../'));
490
-            if ($parent instanceof EE_Form_Section_Base) {
491
-                return $parent->find_section_from_path($form_section_path);
492
-            }
493
-            if (empty($form_section_path)) {
494
-                return $this;
495
-            }
496
-        }
497
-        // couldn't find it using simple parent following
498
-        return null;
499
-    }
17
+	/**
18
+	 * the URL the form is submitted to
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected $_action = '';
23
+
24
+	/**
25
+	 * POST (default) or GET
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $_method = '';
30
+
31
+	/**
32
+	 * html_id and html_name are derived from this by default
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_name = '';
37
+
38
+	/**
39
+	 * $_html_id
40
+	 * @var string
41
+	 */
42
+	protected $_html_id = '';
43
+
44
+	/**
45
+	 * $_html_class
46
+	 * @var string
47
+	 */
48
+	protected $_html_class = '';
49
+
50
+	/**
51
+	 * $_html_style
52
+	 * @var string
53
+	 */
54
+	protected $_html_style = '';
55
+
56
+	/**
57
+	 * $_other_html_attributes
58
+	 * @var string
59
+	 */
60
+	protected $_other_html_attributes = '';
61
+
62
+	/**
63
+	 * The form section of which this form section is a part
64
+	 *
65
+	 * @var EE_Form_Section_Proper
66
+	 */
67
+	protected $_parent_section;
68
+
69
+	/**
70
+	 * flag indicating that _construct_finalize has been called.
71
+	 * If it has not been called and we try to use functions which require it, we call it
72
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
73
+	 *
74
+	 * @var bool
75
+	 */
76
+	protected $_construction_finalized = false;
77
+
78
+	/**
79
+	 * Strategy for parsing the form HTML upon display
80
+	 *
81
+	 * @var FormHtmlFilter
82
+	 */
83
+	protected $_form_html_filter;
84
+
85
+
86
+	/**
87
+	 * @param array $options_array {
88
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
89
+	 *                             }
90
+	 * @throws InvalidDataTypeException
91
+	 */
92
+	public function __construct($options_array = [])
93
+	{
94
+		// set parser which allows the form section's rendered HTML to be filtered
95
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
96
+			$this->_form_html_filter = $options_array['form_html_filter'];
97
+			unset($options_array['form_html_filter']);
98
+		}
99
+		// used by display strategies
100
+		// assign incoming values to properties
101
+		foreach ($options_array as $key => $value) {
102
+			$setter = 'set_' . $key;
103
+			if (method_exists($this, $setter)) {
104
+				$this->$setter($value);
105
+				continue;
106
+			}
107
+			$_key = "_$key";
108
+			if (property_exists($this, $_key) && empty($this->{$_key})) {
109
+				if ($_key === '_subsections' && ! is_array($value)) {
110
+					throw new InvalidDataTypeException($_key, $value, 'array');
111
+				}
112
+				$this->{$_key} = $value;
113
+			}
114
+		}
115
+	}
116
+
117
+
118
+	/**
119
+	 * @param EE_Form_Section_Base|null $parent_form_section
120
+	 * @param $name
121
+	 */
122
+	protected function _construct_finalize($parent_form_section, $name)
123
+	{
124
+		$this->_construction_finalized = true;
125
+		$this->_parent_section         = $parent_form_section;
126
+		if ($name !== null) {
127
+			$this->_name = $name;
128
+		}
129
+	}
130
+
131
+
132
+	/**
133
+	 * make sure construction finalized was called, otherwise children might not be ready
134
+	 *
135
+	 * @return void
136
+	 */
137
+	public function ensure_construct_finalized_called()
138
+	{
139
+		if (! $this->_construction_finalized) {
140
+			$this->_construct_finalize($this->_parent_section, $this->_name);
141
+		}
142
+	}
143
+
144
+
145
+	/**
146
+	 * @return string
147
+	 */
148
+	public function action()
149
+	{
150
+		return $this->_action;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param string $action
156
+	 */
157
+	public function set_action($action)
158
+	{
159
+		$this->_action = $action;
160
+	}
161
+
162
+
163
+	/**
164
+	 * @return string
165
+	 */
166
+	public function method()
167
+	{
168
+		return ! empty($this->_method) ? $this->_method : 'POST';
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param string $method
174
+	 */
175
+	public function set_method($method)
176
+	{
177
+		switch ($method) {
178
+			case 'get':
179
+			case 'GET':
180
+				$this->_method = 'GET';
181
+				break;
182
+			default:
183
+				$this->_method = 'POST';
184
+		}
185
+	}
186
+
187
+
188
+	/**
189
+	 * Sets the html_id to its default value, if none was specified in the constructor.
190
+	 * Calculation involves using the name and the parent's html id
191
+	 * return void
192
+	 *
193
+	 * @throws \EE_Error
194
+	 */
195
+	protected function _set_default_html_id_if_empty()
196
+	{
197
+		if (! $this->_html_id) {
198
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
199
+				$this->_html_id = $this->_parent_section->html_id()
200
+								  . '-'
201
+								  . $this->_prep_name_for_html_id($this->name());
202
+			} else {
203
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
204
+			}
205
+		}
206
+	}
207
+
208
+
209
+	/**
210
+	 * _prep_name_for_html_id
211
+	 *
212
+	 * @param $name
213
+	 * @return string
214
+	 */
215
+	private function _prep_name_for_html_id($name)
216
+	{
217
+		return sanitize_key(str_replace(['&nbsp;', ' ', '_'], '-', $name));
218
+	}
219
+
220
+
221
+	/**
222
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
223
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
224
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
225
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
226
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
227
+	 * and so might stop working anytime.
228
+	 *
229
+	 * @return string
230
+	 */
231
+	public function get_html_and_js()
232
+	{
233
+		return $this->get_html();
234
+	}
235
+
236
+
237
+	/**
238
+	 * Gets the HTML for displaying this form section
239
+	 *
240
+	 * @return string
241
+	 */
242
+	abstract public function get_html();
243
+
244
+
245
+	/**
246
+	 * @param bool $add_pound_sign
247
+	 * @return string
248
+	 * @throws EE_Error
249
+	 */
250
+	public function html_id($add_pound_sign = false)
251
+	{
252
+		$this->_set_default_html_id_if_empty();
253
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
254
+	}
255
+
256
+
257
+	/**
258
+	 * @return string
259
+	 */
260
+	public function html_class()
261
+	{
262
+		return $this->_html_class;
263
+	}
264
+
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function html_style()
270
+	{
271
+		return $this->_html_style;
272
+	}
273
+
274
+
275
+	/**
276
+	 * @param string $html_class
277
+	 */
278
+	public function add_html_class(string $html_class)
279
+	{
280
+		$this->_html_class .= ' ' . trim($html_class);
281
+	}
282
+
283
+
284
+	/**
285
+	 * @param string $html_class
286
+	 */
287
+	public function set_html_class(string $html_class)
288
+	{
289
+		$this->_html_class = trim($html_class);
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param mixed $html_id
295
+	 */
296
+	public function set_html_id($html_id)
297
+	{
298
+		$this->_html_id = $html_id;
299
+	}
300
+
301
+
302
+	/**
303
+	 * @param mixed $html_style
304
+	 */
305
+	public function set_html_style($html_style)
306
+	{
307
+		$this->_html_style = $html_style;
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param string $other_html_attributes
313
+	 */
314
+	public function set_other_html_attributes($other_html_attributes)
315
+	{
316
+		if (empty($other_html_attributes)) {
317
+			return;
318
+		}
319
+		// make sure attributes are separated by a space
320
+		$other_html_attributes = strpos($other_html_attributes, ' ') !== 0
321
+			? " $other_html_attributes"
322
+			: $other_html_attributes;
323
+		$this->_other_html_attributes .= $other_html_attributes;
324
+	}
325
+
326
+
327
+	/**
328
+	 * @return string
329
+	 */
330
+	public function other_html_attributes()
331
+	{
332
+		return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
333
+	}
334
+
335
+
336
+	/**
337
+	 * Gets the name of the form section. This is not the same as the HTML name.
338
+	 *
339
+	 * @return string
340
+	 * @throws EE_Error
341
+	 */
342
+	public function name()
343
+	{
344
+		if (! $this->_construction_finalized) {
345
+			throw new EE_Error(
346
+				sprintf(
347
+					esc_html__(
348
+						'You cannot use the form section\'s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
349
+						'event_espresso'
350
+					),
351
+					get_class($this)
352
+				)
353
+			);
354
+		}
355
+		return $this->_name;
356
+	}
357
+
358
+
359
+	/**
360
+	 * Gets the parent section
361
+	 *
362
+	 * @return EE_Form_Section_Proper
363
+	 */
364
+	public function parent_section()
365
+	{
366
+		return $this->_parent_section;
367
+	}
368
+
369
+
370
+	/**
371
+	 * returns HTML for generating the opening form HTML tag (<form>)
372
+	 *
373
+	 * @param string $action           the URL the form is submitted to
374
+	 * @param string $method           POST (default) or GET
375
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
376
+	 * @return string
377
+	 * @throws EE_Error
378
+	 */
379
+	public function form_open($action = '', $method = '', $other_attributes = '')
380
+	{
381
+		if (! empty($action)) {
382
+			$this->set_action($action);
383
+		}
384
+		if (! empty($method)) {
385
+			$this->set_method($method);
386
+		}
387
+		$html = EEH_HTML::nl(1, 'form') . '<form';
388
+		$html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
389
+		$html .= ' action="' . esc_url_raw($this->action()) . '"';
390
+		$html .= ' method="' . $this->method() . '"';
391
+		$html .= ' name="' . $this->name() . '"';
392
+		$html .= ' ' . $other_attributes . '>';
393
+		return $html;
394
+	}
395
+
396
+
397
+	/**
398
+	 * ensures that html id for form either ends in "-form" or "-frm"
399
+	 * so that id doesn't conflict/collide with other elements
400
+	 *
401
+	 * @param string $html_id
402
+	 * @return string
403
+	 */
404
+	protected function get_html_id_for_form($html_id)
405
+	{
406
+		$strlen  = strlen($html_id);
407
+		$html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
408
+			? $html_id
409
+			: $html_id . '-frm';
410
+		return $html_id;
411
+	}
412
+
413
+
414
+	/**
415
+	 * returns HTML for generating the closing form HTML tag (</form>)
416
+	 *
417
+	 * @return string
418
+	 * @throws EE_Error
419
+	 */
420
+	public function form_close()
421
+	{
422
+		return EEH_HTML::nl(-1, 'form')
423
+			   . '</form>'
424
+			   . EEH_HTML::nl()
425
+			   . '<!-- end of ee-'
426
+			   . $this->html_id()
427
+			   . '-form -->'
428
+			   . EEH_HTML::nl();
429
+	}
430
+
431
+
432
+	/**
433
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
434
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
435
+	 * Default does nothing, but child classes can override
436
+	 *
437
+	 * @return void
438
+	 */
439
+	public function enqueue_js()
440
+	{
441
+		// defaults to enqueue NO js or css
442
+	}
443
+
444
+
445
+	/**
446
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
447
+	 * with it, and it will be on each form section's 'other_data' property.
448
+	 * By default nothing is added, but child classes can extend this method to add something.
449
+	 * Eg, if you have an input that will cause a modal dialog to appear,
450
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
451
+	 * to map between the input's html ID and the modal dialogue's ID, so that
452
+	 * your JS code will know where to find the modal dialog when the input is pressed.
453
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
454
+	 *
455
+	 * @param array $form_other_js_data
456
+	 * @return array
457
+	 */
458
+	public function get_other_js_data($form_other_js_data = [])
459
+	{
460
+		return $form_other_js_data;
461
+	}
462
+
463
+
464
+	/**
465
+	 * This isn't just the name of an input, it's a path pointing to an input. The
466
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
467
+	 * dot-dot-slash (../) means to ascend into the parent section.
468
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
469
+	 * which will be returned.
470
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
471
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
472
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
473
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
474
+	 * Etc
475
+	 *
476
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
477
+	 * @return EE_Form_Section_Base
478
+	 */
479
+	public function find_section_from_path($form_section_path)
480
+	{
481
+		if (strpos($form_section_path, '/') === 0) {
482
+			$form_section_path = substr($form_section_path, strlen('/'));
483
+		}
484
+		if (empty($form_section_path)) {
485
+			return $this;
486
+		}
487
+		if (strpos($form_section_path, '../') === 0) {
488
+			$parent            = $this->parent_section();
489
+			$form_section_path = substr($form_section_path, strlen('../'));
490
+			if ($parent instanceof EE_Form_Section_Base) {
491
+				return $parent->find_section_from_path($form_section_path);
492
+			}
493
+			if (empty($form_section_path)) {
494
+				return $this;
495
+			}
496
+		}
497
+		// couldn't find it using simple parent following
498
+		return null;
499
+	}
500 500
 }
501 501
 // End of file EE_Form_Section_Base.form.php
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         // used by display strategies
100 100
         // assign incoming values to properties
101 101
         foreach ($options_array as $key => $value) {
102
-            $setter = 'set_' . $key;
102
+            $setter = 'set_'.$key;
103 103
             if (method_exists($this, $setter)) {
104 104
                 $this->$setter($value);
105 105
                 continue;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function ensure_construct_finalized_called()
138 138
     {
139
-        if (! $this->_construction_finalized) {
139
+        if ( ! $this->_construction_finalized) {
140 140
             $this->_construct_finalize($this->_parent_section, $this->_name);
141 141
         }
142 142
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     protected function _set_default_html_id_if_empty()
196 196
     {
197
-        if (! $this->_html_id) {
197
+        if ( ! $this->_html_id) {
198 198
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
199 199
                 $this->_html_id = $this->_parent_section->html_id()
200 200
                                   . '-'
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
     public function html_id($add_pound_sign = false)
251 251
     {
252 252
         $this->_set_default_html_id_if_empty();
253
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
253
+        return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id;
254 254
     }
255 255
 
256 256
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
      */
278 278
     public function add_html_class(string $html_class)
279 279
     {
280
-        $this->_html_class .= ' ' . trim($html_class);
280
+        $this->_html_class .= ' '.trim($html_class);
281 281
     }
282 282
 
283 283
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
      */
330 330
     public function other_html_attributes()
331 331
     {
332
-        return ! empty($this->_other_html_attributes) ? ' ' . $this->_other_html_attributes : '';
332
+        return ! empty($this->_other_html_attributes) ? ' '.$this->_other_html_attributes : '';
333 333
     }
334 334
 
335 335
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     public function name()
343 343
     {
344
-        if (! $this->_construction_finalized) {
344
+        if ( ! $this->_construction_finalized) {
345 345
             throw new EE_Error(
346 346
                 sprintf(
347 347
                     esc_html__(
@@ -378,18 +378,18 @@  discard block
 block discarded – undo
378 378
      */
379 379
     public function form_open($action = '', $method = '', $other_attributes = '')
380 380
     {
381
-        if (! empty($action)) {
381
+        if ( ! empty($action)) {
382 382
             $this->set_action($action);
383 383
         }
384
-        if (! empty($method)) {
384
+        if ( ! empty($method)) {
385 385
             $this->set_method($method);
386 386
         }
387
-        $html = EEH_HTML::nl(1, 'form') . '<form';
388
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
389
-        $html .= ' action="' . esc_url_raw($this->action()) . '"';
390
-        $html .= ' method="' . $this->method() . '"';
391
-        $html .= ' name="' . $this->name() . '"';
392
-        $html .= ' ' . $other_attributes . '>';
387
+        $html = EEH_HTML::nl(1, 'form').'<form';
388
+        $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : '';
389
+        $html .= ' action="'.esc_url_raw($this->action()).'"';
390
+        $html .= ' method="'.$this->method().'"';
391
+        $html .= ' name="'.$this->name().'"';
392
+        $html .= ' '.$other_attributes.'>';
393 393
         return $html;
394 394
     }
395 395
 
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
         $strlen  = strlen($html_id);
407 407
         $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
408 408
             ? $html_id
409
-            : $html_id . '-frm';
409
+            : $html_id.'-frm';
410 410
         return $html_id;
411 411
     }
412 412
 
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Scheduler.lib.php 2 patches
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -15,234 +15,234 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Messages_Scheduler extends EE_Base
17 17
 {
18
-    /**
19
-     * Number of seconds between batch sends/generates on the cron job.
20
-     * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
21
-     * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
22
-     *
23
-     * @type int
24
-     */
25
-    const message_cron_schedule = 300;
26
-
27
-
28
-    /**
29
-     * Constructor
30
-     */
31
-    public function __construct()
32
-    {
33
-        // register tasks (and make sure only registered once).
34
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
35
-            add_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks']);
36
-        }
37
-
38
-        // register callbacks for scheduled events (but make sure they are set only once).
39
-        if (
40
-            ! has_action(
41
-                'AHEE__EE_Messages_Scheduler__generation',
42
-                ['EE_Messages_Scheduler', 'batch_generation']
43
-            )
44
-        ) {
45
-            add_action('AHEE__EE_Messages_Scheduler__generation', ['EE_Messages_Scheduler', 'batch_generation']);
46
-            add_action('AHEE__EE_Messages_Scheduler__sending', ['EE_Messages_Scheduler', 'batch_sending']);
47
-            add_action('AHEE__EE_Messages_Scheduler__cleanup', ['EE_Messages_Scheduler', 'cleanup']);
48
-        }
49
-
50
-        // add custom schedules
51
-        add_filter('cron_schedules', [$this, 'custom_schedules']);
52
-    }
53
-
54
-
55
-    /**
56
-     * Add custom schedules for wp_cron
57
-     *
58
-     * @param array $schedules
59
-     * @return array
60
-     */
61
-    public function custom_schedules(array $schedules): array
62
-    {
63
-        $schedules['ee_message_cron'] = [
64
-            'interval' => self::message_cron_schedule,
65
-            'display'  => esc_html__(
66
-                'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
67
-                'event_espresso'
68
-            ),
69
-        ];
70
-        return $schedules;
71
-    }
72
-
73
-
74
-    /**
75
-     * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
76
-     * remove.
77
-     *
78
-     * @param array $tasks already existing scheduled tasks
79
-     * @return array
80
-     * @throws EE_Error
81
-     * @throws ReflectionException
82
-     */
83
-    public function register_scheduled_tasks(array $tasks): array
84
-    {
85
-        EE_Registry::instance()->load_helper('DTT_Helper');
86
-        $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
87
-        $tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
88
-        $tasks['AHEE__EE_Messages_Scheduler__cleanup']    = [EEH_DTT_Helper::tomorrow(), 'daily'];
89
-        return $tasks;
90
-    }
91
-
92
-
93
-    /**
94
-     * This initiates a non-blocking separate request to execute on a scheduled task.
95
-     * Note: The EED_Messages module has the handlers for these requests.
96
-     *
97
-     * @param string $task The task the request is being generated for.
98
-     * @throws EE_Error
99
-     * @throws ReflectionException
100
-     */
101
-    public static function initiate_scheduled_non_blocking_request(string $task)
102
-    {
103
-        if (
104
-            apply_filters(
105
-                'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
106
-                true
107
-            )
108
-        ) {
109
-            $request_url  = add_query_arg(
110
-                array_merge(
111
-                    ['ee' => 'msg_cron_trigger'],
112
-                    EE_Messages_Scheduler::get_request_params($task)
113
-                ),
114
-                site_url()
115
-            );
116
-            $request_args = [
117
-                'timeout'     => 300,
118
-                'blocking'    => (defined('DOING_CRON') && DOING_CRON)
119
-                    || (defined('DOING_AJAX') && DOING_AJAX),
120
-                'sslverify'   => Manager::verifySSL(),
121
-                'redirection' => 10,
122
-            ];
123
-            $response     = wp_remote_get($request_url, $request_args);
124
-            if (is_wp_error($response)) {
125
-                trigger_error($response->get_error_message());
126
-            }
127
-        } else {
128
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
129
-        }
130
-    }
131
-
132
-
133
-    /**
134
-     * This returns
135
-     * the request params used for a scheduled message task request.
136
-     *
137
-     * @param string $task The task the request is for.
138
-     * @return array
139
-     */
140
-    public static function get_request_params(string $task): array
141
-    {
142
-        // transient is used for flood control on msg_cron_trigger requests
143
-        $transient_key = 'ee_trans_' . uniqid($task);
144
-        set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
145
-        return [
146
-            'type' => $task,
147
-            'key'  => $transient_key,
148
-        ];
149
-    }
150
-
151
-
152
-    /**
153
-     * This is used to execute an immediate call to the run_cron task performed by EED_Messages
154
-     *
155
-     * @param string $task The task the request is being generated for.
156
-     * @throws EE_Error
157
-     * @throws ReflectionException
158
-     */
159
-    public static function initiate_immediate_request_on_cron(string $task)
160
-    {
161
-        /** @var RequestInterface $request */
162
-        $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
163
-        $request_args = EE_Messages_Scheduler::get_request_params($task);
164
-        // set those request args in the request so it gets picked up
165
-        foreach ($request_args as $request_key => $request_value) {
166
-            $request->setRequestParam($request_key, $request_value);
167
-        }
168
-        EED_Messages::instance()->run_cron();
169
-    }
170
-
171
-
172
-    /**
173
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
174
-     *
175
-     * @throws EE_Error
176
-     * @throws ReflectionException
177
-     */
178
-    public static function batch_generation()
179
-    {
180
-        /**
181
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
182
-         */
183
-        if (
184
-            ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
185
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
186
-        ) {
187
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
188
-        }
189
-    }
190
-
191
-
192
-    /**
193
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
194
-     *
195
-     * @throws EE_Error
196
-     * @throws ReflectionException
197
-     */
198
-    public static function batch_sending()
199
-    {
200
-        /**
201
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
202
-         */
203
-        if (
204
-            ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
205
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
206
-        ) {
207
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
208
-        }
209
-    }
210
-
211
-
212
-    /**
213
-     * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
214
-     * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete
215
-     * permanently from the database messages that have a MSG_modified date older than 30 days.
216
-     *
217
-     * @throws EE_Error
218
-     * @throws ReflectionException
219
-     */
220
-    public static function cleanup()
221
-    {
222
-        // First, confirm that the generation and sending EE_Messages_Scheduler crons are
223
-        // set and reschedule them if they are not.
224
-        $message_crons_to_check = [
225
-            'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron',
226
-            'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
227
-        ];
228
-        foreach ($message_crons_to_check as $hook_name => $frequency) {
229
-            if (! wp_next_scheduled($hook_name)) {
230
-                wp_schedule_event(time(), $frequency, $hook_name);
231
-            }
232
-        }
233
-
234
-        // check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
235
-        // until the next scheduled event.
236
-        if (! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
237
-            return;
238
-        }
239
-
240
-        /**
241
-         * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
242
-         * of deleting messages.
243
-         */
244
-        if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
245
-            EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
246
-        }
247
-    }
18
+	/**
19
+	 * Number of seconds between batch sends/generates on the cron job.
20
+	 * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
21
+	 * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
22
+	 *
23
+	 * @type int
24
+	 */
25
+	const message_cron_schedule = 300;
26
+
27
+
28
+	/**
29
+	 * Constructor
30
+	 */
31
+	public function __construct()
32
+	{
33
+		// register tasks (and make sure only registered once).
34
+		if (! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
35
+			add_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks']);
36
+		}
37
+
38
+		// register callbacks for scheduled events (but make sure they are set only once).
39
+		if (
40
+			! has_action(
41
+				'AHEE__EE_Messages_Scheduler__generation',
42
+				['EE_Messages_Scheduler', 'batch_generation']
43
+			)
44
+		) {
45
+			add_action('AHEE__EE_Messages_Scheduler__generation', ['EE_Messages_Scheduler', 'batch_generation']);
46
+			add_action('AHEE__EE_Messages_Scheduler__sending', ['EE_Messages_Scheduler', 'batch_sending']);
47
+			add_action('AHEE__EE_Messages_Scheduler__cleanup', ['EE_Messages_Scheduler', 'cleanup']);
48
+		}
49
+
50
+		// add custom schedules
51
+		add_filter('cron_schedules', [$this, 'custom_schedules']);
52
+	}
53
+
54
+
55
+	/**
56
+	 * Add custom schedules for wp_cron
57
+	 *
58
+	 * @param array $schedules
59
+	 * @return array
60
+	 */
61
+	public function custom_schedules(array $schedules): array
62
+	{
63
+		$schedules['ee_message_cron'] = [
64
+			'interval' => self::message_cron_schedule,
65
+			'display'  => esc_html__(
66
+				'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
67
+				'event_espresso'
68
+			),
69
+		];
70
+		return $schedules;
71
+	}
72
+
73
+
74
+	/**
75
+	 * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
76
+	 * remove.
77
+	 *
78
+	 * @param array $tasks already existing scheduled tasks
79
+	 * @return array
80
+	 * @throws EE_Error
81
+	 * @throws ReflectionException
82
+	 */
83
+	public function register_scheduled_tasks(array $tasks): array
84
+	{
85
+		EE_Registry::instance()->load_helper('DTT_Helper');
86
+		$tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
87
+		$tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
88
+		$tasks['AHEE__EE_Messages_Scheduler__cleanup']    = [EEH_DTT_Helper::tomorrow(), 'daily'];
89
+		return $tasks;
90
+	}
91
+
92
+
93
+	/**
94
+	 * This initiates a non-blocking separate request to execute on a scheduled task.
95
+	 * Note: The EED_Messages module has the handlers for these requests.
96
+	 *
97
+	 * @param string $task The task the request is being generated for.
98
+	 * @throws EE_Error
99
+	 * @throws ReflectionException
100
+	 */
101
+	public static function initiate_scheduled_non_blocking_request(string $task)
102
+	{
103
+		if (
104
+			apply_filters(
105
+				'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
106
+				true
107
+			)
108
+		) {
109
+			$request_url  = add_query_arg(
110
+				array_merge(
111
+					['ee' => 'msg_cron_trigger'],
112
+					EE_Messages_Scheduler::get_request_params($task)
113
+				),
114
+				site_url()
115
+			);
116
+			$request_args = [
117
+				'timeout'     => 300,
118
+				'blocking'    => (defined('DOING_CRON') && DOING_CRON)
119
+					|| (defined('DOING_AJAX') && DOING_AJAX),
120
+				'sslverify'   => Manager::verifySSL(),
121
+				'redirection' => 10,
122
+			];
123
+			$response     = wp_remote_get($request_url, $request_args);
124
+			if (is_wp_error($response)) {
125
+				trigger_error($response->get_error_message());
126
+			}
127
+		} else {
128
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
129
+		}
130
+	}
131
+
132
+
133
+	/**
134
+	 * This returns
135
+	 * the request params used for a scheduled message task request.
136
+	 *
137
+	 * @param string $task The task the request is for.
138
+	 * @return array
139
+	 */
140
+	public static function get_request_params(string $task): array
141
+	{
142
+		// transient is used for flood control on msg_cron_trigger requests
143
+		$transient_key = 'ee_trans_' . uniqid($task);
144
+		set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
145
+		return [
146
+			'type' => $task,
147
+			'key'  => $transient_key,
148
+		];
149
+	}
150
+
151
+
152
+	/**
153
+	 * This is used to execute an immediate call to the run_cron task performed by EED_Messages
154
+	 *
155
+	 * @param string $task The task the request is being generated for.
156
+	 * @throws EE_Error
157
+	 * @throws ReflectionException
158
+	 */
159
+	public static function initiate_immediate_request_on_cron(string $task)
160
+	{
161
+		/** @var RequestInterface $request */
162
+		$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
163
+		$request_args = EE_Messages_Scheduler::get_request_params($task);
164
+		// set those request args in the request so it gets picked up
165
+		foreach ($request_args as $request_key => $request_value) {
166
+			$request->setRequestParam($request_key, $request_value);
167
+		}
168
+		EED_Messages::instance()->run_cron();
169
+	}
170
+
171
+
172
+	/**
173
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
174
+	 *
175
+	 * @throws EE_Error
176
+	 * @throws ReflectionException
177
+	 */
178
+	public static function batch_generation()
179
+	{
180
+		/**
181
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
182
+		 */
183
+		if (
184
+			! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
185
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
186
+		) {
187
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
188
+		}
189
+	}
190
+
191
+
192
+	/**
193
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
194
+	 *
195
+	 * @throws EE_Error
196
+	 * @throws ReflectionException
197
+	 */
198
+	public static function batch_sending()
199
+	{
200
+		/**
201
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
202
+		 */
203
+		if (
204
+			! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
205
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
206
+		) {
207
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
208
+		}
209
+	}
210
+
211
+
212
+	/**
213
+	 * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
214
+	 * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete
215
+	 * permanently from the database messages that have a MSG_modified date older than 30 days.
216
+	 *
217
+	 * @throws EE_Error
218
+	 * @throws ReflectionException
219
+	 */
220
+	public static function cleanup()
221
+	{
222
+		// First, confirm that the generation and sending EE_Messages_Scheduler crons are
223
+		// set and reschedule them if they are not.
224
+		$message_crons_to_check = [
225
+			'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron',
226
+			'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
227
+		];
228
+		foreach ($message_crons_to_check as $hook_name => $frequency) {
229
+			if (! wp_next_scheduled($hook_name)) {
230
+				wp_schedule_event(time(), $frequency, $hook_name);
231
+			}
232
+		}
233
+
234
+		// check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
235
+		// until the next scheduled event.
236
+		if (! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
237
+			return;
238
+		}
239
+
240
+		/**
241
+		 * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
242
+		 * of deleting messages.
243
+		 */
244
+		if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
245
+			EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
246
+		}
247
+	}
248 248
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     public function __construct()
32 32
     {
33 33
         // register tasks (and make sure only registered once).
34
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
34
+        if ( ! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
35 35
             add_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks']);
36 36
         }
37 37
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                 true
107 107
             )
108 108
         ) {
109
-            $request_url  = add_query_arg(
109
+            $request_url = add_query_arg(
110 110
                 array_merge(
111 111
                     ['ee' => 'msg_cron_trigger'],
112 112
                     EE_Messages_Scheduler::get_request_params($task)
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                 'sslverify'   => Manager::verifySSL(),
121 121
                 'redirection' => 10,
122 122
             ];
123
-            $response     = wp_remote_get($request_url, $request_args);
123
+            $response = wp_remote_get($request_url, $request_args);
124 124
             if (is_wp_error($response)) {
125 125
                 trigger_error($response->get_error_message());
126 126
             }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     public static function get_request_params(string $task): array
141 141
     {
142 142
         // transient is used for flood control on msg_cron_trigger requests
143
-        $transient_key = 'ee_trans_' . uniqid($task);
143
+        $transient_key = 'ee_trans_'.uniqid($task);
144 144
         set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
145 145
         return [
146 146
             'type' => $task,
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
             'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
227 227
         ];
228 228
         foreach ($message_crons_to_check as $hook_name => $frequency) {
229
-            if (! wp_next_scheduled($hook_name)) {
229
+            if ( ! wp_next_scheduled($hook_name)) {
230 230
                 wp_schedule_event(time(), $frequency, $hook_name);
231 231
             }
232 232
         }
233 233
 
234 234
         // check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
235 235
         // until the next scheduled event.
236
-        if (! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
236
+        if ( ! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
237 237
             return;
238 238
         }
239 239
 
Please login to merge, or discard this patch.
messages/message_type/EE_Not_Approved_Registration_message_type.class.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,60 +13,60 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Not_Approved_Registration_message_type extends EE_Registration_Base_message_type
15 15
 {
16
-    public function __construct()
17
-    {
18
-        $this->name = 'not_approved_registration';
19
-        $this->description = esc_html__('This message type is for messages sent to registrants when their registration is set to "not approved" / "awaiting review" status.', 'event_espresso');
20
-        $this->label = array(
21
-            'singular' => esc_html__('not approved / awaiting review registration', 'event_espresso'),
22
-            'plural' => esc_html__('not approved / awaiting review registrations', 'event_espresso')
23
-            );
16
+	public function __construct()
17
+	{
18
+		$this->name = 'not_approved_registration';
19
+		$this->description = esc_html__('This message type is for messages sent to registrants when their registration is set to "not approved" / "awaiting review" status.', 'event_espresso');
20
+		$this->label = array(
21
+			'singular' => esc_html__('not approved / awaiting review registration', 'event_espresso'),
22
+			'plural' => esc_html__('not approved / awaiting review registrations', 'event_espresso')
23
+			);
24 24
 
25
-        $this->_master_templates = array(
26
-            'email' => 'registration'
27
-            );
25
+		$this->_master_templates = array(
26
+			'email' => 'registration'
27
+			);
28 28
 
29
-        parent::__construct();
30
-    }
29
+		parent::__construct();
30
+	}
31 31
 
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * _set_contexts
37
-     * This sets up the contexts associated with the message_type
38
-     *
39
-     * @access  protected
40
-     * @return  void
41
-     */
42
-    protected function _set_contexts()
43
-    {
44
-        $this->_context_label = array(
45
-            'label' => esc_html__('recipient', 'event_espresso'),
46
-            'plural' => esc_html__('recipients', 'event_espresso'),
47
-            'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
48
-            );
35
+	/**
36
+	 * _set_contexts
37
+	 * This sets up the contexts associated with the message_type
38
+	 *
39
+	 * @access  protected
40
+	 * @return  void
41
+	 */
42
+	protected function _set_contexts()
43
+	{
44
+		$this->_context_label = array(
45
+			'label' => esc_html__('recipient', 'event_espresso'),
46
+			'plural' => esc_html__('recipients', 'event_espresso'),
47
+			'description' => esc_html__('Recipient\'s are who will receive the template.  You may want different registration details sent out depending on who the recipient is', 'event_espresso')
48
+			);
49 49
 
50
-        $this->_contexts = array(
51
-            'admin' => array(
52
-                'label' => esc_html__('Event Admin', 'event_espresso'),
53
-                'description' => esc_html__('This template is what event administrators will receive when registration status is set to not approved / awaiting review.', 'event_espresso')
54
-                ),
55
-            'primary_attendee' => array(
56
-                'label' => esc_html__('Primary Registrant', 'event_espresso'),
57
-                'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive when the registration status is not approved / awaiting review.', 'event_espresso')
58
-                )
59
-            );
60
-    }
50
+		$this->_contexts = array(
51
+			'admin' => array(
52
+				'label' => esc_html__('Event Admin', 'event_espresso'),
53
+				'description' => esc_html__('This template is what event administrators will receive when registration status is set to not approved / awaiting review.', 'event_espresso')
54
+				),
55
+			'primary_attendee' => array(
56
+				'label' => esc_html__('Primary Registrant', 'event_espresso'),
57
+				'description' => esc_html__('This template is what the primary registrant (the person who completed the initial transaction) will receive when the registration status is not approved / awaiting review.', 'event_espresso')
58
+				)
59
+			);
60
+	}
61 61
 
62 62
 
63 63
 
64
-    protected function _primary_attendee_addressees()
65
-    {
66
-        $cached = $this->_single_message;
67
-        $this->_single_message = false;
68
-        $addressees = parent::_primary_attendee_addressees();
69
-        $this->_single_message = $cached;
70
-        return $addressees;
71
-    }
64
+	protected function _primary_attendee_addressees()
65
+	{
66
+		$cached = $this->_single_message;
67
+		$this->_single_message = false;
68
+		$addressees = parent::_primary_attendee_addressees();
69
+		$this->_single_message = $cached;
70
+		return $addressees;
71
+	}
72 72
 }
Please login to merge, or discard this patch.