Completed
Branch BUG/fix-ee-rest-debug-headers (1355bc)
by
unknown
03:29 queued 18s
created
core/libraries/form_sections/inputs/EE_CVV_Input.input.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
         $this->_add_validation_strategy(
24 24
             new EE_Text_Validation_Strategy(
25 25
                 isset($input_settings['validation_error_message'])
26
-                    ?  $input_settings['validation_error_message']
26
+                    ? $input_settings['validation_error_message']
27 27
                     : esc_html__(
28 28
                         'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
29 29
                         'event_espresso'
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -11,43 +11,43 @@
 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 = array())
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
-                isset($input_settings['validation_error_message'])
25
-                    ?  $input_settings['validation_error_message']
26
-                    : esc_html__(
27
-                        'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
28
-                        'event_espresso'
29
-                    ),
30
-                '~^\d{3,4}$~'
31
-            )
32
-        );
33
-        parent::__construct($input_settings);
34
-        if (
35
-            ! isset($input_settings['include_whats_this_link'])
36
-            || (
37
-                isset($input_settings['include_whats_this_link'])
38
-                 && $input_settings['include_whats_this_link'] === true
39
-            )
40
-        ) {
41
-            $this->_html_label_text = sprintf(
42
-                esc_html_x(
43
-                    '%1$s %2$s(What\'s this?)%3$s',
44
-                    'CVV (What\'s this?)',
45
-                    'event_espresso'
46
-                ),
47
-                $this->_html_label_text,
48
-                '<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
49
-                '</a>'
50
-            );
51
-        }
52
-    }
14
+	/**
15
+	 * @param array $input_settings {
16
+	 *  @type boolean $include_whats_this_link defaults to true
17
+	 * }
18
+	 */
19
+	public function __construct($input_settings = array())
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
+				isset($input_settings['validation_error_message'])
25
+					?  $input_settings['validation_error_message']
26
+					: esc_html__(
27
+						'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
28
+						'event_espresso'
29
+					),
30
+				'~^\d{3,4}$~'
31
+			)
32
+		);
33
+		parent::__construct($input_settings);
34
+		if (
35
+			! isset($input_settings['include_whats_this_link'])
36
+			|| (
37
+				isset($input_settings['include_whats_this_link'])
38
+				 && $input_settings['include_whats_this_link'] === true
39
+			)
40
+		) {
41
+			$this->_html_label_text = sprintf(
42
+				esc_html_x(
43
+					'%1$s %2$s(What\'s this?)%3$s',
44
+					'CVV (What\'s this?)',
45
+					'event_espresso'
46
+				),
47
+				$this->_html_label_text,
48
+				'<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
49
+				'</a>'
50
+			);
51
+		}
52
+	}
53 53
 }
