@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | * @param bool $add_pound_sign |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public function get_sub_input_id( $option_value, $add_pound_sign = false ) { |
|
31 | - return $this->_append_chars( $this->_input->html_id( $add_pound_sign ), '-' ) . sanitize_key( $option_value ); |
|
30 | + public function get_sub_input_id($option_value, $add_pound_sign = false) { |
|
31 | + return $this->_append_chars($this->_input->html_id($add_pound_sign), '-').sanitize_key($option_value); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | * @return array |
41 | 41 | * @throws \EE_Error |
42 | 42 | */ |
43 | - public function get_html_input_ids( $add_pound_sign = false ) { |
|
43 | + public function get_html_input_ids($add_pound_sign = false) { |
|
44 | 44 | $html_input_ids = array(); |
45 | - foreach( $this->get_input()->options() as $value => $display ) { |
|
46 | - $html_input_ids[] = $this->get_sub_input_id( $value, $add_pound_sign ); |
|
45 | + foreach ($this->get_input()->options() as $value => $display) { |
|
46 | + $html_input_ids[] = $this->get_sub_input_id($value, $add_pound_sign); |
|
47 | 47 | } |
48 | 48 | return $html_input_ids; |
49 | 49 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @throws \EE_Error |
59 | 59 | */ |
60 | 60 | public function get_input() { |
61 | - if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base ){ |
|
61 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
62 | 62 | throw new EE_Error( |
63 | 63 | sprintf( |
64 | 64 | __( |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | * @param EE_Messages_Queue $queue |
26 | 26 | * @param string $custom_subject Used if a custom subject is desired for the generated aggregate EE_Message object |
27 | 27 | */ |
28 | - public function __construct( $messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '' ) { |
|
28 | + public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '') { |
|
29 | 29 | $this->queue = $queue; |
30 | - parent::__construct( $messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle ); |
|
31 | - if ( $this->valid() ) { |
|
32 | - $this->_message->set_content( $this->_get_content() ); |
|
33 | - $this->_message->set_subject( $this->_get_subject( $custom_subject ) ); |
|
30 | + parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle); |
|
31 | + if ($this->valid()) { |
|
32 | + $this->_message->set_content($this->_get_content()); |
|
33 | + $this->_message->set_subject($this->_get_subject($custom_subject)); |
|
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | protected function _get_content() { |
45 | 45 | $content = ''; |
46 | 46 | $this->queue->get_message_repository()->rewind(); |
47 | - while ( $this->queue->get_message_repository()->valid() ) { |
|
47 | + while ($this->queue->get_message_repository()->valid()) { |
|
48 | 48 | $content .= $this->queue->get_message_repository()->current()->content(); |
49 | 49 | $this->queue->get_message_repository()->next(); |
50 | 50 | } |
@@ -58,15 +58,15 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - protected function _get_subject( $custom_subject = '' ) { |
|
62 | - if ( ! empty( $custom_subject ) ) { |
|
61 | + protected function _get_subject($custom_subject = '') { |
|
62 | + if ( ! empty($custom_subject)) { |
|
63 | 63 | return $custom_subject; |
64 | 64 | } |
65 | 65 | $this->queue->get_message_repository()->rewind(); |
66 | 66 | $count_of_items = $this->queue->get_message_repository()->count(); |
67 | 67 | |
68 | 68 | //if $count of items in queue == 1, then let's just return the subject for that item. |
69 | - if ( $count_of_items === 1 ) { |
|
69 | + if ($count_of_items === 1) { |
|
70 | 70 | return $this->queue->get_message_repository()->current()->subject(); |
71 | 71 | } |
72 | 72 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @return void |
290 | 290 | */ |
291 | 291 | public function enqueue_scripts_styles() { |
292 | - do_action( 'AHEE__EE_messenger__enqueue_scripts_styles'); |
|
292 | + do_action('AHEE__EE_messenger__enqueue_scripts_styles'); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | |
360 | 360 | $this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure. Usually these affect things like font style, color, borders etc. In some cases the styles will also make minor layout changes.'); |
361 | 361 | |
362 | - $this->_supports_labels = apply_filters( 'FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this ); |
|
362 | + $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | |
@@ -374,10 +374,10 @@ discard block |
||
374 | 374 | * @return stdClass |
375 | 375 | */ |
376 | 376 | public function get_supports_labels() { |
377 | - if ( empty( $this->_supports_labels->template_pack ) || empty( $this->_supports_labels->template_variation) ) { |
|
377 | + if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) { |
|
378 | 378 | $this->_set_supports_labels_defaults(); |
379 | 379 | } |
380 | - return apply_filters( 'FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this ); |
|
380 | + return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | |
@@ -397,10 +397,10 @@ discard block |
||
397 | 397 | * |
398 | 398 | * @return string path or url for the requested variation. |
399 | 399 | */ |
400 | - public function get_variation( EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE ) { |
|
400 | + public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE) { |
|
401 | 401 | $this->_tmp_pack = $pack; |
402 | - $variation_path = apply_filters( 'EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters ); |
|
403 | - $variation_path = empty( $variation_path ) ? $this->_tmp_pack->get_variation( $this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters ) : $variation_path; |
|
402 | + $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters); |
|
403 | + $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path; |
|
404 | 404 | return $variation_path; |
405 | 405 | |
406 | 406 | } |
@@ -418,13 +418,13 @@ discard block |
||
418 | 418 | * @return array |
419 | 419 | */ |
420 | 420 | public function get_default_message_types() { |
421 | - $class = get_class( $this ); |
|
421 | + $class = get_class($this); |
|
422 | 422 | |
423 | 423 | //messenger specific filter |
424 | - $default_types = apply_filters( 'FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this ); |
|
424 | + $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this); |
|
425 | 425 | |
426 | 426 | //all messengers filter |
427 | - $default_types = apply_filters( 'FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this ); |
|
427 | + $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); |
|
428 | 428 | return $default_types; |
429 | 429 | } |
430 | 430 | |
@@ -439,14 +439,14 @@ discard block |
||
439 | 439 | * @return array |
440 | 440 | */ |
441 | 441 | public function get_valid_message_types() { |
442 | - $class = get_class( $this ); |
|
442 | + $class = get_class($this); |
|
443 | 443 | |
444 | 444 | //messenger specific filter |
445 | 445 | //messenger specific filter |
446 | - $valid_types = apply_filters( 'FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this ); |
|
446 | + $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this); |
|
447 | 447 | |
448 | 448 | //all messengers filter |
449 | - $valid_types = apply_filters( 'FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this ); |
|
449 | + $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); |
|
450 | 450 | return $valid_types; |
451 | 451 | } |
452 | 452 | |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @access public |
461 | 461 | * @param array $new_config Whatever is put in here will reset the _validator_config property |
462 | 462 | */ |
463 | - public function set_validator_config( $new_config ) { |
|
463 | + public function set_validator_config($new_config) { |
|
464 | 464 | $this->_validator_config = $new_config; |
465 | 465 | } |
466 | 466 | |
@@ -476,8 +476,8 @@ discard block |
||
476 | 476 | public function get_validator_config() { |
477 | 477 | $class = get_class($this); |
478 | 478 | |
479 | - $config = apply_filters( 'FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this ); |
|
480 | - $config = apply_filters( 'FHEE__EE_messenger__get_validator_config', $config, $this ); |
|
479 | + $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this); |
|
480 | + $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); |
|
481 | 481 | return $config; |
482 | 482 | } |
483 | 483 | |
@@ -494,8 +494,8 @@ discard block |
||
494 | 494 | * @access public |
495 | 495 | * @return string content for page |
496 | 496 | */ |
497 | - public function get_messenger_admin_page_content( $page, $action = null, $extra = array(), $message_types = array() ) { |
|
498 | - return $this->_get_admin_page_content( $page, $action, $extra, $message_types ); |
|
497 | + public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array()) { |
|
498 | + return $this->_get_admin_page_content($page, $action, $extra, $message_types); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | |
@@ -505,20 +505,20 @@ discard block |
||
505 | 505 | * @param array $extra |
506 | 506 | * @return mixed|string |
507 | 507 | */ |
508 | - protected function _get_admin_content_events_edit( $message_types, $extra ) { |
|
508 | + protected function _get_admin_content_events_edit($message_types, $extra) { |
|
509 | 509 | //defaults |
510 | 510 | $template_args = array(); |
511 | 511 | $selector_rows = ''; |
512 | 512 | |
513 | 513 | //we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event. |
514 | - $event_id = isset( $extra['event'] ) ? $extra['event'] : NULL; |
|
514 | + $event_id = isset($extra['event']) ? $extra['event'] : NULL; |
|
515 | 515 | |
516 | - $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
517 | - $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
516 | + $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
517 | + $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
518 | 518 | |
519 | 519 | //array of template objects for global and custom (non-trashed) (but remember just for this messenger!) |
520 | 520 | $global_templates = EEM_Message_Template_Group::instance()->get_all( |
521 | - array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) ) |
|
521 | + array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true)) |
|
522 | 522 | ); |
523 | 523 | $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event( |
524 | 524 | $event_id, |
@@ -527,55 +527,55 @@ discard block |
||
527 | 527 | 'MTP_is_active' => true |
528 | 528 | ) |
529 | 529 | ); |
530 | - $templates_for_event = !empty( $templates_for_event ) ? $templates_for_event : array(); |
|
530 | + $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array(); |
|
531 | 531 | |
532 | 532 | //so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups) |
533 | - foreach ( $global_templates as $mtpgID => $mtpg ) { |
|
534 | - if ( $mtpg instanceof EE_Message_Template_Group ) { |
|
533 | + foreach ($global_templates as $mtpgID => $mtpg) { |
|
534 | + if ($mtpg instanceof EE_Message_Template_Group) { |
|
535 | 535 | //verify this message type is supposed to show on this page |
536 | 536 | $mtp_obj = $mtpg->message_type_obj(); |
537 | - if ( ! $mtp_obj instanceof EE_message_type ) { |
|
537 | + if ( ! $mtp_obj instanceof EE_message_type) { |
|
538 | 538 | continue; |
539 | 539 | } |
540 | - $mtp_obj->admin_registered_pages = (array)$mtp_obj->admin_registered_pages; |
|
541 | - if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) ) { |
|
540 | + $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages; |
|
541 | + if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) { |
|
542 | 542 | continue; |
543 | 543 | } |
544 | 544 | $select_values = array(); |
545 | - $select_values[ $mtpgID ] = __( 'Global', 'event_espresso' ); |
|
546 | - $default_value = array_key_exists( $mtpgID, $templates_for_event ) && ! $mtpg->get( 'MTP_is_override' ) ? $mtpgID : null; |
|
545 | + $select_values[$mtpgID] = __('Global', 'event_espresso'); |
|
546 | + $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null; |
|
547 | 547 | //if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override. |
548 | - if ( ! $mtpg->get( 'MTP_is_override' ) ) { |
|
548 | + if ( ! $mtpg->get('MTP_is_override')) { |
|
549 | 549 | //any custom templates for this message type? |
550 | - $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt( $this->name, $mtpg->message_type() ); |
|
551 | - foreach ( $custom_templates as $cmtpgID => $cmtpg ) { |
|
552 | - $select_values[ $cmtpgID ] = $cmtpg->name(); |
|
553 | - $default_value = array_key_exists( $cmtpgID, $templates_for_event ) ? $cmtpgID : $default_value; |
|
550 | + $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type()); |
|
551 | + foreach ($custom_templates as $cmtpgID => $cmtpg) { |
|
552 | + $select_values[$cmtpgID] = $cmtpg->name(); |
|
553 | + $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value; |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | //if there is no $default_value then we set it as the global |
557 | - $default_value = empty( $default_value ) ? $mtpgID : $default_value; |
|
558 | - $edit_url = EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url( 'admin.php' ) ); |
|
559 | - $create_url = EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url( 'admin.php' ) ); |
|
560 | - $st_args[ 'mt_name' ] = ucwords( $mtp_obj->label[ 'singular' ] ); |
|
561 | - $st_args[ 'mt_slug' ] = $mtpg->message_type(); |
|
562 | - $st_args[ 'messenger_slug' ] = $this->name; |
|
563 | - $st_args[ 'selector' ] = EEH_Form_Fields::select_input( 'event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector' ); |
|
557 | + $default_value = empty($default_value) ? $mtpgID : $default_value; |
|
558 | + $edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php')); |
|
559 | + $create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value), admin_url('admin.php')); |
|
560 | + $st_args['mt_name'] = ucwords($mtp_obj->label['singular']); |
|
561 | + $st_args['mt_slug'] = $mtpg->message_type(); |
|
562 | + $st_args['messenger_slug'] = $this->name; |
|
563 | + $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector'); |
|
564 | 564 | //note that message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates). |
565 | - $st_args[ 'create_button' ] = $mtpg->get( 'MTP_is_override' ) ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __( 'Create New Custom', 'event_espresso' ) . '</a>'; |
|
566 | - $st_args[ 'create_button' ] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_messages', 'espresso_messages_add_new_message_template' ) ? $st_args[ 'create_button' ] : ''; |
|
567 | - $st_args[ 'edit_button' ] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID ) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __( 'Edit', 'event_espresso' ) . '</a>' : ''; |
|
568 | - $selector_rows .= EEH_Template::display_template( $template_row_path, $st_args, true ); |
|
565 | + $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>'; |
|
566 | + $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : ''; |
|
567 | + $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : ''; |
|
568 | + $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true); |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | |
572 | 572 | //if no selectors present then get out. |
573 | - if ( empty( $selector_rows ) ) { |
|
573 | + if (empty($selector_rows)) { |
|
574 | 574 | return ''; |
575 | 575 | } |
576 | 576 | |
577 | 577 | $template_args['selector_rows'] = $selector_rows; |
578 | - return EEH_Template::display_template( $template_wrapper_path, $template_args, TRUE ); |
|
578 | + return EEH_Template::display_template($template_wrapper_path, $template_args, TRUE); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | * @return array $this->_template_fields |
591 | 591 | */ |
592 | 592 | public function get_template_fields() { |
593 | - $template_fields = apply_filters( 'FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this ); |
|
594 | - $template_fields = apply_filters( 'FHEE__EE_messenger__get_template_fields', $template_fields, $this ); |
|
593 | + $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this); |
|
594 | + $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this); |
|
595 | 595 | return $template_fields; |
596 | 596 | } |
597 | 597 | |
@@ -605,9 +605,9 @@ discard block |
||
605 | 605 | * @param mixed $value |
606 | 606 | */ |
607 | 607 | protected function _set_template_value($item, $value) { |
608 | - if ( array_key_exists($item, $this->_template_fields) ) { |
|
609 | - $prop = '_' . $item; |
|
610 | - $this->{$prop}= $value; |
|
608 | + if (array_key_exists($item, $this->_template_fields)) { |
|
609 | + $prop = '_'.$item; |
|
610 | + $this->{$prop} = $value; |
|
611 | 611 | } |
612 | 612 | } |
613 | 613 | |
@@ -618,8 +618,8 @@ discard block |
||
618 | 618 | * @return bool Very important that all messengers return bool for successful send or not. Error messages can be |
619 | 619 | * added to EE_Error. |
620 | 620 | */ |
621 | - public function send_message( $message, EE_message_type $message_type ) { |
|
622 | - $this->_validate_and_setup( $message ); |
|
621 | + public function send_message($message, EE_message_type $message_type) { |
|
622 | + $this->_validate_and_setup($message); |
|
623 | 623 | $this->_incoming_message_type = $message_type; |
624 | 624 | return $this->_send_message(); |
625 | 625 | } |
@@ -633,28 +633,28 @@ discard block |
||
633 | 633 | * @param bool $send true we will actually use the _send method (for test sends). FALSE we just return preview |
634 | 634 | * @return string return the message html content |
635 | 635 | */ |
636 | - public function get_preview( EE_Message $message, EE_message_type $message_type, $send = false ) { |
|
637 | - $this->_validate_and_setup( $message ); |
|
636 | + public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false) { |
|
637 | + $this->_validate_and_setup($message); |
|
638 | 638 | |
639 | 639 | $this->_incoming_message_type = $message_type; |
640 | 640 | |
641 | - if ( $send ) { |
|
641 | + if ($send) { |
|
642 | 642 | //are we overriding any existing template fields? |
643 | 643 | $settings = $this->get_existing_test_settings(); |
644 | - if ( ! empty( $settings ) ) { |
|
645 | - foreach ( $settings as $field => $value ) { |
|
646 | - $this->_set_template_value( $field, $value ); |
|
644 | + if ( ! empty($settings)) { |
|
645 | + foreach ($settings as $field => $value) { |
|
646 | + $this->_set_template_value($field, $value); |
|
647 | 647 | } |
648 | 648 | } |
649 | 649 | } |
650 | 650 | |
651 | 651 | //enqueue preview js so that any links/buttons on the page are disabled. |
652 | - if ( ! $send ) { |
|
652 | + if ( ! $send) { |
|
653 | 653 | // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles, |
654 | 654 | // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup. |
655 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10 ); |
|
656 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10 ); |
|
657 | - add_action( 'AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10 ); |
|
655 | + add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10); |
|
656 | + add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10); |
|
657 | + add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | return $send ? $this->_send_message() : $this->_preview(); |
@@ -672,10 +672,10 @@ discard block |
||
672 | 672 | */ |
673 | 673 | public function add_preview_script() { |
674 | 674 | //error message |
675 | - EE_Registry::$i18n_js_strings[ 'links_disabled' ] = __( 'All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup. To test generated links, you must trigger an actual message notification.', 'event_espresso' ); |
|
676 | - wp_register_script( 'ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true ); |
|
677 | - wp_localize_script( 'ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings ); |
|
678 | - wp_enqueue_script( 'ee-messages-preview-js' ); |
|
675 | + EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup. To test generated links, you must trigger an actual message notification.', 'event_espresso'); |
|
676 | + wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
677 | + wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); |
|
678 | + wp_enqueue_script('ee-messages-preview-js'); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | |
@@ -686,13 +686,13 @@ discard block |
||
686 | 686 | * @param EE_Message $message |
687 | 687 | * @throws EE_Error |
688 | 688 | */ |
689 | - protected function _validate_and_setup( EE_Message $message ) { |
|
689 | + protected function _validate_and_setup(EE_Message $message) { |
|
690 | 690 | $template_pack = $message->get_template_pack(); |
691 | 691 | $variation = $message->get_template_pack_variation(); |
692 | 692 | |
693 | 693 | //verify we have the required template pack value on the $message object. |
694 | - if ( ! $template_pack instanceof EE_Messages_Template_Pack ) { |
|
695 | - throw new EE_Error( __('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso' ) ); |
|
694 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack) { |
|
695 | + throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso')); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | $this->_tmp_pack = $template_pack; |
@@ -701,11 +701,11 @@ discard block |
||
701 | 701 | |
702 | 702 | $template_fields = $this->get_template_fields(); |
703 | 703 | |
704 | - foreach ( $template_fields as $template => $value ) { |
|
705 | - if ( $template !== 'extra' ) { |
|
706 | - $column_value = $message->get_field_or_extra_meta( 'MSG_' . $template ); |
|
704 | + foreach ($template_fields as $template => $value) { |
|
705 | + if ($template !== 'extra') { |
|
706 | + $column_value = $message->get_field_or_extra_meta('MSG_'.$template); |
|
707 | 707 | $message_template_value = $column_value ? $column_value : null; |
708 | - $this->_set_template_value( $template, $message_template_value ); |
|
708 | + $this->_set_template_value($template, $message_template_value); |
|
709 | 709 | } |
710 | 710 | } |
711 | 711 | } |
@@ -720,19 +720,19 @@ discard block |
||
720 | 720 | * @return string |
721 | 721 | * @throws \EE_Error |
722 | 722 | */ |
723 | - protected function _get_main_template( $preview = FALSE ) { |
|
723 | + protected function _get_main_template($preview = FALSE) { |
|
724 | 724 | $type = $preview ? 'preview' : 'main'; |
725 | 725 | |
726 | - $wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type ); |
|
726 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type); |
|
727 | 727 | |
728 | 728 | //check file exists and is readable |
729 | - if ( !is_readable( $wrapper_template ) ) |
|
730 | - throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) ); |
|
729 | + if ( ! is_readable($wrapper_template)) |
|
730 | + throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template)); |
|
731 | 731 | |
732 | 732 | //add message type to template args |
733 | 733 | $this->_template_args['message_type'] = $this->_incoming_message_type; |
734 | 734 | |
735 | - return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE ); |
|
735 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | |
@@ -768,9 +768,9 @@ discard block |
||
768 | 768 | */ |
769 | 769 | public function get_existing_test_settings() { |
770 | 770 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
771 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
771 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
772 | 772 | $settings = $Message_Resource_Manager->get_active_messengers_option(); |
773 | - return isset( $settings[ $this->name ]['test_settings'] ) ? $settings[ $this->name ]['test_settings'] : array(); |
|
773 | + return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array(); |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | |
@@ -782,12 +782,12 @@ discard block |
||
782 | 782 | * @param $settings |
783 | 783 | * @return bool success/fail |
784 | 784 | */ |
785 | - public function set_existing_test_settings( $settings ) { |
|
785 | + public function set_existing_test_settings($settings) { |
|
786 | 786 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
787 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
787 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
788 | 788 | $existing = $Message_Resource_Manager->get_active_messengers_option(); |
789 | - $existing[ $this->name ]['test_settings'] = $settings; |
|
790 | - return $Message_Resource_Manager->update_active_messengers_option( $existing ); |
|
789 | + $existing[$this->name]['test_settings'] = $settings; |
|
790 | + return $Message_Resource_Manager->update_active_messengers_option($existing); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | |
@@ -800,21 +800,21 @@ discard block |
||
800 | 800 | * @param string $field The field to retrieve the label for |
801 | 801 | * @return string The label |
802 | 802 | */ |
803 | - public function get_field_label( $field ) { |
|
803 | + public function get_field_label($field) { |
|
804 | 804 | //first let's see if the field requests is in the top level array. |
805 | - if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) |
|
805 | + if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) |
|
806 | 806 | return $this->_template[$field]['label']; |
807 | 807 | |
808 | 808 | //nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index. |
809 | - if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] ) ) |
|
809 | + if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) |
|
810 | 810 | return $this->_template_fields['extra'][$field]['main']['label']; |
811 | 811 | |
812 | 812 | //now it's possible this field may just be existing in any of the extra array items. |
813 | - if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) { |
|
814 | - foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) { |
|
815 | - if ( !is_array( $subfields ) ) |
|
813 | + if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { |
|
814 | + foreach ($this->_template_fields['extra'] as $main_field => $subfields) { |
|
815 | + if ( ! is_array($subfields)) |
|
816 | 816 | continue; |
817 | - if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) |
|
817 | + if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) |
|
818 | 818 | return $subfields[$field]['label']; |
819 | 819 | } |
820 | 820 | } |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * |
836 | 836 | * @return void |
837 | 837 | */ |
838 | - public function do_secondary_messenger_hooks( $sending_messenger_name ) { |
|
838 | + public function do_secondary_messenger_hooks($sending_messenger_name) { |
|
839 | 839 | return; |
840 | 840 | } |
841 | 841 |
@@ -1,6 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | +} |
|
4 | 5 | |
5 | 6 | /** |
6 | 7 | * Event Espresso |
@@ -726,8 +727,9 @@ discard block |
||
726 | 727 | $wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type ); |
727 | 728 | |
728 | 729 | //check file exists and is readable |
729 | - if ( !is_readable( $wrapper_template ) ) |
|
730 | - throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) ); |
|
730 | + if ( !is_readable( $wrapper_template ) ) { |
|
731 | + throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) ); |
|
732 | + } |
|
731 | 733 | |
732 | 734 | //add message type to template args |
733 | 735 | $this->_template_args['message_type'] = $this->_incoming_message_type; |
@@ -802,20 +804,24 @@ discard block |
||
802 | 804 | */ |
803 | 805 | public function get_field_label( $field ) { |
804 | 806 | //first let's see if the field requests is in the top level array. |
805 | - if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) |
|
806 | - return $this->_template[$field]['label']; |
|
807 | + if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) { |
|
808 | + return $this->_template[$field]['label']; |
|
809 | + } |
|
807 | 810 | |
808 | 811 | //nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index. |
809 | - if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] ) ) |
|
810 | - return $this->_template_fields['extra'][$field]['main']['label']; |
|
812 | + if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] ) ) { |
|
813 | + return $this->_template_fields['extra'][$field]['main']['label']; |
|
814 | + } |
|
811 | 815 | |
812 | 816 | //now it's possible this field may just be existing in any of the extra array items. |
813 | 817 | if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) { |
814 | 818 | foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) { |
815 | - if ( !is_array( $subfields ) ) |
|
816 | - continue; |
|
817 | - if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) |
|
818 | - return $subfields[$field]['label']; |
|
819 | + if ( !is_array( $subfields ) ) { |
|
820 | + continue; |
|
821 | + } |
|
822 | + if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) { |
|
823 | + return $subfields[$field]['label']; |
|
824 | + } |
|
819 | 825 | } |
820 | 826 | } |
821 | 827 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @param $context |
120 | 120 | * @throws \EE_Error |
121 | 121 | */ |
122 | - public function __construct( $fields, $context ) { |
|
122 | + public function __construct($fields, $context) { |
|
123 | 123 | //check that _m_name and _mt_name have been set by child class otherwise we get out. |
124 | - if ( empty($this->_m_name ) || empty( $this->_mt_name) ) |
|
124 | + if (empty($this->_m_name) || empty($this->_mt_name)) |
|
125 | 125 | throw new EE_Error( |
126 | 126 | __( |
127 | 127 | 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
@@ -167,14 +167,14 @@ discard block |
||
167 | 167 | */ |
168 | 168 | private function _load_objects() { |
169 | 169 | //load messenger |
170 | - $messenger = ucwords( str_replace( '_', ' ', $this->_m_name ) ); |
|
171 | - $messenger = str_replace( ' ', '_', $messenger ); |
|
172 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
170 | + $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
171 | + $messenger = str_replace(' ', '_', $messenger); |
|
172 | + $messenger = 'EE_'.$messenger.'_messenger'; |
|
173 | 173 | |
174 | - if ( ! class_exists( $messenger ) ) { |
|
174 | + if ( ! class_exists($messenger)) { |
|
175 | 175 | throw new EE_Error( |
176 | 176 | sprintf( |
177 | - __( 'There is no messenger class for the given string (%s)', 'event_espresso' ), |
|
177 | + __('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
178 | 178 | $this->_m_name |
179 | 179 | ) |
180 | 180 | ); |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | $this->_messenger = new $messenger(); |
184 | 184 | |
185 | 185 | //load message type |
186 | - $message_type = ucwords( str_replace( '_', ' ', $this->_mt_name ) ); |
|
187 | - $message_type = str_replace( ' ', '_', $message_type ); |
|
188 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
186 | + $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
187 | + $message_type = str_replace(' ', '_', $message_type); |
|
188 | + $message_type = 'EE_'.$message_type.'_message_type'; |
|
189 | 189 | |
190 | - if ( !class_exists( $message_type ) ) { |
|
190 | + if ( ! class_exists($message_type)) { |
|
191 | 191 | throw new EE_Error( |
192 | 192 | sprintf( |
193 | - __( 'There is no message type class for the given string (%s)', 'event_espresso' ), |
|
193 | + __('There is no message type class for the given string (%s)', 'event_espresso'), |
|
194 | 194 | $this->_mt_name |
195 | 195 | ) |
196 | 196 | ); |
@@ -227,25 +227,25 @@ discard block |
||
227 | 227 | $shortcode_groups = $mt_codes; |
228 | 228 | $groups_per_field = array(); |
229 | 229 | |
230 | - foreach ( $msgr_validator as $field => $config ) { |
|
231 | - if ( empty($config) || !isset($config['shortcodes']) ) |
|
232 | - continue; //Nothing to see here. |
|
233 | - $groups_per_field[$field] = array_intersect( $config['shortcodes'], $mt_codes ); |
|
234 | - $shortcode_groups = array_merge( $config[ 'shortcodes'], $shortcode_groups ); |
|
230 | + foreach ($msgr_validator as $field => $config) { |
|
231 | + if (empty($config) || ! isset($config['shortcodes'])) |
|
232 | + continue; //Nothing to see here. |
|
233 | + $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes); |
|
234 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
235 | 235 | } |
236 | 236 | |
237 | - $shortcode_groups = array_unique( $shortcode_groups); |
|
237 | + $shortcode_groups = array_unique($shortcode_groups); |
|
238 | 238 | |
239 | 239 | // okay now we've got our groups. |
240 | 240 | // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
241 | 241 | $codes_from_objs = array(); |
242 | 242 | |
243 | - foreach ( $shortcode_groups as $group ) { |
|
244 | - $ref = ucwords( str_replace('_', ' ', $group ) ); |
|
245 | - $ref = str_replace( ' ', '_', $ref ); |
|
246 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
247 | - if ( class_exists( $classname ) ) { |
|
248 | - $a = new ReflectionClass( $classname ); |
|
243 | + foreach ($shortcode_groups as $group) { |
|
244 | + $ref = ucwords(str_replace('_', ' ', $group)); |
|
245 | + $ref = str_replace(' ', '_', $ref); |
|
246 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
247 | + if (class_exists($classname)) { |
|
248 | + $a = new ReflectionClass($classname); |
|
249 | 249 | $obj = $a->newInstance(); |
250 | 250 | $codes_from_objs[$group] = $obj->get_shortcodes(); |
251 | 251 | } |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | |
255 | 255 | //let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
256 | 256 | $final_mt_codes = array(); |
257 | - foreach ( $mt_codes as $group ) { |
|
258 | - $final_mt_codes = array_merge( $final_mt_codes, $codes_from_objs[$group] ); |
|
257 | + foreach ($mt_codes as $group) { |
|
258 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | $mt_codes = $final_mt_codes; |
@@ -263,60 +263,60 @@ discard block |
||
263 | 263 | |
264 | 264 | // k now in this next loop we're going to loop through $msgr_validator again |
265 | 265 | // and setup the _validators property from the data we've setup so far. |
266 | - foreach ( $msgr_validator as $field => $config ) { |
|
266 | + foreach ($msgr_validator as $field => $config) { |
|
267 | 267 | //if required shortcode is not in our list of codes for the given field, then we skip this field. |
268 | 268 | $required = isset($config['required']) |
269 | 269 | ? array_intersect($config['required'], array_keys($mt_codes)) |
270 | 270 | : true; |
271 | - if ( empty($required) ) |
|
271 | + if (empty($required)) |
|
272 | 272 | continue; |
273 | 273 | |
274 | 274 | //If we have an override then we use it to indicate the codes we want. |
275 | - if ( isset( $this->_valid_shortcodes_modifier[$context][$field] ) ) { |
|
276 | - $this->_validators[ $field ][ 'shortcodes' ] = $this->_reassemble_valid_shortcodes_from_group( |
|
277 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
275 | + if (isset($this->_valid_shortcodes_modifier[$context][$field])) { |
|
276 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
277 | + $this->_valid_shortcodes_modifier[$context][$field], |
|
278 | 278 | $codes_from_objs |
279 | 279 | ); |
280 | 280 | } |
281 | 281 | |
282 | 282 | //if we have specific shortcodes for a field then we need to use them |
283 | - else if ( isset( $groups_per_field[$field] ) ) { |
|
284 | - $this->_validators[ $field ][ 'shortcodes' ] = $this->_reassemble_valid_shortcodes_from_group( |
|
285 | - $groups_per_field[ $field ], |
|
283 | + else if (isset($groups_per_field[$field])) { |
|
284 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
285 | + $groups_per_field[$field], |
|
286 | 286 | $codes_from_objs |
287 | 287 | ); |
288 | 288 | } |
289 | 289 | |
290 | 290 | //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
291 | - else if ( empty( $config ) ) { |
|
291 | + else if (empty($config)) { |
|
292 | 292 | $this->_validators[$field]['shortcodes'] = $mt_codes; |
293 | 293 | } |
294 | 294 | |
295 | 295 | //if we have specific shortcodes then we need to use them |
296 | - else if ( isset($config['specific_shortcodes'] ) ) { |
|
296 | + else if (isset($config['specific_shortcodes'])) { |
|
297 | 297 | $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes']; |
298 | 298 | } |
299 | 299 | |
300 | 300 | //otherwise the shortcodes are what is set by the messenger for that field |
301 | 301 | else { |
302 | - foreach ( $config['shortcodes'] as $group ) { |
|
302 | + foreach ($config['shortcodes'] as $group) { |
|
303 | 303 | $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes']) |
304 | - ? array_merge( $this->_validators[$field]['shortcodes'], $codes_from_objs[$group] ) |
|
304 | + ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group]) |
|
305 | 305 | : $codes_from_objs[$group]; |
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | //now let's just make sure that any excluded specific shortcodes are removed. |
310 | 310 | $specific_excludes = $this->get_specific_shortcode_excludes(); |
311 | - if ( isset( $specific_excludes[$field] ) ) { |
|
312 | - foreach( $specific_excludes[$field] as $sex ) { |
|
313 | - if ( isset( $this->_validators[$field]['shortcodes'][$sex] ) ) |
|
314 | - unset( $this->_validators[$field]['shortcodes'][$sex] ); |
|
311 | + if (isset($specific_excludes[$field])) { |
|
312 | + foreach ($specific_excludes[$field] as $sex) { |
|
313 | + if (isset($this->_validators[$field]['shortcodes'][$sex])) |
|
314 | + unset($this->_validators[$field]['shortcodes'][$sex]); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | 318 | //hey! don't forget to include the type if present! |
319 | - $this->_validators[$field]['type'] = isset( $config['type'] ) ? $config['type'] : NULL; |
|
319 | + $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : NULL; |
|
320 | 320 | } |
321 | 321 | } |
322 | 322 | |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | public function get_specific_shortcode_excludes() { |
345 | 345 | //specific validator filter |
346 | 346 | $shortcode_excludes = apply_filters( |
347 | - 'FHEE__' . get_class( $this ) . '__get_specific_shortcode_excludes;', |
|
347 | + 'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;', |
|
348 | 348 | $this->_specific_shortcode_excludes, |
349 | 349 | $this->_context |
350 | 350 | ); |
@@ -372,20 +372,20 @@ discard block |
||
372 | 372 | //some defaults |
373 | 373 | $template_fields = $this->_messenger->get_template_fields(); |
374 | 374 | //loop through the fields and check! |
375 | - foreach ( $this->_fields as $field => $value ) { |
|
375 | + foreach ($this->_fields as $field => $value) { |
|
376 | 376 | $this->_errors[$field] = array(); |
377 | 377 | $err_msg = ''; |
378 | 378 | $field_label = ''; |
379 | 379 | //if field is not present in the _validators array then we continue |
380 | - if ( !isset( $this->_validators[$field] ) ) { |
|
381 | - unset( $this->_errors[$field] ); |
|
380 | + if ( ! isset($this->_validators[$field])) { |
|
381 | + unset($this->_errors[$field]); |
|
382 | 382 | continue; |
383 | 383 | } |
384 | 384 | |
385 | 385 | //get the translated field label! |
386 | 386 | //first check if it's in the main fields list |
387 | - if ( isset( $template_fields[$field] ) ) { |
|
388 | - if ( empty( $template_fields[$field] ) ) |
|
387 | + if (isset($template_fields[$field])) { |
|
388 | + if (empty($template_fields[$field])) |
|
389 | 389 | $field_label = $field; //most likely the field is found in the 'extra' array. |
390 | 390 | else |
391 | 391 | $field_label = $template_fields[$field]['label']; |
@@ -393,16 +393,16 @@ discard block |
||
393 | 393 | |
394 | 394 | // if field label is empty OR is equal to the current field |
395 | 395 | // then we need to loop through the 'extra' fields in the template_fields config (if present) |
396 | - if ( isset( $template_fields['extra'] ) && ( empty($field_label) ) || $field_label == $field ) { |
|
397 | - foreach( $template_fields['extra'] as $main_field => $secondary_field ) { |
|
398 | - foreach ( $secondary_field as $name => $values ) { |
|
399 | - if ( $name == $field ) { |
|
396 | + if (isset($template_fields['extra']) && (empty($field_label)) || $field_label == $field) { |
|
397 | + foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
398 | + foreach ($secondary_field as $name => $values) { |
|
399 | + if ($name == $field) { |
|
400 | 400 | $field_label = $values['label']; |
401 | 401 | } |
402 | 402 | |
403 | 403 | // if we've got a 'main' secondary field, let's see if that matches what field we're on |
404 | 404 | // which means it contains the label for this field. |
405 | - if ( $name == 'main' && $main_field == $field_label ) |
|
405 | + if ($name == 'main' && $main_field == $field_label) |
|
406 | 406 | $field_label = $values['label']; |
407 | 407 | } |
408 | 408 | } |
@@ -410,27 +410,27 @@ discard block |
||
410 | 410 | |
411 | 411 | //field is present. Let's validate shortcodes first (but only if shortcodes present). |
412 | 412 | if ( |
413 | - isset( $this->_validators[ $field ][ 'shortcodes' ] ) |
|
414 | - && ! empty( $this->_validators[ $field ][ 'shortcodes' ] ) |
|
413 | + isset($this->_validators[$field]['shortcodes']) |
|
414 | + && ! empty($this->_validators[$field]['shortcodes']) |
|
415 | 415 | ) { |
416 | - $invalid_shortcodes = $this->_invalid_shortcodes( $value, $this->_validators[$field]['shortcodes'] ); |
|
416 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']); |
|
417 | 417 | // if true then that means there is a returned error message |
418 | 418 | // that we'll need to add to the _errors array for this field. |
419 | - if ( $invalid_shortcodes ) { |
|
419 | + if ($invalid_shortcodes) { |
|
420 | 420 | $v_s = array_keys($this->_validators[$field]['shortcodes']); |
421 | 421 | $err_msg = sprintf( |
422 | 422 | __( |
423 | 423 | '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
424 | 424 | 'event_espresso' |
425 | 425 | ), |
426 | - '<strong>' . $field_label . '</strong>', |
|
426 | + '<strong>'.$field_label.'</strong>', |
|
427 | 427 | $invalid_shortcodes, |
428 | 428 | '<p>', |
429 | 429 | '</p >' |
430 | 430 | ); |
431 | 431 | $err_msg .= sprintf( |
432 | - __( '%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso' ), |
|
433 | - implode( ', ', $v_s ), |
|
432 | + __('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
433 | + implode(', ', $v_s), |
|
434 | 434 | '<strong>', |
435 | 435 | '</strong>' |
436 | 436 | ); |
@@ -438,10 +438,10 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | //if there's a "type" to be validated then let's do that too. |
441 | - if ( isset( $this->_validators[$field]['type'] ) && !empty( $this->_validators[$field]['type'] ) ) { |
|
442 | - switch ( $this->_validators[$field]['type'] ) { |
|
441 | + if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) { |
|
442 | + switch ($this->_validators[$field]['type']) { |
|
443 | 443 | case 'number' : |
444 | - if ( !is_numeric($value) ) |
|
444 | + if ( ! is_numeric($value)) |
|
445 | 445 | $err_msg .= sprintf( |
446 | 446 | __( |
447 | 447 | '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | break; |
456 | 456 | case 'email' : |
457 | 457 | $valid_email = $this->_validate_email($value); |
458 | - if ( !$valid_email ) |
|
458 | + if ( ! $valid_email) |
|
459 | 459 | $err_msg .= htmlentities( |
460 | 460 | sprintf( |
461 | 461 | __( |
@@ -472,23 +472,23 @@ discard block |
||
472 | 472 | } |
473 | 473 | |
474 | 474 | //if $err_msg isn't empty let's setup the _errors array for this field. |
475 | - if ( !empty($err_msg ) ) { |
|
475 | + if ( ! empty($err_msg)) { |
|
476 | 476 | $this->_errors[$field]['msg'] = $err_msg; |
477 | 477 | } else { |
478 | - unset( $this->_errors[$field] ); |
|
478 | + unset($this->_errors[$field]); |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
482 | 482 | // if we have ANY errors, then we want to make sure we return the values |
483 | 483 | // for ALL the fields so the user doesn't have to retype them all. |
484 | - if ( !empty( $this->_errors ) ) { |
|
485 | - foreach ( $this->_fields as $field => $value ) { |
|
484 | + if ( ! empty($this->_errors)) { |
|
485 | + foreach ($this->_fields as $field => $value) { |
|
486 | 486 | $this->_errors[$field]['value'] = stripslashes($value); |
487 | 487 | } |
488 | 488 | } |
489 | 489 | |
490 | 490 | //return any errors or just TRUE if everything validates |
491 | - return empty( $this->_errors ) ? TRUE : $this->_errors; |
|
491 | + return empty($this->_errors) ? TRUE : $this->_errors; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | |
@@ -501,10 +501,10 @@ discard block |
||
501 | 501 | * @param array $codes_from_objs All the codes available. |
502 | 502 | * @return array an array of actual shortcodes (that will be used for validation). |
503 | 503 | */ |
504 | - private function _reassemble_valid_shortcodes_from_group( $groups, $codes_from_objs ) { |
|
504 | + private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) { |
|
505 | 505 | $shortcodes = array(); |
506 | - foreach ( $groups as $group ) { |
|
507 | - $shortcodes = array_merge( $shortcodes, $codes_from_objs[$group] ); |
|
506 | + foreach ($groups as $group) { |
|
507 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]); |
|
508 | 508 | } |
509 | 509 | return $shortcodes; |
510 | 510 | } |
@@ -523,29 +523,29 @@ discard block |
||
523 | 523 | */ |
524 | 524 | protected function _invalid_shortcodes($value, $valid_shortcodes) { |
525 | 525 | //first we need to go through the string and get the shortcodes in the string |
526 | - preg_match_all( '/(\[.+?\])/', $value, $matches ); |
|
526 | + preg_match_all('/(\[.+?\])/', $value, $matches); |
|
527 | 527 | $incoming_shortcodes = (array) $matches[0]; |
528 | 528 | |
529 | 529 | //get a diff of the shortcodes in the string vs the valid shortcodes |
530 | - $diff = array_diff( $incoming_shortcodes, array_keys($valid_shortcodes) ); |
|
530 | + $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
531 | 531 | |
532 | 532 | //we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
533 | - foreach ( $diff as $ind => $code ) { |
|
534 | - if ( preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code ) ) { |
|
533 | + foreach ($diff as $ind => $code) { |
|
534 | + if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
535 | 535 | //strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
536 | 536 | $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
537 | 537 | //does this exist in the $valid_shortcodes? If so then unset. |
538 | - if ( isset( $valid_shortcodes[$dynamic_sc] ) ) { |
|
539 | - unset( $diff[$ind] ); |
|
538 | + if (isset($valid_shortcodes[$dynamic_sc])) { |
|
539 | + unset($diff[$ind]); |
|
540 | 540 | } |
541 | 541 | } |
542 | 542 | } |
543 | 543 | |
544 | - if ( empty( $diff ) ) return FALSE; //there is no diff, we have no invalid shortcodes, so return |
|
544 | + if (empty($diff)) return FALSE; //there is no diff, we have no invalid shortcodes, so return |
|
545 | 545 | |
546 | 546 | //made it here? then let's assemble the error message |
547 | - $invalid_shortcodes = implode( '</strong>,<strong>', $diff ); |
|
548 | - $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
547 | + $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
548 | + $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>'; |
|
549 | 549 | return $invalid_shortcodes; |
550 | 550 | } |
551 | 551 | |
@@ -557,13 +557,13 @@ discard block |
||
557 | 557 | * @param string $value incoming value to validate |
558 | 558 | * @return bool true if the string validates, false if it doesn't |
559 | 559 | */ |
560 | - protected function _validate_email( $value ) { |
|
560 | + protected function _validate_email($value) { |
|
561 | 561 | $validate = TRUE; |
562 | 562 | $or_val = $value; |
563 | 563 | |
564 | 564 | // empty strings will validate because this is how a message template |
565 | 565 | // for a particular context can be "turned off" (if there is no email then no message) |
566 | - if ( empty( $value ) ) |
|
566 | + if (empty($value)) |
|
567 | 567 | return $validate; |
568 | 568 | |
569 | 569 | // first determine if there ARE any shortcodes. |
@@ -581,19 +581,19 @@ discard block |
||
581 | 581 | // its possible that this message is being "turned off" for a particular context |
582 | 582 | |
583 | 583 | |
584 | - if ( !empty($or_val) && empty($value) ) |
|
584 | + if ( ! empty($or_val) && empty($value)) |
|
585 | 585 | return $validate; |
586 | 586 | |
587 | 587 | //trim any commas from beginning and end of string ( after whitespace trimmed ); |
588 | - $value = trim( trim($value), ',' ); |
|
588 | + $value = trim(trim($value), ','); |
|
589 | 589 | |
590 | 590 | |
591 | 591 | //next we need to split up the string if its comma delimited. |
592 | 592 | $emails = explode(',', $value); |
593 | 593 | $empty = FALSE; //used to indicate that there is an empty comma. |
594 | 594 | //now let's loop through the emails and do our checks |
595 | - foreach ( $emails as $email ) { |
|
596 | - if ( empty($email) ) { |
|
595 | + foreach ($emails as $email) { |
|
596 | + if (empty($email)) { |
|
597 | 597 | $empty = TRUE; |
598 | 598 | continue; |
599 | 599 | } |
@@ -601,20 +601,20 @@ discard block |
||
601 | 601 | //trim whitespace |
602 | 602 | $email = trim($email); |
603 | 603 | //either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
604 | - if(is_email($email)){ |
|
604 | + if (is_email($email)) { |
|
605 | 605 | continue; |
606 | - }else{ |
|
606 | + } else { |
|
607 | 607 | $matches = array(); |
608 | - $validate = preg_match( '/(.*)<(.+)>/', $email, $matches ) ? TRUE : FALSE; |
|
609 | - if( $validate && is_email($matches[2])){ |
|
608 | + $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? TRUE : FALSE; |
|
609 | + if ($validate && is_email($matches[2])) { |
|
610 | 610 | continue; |
611 | - }else{ |
|
611 | + } else { |
|
612 | 612 | return false; |
613 | 613 | } |
614 | 614 | } |
615 | 615 | } |
616 | 616 | |
617 | - $validate = $empty && !$has_shortcodes ? FALSE : $validate; |
|
617 | + $validate = $empty && ! $has_shortcodes ? FALSE : $validate; |
|
618 | 618 | |
619 | 619 | return $validate; |
620 | 620 | |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | * @throws Exception |
631 | 631 | * @return mixed |
632 | 632 | */ |
633 | - public function __get( $property ) { |
|
633 | + public function __get($property) { |
|
634 | 634 | $expected_properties_map = array( |
635 | 635 | /** |
636 | 636 | * @deprecated 4.9.0 |
@@ -642,15 +642,15 @@ discard block |
||
642 | 642 | '_MSGTYP' => '_message_type' |
643 | 643 | ); |
644 | 644 | |
645 | - if ( isset( $expected_properties_map[ $property ] ) ) { |
|
646 | - return $this->{$expected_properties_map[ $property ]}; |
|
645 | + if (isset($expected_properties_map[$property])) { |
|
646 | + return $this->{$expected_properties_map[$property]}; |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | throw new Exception( |
650 | 650 | sprintf( |
651 | - __( 'The property %1$s being requested on %2$s does not exist', 'event_espresso' ), |
|
651 | + __('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
652 | 652 | $property, |
653 | - get_class( $this ) |
|
653 | + get_class($this) |
|
654 | 654 | ) |
655 | 655 | ); |
656 | 656 | } |
@@ -519,7 +519,7 @@ |
||
519 | 519 | * |
520 | 520 | * @param string $value string to evaluate |
521 | 521 | * @param array $valid_shortcodes array of shortcodes that are acceptable. |
522 | - * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
522 | + * @return false|string (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
523 | 523 | */ |
524 | 524 | protected function _invalid_shortcodes($value, $valid_shortcodes) { |
525 | 525 | //first we need to go through the string and get the shortcodes in the string |
@@ -458,8 +458,8 @@ discard block |
||
458 | 458 | //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
459 | 459 | //context is turned off) EXCEPT if we're previewing |
460 | 460 | if ( empty( $templates['to'][ $context ] ) |
461 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
462 | - && ! $this->_current_messenger->allow_empty_to_field() ) { |
|
461 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
462 | + && ! $this->_current_messenger->allow_empty_to_field() ) { |
|
463 | 463 | //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" field. |
464 | 464 | return false; |
465 | 465 | } |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | * Check if there is any generation data, but only if this is not for a preview. |
576 | 576 | */ |
577 | 577 | if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
578 | - && ( |
|
579 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
580 | - && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data' ) |
|
578 | + && ( |
|
579 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
580 | + && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data' ) |
|
581 | 581 | ) { |
582 | 582 | $this->_error_msg[] = __( 'There is no generation data for this message. Unable to generate.' ); |
583 | 583 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit( 'No direct script access allowed' ); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * This class is used for generating EE_Message objects with given info. |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
118 | 118 | */ |
119 | - public function generate( $save = true ) { |
|
119 | + public function generate($save = true) { |
|
120 | 120 | //iterate through the messages in the queue, generate, and add to new queue. |
121 | 121 | $this->_generation_queue->get_message_repository()->rewind(); |
122 | - while ( $this->_generation_queue->get_message_repository()->valid() ) { |
|
122 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
123 | 123 | //reset "current" properties |
124 | 124 | $this->_reset_current_properties(); |
125 | 125 | |
@@ -133,18 +133,18 @@ discard block |
||
133 | 133 | $this->_generation_queue->get_message_repository()->next(); |
134 | 134 | $next_msg = $this->_generation_queue->get_message_repository()->current(); |
135 | 135 | //restore pointer to current item |
136 | - $this->_generation_queue->get_message_repository()->set_current( $msg ); |
|
136 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
137 | 137 | |
138 | 138 | //skip and delete if the current $msg is NOT incomplete (queued for generation) |
139 | - if ( $msg->STS_ID() !== EEM_Message::status_incomplete ) { |
|
139 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
140 | 140 | //we keep this item in the db just remove from the repo. |
141 | - $this->_generation_queue->get_message_repository()->remove( $msg ); |
|
141 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
142 | 142 | //next item |
143 | - $this->_generation_queue->get_message_repository()->set_current( $next_msg ); |
|
143 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
144 | 144 | continue; |
145 | 145 | } |
146 | 146 | |
147 | - if ( $this->_verify() ) { |
|
147 | + if ($this->_verify()) { |
|
148 | 148 | //let's get generating! |
149 | 149 | $this->_generate(); |
150 | 150 | } |
@@ -155,28 +155,28 @@ discard block |
||
155 | 155 | && ! EEM_Message::debug() |
156 | 156 | ) { |
157 | 157 | $this->_generation_queue->get_message_repository()->delete(); |
158 | - $this->_generation_queue->get_message_repository()->set_current( $next_msg ); |
|
158 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | |
162 | 162 | //if there are error messages then let's set the status and the error message. |
163 | - if ( $this->_error_msg ) { |
|
163 | + if ($this->_error_msg) { |
|
164 | 164 | //if the status is already debug only, then let's leave it at that. |
165 | - if ( $msg->STS_ID() !== EEM_Message::status_debug_only ) { |
|
166 | - $msg->set_STS_ID( EEM_Message::status_failed ); |
|
165 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
166 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
167 | 167 | } |
168 | 168 | $msg->set_error_message( |
169 | - __( 'Message failed to generate for the following reasons: ' ) |
|
169 | + __('Message failed to generate for the following reasons: ') |
|
170 | 170 | . "\n" |
171 | - . implode( "\n", $this->_error_msg ) |
|
171 | + . implode("\n", $this->_error_msg) |
|
172 | 172 | ); |
173 | - $msg->set_modified( time() ); |
|
173 | + $msg->set_modified(time()); |
|
174 | 174 | } else { |
175 | 175 | //remove from db |
176 | 176 | $this->_generation_queue->get_message_repository()->delete(); |
177 | 177 | } |
178 | 178 | //next item |
179 | - $this->_generation_queue->get_message_repository()->set_current( $next_msg ); |
|
179 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | //generation queue is ALWAYS saved to record any errors in the generation process. |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
190 | 190 | * irrelevant. |
191 | 191 | */ |
192 | - if ( $save ) { |
|
192 | + if ($save) { |
|
193 | 193 | $this->_ready_queue->save(); |
194 | 194 | } |
195 | 195 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | protected function _reset_current_properties() { |
208 | 208 | $this->_verified = false; |
209 | 209 | //make sure any _data value in the current message type is reset |
210 | - if ( $this->_current_message_type instanceof EE_message_type ) { |
|
210 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
211 | 211 | $this->_current_message_type->reset_data(); |
212 | 212 | } |
213 | 213 | $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | protected function _generate() { |
228 | 228 | //double check verification has run and that everything is ready to work with (saves us having to validate everything again). |
229 | - if ( ! $this->_verified ) { |
|
229 | + if ( ! $this->_verified) { |
|
230 | 230 | return false; //get out because we don't have a valid setup to work with. |
231 | 231 | } |
232 | 232 | |
@@ -236,34 +236,34 @@ discard block |
||
236 | 236 | $this->_current_data_handler, |
237 | 237 | $this->_generation_queue->get_message_repository()->current()->context() |
238 | 238 | ); |
239 | - } catch ( EE_Error $e ) { |
|
239 | + } catch (EE_Error $e) { |
|
240 | 240 | $this->_error_msg[] = $e->getMessage(); |
241 | 241 | return false; |
242 | 242 | } |
243 | 243 | |
244 | 244 | |
245 | 245 | //if no addressees then get out because there is nothing to generation (possible bad data). |
246 | - if ( ! $this->_valid_addressees( $addressees ) ) { |
|
247 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID( EEM_Message::status_debug_only ); |
|
248 | - $this->_error_msg[] = __( 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. |
|
249 | - Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', 'event_espresso' ); |
|
246 | + if ( ! $this->_valid_addressees($addressees)) { |
|
247 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID(EEM_Message::status_debug_only); |
|
248 | + $this->_error_msg[] = __('This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. |
|
249 | + Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', 'event_espresso'); |
|
250 | 250 | return false; |
251 | 251 | } |
252 | 252 | |
253 | 253 | $message_template_group = $this->_get_message_template_group(); |
254 | 254 | |
255 | 255 | //in the unlikely event there is no EE_Message_Template_Group available, get out! |
256 | - if ( ! $message_template_group instanceof EE_Message_Template_Group ) { |
|
257 | - $this->_error_msg[] = __( 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', 'event_espresso' ); |
|
256 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
257 | + $this->_error_msg[] = __('Unable to get the Message Templates for the Message being generated. No message template group accessible.', 'event_espresso'); |
|
258 | 258 | return false; |
259 | 259 | } |
260 | 260 | |
261 | 261 | //get formatted templates for using to parse and setup EE_Message objects. |
262 | - $templates = $this->_get_templates( $message_template_group ); |
|
262 | + $templates = $this->_get_templates($message_template_group); |
|
263 | 263 | |
264 | 264 | |
265 | 265 | //setup new EE_Message objects (and add to _ready_queue) |
266 | - return $this->_assemble_messages( $addressees, $templates, $message_template_group ); |
|
266 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | |
@@ -281,17 +281,17 @@ discard block |
||
281 | 281 | //so let's use that. |
282 | 282 | $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
283 | 283 | |
284 | - if ( $GRP_ID ) { |
|
284 | + if ($GRP_ID) { |
|
285 | 285 | //attempt to retrieve from repo first |
286 | - $GRP = $this->_template_collection->get_by_ID( $GRP_ID ); |
|
287 | - if ( $GRP instanceof EE_Message_Template_Group ) { |
|
288 | - return $GRP; //got it! |
|
286 | + $GRP = $this->_template_collection->get_by_ID($GRP_ID); |
|
287 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
288 | + return $GRP; //got it! |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | //nope don't have it yet. Get from DB then add to repo |
292 | - $GRP = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
293 | - if ( $GRP instanceof EE_Message_Template_Group ) { |
|
294 | - $this->_template_collection->add( $GRP ); |
|
292 | + $GRP = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
293 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
294 | + $this->_template_collection->add($GRP); |
|
295 | 295 | } |
296 | 296 | return $GRP; |
297 | 297 | } |
@@ -310,41 +310,41 @@ discard block |
||
310 | 310 | //in vanilla EE we're assuming there's only one event. |
311 | 311 | //However, if there are multiple events then we'll just use the default templates instead of different |
312 | 312 | // templates per event (which could create problems). |
313 | - if ( count( $this->_current_data_handler->events ) === 1 ) { |
|
314 | - foreach ( $this->_current_data_handler->events as $event ) { |
|
313 | + if (count($this->_current_data_handler->events) === 1) { |
|
314 | + foreach ($this->_current_data_handler->events as $event) { |
|
315 | 315 | $EVT_ID = $event['ID']; |
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | 319 | //before going any further, let's see if its in the queue |
320 | - $GRP = $this->_template_collection->get_by_key( $this->_template_collection->get_key( $this->_current_messenger->name, $this->_current_message_type->name, $EVT_ID ) ); |
|
320 | + $GRP = $this->_template_collection->get_by_key($this->_template_collection->get_key($this->_current_messenger->name, $this->_current_message_type->name, $EVT_ID)); |
|
321 | 321 | |
322 | - if ( $GRP instanceof EE_Message_Template_Group ) { |
|
322 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
323 | 323 | return $GRP; |
324 | 324 | } |
325 | 325 | |
326 | 326 | //nope still no GRP? |
327 | 327 | //first we get the global template in case it has an override set. |
328 | - $global_template_qa = array_merge( array( 'MTP_is_global' => true ), $template_qa ); |
|
329 | - $global_GRP = EEM_Message_Template_Group::instance()->get_one( array( $global_template_qa ) ); |
|
328 | + $global_template_qa = array_merge(array('MTP_is_global' => true), $template_qa); |
|
329 | + $global_GRP = EEM_Message_Template_Group::instance()->get_one(array($global_template_qa)); |
|
330 | 330 | |
331 | 331 | //if this is an override, then we just return it. |
332 | - if ( $global_GRP instanceof EE_Message_Template_Group && $global_GRP->get( 'MTP_is_override' ) ) { |
|
333 | - $this->_template_collection->add( $global_GRP, $EVT_ID ); |
|
332 | + if ($global_GRP instanceof EE_Message_Template_Group && $global_GRP->get('MTP_is_override')) { |
|
333 | + $this->_template_collection->add($global_GRP, $EVT_ID); |
|
334 | 334 | return $global_GRP; |
335 | 335 | } |
336 | 336 | |
337 | 337 | //STILL here? Okay that means we want to see if there is event specific group and if there is we return it, |
338 | 338 | //otherwise we return the global group we retrieved. |
339 | - if ( $EVT_ID ) { |
|
339 | + if ($EVT_ID) { |
|
340 | 340 | $template_qa['Event.EVT_ID'] = $EVT_ID; |
341 | 341 | } |
342 | 342 | |
343 | - $GRP = EEM_Message_Template_Group::instance()->get_one( array( $template_qa ) ); |
|
343 | + $GRP = EEM_Message_Template_Group::instance()->get_one(array($template_qa)); |
|
344 | 344 | $GRP = $GRP instanceof EE_Message_Template_Group ? $GRP : $global_GRP; |
345 | 345 | |
346 | - if ( $GRP instanceof EE_Message_Template_Group ) { |
|
347 | - $this->_template_collection->add( $GRP, $EVT_ID ); |
|
346 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
347 | + $this->_template_collection->add($GRP, $EVT_ID); |
|
348 | 348 | return $GRP; |
349 | 349 | } |
350 | 350 | |
@@ -368,15 +368,15 @@ discard block |
||
368 | 368 | * ) |
369 | 369 | * ) |
370 | 370 | */ |
371 | - protected function _get_templates( EE_Message_Template_Group $message_template_group ) { |
|
371 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) { |
|
372 | 372 | $templates = array(); |
373 | 373 | $context_templates = $message_template_group->context_templates(); |
374 | - foreach ( $context_templates as $context => $template_fields ) { |
|
375 | - foreach ( $template_fields as $template_field => $template_obj ) { |
|
376 | - if ( ! $template_obj instanceof EE_Message_Template ) { |
|
374 | + foreach ($context_templates as $context => $template_fields) { |
|
375 | + foreach ($template_fields as $template_field => $template_obj) { |
|
376 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
377 | 377 | continue; |
378 | 378 | } |
379 | - $templates[ $template_field ][ $context ] = $template_obj->get( 'MTP_content' ); |
|
379 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | return $templates; |
@@ -398,20 +398,20 @@ discard block |
||
398 | 398 | * get added to the queue with EEM_Message::status_idle, unsuccessfully generated messages will get added |
399 | 399 | * to the queue as EEM_Message::status_failed. Very rarely should "false" be returned from this method. |
400 | 400 | */ |
401 | - protected function _assemble_messages( $addressees, $templates, EE_Message_Template_Group $message_template_group ) { |
|
401 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) { |
|
402 | 402 | |
403 | 403 | //if templates are empty then get out because we can't generate anything. |
404 | - if ( ! $templates ) { |
|
404 | + if ( ! $templates) { |
|
405 | 405 | return false; |
406 | 406 | } |
407 | 407 | |
408 | 408 | //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
409 | 409 | //generation_queue. So _ready_queue may have generated EE_Message objects already. |
410 | 410 | $generated_count = 0; |
411 | - foreach ( $addressees as $context => $recipients ) { |
|
412 | - foreach ( $recipients as $recipient ) { |
|
413 | - $message = $this->_setup_message_object( $context, $recipient, $templates, $message_template_group ); |
|
414 | - if ( $message instanceof EE_Message ) { |
|
411 | + foreach ($addressees as $context => $recipients) { |
|
412 | + foreach ($recipients as $recipient) { |
|
413 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
414 | + if ($message instanceof EE_Message) { |
|
415 | 415 | $this->_ready_queue->add( |
416 | 416 | $message, |
417 | 417 | array(), |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | } |
423 | 423 | |
424 | 424 | //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
425 | - if ( $this->_generation_queue->get_message_repository()->is_test_send() ) { |
|
425 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
426 | 426 | break 2; |
427 | 427 | } |
428 | 428 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | ) { |
452 | 452 | //stuff we already know |
453 | 453 | $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
454 | - $transaction_id = empty( $transaction_id ) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
454 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
455 | 455 | ? $this->_current_data_handler->txn->ID() |
456 | 456 | : $transaction_id; |
457 | 457 | $message_fields = array( |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | |
465 | 465 | //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab the |
466 | 466 | //info from the att_obj found in the EE_Messages_Addressee object. |
467 | - if ( empty( $recipient->recipient_id ) || empty( $recipient->recipient_type ) ) { |
|
467 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
468 | 468 | $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
469 | 469 | ? $recipient->att_obj->ID() |
470 | 470 | : 0; |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
474 | 474 | $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
475 | 475 | } |
476 | - $message = EE_Message_Factory::create( $message_fields ); |
|
476 | + $message = EE_Message_Factory::create($message_fields); |
|
477 | 477 | |
478 | 478 | //grab valid shortcodes for shortcode parser |
479 | 479 | $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
@@ -481,43 +481,43 @@ discard block |
||
481 | 481 | |
482 | 482 | //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
483 | 483 | //context is turned off) EXCEPT if we're previewing |
484 | - if ( empty( $templates['to'][ $context ] ) |
|
484 | + if (empty($templates['to'][$context]) |
|
485 | 485 | && ! $this->_generation_queue->get_message_repository()->is_preview() |
486 | - && ! $this->_current_messenger->allow_empty_to_field() ) { |
|
486 | + && ! $this->_current_messenger->allow_empty_to_field()) { |
|
487 | 487 | //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" field. |
488 | 488 | return false; |
489 | 489 | } |
490 | 490 | $error_msg = array(); |
491 | - foreach ( $templates as $field => $field_context ) { |
|
491 | + foreach ($templates as $field => $field_context) { |
|
492 | 492 | $error_msg = array(); |
493 | 493 | //let's setup the valid shortcodes for the incoming context. |
494 | - $valid_shortcodes = $mt_shortcodes[ $context ]; |
|
494 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
495 | 495 | //merge in valid shortcodes for the field. |
496 | - $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes; |
|
497 | - if ( isset( $templates[ $field ][ $context ] ) ) { |
|
496 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
497 | + if (isset($templates[$field][$context])) { |
|
498 | 498 | //prefix field. |
499 | - $column_name = 'MSG_' . $field; |
|
499 | + $column_name = 'MSG_'.$field; |
|
500 | 500 | try { |
501 | 501 | $content = $this->_shortcode_parser->parse_message_template( |
502 | - $templates[ $field ][ $context ], |
|
502 | + $templates[$field][$context], |
|
503 | 503 | $recipient, |
504 | 504 | $shortcodes, |
505 | 505 | $this->_current_message_type, |
506 | 506 | $this->_current_messenger, |
507 | 507 | $message ); |
508 | - $message->set_field_or_extra_meta( $column_name, $content ); |
|
509 | - } catch ( EE_Error $e ) { |
|
510 | - $error_msg[] = sprintf( __( 'There was a problem generating the content for the field %s: %s', 'event_espresso' ), $field, $e->getMessage() ); |
|
511 | - $message->set_STS_ID( EEM_Message::status_failed ); |
|
508 | + $message->set_field_or_extra_meta($column_name, $content); |
|
509 | + } catch (EE_Error $e) { |
|
510 | + $error_msg[] = sprintf(__('There was a problem generating the content for the field %s: %s', 'event_espresso'), $field, $e->getMessage()); |
|
511 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
512 | 512 | } |
513 | 513 | } |
514 | 514 | } |
515 | 515 | |
516 | - if ( $message->STS_ID() === EEM_Message::status_failed ) { |
|
517 | - $error_msg = __( 'There were problems generating this message:', 'event_espresso' ) . "\n" . implode( "\n", $error_msg ); |
|
518 | - $message->set_error_message( $error_msg ); |
|
516 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
517 | + $error_msg = __('There were problems generating this message:', 'event_espresso')."\n".implode("\n", $error_msg); |
|
518 | + $message->set_error_message($error_msg); |
|
519 | 519 | } else { |
520 | - $message->set_STS_ID( EEM_Message::status_idle ); |
|
520 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
521 | 521 | } |
522 | 522 | return $message; |
523 | 523 | } |
@@ -551,14 +551,14 @@ discard block |
||
551 | 551 | * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
552 | 552 | * @return bool |
553 | 553 | */ |
554 | - protected function _valid_addressees( $addressees ) { |
|
555 | - if ( ! $addressees || ! is_array( $addressees ) ) { |
|
554 | + protected function _valid_addressees($addressees) { |
|
555 | + if ( ! $addressees || ! is_array($addressees)) { |
|
556 | 556 | return false; |
557 | 557 | } |
558 | 558 | |
559 | - foreach( $addressees as $addressee_array ) { |
|
560 | - foreach ( $addressee_array as $addressee ) { |
|
561 | - if ( ! $addressee instanceof EE_Messages_Addressee ) { |
|
559 | + foreach ($addressees as $addressee_array) { |
|
560 | + foreach ($addressee_array as $addressee) { |
|
561 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
562 | 562 | return false; |
563 | 563 | } |
564 | 564 | } |
@@ -579,19 +579,19 @@ discard block |
||
579 | 579 | protected function _validate_messenger_and_message_type() { |
580 | 580 | |
581 | 581 | //first are there any existing error messages? If so then return. |
582 | - if ( $this->_error_msg ) { |
|
582 | + if ($this->_error_msg) { |
|
583 | 583 | return false; |
584 | 584 | } |
585 | 585 | /** @type EE_Message $message */ |
586 | 586 | $message = $this->_generation_queue->get_message_repository()->current(); |
587 | 587 | try { |
588 | - $this->_current_messenger = $message->valid_messenger( true ) ? $message->messenger_object() : null; |
|
589 | - } catch ( Exception $e ) { |
|
588 | + $this->_current_messenger = $message->valid_messenger(true) ? $message->messenger_object() : null; |
|
589 | + } catch (Exception $e) { |
|
590 | 590 | $this->_error_msg[] = $e->getMessage(); |
591 | 591 | } |
592 | 592 | try { |
593 | - $this->_current_message_type = $message->valid_message_type( true ) ? $message->message_type_object() : null; |
|
594 | - } catch ( Exception $e ) { |
|
593 | + $this->_current_message_type = $message->valid_message_type(true) ? $message->message_type_object() : null; |
|
594 | + } catch (Exception $e) { |
|
595 | 595 | $this->_error_msg[] = $e->getMessage(); |
596 | 596 | } |
597 | 597 | |
@@ -603,10 +603,10 @@ discard block |
||
603 | 603 | ! $this->_generation_queue->get_message_repository()->is_preview() |
604 | 604 | && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data' ) |
605 | 605 | ) { |
606 | - $this->_error_msg[] = __( 'There is no generation data for this message. Unable to generate.' ); |
|
606 | + $this->_error_msg[] = __('There is no generation data for this message. Unable to generate.'); |
|
607 | 607 | } |
608 | 608 | |
609 | - return empty( $this->_error_msg ); |
|
609 | + return empty($this->_error_msg); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | |
624 | 624 | //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
625 | 625 | //be used anyways. |
626 | - if ( $this->_error_msg ) { |
|
626 | + if ($this->_error_msg) { |
|
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | |
@@ -632,29 +632,29 @@ discard block |
||
632 | 632 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
633 | 633 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
634 | 634 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
635 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler( $generation_data ) . '_incoming_data'; |
|
635 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
636 | 636 | |
637 | 637 | //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
638 | - if ( $this->_generation_queue->get_message_repository()->is_preview() ) { |
|
639 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
638 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
639 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | //First get the class name for the data handler (and also verifies it exists. |
643 | - if ( ! class_exists( $data_handler_class_name ) ) { |
|
643 | + if ( ! class_exists($data_handler_class_name)) { |
|
644 | 644 | $this->_error_msg[] = sprintf( |
645 | - __( 'The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', 'event_espresso' ), |
|
645 | + __('The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', 'event_espresso'), |
|
646 | 646 | $data_handler_class_name |
647 | 647 | ); |
648 | 648 | return false; |
649 | 649 | } |
650 | 650 | |
651 | 651 | //convert generation_data for data_handler_instantiation. |
652 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage( $generation_data ); |
|
652 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
653 | 653 | |
654 | 654 | //note, this may set error messages as well. |
655 | - $this->_set_data_handler( $generation_data, $data_handler_class_name ); |
|
655 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
656 | 656 | |
657 | - return empty( $this->_error_msg ); |
|
657 | + return empty($this->_error_msg); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | |
@@ -671,16 +671,16 @@ discard block |
||
671 | 671 | * |
672 | 672 | * @return void. |
673 | 673 | */ |
674 | - protected function _set_data_handler( $generating_data, $data_handler_class_name ) { |
|
674 | + protected function _set_data_handler($generating_data, $data_handler_class_name) { |
|
675 | 675 | //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
676 | 676 | //is already a ready data handler in the repository. |
677 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key( $this->_data_handler_collection->get_key( $data_handler_class_name, $generating_data ) ); |
|
678 | - if ( ! $this->_current_data_handler instanceof EE_messages_incoming_data ) { |
|
677 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key($this->_data_handler_collection->get_key($data_handler_class_name, $generating_data)); |
|
678 | + if ( ! $this->_current_data_handler instanceof EE_messages_incoming_data) { |
|
679 | 679 | //no saved data_handler in the repo so let's set one up and add it to the repo. |
680 | 680 | try { |
681 | - $this->_current_data_handler = new $data_handler_class_name( $generating_data ); |
|
682 | - $this->_data_handler_collection->add( $this->_current_data_handler, $generating_data ); |
|
683 | - } catch( EE_Error $e ) { |
|
681 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
682 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
683 | + } catch (EE_Error $e) { |
|
684 | 684 | $this->_error_msg[] = $e->get_error(); |
685 | 685 | } |
686 | 686 | } |
@@ -700,13 +700,13 @@ discard block |
||
700 | 700 | * @param bool $preview Indicate whether this is being used for a preview or not. |
701 | 701 | * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
702 | 702 | */ |
703 | - protected function _prepare_data_for_queue( EE_Message_To_Generate $message_to_generate, $preview ) { |
|
703 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) { |
|
704 | 704 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
705 | - $data_handler = $message_to_generate->get_data_handler_class_name( $preview ); |
|
706 | - if ( ! $message_to_generate->valid() ) { |
|
705 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
706 | + if ( ! $message_to_generate->valid()) { |
|
707 | 707 | return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
708 | 708 | } |
709 | - return $data_handler::convert_data_for_persistent_storage( $message_to_generate->data() ); |
|
709 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | |
@@ -719,26 +719,26 @@ discard block |
||
719 | 719 | * @param EE_Message_To_Generate $message_to_generate |
720 | 720 | * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
721 | 721 | */ |
722 | - public function create_and_add_message_to_queue( EE_Message_To_Generate $message_to_generate, $test_send = false ) { |
|
722 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) { |
|
723 | 723 | //prep data |
724 | - $data = $this->_prepare_data_for_queue( $message_to_generate, $message_to_generate->preview() ); |
|
724 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
725 | 725 | |
726 | 726 | $message = $message_to_generate->get_EE_Message(); |
727 | 727 | |
728 | 728 | //is there a GRP_ID in the request? |
729 | - if ( $GRP_ID = EE_Registry::instance()->REQ->get( 'GRP_ID' ) ) { |
|
730 | - $message->set_GRP_ID( $GRP_ID ); |
|
729 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
730 | + $message->set_GRP_ID($GRP_ID); |
|
731 | 731 | } |
732 | 732 | |
733 | - if ( $data === false ) { |
|
734 | - $message->set_STS_ID( EEM_Message::status_failed ); |
|
735 | - $message->set_error_message( __( 'Unable to prepare data for persistence to the database.', 'event_espresso' ) ); |
|
733 | + if ($data === false) { |
|
734 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
735 | + $message->set_error_message(__('Unable to prepare data for persistence to the database.', 'event_espresso')); |
|
736 | 736 | } else { |
737 | 737 | //make sure that the data handler is cached on the message as well |
738 | 738 | $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
739 | 739 | } |
740 | 740 | |
741 | - $this->_generation_queue->add( $message, $data, $message_to_generate->preview(), $test_send ); |
|
741 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * EE_Message_Template_Group class |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | * @param string $timezone |
19 | 19 | * @return EE_Message_Template_Group|mixed |
20 | 20 | */ |
21 | - public static function new_instance( $props_n_values = array(), $timezone = '' ) { |
|
22 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone ); |
|
23 | - return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone ); |
|
21 | + public static function new_instance($props_n_values = array(), $timezone = '') { |
|
22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | + return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | * @param string $timezone |
31 | 31 | * @return EE_Message_Template_Group |
32 | 32 | */ |
33 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = '' ) { |
|
34 | - return new self( $props_n_values, TRUE, $timezone ); |
|
33 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') { |
|
34 | + return new self($props_n_values, TRUE, $timezone); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | * @param bool $message_type |
41 | 41 | * @throws EE_Error |
42 | 42 | */ |
43 | - public function set_message_type( $message_type = FALSE ) { |
|
44 | - if ( ! $message_type ) { |
|
45 | - throw new EE_Error( __( 'Missing required value for the message_type parameter', 'event_espresso' ) ); |
|
43 | + public function set_message_type($message_type = FALSE) { |
|
44 | + if ( ! $message_type) { |
|
45 | + throw new EE_Error(__('Missing required value for the message_type parameter', 'event_espresso')); |
|
46 | 46 | } |
47 | - $this->set( 'MTP_message_type', $message_type ); |
|
47 | + $this->set('MTP_message_type', $message_type); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | * @param bool $messenger |
54 | 54 | * @throws EE_Error |
55 | 55 | */ |
56 | - public function set_messenger( $messenger = FALSE ) { |
|
57 | - if ( ! $messenger ) { |
|
58 | - throw new EE_Error( __( 'Missing required value for the messenger parameter', 'event_espresso' ) ); |
|
56 | + public function set_messenger($messenger = FALSE) { |
|
57 | + if ( ! $messenger) { |
|
58 | + throw new EE_Error(__('Missing required value for the messenger parameter', 'event_espresso')); |
|
59 | 59 | } |
60 | - $this->set( 'MTP_messenger', $messenger ); |
|
60 | + $this->set('MTP_messenger', $messenger); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @param bool $GRP_ID |
67 | 67 | * @throws EE_Error |
68 | 68 | */ |
69 | - public function set_group_template_id( $GRP_ID = FALSE ) { |
|
70 | - if ( ! $GRP_ID ) { |
|
71 | - throw new EE_Error( __( 'Missing required value for the message template group id', 'event_espresso' ) ); |
|
69 | + public function set_group_template_id($GRP_ID = FALSE) { |
|
70 | + if ( ! $GRP_ID) { |
|
71 | + throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
72 | 72 | } |
73 | - $this->set( 'GRP_ID', $GRP_ID ); |
|
73 | + $this->set('GRP_ID', $GRP_ID); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return int |
82 | 82 | */ |
83 | 83 | public function GRP_ID() { |
84 | - return $this->get( 'GRP_ID' ); |
|
84 | + return $this->get('GRP_ID'); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | * @return int |
93 | 93 | */ |
94 | 94 | public function user() { |
95 | - $user_id = $this->get( 'MTP_user_id' ); |
|
96 | - return empty( $user_id ) ? get_current_user_id() : $user_id; |
|
95 | + $user_id = $this->get('MTP_user_id'); |
|
96 | + return empty($user_id) ? get_current_user_id() : $user_id; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @return int |
117 | 117 | */ |
118 | 118 | public function count_events() { |
119 | - return $this->count_related( 'Event' ); |
|
119 | + return $this->count_related('Event'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @return string |
127 | 127 | */ |
128 | 128 | public function name() { |
129 | - return $this->get( 'MTP_name' ); |
|
129 | + return $this->get('MTP_name'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @return string |
137 | 137 | */ |
138 | 138 | public function description() { |
139 | - return $this->get( 'MTP_description' ); |
|
139 | + return $this->get('MTP_description'); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @param array $query_params like EEM_Base::get_all() |
147 | 147 | * @return EE_Message_Template[] |
148 | 148 | */ |
149 | - public function message_templates( $query_params = array() ) { |
|
150 | - return $this->get_many_related( 'Message_Template', $query_params ); |
|
149 | + public function message_templates($query_params = array()) { |
|
150 | + return $this->get_many_related('Message_Template', $query_params); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | public function messenger() { |
161 | - return $this->get( 'MTP_messenger' ); |
|
161 | + return $this->get('MTP_messenger'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | public function messenger_obj() { |
176 | 176 | $messenger = $this->messenger(); |
177 | 177 | try { |
178 | - $messenger = EEH_MSG_Template::messenger_obj( $messenger ); |
|
179 | - } catch( EE_Error $e ) { |
|
178 | + $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
179 | + } catch (EE_Error $e) { |
|
180 | 180 | //if an exception was thrown then let's deactivate this message template group because it means there is no class for this messenger in this group. |
181 | - $this->set( 'MTP_is_active', false ); |
|
181 | + $this->set('MTP_is_active', false); |
|
182 | 182 | $this->save(); |
183 | 183 | return null; |
184 | 184 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * @return string |
195 | 195 | */ |
196 | 196 | public function message_type() { |
197 | - return $this->get( 'MTP_message_type' ); |
|
197 | + return $this->get('MTP_message_type'); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | public function message_type_obj() { |
213 | 213 | $message_type = $this->message_type(); |
214 | 214 | try { |
215 | - $message_type = EEH_MSG_Template::message_type_obj( $message_type ); |
|
216 | - } catch(EE_Error $e) { |
|
215 | + $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
216 | + } catch (EE_Error $e) { |
|
217 | 217 | //if an exception was thrown then let's deactivate this message template group because it means there is no class for the message type in this group. |
218 | - $this->set( 'MTP_is_active', false ); |
|
218 | + $this->set('MTP_is_active', false); |
|
219 | 219 | $this->save(); |
220 | 220 | return null; |
221 | 221 | } |
@@ -252,13 +252,13 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function context_templates() { |
254 | 254 | $mtps_arr = array(); |
255 | - $mtps = $this->get_many_related( 'Message_Template' ); |
|
256 | - if ( empty( $mtps ) ) { |
|
255 | + $mtps = $this->get_many_related('Message_Template'); |
|
256 | + if (empty($mtps)) { |
|
257 | 257 | return array(); |
258 | 258 | } |
259 | 259 | //note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
260 | - foreach ( $mtps as $mtp ) { |
|
261 | - $mtps_arr[ $mtp->get( 'MTP_context' ) ][ $mtp->get( 'MTP_template_field' ) ] = $mtp; |
|
260 | + foreach ($mtps as $mtp) { |
|
261 | + $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp; |
|
262 | 262 | } |
263 | 263 | return $mtps_arr; |
264 | 264 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @return boolean true if it is, false if it isn't |
271 | 271 | */ |
272 | 272 | public function is_global() { |
273 | - return $this->get( 'MTP_is_global' ); |
|
273 | + return $this->get('MTP_is_global'); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @return boolean true if it is, false if it isn't |
281 | 281 | */ |
282 | 282 | public function is_active() { |
283 | - return $this->get( 'MTP_is_active' ); |
|
283 | + return $this->get('MTP_is_active'); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the unique shortcodes for all the given (or all) fields. |
297 | 297 | * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no shortcodes found. |
298 | 298 | */ |
299 | - public function get_shortcodes( $context, $fields = array(), $merged = FALSE ) { |
|
299 | + public function get_shortcodes($context, $fields = array(), $merged = FALSE) { |
|
300 | 300 | $messenger = $this->messenger(); |
301 | 301 | $message_type = $this->message_type(); |
302 | - return EEH_MSG_Template::get_shortcodes( $message_type, $messenger, $fields, $context, $merged ); |
|
302 | + return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | * @return string |
341 | 341 | */ |
342 | 342 | public function get_template_pack_name() { |
343 | - return $this->get_extra_meta( 'MTP_template_pack', true, 'default' ); |
|
343 | + return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | */ |
356 | 356 | public function get_template_pack() { |
357 | 357 | $pack_name = $this->get_template_pack_name(); |
358 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
359 | - return EEH_MSG_Template::get_template_pack( $pack_name ); |
|
358 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
359 | + return EEH_MSG_Template::get_template_pack($pack_name); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return string |
370 | 370 | */ |
371 | 371 | public function get_template_pack_variation() { |
372 | - return $this->get_extra_meta( 'MTP_variation', TRUE, 'default' ); |
|
372 | + return $this->get_extra_meta('MTP_variation', TRUE, 'default'); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | * @param string $template_pack_name What message template pack is assigned. |
382 | 382 | * @return int |
383 | 383 | */ |
384 | - public function set_template_pack_name( $template_pack_name ) { |
|
385 | - return $this->update_extra_meta( 'MTP_template_pack', $template_pack_name ); |
|
384 | + public function set_template_pack_name($template_pack_name) { |
|
385 | + return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param string $variation What variation is being set on the message template group. |
395 | 395 | * @return int |
396 | 396 | */ |
397 | - public function set_template_pack_variation( $variation ) { |
|
398 | - return $this->update_extra_meta( 'MTP_variation', $variation ); |
|
397 | + public function set_template_pack_variation($variation) { |
|
398 | + return $this->update_extra_meta('MTP_variation', $variation); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | //end EE_Message_Template_Group class |
@@ -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 | } |
@@ -458,14 +458,14 @@ discard block |
||
458 | 458 | if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
459 | 459 | try{ |
460 | 460 | $validation_strategy->validate($this->normalized_value()); |
461 | - }catch(EE_Validation_Error $e){ |
|
461 | + } catch(EE_Validation_Error $e){ |
|
462 | 462 | $this->add_validation_error($e); |
463 | 463 | } |
464 | 464 | } |
465 | 465 | } |
466 | 466 | if( $this->get_validation_errors()){ |
467 | 467 | return false; |
468 | - }else{ |
|
468 | + } else{ |
|
469 | 469 | return true; |
470 | 470 | } |
471 | 471 | } |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
829 | 829 | $name_parts = $matches[ 1 ]; |
830 | 830 | array_unshift($name_parts, $before_any_brackets); |
831 | - }else{ |
|
831 | + } else{ |
|
832 | 832 | $name_parts = array( $before_any_brackets ); |
833 | 833 | } |
834 | 834 | // now get the value for the input |
@@ -853,13 +853,13 @@ discard block |
||
853 | 853 | if( isset( $req_data[ $first_part_to_consider ] ) ){ |
854 | 854 | if( empty($html_name_parts ) ){ |
855 | 855 | return $req_data[ $first_part_to_consider ]; |
856 | - }else{ |
|
856 | + } else{ |
|
857 | 857 | return $this->_find_form_data_for_this_section_using_name_parts( |
858 | 858 | $html_name_parts, |
859 | 859 | $req_data[ $first_part_to_consider ] |
860 | 860 | ); |
861 | 861 | } |
862 | - }else{ |
|
862 | + } else{ |
|
863 | 863 | return NULL; |
864 | 864 | } |
865 | 865 | } |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | $checked_value = $this->find_form_data_for_this_section( $req_data ); |
881 | 881 | if( $checked_value !== null ){ |
882 | 882 | return TRUE; |
883 | - }else{ |
|
883 | + } else{ |
|
884 | 884 | return FALSE; |
885 | 885 | } |
886 | 886 | } |
@@ -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 && ! $this->_html_label_text){ |
|
224 | - $this->_html_label_text = ucwords( str_replace("_"," ",$name)); |
|
223 | + if ( ! $this->_html_label && ! $this->_html_label_text) { |
|
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,24 +493,24 @@ 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 | $this->_raw_value = array(); |
504 | - foreach( $raw_input as $key => $value ) { |
|
505 | - $this->_raw_value[ $key ] = $this->_sanitize( $value ); |
|
504 | + foreach ($raw_input as $key => $value) { |
|
505 | + $this->_raw_value[$key] = $this->_sanitize($value); |
|
506 | 506 | } |
507 | 507 | } else { |
508 | - $this->_raw_value = $this->_sanitize( $raw_input ); |
|
508 | + $this->_raw_value = $this->_sanitize($raw_input); |
|
509 | 509 | } |
510 | 510 | //we want ot mostly leave the input alone in case we need to re-display it to the user |
511 | - $this->_normalized_value = $this->_normalization_strategy->normalize( $this->raw_value() ); |
|
512 | - } catch ( EE_Validation_Error $e ) { |
|
513 | - $this->add_validation_error( $e ); |
|
511 | + $this->_normalized_value = $this->_normalization_strategy->normalize($this->raw_value()); |
|
512 | + } catch (EE_Validation_Error $e) { |
|
513 | + $this->add_validation_error($e); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | /** |
520 | 520 | * @return string |
521 | 521 | */ |
522 | - public function html_name(){ |
|
522 | + public function html_name() { |
|
523 | 523 | return $this->_html_name; |
524 | 524 | } |
525 | 525 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | /** |
529 | 529 | * @return string |
530 | 530 | */ |
531 | - public function html_label_id(){ |
|
532 | - return ! empty( $this->_html_label_id ) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
531 | + public function html_label_id() { |
|
532 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id.'-lbl'; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | /** |
538 | 538 | * @return string |
539 | 539 | */ |
540 | - public function html_label_class(){ |
|
540 | + public function html_label_class() { |
|
541 | 541 | return $this->_html_label_class; |
542 | 542 | } |
543 | 543 | |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | /** |
547 | 547 | * @return string |
548 | 548 | */ |
549 | - public function html_label_style(){ |
|
549 | + public function html_label_style() { |
|
550 | 550 | return $this->_html_label_style; |
551 | 551 | } |
552 | 552 | |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | /** |
556 | 556 | * @return string |
557 | 557 | */ |
558 | - public function html_label_text(){ |
|
558 | + public function html_label_text() { |
|
559 | 559 | return $this->_html_label_text; |
560 | 560 | } |
561 | 561 | |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | /** |
565 | 565 | * @return string |
566 | 566 | */ |
567 | - public function html_help_text(){ |
|
567 | + public function html_help_text() { |
|
568 | 568 | return $this->_html_help_text; |
569 | 569 | } |
570 | 570 | |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | /** |
574 | 574 | * @return string |
575 | 575 | */ |
576 | - public function html_help_class(){ |
|
576 | + public function html_help_class() { |
|
577 | 577 | return $this->_html_help_class; |
578 | 578 | } |
579 | 579 | |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | /** |
583 | 583 | * @return string |
584 | 584 | */ |
585 | - public function html_help_style(){ |
|
585 | + public function html_help_style() { |
|
586 | 586 | return $this->_html_style; |
587 | 587 | } |
588 | 588 | /** |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | * in which case, we would have stored the malicious content to our database. |
596 | 596 | * @return string |
597 | 597 | */ |
598 | - public function raw_value(){ |
|
598 | + public function raw_value() { |
|
599 | 599 | return $this->_raw_value; |
600 | 600 | } |
601 | 601 | /** |
@@ -603,15 +603,15 @@ discard block |
||
603 | 603 | * it escapes all html entities |
604 | 604 | * @return string |
605 | 605 | */ |
606 | - public function raw_value_in_form(){ |
|
607 | - return htmlentities($this->raw_value(),ENT_QUOTES, 'UTF-8'); |
|
606 | + public function raw_value_in_form() { |
|
607 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
608 | 608 | } |
609 | 609 | /** |
610 | 610 | * returns the value after it's been sanitized, and then converted into it's proper type |
611 | 611 | * in PHP. Eg, a string, an int, an array, |
612 | 612 | * @return mixed |
613 | 613 | */ |
614 | - public function normalized_value(){ |
|
614 | + public function normalized_value() { |
|
615 | 615 | return $this->_normalized_value; |
616 | 616 | } |
617 | 617 | |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * the best thing to display |
622 | 622 | * @return string |
623 | 623 | */ |
624 | - public function pretty_value(){ |
|
624 | + public function pretty_value() { |
|
625 | 625 | return $this->_normalized_value; |
626 | 626 | } |
627 | 627 | /** |
@@ -640,19 +640,19 @@ discard block |
||
640 | 640 | }</code> |
641 | 641 | * @return array |
642 | 642 | */ |
643 | - public function get_jquery_validation_rules(){ |
|
643 | + public function get_jquery_validation_rules() { |
|
644 | 644 | $jquery_validation_js = array(); |
645 | 645 | $jquery_validation_rules = array(); |
646 | - foreach($this->get_validation_strategies() as $validation_strategy){ |
|
646 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
647 | 647 | $jquery_validation_rules = array_replace_recursive( |
648 | 648 | $jquery_validation_rules, |
649 | 649 | $validation_strategy->get_jquery_validation_rule_array() |
650 | 650 | ); |
651 | 651 | } |
652 | 652 | |
653 | - if(! empty($jquery_validation_rules)){ |
|
654 | - foreach( $this->get_display_strategy()->get_html_input_ids( true ) as $html_id_with_pound_sign ) { |
|
655 | - $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
653 | + if ( ! empty($jquery_validation_rules)) { |
|
654 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
655 | + $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
656 | 656 | } |
657 | 657 | } |
658 | 658 | return $jquery_validation_js; |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | * @param mixed $value |
665 | 665 | * @return void |
666 | 666 | */ |
667 | - public function set_default($value){ |
|
667 | + public function set_default($value) { |
|
668 | 668 | $this->_normalized_value = $value; |
669 | - $this->_raw_value = $this->_normalization_strategy->unnormalize( $value ); |
|
669 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | * @param string $label |
675 | 675 | * @return void |
676 | 676 | */ |
677 | - public function set_html_label_text($label){ |
|
677 | + public function set_html_label_text($label) { |
|
678 | 678 | $this->_html_label_text = $label; |
679 | 679 | } |
680 | 680 | |
@@ -688,13 +688,13 @@ discard block |
||
688 | 688 | * @param boolean $required boolean |
689 | 689 | * @param null $required_text |
690 | 690 | */ |
691 | - public function set_required($required = true, $required_text = NULL ){ |
|
692 | - $required = filter_var( $required, FILTER_VALIDATE_BOOLEAN ); |
|
691 | + public function set_required($required = true, $required_text = NULL) { |
|
692 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
693 | 693 | //whether $required is a string or a boolean, we want to add a required validation strategy |
694 | - if ( $required ) { |
|
695 | - $this->_add_validation_strategy( new EE_Required_Validation_Strategy( $required_text ) ); |
|
694 | + if ($required) { |
|
695 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
696 | 696 | } else { |
697 | - unset( $this->_validation_strategies[ 'EE_Required_Validation_Strategy' ] ); |
|
697 | + unset($this->_validation_strategies['EE_Required_Validation_Strategy']); |
|
698 | 698 | } |
699 | 699 | $this->_required = $required; |
700 | 700 | } |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | * Returns whether or not this field is required |
703 | 703 | * @return boolean |
704 | 704 | */ |
705 | - public function required(){ |
|
705 | + public function required() { |
|
706 | 706 | return $this->_required; |
707 | 707 | } |
708 | 708 | |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | /** |
712 | 712 | * @param string $required_css_class |
713 | 713 | */ |
714 | - public function set_required_css_class( $required_css_class ) { |
|
714 | + public function set_required_css_class($required_css_class) { |
|
715 | 715 | $this->_required_css_class = $required_css_class; |
716 | 716 | } |
717 | 717 | |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * Sets the help text, in case |
731 | 731 | * @param string $text |
732 | 732 | */ |
733 | - public function set_html_help_text($text){ |
|
733 | + public function set_html_help_text($text) { |
|
734 | 734 | $this->_html_help_text = $text; |
735 | 735 | } |
736 | 736 | /** |
@@ -742,8 +742,8 @@ discard block |
||
742 | 742 | public function clean_sensitive_data() { |
743 | 743 | //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
744 | 744 | //if we need more logic than this we'll make a strategy for it |
745 | - if( $this->_sensitive_data_removal_strategy && |
|
746 | - ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal ){ |
|
745 | + if ($this->_sensitive_data_removal_strategy && |
|
746 | + ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal) { |
|
747 | 747 | $this->_raw_value = NULL; |
748 | 748 | } |
749 | 749 | //and clean the normalized value according to the appropriate strategy |
@@ -759,10 +759,10 @@ discard block |
||
759 | 759 | * @param string $button_size |
760 | 760 | * @param string $other_attributes |
761 | 761 | */ |
762 | - public function set_button_css_attributes( $primary = TRUE, $button_size = '', $other_attributes = '' ) { |
|
762 | + public function set_button_css_attributes($primary = TRUE, $button_size = '', $other_attributes = '') { |
|
763 | 763 | $button_css_attributes = 'button'; |
764 | 764 | $button_css_attributes .= $primary === TRUE ? ' button-primary' : ' button-secondary'; |
765 | - switch ( $button_size ) { |
|
765 | + switch ($button_size) { |
|
766 | 766 | case 'xs' : |
767 | 767 | case 'extra-small' : |
768 | 768 | $button_css_attributes .= ' button-xs'; |
@@ -783,8 +783,8 @@ discard block |
||
783 | 783 | default : |
784 | 784 | $button_css_attributes .= ''; |
785 | 785 | } |
786 | - $this->_button_css_attributes .= ! empty( $other_attributes ) |
|
787 | - ? $button_css_attributes . ' ' . $other_attributes |
|
786 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
787 | + ? $button_css_attributes.' '.$other_attributes |
|
788 | 788 | : $button_css_attributes; |
789 | 789 | } |
790 | 790 | |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | * @return string |
795 | 795 | */ |
796 | 796 | public function button_css_attributes() { |
797 | - if ( empty( $this->_button_css_attributes )) { |
|
797 | + if (empty($this->_button_css_attributes)) { |
|
798 | 798 | $this->set_button_css_attributes(); |
799 | 799 | } |
800 | 800 | return $this->_button_css_attributes; |
@@ -816,26 +816,26 @@ discard block |
||
816 | 816 | * @return mixed whatever the raw value of this form section is in the request data |
817 | 817 | * @throws \EE_Error |
818 | 818 | */ |
819 | - public function find_form_data_for_this_section( $req_data ){ |
|
819 | + public function find_form_data_for_this_section($req_data) { |
|
820 | 820 | // break up the html name by "[]" |
821 | - if ( strpos( $this->html_name(), '[' ) !== FALSE ) { |
|
822 | - $before_any_brackets = substr( $this->html_name(), 0, strpos($this->html_name(), '[') ); |
|
821 | + if (strpos($this->html_name(), '[') !== FALSE) { |
|
822 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
823 | 823 | } else { |
824 | 824 | $before_any_brackets = $this->html_name(); |
825 | 825 | } |
826 | 826 | // grab all of the segments |
827 | - preg_match_all('~\[([^]]*)\]~',$this->html_name(), $matches); |
|
828 | - if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
|
829 | - $name_parts = $matches[ 1 ]; |
|
827 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
828 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
829 | + $name_parts = $matches[1]; |
|
830 | 830 | array_unshift($name_parts, $before_any_brackets); |
831 | - }else{ |
|
832 | - $name_parts = array( $before_any_brackets ); |
|
831 | + } else { |
|
832 | + $name_parts = array($before_any_brackets); |
|
833 | 833 | } |
834 | 834 | // now get the value for the input |
835 | 835 | $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
836 | 836 | // check if this thing's name is at the TOP level of the request data |
837 | - if( $value === null && isset( $req_data[ $this->name() ] ) ){ |
|
838 | - $value = $req_data[ $this->name() ]; |
|
837 | + if ($value === null && isset($req_data[$this->name()])) { |
|
838 | + $value = $req_data[$this->name()]; |
|
839 | 839 | } |
840 | 840 | return $value; |
841 | 841 | } |
@@ -848,18 +848,18 @@ discard block |
||
848 | 848 | * @param array $req_data |
849 | 849 | * @return array | NULL |
850 | 850 | */ |
851 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data){ |
|
852 | - $first_part_to_consider = array_shift( $html_name_parts ); |
|
853 | - if( isset( $req_data[ $first_part_to_consider ] ) ){ |
|
854 | - if( empty($html_name_parts ) ){ |
|
855 | - return $req_data[ $first_part_to_consider ]; |
|
856 | - }else{ |
|
851 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) { |
|
852 | + $first_part_to_consider = array_shift($html_name_parts); |
|
853 | + if (isset($req_data[$first_part_to_consider])) { |
|
854 | + if (empty($html_name_parts)) { |
|
855 | + return $req_data[$first_part_to_consider]; |
|
856 | + } else { |
|
857 | 857 | return $this->_find_form_data_for_this_section_using_name_parts( |
858 | 858 | $html_name_parts, |
859 | - $req_data[ $first_part_to_consider ] |
|
859 | + $req_data[$first_part_to_consider] |
|
860 | 860 | ); |
861 | 861 | } |
862 | - }else{ |
|
862 | + } else { |
|
863 | 863 | return NULL; |
864 | 864 | } |
865 | 865 | } |
@@ -873,14 +873,14 @@ discard block |
||
873 | 873 | * @return boolean |
874 | 874 | * @throws \EE_Error |
875 | 875 | */ |
876 | - public function form_data_present_in($req_data = NULL){ |
|
877 | - if( $req_data === NULL ){ |
|
876 | + public function form_data_present_in($req_data = NULL) { |
|
877 | + if ($req_data === NULL) { |
|
878 | 878 | $req_data = $_POST; |
879 | 879 | } |
880 | - $checked_value = $this->find_form_data_for_this_section( $req_data ); |
|
881 | - if( $checked_value !== null ){ |
|
880 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
881 | + if ($checked_value !== null) { |
|
882 | 882 | return TRUE; |
883 | - }else{ |
|
883 | + } else { |
|
884 | 884 | return FALSE; |
885 | 885 | } |
886 | 886 | } |
@@ -891,8 +891,8 @@ discard block |
||
891 | 891 | * @param array $form_other_js_data |
892 | 892 | * @return array |
893 | 893 | */ |
894 | - public function get_other_js_data( $form_other_js_data = array() ) { |
|
895 | - $form_other_js_data = $this->get_other_js_data_from_strategies( $form_other_js_data ); |
|
894 | + public function get_other_js_data($form_other_js_data = array()) { |
|
895 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
896 | 896 | return $form_other_js_data; |
897 | 897 | } |
898 | 898 | |
@@ -905,10 +905,10 @@ discard block |
||
905 | 905 | * @param array $form_other_js_data |
906 | 906 | * @return array |
907 | 907 | */ |
908 | - public function get_other_js_data_from_strategies( $form_other_js_data = array() ) { |
|
909 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data( $form_other_js_data ); |
|
910 | - foreach( $this->get_validation_strategies() as $validation_strategy ) { |
|
911 | - $form_other_js_data = $validation_strategy->get_other_js_data( $form_other_js_data ); |
|
908 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) { |
|
909 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
910 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
911 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
912 | 912 | } |
913 | 913 | return $form_other_js_data; |
914 | 914 | } |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
918 | 918 | * @return void |
919 | 919 | */ |
920 | - public function enqueue_js(){ |
|
920 | + public function enqueue_js() { |
|
921 | 921 | //ask our display strategy and validation strategies if they have js to enqueue |
922 | 922 | $this->enqueue_js_from_strategies(); |
923 | 923 | } |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | */ |
929 | 929 | public function enqueue_js_from_strategies() { |
930 | 930 | $this->get_display_strategy()->enqueue_js(); |
931 | - foreach( $this->get_validation_strategies() as $validation_strategy ) { |
|
931 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
932 | 932 | $validation_strategy->enqueue_js(); |
933 | 933 | } |
934 | 934 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @since $VID:$ |
13 | 13 | * |
14 | 14 | */ |
15 | -class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy{ |
|
15 | +class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Arguments that will be passed into the select2 javascript constructor |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
26 | 26 | * to pass into the select2 js/html input. See https://select2.github.io |
27 | 27 | */ |
28 | - public function __construct( $select2_js_args = array() ) { |
|
28 | + public function __construct($select2_js_args = array()) { |
|
29 | 29 | $this->_select2_js_args = $select2_js_args; |
30 | 30 | parent::__construct(); |
31 | 31 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * the select2 css |
36 | 36 | */ |
37 | 37 | public function enqueue_js() { |
38 | - wp_enqueue_script( 'form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true ); |
|
39 | - wp_enqueue_style( 'select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all' ); |
|
38 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL.'scripts/form_section_select2_init.js', array('select2'), '1.0.0', true); |
|
39 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * Sets the exact js args which will be passed into the select2 js/html input |
52 | 52 | * @param array $js_args |
53 | 53 | */ |
54 | - public function set_js_args( $js_args ) { |
|
54 | + public function set_js_args($js_args) { |
|
55 | 55 | $this->_select2_js_args = $js_args; |
56 | 56 | } |
57 | 57 | |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | * @param array $other_js_data |
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public function get_other_js_data( $other_js_data = array() ) { |
|
64 | - $other_js_data = parent::get_other_js_data( $other_js_data ); |
|
65 | - if( ! isset( $other_js_data[ 'select2s' ] ) ) { |
|
63 | + public function get_other_js_data($other_js_data = array()) { |
|
64 | + $other_js_data = parent::get_other_js_data($other_js_data); |
|
65 | + if ( ! isset($other_js_data['select2s'])) { |
|
66 | 66 | $other_js_data['select2s'] = array(); |
67 | 67 | } |
68 | - $other_js_data[ 'select2s' ][ $this->_input->html_id() ] = $this->get_js_args(); |
|
68 | + $other_js_data['select2s'][$this->_input->html_id()] = $this->get_js_args(); |
|
69 | 69 | return $other_js_data; |
70 | 70 | } |
71 | 71 | } |
72 | 72 | \ No newline at end of file |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * before the hook wp_enqueue_scripts is called (so that the form section can enqueue its needed scripts). |
8 | 8 | * However, you may output the form (usually by calling get_html) anywhere you like. |
9 | 9 | */ |
10 | -class EE_Form_Section_Proper extends EE_Form_Section_Validatable{ |
|
10 | +class EE_Form_Section_Proper extends EE_Form_Section_Validatable { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Subsections |
@@ -69,49 +69,49 @@ discard block |
||
69 | 69 | * } @see EE_Form_Section_Validatable::__construct() |
70 | 70 | * @throws \EE_Error |
71 | 71 | */ |
72 | - public function __construct( $options_array = array() ){ |
|
73 | - $options_array = (array) apply_filters( 'FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, $this ); |
|
72 | + public function __construct($options_array = array()) { |
|
73 | + $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, $this); |
|
74 | 74 | //call parent first, as it may be setting the name |
75 | 75 | parent::__construct($options_array); |
76 | 76 | //if they've included subsections in the constructor, add them now |
77 | - if( isset( $options_array['include'] )){ |
|
77 | + if (isset($options_array['include'])) { |
|
78 | 78 | //we are going to make sure we ONLY have those subsections to include |
79 | 79 | //AND we are going to make sure they're in that specified order |
80 | 80 | $reordered_subsections = array(); |
81 | - foreach($options_array['include'] as $input_name){ |
|
82 | - if(isset($this->_subsections[$input_name])){ |
|
81 | + foreach ($options_array['include'] as $input_name) { |
|
82 | + if (isset($this->_subsections[$input_name])) { |
|
83 | 83 | $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
84 | 84 | } |
85 | 85 | } |
86 | 86 | $this->_subsections = $reordered_subsections; |
87 | 87 | } |
88 | - if(isset($options_array['exclude'])){ |
|
88 | + if (isset($options_array['exclude'])) { |
|
89 | 89 | $exclude = $options_array['exclude']; |
90 | 90 | $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
91 | 91 | } |
92 | - if(isset($options_array['layout_strategy'])){ |
|
92 | + if (isset($options_array['layout_strategy'])) { |
|
93 | 93 | $this->_layout_strategy = $options_array['layout_strategy']; |
94 | 94 | } |
95 | - if( ! $this->_layout_strategy){ |
|
95 | + if ( ! $this->_layout_strategy) { |
|
96 | 96 | $this->_layout_strategy = new EE_Two_Column_Layout(); |
97 | 97 | } |
98 | 98 | $this->_layout_strategy->_construct_finalize($this); |
99 | 99 | |
100 | 100 | //ok so we are definitely going to want the forms JS, |
101 | 101 | //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
102 | - if( did_action( 'wp_enqueue_scripts' ) |
|
103 | - || did_action( 'admin_enqueue_scripts' ) ) { |
|
102 | + if (did_action('wp_enqueue_scripts') |
|
103 | + || did_action('admin_enqueue_scripts')) { |
|
104 | 104 | //ok so they've constructed this object after when they should have. |
105 | 105 | //just enqueue the generic form scripts and initialize the form immediately in the JS |
106 | - \EE_Form_Section_Proper::wp_enqueue_scripts( true ); |
|
106 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
107 | 107 | } else { |
108 | - add_action( 'wp_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
109 | - add_action( 'admin_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
108 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
109 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
110 | 110 | } |
111 | - add_action( 'wp_footer', array( $this, 'ensure_scripts_localized' ), 1 ); |
|
111 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
112 | 112 | |
113 | - if( isset( $options_array[ 'name' ] ) ) { |
|
114 | - $this->_construct_finalize( null, $options_array[ 'name' ] ); |
|
113 | + if (isset($options_array['name'])) { |
|
114 | + $this->_construct_finalize(null, $options_array['name']); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -124,25 +124,25 @@ discard block |
||
124 | 124 | * @param string $name |
125 | 125 | * @throws \EE_Error |
126 | 126 | */ |
127 | - public function _construct_finalize( $parent_form_section, $name ) { |
|
127 | + public function _construct_finalize($parent_form_section, $name) { |
|
128 | 128 | parent::_construct_finalize($parent_form_section, $name); |
129 | 129 | $this->_set_default_name_if_empty(); |
130 | 130 | $this->_set_default_html_id_if_empty(); |
131 | - foreach( $this->_subsections as $subsection_name => $subsection ){ |
|
132 | - if ( $subsection instanceof EE_Form_Section_Base ) { |
|
133 | - $subsection->_construct_finalize( $this, $subsection_name ); |
|
131 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
132 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
133 | + $subsection->_construct_finalize($this, $subsection_name); |
|
134 | 134 | } else { |
135 | 135 | throw new EE_Error( |
136 | 136 | sprintf( |
137 | - __( 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso' ), |
|
137 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso'), |
|
138 | 138 | $subsection_name, |
139 | 139 | get_class($this), |
140 | - $subsection ? get_class($subsection) : __( 'NULL', 'event_espresso' ) |
|
140 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
141 | 141 | ) |
142 | 142 | ); |
143 | 143 | } |
144 | 144 | } |
145 | - do_action( 'AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name ); |
|
145 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * Gets the layout strategy for this form section |
152 | 152 | * @return EE_Form_Section_Layout_Base |
153 | 153 | */ |
154 | - public function get_layout_strategy(){ |
|
154 | + public function get_layout_strategy() { |
|
155 | 155 | return $this->_layout_strategy; |
156 | 156 | } |
157 | 157 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param EE_Form_Input_Base $input |
164 | 164 | * @return string |
165 | 165 | */ |
166 | - public function get_html_for_input($input){ |
|
166 | + public function get_html_for_input($input) { |
|
167 | 167 | return $this->_layout_strategy->layout_input($input); |
168 | 168 | } |
169 | 169 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @param null $form_data |
177 | 177 | * @return boolean |
178 | 178 | */ |
179 | - public function was_submitted($form_data = NULL){ |
|
179 | + public function was_submitted($form_data = NULL) { |
|
180 | 180 | return $this->form_data_present_in($form_data); |
181 | 181 | } |
182 | 182 | |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | * (eg you validated the data then stored it in the DB) you may want to skip this step. |
202 | 202 | * @return void |
203 | 203 | */ |
204 | - public function receive_form_submission($req_data = NULL, $validate = TRUE){ |
|
205 | - $req_data = apply_filters( 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, $validate ); |
|
206 | - if( $req_data === NULL){ |
|
207 | - $req_data = array_merge( $_GET, $_POST ); |
|
204 | + public function receive_form_submission($req_data = NULL, $validate = TRUE) { |
|
205 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, $validate); |
|
206 | + if ($req_data === NULL) { |
|
207 | + $req_data = array_merge($_GET, $_POST); |
|
208 | 208 | } |
209 | - $req_data = apply_filters( 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, $this ); |
|
209 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, $this); |
|
210 | 210 | $this->_normalize($req_data); |
211 | - if( $validate ){ |
|
211 | + if ($validate) { |
|
212 | 212 | $this->_validate(); |
213 | 213 | } |
214 | - do_action( 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate ); |
|
214 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | |
@@ -224,12 +224,12 @@ discard block |
||
224 | 224 | * the value being an array formatted in teh same way |
225 | 225 | * @param array $default_data |
226 | 226 | */ |
227 | - public function populate_defaults($default_data){ |
|
228 | - foreach($this->subsections() as $subsection_name => $subsection){ |
|
229 | - if(isset($default_data[$subsection_name])){ |
|
230 | - if($subsection instanceof EE_Form_Input_Base){ |
|
227 | + public function populate_defaults($default_data) { |
|
228 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
229 | + if (isset($default_data[$subsection_name])) { |
|
230 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
231 | 231 | $subsection->set_default($default_data[$subsection_name]); |
232 | - }elseif($subsection instanceof EE_Form_Section_Proper){ |
|
232 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
233 | 233 | $subsection->populate_defaults($default_data[$subsection_name]); |
234 | 234 | } |
235 | 235 | } |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @return EE_Form_Section_Base |
252 | 252 | * @throws \EE_Error |
253 | 253 | */ |
254 | - public function get_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
255 | - if( $require_construction_to_be_finalized ){ |
|
254 | + public function get_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
255 | + if ($require_construction_to_be_finalized) { |
|
256 | 256 | $this->ensure_construct_finalized_called(); |
257 | 257 | } |
258 | 258 | return isset($this->_subsections[$name]) ? $this->_subsections[$name] : NULL; |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | * Gets all the validatable subsections of this form section |
265 | 265 | * @return EE_Form_Section_Validatable[] |
266 | 266 | */ |
267 | - public function get_validatable_subsections(){ |
|
267 | + public function get_validatable_subsections() { |
|
268 | 268 | $validatable_subsections = array(); |
269 | - foreach($this->subsections() as $name=>$obj){ |
|
270 | - if($obj instanceof EE_Form_Section_Validatable){ |
|
269 | + foreach ($this->subsections() as $name=>$obj) { |
|
270 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
271 | 271 | $validatable_subsections[$name] = $obj; |
272 | 272 | } |
273 | 273 | } |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | * @return EE_Form_Input_Base |
288 | 288 | * @throws EE_Error |
289 | 289 | */ |
290 | - public function get_input($name, $require_construction_to_be_finalized = TRUE ){ |
|
290 | + public function get_input($name, $require_construction_to_be_finalized = TRUE) { |
|
291 | 291 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
292 | - if( ! $subsection instanceof EE_Form_Input_Base){ |
|
293 | - throw new EE_Error(sprintf(__("Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", 'event_espresso'),$name, get_class($this),$subsection ? get_class($subsection) : __("NULL", 'event_espresso'))); |
|
292 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
293 | + throw new EE_Error(sprintf(__("Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", 'event_espresso'), $name, get_class($this), $subsection ? get_class($subsection) : __("NULL", 'event_espresso'))); |
|
294 | 294 | } |
295 | 295 | return $subsection; |
296 | 296 | } |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | * @return EE_Form_Section_Proper |
309 | 309 | * @throws EE_Error |
310 | 310 | */ |
311 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
312 | - $subsection = $this->get_subsection( $name, $require_construction_to_be_finalized ); |
|
313 | - if( ! $subsection instanceof EE_Form_Section_Proper){ |
|
314 | - throw new EE_Error(sprintf(__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),$name, get_class($this))); |
|
311 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
312 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
313 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
314 | + throw new EE_Error(sprintf(__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), $name, get_class($this))); |
|
315 | 315 | } |
316 | 316 | return $subsection; |
317 | 317 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @return mixed depending on the input's type and its normalization strategy |
327 | 327 | * @throws \EE_Error |
328 | 328 | */ |
329 | - public function get_input_value($name){ |
|
329 | + public function get_input_value($name) { |
|
330 | 330 | $input = $this->get_input($name); |
331 | 331 | return $input->normalized_value(); |
332 | 332 | } |
@@ -339,16 +339,16 @@ discard block |
||
339 | 339 | * @return boolean |
340 | 340 | */ |
341 | 341 | public function is_valid() { |
342 | - if( ! $this->has_received_submission()){ |
|
342 | + if ( ! $this->has_received_submission()) { |
|
343 | 343 | throw new EE_Error(sprintf(__("You cannot check if a form is valid before receiving the form submission using receive_form_submission", "event_espresso"))); |
344 | 344 | } |
345 | - if( ! parent::is_valid()){ |
|
345 | + if ( ! parent::is_valid()) { |
|
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | //ok so no errors general to this entire form section. so let's check the subsections |
349 | - foreach( $this->get_validatable_subsections() as $subsection ){ |
|
350 | - if( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '' ){ |
|
351 | - $this->set_submission_error_message( $subsection->get_validation_error_string() ); |
|
349 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
350 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
351 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
352 | 352 | return false; |
353 | 353 | } |
354 | 354 | } |
@@ -361,11 +361,11 @@ discard block |
||
361 | 361 | * gets teh default name of this form section if none is specified |
362 | 362 | * @return string |
363 | 363 | */ |
364 | - protected function _set_default_name_if_empty(){ |
|
365 | - if( ! $this->_name ){ |
|
364 | + protected function _set_default_name_if_empty() { |
|
365 | + if ( ! $this->_name) { |
|
366 | 366 | $classname = get_class($this); |
367 | 367 | $default_name = str_replace("EE_", "", $classname); |
368 | - $this->_name = $default_name; |
|
368 | + $this->_name = $default_name; |
|
369 | 369 | } |
370 | 370 | } |
371 | 371 | |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * and get_html when you are about to display the form. |
381 | 381 | * @throws \EE_Error |
382 | 382 | */ |
383 | - public function get_html_and_js(){ |
|
383 | + public function get_html_and_js() { |
|
384 | 384 | //no doing_it_wrong yet because we ourselves are still doing it wrong... |
385 | 385 | //and theoretically this CAN be used properly, provided its used during "wp_enqueue_scripts" |
386 | 386 | $this->enqueue_js(); |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | * @return string |
396 | 396 | * @throws \EE_Error |
397 | 397 | */ |
398 | - public function get_html(){ |
|
398 | + public function get_html() { |
|
399 | 399 | $this->ensure_construct_finalized_called(); |
400 | 400 | return $this->_layout_strategy->layout_form(); |
401 | 401 | } |
@@ -408,9 +408,9 @@ discard block |
||
408 | 408 | * @return string |
409 | 409 | * @throws \EE_Error |
410 | 410 | */ |
411 | - public function enqueue_js(){ |
|
411 | + public function enqueue_js() { |
|
412 | 412 | $this->_enqueue_and_localize_form_js(); |
413 | - foreach( $this->subsections() as $subsection ) { |
|
413 | + foreach ($this->subsections() as $subsection) { |
|
414 | 414 | $subsection->enqueue_js(); |
415 | 415 | } |
416 | 416 | } |
@@ -427,10 +427,10 @@ discard block |
||
427 | 427 | * @param boolean $init_form_validation_automatically whether or not we want the form validation to be triggered automatically or not |
428 | 428 | * @return void |
429 | 429 | */ |
430 | - public static function wp_enqueue_scripts( $init_form_validation_automatically = true ){ |
|
431 | - add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
432 | - wp_register_script( 'ee_form_section_validation', EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', array( 'jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods' ), EVENT_ESPRESSO_VERSION, TRUE ); |
|
433 | - wp_localize_script( 'ee_form_section_validation', 'ee_form_section_validation_init', array( 'init' => $init_form_validation_automatically ? true : false ) ); |
|
430 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) { |
|
431 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
432 | + wp_register_script('ee_form_section_validation', EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), EVENT_ESPRESSO_VERSION, TRUE); |
|
433 | + wp_localize_script('ee_form_section_validation', 'ee_form_section_validation_init', array('init' => $init_form_validation_automatically ? true : false)); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -442,14 +442,14 @@ discard block |
||
442 | 442 | * |
443 | 443 | * @throws \EE_Error |
444 | 444 | */ |
445 | - public function _enqueue_and_localize_form_js(){ |
|
445 | + public function _enqueue_and_localize_form_js() { |
|
446 | 446 | $this->ensure_construct_finalized_called(); |
447 | 447 | //actually, we don't want to localize just yet. There may be other forms on the page. |
448 | 448 | //so we need to add our form section data to a static variable accessible by all form sections |
449 | 449 | //and localize it just before the footer |
450 | 450 | $this->localize_validation_rules(); |
451 | - add_action( 'wp_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ), 2 ); |
|
452 | - add_action( 'admin_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ) ); |
|
451 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
452 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | |
@@ -461,11 +461,11 @@ discard block |
||
461 | 461 | * @return void |
462 | 462 | * @throws \EE_Error |
463 | 463 | */ |
464 | - public function localize_validation_rules( $return_for_subsection = FALSE ){ |
|
464 | + public function localize_validation_rules($return_for_subsection = FALSE) { |
|
465 | 465 | // we only want to localize vars ONCE for the entire form, so if the form section doesn't have a parent, then it must be the top dog |
466 | - if ( $return_for_subsection || ! $this->parent_section() ) { |
|
467 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
468 | - 'form_section_id'=> $this->html_id( TRUE ), |
|
466 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
467 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
468 | + 'form_section_id'=> $this->html_id(TRUE), |
|
469 | 469 | 'validation_rules'=> $this->get_jquery_validation_rules(), |
470 | 470 | 'other_data' => $this->get_other_js_data(), |
471 | 471 | 'errors'=> $this->subsection_validation_errors_by_html_name() |
@@ -481,9 +481,9 @@ discard block |
||
481 | 481 | * @param array $form_other_js_data |
482 | 482 | * @return array |
483 | 483 | */ |
484 | - public function get_other_js_data( $form_other_js_data = array() ) { |
|
485 | - foreach( $this->subsections() as $subsection ) { |
|
486 | - $form_other_js_data = $subsection->get_other_js_data( $form_other_js_data ); |
|
484 | + public function get_other_js_data($form_other_js_data = array()) { |
|
485 | + foreach ($this->subsections() as $subsection) { |
|
486 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
487 | 487 | } |
488 | 488 | return $form_other_js_data; |
489 | 489 | } |
@@ -494,12 +494,12 @@ discard block |
||
494 | 494 | * Keys are their form names, and values are the inputs themselves |
495 | 495 | * @return EE_Form_Input_Base |
496 | 496 | */ |
497 | - public function inputs_in_subsections(){ |
|
497 | + public function inputs_in_subsections() { |
|
498 | 498 | $inputs = array(); |
499 | - foreach($this->subsections() as $subsection){ |
|
500 | - if( $subsection instanceof EE_Form_Input_Base ){ |
|
501 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
502 | - }elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
499 | + foreach ($this->subsections() as $subsection) { |
|
500 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
501 | + $inputs[$subsection->html_name()] = $subsection; |
|
502 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
503 | 503 | $inputs += $subsection->inputs_in_subsections(); |
504 | 504 | } |
505 | 505 | } |
@@ -512,12 +512,12 @@ discard block |
||
512 | 512 | * and values are a string of all their validation errors |
513 | 513 | * @return string[] |
514 | 514 | */ |
515 | - public function subsection_validation_errors_by_html_name(){ |
|
515 | + public function subsection_validation_errors_by_html_name() { |
|
516 | 516 | $inputs = $this->inputs(); |
517 | 517 | $errors = array(); |
518 | - foreach( $inputs as $form_input ){ |
|
519 | - if ( $form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors() ){ |
|
520 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
518 | + foreach ($inputs as $form_input) { |
|
519 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
520 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | return $errors; |
@@ -529,16 +529,16 @@ discard block |
||
529 | 529 | * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
530 | 530 | * Should be setup by each form during the _enqueues_and_localize_form_js |
531 | 531 | */ |
532 | - public static function localize_script_for_all_forms(){ |
|
532 | + public static function localize_script_for_all_forms() { |
|
533 | 533 | //allow inputs and stuff to hook in their JS and stuff here |
534 | 534 | do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
535 | 535 | EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
536 | - $email_validation_level = isset( EE_Registry::instance()->CFG->registration->email_validation_level ) |
|
536 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
537 | 537 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
538 | 538 | : 'wp_default'; |
539 | 539 | EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
540 | - wp_enqueue_script( 'ee_form_section_validation' ); |
|
541 | - wp_localize_script( 'ee_form_section_validation', 'ee_form_section_vars', EE_Form_Section_Proper::$_js_localization ); |
|
540 | + wp_enqueue_script('ee_form_section_validation'); |
|
541 | + wp_localize_script('ee_form_section_validation', 'ee_form_section_vars', EE_Form_Section_Proper::$_js_localization); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | |
@@ -546,8 +546,8 @@ discard block |
||
546 | 546 | /** |
547 | 547 | * ensure_scripts_localized |
548 | 548 | */ |
549 | - public function ensure_scripts_localized(){ |
|
550 | - if ( ! EE_Form_Section_Proper::$_scripts_localized ) { |
|
549 | + public function ensure_scripts_localized() { |
|
550 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
551 | 551 | $this->_enqueue_and_localize_form_js(); |
552 | 552 | } |
553 | 553 | } |
@@ -559,10 +559,10 @@ discard block |
||
559 | 559 | * is that the key here should be the same as the custom validation rule put in the JS file |
560 | 560 | * @return array keys are custom validation rules, and values are internationalized strings |
561 | 561 | */ |
562 | - private static function _get_localized_error_messages(){ |
|
562 | + private static function _get_localized_error_messages() { |
|
563 | 563 | return array( |
564 | 564 | 'validUrl'=> __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
565 | - 'regex' => __( 'Please check your input', 'event_espresso' ), |
|
565 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
566 | 566 | ); |
567 | 567 | } |
568 | 568 | |
@@ -590,10 +590,10 @@ discard block |
||
590 | 590 | * Gets the JS to put inside the jquery validation rules for subsection of this form section. See parent function for more... |
591 | 591 | * @return array |
592 | 592 | */ |
593 | - public function get_jquery_validation_rules(){ |
|
593 | + public function get_jquery_validation_rules() { |
|
594 | 594 | $jquery_validation_rules = array(); |
595 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
596 | - $jquery_validation_rules = array_merge( $jquery_validation_rules, $subsection->get_jquery_validation_rules() ); |
|
595 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
596 | + $jquery_validation_rules = array_merge($jquery_validation_rules, $subsection->get_jquery_validation_rules()); |
|
597 | 597 | } |
598 | 598 | return $jquery_validation_rules; |
599 | 599 | } |
@@ -608,11 +608,11 @@ discard block |
||
608 | 608 | protected function _normalize($req_data) { |
609 | 609 | $this->_received_submission = TRUE; |
610 | 610 | $this->_validation_errors = array(); |
611 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
612 | - try{ |
|
611 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
612 | + try { |
|
613 | 613 | $subsection->_normalize($req_data); |
614 | - }catch( EE_Validation_Error $e ){ |
|
615 | - $subsection->add_validation_error( $e ); |
|
614 | + } catch (EE_Validation_Error $e) { |
|
615 | + $subsection->add_validation_error($e); |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | } |
@@ -626,9 +626,9 @@ discard block |
||
626 | 626 | * calling parent::_validate() first. |
627 | 627 | */ |
628 | 628 | protected function _validate() { |
629 | - foreach($this->get_validatable_subsections() as $subsection_name => $subsection){ |
|
630 | - if(method_exists($this,'_validate_'.$subsection_name)){ |
|
631 | - call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection)); |
|
629 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
630 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
631 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
632 | 632 | } |
633 | 633 | $subsection->_validate(); |
634 | 634 | } |
@@ -640,13 +640,13 @@ discard block |
||
640 | 640 | * Gets all the validated inputs for the form section |
641 | 641 | * @return array |
642 | 642 | */ |
643 | - public function valid_data(){ |
|
643 | + public function valid_data() { |
|
644 | 644 | $inputs = array(); |
645 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
646 | - if ( $subsection instanceof EE_Form_Section_Proper ) { |
|
647 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
648 | - } else if ( $subsection instanceof EE_Form_Input_Base ){ |
|
649 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
645 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
646 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
647 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
648 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
649 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
650 | 650 | } |
651 | 651 | } |
652 | 652 | return $inputs; |
@@ -658,11 +658,11 @@ discard block |
||
658 | 658 | * Gets all the inputs on this form section |
659 | 659 | * @return EE_Form_Input_Base[] |
660 | 660 | */ |
661 | - public function inputs(){ |
|
661 | + public function inputs() { |
|
662 | 662 | $inputs = array(); |
663 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
664 | - if ( $subsection instanceof EE_Form_Input_Base ){ |
|
665 | - $inputs[ $subsection_name ] = $subsection; |
|
663 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
664 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
665 | + $inputs[$subsection_name] = $subsection; |
|
666 | 666 | } |
667 | 667 | } |
668 | 668 | return $inputs; |
@@ -674,10 +674,10 @@ discard block |
||
674 | 674 | * Gets all the subsections which are a proper form |
675 | 675 | * @return EE_Form_Section_Proper[] |
676 | 676 | */ |
677 | - public function subforms(){ |
|
677 | + public function subforms() { |
|
678 | 678 | $form_sections = array(); |
679 | - foreach($this->subsections() as $name=>$obj){ |
|
680 | - if($obj instanceof EE_Form_Section_Proper){ |
|
679 | + foreach ($this->subsections() as $name=>$obj) { |
|
680 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
681 | 681 | $form_sections[$name] = $obj; |
682 | 682 | } |
683 | 683 | } |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | * if you only want form inputs or proper form sections. |
693 | 693 | * @return EE_Form_Section_Proper[] |
694 | 694 | */ |
695 | - public function subsections(){ |
|
695 | + public function subsections() { |
|
696 | 696 | $this->ensure_construct_finalized_called(); |
697 | 697 | return $this->_subsections; |
698 | 698 | } |
@@ -710,8 +710,8 @@ discard block |
||
710 | 710 | * it can be a multidimensional array where keys are always subsection names and values are either the |
711 | 711 | * input's normalized value, or an array like the top-level array |
712 | 712 | */ |
713 | - public function input_values( $include_subform_inputs = false, $flatten = false ){ |
|
714 | - return $this->_input_values( false, $include_subform_inputs, $flatten ); |
|
713 | + public function input_values($include_subform_inputs = false, $flatten = false) { |
|
714 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -727,8 +727,8 @@ discard block |
||
727 | 727 | * it can be a multidimensional array where keys are always subsection names and values are either the |
728 | 728 | * input's normalized value, or an array like the top-level array |
729 | 729 | */ |
730 | - public function input_pretty_values( $include_subform_inputs = false, $flatten = false ){ |
|
731 | - return $this->_input_values( true, $include_subform_inputs, $flatten ); |
|
730 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) { |
|
731 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
@@ -741,17 +741,17 @@ discard block |
||
741 | 741 | * it can be a multidimensional array where keys are always subsection names and values are either the |
742 | 742 | * input's normalized value, or an array like the top-level array |
743 | 743 | */ |
744 | - public function _input_values( $pretty = false, $include_subform_inputs = false, $flatten = false ) { |
|
744 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) { |
|
745 | 745 | $input_values = array(); |
746 | - foreach( $this->subsections() as $subsection_name => $subsection ) { |
|
747 | - if( $subsection instanceof EE_Form_Input_Base ) { |
|
748 | - $input_values[ $subsection_name ] = $pretty ? $subsection->pretty_value() : $subsection->normalized_value(); |
|
749 | - } else if( $subsection instanceof EE_Form_Section_Proper && $include_subform_inputs ) { |
|
750 | - $subform_input_values = $subsection->_input_values( $pretty, $include_subform_inputs, $flatten ); |
|
751 | - if( $flatten ) { |
|
752 | - $input_values = array_merge( $input_values, $subform_input_values ); |
|
746 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
747 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
748 | + $input_values[$subsection_name] = $pretty ? $subsection->pretty_value() : $subsection->normalized_value(); |
|
749 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
750 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
751 | + if ($flatten) { |
|
752 | + $input_values = array_merge($input_values, $subform_input_values); |
|
753 | 753 | } else { |
754 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
754 | + $input_values[$subsection_name] = $subform_input_values; |
|
755 | 755 | } |
756 | 756 | } |
757 | 757 | } |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | * @return boolean |
768 | 768 | * @throws \EE_Error |
769 | 769 | */ |
770 | - public function has_received_submission(){ |
|
770 | + public function has_received_submission() { |
|
771 | 771 | $this->ensure_construct_finalized_called(); |
772 | 772 | return $this->_received_submission; |
773 | 773 | } |
@@ -780,8 +780,8 @@ discard block |
||
780 | 780 | * @param array $inputs_to_exclude values are the input names |
781 | 781 | * @return void |
782 | 782 | */ |
783 | - public function exclude($inputs_to_exclude = array()){ |
|
784 | - foreach($inputs_to_exclude as $input_to_exclude_name){ |
|
783 | + public function exclude($inputs_to_exclude = array()) { |
|
784 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
785 | 785 | unset($this->_subsections[$input_to_exclude_name]); |
786 | 786 | } |
787 | 787 | } |
@@ -792,8 +792,8 @@ discard block |
||
792 | 792 | * @param array $inputs_to_hide |
793 | 793 | * @throws \EE_Error |
794 | 794 | */ |
795 | - public function hide($inputs_to_hide= array()){ |
|
796 | - foreach($inputs_to_hide as $input_to_hide){ |
|
795 | + public function hide($inputs_to_hide = array()) { |
|
796 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
797 | 797 | $input = $this->get_input($input_to_hide); |
798 | 798 | |
799 | 799 | $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
@@ -818,13 +818,13 @@ discard block |
||
818 | 818 | * @return void |
819 | 819 | * @throws \EE_Error |
820 | 820 | */ |
821 | - public function add_subsections( $new_subsections, $subsection_name_to_target = NULL, $add_before = true ){ |
|
822 | - foreach($new_subsections as $subsection_name => $subsection){ |
|
823 | - if( ! $subsection instanceof EE_Form_Section_Base){ |
|
821 | + public function add_subsections($new_subsections, $subsection_name_to_target = NULL, $add_before = true) { |
|
822 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
823 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
824 | 824 | EE_Error::add_error( |
825 | 825 | sprintf( |
826 | 826 | __("Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", "event_espresso"), |
827 | - get_class( $subsection ), |
|
827 | + get_class($subsection), |
|
828 | 828 | $subsection_name, |
829 | 829 | $this->name() |
830 | 830 | ) |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | } |
834 | 834 | } |
835 | 835 | |
836 | - $this->_subsections = EEH_Array::insert_into_array( $this->_subsections, $new_subsections, $subsection_name_to_target, $add_before ); |
|
836 | + $this->_subsections = EEH_Array::insert_into_array($this->_subsections, $new_subsections, $subsection_name_to_target, $add_before); |
|
837 | 837 | |
838 | 838 | /*$subsections_before = array(); |
839 | 839 | if( $subsection_name_to_target ){ |
@@ -864,8 +864,8 @@ discard block |
||
864 | 864 | $this->_subsections = $new_subsections; |
865 | 865 | } |
866 | 866 | }*/ |
867 | - if( $this->_construction_finalized ){ |
|
868 | - foreach($this->_subsections as $name => $subsection){ |
|
867 | + if ($this->_construction_finalized) { |
|
868 | + foreach ($this->_subsections as $name => $subsection) { |
|
869 | 869 | $subsection->_construct_finalize($this, $name); |
870 | 870 | } |
871 | 871 | } |
@@ -876,8 +876,8 @@ discard block |
||
876 | 876 | /** |
877 | 877 | * Just gets all validatable subsections to clean their sensitive data |
878 | 878 | */ |
879 | - public function clean_sensitive_data(){ |
|
880 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
879 | + public function clean_sensitive_data() { |
|
880 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
881 | 881 | $subsection->clean_sensitive_data(); |
882 | 882 | } |
883 | 883 | } |
@@ -887,8 +887,8 @@ discard block |
||
887 | 887 | /** |
888 | 888 | * @param string $form_submission_error_message |
889 | 889 | */ |
890 | - public function set_submission_error_message( $form_submission_error_message = '' ) { |
|
891 | - $this->_form_submission_error_message .= ! empty( $form_submission_error_message ) ? $form_submission_error_message : __( 'Form submission failed due to errors', 'event_espresso' ); |
|
890 | + public function set_submission_error_message($form_submission_error_message = '') { |
|
891 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) ? $form_submission_error_message : __('Form submission failed due to errors', 'event_espresso'); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | |
@@ -905,8 +905,8 @@ discard block |
||
905 | 905 | /** |
906 | 906 | * @param string $form_submission_success_message |
907 | 907 | */ |
908 | - public function set_submission_success_message( $form_submission_success_message ) { |
|
909 | - $this->_form_submission_success_message .= ! empty( $form_submission_success_message ) ? $form_submission_success_message : __( 'Form submitted successfully', 'event_espresso' ); |
|
908 | + public function set_submission_success_message($form_submission_success_message) { |
|
909 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) ? $form_submission_success_message : __('Form submitted successfully', 'event_espresso'); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | |
@@ -929,10 +929,10 @@ discard block |
||
929 | 929 | * @return string |
930 | 930 | * @throws \EE_Error |
931 | 931 | */ |
932 | - public function html_name_prefix(){ |
|
933 | - if( $this->parent_section() instanceof EE_Form_Section_Proper ){ |
|
934 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
935 | - }else{ |
|
932 | + public function html_name_prefix() { |
|
933 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
934 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
935 | + } else { |
|
936 | 936 | return $this->name(); |
937 | 937 | } |
938 | 938 | } |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | * @return string |
948 | 948 | * @throws \EE_Error |
949 | 949 | */ |
950 | - public function name(){ |
|
950 | + public function name() { |
|
951 | 951 | $this->ensure_construct_finalized_called(); |
952 | 952 | return parent::name(); |
953 | 953 | } |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | * @return EE_Form_Section_Proper |
959 | 959 | * @throws \EE_Error |
960 | 960 | */ |
961 | - public function parent_section(){ |
|
961 | + public function parent_section() { |
|
962 | 962 | $this->ensure_construct_finalized_called(); |
963 | 963 | return parent::parent_section(); |
964 | 964 | } |
@@ -971,9 +971,9 @@ discard block |
||
971 | 971 | * @return void |
972 | 972 | * @throws \EE_Error |
973 | 973 | */ |
974 | - public function ensure_construct_finalized_called(){ |
|
975 | - if( ! $this->_construction_finalized ){ |
|
976 | - $this->_construct_finalize($this->_parent_section, $this->_name ); |
|
974 | + public function ensure_construct_finalized_called() { |
|
975 | + if ( ! $this->_construction_finalized) { |
|
976 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
977 | 977 | } |
978 | 978 | } |
979 | 979 | |
@@ -985,17 +985,17 @@ discard block |
||
985 | 985 | * @param array $req_data |
986 | 986 | * @return boolean |
987 | 987 | */ |
988 | - public function form_data_present_in( $req_data = NULL ) { |
|
989 | - if( $req_data === NULL){ |
|
988 | + public function form_data_present_in($req_data = NULL) { |
|
989 | + if ($req_data === NULL) { |
|
990 | 990 | $req_data = $_POST; |
991 | 991 | } |
992 | - foreach( $this->subsections() as $subsection ) { |
|
993 | - if($subsection instanceof EE_Form_Input_Base ) { |
|
994 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
992 | + foreach ($this->subsections() as $subsection) { |
|
993 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
994 | + if ($subsection->form_data_present_in($req_data)) { |
|
995 | 995 | return TRUE; |
996 | 996 | } |
997 | - }elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
998 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
997 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
998 | + if ($subsection->form_data_present_in($req_data)) { |
|
999 | 999 | return TRUE; |
1000 | 1000 | } |
1001 | 1001 | } |
@@ -1012,14 +1012,14 @@ discard block |
||
1012 | 1012 | */ |
1013 | 1013 | public function get_validation_errors_accumulated() { |
1014 | 1014 | $validation_errors = $this->get_validation_errors(); |
1015 | - foreach($this->get_validatable_subsections() as $subsection ) { |
|
1016 | - if( $subsection instanceof EE_Form_Section_Proper ) { |
|
1015 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1016 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1017 | 1017 | $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
1018 | 1018 | } else { |
1019 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1019 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1020 | 1020 | } |
1021 | - if( $validation_errors_on_this_subsection ){ |
|
1022 | - $validation_errors = array_merge( $validation_errors, $validation_errors_on_this_subsection ); |
|
1021 | + if ($validation_errors_on_this_subsection) { |
|
1022 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1023 | 1023 | } |
1024 | 1024 | } |
1025 | 1025 | return $validation_errors; |
@@ -1041,24 +1041,24 @@ discard block |
||
1041 | 1041 | * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
1042 | 1042 | * @return EE_Form_Section_Base |
1043 | 1043 | */ |
1044 | - public function find_section_from_path( $form_section_path ) { |
|
1044 | + public function find_section_from_path($form_section_path) { |
|
1045 | 1045 | //check if we can find the input from purely going straight up the tree |
1046 | - $input = parent::find_section_from_path( $form_section_path ); |
|
1047 | - if( $input instanceof EE_Form_Section_Base ) { |
|
1046 | + $input = parent::find_section_from_path($form_section_path); |
|
1047 | + if ($input instanceof EE_Form_Section_Base) { |
|
1048 | 1048 | return $input; |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - $next_slash_pos = strpos( $form_section_path, '/' ); |
|
1052 | - if( $next_slash_pos !== false ) { |
|
1053 | - $child_section_name = substr( $form_section_path, 0, $next_slash_pos ); |
|
1054 | - $subpath = substr( $form_section_path, $next_slash_pos + 1 ); |
|
1051 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1052 | + if ($next_slash_pos !== false) { |
|
1053 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1054 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1055 | 1055 | } else { |
1056 | 1056 | $child_section_name = $form_section_path; |
1057 | 1057 | $subpath = ''; |
1058 | 1058 | } |
1059 | - $child_section = $this->get_subsection( $child_section_name ); |
|
1060 | - if ( $child_section instanceof EE_Form_Section_Base ) { |
|
1061 | - return $child_section->find_section_from_path( $subpath ); |
|
1059 | + $child_section = $this->get_subsection($child_section_name); |
|
1060 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1061 | + return $child_section->find_section_from_path($subpath); |
|
1062 | 1062 | } else { |
1063 | 1063 | return null; |
1064 | 1064 | } |
@@ -248,7 +248,7 @@ |
||
248 | 248 | * with construction finalize being called later |
249 | 249 | * (realizing that the subsections' html names |
250 | 250 | * might not be set yet, etc.) |
251 | - * @return EE_Form_Section_Base |
|
251 | + * @return EE_Form_Section_Validatable|null |
|
252 | 252 | * @throws \EE_Error |
253 | 253 | */ |
254 | 254 | public function get_subsection($name, $require_construction_to_be_finalized = TRUE ){ |