@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); } |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * ---------------------------------------------- |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | *@param array $settings_array |
98 | 98 | */ |
99 | - public function set_settings( $settings_array ) { |
|
99 | + public function set_settings($settings_array) { |
|
100 | 100 | parent::set_settings($settings_array); |
101 | 101 | // Redirect URL. |
102 | 102 | $this->_base_gateway_url = $this->_debug_mode |
@@ -115,19 +115,19 @@ discard block |
||
115 | 115 | * @return \EE_Payment|\EEI_Payment |
116 | 116 | * @throws \EE_Error |
117 | 117 | */ |
118 | - public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
|
119 | - if ( ! $payment instanceof EEI_Payment ) { |
|
120 | - $payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
|
121 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
118 | + public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) { |
|
119 | + if ( ! $payment instanceof EEI_Payment) { |
|
120 | + $payment->set_gateway_response(__('Error. No associated payment was found.', 'event_espresso')); |
|
121 | + $payment->set_status($this->_pay_model->failed_status()); |
|
122 | 122 | return $payment; |
123 | 123 | } |
124 | 124 | $transaction = $payment->transaction(); |
125 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
126 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
127 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
125 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
126 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
127 | + $payment->set_status($this->_pay_model->failed_status()); |
|
128 | 128 | return $payment; |
129 | 129 | } |
130 | - $order_description = substr( $this->_format_order_description($payment), 0, 127 ); |
|
130 | + $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
131 | 131 | $primary_registration = $transaction->primary_registration(); |
132 | 132 | $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false; |
133 | 133 | $locale = explode('-', get_bloginfo('language')); |
@@ -141,37 +141,37 @@ discard block |
||
141 | 141 | 'RETURNURL' => $return_url, |
142 | 142 | 'CANCELURL' => $cancel_url, |
143 | 143 | 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
144 | - 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | - 'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this |
|
144 | + 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | + 'BUTTONSOURCE' => 'EventEspresso_SP', //EE will blow up if you change this |
|
146 | 146 | 'LOCALECODE' => $locale[1] // Locale of the pages displayed by PayPal during Express Checkout. |
147 | 147 | ); |
148 | 148 | |
149 | 149 | // Show itemized list. |
150 | - if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) { |
|
150 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
151 | 151 | $item_num = 0; |
152 | 152 | $itemized_sum = 0; |
153 | 153 | $total_line_items = $transaction->total_line_item(); |
154 | 154 | // Go through each item in the list. |
155 | - foreach ( $total_line_items->get_items() as $line_item ) { |
|
156 | - if ( $line_item instanceof EE_Line_Item ) { |
|
155 | + foreach ($total_line_items->get_items() as $line_item) { |
|
156 | + if ($line_item instanceof EE_Line_Item) { |
|
157 | 157 | // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
158 | - if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) { |
|
158 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | |
162 | 162 | $unit_price = $line_item->unit_price(); |
163 | 163 | $line_item_quantity = $line_item->quantity(); |
164 | 164 | // This is a discount. |
165 | - if ( $line_item->is_percent() ) { |
|
165 | + if ($line_item->is_percent()) { |
|
166 | 166 | $unit_price = $line_item->total(); |
167 | 167 | $line_item_quantity = 1; |
168 | 168 | } |
169 | 169 | // Item Name. |
170 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127); |
|
170 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name($line_item, $payment), 0, 127); |
|
171 | 171 | // Item description. |
172 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127); |
|
172 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc($line_item, $payment), 0, 127); |
|
173 | 173 | // Cost of individual item. |
174 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price ); |
|
174 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price); |
|
175 | 175 | // Item Number. |
176 | 176 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
177 | 177 | // Item quantity. |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
189 | 189 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
190 | 190 | |
191 | - $itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 ); |
|
191 | + $itemized_sum_diff_from_txn_total = round($transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2); |
|
192 | 192 | // If we were not able to recognize some item like promotion, surcharge or cancellation, |
193 | 193 | // add the difference as an extra line item. |
194 | - if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) { |
|
194 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
195 | 195 | // Item Name. |
196 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 ); |
|
196 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr(__('Other (promotion/surcharge/cancellation)', 'event_espresso'), 0, 127); |
|
197 | 197 | // Item description. |
198 | 198 | $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
199 | 199 | // Cost of individual item. |
200 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total ); |
|
200 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total); |
|
201 | 201 | // Item Number. |
202 | 202 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203 | 203 | // Item quantity. |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | } else { |
210 | 210 | // Just one Item. |
211 | 211 | // Item Name. |
212 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 ); |
|
212 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr($this->_format_partial_payment_line_item_name($payment), 0, 127); |
|
213 | 213 | // Item description. |
214 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 ); |
|
214 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr($this->_format_partial_payment_line_item_desc($payment), 0, 127); |
|
215 | 215 | // Cost of individual item. |
216 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() ); |
|
216 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
217 | 217 | // Item Number. |
218 | 218 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
219 | 219 | // Item quantity. |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | // Digital item is sold. |
222 | 222 | $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
223 | 223 | // Item's sales S/H and tax amount. |
224 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() ); |
|
224 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
225 | 225 | $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
226 | 226 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
227 | 227 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
228 | 228 | } |
229 | 229 | // Automatically filling out shipping and contact information. |
230 | - if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) { |
|
231 | - $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
230 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
231 | + $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
232 | 232 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
233 | 233 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
234 | 234 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
@@ -237,14 +237,14 @@ discard block |
||
237 | 237 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
238 | 238 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
239 | 239 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
240 | - } elseif ( ! $this->_request_shipping_addr ) { |
|
240 | + } elseif ( ! $this->_request_shipping_addr) { |
|
241 | 241 | // Do not request shipping details on the PP Checkout page. |
242 | 242 | $token_request_dtls['NOSHIPPING'] = '1'; |
243 | 243 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
244 | 244 | |
245 | 245 | } |
246 | 246 | // Used a business/personal logo on the PayPal page. |
247 | - if ( ! empty($this->_image_url) ) { |
|
247 | + if ( ! empty($this->_image_url)) { |
|
248 | 248 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
249 | 249 | } |
250 | 250 | $token_request_dtls = apply_filters( |
@@ -253,23 +253,23 @@ discard block |
||
253 | 253 | $this |
254 | 254 | ); |
255 | 255 | // Request PayPal token. |
256 | - $token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment ); |
|
257 | - $token_rstatus = $this->_ppExpress_check_response( $token_request_response ); |
|
258 | - $response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array(); |
|
259 | - if ( $token_rstatus['status'] ) { |
|
256 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
257 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
258 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) ? $token_rstatus['args'] : array(); |
|
259 | + if ($token_rstatus['status']) { |
|
260 | 260 | // We got the Token so we may continue with the payment and redirect the client. |
261 | - $payment->set_details( $response_args ); |
|
261 | + $payment->set_details($response_args); |
|
262 | 262 | |
263 | 263 | $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
264 | - $payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] ); |
|
264 | + $payment->set_redirect_url($gateway_url.'/checkoutnow?useraction=commit&cmd=_express-checkout&token='.$response_args['TOKEN']); |
|
265 | 265 | } else { |
266 | - if ( isset($response_args['L_ERRORCODE']) ) { |
|
267 | - $payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] ); |
|
266 | + if (isset($response_args['L_ERRORCODE'])) { |
|
267 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
268 | 268 | } else { |
269 | - $payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) ); |
|
269 | + $payment->set_gateway_response(__('Error occurred while trying to setup the Express Checkout.', 'event_espresso')); |
|
270 | 270 | } |
271 | - $payment->set_details( $response_args ); |
|
272 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
271 | + $payment->set_details($response_args); |
|
272 | + $payment->set_status($this->_pay_model->failed_status()); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | return $payment; |
@@ -285,22 +285,22 @@ discard block |
||
285 | 285 | * @param EEI_Transaction $transaction |
286 | 286 | * @return EEI_Payment |
287 | 287 | */ |
288 | - public function handle_payment_update( $update_info, $transaction ) { |
|
288 | + public function handle_payment_update($update_info, $transaction) { |
|
289 | 289 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
290 | 290 | |
291 | - if ( $payment instanceof EEI_Payment ) { |
|
292 | - $this->log( array( 'Return from Authorization' => $update_info ), $payment ); |
|
291 | + if ($payment instanceof EEI_Payment) { |
|
292 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
293 | 293 | $transaction = $payment->transaction(); |
294 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
295 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
296 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
294 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
295 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
296 | + $payment->set_status($this->_pay_model->failed_status()); |
|
297 | 297 | return $payment; |
298 | 298 | } |
299 | 299 | $primary_registrant = $transaction->primary_registration(); |
300 | 300 | $payment_details = $payment->details(); |
301 | 301 | // Check if we still have the token. |
302 | - if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
|
303 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
302 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
303 | + $payment->set_status($this->_pay_model->failed_status()); |
|
304 | 304 | return $payment; |
305 | 305 | } |
306 | 306 | |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | 'TOKEN' => $payment_details['TOKEN'] |
310 | 310 | ); |
311 | 311 | // Request Customer Details. |
312 | - $cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment ); |
|
313 | - $cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response ); |
|
314 | - $cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array(); |
|
315 | - if ( $cdetails_rstatus['status'] ) { |
|
312 | + $cdetails_request_response = $this->_ppExpress_request($cdetails_request_dtls, 'Customer Details', $payment); |
|
313 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
314 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) ? $cdetails_rstatus['args'] : array(); |
|
315 | + if ($cdetails_rstatus['status']) { |
|
316 | 316 | // We got the PayerID so now we can Complete the transaction. |
317 | 317 | $docheckout_request_dtls = array( |
318 | 318 | 'METHOD' => 'DoExpressCheckoutPayment', |
@@ -323,39 +323,39 @@ discard block |
||
323 | 323 | 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code() |
324 | 324 | ); |
325 | 325 | // Payment Checkout/Capture. |
326 | - $docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment ); |
|
327 | - $docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response ); |
|
328 | - $docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array(); |
|
329 | - if ( $docheckout_rstatus['status'] ) { |
|
326 | + $docheckout_request_response = $this->_ppExpress_request($docheckout_request_dtls, 'Do Payment', $payment); |
|
327 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
328 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) ? $docheckout_rstatus['args'] : array(); |
|
329 | + if ($docheckout_rstatus['status']) { |
|
330 | 330 | // All is well, payment approved. |
331 | 331 | $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
332 | - $payment->set_extra_accntng( $primary_registration_code ); |
|
333 | - $payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 ); |
|
334 | - $payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null ); |
|
335 | - $payment->set_details( $cdata_response_args ); |
|
336 | - $payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' ); |
|
337 | - $payment->set_status( $this->_pay_model->approved_status() ); |
|
332 | + $payment->set_extra_accntng($primary_registration_code); |
|
333 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0); |
|
334 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null); |
|
335 | + $payment->set_details($cdata_response_args); |
|
336 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : ''); |
|
337 | + $payment->set_status($this->_pay_model->approved_status()); |
|
338 | 338 | } else { |
339 | - if ( isset($docheckout_response_args['L_ERRORCODE']) ) { |
|
340 | - $payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] ); |
|
339 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
340 | + $payment->set_gateway_response($docheckout_response_args['L_ERRORCODE'].'; '.$docheckout_response_args['L_SHORTMESSAGE']); |
|
341 | 341 | } else { |
342 | - $payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) ); |
|
342 | + $payment->set_gateway_response(__('Error occurred while trying to Capture the funds.', 'event_espresso')); |
|
343 | 343 | } |
344 | - $payment->set_details( $docheckout_response_args ); |
|
345 | - $payment->set_status( $this->_pay_model->declined_status() ); |
|
344 | + $payment->set_details($docheckout_response_args); |
|
345 | + $payment->set_status($this->_pay_model->declined_status()); |
|
346 | 346 | } |
347 | 347 | } else { |
348 | - if ( isset($cdata_response_args['L_ERRORCODE']) ) { |
|
349 | - $payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] ); |
|
348 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
349 | + $payment->set_gateway_response($cdata_response_args['L_ERRORCODE'].'; '.$cdata_response_args['L_SHORTMESSAGE']); |
|
350 | 350 | } else { |
351 | - $payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) ); |
|
351 | + $payment->set_gateway_response(__('Error occurred while trying to get payment Details from PayPal.', 'event_espresso')); |
|
352 | 352 | } |
353 | - $payment->set_details( $cdata_response_args ); |
|
354 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
353 | + $payment->set_details($cdata_response_args); |
|
354 | + $payment->set_status($this->_pay_model->failed_status()); |
|
355 | 355 | } |
356 | 356 | } else { |
357 | - $payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) ); |
|
358 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
357 | + $payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso')); |
|
358 | + $payment->set_status($this->_pay_model->failed_status()); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | return $payment; |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | * @param EEI_Payment $payment |
371 | 371 | * @return mixed |
372 | 372 | */ |
373 | - public function _ppExpress_request( $request_params, $request_text, $payment ) { |
|
373 | + public function _ppExpress_request($request_params, $request_text, $payment) { |
|
374 | 374 | $request_dtls = array( |
375 | 375 | 'VERSION' => '204.0', |
376 | - 'USER' => urlencode( $this->_api_username ), |
|
377 | - 'PWD' => urlencode( $this->_api_password ), |
|
378 | - 'SIGNATURE' => urlencode( $this->_api_signature ) |
|
376 | + 'USER' => urlencode($this->_api_username), |
|
377 | + 'PWD' => urlencode($this->_api_password), |
|
378 | + 'SIGNATURE' => urlencode($this->_api_signature) |
|
379 | 379 | ); |
380 | - $dtls = array_merge( $request_dtls, $request_params ); |
|
380 | + $dtls = array_merge($request_dtls, $request_params); |
|
381 | 381 | |
382 | - $this->_log_clean_request( $dtls, $payment, $request_text . ' Request' ); |
|
382 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
383 | 383 | // Request Customer Details. |
384 | 384 | $request_response = wp_remote_post( |
385 | 385 | $this->_base_gateway_url, |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | 'httpversion' => '1.1', |
390 | 390 | 'cookies' => array(), |
391 | 391 | 'headers' => array(), |
392 | - 'body' => http_build_query( $dtls ) |
|
392 | + 'body' => http_build_query($dtls) |
|
393 | 393 | ) |
394 | 394 | ); |
395 | 395 | // Log the response. |
396 | - $this->log( array( $request_text . ' Response' => $request_response), $payment ); |
|
396 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
397 | 397 | |
398 | 398 | return $request_response; |
399 | 399 | } |
@@ -405,13 +405,13 @@ discard block |
||
405 | 405 | * @param mixed $request_response |
406 | 406 | * @return array |
407 | 407 | */ |
408 | - public function _ppExpress_check_response( $request_response ) { |
|
409 | - if ( is_wp_error( $request_response ) || empty($request_response['body']) ) { |
|
408 | + public function _ppExpress_check_response($request_response) { |
|
409 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
410 | 410 | // If we got here then there was an error in this request. |
411 | 411 | return array('status' => false, 'args' => $request_response); |
412 | 412 | } |
413 | 413 | $response_args = array(); |
414 | - parse_str( urldecode($request_response['body']), $response_args ); |
|
414 | + parse_str(urldecode($request_response['body']), $response_args); |
|
415 | 415 | if ( ! isset($response_args['ACK'])) { |
416 | 416 | return array('status' => false, 'args' => $request_response); |
417 | 417 | } |
@@ -441,10 +441,10 @@ discard block |
||
441 | 441 | * @param string $info |
442 | 442 | * @return void |
443 | 443 | */ |
444 | - private function _log_clean_request($request, $payment, $info ) { |
|
444 | + private function _log_clean_request($request, $payment, $info) { |
|
445 | 445 | $cleaned_request_data = $request; |
446 | 446 | unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
447 | - $this->log( array($info => $cleaned_request_data), $payment ); |
|
447 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | |
@@ -454,10 +454,10 @@ discard block |
||
454 | 454 | * @param array $data_array |
455 | 455 | * @return array |
456 | 456 | */ |
457 | - private function _get_errors( $data_array ) { |
|
457 | + private function _get_errors($data_array) { |
|
458 | 458 | $errors = array(); |
459 | 459 | $n = 0; |
460 | - while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
|
460 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
461 | 461 | $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
462 | 462 | ? $data_array["L_ERRORCODE{$n}"] |
463 | 463 | : ''; |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | ? $data_array["L_LONGMESSAGE{$n}"] |
472 | 472 | : ''; |
473 | 473 | |
474 | - if ( $n === 0 ) { |
|
474 | + if ($n === 0) { |
|
475 | 475 | $errors = array( |
476 | 476 | 'L_ERRORCODE' => $l_error_code, |
477 | 477 | 'L_SHORTMESSAGE' => $l_short_message, |
@@ -479,10 +479,10 @@ discard block |
||
479 | 479 | 'L_SEVERITYCODE' => $l_severity_code |
480 | 480 | ); |
481 | 481 | } else { |
482 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
483 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
484 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
485 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
482 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
483 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
484 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
485 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | $n++; |
@@ -44,77 +44,76 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected $_image_url; |
46 | 46 | |
47 | - /** |
|
48 | - * gateway URL variable |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_base_gateway_url = ''; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * EEG_Paypal_Express constructor. |
|
58 | - */ |
|
59 | - public function __construct() |
|
60 | - { |
|
61 | - $this->_currencies_supported = array( |
|
62 | - 'USD', |
|
63 | - 'AUD', |
|
64 | - 'BRL', |
|
65 | - 'CAD', |
|
66 | - 'CZK', |
|
67 | - 'DKK', |
|
68 | - 'EUR', |
|
69 | - 'HKD', |
|
70 | - 'HUF', |
|
71 | - 'ILS', |
|
72 | - 'JPY', |
|
73 | - 'MYR', |
|
74 | - 'MXN', |
|
75 | - 'NOK', |
|
76 | - 'NZD', |
|
77 | - 'PHP', |
|
78 | - 'PLN', |
|
79 | - 'GBP', |
|
80 | - 'RUB', |
|
81 | - 'SGD', |
|
82 | - 'SEK', |
|
83 | - 'CHF', |
|
84 | - 'TWD', |
|
85 | - 'THB', |
|
86 | - 'TRY' |
|
87 | - ); |
|
88 | - parent::__construct(); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
47 | + /** |
|
48 | + * gateway URL variable |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_base_gateway_url = ''; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * EEG_Paypal_Express constructor. |
|
58 | + */ |
|
59 | + public function __construct() |
|
60 | + { |
|
61 | + $this->_currencies_supported = array( |
|
62 | + 'USD', |
|
63 | + 'AUD', |
|
64 | + 'BRL', |
|
65 | + 'CAD', |
|
66 | + 'CZK', |
|
67 | + 'DKK', |
|
68 | + 'EUR', |
|
69 | + 'HKD', |
|
70 | + 'HUF', |
|
71 | + 'ILS', |
|
72 | + 'JPY', |
|
73 | + 'MYR', |
|
74 | + 'MXN', |
|
75 | + 'NOK', |
|
76 | + 'NZD', |
|
77 | + 'PHP', |
|
78 | + 'PLN', |
|
79 | + 'GBP', |
|
80 | + 'RUB', |
|
81 | + 'SGD', |
|
82 | + 'SEK', |
|
83 | + 'CHF', |
|
84 | + 'TWD', |
|
85 | + 'THB', |
|
86 | + 'TRY' |
|
87 | + ); |
|
88 | + parent::__construct(); |
|
89 | + } |
|
90 | + |
|
95 | 91 | |
92 | + |
|
93 | + /** |
|
94 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
96 | 95 | * |
97 | 96 | *@param array $settings_array |
98 | 97 | */ |
99 | 98 | public function set_settings( $settings_array ) { |
100 | 99 | parent::set_settings($settings_array); |
101 | 100 | // Redirect URL. |
102 | - $this->_base_gateway_url = $this->_debug_mode |
|
103 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
104 | - : 'https://api-3t.paypal.com/nvp'; |
|
101 | + $this->_base_gateway_url = $this->_debug_mode |
|
102 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
103 | + : 'https://api-3t.paypal.com/nvp'; |
|
105 | 104 | } |
106 | 105 | |
107 | 106 | |
108 | 107 | |
109 | - /** |
|
110 | - * @param EEI_Payment $payment |
|
111 | - * @param array $billing_info |
|
112 | - * @param string $return_url |
|
113 | - * @param string $notify_url |
|
114 | - * @param string $cancel_url |
|
115 | - * @return \EE_Payment|\EEI_Payment |
|
116 | - * @throws \EE_Error |
|
117 | - */ |
|
108 | + /** |
|
109 | + * @param EEI_Payment $payment |
|
110 | + * @param array $billing_info |
|
111 | + * @param string $return_url |
|
112 | + * @param string $notify_url |
|
113 | + * @param string $cancel_url |
|
114 | + * @return \EE_Payment|\EEI_Payment |
|
115 | + * @throws \EE_Error |
|
116 | + */ |
|
118 | 117 | public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
119 | 118 | if ( ! $payment instanceof EEI_Payment ) { |
120 | 119 | $payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
@@ -202,9 +201,9 @@ discard block |
||
202 | 201 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203 | 202 | // Item quantity. |
204 | 203 | $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
205 | - // Digital item is sold. |
|
206 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
207 | - $item_num++; |
|
204 | + // Digital item is sold. |
|
205 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
206 | + $item_num++; |
|
208 | 207 | } |
209 | 208 | } else { |
210 | 209 | // Just one Item. |
@@ -277,7 +276,6 @@ discard block |
||
277 | 276 | |
278 | 277 | |
279 | 278 | /** |
280 | - |
|
281 | 279 | * @param array $update_info { |
282 | 280 | * @type string $gateway_txn_id |
283 | 281 | * @type string status an EEMI_Payment status |
@@ -297,8 +295,8 @@ discard block |
||
297 | 295 | return $payment; |
298 | 296 | } |
299 | 297 | $primary_registrant = $transaction->primary_registration(); |
300 | - $payment_details = $payment->details(); |
|
301 | - // Check if we still have the token. |
|
298 | + $payment_details = $payment->details(); |
|
299 | + // Check if we still have the token. |
|
302 | 300 | if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
303 | 301 | $payment->set_status( $this->_pay_model->failed_status() ); |
304 | 302 | return $payment; |
@@ -407,36 +405,36 @@ discard block |
||
407 | 405 | */ |
408 | 406 | public function _ppExpress_check_response( $request_response ) { |
409 | 407 | if ( is_wp_error( $request_response ) || empty($request_response['body']) ) { |
410 | - // If we got here then there was an error in this request. |
|
411 | - return array('status' => false, 'args' => $request_response); |
|
412 | - } |
|
413 | - $response_args = array(); |
|
414 | - parse_str( urldecode($request_response['body']), $response_args ); |
|
415 | - if ( ! isset($response_args['ACK'])) { |
|
416 | - return array('status' => false, 'args' => $request_response); |
|
417 | - } |
|
418 | - if ( |
|
419 | - $response_args['ACK'] === 'Success' |
|
420 | - && ( |
|
421 | - isset($response_args['PAYERID']) |
|
422 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
423 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
424 | - || isset($response_args['TOKEN']) |
|
425 | - ) |
|
426 | - ) { |
|
427 | - // Response status OK, return response parameters for further processing. |
|
428 | - return array('status' => true, 'args' => $response_args); |
|
429 | - } else { |
|
430 | - $errors = $this->_get_errors($response_args); |
|
431 | - return array('status' => false, 'args' => $errors); |
|
432 | - } |
|
408 | + // If we got here then there was an error in this request. |
|
409 | + return array('status' => false, 'args' => $request_response); |
|
410 | + } |
|
411 | + $response_args = array(); |
|
412 | + parse_str( urldecode($request_response['body']), $response_args ); |
|
413 | + if ( ! isset($response_args['ACK'])) { |
|
414 | + return array('status' => false, 'args' => $request_response); |
|
415 | + } |
|
416 | + if ( |
|
417 | + $response_args['ACK'] === 'Success' |
|
418 | + && ( |
|
419 | + isset($response_args['PAYERID']) |
|
420 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
421 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
422 | + || isset($response_args['TOKEN']) |
|
423 | + ) |
|
424 | + ) { |
|
425 | + // Response status OK, return response parameters for further processing. |
|
426 | + return array('status' => true, 'args' => $response_args); |
|
427 | + } else { |
|
428 | + $errors = $this->_get_errors($response_args); |
|
429 | + return array('status' => false, 'args' => $errors); |
|
430 | + } |
|
433 | 431 | } |
434 | 432 | |
435 | 433 | |
436 | 434 | /** |
437 | - * Log a "Cleared" request. |
|
438 | - * |
|
439 | - * @param array $request |
|
435 | + * Log a "Cleared" request. |
|
436 | + * |
|
437 | + * @param array $request |
|
440 | 438 | * @param EEI_Payment $payment |
441 | 439 | * @param string $info |
442 | 440 | * @return void |
@@ -459,17 +457,17 @@ discard block |
||
459 | 457 | $n = 0; |
460 | 458 | while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
461 | 459 | $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
462 | - ? $data_array["L_ERRORCODE{$n}"] |
|
463 | - : ''; |
|
460 | + ? $data_array["L_ERRORCODE{$n}"] |
|
461 | + : ''; |
|
464 | 462 | $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
465 | - ? $data_array["L_SEVERITYCODE{$n}"] |
|
466 | - : ''; |
|
463 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
464 | + : ''; |
|
467 | 465 | $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
468 | - ? $data_array["L_SHORTMESSAGE{$n}"] |
|
469 | - : ''; |
|
466 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
467 | + : ''; |
|
470 | 468 | $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
471 | - ? $data_array["L_LONGMESSAGE{$n}"] |
|
472 | - : ''; |
|
469 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
470 | + : ''; |
|
473 | 471 | |
474 | 472 | if ( $n === 0 ) { |
475 | 473 | $errors = array( |
@@ -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 | |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | class EE_Credit_Card_Normalization extends EE_Text_Normalization |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param string $value_to_normalize |
|
19 | - * @return mixed |
|
20 | - */ |
|
21 | - public function normalize($value_to_normalize) |
|
22 | - { |
|
23 | - $normalized_by_parent = parent::normalize($value_to_normalize); |
|
24 | - //we want to make it consistent, so remove whitespace from cc number |
|
25 | - return preg_replace('/\s+/', '', $normalized_by_parent); |
|
26 | - } |
|
17 | + /** |
|
18 | + * @param string $value_to_normalize |
|
19 | + * @return mixed |
|
20 | + */ |
|
21 | + public function normalize($value_to_normalize) |
|
22 | + { |
|
23 | + $normalized_by_parent = parent::normalize($value_to_normalize); |
|
24 | + //we want to make it consistent, so remove whitespace from cc number |
|
25 | + return preg_replace('/\s+/', '', $normalized_by_parent); |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | // End of file EE_Credit_Card_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
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 |
@@ -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 | |
@@ -14,91 +14,91 @@ discard block |
||
14 | 14 | class EE_Many_Valued_Normalization extends EE_Normalization_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - protected $_individual_item_normalization_strategy = array(); |
|
18 | - |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
23 | - */ |
|
24 | - public function __construct($individual_item_normalization_strategy) |
|
25 | - { |
|
26 | - $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
27 | - parent::__construct(); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Normalizes the input into an array, and normalizes each item according to its |
|
34 | - * individual item normalization strategy |
|
35 | - * |
|
36 | - * @param array | string $value_to_normalize |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function normalize($value_to_normalize) |
|
40 | - { |
|
41 | - if (is_array($value_to_normalize)) { |
|
42 | - $items_to_normalize = $value_to_normalize; |
|
43 | - } else if ($value_to_normalize !== null) { |
|
44 | - $items_to_normalize = array($value_to_normalize); |
|
45 | - } else { |
|
46 | - $items_to_normalize = array(); |
|
47 | - } |
|
48 | - $normalized_array_value = array(); |
|
49 | - foreach ($items_to_normalize as $key => $individual_item) { |
|
50 | - $normalized_array_value[$key] = $this->normalize_one($individual_item); |
|
51 | - } |
|
52 | - return $normalized_array_value; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
59 | - * |
|
60 | - * @param string $individual_value_to_normalize but definitely NOT an array |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - public function normalize_one($individual_value_to_normalize) |
|
64 | - { |
|
65 | - return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Converts the array of normalized things to an array of raw html values. |
|
72 | - * |
|
73 | - * @param array $normalized_values |
|
74 | - * @return string[] |
|
75 | - */ |
|
76 | - public function unnormalize($normalized_values) |
|
77 | - { |
|
78 | - if ($normalized_values === null) { |
|
79 | - $normalized_values = array(); |
|
80 | - } |
|
81 | - if (! is_array($normalized_values)) { |
|
82 | - $normalized_values = array($normalized_values); |
|
83 | - } |
|
84 | - $non_normal_values = array(); |
|
85 | - foreach ($normalized_values as $key => $value) { |
|
86 | - $non_normal_values[$key] = $this->unnormalize_one($value); |
|
87 | - } |
|
88 | - return $non_normal_values; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Unnormalizes an individual item in the array of values |
|
95 | - * |
|
96 | - * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function unnormalize_one($individual_value_to_unnormalize) |
|
100 | - { |
|
101 | - return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
102 | - } |
|
17 | + protected $_individual_item_normalization_strategy = array(); |
|
18 | + |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * @param EE_Normalization_Strategy_Base $individual_item_normalization_strategy |
|
23 | + */ |
|
24 | + public function __construct($individual_item_normalization_strategy) |
|
25 | + { |
|
26 | + $this->_individual_item_normalization_strategy = $individual_item_normalization_strategy; |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Normalizes the input into an array, and normalizes each item according to its |
|
34 | + * individual item normalization strategy |
|
35 | + * |
|
36 | + * @param array | string $value_to_normalize |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function normalize($value_to_normalize) |
|
40 | + { |
|
41 | + if (is_array($value_to_normalize)) { |
|
42 | + $items_to_normalize = $value_to_normalize; |
|
43 | + } else if ($value_to_normalize !== null) { |
|
44 | + $items_to_normalize = array($value_to_normalize); |
|
45 | + } else { |
|
46 | + $items_to_normalize = array(); |
|
47 | + } |
|
48 | + $normalized_array_value = array(); |
|
49 | + foreach ($items_to_normalize as $key => $individual_item) { |
|
50 | + $normalized_array_value[$key] = $this->normalize_one($individual_item); |
|
51 | + } |
|
52 | + return $normalized_array_value; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Normalized the one item (called for each array item in EE_Many_values_Normalization::normalize()) |
|
59 | + * |
|
60 | + * @param string $individual_value_to_normalize but definitely NOT an array |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + public function normalize_one($individual_value_to_normalize) |
|
64 | + { |
|
65 | + return $this->_individual_item_normalization_strategy->normalize($individual_value_to_normalize); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Converts the array of normalized things to an array of raw html values. |
|
72 | + * |
|
73 | + * @param array $normalized_values |
|
74 | + * @return string[] |
|
75 | + */ |
|
76 | + public function unnormalize($normalized_values) |
|
77 | + { |
|
78 | + if ($normalized_values === null) { |
|
79 | + $normalized_values = array(); |
|
80 | + } |
|
81 | + if (! is_array($normalized_values)) { |
|
82 | + $normalized_values = array($normalized_values); |
|
83 | + } |
|
84 | + $non_normal_values = array(); |
|
85 | + foreach ($normalized_values as $key => $value) { |
|
86 | + $non_normal_values[$key] = $this->unnormalize_one($value); |
|
87 | + } |
|
88 | + return $non_normal_values; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Unnormalizes an individual item in the array of values |
|
95 | + * |
|
96 | + * @param mixed $individual_value_to_unnormalize but certainly NOT an array |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function unnormalize_one($individual_value_to_unnormalize) |
|
100 | + { |
|
101 | + return $this->_individual_item_normalization_strategy->unnormalize($individual_value_to_unnormalize); |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | // End of file EE_Many_Valued_Normalization.strategy.php |
@@ -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 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | if ($normalized_values === null) { |
79 | 79 | $normalized_values = array(); |
80 | 80 | } |
81 | - if (! is_array($normalized_values)) { |
|
81 | + if ( ! is_array($normalized_values)) { |
|
82 | 82 | $normalized_values = array($normalized_values); |
83 | 83 | } |
84 | 84 | $non_normal_values = array(); |
@@ -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 | |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | return null; |
37 | 37 | } |
38 | 38 | if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
39 | - return (float)$value_to_normalize; |
|
39 | + return (float) $value_to_normalize; |
|
40 | 40 | } |
41 | - if (! is_string($value_to_normalize)) { |
|
41 | + if ( ! is_string($value_to_normalize)) { |
|
42 | 42 | throw new EE_Validation_Error( |
43 | 43 | sprintf( |
44 | 44 | __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | // if first match is the negative sign, |
61 | 61 | // then the number needs to be multiplied by -1 to remain negative |
62 | 62 | return $matches[1] === '-' |
63 | - ? (float)$matches[2] * -1 |
|
64 | - : (float)$matches[2]; |
|
63 | + ? (float) $matches[2] * -1 |
|
64 | + : (float) $matches[2]; |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | //find if this input has a float validation strategy |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | //this really shouldn't ever happen because fields with a float normalization strategy |
76 | 76 | //should also have a float validation strategy, but in case it doesn't use the default |
77 | - if (! $validation_error_message) { |
|
77 | + if ( ! $validation_error_message) { |
|
78 | 78 | $default_validation_strategy = new EE_Float_Validation_Strategy(); |
79 | 79 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
80 | 80 | } |
@@ -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,85 +15,85 @@ discard block |
||
15 | 15 | class EE_Float_Normalization extends EE_Normalization_Strategy_Base |
16 | 16 | { |
17 | 17 | |
18 | - /* |
|
18 | + /* |
|
19 | 19 | * regex pattern that matches for the following: |
20 | 20 | * * optional negative sign |
21 | 21 | * * one or more digits or decimals |
22 | 22 | */ |
23 | - const REGEX = '/^(-?)([\d.]+)$/'; |
|
23 | + const REGEX = '/^(-?)([\d.]+)$/'; |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param string $value_to_normalize |
|
29 | - * @return float |
|
30 | - * @throws \EE_Validation_Error |
|
31 | - */ |
|
32 | - public function normalize($value_to_normalize) |
|
33 | - { |
|
34 | - if ($value_to_normalize === null) { |
|
35 | - return null; |
|
36 | - } |
|
37 | - if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
38 | - return (float)$value_to_normalize; |
|
39 | - } |
|
40 | - if (! is_string($value_to_normalize)) { |
|
41 | - throw new EE_Validation_Error( |
|
42 | - sprintf( |
|
43 | - __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
44 | - print_r($value_to_normalize, true), |
|
45 | - gettype($value_to_normalize) |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
49 | - $normalized_value = filter_var( |
|
50 | - $value_to_normalize, |
|
51 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
52 | - FILTER_FLAG_ALLOW_FRACTION |
|
53 | - ); |
|
54 | - if ($normalized_value === '') { |
|
55 | - return null; |
|
56 | - } |
|
57 | - if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
58 | - if (count($matches) === 3) { |
|
59 | - // if first match is the negative sign, |
|
60 | - // then the number needs to be multiplied by -1 to remain negative |
|
61 | - return $matches[1] === '-' |
|
62 | - ? (float)$matches[2] * -1 |
|
63 | - : (float)$matches[2]; |
|
64 | - } |
|
65 | - } |
|
66 | - //find if this input has a float validation strategy |
|
67 | - //in which case, use its message |
|
68 | - $validation_error_message = null; |
|
69 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
70 | - if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
71 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
72 | - } |
|
73 | - } |
|
74 | - //this really shouldn't ever happen because fields with a float normalization strategy |
|
75 | - //should also have a float validation strategy, but in case it doesn't use the default |
|
76 | - if (! $validation_error_message) { |
|
77 | - $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
78 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
79 | - } |
|
80 | - throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
81 | - } |
|
27 | + /** |
|
28 | + * @param string $value_to_normalize |
|
29 | + * @return float |
|
30 | + * @throws \EE_Validation_Error |
|
31 | + */ |
|
32 | + public function normalize($value_to_normalize) |
|
33 | + { |
|
34 | + if ($value_to_normalize === null) { |
|
35 | + return null; |
|
36 | + } |
|
37 | + if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
38 | + return (float)$value_to_normalize; |
|
39 | + } |
|
40 | + if (! is_string($value_to_normalize)) { |
|
41 | + throw new EE_Validation_Error( |
|
42 | + sprintf( |
|
43 | + __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
44 | + print_r($value_to_normalize, true), |
|
45 | + gettype($value_to_normalize) |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | + $normalized_value = filter_var( |
|
50 | + $value_to_normalize, |
|
51 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
52 | + FILTER_FLAG_ALLOW_FRACTION |
|
53 | + ); |
|
54 | + if ($normalized_value === '') { |
|
55 | + return null; |
|
56 | + } |
|
57 | + if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
58 | + if (count($matches) === 3) { |
|
59 | + // if first match is the negative sign, |
|
60 | + // then the number needs to be multiplied by -1 to remain negative |
|
61 | + return $matches[1] === '-' |
|
62 | + ? (float)$matches[2] * -1 |
|
63 | + : (float)$matches[2]; |
|
64 | + } |
|
65 | + } |
|
66 | + //find if this input has a float validation strategy |
|
67 | + //in which case, use its message |
|
68 | + $validation_error_message = null; |
|
69 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
70 | + if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
71 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
72 | + } |
|
73 | + } |
|
74 | + //this really shouldn't ever happen because fields with a float normalization strategy |
|
75 | + //should also have a float validation strategy, but in case it doesn't use the default |
|
76 | + if (! $validation_error_message) { |
|
77 | + $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
78 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
79 | + } |
|
80 | + throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * Converts a float into a string |
|
87 | - * |
|
88 | - * @param float $normalized_value |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function unnormalize($normalized_value) |
|
92 | - { |
|
93 | - if (empty($normalized_value)) { |
|
94 | - return '0.00'; |
|
95 | - } |
|
96 | - return "{$normalized_value}"; |
|
97 | - } |
|
85 | + /** |
|
86 | + * Converts a float into a string |
|
87 | + * |
|
88 | + * @param float $normalized_value |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function unnormalize($normalized_value) |
|
92 | + { |
|
93 | + if (empty($normalized_value)) { |
|
94 | + return '0.00'; |
|
95 | + } |
|
96 | + return "{$normalized_value}"; |
|
97 | + } |
|
98 | 98 | } |
99 | 99 | // End of file EE_Float_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
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 |
@@ -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,26 +15,26 @@ discard block |
||
15 | 15 | class EE_Slug_Normalization extends EE_Normalization_Strategy_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $value_to_normalize |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function normalize($value_to_normalize) |
|
23 | - { |
|
24 | - return sanitize_title($value_to_normalize); |
|
25 | - } |
|
18 | + /** |
|
19 | + * @param string $value_to_normalize |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function normalize($value_to_normalize) |
|
23 | + { |
|
24 | + return sanitize_title($value_to_normalize); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * It's hard to unnormalize this- let's just take a guess |
|
31 | - * |
|
32 | - * @param string $normalized_value |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function unnormalize($normalized_value) |
|
36 | - { |
|
37 | - return str_replace("-", " ", $normalized_value); |
|
38 | - } |
|
29 | + /** |
|
30 | + * It's hard to unnormalize this- let's just take a guess |
|
31 | + * |
|
32 | + * @param string $normalized_value |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function unnormalize($normalized_value) |
|
36 | + { |
|
37 | + return str_replace("-", " ", $normalized_value); |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | // End of file EE_Slug_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
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 |
@@ -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,27 +16,27 @@ discard block |
||
16 | 16 | class EE_All_Caps_Normalization extends EE_Normalization_Strategy_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param string $value_to_normalize |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public function normalize($value_to_normalize) |
|
24 | - { |
|
25 | - return strtoupper($value_to_normalize); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * It's kinda hard to unnormalize this- we can't determine which parts used to be lowercase |
|
32 | - * so just return it as-is. |
|
33 | - * |
|
34 | - * @param string $normalized_value |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function unnormalize($normalized_value) |
|
38 | - { |
|
39 | - return $normalized_value; |
|
40 | - } |
|
19 | + /** |
|
20 | + * @param string $value_to_normalize |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public function normalize($value_to_normalize) |
|
24 | + { |
|
25 | + return strtoupper($value_to_normalize); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * It's kinda hard to unnormalize this- we can't determine which parts used to be lowercase |
|
32 | + * so just return it as-is. |
|
33 | + * |
|
34 | + * @param string $normalized_value |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function unnormalize($normalized_value) |
|
38 | + { |
|
39 | + return $normalized_value; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -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 | |
@@ -18,28 +18,28 @@ discard block |
||
18 | 18 | class EE_Boolean_Normalization extends EE_Normalization_Strategy_Base |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @param string | int | bool $value_to_normalize |
|
23 | - * @return boolean |
|
24 | - */ |
|
25 | - public function normalize($value_to_normalize) |
|
26 | - { |
|
27 | - return filter_var($value_to_normalize, FILTER_VALIDATE_BOOLEAN); |
|
28 | - } |
|
21 | + /** |
|
22 | + * @param string | int | bool $value_to_normalize |
|
23 | + * @return boolean |
|
24 | + */ |
|
25 | + public function normalize($value_to_normalize) |
|
26 | + { |
|
27 | + return filter_var($value_to_normalize, FILTER_VALIDATE_BOOLEAN); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param boolean $normalized_value |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function unnormalize($normalized_value) |
|
37 | - { |
|
38 | - if ($normalized_value) { |
|
39 | - return '1'; |
|
40 | - } else { |
|
41 | - return '0'; |
|
42 | - } |
|
43 | - } |
|
32 | + /** |
|
33 | + * @param boolean $normalized_value |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function unnormalize($normalized_value) |
|
37 | + { |
|
38 | + if ($normalized_value) { |
|
39 | + return '1'; |
|
40 | + } else { |
|
41 | + return '0'; |
|
42 | + } |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | // End of file EE_Boolean_Normalization.strategy.php |
@@ -1,4 +1,4 @@ |
||
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 |
@@ -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,39 +15,39 @@ discard block |
||
15 | 15 | class EE_Text_Normalization extends EE_Normalization_Strategy_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $value_to_normalize |
|
20 | - * @return array|mixed|string |
|
21 | - */ |
|
22 | - public function normalize($value_to_normalize) |
|
23 | - { |
|
24 | - if (is_array($value_to_normalize)) { |
|
25 | - return (string)array_shift($value_to_normalize); |
|
26 | - } |
|
27 | - // consider `"null"` values to be equivalent to null. |
|
28 | - if ($value_to_normalize === '' || $value_to_normalize === null) { |
|
29 | - return null; |
|
30 | - } |
|
31 | - return (string)$value_to_normalize; |
|
32 | - } |
|
18 | + /** |
|
19 | + * @param string $value_to_normalize |
|
20 | + * @return array|mixed|string |
|
21 | + */ |
|
22 | + public function normalize($value_to_normalize) |
|
23 | + { |
|
24 | + if (is_array($value_to_normalize)) { |
|
25 | + return (string)array_shift($value_to_normalize); |
|
26 | + } |
|
27 | + // consider `"null"` values to be equivalent to null. |
|
28 | + if ($value_to_normalize === '' || $value_to_normalize === null) { |
|
29 | + return null; |
|
30 | + } |
|
31 | + return (string)$value_to_normalize; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * IF its a string in PHP, it will be a string in the HTML form. easy |
|
38 | - * |
|
39 | - * @param string $normalized_value |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function unnormalize($normalized_value) |
|
43 | - { |
|
44 | - //account for default "select here" option values |
|
45 | - if ($normalized_value === null) { |
|
46 | - return ''; |
|
47 | - } |
|
48 | - //double-check it's a string. It's possible this value was a question option that happened to be a numeric |
|
49 | - //string, in which case PHP has automatically converted it to an integer! |
|
50 | - return (string)$normalized_value; |
|
51 | - } |
|
36 | + /** |
|
37 | + * IF its a string in PHP, it will be a string in the HTML form. easy |
|
38 | + * |
|
39 | + * @param string $normalized_value |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function unnormalize($normalized_value) |
|
43 | + { |
|
44 | + //account for default "select here" option values |
|
45 | + if ($normalized_value === null) { |
|
46 | + return ''; |
|
47 | + } |
|
48 | + //double-check it's a string. It's possible this value was a question option that happened to be a numeric |
|
49 | + //string, in which case PHP has automatically converted it to an integer! |
|
50 | + return (string)$normalized_value; |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | // End of file EE_Text_Normalization.strategy.php |
@@ -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 | |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | public function normalize($value_to_normalize) |
23 | 23 | { |
24 | 24 | if (is_array($value_to_normalize)) { |
25 | - return (string)array_shift($value_to_normalize); |
|
25 | + return (string) array_shift($value_to_normalize); |
|
26 | 26 | } |
27 | 27 | // consider `"null"` values to be equivalent to null. |
28 | 28 | if ($value_to_normalize === '' || $value_to_normalize === null) { |
29 | 29 | return null; |
30 | 30 | } |
31 | - return (string)$value_to_normalize; |
|
31 | + return (string) $value_to_normalize; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | //double-check it's a string. It's possible this value was a question option that happened to be a numeric |
49 | 49 | //string, in which case PHP has automatically converted it to an integer! |
50 | - return (string)$normalized_value; |
|
50 | + return (string) $normalized_value; |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | // End of file EE_Text_Normalization.strategy.php |
@@ -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 | |
@@ -14,60 +14,60 @@ discard block |
||
14 | 14 | abstract class EE_Normalization_Strategy_Base extends EE_Form_Input_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Takes the sanitized value for the input and casts it into the correct PHP type. |
|
19 | - * Eg, turns it into an int, float, string, boolean, datetime, etc. The validation |
|
20 | - * strategy should be able to depend on the normalized value being of the correct type. |
|
21 | - * If the normalized value passes validation, the normalized value is what other code |
|
22 | - * will operate on. If the sanitized value cannot be normalized, this method should either |
|
23 | - * add a validation error onto the input, or wrangle the input into a format that can be normalized |
|
24 | - * (eg, for a date input, if the user enters "2014/100/100", you can either add an error stating |
|
25 | - * "hey! 2014/100/100 is not a valid date!", or simply convert it into a valid date like "2014/12/31". |
|
26 | - * For this case, I'd prefer the former. But there may be cases where you'd just rather correct it for them) |
|
27 | - * |
|
28 | - * @param string $value_to_normalize it should always be a string. If the input receives an array, then the |
|
29 | - * validation strategy should be called on array elements, not on the entire array |
|
30 | - * @return mixed the normalized value |
|
31 | - */ |
|
32 | - abstract public function normalize($value_to_normalize); |
|
17 | + /** |
|
18 | + * Takes the sanitized value for the input and casts it into the correct PHP type. |
|
19 | + * Eg, turns it into an int, float, string, boolean, datetime, etc. The validation |
|
20 | + * strategy should be able to depend on the normalized value being of the correct type. |
|
21 | + * If the normalized value passes validation, the normalized value is what other code |
|
22 | + * will operate on. If the sanitized value cannot be normalized, this method should either |
|
23 | + * add a validation error onto the input, or wrangle the input into a format that can be normalized |
|
24 | + * (eg, for a date input, if the user enters "2014/100/100", you can either add an error stating |
|
25 | + * "hey! 2014/100/100 is not a valid date!", or simply convert it into a valid date like "2014/12/31". |
|
26 | + * For this case, I'd prefer the former. But there may be cases where you'd just rather correct it for them) |
|
27 | + * |
|
28 | + * @param string $value_to_normalize it should always be a string. If the input receives an array, then the |
|
29 | + * validation strategy should be called on array elements, not on the entire array |
|
30 | + * @return mixed the normalized value |
|
31 | + */ |
|
32 | + abstract public function normalize($value_to_normalize); |
|
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * Identical to normalize, except normalize_one() CANNOT be passed an array and |
|
38 | - * never returns an array. Useful if the normalization strategy converts between arrays |
|
39 | - * |
|
40 | - * @param string $individual_item_to_normalize |
|
41 | - * @return mixed |
|
42 | - */ |
|
43 | - public function normalize_one($individual_item_to_normalize) |
|
44 | - { |
|
45 | - return $this->normalize($individual_item_to_normalize); |
|
46 | - } |
|
36 | + /** |
|
37 | + * Identical to normalize, except normalize_one() CANNOT be passed an array and |
|
38 | + * never returns an array. Useful if the normalization strategy converts between arrays |
|
39 | + * |
|
40 | + * @param string $individual_item_to_normalize |
|
41 | + * @return mixed |
|
42 | + */ |
|
43 | + public function normalize_one($individual_item_to_normalize) |
|
44 | + { |
|
45 | + return $this->normalize($individual_item_to_normalize); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Takes the normalized value (for an Yes_No_Input this could be TRUE or FALSE), and converts it into |
|
52 | - * the value you would use in the html form (for a Yes_No_Input this could be '1' or '0'). |
|
53 | - * |
|
54 | - * @param $normalized_value |
|
55 | - * @return array|string the 'raw' value as used in the form, usually a string or array of strings. |
|
56 | - */ |
|
57 | - abstract public function unnormalize($normalized_value); |
|
50 | + /** |
|
51 | + * Takes the normalized value (for an Yes_No_Input this could be TRUE or FALSE), and converts it into |
|
52 | + * the value you would use in the html form (for a Yes_No_Input this could be '1' or '0'). |
|
53 | + * |
|
54 | + * @param $normalized_value |
|
55 | + * @return array|string the 'raw' value as used in the form, usually a string or array of strings. |
|
56 | + */ |
|
57 | + abstract public function unnormalize($normalized_value); |
|
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Normally the same as unnormalize, except it CANNOT be passed an array and |
|
63 | - * ALWAYS returns a string |
|
64 | - * |
|
65 | - * @param mixed $individual_item_to_unnormalize NOT an array |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function unnormalize_one($individual_item_to_unnormalize) |
|
69 | - { |
|
70 | - return $this->unnormalize($individual_item_to_unnormalize); |
|
71 | - } |
|
61 | + /** |
|
62 | + * Normally the same as unnormalize, except it CANNOT be passed an array and |
|
63 | + * ALWAYS returns a string |
|
64 | + * |
|
65 | + * @param mixed $individual_item_to_unnormalize NOT an array |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function unnormalize_one($individual_item_to_unnormalize) |
|
69 | + { |
|
70 | + return $this->unnormalize($individual_item_to_unnormalize); |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | // End of file EE_Normalization_Strategy_Base.strategy.php |
@@ -1,4 +1,4 @@ |
||
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 |