@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage |
9 | 9 | * @author Mike Nelson |
10 | 10 | */ |
11 | -abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable{ |
|
11 | +abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * the input's name attribute |
@@ -143,54 +143,54 @@ discard block |
||
143 | 143 | * @type EE_Validation_Strategy_Base[] $validation_strategies |
144 | 144 | * } |
145 | 145 | */ |
146 | - public function __construct( $input_args = array() ){ |
|
147 | - $input_args = (array) apply_filters( 'FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this ); |
|
146 | + public function __construct($input_args = array()) { |
|
147 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
148 | 148 | // the following properties must be cast as arrays |
149 | - if ( isset( $input_args['validation_strategies'] ) ) { |
|
150 | - foreach ( (array) $input_args['validation_strategies'] as $validation_strategy ) { |
|
151 | - if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
|
152 | - $this->_validation_strategies[ get_class( $validation_strategy ) ] = $validation_strategy; |
|
149 | + if (isset($input_args['validation_strategies'])) { |
|
150 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
151 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
152 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
153 | 153 | } |
154 | 154 | } |
155 | - unset( $input_args['validation_strategies'] ); |
|
155 | + unset($input_args['validation_strategies']); |
|
156 | 156 | } |
157 | 157 | // loop thru incoming options |
158 | - foreach( $input_args as $key => $value ) { |
|
158 | + foreach ($input_args as $key => $value) { |
|
159 | 159 | // add underscore to $key to match property names |
160 | - $_key = '_' . $key; |
|
161 | - if ( property_exists( $this, $_key )) { |
|
160 | + $_key = '_'.$key; |
|
161 | + if (property_exists($this, $_key)) { |
|
162 | 162 | $this->{$_key} = $value; |
163 | 163 | } |
164 | 164 | } |
165 | 165 | // ensure that "required" is set correctly |
166 | 166 | $this->set_required( |
167 | - $this->_required, isset( $input_args[ 'required_validation_error_message' ] ) |
|
168 | - ? $input_args[ 'required_validation_error_message' ] |
|
167 | + $this->_required, isset($input_args['required_validation_error_message']) |
|
168 | + ? $input_args['required_validation_error_message'] |
|
169 | 169 | : null |
170 | 170 | ); |
171 | 171 | |
172 | 172 | //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
173 | 173 | |
174 | 174 | $this->_display_strategy->_construct_finalize($this); |
175 | - foreach( $this->_validation_strategies as $validation_strategy ){ |
|
175 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
176 | 176 | $validation_strategy->_construct_finalize($this); |
177 | 177 | } |
178 | 178 | |
179 | - if( ! $this->_normalization_strategy){ |
|
179 | + if ( ! $this->_normalization_strategy) { |
|
180 | 180 | $this->_normalization_strategy = new EE_Text_Normalization(); |
181 | 181 | } |
182 | 182 | $this->_normalization_strategy->_construct_finalize($this); |
183 | 183 | |
184 | 184 | //at least we can use the normalization strategy to populate the default |
185 | - if( isset( $input_args[ 'default' ] ) ) { |
|
186 | - $this->set_default( $input_args[ 'default' ] ); |
|
185 | + if (isset($input_args['default'])) { |
|
186 | + $this->set_default($input_args['default']); |
|
187 | 187 | } |
188 | 188 | |
189 | - if( ! $this->_sensitive_data_removal_strategy){ |
|
189 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
190 | 190 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
191 | 191 | } |
192 | 192 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
193 | - parent::__construct( $input_args ); |
|
193 | + parent::__construct($input_args); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @throws \EE_Error |
203 | 203 | */ |
204 | - protected function _set_default_html_name_if_empty(){ |
|
205 | - if( ! $this->_html_name){ |
|
204 | + protected function _set_default_html_name_if_empty() { |
|
205 | + if ( ! $this->_html_name) { |
|
206 | 206 | $this->_html_name = $this->name(); |
207 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper){ |
|
208 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
207 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
208 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | public function _construct_finalize($parent_form_section, $name) { |
221 | 221 | parent::_construct_finalize($parent_form_section, $name); |
222 | 222 | $this->_set_default_html_name_if_empty(); |
223 | - if( $this->_html_label === null && $this->_html_label_text === null ){ |
|
224 | - $this->_html_label_text = ucwords( str_replace("_"," ",$name)); |
|
223 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
224 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
225 | 225 | } |
226 | - do_action( 'AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name ); |
|
226 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -231,8 +231,8 @@ discard block |
||
231 | 231 | * @return EE_Display_Strategy_Base |
232 | 232 | * @throws EE_Error |
233 | 233 | */ |
234 | - protected function _get_display_strategy(){ |
|
235 | - if( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base){ |
|
234 | + protected function _get_display_strategy() { |
|
235 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
236 | 236 | throw new EE_Error( |
237 | 237 | sprintf( |
238 | 238 | __( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $this->html_id() |
244 | 244 | ) |
245 | 245 | ); |
246 | - }else{ |
|
246 | + } else { |
|
247 | 247 | return $this->_display_strategy; |
248 | 248 | } |
249 | 249 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * Sets the display strategy. |
252 | 252 | * @param EE_Display_Strategy_Base $strategy |
253 | 253 | */ |
254 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy){ |
|
254 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) { |
|
255 | 255 | $this->_display_strategy = $strategy; |
256 | 256 | } |
257 | 257 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * Sets the sanitization strategy |
260 | 260 | * @param EE_Normalization_Strategy_Base $strategy |
261 | 261 | */ |
262 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy){ |
|
262 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) { |
|
263 | 263 | $this->_normalization_strategy = $strategy; |
264 | 264 | } |
265 | 265 | |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | * Gets the display strategy for this input |
286 | 286 | * @return EE_Display_Strategy_Base |
287 | 287 | */ |
288 | - public function get_display_strategy(){ |
|
288 | + public function get_display_strategy() { |
|
289 | 289 | return $this->_display_strategy; |
290 | 290 | } |
291 | 291 | /** |
292 | 292 | * Overwrites the display strategy |
293 | 293 | * @param EE_Display_Strategy_Base $display_strategy |
294 | 294 | */ |
295 | - public function set_display_strategy($display_strategy){ |
|
295 | + public function set_display_strategy($display_strategy) { |
|
296 | 296 | $this->_display_strategy = $display_strategy; |
297 | 297 | $this->_display_strategy->_construct_finalize($this); |
298 | 298 | } |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | * Gets the normalization strategy set on this input |
301 | 301 | * @return EE_Normalization_Strategy_Base |
302 | 302 | */ |
303 | - public function get_normalization_strategy(){ |
|
303 | + public function get_normalization_strategy() { |
|
304 | 304 | return $this->_normalization_strategy; |
305 | 305 | } |
306 | 306 | /** |
307 | 307 | * Overwrites the normalization strategy |
308 | 308 | * @param EE_Normalization_Strategy_Base $normalization_strategy |
309 | 309 | */ |
310 | - public function set_normalization_strategy($normalization_strategy){ |
|
310 | + public function set_normalization_strategy($normalization_strategy) { |
|
311 | 311 | $this->_normalization_strategy = $normalization_strategy; |
312 | 312 | $this->_normalization_strategy->_construct_finalize($this); |
313 | 313 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * Returns all teh validation strategies which apply to this field, numerically indexed |
317 | 317 | * @return EE_Validation_Strategy_Base[] |
318 | 318 | */ |
319 | - public function get_validation_strategies(){ |
|
319 | + public function get_validation_strategies() { |
|
320 | 320 | return $this->_validation_strategies; |
321 | 321 | } |
322 | 322 | |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | * @param EE_Validation_Strategy_Base $validation_strategy |
328 | 328 | * @return void |
329 | 329 | */ |
330 | - protected function _add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ){ |
|
331 | - $validation_strategy->_construct_finalize( $this ); |
|
330 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
331 | + $validation_strategy->_construct_finalize($this); |
|
332 | 332 | $this->_validation_strategies[] = $validation_strategy; |
333 | 333 | } |
334 | 334 | |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param EE_Validation_Strategy_Base $validation_strategy |
340 | 340 | * @return void |
341 | 341 | */ |
342 | - public function add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ) { |
|
343 | - $this->_add_validation_strategy( $validation_strategy ); |
|
342 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
343 | + $this->_add_validation_strategy($validation_strategy); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -350,13 +350,13 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @param string $validation_strategy_classname |
352 | 352 | */ |
353 | - public function remove_validation_strategy( $validation_strategy_classname ) { |
|
354 | - foreach( $this->_validation_strategies as $key => $validation_strategy ){ |
|
355 | - if( |
|
353 | + public function remove_validation_strategy($validation_strategy_classname) { |
|
354 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
355 | + if ( |
|
356 | 356 | $validation_strategy instanceof $validation_strategy_classname |
357 | - || is_subclass_of( $validation_strategy, $validation_strategy_classname ) |
|
357 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
358 | 358 | ) { |
359 | - unset( $this->_validation_strategies[ $key ] ); |
|
359 | + unset($this->_validation_strategies[$key]); |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | } |
@@ -369,12 +369,12 @@ discard block |
||
369 | 369 | * @param array $validation_strategy_classnames |
370 | 370 | * @return bool |
371 | 371 | */ |
372 | - public function has_validation_strategy( $validation_strategy_classnames ) { |
|
373 | - $validation_strategy_classnames = is_array( $validation_strategy_classnames ) |
|
372 | + public function has_validation_strategy($validation_strategy_classnames) { |
|
373 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
374 | 374 | ? $validation_strategy_classnames |
375 | - : array( $validation_strategy_classnames ); |
|
376 | - foreach( $this->_validation_strategies as $key => $validation_strategy ){ |
|
377 | - if( in_array( $key, $validation_strategy_classnames ) ) { |
|
375 | + : array($validation_strategy_classnames); |
|
376 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
377 | + if (in_array($key, $validation_strategy_classnames)) { |
|
378 | 378 | return true; |
379 | 379 | } |
380 | 380 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * Gets the HTML |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - public function get_html(){ |
|
390 | + public function get_html() { |
|
391 | 391 | return $this->_parent_section->get_html_for_input($this); |
392 | 392 | } |
393 | 393 | |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @return string |
402 | 402 | * @throws \EE_Error |
403 | 403 | */ |
404 | - public function get_html_for_input(){ |
|
404 | + public function get_html_for_input() { |
|
405 | 405 | return $this->_get_display_strategy()->display(); |
406 | 406 | } |
407 | 407 | |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * @return string |
412 | 412 | */ |
413 | 413 | public function html_other_attributes() { |
414 | - return ! empty( $this->_html_other_attributes ) ? ' ' . $this->_html_other_attributes : ''; |
|
414 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | /** |
420 | 420 | * @param string $html_other_attributes |
421 | 421 | */ |
422 | - public function set_html_other_attributes( $html_other_attributes ) { |
|
422 | + public function set_html_other_attributes($html_other_attributes) { |
|
423 | 423 | $this->_html_other_attributes = $html_other_attributes; |
424 | 424 | } |
425 | 425 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * according to the form section's layout strategy |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public function get_html_for_label(){ |
|
431 | + public function get_html_for_label() { |
|
432 | 432 | return $this->_parent_section->get_layout_strategy()->display_label($this); |
433 | 433 | } |
434 | 434 | /** |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * according to the form section's layout strategy |
437 | 437 | * @return string |
438 | 438 | */ |
439 | - public function get_html_for_errors(){ |
|
439 | + public function get_html_for_errors() { |
|
440 | 440 | return $this->_parent_section->get_layout_strategy()->display_errors($this); |
441 | 441 | } |
442 | 442 | /** |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * according to the form section's layout strategy |
445 | 445 | * @return string |
446 | 446 | */ |
447 | - public function get_html_for_help(){ |
|
447 | + public function get_html_for_help() { |
|
448 | 448 | return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
449 | 449 | } |
450 | 450 | /** |
@@ -453,18 +453,18 @@ discard block |
||
453 | 453 | * @return boolean |
454 | 454 | */ |
455 | 455 | protected function _validate() { |
456 | - foreach($this->_validation_strategies as $validation_strategy){ |
|
457 | - if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
|
458 | - try{ |
|
456 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
457 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
458 | + try { |
|
459 | 459 | $validation_strategy->validate($this->normalized_value()); |
460 | - }catch(EE_Validation_Error $e){ |
|
460 | + } catch (EE_Validation_Error $e) { |
|
461 | 461 | $this->add_validation_error($e); |
462 | 462 | } |
463 | 463 | } |
464 | 464 | } |
465 | - if( $this->get_validation_errors()){ |
|
465 | + if ($this->get_validation_errors()) { |
|
466 | 466 | return false; |
467 | - }else{ |
|
467 | + } else { |
|
468 | 468 | return true; |
469 | 469 | } |
470 | 470 | } |
@@ -478,8 +478,8 @@ discard block |
||
478 | 478 | * @param string $value |
479 | 479 | * @return null|string |
480 | 480 | */ |
481 | - private function _sanitize( $value ) { |
|
482 | - return $value !== null ? stripslashes( html_entity_decode( trim( $value ) ) ) : null; |
|
481 | + private function _sanitize($value) { |
|
482 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | |
@@ -493,25 +493,25 @@ discard block |
||
493 | 493 | * @return boolean whether or not there was an error |
494 | 494 | * @throws \EE_Error |
495 | 495 | */ |
496 | - protected function _normalize( $req_data ) { |
|
496 | + protected function _normalize($req_data) { |
|
497 | 497 | //any existing validation errors don't apply so clear them |
498 | 498 | $this->_validation_errors = array(); |
499 | 499 | try { |
500 | - $raw_input = $this->find_form_data_for_this_section( $req_data ); |
|
500 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
501 | 501 | //super simple sanitization for now |
502 | - if ( is_array( $raw_input )) { |
|
502 | + if (is_array($raw_input)) { |
|
503 | 503 | $raw_value = array(); |
504 | - foreach( $raw_input as $key => $value ) { |
|
505 | - $raw_value[ $key ] = $this->_sanitize( $value ); |
|
504 | + foreach ($raw_input as $key => $value) { |
|
505 | + $raw_value[$key] = $this->_sanitize($value); |
|
506 | 506 | } |
507 | - $this->_set_raw_value( $raw_value ); |
|
507 | + $this->_set_raw_value($raw_value); |
|
508 | 508 | } else { |
509 | - $this->_set_raw_value( $this->_sanitize( $raw_input ) ); |
|
509 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
510 | 510 | } |
511 | 511 | //we want to mostly leave the input alone in case we need to re-display it to the user |
512 | - $this->_set_normalized_value( $this->_normalization_strategy->normalize( $this->raw_value() ) ); |
|
513 | - } catch ( EE_Validation_Error $e ) { |
|
514 | - $this->add_validation_error( $e ); |
|
512 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
513 | + } catch (EE_Validation_Error $e) { |
|
514 | + $this->add_validation_error($e); |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | /** |
521 | 521 | * @return string |
522 | 522 | */ |
523 | - public function html_name(){ |
|
523 | + public function html_name() { |
|
524 | 524 | return $this->_html_name; |
525 | 525 | } |
526 | 526 | |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | /** |
530 | 530 | * @return string |
531 | 531 | */ |
532 | - public function html_label_id(){ |
|
533 | - return ! empty( $this->_html_label_id ) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
532 | + public function html_label_id() { |
|
533 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id.'-lbl'; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | /** |
539 | 539 | * @return string |
540 | 540 | */ |
541 | - public function html_label_class(){ |
|
541 | + public function html_label_class() { |
|
542 | 542 | return $this->_html_label_class; |
543 | 543 | } |
544 | 544 | |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | /** |
548 | 548 | * @return string |
549 | 549 | */ |
550 | - public function html_label_style(){ |
|
550 | + public function html_label_style() { |
|
551 | 551 | return $this->_html_label_style; |
552 | 552 | } |
553 | 553 | |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | /** |
557 | 557 | * @return string |
558 | 558 | */ |
559 | - public function html_label_text(){ |
|
559 | + public function html_label_text() { |
|
560 | 560 | return $this->_html_label_text; |
561 | 561 | } |
562 | 562 | |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | /** |
566 | 566 | * @return string |
567 | 567 | */ |
568 | - public function html_help_text(){ |
|
568 | + public function html_help_text() { |
|
569 | 569 | return $this->_html_help_text; |
570 | 570 | } |
571 | 571 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | /** |
575 | 575 | * @return string |
576 | 576 | */ |
577 | - public function html_help_class(){ |
|
577 | + public function html_help_class() { |
|
578 | 578 | return $this->_html_help_class; |
579 | 579 | } |
580 | 580 | |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | /** |
584 | 584 | * @return string |
585 | 585 | */ |
586 | - public function html_help_style(){ |
|
586 | + public function html_help_style() { |
|
587 | 587 | return $this->_html_style; |
588 | 588 | } |
589 | 589 | /** |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * in which case, we would have stored the malicious content to our database. |
597 | 597 | * @return string |
598 | 598 | */ |
599 | - public function raw_value(){ |
|
599 | + public function raw_value() { |
|
600 | 600 | return $this->_raw_value; |
601 | 601 | } |
602 | 602 | /** |
@@ -604,15 +604,15 @@ discard block |
||
604 | 604 | * it escapes all html entities |
605 | 605 | * @return string |
606 | 606 | */ |
607 | - public function raw_value_in_form(){ |
|
608 | - return htmlentities($this->raw_value(),ENT_QUOTES, 'UTF-8'); |
|
607 | + public function raw_value_in_form() { |
|
608 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
609 | 609 | } |
610 | 610 | /** |
611 | 611 | * returns the value after it's been sanitized, and then converted into it's proper type |
612 | 612 | * in PHP. Eg, a string, an int, an array, |
613 | 613 | * @return mixed |
614 | 614 | */ |
615 | - public function normalized_value(){ |
|
615 | + public function normalized_value() { |
|
616 | 616 | return $this->_normalized_value; |
617 | 617 | } |
618 | 618 | |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | * the best thing to display |
623 | 623 | * @return string |
624 | 624 | */ |
625 | - public function pretty_value(){ |
|
625 | + public function pretty_value() { |
|
626 | 626 | return $this->_normalized_value; |
627 | 627 | } |
628 | 628 | /** |
@@ -641,19 +641,19 @@ discard block |
||
641 | 641 | }</code> |
642 | 642 | * @return array |
643 | 643 | */ |
644 | - public function get_jquery_validation_rules(){ |
|
644 | + public function get_jquery_validation_rules() { |
|
645 | 645 | $jquery_validation_js = array(); |
646 | 646 | $jquery_validation_rules = array(); |
647 | - foreach($this->get_validation_strategies() as $validation_strategy){ |
|
647 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
648 | 648 | $jquery_validation_rules = array_replace_recursive( |
649 | 649 | $jquery_validation_rules, |
650 | 650 | $validation_strategy->get_jquery_validation_rule_array() |
651 | 651 | ); |
652 | 652 | } |
653 | 653 | |
654 | - if(! empty($jquery_validation_rules)){ |
|
655 | - foreach( $this->get_display_strategy()->get_html_input_ids( true ) as $html_id_with_pound_sign ) { |
|
656 | - $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
654 | + if ( ! empty($jquery_validation_rules)) { |
|
655 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
656 | + $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | return $jquery_validation_js; |
@@ -665,16 +665,16 @@ discard block |
||
665 | 665 | * @param mixed $value |
666 | 666 | * @return void |
667 | 667 | */ |
668 | - public function set_default($value){ |
|
669 | - $this->_set_normalized_value( $value ); |
|
670 | - $this->_set_raw_value( $value ); |
|
668 | + public function set_default($value) { |
|
669 | + $this->_set_normalized_value($value); |
|
670 | + $this->_set_raw_value($value); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
674 | 674 | * Sets the normalized value on this input |
675 | 675 | * @param mixed $value |
676 | 676 | */ |
677 | - protected function _set_normalized_value( $value ) { |
|
677 | + protected function _set_normalized_value($value) { |
|
678 | 678 | $this->_normalized_value = $value; |
679 | 679 | } |
680 | 680 | |
@@ -682,8 +682,8 @@ discard block |
||
682 | 682 | * Sets the raw value on this input (ie, exactly as the user submitted it) |
683 | 683 | * @param mixed $value |
684 | 684 | */ |
685 | - protected function _set_raw_value( $value ) { |
|
686 | - $this->_raw_value = $this->_normalization_strategy->unnormalize( $value ); |
|
685 | + protected function _set_raw_value($value) { |
|
686 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * @param string $label |
692 | 692 | * @return void |
693 | 693 | */ |
694 | - public function set_html_label_text($label){ |
|
694 | + public function set_html_label_text($label) { |
|
695 | 695 | $this->_html_label_text = $label; |
696 | 696 | } |
697 | 697 | |
@@ -705,13 +705,13 @@ discard block |
||
705 | 705 | * @param boolean $required boolean |
706 | 706 | * @param null $required_text |
707 | 707 | */ |
708 | - public function set_required($required = true, $required_text = NULL ){ |
|
709 | - $required = filter_var( $required, FILTER_VALIDATE_BOOLEAN ); |
|
708 | + public function set_required($required = true, $required_text = NULL) { |
|
709 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
710 | 710 | //whether $required is a string or a boolean, we want to add a required validation strategy |
711 | - if ( $required ) { |
|
712 | - $this->_add_validation_strategy( new EE_Required_Validation_Strategy( $required_text ) ); |
|
711 | + if ($required) { |
|
712 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
713 | 713 | } else { |
714 | - $this->remove_validation_strategy( 'EE_Required_Validation_Strategy' ); |
|
714 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
715 | 715 | } |
716 | 716 | $this->_required = $required; |
717 | 717 | } |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * Returns whether or not this field is required |
720 | 720 | * @return boolean |
721 | 721 | */ |
722 | - public function required(){ |
|
722 | + public function required() { |
|
723 | 723 | return $this->_required; |
724 | 724 | } |
725 | 725 | |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | /** |
729 | 729 | * @param string $required_css_class |
730 | 730 | */ |
731 | - public function set_required_css_class( $required_css_class ) { |
|
731 | + public function set_required_css_class($required_css_class) { |
|
732 | 732 | $this->_required_css_class = $required_css_class; |
733 | 733 | } |
734 | 734 | |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | * Sets the help text, in case |
748 | 748 | * @param string $text |
749 | 749 | */ |
750 | - public function set_html_help_text($text){ |
|
750 | + public function set_html_help_text($text) { |
|
751 | 751 | $this->_html_help_text = $text; |
752 | 752 | } |
753 | 753 | /** |
@@ -759,9 +759,9 @@ discard block |
||
759 | 759 | public function clean_sensitive_data() { |
760 | 760 | //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
761 | 761 | //if we need more logic than this we'll make a strategy for it |
762 | - if( $this->_sensitive_data_removal_strategy && |
|
763 | - ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal ){ |
|
764 | - $this->_set_raw_value( null ); |
|
762 | + if ($this->_sensitive_data_removal_strategy && |
|
763 | + ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal) { |
|
764 | + $this->_set_raw_value(null); |
|
765 | 765 | } |
766 | 766 | //and clean the normalized value according to the appropriate strategy |
767 | 767 | $this->_set_normalized_value( |
@@ -778,10 +778,10 @@ discard block |
||
778 | 778 | * @param string $button_size |
779 | 779 | * @param string $other_attributes |
780 | 780 | */ |
781 | - public function set_button_css_attributes( $primary = TRUE, $button_size = '', $other_attributes = '' ) { |
|
781 | + public function set_button_css_attributes($primary = TRUE, $button_size = '', $other_attributes = '') { |
|
782 | 782 | $button_css_attributes = 'button'; |
783 | 783 | $button_css_attributes .= $primary === TRUE ? ' button-primary' : ' button-secondary'; |
784 | - switch ( $button_size ) { |
|
784 | + switch ($button_size) { |
|
785 | 785 | case 'xs' : |
786 | 786 | case 'extra-small' : |
787 | 787 | $button_css_attributes .= ' button-xs'; |
@@ -802,8 +802,8 @@ discard block |
||
802 | 802 | default : |
803 | 803 | $button_css_attributes .= ''; |
804 | 804 | } |
805 | - $this->_button_css_attributes .= ! empty( $other_attributes ) |
|
806 | - ? $button_css_attributes . ' ' . $other_attributes |
|
805 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
806 | + ? $button_css_attributes.' '.$other_attributes |
|
807 | 807 | : $button_css_attributes; |
808 | 808 | } |
809 | 809 | |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | * @return string |
814 | 814 | */ |
815 | 815 | public function button_css_attributes() { |
816 | - if ( empty( $this->_button_css_attributes )) { |
|
816 | + if (empty($this->_button_css_attributes)) { |
|
817 | 817 | $this->set_button_css_attributes(); |
818 | 818 | } |
819 | 819 | return $this->_button_css_attributes; |
@@ -835,26 +835,26 @@ discard block |
||
835 | 835 | * @return mixed whatever the raw value of this form section is in the request data |
836 | 836 | * @throws \EE_Error |
837 | 837 | */ |
838 | - public function find_form_data_for_this_section( $req_data ){ |
|
838 | + public function find_form_data_for_this_section($req_data) { |
|
839 | 839 | // break up the html name by "[]" |
840 | - if ( strpos( $this->html_name(), '[' ) !== FALSE ) { |
|
841 | - $before_any_brackets = substr( $this->html_name(), 0, strpos($this->html_name(), '[') ); |
|
840 | + if (strpos($this->html_name(), '[') !== FALSE) { |
|
841 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
842 | 842 | } else { |
843 | 843 | $before_any_brackets = $this->html_name(); |
844 | 844 | } |
845 | 845 | // grab all of the segments |
846 | - preg_match_all('~\[([^]]*)\]~',$this->html_name(), $matches); |
|
847 | - if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
|
848 | - $name_parts = $matches[ 1 ]; |
|
846 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
847 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
848 | + $name_parts = $matches[1]; |
|
849 | 849 | array_unshift($name_parts, $before_any_brackets); |
850 | - }else{ |
|
851 | - $name_parts = array( $before_any_brackets ); |
|
850 | + } else { |
|
851 | + $name_parts = array($before_any_brackets); |
|
852 | 852 | } |
853 | 853 | // now get the value for the input |
854 | 854 | $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
855 | 855 | // check if this thing's name is at the TOP level of the request data |
856 | - if( $value === null && isset( $req_data[ $this->name() ] ) ){ |
|
857 | - $value = $req_data[ $this->name() ]; |
|
856 | + if ($value === null && isset($req_data[$this->name()])) { |
|
857 | + $value = $req_data[$this->name()]; |
|
858 | 858 | } |
859 | 859 | return $value; |
860 | 860 | } |
@@ -867,18 +867,18 @@ discard block |
||
867 | 867 | * @param array $req_data |
868 | 868 | * @return array | NULL |
869 | 869 | */ |
870 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data){ |
|
871 | - $first_part_to_consider = array_shift( $html_name_parts ); |
|
872 | - if( isset( $req_data[ $first_part_to_consider ] ) ){ |
|
873 | - if( empty($html_name_parts ) ){ |
|
874 | - return $req_data[ $first_part_to_consider ]; |
|
875 | - }else{ |
|
870 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) { |
|
871 | + $first_part_to_consider = array_shift($html_name_parts); |
|
872 | + if (isset($req_data[$first_part_to_consider])) { |
|
873 | + if (empty($html_name_parts)) { |
|
874 | + return $req_data[$first_part_to_consider]; |
|
875 | + } else { |
|
876 | 876 | return $this->_find_form_data_for_this_section_using_name_parts( |
877 | 877 | $html_name_parts, |
878 | - $req_data[ $first_part_to_consider ] |
|
878 | + $req_data[$first_part_to_consider] |
|
879 | 879 | ); |
880 | 880 | } |
881 | - }else{ |
|
881 | + } else { |
|
882 | 882 | return NULL; |
883 | 883 | } |
884 | 884 | } |
@@ -892,14 +892,14 @@ discard block |
||
892 | 892 | * @return boolean |
893 | 893 | * @throws \EE_Error |
894 | 894 | */ |
895 | - public function form_data_present_in($req_data = NULL){ |
|
896 | - if( $req_data === NULL ){ |
|
895 | + public function form_data_present_in($req_data = NULL) { |
|
896 | + if ($req_data === NULL) { |
|
897 | 897 | $req_data = $_POST; |
898 | 898 | } |
899 | - $checked_value = $this->find_form_data_for_this_section( $req_data ); |
|
900 | - if( $checked_value !== null ){ |
|
899 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
900 | + if ($checked_value !== null) { |
|
901 | 901 | return TRUE; |
902 | - }else{ |
|
902 | + } else { |
|
903 | 903 | return FALSE; |
904 | 904 | } |
905 | 905 | } |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | * @param array $form_other_js_data |
911 | 911 | * @return array |
912 | 912 | */ |
913 | - public function get_other_js_data( $form_other_js_data = array() ) { |
|
914 | - $form_other_js_data = $this->get_other_js_data_from_strategies( $form_other_js_data ); |
|
913 | + public function get_other_js_data($form_other_js_data = array()) { |
|
914 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
915 | 915 | return $form_other_js_data; |
916 | 916 | } |
917 | 917 | |
@@ -924,10 +924,10 @@ discard block |
||
924 | 924 | * @param array $form_other_js_data |
925 | 925 | * @return array |
926 | 926 | */ |
927 | - public function get_other_js_data_from_strategies( $form_other_js_data = array() ) { |
|
928 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data( $form_other_js_data ); |
|
929 | - foreach( $this->get_validation_strategies() as $validation_strategy ) { |
|
930 | - $form_other_js_data = $validation_strategy->get_other_js_data( $form_other_js_data ); |
|
927 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) { |
|
928 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
929 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
930 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
931 | 931 | } |
932 | 932 | return $form_other_js_data; |
933 | 933 | } |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
937 | 937 | * @return void |
938 | 938 | */ |
939 | - public function enqueue_js(){ |
|
939 | + public function enqueue_js() { |
|
940 | 940 | //ask our display strategy and validation strategies if they have js to enqueue |
941 | 941 | $this->enqueue_js_from_strategies(); |
942 | 942 | } |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | */ |
948 | 948 | public function enqueue_js_from_strategies() { |
949 | 949 | $this->get_display_strategy()->enqueue_js(); |
950 | - foreach( $this->get_validation_strategies() as $validation_strategy ) { |
|
950 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
951 | 951 | $validation_strategy->enqueue_js(); |
952 | 952 | } |
953 | 953 | } |