Please login to merge, or discard this patch.
libraries/form_sections/inputs/EE_Form_Input_With_Options_Base.input.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             $all_ints = true;
116 116
             array_walk_recursive(
117 117
                 $this->_options,
118
-                function ($value, $key) use (&$all_ints) {
118
+                function($value, $key) use (&$all_ints) {
119 119
                     // is this a top-level key? ignore it
120 120
                     if (
121 121
                         ! is_array($value)
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
         if (EEH_Array::is_multi_dimensional_array($arr)) {
178 178
             foreach ($arr as $sub_array) {
179 179
                 foreach ((array) $sub_array as $key => $value) {
180
-                    $flat_array[ $key ] = $value;
180
+                    $flat_array[$key] = $value;
181 181
                     $this->_set_label_size($value);
182 182
                 }
183 183
             }
184 184
         } else {
185 185
             foreach ($arr as $key => $value) {
186
-                $flat_array[ $key ] = $value;
186
+                $flat_array[$key] = $value;
187 187
                 $this->_set_label_size($value);
188 188
             }
189 189
         }
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
                 $desc = '';
205 205
                 if ($this->_use_desc_in_label) {
206 206
                     $desc = $question_option->desc();
207
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
207
+                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : '';
208 208
                 }
209 209
                 $value = $question_option->value();
210 210
                 // add value even if it's empty
211
-                $flat_array[ $value ] = $value;
211
+                $flat_array[$value] = $value;
212 212
                 // if both value and desc are not empty, then separate with a dash
213
-                if (! empty($value) && ! empty($desc)) {
214
-                    $flat_array[ $value ] .= ' - ' . $desc;
213
+                if ( ! empty($value) && ! empty($desc)) {
214
+                    $flat_array[$value] .= ' - '.$desc;
215 215
                 } else {
216 216
                     // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
217
-                    $flat_array[ $value ] .= $desc;
217
+                    $flat_array[$value] .= $desc;
218 218
                 }
219 219
             } elseif (is_array($question_option)) {
220 220
                 $flat_array += $this->_flatten_select_options($question_option);
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     public function set_label_sizes()
234 234
     {
235 235
         // did the input settings specifically say to NOT set the label size dynamically ?
236
-        if (! $this->_enforce_label_size) {
236
+        if ( ! $this->_enforce_label_size) {
237 237
             foreach ($this->_options as $option) {
238 238
                 // calculate the strlen of the label
239 239
                 $this->_set_label_size($option);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
     private function _set_label_size($value = '')
253 253
     {
254 254
         // don't change label size if it has already been set and is being enforced
255
-        if ($this->_enforce_label_size && $this->_label_size >  0) {
255
+        if ($this->_enforce_label_size && $this->_label_size > 0) {
256 256
             return;
257 257
         }
258 258
         // determine length of option value
@@ -299,13 +299,13 @@  discard block
 block discarded – undo
299 299
     {
300 300
         $options = $this->flat_options();
301 301
         $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
302
-        if (! $this->_multiple_selections) {
302
+        if ( ! $this->_multiple_selections) {
303 303
             $unnormalized_value_choices = array($unnormalized_value_choices);
304 304
         }
305 305
         $pretty_strings = array();
306 306
         foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
307
-            if (isset($options[ $unnormalized_value_choice ])) {
308
-                $pretty_strings[] = $options[ $unnormalized_value_choice ];
307
+            if (isset($options[$unnormalized_value_choice])) {
308
+                $pretty_strings[] = $options[$unnormalized_value_choice];
309 309
             } else {
310 310
                 $pretty_strings[] = $this->normalized_value();
311 311
             }
Please login to merge, or discard this patch.
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -11,324 +11,324 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base
13 13
 {
14
-    /**
15
-     * array of available options to choose as an answer
16
-     *
17
-     * @var array
18
-     */
19
-    protected $_options = array();
20
-
21
-    /**
22
-     * whether to display the html_label_text above the checkbox/radio button options
23
-     *
24
-     * @var boolean
25
-     */
26
-    protected $_display_html_label_text = true;
27
-
28
-    /**
29
-     * whether to display an question option description as part of the input label
30
-     *
31
-     * @var boolean
32
-     */
33
-    protected $_use_desc_in_label = true;
34
-
35
-    /**
36
-     * strlen() result for the longest input value (what gets displayed in the label)
37
-     * this is used to apply a css class to the input label
38
-     *
39
-     * @var int
40
-     */
41
-    protected $_label_size = 0;
42
-
43
-    /**
44
-     * whether to enforce the label size value passed in the constructor
45
-     *
46
-     * @var boolean
47
-     */
48
-    protected $_enforce_label_size = false;
49
-
50
-    /**
51
-     * whether to allow multiple selections (ie, the value of this input should be an array)
52
-     * or not (ie, the value should be a simple int, string, etc)
53
-     *
54
-     * @var boolean
55
-     */
56
-    protected $_multiple_selections = false;
57
-
58
-
59
-
60
-    /**
61
-     * @param array     $answer_options
62
-     * @param array     $input_settings {
63
-     * @type int|string $label_size
64
-     * @type boolean    $display_html_label_text
65
-     *                                  }
66
-     *                                  And all the options accepted by EE_Form_Input_Base
67
-     */
68
-    public function __construct($answer_options = array(), $input_settings = array())
69
-    {
70
-        if (isset($input_settings['label_size'])) {
71
-            $this->_set_label_size($input_settings['label_size']);
72
-            if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
73
-                $this->_enforce_label_size = true;
74
-            }
75
-        }
76
-        if (isset($input_settings['display_html_label_text'])) {
77
-            $this->set_display_html_label_text($input_settings['display_html_label_text']);
78
-        }
79
-        $this->set_select_options($answer_options);
80
-        parent::__construct($input_settings);
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Sets the allowed options for this input. Also has the side-effect of
87
-     * updating the normalization strategy to match the keys provided in the array
88
-     *
89
-     * @param array $answer_options
90
-     * @return void  just has the side-effect of setting the options for this input
91
-     */
92
-    public function set_select_options($answer_options = array())
93
-    {
94
-        $answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
95
-        // get the first item in the select options and check it's type
96
-        $this->_options = reset($answer_options) instanceof EE_Question_Option
97
-            ? $this->_process_question_options($answer_options)
98
-            : $answer_options;
99
-        // d( $this->_options );
100
-        $select_option_keys = array_keys($this->_options);
101
-        // attempt to determine data type for values in order to set normalization type
102
-        // purposefully only
103
-        if (
104
-            count($this->_options) === 2
105
-            && (
106
-                (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
107
-                || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
108
-            )
109
-        ) {
110
-            // values appear to be boolean, like TRUE, FALSE, 1, 0
111
-            $normalization = new EE_Boolean_Normalization();
112
-        } else {
113
-            // are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
114
-            $all_ints = true;
115
-            array_walk_recursive(
116
-                $this->_options,
117
-                function ($value, $key) use (&$all_ints) {
118
-                    // is this a top-level key? ignore it
119
-                    if (
120
-                        ! is_array($value)
121
-                        && ! is_int($key)
122
-                        && $key !== ''
123
-                        && $key !== null
124
-                    ) {
125
-                        $all_ints = false;
126
-                    }
127
-                }
128
-            );
129
-            if ($all_ints) {
130
-                $normalization = new EE_Int_Normalization();
131
-            } else {
132
-                $normalization = new EE_Text_Normalization();
133
-            }
134
-        }
135
-        // does input type have multiple options ?
136
-        if ($this->_multiple_selections) {
137
-            $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
138
-        } else {
139
-            $this->_set_normalization_strategy($normalization);
140
-        }
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @return array
147
-     */
148
-    public function options()
149
-    {
150
-        return $this->_options;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Returns an array which is guaranteed to not be multidimensional
157
-     *
158
-     * @return array
159
-     */
160
-    public function flat_options()
161
-    {
162
-        return $this->_flatten_select_options($this->options());
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Makes sure $arr is a flat array, not a multidimensional one
169
-     *
170
-     * @param array $arr
171
-     * @return array
172
-     */
173
-    protected function _flatten_select_options($arr)
174
-    {
175
-        $flat_array = array();
176
-        if (EEH_Array::is_multi_dimensional_array($arr)) {
177
-            foreach ($arr as $sub_array) {
178
-                foreach ((array) $sub_array as $key => $value) {
179
-                    $flat_array[ $key ] = $value;
180
-                    $this->_set_label_size($value);
181
-                }
182
-            }
183
-        } else {
184
-            foreach ($arr as $key => $value) {
185
-                $flat_array[ $key ] = $value;
186
-                $this->_set_label_size($value);
187
-            }
188
-        }
189
-        return $flat_array;
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     * @param EE_Question_Option[] $question_options_array
196
-     * @return array
197
-     */
198
-    protected function _process_question_options($question_options_array = array())
199
-    {
200
-        $flat_array = array();
201
-        foreach ($question_options_array as $question_option) {
202
-            if ($question_option instanceof EE_Question_Option) {
203
-                $desc = '';
204
-                if ($this->_use_desc_in_label) {
205
-                    $desc = $question_option->desc();
206
-                    $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
207
-                }
208
-                $value = $question_option->value();
209
-                // add value even if it's empty
210
-                $flat_array[ $value ] = $value;
211
-                // if both value and desc are not empty, then separate with a dash
212
-                if (! empty($value) && ! empty($desc)) {
213
-                    $flat_array[ $value ] .= ' - ' . $desc;
214
-                } else {
215
-                    // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
216
-                    $flat_array[ $value ] .= $desc;
217
-                }
218
-            } elseif (is_array($question_option)) {
219
-                $flat_array += $this->_flatten_select_options($question_option);
220
-            }
221
-        }
222
-        return $flat_array;
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     *    set_label_sizes
229
-     *
230
-     * @return void
231
-     */
232
-    public function set_label_sizes()
233
-    {
234
-        // did the input settings specifically say to NOT set the label size dynamically ?
235
-        if (! $this->_enforce_label_size) {
236
-            foreach ($this->_options as $option) {
237
-                // calculate the strlen of the label
238
-                $this->_set_label_size($option);
239
-            }
240
-        }
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     *    _set_label_size_class
247
-     *
248
-     * @param int|string $value
249
-     * @return void
250
-     */
251
-    private function _set_label_size($value = '')
252
-    {
253
-        // don't change label size if it has already been set and is being enforced
254
-        if ($this->_enforce_label_size && $this->_label_size >  0) {
255
-            return;
256
-        }
257
-        // determine length of option value
258
-        $val_size = is_int($value) ? $value : strlen($value);
259
-        // use new value if bigger than existing
260
-        $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     *    get_label_size_class
267
-     *
268
-     * @return string
269
-     */
270
-    public function get_label_size_class()
271
-    {
272
-        $size = ' medium-lbl';
273
-        // use maximum option value length to determine label size
274
-        if ($this->_label_size < 3) {
275
-            $size = ' nano-lbl';
276
-        } elseif ($this->_label_size < 6) {
277
-            $size = ' micro-lbl';
278
-        } elseif ($this->_label_size < 12) {
279
-            $size = ' tiny-lbl';
280
-        } elseif ($this->_label_size < 25) {
281
-            $size = ' small-lbl';
282
-        } elseif ($this->_label_size < 50) {
283
-            $size = ' medium-lbl';
284
-        } elseif ($this->_label_size >= 100) {
285
-            $size = ' big-lbl';
286
-        }
287
-        return $size;
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * Returns the pretty value for the normalized value
294
-     *
295
-     * @return string
296
-     */
297
-    public function pretty_value()
298
-    {
299
-        $options = $this->flat_options();
300
-        $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
301
-        if (! $this->_multiple_selections) {
302
-            $unnormalized_value_choices = array($unnormalized_value_choices);
303
-        }
304
-        $pretty_strings = array();
305
-        foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
306
-            if (isset($options[ $unnormalized_value_choice ])) {
307
-                $pretty_strings[] = $options[ $unnormalized_value_choice ];
308
-            } else {
309
-                $pretty_strings[] = $this->normalized_value();
310
-            }
311
-        }
312
-        return implode(', ', $pretty_strings);
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * @return boolean
319
-     */
320
-    public function display_html_label_text()
321
-    {
322
-        return $this->_display_html_label_text;
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * @param boolean $display_html_label_text
329
-     */
330
-    public function set_display_html_label_text($display_html_label_text)
331
-    {
332
-        $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
333
-    }
14
+	/**
15
+	 * array of available options to choose as an answer
16
+	 *
17
+	 * @var array
18
+	 */
19
+	protected $_options = array();
20
+
21
+	/**
22
+	 * whether to display the html_label_text above the checkbox/radio button options
23
+	 *
24
+	 * @var boolean
25
+	 */
26
+	protected $_display_html_label_text = true;
27
+
28
+	/**
29
+	 * whether to display an question option description as part of the input label
30
+	 *
31
+	 * @var boolean
32
+	 */
33
+	protected $_use_desc_in_label = true;
34
+
35
+	/**
36
+	 * strlen() result for the longest input value (what gets displayed in the label)
37
+	 * this is used to apply a css class to the input label
38
+	 *
39
+	 * @var int
40
+	 */
41
+	protected $_label_size = 0;
42
+
43
+	/**
44
+	 * whether to enforce the label size value passed in the constructor
45
+	 *
46
+	 * @var boolean
47
+	 */
48
+	protected $_enforce_label_size = false;
49
+
50
+	/**
51
+	 * whether to allow multiple selections (ie, the value of this input should be an array)
52
+	 * or not (ie, the value should be a simple int, string, etc)
53
+	 *
54
+	 * @var boolean
55
+	 */
56
+	protected $_multiple_selections = false;
57
+
58
+
59
+
60
+	/**
61
+	 * @param array     $answer_options
62
+	 * @param array     $input_settings {
63
+	 * @type int|string $label_size
64
+	 * @type boolean    $display_html_label_text
65
+	 *                                  }
66
+	 *                                  And all the options accepted by EE_Form_Input_Base
67
+	 */
68
+	public function __construct($answer_options = array(), $input_settings = array())
69
+	{
70
+		if (isset($input_settings['label_size'])) {
71
+			$this->_set_label_size($input_settings['label_size']);
72
+			if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) {
73
+				$this->_enforce_label_size = true;
74
+			}
75
+		}
76
+		if (isset($input_settings['display_html_label_text'])) {
77
+			$this->set_display_html_label_text($input_settings['display_html_label_text']);
78
+		}
79
+		$this->set_select_options($answer_options);
80
+		parent::__construct($input_settings);
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Sets the allowed options for this input. Also has the side-effect of
87
+	 * updating the normalization strategy to match the keys provided in the array
88
+	 *
89
+	 * @param array $answer_options
90
+	 * @return void  just has the side-effect of setting the options for this input
91
+	 */
92
+	public function set_select_options($answer_options = array())
93
+	{
94
+		$answer_options = is_array($answer_options) ? $answer_options : array($answer_options);
95
+		// get the first item in the select options and check it's type
96
+		$this->_options = reset($answer_options) instanceof EE_Question_Option
97
+			? $this->_process_question_options($answer_options)
98
+			: $answer_options;
99
+		// d( $this->_options );
100
+		$select_option_keys = array_keys($this->_options);
101
+		// attempt to determine data type for values in order to set normalization type
102
+		// purposefully only
103
+		if (
104
+			count($this->_options) === 2
105
+			&& (
106
+				(in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true))
107
+				|| (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true))
108
+			)
109
+		) {
110
+			// values appear to be boolean, like TRUE, FALSE, 1, 0
111
+			$normalization = new EE_Boolean_Normalization();
112
+		} else {
113
+			// are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation
114
+			$all_ints = true;
115
+			array_walk_recursive(
116
+				$this->_options,
117
+				function ($value, $key) use (&$all_ints) {
118
+					// is this a top-level key? ignore it
119
+					if (
120
+						! is_array($value)
121
+						&& ! is_int($key)
122
+						&& $key !== ''
123
+						&& $key !== null
124
+					) {
125
+						$all_ints = false;
126
+					}
127
+				}
128
+			);
129
+			if ($all_ints) {
130
+				$normalization = new EE_Int_Normalization();
131
+			} else {
132
+				$normalization = new EE_Text_Normalization();
133
+			}
134
+		}
135
+		// does input type have multiple options ?
136
+		if ($this->_multiple_selections) {
137
+			$this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization));
138
+		} else {
139
+			$this->_set_normalization_strategy($normalization);
140
+		}
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @return array
147
+	 */
148
+	public function options()
149
+	{
150
+		return $this->_options;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Returns an array which is guaranteed to not be multidimensional
157
+	 *
158
+	 * @return array
159
+	 */
160
+	public function flat_options()
161
+	{
162
+		return $this->_flatten_select_options($this->options());
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Makes sure $arr is a flat array, not a multidimensional one
169
+	 *
170
+	 * @param array $arr
171
+	 * @return array
172
+	 */
173
+	protected function _flatten_select_options($arr)
174
+	{
175
+		$flat_array = array();
176
+		if (EEH_Array::is_multi_dimensional_array($arr)) {
177
+			foreach ($arr as $sub_array) {
178
+				foreach ((array) $sub_array as $key => $value) {
179
+					$flat_array[ $key ] = $value;
180
+					$this->_set_label_size($value);
181
+				}
182
+			}
183
+		} else {
184
+			foreach ($arr as $key => $value) {
185
+				$flat_array[ $key ] = $value;
186
+				$this->_set_label_size($value);
187
+			}
188
+		}
189
+		return $flat_array;
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 * @param EE_Question_Option[] $question_options_array
196
+	 * @return array
197
+	 */
198
+	protected function _process_question_options($question_options_array = array())
199
+	{
200
+		$flat_array = array();
201
+		foreach ($question_options_array as $question_option) {
202
+			if ($question_option instanceof EE_Question_Option) {
203
+				$desc = '';
204
+				if ($this->_use_desc_in_label) {
205
+					$desc = $question_option->desc();
206
+					$desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : '';
207
+				}
208
+				$value = $question_option->value();
209
+				// add value even if it's empty
210
+				$flat_array[ $value ] = $value;
211
+				// if both value and desc are not empty, then separate with a dash
212
+				if (! empty($value) && ! empty($desc)) {
213
+					$flat_array[ $value ] .= ' - ' . $desc;
214
+				} else {
215
+					// otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary
216
+					$flat_array[ $value ] .= $desc;
217
+				}
218
+			} elseif (is_array($question_option)) {
219
+				$flat_array += $this->_flatten_select_options($question_option);
220
+			}
221
+		}
222
+		return $flat_array;
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 *    set_label_sizes
229
+	 *
230
+	 * @return void
231
+	 */
232
+	public function set_label_sizes()
233
+	{
234
+		// did the input settings specifically say to NOT set the label size dynamically ?
235
+		if (! $this->_enforce_label_size) {
236
+			foreach ($this->_options as $option) {
237
+				// calculate the strlen of the label
238
+				$this->_set_label_size($option);
239
+			}
240
+		}
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 *    _set_label_size_class
247
+	 *
248
+	 * @param int|string $value
249
+	 * @return void
250
+	 */
251
+	private function _set_label_size($value = '')
252
+	{
253
+		// don't change label size if it has already been set and is being enforced
254
+		if ($this->_enforce_label_size && $this->_label_size >  0) {
255
+			return;
256
+		}
257
+		// determine length of option value
258
+		$val_size = is_int($value) ? $value : strlen($value);
259
+		// use new value if bigger than existing
260
+		$this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 *    get_label_size_class
267
+	 *
268
+	 * @return string
269
+	 */
270
+	public function get_label_size_class()
271
+	{
272
+		$size = ' medium-lbl';
273
+		// use maximum option value length to determine label size
274
+		if ($this->_label_size < 3) {
275
+			$size = ' nano-lbl';
276
+		} elseif ($this->_label_size < 6) {
277
+			$size = ' micro-lbl';
278
+		} elseif ($this->_label_size < 12) {
279
+			$size = ' tiny-lbl';
280
+		} elseif ($this->_label_size < 25) {
281
+			$size = ' small-lbl';
282
+		} elseif ($this->_label_size < 50) {
283
+			$size = ' medium-lbl';
284
+		} elseif ($this->_label_size >= 100) {
285
+			$size = ' big-lbl';
286
+		}
287
+		return $size;
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * Returns the pretty value for the normalized value
294
+	 *
295
+	 * @return string
296
+	 */
297
+	public function pretty_value()
298
+	{
299
+		$options = $this->flat_options();
300
+		$unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value);
301
+		if (! $this->_multiple_selections) {
302
+			$unnormalized_value_choices = array($unnormalized_value_choices);
303
+		}
304
+		$pretty_strings = array();
305
+		foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) {
306
+			if (isset($options[ $unnormalized_value_choice ])) {
307
+				$pretty_strings[] = $options[ $unnormalized_value_choice ];
308
+			} else {
309
+				$pretty_strings[] = $this->normalized_value();
310
+			}
311
+		}
312
+		return implode(', ', $pretty_strings);
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * @return boolean
319
+	 */
320
+	public function display_html_label_text()
321
+	{
322
+		return $this->_display_html_label_text;
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * @param boolean $display_html_label_text
329
+	 */
330
+	public function set_display_html_label_text($display_html_label_text)
331
+	{
332
+		$this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN);
333
+	}
334 334
 }
Please login to merge, or discard this patch.
strategies/display/EE_Text_Input_Display_Strategy.strategy.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Text_Input_Display_Strategy extends EE_Display_Strategy_Base
16 16
 {
17
-    /**
18
-     * The html "type" attribute value. default is "text"
19
-     * @var string
20
-     */
21
-    protected $_type;
17
+	/**
18
+	 * The html "type" attribute value. default is "text"
19
+	 * @var string
20
+	 */
21
+	protected $_type;
22 22
 
23 23
 
24 24
 
25
-    /**
26
-     * @param string $type
27
-     */
28
-    public function __construct($type = 'text')
29
-    {
30
-        $this->_type = $type;
31
-        parent::__construct();
32
-    }
25
+	/**
26
+	 * @param string $type
27
+	 */
28
+	public function __construct($type = 'text')
29
+	{
30
+		$this->_type = $type;
31
+		parent::__construct();
32
+	}
33 33
 
34 34
 
35 35
 
36
-    /**
37
-     * Gets the html "type" attribute's value
38
-     * @return string
39
-     */
40
-    public function get_type()
41
-    {
42
-        if (
43
-            $this->_type === 'email'
44
-            && ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false)
45
-        ) {
46
-            return 'text';
47
-        }
48
-        return $this->_type;
49
-    }
36
+	/**
37
+	 * Gets the html "type" attribute's value
38
+	 * @return string
39
+	 */
40
+	public function get_type()
41
+	{
42
+		if (
43
+			$this->_type === 'email'
44
+			&& ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false)
45
+		) {
46
+			return 'text';
47
+		}
48
+		return $this->_type;
49
+	}
50 50
 
51 51
 
52 52
 
53
-    /**
54
-     *
55
-     * @return string of html to display the field
56
-     */
57
-    public function display()
58
-    {
59
-        $input = '<input type="' . $this->get_type() . '"';
60
-        $input .= ' name="' . $this->_input->html_name() . '"';
61
-        $input .= ' id="' . $this->_input->html_id() . '"';
62
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
-        $input .= ' class="' . $class . '"';
64
-        // add html5 required
65
-        $input .= $this->_input->required() ? ' required' : '';
66
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
-        $input .= ' style="' . $this->_input->html_style() . '"';
68
-        $input .= $this->_input->other_html_attributes();
69
-        $input .= '/>';
70
-        return $input;
71
-    }
53
+	/**
54
+	 *
55
+	 * @return string of html to display the field
56
+	 */
57
+	public function display()
58
+	{
59
+		$input = '<input type="' . $this->get_type() . '"';
60
+		$input .= ' name="' . $this->_input->html_name() . '"';
61
+		$input .= ' id="' . $this->_input->html_id() . '"';
62
+		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
+		$input .= ' class="' . $class . '"';
64
+		// add html5 required
65
+		$input .= $this->_input->required() ? ' required' : '';
66
+		$input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
+		$input .= ' style="' . $this->_input->html_style() . '"';
68
+		$input .= $this->_input->other_html_attributes();
69
+		$input .= '/>';
70
+		return $input;
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,15 +56,15 @@
 block discarded – undo
56 56
      */
57 57
     public function display()
58 58
     {
59
-        $input = '<input type="' . $this->get_type() . '"';
60
-        $input .= ' name="' . $this->_input->html_name() . '"';
61
-        $input .= ' id="' . $this->_input->html_id() . '"';
62
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
63
-        $input .= ' class="' . $class . '"';
59
+        $input = '<input type="'.$this->get_type().'"';
60
+        $input .= ' name="'.$this->_input->html_name().'"';
61
+        $input .= ' id="'.$this->_input->html_id().'"';
62
+        $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
63
+        $input .= ' class="'.$class.'"';
64 64
         // add html5 required
65 65
         $input .= $this->_input->required() ? ' required' : '';
66
-        $input .= ' value="' . $this->_input->raw_value_in_form() . '"';
67
-        $input .= ' style="' . $this->_input->html_style() . '"';
66
+        $input .= ' value="'.$this->_input->raw_value_in_form().'"';
67
+        $input .= ' style="'.$this->_input->html_style().'"';
68 68
         $input .= $this->_input->other_html_attributes();
69 69
         $input .= '/>';
70 70
         return $input;
Please login to merge, or discard this patch.
sensitive_data_removal/EE_CCV_Sensitive_Data_Removal.strategy.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@
 block discarded – undo
11 11
  */
12 12
 class EE_CCV_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base
13 13
 {
14
-    public function remove_sensitive_data($normalized_value)
15
-    {
16
-        // Get the ccv Length
17
-        $ccv_lenght = strlen($normalized_value);
18
-        // Replace all characters of credit card except the last four and dashes
19
-        for ($i = 0; $i < $ccv_lenght; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
21
-                continue;
22
-            }
23
-            $normalized_value[ $i ] = 'X';
24
-        }
25
-        // Return the masked Credit Card #
26
-        return $normalized_value;
27
-    }
14
+	public function remove_sensitive_data($normalized_value)
15
+	{
16
+		// Get the ccv Length
17
+		$ccv_lenght = strlen($normalized_value);
18
+		// Replace all characters of credit card except the last four and dashes
19
+		for ($i = 0; $i < $ccv_lenght; $i++) {
20
+			if ($normalized_value[ $i ] == '-') {
21
+				continue;
22
+			}
23
+			$normalized_value[ $i ] = 'X';
24
+		}
25
+		// Return the masked Credit Card #
26
+		return $normalized_value;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
         $ccv_lenght = strlen($normalized_value);
18 18
         // Replace all characters of credit card except the last four and dashes
19 19
         for ($i = 0; $i < $ccv_lenght; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
20
+            if ($normalized_value[$i] == '-') {
21 21
                 continue;
22 22
             }
23
-            $normalized_value[ $i ] = 'X';
23
+            $normalized_value[$i] = 'X';
24 24
         }
25 25
         // Return the masked Credit Card #
26 26
         return $normalized_value;
Please login to merge, or discard this patch.
sensitive_data_removal/EE_Credit_Card_Sensitive_Data_Removal.strategy.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Credit_Card_Sensitive_Data_Removal extends EE_Sensitive_Data_Removal_Base
13 13
 {
14
-    public function remove_sensitive_data($normalized_value)
15
-    {
16
-        // Get the cc Length
17
-        $cc_length = strlen($normalized_value);
18
-        // Replace all characters of credit card except the last four and dashes
19
-        for ($i = 0; $i < $cc_length - 4; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
21
-                continue;
22
-            }
23
-            $normalized_value[ $i ] = 'X';
24
-        }
25
-        // Return the masked Credit Card #
26
-        return $normalized_value;
27
-    }
14
+	public function remove_sensitive_data($normalized_value)
15
+	{
16
+		// Get the cc Length
17
+		$cc_length = strlen($normalized_value);
18
+		// Replace all characters of credit card except the last four and dashes
19
+		for ($i = 0; $i < $cc_length - 4; $i++) {
20
+			if ($normalized_value[ $i ] == '-') {
21
+				continue;
22
+			}
23
+			$normalized_value[ $i ] = 'X';
24
+		}
25
+		// Return the masked Credit Card #
26
+		return $normalized_value;
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
         $cc_length = strlen($normalized_value);
18 18
         // Replace all characters of credit card except the last four and dashes
19 19
         for ($i = 0; $i < $cc_length - 4; $i++) {
20
-            if ($normalized_value[ $i ] == '-') {
20
+            if ($normalized_value[$i] == '-') {
21 21
                 continue;
22 22
             }
23
-            $normalized_value[ $i ] = 'X';
23
+            $normalized_value[$i] = 'X';
24 24
         }
25 25
         // Return the masked Credit Card #
26 26
         return $normalized_value;
Please login to merge, or discard this patch.
strategies/validation/EE_Max_Length_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     public function get_jquery_validation_rule_array()
45 45
     {
46 46
         if ($this->_max_length !== EE_INF) {
47
-            return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
47
+            return array('maxlength' => $this->_max_length, 'messages' => array('maxlength' => $this->get_validation_error_message()));
48 48
         } else {
49 49
             return array();
50 50
         }
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,41 +11,41 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Max_Length_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14
-    protected $_max_length;
14
+	protected $_max_length;
15 15
 
16
-    public function __construct($validation_error_message = null, $max_length = EE_INF)
17
-    {
18
-        $this->_max_length = $max_length;
19
-        if ($validation_error_message === null) {
20
-            $validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
21
-        }
22
-        parent::__construct($validation_error_message);
23
-    }
16
+	public function __construct($validation_error_message = null, $max_length = EE_INF)
17
+	{
18
+		$this->_max_length = $max_length;
19
+		if ($validation_error_message === null) {
20
+			$validation_error_message = sprintf(esc_html__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
21
+		}
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25
-    /**
26
-     * @param $normalized_value
27
-     */
28
-    public function validate($normalized_value)
29
-    {
30
-        if (
31
-            $this->_max_length !== EE_INF &&
32
-                $normalized_value &&
33
-                is_string($normalized_value) &&
34
-                 strlen($normalized_value) > $this->_max_length
35
-        ) {
36
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
37
-        }
38
-    }
25
+	/**
26
+	 * @param $normalized_value
27
+	 */
28
+	public function validate($normalized_value)
29
+	{
30
+		if (
31
+			$this->_max_length !== EE_INF &&
32
+				$normalized_value &&
33
+				is_string($normalized_value) &&
34
+				 strlen($normalized_value) > $this->_max_length
35
+		) {
36
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
37
+		}
38
+	}
39 39
 
40
-    /**
41
-     * @return array
42
-     */
43
-    public function get_jquery_validation_rule_array()
44
-    {
45
-        if ($this->_max_length !== EE_INF) {
46
-            return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
47
-        } else {
48
-            return array();
49
-        }
50
-    }
40
+	/**
41
+	 * @return array
42
+	 */
43
+	public function get_jquery_validation_rule_array()
44
+	{
45
+		if ($this->_max_length !== EE_INF) {
46
+			return array( 'maxlength' => $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
47
+		} else {
48
+			return array();
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Min_Length_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,6 +40,6 @@
 block discarded – undo
40 40
      */
41 41
     public function get_jquery_validation_rule_array()
42 42
     {
43
-        return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
43
+        return array('minlength' => $this->_min_length, 'messages' => array('minlength' => $this->get_validation_error_message()));
44 44
     }
45 45
 }
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,34 +11,34 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Min_Length_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14
-    protected $_min_length;
14
+	protected $_min_length;
15 15
 
16
-    public function __construct($validation_error_message = null, $min_length = 0)
17
-    {
18
-        $this->_min_length = $min_length;
19
-        parent::__construct($validation_error_message);
20
-    }
16
+	public function __construct($validation_error_message = null, $min_length = 0)
17
+	{
18
+		$this->_min_length = $min_length;
19
+		parent::__construct($validation_error_message);
20
+	}
21 21
 
22
-    /**
23
-     * @param $normalized_value
24
-     */
25
-    public function validate($normalized_value)
26
-    {
27
-        if (
28
-            $this->_min_length > 0 &&
29
-                $normalized_value &&
30
-                is_string($normalized_value) &&
31
-                strlen($normalized_value) < $this->_min_length
32
-        ) {
33
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
34
-        }
35
-    }
22
+	/**
23
+	 * @param $normalized_value
24
+	 */
25
+	public function validate($normalized_value)
26
+	{
27
+		if (
28
+			$this->_min_length > 0 &&
29
+				$normalized_value &&
30
+				is_string($normalized_value) &&
31
+				strlen($normalized_value) < $this->_min_length
32
+		) {
33
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
34
+		}
35
+	}
36 36
 
37
-    /**
38
-     * @return array
39
-     */
40
-    public function get_jquery_validation_rule_array()
41
-    {
42
-        return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
43
-    }
37
+	/**
38
+	 * @return array
39
+	 */
40
+	public function get_jquery_validation_rule_array()
41
+	{
42
+		return array( 'minlength' => $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
43
+	}
44 44
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Text_Validation_Strategy.strategy.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
     public function validate($normalized_value)
30 30
     {
31 31
         $string_normalized_value = (string) $normalized_value;
32
-        if ($this->_regex &&  $string_normalized_value) {
33
-            if (! preg_match($this->_regex, $string_normalized_value)) {
32
+        if ($this->_regex && $string_normalized_value) {
33
+            if ( ! preg_match($this->_regex, $string_normalized_value)) {
34 34
                 throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
35 35
             }
36 36
         }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public function get_jquery_validation_rule_array()
43 43
     {
44 44
         if ($this->_regex !== null) {
45
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
+            return array('regex' => $this->regex_js(), 'messages' => array('regex' => $this->get_validation_error_message()));
46 46
         } else {
47 47
             return array();
48 48
         }
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -10,53 +10,53 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13
-    protected $_regex = null;
14
-    /**
15
-     *
16
-     * @param string $validation_error_message
17
-     * @param string $regex a PHP regex; the javascript regex will be derived from this
18
-     */
19
-    public function __construct($validation_error_message = null, $regex = null)
20
-    {
21
-        $this->_regex = $regex;
22
-        parent::__construct($validation_error_message);
23
-    }
13
+	protected $_regex = null;
14
+	/**
15
+	 *
16
+	 * @param string $validation_error_message
17
+	 * @param string $regex a PHP regex; the javascript regex will be derived from this
18
+	 */
19
+	public function __construct($validation_error_message = null, $regex = null)
20
+	{
21
+		$this->_regex = $regex;
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25
-    /**
26
-     * @param $normalized_value
27
-     */
28
-    public function validate($normalized_value)
29
-    {
30
-        $string_normalized_value = (string) $normalized_value;
31
-        if ($this->_regex &&  $string_normalized_value) {
32
-            if (! preg_match($this->_regex, $string_normalized_value)) {
33
-                throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
34
-            }
35
-        }
36
-    }
25
+	/**
26
+	 * @param $normalized_value
27
+	 */
28
+	public function validate($normalized_value)
29
+	{
30
+		$string_normalized_value = (string) $normalized_value;
31
+		if ($this->_regex &&  $string_normalized_value) {
32
+			if (! preg_match($this->_regex, $string_normalized_value)) {
33
+				throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
34
+			}
35
+		}
36
+	}
37 37
 
38
-    /**
39
-     * @return array
40
-     */
41
-    public function get_jquery_validation_rule_array()
42
-    {
43
-        if ($this->_regex !== null) {
44
-            return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
-        } else {
46
-            return array();
47
-        }
48
-    }
38
+	/**
39
+	 * @return array
40
+	 */
41
+	public function get_jquery_validation_rule_array()
42
+	{
43
+		if ($this->_regex !== null) {
44
+			return array( 'regex' => $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
45
+		} else {
46
+			return array();
47
+		}
48
+	}
49 49
 
50 50
 /**
51 51
  * Translates a PHP regex into a javscript regex (eg, PHP needs separate delimieters, whereas
52 52
  * javscript does not
53 53
  * @return string
54 54
  */
55
-    public function regex_js()
56
-    {
57
-        // first character must be the delimiter
58
-        $delimeter = $this->_regex[0];
59
-        $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
60
-        return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
61
-    }
55
+	public function regex_js()
56
+	{
57
+		// first character must be the delimiter
58
+		$delimeter = $this->_regex[0];
59
+		$last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
60
+		return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function form($for_display = false)
173 173
     {
174
-        if (! $this->formIsValid()) {
174
+        if ( ! $this->formIsValid()) {
175 175
             return null;
176 176
         }
177 177
         if ($for_display) {
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      */
275 275
     public function setFormName($form_name)
276 276
     {
277
-        if (! is_string($form_name)) {
277
+        if ( ! is_string($form_name)) {
278 278
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
279 279
         }
280 280
         $this->form_name = $form_name;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public function setAdminName($admin_name)
300 300
     {
301
-        if (! is_string($admin_name)) {
301
+        if ( ! is_string($admin_name)) {
302 302
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
303 303
         }
304 304
         $this->admin_name = $admin_name;
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public function setSlug($slug)
324 324
     {
325
-        if (! is_string($slug)) {
325
+        if ( ! is_string($slug)) {
326 326
             throw new InvalidDataTypeException('$slug', $slug, 'string');
327 327
         }
328 328
         $this->slug = $slug;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
      */
346 346
     public function setSubmitBtnText($submit_btn_text)
347 347
     {
348
-        if (! is_string($submit_btn_text)) {
348
+        if ( ! is_string($submit_btn_text)) {
349 349
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
350 350
         }
351 351
         if (empty($submit_btn_text)) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function setFormAction($form_action)
376 376
     {
377
-        if (! is_string($form_action)) {
377
+        if ( ! is_string($form_action)) {
378 378
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
379 379
         }
380 380
         $this->form_action = $form_action;
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
         $text = ! empty($text) ? $text : $this->submitBtnText();
494 494
         return new EE_Submit_Input(
495 495
             array(
496
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
497
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
496
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
497
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
498 498
                 'html_class'            => 'ee-form-submit',
499 499
                 'html_label'            => '&nbsp;',
500
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
500
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
501 501
                 'default'               => $text,
502 502
             )
503 503
         );
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
      */
514 514
     public function appendSubmitButton($text = '')
515 515
     {
516
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
516
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
517 517
             return;
518 518
         }
519 519
         $this->form->add_subsections(
520
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
520
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
521 521
             null,
522 522
             false
523 523
         );
@@ -534,11 +534,11 @@  discard block
 block discarded – undo
534 534
     {
535 535
         $cancel_button = new EE_Submit_Input(
536 536
             array(
537
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
538
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
538
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
539 539
                 'html_class'            => 'ee-cancel-form',
540 540
                 'html_label'            => '&nbsp;',
541
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
541
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
542 542
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
543 543
             )
544 544
         );
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
         $this->form->add_subsections(
559 559
             array(
560 560
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
561
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
561
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
562 562
                 ),
563 563
             ),
564 564
             null,
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
      */
645 645
     public function process($submitted_form_data = array())
646 646
     {
647
-        if (! $this->form()->was_submitted($submitted_form_data)) {
647
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
648 648
             throw new InvalidFormSubmissionException($this->form_name);
649 649
         }
650 650
         $this->form(true)->receive_form_submission($submitted_form_data);
651
-        if (! $this->form()->is_valid()) {
651
+        if ( ! $this->form()->is_valid()) {
652 652
             throw new InvalidFormSubmissionException(
653 653
                 $this->form_name,
654 654
                 sprintf(
Please login to merge, or discard this patch.
Indentation   +638 added lines, -638 removed lines patch added patch discarded remove patch
@@ -28,642 +28,642 @@
 block discarded – undo
28 28
  */
29 29
 abstract class FormHandler implements FormHandlerInterface
30 30
 {
31
-    /**
32
-     * will add opening and closing HTML form tags as well as a submit button
33
-     */
34
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
35
-
36
-    /**
37
-     * will add opening and closing HTML form tags but NOT a submit button
38
-     */
39
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
40
-
41
-    /**
42
-     * will NOT add opening and closing HTML form tags but will add a submit button
43
-     */
44
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
45
-
46
-    /**
47
-     * will NOT add opening and closing HTML form tags NOR a submit button
48
-     */
49
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
50
-
51
-    /**
52
-     * if set to false, then this form has no displayable content,
53
-     * and will only be used for processing data sent passed via GET or POST
54
-     * defaults to true ( ie: form has displayable content )
55
-     *
56
-     * @var boolean $displayable
57
-     */
58
-    private $displayable = true;
59
-
60
-    /**
61
-     * @var string $form_name
62
-     */
63
-    private $form_name;
64
-
65
-    /**
66
-     * @var string $admin_name
67
-     */
68
-    private $admin_name;
69
-
70
-    /**
71
-     * @var string $slug
72
-     */
73
-    private $slug;
74
-
75
-    /**
76
-     * @var string $submit_btn_text
77
-     */
78
-    private $submit_btn_text;
79
-
80
-    /**
81
-     * @var string $form_action
82
-     */
83
-    private $form_action;
84
-
85
-    /**
86
-     * form params in key value pairs
87
-     * can be added to form action URL or as hidden inputs
88
-     *
89
-     * @var array $form_args
90
-     */
91
-    private $form_args = array();
92
-
93
-    /**
94
-     * value of one of the string constant above
95
-     *
96
-     * @var string $form_config
97
-     */
98
-    private $form_config;
99
-
100
-    /**
101
-     * whether or not the form was determined to be invalid
102
-     *
103
-     * @var boolean $form_has_errors
104
-     */
105
-    private $form_has_errors;
106
-
107
-    /**
108
-     * the absolute top level form section being used on the page
109
-     *
110
-     * @var EE_Form_Section_Proper $form
111
-     */
112
-    private $form;
113
-
114
-    /**
115
-     * @var EE_Registry $registry
116
-     */
117
-    protected $registry;
118
-
119
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
120
-
121
-
122
-    /**
123
-     * Form constructor.
124
-     *
125
-     * @param string           $form_name
126
-     * @param string           $admin_name
127
-     * @param string           $slug
128
-     * @param string           $form_action
129
-     * @param string           $form_config
130
-     * @param EE_Registry|null $registry
131
-     */
132
-    public function __construct(
133
-        $form_name,
134
-        $admin_name,
135
-        $slug,
136
-        $form_action = '',
137
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
138
-        EE_Registry $registry = null
139
-    ) {
140
-        $this->setFormName($form_name);
141
-        $this->setAdminName($admin_name);
142
-        $this->setSlug($slug);
143
-        $this->setFormAction($form_action);
144
-        $this->setFormConfig($form_config);
145
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
146
-        $this->registry = $registry;
147
-    }
148
-
149
-
150
-    /**
151
-     * @return array
152
-     */
153
-    public static function getFormConfigConstants()
154
-    {
155
-        return array(
156
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
157
-            FormHandler::ADD_FORM_TAGS_ONLY,
158
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
159
-            FormHandler::DO_NOT_SETUP_FORM,
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * @param bool $for_display
166
-     * @return EE_Form_Section_Proper
167
-     * @throws EE_Error
168
-     * @throws LogicException
169
-     */
170
-    public function form($for_display = false)
171
-    {
172
-        if (! $this->formIsValid()) {
173
-            return null;
174
-        }
175
-        if ($for_display) {
176
-            $form_config = $this->formConfig();
177
-            if (
178
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
179
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
180
-            ) {
181
-                $this->appendSubmitButton();
182
-                $this->clearFormButtonFloats();
183
-            }
184
-        }
185
-        return $this->form;
186
-    }
187
-
188
-
189
-    /**
190
-     * @return boolean
191
-     * @throws LogicException
192
-     */
193
-    public function formIsValid()
194
-    {
195
-        if ($this->form instanceof EE_Form_Section_Proper) {
196
-            return true;
197
-        }
198
-        $form = apply_filters(
199
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
200
-            $this->generate(),
201
-            $this
202
-        );
203
-        if ($this->verifyForm($form)) {
204
-            $this->setForm($form);
205
-        }
206
-        return true;
207
-    }
208
-
209
-
210
-    /**
211
-     * @param EE_Form_Section_Proper|null $form
212
-     * @return bool
213
-     * @throws LogicException
214
-     */
215
-    public function verifyForm(EE_Form_Section_Proper $form = null)
216
-    {
217
-        $form = $form !== null ? $form : $this->form;
218
-        if ($form instanceof EE_Form_Section_Proper) {
219
-            return true;
220
-        }
221
-        throw new LogicException(
222
-            sprintf(
223
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
224
-                $this->form_name,
225
-                var_export($form, true)
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-    /**
232
-     * @param EE_Form_Section_Proper $form
233
-     */
234
-    public function setForm(EE_Form_Section_Proper $form)
235
-    {
236
-        $this->form = $form;
237
-    }
238
-
239
-
240
-    /**
241
-     * @return boolean
242
-     */
243
-    public function displayable()
244
-    {
245
-        return $this->displayable;
246
-    }
247
-
248
-
249
-    /**
250
-     * @param boolean $displayable
251
-     */
252
-    public function setDisplayable($displayable = false)
253
-    {
254
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
255
-    }
256
-
257
-
258
-    /**
259
-     * a public name for the form that can be displayed on the frontend of a site
260
-     *
261
-     * @return string
262
-     */
263
-    public function formName()
264
-    {
265
-        return $this->form_name;
266
-    }
267
-
268
-
269
-    /**
270
-     * @param string $form_name
271
-     * @throws InvalidDataTypeException
272
-     */
273
-    public function setFormName($form_name)
274
-    {
275
-        if (! is_string($form_name)) {
276
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
277
-        }
278
-        $this->form_name = $form_name;
279
-    }
280
-
281
-
282
-    /**
283
-     * a public name for the form that can be displayed, but only in the admin
284
-     *
285
-     * @return string
286
-     */
287
-    public function adminName()
288
-    {
289
-        return $this->admin_name;
290
-    }
291
-
292
-
293
-    /**
294
-     * @param string $admin_name
295
-     * @throws InvalidDataTypeException
296
-     */
297
-    public function setAdminName($admin_name)
298
-    {
299
-        if (! is_string($admin_name)) {
300
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
301
-        }
302
-        $this->admin_name = $admin_name;
303
-    }
304
-
305
-
306
-    /**
307
-     * a URL friendly string that can be used for identifying the form
308
-     *
309
-     * @return string
310
-     */
311
-    public function slug()
312
-    {
313
-        return $this->slug;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param string $slug
319
-     * @throws InvalidDataTypeException
320
-     */
321
-    public function setSlug($slug)
322
-    {
323
-        if (! is_string($slug)) {
324
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
325
-        }
326
-        $this->slug = $slug;
327
-    }
328
-
329
-
330
-    /**
331
-     * @return string
332
-     */
333
-    public function submitBtnText()
334
-    {
335
-        return $this->submit_btn_text;
336
-    }
337
-
338
-
339
-    /**
340
-     * @param string $submit_btn_text
341
-     * @throws InvalidDataTypeException
342
-     * @throws InvalidArgumentException
343
-     */
344
-    public function setSubmitBtnText($submit_btn_text)
345
-    {
346
-        if (! is_string($submit_btn_text)) {
347
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
348
-        }
349
-        if (empty($submit_btn_text)) {
350
-            throw new InvalidArgumentException(
351
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
352
-            );
353
-        }
354
-        $this->submit_btn_text = $submit_btn_text;
355
-    }
356
-
357
-
358
-    /**
359
-     * @return string
360
-     */
361
-    public function formAction()
362
-    {
363
-        return ! empty($this->form_args)
364
-            ? add_query_arg($this->form_args, $this->form_action)
365
-            : $this->form_action;
366
-    }
367
-
368
-
369
-    /**
370
-     * @param string $form_action
371
-     * @throws InvalidDataTypeException
372
-     */
373
-    public function setFormAction($form_action)
374
-    {
375
-        if (! is_string($form_action)) {
376
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
377
-        }
378
-        $this->form_action = $form_action;
379
-    }
380
-
381
-
382
-    /**
383
-     * @param array $form_args
384
-     * @throws InvalidDataTypeException
385
-     * @throws InvalidArgumentException
386
-     */
387
-    public function addFormActionArgs($form_args = array())
388
-    {
389
-        if (is_object($form_args)) {
390
-            throw new InvalidDataTypeException(
391
-                '$form_args',
392
-                $form_args,
393
-                'anything other than an object was expected.'
394
-            );
395
-        }
396
-        if (empty($form_args)) {
397
-            throw new InvalidArgumentException(
398
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
399
-            );
400
-        }
401
-        $this->form_args = array_merge($this->form_args, $form_args);
402
-    }
403
-
404
-
405
-    /**
406
-     * @return string
407
-     */
408
-    public function formConfig()
409
-    {
410
-        return $this->form_config;
411
-    }
412
-
413
-
414
-    /**
415
-     * @param string $form_config
416
-     * @throws DomainException
417
-     */
418
-    public function setFormConfig($form_config)
419
-    {
420
-        if (
421
-            ! in_array(
422
-                $form_config,
423
-                array(
424
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
425
-                FormHandler::ADD_FORM_TAGS_ONLY,
426
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
427
-                FormHandler::DO_NOT_SETUP_FORM,
428
-                ),
429
-                true
430
-            )
431
-        ) {
432
-            throw new DomainException(
433
-                sprintf(
434
-                    esc_html__(
435
-                        '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
436
-                        'event_espresso'
437
-                    ),
438
-                    $form_config
439
-                )
440
-            );
441
-        }
442
-        $this->form_config = $form_config;
443
-    }
444
-
445
-
446
-    /**
447
-     * called after the form is instantiated
448
-     * and used for performing any logic that needs to occur early
449
-     * before any of the other methods are called.
450
-     * returns true if everything is ok to proceed,
451
-     * and false if no further form logic should be implemented
452
-     *
453
-     * @return boolean
454
-     */
455
-    public function initialize()
456
-    {
457
-        $this->form_has_errors = EE_Error::has_error(true);
458
-        return true;
459
-    }
460
-
461
-
462
-    /**
463
-     * used for setting up css and js
464
-     *
465
-     * @return void
466
-     * @throws LogicException
467
-     * @throws EE_Error
468
-     */
469
-    public function enqueueStylesAndScripts()
470
-    {
471
-        $this->form()->enqueue_js();
472
-    }
473
-
474
-
475
-    /**
476
-     * creates and returns the actual form
477
-     *
478
-     * @return EE_Form_Section_Proper
479
-     */
480
-    abstract public function generate();
481
-
482
-
483
-    /**
484
-     * creates and returns an EE_Submit_Input labeled "Submit"
485
-     *
486
-     * @param string $text
487
-     * @return EE_Submit_Input
488
-     */
489
-    public function generateSubmitButton($text = '')
490
-    {
491
-        $text = ! empty($text) ? $text : $this->submitBtnText();
492
-        return new EE_Submit_Input(
493
-            array(
494
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
495
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
496
-                'html_class'            => 'ee-form-submit',
497
-                'html_label'            => '&nbsp;',
498
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
499
-                'default'               => $text,
500
-            )
501
-        );
502
-    }
503
-
504
-
505
-    /**
506
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
507
-     *
508
-     * @param string $text
509
-     * @return void
510
-     * @throws EE_Error
511
-     */
512
-    public function appendSubmitButton($text = '')
513
-    {
514
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
515
-            return;
516
-        }
517
-        $this->form->add_subsections(
518
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
519
-            null,
520
-            false
521
-        );
522
-    }
523
-
524
-
525
-    /**
526
-     * creates and returns an EE_Submit_Input labeled "Cancel"
527
-     *
528
-     * @param string $text
529
-     * @return EE_Submit_Input
530
-     */
531
-    public function generateCancelButton($text = '')
532
-    {
533
-        $cancel_button = new EE_Submit_Input(
534
-            array(
535
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
536
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
-                'html_class'            => 'ee-cancel-form',
538
-                'html_label'            => '&nbsp;',
539
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
540
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
541
-            )
542
-        );
543
-        $cancel_button->set_button_css_attributes(false);
544
-        return $cancel_button;
545
-    }
546
-
547
-
548
-    /**
549
-     * appends a float clearing div onto end of form
550
-     *
551
-     * @return void
552
-     * @throws EE_Error
553
-     */
554
-    public function clearFormButtonFloats()
555
-    {
556
-        $this->form->add_subsections(
557
-            array(
558
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
559
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
560
-                ),
561
-            ),
562
-            null,
563
-            false
564
-        );
565
-    }
566
-
567
-
568
-    /**
569
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
570
-     * returns a string of HTML that can be directly echoed in a template
571
-     *
572
-     * @return string
573
-     * @throws \InvalidArgumentException
574
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
575
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
576
-     * @throws LogicException
577
-     * @throws EE_Error
578
-     */
579
-    public function display()
580
-    {
581
-        $form_html = apply_filters(
582
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
583
-            ''
584
-        );
585
-        $form_config = $this->formConfig();
586
-        if (
587
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
588
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
589
-        ) {
590
-            $additional_props = $this->requiresMultipartEnctype()
591
-                ? ' enctype="multipart/form-data"'
592
-                : '';
593
-            $form_html .= $this->form()->form_open(
594
-                $this->formAction(),
595
-                'POST',
596
-                $additional_props
597
-            );
598
-        }
599
-        $form_html .= $this->form(true)->get_html();
600
-        if (
601
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
602
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
603
-        ) {
604
-            $form_html .= $this->form()->form_close();
605
-        }
606
-        $form_html .= apply_filters(
607
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
608
-            ''
609
-        );
610
-        return $form_html;
611
-    }
612
-
613
-    /**
614
-     * Determines if this form needs "enctype='multipart/form-data'" or not.
615
-     * @since 4.9.80.p
616
-     * @return bool
617
-     * @throws EE_Error
618
-     */
619
-    public function requiresMultipartEnctype()
620
-    {
621
-        foreach ($this->form()->inputs_in_subsections() as $input) {
622
-            if ($input instanceof EE_File_Input) {
623
-                return true;
624
-            }
625
-        }
626
-        return false;
627
-    }
628
-
629
-
630
-    /**
631
-     * handles processing the form submission
632
-     * returns true or false depending on whether the form was processed successfully or not
633
-     *
634
-     * @param array $submitted_form_data
635
-     * @return array
636
-     * @throws \InvalidArgumentException
637
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
638
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
639
-     * @throws EE_Error
640
-     * @throws LogicException
641
-     * @throws InvalidFormSubmissionException
642
-     */
643
-    public function process($submitted_form_data = array())
644
-    {
645
-        if (! $this->form()->was_submitted($submitted_form_data)) {
646
-            throw new InvalidFormSubmissionException($this->form_name);
647
-        }
648
-        $this->form(true)->receive_form_submission($submitted_form_data);
649
-        if (! $this->form()->is_valid()) {
650
-            throw new InvalidFormSubmissionException(
651
-                $this->form_name,
652
-                sprintf(
653
-                    esc_html__(
654
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
655
-                        'event_espresso'
656
-                    ),
657
-                    $this->form_name,
658
-                    '<br />',
659
-                    implode('<br />', $this->form()->get_validation_errors_accumulated())
660
-                )
661
-            );
662
-        }
663
-        return apply_filters(
664
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
665
-            $this->form()->valid_data(),
666
-            $this
667
-        );
668
-    }
31
+	/**
32
+	 * will add opening and closing HTML form tags as well as a submit button
33
+	 */
34
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
35
+
36
+	/**
37
+	 * will add opening and closing HTML form tags but NOT a submit button
38
+	 */
39
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
40
+
41
+	/**
42
+	 * will NOT add opening and closing HTML form tags but will add a submit button
43
+	 */
44
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
45
+
46
+	/**
47
+	 * will NOT add opening and closing HTML form tags NOR a submit button
48
+	 */
49
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
50
+
51
+	/**
52
+	 * if set to false, then this form has no displayable content,
53
+	 * and will only be used for processing data sent passed via GET or POST
54
+	 * defaults to true ( ie: form has displayable content )
55
+	 *
56
+	 * @var boolean $displayable
57
+	 */
58
+	private $displayable = true;
59
+
60
+	/**
61
+	 * @var string $form_name
62
+	 */
63
+	private $form_name;
64
+
65
+	/**
66
+	 * @var string $admin_name
67
+	 */
68
+	private $admin_name;
69
+
70
+	/**
71
+	 * @var string $slug
72
+	 */
73
+	private $slug;
74
+
75
+	/**
76
+	 * @var string $submit_btn_text
77
+	 */
78
+	private $submit_btn_text;
79
+
80
+	/**
81
+	 * @var string $form_action
82
+	 */
83
+	private $form_action;
84
+
85
+	/**
86
+	 * form params in key value pairs
87
+	 * can be added to form action URL or as hidden inputs
88
+	 *
89
+	 * @var array $form_args
90
+	 */
91
+	private $form_args = array();
92
+
93
+	/**
94
+	 * value of one of the string constant above
95
+	 *
96
+	 * @var string $form_config
97
+	 */
98
+	private $form_config;
99
+
100
+	/**
101
+	 * whether or not the form was determined to be invalid
102
+	 *
103
+	 * @var boolean $form_has_errors
104
+	 */
105
+	private $form_has_errors;
106
+
107
+	/**
108
+	 * the absolute top level form section being used on the page
109
+	 *
110
+	 * @var EE_Form_Section_Proper $form
111
+	 */
112
+	private $form;
113
+
114
+	/**
115
+	 * @var EE_Registry $registry
116
+	 */
117
+	protected $registry;
118
+
119
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
120
+
121
+
122
+	/**
123
+	 * Form constructor.
124
+	 *
125
+	 * @param string           $form_name
126
+	 * @param string           $admin_name
127
+	 * @param string           $slug
128
+	 * @param string           $form_action
129
+	 * @param string           $form_config
130
+	 * @param EE_Registry|null $registry
131
+	 */
132
+	public function __construct(
133
+		$form_name,
134
+		$admin_name,
135
+		$slug,
136
+		$form_action = '',
137
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
138
+		EE_Registry $registry = null
139
+	) {
140
+		$this->setFormName($form_name);
141
+		$this->setAdminName($admin_name);
142
+		$this->setSlug($slug);
143
+		$this->setFormAction($form_action);
144
+		$this->setFormConfig($form_config);
145
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
146
+		$this->registry = $registry;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @return array
152
+	 */
153
+	public static function getFormConfigConstants()
154
+	{
155
+		return array(
156
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
157
+			FormHandler::ADD_FORM_TAGS_ONLY,
158
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
159
+			FormHandler::DO_NOT_SETUP_FORM,
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param bool $for_display
166
+	 * @return EE_Form_Section_Proper
167
+	 * @throws EE_Error
168
+	 * @throws LogicException
169
+	 */
170
+	public function form($for_display = false)
171
+	{
172
+		if (! $this->formIsValid()) {
173
+			return null;
174
+		}
175
+		if ($for_display) {
176
+			$form_config = $this->formConfig();
177
+			if (
178
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
179
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
180
+			) {
181
+				$this->appendSubmitButton();
182
+				$this->clearFormButtonFloats();
183
+			}
184
+		}
185
+		return $this->form;
186
+	}
187
+
188
+
189
+	/**
190
+	 * @return boolean
191
+	 * @throws LogicException
192
+	 */
193
+	public function formIsValid()
194
+	{
195
+		if ($this->form instanceof EE_Form_Section_Proper) {
196
+			return true;
197
+		}
198
+		$form = apply_filters(
199
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
200
+			$this->generate(),
201
+			$this
202
+		);
203
+		if ($this->verifyForm($form)) {
204
+			$this->setForm($form);
205
+		}
206
+		return true;
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param EE_Form_Section_Proper|null $form
212
+	 * @return bool
213
+	 * @throws LogicException
214
+	 */
215
+	public function verifyForm(EE_Form_Section_Proper $form = null)
216
+	{
217
+		$form = $form !== null ? $form : $this->form;
218
+		if ($form instanceof EE_Form_Section_Proper) {
219
+			return true;
220
+		}
221
+		throw new LogicException(
222
+			sprintf(
223
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
224
+				$this->form_name,
225
+				var_export($form, true)
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+	/**
232
+	 * @param EE_Form_Section_Proper $form
233
+	 */
234
+	public function setForm(EE_Form_Section_Proper $form)
235
+	{
236
+		$this->form = $form;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @return boolean
242
+	 */
243
+	public function displayable()
244
+	{
245
+		return $this->displayable;
246
+	}
247
+
248
+
249
+	/**
250
+	 * @param boolean $displayable
251
+	 */
252
+	public function setDisplayable($displayable = false)
253
+	{
254
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
255
+	}
256
+
257
+
258
+	/**
259
+	 * a public name for the form that can be displayed on the frontend of a site
260
+	 *
261
+	 * @return string
262
+	 */
263
+	public function formName()
264
+	{
265
+		return $this->form_name;
266
+	}
267
+
268
+
269
+	/**
270
+	 * @param string $form_name
271
+	 * @throws InvalidDataTypeException
272
+	 */
273
+	public function setFormName($form_name)
274
+	{
275
+		if (! is_string($form_name)) {
276
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
277
+		}
278
+		$this->form_name = $form_name;
279
+	}
280
+
281
+
282
+	/**
283
+	 * a public name for the form that can be displayed, but only in the admin
284
+	 *
285
+	 * @return string
286
+	 */
287
+	public function adminName()
288
+	{
289
+		return $this->admin_name;
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param string $admin_name
295
+	 * @throws InvalidDataTypeException
296
+	 */
297
+	public function setAdminName($admin_name)
298
+	{
299
+		if (! is_string($admin_name)) {
300
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
301
+		}
302
+		$this->admin_name = $admin_name;
303
+	}
304
+
305
+
306
+	/**
307
+	 * a URL friendly string that can be used for identifying the form
308
+	 *
309
+	 * @return string
310
+	 */
311
+	public function slug()
312
+	{
313
+		return $this->slug;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param string $slug
319
+	 * @throws InvalidDataTypeException
320
+	 */
321
+	public function setSlug($slug)
322
+	{
323
+		if (! is_string($slug)) {
324
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
325
+		}
326
+		$this->slug = $slug;
327
+	}
328
+
329
+
330
+	/**
331
+	 * @return string
332
+	 */
333
+	public function submitBtnText()
334
+	{
335
+		return $this->submit_btn_text;
336
+	}
337
+
338
+
339
+	/**
340
+	 * @param string $submit_btn_text
341
+	 * @throws InvalidDataTypeException
342
+	 * @throws InvalidArgumentException
343
+	 */
344
+	public function setSubmitBtnText($submit_btn_text)
345
+	{
346
+		if (! is_string($submit_btn_text)) {
347
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
348
+		}
349
+		if (empty($submit_btn_text)) {
350
+			throw new InvalidArgumentException(
351
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
352
+			);
353
+		}
354
+		$this->submit_btn_text = $submit_btn_text;
355
+	}
356
+
357
+
358
+	/**
359
+	 * @return string
360
+	 */
361
+	public function formAction()
362
+	{
363
+		return ! empty($this->form_args)
364
+			? add_query_arg($this->form_args, $this->form_action)
365
+			: $this->form_action;
366
+	}
367
+
368
+
369
+	/**
370
+	 * @param string $form_action
371
+	 * @throws InvalidDataTypeException
372
+	 */
373
+	public function setFormAction($form_action)
374
+	{
375
+		if (! is_string($form_action)) {
376
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
377
+		}
378
+		$this->form_action = $form_action;
379
+	}
380
+
381
+
382
+	/**
383
+	 * @param array $form_args
384
+	 * @throws InvalidDataTypeException
385
+	 * @throws InvalidArgumentException
386
+	 */
387
+	public function addFormActionArgs($form_args = array())
388
+	{
389
+		if (is_object($form_args)) {
390
+			throw new InvalidDataTypeException(
391
+				'$form_args',
392
+				$form_args,
393
+				'anything other than an object was expected.'
394
+			);
395
+		}
396
+		if (empty($form_args)) {
397
+			throw new InvalidArgumentException(
398
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
399
+			);
400
+		}
401
+		$this->form_args = array_merge($this->form_args, $form_args);
402
+	}
403
+
404
+
405
+	/**
406
+	 * @return string
407
+	 */
408
+	public function formConfig()
409
+	{
410
+		return $this->form_config;
411
+	}
412
+
413
+
414
+	/**
415
+	 * @param string $form_config
416
+	 * @throws DomainException
417
+	 */
418
+	public function setFormConfig($form_config)
419
+	{
420
+		if (
421
+			! in_array(
422
+				$form_config,
423
+				array(
424
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
425
+				FormHandler::ADD_FORM_TAGS_ONLY,
426
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
427
+				FormHandler::DO_NOT_SETUP_FORM,
428
+				),
429
+				true
430
+			)
431
+		) {
432
+			throw new DomainException(
433
+				sprintf(
434
+					esc_html__(
435
+						'"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
436
+						'event_espresso'
437
+					),
438
+					$form_config
439
+				)
440
+			);
441
+		}
442
+		$this->form_config = $form_config;
443
+	}
444
+
445
+
446
+	/**
447
+	 * called after the form is instantiated
448
+	 * and used for performing any logic that needs to occur early
449
+	 * before any of the other methods are called.
450
+	 * returns true if everything is ok to proceed,
451
+	 * and false if no further form logic should be implemented
452
+	 *
453
+	 * @return boolean
454
+	 */
455
+	public function initialize()
456
+	{
457
+		$this->form_has_errors = EE_Error::has_error(true);
458
+		return true;
459
+	}
460
+
461
+
462
+	/**
463
+	 * used for setting up css and js
464
+	 *
465
+	 * @return void
466
+	 * @throws LogicException
467
+	 * @throws EE_Error
468
+	 */
469
+	public function enqueueStylesAndScripts()
470
+	{
471
+		$this->form()->enqueue_js();
472
+	}
473
+
474
+
475
+	/**
476
+	 * creates and returns the actual form
477
+	 *
478
+	 * @return EE_Form_Section_Proper
479
+	 */
480
+	abstract public function generate();
481
+
482
+
483
+	/**
484
+	 * creates and returns an EE_Submit_Input labeled "Submit"
485
+	 *
486
+	 * @param string $text
487
+	 * @return EE_Submit_Input
488
+	 */
489
+	public function generateSubmitButton($text = '')
490
+	{
491
+		$text = ! empty($text) ? $text : $this->submitBtnText();
492
+		return new EE_Submit_Input(
493
+			array(
494
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
495
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
496
+				'html_class'            => 'ee-form-submit',
497
+				'html_label'            => '&nbsp;',
498
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
499
+				'default'               => $text,
500
+			)
501
+		);
502
+	}
503
+
504
+
505
+	/**
506
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
507
+	 *
508
+	 * @param string $text
509
+	 * @return void
510
+	 * @throws EE_Error
511
+	 */
512
+	public function appendSubmitButton($text = '')
513
+	{
514
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
515
+			return;
516
+		}
517
+		$this->form->add_subsections(
518
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
519
+			null,
520
+			false
521
+		);
522
+	}
523
+
524
+
525
+	/**
526
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
527
+	 *
528
+	 * @param string $text
529
+	 * @return EE_Submit_Input
530
+	 */
531
+	public function generateCancelButton($text = '')
532
+	{
533
+		$cancel_button = new EE_Submit_Input(
534
+			array(
535
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
536
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
537
+				'html_class'            => 'ee-cancel-form',
538
+				'html_label'            => '&nbsp;',
539
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
540
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
541
+			)
542
+		);
543
+		$cancel_button->set_button_css_attributes(false);
544
+		return $cancel_button;
545
+	}
546
+
547
+
548
+	/**
549
+	 * appends a float clearing div onto end of form
550
+	 *
551
+	 * @return void
552
+	 * @throws EE_Error
553
+	 */
554
+	public function clearFormButtonFloats()
555
+	{
556
+		$this->form->add_subsections(
557
+			array(
558
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
559
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
560
+				),
561
+			),
562
+			null,
563
+			false
564
+		);
565
+	}
566
+
567
+
568
+	/**
569
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
570
+	 * returns a string of HTML that can be directly echoed in a template
571
+	 *
572
+	 * @return string
573
+	 * @throws \InvalidArgumentException
574
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
575
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
576
+	 * @throws LogicException
577
+	 * @throws EE_Error
578
+	 */
579
+	public function display()
580
+	{
581
+		$form_html = apply_filters(
582
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
583
+			''
584
+		);
585
+		$form_config = $this->formConfig();
586
+		if (
587
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
588
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
589
+		) {
590
+			$additional_props = $this->requiresMultipartEnctype()
591
+				? ' enctype="multipart/form-data"'
592
+				: '';
593
+			$form_html .= $this->form()->form_open(
594
+				$this->formAction(),
595
+				'POST',
596
+				$additional_props
597
+			);
598
+		}
599
+		$form_html .= $this->form(true)->get_html();
600
+		if (
601
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
602
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
603
+		) {
604
+			$form_html .= $this->form()->form_close();
605
+		}
606
+		$form_html .= apply_filters(
607
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
608
+			''
609
+		);
610
+		return $form_html;
611
+	}
612
+
613
+	/**
614
+	 * Determines if this form needs "enctype='multipart/form-data'" or not.
615
+	 * @since 4.9.80.p
616
+	 * @return bool
617
+	 * @throws EE_Error
618
+	 */
619
+	public function requiresMultipartEnctype()
620
+	{
621
+		foreach ($this->form()->inputs_in_subsections() as $input) {
622
+			if ($input instanceof EE_File_Input) {
623
+				return true;
624
+			}
625
+		}
626
+		return false;
627
+	}
628
+
629
+
630
+	/**
631
+	 * handles processing the form submission
632
+	 * returns true or false depending on whether the form was processed successfully or not
633
+	 *
634
+	 * @param array $submitted_form_data
635
+	 * @return array
636
+	 * @throws \InvalidArgumentException
637
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
638
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
639
+	 * @throws EE_Error
640
+	 * @throws LogicException
641
+	 * @throws InvalidFormSubmissionException
642
+	 */
643
+	public function process($submitted_form_data = array())
644
+	{
645
+		if (! $this->form()->was_submitted($submitted_form_data)) {
646
+			throw new InvalidFormSubmissionException($this->form_name);
647
+		}
648
+		$this->form(true)->receive_form_submission($submitted_form_data);
649
+		if (! $this->form()->is_valid()) {
650
+			throw new InvalidFormSubmissionException(
651
+				$this->form_name,
652
+				sprintf(
653
+					esc_html__(
654
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
655
+						'event_espresso'
656
+					),
657
+					$this->form_name,
658
+					'<br />',
659
+					implode('<br />', $this->form()->get_validation_errors_accumulated())
660
+				)
661
+			);
662
+		}
663
+		return apply_filters(
664
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
665
+			$this->form()->valid_data(),
666
+			$this
667
+		);
668
+	}
669 669
 }
Please login to merge, or discard this patch.