@@ -9,36 +9,36 @@ |
||
| 9 | 9 | class EE_Month_Input extends EE_Select_Input |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param bool $leading_zero |
|
| 14 | - * @param array $input_settings |
|
| 15 | - * @param bool $january_is_month_1 whether january should have value of 1; or it should be month 0 |
|
| 16 | - */ |
|
| 17 | - public function __construct($leading_zero = false, $input_settings = array(), $january_is_month_1 = true) |
|
| 18 | - { |
|
| 19 | - $key_begin_range = $january_is_month_1 ? 1 : 0; |
|
| 20 | - $key_range = range($key_begin_range, $key_begin_range + 11); |
|
| 21 | - if ($leading_zero) { |
|
| 22 | - array_walk($key_range, array( $this, '_zero_pad' )); |
|
| 23 | - } |
|
| 24 | - $value_range = range(1, 12); |
|
| 25 | - array_walk($value_range, array( $this, '_zero_pad' )); |
|
| 26 | - parent::__construct( |
|
| 27 | - array_combine( |
|
| 28 | - $key_range, |
|
| 29 | - $value_range |
|
| 30 | - ), |
|
| 31 | - $input_settings |
|
| 32 | - ); |
|
| 33 | - } |
|
| 12 | + /** |
|
| 13 | + * @param bool $leading_zero |
|
| 14 | + * @param array $input_settings |
|
| 15 | + * @param bool $january_is_month_1 whether january should have value of 1; or it should be month 0 |
|
| 16 | + */ |
|
| 17 | + public function __construct($leading_zero = false, $input_settings = array(), $january_is_month_1 = true) |
|
| 18 | + { |
|
| 19 | + $key_begin_range = $january_is_month_1 ? 1 : 0; |
|
| 20 | + $key_range = range($key_begin_range, $key_begin_range + 11); |
|
| 21 | + if ($leading_zero) { |
|
| 22 | + array_walk($key_range, array( $this, '_zero_pad' )); |
|
| 23 | + } |
|
| 24 | + $value_range = range(1, 12); |
|
| 25 | + array_walk($value_range, array( $this, '_zero_pad' )); |
|
| 26 | + parent::__construct( |
|
| 27 | + array_combine( |
|
| 28 | + $key_range, |
|
| 29 | + $value_range |
|
| 30 | + ), |
|
| 31 | + $input_settings |
|
| 32 | + ); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Changes int 1 to 01, etc. Useful with array_walk |
|
| 37 | - * @param int $input |
|
| 38 | - * @param mixed $key |
|
| 39 | - */ |
|
| 40 | - protected function _zero_pad(&$input, $key) |
|
| 41 | - { |
|
| 42 | - $input = str_pad($input, 2, '0', STR_PAD_LEFT); |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * Changes int 1 to 01, etc. Useful with array_walk |
|
| 37 | + * @param int $input |
|
| 38 | + * @param mixed $key |
|
| 39 | + */ |
|
| 40 | + protected function _zero_pad(&$input, $key) |
|
| 41 | + { |
|
| 42 | + $input = str_pad($input, 2, '0', STR_PAD_LEFT); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -19,10 +19,10 @@ |
||
| 19 | 19 | $key_begin_range = $january_is_month_1 ? 1 : 0; |
| 20 | 20 | $key_range = range($key_begin_range, $key_begin_range + 11); |
| 21 | 21 | if ($leading_zero) { |
| 22 | - array_walk($key_range, array( $this, '_zero_pad' )); |
|
| 22 | + array_walk($key_range, array($this, '_zero_pad')); |
|
| 23 | 23 | } |
| 24 | 24 | $value_range = range(1, 12); |
| 25 | - array_walk($value_range, array( $this, '_zero_pad' )); |
|
| 25 | + array_walk($value_range, array($this, '_zero_pad')); |
|
| 26 | 26 | parent::__construct( |
| 27 | 27 | array_combine( |
| 28 | 28 | $key_range, |
@@ -10,15 +10,15 @@ |
||
| 10 | 10 | class EE_Credit_Card_Year_Input extends EE_Year_Input |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $input_settings |
|
| 15 | - * @param bool $four_digit_year |
|
| 16 | - * @param int $years_behind |
|
| 17 | - * @param int $years_ahead |
|
| 18 | - */ |
|
| 19 | - public function __construct($input_settings = array(), $four_digit_year = true, $years_behind = 0, $years_ahead = 15) |
|
| 20 | - { |
|
| 21 | - $this->set_sensitive_data_removal_strategy(new EE_All_Sensitive_Data_Removal()); |
|
| 22 | - parent::__construct($input_settings, $four_digit_year, $years_behind, $years_ahead); |
|
| 23 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $input_settings |
|
| 15 | + * @param bool $four_digit_year |
|
| 16 | + * @param int $years_behind |
|
| 17 | + * @param int $years_ahead |
|
| 18 | + */ |
|
| 19 | + public function __construct($input_settings = array(), $four_digit_year = true, $years_behind = 0, $years_ahead = 15) |
|
| 20 | + { |
|
| 21 | + $this->set_sensitive_data_removal_strategy(new EE_All_Sensitive_Data_Removal()); |
|
| 22 | + parent::__construct($input_settings, $four_digit_year, $years_behind, $years_ahead); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | ); |
| 68 | 68 | // make sure limit and caps are always set |
| 69 | 69 | $query_params = array_merge( |
| 70 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
| 70 | + array('limit' => 10, 'caps' => EEM_Base::caps_read_admin), |
|
| 71 | 71 | $query_params |
| 72 | 72 | ); |
| 73 | 73 | $this->_value_field_name = EEH_Array::is_set( |
@@ -146,12 +146,12 @@ discard block |
||
| 146 | 146 | $values_for_options = (array) $value; |
| 147 | 147 | $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
| 148 | 148 | $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
| 149 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
| 150 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
| 149 | + $this->_extra_select_columns[] = $value_field->get_qualified_column().' AS '.$this->_value_field_name; |
|
| 150 | + $this->_extra_select_columns[] = $display_field->get_qualified_column().' AS '.$this->_display_field_name; |
|
| 151 | 151 | $display_values = $this->_get_model()->get_all_wpdb_results( |
| 152 | 152 | array( |
| 153 | 153 | array( |
| 154 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
| 154 | + $this->_value_field_name => array('IN', $values_for_options) |
|
| 155 | 155 | ) |
| 156 | 156 | ), |
| 157 | 157 | ARRAY_A, |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | if (is_array($select_options)) { |
| 162 | 162 | foreach ($display_values as $db_rows) { |
| 163 | 163 | $db_rows = (array) $db_rows; |
| 164 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
| 164 | + $select_options[$db_rows[$this->_value_field_name]] = apply_filters( |
|
| 165 | 165 | 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
| 166 | - $db_rows[ $this->_display_field_name ], |
|
| 166 | + $db_rows[$this->_display_field_name], |
|
| 167 | 167 | $db_rows |
| 168 | 168 | ); |
| 169 | 169 | } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | protected function _get_model() |
| 181 | 181 | { |
| 182 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 182 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 183 | 183 | throw new EE_Error( |
| 184 | 184 | sprintf( |
| 185 | 185 | __( |
@@ -17,189 +17,189 @@ |
||
| 17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string $_model_name |
|
| 22 | - */ |
|
| 23 | - protected $_model_name; |
|
| 20 | + /** |
|
| 21 | + * @var string $_model_name |
|
| 22 | + */ |
|
| 23 | + protected $_model_name; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var string $_display_field_name |
|
| 27 | - */ |
|
| 28 | - protected $_display_field_name; |
|
| 25 | + /** |
|
| 26 | + * @var string $_display_field_name |
|
| 27 | + */ |
|
| 28 | + protected $_display_field_name; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var string $_value_field_name |
|
| 32 | - */ |
|
| 33 | - protected $_value_field_name; |
|
| 30 | + /** |
|
| 31 | + * @var string $_value_field_name |
|
| 32 | + */ |
|
| 33 | + protected $_value_field_name; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var array $_extra_select_columns |
|
| 37 | - */ |
|
| 38 | - protected $_extra_select_columns = array(); |
|
| 35 | + /** |
|
| 36 | + * @var array $_extra_select_columns |
|
| 37 | + */ |
|
| 38 | + protected $_extra_select_columns = array(); |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param array $input_settings { |
|
| 43 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
| 44 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
| 45 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
| 46 | - * the string "where") |
|
| 47 | - * @type string $value_field_name the name of the model field on this model to |
|
| 48 | - * be used for the HTML select's option's values |
|
| 49 | - * @type string $display_field_name the name of the model field on this model |
|
| 50 | - * to be used for the HTML select's option's display text |
|
| 51 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
| 52 | - * } |
|
| 53 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
| 54 | - * } |
|
| 55 | - * @throws EE_Error |
|
| 56 | - * @throws InvalidArgumentException |
|
| 57 | - * @throws InvalidDataTypeException |
|
| 58 | - * @throws InvalidInterfaceException |
|
| 59 | - */ |
|
| 60 | - public function __construct($input_settings = array()) |
|
| 61 | - { |
|
| 62 | - // needed input settings: |
|
| 63 | - // select2_args |
|
| 64 | - $this->_model_name = EEH_Array::is_set( |
|
| 65 | - $input_settings, |
|
| 66 | - 'model_name', |
|
| 67 | - null |
|
| 68 | - ); |
|
| 69 | - $model = $this->_get_model(); |
|
| 70 | - $query_params = EEH_Array::is_set( |
|
| 71 | - $input_settings, |
|
| 72 | - 'query_params', |
|
| 73 | - array() |
|
| 74 | - ); |
|
| 75 | - // make sure limit and caps are always set |
|
| 76 | - $query_params = array_merge( |
|
| 77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
| 78 | - $query_params |
|
| 79 | - ); |
|
| 80 | - $this->_value_field_name = EEH_Array::is_set( |
|
| 81 | - $input_settings, |
|
| 82 | - 'value_field_name', |
|
| 83 | - $model->primary_key_name() |
|
| 84 | - ); |
|
| 85 | - $this->_display_field_name = EEH_Array::is_set( |
|
| 86 | - $input_settings, |
|
| 87 | - 'display_field_name', |
|
| 88 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
| 89 | - ); |
|
| 90 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
| 91 | - $input_settings, |
|
| 92 | - 'extra_select_columns', |
|
| 93 | - array() |
|
| 94 | - ); |
|
| 95 | - $this->_add_validation_strategy( |
|
| 96 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
| 97 | - '', |
|
| 98 | - $this->_model_name, |
|
| 99 | - $query_params, |
|
| 100 | - $this->_value_field_name |
|
| 101 | - ) |
|
| 102 | - ); |
|
| 103 | - // get resource endpoint |
|
| 104 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
| 105 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
| 106 | - ); |
|
| 107 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
| 108 | - $default_select2_args = array( |
|
| 109 | - 'ajax' => array( |
|
| 110 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
| 111 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
| 112 | - ), |
|
| 113 | - 'dataType' => 'json', |
|
| 114 | - 'delay' => '250', |
|
| 115 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
| 116 | - 'data_interface_args' => array( |
|
| 117 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
| 118 | - $query_params, |
|
| 119 | - $model |
|
| 120 | - ), |
|
| 121 | - 'display_field' => $this->_display_field_name, |
|
| 122 | - 'value_field' => $this->_value_field_name, |
|
| 123 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
| 124 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
| 125 | - ), |
|
| 126 | - ), |
|
| 127 | - 'cache' => true, |
|
| 128 | - 'width' => 'resolve' |
|
| 129 | - ); |
|
| 130 | - $select2_args = array_replace_recursive( |
|
| 131 | - $default_select2_args, |
|
| 132 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
| 133 | - ); |
|
| 134 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
| 135 | - parent::__construct(array(), $input_settings); |
|
| 136 | - } |
|
| 41 | + /** |
|
| 42 | + * @param array $input_settings { |
|
| 43 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
| 44 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
| 45 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
| 46 | + * the string "where") |
|
| 47 | + * @type string $value_field_name the name of the model field on this model to |
|
| 48 | + * be used for the HTML select's option's values |
|
| 49 | + * @type string $display_field_name the name of the model field on this model |
|
| 50 | + * to be used for the HTML select's option's display text |
|
| 51 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
| 52 | + * } |
|
| 53 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
| 54 | + * } |
|
| 55 | + * @throws EE_Error |
|
| 56 | + * @throws InvalidArgumentException |
|
| 57 | + * @throws InvalidDataTypeException |
|
| 58 | + * @throws InvalidInterfaceException |
|
| 59 | + */ |
|
| 60 | + public function __construct($input_settings = array()) |
|
| 61 | + { |
|
| 62 | + // needed input settings: |
|
| 63 | + // select2_args |
|
| 64 | + $this->_model_name = EEH_Array::is_set( |
|
| 65 | + $input_settings, |
|
| 66 | + 'model_name', |
|
| 67 | + null |
|
| 68 | + ); |
|
| 69 | + $model = $this->_get_model(); |
|
| 70 | + $query_params = EEH_Array::is_set( |
|
| 71 | + $input_settings, |
|
| 72 | + 'query_params', |
|
| 73 | + array() |
|
| 74 | + ); |
|
| 75 | + // make sure limit and caps are always set |
|
| 76 | + $query_params = array_merge( |
|
| 77 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
| 78 | + $query_params |
|
| 79 | + ); |
|
| 80 | + $this->_value_field_name = EEH_Array::is_set( |
|
| 81 | + $input_settings, |
|
| 82 | + 'value_field_name', |
|
| 83 | + $model->primary_key_name() |
|
| 84 | + ); |
|
| 85 | + $this->_display_field_name = EEH_Array::is_set( |
|
| 86 | + $input_settings, |
|
| 87 | + 'display_field_name', |
|
| 88 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
| 89 | + ); |
|
| 90 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
| 91 | + $input_settings, |
|
| 92 | + 'extra_select_columns', |
|
| 93 | + array() |
|
| 94 | + ); |
|
| 95 | + $this->_add_validation_strategy( |
|
| 96 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
| 97 | + '', |
|
| 98 | + $this->_model_name, |
|
| 99 | + $query_params, |
|
| 100 | + $this->_value_field_name |
|
| 101 | + ) |
|
| 102 | + ); |
|
| 103 | + // get resource endpoint |
|
| 104 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
| 105 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
| 106 | + ); |
|
| 107 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
| 108 | + $default_select2_args = array( |
|
| 109 | + 'ajax' => array( |
|
| 110 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
| 111 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
| 112 | + ), |
|
| 113 | + 'dataType' => 'json', |
|
| 114 | + 'delay' => '250', |
|
| 115 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
| 116 | + 'data_interface_args' => array( |
|
| 117 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
| 118 | + $query_params, |
|
| 119 | + $model |
|
| 120 | + ), |
|
| 121 | + 'display_field' => $this->_display_field_name, |
|
| 122 | + 'value_field' => $this->_value_field_name, |
|
| 123 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
| 124 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
| 125 | + ), |
|
| 126 | + ), |
|
| 127 | + 'cache' => true, |
|
| 128 | + 'width' => 'resolve' |
|
| 129 | + ); |
|
| 130 | + $select2_args = array_replace_recursive( |
|
| 131 | + $default_select2_args, |
|
| 132 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
| 133 | + ); |
|
| 134 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
| 135 | + parent::__construct(array(), $input_settings); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Before setting the raw value (usually because we're setting the default, |
|
| 142 | - * or we've received a form submission and this might be re-displayed to the user), |
|
| 143 | - * sets the options so that the current selections appear on initial display. |
|
| 144 | - * |
|
| 145 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
| 146 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
| 147 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
| 148 | - * |
|
| 149 | - * @param mixed $value |
|
| 150 | - * @return void |
|
| 151 | - * @throws \EE_Error |
|
| 152 | - */ |
|
| 153 | - public function _set_raw_value($value) |
|
| 154 | - { |
|
| 155 | - $values_for_options = (array) $value; |
|
| 156 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
| 157 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
| 158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
| 159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
| 160 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
| 161 | - array( |
|
| 162 | - array( |
|
| 163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
| 164 | - ) |
|
| 165 | - ), |
|
| 166 | - ARRAY_A, |
|
| 167 | - implode(',', $this->_extra_select_columns) |
|
| 168 | - ); |
|
| 169 | - $select_options = array(); |
|
| 170 | - if (is_array($select_options)) { |
|
| 171 | - foreach ($display_values as $db_rows) { |
|
| 172 | - $db_rows = (array) $db_rows; |
|
| 173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
| 174 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
| 175 | - $db_rows[ $this->_display_field_name ], |
|
| 176 | - $db_rows |
|
| 177 | - ); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - $this->set_select_options($select_options); |
|
| 181 | - parent::_set_raw_value($value); |
|
| 182 | - } |
|
| 140 | + /** |
|
| 141 | + * Before setting the raw value (usually because we're setting the default, |
|
| 142 | + * or we've received a form submission and this might be re-displayed to the user), |
|
| 143 | + * sets the options so that the current selections appear on initial display. |
|
| 144 | + * |
|
| 145 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
| 146 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
| 147 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
| 148 | + * |
|
| 149 | + * @param mixed $value |
|
| 150 | + * @return void |
|
| 151 | + * @throws \EE_Error |
|
| 152 | + */ |
|
| 153 | + public function _set_raw_value($value) |
|
| 154 | + { |
|
| 155 | + $values_for_options = (array) $value; |
|
| 156 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
| 157 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
| 158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
| 159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
| 160 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
| 161 | + array( |
|
| 162 | + array( |
|
| 163 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
| 164 | + ) |
|
| 165 | + ), |
|
| 166 | + ARRAY_A, |
|
| 167 | + implode(',', $this->_extra_select_columns) |
|
| 168 | + ); |
|
| 169 | + $select_options = array(); |
|
| 170 | + if (is_array($select_options)) { |
|
| 171 | + foreach ($display_values as $db_rows) { |
|
| 172 | + $db_rows = (array) $db_rows; |
|
| 173 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
| 174 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
| 175 | + $db_rows[ $this->_display_field_name ], |
|
| 176 | + $db_rows |
|
| 177 | + ); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + $this->set_select_options($select_options); |
|
| 181 | + parent::_set_raw_value($value); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
| 186 | - * @return EEM_Base |
|
| 187 | - * @throws EE_Error |
|
| 188 | - */ |
|
| 189 | - protected function _get_model() |
|
| 190 | - { |
|
| 191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 192 | - throw new EE_Error( |
|
| 193 | - sprintf( |
|
| 194 | - __( |
|
| 195 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
| 196 | - 'event_espresso' |
|
| 197 | - ), |
|
| 198 | - $this->_model_name |
|
| 199 | - ) |
|
| 200 | - ); |
|
| 201 | - } else { |
|
| 202 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
| 203 | - } |
|
| 204 | - } |
|
| 184 | + /** |
|
| 185 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
| 186 | + * @return EEM_Base |
|
| 187 | + * @throws EE_Error |
|
| 188 | + */ |
|
| 189 | + protected function _get_model() |
|
| 190 | + { |
|
| 191 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 192 | + throw new EE_Error( |
|
| 193 | + sprintf( |
|
| 194 | + __( |
|
| 195 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
| 196 | + 'event_espresso' |
|
| 197 | + ), |
|
| 198 | + $this->_model_name |
|
| 199 | + ) |
|
| 200 | + ); |
|
| 201 | + } else { |
|
| 202 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | 205 | } |
@@ -10,16 +10,16 @@ |
||
| 10 | 10 | class EE_Credit_Card_Input extends EE_Form_Input_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $input_settings |
|
| 15 | - */ |
|
| 16 | - public function __construct($input_settings = array()) |
|
| 17 | - { |
|
| 18 | - $input_settings['required'] = isset($input_settings['required']) ? $input_settings['required'] : true; |
|
| 19 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy()); |
|
| 20 | - $this->_set_normalization_strategy(new EE_Credit_Card_Normalization()); |
|
| 21 | - $this->_add_validation_strategy(new EE_Credit_Card_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null)); |
|
| 22 | - $this->set_sensitive_data_removal_strategy(new EE_Credit_Card_Sensitive_Data_Removal()); |
|
| 23 | - parent::__construct($input_settings); |
|
| 24 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $input_settings |
|
| 15 | + */ |
|
| 16 | + public function __construct($input_settings = array()) |
|
| 17 | + { |
|
| 18 | + $input_settings['required'] = isset($input_settings['required']) ? $input_settings['required'] : true; |
|
| 19 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy()); |
|
| 20 | + $this->_set_normalization_strategy(new EE_Credit_Card_Normalization()); |
|
| 21 | + $this->_add_validation_strategy(new EE_Credit_Card_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : null)); |
|
| 22 | + $this->set_sensitive_data_removal_strategy(new EE_Credit_Card_Sensitive_Data_Removal()); |
|
| 23 | + parent::__construct($input_settings); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -12,35 +12,35 @@ |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $input_settings |
|
| 17 | - */ |
|
| 18 | - public function __construct($input_settings = array()) |
|
| 19 | - { |
|
| 20 | - $this->_set_display_strategy( |
|
| 21 | - new EE_Number_Input_Display_Strategy( |
|
| 22 | - isset($input_settings['min_value']) |
|
| 23 | - ? $input_settings['min_value'] |
|
| 24 | - : null, |
|
| 25 | - isset($input_settings['max_value']) |
|
| 26 | - ? $input_settings['max_value'] |
|
| 27 | - : null |
|
| 28 | - ) |
|
| 29 | - ); |
|
| 30 | - $this->_set_normalization_strategy( |
|
| 31 | - new EE_Int_Normalization( |
|
| 32 | - isset($input_settings['validation_error_message']) |
|
| 33 | - ? $input_settings['validation_error_message'] |
|
| 34 | - : null |
|
| 35 | - ) |
|
| 36 | - ); |
|
| 37 | - $this->_add_validation_strategy( |
|
| 38 | - new EE_Int_Validation_Strategy( |
|
| 39 | - isset($input_settings['validation_error_message']) |
|
| 40 | - ? $input_settings['validation_error_message'] |
|
| 41 | - : null |
|
| 42 | - ) |
|
| 43 | - ); |
|
| 44 | - parent::__construct($input_settings); |
|
| 45 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $input_settings |
|
| 17 | + */ |
|
| 18 | + public function __construct($input_settings = array()) |
|
| 19 | + { |
|
| 20 | + $this->_set_display_strategy( |
|
| 21 | + new EE_Number_Input_Display_Strategy( |
|
| 22 | + isset($input_settings['min_value']) |
|
| 23 | + ? $input_settings['min_value'] |
|
| 24 | + : null, |
|
| 25 | + isset($input_settings['max_value']) |
|
| 26 | + ? $input_settings['max_value'] |
|
| 27 | + : null |
|
| 28 | + ) |
|
| 29 | + ); |
|
| 30 | + $this->_set_normalization_strategy( |
|
| 31 | + new EE_Int_Normalization( |
|
| 32 | + isset($input_settings['validation_error_message']) |
|
| 33 | + ? $input_settings['validation_error_message'] |
|
| 34 | + : null |
|
| 35 | + ) |
|
| 36 | + ); |
|
| 37 | + $this->_add_validation_strategy( |
|
| 38 | + new EE_Int_Validation_Strategy( |
|
| 39 | + isset($input_settings['validation_error_message']) |
|
| 40 | + ? $input_settings['validation_error_message'] |
|
| 41 | + : null |
|
| 42 | + ) |
|
| 43 | + ); |
|
| 44 | + parent::__construct($input_settings); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -9,28 +9,28 @@ |
||
| 9 | 9 | class EE_Hidden_Input extends EE_Form_Input_Base |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param array $input_settings |
|
| 14 | - */ |
|
| 15 | - public function __construct($input_settings = array()) |
|
| 16 | - { |
|
| 17 | - // require_once('strategies/display_strategies/EE_Text_Input_Display_Strategy.strategy.php'); |
|
| 18 | - $this->_set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 19 | - if (isset($input_settings['normalization_strategy']) && $input_settings['normalization_strategy'] instanceof EE_Normalization_Strategy_Base) { |
|
| 20 | - $this->_set_normalization_strategy($input_settings['normalization_strategy']); |
|
| 21 | - } else { |
|
| 22 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 23 | - } |
|
| 24 | - parent::__construct($input_settings); |
|
| 25 | - } |
|
| 12 | + /** |
|
| 13 | + * @param array $input_settings |
|
| 14 | + */ |
|
| 15 | + public function __construct($input_settings = array()) |
|
| 16 | + { |
|
| 17 | + // require_once('strategies/display_strategies/EE_Text_Input_Display_Strategy.strategy.php'); |
|
| 18 | + $this->_set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 19 | + if (isset($input_settings['normalization_strategy']) && $input_settings['normalization_strategy'] instanceof EE_Normalization_Strategy_Base) { |
|
| 20 | + $this->_set_normalization_strategy($input_settings['normalization_strategy']); |
|
| 21 | + } else { |
|
| 22 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
| 23 | + } |
|
| 24 | + parent::__construct($input_settings); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return string |
|
| 31 | - */ |
|
| 32 | - public function get_html_for_label() |
|
| 33 | - { |
|
| 34 | - return ''; |
|
| 35 | - } |
|
| 29 | + /** |
|
| 30 | + * @return string |
|
| 31 | + */ |
|
| 32 | + public function get_html_for_label() |
|
| 33 | + { |
|
| 34 | + return ''; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -12,75 +12,75 @@ |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - protected $_naming_method; |
|
| 15 | + protected $_naming_method; |
|
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * |
|
| 21 | - * @param EE_Base_Class[] $answer_options |
|
| 22 | - * @param array $input_settings { |
|
| 23 | - * @var EE_Base_Class[] or array $default |
|
| 24 | - * @var string $naming_method function name on the class which will be used for getting the displayed-name. |
|
| 25 | - * example: if the class were an EE_Event, this could be slug(), description(), name() (default) |
|
| 26 | - * } |
|
| 27 | - */ |
|
| 28 | - public function __construct($answer_options = array(), $input_settings = array()) |
|
| 29 | - { |
|
| 30 | - if (isset($input_settings['naming_method'])) { |
|
| 31 | - $this->set_option_naming_method($input_settings['naming_method']); |
|
| 32 | - } |
|
| 33 | - parent::__construct($answer_options, $input_settings); |
|
| 34 | - } |
|
| 19 | + /** |
|
| 20 | + * |
|
| 21 | + * @param EE_Base_Class[] $answer_options |
|
| 22 | + * @param array $input_settings { |
|
| 23 | + * @var EE_Base_Class[] or array $default |
|
| 24 | + * @var string $naming_method function name on the class which will be used for getting the displayed-name. |
|
| 25 | + * example: if the class were an EE_Event, this could be slug(), description(), name() (default) |
|
| 26 | + * } |
|
| 27 | + */ |
|
| 28 | + public function __construct($answer_options = array(), $input_settings = array()) |
|
| 29 | + { |
|
| 30 | + if (isset($input_settings['naming_method'])) { |
|
| 31 | + $this->set_option_naming_method($input_settings['naming_method']); |
|
| 32 | + } |
|
| 33 | + parent::__construct($answer_options, $input_settings); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Sets the method name which will be called when outputting the options list |
|
| 38 | - * @param string $method |
|
| 39 | - */ |
|
| 40 | - public function set_option_naming_method($method) |
|
| 41 | - { |
|
| 42 | - $this->_naming_method = $method; |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * Sets the method name which will be called when outputting the options list |
|
| 38 | + * @param string $method |
|
| 39 | + */ |
|
| 40 | + public function set_option_naming_method($method) |
|
| 41 | + { |
|
| 42 | + $this->_naming_method = $method; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * You CAN pass an array of model objects instead of simple values for teh options |
|
| 49 | - * @param EE_Base_Class[] $answer_options |
|
| 50 | - * @return null|void |
|
| 51 | - */ |
|
| 52 | - public function set_select_options($answer_options = array()) |
|
| 53 | - { |
|
| 54 | - // convert the model objects to select from into normal select options |
|
| 55 | - $select_options = array(); |
|
| 56 | - foreach ($answer_options as $model_obj) { |
|
| 57 | - if ($this->_naming_method) { |
|
| 58 | - $display_value = call_user_func(array( $model_obj, $this->_naming_method )); |
|
| 59 | - } else { |
|
| 60 | - $display_value = $model_obj->name(); |
|
| 61 | - } |
|
| 62 | - $select_options[ $model_obj->ID() ] = $display_value; |
|
| 63 | - } |
|
| 64 | - parent::set_select_options($select_options); |
|
| 65 | - } |
|
| 47 | + /** |
|
| 48 | + * You CAN pass an array of model objects instead of simple values for teh options |
|
| 49 | + * @param EE_Base_Class[] $answer_options |
|
| 50 | + * @return null|void |
|
| 51 | + */ |
|
| 52 | + public function set_select_options($answer_options = array()) |
|
| 53 | + { |
|
| 54 | + // convert the model objects to select from into normal select options |
|
| 55 | + $select_options = array(); |
|
| 56 | + foreach ($answer_options as $model_obj) { |
|
| 57 | + if ($this->_naming_method) { |
|
| 58 | + $display_value = call_user_func(array( $model_obj, $this->_naming_method )); |
|
| 59 | + } else { |
|
| 60 | + $display_value = $model_obj->name(); |
|
| 61 | + } |
|
| 62 | + $select_options[ $model_obj->ID() ] = $display_value; |
|
| 63 | + } |
|
| 64 | + parent::set_select_options($select_options); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * if they passed in an array of model objects for the default, convert it |
|
| 71 | - * into the format EE_Select_Multiple expects |
|
| 72 | - * @param EE_Base_Class[]|array $values |
|
| 73 | - */ |
|
| 74 | - public function set_default($values) |
|
| 75 | - { |
|
| 76 | - $defaults_as_simple_ids = array(); |
|
| 77 | - foreach ($values as $key => $value) { |
|
| 78 | - if ($value instanceof EE_Base_Class) { |
|
| 79 | - $defaults_as_simple_ids[] = $value->ID(); |
|
| 80 | - } else { |
|
| 81 | - $defaults_as_simple_ids[] = $value; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - parent::set_default($defaults_as_simple_ids); |
|
| 85 | - } |
|
| 69 | + /** |
|
| 70 | + * if they passed in an array of model objects for the default, convert it |
|
| 71 | + * into the format EE_Select_Multiple expects |
|
| 72 | + * @param EE_Base_Class[]|array $values |
|
| 73 | + */ |
|
| 74 | + public function set_default($values) |
|
| 75 | + { |
|
| 76 | + $defaults_as_simple_ids = array(); |
|
| 77 | + foreach ($values as $key => $value) { |
|
| 78 | + if ($value instanceof EE_Base_Class) { |
|
| 79 | + $defaults_as_simple_ids[] = $value->ID(); |
|
| 80 | + } else { |
|
| 81 | + $defaults_as_simple_ids[] = $value; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + parent::set_default($defaults_as_simple_ids); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -55,11 +55,11 @@ |
||
| 55 | 55 | $select_options = array(); |
| 56 | 56 | foreach ($answer_options as $model_obj) { |
| 57 | 57 | if ($this->_naming_method) { |
| 58 | - $display_value = call_user_func(array( $model_obj, $this->_naming_method )); |
|
| 58 | + $display_value = call_user_func(array($model_obj, $this->_naming_method)); |
|
| 59 | 59 | } else { |
| 60 | 60 | $display_value = $model_obj->name(); |
| 61 | 61 | } |
| 62 | - $select_options[ $model_obj->ID() ] = $display_value; |
|
| 62 | + $select_options[$model_obj->ID()] = $display_value; |
|
| 63 | 63 | } |
| 64 | 64 | parent::set_select_options($select_options); |
| 65 | 65 | } |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | private function addIframeAssets(array $localized_vars) |
| 138 | 138 | { |
| 139 | - if (! $this->useCaptcha()) { |
|
| 139 | + if ( ! $this->useCaptcha()) { |
|
| 140 | 140 | return; |
| 141 | 141 | } |
| 142 | 142 | add_filter( |
| 143 | 143 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
| 144 | - function (array $iframe_assets) { |
|
| 145 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 144 | + function(array $iframe_assets) { |
|
| 145 | + $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA] = |
|
| 146 | 146 | EED_Recaptcha_Invisible::assetsUrl() |
| 147 | 147 | . 'espresso_invisible_recaptcha.js?ver=' |
| 148 | 148 | . EVENT_ESPRESSO_VERSION; |
| 149 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 149 | + $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] = |
|
| 150 | 150 | add_query_arg( |
| 151 | 151 | array( |
| 152 | 152 | 'onload' => 'espressoLoadRecaptcha', |
@@ -160,15 +160,15 @@ discard block |
||
| 160 | 160 | ); |
| 161 | 161 | add_filter( |
| 162 | 162 | 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
| 163 | - function (array $iframe_asset_attributes) { |
|
| 164 | - $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 163 | + function(array $iframe_asset_attributes) { |
|
| 164 | + $iframe_asset_attributes[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] |
|
| 165 | 165 | = ' async="async" defer="defer"'; |
| 166 | 166 | return $iframe_asset_attributes; |
| 167 | 167 | } |
| 168 | 168 | ); |
| 169 | 169 | add_action( |
| 170 | 170 | 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
| 171 | - function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 171 | + function(EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 172 | 172 | $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
| 173 | 173 | } |
| 174 | 174 | ); |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | private function registerScripts() |
| 182 | 182 | { |
| 183 | - if (! $this->useCaptcha()) { |
|
| 183 | + if ( ! $this->useCaptcha()) { |
|
| 184 | 184 | return; |
| 185 | 185 | } |
| 186 | 186 | add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
| 187 | 187 | wp_register_script( |
| 188 | 188 | EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
| 189 | - EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 189 | + EED_Recaptcha_Invisible::assetsUrl().'espresso_invisible_recaptcha.js', |
|
| 190 | 190 | array('espresso_core'), |
| 191 | 191 | EVENT_ESPRESSO_VERSION, |
| 192 | 192 | true |
@@ -15,222 +15,222 @@ |
||
| 15 | 15 | class EE_Invisible_Recaptcha_Input extends EE_Form_Input_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
| 19 | - |
|
| 20 | - const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var EE_Registration_Config $config |
|
| 24 | - */ |
|
| 25 | - private $config; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var string $recaptcha_id |
|
| 29 | - */ |
|
| 30 | - private $recaptcha_id; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var string $submit_button_id |
|
| 34 | - */ |
|
| 35 | - private $submit_button_id; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param array $input_settings |
|
| 40 | - * @param EE_Registration_Config $registration_config |
|
| 41 | - * @throws InvalidArgumentException |
|
| 42 | - * @throws InvalidDataTypeException |
|
| 43 | - * @throws InvalidInterfaceException |
|
| 44 | - * @throws DomainException |
|
| 45 | - */ |
|
| 46 | - public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
| 47 | - { |
|
| 48 | - $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
| 49 | - parent::__construct($input_settings); |
|
| 50 | - $registration_config = $registration_config instanceof EE_Registration_Config |
|
| 51 | - ? $registration_config |
|
| 52 | - : EE_Registry::instance()->CFG->registration; |
|
| 53 | - $this->config = $registration_config; |
|
| 54 | - $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
| 55 | - ? $input_settings['recaptcha_id'] |
|
| 56 | - : substr(spl_object_hash($this), 8, 8); |
|
| 57 | - $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
| 58 | - ? $input_settings['submit_button_id'] |
|
| 59 | - : ''; |
|
| 60 | - if ( |
|
| 61 | - isset($input_settings['localized_vars']) |
|
| 62 | - && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN) |
|
| 63 | - ) { |
|
| 64 | - $this->addIframeAssets($input_settings['localized_vars']); |
|
| 65 | - } else { |
|
| 66 | - $this->registerScripts(); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return bool |
|
| 73 | - */ |
|
| 74 | - public function useCaptcha() |
|
| 75 | - { |
|
| 76 | - return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function badge() |
|
| 84 | - { |
|
| 85 | - return $this->config->recaptcha_badge; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function language() |
|
| 93 | - { |
|
| 94 | - return $this->config->recaptcha_language; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public function siteKey() |
|
| 102 | - { |
|
| 103 | - return $this->config->recaptcha_publickey; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function secretKey() |
|
| 111 | - { |
|
| 112 | - return $this->config->recaptcha_privatekey; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @return string |
|
| 118 | - */ |
|
| 119 | - public function recaptchaId() |
|
| 120 | - { |
|
| 121 | - return $this->recaptcha_id; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function submitButtonId() |
|
| 129 | - { |
|
| 130 | - return $this->submit_button_id; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param array $localized_vars |
|
| 136 | - * @throws DomainException |
|
| 137 | - */ |
|
| 138 | - private function addIframeAssets(array $localized_vars) |
|
| 139 | - { |
|
| 140 | - if (! $this->useCaptcha()) { |
|
| 141 | - return; |
|
| 142 | - } |
|
| 143 | - add_filter( |
|
| 144 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 145 | - function (array $iframe_assets) { |
|
| 146 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 147 | - EED_Recaptcha_Invisible::assetsUrl() |
|
| 148 | - . 'espresso_invisible_recaptcha.js?ver=' |
|
| 149 | - . EVENT_ESPRESSO_VERSION; |
|
| 150 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 151 | - add_query_arg( |
|
| 152 | - array( |
|
| 153 | - 'onload' => 'espressoLoadRecaptcha', |
|
| 154 | - 'render' => 'explicit', |
|
| 155 | - 'hl' => $this->language(), |
|
| 156 | - ), |
|
| 157 | - 'https://www.google.com/recaptcha/api.js?' |
|
| 158 | - ); |
|
| 159 | - return $iframe_assets; |
|
| 160 | - } |
|
| 161 | - ); |
|
| 162 | - add_filter( |
|
| 163 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 164 | - function (array $iframe_asset_attributes) { |
|
| 165 | - $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 166 | - = ' async="async" defer="defer"'; |
|
| 167 | - return $iframe_asset_attributes; |
|
| 168 | - } |
|
| 169 | - ); |
|
| 170 | - add_action( |
|
| 171 | - 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 172 | - function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 173 | - $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
|
| 174 | - } |
|
| 175 | - ); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return void |
|
| 181 | - */ |
|
| 182 | - private function registerScripts() |
|
| 183 | - { |
|
| 184 | - if (! $this->useCaptcha()) { |
|
| 185 | - return; |
|
| 186 | - } |
|
| 187 | - add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
| 188 | - wp_register_script( |
|
| 189 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
| 190 | - EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 191 | - array('espresso_core'), |
|
| 192 | - EVENT_ESPRESSO_VERSION, |
|
| 193 | - true |
|
| 194 | - ); |
|
| 195 | - wp_register_script( |
|
| 196 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
| 197 | - add_query_arg( |
|
| 198 | - array( |
|
| 199 | - 'onload' => 'espressoLoadRecaptcha', |
|
| 200 | - 'render' => 'explicit', |
|
| 201 | - 'hl' => $this->language(), |
|
| 202 | - ), |
|
| 203 | - 'https://www.google.com/recaptcha/api.js?' |
|
| 204 | - ), |
|
| 205 | - array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
| 206 | - false, |
|
| 207 | - true |
|
| 208 | - ); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @param string $tag |
|
| 214 | - * @param string $handle |
|
| 215 | - * @return string |
|
| 216 | - */ |
|
| 217 | - public function addScriptAttributes($tag, $handle) |
|
| 218 | - { |
|
| 219 | - if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
| 220 | - $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
| 221 | - } |
|
| 222 | - return $tag; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Gets the HTML for displaying the label for this form input |
|
| 228 | - * according to the form section's layout strategy |
|
| 229 | - * |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 232 | - public function get_html_for_label() |
|
| 233 | - { |
|
| 234 | - return ''; |
|
| 235 | - } |
|
| 18 | + const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
| 19 | + |
|
| 20 | + const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var EE_Registration_Config $config |
|
| 24 | + */ |
|
| 25 | + private $config; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var string $recaptcha_id |
|
| 29 | + */ |
|
| 30 | + private $recaptcha_id; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var string $submit_button_id |
|
| 34 | + */ |
|
| 35 | + private $submit_button_id; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param array $input_settings |
|
| 40 | + * @param EE_Registration_Config $registration_config |
|
| 41 | + * @throws InvalidArgumentException |
|
| 42 | + * @throws InvalidDataTypeException |
|
| 43 | + * @throws InvalidInterfaceException |
|
| 44 | + * @throws DomainException |
|
| 45 | + */ |
|
| 46 | + public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
| 47 | + { |
|
| 48 | + $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
| 49 | + parent::__construct($input_settings); |
|
| 50 | + $registration_config = $registration_config instanceof EE_Registration_Config |
|
| 51 | + ? $registration_config |
|
| 52 | + : EE_Registry::instance()->CFG->registration; |
|
| 53 | + $this->config = $registration_config; |
|
| 54 | + $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
| 55 | + ? $input_settings['recaptcha_id'] |
|
| 56 | + : substr(spl_object_hash($this), 8, 8); |
|
| 57 | + $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
| 58 | + ? $input_settings['submit_button_id'] |
|
| 59 | + : ''; |
|
| 60 | + if ( |
|
| 61 | + isset($input_settings['localized_vars']) |
|
| 62 | + && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN) |
|
| 63 | + ) { |
|
| 64 | + $this->addIframeAssets($input_settings['localized_vars']); |
|
| 65 | + } else { |
|
| 66 | + $this->registerScripts(); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return bool |
|
| 73 | + */ |
|
| 74 | + public function useCaptcha() |
|
| 75 | + { |
|
| 76 | + return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function badge() |
|
| 84 | + { |
|
| 85 | + return $this->config->recaptcha_badge; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function language() |
|
| 93 | + { |
|
| 94 | + return $this->config->recaptcha_language; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public function siteKey() |
|
| 102 | + { |
|
| 103 | + return $this->config->recaptcha_publickey; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function secretKey() |
|
| 111 | + { |
|
| 112 | + return $this->config->recaptcha_privatekey; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 119 | + public function recaptchaId() |
|
| 120 | + { |
|
| 121 | + return $this->recaptcha_id; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function submitButtonId() |
|
| 129 | + { |
|
| 130 | + return $this->submit_button_id; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param array $localized_vars |
|
| 136 | + * @throws DomainException |
|
| 137 | + */ |
|
| 138 | + private function addIframeAssets(array $localized_vars) |
|
| 139 | + { |
|
| 140 | + if (! $this->useCaptcha()) { |
|
| 141 | + return; |
|
| 142 | + } |
|
| 143 | + add_filter( |
|
| 144 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 145 | + function (array $iframe_assets) { |
|
| 146 | + $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 147 | + EED_Recaptcha_Invisible::assetsUrl() |
|
| 148 | + . 'espresso_invisible_recaptcha.js?ver=' |
|
| 149 | + . EVENT_ESPRESSO_VERSION; |
|
| 150 | + $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 151 | + add_query_arg( |
|
| 152 | + array( |
|
| 153 | + 'onload' => 'espressoLoadRecaptcha', |
|
| 154 | + 'render' => 'explicit', |
|
| 155 | + 'hl' => $this->language(), |
|
| 156 | + ), |
|
| 157 | + 'https://www.google.com/recaptcha/api.js?' |
|
| 158 | + ); |
|
| 159 | + return $iframe_assets; |
|
| 160 | + } |
|
| 161 | + ); |
|
| 162 | + add_filter( |
|
| 163 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 164 | + function (array $iframe_asset_attributes) { |
|
| 165 | + $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 166 | + = ' async="async" defer="defer"'; |
|
| 167 | + return $iframe_asset_attributes; |
|
| 168 | + } |
|
| 169 | + ); |
|
| 170 | + add_action( |
|
| 171 | + 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 172 | + function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) { |
|
| 173 | + $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
|
| 174 | + } |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return void |
|
| 181 | + */ |
|
| 182 | + private function registerScripts() |
|
| 183 | + { |
|
| 184 | + if (! $this->useCaptcha()) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 187 | + add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
| 188 | + wp_register_script( |
|
| 189 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
| 190 | + EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 191 | + array('espresso_core'), |
|
| 192 | + EVENT_ESPRESSO_VERSION, |
|
| 193 | + true |
|
| 194 | + ); |
|
| 195 | + wp_register_script( |
|
| 196 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
| 197 | + add_query_arg( |
|
| 198 | + array( |
|
| 199 | + 'onload' => 'espressoLoadRecaptcha', |
|
| 200 | + 'render' => 'explicit', |
|
| 201 | + 'hl' => $this->language(), |
|
| 202 | + ), |
|
| 203 | + 'https://www.google.com/recaptcha/api.js?' |
|
| 204 | + ), |
|
| 205 | + array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
| 206 | + false, |
|
| 207 | + true |
|
| 208 | + ); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @param string $tag |
|
| 214 | + * @param string $handle |
|
| 215 | + * @return string |
|
| 216 | + */ |
|
| 217 | + public function addScriptAttributes($tag, $handle) |
|
| 218 | + { |
|
| 219 | + if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
| 220 | + $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
| 221 | + } |
|
| 222 | + return $tag; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Gets the HTML for displaying the label for this form input |
|
| 228 | + * according to the form section's layout strategy |
|
| 229 | + * |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | + public function get_html_for_label() |
|
| 233 | + { |
|
| 234 | + return ''; |
|
| 235 | + } |
|
| 236 | 236 | } |
@@ -14,17 +14,17 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Phone_Input extends EE_Text_Input |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @param array $options |
|
| 19 | - */ |
|
| 20 | - public function __construct($options = array()) |
|
| 21 | - { |
|
| 22 | - $this->_add_validation_strategy( |
|
| 23 | - new EE_Text_Validation_Strategy( |
|
| 24 | - __('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
| 25 | - '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
| 26 | - ) |
|
| 27 | - ); |
|
| 28 | - parent::__construct($options); |
|
| 29 | - } |
|
| 17 | + /** |
|
| 18 | + * @param array $options |
|
| 19 | + */ |
|
| 20 | + public function __construct($options = array()) |
|
| 21 | + { |
|
| 22 | + $this->_add_validation_strategy( |
|
| 23 | + new EE_Text_Validation_Strategy( |
|
| 24 | + __('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
| 25 | + '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
| 26 | + ) |
|
| 27 | + ); |
|
| 28 | + parent::__construct($options); |
|
| 29 | + } |
|
| 30 | 30 | } |