@@ -15,37 +15,37 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @param array $input_settings |
|
20 | - */ |
|
21 | - public function __construct($input_settings = array()) |
|
22 | - { |
|
23 | - $this->_set_display_strategy( |
|
24 | - new EE_Number_Input_Display_Strategy( |
|
25 | - isset($input_settings['min_value']) |
|
26 | - ? $input_settings['min_value'] |
|
27 | - : null, |
|
28 | - isset($input_settings['max_value']) |
|
29 | - ? $input_settings['max_value'] |
|
30 | - : null |
|
31 | - ) |
|
32 | - ); |
|
33 | - $this->_set_normalization_strategy( |
|
34 | - new EE_Int_Normalization( |
|
35 | - isset($input_settings['validation_error_message']) |
|
36 | - ? $input_settings['validation_error_message'] |
|
37 | - : null |
|
38 | - ) |
|
39 | - ); |
|
40 | - $this->_add_validation_strategy( |
|
41 | - new EE_Int_Validation_Strategy( |
|
42 | - isset($input_settings['validation_error_message']) |
|
43 | - ? $input_settings['validation_error_message'] |
|
44 | - : null |
|
45 | - ) |
|
46 | - ); |
|
47 | - parent::__construct($input_settings); |
|
48 | - } |
|
18 | + /** |
|
19 | + * @param array $input_settings |
|
20 | + */ |
|
21 | + public function __construct($input_settings = array()) |
|
22 | + { |
|
23 | + $this->_set_display_strategy( |
|
24 | + new EE_Number_Input_Display_Strategy( |
|
25 | + isset($input_settings['min_value']) |
|
26 | + ? $input_settings['min_value'] |
|
27 | + : null, |
|
28 | + isset($input_settings['max_value']) |
|
29 | + ? $input_settings['max_value'] |
|
30 | + : null |
|
31 | + ) |
|
32 | + ); |
|
33 | + $this->_set_normalization_strategy( |
|
34 | + new EE_Int_Normalization( |
|
35 | + isset($input_settings['validation_error_message']) |
|
36 | + ? $input_settings['validation_error_message'] |
|
37 | + : null |
|
38 | + ) |
|
39 | + ); |
|
40 | + $this->_add_validation_strategy( |
|
41 | + new EE_Int_Validation_Strategy( |
|
42 | + isset($input_settings['validation_error_message']) |
|
43 | + ? $input_settings['validation_error_message'] |
|
44 | + : null |
|
45 | + ) |
|
46 | + ); |
|
47 | + parent::__construct($input_settings); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | // End of file EE_Integer_Input.php |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,1137 +16,1137 @@ discard block |
||
16 | 16 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * the input's name attribute |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_html_name; |
|
25 | - |
|
26 | - /** |
|
27 | - * id for the html label tag |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_html_label_id; |
|
32 | - |
|
33 | - /** |
|
34 | - * class for teh html label tag |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $_html_label_class; |
|
39 | - |
|
40 | - /** |
|
41 | - * any additional html attributes that you may want to add |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_html_other_attributes; |
|
46 | - |
|
47 | - /** |
|
48 | - * style for teh html label tag |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_html_label_style; |
|
53 | - |
|
54 | - /** |
|
55 | - * text to be placed in the html label |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $_html_label_text; |
|
60 | - |
|
61 | - /** |
|
62 | - * the full html label. If used, all other html_label_* properties are invalid |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $_html_label; |
|
67 | - |
|
68 | - /** |
|
69 | - * HTML to use for help text (normally placed below form input), in a span which normally |
|
70 | - * has a class of 'description' |
|
71 | - * |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - protected $_html_help_text; |
|
75 | - |
|
76 | - /** |
|
77 | - * CSS classes for displaying the help span |
|
78 | - * |
|
79 | - * @var string |
|
80 | - */ |
|
81 | - protected $_html_help_class = 'description'; |
|
82 | - |
|
83 | - /** |
|
84 | - * CSS to put in the style attribute on the help span |
|
85 | - * |
|
86 | - * @var string |
|
87 | - */ |
|
88 | - protected $_html_help_style; |
|
89 | - |
|
90 | - /** |
|
91 | - * Stores whether or not this input's response is required. |
|
92 | - * Because certain styling elements may also want to know that this |
|
93 | - * input is required etc. |
|
94 | - * |
|
95 | - * @var boolean |
|
96 | - */ |
|
97 | - protected $_required; |
|
98 | - |
|
99 | - /** |
|
100 | - * css class added to required inputs |
|
101 | - * |
|
102 | - * @var string |
|
103 | - */ |
|
104 | - protected $_required_css_class = 'ee-required'; |
|
105 | - |
|
106 | - /** |
|
107 | - * css styles applied to button type inputs |
|
108 | - * |
|
109 | - * @var string |
|
110 | - */ |
|
111 | - protected $_button_css_attributes; |
|
112 | - |
|
113 | - /** |
|
114 | - * The raw data submitted for this, like in the $_POST super global. |
|
115 | - * Generally unsafe for usage in client code |
|
116 | - * |
|
117 | - * @var mixed string or array |
|
118 | - */ |
|
119 | - protected $_raw_value; |
|
120 | - |
|
121 | - /** |
|
122 | - * Value normalized according to the input's normalization strategy. |
|
123 | - * The normalization strategy dictates whether this is a string, int, float, |
|
124 | - * boolean, or array of any of those. |
|
125 | - * |
|
126 | - * @var mixed |
|
127 | - */ |
|
128 | - protected $_normalized_value; |
|
129 | - |
|
130 | - /** |
|
131 | - * Strategy used for displaying this field. |
|
132 | - * Child classes must use _get_display_strategy to access it. |
|
133 | - * |
|
134 | - * @var EE_Display_Strategy_Base |
|
135 | - */ |
|
136 | - private $_display_strategy; |
|
137 | - |
|
138 | - /** |
|
139 | - * Gets all the validation strategies used on this field |
|
140 | - * |
|
141 | - * @var EE_Validation_Strategy_Base[] |
|
142 | - */ |
|
143 | - private $_validation_strategies = array(); |
|
144 | - |
|
145 | - /** |
|
146 | - * The normalization strategy for this field |
|
147 | - * |
|
148 | - * @var EE_Normalization_Strategy_Base |
|
149 | - */ |
|
150 | - private $_normalization_strategy; |
|
151 | - |
|
152 | - /** |
|
153 | - * Strategy for removing sensitive data after we're done with the form input |
|
154 | - * |
|
155 | - * @var EE_Sensitive_Data_Removal_Base |
|
156 | - */ |
|
157 | - protected $_sensitive_data_removal_strategy; |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param array $input_args { |
|
163 | - * @type string $html_name the html name for the input |
|
164 | - * @type string $html_label_id the id attribute to give to the html label tag |
|
165 | - * @type string $html_label_class the class attribute to give to the html label tag |
|
166 | - * @type string $html_label_style the style attribute to give ot teh label tag |
|
167 | - * @type string $html_label_text the text to put in the label tag |
|
168 | - * @type string $html_label the full html label. If used, |
|
169 | - * all other html_label_* args are invalid |
|
170 | - * @type string $html_help_text text to put in help element |
|
171 | - * @type string $html_help_style style attribute to give to teh help element |
|
172 | - * @type string $html_help_class class attribute to give to the help element |
|
173 | - * @type string $default default value NORMALIZED (eg, if providing the default |
|
174 | - * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
175 | - * @type EE_Display_Strategy_Base $display strategy |
|
176 | - * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
177 | - * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
178 | - * } |
|
179 | - */ |
|
180 | - public function __construct($input_args = array()) |
|
181 | - { |
|
182 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
183 | - // the following properties must be cast as arrays |
|
184 | - if (isset($input_args['validation_strategies'])) { |
|
185 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
186 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
187 | - $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
188 | - } |
|
189 | - } |
|
190 | - unset($input_args['validation_strategies']); |
|
191 | - } |
|
192 | - // loop thru incoming options |
|
193 | - foreach ($input_args as $key => $value) { |
|
194 | - // add underscore to $key to match property names |
|
195 | - $_key = '_' . $key; |
|
196 | - if (property_exists($this, $_key)) { |
|
197 | - $this->{$_key} = $value; |
|
198 | - } |
|
199 | - } |
|
200 | - // ensure that "required" is set correctly |
|
201 | - $this->set_required( |
|
202 | - $this->_required, isset($input_args['required_validation_error_message']) |
|
203 | - ? $input_args['required_validation_error_message'] |
|
204 | - : null |
|
205 | - ); |
|
206 | - //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
207 | - $this->_display_strategy->_construct_finalize($this); |
|
208 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
209 | - $validation_strategy->_construct_finalize($this); |
|
210 | - } |
|
211 | - if (! $this->_normalization_strategy) { |
|
212 | - $this->_normalization_strategy = new EE_Text_Normalization(); |
|
213 | - } |
|
214 | - $this->_normalization_strategy->_construct_finalize($this); |
|
215 | - //at least we can use the normalization strategy to populate the default |
|
216 | - if (isset($input_args['default'])) { |
|
217 | - $this->set_default($input_args['default']); |
|
218 | - } |
|
219 | - if (! $this->_sensitive_data_removal_strategy) { |
|
220 | - $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
221 | - } |
|
222 | - $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
223 | - parent::__construct($input_args); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Sets the html_name to its default value, if none was specified in teh constructor. |
|
230 | - * Calculation involves using the name and the parent's html_name |
|
231 | - * |
|
232 | - * @throws \EE_Error |
|
233 | - */ |
|
234 | - protected function _set_default_html_name_if_empty() |
|
235 | - { |
|
236 | - if (! $this->_html_name) { |
|
237 | - $this->_html_name = $this->name(); |
|
238 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
239 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param $parent_form_section |
|
248 | - * @param $name |
|
249 | - * @throws \EE_Error |
|
250 | - */ |
|
251 | - public function _construct_finalize($parent_form_section, $name) |
|
252 | - { |
|
253 | - parent::_construct_finalize($parent_form_section, $name); |
|
254 | - if ($this->_html_label === null && $this->_html_label_text === null) { |
|
255 | - $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
256 | - } |
|
257 | - do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
264 | - * |
|
265 | - * @return EE_Display_Strategy_Base |
|
266 | - * @throws EE_Error |
|
267 | - */ |
|
268 | - protected function _get_display_strategy() |
|
269 | - { |
|
270 | - $this->ensure_construct_finalized_called(); |
|
271 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
272 | - throw new EE_Error( |
|
273 | - sprintf( |
|
274 | - __( |
|
275 | - "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
276 | - "event_espresso" |
|
277 | - ), |
|
278 | - $this->html_name(), |
|
279 | - $this->html_id() |
|
280 | - ) |
|
281 | - ); |
|
282 | - } else { |
|
283 | - return $this->_display_strategy; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Sets the display strategy. |
|
291 | - * |
|
292 | - * @param EE_Display_Strategy_Base $strategy |
|
293 | - */ |
|
294 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
295 | - { |
|
296 | - $this->_display_strategy = $strategy; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Sets the sanitization strategy |
|
303 | - * |
|
304 | - * @param EE_Normalization_Strategy_Base $strategy |
|
305 | - */ |
|
306 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
307 | - { |
|
308 | - $this->_normalization_strategy = $strategy; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets sensitive_data_removal_strategy |
|
315 | - * |
|
316 | - * @return EE_Sensitive_Data_Removal_Base |
|
317 | - */ |
|
318 | - public function get_sensitive_data_removal_strategy() |
|
319 | - { |
|
320 | - return $this->_sensitive_data_removal_strategy; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * Sets sensitive_data_removal_strategy |
|
327 | - * |
|
328 | - * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
329 | - * @return boolean |
|
330 | - */ |
|
331 | - public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
332 | - { |
|
333 | - $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Gets the display strategy for this input |
|
340 | - * |
|
341 | - * @return EE_Display_Strategy_Base |
|
342 | - */ |
|
343 | - public function get_display_strategy() |
|
344 | - { |
|
345 | - return $this->_display_strategy; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * Overwrites the display strategy |
|
352 | - * |
|
353 | - * @param EE_Display_Strategy_Base $display_strategy |
|
354 | - */ |
|
355 | - public function set_display_strategy($display_strategy) |
|
356 | - { |
|
357 | - $this->_display_strategy = $display_strategy; |
|
358 | - $this->_display_strategy->_construct_finalize($this); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Gets the normalization strategy set on this input |
|
365 | - * |
|
366 | - * @return EE_Normalization_Strategy_Base |
|
367 | - */ |
|
368 | - public function get_normalization_strategy() |
|
369 | - { |
|
370 | - return $this->_normalization_strategy; |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Overwrites the normalization strategy |
|
377 | - * |
|
378 | - * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
379 | - */ |
|
380 | - public function set_normalization_strategy($normalization_strategy) |
|
381 | - { |
|
382 | - $this->_normalization_strategy = $normalization_strategy; |
|
383 | - $this->_normalization_strategy->_construct_finalize($this); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Returns all teh validation strategies which apply to this field, numerically indexed |
|
390 | - * |
|
391 | - * @return EE_Validation_Strategy_Base[] |
|
392 | - */ |
|
393 | - public function get_validation_strategies() |
|
394 | - { |
|
395 | - return $this->_validation_strategies; |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
402 | - * |
|
403 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
404 | - * @return void |
|
405 | - */ |
|
406 | - protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
407 | - { |
|
408 | - $validation_strategy->_construct_finalize($this); |
|
409 | - $this->_validation_strategies[] = $validation_strategy; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Adds a new validation strategy onto the form input |
|
416 | - * |
|
417 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
418 | - * @return void |
|
419 | - */ |
|
420 | - public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
421 | - { |
|
422 | - $this->_add_validation_strategy($validation_strategy); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * The classname of the validation strategy to remove |
|
429 | - * |
|
430 | - * @param string $validation_strategy_classname |
|
431 | - */ |
|
432 | - public function remove_validation_strategy($validation_strategy_classname) |
|
433 | - { |
|
434 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
435 | - if ( |
|
436 | - $validation_strategy instanceof $validation_strategy_classname |
|
437 | - || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
438 | - ) { |
|
439 | - unset($this->_validation_strategies[$key]); |
|
440 | - } |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
448 | - * |
|
449 | - * @param array $validation_strategy_classnames |
|
450 | - * @return bool |
|
451 | - */ |
|
452 | - public function has_validation_strategy($validation_strategy_classnames) |
|
453 | - { |
|
454 | - $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
455 | - ? $validation_strategy_classnames |
|
456 | - : array($validation_strategy_classnames); |
|
457 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
458 | - if (in_array($key, $validation_strategy_classnames)) { |
|
459 | - return true; |
|
460 | - } |
|
461 | - } |
|
462 | - return false; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * Gets the HTML |
|
469 | - * |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - public function get_html() |
|
473 | - { |
|
474 | - return $this->_parent_section->get_html_for_input($this); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Gets the HTML for the input itself (no label or errors) according to the |
|
481 | - * input's display strategy |
|
482 | - * Makes sure the JS and CSS are enqueued for it |
|
483 | - * |
|
484 | - * @return string |
|
485 | - * @throws \EE_Error |
|
486 | - */ |
|
487 | - public function get_html_for_input() |
|
488 | - { |
|
489 | - return $this->_get_display_strategy()->display(); |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * @return string |
|
496 | - */ |
|
497 | - public function html_other_attributes() |
|
498 | - { |
|
499 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * @param string $html_other_attributes |
|
506 | - */ |
|
507 | - public function set_html_other_attributes($html_other_attributes) |
|
508 | - { |
|
509 | - $this->_html_other_attributes = $html_other_attributes; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Gets the HTML for displaying the label for this form input |
|
516 | - * according to the form section's layout strategy |
|
517 | - * |
|
518 | - * @return string |
|
519 | - */ |
|
520 | - public function get_html_for_label() |
|
521 | - { |
|
522 | - return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Gets the HTML for displaying the errors section for this form input |
|
529 | - * according to the form section's layout strategy |
|
530 | - * |
|
531 | - * @return string |
|
532 | - */ |
|
533 | - public function get_html_for_errors() |
|
534 | - { |
|
535 | - return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * Gets the HTML for displaying the help text for this form input |
|
542 | - * according to the form section's layout strategy |
|
543 | - * |
|
544 | - * @return string |
|
545 | - */ |
|
546 | - public function get_html_for_help() |
|
547 | - { |
|
548 | - return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
555 | - * and returns whether or not the form input's submitted value is value |
|
556 | - * |
|
557 | - * @return boolean |
|
558 | - */ |
|
559 | - protected function _validate() |
|
560 | - { |
|
561 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
562 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
563 | - try { |
|
564 | - $validation_strategy->validate($this->normalized_value()); |
|
565 | - } catch (EE_Validation_Error $e) { |
|
566 | - $this->add_validation_error($e); |
|
567 | - } |
|
568 | - } |
|
569 | - } |
|
570 | - if ($this->get_validation_errors()) { |
|
571 | - return false; |
|
572 | - } else { |
|
573 | - return true; |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
581 | - * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
582 | - * |
|
583 | - * @param string $value |
|
584 | - * @return null|string |
|
585 | - */ |
|
586 | - private function _sanitize($value) |
|
587 | - { |
|
588 | - return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Picks out the form value that relates to this form input, |
|
595 | - * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
596 | - * Returns whether or not any validation errors occurred |
|
597 | - * |
|
598 | - * @param array $req_data like $_POST |
|
599 | - * @return boolean whether or not there was an error |
|
600 | - * @throws \EE_Error |
|
601 | - */ |
|
602 | - protected function _normalize($req_data) |
|
603 | - { |
|
604 | - //any existing validation errors don't apply so clear them |
|
605 | - $this->_validation_errors = array(); |
|
606 | - try { |
|
607 | - $raw_input = $this->find_form_data_for_this_section($req_data); |
|
608 | - //super simple sanitization for now |
|
609 | - if (is_array($raw_input)) { |
|
610 | - $raw_value = array(); |
|
611 | - foreach ($raw_input as $key => $value) { |
|
612 | - $raw_value[$key] = $this->_sanitize($value); |
|
613 | - } |
|
614 | - $this->_set_raw_value($raw_value); |
|
615 | - } else { |
|
616 | - $this->_set_raw_value($this->_sanitize($raw_input)); |
|
617 | - } |
|
618 | - //we want to mostly leave the input alone in case we need to re-display it to the user |
|
619 | - $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
620 | - } catch (EE_Validation_Error $e) { |
|
621 | - $this->add_validation_error($e); |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * @return string |
|
629 | - */ |
|
630 | - public function html_name() |
|
631 | - { |
|
632 | - $this->_set_default_html_name_if_empty(); |
|
633 | - return $this->_html_name; |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * @return string |
|
640 | - */ |
|
641 | - public function html_label_id() |
|
642 | - { |
|
643 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * @return string |
|
650 | - */ |
|
651 | - public function html_label_class() |
|
652 | - { |
|
653 | - return $this->_html_label_class; |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public function html_label_style() |
|
662 | - { |
|
663 | - return $this->_html_label_style; |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * @return string |
|
670 | - */ |
|
671 | - public function html_label_text() |
|
672 | - { |
|
673 | - return $this->_html_label_text; |
|
674 | - } |
|
675 | - |
|
676 | - |
|
677 | - |
|
678 | - /** |
|
679 | - * @return string |
|
680 | - */ |
|
681 | - public function html_help_text() |
|
682 | - { |
|
683 | - return $this->_html_help_text; |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * @return string |
|
690 | - */ |
|
691 | - public function html_help_class() |
|
692 | - { |
|
693 | - return $this->_html_help_class; |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * @return string |
|
700 | - */ |
|
701 | - public function html_help_style() |
|
702 | - { |
|
703 | - return $this->_html_style; |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
710 | - * Please note that almost all client code should instead use the normalized_value; |
|
711 | - * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
712 | - * mostly by escaping quotes) |
|
713 | - * Note, we do not store the exact original value sent in the user's request because |
|
714 | - * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
715 | - * in which case, we would have stored the malicious content to our database. |
|
716 | - * |
|
717 | - * @return string |
|
718 | - */ |
|
719 | - public function raw_value() |
|
720 | - { |
|
721 | - return $this->_raw_value; |
|
722 | - } |
|
723 | - |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * Returns a string safe to usage in form inputs when displaying, because |
|
728 | - * it escapes all html entities |
|
729 | - * |
|
730 | - * @return string |
|
731 | - */ |
|
732 | - public function raw_value_in_form() |
|
733 | - { |
|
734 | - return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * returns the value after it's been sanitized, and then converted into it's proper type |
|
741 | - * in PHP. Eg, a string, an int, an array, |
|
742 | - * |
|
743 | - * @return mixed |
|
744 | - */ |
|
745 | - public function normalized_value() |
|
746 | - { |
|
747 | - return $this->_normalized_value; |
|
748 | - } |
|
749 | - |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * Returns the normalized value is a presentable way. By default this is just |
|
754 | - * the normalized value by itself, but it can be overridden for when that's not |
|
755 | - * the best thing to display |
|
756 | - * |
|
757 | - * @return string |
|
758 | - */ |
|
759 | - public function pretty_value() |
|
760 | - { |
|
761 | - return $this->_normalized_value; |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * When generating the JS for the jquery validation rules like<br> |
|
768 | - * <code>$( "#myform" ).validate({ |
|
769 | - * rules: { |
|
770 | - * password: "required", |
|
771 | - * password_again: { |
|
772 | - * equalTo: "#password" |
|
773 | - * } |
|
774 | - * } |
|
775 | - * });</code> |
|
776 | - * if this field had the name 'password_again', it should return |
|
777 | - * <br><code>password_again: { |
|
778 | - * equalTo: "#password" |
|
779 | - * }</code> |
|
780 | - * |
|
781 | - * @return array |
|
782 | - */ |
|
783 | - public function get_jquery_validation_rules() |
|
784 | - { |
|
785 | - $jquery_validation_js = array(); |
|
786 | - $jquery_validation_rules = array(); |
|
787 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
788 | - $jquery_validation_rules = array_replace_recursive( |
|
789 | - $jquery_validation_rules, |
|
790 | - $validation_strategy->get_jquery_validation_rule_array() |
|
791 | - ); |
|
792 | - } |
|
793 | - if (! empty($jquery_validation_rules)) { |
|
794 | - foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
795 | - $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
796 | - } |
|
797 | - } |
|
798 | - return $jquery_validation_js; |
|
799 | - } |
|
800 | - |
|
801 | - |
|
802 | - |
|
803 | - /** |
|
804 | - * Sets the input's default value for use in displaying in the form. Note: value should be |
|
805 | - * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
806 | - * |
|
807 | - * @param mixed $value |
|
808 | - * @return void |
|
809 | - */ |
|
810 | - public function set_default($value) |
|
811 | - { |
|
812 | - $this->_set_normalized_value($value); |
|
813 | - $this->_set_raw_value($value); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - |
|
818 | - /** |
|
819 | - * Sets the normalized value on this input |
|
820 | - * |
|
821 | - * @param mixed $value |
|
822 | - */ |
|
823 | - protected function _set_normalized_value($value) |
|
824 | - { |
|
825 | - $this->_normalized_value = $value; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - |
|
830 | - /** |
|
831 | - * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
832 | - * |
|
833 | - * @param mixed $value |
|
834 | - */ |
|
835 | - protected function _set_raw_value($value) |
|
836 | - { |
|
837 | - $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - |
|
842 | - /** |
|
843 | - * Sets the HTML label text after it has already been defined |
|
844 | - * |
|
845 | - * @param string $label |
|
846 | - * @return void |
|
847 | - */ |
|
848 | - public function set_html_label_text($label) |
|
849 | - { |
|
850 | - $this->_html_label_text = $label; |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - |
|
855 | - /** |
|
856 | - * Sets whether or not this field is required, and adjusts the validation strategy. |
|
857 | - * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
858 | - * please add it as a validation strategy using add_validation_strategy as normal |
|
859 | - * |
|
860 | - * @param boolean $required boolean |
|
861 | - * @param null $required_text |
|
862 | - */ |
|
863 | - public function set_required($required = true, $required_text = null) |
|
864 | - { |
|
865 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
866 | - //whether $required is a string or a boolean, we want to add a required validation strategy |
|
867 | - if ($required) { |
|
868 | - $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
869 | - } else { |
|
870 | - $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
871 | - } |
|
872 | - $this->_required = $required; |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - |
|
877 | - /** |
|
878 | - * Returns whether or not this field is required |
|
879 | - * |
|
880 | - * @return boolean |
|
881 | - */ |
|
882 | - public function required() |
|
883 | - { |
|
884 | - return $this->_required; |
|
885 | - } |
|
886 | - |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * @param string $required_css_class |
|
891 | - */ |
|
892 | - public function set_required_css_class($required_css_class) |
|
893 | - { |
|
894 | - $this->_required_css_class = $required_css_class; |
|
895 | - } |
|
896 | - |
|
897 | - |
|
898 | - |
|
899 | - /** |
|
900 | - * @return string |
|
901 | - */ |
|
902 | - public function required_css_class() |
|
903 | - { |
|
904 | - return $this->_required_css_class; |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param bool $add_required |
|
911 | - * @return string |
|
912 | - */ |
|
913 | - public function html_class($add_required = false) |
|
914 | - { |
|
915 | - return $add_required && $this->required() |
|
916 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
917 | - : $this->_html_class; |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * Sets the help text, in case |
|
923 | - * |
|
924 | - * @param string $text |
|
925 | - */ |
|
926 | - public function set_html_help_text($text) |
|
927 | - { |
|
928 | - $this->_html_help_text = $text; |
|
929 | - } |
|
930 | - |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
935 | - * input. If there is any kind of sensitive data removal on this input, we clear |
|
936 | - * out the raw value completely |
|
937 | - * |
|
938 | - * @return void |
|
939 | - */ |
|
940 | - public function clean_sensitive_data() |
|
941 | - { |
|
942 | - //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
943 | - //if we need more logic than this we'll make a strategy for it |
|
944 | - if ($this->_sensitive_data_removal_strategy |
|
945 | - && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
946 | - ) { |
|
947 | - $this->_set_raw_value(null); |
|
948 | - } |
|
949 | - //and clean the normalized value according to the appropriate strategy |
|
950 | - $this->_set_normalized_value( |
|
951 | - $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
952 | - $this->_normalized_value |
|
953 | - ) |
|
954 | - ); |
|
955 | - } |
|
956 | - |
|
957 | - |
|
958 | - |
|
959 | - /** |
|
960 | - * @param bool $primary |
|
961 | - * @param string $button_size |
|
962 | - * @param string $other_attributes |
|
963 | - */ |
|
964 | - public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
965 | - { |
|
966 | - $button_css_attributes = 'button'; |
|
967 | - $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
968 | - switch ($button_size) { |
|
969 | - case 'xs' : |
|
970 | - case 'extra-small' : |
|
971 | - $button_css_attributes .= ' button-xs'; |
|
972 | - break; |
|
973 | - case 'sm' : |
|
974 | - case 'small' : |
|
975 | - $button_css_attributes .= ' button-sm'; |
|
976 | - break; |
|
977 | - case 'lg' : |
|
978 | - case 'large' : |
|
979 | - $button_css_attributes .= ' button-lg'; |
|
980 | - break; |
|
981 | - case 'block' : |
|
982 | - $button_css_attributes .= ' button-block'; |
|
983 | - break; |
|
984 | - case 'md' : |
|
985 | - case 'medium' : |
|
986 | - default : |
|
987 | - $button_css_attributes .= ''; |
|
988 | - } |
|
989 | - $this->_button_css_attributes .= ! empty($other_attributes) |
|
990 | - ? $button_css_attributes . ' ' . $other_attributes |
|
991 | - : $button_css_attributes; |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * @return string |
|
998 | - */ |
|
999 | - public function button_css_attributes() |
|
1000 | - { |
|
1001 | - if (empty($this->_button_css_attributes)) { |
|
1002 | - $this->set_button_css_attributes(); |
|
1003 | - } |
|
1004 | - return $this->_button_css_attributes; |
|
1005 | - } |
|
1006 | - |
|
1007 | - |
|
1008 | - |
|
1009 | - /** |
|
1010 | - * find_form_data_for_this_section |
|
1011 | - * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1012 | - * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1013 | - * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1014 | - * (If that doesn't exist, we also check for this subsection's name |
|
1015 | - * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1016 | - * This function finds its value in the form. |
|
1017 | - * |
|
1018 | - * @param array $req_data |
|
1019 | - * @return mixed whatever the raw value of this form section is in the request data |
|
1020 | - * @throws \EE_Error |
|
1021 | - */ |
|
1022 | - public function find_form_data_for_this_section($req_data) |
|
1023 | - { |
|
1024 | - // break up the html name by "[]" |
|
1025 | - if (strpos($this->html_name(), '[') !== false) { |
|
1026 | - $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1027 | - } else { |
|
1028 | - $before_any_brackets = $this->html_name(); |
|
1029 | - } |
|
1030 | - // grab all of the segments |
|
1031 | - preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1032 | - if (isset($matches[1]) && is_array($matches[1])) { |
|
1033 | - $name_parts = $matches[1]; |
|
1034 | - array_unshift($name_parts, $before_any_brackets); |
|
1035 | - } else { |
|
1036 | - $name_parts = array($before_any_brackets); |
|
1037 | - } |
|
1038 | - // now get the value for the input |
|
1039 | - $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
1040 | - // check if this thing's name is at the TOP level of the request data |
|
1041 | - if ($value === null && isset($req_data[$this->name()])) { |
|
1042 | - $value = $req_data[$this->name()]; |
|
1043 | - } |
|
1044 | - return $value; |
|
1045 | - } |
|
1046 | - |
|
1047 | - |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * @param array $html_name_parts |
|
1051 | - * @param array $req_data |
|
1052 | - * @return array | NULL |
|
1053 | - */ |
|
1054 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
1055 | - { |
|
1056 | - $first_part_to_consider = array_shift($html_name_parts); |
|
1057 | - if (isset($req_data[$first_part_to_consider])) { |
|
1058 | - if (empty($html_name_parts)) { |
|
1059 | - return $req_data[$first_part_to_consider]; |
|
1060 | - } else { |
|
1061 | - return $this->_find_form_data_for_this_section_using_name_parts( |
|
1062 | - $html_name_parts, |
|
1063 | - $req_data[$first_part_to_consider] |
|
1064 | - ); |
|
1065 | - } |
|
1066 | - } else { |
|
1067 | - return null; |
|
1068 | - } |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - |
|
1073 | - /** |
|
1074 | - * Checks if this form input's data is in the request data |
|
1075 | - * |
|
1076 | - * @param array $req_data like $_POST |
|
1077 | - * @return boolean |
|
1078 | - * @throws \EE_Error |
|
1079 | - */ |
|
1080 | - public function form_data_present_in($req_data = null) |
|
1081 | - { |
|
1082 | - if ($req_data === null) { |
|
1083 | - $req_data = $_POST; |
|
1084 | - } |
|
1085 | - $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1086 | - if ($checked_value !== null) { |
|
1087 | - return true; |
|
1088 | - } else { |
|
1089 | - return false; |
|
1090 | - } |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * Overrides parent to add js data from validation and display strategies |
|
1097 | - * |
|
1098 | - * @param array $form_other_js_data |
|
1099 | - * @return array |
|
1100 | - */ |
|
1101 | - public function get_other_js_data($form_other_js_data = array()) |
|
1102 | - { |
|
1103 | - $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1104 | - return $form_other_js_data; |
|
1105 | - } |
|
1106 | - |
|
1107 | - |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * Gets other JS data for localization from this input's strategies, like |
|
1111 | - * the validation strategies and the display strategy |
|
1112 | - * |
|
1113 | - * @param array $form_other_js_data |
|
1114 | - * @return array |
|
1115 | - */ |
|
1116 | - public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1117 | - { |
|
1118 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1119 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1120 | - $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1121 | - } |
|
1122 | - return $form_other_js_data; |
|
1123 | - } |
|
1124 | - |
|
1125 | - |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1129 | - * |
|
1130 | - * @return void |
|
1131 | - */ |
|
1132 | - public function enqueue_js() |
|
1133 | - { |
|
1134 | - //ask our display strategy and validation strategies if they have js to enqueue |
|
1135 | - $this->enqueue_js_from_strategies(); |
|
1136 | - } |
|
1137 | - |
|
1138 | - |
|
1139 | - |
|
1140 | - /** |
|
1141 | - * Tells strategies when its ok to enqueue their js and css |
|
1142 | - * |
|
1143 | - * @return void |
|
1144 | - */ |
|
1145 | - public function enqueue_js_from_strategies() |
|
1146 | - { |
|
1147 | - $this->get_display_strategy()->enqueue_js(); |
|
1148 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1149 | - $validation_strategy->enqueue_js(); |
|
1150 | - } |
|
1151 | - } |
|
19 | + /** |
|
20 | + * the input's name attribute |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_html_name; |
|
25 | + |
|
26 | + /** |
|
27 | + * id for the html label tag |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_html_label_id; |
|
32 | + |
|
33 | + /** |
|
34 | + * class for teh html label tag |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $_html_label_class; |
|
39 | + |
|
40 | + /** |
|
41 | + * any additional html attributes that you may want to add |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_html_other_attributes; |
|
46 | + |
|
47 | + /** |
|
48 | + * style for teh html label tag |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_html_label_style; |
|
53 | + |
|
54 | + /** |
|
55 | + * text to be placed in the html label |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $_html_label_text; |
|
60 | + |
|
61 | + /** |
|
62 | + * the full html label. If used, all other html_label_* properties are invalid |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $_html_label; |
|
67 | + |
|
68 | + /** |
|
69 | + * HTML to use for help text (normally placed below form input), in a span which normally |
|
70 | + * has a class of 'description' |
|
71 | + * |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + protected $_html_help_text; |
|
75 | + |
|
76 | + /** |
|
77 | + * CSS classes for displaying the help span |
|
78 | + * |
|
79 | + * @var string |
|
80 | + */ |
|
81 | + protected $_html_help_class = 'description'; |
|
82 | + |
|
83 | + /** |
|
84 | + * CSS to put in the style attribute on the help span |
|
85 | + * |
|
86 | + * @var string |
|
87 | + */ |
|
88 | + protected $_html_help_style; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores whether or not this input's response is required. |
|
92 | + * Because certain styling elements may also want to know that this |
|
93 | + * input is required etc. |
|
94 | + * |
|
95 | + * @var boolean |
|
96 | + */ |
|
97 | + protected $_required; |
|
98 | + |
|
99 | + /** |
|
100 | + * css class added to required inputs |
|
101 | + * |
|
102 | + * @var string |
|
103 | + */ |
|
104 | + protected $_required_css_class = 'ee-required'; |
|
105 | + |
|
106 | + /** |
|
107 | + * css styles applied to button type inputs |
|
108 | + * |
|
109 | + * @var string |
|
110 | + */ |
|
111 | + protected $_button_css_attributes; |
|
112 | + |
|
113 | + /** |
|
114 | + * The raw data submitted for this, like in the $_POST super global. |
|
115 | + * Generally unsafe for usage in client code |
|
116 | + * |
|
117 | + * @var mixed string or array |
|
118 | + */ |
|
119 | + protected $_raw_value; |
|
120 | + |
|
121 | + /** |
|
122 | + * Value normalized according to the input's normalization strategy. |
|
123 | + * The normalization strategy dictates whether this is a string, int, float, |
|
124 | + * boolean, or array of any of those. |
|
125 | + * |
|
126 | + * @var mixed |
|
127 | + */ |
|
128 | + protected $_normalized_value; |
|
129 | + |
|
130 | + /** |
|
131 | + * Strategy used for displaying this field. |
|
132 | + * Child classes must use _get_display_strategy to access it. |
|
133 | + * |
|
134 | + * @var EE_Display_Strategy_Base |
|
135 | + */ |
|
136 | + private $_display_strategy; |
|
137 | + |
|
138 | + /** |
|
139 | + * Gets all the validation strategies used on this field |
|
140 | + * |
|
141 | + * @var EE_Validation_Strategy_Base[] |
|
142 | + */ |
|
143 | + private $_validation_strategies = array(); |
|
144 | + |
|
145 | + /** |
|
146 | + * The normalization strategy for this field |
|
147 | + * |
|
148 | + * @var EE_Normalization_Strategy_Base |
|
149 | + */ |
|
150 | + private $_normalization_strategy; |
|
151 | + |
|
152 | + /** |
|
153 | + * Strategy for removing sensitive data after we're done with the form input |
|
154 | + * |
|
155 | + * @var EE_Sensitive_Data_Removal_Base |
|
156 | + */ |
|
157 | + protected $_sensitive_data_removal_strategy; |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param array $input_args { |
|
163 | + * @type string $html_name the html name for the input |
|
164 | + * @type string $html_label_id the id attribute to give to the html label tag |
|
165 | + * @type string $html_label_class the class attribute to give to the html label tag |
|
166 | + * @type string $html_label_style the style attribute to give ot teh label tag |
|
167 | + * @type string $html_label_text the text to put in the label tag |
|
168 | + * @type string $html_label the full html label. If used, |
|
169 | + * all other html_label_* args are invalid |
|
170 | + * @type string $html_help_text text to put in help element |
|
171 | + * @type string $html_help_style style attribute to give to teh help element |
|
172 | + * @type string $html_help_class class attribute to give to the help element |
|
173 | + * @type string $default default value NORMALIZED (eg, if providing the default |
|
174 | + * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
175 | + * @type EE_Display_Strategy_Base $display strategy |
|
176 | + * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
177 | + * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
178 | + * } |
|
179 | + */ |
|
180 | + public function __construct($input_args = array()) |
|
181 | + { |
|
182 | + $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
183 | + // the following properties must be cast as arrays |
|
184 | + if (isset($input_args['validation_strategies'])) { |
|
185 | + foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
186 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
187 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
188 | + } |
|
189 | + } |
|
190 | + unset($input_args['validation_strategies']); |
|
191 | + } |
|
192 | + // loop thru incoming options |
|
193 | + foreach ($input_args as $key => $value) { |
|
194 | + // add underscore to $key to match property names |
|
195 | + $_key = '_' . $key; |
|
196 | + if (property_exists($this, $_key)) { |
|
197 | + $this->{$_key} = $value; |
|
198 | + } |
|
199 | + } |
|
200 | + // ensure that "required" is set correctly |
|
201 | + $this->set_required( |
|
202 | + $this->_required, isset($input_args['required_validation_error_message']) |
|
203 | + ? $input_args['required_validation_error_message'] |
|
204 | + : null |
|
205 | + ); |
|
206 | + //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
207 | + $this->_display_strategy->_construct_finalize($this); |
|
208 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
209 | + $validation_strategy->_construct_finalize($this); |
|
210 | + } |
|
211 | + if (! $this->_normalization_strategy) { |
|
212 | + $this->_normalization_strategy = new EE_Text_Normalization(); |
|
213 | + } |
|
214 | + $this->_normalization_strategy->_construct_finalize($this); |
|
215 | + //at least we can use the normalization strategy to populate the default |
|
216 | + if (isset($input_args['default'])) { |
|
217 | + $this->set_default($input_args['default']); |
|
218 | + } |
|
219 | + if (! $this->_sensitive_data_removal_strategy) { |
|
220 | + $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
221 | + } |
|
222 | + $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
223 | + parent::__construct($input_args); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Sets the html_name to its default value, if none was specified in teh constructor. |
|
230 | + * Calculation involves using the name and the parent's html_name |
|
231 | + * |
|
232 | + * @throws \EE_Error |
|
233 | + */ |
|
234 | + protected function _set_default_html_name_if_empty() |
|
235 | + { |
|
236 | + if (! $this->_html_name) { |
|
237 | + $this->_html_name = $this->name(); |
|
238 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
239 | + $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param $parent_form_section |
|
248 | + * @param $name |
|
249 | + * @throws \EE_Error |
|
250 | + */ |
|
251 | + public function _construct_finalize($parent_form_section, $name) |
|
252 | + { |
|
253 | + parent::_construct_finalize($parent_form_section, $name); |
|
254 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
255 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
256 | + } |
|
257 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
264 | + * |
|
265 | + * @return EE_Display_Strategy_Base |
|
266 | + * @throws EE_Error |
|
267 | + */ |
|
268 | + protected function _get_display_strategy() |
|
269 | + { |
|
270 | + $this->ensure_construct_finalized_called(); |
|
271 | + if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
272 | + throw new EE_Error( |
|
273 | + sprintf( |
|
274 | + __( |
|
275 | + "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
276 | + "event_espresso" |
|
277 | + ), |
|
278 | + $this->html_name(), |
|
279 | + $this->html_id() |
|
280 | + ) |
|
281 | + ); |
|
282 | + } else { |
|
283 | + return $this->_display_strategy; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Sets the display strategy. |
|
291 | + * |
|
292 | + * @param EE_Display_Strategy_Base $strategy |
|
293 | + */ |
|
294 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
295 | + { |
|
296 | + $this->_display_strategy = $strategy; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Sets the sanitization strategy |
|
303 | + * |
|
304 | + * @param EE_Normalization_Strategy_Base $strategy |
|
305 | + */ |
|
306 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
307 | + { |
|
308 | + $this->_normalization_strategy = $strategy; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets sensitive_data_removal_strategy |
|
315 | + * |
|
316 | + * @return EE_Sensitive_Data_Removal_Base |
|
317 | + */ |
|
318 | + public function get_sensitive_data_removal_strategy() |
|
319 | + { |
|
320 | + return $this->_sensitive_data_removal_strategy; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * Sets sensitive_data_removal_strategy |
|
327 | + * |
|
328 | + * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
329 | + * @return boolean |
|
330 | + */ |
|
331 | + public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
332 | + { |
|
333 | + $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Gets the display strategy for this input |
|
340 | + * |
|
341 | + * @return EE_Display_Strategy_Base |
|
342 | + */ |
|
343 | + public function get_display_strategy() |
|
344 | + { |
|
345 | + return $this->_display_strategy; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * Overwrites the display strategy |
|
352 | + * |
|
353 | + * @param EE_Display_Strategy_Base $display_strategy |
|
354 | + */ |
|
355 | + public function set_display_strategy($display_strategy) |
|
356 | + { |
|
357 | + $this->_display_strategy = $display_strategy; |
|
358 | + $this->_display_strategy->_construct_finalize($this); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Gets the normalization strategy set on this input |
|
365 | + * |
|
366 | + * @return EE_Normalization_Strategy_Base |
|
367 | + */ |
|
368 | + public function get_normalization_strategy() |
|
369 | + { |
|
370 | + return $this->_normalization_strategy; |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Overwrites the normalization strategy |
|
377 | + * |
|
378 | + * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
379 | + */ |
|
380 | + public function set_normalization_strategy($normalization_strategy) |
|
381 | + { |
|
382 | + $this->_normalization_strategy = $normalization_strategy; |
|
383 | + $this->_normalization_strategy->_construct_finalize($this); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Returns all teh validation strategies which apply to this field, numerically indexed |
|
390 | + * |
|
391 | + * @return EE_Validation_Strategy_Base[] |
|
392 | + */ |
|
393 | + public function get_validation_strategies() |
|
394 | + { |
|
395 | + return $this->_validation_strategies; |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
402 | + * |
|
403 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
404 | + * @return void |
|
405 | + */ |
|
406 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
407 | + { |
|
408 | + $validation_strategy->_construct_finalize($this); |
|
409 | + $this->_validation_strategies[] = $validation_strategy; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Adds a new validation strategy onto the form input |
|
416 | + * |
|
417 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
418 | + * @return void |
|
419 | + */ |
|
420 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
421 | + { |
|
422 | + $this->_add_validation_strategy($validation_strategy); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * The classname of the validation strategy to remove |
|
429 | + * |
|
430 | + * @param string $validation_strategy_classname |
|
431 | + */ |
|
432 | + public function remove_validation_strategy($validation_strategy_classname) |
|
433 | + { |
|
434 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
435 | + if ( |
|
436 | + $validation_strategy instanceof $validation_strategy_classname |
|
437 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
438 | + ) { |
|
439 | + unset($this->_validation_strategies[$key]); |
|
440 | + } |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
448 | + * |
|
449 | + * @param array $validation_strategy_classnames |
|
450 | + * @return bool |
|
451 | + */ |
|
452 | + public function has_validation_strategy($validation_strategy_classnames) |
|
453 | + { |
|
454 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
455 | + ? $validation_strategy_classnames |
|
456 | + : array($validation_strategy_classnames); |
|
457 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
458 | + if (in_array($key, $validation_strategy_classnames)) { |
|
459 | + return true; |
|
460 | + } |
|
461 | + } |
|
462 | + return false; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * Gets the HTML |
|
469 | + * |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + public function get_html() |
|
473 | + { |
|
474 | + return $this->_parent_section->get_html_for_input($this); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Gets the HTML for the input itself (no label or errors) according to the |
|
481 | + * input's display strategy |
|
482 | + * Makes sure the JS and CSS are enqueued for it |
|
483 | + * |
|
484 | + * @return string |
|
485 | + * @throws \EE_Error |
|
486 | + */ |
|
487 | + public function get_html_for_input() |
|
488 | + { |
|
489 | + return $this->_get_display_strategy()->display(); |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * @return string |
|
496 | + */ |
|
497 | + public function html_other_attributes() |
|
498 | + { |
|
499 | + return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * @param string $html_other_attributes |
|
506 | + */ |
|
507 | + public function set_html_other_attributes($html_other_attributes) |
|
508 | + { |
|
509 | + $this->_html_other_attributes = $html_other_attributes; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Gets the HTML for displaying the label for this form input |
|
516 | + * according to the form section's layout strategy |
|
517 | + * |
|
518 | + * @return string |
|
519 | + */ |
|
520 | + public function get_html_for_label() |
|
521 | + { |
|
522 | + return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Gets the HTML for displaying the errors section for this form input |
|
529 | + * according to the form section's layout strategy |
|
530 | + * |
|
531 | + * @return string |
|
532 | + */ |
|
533 | + public function get_html_for_errors() |
|
534 | + { |
|
535 | + return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * Gets the HTML for displaying the help text for this form input |
|
542 | + * according to the form section's layout strategy |
|
543 | + * |
|
544 | + * @return string |
|
545 | + */ |
|
546 | + public function get_html_for_help() |
|
547 | + { |
|
548 | + return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
555 | + * and returns whether or not the form input's submitted value is value |
|
556 | + * |
|
557 | + * @return boolean |
|
558 | + */ |
|
559 | + protected function _validate() |
|
560 | + { |
|
561 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
562 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
563 | + try { |
|
564 | + $validation_strategy->validate($this->normalized_value()); |
|
565 | + } catch (EE_Validation_Error $e) { |
|
566 | + $this->add_validation_error($e); |
|
567 | + } |
|
568 | + } |
|
569 | + } |
|
570 | + if ($this->get_validation_errors()) { |
|
571 | + return false; |
|
572 | + } else { |
|
573 | + return true; |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
581 | + * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
582 | + * |
|
583 | + * @param string $value |
|
584 | + * @return null|string |
|
585 | + */ |
|
586 | + private function _sanitize($value) |
|
587 | + { |
|
588 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Picks out the form value that relates to this form input, |
|
595 | + * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
596 | + * Returns whether or not any validation errors occurred |
|
597 | + * |
|
598 | + * @param array $req_data like $_POST |
|
599 | + * @return boolean whether or not there was an error |
|
600 | + * @throws \EE_Error |
|
601 | + */ |
|
602 | + protected function _normalize($req_data) |
|
603 | + { |
|
604 | + //any existing validation errors don't apply so clear them |
|
605 | + $this->_validation_errors = array(); |
|
606 | + try { |
|
607 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
608 | + //super simple sanitization for now |
|
609 | + if (is_array($raw_input)) { |
|
610 | + $raw_value = array(); |
|
611 | + foreach ($raw_input as $key => $value) { |
|
612 | + $raw_value[$key] = $this->_sanitize($value); |
|
613 | + } |
|
614 | + $this->_set_raw_value($raw_value); |
|
615 | + } else { |
|
616 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
617 | + } |
|
618 | + //we want to mostly leave the input alone in case we need to re-display it to the user |
|
619 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
620 | + } catch (EE_Validation_Error $e) { |
|
621 | + $this->add_validation_error($e); |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * @return string |
|
629 | + */ |
|
630 | + public function html_name() |
|
631 | + { |
|
632 | + $this->_set_default_html_name_if_empty(); |
|
633 | + return $this->_html_name; |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * @return string |
|
640 | + */ |
|
641 | + public function html_label_id() |
|
642 | + { |
|
643 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * @return string |
|
650 | + */ |
|
651 | + public function html_label_class() |
|
652 | + { |
|
653 | + return $this->_html_label_class; |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public function html_label_style() |
|
662 | + { |
|
663 | + return $this->_html_label_style; |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * @return string |
|
670 | + */ |
|
671 | + public function html_label_text() |
|
672 | + { |
|
673 | + return $this->_html_label_text; |
|
674 | + } |
|
675 | + |
|
676 | + |
|
677 | + |
|
678 | + /** |
|
679 | + * @return string |
|
680 | + */ |
|
681 | + public function html_help_text() |
|
682 | + { |
|
683 | + return $this->_html_help_text; |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * @return string |
|
690 | + */ |
|
691 | + public function html_help_class() |
|
692 | + { |
|
693 | + return $this->_html_help_class; |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * @return string |
|
700 | + */ |
|
701 | + public function html_help_style() |
|
702 | + { |
|
703 | + return $this->_html_style; |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
710 | + * Please note that almost all client code should instead use the normalized_value; |
|
711 | + * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
712 | + * mostly by escaping quotes) |
|
713 | + * Note, we do not store the exact original value sent in the user's request because |
|
714 | + * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
715 | + * in which case, we would have stored the malicious content to our database. |
|
716 | + * |
|
717 | + * @return string |
|
718 | + */ |
|
719 | + public function raw_value() |
|
720 | + { |
|
721 | + return $this->_raw_value; |
|
722 | + } |
|
723 | + |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * Returns a string safe to usage in form inputs when displaying, because |
|
728 | + * it escapes all html entities |
|
729 | + * |
|
730 | + * @return string |
|
731 | + */ |
|
732 | + public function raw_value_in_form() |
|
733 | + { |
|
734 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * returns the value after it's been sanitized, and then converted into it's proper type |
|
741 | + * in PHP. Eg, a string, an int, an array, |
|
742 | + * |
|
743 | + * @return mixed |
|
744 | + */ |
|
745 | + public function normalized_value() |
|
746 | + { |
|
747 | + return $this->_normalized_value; |
|
748 | + } |
|
749 | + |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * Returns the normalized value is a presentable way. By default this is just |
|
754 | + * the normalized value by itself, but it can be overridden for when that's not |
|
755 | + * the best thing to display |
|
756 | + * |
|
757 | + * @return string |
|
758 | + */ |
|
759 | + public function pretty_value() |
|
760 | + { |
|
761 | + return $this->_normalized_value; |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * When generating the JS for the jquery validation rules like<br> |
|
768 | + * <code>$( "#myform" ).validate({ |
|
769 | + * rules: { |
|
770 | + * password: "required", |
|
771 | + * password_again: { |
|
772 | + * equalTo: "#password" |
|
773 | + * } |
|
774 | + * } |
|
775 | + * });</code> |
|
776 | + * if this field had the name 'password_again', it should return |
|
777 | + * <br><code>password_again: { |
|
778 | + * equalTo: "#password" |
|
779 | + * }</code> |
|
780 | + * |
|
781 | + * @return array |
|
782 | + */ |
|
783 | + public function get_jquery_validation_rules() |
|
784 | + { |
|
785 | + $jquery_validation_js = array(); |
|
786 | + $jquery_validation_rules = array(); |
|
787 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
788 | + $jquery_validation_rules = array_replace_recursive( |
|
789 | + $jquery_validation_rules, |
|
790 | + $validation_strategy->get_jquery_validation_rule_array() |
|
791 | + ); |
|
792 | + } |
|
793 | + if (! empty($jquery_validation_rules)) { |
|
794 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
795 | + $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
796 | + } |
|
797 | + } |
|
798 | + return $jquery_validation_js; |
|
799 | + } |
|
800 | + |
|
801 | + |
|
802 | + |
|
803 | + /** |
|
804 | + * Sets the input's default value for use in displaying in the form. Note: value should be |
|
805 | + * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
806 | + * |
|
807 | + * @param mixed $value |
|
808 | + * @return void |
|
809 | + */ |
|
810 | + public function set_default($value) |
|
811 | + { |
|
812 | + $this->_set_normalized_value($value); |
|
813 | + $this->_set_raw_value($value); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + |
|
818 | + /** |
|
819 | + * Sets the normalized value on this input |
|
820 | + * |
|
821 | + * @param mixed $value |
|
822 | + */ |
|
823 | + protected function _set_normalized_value($value) |
|
824 | + { |
|
825 | + $this->_normalized_value = $value; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + |
|
830 | + /** |
|
831 | + * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
832 | + * |
|
833 | + * @param mixed $value |
|
834 | + */ |
|
835 | + protected function _set_raw_value($value) |
|
836 | + { |
|
837 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + |
|
842 | + /** |
|
843 | + * Sets the HTML label text after it has already been defined |
|
844 | + * |
|
845 | + * @param string $label |
|
846 | + * @return void |
|
847 | + */ |
|
848 | + public function set_html_label_text($label) |
|
849 | + { |
|
850 | + $this->_html_label_text = $label; |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + |
|
855 | + /** |
|
856 | + * Sets whether or not this field is required, and adjusts the validation strategy. |
|
857 | + * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
858 | + * please add it as a validation strategy using add_validation_strategy as normal |
|
859 | + * |
|
860 | + * @param boolean $required boolean |
|
861 | + * @param null $required_text |
|
862 | + */ |
|
863 | + public function set_required($required = true, $required_text = null) |
|
864 | + { |
|
865 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
866 | + //whether $required is a string or a boolean, we want to add a required validation strategy |
|
867 | + if ($required) { |
|
868 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
869 | + } else { |
|
870 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
871 | + } |
|
872 | + $this->_required = $required; |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + |
|
877 | + /** |
|
878 | + * Returns whether or not this field is required |
|
879 | + * |
|
880 | + * @return boolean |
|
881 | + */ |
|
882 | + public function required() |
|
883 | + { |
|
884 | + return $this->_required; |
|
885 | + } |
|
886 | + |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * @param string $required_css_class |
|
891 | + */ |
|
892 | + public function set_required_css_class($required_css_class) |
|
893 | + { |
|
894 | + $this->_required_css_class = $required_css_class; |
|
895 | + } |
|
896 | + |
|
897 | + |
|
898 | + |
|
899 | + /** |
|
900 | + * @return string |
|
901 | + */ |
|
902 | + public function required_css_class() |
|
903 | + { |
|
904 | + return $this->_required_css_class; |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param bool $add_required |
|
911 | + * @return string |
|
912 | + */ |
|
913 | + public function html_class($add_required = false) |
|
914 | + { |
|
915 | + return $add_required && $this->required() |
|
916 | + ? $this->required_css_class() . ' ' . $this->_html_class |
|
917 | + : $this->_html_class; |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * Sets the help text, in case |
|
923 | + * |
|
924 | + * @param string $text |
|
925 | + */ |
|
926 | + public function set_html_help_text($text) |
|
927 | + { |
|
928 | + $this->_html_help_text = $text; |
|
929 | + } |
|
930 | + |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
935 | + * input. If there is any kind of sensitive data removal on this input, we clear |
|
936 | + * out the raw value completely |
|
937 | + * |
|
938 | + * @return void |
|
939 | + */ |
|
940 | + public function clean_sensitive_data() |
|
941 | + { |
|
942 | + //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
943 | + //if we need more logic than this we'll make a strategy for it |
|
944 | + if ($this->_sensitive_data_removal_strategy |
|
945 | + && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
946 | + ) { |
|
947 | + $this->_set_raw_value(null); |
|
948 | + } |
|
949 | + //and clean the normalized value according to the appropriate strategy |
|
950 | + $this->_set_normalized_value( |
|
951 | + $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
952 | + $this->_normalized_value |
|
953 | + ) |
|
954 | + ); |
|
955 | + } |
|
956 | + |
|
957 | + |
|
958 | + |
|
959 | + /** |
|
960 | + * @param bool $primary |
|
961 | + * @param string $button_size |
|
962 | + * @param string $other_attributes |
|
963 | + */ |
|
964 | + public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
965 | + { |
|
966 | + $button_css_attributes = 'button'; |
|
967 | + $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
968 | + switch ($button_size) { |
|
969 | + case 'xs' : |
|
970 | + case 'extra-small' : |
|
971 | + $button_css_attributes .= ' button-xs'; |
|
972 | + break; |
|
973 | + case 'sm' : |
|
974 | + case 'small' : |
|
975 | + $button_css_attributes .= ' button-sm'; |
|
976 | + break; |
|
977 | + case 'lg' : |
|
978 | + case 'large' : |
|
979 | + $button_css_attributes .= ' button-lg'; |
|
980 | + break; |
|
981 | + case 'block' : |
|
982 | + $button_css_attributes .= ' button-block'; |
|
983 | + break; |
|
984 | + case 'md' : |
|
985 | + case 'medium' : |
|
986 | + default : |
|
987 | + $button_css_attributes .= ''; |
|
988 | + } |
|
989 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
990 | + ? $button_css_attributes . ' ' . $other_attributes |
|
991 | + : $button_css_attributes; |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * @return string |
|
998 | + */ |
|
999 | + public function button_css_attributes() |
|
1000 | + { |
|
1001 | + if (empty($this->_button_css_attributes)) { |
|
1002 | + $this->set_button_css_attributes(); |
|
1003 | + } |
|
1004 | + return $this->_button_css_attributes; |
|
1005 | + } |
|
1006 | + |
|
1007 | + |
|
1008 | + |
|
1009 | + /** |
|
1010 | + * find_form_data_for_this_section |
|
1011 | + * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1012 | + * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1013 | + * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1014 | + * (If that doesn't exist, we also check for this subsection's name |
|
1015 | + * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1016 | + * This function finds its value in the form. |
|
1017 | + * |
|
1018 | + * @param array $req_data |
|
1019 | + * @return mixed whatever the raw value of this form section is in the request data |
|
1020 | + * @throws \EE_Error |
|
1021 | + */ |
|
1022 | + public function find_form_data_for_this_section($req_data) |
|
1023 | + { |
|
1024 | + // break up the html name by "[]" |
|
1025 | + if (strpos($this->html_name(), '[') !== false) { |
|
1026 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1027 | + } else { |
|
1028 | + $before_any_brackets = $this->html_name(); |
|
1029 | + } |
|
1030 | + // grab all of the segments |
|
1031 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1032 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
1033 | + $name_parts = $matches[1]; |
|
1034 | + array_unshift($name_parts, $before_any_brackets); |
|
1035 | + } else { |
|
1036 | + $name_parts = array($before_any_brackets); |
|
1037 | + } |
|
1038 | + // now get the value for the input |
|
1039 | + $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
1040 | + // check if this thing's name is at the TOP level of the request data |
|
1041 | + if ($value === null && isset($req_data[$this->name()])) { |
|
1042 | + $value = $req_data[$this->name()]; |
|
1043 | + } |
|
1044 | + return $value; |
|
1045 | + } |
|
1046 | + |
|
1047 | + |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * @param array $html_name_parts |
|
1051 | + * @param array $req_data |
|
1052 | + * @return array | NULL |
|
1053 | + */ |
|
1054 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
1055 | + { |
|
1056 | + $first_part_to_consider = array_shift($html_name_parts); |
|
1057 | + if (isset($req_data[$first_part_to_consider])) { |
|
1058 | + if (empty($html_name_parts)) { |
|
1059 | + return $req_data[$first_part_to_consider]; |
|
1060 | + } else { |
|
1061 | + return $this->_find_form_data_for_this_section_using_name_parts( |
|
1062 | + $html_name_parts, |
|
1063 | + $req_data[$first_part_to_consider] |
|
1064 | + ); |
|
1065 | + } |
|
1066 | + } else { |
|
1067 | + return null; |
|
1068 | + } |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + |
|
1073 | + /** |
|
1074 | + * Checks if this form input's data is in the request data |
|
1075 | + * |
|
1076 | + * @param array $req_data like $_POST |
|
1077 | + * @return boolean |
|
1078 | + * @throws \EE_Error |
|
1079 | + */ |
|
1080 | + public function form_data_present_in($req_data = null) |
|
1081 | + { |
|
1082 | + if ($req_data === null) { |
|
1083 | + $req_data = $_POST; |
|
1084 | + } |
|
1085 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1086 | + if ($checked_value !== null) { |
|
1087 | + return true; |
|
1088 | + } else { |
|
1089 | + return false; |
|
1090 | + } |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * Overrides parent to add js data from validation and display strategies |
|
1097 | + * |
|
1098 | + * @param array $form_other_js_data |
|
1099 | + * @return array |
|
1100 | + */ |
|
1101 | + public function get_other_js_data($form_other_js_data = array()) |
|
1102 | + { |
|
1103 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1104 | + return $form_other_js_data; |
|
1105 | + } |
|
1106 | + |
|
1107 | + |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * Gets other JS data for localization from this input's strategies, like |
|
1111 | + * the validation strategies and the display strategy |
|
1112 | + * |
|
1113 | + * @param array $form_other_js_data |
|
1114 | + * @return array |
|
1115 | + */ |
|
1116 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1117 | + { |
|
1118 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1119 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1120 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1121 | + } |
|
1122 | + return $form_other_js_data; |
|
1123 | + } |
|
1124 | + |
|
1125 | + |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1129 | + * |
|
1130 | + * @return void |
|
1131 | + */ |
|
1132 | + public function enqueue_js() |
|
1133 | + { |
|
1134 | + //ask our display strategy and validation strategies if they have js to enqueue |
|
1135 | + $this->enqueue_js_from_strategies(); |
|
1136 | + } |
|
1137 | + |
|
1138 | + |
|
1139 | + |
|
1140 | + /** |
|
1141 | + * Tells strategies when its ok to enqueue their js and css |
|
1142 | + * |
|
1143 | + * @return void |
|
1144 | + */ |
|
1145 | + public function enqueue_js_from_strategies() |
|
1146 | + { |
|
1147 | + $this->get_display_strategy()->enqueue_js(); |
|
1148 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1149 | + $validation_strategy->enqueue_js(); |
|
1150 | + } |
|
1151 | + } |
|
1152 | 1152 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function __construct($input_args = array()) |
181 | 181 | { |
182 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
182 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
183 | 183 | // the following properties must be cast as arrays |
184 | 184 | if (isset($input_args['validation_strategies'])) { |
185 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
185 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
186 | 186 | if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
187 | 187 | $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
188 | 188 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | // loop thru incoming options |
193 | 193 | foreach ($input_args as $key => $value) { |
194 | 194 | // add underscore to $key to match property names |
195 | - $_key = '_' . $key; |
|
195 | + $_key = '_'.$key; |
|
196 | 196 | if (property_exists($this, $_key)) { |
197 | 197 | $this->{$_key} = $value; |
198 | 198 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | foreach ($this->_validation_strategies as $validation_strategy) { |
209 | 209 | $validation_strategy->_construct_finalize($this); |
210 | 210 | } |
211 | - if (! $this->_normalization_strategy) { |
|
211 | + if ( ! $this->_normalization_strategy) { |
|
212 | 212 | $this->_normalization_strategy = new EE_Text_Normalization(); |
213 | 213 | } |
214 | 214 | $this->_normalization_strategy->_construct_finalize($this); |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | if (isset($input_args['default'])) { |
217 | 217 | $this->set_default($input_args['default']); |
218 | 218 | } |
219 | - if (! $this->_sensitive_data_removal_strategy) { |
|
219 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
220 | 220 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
221 | 221 | } |
222 | 222 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
@@ -233,10 +233,10 @@ discard block |
||
233 | 233 | */ |
234 | 234 | protected function _set_default_html_name_if_empty() |
235 | 235 | { |
236 | - if (! $this->_html_name) { |
|
236 | + if ( ! $this->_html_name) { |
|
237 | 237 | $this->_html_name = $this->name(); |
238 | 238 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
239 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
239 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | protected function _get_display_strategy() |
269 | 269 | { |
270 | 270 | $this->ensure_construct_finalized_called(); |
271 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
271 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
272 | 272 | throw new EE_Error( |
273 | 273 | sprintf( |
274 | 274 | __( |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | */ |
497 | 497 | public function html_other_attributes() |
498 | 498 | { |
499 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
499 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | */ |
641 | 641 | public function html_label_id() |
642 | 642 | { |
643 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
643 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id.'-lbl'; |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | $validation_strategy->get_jquery_validation_rule_array() |
791 | 791 | ); |
792 | 792 | } |
793 | - if (! empty($jquery_validation_rules)) { |
|
793 | + if ( ! empty($jquery_validation_rules)) { |
|
794 | 794 | foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
795 | 795 | $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
796 | 796 | } |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | public function html_class($add_required = false) |
914 | 914 | { |
915 | 915 | return $add_required && $this->required() |
916 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
916 | + ? $this->required_css_class().' '.$this->_html_class |
|
917 | 917 | : $this->_html_class; |
918 | 918 | } |
919 | 919 | |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | $button_css_attributes .= ''; |
988 | 988 | } |
989 | 989 | $this->_button_css_attributes .= ! empty($other_attributes) |
990 | - ? $button_css_attributes . ' ' . $other_attributes |
|
990 | + ? $button_css_attributes.' '.$other_attributes |
|
991 | 991 | : $button_css_attributes; |
992 | 992 | } |
993 | 993 |
@@ -14,55 +14,55 @@ |
||
14 | 14 | class EE_Number_Input_Display_Strategy extends EE_Display_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * minimum value for number field |
|
19 | - * |
|
20 | - * @var int|null $min |
|
21 | - */ |
|
22 | - protected $min; |
|
17 | + /** |
|
18 | + * minimum value for number field |
|
19 | + * |
|
20 | + * @var int|null $min |
|
21 | + */ |
|
22 | + protected $min; |
|
23 | 23 | |
24 | - /** |
|
25 | - * maximum value for number field |
|
26 | - * |
|
27 | - * @var int|null $max |
|
28 | - */ |
|
29 | - protected $max; |
|
24 | + /** |
|
25 | + * maximum value for number field |
|
26 | + * |
|
27 | + * @var int|null $max |
|
28 | + */ |
|
29 | + protected $max; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * EE_Number_Input_Display_Strategy constructor. |
|
35 | - * |
|
36 | - * @param int $min |
|
37 | - * @param int $max |
|
38 | - */ |
|
39 | - public function __construct($min = null, $max = null) |
|
40 | - { |
|
41 | - $this->min = $min; |
|
42 | - $this->max = $max; |
|
43 | - } |
|
33 | + /** |
|
34 | + * EE_Number_Input_Display_Strategy constructor. |
|
35 | + * |
|
36 | + * @param int $min |
|
37 | + * @param int $max |
|
38 | + */ |
|
39 | + public function __construct($min = null, $max = null) |
|
40 | + { |
|
41 | + $this->min = $min; |
|
42 | + $this->max = $max; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * @return string of html to display the field |
|
49 | - */ |
|
50 | - public function display() |
|
51 | - { |
|
52 | - $input = $this->opening_tag('input'); |
|
53 | - $input .= $this->attribute('type', 'number'); |
|
54 | - $input .= $this->attribute('min', $this->min); |
|
55 | - $input .= $this->attribute('max', $this->max); |
|
56 | - $input .= $this->attribute('name', $this->_input->html_name()); |
|
57 | - $input .= $this->attribute('id', $this->_input->html_id()); |
|
58 | - $input .= $this->attribute('class', $this->_input->html_class(true)); |
|
59 | - $input .= $this->single_attribute('required', $this->_input->required()); |
|
60 | - $input .= $this->attribute('value', $this->_input->raw_value_in_form()); |
|
61 | - $input .= $this->attribute('style', $this->_input->html_style()); |
|
62 | - $input .= $this->_input->other_html_attributes(); |
|
63 | - $input .= $this->closing_tag(); |
|
64 | - return $input; |
|
65 | - } |
|
47 | + /** |
|
48 | + * @return string of html to display the field |
|
49 | + */ |
|
50 | + public function display() |
|
51 | + { |
|
52 | + $input = $this->opening_tag('input'); |
|
53 | + $input .= $this->attribute('type', 'number'); |
|
54 | + $input .= $this->attribute('min', $this->min); |
|
55 | + $input .= $this->attribute('max', $this->max); |
|
56 | + $input .= $this->attribute('name', $this->_input->html_name()); |
|
57 | + $input .= $this->attribute('id', $this->_input->html_id()); |
|
58 | + $input .= $this->attribute('class', $this->_input->html_class(true)); |
|
59 | + $input .= $this->single_attribute('required', $this->_input->required()); |
|
60 | + $input .= $this->attribute('value', $this->_input->raw_value_in_form()); |
|
61 | + $input .= $this->attribute('style', $this->_input->html_style()); |
|
62 | + $input .= $this->_input->other_html_attributes(); |
|
63 | + $input .= $this->closing_tag(); |
|
64 | + return $input; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | } |
68 | 68 | // End of file EE_Number_Input_Display_Strategy.php |
@@ -72,59 +72,59 @@ |
||
72 | 72 | |
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * returns string like: attribute="value" |
|
77 | - * returns an empty string if $value is null |
|
78 | - * |
|
79 | - * @param string $tag |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - protected function opening_tag($tag) |
|
83 | - { |
|
84 | - return "<{$tag}"; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * returns string like: attribute="value" |
|
91 | - * returns an empty string if $value is null |
|
92 | - * |
|
93 | - * @param string $tag |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - protected function closing_tag($tag = '') |
|
97 | - { |
|
98 | - return ! empty($tag) ? "/{$tag}>" : '/>'; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * returns string like: ' attribute="value"' |
|
105 | - * returns an empty string if $value is null |
|
106 | - * |
|
107 | - * @param string $attribute |
|
108 | - * @param string $value |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - protected function attribute($attribute, $value = '') |
|
112 | - { |
|
113 | - return $value !== null ? " {$attribute}=\"{$value}\"" : ''; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * returns string like: ' attribute' if $add is true |
|
120 | - * |
|
121 | - * @param string $attribute |
|
122 | - * @param boolean $add |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - protected function single_attribute($attribute, $add = true) |
|
126 | - { |
|
127 | - return $add ? " {$attribute}" : ''; |
|
128 | - } |
|
75 | + /** |
|
76 | + * returns string like: attribute="value" |
|
77 | + * returns an empty string if $value is null |
|
78 | + * |
|
79 | + * @param string $tag |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + protected function opening_tag($tag) |
|
83 | + { |
|
84 | + return "<{$tag}"; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * returns string like: attribute="value" |
|
91 | + * returns an empty string if $value is null |
|
92 | + * |
|
93 | + * @param string $tag |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + protected function closing_tag($tag = '') |
|
97 | + { |
|
98 | + return ! empty($tag) ? "/{$tag}>" : '/>'; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * returns string like: ' attribute="value"' |
|
105 | + * returns an empty string if $value is null |
|
106 | + * |
|
107 | + * @param string $attribute |
|
108 | + * @param string $value |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + protected function attribute($attribute, $value = '') |
|
112 | + { |
|
113 | + return $value !== null ? " {$attribute}=\"{$value}\"" : ''; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * returns string like: ' attribute' if $add is true |
|
120 | + * |
|
121 | + * @param string $attribute |
|
122 | + * @param boolean $add |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + protected function single_attribute($attribute, $add = true) |
|
126 | + { |
|
127 | + return $add ? " {$attribute}" : ''; |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | \ No newline at end of file |