@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * |
@@ -37,33 +37,33 @@ discard block |
||
37 | 37 | * @access protected |
38 | 38 | * @return EEM_Payment_Method |
39 | 39 | */ |
40 | - protected function __construct( $timezone = NULL ) { |
|
41 | - $this->singlular_item = __( 'Payment Method', 'event_espresso' ); |
|
42 | - $this->plural_item = __( 'Payment Methods', 'event_espresso' ); |
|
43 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table( 'esp_payment_method', 'PMD_ID' ) ); |
|
40 | + protected function __construct($timezone = NULL) { |
|
41 | + $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
42 | + $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
43 | + $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID')); |
|
44 | 44 | $this->_fields = array( |
45 | 45 | 'Payment_Method' => array( |
46 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( 'PMD_ID', __( "ID", 'event_espresso' ) ), |
|
47 | - 'PMD_type' => new EE_Plain_Text_Field( 'PMD_type', __( "Payment Method Type", 'event_espresso' ), FALSE, 'Admin_Only' ), |
|
48 | - 'PMD_name' => new EE_Plain_Text_Field( 'PMD_name', __( "Name", 'event_espresso' ), FALSE ), |
|
49 | - 'PMD_desc' => new EE_Post_Content_Field( 'PMD_desc', __( "Description", 'event_espresso' ), FALSE, '' ), |
|
50 | - 'PMD_admin_name' => new EE_Plain_Text_Field( 'PMD_admin_name', __( "Admin-Only Name", 'event_espresso' ), TRUE ), |
|
51 | - 'PMD_admin_desc' => new EE_Post_Content_Field( 'PMD_admin_desc', __( "Admin-Only Description", 'event_espresso' ), TRUE ), |
|
52 | - 'PMD_slug' => new EE_Slug_Field( 'PMD_slug', __( "Slug", 'event_espresso' ), FALSE ), |
|
53 | - 'PMD_order' => new EE_Integer_Field( 'PMD_order', __( "Order", 'event_espresso' ), FALSE, 0 ), |
|
54 | - 'PMD_debug_mode' => new EE_Boolean_Field( 'PMD_debug_mode', __( "Debug Mode On?", 'event_espresso' ), FALSE, FALSE ), |
|
55 | - 'PMD_wp_user' => new EE_WP_User_Field( 'PMD_wp_user', __( "Payment Method Creator ID", 'event_espresso' ), FALSE ), |
|
56 | - 'PMD_open_by_default' => new EE_Boolean_Field( 'PMD_open_by_default', __( "Open by Default?", 'event_espresso' ), FALSE, FALSE ), 'PMD_button_url' => new EE_Plain_Text_Field( 'PMD_button_url', __( "Button URL", 'event_espresso' ), TRUE, '' ), |
|
57 | - 'PMD_scope' => new EE_Serialized_Text_Field( 'PMD_scope', __( "Usable From?", 'event_espresso' ), FALSE, array() ), //possible values currently are 'CART','ADMIN','API' |
|
46 | + 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
47 | + 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), FALSE, 'Admin_Only'), |
|
48 | + 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), FALSE), |
|
49 | + 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), FALSE, ''), |
|
50 | + 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), TRUE), |
|
51 | + 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), TRUE), |
|
52 | + 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), FALSE), |
|
53 | + 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), FALSE, 0), |
|
54 | + 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), FALSE, FALSE), |
|
55 | + 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), FALSE), |
|
56 | + 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), FALSE, FALSE), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), TRUE, ''), |
|
57 | + 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), FALSE, array()), //possible values currently are 'CART','ADMIN','API' |
|
58 | 58 | ) ); |
59 | 59 | $this->_model_relations = array( |
60 | 60 | // 'Event'=>new EE_HABTM_Relation('Event_Payment_Method'), |
61 | 61 | 'Payment' => new EE_Has_Many_Relation(), |
62 | - 'Currency' => new EE_HABTM_Relation( 'Currency_Payment_Method' ), |
|
62 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
63 | 63 | 'Transaction' => new EE_Has_Many_Relation(), |
64 | 64 | 'WP_User' => new EE_Belongs_To_Relation(), |
65 | 65 | ); |
66 | - parent::__construct( $timezone ); |
|
66 | + parent::__construct($timezone); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @param string $slug |
74 | 74 | * @return EE_Payment_Method |
75 | 75 | */ |
76 | - public function get_one_by_slug( $slug ) { |
|
77 | - return $this->get_one( array( array( 'PMD_slug' => $slug ) ) ); |
|
76 | + public function get_one_by_slug($slug) { |
|
77 | + return $this->get_one(array(array('PMD_slug' => $slug))); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | return apply_filters( |
89 | 89 | 'FHEE__EEM_Payment_Method__scopes', |
90 | 90 | array( |
91 | - self::scope_cart => __( "Front-end Registration Page", 'event_espresso' ), |
|
92 | - self::scope_admin => __( "Admin Registration Page (no online processing)", 'event_espresso' ) |
|
91 | + self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
92 | + self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
93 | 93 | ) |
94 | 94 | ); |
95 | 95 | } |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
102 | 102 | * @return boolean |
103 | 103 | */ |
104 | - public function is_valid_scope( $scope ) { |
|
104 | + public function is_valid_scope($scope) { |
|
105 | 105 | $scopes = $this->scopes(); |
106 | - if ( isset( $scopes[ $scope ] ) ) { |
|
106 | + if (isset($scopes[$scope])) { |
|
107 | 107 | return TRUE; |
108 | 108 | } else { |
109 | 109 | return FALSE; |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | * @throws EE_Error |
120 | 120 | * @return EE_Payment_Method[] |
121 | 121 | */ |
122 | - public function get_all_active( $scope = NULL, $query_params = array() ) { |
|
123 | - if( ! isset( $query_params[ 'order_by' ] ) && ! isset( $query_params[ 'order' ] ) ) { |
|
124 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
122 | + public function get_all_active($scope = NULL, $query_params = array()) { |
|
123 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
124 | + $query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC'); |
|
125 | 125 | } |
126 | - return $this->get_all( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
126 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param array $query_params |
133 | 133 | * @return int |
134 | 134 | */ |
135 | - public function count_active( $scope = NULL, $query_params = array() ){ |
|
136 | - return $this->count( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
135 | + public function count_active($scope = NULL, $query_params = array()) { |
|
136 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -144,21 +144,21 @@ discard block |
||
144 | 144 | * @return array like param of EEM_Base::get_all() |
145 | 145 | * @throws EE_Error |
146 | 146 | */ |
147 | - protected function _get_query_params_for_all_active( $scope = NULL, $query_params = array() ){ |
|
148 | - if ( $scope ) { |
|
149 | - if ( $this->is_valid_scope( $scope ) ) { |
|
150 | - return array_replace_recursive( array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params ); |
|
147 | + protected function _get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
148 | + if ($scope) { |
|
149 | + if ($this->is_valid_scope($scope)) { |
|
150 | + return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params); |
|
151 | 151 | } else { |
152 | - throw new EE_Error( sprintf( __( "'%s' is not a valid scope for a payment method", "event_espresso" ), $scope ) ); |
|
152 | + throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
153 | 153 | } |
154 | 154 | } else { |
155 | 155 | $acceptable_scopes = array(); |
156 | 156 | $count = 0; |
157 | - foreach ( $this->scopes() as $scope_name => $desc ) { |
|
157 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
158 | 158 | $count++; |
159 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
159 | + $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%'); |
|
160 | 160 | } |
161 | - return array_replace_recursive( array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params ); |
|
161 | + return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * @return array like param of EEM_Base::get_all() |
171 | 171 | * @throws EE_Error |
172 | 172 | */ |
173 | - public function get_query_params_for_all_active( $scope = NULL, $query_params = array() ) { |
|
174 | - return $this->_get_query_params_for_all_active( $scope, $query_params ); |
|
173 | + public function get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
174 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param array $query_params |
182 | 182 | * @return EE_Payment_Method |
183 | 183 | */ |
184 | - public function get_one_active( $scope = NULL, $query_params = array() ) { |
|
185 | - return $this->get_one( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
184 | + public function get_one_active($scope = NULL, $query_params = array()) { |
|
185 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * @param string $type |
193 | 193 | * @return EE_Payment_Method |
194 | 194 | */ |
195 | - public function get_one_of_type( $type ) { |
|
196 | - return $this->get_one( array( array( 'PMD_type' => $type ) ) ); |
|
195 | + public function get_one_of_type($type) { |
|
196 | + return $this->get_one(array(array('PMD_type' => $type))); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -206,22 +206,22 @@ discard block |
||
206 | 206 | * @return EE_Payment_Method |
207 | 207 | * @throws EE_Error |
208 | 208 | */ |
209 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ) { |
|
209 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
210 | 210 | //first: check if it's a slug |
211 | - if( is_string( $base_class_obj_or_id ) ) { |
|
212 | - $obj = $this->get_one_by_slug( $base_class_obj_or_id ); |
|
213 | - if( $obj ) { |
|
211 | + if (is_string($base_class_obj_or_id)) { |
|
212 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
213 | + if ($obj) { |
|
214 | 214 | return $obj; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | //ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
218 | 218 | try { |
219 | - return parent::ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db ); |
|
219 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
220 | 220 | } |
221 | - catch ( EE_Error $e ) { |
|
221 | + catch (EE_Error $e) { |
|
222 | 222 | //handle it outside the catch |
223 | 223 | } |
224 | - throw new EE_Error( sprintf( __( "'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso" ), $base_class_obj_or_id ) ); |
|
224 | + throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | |
@@ -232,12 +232,12 @@ discard block |
||
232 | 232 | * @param mixed $base_obj_or_id_or_slug |
233 | 233 | * @return int |
234 | 234 | */ |
235 | - function ensure_is_ID( $base_obj_or_id_or_slug ) { |
|
236 | - if ( is_string( $base_obj_or_id_or_slug ) ) { |
|
235 | + function ensure_is_ID($base_obj_or_id_or_slug) { |
|
236 | + if (is_string($base_obj_or_id_or_slug)) { |
|
237 | 237 | //assume it's a slug |
238 | - $base_obj_or_id_or_slug = $this->get_one_by_slug( $base_obj_or_id_or_slug ); |
|
238 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
239 | 239 | } |
240 | - return parent::ensure_is_ID( $base_obj_or_id_or_slug ); |
|
240 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | |
@@ -246,36 +246,36 @@ discard block |
||
246 | 246 | * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
247 | 247 | * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
248 | 248 | */ |
249 | - function verify_button_urls( $payment_methods = NULL ) { |
|
250 | - $payment_methods = is_array( $payment_methods ) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
251 | - foreach ( $payment_methods as $payment_method ) { |
|
249 | + function verify_button_urls($payment_methods = NULL) { |
|
250 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
251 | + foreach ($payment_methods as $payment_method) { |
|
252 | 252 | try { |
253 | 253 | $current_button_url = $payment_method->button_url(); |
254 | - $buttons_urls_to_try = apply_filters( 'FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
255 | - 'current_ssl' => str_replace( "http://", "https://", $current_button_url ), |
|
256 | - 'current' => str_replace( "https://", "http://", $current_button_url ), |
|
257 | - 'default_ssl' => str_replace( "http://", "https://", $payment_method->type_obj()->default_button_url() ), |
|
258 | - 'default' => str_replace( "https://", "http://", $payment_method->type_obj()->default_button_url() ), |
|
259 | - ) ); |
|
260 | - foreach( $buttons_urls_to_try as $button_url_to_try ) { |
|
261 | - if( |
|
254 | + $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
255 | + 'current_ssl' => str_replace("http://", "https://", $current_button_url), |
|
256 | + 'current' => str_replace("https://", "http://", $current_button_url), |
|
257 | + 'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()), |
|
258 | + 'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()), |
|
259 | + )); |
|
260 | + foreach ($buttons_urls_to_try as $button_url_to_try) { |
|
261 | + if ( |
|
262 | 262 | (//this is the current url and it exists, regardless of SSL issues |
263 | 263 | $button_url_to_try == $current_button_url && |
264 | 264 | EEH_URL::remote_file_exists( |
265 | 265 | $button_url_to_try, |
266 | 266 | array( |
267 | 267 | 'sslverify' => false, |
268 | - 'limit_response_size' => 4095,//we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
268 | + 'limit_response_size' => 4095, //we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
269 | 269 | ) ) |
270 | 270 | ) |
271 | 271 | || |
272 | 272 | (//this is NOT the current url and it exists with a working SSL cert |
273 | 273 | $button_url_to_try != $current_button_url && |
274 | - EEH_URL::remote_file_exists( $button_url_to_try ) |
|
274 | + EEH_URL::remote_file_exists($button_url_to_try) |
|
275 | 275 | ) ) { |
276 | - if( $current_button_url != $button_url_to_try ){ |
|
277 | - $payment_method->save( array( 'PMD_button_url' => $button_url_to_try ) ); |
|
278 | - EE_Error::add_attention( sprintf( __( "Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso" ), $payment_method->name(), $button_url_to_try ) ); |
|
276 | + if ($current_button_url != $button_url_to_try) { |
|
277 | + $payment_method->save(array('PMD_button_url' => $button_url_to_try)); |
|
278 | + EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try)); |
|
279 | 279 | } |
280 | 280 | //this image exists. So if wasn't set before, now it is; |
281 | 281 | //or if it was already set, we have nothing to do |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | } |
286 | - catch ( EE_Error $e ) { |
|
287 | - $payment_method->set_active( FALSE ); |
|
286 | + catch (EE_Error $e) { |
|
287 | + $payment_method->set_active(FALSE); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | } |
@@ -298,29 +298,29 @@ discard block |
||
298 | 298 | * @param array $rows |
299 | 299 | * @return EE_Payment_Method[] |
300 | 300 | */ |
301 | - protected function _create_objects( $rows = array() ) { |
|
302 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
303 | - $payment_methods = parent::_create_objects( $rows ); |
|
301 | + protected function _create_objects($rows = array()) { |
|
302 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
303 | + $payment_methods = parent::_create_objects($rows); |
|
304 | 304 | /* @var $payment_methods EE_Payment_Method[] */ |
305 | 305 | $usable_payment_methods = array(); |
306 | - foreach ( $payment_methods as $key => $payment_method ) { |
|
307 | - if ( EE_Payment_Method_Manager::instance()->payment_method_type_exists( $payment_method->type() ) ) { |
|
308 | - $usable_payment_methods[ $key ] = $payment_method; |
|
306 | + foreach ($payment_methods as $key => $payment_method) { |
|
307 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
308 | + $usable_payment_methods[$key] = $payment_method; |
|
309 | 309 | //some payment methods enqueue their scripts in EE_PMT_*::__construct |
310 | 310 | //which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
311 | 311 | //its scripts). but for backwards-compat we should continue to do that |
312 | 312 | $payment_method->type_obj(); |
313 | - } elseif( $payment_method->active() ) { |
|
313 | + } elseif ($payment_method->active()) { |
|
314 | 314 | //only deactivate and notify the admin if the payment is active somewhere |
315 | 315 | $payment_method->deactivate(); |
316 | 316 | $payment_method->save(); |
317 | 317 | EE_Error::add_persistent_admin_notice( |
318 | - 'auto-deactivated-' . $payment_method->type(), |
|
318 | + 'auto-deactivated-'.$payment_method->type(), |
|
319 | 319 | sprintf( |
320 | - __( 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', 'event_espresso' ), |
|
320 | + __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', 'event_espresso'), |
|
321 | 321 | $payment_method->admin_name(), |
322 | 322 | '<br />', |
323 | - '<a href="' . admin_url('plugins.php') . '">', |
|
323 | + '<a href="'.admin_url('plugins.php').'">', |
|
324 | 324 | '</a>' |
325 | 325 | ), |
326 | 326 | true |
@@ -340,11 +340,11 @@ discard block |
||
340 | 340 | * @param string $scope @see EEM_Payment_Method::get_all_for_events |
341 | 341 | * @return EE_Payment_Method[] |
342 | 342 | */ |
343 | - public function get_all_for_transaction( $transaction, $scope ) { |
|
343 | + public function get_all_for_transaction($transaction, $scope) { |
|
344 | 344 | //give addons a chance to override what payment methods are chosen based on the transaction |
345 | 345 | return apply_filters( |
346 | 346 | 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
347 | - $this->get_all_active( $scope, array( 'group_by' => 'PMD_type' ) ), |
|
347 | + $this->get_all_active($scope, array('group_by' => 'PMD_type')), |
|
348 | 348 | $transaction, |
349 | 349 | $scope |
350 | 350 | ); |
@@ -360,16 +360,16 @@ discard block |
||
360 | 360 | * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
361 | 361 | * @return EE_Payment|null |
362 | 362 | */ |
363 | - public function get_last_used_for_registration( $registration_or_reg_id ) { |
|
364 | - $registration_id = EEM_Registration::instance()->ensure_is_ID( $registration_or_reg_id ); |
|
363 | + public function get_last_used_for_registration($registration_or_reg_id) { |
|
364 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
365 | 365 | |
366 | 366 | $query_params = array( |
367 | 367 | 0 => array( |
368 | 368 | 'Payment.Registration.REG_ID' => $registration_id, |
369 | 369 | ), |
370 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
370 | + 'order_by' => array('Payment.PAY_ID' => 'DESC') |
|
371 | 371 | ); |
372 | - return $this->get_one( $query_params ); |
|
372 | + return $this->get_one($query_params); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | * Checks if that value is the one selected |
85 | 85 | * |
86 | 86 | * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
87 | - * @return string |
|
87 | + * @return boolean |
|
88 | 88 | */ |
89 | 89 | protected function _check_if_option_selected($option_value ){ |
90 | 90 | return $option_value === $this->_input->raw_value(); |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) { |
39 | 39 | EEH_HTML::indent( 1, 'optgroup' ); |
40 | 40 | foreach( $this->_input->options() as $opt_group_label => $opt_group ){ |
41 | - if ( ! empty($opt_group_label)) { |
|
42 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
43 | - } |
|
41 | + if ( ! empty($opt_group_label)) { |
|
42 | + $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
43 | + } |
|
44 | 44 | EEH_HTML::indent( 1, 'option' ); |
45 | 45 | $html .= $this->_display_options( $opt_group ); |
46 | 46 | EEH_HTML::indent( -1, 'option' ); |
47 | - if ( ! empty($opt_group_label)) { |
|
48 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
49 | - } |
|
47 | + if ( ! empty($opt_group_label)) { |
|
48 | + $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | EEH_HTML::indent( -1, 'optgroup' ); |
52 | 52 | } else { |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $html = ''; |
69 | 69 | EEH_HTML::indent( 1, 'option' ); |
70 | 70 | foreach( $options as $value => $display_text ){ |
71 | - //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
72 | - //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
73 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
74 | - $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : ''; |
|
75 | - $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
71 | + //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
72 | + //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
73 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
74 | + $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : ''; |
|
75 | + $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
76 | 76 | } |
77 | 77 | EEH_HTML::indent( -1, 'option' ); |
78 | 78 | return $html; |
@@ -11,49 +11,49 @@ 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 | |
26 | - $html = EEH_HTML::nl( 0, 'select' ); |
|
26 | + $html = EEH_HTML::nl(0, 'select'); |
|
27 | 27 | $html .= '<select'; |
28 | - $html .= ' id="' . $this->_input->html_id() . '"'; |
|
29 | - $html .= ' name="' . $this->_input->html_name() . '"'; |
|
30 | - $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
31 | - $html .= ' class="' . $class . '"'; |
|
28 | + $html .= ' id="'.$this->_input->html_id().'"'; |
|
29 | + $html .= ' name="'.$this->_input->html_name().'"'; |
|
30 | + $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class(); |
|
31 | + $html .= ' class="'.$class.'"'; |
|
32 | 32 | // add html5 required |
33 | 33 | $html .= $this->_input->required() ? ' required' : ''; |
34 | - $html .= ' style="' . $this->_input->html_style() . '"'; |
|
35 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
34 | + $html .= ' style="'.$this->_input->html_style().'"'; |
|
35 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
36 | 36 | $html .= '>'; |
37 | 37 | |
38 | - if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) { |
|
39 | - EEH_HTML::indent( 1, 'optgroup' ); |
|
40 | - foreach( $this->_input->options() as $opt_group_label => $opt_group ){ |
|
38 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
39 | + EEH_HTML::indent(1, 'optgroup'); |
|
40 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
41 | 41 | if ( ! empty($opt_group_label)) { |
42 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
42 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
43 | 43 | } |
44 | - EEH_HTML::indent( 1, 'option' ); |
|
45 | - $html .= $this->_display_options( $opt_group ); |
|
44 | + EEH_HTML::indent(1, 'option'); |
|
45 | + $html .= $this->_display_options($opt_group); |
|
46 | 46 | EEH_HTML::indent( -1, 'option' ); |
47 | 47 | if ( ! empty($opt_group_label)) { |
48 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
48 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | EEH_HTML::indent( -1, 'optgroup' ); |
52 | 52 | } else { |
53 | - $html.=$this->_display_options( $this->_input->options() ); |
|
53 | + $html .= $this->_display_options($this->_input->options()); |
|
54 | 54 | } |
55 | 55 | |
56 | - $html.= EEH_HTML::nl( 0, 'select' ) . '</select>'; |
|
56 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
57 | 57 | return $html; |
58 | 58 | } |
59 | 59 | |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | * @param array $options |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - protected function _display_options($options){ |
|
67 | + protected function _display_options($options) { |
|
68 | 68 | $html = ''; |
69 | - EEH_HTML::indent( 1, 'option' ); |
|
70 | - foreach( $options as $value => $display_text ){ |
|
69 | + EEH_HTML::indent(1, 'option'); |
|
70 | + foreach ($options as $value => $display_text) { |
|
71 | 71 | //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
72 | 72 | //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
73 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
74 | - $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : ''; |
|
75 | - $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
73 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
74 | + $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
|
75 | + $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>'; |
|
76 | 76 | } |
77 | 77 | EEH_HTML::indent( -1, 'option' ); |
78 | 78 | return $html; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - protected function _check_if_option_selected($option_value ){ |
|
89 | + protected function _check_if_option_selected($option_value) { |
|
90 | 90 | return $option_value === $this->_input->raw_value(); |
91 | 91 | } |
92 | 92 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,320 +16,320 @@ discard block |
||
16 | 16 | class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * array of available options to choose as an answer |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $_options = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * whether to display the html_label_text above the checkbox/radio button options |
|
28 | - * |
|
29 | - * @var boolean |
|
30 | - */ |
|
31 | - protected $_display_html_label_text = true; |
|
32 | - |
|
33 | - /** |
|
34 | - * whether to display an question option description as part of the input label |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_use_desc_in_label = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * strlen() result for the longest input value (what gets displayed in the label) |
|
42 | - * this is used to apply a css class to the input label |
|
43 | - * |
|
44 | - * @var int |
|
45 | - */ |
|
46 | - protected $_label_size = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * whether to enforce the label size value passed in the constructor |
|
50 | - * |
|
51 | - * @var boolean |
|
52 | - */ |
|
53 | - protected $_enforce_label_size = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * whether to allow multiple selections (ie, the value of this input should be an array) |
|
57 | - * or not (ie, the value should be a simple int, string, etc) |
|
58 | - * |
|
59 | - * @var boolean |
|
60 | - */ |
|
61 | - protected $_multiple_selections = false; |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param array $answer_options |
|
67 | - * @param array $input_settings { |
|
68 | - * @type int|string $label_size |
|
69 | - * @type boolean $display_html_label_text |
|
70 | - * } |
|
71 | - * And all the options accepted by EE_Form_Input_Base |
|
72 | - */ |
|
73 | - public function __construct($answer_options = array(), $input_settings = array()) |
|
74 | - { |
|
75 | - if (isset($input_settings['label_size'])) { |
|
76 | - $this->_set_label_size($input_settings['label_size']); |
|
77 | - if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
78 | - $this->_enforce_label_size = true; |
|
79 | - } |
|
80 | - } |
|
81 | - if (isset($input_settings['display_html_label_text'])) { |
|
82 | - $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
83 | - } |
|
84 | - $this->set_select_options($answer_options); |
|
85 | - parent::__construct($input_settings); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Sets the allowed options for this input. Also has the side-effect of |
|
92 | - * updating the normalization strategy to match the keys provided in the array |
|
93 | - * |
|
94 | - * @param array $answer_options |
|
95 | - * @return void just has the side-effect of setting the options for this input |
|
96 | - */ |
|
97 | - public function set_select_options($answer_options = array()) |
|
98 | - { |
|
99 | - $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
100 | - //get the first item in the select options and check it's type |
|
101 | - $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
102 | - ? $this->_process_question_options($answer_options) |
|
103 | - : $answer_options; |
|
104 | - //d( $this->_options ); |
|
105 | - $select_option_keys = array_keys($this->_options); |
|
106 | - // attempt to determine data type for values in order to set normalization type |
|
107 | - //purposefully only |
|
108 | - if ( |
|
109 | - count($this->_options) === 2 |
|
110 | - && ( |
|
111 | - (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
112 | - || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
113 | - ) |
|
114 | - ) { |
|
115 | - // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
116 | - $normalization = new EE_Boolean_Normalization(); |
|
117 | - } else { |
|
118 | - //are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
119 | - $all_ints = true; |
|
120 | - array_walk_recursive( |
|
121 | - $this->_options, |
|
122 | - function($value,$key) use (&$all_ints){ |
|
123 | - //is this a top-level key? ignore it |
|
124 | - if(! is_array($value) |
|
125 | - && ! is_int($key) |
|
126 | - && $key !== '' |
|
127 | - && $key !== null){ |
|
128 | - $all_ints = false; |
|
129 | - } |
|
130 | - } |
|
131 | - ); |
|
132 | - if ($all_ints) { |
|
133 | - $normalization = new EE_Int_Normalization(); |
|
134 | - } else { |
|
135 | - $normalization = new EE_Text_Normalization(); |
|
136 | - } |
|
137 | - } |
|
138 | - // does input type have multiple options ? |
|
139 | - if ($this->_multiple_selections) { |
|
140 | - $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
141 | - } else { |
|
142 | - $this->_set_normalization_strategy($normalization); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function options() |
|
152 | - { |
|
153 | - return $this->_options; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Returns an array which is guaranteed to not be multidimensional |
|
160 | - * |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function flat_options() |
|
164 | - { |
|
165 | - return $this->_flatten_select_options($this->options()); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Makes sure $arr is a flat array, not a multidimensional one |
|
172 | - * |
|
173 | - * @param array $arr |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - protected function _flatten_select_options($arr) |
|
177 | - { |
|
178 | - $flat_array = array(); |
|
179 | - if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
180 | - foreach ($arr as $sub_array) { |
|
181 | - foreach ((array)$sub_array as $key => $value) { |
|
182 | - $flat_array[$key] = $value; |
|
183 | - $this->_set_label_size($value); |
|
184 | - } |
|
185 | - } |
|
186 | - } else { |
|
187 | - foreach ($arr as $key => $value) { |
|
188 | - $flat_array[$key] = $value; |
|
189 | - $this->_set_label_size($value); |
|
190 | - } |
|
191 | - } |
|
192 | - return $flat_array; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param EE_Question_Option[] $question_options_array |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - protected function _process_question_options($question_options_array = array()) |
|
202 | - { |
|
203 | - $flat_array = array(); |
|
204 | - foreach ($question_options_array as $question_option) { |
|
205 | - if ($question_option instanceof EE_Question_Option) { |
|
206 | - $desc = ''; |
|
207 | - if ($this->_use_desc_in_label) { |
|
208 | - $desc = $question_option->desc(); |
|
209 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
210 | - } |
|
211 | - $value = $question_option->value(); |
|
212 | - // add value even if it's empty |
|
213 | - $flat_array[$value] = $value; |
|
214 | - // if both value and desc are not empty, then separate with a dash |
|
215 | - if ( ! empty($value) && ! empty($desc)) { |
|
216 | - $flat_array[$value] .= ' - ' . $desc; |
|
217 | - } else { |
|
218 | - // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
219 | - $flat_array[$value] .= $desc; |
|
220 | - } |
|
221 | - } elseif (is_array($question_option)) { |
|
222 | - $flat_array += $this->_flatten_select_options($question_option); |
|
223 | - } |
|
224 | - } |
|
225 | - return $flat_array; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * set_label_sizes |
|
232 | - * |
|
233 | - * @return void |
|
234 | - */ |
|
235 | - public function set_label_sizes() |
|
236 | - { |
|
237 | - // did the input settings specifically say to NOT set the label size dynamically ? |
|
238 | - if ( ! $this->_enforce_label_size) { |
|
239 | - foreach ($this->_options as $option) { |
|
240 | - // calculate the strlen of the label |
|
241 | - $this->_set_label_size($option); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * _set_label_size_class |
|
250 | - * |
|
251 | - * @param int|string $value |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - private function _set_label_size($value = '') |
|
255 | - { |
|
256 | - // determine length of option value |
|
257 | - $val_size = is_int($value) ? $value : strlen($value); |
|
258 | - // use new value if bigger than existing |
|
259 | - $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * get_label_size_class |
|
266 | - * |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function get_label_size_class() |
|
270 | - { |
|
271 | - $size = ' medium-lbl'; |
|
272 | - // use maximum option value length to determine label size |
|
273 | - if ($this->_label_size < 3) { |
|
274 | - $size = ' nano-lbl'; |
|
275 | - } else if ($this->_label_size < 6) { |
|
276 | - $size = ' micro-lbl'; |
|
277 | - } else if ($this->_label_size < 12) { |
|
278 | - $size = ' tiny-lbl'; |
|
279 | - } else if ($this->_label_size < 25) { |
|
280 | - $size = ' small-lbl'; |
|
281 | - } else if ($this->_label_size < 50) { |
|
282 | - $size = ' medium-lbl'; |
|
283 | - } else if ($this->_label_size >= 100) { |
|
284 | - $size = ' big-lbl'; |
|
285 | - } |
|
286 | - return $size; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Returns the pretty value for the normalized value |
|
293 | - * |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function pretty_value() |
|
297 | - { |
|
298 | - $options = $this->flat_options(); |
|
299 | - $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
300 | - if ( ! $this->_multiple_selections) { |
|
301 | - $unnormalized_value_choices = array($unnormalized_value_choices); |
|
302 | - } |
|
303 | - $pretty_strings = array(); |
|
304 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
305 | - if (isset($options[$unnormalized_value_choice])) { |
|
306 | - $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
307 | - } else { |
|
308 | - $pretty_strings[] = $this->normalized_value(); |
|
309 | - } |
|
310 | - } |
|
311 | - return implode(', ', $pretty_strings); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @return boolean |
|
318 | - */ |
|
319 | - public function display_html_label_text() |
|
320 | - { |
|
321 | - return $this->_display_html_label_text; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param boolean $display_html_label_text |
|
328 | - */ |
|
329 | - public function set_display_html_label_text($display_html_label_text) |
|
330 | - { |
|
331 | - $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
332 | - } |
|
19 | + /** |
|
20 | + * array of available options to choose as an answer |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $_options = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * whether to display the html_label_text above the checkbox/radio button options |
|
28 | + * |
|
29 | + * @var boolean |
|
30 | + */ |
|
31 | + protected $_display_html_label_text = true; |
|
32 | + |
|
33 | + /** |
|
34 | + * whether to display an question option description as part of the input label |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_use_desc_in_label = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * strlen() result for the longest input value (what gets displayed in the label) |
|
42 | + * this is used to apply a css class to the input label |
|
43 | + * |
|
44 | + * @var int |
|
45 | + */ |
|
46 | + protected $_label_size = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * whether to enforce the label size value passed in the constructor |
|
50 | + * |
|
51 | + * @var boolean |
|
52 | + */ |
|
53 | + protected $_enforce_label_size = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * whether to allow multiple selections (ie, the value of this input should be an array) |
|
57 | + * or not (ie, the value should be a simple int, string, etc) |
|
58 | + * |
|
59 | + * @var boolean |
|
60 | + */ |
|
61 | + protected $_multiple_selections = false; |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param array $answer_options |
|
67 | + * @param array $input_settings { |
|
68 | + * @type int|string $label_size |
|
69 | + * @type boolean $display_html_label_text |
|
70 | + * } |
|
71 | + * And all the options accepted by EE_Form_Input_Base |
|
72 | + */ |
|
73 | + public function __construct($answer_options = array(), $input_settings = array()) |
|
74 | + { |
|
75 | + if (isset($input_settings['label_size'])) { |
|
76 | + $this->_set_label_size($input_settings['label_size']); |
|
77 | + if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
78 | + $this->_enforce_label_size = true; |
|
79 | + } |
|
80 | + } |
|
81 | + if (isset($input_settings['display_html_label_text'])) { |
|
82 | + $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
83 | + } |
|
84 | + $this->set_select_options($answer_options); |
|
85 | + parent::__construct($input_settings); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Sets the allowed options for this input. Also has the side-effect of |
|
92 | + * updating the normalization strategy to match the keys provided in the array |
|
93 | + * |
|
94 | + * @param array $answer_options |
|
95 | + * @return void just has the side-effect of setting the options for this input |
|
96 | + */ |
|
97 | + public function set_select_options($answer_options = array()) |
|
98 | + { |
|
99 | + $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
100 | + //get the first item in the select options and check it's type |
|
101 | + $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
102 | + ? $this->_process_question_options($answer_options) |
|
103 | + : $answer_options; |
|
104 | + //d( $this->_options ); |
|
105 | + $select_option_keys = array_keys($this->_options); |
|
106 | + // attempt to determine data type for values in order to set normalization type |
|
107 | + //purposefully only |
|
108 | + if ( |
|
109 | + count($this->_options) === 2 |
|
110 | + && ( |
|
111 | + (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
112 | + || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
113 | + ) |
|
114 | + ) { |
|
115 | + // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
116 | + $normalization = new EE_Boolean_Normalization(); |
|
117 | + } else { |
|
118 | + //are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
119 | + $all_ints = true; |
|
120 | + array_walk_recursive( |
|
121 | + $this->_options, |
|
122 | + function($value,$key) use (&$all_ints){ |
|
123 | + //is this a top-level key? ignore it |
|
124 | + if(! is_array($value) |
|
125 | + && ! is_int($key) |
|
126 | + && $key !== '' |
|
127 | + && $key !== null){ |
|
128 | + $all_ints = false; |
|
129 | + } |
|
130 | + } |
|
131 | + ); |
|
132 | + if ($all_ints) { |
|
133 | + $normalization = new EE_Int_Normalization(); |
|
134 | + } else { |
|
135 | + $normalization = new EE_Text_Normalization(); |
|
136 | + } |
|
137 | + } |
|
138 | + // does input type have multiple options ? |
|
139 | + if ($this->_multiple_selections) { |
|
140 | + $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
141 | + } else { |
|
142 | + $this->_set_normalization_strategy($normalization); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function options() |
|
152 | + { |
|
153 | + return $this->_options; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Returns an array which is guaranteed to not be multidimensional |
|
160 | + * |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function flat_options() |
|
164 | + { |
|
165 | + return $this->_flatten_select_options($this->options()); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Makes sure $arr is a flat array, not a multidimensional one |
|
172 | + * |
|
173 | + * @param array $arr |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + protected function _flatten_select_options($arr) |
|
177 | + { |
|
178 | + $flat_array = array(); |
|
179 | + if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
180 | + foreach ($arr as $sub_array) { |
|
181 | + foreach ((array)$sub_array as $key => $value) { |
|
182 | + $flat_array[$key] = $value; |
|
183 | + $this->_set_label_size($value); |
|
184 | + } |
|
185 | + } |
|
186 | + } else { |
|
187 | + foreach ($arr as $key => $value) { |
|
188 | + $flat_array[$key] = $value; |
|
189 | + $this->_set_label_size($value); |
|
190 | + } |
|
191 | + } |
|
192 | + return $flat_array; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param EE_Question_Option[] $question_options_array |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + protected function _process_question_options($question_options_array = array()) |
|
202 | + { |
|
203 | + $flat_array = array(); |
|
204 | + foreach ($question_options_array as $question_option) { |
|
205 | + if ($question_option instanceof EE_Question_Option) { |
|
206 | + $desc = ''; |
|
207 | + if ($this->_use_desc_in_label) { |
|
208 | + $desc = $question_option->desc(); |
|
209 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
210 | + } |
|
211 | + $value = $question_option->value(); |
|
212 | + // add value even if it's empty |
|
213 | + $flat_array[$value] = $value; |
|
214 | + // if both value and desc are not empty, then separate with a dash |
|
215 | + if ( ! empty($value) && ! empty($desc)) { |
|
216 | + $flat_array[$value] .= ' - ' . $desc; |
|
217 | + } else { |
|
218 | + // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
219 | + $flat_array[$value] .= $desc; |
|
220 | + } |
|
221 | + } elseif (is_array($question_option)) { |
|
222 | + $flat_array += $this->_flatten_select_options($question_option); |
|
223 | + } |
|
224 | + } |
|
225 | + return $flat_array; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * set_label_sizes |
|
232 | + * |
|
233 | + * @return void |
|
234 | + */ |
|
235 | + public function set_label_sizes() |
|
236 | + { |
|
237 | + // did the input settings specifically say to NOT set the label size dynamically ? |
|
238 | + if ( ! $this->_enforce_label_size) { |
|
239 | + foreach ($this->_options as $option) { |
|
240 | + // calculate the strlen of the label |
|
241 | + $this->_set_label_size($option); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * _set_label_size_class |
|
250 | + * |
|
251 | + * @param int|string $value |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + private function _set_label_size($value = '') |
|
255 | + { |
|
256 | + // determine length of option value |
|
257 | + $val_size = is_int($value) ? $value : strlen($value); |
|
258 | + // use new value if bigger than existing |
|
259 | + $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * get_label_size_class |
|
266 | + * |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function get_label_size_class() |
|
270 | + { |
|
271 | + $size = ' medium-lbl'; |
|
272 | + // use maximum option value length to determine label size |
|
273 | + if ($this->_label_size < 3) { |
|
274 | + $size = ' nano-lbl'; |
|
275 | + } else if ($this->_label_size < 6) { |
|
276 | + $size = ' micro-lbl'; |
|
277 | + } else if ($this->_label_size < 12) { |
|
278 | + $size = ' tiny-lbl'; |
|
279 | + } else if ($this->_label_size < 25) { |
|
280 | + $size = ' small-lbl'; |
|
281 | + } else if ($this->_label_size < 50) { |
|
282 | + $size = ' medium-lbl'; |
|
283 | + } else if ($this->_label_size >= 100) { |
|
284 | + $size = ' big-lbl'; |
|
285 | + } |
|
286 | + return $size; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Returns the pretty value for the normalized value |
|
293 | + * |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function pretty_value() |
|
297 | + { |
|
298 | + $options = $this->flat_options(); |
|
299 | + $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
300 | + if ( ! $this->_multiple_selections) { |
|
301 | + $unnormalized_value_choices = array($unnormalized_value_choices); |
|
302 | + } |
|
303 | + $pretty_strings = array(); |
|
304 | + foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
305 | + if (isset($options[$unnormalized_value_choice])) { |
|
306 | + $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
307 | + } else { |
|
308 | + $pretty_strings[] = $this->normalized_value(); |
|
309 | + } |
|
310 | + } |
|
311 | + return implode(', ', $pretty_strings); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @return boolean |
|
318 | + */ |
|
319 | + public function display_html_label_text() |
|
320 | + { |
|
321 | + return $this->_display_html_label_text; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param boolean $display_html_label_text |
|
328 | + */ |
|
329 | + public function set_display_html_label_text($display_html_label_text) |
|
330 | + { |
|
331 | + $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
332 | + } |
|
333 | 333 | |
334 | 334 | |
335 | 335 |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | $all_ints = true; |
120 | 120 | array_walk_recursive( |
121 | 121 | $this->_options, |
122 | - function($value,$key) use (&$all_ints){ |
|
122 | + function($value, $key) use (&$all_ints){ |
|
123 | 123 | //is this a top-level key? ignore it |
124 | - if(! is_array($value) |
|
124 | + if ( ! is_array($value) |
|
125 | 125 | && ! is_int($key) |
126 | 126 | && $key !== '' |
127 | - && $key !== null){ |
|
127 | + && $key !== null) { |
|
128 | 128 | $all_ints = false; |
129 | 129 | } |
130 | 130 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $flat_array = array(); |
179 | 179 | if (EEH_Array::is_multi_dimensional_array($arr)) { |
180 | 180 | foreach ($arr as $sub_array) { |
181 | - foreach ((array)$sub_array as $key => $value) { |
|
181 | + foreach ((array) $sub_array as $key => $value) { |
|
182 | 182 | $flat_array[$key] = $value; |
183 | 183 | $this->_set_label_size($value); |
184 | 184 | } |
@@ -206,14 +206,14 @@ discard block |
||
206 | 206 | $desc = ''; |
207 | 207 | if ($this->_use_desc_in_label) { |
208 | 208 | $desc = $question_option->desc(); |
209 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
209 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : ''; |
|
210 | 210 | } |
211 | 211 | $value = $question_option->value(); |
212 | 212 | // add value even if it's empty |
213 | 213 | $flat_array[$value] = $value; |
214 | 214 | // if both value and desc are not empty, then separate with a dash |
215 | 215 | if ( ! empty($value) && ! empty($desc)) { |
216 | - $flat_array[$value] .= ' - ' . $desc; |
|
216 | + $flat_array[$value] .= ' - '.$desc; |
|
217 | 217 | } else { |
218 | 218 | // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
219 | 219 | $flat_array[$value] .= $desc; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $unnormalized_value_choices = array($unnormalized_value_choices); |
302 | 302 | } |
303 | 303 | $pretty_strings = array(); |
304 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
304 | + foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
305 | 305 | if (isset($options[$unnormalized_value_choice])) { |
306 | 306 | $pretty_strings[] = $options[$unnormalized_value_choice]; |
307 | 307 | } else { |
@@ -15,26 +15,26 @@ |
||
15 | 15 | */ |
16 | 16 | public function normalize($value_to_normalize) { |
17 | 17 | if(is_array($value_to_normalize)) { |
18 | - return (string)array_shift($value_to_normalize); |
|
19 | - } |
|
20 | - // consider `"null"` values to be equivalent to null. |
|
21 | - if($value_to_normalize === '' || $value_to_normalize === null) { |
|
22 | - return null; |
|
18 | + return (string)array_shift($value_to_normalize); |
|
23 | 19 | } |
24 | - return (string)$value_to_normalize; |
|
25 | - } |
|
20 | + // consider `"null"` values to be equivalent to null. |
|
21 | + if($value_to_normalize === '' || $value_to_normalize === null) { |
|
22 | + return null; |
|
23 | + } |
|
24 | + return (string)$value_to_normalize; |
|
25 | + } |
|
26 | 26 | /** |
27 | 27 | * IF its a string in PHP, it will be a string in the HTML form. easy |
28 | 28 | * @param string $normalized_value |
29 | 29 | * @return string |
30 | 30 | */ |
31 | 31 | public function unnormalize( $normalized_value ){ |
32 | - //account for default "select here" option values |
|
33 | - if ($normalized_value === null) { |
|
34 | - return ''; |
|
35 | - } |
|
36 | - //double-check it's a string. It's possible this value was a question option that happened to be a numeric |
|
37 | - //string, in which case PHP has automatically converted it to an integer! |
|
32 | + //account for default "select here" option values |
|
33 | + if ($normalized_value === null) { |
|
34 | + return ''; |
|
35 | + } |
|
36 | + //double-check it's a string. It's possible this value was a question option that happened to be a numeric |
|
37 | + //string, in which case PHP has automatically converted it to an integer! |
|
38 | 38 | return (string)$normalized_value; |
39 | 39 | } |
40 | 40 | } |
@@ -7,35 +7,35 @@ |
||
7 | 7 | * @subpackage |
8 | 8 | * @author Mike Nelson |
9 | 9 | */ |
10 | -class EE_Text_Normalization extends EE_Normalization_Strategy_Base{ |
|
10 | +class EE_Text_Normalization extends EE_Normalization_Strategy_Base { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @param string $value_to_normalize |
14 | 14 | * @return array|mixed|string |
15 | 15 | */ |
16 | 16 | public function normalize($value_to_normalize) { |
17 | - if(is_array($value_to_normalize)) { |
|
18 | - return (string)array_shift($value_to_normalize); |
|
17 | + if (is_array($value_to_normalize)) { |
|
18 | + return (string) array_shift($value_to_normalize); |
|
19 | 19 | } |
20 | 20 | // consider `"null"` values to be equivalent to null. |
21 | - if($value_to_normalize === '' || $value_to_normalize === null) { |
|
21 | + if ($value_to_normalize === '' || $value_to_normalize === null) { |
|
22 | 22 | return null; |
23 | 23 | } |
24 | - return (string)$value_to_normalize; |
|
24 | + return (string) $value_to_normalize; |
|
25 | 25 | } |
26 | 26 | /** |
27 | 27 | * IF its a string in PHP, it will be a string in the HTML form. easy |
28 | 28 | * @param string $normalized_value |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function unnormalize( $normalized_value ){ |
|
31 | + public function unnormalize($normalized_value) { |
|
32 | 32 | //account for default "select here" option values |
33 | 33 | if ($normalized_value === null) { |
34 | 34 | return ''; |
35 | 35 | } |
36 | 36 | //double-check it's a string. It's possible this value was a question option that happened to be a numeric |
37 | 37 | //string, in which case PHP has automatically converted it to an integer! |
38 | - return (string)$normalized_value; |
|
38 | + return (string) $normalized_value; |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.37.rc.002'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.37.rc.002'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -17,7 +17,7 @@ |
||
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param string $value_to_normalize |
20 | - * @return int|mixed|string |
|
20 | + * @return null|integer |
|
21 | 21 | * @throws \EE_Validation_Error |
22 | 22 | */ |
23 | 23 | public function normalize($value_to_normalize) |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -15,81 +15,81 @@ discard block |
||
15 | 15 | class EE_Int_Normalization extends EE_Normalization_Strategy_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $value_to_normalize |
|
20 | - * @return int|mixed|string |
|
21 | - * @throws \EE_Validation_Error |
|
22 | - */ |
|
23 | - public function normalize($value_to_normalize) |
|
24 | - { |
|
25 | - if ($value_to_normalize === null) { |
|
26 | - return null; |
|
27 | - } |
|
28 | - if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
29 | - return (int)$value_to_normalize; |
|
30 | - } |
|
31 | - if (! is_string($value_to_normalize)) { |
|
32 | - throw new EE_Validation_Error( |
|
33 | - sprintf( |
|
34 | - __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
35 | - print_r($value_to_normalize, true), |
|
36 | - gettype($value_to_normalize) |
|
37 | - ) |
|
38 | - ); |
|
39 | - } |
|
40 | - $value_to_normalize = EEH_Money::strip_localized_money_formatting($value_to_normalize); |
|
41 | - if($value_to_normalize === ''){ |
|
42 | - return null; |
|
43 | - } |
|
44 | - $matches = array(); |
|
45 | - if (preg_match('/^(-?)(\d+)$/', $value_to_normalize, $matches)) { |
|
46 | - if (count($matches) !== 3) { |
|
47 | - throw new EE_Validation_Error( |
|
48 | - sprintf(__('The integer value of "%1$s" could not be determined.', 'event_espresso'), |
|
49 | - $value_to_normalize) |
|
50 | - ); |
|
51 | - } |
|
52 | - // if first match is the negative sign, |
|
53 | - // then the number needs to be multiplied by -1 to remain negative |
|
54 | - return $matches[1] === '-' |
|
55 | - ? (int)$matches[2] * -1 |
|
56 | - : (int)$matches[2]; |
|
57 | - } |
|
58 | - //find if this input has a int validation strategy |
|
59 | - //in which case, use its message |
|
60 | - $validation_error_message = null; |
|
61 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
62 | - if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
63 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
64 | - } |
|
65 | - } |
|
66 | - //this really shouldn't ever happen because fields with a int normalization strategy |
|
67 | - //should also have a int validation strategy, but in case it doesnt use the default |
|
68 | - if (! $validation_error_message) { |
|
69 | - $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
70 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
71 | - } |
|
72 | - throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
73 | - } |
|
18 | + /** |
|
19 | + * @param string $value_to_normalize |
|
20 | + * @return int|mixed|string |
|
21 | + * @throws \EE_Validation_Error |
|
22 | + */ |
|
23 | + public function normalize($value_to_normalize) |
|
24 | + { |
|
25 | + if ($value_to_normalize === null) { |
|
26 | + return null; |
|
27 | + } |
|
28 | + if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
29 | + return (int)$value_to_normalize; |
|
30 | + } |
|
31 | + if (! is_string($value_to_normalize)) { |
|
32 | + throw new EE_Validation_Error( |
|
33 | + sprintf( |
|
34 | + __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
35 | + print_r($value_to_normalize, true), |
|
36 | + gettype($value_to_normalize) |
|
37 | + ) |
|
38 | + ); |
|
39 | + } |
|
40 | + $value_to_normalize = EEH_Money::strip_localized_money_formatting($value_to_normalize); |
|
41 | + if($value_to_normalize === ''){ |
|
42 | + return null; |
|
43 | + } |
|
44 | + $matches = array(); |
|
45 | + if (preg_match('/^(-?)(\d+)$/', $value_to_normalize, $matches)) { |
|
46 | + if (count($matches) !== 3) { |
|
47 | + throw new EE_Validation_Error( |
|
48 | + sprintf(__('The integer value of "%1$s" could not be determined.', 'event_espresso'), |
|
49 | + $value_to_normalize) |
|
50 | + ); |
|
51 | + } |
|
52 | + // if first match is the negative sign, |
|
53 | + // then the number needs to be multiplied by -1 to remain negative |
|
54 | + return $matches[1] === '-' |
|
55 | + ? (int)$matches[2] * -1 |
|
56 | + : (int)$matches[2]; |
|
57 | + } |
|
58 | + //find if this input has a int validation strategy |
|
59 | + //in which case, use its message |
|
60 | + $validation_error_message = null; |
|
61 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
62 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
63 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
64 | + } |
|
65 | + } |
|
66 | + //this really shouldn't ever happen because fields with a int normalization strategy |
|
67 | + //should also have a int validation strategy, but in case it doesnt use the default |
|
68 | + if (! $validation_error_message) { |
|
69 | + $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
70 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
71 | + } |
|
72 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * Converts the int into a string for use in teh html form |
|
79 | - * |
|
80 | - * @param int $normalized_value |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function unnormalize($normalized_value) |
|
84 | - { |
|
85 | - if ($normalized_value === null) { |
|
86 | - return ''; |
|
87 | - } |
|
88 | - if (empty($normalized_value)) { |
|
89 | - return '0'; |
|
90 | - } |
|
91 | - return "$normalized_value"; |
|
92 | - } |
|
77 | + /** |
|
78 | + * Converts the int into a string for use in teh html form |
|
79 | + * |
|
80 | + * @param int $normalized_value |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function unnormalize($normalized_value) |
|
84 | + { |
|
85 | + if ($normalized_value === null) { |
|
86 | + return ''; |
|
87 | + } |
|
88 | + if (empty($normalized_value)) { |
|
89 | + return '0'; |
|
90 | + } |
|
91 | + return "$normalized_value"; |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // End of file EE_Int_Normalization.strategy.php |
96 | 96 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | return null; |
27 | 27 | } |
28 | 28 | if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
29 | - return (int)$value_to_normalize; |
|
29 | + return (int) $value_to_normalize; |
|
30 | 30 | } |
31 | - if (! is_string($value_to_normalize)) { |
|
31 | + if ( ! is_string($value_to_normalize)) { |
|
32 | 32 | throw new EE_Validation_Error( |
33 | 33 | sprintf( |
34 | 34 | __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | ); |
39 | 39 | } |
40 | 40 | $value_to_normalize = EEH_Money::strip_localized_money_formatting($value_to_normalize); |
41 | - if($value_to_normalize === ''){ |
|
41 | + if ($value_to_normalize === '') { |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 | $matches = array(); |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | // if first match is the negative sign, |
53 | 53 | // then the number needs to be multiplied by -1 to remain negative |
54 | 54 | return $matches[1] === '-' |
55 | - ? (int)$matches[2] * -1 |
|
56 | - : (int)$matches[2]; |
|
55 | + ? (int) $matches[2] * -1 |
|
56 | + : (int) $matches[2]; |
|
57 | 57 | } |
58 | 58 | //find if this input has a int validation strategy |
59 | 59 | //in which case, use its message |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | //this really shouldn't ever happen because fields with a int normalization strategy |
67 | 67 | //should also have a int validation strategy, but in case it doesnt use the default |
68 | - if (! $validation_error_message) { |
|
68 | + if ( ! $validation_error_message) { |
|
69 | 69 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
70 | 70 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
71 | 71 | } |
@@ -33,14 +33,14 @@ |
||
33 | 33 | * @return array |
34 | 34 | */ |
35 | 35 | function get_jquery_validation_rule_array(){ |
36 | - return array( |
|
37 | - 'number'=>true, |
|
38 | - 'step' => 1, |
|
39 | - 'messages' => array( |
|
40 | - 'number' => $this->get_validation_error_message(), |
|
41 | - 'step' => $this->get_validation_error_message() |
|
42 | - ) |
|
43 | - ); |
|
36 | + return array( |
|
37 | + 'number'=>true, |
|
38 | + 'step' => 1, |
|
39 | + 'messages' => array( |
|
40 | + 'number' => $this->get_validation_error_message(), |
|
41 | + 'step' => $this->get_validation_error_message() |
|
42 | + ) |
|
43 | + ); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | * @subpackage Expression package is undefined on line 19, column 19 in Templates/Scripting/PHPClass.php. |
7 | 7 | * @author Mike Nelson |
8 | 8 | */ |
9 | -class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base{ |
|
9 | +class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @param null $validation_error_message |
13 | 13 | */ |
14 | - public function __construct( $validation_error_message = NULL ) { |
|
15 | - if( ! $validation_error_message ){ |
|
14 | + public function __construct($validation_error_message = NULL) { |
|
15 | + if ( ! $validation_error_message) { |
|
16 | 16 | $validation_error_message = __("Only digits are allowed.", "event_espresso"); |
17 | 17 | } |
18 | - parent::__construct( $validation_error_message ); |
|
18 | + parent::__construct($validation_error_message); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @return array |
34 | 34 | */ |
35 | - function get_jquery_validation_rule_array(){ |
|
35 | + function get_jquery_validation_rule_array() { |
|
36 | 36 | return array( |
37 | 37 | 'number'=>true, |
38 | 38 | 'step' => 1, |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -15,77 +15,77 @@ discard block |
||
15 | 15 | class EE_Float_Normalization extends EE_Normalization_Strategy_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $value_to_normalize |
|
20 | - * @return float |
|
21 | - * @throws \EE_Validation_Error |
|
22 | - */ |
|
23 | - public function normalize($value_to_normalize) |
|
24 | - { |
|
25 | - if ($value_to_normalize === null) { |
|
26 | - return null; |
|
27 | - } |
|
28 | - if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
29 | - return (float)$value_to_normalize; |
|
30 | - } |
|
31 | - if (! is_string($value_to_normalize)) { |
|
32 | - throw new EE_Validation_Error( |
|
33 | - sprintf( |
|
34 | - __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
35 | - print_r($value_to_normalize, true), |
|
36 | - gettype($value_to_normalize) |
|
37 | - ) |
|
38 | - ); |
|
39 | - } |
|
40 | - $normalized_value = EEH_Money::strip_localized_money_formatting($value_to_normalize); |
|
41 | - if($normalized_value === ''){ |
|
42 | - return null; |
|
43 | - } |
|
44 | - if (preg_match('/(-?)([\d.]+)/', $normalized_value, $matches)) { |
|
45 | - if (count($matches) !== 3) { |
|
46 | - throw new EE_Validation_Error( |
|
47 | - sprintf(__('The float value of "%1$s" could not be determined.', 'event_espresso'), |
|
48 | - $value_to_normalize) |
|
49 | - ); |
|
50 | - } |
|
51 | - // if first match is the negative sign, |
|
52 | - // then the number needs to be multiplied by -1 to remain negative |
|
53 | - return $matches[1] === '-' |
|
54 | - ? (float)$matches[2] * -1 |
|
55 | - : (float)$matches[2]; |
|
56 | - } |
|
57 | - //find if this input has a float validation strategy |
|
58 | - //in which case, use its message |
|
59 | - $validation_error_message = null; |
|
60 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
61 | - if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
62 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
63 | - } |
|
64 | - } |
|
65 | - //this really shouldn't ever happen because fields with a float normalization strategy |
|
66 | - //should also have a float validation strategy, but in case it doesn't use the default |
|
67 | - if (! $validation_error_message) { |
|
68 | - $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
69 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
70 | - } |
|
71 | - throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
72 | - } |
|
18 | + /** |
|
19 | + * @param string $value_to_normalize |
|
20 | + * @return float |
|
21 | + * @throws \EE_Validation_Error |
|
22 | + */ |
|
23 | + public function normalize($value_to_normalize) |
|
24 | + { |
|
25 | + if ($value_to_normalize === null) { |
|
26 | + return null; |
|
27 | + } |
|
28 | + if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
29 | + return (float)$value_to_normalize; |
|
30 | + } |
|
31 | + if (! is_string($value_to_normalize)) { |
|
32 | + throw new EE_Validation_Error( |
|
33 | + sprintf( |
|
34 | + __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
35 | + print_r($value_to_normalize, true), |
|
36 | + gettype($value_to_normalize) |
|
37 | + ) |
|
38 | + ); |
|
39 | + } |
|
40 | + $normalized_value = EEH_Money::strip_localized_money_formatting($value_to_normalize); |
|
41 | + if($normalized_value === ''){ |
|
42 | + return null; |
|
43 | + } |
|
44 | + if (preg_match('/(-?)([\d.]+)/', $normalized_value, $matches)) { |
|
45 | + if (count($matches) !== 3) { |
|
46 | + throw new EE_Validation_Error( |
|
47 | + sprintf(__('The float value of "%1$s" could not be determined.', 'event_espresso'), |
|
48 | + $value_to_normalize) |
|
49 | + ); |
|
50 | + } |
|
51 | + // if first match is the negative sign, |
|
52 | + // then the number needs to be multiplied by -1 to remain negative |
|
53 | + return $matches[1] === '-' |
|
54 | + ? (float)$matches[2] * -1 |
|
55 | + : (float)$matches[2]; |
|
56 | + } |
|
57 | + //find if this input has a float validation strategy |
|
58 | + //in which case, use its message |
|
59 | + $validation_error_message = null; |
|
60 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
61 | + if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
62 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
63 | + } |
|
64 | + } |
|
65 | + //this really shouldn't ever happen because fields with a float normalization strategy |
|
66 | + //should also have a float validation strategy, but in case it doesn't use the default |
|
67 | + if (! $validation_error_message) { |
|
68 | + $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
69 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
70 | + } |
|
71 | + throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Converts a float into a string |
|
78 | - * |
|
79 | - * @param float $normalized_value |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function unnormalize($normalized_value) |
|
83 | - { |
|
84 | - if (empty($normalized_value)) { |
|
85 | - return '0.00'; |
|
86 | - } |
|
87 | - return "$normalized_value"; |
|
88 | - } |
|
76 | + /** |
|
77 | + * Converts a float into a string |
|
78 | + * |
|
79 | + * @param float $normalized_value |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function unnormalize($normalized_value) |
|
83 | + { |
|
84 | + if (empty($normalized_value)) { |
|
85 | + return '0.00'; |
|
86 | + } |
|
87 | + return "$normalized_value"; |
|
88 | + } |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // End of file EE_Float_Normalization.strategy.php |
92 | 92 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | return null; |
27 | 27 | } |
28 | 28 | if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
29 | - return (float)$value_to_normalize; |
|
29 | + return (float) $value_to_normalize; |
|
30 | 30 | } |
31 | - if (! is_string($value_to_normalize)) { |
|
31 | + if ( ! is_string($value_to_normalize)) { |
|
32 | 32 | throw new EE_Validation_Error( |
33 | 33 | sprintf( |
34 | 34 | __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | ); |
39 | 39 | } |
40 | 40 | $normalized_value = EEH_Money::strip_localized_money_formatting($value_to_normalize); |
41 | - if($normalized_value === ''){ |
|
41 | + if ($normalized_value === '') { |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 | if (preg_match('/(-?)([\d.]+)/', $normalized_value, $matches)) { |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | // if first match is the negative sign, |
52 | 52 | // then the number needs to be multiplied by -1 to remain negative |
53 | 53 | return $matches[1] === '-' |
54 | - ? (float)$matches[2] * -1 |
|
55 | - : (float)$matches[2]; |
|
54 | + ? (float) $matches[2] * -1 |
|
55 | + : (float) $matches[2]; |
|
56 | 56 | } |
57 | 57 | //find if this input has a float validation strategy |
58 | 58 | //in which case, use its message |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | } |
65 | 65 | //this really shouldn't ever happen because fields with a float normalization strategy |
66 | 66 | //should also have a float validation strategy, but in case it doesn't use the default |
67 | - if (! $validation_error_message) { |
|
67 | + if ( ! $validation_error_message) { |
|
68 | 68 | $default_validation_strategy = new EE_Float_Validation_Strategy(); |
69 | 69 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
70 | 70 | } |
@@ -8,18 +8,18 @@ discard block |
||
8 | 8 | */ |
9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
10 | 10 | /** |
11 | - * |
|
12 | - * Money helper class. |
|
13 | - * This class has helper methods that help with money related conversions and calculations. |
|
14 | - * |
|
15 | - * @since %VER% |
|
16 | - * |
|
17 | - * @package Event Espresso |
|
18 | - * @subpackage helpers |
|
19 | - * @author Darren Ethier |
|
20 | - * |
|
21 | - * ------------------------------------------------------------------------ |
|
22 | - */ |
|
11 | + * |
|
12 | + * Money helper class. |
|
13 | + * This class has helper methods that help with money related conversions and calculations. |
|
14 | + * |
|
15 | + * @since %VER% |
|
16 | + * |
|
17 | + * @package Event Espresso |
|
18 | + * @subpackage helpers |
|
19 | + * @author Darren Ethier |
|
20 | + * |
|
21 | + * ------------------------------------------------------------------------ |
|
22 | + */ |
|
23 | 23 | class EEH_Money extends EEH_Base { |
24 | 24 | |
25 | 25 | |
@@ -31,22 +31,22 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public static function strip_localized_money_formatting($money_value ) { |
33 | 33 | return str_replace( |
34 | - array( |
|
35 | - ' ', |
|
36 | - "\t", |
|
37 | - "\n", |
|
38 | - EE_Registry::instance()->CFG->currency->thsnds, |
|
39 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
40 | - ), |
|
41 | - array( |
|
42 | - '', // remove spaces |
|
43 | - '', // remove tabs |
|
44 | - '', // remove newlines |
|
45 | - '', // remove thousands separator |
|
46 | - '.', // convert decimal mark to what PHP expects |
|
47 | - ), |
|
48 | - $money_value |
|
49 | - ); |
|
34 | + array( |
|
35 | + ' ', |
|
36 | + "\t", |
|
37 | + "\n", |
|
38 | + EE_Registry::instance()->CFG->currency->thsnds, |
|
39 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
40 | + ), |
|
41 | + array( |
|
42 | + '', // remove spaces |
|
43 | + '', // remove tabs |
|
44 | + '', // remove newlines |
|
45 | + '', // remove thousands separator |
|
46 | + '.', // convert decimal mark to what PHP expects |
|
47 | + ), |
|
48 | + $money_value |
|
49 | + ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public static function convert_to_float_from_localized_money($money_value ) { |
60 | 60 | //float it! and round to three decimal places |
61 | - return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
61 | + return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * ------------------------------------------------------------------------ |
22 | 22 | */ |
23 | -class EEH_Money extends EEH_Base { |
|
23 | +class EEH_Money extends EEH_Base { |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param int|float|string $money_value |
30 | 30 | * @return float |
31 | 31 | */ |
32 | - public static function strip_localized_money_formatting($money_value ) { |
|
32 | + public static function strip_localized_money_formatting($money_value) { |
|
33 | 33 | return str_replace( |
34 | 34 | array( |
35 | 35 | ' ', |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * @param int|string $money_value |
57 | 57 | * @return float |
58 | 58 | */ |
59 | - public static function convert_to_float_from_localized_money($money_value ) { |
|
59 | + public static function convert_to_float_from_localized_money($money_value) { |
|
60 | 60 | //float it! and round to three decimal places |
61 | - return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
61 | + return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | * @throws \EE_Error |
78 | 78 | */ |
79 | 79 | |
80 | - public static function compare_floats( $float1, $float2, $operator='=' ) { |
|
80 | + public static function compare_floats($float1, $float2, $operator = '=') { |
|
81 | 81 | // Check numbers to 5 digits of precision |
82 | 82 | $epsilon = 0.00001; |
83 | 83 | |
84 | - $float1 = (float)$float1; |
|
85 | - $float2 = (float)$float2; |
|
84 | + $float1 = (float) $float1; |
|
85 | + $float2 = (float) $float2; |
|
86 | 86 | |
87 | 87 | switch ($operator) { |
88 | 88 | // equal |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | } |
139 | 139 | break; |
140 | 140 | default: |
141 | - throw new EE_Error(__( "Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", 'event_espresso' ) ); |
|
141 | + throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", 'event_espresso')); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return false; |
@@ -153,21 +153,21 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - public static function get_format_for_jqplot( $CNT_ISO = '') { |
|
156 | + public static function get_format_for_jqplot($CNT_ISO = '') { |
|
157 | 157 | //default format |
158 | 158 | $format = 'f'; |
159 | 159 | //if CNT_ISO passed lets try to get currency settings for it. |
160 | - $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config( $CNT_ISO ) : null; |
|
160 | + $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
161 | 161 | //default currency settings for site if not set |
162 | - if ( ! $currency_config instanceof EE_Currency_Config ) { |
|
162 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
163 | 163 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config(); |
164 | 164 | } |
165 | 165 | |
166 | 166 | //first get the decimal place and number of places |
167 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
167 | + $format = "%'.".$currency_config->dec_plc.$format; |
|
168 | 168 | |
169 | 169 | //currency symbol on right side. |
170 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
170 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
171 | 171 | return $format; |
172 | 172 | } |
173 | 173 | |
@@ -182,27 +182,27 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return string |
184 | 184 | */ |
185 | - public static function get_format_for_google_charts( $CNT_ISO = '' ) { |
|
185 | + public static function get_format_for_google_charts($CNT_ISO = '') { |
|
186 | 186 | //if CNT_ISO passed lets try to get currency settings for it. |
187 | - $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config( $CNT_ISO ) : null; |
|
187 | + $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
188 | 188 | //default currency settings for site if not set |
189 | - if ( ! $currency_config instanceof EE_Currency_Config ) { |
|
189 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
190 | 190 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config(); |
191 | 191 | } |
192 | 192 | |
193 | - $decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' ); |
|
193 | + $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
194 | 194 | |
195 | 195 | //first get the decimal place and number of places |
196 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
196 | + $format = '#,##0.'.$decimal_places_placeholder; |
|
197 | 197 | |
198 | 198 | //currency symbol on right side. |
199 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
199 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
200 | 200 | $formatterObject = array( |
201 | 201 | 'decimalSymbol' => $currency_config->dec_mrk, |
202 | 202 | 'groupingSymbol' => $currency_config->thsnds, |
203 | 203 | 'fractionDigits' => $currency_config->dec_plc, |
204 | 204 | ); |
205 | - if ( $currency_config->sign_b4 ) { |
|
205 | + if ($currency_config->sign_b4) { |
|
206 | 206 | $formatterObject['prefix'] = $currency_config->sign; |
207 | 207 | } else { |
208 | 208 | $formatterObject['suffix'] = $currency_config->sign; |