@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | /** |
132 | 132 | * For verifying that a variable is indeed an array, else throw an EE_Error |
133 | 133 | * @param type $variable_to_test |
134 | - * @param type $variable_name |
|
134 | + * @param string $variable_name |
|
135 | 135 | * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty' |
136 | 136 | * @return void |
137 | 137 | * @throws EE_Error |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * for verifying that a variable is one of the string optiosn supplied |
160 | 160 | * @param mixed $variable_to_test |
161 | 161 | * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages |
162 | - * @param array $string_options an array of acceptable values |
|
162 | + * @param string[] $string_options an array of acceptable values |
|
163 | 163 | * @return void |
164 | 164 | * @throws EE_Error |
165 | 165 | */ |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | * @return void |
51 | 51 | * @throws EE_Error (indirectly) |
52 | 52 | */ |
53 | - static function verify_is_array_of($variable_to_test,$name_of_variable,$class_name,$allow_null='allow_null'){ |
|
54 | - if(!WP_DEBUG)return; |
|
55 | - self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
|
56 | - if('allow_null' == $allow_null && is_null($variable_to_test)){ |
|
53 | + static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null') { |
|
54 | + if ( ! WP_DEBUG)return; |
|
55 | + self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null')); |
|
56 | + if ('allow_null' == $allow_null && is_null($variable_to_test)) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | self::verify_is_array($variable_to_test, $name_of_variable); |
60 | - foreach($variable_to_test as $key=>$array_element){ |
|
60 | + foreach ($variable_to_test as $key=>$array_element) { |
|
61 | 61 | self::verify_instanceof($array_element, $key, $class_name); |
62 | 62 | } |
63 | 63 | } |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | * @return void |
74 | 74 | * @throws EE_Error |
75 | 75 | */ |
76 | - static function verify_isnt_null($variable_to_test,$name_of_variable){ |
|
77 | - if(!WP_DEBUG)return; |
|
78 | - if($variable_to_test==null && $variable_to_test!=0 && $variable_to_test!=FALSE){ |
|
79 | - $error[]=__('Variable named %s is null.','event_espresso'); |
|
80 | - $error[]=__("Consider looking at the stack trace to see why it wasn't set.",'event_espresso'); |
|
81 | - throw new EE_Error(sprintf(implode(",",$error),$name_of_variable,$name_of_variable)); |
|
76 | + static function verify_isnt_null($variable_to_test, $name_of_variable) { |
|
77 | + if ( ! WP_DEBUG)return; |
|
78 | + if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != FALSE) { |
|
79 | + $error[] = __('Variable named %s is null.', 'event_espresso'); |
|
80 | + $error[] = __("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso'); |
|
81 | + throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable)); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * @return void |
91 | 91 | * @throws EE_Error |
92 | 92 | */ |
93 | - static function verify_is_true($expression_to_test,$expression_string_representation){ |
|
94 | - if(!WP_DEBUG)return; |
|
95 | - if(!$expression_to_test){ |
|
96 | - $error[]=__('Template error.','event_espresso'); |
|
97 | - $error[]=__("%s evaluated to false, but it must be true!",'event_espresso'); |
|
98 | - throw new EE_Error(sprintf(implode(",",$error),$expression_string_representation)); |
|
93 | + static function verify_is_true($expression_to_test, $expression_string_representation) { |
|
94 | + if ( ! WP_DEBUG)return; |
|
95 | + if ( ! $expression_to_test) { |
|
96 | + $error[] = __('Template error.', 'event_espresso'); |
|
97 | + $error[] = __("%s evaluated to false, but it must be true!", 'event_espresso'); |
|
98 | + throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation)); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -111,16 +111,16 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | * @throws EE_Error |
113 | 113 | */ |
114 | - static function verify_instanceof($variable_to_test,$name_of_variable,$class_name, $allow_null = 'do_not_allow_null'){ |
|
115 | - if(!WP_DEBUG)return; |
|
116 | - self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
|
117 | - if($allow_null == 'allow_null' && is_null($variable_to_test)){ |
|
114 | + static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null') { |
|
115 | + if ( ! WP_DEBUG)return; |
|
116 | + self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null')); |
|
117 | + if ($allow_null == 'allow_null' && is_null($variable_to_test)) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | - if( $variable_to_test == NULL || ! ( $variable_to_test instanceof $class_name )){ |
|
121 | - $msg[]=__('Variable %s is not of the correct type.','event_espresso'); |
|
122 | - $msg[]=__("It should be of type %s",'event_espresso'); |
|
123 | - throw new EE_Error(sprintf(implode(",",$msg),$name_of_variable,$name_of_variable,$class_name)); |
|
120 | + if ($variable_to_test == NULL || ! ($variable_to_test instanceof $class_name)) { |
|
121 | + $msg[] = __('Variable %s is not of the correct type.', 'event_espresso'); |
|
122 | + $msg[] = __("It should be of type %s", 'event_espresso'); |
|
123 | + throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name)); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -136,16 +136,16 @@ discard block |
||
136 | 136 | * @return void |
137 | 137 | * @throws EE_Error |
138 | 138 | */ |
139 | - static function verify_is_array($variable_to_test,$variable_name,$allow_empty='allow_empty'){ |
|
140 | - if(!WP_DEBUG)return; |
|
141 | - self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty')); |
|
142 | - if(empty($variable_to_test) && 'allow_empty'==$allow_empty){ |
|
139 | + static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty') { |
|
140 | + if ( ! WP_DEBUG)return; |
|
141 | + self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty', 'do_not_allow_empty')); |
|
142 | + if (empty($variable_to_test) && 'allow_empty' == $allow_empty) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | - if(!is_array($variable_to_test)){ |
|
146 | - $error[]=__('Variable %s should be an array, but it is not.'); |
|
147 | - $error[]=__("Its value is, instead '%s'",'event_espresso'); |
|
148 | - throw new EE_Error(sprintf(implode(",",$error),$variable_name,$variable_name,$variable_to_test)); |
|
145 | + if ( ! is_array($variable_to_test)) { |
|
146 | + $error[] = __('Variable %s should be an array, but it is not.'); |
|
147 | + $error[] = __("Its value is, instead '%s'", 'event_espresso'); |
|
148 | + throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test)); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @return void |
164 | 164 | * @throws EE_Error |
165 | 165 | */ |
166 | - static function verify_argument_is_one_of($variable_to_test,$variable_name,$string_options){ |
|
167 | - if(!WP_DEBUG)return; |
|
168 | - if(!in_array($variable_to_test,$string_options)){ |
|
169 | - $msg[0]=__('Malconfigured template.','event_espresso'); |
|
170 | - $msg[1]=__("Variable named '%s' was set to '%s'. It can only be one of '%s'",'event_espresso'); |
|
171 | - throw new EE_Error(sprintf(implode("||",$msg),$variable_name,$variable_to_test, implode("', '",$string_options))); |
|
166 | + static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options) { |
|
167 | + if ( ! WP_DEBUG)return; |
|
168 | + if ( ! in_array($variable_to_test, $string_options)) { |
|
169 | + $msg[0] = __('Malconfigured template.', 'event_espresso'); |
|
170 | + $msg[1] = __("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso'); |
|
171 | + throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options))); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | |
3 | 5 | /** |
4 | 6 | * Event Espresso |
@@ -51,7 +53,9 @@ discard block |
||
51 | 53 | * @throws EE_Error (indirectly) |
52 | 54 | */ |
53 | 55 | static function verify_is_array_of($variable_to_test,$name_of_variable,$class_name,$allow_null='allow_null'){ |
54 | - if(!WP_DEBUG)return; |
|
56 | + if(!WP_DEBUG) { |
|
57 | + return; |
|
58 | + } |
|
55 | 59 | self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
56 | 60 | if('allow_null' == $allow_null && is_null($variable_to_test)){ |
57 | 61 | return; |
@@ -74,7 +78,9 @@ discard block |
||
74 | 78 | * @throws EE_Error |
75 | 79 | */ |
76 | 80 | static function verify_isnt_null($variable_to_test,$name_of_variable){ |
77 | - if(!WP_DEBUG)return; |
|
81 | + if(!WP_DEBUG) { |
|
82 | + return; |
|
83 | + } |
|
78 | 84 | if($variable_to_test==null && $variable_to_test!=0 && $variable_to_test!=FALSE){ |
79 | 85 | $error[]=__('Variable named %s is null.','event_espresso'); |
80 | 86 | $error[]=__("Consider looking at the stack trace to see why it wasn't set.",'event_espresso'); |
@@ -91,7 +97,9 @@ discard block |
||
91 | 97 | * @throws EE_Error |
92 | 98 | */ |
93 | 99 | static function verify_is_true($expression_to_test,$expression_string_representation){ |
94 | - if(!WP_DEBUG)return; |
|
100 | + if(!WP_DEBUG) { |
|
101 | + return; |
|
102 | + } |
|
95 | 103 | if(!$expression_to_test){ |
96 | 104 | $error[]=__('Template error.','event_espresso'); |
97 | 105 | $error[]=__("%s evaluated to false, but it must be true!",'event_espresso'); |
@@ -112,7 +120,9 @@ discard block |
||
112 | 120 | * @throws EE_Error |
113 | 121 | */ |
114 | 122 | static function verify_instanceof($variable_to_test,$name_of_variable,$class_name, $allow_null = 'do_not_allow_null'){ |
115 | - if(!WP_DEBUG)return; |
|
123 | + if(!WP_DEBUG) { |
|
124 | + return; |
|
125 | + } |
|
116 | 126 | self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
117 | 127 | if($allow_null == 'allow_null' && is_null($variable_to_test)){ |
118 | 128 | return; |
@@ -137,7 +147,9 @@ discard block |
||
137 | 147 | * @throws EE_Error |
138 | 148 | */ |
139 | 149 | static function verify_is_array($variable_to_test,$variable_name,$allow_empty='allow_empty'){ |
140 | - if(!WP_DEBUG)return; |
|
150 | + if(!WP_DEBUG) { |
|
151 | + return; |
|
152 | + } |
|
141 | 153 | self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty')); |
142 | 154 | if(empty($variable_to_test) && 'allow_empty'==$allow_empty){ |
143 | 155 | return; |
@@ -164,7 +176,9 @@ discard block |
||
164 | 176 | * @throws EE_Error |
165 | 177 | */ |
166 | 178 | static function verify_argument_is_one_of($variable_to_test,$variable_name,$string_options){ |
167 | - if(!WP_DEBUG)return; |
|
179 | + if(!WP_DEBUG) { |
|
180 | + return; |
|
181 | + } |
|
168 | 182 | if(!in_array($variable_to_test,$string_options)){ |
169 | 183 | $msg[0]=__('Malconfigured template.','event_espresso'); |
170 | 184 | $msg[1]=__("Variable named '%s' was set to '%s'. It can only be one of '%s'",'event_espresso'); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | |
186 | 186 | /** |
187 | 187 | * _prep_name_for_html_id |
188 | - * @param $name |
|
188 | + * @param string $name |
|
189 | 189 | * @return string |
190 | 190 | */ |
191 | 191 | private function _prep_name_for_html_id( $name ) { |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | |
233 | 233 | /** |
234 | - * @param mixed $html_class |
|
234 | + * @param string $html_class |
|
235 | 235 | */ |
236 | 236 | public function set_html_class( $html_class ) { |
237 | 237 | $this->_html_class = $html_class; |
@@ -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 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * @type $name string the name for this form section, if you want to explicitly define it |
96 | 96 | * } |
97 | 97 | */ |
98 | - function __construct( $options_array = array() ) { |
|
98 | + function __construct($options_array = array()) { |
|
99 | 99 | // used by display strategies |
100 | 100 | EE_Registry::instance()->load_helper('HTML'); |
101 | 101 | // assign incoming values to properties |
102 | - foreach( $options_array as $key => $value ) { |
|
103 | - $key = '_' . $key; |
|
104 | - if ( property_exists( $this, $key ) && empty( $this->$key )) { |
|
102 | + foreach ($options_array as $key => $value) { |
|
103 | + $key = '_'.$key; |
|
104 | + if (property_exists($this, $key) && empty($this->$key)) { |
|
105 | 105 | $this->$key = $value; |
106 | 106 | } |
107 | 107 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param $parent_form_section |
114 | 114 | * @param $name |
115 | 115 | */ |
116 | - protected function _construct_finalize( $parent_form_section, $name ){ |
|
116 | + protected function _construct_finalize($parent_form_section, $name) { |
|
117 | 117 | $this->_construction_finalized = TRUE; |
118 | 118 | $this->_parent_section = $parent_form_section; |
119 | 119 | $this->_name = $name; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | /** |
135 | 135 | * @param string $action |
136 | 136 | */ |
137 | - public function set_action( $action ) { |
|
137 | + public function set_action($action) { |
|
138 | 138 | $this->_action = $action; |
139 | 139 | } |
140 | 140 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return string |
145 | 145 | */ |
146 | 146 | public function method() { |
147 | - return ! empty( $this->_method ) ? $this->_method : 'POST'; |
|
147 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | /** |
153 | 153 | * @param string $method |
154 | 154 | */ |
155 | - public function set_method( $method ) { |
|
156 | - switch ( $method ) { |
|
155 | + public function set_method($method) { |
|
156 | + switch ($method) { |
|
157 | 157 | case 'get' : |
158 | 158 | case 'GET' : |
159 | 159 | $this->_method = 'GET'; |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | * Calculation involves using the name and the parent's html id |
172 | 172 | * return void |
173 | 173 | */ |
174 | - protected function _set_default_html_id_if_empty(){ |
|
175 | - if( ! $this->_html_id ){ |
|
176 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper ){ |
|
177 | - $this->_html_id = $this->_parent_section->html_id() . '-' . $this->_prep_name_for_html_id( $this->name() ); |
|
178 | - }else{ |
|
179 | - $this->_html_id = $this->_prep_name_for_html_id( $this->name() ); |
|
174 | + protected function _set_default_html_id_if_empty() { |
|
175 | + if ( ! $this->_html_id) { |
|
176 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
177 | + $this->_html_id = $this->_parent_section->html_id().'-'.$this->_prep_name_for_html_id($this->name()); |
|
178 | + } else { |
|
179 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param $name |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - private function _prep_name_for_html_id( $name ) { |
|
192 | - return sanitize_key( str_replace( array( ' ', ' ', '_' ), '-', $name )); |
|
191 | + private function _prep_name_for_html_id($name) { |
|
192 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | * @param bool $add_pound_sign |
207 | 207 | * @return string |
208 | 208 | */ |
209 | - public function html_id( $add_pound_sign = FALSE ){ |
|
210 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
209 | + public function html_id($add_pound_sign = FALSE) { |
|
210 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | /** |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public function html_class(){ |
|
218 | + public function html_class() { |
|
219 | 219 | return $this->_html_class; |
220 | 220 | } |
221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | /** |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - public function html_style(){ |
|
227 | + public function html_style() { |
|
228 | 228 | return $this->_html_style; |
229 | 229 | } |
230 | 230 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | /** |
234 | 234 | * @param mixed $html_class |
235 | 235 | */ |
236 | - public function set_html_class( $html_class ) { |
|
236 | + public function set_html_class($html_class) { |
|
237 | 237 | $this->_html_class = $html_class; |
238 | 238 | } |
239 | 239 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | /** |
243 | 243 | * @param mixed $html_id |
244 | 244 | */ |
245 | - public function set_html_id( $html_id ) { |
|
245 | + public function set_html_id($html_id) { |
|
246 | 246 | $this->_html_id = $html_id; |
247 | 247 | } |
248 | 248 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | /** |
252 | 252 | * @param mixed $html_style |
253 | 253 | */ |
254 | - public function set_html_style( $html_style ) { |
|
254 | + public function set_html_style($html_style) { |
|
255 | 255 | $this->_html_style = $html_style; |
256 | 256 | } |
257 | 257 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | /** |
261 | 261 | * @param string $other_html_attributes |
262 | 262 | */ |
263 | - public function set_other_html_attributes( $other_html_attributes ) { |
|
263 | + public function set_other_html_attributes($other_html_attributes) { |
|
264 | 264 | $this->_other_html_attributes = $other_html_attributes; |
265 | 265 | } |
266 | 266 | |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | * @throws EE_Error |
281 | 281 | * @return string |
282 | 282 | */ |
283 | - function name(){ |
|
284 | - if( ! $this->_construction_finalized ){ |
|
285 | - throw new EE_Error(sprintf( __( 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso' ), get_class($this) ) ); |
|
283 | + function name() { |
|
284 | + if ( ! $this->_construction_finalized) { |
|
285 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso'), get_class($this))); |
|
286 | 286 | } |
287 | 287 | return $this->_name; |
288 | 288 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * Gets the parent section |
294 | 294 | * @return EE_Form_Section_Proper |
295 | 295 | */ |
296 | - function parent_section(){ |
|
296 | + function parent_section() { |
|
297 | 297 | return $this->_parent_section; |
298 | 298 | } |
299 | 299 | |
@@ -306,18 +306,18 @@ discard block |
||
306 | 306 | * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - public function form_open( $action = '', $method = '', $other_attributes = '' ) { |
|
310 | - if ( ! empty( $action )) { |
|
311 | - $this->set_action( $action ); |
|
309 | + public function form_open($action = '', $method = '', $other_attributes = '') { |
|
310 | + if ( ! empty($action)) { |
|
311 | + $this->set_action($action); |
|
312 | 312 | } |
313 | - if ( ! empty( $method )) { |
|
314 | - $this->set_method( $method ); |
|
313 | + if ( ! empty($method)) { |
|
314 | + $this->set_method($method); |
|
315 | 315 | } |
316 | - $html = EEH_HTML::nl( 1, 'form' ) . '<form'; |
|
317 | - $html .= $this->html_id() !== '' ? ' id="' . $this->html_id() . '"' : ''; |
|
318 | - $html .= ' action="' . $this->action() . '"'; |
|
319 | - $html .= ' method="' . $this->method() . '"'; |
|
320 | - $html .= $other_attributes . '>'; |
|
316 | + $html = EEH_HTML::nl(1, 'form').'<form'; |
|
317 | + $html .= $this->html_id() !== '' ? ' id="'.$this->html_id().'"' : ''; |
|
318 | + $html .= ' action="'.$this->action().'"'; |
|
319 | + $html .= ' method="'.$this->method().'"'; |
|
320 | + $html .= $other_attributes.'>'; |
|
321 | 321 | return $html; |
322 | 322 | } |
323 | 323 | |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * @return string |
329 | 329 | */ |
330 | 330 | public function form_close() { |
331 | - return EEH_HTML::nl( -1, 'form' ) . '</form>' . EEH_HTML::nl() . '<!-- end of ee-' . $this->html_id() . '-form -->' . EEH_HTML::nl(); |
|
331 | + return EEH_HTML::nl( -1, 'form' ).'</form>'.EEH_HTML::nl().'<!-- end of ee-'.$this->html_id().'-form -->'.EEH_HTML::nl(); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 |
@@ -1,7 +1,8 @@ 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 | 7 | /** |
7 | 8 | * Event Espresso |
@@ -69,7 +70,7 @@ discard block |
||
69 | 70 | $default_address .= $state ? $state->name() . '<br />' : ''; |
70 | 71 | $default_address .= $country ? $country->name(). '<br />' : ''; |
71 | 72 | $default_address .= $organization->zip != '' ? $organization->get_pretty( 'zip' ) : ''; |
72 | - }else{ |
|
73 | + } else{ |
|
73 | 74 | $default_address = 'unknown'; |
74 | 75 | $organization_name = 'unknown'; |
75 | 76 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * leave this as TRUE so that the inputs will be properly configured. However, |
226 | 226 | * some client code may be ok with construction finalize being called later |
227 | 227 | * (realizing that the subsections' html names might not be set yet, etc.) |
228 | - * @return EE_Form_Section_Base |
|
228 | + * @return EE_Form_Section_Validatable|null |
|
229 | 229 | */ |
230 | 230 | public function get_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
231 | 231 | if( $require_construction_to_be_finalized ){ |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | /** |
713 | 713 | * Equivalent to passing 'exclude' in the constructor's options array. |
714 | 714 | * Removes the listed inputs from the form |
715 | - * @param array $inputs_to_exclude values are the input names |
|
715 | + * @param string[] $inputs_to_exclude values are the input names |
|
716 | 716 | * @return void |
717 | 717 | */ |
718 | 718 | public function exclude($inputs_to_exclude = array()){ |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | if(isset($default_data[$subsection_name])){ |
210 | 210 | if($subsection instanceof EE_Form_Input_Base){ |
211 | 211 | $subsection->set_default($default_data[$subsection_name]); |
212 | - }elseif($subsection instanceof EE_Form_Section_Proper){ |
|
212 | + } elseif($subsection instanceof EE_Form_Section_Proper){ |
|
213 | 213 | $subsection->populate_defaults($default_data[$subsection_name]); |
214 | 214 | } |
215 | 215 | } |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | foreach($this->subsections() as $subsection){ |
441 | 441 | if( $subsection instanceof EE_Form_Input_Base ){ |
442 | 442 | $inputs[ $subsection->html_name() ] = $subsection; |
443 | - }elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
443 | + } elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
444 | 444 | $inputs += $subsection->inputs_in_subsections(); |
445 | 445 | } |
446 | 446 | } |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | foreach($this->get_validatable_subsections() as $subsection){ |
549 | 549 | try{ |
550 | 550 | $subsection->_normalize($req_data); |
551 | - }catch( EE_Validation_Error $e ){ |
|
551 | + } catch( EE_Validation_Error $e ){ |
|
552 | 552 | $subsection->add_validation_error( $e ); |
553 | 553 | } |
554 | 554 | } |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | } |
768 | 768 | $subsections_after = array_diff_key($this->_subsections, $subsections_before); |
769 | 769 | $this->_subsections = array_merge($subsections_before,$subsections,$subsections_after); |
770 | - }else{ |
|
770 | + } else{ |
|
771 | 771 | //don't use array_merge because keys might be numeric and we want to preserve their keys |
772 | 772 | foreach( $subsections as $key => $subsection ){ |
773 | 773 | $this->_subsections[ $key ] = $subsection; |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | public function html_name_prefix(){ |
841 | 841 | if( $this->parent_section() instanceof EE_Form_Section_Proper ){ |
842 | 842 | return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
843 | - }else{ |
|
843 | + } else{ |
|
844 | 844 | return $this->name(); |
845 | 845 | } |
846 | 846 | } |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | if( $subsection->form_data_present_in( $req_data ) ) { |
893 | 893 | return TRUE; |
894 | 894 | } |
895 | - }elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
895 | + } elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
896 | 896 | if( $subsection->form_data_present_in( $req_data ) ) { |
897 | 897 | return TRUE; |
898 | 898 | } |
@@ -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_and_js) 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 |
@@ -68,37 +68,37 @@ discard block |
||
68 | 68 | * } @see EE_Form_Section_Validatable::__construct() |
69 | 69 | * |
70 | 70 | */ |
71 | - public function __construct( $options_array = array() ){ |
|
71 | + public function __construct($options_array = array()) { |
|
72 | 72 | EE_Registry::instance()->load_helper('Formatter'); |
73 | 73 | //call parent first, as it may be setting the name |
74 | 74 | parent::__construct($options_array); |
75 | 75 | //if they've included subsections in the constructor, add them now |
76 | - if( isset( $options_array['include'] )){ |
|
76 | + if (isset($options_array['include'])) { |
|
77 | 77 | //we are going to make sure we ONLY have those subsections to include |
78 | 78 | //AND we are going to make sure they're in that specified order |
79 | 79 | $reordered_subsections = array(); |
80 | - foreach($options_array['include'] as $input_name){ |
|
81 | - if(isset($this->_subsections[$input_name])){ |
|
80 | + foreach ($options_array['include'] as $input_name) { |
|
81 | + if (isset($this->_subsections[$input_name])) { |
|
82 | 82 | $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | $this->_subsections = $reordered_subsections; |
86 | 86 | } |
87 | - if(isset($options_array['exclude'])){ |
|
87 | + if (isset($options_array['exclude'])) { |
|
88 | 88 | $exclude = $options_array['exclude']; |
89 | 89 | $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
90 | 90 | } |
91 | - if(isset($options_array['layout_strategy'])){ |
|
91 | + if (isset($options_array['layout_strategy'])) { |
|
92 | 92 | $this->_layout_strategy = $options_array['layout_strategy']; |
93 | 93 | } |
94 | - if( ! $this->_layout_strategy){ |
|
94 | + if ( ! $this->_layout_strategy) { |
|
95 | 95 | $this->_layout_strategy = new EE_Two_Column_Layout(); |
96 | 96 | } |
97 | 97 | $this->_layout_strategy->_construct_finalize($this); |
98 | 98 | |
99 | - add_action( 'wp_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
100 | - add_action( 'admin_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
101 | - add_action( 'wp_footer', array( $this, 'ensure_scripts_localized' ), 1 ); |
|
99 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
100 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
101 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
102 | 102 | |
103 | 103 | |
104 | 104 | } |
@@ -112,20 +112,20 @@ discard block |
||
112 | 112 | * @param string $name |
113 | 113 | * @throws \EE_Error |
114 | 114 | */ |
115 | - public function _construct_finalize( $parent_form_section, $name ) { |
|
115 | + public function _construct_finalize($parent_form_section, $name) { |
|
116 | 116 | parent::_construct_finalize($parent_form_section, $name); |
117 | 117 | $this->_set_default_name_if_empty(); |
118 | 118 | $this->_set_default_html_id_if_empty(); |
119 | - foreach( $this->_subsections as $subsection_name => $subsection ){ |
|
120 | - if ( $subsection instanceof EE_Form_Section_Base ) { |
|
121 | - $subsection->_construct_finalize( $this, $subsection_name ); |
|
119 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
120 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
121 | + $subsection->_construct_finalize($this, $subsection_name); |
|
122 | 122 | } else { |
123 | 123 | throw new EE_Error( |
124 | 124 | sprintf( |
125 | - __( 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso' ), |
|
125 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso'), |
|
126 | 126 | $subsection_name, |
127 | 127 | get_class($this), |
128 | - $subsection ? get_class($subsection) : __( 'NULL', 'event_espresso' ) |
|
128 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
129 | 129 | ) |
130 | 130 | ); |
131 | 131 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * Gets the layout strategy for this form section |
139 | 139 | * @return EE_Form_Section_Layout_Base |
140 | 140 | */ |
141 | - public function get_layout_strategy(){ |
|
141 | + public function get_layout_strategy() { |
|
142 | 142 | return $this->_layout_strategy; |
143 | 143 | } |
144 | 144 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @param EE_Form_Input_Base $input |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function get_html_for_input($input){ |
|
153 | + public function get_html_for_input($input) { |
|
154 | 154 | return $this->_layout_strategy->layout_input($input); |
155 | 155 | } |
156 | 156 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param null $form_data |
164 | 164 | * @return boolean |
165 | 165 | */ |
166 | - public function was_submitted($form_data = NULL){ |
|
166 | + public function was_submitted($form_data = NULL) { |
|
167 | 167 | return $this->form_data_present_in($form_data); |
168 | 168 | } |
169 | 169 | |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | * to skip this step. |
185 | 185 | * @return void |
186 | 186 | */ |
187 | - public function receive_form_submission($req_data = NULL, $validate = TRUE){ |
|
188 | - if( $req_data === NULL){ |
|
187 | + public function receive_form_submission($req_data = NULL, $validate = TRUE) { |
|
188 | + if ($req_data === NULL) { |
|
189 | 189 | $req_data = $_REQUEST; |
190 | 190 | } |
191 | 191 | $this->_normalize($req_data); |
192 | - if( $validate ){ |
|
192 | + if ($validate) { |
|
193 | 193 | $this->_validate(); |
194 | 194 | } |
195 | 195 | } |
@@ -204,12 +204,12 @@ discard block |
||
204 | 204 | * the value being an array formatted in teh same way |
205 | 205 | * @param array $default_data |
206 | 206 | */ |
207 | - public function populate_defaults($default_data){ |
|
208 | - foreach($this->subsections() as $subsection_name => $subsection){ |
|
209 | - if(isset($default_data[$subsection_name])){ |
|
210 | - if($subsection instanceof EE_Form_Input_Base){ |
|
207 | + public function populate_defaults($default_data) { |
|
208 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
209 | + if (isset($default_data[$subsection_name])) { |
|
210 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
211 | 211 | $subsection->set_default($default_data[$subsection_name]); |
212 | - }elseif($subsection instanceof EE_Form_Section_Proper){ |
|
212 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
213 | 213 | $subsection->populate_defaults($default_data[$subsection_name]); |
214 | 214 | } |
215 | 215 | } |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | * (realizing that the subsections' html names might not be set yet, etc.) |
228 | 228 | * @return EE_Form_Section_Base |
229 | 229 | */ |
230 | - public function get_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
231 | - if( $require_construction_to_be_finalized ){ |
|
230 | + public function get_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
231 | + if ($require_construction_to_be_finalized) { |
|
232 | 232 | $this->ensure_construct_finalized_called(); |
233 | 233 | } |
234 | 234 | return isset($this->_subsections[$name]) ? $this->_subsections[$name] : NULL; |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | * Gets all the validatable subsections of this form section |
241 | 241 | * @return EE_Form_Section_Validatable[] |
242 | 242 | */ |
243 | - public function get_validatable_subsections(){ |
|
243 | + public function get_validatable_subsections() { |
|
244 | 244 | $validatable_subsections = array(); |
245 | - foreach($this->subsections() as $name=>$obj){ |
|
246 | - if($obj instanceof EE_Form_Section_Validatable){ |
|
245 | + foreach ($this->subsections() as $name=>$obj) { |
|
246 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
247 | 247 | $validatable_subsections[$name] = $obj; |
248 | 248 | } |
249 | 249 | } |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | * @return EE_Form_Input_Base |
264 | 264 | * @throws EE_Error |
265 | 265 | */ |
266 | - public function get_input($name, $require_construction_to_be_finalized = TRUE ){ |
|
266 | + public function get_input($name, $require_construction_to_be_finalized = TRUE) { |
|
267 | 267 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
268 | - if( ! $subsection instanceof EE_Form_Input_Base){ |
|
269 | - 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'))); |
|
268 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
269 | + 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'))); |
|
270 | 270 | } |
271 | 271 | return $subsection; |
272 | 272 | } |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | * @return EE_Form_Section_Proper |
285 | 285 | * @throws EE_Error |
286 | 286 | */ |
287 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
288 | - $subsection = $this->get_subsection( $name, $require_construction_to_be_finalized ); |
|
289 | - if( ! $subsection instanceof EE_Form_Section_Proper){ |
|
290 | - throw new EE_Error(sprintf(__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),$name, get_class($this))); |
|
287 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
288 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
289 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
290 | + throw new EE_Error(sprintf(__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), $name, get_class($this))); |
|
291 | 291 | } |
292 | 292 | return $subsection; |
293 | 293 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param string $name |
301 | 301 | * @return mixed depending on the input's type and its normalization strategy |
302 | 302 | */ |
303 | - public function get_input_value($name){ |
|
303 | + public function get_input_value($name) { |
|
304 | 304 | $input = $this->get_input($name); |
305 | 305 | return $input->normalized_value(); |
306 | 306 | } |
@@ -313,16 +313,16 @@ discard block |
||
313 | 313 | * @return boolean |
314 | 314 | */ |
315 | 315 | public function is_valid() { |
316 | - if( ! $this->has_received_submission()){ |
|
316 | + if ( ! $this->has_received_submission()) { |
|
317 | 317 | throw new EE_Error(sprintf(__("You cannot check if a form is valid before receiving the form submission using receive_form_submission", "event_espresso"))); |
318 | 318 | } |
319 | - if( ! parent::is_valid()){ |
|
319 | + if ( ! parent::is_valid()) { |
|
320 | 320 | return false; |
321 | 321 | } |
322 | 322 | //ok so no errors general to this entire form section. so let's check the subsections |
323 | - foreach( $this->get_validatable_subsections() as $subsection ){ |
|
324 | - if( ! $subsection->is_valid() || $subsection->get_validation_error_string() != '' ){ |
|
325 | - $this->set_submission_error_message( $subsection->get_validation_error_string() ); |
|
323 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
324 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() != '') { |
|
325 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
326 | 326 | return false; |
327 | 327 | } |
328 | 328 | } |
@@ -335,11 +335,11 @@ discard block |
||
335 | 335 | * gets teh default name of this form section if none is specified |
336 | 336 | * @return string |
337 | 337 | */ |
338 | - protected function _set_default_name_if_empty(){ |
|
339 | - if( ! $this->_name ){ |
|
338 | + protected function _set_default_name_if_empty() { |
|
339 | + if ( ! $this->_name) { |
|
340 | 340 | $classname = get_class($this); |
341 | 341 | $default_name = str_replace("EE_", "", $classname); |
342 | - $this->_name = $default_name; |
|
342 | + $this->_name = $default_name; |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | * Also returns the HTML for the form, except for the form opening and closing tags |
351 | 351 | * (as the form section doesn't know where you necessarily want to send the information to), and except for a submit button. |
352 | 352 | */ |
353 | - public function get_html_and_js(){ |
|
353 | + public function get_html_and_js() { |
|
354 | 354 | $this->enqueue_js(); |
355 | 355 | return $this->get_html(); |
356 | 356 | } |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
362 | 362 | * @return string |
363 | 363 | */ |
364 | - public function get_html(){ |
|
364 | + public function get_html() { |
|
365 | 365 | $this->ensure_construct_finalized_called(); |
366 | 366 | return $this->_layout_strategy->layout_form(); |
367 | 367 | } |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | * enqueues JS for the form |
373 | 373 | * @return string |
374 | 374 | */ |
375 | - public function enqueue_js(){ |
|
375 | + public function enqueue_js() { |
|
376 | 376 | $this->_enqueue_and_localize_form_js(); |
377 | 377 | } |
378 | 378 | |
@@ -387,9 +387,9 @@ discard block |
||
387 | 387 | * could change until it's actually outputted) |
388 | 388 | * @return void |
389 | 389 | */ |
390 | - public static function wp_enqueue_scripts(){ |
|
391 | - add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
392 | - wp_register_script( 'ee_form_section_validation', EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', array( 'jquery-validate', 'jquery-ui-datepicker' ), EVENT_ESPRESSO_VERSION, TRUE ); |
|
390 | + public static function wp_enqueue_scripts() { |
|
391 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
392 | + wp_register_script('ee_form_section_validation', EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', array('jquery-validate', 'jquery-ui-datepicker'), EVENT_ESPRESSO_VERSION, TRUE); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
400 | 400 | * but before the wordpress hook wp_loaded |
401 | 401 | */ |
402 | - public function _enqueue_and_localize_form_js(){ |
|
402 | + public function _enqueue_and_localize_form_js() { |
|
403 | 403 | $this->ensure_construct_finalized_called(); |
404 | 404 | //actually, we don't want to localize just yet. There may be other forms on the page. |
405 | 405 | //so we need to add our form section data to a static variable accessible by all form sections |
406 | 406 | //and localize it just before the footer |
407 | 407 | $this->localize_validation_rules(); |
408 | - add_action( 'wp_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ), 2 ); |
|
409 | - add_action( 'admin_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ) ); |
|
408 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
409 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | |
@@ -415,11 +415,11 @@ discard block |
||
415 | 415 | * add our form section data to a static variable accessible by all form sections |
416 | 416 | * @return void |
417 | 417 | */ |
418 | - public function localize_validation_rules(){ |
|
418 | + public function localize_validation_rules() { |
|
419 | 419 | // 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 |
420 | - if ( ! $this->parent_section() ) { |
|
421 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
422 | - 'form_section_id'=> $this->html_id( TRUE ), |
|
420 | + if ( ! $this->parent_section()) { |
|
421 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
422 | + 'form_section_id'=> $this->html_id(TRUE), |
|
423 | 423 | 'validation_rules'=> $this->get_jquery_validation_rules(), |
424 | 424 | 'errors'=> $this->subsection_validation_errors_by_html_name() |
425 | 425 | ); |
@@ -434,12 +434,12 @@ discard block |
||
434 | 434 | * Keys are their form names, and values are the inputs themselves |
435 | 435 | * @return EE_Form_Input_Base |
436 | 436 | */ |
437 | - public function inputs_in_subsections(){ |
|
437 | + public function inputs_in_subsections() { |
|
438 | 438 | $inputs = array(); |
439 | - foreach($this->subsections() as $subsection){ |
|
440 | - if( $subsection instanceof EE_Form_Input_Base ){ |
|
441 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
442 | - }elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
439 | + foreach ($this->subsections() as $subsection) { |
|
440 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
441 | + $inputs[$subsection->html_name()] = $subsection; |
|
442 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
443 | 443 | $inputs += $subsection->inputs_in_subsections(); |
444 | 444 | } |
445 | 445 | } |
@@ -452,12 +452,12 @@ discard block |
||
452 | 452 | * and values are a string of all their validation errors |
453 | 453 | * @return string[] |
454 | 454 | */ |
455 | - public function subsection_validation_errors_by_html_name(){ |
|
455 | + public function subsection_validation_errors_by_html_name() { |
|
456 | 456 | $inputs = $this->inputs(); |
457 | 457 | $errors = array(); |
458 | - foreach( $inputs as $form_input ){ |
|
459 | - if ( $form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors() ){ |
|
460 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
458 | + foreach ($inputs as $form_input) { |
|
459 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
460 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | return $errors; |
@@ -469,12 +469,12 @@ discard block |
||
469 | 469 | * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
470 | 470 | * Should be setup by each form during the _enqueues_and_localize_form_js |
471 | 471 | */ |
472 | - public static function localize_script_for_all_forms(){ |
|
472 | + public static function localize_script_for_all_forms() { |
|
473 | 473 | //allow inputs and stuff to hook in their JS and stuff here |
474 | 474 | do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
475 | 475 | EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
476 | - wp_enqueue_script( 'ee_form_section_validation' ); |
|
477 | - wp_localize_script( 'ee_form_section_validation', 'ee_form_section_vars', EE_Form_Section_Proper::$_js_localization ); |
|
476 | + wp_enqueue_script('ee_form_section_validation'); |
|
477 | + wp_localize_script('ee_form_section_validation', 'ee_form_section_vars', EE_Form_Section_Proper::$_js_localization); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | /** |
483 | 483 | * ensure_scripts_localized |
484 | 484 | */ |
485 | - public function ensure_scripts_localized(){ |
|
486 | - if ( ! EE_Form_Section_Proper::$_scripts_localized ) { |
|
485 | + public function ensure_scripts_localized() { |
|
486 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
487 | 487 | $this->_enqueue_and_localize_form_js(); |
488 | 488 | } |
489 | 489 | } |
@@ -495,10 +495,10 @@ discard block |
||
495 | 495 | * is that the key here should be the same as the custom validation rule put in the JS file |
496 | 496 | * @return array keys are custom validation rules, and values are internationalized strings |
497 | 497 | */ |
498 | - private static function _get_localized_error_messages(){ |
|
498 | + private static function _get_localized_error_messages() { |
|
499 | 499 | return array( |
500 | 500 | 'validUrl'=> __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
501 | - 'regex' => __( 'Please check your input', 'event_espresso' ), |
|
501 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
502 | 502 | ); |
503 | 503 | } |
504 | 504 | |
@@ -526,10 +526,10 @@ discard block |
||
526 | 526 | * Gets the JS to put inside the jquery validation rules for subsection of this form section. See parent function for more... |
527 | 527 | * @return array |
528 | 528 | */ |
529 | - function get_jquery_validation_rules(){ |
|
529 | + function get_jquery_validation_rules() { |
|
530 | 530 | $jquery_validation_rules = array(); |
531 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
532 | - $jquery_validation_rules = array_merge( $jquery_validation_rules, $subsection->get_jquery_validation_rules() ); |
|
531 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
532 | + $jquery_validation_rules = array_merge($jquery_validation_rules, $subsection->get_jquery_validation_rules()); |
|
533 | 533 | } |
534 | 534 | return $jquery_validation_rules; |
535 | 535 | } |
@@ -544,11 +544,11 @@ discard block |
||
544 | 544 | protected function _normalize($req_data) { |
545 | 545 | $this->_received_submission = TRUE; |
546 | 546 | $this->_validation_errors = array(); |
547 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
548 | - try{ |
|
547 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
548 | + try { |
|
549 | 549 | $subsection->_normalize($req_data); |
550 | - }catch( EE_Validation_Error $e ){ |
|
551 | - $subsection->add_validation_error( $e ); |
|
550 | + } catch (EE_Validation_Error $e) { |
|
551 | + $subsection->add_validation_error($e); |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | } |
@@ -562,9 +562,9 @@ discard block |
||
562 | 562 | * calling parent::_validate() first. |
563 | 563 | */ |
564 | 564 | protected function _validate() { |
565 | - foreach($this->get_validatable_subsections() as $subsection_name => $subsection){ |
|
566 | - if(method_exists($this,'_validate_'.$subsection_name)){ |
|
567 | - call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection)); |
|
565 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
566 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
567 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
568 | 568 | } |
569 | 569 | $subsection->_validate(); |
570 | 570 | } |
@@ -576,13 +576,13 @@ discard block |
||
576 | 576 | * Gets all the validated inputs for the form section |
577 | 577 | * @return array |
578 | 578 | */ |
579 | - public function valid_data(){ |
|
579 | + public function valid_data() { |
|
580 | 580 | $inputs = array(); |
581 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
582 | - if ( $subsection instanceof EE_Form_Section_Proper ) { |
|
583 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
584 | - } else if ( $subsection instanceof EE_Form_Input_Base ){ |
|
585 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
581 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
582 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
583 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
584 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
585 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
586 | 586 | } |
587 | 587 | } |
588 | 588 | return $inputs; |
@@ -594,11 +594,11 @@ discard block |
||
594 | 594 | * Gets all the inputs on this form section |
595 | 595 | * @return EE_Form_Input_Base[] |
596 | 596 | */ |
597 | - public function inputs(){ |
|
597 | + public function inputs() { |
|
598 | 598 | $inputs = array(); |
599 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
600 | - if ( $subsection instanceof EE_Form_Input_Base ){ |
|
601 | - $inputs[ $subsection_name ] = $subsection; |
|
599 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
600 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
601 | + $inputs[$subsection_name] = $subsection; |
|
602 | 602 | } |
603 | 603 | } |
604 | 604 | return $inputs; |
@@ -610,10 +610,10 @@ discard block |
||
610 | 610 | * Gets all the subsections which are a proper form |
611 | 611 | * @return EE_Form_Section_Proper[] |
612 | 612 | */ |
613 | - public function subforms(){ |
|
613 | + public function subforms() { |
|
614 | 614 | $form_sections = array(); |
615 | - foreach($this->subsections() as $name=>$obj){ |
|
616 | - if($obj instanceof EE_Form_Section_Proper){ |
|
615 | + foreach ($this->subsections() as $name=>$obj) { |
|
616 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
617 | 617 | $form_sections[$name] = $obj; |
618 | 618 | } |
619 | 619 | } |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | * if you only want form inputs or proper form sections. |
629 | 629 | * @return EE_Form_Section_Proper[] |
630 | 630 | */ |
631 | - public function subsections(){ |
|
631 | + public function subsections() { |
|
632 | 632 | $this->ensure_construct_finalized_called(); |
633 | 633 | return $this->_subsections; |
634 | 634 | } |
@@ -646,8 +646,8 @@ discard block |
||
646 | 646 | * it can be a multidimensional array where keys are always subsection names and values are either the |
647 | 647 | * input's normalized value, or an array like the top-level array |
648 | 648 | */ |
649 | - public function input_values( $include_subform_inputs = false, $flatten = false ){ |
|
650 | - return $this->_input_values( false, $include_subform_inputs, $flatten ); |
|
649 | + public function input_values($include_subform_inputs = false, $flatten = false) { |
|
650 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | /** |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | * it can be a multidimensional array where keys are always subsection names and values are either the |
664 | 664 | * input's normalized value, or an array like the top-level array |
665 | 665 | */ |
666 | - public function input_pretty_values( $include_subform_inputs = false, $flatten = false ){ |
|
667 | - return $this->_input_values( true, $include_subform_inputs, $flatten ); |
|
666 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) { |
|
667 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -677,17 +677,17 @@ discard block |
||
677 | 677 | * it can be a multidimensional array where keys are always subsection names and values are either the |
678 | 678 | * input's normalized value, or an array like the top-level array |
679 | 679 | */ |
680 | - public function _input_values( $pretty = false, $include_subform_inputs = false, $flatten = false ) { |
|
680 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) { |
|
681 | 681 | $input_values = array(); |
682 | - foreach( $this->subsections() as $subsection_name => $subsection ) { |
|
683 | - if( $subsection instanceof EE_Form_Input_Base ) { |
|
684 | - $input_values[ $subsection_name ] = $pretty ? $subsection->pretty_value() : $subsection->normalized_value(); |
|
685 | - } else if( $subsection instanceof EE_Form_Section_Proper && $include_subform_inputs ) { |
|
686 | - $subform_input_values = $subsection->_input_values( $pretty, $include_subform_inputs, $flatten ); |
|
687 | - if( $flatten ) { |
|
688 | - $input_values = array_merge( $input_values, $subform_input_values ); |
|
682 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
683 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
684 | + $input_values[$subsection_name] = $pretty ? $subsection->pretty_value() : $subsection->normalized_value(); |
|
685 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
686 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
687 | + if ($flatten) { |
|
688 | + $input_values = array_merge($input_values, $subform_input_values); |
|
689 | 689 | } else { |
690 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
690 | + $input_values[$subsection_name] = $subform_input_values; |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | } |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | * (ie, had receive_form_submission called on it yet) |
702 | 702 | * @return boolean |
703 | 703 | */ |
704 | - public function has_received_submission(){ |
|
704 | + public function has_received_submission() { |
|
705 | 705 | $this->ensure_construct_finalized_called(); |
706 | 706 | return $this->_received_submission; |
707 | 707 | } |
@@ -714,8 +714,8 @@ discard block |
||
714 | 714 | * @param array $inputs_to_exclude values are the input names |
715 | 715 | * @return void |
716 | 716 | */ |
717 | - public function exclude($inputs_to_exclude = array()){ |
|
718 | - foreach($inputs_to_exclude as $input_to_exclude_name){ |
|
717 | + public function exclude($inputs_to_exclude = array()) { |
|
718 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
719 | 719 | unset($this->_subsections[$input_to_exclude_name]); |
720 | 720 | } |
721 | 721 | } |
@@ -725,8 +725,8 @@ discard block |
||
725 | 725 | /** |
726 | 726 | * @param array $inputs_to_hide |
727 | 727 | */ |
728 | - public function hide($inputs_to_hide= array()){ |
|
729 | - foreach($inputs_to_hide as $input_to_hide){ |
|
728 | + public function hide($inputs_to_hide = array()) { |
|
729 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
730 | 730 | $input = $this->get_input($input_to_hide); |
731 | 731 | |
732 | 732 | $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
@@ -742,13 +742,13 @@ discard block |
||
742 | 742 | * @param string $subsection_name_to_add_before name of the section to add these subsections in front of, or null to add at the very end |
743 | 743 | * @return void |
744 | 744 | */ |
745 | - public function add_subsections($subsections,$subsection_name_to_add_before = NULL){ |
|
746 | - foreach($subsections as $subsection_name => $subsection){ |
|
747 | - if( ! $subsection instanceof EE_Form_Section_Base){ |
|
745 | + public function add_subsections($subsections, $subsection_name_to_add_before = NULL) { |
|
746 | + foreach ($subsections as $subsection_name => $subsection) { |
|
747 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
748 | 748 | EE_Error::add_error( |
749 | 749 | sprintf( |
750 | 750 | __("Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", "event_espresso"), |
751 | - get_class( $subsection ), |
|
751 | + get_class($subsection), |
|
752 | 752 | $subsection_name, |
753 | 753 | $this->name() |
754 | 754 | ) |
@@ -757,23 +757,23 @@ discard block |
||
757 | 757 | } |
758 | 758 | } |
759 | 759 | $subsections_before = array(); |
760 | - if( $subsection_name_to_add_before ){ |
|
761 | - foreach( $this->_subsections as $subsection_name => $subsection ) { |
|
762 | - if ( $subsection_name == $subsection_name_to_add_before ) { |
|
760 | + if ($subsection_name_to_add_before) { |
|
761 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
762 | + if ($subsection_name == $subsection_name_to_add_before) { |
|
763 | 763 | break; |
764 | 764 | } |
765 | 765 | $subsections_before[$subsection_name] = $subsection; |
766 | 766 | } |
767 | 767 | $subsections_after = array_diff_key($this->_subsections, $subsections_before); |
768 | - $this->_subsections = array_merge($subsections_before,$subsections,$subsections_after); |
|
769 | - }else{ |
|
768 | + $this->_subsections = array_merge($subsections_before, $subsections, $subsections_after); |
|
769 | + } else { |
|
770 | 770 | //don't use array_merge because keys might be numeric and we want to preserve their keys |
771 | - foreach( $subsections as $key => $subsection ){ |
|
772 | - $this->_subsections[ $key ] = $subsection; |
|
771 | + foreach ($subsections as $key => $subsection) { |
|
772 | + $this->_subsections[$key] = $subsection; |
|
773 | 773 | } |
774 | 774 | } |
775 | - if( $this->_construction_finalized ){ |
|
776 | - foreach($this->_subsections as $name => $subsection){ |
|
775 | + if ($this->_construction_finalized) { |
|
776 | + foreach ($this->_subsections as $name => $subsection) { |
|
777 | 777 | $subsection->_construct_finalize($this, $name); |
778 | 778 | } |
779 | 779 | } |
@@ -784,8 +784,8 @@ discard block |
||
784 | 784 | /** |
785 | 785 | * Just gets all validatable subsections to clean their sensitive data |
786 | 786 | */ |
787 | - public function clean_sensitive_data(){ |
|
788 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
787 | + public function clean_sensitive_data() { |
|
788 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
789 | 789 | $subsection->clean_sensitive_data(); |
790 | 790 | } |
791 | 791 | } |
@@ -795,8 +795,8 @@ discard block |
||
795 | 795 | /** |
796 | 796 | * @param string $form_submission_error_message |
797 | 797 | */ |
798 | - public function set_submission_error_message( $form_submission_error_message = '' ) { |
|
799 | - $this->_form_submission_error_message .= ! empty( $form_submission_error_message ) ? $form_submission_error_message : __( 'Form submission failed due to errors', 'event_espresso' ); |
|
798 | + public function set_submission_error_message($form_submission_error_message = '') { |
|
799 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) ? $form_submission_error_message : __('Form submission failed due to errors', 'event_espresso'); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * @param string $form_submission_success_message |
815 | 815 | */ |
816 | - public function set_submission_success_message( $form_submission_success_message ) { |
|
817 | - $this->_form_submission_success_message .= ! empty( $form_submission_success_message ) ? $form_submission_success_message : __( 'Form submitted successfully', 'event_espresso' ); |
|
816 | + public function set_submission_success_message($form_submission_success_message) { |
|
817 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) ? $form_submission_success_message : __('Form submitted successfully', 'event_espresso'); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | |
@@ -836,10 +836,10 @@ discard block |
||
836 | 836 | * EE_Form_Input_Base::_set_default_html_name_if_empty |
837 | 837 | * @return string |
838 | 838 | */ |
839 | - public function html_name_prefix(){ |
|
840 | - if( $this->parent_section() instanceof EE_Form_Section_Proper ){ |
|
841 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
842 | - }else{ |
|
839 | + public function html_name_prefix() { |
|
840 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
841 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
842 | + } else { |
|
843 | 843 | return $this->name(); |
844 | 844 | } |
845 | 845 | } |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | * was set, which is probably nothing, or the classname) |
851 | 851 | * @return string |
852 | 852 | */ |
853 | - public function name(){ |
|
853 | + public function name() { |
|
854 | 854 | $this->ensure_construct_finalized_called(); |
855 | 855 | return parent::name(); |
856 | 856 | } |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | * |
860 | 860 | * @return EE_Form_Section_Proper |
861 | 861 | */ |
862 | - public function parent_section(){ |
|
862 | + public function parent_section() { |
|
863 | 863 | $this->ensure_construct_finalized_called(); |
864 | 864 | return parent::parent_section(); |
865 | 865 | } |
@@ -868,9 +868,9 @@ discard block |
||
868 | 868 | * make sure construction finalized was called, otherwise children might not be ready |
869 | 869 | * @return void |
870 | 870 | */ |
871 | - public function ensure_construct_finalized_called(){ |
|
872 | - if( ! $this->_construction_finalized ){ |
|
873 | - $this->_construct_finalize($this->_parent_section, $this->_name ); |
|
871 | + public function ensure_construct_finalized_called() { |
|
872 | + if ( ! $this->_construction_finalized) { |
|
873 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
874 | 874 | } |
875 | 875 | } |
876 | 876 | |
@@ -882,17 +882,17 @@ discard block |
||
882 | 882 | * @param array $req_data |
883 | 883 | * @return boolean |
884 | 884 | */ |
885 | - public function form_data_present_in( $req_data = NULL ) { |
|
886 | - if( $req_data === NULL){ |
|
885 | + public function form_data_present_in($req_data = NULL) { |
|
886 | + if ($req_data === NULL) { |
|
887 | 887 | $req_data = $_POST; |
888 | 888 | } |
889 | - foreach( $this->subsections() as $subsection ) { |
|
890 | - if($subsection instanceof EE_Form_Input_Base ) { |
|
891 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
889 | + foreach ($this->subsections() as $subsection) { |
|
890 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
891 | + if ($subsection->form_data_present_in($req_data)) { |
|
892 | 892 | return TRUE; |
893 | 893 | } |
894 | - }elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
895 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
894 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
895 | + if ($subsection->form_data_present_in($req_data)) { |
|
896 | 896 | return TRUE; |
897 | 897 | } |
898 | 898 | } |
@@ -909,14 +909,14 @@ discard block |
||
909 | 909 | */ |
910 | 910 | public function get_validation_errors_accumulated() { |
911 | 911 | $validation_errors = $this->get_validation_errors(); |
912 | - foreach($this->get_validatable_subsections() as $subsection ) { |
|
913 | - if( $subsection instanceof EE_Form_Section_Proper ) { |
|
912 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
913 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
914 | 914 | $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
915 | 915 | } else { |
916 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
916 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
917 | 917 | } |
918 | - if( $validation_errors_on_this_subsection ){ |
|
919 | - $validation_errors = array_merge( $validation_errors, $validation_errors_on_this_subsection ); |
|
918 | + if ($validation_errors_on_this_subsection) { |
|
919 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
920 | 920 | } |
921 | 921 | } |
922 | 922 | return $validation_errors; |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * For containing info about a non-field form section, which contains other form sections/fields. |
|
4 | - * Relies heavily on the script form_section_validation.js for client-side validation, mostly |
|
5 | - * the php code just provides form_section_validation.js with teh variables to use. |
|
6 | - * Important: in order for the JS to be loaded properly, you must construct a form section |
|
7 | - * before the hook wp_enqueue_scripts is called (so that the form section can enqueue its needed scripts). |
|
8 | - * However, you may output the form (usually by calling get_html_and_js) anywhere you like. |
|
9 | - */ |
|
3 | + * For containing info about a non-field form section, which contains other form sections/fields. |
|
4 | + * Relies heavily on the script form_section_validation.js for client-side validation, mostly |
|
5 | + * the php code just provides form_section_validation.js with teh variables to use. |
|
6 | + * Important: in order for the JS to be loaded properly, you must construct a form section |
|
7 | + * before the hook wp_enqueue_scripts is called (so that the form section can enqueue its needed scripts). |
|
8 | + * However, you may output the form (usually by calling get_html_and_js) anywhere you like. |
|
9 | + */ |
|
10 | 10 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable{ |
11 | 11 | |
12 | 12 | /** |
@@ -348,6 +348,7 @@ |
||
348 | 348 | * Automatically finds the related model info from the form, if present, and |
349 | 349 | * save the relations indicated |
350 | 350 | * @type string $relation_name |
351 | + * @param integer $relation_name |
|
351 | 352 | * @return bool |
352 | 353 | * @throws EE_Error |
353 | 354 | */ |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @since 4.5.0 |
12 | 12 | * |
13 | 13 | */ |
14 | -class EE_Model_Form_Section extends EE_Form_Section_Proper{ |
|
14 | +class EE_Model_Form_Section extends EE_Form_Section_Proper { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * |
@@ -36,36 +36,36 @@ discard block |
||
36 | 36 | * } |
37 | 37 | * @throws EE_Error |
38 | 38 | */ |
39 | - public function __construct($options_array = array()){ |
|
40 | - if(isset($options_array['model']) && $options_array['model'] instanceof EEM_Base){ |
|
39 | + public function __construct($options_array = array()) { |
|
40 | + if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
41 | 41 | $this->_model = $options_array['model']; |
42 | 42 | } |
43 | - if( ! $this->_model || ! $this->_model instanceof EEM_Base ){ |
|
43 | + if ( ! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | 44 | throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", "event_espresso"))); |
45 | 45 | } |
46 | 46 | |
47 | - if(isset($options_array['subsection_args'])){ |
|
47 | + if (isset($options_array['subsection_args'])) { |
|
48 | 48 | $subsection_args = $options_array['subsection_args']; |
49 | - }else{ |
|
49 | + } else { |
|
50 | 50 | $subsection_args = array(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | //gather fields and relations to convert to inputs |
54 | 54 | //but if they're just going to exclude a field anyways, don't bother converting it to an input |
55 | 55 | $exclude = $this->_subsections; |
56 | - if(isset($options_array['exclude'])){ |
|
57 | - $exclude = array_merge($exclude,array_flip($options_array['exclude'])); |
|
56 | + if (isset($options_array['exclude'])) { |
|
57 | + $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
58 | 58 | } |
59 | 59 | $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
60 | 60 | $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
61 | 61 | //convert fields and relations to inputs |
62 | 62 | $this->_subsections = array_merge( |
63 | 63 | $this->_convert_model_fields_to_inputs($model_fields), |
64 | - $this->_convert_model_relations_to_inputs($model_relations,$subsection_args), |
|
64 | + $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
65 | 65 | $this->_subsections |
66 | 66 | ); |
67 | 67 | parent::__construct($options_array); |
68 | - if(isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class){ |
|
68 | + if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
69 | 69 | $this->populate_model_obj($options_array['model_object']); |
70 | 70 | } |
71 | 71 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * } |
84 | 84 | * @return array |
85 | 85 | */ |
86 | - protected function _convert_model_relations_to_inputs($relations,$subsection_args = array()){ |
|
86 | + protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) { |
|
87 | 87 | $inputs = array(); |
88 | - foreach( $relations as $relation_name => $relation_obj ) { |
|
88 | + foreach ($relations as $relation_name => $relation_obj) { |
|
89 | 89 | $input_constructor_args = array( |
90 | 90 | array_merge( |
91 | 91 | array( |
@@ -96,19 +96,19 @@ discard block |
||
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | $input = NULL; |
99 | - switch(get_class($relation_obj)){ |
|
99 | + switch (get_class($relation_obj)) { |
|
100 | 100 | case 'EE_HABTM_Relation': |
101 | - if(isset($subsection_args[$relation_name]) && |
|
102 | - isset($subsection_args[$relation_name]['model_objects'])){ |
|
101 | + if (isset($subsection_args[$relation_name]) && |
|
102 | + isset($subsection_args[$relation_name]['model_objects'])) { |
|
103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
104 | - }else{ |
|
104 | + } else { |
|
105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
106 | 106 | } |
107 | - $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
|
107 | + $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
108 | 108 | break; |
109 | 109 | default: |
110 | 110 | } |
111 | - if($input){ |
|
111 | + if ($input) { |
|
112 | 112 | $inputs[$relation_name] = $input; |
113 | 113 | } |
114 | 114 | } |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | * @throws EE_Error |
124 | 124 | * @return EE_Form_Input_Base[] |
125 | 125 | */ |
126 | - protected function _convert_model_fields_to_inputs( $model_fields = array() ){ |
|
126 | + protected function _convert_model_fields_to_inputs($model_fields = array()) { |
|
127 | 127 | $inputs = array(); |
128 | - foreach( $model_fields as $field_name=>$model_field ){ |
|
129 | - if ( $model_field instanceof EE_Model_Field_Base ) { |
|
128 | + foreach ($model_fields as $field_name=>$model_field) { |
|
129 | + if ($model_field instanceof EE_Model_Field_Base) { |
|
130 | 130 | $input_constructor_args = array( |
131 | 131 | array( |
132 | 132 | 'required'=> ! $model_field->is_nullable() && $model_field->get_default_value() === NULL, |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | 'default'=>$model_field->get_default_value(), |
135 | 135 | ) |
136 | 136 | ); |
137 | - switch(get_class($model_field)){ |
|
137 | + switch (get_class($model_field)) { |
|
138 | 138 | case 'EE_All_Caps_Text_Field': |
139 | 139 | case 'EE_Any_Foreign_Model_Name_Field': |
140 | 140 | $input_class = 'EE_Text_Input'; |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | $input_class = 'EE_Yes_No_Input'; |
144 | 144 | break; |
145 | 145 | case 'EE_Datetime_Field': |
146 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
146 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
147 | 147 | break; |
148 | 148 | case 'EE_Email_Field': |
149 | 149 | $input_class = 'EE_Email_Input'; |
150 | 150 | break; |
151 | 151 | case 'EE_Enum_Integer_Field': |
152 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
152 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
153 | 153 | break; |
154 | 154 | case 'EE_Enum_Text_Field': |
155 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
155 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
156 | 156 | break; |
157 | 157 | case 'EE_Float_Field': |
158 | 158 | $input_class = 'EE_Float_Input'; |
@@ -161,15 +161,15 @@ discard block |
||
161 | 161 | case 'EE_Foreign_Key_String_Field': |
162 | 162 | case 'EE_WP_User_Field': |
163 | 163 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
164 | - if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
|
164 | + if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
165 | 165 | $input_class = 'EE_Text_Input'; |
166 | - }else{ |
|
166 | + } else { |
|
167 | 167 | //so its just one model |
168 | 168 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
169 | 169 | $model = EE_Registry::instance()->load_model($model_name); |
170 | 170 | $model_names = $model->get_all_names(array('limit'=>10)); |
171 | - if($model_field->is_nullable()){ |
|
172 | - array_unshift( $model_names, __( "Please Select", 'event_espresso' )); |
|
171 | + if ($model_field->is_nullable()) { |
|
172 | + array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
173 | 173 | } |
174 | 174 | $input_constructor_args[1] = $input_constructor_args[0]; |
175 | 175 | $input_constructor_args[0] = $model_names; |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | break; |
179 | 179 | case 'EE_Full_HTML_Field': |
180 | 180 | $input_class = 'EE_Text_Area_Input'; |
181 | - $input_constructor_args[ 0 ]['validation_strategies'] = array( new EE_Full_HTML_Validation_Strategy() ); |
|
181 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
182 | 182 | break; |
183 | 183 | case 'EE_Infinite_Integer': |
184 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
184 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
185 | 185 | break; |
186 | 186 | case 'EE_Integer_Field': |
187 | 187 | $input_class = 'EE_Text_Input'; |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | $input_class = 'EE_Text_Area_Input'; |
191 | 191 | break; |
192 | 192 | case 'EE_Money_Field': |
193 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
193 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
194 | 194 | break; |
195 | 195 | case 'EE_Post_Content_Field': |
196 | 196 | $input_class = 'EE_Text_Area_Input'; |
197 | - $input_constructor_args[ 0 ][ 'validation_strategies' ] = array( new EE_Full_HTML_Validation_Strategy() ); |
|
197 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
198 | 198 | break; |
199 | 199 | case 'EE_Plain_Text_Field': |
200 | 200 | $input_class = 'EE_Text_Input'; |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | break; |
212 | 212 | case 'EE_Simple_HTML_Field': |
213 | 213 | $input_class = 'EE_Text_Area_Input'; |
214 | - $input_constructor_args[ 0 ][ 'validation_strategies' ] = array( new EE_Simple_HTML_Validation_Strategy() ); |
|
214 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
215 | 215 | break; |
216 | 216 | case 'EE_Slug_Field': |
217 | 217 | $input_class = 'EE_Text_Input'; |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | $input_class = 'EE_Yes_No_Input'; |
221 | 221 | break; |
222 | 222 | case 'EE_WP_Post_Status_Field': |
223 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
223 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
224 | 224 | break; |
225 | 225 | case 'EE_WP_Post_Type_Field': |
226 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
226 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
227 | 227 | break; |
228 | 228 | default: |
229 | - throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"),get_class($model_field))); |
|
229 | + throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"), get_class($model_field))); |
|
230 | 230 | } |
231 | 231 | $reflection = new ReflectionClass($input_class); |
232 | 232 | $input = $reflection->newInstanceArgs($input_constructor_args); |
@@ -244,21 +244,21 @@ discard block |
||
244 | 244 | * @param EE_Base_Class $model_obj |
245 | 245 | * @return void |
246 | 246 | */ |
247 | - public function populate_model_obj($model_obj){ |
|
247 | + public function populate_model_obj($model_obj) { |
|
248 | 248 | $model_obj = $this->_model->ensure_is_obj($model_obj); |
249 | 249 | $this->_model_object = $model_obj; |
250 | 250 | $defaults = $model_obj->model_field_array(); |
251 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
251 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
252 | 252 | $form_inputs = $this->inputs(); |
253 | - if(isset($form_inputs[$relation_name])){ |
|
254 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
253 | + if (isset($form_inputs[$relation_name])) { |
|
254 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
255 | 255 | //then we only expect there to be one |
256 | 256 | $related_item = $this->_model_object->get_first_related($relation_name); |
257 | 257 | $defaults[$relation_name] = $related_item->ID(); |
258 | - }else{ |
|
258 | + } else { |
|
259 | 259 | $related_items = $this->_model_object->get_many_related($relation_name); |
260 | 260 | $ids = array(); |
261 | - foreach($related_items as $related_item){ |
|
261 | + foreach ($related_items as $related_item) { |
|
262 | 262 | $ids[] = $related_item->ID(); |
263 | 263 | } |
264 | 264 | $defaults[$relation_name] = $ids; |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * values are their normalized values |
276 | 276 | * @return array |
277 | 277 | */ |
278 | - public function inputs_values_corresponding_to_model_fields(){ |
|
279 | - return array_intersect_key($this->input_values(),$this->_model->field_settings()); |
|
278 | + public function inputs_values_corresponding_to_model_fields() { |
|
279 | + return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -299,21 +299,21 @@ discard block |
||
299 | 299 | public function receive_form_submission($req_data = NULL, $validate = TRUE) { |
300 | 300 | parent::receive_form_submission($req_data, $validate); |
301 | 301 | //create or set the model object, if it isn't already |
302 | - if( ! $this->_model_object ){ |
|
302 | + if ( ! $this->_model_object) { |
|
303 | 303 | //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
304 | 304 | $pk_name = $this->_model->primary_key_name(); |
305 | 305 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
306 | - if($model_obj){ |
|
306 | + if ($model_obj) { |
|
307 | 307 | $this->_model_object = $model_obj; |
308 | - }else{ |
|
309 | - $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
|
308 | + } else { |
|
309 | + $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | //ok so the model object is set. Just set it with the submitted form data (don't save yet though) |
313 | - foreach($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value){ |
|
313 | + foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value) { |
|
314 | 314 | //only set the non-primary key |
315 | - if($field_name != $this->_model->primary_key_name()){ |
|
316 | - $this->_model_object->set($field_name,$field_value); |
|
315 | + if ($field_name != $this->_model->primary_key_name()) { |
|
316 | + $this->_model_object->set($field_name, $field_value); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
@@ -329,13 +329,13 @@ discard block |
||
329 | 329 | * @return int, 1 on a successful update, the ID of |
330 | 330 | * the new entry on insert; 0 on failure |
331 | 331 | */ |
332 | - public function save(){ |
|
333 | - if( ! $this->_model_object){ |
|
334 | - throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"),get_class($this->_model))); |
|
332 | + public function save() { |
|
333 | + if ( ! $this->_model_object) { |
|
334 | + throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"), get_class($this->_model))); |
|
335 | 335 | } |
336 | - $success = $this->_model_object->save(); |
|
337 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
338 | - if(isset($this->_subsections[$relation_name])){ |
|
336 | + $success = $this->_model_object->save(); |
|
337 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
338 | + if (isset($this->_subsections[$relation_name])) { |
|
339 | 339 | $success = $this->_save_related_info($relation_name); |
340 | 340 | } |
341 | 341 | } |
@@ -351,29 +351,29 @@ discard block |
||
351 | 351 | * @return bool |
352 | 352 | * @throws EE_Error |
353 | 353 | */ |
354 | - protected function _save_related_info($relation_name){ |
|
354 | + protected function _save_related_info($relation_name) { |
|
355 | 355 | $relation_obj = $this->_model->related_settings_for($relation_name); |
356 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
356 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
357 | 357 | //there is just a foreign key on this model pointing to that one |
358 | 358 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
359 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
359 | + }elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
360 | 360 | //then we want to consider all of its currently-related things. |
361 | 361 | //if they're in this list, keep them |
362 | 362 | //if they're not in this list, remove them |
363 | 363 | //and lastly add all the new items |
364 | 364 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
365 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
365 | + }elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
366 | 366 | //delete everything NOT in this list |
367 | 367 | $normalized_input_value = $this->get_input_value($relation_name); |
368 | - if($normalized_input_value && is_array($normalized_input_value)){ |
|
368 | + if ($normalized_input_value && is_array($normalized_input_value)) { |
|
369 | 369 | $where_query_params = array( |
370 | - $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
|
371 | - }else{ |
|
370 | + $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value)); |
|
371 | + } else { |
|
372 | 372 | $where_query_params = array(); |
373 | 373 | } |
374 | - $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |
|
375 | - foreach($normalized_input_value as $id){ |
|
376 | - $this->_model_object->_add_relation_to( $id, $relation_name ); |
|
374 | + $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
375 | + foreach ($normalized_input_value as $id) { |
|
376 | + $this->_model_object->_add_relation_to($id, $relation_name); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | return TRUE; |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * Gets the model of this model form |
386 | 386 | * @return EEM_Base |
387 | 387 | */ |
388 | - public function get_model(){ |
|
388 | + public function get_model() { |
|
389 | 389 | return $this->_model; |
390 | 390 | } |
391 | 391 | |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | * when receive_form_submission($req_data) was called. |
399 | 399 | * @return EE_Base_Class |
400 | 400 | */ |
401 | - public function get_model_object(){ |
|
401 | + public function get_model_object() { |
|
402 | 402 | return $this->_model_object; |
403 | 403 | } |
404 | 404 | |
@@ -408,10 +408,10 @@ discard block |
||
408 | 408 | * gets teh default name of this form section if none is specified |
409 | 409 | * @return string |
410 | 410 | */ |
411 | - protected function _set_default_name_if_empty(){ |
|
412 | - if( ! $this->_name ){ |
|
413 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
414 | - $this->_name = $default_name; |
|
411 | + protected function _set_default_name_if_empty() { |
|
412 | + if ( ! $this->_name) { |
|
413 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
414 | + $this->_name = $default_name; |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | if(isset($options_array['subsection_args'])){ |
48 | 48 | $subsection_args = $options_array['subsection_args']; |
49 | - }else{ |
|
49 | + } else{ |
|
50 | 50 | $subsection_args = array(); |
51 | 51 | } |
52 | 52 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | if(isset($subsection_args[$relation_name]) && |
102 | 102 | isset($subsection_args[$relation_name]['model_objects'])){ |
103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
104 | - }else{ |
|
104 | + } else{ |
|
105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
106 | 106 | } |
107 | 107 | $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
164 | 164 | if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
165 | 165 | $input_class = 'EE_Text_Input'; |
166 | - }else{ |
|
166 | + } else{ |
|
167 | 167 | //so its just one model |
168 | 168 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
169 | 169 | $model = EE_Registry::instance()->load_model($model_name); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | //then we only expect there to be one |
256 | 256 | $related_item = $this->_model_object->get_first_related($relation_name); |
257 | 257 | $defaults[$relation_name] = $related_item->ID(); |
258 | - }else{ |
|
258 | + } else{ |
|
259 | 259 | $related_items = $this->_model_object->get_many_related($relation_name); |
260 | 260 | $ids = array(); |
261 | 261 | foreach($related_items as $related_item){ |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
306 | 306 | if($model_obj){ |
307 | 307 | $this->_model_object = $model_obj; |
308 | - }else{ |
|
308 | + } else{ |
|
309 | 309 | $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
310 | 310 | } |
311 | 311 | } |
@@ -356,19 +356,19 @@ discard block |
||
356 | 356 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
357 | 357 | //there is just a foreign key on this model pointing to that one |
358 | 358 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
359 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
359 | + } elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
360 | 360 | //then we want to consider all of its currently-related things. |
361 | 361 | //if they're in this list, keep them |
362 | 362 | //if they're not in this list, remove them |
363 | 363 | //and lastly add all the new items |
364 | 364 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
365 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
365 | + } elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
366 | 366 | //delete everything NOT in this list |
367 | 367 | $normalized_input_value = $this->get_input_value($relation_name); |
368 | 368 | if($normalized_input_value && is_array($normalized_input_value)){ |
369 | 369 | $where_query_params = array( |
370 | 370 | $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
371 | - }else{ |
|
371 | + } else{ |
|
372 | 372 | $where_query_params = array(); |
373 | 373 | } |
374 | 374 | $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | /** |
262 | 262 | * Sets sensitive_data_removal_strategy |
263 | 263 | * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
264 | - * @return boolean |
|
264 | + * @return boolean|null |
|
265 | 265 | */ |
266 | 266 | public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) { |
267 | 267 | $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * Returns whether or not any validation errors occurred |
446 | 446 | * |
447 | 447 | * @param array $req_data like $_POST |
448 | - * @return boolean whether or not there was an error |
|
448 | + * @return boolean|null whether or not there was an error |
|
449 | 449 | */ |
450 | 450 | protected function _normalize( $req_data ) { |
451 | 451 | //any existing validation errors don't apply so clear them |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * EE_Form_Input_Base |
|
4 | - * For representing a single form input. Extends EE_Form_Section_Base because |
|
5 | - * it is a part of a form and shares a surprisingly large amount of functionality |
|
6 | - * |
|
7 | - * @package Event Espresso |
|
8 | - * @subpackage |
|
9 | - * @author Mike Nelson |
|
10 | - */ |
|
3 | + * EE_Form_Input_Base |
|
4 | + * For representing a single form input. Extends EE_Form_Section_Base because |
|
5 | + * it is a part of a form and shares a surprisingly large amount of functionality |
|
6 | + * |
|
7 | + * @package Event Espresso |
|
8 | + * @subpackage |
|
9 | + * @author Mike Nelson |
|
10 | + */ |
|
11 | 11 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable{ |
12 | 12 | |
13 | 13 | /** |
@@ -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 |
@@ -141,66 +141,66 @@ discard block |
||
141 | 141 | * @type EE_Validation_Strategy_Base[] $validation_strategies |
142 | 142 | * } |
143 | 143 | */ |
144 | - public function __construct( $input_args = array() ){ |
|
144 | + public function __construct($input_args = array()) { |
|
145 | 145 | // the following properties must be cast as arrays |
146 | 146 | $set_as_array = array( |
147 | 147 | 'validation_strategies' |
148 | 148 | ); |
149 | 149 | // loop thru incoming options |
150 | - foreach( $input_args as $key => $value ) { |
|
150 | + foreach ($input_args as $key => $value) { |
|
151 | 151 | // add underscore to $key to match property names |
152 | - $_key = '_' . $key; |
|
153 | - if ( property_exists( $this, $_key )) { |
|
152 | + $_key = '_'.$key; |
|
153 | + if (property_exists($this, $_key)) { |
|
154 | 154 | // first check if this property needs to be set as an array |
155 | - if ( isset( $set_as_array[ $key ] )) { |
|
155 | + if (isset($set_as_array[$key])) { |
|
156 | 156 | // ensure value is an array |
157 | - $value = is_array( $value ) ? $value : array( $value ); |
|
157 | + $value = is_array($value) ? $value : array($value); |
|
158 | 158 | // and merge with existing values |
159 | - $this->$_key = array_merge( $this->$_key, $value ); |
|
159 | + $this->$_key = array_merge($this->$_key, $value); |
|
160 | 160 | } else { |
161 | 161 | $this->$_key = $value; |
162 | 162 | } |
163 | 163 | } |
164 | 164 | } |
165 | 165 | // ensure that "required" is set correctly |
166 | - $this->set_required( $this->_required, isset( $input_args[ 'required_validation_error_message' ] ) ? $input_args[ 'required_validation_error_message' ] : NULL ); |
|
166 | + $this->set_required($this->_required, isset($input_args['required_validation_error_message']) ? $input_args['required_validation_error_message'] : NULL); |
|
167 | 167 | |
168 | - $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
168 | + $this->_html_name_specified = isset($input_args['html_name']) ? TRUE : FALSE; |
|
169 | 169 | |
170 | 170 | $this->_display_strategy->_construct_finalize($this); |
171 | 171 | |
172 | - if ( $this->_validation_strategies ){ |
|
173 | - foreach( $this->_validation_strategies as $validation_strategy ){ |
|
172 | + if ($this->_validation_strategies) { |
|
173 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
174 | 174 | $validation_strategy->_construct_finalize($this); |
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | - if( ! $this->_normalization_strategy){ |
|
178 | + if ( ! $this->_normalization_strategy) { |
|
179 | 179 | $this->_normalization_strategy = new EE_Text_Normalization(); |
180 | 180 | } |
181 | 181 | $this->_normalization_strategy->_construct_finalize($this); |
182 | 182 | |
183 | 183 | //at least we can use the normalization strategy to populate the default |
184 | - if( isset( $input_args[ 'default' ] ) ) { |
|
185 | - $this->set_default( $input_args[ 'default' ] ); |
|
184 | + if (isset($input_args['default'])) { |
|
185 | + $this->set_default($input_args['default']); |
|
186 | 186 | } |
187 | 187 | |
188 | - if( ! $this->_sensitive_data_removal_strategy){ |
|
188 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
189 | 189 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
190 | 190 | } |
191 | 191 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
192 | - parent::__construct( $input_args ); |
|
192 | + parent::__construct($input_args); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | 196 | * Sets the html_name to its default value, if none was specified in teh constructor. |
197 | 197 | * Calculation involves using the name and the parent's html_name |
198 | 198 | */ |
199 | - protected function _set_default_html_name_if_empty(){ |
|
200 | - if( ! $this->_html_name){ |
|
201 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper){ |
|
202 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
203 | - }else{ |
|
199 | + protected function _set_default_html_name_if_empty() { |
|
200 | + if ( ! $this->_html_name) { |
|
201 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
202 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
203 | + } else { |
|
204 | 204 | $this->_html_name = $this->name(); |
205 | 205 | } |
206 | 206 | } |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | function _construct_finalize($parent_form_section, $name) { |
216 | 216 | parent::_construct_finalize($parent_form_section, $name); |
217 | 217 | $this->_set_default_html_name_if_empty(); |
218 | - if( ! $this->_html_label ){ |
|
219 | - if( ! $this->_html_label_text){ |
|
220 | - $this->_html_label_text = ucwords( str_replace("_"," ",$name)); |
|
218 | + if ( ! $this->_html_label) { |
|
219 | + if ( ! $this->_html_label_text) { |
|
220 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | } |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * @return EE_Display_Strategy_Base |
228 | 228 | * @throws EE_Error |
229 | 229 | */ |
230 | - protected function _get_display_strategy(){ |
|
231 | - if( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base){ |
|
232 | - throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"),$this->html_name(),$this->html_id())); |
|
233 | - }else{ |
|
230 | + protected function _get_display_strategy() { |
|
231 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
232 | + throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"), $this->html_name(), $this->html_id())); |
|
233 | + } else { |
|
234 | 234 | return $this->_display_strategy; |
235 | 235 | } |
236 | 236 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * Sets the display strategy. |
239 | 239 | * @param EE_Display_Strategy_Base $strategy |
240 | 240 | */ |
241 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy){ |
|
241 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) { |
|
242 | 242 | $this->_display_strategy = $strategy; |
243 | 243 | } |
244 | 244 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * Sets the sanitization strategy |
247 | 247 | * @param EE_Normalization_Strategy_Base $strategy |
248 | 248 | */ |
249 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy){ |
|
249 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) { |
|
250 | 250 | $this->_normalization_strategy = $strategy; |
251 | 251 | } |
252 | 252 | |
@@ -272,14 +272,14 @@ discard block |
||
272 | 272 | * Gets the display strategy for this input |
273 | 273 | * @return EE_Display_Strategy_Base |
274 | 274 | */ |
275 | - public function get_display_strategy(){ |
|
275 | + public function get_display_strategy() { |
|
276 | 276 | return $this->_display_strategy; |
277 | 277 | } |
278 | 278 | /** |
279 | 279 | * Overwrites the display strategy |
280 | 280 | * @param EE_Display_Strategy_Base $display_strategy |
281 | 281 | */ |
282 | - public function set_display_strategy($display_strategy){ |
|
282 | + public function set_display_strategy($display_strategy) { |
|
283 | 283 | $this->_display_strategy = $display_strategy; |
284 | 284 | $this->_display_strategy->_construct_finalize($this); |
285 | 285 | } |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | * Gets the normalization strategy set on this input |
288 | 288 | * @return EE_Normalization_Strategy_Base |
289 | 289 | */ |
290 | - public function get_normalization_strategy(){ |
|
290 | + public function get_normalization_strategy() { |
|
291 | 291 | return $this->_normalization_strategy; |
292 | 292 | } |
293 | 293 | /** |
294 | 294 | * Overwrites the normalization strategy |
295 | 295 | * @param EE_Normalization_Strategy_Base $normalization_strategy |
296 | 296 | */ |
297 | - public function set_normalization_strategy($normalization_strategy){ |
|
297 | + public function set_normalization_strategy($normalization_strategy) { |
|
298 | 298 | $this->_normalization_strategy = $normalization_strategy; |
299 | 299 | $this->_normalization_strategy->_construct_finalize($this); |
300 | 300 | } |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | * Returns all teh validation strategies which apply to this field, numerically indexed |
304 | 304 | * @return EE_Validation_Strategy_Base[] |
305 | 305 | */ |
306 | - public function get_validation_strategies(){ |
|
307 | - if(is_array($this->_validation_strategies)){ |
|
306 | + public function get_validation_strategies() { |
|
307 | + if (is_array($this->_validation_strategies)) { |
|
308 | 308 | return $this->_validation_strategies; |
309 | - }else{ |
|
309 | + } else { |
|
310 | 310 | return array(); |
311 | 311 | } |
312 | 312 | |
@@ -316,9 +316,9 @@ discard block |
||
316 | 316 | * @param EE_Validation_Strategy_Base $validation_strategy |
317 | 317 | * @return void |
318 | 318 | */ |
319 | - protected function _add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ){ |
|
320 | - $validation_strategy->_construct_finalize( $this ); |
|
321 | - $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
319 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
320 | + $validation_strategy->_construct_finalize($this); |
|
321 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
322 | 322 | |
323 | 323 | } |
324 | 324 | |
@@ -327,18 +327,18 @@ discard block |
||
327 | 327 | * @param EE_Validation_Strategy_Base $validation_strategy |
328 | 328 | * @return void |
329 | 329 | */ |
330 | - public function add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ) { |
|
331 | - $this->_add_validation_strategy( $validation_strategy ); |
|
330 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
331 | + $this->_add_validation_strategy($validation_strategy); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
335 | 335 | * The classname of the validation strategy to remove |
336 | 336 | * @param string $validation_strategy_classname |
337 | 337 | */ |
338 | - public function remove_validation_strategy( $validation_strategy_classname ) { |
|
339 | - foreach( $this->_validation_strategies as $key => $validation_strategy ){ |
|
340 | - if( is_subclass_of( $validation_strategy, $validation_strategy_classname ) ){ |
|
341 | - unset( $this->_validation_strategies[ $key ] ); |
|
338 | + public function remove_validation_strategy($validation_strategy_classname) { |
|
339 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
340 | + if (is_subclass_of($validation_strategy, $validation_strategy_classname)) { |
|
341 | + unset($this->_validation_strategies[$key]); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * to the parent form's layout strategy |
348 | 348 | * @return string |
349 | 349 | */ |
350 | - public function get_html_and_js(){ |
|
350 | + public function get_html_and_js() { |
|
351 | 351 | return $this->_parent_section->get_html_for_input($this); |
352 | 352 | } |
353 | 353 | /** |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * Makes sure the JS and CSS are enqueued for it |
357 | 357 | * @return string |
358 | 358 | */ |
359 | - public function get_html_for_input(){ |
|
359 | + public function get_html_for_input() { |
|
360 | 360 | return $this->_get_display_strategy()->display(); |
361 | 361 | } |
362 | 362 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @return string |
367 | 367 | */ |
368 | 368 | public function html_other_attributes() { |
369 | - return ! empty( $this->_html_other_attributes ) ? ' ' . $this->_html_other_attributes : ''; |
|
369 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | /** |
375 | 375 | * @param string $html_other_attributes |
376 | 376 | */ |
377 | - public function set_html_other_attributes( $html_other_attributes ) { |
|
377 | + public function set_html_other_attributes($html_other_attributes) { |
|
378 | 378 | $this->_html_other_attributes = $html_other_attributes; |
379 | 379 | } |
380 | 380 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * according to the form section's layout strategy |
384 | 384 | * @return string |
385 | 385 | */ |
386 | - public function get_html_for_label(){ |
|
386 | + public function get_html_for_label() { |
|
387 | 387 | return $this->_parent_section->get_layout_strategy()->display_label($this); |
388 | 388 | } |
389 | 389 | /** |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * according to the form section's layout strategy |
392 | 392 | * @return string |
393 | 393 | */ |
394 | - public function get_html_for_errors(){ |
|
394 | + public function get_html_for_errors() { |
|
395 | 395 | return $this->_parent_section->get_layout_strategy()->display_errors($this); |
396 | 396 | } |
397 | 397 | /** |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * according to the form section's layout strategy |
400 | 400 | * @return string |
401 | 401 | */ |
402 | - public function get_html_for_help(){ |
|
402 | + public function get_html_for_help() { |
|
403 | 403 | return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
404 | 404 | } |
405 | 405 | /** |
@@ -408,20 +408,20 @@ discard block |
||
408 | 408 | * @return boolean |
409 | 409 | */ |
410 | 410 | protected function _validate() { |
411 | - if(is_array($this->_validation_strategies)){ |
|
412 | - foreach($this->_validation_strategies as $validation_strategy){ |
|
413 | - if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
|
414 | - try{ |
|
411 | + if (is_array($this->_validation_strategies)) { |
|
412 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
413 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
414 | + try { |
|
415 | 415 | $validation_strategy->validate($this->normalized_value()); |
416 | - }catch(EE_Validation_Error $e){ |
|
416 | + } catch (EE_Validation_Error $e) { |
|
417 | 417 | $this->add_validation_error($e); |
418 | 418 | } |
419 | 419 | } |
420 | 420 | } |
421 | 421 | } |
422 | - if( $this->get_validation_errors()){ |
|
422 | + if ($this->get_validation_errors()) { |
|
423 | 423 | return false; |
424 | - }else{ |
|
424 | + } else { |
|
425 | 425 | return true; |
426 | 426 | } |
427 | 427 | } |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | * @param string $value |
435 | 435 | * @return null|string |
436 | 436 | */ |
437 | - private function _sanitize($value){ |
|
438 | - return $value !== NULL ?stripslashes(html_entity_decode($value)) : NULL;//don't sanitize_text_field |
|
437 | + private function _sanitize($value) { |
|
438 | + return $value !== NULL ? stripslashes(html_entity_decode($value)) : NULL; //don't sanitize_text_field |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | |
@@ -447,24 +447,24 @@ discard block |
||
447 | 447 | * @param array $req_data like $_POST |
448 | 448 | * @return boolean whether or not there was an error |
449 | 449 | */ |
450 | - protected function _normalize( $req_data ) { |
|
450 | + protected function _normalize($req_data) { |
|
451 | 451 | //any existing validation errors don't apply so clear them |
452 | 452 | $this->_validation_errors = array(); |
453 | 453 | try { |
454 | - $raw_input = $this->find_form_data_for_this_section( $req_data ); |
|
454 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
455 | 455 | //super simple sanitization for now |
456 | - if ( is_array( $raw_input )) { |
|
456 | + if (is_array($raw_input)) { |
|
457 | 457 | $this->_raw_value = array(); |
458 | - foreach( $raw_input as $key => $value ) { |
|
459 | - $this->_raw_value[ $key ] = $this->_sanitize( $value ); |
|
458 | + foreach ($raw_input as $key => $value) { |
|
459 | + $this->_raw_value[$key] = $this->_sanitize($value); |
|
460 | 460 | } |
461 | 461 | } else { |
462 | - $this->_raw_value = $this->_sanitize( $raw_input ); |
|
462 | + $this->_raw_value = $this->_sanitize($raw_input); |
|
463 | 463 | } |
464 | 464 | //we want ot mostly leave the input alone in case we need to re-display it to the user |
465 | - $this->_normalized_value = $this->_normalization_strategy->normalize( $this->raw_value() ); |
|
466 | - } catch ( EE_Validation_Error $e ) { |
|
467 | - $this->add_validation_error( $e ); |
|
465 | + $this->_normalized_value = $this->_normalization_strategy->normalize($this->raw_value()); |
|
466 | + } catch (EE_Validation_Error $e) { |
|
467 | + $this->add_validation_error($e); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | /** |
474 | 474 | * @return string |
475 | 475 | */ |
476 | - public function html_name(){ |
|
476 | + public function html_name() { |
|
477 | 477 | return $this->_html_name; |
478 | 478 | } |
479 | 479 | |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | /** |
483 | 483 | * @return string |
484 | 484 | */ |
485 | - function html_label_id(){ |
|
486 | - return ! empty( $this->_html_label_id ) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
485 | + function html_label_id() { |
|
486 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id.'-lbl'; |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | /** |
492 | 492 | * @return string |
493 | 493 | */ |
494 | - function html_label_class(){ |
|
494 | + function html_label_class() { |
|
495 | 495 | return $this->_html_label_class; |
496 | 496 | } |
497 | 497 | |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | /** |
501 | 501 | * @return string |
502 | 502 | */ |
503 | - function html_label_style(){ |
|
503 | + function html_label_style() { |
|
504 | 504 | return $this->_html_label_style; |
505 | 505 | } |
506 | 506 | |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | /** |
510 | 510 | * @return string |
511 | 511 | */ |
512 | - function html_label_text(){ |
|
512 | + function html_label_text() { |
|
513 | 513 | return $this->_html_label_text; |
514 | 514 | } |
515 | 515 | |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | /** |
519 | 519 | * @return string |
520 | 520 | */ |
521 | - function html_help_text(){ |
|
521 | + function html_help_text() { |
|
522 | 522 | return $this->_html_help_text; |
523 | 523 | } |
524 | 524 | |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | /** |
528 | 528 | * @return string |
529 | 529 | */ |
530 | - function html_help_class(){ |
|
530 | + function html_help_class() { |
|
531 | 531 | return $this->_html_help_class; |
532 | 532 | } |
533 | 533 | |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | /** |
537 | 537 | * @return string |
538 | 538 | */ |
539 | - function html_help_style(){ |
|
539 | + function html_help_style() { |
|
540 | 540 | return $this->_html_style; |
541 | 541 | } |
542 | 542 | /** |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * in which case, we would have stored the malicious content to our database. |
550 | 550 | * @return string |
551 | 551 | */ |
552 | - function raw_value(){ |
|
552 | + function raw_value() { |
|
553 | 553 | return $this->_raw_value; |
554 | 554 | } |
555 | 555 | /** |
@@ -557,15 +557,15 @@ discard block |
||
557 | 557 | * it escapes all html entities |
558 | 558 | * @return string |
559 | 559 | */ |
560 | - function raw_value_in_form(){ |
|
561 | - return htmlentities($this->raw_value(),ENT_QUOTES, 'UTF-8'); |
|
560 | + function raw_value_in_form() { |
|
561 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
562 | 562 | } |
563 | 563 | /** |
564 | 564 | * returns the value after it's been sanitized, and then converted into it's proper type |
565 | 565 | * in PHP. Eg, a string, an int, an array, |
566 | 566 | * @return mixed |
567 | 567 | */ |
568 | - function normalized_value(){ |
|
568 | + function normalized_value() { |
|
569 | 569 | return $this->_normalized_value; |
570 | 570 | } |
571 | 571 | |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | * the best thing to display |
576 | 576 | * @return string |
577 | 577 | */ |
578 | - function pretty_value(){ |
|
578 | + function pretty_value() { |
|
579 | 579 | return $this->_normalized_value; |
580 | 580 | } |
581 | 581 | /** |
@@ -594,15 +594,15 @@ discard block |
||
594 | 594 | }</code> |
595 | 595 | * @return array |
596 | 596 | */ |
597 | - function get_jquery_validation_rules(){ |
|
597 | + function get_jquery_validation_rules() { |
|
598 | 598 | $jquery_validation_rules = array(); |
599 | - foreach($this->get_validation_strategies() as $validation_strategy){ |
|
600 | - $jquery_validation_rules = array_replace_recursive( $jquery_validation_rules, $validation_strategy->get_jquery_validation_rule_array()); |
|
599 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
600 | + $jquery_validation_rules = array_replace_recursive($jquery_validation_rules, $validation_strategy->get_jquery_validation_rule_array()); |
|
601 | 601 | } |
602 | 602 | |
603 | - if(! empty($jquery_validation_rules)){ |
|
604 | - $jquery_validation_js[ $this->html_id( TRUE ) ] = $jquery_validation_rules; |
|
605 | - }else{ |
|
603 | + if ( ! empty($jquery_validation_rules)) { |
|
604 | + $jquery_validation_js[$this->html_id(TRUE)] = $jquery_validation_rules; |
|
605 | + } else { |
|
606 | 606 | return array(); |
607 | 607 | } |
608 | 608 | return $jquery_validation_js; |
@@ -614,9 +614,9 @@ discard block |
||
614 | 614 | * @param mixed $value |
615 | 615 | * @return void |
616 | 616 | */ |
617 | - function set_default($value){ |
|
617 | + function set_default($value) { |
|
618 | 618 | $this->_normalized_value = $value; |
619 | - $this->_raw_value = $this->_normalization_strategy->unnormalize( $value ); |
|
619 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | * @param string $label |
625 | 625 | * @return void |
626 | 626 | */ |
627 | - function set_html_label_text($label){ |
|
627 | + function set_html_label_text($label) { |
|
628 | 628 | $this->_html_label_text = $label; |
629 | 629 | } |
630 | 630 | |
@@ -636,12 +636,12 @@ discard block |
||
636 | 636 | * @param boolean $required |
637 | 637 | * @param null $required_text |
638 | 638 | */ |
639 | - function set_required($required = true, $required_text = NULL ){ |
|
640 | - $required = filter_var( $required, FILTER_VALIDATE_BOOLEAN ); |
|
641 | - if ( $required ) { |
|
642 | - $this->_add_validation_strategy( new EE_Required_Validation_Strategy( $required_text ) ); |
|
639 | + function set_required($required = true, $required_text = NULL) { |
|
640 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
641 | + if ($required) { |
|
642 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
643 | 643 | } else { |
644 | - unset( $this->_validation_strategies[ get_class( new EE_Required_Validation_Strategy() ) ] ); |
|
644 | + unset($this->_validation_strategies[get_class(new EE_Required_Validation_Strategy())]); |
|
645 | 645 | } |
646 | 646 | $this->_required = $required; |
647 | 647 | } |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | * Returns whether or not this field is required |
650 | 650 | * @return boolean |
651 | 651 | */ |
652 | - public function required(){ |
|
652 | + public function required() { |
|
653 | 653 | return $this->_required; |
654 | 654 | } |
655 | 655 | |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | /** |
659 | 659 | * @param string $required_css_class |
660 | 660 | */ |
661 | - public function set_required_css_class( $required_css_class ) { |
|
661 | + public function set_required_css_class($required_css_class) { |
|
662 | 662 | $this->_required_css_class = $required_css_class; |
663 | 663 | } |
664 | 664 | |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | * Sets the help text, in case |
678 | 678 | * @param string $text |
679 | 679 | */ |
680 | - public function set_html_help_text($text){ |
|
680 | + public function set_html_help_text($text) { |
|
681 | 681 | $this->_html_help_text = $text; |
682 | 682 | } |
683 | 683 | /** |
@@ -689,8 +689,8 @@ discard block |
||
689 | 689 | public function clean_sensitive_data() { |
690 | 690 | //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
691 | 691 | //if we need more logic than this we'll make a strategy for it |
692 | - if( $this->_sensitive_data_removal_strategy && |
|
693 | - ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal ){ |
|
692 | + if ($this->_sensitive_data_removal_strategy && |
|
693 | + ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal) { |
|
694 | 694 | $this->_raw_value = NULL; |
695 | 695 | } |
696 | 696 | //and clean the normalized value according to the appropriate strategy |
@@ -704,10 +704,10 @@ discard block |
||
704 | 704 | * @param string $button_size |
705 | 705 | * @param string $other_attributes |
706 | 706 | */ |
707 | - public function set_button_css_attributes( $primary = TRUE, $button_size = '', $other_attributes = '' ) { |
|
707 | + public function set_button_css_attributes($primary = TRUE, $button_size = '', $other_attributes = '') { |
|
708 | 708 | $button_css_attributes = 'button'; |
709 | 709 | $button_css_attributes .= $primary === TRUE ? ' button-primary' : ' button-secondary'; |
710 | - switch ( $button_size ) { |
|
710 | + switch ($button_size) { |
|
711 | 711 | case 'xs' : |
712 | 712 | case 'extra-small' : |
713 | 713 | $button_css_attributes .= ' button-xs'; |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | default : |
729 | 729 | $button_css_attributes .= ''; |
730 | 730 | } |
731 | - $this->_button_css_attributes .= ! empty( $other_attributes ) ? $button_css_attributes . ' ' . $other_attributes : $button_css_attributes; |
|
731 | + $this->_button_css_attributes .= ! empty($other_attributes) ? $button_css_attributes.' '.$other_attributes : $button_css_attributes; |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | * @return string |
738 | 738 | */ |
739 | 739 | public function button_css_attributes() { |
740 | - if ( empty( $this->_button_css_attributes )) { |
|
740 | + if (empty($this->_button_css_attributes)) { |
|
741 | 741 | $this->set_button_css_attributes(); |
742 | 742 | } |
743 | 743 | return $this->_button_css_attributes; |
@@ -757,27 +757,27 @@ discard block |
||
757 | 757 | * @param array $req_data |
758 | 758 | * @return mixed whatever the raw value of this form section is in the request data |
759 | 759 | */ |
760 | - public function find_form_data_for_this_section( $req_data ){ |
|
760 | + public function find_form_data_for_this_section($req_data) { |
|
761 | 761 | // break up the html name by "[]" |
762 | - if ( strpos( $this->html_name(), '[' ) !== FALSE ) { |
|
763 | - $before_any_brackets = substr( $this->html_name(), 0, strpos($this->html_name(), '[') ); |
|
762 | + if (strpos($this->html_name(), '[') !== FALSE) { |
|
763 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
764 | 764 | } else { |
765 | 765 | $before_any_brackets = $this->html_name(); |
766 | 766 | } |
767 | 767 | // grab all of the segments |
768 | - preg_match_all('~\[([^]]*)\]~',$this->html_name(), $matches); |
|
769 | - if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
|
770 | - $name_parts = $matches[ 1 ]; |
|
768 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
769 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
770 | + $name_parts = $matches[1]; |
|
771 | 771 | array_unshift($name_parts, $before_any_brackets); |
772 | - }else{ |
|
773 | - $name_parts = array( $before_any_brackets ); |
|
772 | + } else { |
|
773 | + $name_parts = array($before_any_brackets); |
|
774 | 774 | } |
775 | 775 | // now get the value for the input |
776 | 776 | $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
777 | - if( $value === NULL ){ |
|
777 | + if ($value === NULL) { |
|
778 | 778 | //check if this thing's name is at the TOP level of the request data |
779 | - if( isset( $req_data[ $this->name() ] ) ){ |
|
780 | - $value = $req_data[ $this->name() ]; |
|
779 | + if (isset($req_data[$this->name()])) { |
|
780 | + $value = $req_data[$this->name()]; |
|
781 | 781 | } |
782 | 782 | } |
783 | 783 | return $value; |
@@ -791,15 +791,15 @@ discard block |
||
791 | 791 | * @param array $req_data |
792 | 792 | * @return array | NULL |
793 | 793 | */ |
794 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data){ |
|
795 | - $first_part_to_consider = array_shift( $html_name_parts ); |
|
796 | - if( isset( $req_data[ $first_part_to_consider ] ) ){ |
|
797 | - if( empty($html_name_parts ) ){ |
|
798 | - return $req_data[ $first_part_to_consider ]; |
|
799 | - }else{ |
|
800 | - return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[ $first_part_to_consider ] ); |
|
794 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) { |
|
795 | + $first_part_to_consider = array_shift($html_name_parts); |
|
796 | + if (isset($req_data[$first_part_to_consider])) { |
|
797 | + if (empty($html_name_parts)) { |
|
798 | + return $req_data[$first_part_to_consider]; |
|
799 | + } else { |
|
800 | + return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[$first_part_to_consider]); |
|
801 | 801 | } |
802 | - }else{ |
|
802 | + } else { |
|
803 | 803 | return NULL; |
804 | 804 | } |
805 | 805 | } |
@@ -811,14 +811,14 @@ discard block |
||
811 | 811 | * @param array $req_data like $_POST |
812 | 812 | * @return boolean |
813 | 813 | */ |
814 | - public function form_data_present_in($req_data = NULL){ |
|
815 | - if( $req_data === NULL ){ |
|
814 | + public function form_data_present_in($req_data = NULL) { |
|
815 | + if ($req_data === NULL) { |
|
816 | 816 | $req_data = $_POST; |
817 | 817 | } |
818 | - $checked_value = $this->find_form_data_for_this_section( $req_data ); |
|
819 | - if( $checked_value !== null ){ |
|
818 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
819 | + if ($checked_value !== null) { |
|
820 | 820 | return TRUE; |
821 | - }else{ |
|
821 | + } else { |
|
822 | 822 | return FALSE; |
823 | 823 | } |
824 | 824 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | if( ! $this->_html_name){ |
201 | 201 | if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper){ |
202 | 202 | $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
203 | - }else{ |
|
203 | + } else{ |
|
204 | 204 | $this->_html_name = $this->name(); |
205 | 205 | } |
206 | 206 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | protected function _get_display_strategy(){ |
231 | 231 | if( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base){ |
232 | 232 | throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"),$this->html_name(),$this->html_id())); |
233 | - }else{ |
|
233 | + } else{ |
|
234 | 234 | return $this->_display_strategy; |
235 | 235 | } |
236 | 236 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | public function get_validation_strategies(){ |
307 | 307 | if(is_array($this->_validation_strategies)){ |
308 | 308 | return $this->_validation_strategies; |
309 | - }else{ |
|
309 | + } else{ |
|
310 | 310 | return array(); |
311 | 311 | } |
312 | 312 | |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
414 | 414 | try{ |
415 | 415 | $validation_strategy->validate($this->normalized_value()); |
416 | - }catch(EE_Validation_Error $e){ |
|
416 | + } catch(EE_Validation_Error $e){ |
|
417 | 417 | $this->add_validation_error($e); |
418 | 418 | } |
419 | 419 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | } |
422 | 422 | if( $this->get_validation_errors()){ |
423 | 423 | return false; |
424 | - }else{ |
|
424 | + } else{ |
|
425 | 425 | return true; |
426 | 426 | } |
427 | 427 | } |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | |
603 | 603 | if(! empty($jquery_validation_rules)){ |
604 | 604 | $jquery_validation_js[ $this->html_id( TRUE ) ] = $jquery_validation_rules; |
605 | - }else{ |
|
605 | + } else{ |
|
606 | 606 | return array(); |
607 | 607 | } |
608 | 608 | return $jquery_validation_js; |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
770 | 770 | $name_parts = $matches[ 1 ]; |
771 | 771 | array_unshift($name_parts, $before_any_brackets); |
772 | - }else{ |
|
772 | + } else{ |
|
773 | 773 | $name_parts = array( $before_any_brackets ); |
774 | 774 | } |
775 | 775 | // now get the value for the input |
@@ -796,10 +796,10 @@ discard block |
||
796 | 796 | if( isset( $req_data[ $first_part_to_consider ] ) ){ |
797 | 797 | if( empty($html_name_parts ) ){ |
798 | 798 | return $req_data[ $first_part_to_consider ]; |
799 | - }else{ |
|
799 | + } else{ |
|
800 | 800 | return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[ $first_part_to_consider ] ); |
801 | 801 | } |
802 | - }else{ |
|
802 | + } else{ |
|
803 | 803 | return NULL; |
804 | 804 | } |
805 | 805 | } |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | $checked_value = $this->find_form_data_for_this_section( $req_data ); |
819 | 819 | if( $checked_value !== null ){ |
820 | 820 | return TRUE; |
821 | - }else{ |
|
821 | + } else{ |
|
822 | 822 | return FALSE; |
823 | 823 | } |
824 | 824 | } |
@@ -101,7 +101,7 @@ |
||
101 | 101 | |
102 | 102 | |
103 | 103 | /** |
104 | - * @param $payment_method_type |
|
104 | + * @param EE_PMT_Base $payment_method_type |
|
105 | 105 | * @throws EE_Error |
106 | 106 | */ |
107 | 107 | public function set_payment_method_type( $payment_method_type ){ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * Specialized form for payment methods, allowing for easy setting and retrieving of meta fields. |
5 | 5 | * Uses EEM_Payment_Method as the model |
6 | 6 | */ |
7 | -class EE_Payment_Method_Form extends EE_Model_Form_Section{ |
|
7 | +class EE_Payment_Method_Form extends EE_Model_Form_Section { |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * All the subsection inputs that correspond ot extra meta rows |
@@ -39,36 +39,36 @@ discard block |
||
39 | 39 | * @see EE_Model_Form_Section::__construct() for more |
40 | 40 | * } |
41 | 41 | */ |
42 | - public function __construct($options_array = array()){ |
|
42 | + public function __construct($options_array = array()) { |
|
43 | 43 | $this->_model = EEM_Payment_Method::instance(); |
44 | 44 | $this->_options_array = $options_array; |
45 | - if(isset($options_array['payment_method_type'])){ |
|
45 | + if (isset($options_array['payment_method_type'])) { |
|
46 | 46 | $this->_payment_method_type = $options_array['payment_method_type']; |
47 | 47 | } |
48 | 48 | $options_array = $this->_options_array; |
49 | - if(isset($options_array['extra_meta_inputs'])){ |
|
50 | - $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs,$options_array['extra_meta_inputs']); |
|
49 | + if (isset($options_array['extra_meta_inputs'])) { |
|
50 | + $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']); |
|
51 | 51 | } |
52 | - if($this->_extra_meta_inputs){ |
|
53 | - $this->_subsections = array_merge($this->_subsections,$this->_extra_meta_inputs); |
|
52 | + if ($this->_extra_meta_inputs) { |
|
53 | + $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs); |
|
54 | 54 | } |
55 | 55 | $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input( |
56 | - array( 'html_label_text'=> __( 'Button URL', 'event_espresso' )) |
|
56 | + array('html_label_text'=> __('Button URL', 'event_espresso')) |
|
57 | 57 | ); |
58 | 58 | $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input( |
59 | 59 | EEM_Payment_Method::instance()->scopes(), |
60 | - array( 'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename() . EEH_Template::get_help_tab_link( 'payment_methods_overview' )) |
|
60 | + array('html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename().EEH_Template::get_help_tab_link('payment_methods_overview')) |
|
61 | 61 | ); |
62 | 62 | //setup the currency options |
63 | 63 | $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input( |
64 | - EEM_Currency::instance()->get_all_currencies_usable_by( $this->_payment_method_type ), |
|
64 | + EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type), |
|
65 | 65 | array( |
66 | - 'html_label_text'=> __( 'Currencies Supported', 'event_espresso' ), |
|
66 | + 'html_label_text'=> __('Currencies Supported', 'event_espresso'), |
|
67 | 67 | 'required'=>TRUE |
68 | 68 | ) |
69 | 69 | ); |
70 | - $this->_subsections['PMD_order'] = new EE_Text_Input( array( |
|
71 | - 'html_help_text' => __( 'Lowest numbers will be shown first', 'event_espresso' ), |
|
70 | + $this->_subsections['PMD_order'] = new EE_Text_Input(array( |
|
71 | + 'html_help_text' => __('Lowest numbers will be shown first', 'event_espresso'), |
|
72 | 72 | 'normalization_strategy' => new EE_Int_Normalization(), |
73 | 73 | 'validation_strategies' => array( |
74 | 74 | new EE_Int_Validation_Strategy() |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | * @param string $name |
88 | 88 | * @throws EE_Error |
89 | 89 | */ |
90 | - public function _construct_finalize( $parent_form_section, $name ) { |
|
91 | - if( ! $this->_payment_method_type instanceof EE_PMT_Base ){ |
|
92 | - throw new EE_Error( sprintf( __( 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', 'event_espresso' ))); |
|
90 | + public function _construct_finalize($parent_form_section, $name) { |
|
91 | + if ( ! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
92 | + throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', 'event_espresso'))); |
|
93 | 93 | } |
94 | 94 | //set the name of this form based on the payment method type |
95 | - if( ! $this->_name && ! $name ){ |
|
96 | - $name = str_replace(" ","_",ucwords(str_replace("_"," ",($this->_payment_method_type->system_name()))))."_Settings_Form"; |
|
95 | + if ( ! $this->_name && ! $name) { |
|
96 | + $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))."_Settings_Form"; |
|
97 | 97 | } |
98 | - parent::_construct_finalize( $parent_form_section, $name ); |
|
98 | + parent::_construct_finalize($parent_form_section, $name); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @param $payment_method_type |
105 | 105 | * @throws EE_Error |
106 | 106 | */ |
107 | - public function set_payment_method_type( $payment_method_type ){ |
|
108 | - if( ! $payment_method_type instanceof EE_PMT_Base){ |
|
107 | + public function set_payment_method_type($payment_method_type) { |
|
108 | + if ( ! $payment_method_type instanceof EE_PMT_Base) { |
|
109 | 109 | throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type", "event_espresso"))); |
110 | 110 | } |
111 | 111 | $this->_payment_method_type = $payment_method_type; |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | * extends the model form section's save method to also save the extra meta field values |
118 | 118 | * @return int ID of the payment method inserted, or true on update |
119 | 119 | */ |
120 | - public function save(){ |
|
120 | + public function save() { |
|
121 | 121 | $parent_save_val = parent::save(); |
122 | - if( $this->_model_object && $this->_model_object->ID()){ |
|
123 | - foreach($this->_extra_meta_inputs as $input_name => $input){ |
|
122 | + if ($this->_model_object && $this->_model_object->ID()) { |
|
123 | + foreach ($this->_extra_meta_inputs as $input_name => $input) { |
|
124 | 124 | $this->_model_object->update_extra_meta($input_name, $input->normalized_value()); |
125 | 125 | } |
126 | 126 | } |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | $model_obj = $this->_model->ensure_is_obj($model_obj); |
138 | 138 | parent::populate_model_obj($model_obj); |
139 | 139 | $extra_meta = $model_obj->all_extra_meta_array(); |
140 | - foreach($this->_extra_meta_inputs as $input_name => $extra_meta_input){ |
|
141 | - if(isset($extra_meta[$input_name])){ |
|
140 | + foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) { |
|
141 | + if (isset($extra_meta[$input_name])) { |
|
142 | 142 | $extra_meta_input->set_default($extra_meta[$input_name]); |
143 | 143 | } |
144 | 144 | } |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | * gets the default name of this form section if none is specified |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - protected function _set_default_name_if_empty(){ |
|
154 | - if( ! $this->_name ){ |
|
155 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
156 | - $this->_name = $default_name; |
|
153 | + protected function _set_default_name_if_empty() { |
|
154 | + if ( ! $this->_name) { |
|
155 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
156 | + $this->_name = $default_name; |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * Gets all the extra meta inputs in this form |
164 | 164 | * @return EE_Form_Input_Base[] |
165 | 165 | */ |
166 | - public function extra_meta_inputs(){ |
|
166 | + public function extra_meta_inputs() { |
|
167 | 167 | return $this->_extra_meta_inputs; |
168 | 168 | } |
169 | 169 | } |
@@ -80,7 +80,7 @@ |
||
80 | 80 | /** |
81 | 81 | * Checks if that value is the one selected |
82 | 82 | * @param string|int $value unnormalized value option (string) |
83 | - * @return string |
|
83 | + * @return boolean |
|
84 | 84 | */ |
85 | 85 | protected function _check_if_option_selected( $value ){ |
86 | 86 | return $this->_input->raw_value() == $value ? TRUE : FALSE; |
@@ -11,47 +11,47 @@ discard block |
||
11 | 11 | * @since $VID:$ |
12 | 12 | * |
13 | 13 | */ |
14 | -class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{ |
|
14 | +class EE_Select_Display_Strategy extends EE_Display_Strategy_Base { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * |
18 | 18 | * @throws EE_Error |
19 | 19 | * @return string of html to display the field |
20 | 20 | */ |
21 | - function display(){ |
|
22 | - if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){ |
|
23 | - throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' ))); |
|
21 | + function display() { |
|
22 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
23 | + throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
24 | 24 | } |
25 | 25 | EE_Registry::instance()->load_helper('Array'); |
26 | 26 | |
27 | - $html = EEH_HTML::nl( 0, 'select' ); |
|
27 | + $html = EEH_HTML::nl(0, 'select'); |
|
28 | 28 | $html .= '<select'; |
29 | - $html .= ' id="' . $this->_input->html_id() . '"'; |
|
30 | - $html .= ' name="' . $this->_input->html_name() . '"'; |
|
31 | - $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
32 | - $html .= ' class="' . $class . '"'; |
|
29 | + $html .= ' id="'.$this->_input->html_id().'"'; |
|
30 | + $html .= ' name="'.$this->_input->html_name().'"'; |
|
31 | + $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class(); |
|
32 | + $html .= ' class="'.$class.'"'; |
|
33 | 33 | // add html5 required |
34 | 34 | |
35 | 35 | $html .= $this->_input->required() ? ' required' : ''; |
36 | - $html .= ' style="' . $this->_input->html_style() . '"'; |
|
36 | + $html .= ' style="'.$this->_input->html_style().'"'; |
|
37 | 37 | $html .= '>'; |
38 | 38 | |
39 | 39 | // EEH_HTML::indent( 1, 'select' ); |
40 | - if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) { |
|
41 | - EEH_HTML::indent( 1, 'optgroup' ); |
|
42 | - foreach( $this->_input->options() as $opt_group_label => $opt_group ){ |
|
43 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '<optgroup label="' . esc_attr( $opt_group_label ) . '">'; |
|
44 | - EEH_HTML::indent( 1, 'option' ); |
|
45 | - $html .= $this->_display_options( $opt_group ); |
|
40 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
41 | + EEH_HTML::indent(1, 'optgroup'); |
|
42 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
43 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
44 | + EEH_HTML::indent(1, 'option'); |
|
45 | + $html .= $this->_display_options($opt_group); |
|
46 | 46 | $html .= EEH_HTML::indent( -1, 'option' ); |
47 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
47 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
48 | 48 | } |
49 | 49 | EEH_HTML::indent( -1, 'optgroup' ); |
50 | 50 | } else { |
51 | - $html.=$this->_display_options( $this->_input->options() ); |
|
51 | + $html .= $this->_display_options($this->_input->options()); |
|
52 | 52 | } |
53 | 53 | |
54 | - $html.= EEH_HTML::nl( 0, 'select' ) . '</select>'; |
|
54 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
55 | 55 | // $html.= EEH_HTML::nl( -1, 'select' ) . '</select>'; |
56 | 56 | return $html; |
57 | 57 | } |
@@ -63,13 +63,13 @@ discard block |
||
63 | 63 | * @param array $options |
64 | 64 | * @return string |
65 | 65 | */ |
66 | - protected function _display_options($options){ |
|
66 | + protected function _display_options($options) { |
|
67 | 67 | $html = ''; |
68 | - EEH_HTML::indent( 1, 'option' ); |
|
69 | - foreach( $options as $value => $display_text ){ |
|
70 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
71 | - $selected = $this->_check_if_option_selected( $unnormalized_value ) ? ' selected="selected"' : ''; |
|
72 | - $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr( $unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
68 | + EEH_HTML::indent(1, 'option'); |
|
69 | + foreach ($options as $value => $display_text) { |
|
70 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
71 | + $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
|
72 | + $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>'; |
|
73 | 73 | } |
74 | 74 | EEH_HTML::indent( -1, 'option' ); |
75 | 75 | return $html; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param string|int $value unnormalized value option (string) |
83 | 83 | * @return string |
84 | 84 | */ |
85 | - protected function _check_if_option_selected( $value ){ |
|
85 | + protected function _check_if_option_selected($value) { |
|
86 | 86 | return $this->_input->raw_value() == $value ? TRUE : FALSE; |
87 | 87 | } |
88 | 88 |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @param string $value_to_normalize |
14 | - * @return int|mixed|string |
|
14 | + * @return integer |
|
15 | 15 | * @throws \EE_Validation_Error |
16 | 16 | */ |
17 | 17 | public function normalize($value_to_normalize) { |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @subpackage |
8 | 8 | * @author Mike Nelson |
9 | 9 | */ |
10 | -class EE_Int_Normalization extends EE_Normalization_Strategy_Base{ |
|
10 | +class EE_Int_Normalization extends EE_Normalization_Strategy_Base { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @param string $value_to_normalize |
@@ -15,33 +15,33 @@ discard block |
||
15 | 15 | * @throws \EE_Validation_Error |
16 | 16 | */ |
17 | 17 | public function normalize($value_to_normalize) { |
18 | - if( is_int( $value_to_normalize ) ){ |
|
18 | + if (is_int($value_to_normalize)) { |
|
19 | 19 | return $value_to_normalize; |
20 | 20 | } |
21 | - if( ! is_string( $value_to_normalize )){ |
|
22 | - throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) ); |
|
21 | + if ( ! is_string($value_to_normalize)) { |
|
22 | + throw new EE_Validation_Error(sprintf(__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), print_r($value_to_normalize, TRUE), gettype($value_to_normalize))); |
|
23 | 23 | } |
24 | 24 | $thousands_separator = EE_Config::instance()->currency->thsnds; |
25 | - $value_to_normalize = str_replace( $thousands_separator, "", $value_to_normalize ); |
|
26 | - $value_to_normalize = str_replace( array(" ","\t"), '', $value_to_normalize ); |
|
27 | - if ( preg_match( '/^\d+$/', $value_to_normalize )) { |
|
28 | - return intval( $value_to_normalize ); |
|
25 | + $value_to_normalize = str_replace($thousands_separator, "", $value_to_normalize); |
|
26 | + $value_to_normalize = str_replace(array(" ", "\t"), '', $value_to_normalize); |
|
27 | + if (preg_match('/^\d+$/', $value_to_normalize)) { |
|
28 | + return intval($value_to_normalize); |
|
29 | 29 | } else { |
30 | 30 | //find if this input has a int validation strategy |
31 | 31 | //in which case, use its message |
32 | 32 | $validation_error_message = NULL; |
33 | - foreach( $this->_input->get_validation_strategies() as $validation_strategy ){ |
|
34 | - if( $validation_strategy instanceof EE_Int_Validation_Strategy ){ |
|
33 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
34 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
35 | 35 | $validation_error_message = $validation_strategy->get_validation_error_message(); |
36 | 36 | } |
37 | 37 | } |
38 | 38 | //this really shouldn't ever happen because fields with a int normalization strategy |
39 | 39 | //should also have a int validation strategy, but in case it doesnt use the default |
40 | - if( ! $validation_error_message ){ |
|
40 | + if ( ! $validation_error_message) { |
|
41 | 41 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
42 | 42 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
43 | 43 | } |
44 | - throw new EE_Validation_Error( $validation_error_message, 'numeric_only' ); |
|
44 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * @param int $normalized_value |
51 | 51 | * @return string |
52 | 52 | */ |
53 | - public function unnormalize( $normalized_value ) { |
|
54 | - if( empty( $normalized_value ) ){ |
|
53 | + public function unnormalize($normalized_value) { |
|
54 | + if (empty($normalized_value)) { |
|
55 | 55 | return '0'; |
56 | - }else{ |
|
56 | + } else { |
|
57 | 57 | return "$normalized_value"; |
58 | 58 | } |
59 | 59 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | //so in case teh IPN is arriving later, let's try to process an IPN! |
91 | 91 | if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
92 | 92 | return $this->handle_ipn($_POST, $transaction ); |
93 | - }else{ |
|
93 | + } else{ |
|
94 | 94 | return parent::finalize_payment_for( $transaction ); |
95 | 95 | } |
96 | 96 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | * just checks the field isn't blank |
27 | 27 | * |
28 | 28 | * @param $normalized_value |
29 | - * @return bool |
|
29 | + * @return boolean|null |
|
30 | 30 | * @throws \EE_Validation_Error |
31 | 31 | */ |
32 | 32 | function validate($normalized_value) { |
@@ -8,16 +8,16 @@ discard block |
||
8 | 8 | * @since 4.6 |
9 | 9 | * |
10 | 10 | */ |
11 | -class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy{ |
|
11 | +class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param null $validation_error_message |
15 | 15 | */ |
16 | - public function __construct( $validation_error_message = NULL ) { |
|
17 | - if( ! $validation_error_message ){ |
|
16 | + public function __construct($validation_error_message = NULL) { |
|
17 | + if ( ! $validation_error_message) { |
|
18 | 18 | $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
19 | 19 | } |
20 | - parent::__construct( $validation_error_message ); |
|
20 | + parent::__construct($validation_error_message); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | * @throws \EE_Validation_Error |
31 | 31 | */ |
32 | 32 | function validate($normalized_value) { |
33 | - if( $normalized_value && ! $this->_validate_email($normalized_value) ){ |
|
34 | - throw new EE_Validation_Error( $this->get_validation_error_message(), 'required'); |
|
33 | + if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
34 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - function get_jquery_validation_rule_array(){ |
|
44 | - return array( 'email'=>true, 'messages' => array( 'email' => $this->get_validation_error_message() ) ); |
|
43 | + function get_jquery_validation_rule_array() { |
|
44 | + return array('email'=>true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | { |
58 | 58 | $isValid = true; |
59 | 59 | $atIndex = strrpos($email, "@"); |
60 | - if (is_bool($atIndex) && !$atIndex) |
|
60 | + if (is_bool($atIndex) && ! $atIndex) |
|
61 | 61 | { |
62 | 62 | $isValid = false; |
63 | 63 | } |
64 | 64 | else |
65 | 65 | { |
66 | - $domain = substr($email, $atIndex+1); |
|
66 | + $domain = substr($email, $atIndex + 1); |
|
67 | 67 | $local = substr($email, 0, $atIndex); |
68 | 68 | $localLen = strlen($local); |
69 | 69 | $domainLen = strlen($domain); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | // domain part length exceeded |
78 | 78 | $isValid = false; |
79 | 79 | } |
80 | - else if ($local[0] == '.' || $local[$localLen-1] == '.') |
|
80 | + else if ($local[0] == '.' || $local[$localLen - 1] == '.') |
|
81 | 81 | { |
82 | 82 | // local part starts or ends with '.' |
83 | 83 | $isValid = false; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | // local part has two consecutive dots |
88 | 88 | $isValid = false; |
89 | 89 | } |
90 | - else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) |
|
90 | + else if ( ! preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) |
|
91 | 91 | { |
92 | 92 | // character not valid in domain part |
93 | 93 | $isValid = false; |
@@ -97,14 +97,13 @@ discard block |
||
97 | 97 | // domain part has two consecutive dots |
98 | 98 | $isValid = false; |
99 | 99 | } |
100 | - else if |
|
101 | -(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', |
|
102 | - str_replace("\\\\","",$local))) |
|
100 | + else if ( ! preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', |
|
101 | + str_replace("\\\\", "", $local))) |
|
103 | 102 | { |
104 | 103 | // character not valid in local part unless |
105 | 104 | // local part is quoted |
106 | - if (!preg_match('/^"(\\\\"|[^"])+"$/', |
|
107 | - str_replace("\\\\","",$local))) |
|
105 | + if ( ! preg_match('/^"(\\\\"|[^"])+"$/', |
|
106 | + str_replace("\\\\", "", $local))) |
|
108 | 107 | { |
109 | 108 | $isValid = false; |
110 | 109 | } |
@@ -60,8 +60,7 @@ discard block |
||
60 | 60 | if (is_bool($atIndex) && !$atIndex) |
61 | 61 | { |
62 | 62 | $isValid = false; |
63 | - } |
|
64 | - else |
|
63 | + } else |
|
65 | 64 | { |
66 | 65 | $domain = substr($email, $atIndex+1); |
67 | 66 | $local = substr($email, 0, $atIndex); |
@@ -71,33 +70,27 @@ discard block |
||
71 | 70 | { |
72 | 71 | // local part length exceeded |
73 | 72 | $isValid = false; |
74 | - } |
|
75 | - else if ($domainLen < 1 || $domainLen > 255) |
|
73 | + } else if ($domainLen < 1 || $domainLen > 255) |
|
76 | 74 | { |
77 | 75 | // domain part length exceeded |
78 | 76 | $isValid = false; |
79 | - } |
|
80 | - else if ($local[0] == '.' || $local[$localLen-1] == '.') |
|
77 | + } else if ($local[0] == '.' || $local[$localLen-1] == '.') |
|
81 | 78 | { |
82 | 79 | // local part starts or ends with '.' |
83 | 80 | $isValid = false; |
84 | - } |
|
85 | - else if (preg_match('/\\.\\./', $local)) |
|
81 | + } else if (preg_match('/\\.\\./', $local)) |
|
86 | 82 | { |
87 | 83 | // local part has two consecutive dots |
88 | 84 | $isValid = false; |
89 | - } |
|
90 | - else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) |
|
85 | + } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) |
|
91 | 86 | { |
92 | 87 | // character not valid in domain part |
93 | 88 | $isValid = false; |
94 | - } |
|
95 | - else if (preg_match('/\\.\\./', $domain)) |
|
89 | + } else if (preg_match('/\\.\\./', $domain)) |
|
96 | 90 | { |
97 | 91 | // domain part has two consecutive dots |
98 | 92 | $isValid = false; |
99 | - } |
|
100 | - else if |
|
93 | + } else if |
|
101 | 94 | (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', |
102 | 95 | str_replace("\\\\","",$local))) |
103 | 96 | { |
@@ -1,18 +1,18 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * Class EE_Email_Validation_Strategy |
|
4 | - * |
|
5 | - * @package Event Espresso |
|
6 | - * @subpackage core |
|
7 | - * @author Mike Nelson |
|
8 | - * @since 4.6 |
|
9 | - * |
|
10 | - */ |
|
3 | + * Class EE_Email_Validation_Strategy |
|
4 | + * |
|
5 | + * @package Event Espresso |
|
6 | + * @subpackage core |
|
7 | + * @author Mike Nelson |
|
8 | + * @since 4.6 |
|
9 | + * |
|
10 | + */ |
|
11 | 11 | class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy{ |
12 | 12 | |
13 | 13 | /** |
14 | - * @param null $validation_error_message |
|
15 | - */ |
|
14 | + * @param null $validation_error_message |
|
15 | + */ |
|
16 | 16 | public function __construct( $validation_error_message = NULL ) { |
17 | 17 | if( ! $validation_error_message ){ |
18 | 18 | $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | |
40 | 40 | /** |
41 | - * @return array |
|
42 | - */ |
|
41 | + * @return array |
|
42 | + */ |
|
43 | 43 | function get_jquery_validation_rule_array(){ |
44 | 44 | return array( 'email'=>true, 'messages' => array( 'email' => $this->get_validation_error_message() ) ); |
45 | 45 | } |
@@ -59,56 +59,56 @@ discard block |
||
59 | 59 | $atIndex = strrpos($email, "@"); |
60 | 60 | if (is_bool($atIndex) && !$atIndex) |
61 | 61 | { |
62 | - $isValid = false; |
|
62 | + $isValid = false; |
|
63 | 63 | } |
64 | 64 | else |
65 | 65 | { |
66 | - $domain = substr($email, $atIndex+1); |
|
67 | - $local = substr($email, 0, $atIndex); |
|
68 | - $localLen = strlen($local); |
|
69 | - $domainLen = strlen($domain); |
|
70 | - if ($localLen < 1 || $localLen > 64) |
|
71 | - { |
|
72 | - // local part length exceeded |
|
73 | - $isValid = false; |
|
74 | - } |
|
75 | - else if ($domainLen < 1 || $domainLen > 255) |
|
76 | - { |
|
77 | - // domain part length exceeded |
|
78 | - $isValid = false; |
|
79 | - } |
|
80 | - else if ($local[0] == '.' || $local[$localLen-1] == '.') |
|
81 | - { |
|
82 | - // local part starts or ends with '.' |
|
83 | - $isValid = false; |
|
84 | - } |
|
85 | - else if (preg_match('/\\.\\./', $local)) |
|
86 | - { |
|
87 | - // local part has two consecutive dots |
|
88 | - $isValid = false; |
|
89 | - } |
|
90 | - else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) |
|
91 | - { |
|
92 | - // character not valid in domain part |
|
93 | - $isValid = false; |
|
94 | - } |
|
95 | - else if (preg_match('/\\.\\./', $domain)) |
|
96 | - { |
|
97 | - // domain part has two consecutive dots |
|
98 | - $isValid = false; |
|
99 | - } |
|
100 | - else if |
|
66 | + $domain = substr($email, $atIndex+1); |
|
67 | + $local = substr($email, 0, $atIndex); |
|
68 | + $localLen = strlen($local); |
|
69 | + $domainLen = strlen($domain); |
|
70 | + if ($localLen < 1 || $localLen > 64) |
|
71 | + { |
|
72 | + // local part length exceeded |
|
73 | + $isValid = false; |
|
74 | + } |
|
75 | + else if ($domainLen < 1 || $domainLen > 255) |
|
76 | + { |
|
77 | + // domain part length exceeded |
|
78 | + $isValid = false; |
|
79 | + } |
|
80 | + else if ($local[0] == '.' || $local[$localLen-1] == '.') |
|
81 | + { |
|
82 | + // local part starts or ends with '.' |
|
83 | + $isValid = false; |
|
84 | + } |
|
85 | + else if (preg_match('/\\.\\./', $local)) |
|
86 | + { |
|
87 | + // local part has two consecutive dots |
|
88 | + $isValid = false; |
|
89 | + } |
|
90 | + else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) |
|
91 | + { |
|
92 | + // character not valid in domain part |
|
93 | + $isValid = false; |
|
94 | + } |
|
95 | + else if (preg_match('/\\.\\./', $domain)) |
|
96 | + { |
|
97 | + // domain part has two consecutive dots |
|
98 | + $isValid = false; |
|
99 | + } |
|
100 | + else if |
|
101 | 101 | (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', |
102 | - str_replace("\\\\","",$local))) |
|
103 | - { |
|
104 | - // character not valid in local part unless |
|
105 | - // local part is quoted |
|
106 | - if (!preg_match('/^"(\\\\"|[^"])+"$/', |
|
107 | - str_replace("\\\\","",$local))) |
|
108 | - { |
|
109 | - $isValid = false; |
|
110 | - } |
|
111 | - } |
|
102 | + str_replace("\\\\","",$local))) |
|
103 | + { |
|
104 | + // character not valid in local part unless |
|
105 | + // local part is quoted |
|
106 | + if (!preg_match('/^"(\\\\"|[^"])+"$/', |
|
107 | + str_replace("\\\\","",$local))) |
|
108 | + { |
|
109 | + $isValid = false; |
|
110 | + } |
|
111 | + } |
|
112 | 112 | //don't check the DNS records... just personal preference |
113 | 113 | // if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) |
114 | 114 | // { |