Completed
Branch BUG-10381-asset-loading (366f84)
by
unknown
13:07 queued 32s
created
templates/support_admin_details_shortcodes_event_listings.template.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <div class="padding">
2 2
 	<p>
3
-        <?php esc_html_e('Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', 'event_espresso'); ?> <?php echo sprintf( esc_html__('For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', 'event_espresso'), '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', '</a>' ); ?>
3
+        <?php esc_html_e('Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', 'event_espresso'); ?> <?php echo sprintf(esc_html__('For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', 'event_espresso'), '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', '</a>'); ?>
4 4
     </p>
5 5
 		<ul>
6 6
 			<li><strong><?php esc_html_e('Show a list of all of your events', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS]</li>
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 			<li><strong><?php esc_html_e('Don\'t display a title/heading before the event list', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS show_title=false]</li>
9 9
 			<li><strong><?php esc_html_e('Limit (paginate) the number of events that are shown in the event list on a page or post', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS limit=5]</li>
10 10
 			<li><strong><?php esc_html_e('Add a custom CSS class to each event post/article', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS css_class=my-custom-class]</li>
11
-			<li><strong><?php esc_html_e('Filter the event list by month and year', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS month="<?php echo date( 'F Y' ); ?>"]</li>
11
+			<li><strong><?php esc_html_e('Filter the event list by month and year', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS month="<?php echo date('F Y'); ?>"]</li>
12 12
 			<li><strong><?php esc_html_e('Show expired events in the event list', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS show_expired=true]</li>
13 13
 			<li><strong><?php esc_html_e('Sorts the event list in ascending order', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS sort=ASC]</li>
14 14
 			<li><strong><?php esc_html_e('Sorts the event list in descending order', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS sort=DESC]</li>
Please login to merge, or discard this patch.
caffeinated/payment_methods/Paypal_Pro/EEG_Paypal_Pro.gateway.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@
 block discarded – undo
450 450
 
451 451
 
452 452
     /**
453
-     * @param $Request
453
+     * @param string $Request
454 454
      * @return mixed
455 455
      */
456 456
     private function _CURLRequest($Request)
Please login to merge, or discard this patch.
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -25,549 +25,549 @@  discard block
 block discarded – undo
25 25
 class EEG_Paypal_Pro extends EE_Onsite_Gateway
26 26
 {
27 27
 
28
-    /**
29
-     * @var $_paypal_api_username string
30
-     */
31
-    protected $_username = null;
32
-
33
-    /**
34
-     * @var $_password string
35
-     */
36
-    protected $_password = null;
37
-
38
-    /**
39
-     * @var $_signature string
40
-     */
41
-    protected $_signature = null;
42
-
43
-    /**
44
-     * @var $_credit_card_types array with the keys for credit card types accepted on this account
45
-     */
46
-    protected $_credit_card_types    = null;
47
-
48
-    protected $_currencies_supported = array(
49
-        'USD',
50
-        'GBP',
51
-        'CAD',
52
-        'AUD',
53
-        'BRL',
54
-        'CHF',
55
-        'CZK',
56
-        'DKK',
57
-        'EUR',
58
-        'HKD',
59
-        'HUF',
60
-        'ILS',
61
-        'JPY',
62
-        'MXN',
63
-        'MYR',
64
-        'NOK',
65
-        'NZD',
66
-        'PHP',
67
-        'PLN',
68
-        'SEK',
69
-        'SGD',
70
-        'THB',
71
-        'TRY',
72
-        'TWD',
73
-        'RUB',
74
-    );
75
-
76
-
77
-
78
-    /**
79
-     * @param EEI_Payment $payment
80
-     * @param array       $billing_info     {
81
-     * @type              $credit_card      string
82
-     * @type              $credit_card_type string
83
-     * @type              $exp_month        string always 2 characters
84
-     * @type              $exp_year         string always 4 characters
85
-     * @type              $cvv              string
86
-     *                                      } @see parent::do_direct_payment for more info
87
-     * @return \EE_Payment|\EEI_Payment
88
-     */
89
-    public function do_direct_payment($payment, $billing_info = null)
90
-    {
91
-        $transaction = $payment->transaction();
92
-        if (! $transaction instanceof EEI_Transaction) {
93
-            throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso'));
94
-        }
95
-        $primary_registrant = $transaction->primary_registration();
96
-        if (! $primary_registrant instanceof EEI_Registration) {
97
-            throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.',
98
-                'event_espresso'));
99
-        }
100
-        $attendee = $primary_registrant->attendee();
101
-        if (! $attendee instanceof EEI_Attendee) {
102
-            throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.',
103
-                'event_espresso'));
104
-        }
105
-        $order_description = $this->_format_order_description($payment);
106
-        //charge for the full amount. Show itemized list
107
-        if ($this->_can_easily_itemize_transaction_for($payment)) {
108
-            $item_num = 1;
109
-            $total_line_item = $transaction->total_line_item();
110
-            $order_items = array();
111
-            foreach ($total_line_item->get_items() as $line_item) {
112
-                //ignore line items with a quantity of 0
113
-                if ($line_item->quantity() == 0) {
114
-                    continue;
115
-                }
116
-                $item = array(
117
-                    // Item Name.  127 char max.
118
-                    'l_name'                 => substr(
119
-                        $this->_format_line_item_name($line_item, $payment),
120
-                        0,
121
-                        127
122
-                    ),
123
-                    // Item description.  127 char max.
124
-                    'l_desc'                 => substr(
125
-                        $this->_format_line_item_desc($line_item, $payment),
126
-                        0,
127
-                        127
128
-                    ),
129
-                    // Cost of individual item.
130
-                    'l_amt'                  => $line_item->unit_price(),
131
-                    // Item Number.  127 char max.
132
-                    'l_number'               => $item_num++,
133
-                    // Item quantity.  Must be any positive integer.
134
-                    'l_qty'                  => $line_item->quantity(),
135
-                    // Item's sales tax amount.
136
-                    'l_taxamt'               => '',
137
-                    // eBay auction number of item.
138
-                    'l_ebayitemnumber'       => '',
139
-                    // eBay transaction ID of purchased item.
140
-                    'l_ebayitemauctiontxnid' => '',
141
-                    // eBay order ID for the item.
142
-                    'l_ebayitemorderid'      => '',
143
-                );
144
-                // add to array of all items
145
-                array_push($order_items, $item);
146
-            }
147
-            $item_amount = $total_line_item->get_items_total();
148
-            $tax_amount = $total_line_item->get_total_tax();
149
-        } else {
150
-            $order_items = array();
151
-            $item_amount = $payment->amount();
152
-            $tax_amount = 0;
153
-            array_push($order_items, array(
154
-                // Item Name.  127 char max.
155
-                'l_name'   => substr(
156
-                    $this->_format_partial_payment_line_item_name($payment),
157
-                    0,
158
-                    127
159
-                ),
160
-                // Item description.  127 char max.
161
-                'l_desc'   => substr(
162
-                    $this->_format_partial_payment_line_item_desc($payment),
163
-                    0,
164
-                    127
165
-                ),
166
-                // Cost of individual item.
167
-                'l_amt'    => $payment->amount(),
168
-                // Item Number.  127 char max.
169
-                'l_number' => 1,
170
-                // Item quantity.  Must be any positive integer.
171
-                'l_qty'    => 1,
172
-            ));
173
-        }
174
-        // Populate data arrays with order data.
175
-        $DPFields = array(
176
-            // How you want to obtain payment ?
177
-            // Authorization indidicates the payment is a basic auth subject to settlement with Auth & Capture.
178
-            // Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
179
-            'paymentaction'    => 'Sale',
180
-            // Required.  IP address of the payer's browser.
181
-            'ipaddress'        => $_SERVER['REMOTE_ADDR'],
182
-            // Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
183
-            'returnfmfdetails' => '1',
184
-        );
185
-        $CCDetails = array(
186
-            // Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
187
-            // If Maestro or Solo, the currency code must be GBP.  In addition, either start date or issue number must be specified.
188
-            'creditcardtype' => $billing_info['credit_card_type'],
189
-            // Required.  Credit card number.  No spaces or punctuation.
190
-            'acct'           => $billing_info['credit_card'],
191
-            // Required.  Credit card expiration date.  Format is MMYYYY
192
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
193
-            // Requirements determined by your PayPal account settings.  Security digits for credit card.
194
-            'cvv2'           => $billing_info['cvv'],
195
-        );
196
-        $PayerInfo = array(
197
-            // Email address of payer.
198
-            'email'       => $billing_info['email'],
199
-            // Unique PayPal customer ID for payer.
200
-            'payerid'     => '',
201
-            // Status of payer.  Values are verified or unverified
202
-            'payerstatus' => '',
203
-            // Payer's business name.
204
-            'business'    => '',
205
-        );
206
-        $PayerName = array(
207
-            // Payer's salutation.  20 char max.
208
-            'salutation' => '',
209
-            // Payer's first name.  25 char max.
210
-            'firstname'  => substr($billing_info['first_name'], 0, 25),
211
-            // Payer's middle name.  25 char max.
212
-            'middlename' => '',
213
-            // Payer's last name.  25 char max.
214
-            'lastname'   => substr($billing_info['last_name'], 0, 25),
215
-            // Payer's suffix.  12 char max.
216
-            'suffix'     => '',
217
-        );
218
-        $BillingAddress = array(
219
-            // Required.  First street address.
220
-            'street'      => $billing_info['address'],
221
-            // Second street address.
222
-            'street2'     => $billing_info['address2'],
223
-            // Required.  Name of City.
224
-            'city'        => $billing_info['city'],
225
-            // Required. Name of State or Province.
226
-            'state'       => substr($billing_info['state'], 0, 40),
227
-            // Required.  Country code.
228
-            'countrycode' => $billing_info['country'],
229
-            // Required.  Postal code of payer.
230
-            'zip'         => $billing_info['zip'],
231
-        );
232
-        //check if the registration info contains the needed fields for paypal pro (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
233
-        if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
234
-            $use_registration_address_info = true;
235
-        } else {
236
-            $use_registration_address_info = false;
237
-        }
238
-        //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again
239
-        $ShippingAddress = array(
240
-            'shiptoname'     => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
241
-            'shiptostreet'   => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100),
242
-            'shiptostreet2'  => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'], 0, 100),
243
-            'shiptocity'     => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'], 0, 40),
244
-            'state'          => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'], 0, 40),
245
-            'shiptocountry'  => $use_registration_address_info ? $attendee->country_ID() : $billing_info['country'],
246
-            'shiptozip'      => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'], 0, 20),
247
-            'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'], 0, 20),
248
-        );
249
-        $PaymentDetails = array(
250
-            // Required.  Total amount of order, including shipping, handling, and tax.
251
-            'amt'          => $this->format_currency($payment->amount()),
252
-            // Required.  Three-letter currency code.  Default is USD.
253
-            'currencycode' => $payment->currency_code(),
254
-            // Required if you include itemized cart details. (L_AMTn, etc.)  Subtotal of items not including S&H, or tax.
255
-            'itemamt'      => $this->format_currency($item_amount),//
256
-            // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
257
-            'shippingamt'  => '',
258
-            // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
259
-            'handlingamt'  => '',
260
-            // Required if you specify itemized cart tax details. Sum of tax for all items on the order.  Total sales tax.
261
-            'taxamt'       => $this->format_currency($tax_amount),
262
-            // Description of the order the customer is purchasing.  127 char max.
263
-            'desc'         => $order_description,
264
-            // Free-form field for your own use.  256 char max.
265
-            'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
266
-            // Your own invoice or tracking number
267
-            'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
268
-            // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
269
-            'notifyurl'    => '',
270
-            'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
271
-        );
272
-        // Wrap all data arrays into a single, "master" array which will be passed into the class function.
273
-        $PayPalRequestData = array(
274
-            'DPFields'        => $DPFields,
275
-            'CCDetails'       => $CCDetails,
276
-            'PayerInfo'       => $PayerInfo,
277
-            'PayerName'       => $PayerName,
278
-            'BillingAddress'  => $BillingAddress,
279
-            'ShippingAddress' => $ShippingAddress,
280
-            'PaymentDetails'  => $PaymentDetails,
281
-            'OrderItems'      => $order_items,
282
-        );
283
-        $this->_log_clean_request($PayPalRequestData, $payment);
284
-        try {
285
-            $PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
286
-            //remove PCI-sensitive data so it doesn't get stored
287
-            $PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
288
-            $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
289
-            if (empty($PayPalResult['RAWRESPONSE'])) {
290
-                $payment->set_status($this->_pay_model->failed_status());
291
-                $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
292
-                $payment->set_details($PayPalResult);
293
-            } else {
294
-                if ($this->_APICallSuccessful($PayPalResult)) {
295
-                    $payment->set_status($this->_pay_model->approved_status());
296
-                } else {
297
-                    $payment->set_status($this->_pay_model->declined_status());
298
-                }
299
-                //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
300
-                $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
301
-                $payment->set_gateway_response($message);
302
-                $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) ? $PayPalResult['TRANSACTIONID'] : null);
303
-                $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : '';
304
-                $payment->set_extra_accntng($primary_registration_code);
305
-                $payment->set_details($PayPalResult);
306
-            }
307
-        } catch (Exception $e) {
308
-            $payment->set_status($this->_pay_model->failed_status());
309
-            $payment->set_gateway_response($e->getMessage());
310
-        }
311
-        //$payment->set_status( $this->_pay_model->declined_status() );
312
-        //$payment->set_gateway_response( '' );
313
-        return $payment;
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * CLeans out sensitive CC data and then logs it, and returns the cleaned request
320
-     *
321
-     * @param array       $request
322
-     * @param EEI_Payment $payment
323
-     * @return array
324
-     */
325
-    private function _log_clean_request($request, $payment)
326
-    {
327
-        $cleaned_request_data = $request;
328
-        unset($cleaned_request_data['CCDetails']['acct']);
329
-        unset($cleaned_request_data['CCDetails']['cvv2']);
330
-        unset($cleaned_request_data['CCDetails']['expdate']);
331
-        $this->log(array('Paypal Request' => $cleaned_request_data), $payment);
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * Cleans the response, logs it, and returns it
338
-     *
339
-     * @param array       $response
340
-     * @param EEI_Payment $payment
341
-     * @return array cleaned
342
-     */
343
-    private function _log_clean_response($response, $payment)
344
-    {
345
-        unset($response['REQUESTDATA']['CREDITCARDTYPE']);
346
-        unset($response['REQUESTDATA']['ACCT']);
347
-        unset($response['REQUESTDATA']['EXPDATE']);
348
-        unset($response['REQUESTDATA']['CVV2']);
349
-        unset($response['RAWREQUEST']);
350
-        $this->log(array('Paypal Response' => $response), $payment);
351
-        return $response;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * @param $DataArray
358
-     * @return array
359
-     */
360
-    private function prep_and_curl_request($DataArray)
361
-    {
362
-        // Create empty holders for each portion of the NVP string
363
-        $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
364
-        $CCDetailsNVP = '';
365
-        $PayerInfoNVP = '';
366
-        $PayerNameNVP = '';
367
-        $BillingAddressNVP = '';
368
-        $ShippingAddressNVP = '';
369
-        $PaymentDetailsNVP = '';
370
-        $OrderItemsNVP = '';
371
-        $Secure3DNVP = '';
372
-        // DP Fields
373
-        $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
374
-        foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
375
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
376
-        }
377
-        // CC Details Fields
378
-        $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
379
-        foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
380
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
381
-        }
382
-        // PayerInfo Type Fields
383
-        $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
384
-        foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
385
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
386
-        }
387
-        // Payer Name Fields
388
-        $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
389
-        foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
390
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
391
-        }
392
-        // Address Fields (Billing)
393
-        $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
394
-        foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
395
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
396
-        }
397
-        // Payment Details Type Fields
398
-        $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
399
-        foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
400
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
401
-        }
402
-        // Payment Details Item Type Fields
403
-        $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
404
-        $n = 0;
405
-        foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
406
-            $CurrentItem = $OrderItems[$OrderItemsVar];
407
-            foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
408
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
409
-            }
410
-            $n++;
411
-        }
412
-        // Ship To Address Fields
413
-        $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
414
-        foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
415
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
416
-        }
417
-        // 3D Secure Fields
418
-        $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
419
-        foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
420
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
421
-        }
422
-        // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
423
-        $NVPRequest = 'USER='
424
-                      . $this->_username
425
-                      . '&PWD='
426
-                      . $this->_password
427
-                      . '&VERSION=64.0'
428
-                      . '&SIGNATURE='
429
-                      . $this->_signature
430
-                      . $DPFieldsNVP
431
-                      . $CCDetailsNVP
432
-                      . $PayerInfoNVP
433
-                      . $PayerNameNVP
434
-                      . $BillingAddressNVP
435
-                      . $PaymentDetailsNVP
436
-                      . $OrderItemsNVP
437
-                      . $ShippingAddressNVP
438
-                      . $Secure3DNVP;
439
-        $NVPResponse = $this->_CURLRequest($NVPRequest);
440
-        $NVPRequestArray = $this->_NVPToArray($NVPRequest);
441
-        $NVPResponseArray = $this->_NVPToArray($NVPResponse);
442
-        $Errors = $this->_GetErrors($NVPResponseArray);
443
-        $NVPResponseArray['ERRORS'] = $Errors;
444
-        $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
445
-        $NVPResponseArray['RAWREQUEST'] = $NVPRequest;
446
-        $NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
447
-        return $NVPResponseArray;
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     * @param $Request
454
-     * @return mixed
455
-     */
456
-    private function _CURLRequest($Request)
457
-    {
458
-        $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
459
-        $curl = curl_init();
460
-        curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
461
-        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
462
-        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
463
-        curl_setopt($curl, CURLOPT_URL, $EndPointURL);
464
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
465
-        curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
466
-        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
467
-        //execute the curl POST
468
-        $Response = curl_exec($curl);
469
-        curl_close($curl);
470
-        return $Response;
471
-    }
472
-
473
-
474
-
475
-    /**
476
-     * @param $NVPString
477
-     * @return array
478
-     */
479
-    private function _NVPToArray($NVPString)
480
-    {
481
-        // prepare responses into array
482
-        $proArray = array();
483
-        while (strlen($NVPString)) {
484
-            // name
485
-            $keypos = strpos($NVPString, '=');
486
-            $keyval = substr($NVPString, 0, $keypos);
487
-            // value
488
-            $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
489
-            $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
490
-            // decoding the respose
491
-            $proArray[$keyval] = urldecode($valval);
492
-            $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
493
-        }
494
-        return $proArray;
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * @param array $PayPalResult
501
-     * @return bool
502
-     */
503
-    private function _APICallSuccessful($PayPalResult)
504
-    {
505
-        $approved = false;
506
-        // check main response message from PayPal
507
-        if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
508
-            $ack = strtoupper($PayPalResult['ACK']);
509
-            $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
510
-        }
511
-        return $approved;
512
-    }
513
-
514
-
515
-
516
-    /**
517
-     * @param $DataArray
518
-     * @return array
519
-     */
520
-    private function _GetErrors($DataArray)
521
-    {
522
-        $Errors = array();
523
-        $n = 0;
524
-        while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
525
-            $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
526
-            $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : '';
527
-            $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : '';
528
-            $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : '';
529
-            $CurrentItem = array(
530
-                'L_ERRORCODE'    => $LErrorCode,
531
-                'L_SHORTMESSAGE' => $LShortMessage,
532
-                'L_LONGMESSAGE'  => $LLongMessage,
533
-                'L_SEVERITYCODE' => $LSeverityCode,
534
-            );
535
-            array_push($Errors, $CurrentItem);
536
-            $n++;
537
-        }
538
-        return $Errors;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     *        nothing to see here...  move along....
545
-     *
546
-     * @access protected
547
-     * @param $Errors
548
-     * @return string
549
-     */
550
-    private function _DisplayErrors($Errors)
551
-    {
552
-        $error = '';
553
-        foreach ($Errors as $ErrorVar => $ErrorVal) {
554
-            $CurrentError = $Errors[$ErrorVar];
555
-            foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
556
-                $CurrentVarName = '';
557
-                if ($CurrentErrorVar == 'L_ERRORCODE') {
558
-                    $CurrentVarName = 'Error Code';
559
-                } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
560
-                    $CurrentVarName = 'Short Message';
561
-                } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
562
-                    $CurrentVarName = 'Long Message';
563
-                } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
564
-                    $CurrentVarName = 'Severity Code';
565
-                }
566
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
567
-            }
568
-        }
569
-        return $error;
570
-    }
28
+	/**
29
+	 * @var $_paypal_api_username string
30
+	 */
31
+	protected $_username = null;
32
+
33
+	/**
34
+	 * @var $_password string
35
+	 */
36
+	protected $_password = null;
37
+
38
+	/**
39
+	 * @var $_signature string
40
+	 */
41
+	protected $_signature = null;
42
+
43
+	/**
44
+	 * @var $_credit_card_types array with the keys for credit card types accepted on this account
45
+	 */
46
+	protected $_credit_card_types    = null;
47
+
48
+	protected $_currencies_supported = array(
49
+		'USD',
50
+		'GBP',
51
+		'CAD',
52
+		'AUD',
53
+		'BRL',
54
+		'CHF',
55
+		'CZK',
56
+		'DKK',
57
+		'EUR',
58
+		'HKD',
59
+		'HUF',
60
+		'ILS',
61
+		'JPY',
62
+		'MXN',
63
+		'MYR',
64
+		'NOK',
65
+		'NZD',
66
+		'PHP',
67
+		'PLN',
68
+		'SEK',
69
+		'SGD',
70
+		'THB',
71
+		'TRY',
72
+		'TWD',
73
+		'RUB',
74
+	);
75
+
76
+
77
+
78
+	/**
79
+	 * @param EEI_Payment $payment
80
+	 * @param array       $billing_info     {
81
+	 * @type              $credit_card      string
82
+	 * @type              $credit_card_type string
83
+	 * @type              $exp_month        string always 2 characters
84
+	 * @type              $exp_year         string always 4 characters
85
+	 * @type              $cvv              string
86
+	 *                                      } @see parent::do_direct_payment for more info
87
+	 * @return \EE_Payment|\EEI_Payment
88
+	 */
89
+	public function do_direct_payment($payment, $billing_info = null)
90
+	{
91
+		$transaction = $payment->transaction();
92
+		if (! $transaction instanceof EEI_Transaction) {
93
+			throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso'));
94
+		}
95
+		$primary_registrant = $transaction->primary_registration();
96
+		if (! $primary_registrant instanceof EEI_Registration) {
97
+			throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.',
98
+				'event_espresso'));
99
+		}
100
+		$attendee = $primary_registrant->attendee();
101
+		if (! $attendee instanceof EEI_Attendee) {
102
+			throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.',
103
+				'event_espresso'));
104
+		}
105
+		$order_description = $this->_format_order_description($payment);
106
+		//charge for the full amount. Show itemized list
107
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
108
+			$item_num = 1;
109
+			$total_line_item = $transaction->total_line_item();
110
+			$order_items = array();
111
+			foreach ($total_line_item->get_items() as $line_item) {
112
+				//ignore line items with a quantity of 0
113
+				if ($line_item->quantity() == 0) {
114
+					continue;
115
+				}
116
+				$item = array(
117
+					// Item Name.  127 char max.
118
+					'l_name'                 => substr(
119
+						$this->_format_line_item_name($line_item, $payment),
120
+						0,
121
+						127
122
+					),
123
+					// Item description.  127 char max.
124
+					'l_desc'                 => substr(
125
+						$this->_format_line_item_desc($line_item, $payment),
126
+						0,
127
+						127
128
+					),
129
+					// Cost of individual item.
130
+					'l_amt'                  => $line_item->unit_price(),
131
+					// Item Number.  127 char max.
132
+					'l_number'               => $item_num++,
133
+					// Item quantity.  Must be any positive integer.
134
+					'l_qty'                  => $line_item->quantity(),
135
+					// Item's sales tax amount.
136
+					'l_taxamt'               => '',
137
+					// eBay auction number of item.
138
+					'l_ebayitemnumber'       => '',
139
+					// eBay transaction ID of purchased item.
140
+					'l_ebayitemauctiontxnid' => '',
141
+					// eBay order ID for the item.
142
+					'l_ebayitemorderid'      => '',
143
+				);
144
+				// add to array of all items
145
+				array_push($order_items, $item);
146
+			}
147
+			$item_amount = $total_line_item->get_items_total();
148
+			$tax_amount = $total_line_item->get_total_tax();
149
+		} else {
150
+			$order_items = array();
151
+			$item_amount = $payment->amount();
152
+			$tax_amount = 0;
153
+			array_push($order_items, array(
154
+				// Item Name.  127 char max.
155
+				'l_name'   => substr(
156
+					$this->_format_partial_payment_line_item_name($payment),
157
+					0,
158
+					127
159
+				),
160
+				// Item description.  127 char max.
161
+				'l_desc'   => substr(
162
+					$this->_format_partial_payment_line_item_desc($payment),
163
+					0,
164
+					127
165
+				),
166
+				// Cost of individual item.
167
+				'l_amt'    => $payment->amount(),
168
+				// Item Number.  127 char max.
169
+				'l_number' => 1,
170
+				// Item quantity.  Must be any positive integer.
171
+				'l_qty'    => 1,
172
+			));
173
+		}
174
+		// Populate data arrays with order data.
175
+		$DPFields = array(
176
+			// How you want to obtain payment ?
177
+			// Authorization indidicates the payment is a basic auth subject to settlement with Auth & Capture.
178
+			// Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
179
+			'paymentaction'    => 'Sale',
180
+			// Required.  IP address of the payer's browser.
181
+			'ipaddress'        => $_SERVER['REMOTE_ADDR'],
182
+			// Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
183
+			'returnfmfdetails' => '1',
184
+		);
185
+		$CCDetails = array(
186
+			// Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
187
+			// If Maestro or Solo, the currency code must be GBP.  In addition, either start date or issue number must be specified.
188
+			'creditcardtype' => $billing_info['credit_card_type'],
189
+			// Required.  Credit card number.  No spaces or punctuation.
190
+			'acct'           => $billing_info['credit_card'],
191
+			// Required.  Credit card expiration date.  Format is MMYYYY
192
+			'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
193
+			// Requirements determined by your PayPal account settings.  Security digits for credit card.
194
+			'cvv2'           => $billing_info['cvv'],
195
+		);
196
+		$PayerInfo = array(
197
+			// Email address of payer.
198
+			'email'       => $billing_info['email'],
199
+			// Unique PayPal customer ID for payer.
200
+			'payerid'     => '',
201
+			// Status of payer.  Values are verified or unverified
202
+			'payerstatus' => '',
203
+			// Payer's business name.
204
+			'business'    => '',
205
+		);
206
+		$PayerName = array(
207
+			// Payer's salutation.  20 char max.
208
+			'salutation' => '',
209
+			// Payer's first name.  25 char max.
210
+			'firstname'  => substr($billing_info['first_name'], 0, 25),
211
+			// Payer's middle name.  25 char max.
212
+			'middlename' => '',
213
+			// Payer's last name.  25 char max.
214
+			'lastname'   => substr($billing_info['last_name'], 0, 25),
215
+			// Payer's suffix.  12 char max.
216
+			'suffix'     => '',
217
+		);
218
+		$BillingAddress = array(
219
+			// Required.  First street address.
220
+			'street'      => $billing_info['address'],
221
+			// Second street address.
222
+			'street2'     => $billing_info['address2'],
223
+			// Required.  Name of City.
224
+			'city'        => $billing_info['city'],
225
+			// Required. Name of State or Province.
226
+			'state'       => substr($billing_info['state'], 0, 40),
227
+			// Required.  Country code.
228
+			'countrycode' => $billing_info['country'],
229
+			// Required.  Postal code of payer.
230
+			'zip'         => $billing_info['zip'],
231
+		);
232
+		//check if the registration info contains the needed fields for paypal pro (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
233
+		if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
234
+			$use_registration_address_info = true;
235
+		} else {
236
+			$use_registration_address_info = false;
237
+		}
238
+		//so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again
239
+		$ShippingAddress = array(
240
+			'shiptoname'     => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
241
+			'shiptostreet'   => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100),
242
+			'shiptostreet2'  => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'], 0, 100),
243
+			'shiptocity'     => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'], 0, 40),
244
+			'state'          => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'], 0, 40),
245
+			'shiptocountry'  => $use_registration_address_info ? $attendee->country_ID() : $billing_info['country'],
246
+			'shiptozip'      => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'], 0, 20),
247
+			'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'], 0, 20),
248
+		);
249
+		$PaymentDetails = array(
250
+			// Required.  Total amount of order, including shipping, handling, and tax.
251
+			'amt'          => $this->format_currency($payment->amount()),
252
+			// Required.  Three-letter currency code.  Default is USD.
253
+			'currencycode' => $payment->currency_code(),
254
+			// Required if you include itemized cart details. (L_AMTn, etc.)  Subtotal of items not including S&H, or tax.
255
+			'itemamt'      => $this->format_currency($item_amount),//
256
+			// Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
257
+			'shippingamt'  => '',
258
+			// Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
259
+			'handlingamt'  => '',
260
+			// Required if you specify itemized cart tax details. Sum of tax for all items on the order.  Total sales tax.
261
+			'taxamt'       => $this->format_currency($tax_amount),
262
+			// Description of the order the customer is purchasing.  127 char max.
263
+			'desc'         => $order_description,
264
+			// Free-form field for your own use.  256 char max.
265
+			'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
266
+			// Your own invoice or tracking number
267
+			'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
268
+			// URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
269
+			'notifyurl'    => '',
270
+			'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
271
+		);
272
+		// Wrap all data arrays into a single, "master" array which will be passed into the class function.
273
+		$PayPalRequestData = array(
274
+			'DPFields'        => $DPFields,
275
+			'CCDetails'       => $CCDetails,
276
+			'PayerInfo'       => $PayerInfo,
277
+			'PayerName'       => $PayerName,
278
+			'BillingAddress'  => $BillingAddress,
279
+			'ShippingAddress' => $ShippingAddress,
280
+			'PaymentDetails'  => $PaymentDetails,
281
+			'OrderItems'      => $order_items,
282
+		);
283
+		$this->_log_clean_request($PayPalRequestData, $payment);
284
+		try {
285
+			$PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
286
+			//remove PCI-sensitive data so it doesn't get stored
287
+			$PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
288
+			$message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
289
+			if (empty($PayPalResult['RAWRESPONSE'])) {
290
+				$payment->set_status($this->_pay_model->failed_status());
291
+				$payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
292
+				$payment->set_details($PayPalResult);
293
+			} else {
294
+				if ($this->_APICallSuccessful($PayPalResult)) {
295
+					$payment->set_status($this->_pay_model->approved_status());
296
+				} else {
297
+					$payment->set_status($this->_pay_model->declined_status());
298
+				}
299
+				//make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
300
+				$payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
301
+				$payment->set_gateway_response($message);
302
+				$payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) ? $PayPalResult['TRANSACTIONID'] : null);
303
+				$primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : '';
304
+				$payment->set_extra_accntng($primary_registration_code);
305
+				$payment->set_details($PayPalResult);
306
+			}
307
+		} catch (Exception $e) {
308
+			$payment->set_status($this->_pay_model->failed_status());
309
+			$payment->set_gateway_response($e->getMessage());
310
+		}
311
+		//$payment->set_status( $this->_pay_model->declined_status() );
312
+		//$payment->set_gateway_response( '' );
313
+		return $payment;
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * CLeans out sensitive CC data and then logs it, and returns the cleaned request
320
+	 *
321
+	 * @param array       $request
322
+	 * @param EEI_Payment $payment
323
+	 * @return array
324
+	 */
325
+	private function _log_clean_request($request, $payment)
326
+	{
327
+		$cleaned_request_data = $request;
328
+		unset($cleaned_request_data['CCDetails']['acct']);
329
+		unset($cleaned_request_data['CCDetails']['cvv2']);
330
+		unset($cleaned_request_data['CCDetails']['expdate']);
331
+		$this->log(array('Paypal Request' => $cleaned_request_data), $payment);
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * Cleans the response, logs it, and returns it
338
+	 *
339
+	 * @param array       $response
340
+	 * @param EEI_Payment $payment
341
+	 * @return array cleaned
342
+	 */
343
+	private function _log_clean_response($response, $payment)
344
+	{
345
+		unset($response['REQUESTDATA']['CREDITCARDTYPE']);
346
+		unset($response['REQUESTDATA']['ACCT']);
347
+		unset($response['REQUESTDATA']['EXPDATE']);
348
+		unset($response['REQUESTDATA']['CVV2']);
349
+		unset($response['RAWREQUEST']);
350
+		$this->log(array('Paypal Response' => $response), $payment);
351
+		return $response;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * @param $DataArray
358
+	 * @return array
359
+	 */
360
+	private function prep_and_curl_request($DataArray)
361
+	{
362
+		// Create empty holders for each portion of the NVP string
363
+		$DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
364
+		$CCDetailsNVP = '';
365
+		$PayerInfoNVP = '';
366
+		$PayerNameNVP = '';
367
+		$BillingAddressNVP = '';
368
+		$ShippingAddressNVP = '';
369
+		$PaymentDetailsNVP = '';
370
+		$OrderItemsNVP = '';
371
+		$Secure3DNVP = '';
372
+		// DP Fields
373
+		$DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
374
+		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
375
+			$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
376
+		}
377
+		// CC Details Fields
378
+		$CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
379
+		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
380
+			$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
381
+		}
382
+		// PayerInfo Type Fields
383
+		$PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
384
+		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
385
+			$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
386
+		}
387
+		// Payer Name Fields
388
+		$PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
389
+		foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
390
+			$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
391
+		}
392
+		// Address Fields (Billing)
393
+		$BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
394
+		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
395
+			$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
396
+		}
397
+		// Payment Details Type Fields
398
+		$PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
399
+		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
400
+			$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
401
+		}
402
+		// Payment Details Item Type Fields
403
+		$OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
404
+		$n = 0;
405
+		foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
406
+			$CurrentItem = $OrderItems[$OrderItemsVar];
407
+			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
408
+				$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
409
+			}
410
+			$n++;
411
+		}
412
+		// Ship To Address Fields
413
+		$ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
414
+		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
415
+			$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
416
+		}
417
+		// 3D Secure Fields
418
+		$Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
419
+		foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
420
+			$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
421
+		}
422
+		// Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
423
+		$NVPRequest = 'USER='
424
+					  . $this->_username
425
+					  . '&PWD='
426
+					  . $this->_password
427
+					  . '&VERSION=64.0'
428
+					  . '&SIGNATURE='
429
+					  . $this->_signature
430
+					  . $DPFieldsNVP
431
+					  . $CCDetailsNVP
432
+					  . $PayerInfoNVP
433
+					  . $PayerNameNVP
434
+					  . $BillingAddressNVP
435
+					  . $PaymentDetailsNVP
436
+					  . $OrderItemsNVP
437
+					  . $ShippingAddressNVP
438
+					  . $Secure3DNVP;
439
+		$NVPResponse = $this->_CURLRequest($NVPRequest);
440
+		$NVPRequestArray = $this->_NVPToArray($NVPRequest);
441
+		$NVPResponseArray = $this->_NVPToArray($NVPResponse);
442
+		$Errors = $this->_GetErrors($NVPResponseArray);
443
+		$NVPResponseArray['ERRORS'] = $Errors;
444
+		$NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
445
+		$NVPResponseArray['RAWREQUEST'] = $NVPRequest;
446
+		$NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
447
+		return $NVPResponseArray;
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 * @param $Request
454
+	 * @return mixed
455
+	 */
456
+	private function _CURLRequest($Request)
457
+	{
458
+		$EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
459
+		$curl = curl_init();
460
+		curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
461
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
462
+		curl_setopt($curl, CURLOPT_TIMEOUT, 60);
463
+		curl_setopt($curl, CURLOPT_URL, $EndPointURL);
464
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
465
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
466
+		curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
467
+		//execute the curl POST
468
+		$Response = curl_exec($curl);
469
+		curl_close($curl);
470
+		return $Response;
471
+	}
472
+
473
+
474
+
475
+	/**
476
+	 * @param $NVPString
477
+	 * @return array
478
+	 */
479
+	private function _NVPToArray($NVPString)
480
+	{
481
+		// prepare responses into array
482
+		$proArray = array();
483
+		while (strlen($NVPString)) {
484
+			// name
485
+			$keypos = strpos($NVPString, '=');
486
+			$keyval = substr($NVPString, 0, $keypos);
487
+			// value
488
+			$valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
489
+			$valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
490
+			// decoding the respose
491
+			$proArray[$keyval] = urldecode($valval);
492
+			$NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
493
+		}
494
+		return $proArray;
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * @param array $PayPalResult
501
+	 * @return bool
502
+	 */
503
+	private function _APICallSuccessful($PayPalResult)
504
+	{
505
+		$approved = false;
506
+		// check main response message from PayPal
507
+		if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
508
+			$ack = strtoupper($PayPalResult['ACK']);
509
+			$approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
510
+		}
511
+		return $approved;
512
+	}
513
+
514
+
515
+
516
+	/**
517
+	 * @param $DataArray
518
+	 * @return array
519
+	 */
520
+	private function _GetErrors($DataArray)
521
+	{
522
+		$Errors = array();
523
+		$n = 0;
524
+		while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
525
+			$LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
526
+			$LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : '';
527
+			$LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : '';
528
+			$LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : '';
529
+			$CurrentItem = array(
530
+				'L_ERRORCODE'    => $LErrorCode,
531
+				'L_SHORTMESSAGE' => $LShortMessage,
532
+				'L_LONGMESSAGE'  => $LLongMessage,
533
+				'L_SEVERITYCODE' => $LSeverityCode,
534
+			);
535
+			array_push($Errors, $CurrentItem);
536
+			$n++;
537
+		}
538
+		return $Errors;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 *        nothing to see here...  move along....
545
+	 *
546
+	 * @access protected
547
+	 * @param $Errors
548
+	 * @return string
549
+	 */
550
+	private function _DisplayErrors($Errors)
551
+	{
552
+		$error = '';
553
+		foreach ($Errors as $ErrorVar => $ErrorVal) {
554
+			$CurrentError = $Errors[$ErrorVar];
555
+			foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
556
+				$CurrentVarName = '';
557
+				if ($CurrentErrorVar == 'L_ERRORCODE') {
558
+					$CurrentVarName = 'Error Code';
559
+				} elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
560
+					$CurrentVarName = 'Short Message';
561
+				} elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
562
+					$CurrentVarName = 'Long Message';
563
+				} elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
564
+					$CurrentVarName = 'Severity Code';
565
+				}
566
+				$error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
567
+			}
568
+		}
569
+		return $error;
570
+	}
571 571
 
572 572
 
573 573
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
     public function do_direct_payment($payment, $billing_info = null)
90 90
     {
91 91
         $transaction = $payment->transaction();
92
-        if (! $transaction instanceof EEI_Transaction) {
92
+        if ( ! $transaction instanceof EEI_Transaction) {
93 93
             throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso'));
94 94
         }
95 95
         $primary_registrant = $transaction->primary_registration();
96
-        if (! $primary_registrant instanceof EEI_Registration) {
96
+        if ( ! $primary_registrant instanceof EEI_Registration) {
97 97
             throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.',
98 98
                 'event_espresso'));
99 99
         }
100 100
         $attendee = $primary_registrant->attendee();
101
-        if (! $attendee instanceof EEI_Attendee) {
101
+        if ( ! $attendee instanceof EEI_Attendee) {
102 102
             throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.',
103 103
                 'event_espresso'));
104 104
         }
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
             // Required.  Credit card number.  No spaces or punctuation.
190 190
             'acct'           => $billing_info['credit_card'],
191 191
             // Required.  Credit card expiration date.  Format is MMYYYY
192
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
192
+            'expdate'        => $billing_info['exp_month'].$billing_info['exp_year'],
193 193
             // Requirements determined by your PayPal account settings.  Security digits for credit card.
194 194
             'cvv2'           => $billing_info['cvv'],
195 195
         );
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         }
238 238
         //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again
239 239
         $ShippingAddress = array(
240
-            'shiptoname'     => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
240
+            'shiptoname'     => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'].' '.$billing_info['last_name'], 0, 32),
241 241
             'shiptostreet'   => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100),
242 242
             'shiptostreet2'  => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'], 0, 100),
243 243
             'shiptocity'     => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'], 0, 40),
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
             // Required.  Three-letter currency code.  Default is USD.
253 253
             'currencycode' => $payment->currency_code(),
254 254
             // Required if you include itemized cart details. (L_AMTn, etc.)  Subtotal of items not including S&H, or tax.
255
-            'itemamt'      => $this->format_currency($item_amount),//
255
+            'itemamt'      => $this->format_currency($item_amount), //
256 256
             // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
257 257
             'shippingamt'  => '',
258 258
             // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
             // Free-form field for your own use.  256 char max.
265 265
             'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
266 266
             // Your own invoice or tracking number
267
-            'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
267
+            'invnum'       => wp_generate_password(12, false), //$transaction->ID(),
268 268
             // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
269 269
             'notifyurl'    => '',
270
-            'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
270
+            'buttonsource' => 'EventEspresso_SP', //EE will blow up if you change this
271 271
         );
272 272
         // Wrap all data arrays into a single, "master" array which will be passed into the class function.
273 273
         $PayPalRequestData = array(
@@ -372,32 +372,32 @@  discard block
 block discarded – undo
372 372
         // DP Fields
373 373
         $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
374 374
         foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
375
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
375
+            $DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal);
376 376
         }
377 377
         // CC Details Fields
378 378
         $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
379 379
         foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
380
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
380
+            $CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal);
381 381
         }
382 382
         // PayerInfo Type Fields
383 383
         $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
384 384
         foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
385
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
385
+            $PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal);
386 386
         }
387 387
         // Payer Name Fields
388 388
         $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
389 389
         foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
390
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
390
+            $PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal);
391 391
         }
392 392
         // Address Fields (Billing)
393 393
         $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
394 394
         foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
395
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
395
+            $BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal);
396 396
         }
397 397
         // Payment Details Type Fields
398 398
         $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
399 399
         foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
400
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
400
+            $PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal);
401 401
         }
402 402
         // Payment Details Item Type Fields
403 403
         $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
@@ -405,19 +405,19 @@  discard block
 block discarded – undo
405 405
         foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
406 406
             $CurrentItem = $OrderItems[$OrderItemsVar];
407 407
             foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
408
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
408
+                $OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal);
409 409
             }
410 410
             $n++;
411 411
         }
412 412
         // Ship To Address Fields
413 413
         $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
414 414
         foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
415
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
415
+            $ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal);
416 416
         }
417 417
         // 3D Secure Fields
418 418
         $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
419 419
         foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
420
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
420
+            $Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal);
421 421
         }
422 422
         // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
423 423
         $NVPRequest = 'USER='
@@ -521,11 +521,11 @@  discard block
 block discarded – undo
521 521
     {
522 522
         $Errors = array();
523 523
         $n = 0;
524
-        while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
525
-            $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
526
-            $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : '';
527
-            $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : '';
528
-            $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : '';
524
+        while (isset($DataArray['L_ERRORCODE'.$n.''])) {
525
+            $LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : '';
526
+            $LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.'']) ? $DataArray['L_SHORTMESSAGE'.$n.''] : '';
527
+            $LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.'']) ? $DataArray['L_LONGMESSAGE'.$n.''] : '';
528
+            $LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.'']) ? $DataArray['L_SEVERITYCODE'.$n.''] : '';
529 529
             $CurrentItem = array(
530 530
                 'L_ERRORCODE'    => $LErrorCode,
531 531
                 'L_SHORTMESSAGE' => $LShortMessage,
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
                 } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
564 564
                     $CurrentVarName = 'Severity Code';
565 565
                 }
566
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
566
+                $error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal;
567 567
             }
568 568
         }
569 569
         return $error;
Please login to merge, or discard this patch.
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param EE_Line_Item $line_item
78 78
      * @param array        $options
79 79
      * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
80
+     * @return string
81 81
      * @throws EE_Error
82 82
      */
83 83
     public function display_line_item(
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * _event_row - basically a Heading row displayed once above each event's ticket rows
224 224
      *
225 225
      * @param EE_Line_Item $line_item
226
-     * @return mixed
226
+     * @return string
227 227
      */
228 228
     private function _event_row(EE_Line_Item $line_item)
229 229
     {
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @param EE_Line_Item $line_item
251 251
      * @param array        $options
252
-     * @return mixed
252
+     * @return string
253 253
      * @throws EE_Error
254 254
      */
255 255
     private function _ticket_row(EE_Line_Item $line_item, $options = array())
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      *
304 304
      * @param EE_Line_Item $line_item
305 305
      * @param array        $options
306
-     * @return mixed
306
+     * @return string
307 307
      * @throws EE_Error
308 308
      */
309 309
     private function _item_row(EE_Line_Item $line_item, $options = array())
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @param EE_Line_Item $line_item
364 364
      * @param array        $options
365 365
      * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
366
+     * @return string
367 367
      * @throws EE_Error
368 368
      */
369 369
     private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      *
408 408
      * @param EE_Line_Item $line_item
409 409
      * @param array        $options
410
-     * @return mixed
410
+     * @return string
411 411
      * @throws EE_Error
412 412
      */
413 413
     private function _tax_row(EE_Line_Item $line_item, $options = array())
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      *
445 445
      * @param EE_Line_Item $line_item
446 446
      * @param string       $text
447
-     * @return mixed
447
+     * @return string
448 448
      * @throws EE_Error
449 449
      */
450 450
     private function _total_tax_row(EE_Line_Item $line_item, $text = '')
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
      * @param EE_Line_Item $line_item
484 484
      * @param string       $text
485 485
      * @param array        $options
486
-     * @return mixed
486
+     * @return string
487 487
      * @throws EE_Error
488 488
      */
489 489
     private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
      *
520 520
      * @param EE_Line_Item $line_item
521 521
      * @param string       $text
522
-     * @return mixed
522
+     * @return string
523 523
      * @throws EE_Error
524 524
      */
525 525
     private function _total_row(EE_Line_Item $line_item, $text = '')
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
      *
547 547
      * @param EE_Line_Item $line_item
548 548
      * @param array        $options
549
-     * @return mixed
549
+     * @return string
550 550
      * @throws EE_Error
551 551
      */
552 552
     private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
Please login to merge, or discard this patch.
Indentation   +603 added lines, -603 removed lines patch added patch discarded remove patch
@@ -16,609 +16,609 @@
 block discarded – undo
16 16
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
17 17
 {
18 18
 
19
-    /**
20
-     * array of events
21
-     *
22
-     * @type EE_Line_Item[] $_events
23
-     */
24
-    private $_events = array();
25
-
26
-    /**
27
-     * whether to display the taxes row or not
28
-     *
29
-     * @type bool $_show_taxes
30
-     */
31
-    private $_show_taxes = false;
32
-
33
-    /**
34
-     * html for any tax rows
35
-     *
36
-     * @type string $_show_taxes
37
-     */
38
-    private $_taxes_html = '';
39
-
40
-    /**
41
-     * total amount including tax we can bill for at this time
42
-     *
43
-     * @type float $_grand_total
44
-     */
45
-    private $_grand_total = 0.00;
46
-
47
-    /**
48
-     * total number of items being billed for
49
-     *
50
-     * @type int $_total_items
51
-     */
52
-    private $_total_items = 0;
53
-
54
-
55
-
56
-    /**
57
-     * @return float
58
-     */
59
-    public function grand_total()
60
-    {
61
-        return $this->_grand_total;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return int
68
-     */
69
-    public function total_items()
70
-    {
71
-        return $this->_total_items;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param EE_Line_Item $line_item
78
-     * @param array        $options
79
-     * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
81
-     * @throws EE_Error
82
-     */
83
-    public function display_line_item(
84
-        EE_Line_Item $line_item,
85
-        $options = array(),
86
-        EE_Line_Item $parent_line_item = null
87
-    ) {
88
-        $html = '';
89
-        // set some default options and merge with incoming
90
-        $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
92
-            'odd'       => false,
93
-        );
94
-        $options = array_merge($default_options, (array)$options);
95
-        switch ($line_item->type()) {
96
-            case EEM_Line_Item::type_line_item:
97
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
-                if ($line_item->OBJ_type() === 'Ticket') {
99
-                    // item row
100
-                    $html .= $this->_ticket_row($line_item, $options);
101
-                } else {
102
-                    // item row
103
-                    $html .= $this->_item_row($line_item, $options);
104
-                }
105
-                if (
106
-                apply_filters(
107
-                    'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
-                    true
109
-                )
110
-                ) {
111
-                    // got any kids?
112
-                    foreach ($line_item->children() as $child_line_item) {
113
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
114
-                    }
115
-                }
116
-                break;
117
-            case EEM_Line_Item::type_sub_line_item:
118
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
-                break;
120
-            case EEM_Line_Item::type_sub_total:
121
-                static $sub_total = 0;
122
-                $event_sub_total = 0;
123
-                $text = esc_html__('Sub-Total', 'event_espresso');
124
-                if ($line_item->OBJ_type() === 'Event') {
125
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
127
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
-                        // if event has default reg status of Not Approved, then don't display info on it
129
-                        if (
130
-                            $event instanceof EE_Event
131
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
-                        ) {
133
-                            $display_event = false;
134
-                            // unless there are registrations for it that are returning to pay
135
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
136
-                                foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
138
-                                        continue;
139
-                                    }
140
-                                    $display_event = $registration->event_ID() === $options['event_id']
141
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
-                                        ? true
143
-                                        : $display_event;
144
-                                }
145
-                            }
146
-                            if (! $display_event) {
147
-                                return '';
148
-                            }
149
-                        }
150
-                        $this->_events[$options['event_id']] = 0;
151
-                        $html .= $this->_event_row($line_item);
152
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
153
-                    }
154
-                }
155
-                $child_line_items = $line_item->children();
156
-                // loop thru children
157
-                foreach ($child_line_items as $child_line_item) {
158
-                    // recursively feed children back into this method
159
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
160
-                }
161
-                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
-                $sub_total += $event_sub_total;
163
-                if (
164
-                    (
165
-                        // event subtotals
166
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
-                    )
168
-                    || (
169
-                        // pre-tax subtotals
170
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
-                    )
172
-                ) {
173
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
175
-                }
176
-                break;
177
-            case EEM_Line_Item::type_tax:
178
-                if ($this->_show_taxes) {
179
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
180
-                }
181
-                break;
182
-            case EEM_Line_Item::type_tax_sub_total:
183
-                if ($this->_show_taxes) {
184
-                    $child_line_items = $line_item->children();
185
-                    // loop thru children
186
-                    foreach ($child_line_items as $child_line_item) {
187
-                        // recursively feed children back into this method
188
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
189
-                    }
190
-                    if (count($child_line_items) > 1) {
191
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
-                    }
193
-                }
194
-                break;
195
-            case EEM_Line_Item::type_total:
196
-                // get all child line items
197
-                $children = $line_item->children();
198
-                // loop thru all non-tax child line items
199
-                foreach ($children as $child_line_item) {
200
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
-                        // recursively feed children back into this method
202
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
203
-                    }
204
-                }
205
-                // now loop thru  tax child line items
206
-                foreach ($children as $child_line_item) {
207
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
-                        // recursively feed children back into this method
209
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
210
-                    }
211
-                }
212
-                $html .= $this->_taxes_html;
213
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
-                break;
216
-        }
217
-        return $html;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
224
-     *
225
-     * @param EE_Line_Item $line_item
226
-     * @return mixed
227
-     */
228
-    private function _event_row(EE_Line_Item $line_item)
229
-    {
230
-        // start of row
231
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
-        // event name td
233
-        $html .= EEH_HTML::td(
234
-            EEH_HTML::strong($line_item->name()),
235
-            '',
236
-            'event-header',
237
-            '',
238
-            ' colspan="4"'
239
-        );
240
-        // end of row
241
-        $html .= EEH_HTML::trx();
242
-        return $html;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * _ticket_row
249
-     *
250
-     * @param EE_Line_Item $line_item
251
-     * @param array        $options
252
-     * @return mixed
253
-     * @throws EE_Error
254
-     */
255
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
-    {
257
-        // start of row
258
-        $row_class = $options['odd'] ? 'item odd' : 'item';
259
-        $html = EEH_HTML::tr('', '', $row_class);
260
-        // name && desc
261
-        $name_and_desc = apply_filters(
262
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
-            $line_item->name(),
264
-            $line_item
265
-        );
266
-        $name_and_desc .= apply_filters(
267
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
-            (
269
-                $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
-                    : ''
272
-            ),
273
-            $line_item,
274
-            $options
275
-        );
276
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
-        // name td
278
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
-            $name_and_desc, '', 'item_l');
280
-        // price td
281
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
-        // quantity td
283
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
-        $this->_total_items += $line_item->quantity();
285
-        // determine total for line item
286
-        $total = $line_item->total();
287
-        $this->_events[$options['event_id']] += $total;
288
-        // total td
289
-        $html .= EEH_HTML::td(
290
-            EEH_Template::format_currency($total, false, false),
291
-            '',
292
-            'item_r jst-rght'
293
-        );
294
-        // end of row
295
-        $html .= EEH_HTML::trx();
296
-        return $html;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * _item_row
303
-     *
304
-     * @param EE_Line_Item $line_item
305
-     * @param array        $options
306
-     * @return mixed
307
-     * @throws EE_Error
308
-     */
309
-    private function _item_row(EE_Line_Item $line_item, $options = array())
310
-    {
311
-        // start of row
312
-        $row_class = $options['odd'] ? 'item odd' : 'item';
313
-        $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
-        // name && desc
316
-        $name_and_desc = apply_filters(
317
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
319
-            $line_item
320
-        );
321
-        $name_and_desc .= apply_filters(
322
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
-            (
324
-                $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
-                : ''
327
-            ),
328
-            $line_item,
329
-            $options
330
-        );
331
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
-        // name td
333
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
-        // price td
335
-        if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
-        } else {
338
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
-        }
340
-        // quantity td
341
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
-        //$total = $line_item->total() * $line_item->quantity();
343
-        $total = $line_item->total();
344
-        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
-            $this->_events[$options['event_id']] += $total;
346
-        }
347
-        // total td
348
-        $html .= EEH_HTML::td(
349
-            EEH_Template::format_currency($total, false, false),
350
-            '',
351
-            'item_r jst-rght'
352
-        );
353
-        // end of row
354
-        $html .= EEH_HTML::trx();
355
-        return $html;
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * _sub_item_row
362
-     *
363
-     * @param EE_Line_Item $line_item
364
-     * @param array        $options
365
-     * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
367
-     * @throws EE_Error
368
-     */
369
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
-    {
371
-        // start of row
372
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
373
-        // name && desc
374
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
375
-                         . $line_item->name();
376
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
377
-                                                  . $line_item->desc()
378
-                                                  . '</span>' : '';
379
-        // name td
380
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
381
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382
-        // discount/surcharge td
383
-        if ($line_item->is_percent()) {
384
-            $html .= EEH_HTML::td(
385
-                EEH_Template::format_currency(
386
-                    $line_item->total() / $qty,
387
-                    false, false
388
-                ),
389
-                '', 'item_c jst-rght'
390
-            );
391
-        } else {
392
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
393
-        }
394
-        // no quantity td
395
-        $html .= EEH_HTML::td();
396
-        // no total td
397
-        $html .= EEH_HTML::td();
398
-        // end of row
399
-        $html .= EEH_HTML::trx();
400
-        return $html;
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * _tax_row
407
-     *
408
-     * @param EE_Line_Item $line_item
409
-     * @param array        $options
410
-     * @return mixed
411
-     * @throws EE_Error
412
-     */
413
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
414
-    {
415
-        // start of row
416
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
417
-        // name && desc
418
-        $name_and_desc = $line_item->name();
419
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
422
-        // name td
423
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
424
-            $name_and_desc, '', 'item_l sub-item');
425
-        // percent td
426
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
427
-        // empty td (price)
428
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
429
-        // total td
430
-        $html .= EEH_HTML::td(EEH_Template::format_currency(
431
-            $line_item->total(), false, false),
432
-            '',
433
-            'item_r jst-rght'
434
-        );
435
-        // end of row
436
-        $html .= EEH_HTML::trx();
437
-        return $html;
438
-    }
439
-
440
-
441
-
442
-    /**
443
-     * _total_row
444
-     *
445
-     * @param EE_Line_Item $line_item
446
-     * @param string       $text
447
-     * @return mixed
448
-     * @throws EE_Error
449
-     */
450
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
451
-    {
452
-        $html = '';
453
-        if ($line_item->total()) {
454
-            // start of row
455
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
456
-            // total td
457
-            $html .= EEH_HTML::td(
458
-                $text,
459
-                '',
460
-                'total_currency total jst-rght',
461
-                '',
462
-                ' colspan="2"'
463
-            );
464
-            // empty td (price)
465
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
466
-            // total td
467
-            $html .= EEH_HTML::td(
468
-                EEH_Template::format_currency($line_item->total(), false, false),
469
-                '',
470
-                'total jst-rght'
471
-            );
472
-            // end of row
473
-            $html .= EEH_HTML::trx();
474
-        }
475
-        return $html;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * _total_row
482
-     *
483
-     * @param EE_Line_Item $line_item
484
-     * @param string       $text
485
-     * @param array        $options
486
-     * @return mixed
487
-     * @throws EE_Error
488
-     */
489
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
490
-    {
491
-        $html = '';
492
-        if ($line_item->total()) {
493
-            // start of row
494
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
495
-            // total td
496
-            $html .= EEH_HTML::td(
497
-                $text,
498
-                '',
499
-                'total_currency total jst-rght',
500
-                '',
501
-                ' colspan="3"'
502
-            );
503
-            // total td
504
-            $html .= EEH_HTML::td(
505
-                EEH_Template::format_currency($options['sub_total'], false, false),
506
-                '',
507
-                'total jst-rght'
508
-            );
509
-            // end of row
510
-            $html .= EEH_HTML::trx();
511
-        }
512
-        return $html;
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * _total_row
519
-     *
520
-     * @param EE_Line_Item $line_item
521
-     * @param string       $text
522
-     * @return mixed
523
-     * @throws EE_Error
524
-     */
525
-    private function _total_row(EE_Line_Item $line_item, $text = '')
526
-    {
527
-        // start of row
528
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
529
-        // total td
530
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
531
-        // total td
532
-        $html .= EEH_HTML::td(
533
-            EEH_Template::format_currency($line_item->total(), false, false),
534
-            '',
535
-            'total jst-rght'
536
-        );
537
-        // end of row
538
-        $html .= EEH_HTML::trx();
539
-        return $html;
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * _payments_and_amount_owing_rows
546
-     *
547
-     * @param EE_Line_Item $line_item
548
-     * @param array        $options
549
-     * @return mixed
550
-     * @throws EE_Error
551
-     */
552
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
553
-    {
554
-        $html = '';
555
-        $owing = $line_item->total();
556
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
557
-        if ($transaction instanceof EE_Transaction) {
558
-            $registration_payments = array();
559
-            $registrations = ! empty($options['registrations'])
560
-                ? $options['registrations']
561
-                : $transaction->registrations();
562
-            foreach ($registrations as $registration) {
563
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
564
-                    $registration_payments += $registration->registration_payments();
565
-                }
566
-            }
567
-            if (! empty($registration_payments)) {
568
-                foreach ($registration_payments as $registration_payment) {
569
-                    if ($registration_payment instanceof EE_Registration_Payment) {
570
-                        $owing -= $registration_payment->amount();
571
-                        $payment = $registration_payment->payment();
572
-                        $payment_desc = '';
573
-                        if ($payment instanceof EE_Payment) {
574
-                            $payment_desc = sprintf(
575
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576
-                                $payment->txn_id_chq_nmbr() !== ''
577
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
578
-                                    : '',
579
-                                $payment->timestamp()
580
-                            );
581
-                        }
582
-                        // start of row
583
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
584
-                        // payment desc
585
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
586
-                        // total td
587
-                        $html .= EEH_HTML::td(
588
-                            EEH_Template::format_currency(
589
-                                $registration_payment->amount(),
590
-                                false,
591
-                                false
592
-                            ),
593
-                            '',
594
-                            'total jst-rght'
595
-                        );
596
-                        // end of row
597
-                        $html .= EEH_HTML::trx();
598
-                    }
599
-                }
600
-                if ($line_item->total()) {
601
-                    // start of row
602
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
603
-                    // total td
604
-                    $html .= EEH_HTML::td(
605
-                        esc_html__('Amount Owing', 'event_espresso'),
606
-                        '', 'total_currency total jst-rght', '', ' colspan="3"'
607
-                    );
608
-                    // total td
609
-                    $html .= EEH_HTML::td(
610
-                        EEH_Template::format_currency($owing, false, false),
611
-                        '',
612
-                        'total jst-rght'
613
-                    );
614
-                    // end of row
615
-                    $html .= EEH_HTML::trx();
616
-                }
617
-            }
618
-        }
619
-        $this->_grand_total = $owing;
620
-        return $html;
621
-    }
19
+	/**
20
+	 * array of events
21
+	 *
22
+	 * @type EE_Line_Item[] $_events
23
+	 */
24
+	private $_events = array();
25
+
26
+	/**
27
+	 * whether to display the taxes row or not
28
+	 *
29
+	 * @type bool $_show_taxes
30
+	 */
31
+	private $_show_taxes = false;
32
+
33
+	/**
34
+	 * html for any tax rows
35
+	 *
36
+	 * @type string $_show_taxes
37
+	 */
38
+	private $_taxes_html = '';
39
+
40
+	/**
41
+	 * total amount including tax we can bill for at this time
42
+	 *
43
+	 * @type float $_grand_total
44
+	 */
45
+	private $_grand_total = 0.00;
46
+
47
+	/**
48
+	 * total number of items being billed for
49
+	 *
50
+	 * @type int $_total_items
51
+	 */
52
+	private $_total_items = 0;
53
+
54
+
55
+
56
+	/**
57
+	 * @return float
58
+	 */
59
+	public function grand_total()
60
+	{
61
+		return $this->_grand_total;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return int
68
+	 */
69
+	public function total_items()
70
+	{
71
+		return $this->_total_items;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param EE_Line_Item $line_item
78
+	 * @param array        $options
79
+	 * @param EE_Line_Item $parent_line_item
80
+	 * @return mixed
81
+	 * @throws EE_Error
82
+	 */
83
+	public function display_line_item(
84
+		EE_Line_Item $line_item,
85
+		$options = array(),
86
+		EE_Line_Item $parent_line_item = null
87
+	) {
88
+		$html = '';
89
+		// set some default options and merge with incoming
90
+		$default_options = array(
91
+			'show_desc' => true,  // 	true 		false
92
+			'odd'       => false,
93
+		);
94
+		$options = array_merge($default_options, (array)$options);
95
+		switch ($line_item->type()) {
96
+			case EEM_Line_Item::type_line_item:
97
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
+				if ($line_item->OBJ_type() === 'Ticket') {
99
+					// item row
100
+					$html .= $this->_ticket_row($line_item, $options);
101
+				} else {
102
+					// item row
103
+					$html .= $this->_item_row($line_item, $options);
104
+				}
105
+				if (
106
+				apply_filters(
107
+					'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
+					true
109
+				)
110
+				) {
111
+					// got any kids?
112
+					foreach ($line_item->children() as $child_line_item) {
113
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
114
+					}
115
+				}
116
+				break;
117
+			case EEM_Line_Item::type_sub_line_item:
118
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
+				break;
120
+			case EEM_Line_Item::type_sub_total:
121
+				static $sub_total = 0;
122
+				$event_sub_total = 0;
123
+				$text = esc_html__('Sub-Total', 'event_espresso');
124
+				if ($line_item->OBJ_type() === 'Event') {
125
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
126
+					if (! isset($this->_events[$options['event_id']])) {
127
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
+						// if event has default reg status of Not Approved, then don't display info on it
129
+						if (
130
+							$event instanceof EE_Event
131
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
+						) {
133
+							$display_event = false;
134
+							// unless there are registrations for it that are returning to pay
135
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
136
+								foreach ($options['registrations'] as $registration) {
137
+									if (! $registration instanceof EE_Registration) {
138
+										continue;
139
+									}
140
+									$display_event = $registration->event_ID() === $options['event_id']
141
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
+										? true
143
+										: $display_event;
144
+								}
145
+							}
146
+							if (! $display_event) {
147
+								return '';
148
+							}
149
+						}
150
+						$this->_events[$options['event_id']] = 0;
151
+						$html .= $this->_event_row($line_item);
152
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
153
+					}
154
+				}
155
+				$child_line_items = $line_item->children();
156
+				// loop thru children
157
+				foreach ($child_line_items as $child_line_item) {
158
+					// recursively feed children back into this method
159
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
160
+				}
161
+				$event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
+				$sub_total += $event_sub_total;
163
+				if (
164
+					(
165
+						// event subtotals
166
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
+					)
168
+					|| (
169
+						// pre-tax subtotals
170
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
+					)
172
+				) {
173
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
+					$html .= $this->_sub_total_row($line_item, $text, $options);
175
+				}
176
+				break;
177
+			case EEM_Line_Item::type_tax:
178
+				if ($this->_show_taxes) {
179
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
180
+				}
181
+				break;
182
+			case EEM_Line_Item::type_tax_sub_total:
183
+				if ($this->_show_taxes) {
184
+					$child_line_items = $line_item->children();
185
+					// loop thru children
186
+					foreach ($child_line_items as $child_line_item) {
187
+						// recursively feed children back into this method
188
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
189
+					}
190
+					if (count($child_line_items) > 1) {
191
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
+					}
193
+				}
194
+				break;
195
+			case EEM_Line_Item::type_total:
196
+				// get all child line items
197
+				$children = $line_item->children();
198
+				// loop thru all non-tax child line items
199
+				foreach ($children as $child_line_item) {
200
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
+						// recursively feed children back into this method
202
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
203
+					}
204
+				}
205
+				// now loop thru  tax child line items
206
+				foreach ($children as $child_line_item) {
207
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
+						// recursively feed children back into this method
209
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
210
+					}
211
+				}
212
+				$html .= $this->_taxes_html;
213
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
+				break;
216
+		}
217
+		return $html;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
224
+	 *
225
+	 * @param EE_Line_Item $line_item
226
+	 * @return mixed
227
+	 */
228
+	private function _event_row(EE_Line_Item $line_item)
229
+	{
230
+		// start of row
231
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
+		// event name td
233
+		$html .= EEH_HTML::td(
234
+			EEH_HTML::strong($line_item->name()),
235
+			'',
236
+			'event-header',
237
+			'',
238
+			' colspan="4"'
239
+		);
240
+		// end of row
241
+		$html .= EEH_HTML::trx();
242
+		return $html;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * _ticket_row
249
+	 *
250
+	 * @param EE_Line_Item $line_item
251
+	 * @param array        $options
252
+	 * @return mixed
253
+	 * @throws EE_Error
254
+	 */
255
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
+	{
257
+		// start of row
258
+		$row_class = $options['odd'] ? 'item odd' : 'item';
259
+		$html = EEH_HTML::tr('', '', $row_class);
260
+		// name && desc
261
+		$name_and_desc = apply_filters(
262
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
+			$line_item->name(),
264
+			$line_item
265
+		);
266
+		$name_and_desc .= apply_filters(
267
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
+			(
269
+				$options['show_desc']
270
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
+					: ''
272
+			),
273
+			$line_item,
274
+			$options
275
+		);
276
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
+		// name td
278
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
+			$name_and_desc, '', 'item_l');
280
+		// price td
281
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
+		// quantity td
283
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
+		$this->_total_items += $line_item->quantity();
285
+		// determine total for line item
286
+		$total = $line_item->total();
287
+		$this->_events[$options['event_id']] += $total;
288
+		// total td
289
+		$html .= EEH_HTML::td(
290
+			EEH_Template::format_currency($total, false, false),
291
+			'',
292
+			'item_r jst-rght'
293
+		);
294
+		// end of row
295
+		$html .= EEH_HTML::trx();
296
+		return $html;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * _item_row
303
+	 *
304
+	 * @param EE_Line_Item $line_item
305
+	 * @param array        $options
306
+	 * @return mixed
307
+	 * @throws EE_Error
308
+	 */
309
+	private function _item_row(EE_Line_Item $line_item, $options = array())
310
+	{
311
+		// start of row
312
+		$row_class = $options['odd'] ? 'item odd' : 'item';
313
+		$html = EEH_HTML::tr('', '', $row_class);
314
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
+		// name && desc
316
+		$name_and_desc = apply_filters(
317
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
+			$obj_name . $line_item->name(),
319
+			$line_item
320
+		);
321
+		$name_and_desc .= apply_filters(
322
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
+			(
324
+				$options['show_desc']
325
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
+				: ''
327
+			),
328
+			$line_item,
329
+			$options
330
+		);
331
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
+		// name td
333
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
+		// price td
335
+		if ($line_item->is_percent()) {
336
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
+		} else {
338
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
+		}
340
+		// quantity td
341
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
+		//$total = $line_item->total() * $line_item->quantity();
343
+		$total = $line_item->total();
344
+		if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
+			$this->_events[$options['event_id']] += $total;
346
+		}
347
+		// total td
348
+		$html .= EEH_HTML::td(
349
+			EEH_Template::format_currency($total, false, false),
350
+			'',
351
+			'item_r jst-rght'
352
+		);
353
+		// end of row
354
+		$html .= EEH_HTML::trx();
355
+		return $html;
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * _sub_item_row
362
+	 *
363
+	 * @param EE_Line_Item $line_item
364
+	 * @param array        $options
365
+	 * @param EE_Line_Item $parent_line_item
366
+	 * @return mixed
367
+	 * @throws EE_Error
368
+	 */
369
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
+	{
371
+		// start of row
372
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
373
+		// name && desc
374
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
375
+						 . $line_item->name();
376
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
377
+												  . $line_item->desc()
378
+												  . '</span>' : '';
379
+		// name td
380
+		$html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
381
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382
+		// discount/surcharge td
383
+		if ($line_item->is_percent()) {
384
+			$html .= EEH_HTML::td(
385
+				EEH_Template::format_currency(
386
+					$line_item->total() / $qty,
387
+					false, false
388
+				),
389
+				'', 'item_c jst-rght'
390
+			);
391
+		} else {
392
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
393
+		}
394
+		// no quantity td
395
+		$html .= EEH_HTML::td();
396
+		// no total td
397
+		$html .= EEH_HTML::td();
398
+		// end of row
399
+		$html .= EEH_HTML::trx();
400
+		return $html;
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * _tax_row
407
+	 *
408
+	 * @param EE_Line_Item $line_item
409
+	 * @param array        $options
410
+	 * @return mixed
411
+	 * @throws EE_Error
412
+	 */
413
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
414
+	{
415
+		// start of row
416
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
417
+		// name && desc
418
+		$name_and_desc = $line_item->name();
419
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
422
+		// name td
423
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
424
+			$name_and_desc, '', 'item_l sub-item');
425
+		// percent td
426
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
427
+		// empty td (price)
428
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
429
+		// total td
430
+		$html .= EEH_HTML::td(EEH_Template::format_currency(
431
+			$line_item->total(), false, false),
432
+			'',
433
+			'item_r jst-rght'
434
+		);
435
+		// end of row
436
+		$html .= EEH_HTML::trx();
437
+		return $html;
438
+	}
439
+
440
+
441
+
442
+	/**
443
+	 * _total_row
444
+	 *
445
+	 * @param EE_Line_Item $line_item
446
+	 * @param string       $text
447
+	 * @return mixed
448
+	 * @throws EE_Error
449
+	 */
450
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
451
+	{
452
+		$html = '';
453
+		if ($line_item->total()) {
454
+			// start of row
455
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
456
+			// total td
457
+			$html .= EEH_HTML::td(
458
+				$text,
459
+				'',
460
+				'total_currency total jst-rght',
461
+				'',
462
+				' colspan="2"'
463
+			);
464
+			// empty td (price)
465
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
466
+			// total td
467
+			$html .= EEH_HTML::td(
468
+				EEH_Template::format_currency($line_item->total(), false, false),
469
+				'',
470
+				'total jst-rght'
471
+			);
472
+			// end of row
473
+			$html .= EEH_HTML::trx();
474
+		}
475
+		return $html;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * _total_row
482
+	 *
483
+	 * @param EE_Line_Item $line_item
484
+	 * @param string       $text
485
+	 * @param array        $options
486
+	 * @return mixed
487
+	 * @throws EE_Error
488
+	 */
489
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
490
+	{
491
+		$html = '';
492
+		if ($line_item->total()) {
493
+			// start of row
494
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
495
+			// total td
496
+			$html .= EEH_HTML::td(
497
+				$text,
498
+				'',
499
+				'total_currency total jst-rght',
500
+				'',
501
+				' colspan="3"'
502
+			);
503
+			// total td
504
+			$html .= EEH_HTML::td(
505
+				EEH_Template::format_currency($options['sub_total'], false, false),
506
+				'',
507
+				'total jst-rght'
508
+			);
509
+			// end of row
510
+			$html .= EEH_HTML::trx();
511
+		}
512
+		return $html;
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * _total_row
519
+	 *
520
+	 * @param EE_Line_Item $line_item
521
+	 * @param string       $text
522
+	 * @return mixed
523
+	 * @throws EE_Error
524
+	 */
525
+	private function _total_row(EE_Line_Item $line_item, $text = '')
526
+	{
527
+		// start of row
528
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
529
+		// total td
530
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
531
+		// total td
532
+		$html .= EEH_HTML::td(
533
+			EEH_Template::format_currency($line_item->total(), false, false),
534
+			'',
535
+			'total jst-rght'
536
+		);
537
+		// end of row
538
+		$html .= EEH_HTML::trx();
539
+		return $html;
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * _payments_and_amount_owing_rows
546
+	 *
547
+	 * @param EE_Line_Item $line_item
548
+	 * @param array        $options
549
+	 * @return mixed
550
+	 * @throws EE_Error
551
+	 */
552
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
553
+	{
554
+		$html = '';
555
+		$owing = $line_item->total();
556
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
557
+		if ($transaction instanceof EE_Transaction) {
558
+			$registration_payments = array();
559
+			$registrations = ! empty($options['registrations'])
560
+				? $options['registrations']
561
+				: $transaction->registrations();
562
+			foreach ($registrations as $registration) {
563
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
564
+					$registration_payments += $registration->registration_payments();
565
+				}
566
+			}
567
+			if (! empty($registration_payments)) {
568
+				foreach ($registration_payments as $registration_payment) {
569
+					if ($registration_payment instanceof EE_Registration_Payment) {
570
+						$owing -= $registration_payment->amount();
571
+						$payment = $registration_payment->payment();
572
+						$payment_desc = '';
573
+						if ($payment instanceof EE_Payment) {
574
+							$payment_desc = sprintf(
575
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576
+								$payment->txn_id_chq_nmbr() !== ''
577
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
578
+									: '',
579
+								$payment->timestamp()
580
+							);
581
+						}
582
+						// start of row
583
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
584
+						// payment desc
585
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
586
+						// total td
587
+						$html .= EEH_HTML::td(
588
+							EEH_Template::format_currency(
589
+								$registration_payment->amount(),
590
+								false,
591
+								false
592
+							),
593
+							'',
594
+							'total jst-rght'
595
+						);
596
+						// end of row
597
+						$html .= EEH_HTML::trx();
598
+					}
599
+				}
600
+				if ($line_item->total()) {
601
+					// start of row
602
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
603
+					// total td
604
+					$html .= EEH_HTML::td(
605
+						esc_html__('Amount Owing', 'event_espresso'),
606
+						'', 'total_currency total jst-rght', '', ' colspan="3"'
607
+					);
608
+					// total td
609
+					$html .= EEH_HTML::td(
610
+						EEH_Template::format_currency($owing, false, false),
611
+						'',
612
+						'total jst-rght'
613
+					);
614
+					// end of row
615
+					$html .= EEH_HTML::trx();
616
+				}
617
+			}
618
+		}
619
+		$this->_grand_total = $owing;
620
+		return $html;
621
+	}
622 622
 
623 623
 
624 624
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
         $html = '';
89 89
         // set some default options and merge with incoming
90 90
         $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
91
+            'show_desc' => true, // 	true 		false
92 92
             'odd'       => false,
93 93
         );
94
-        $options = array_merge($default_options, (array)$options);
94
+        $options = array_merge($default_options, (array) $options);
95 95
         switch ($line_item->type()) {
96 96
             case EEM_Line_Item::type_line_item:
97 97
                 $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $text = esc_html__('Sub-Total', 'event_espresso');
124 124
                 if ($line_item->OBJ_type() === 'Event') {
125 125
                     $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
126
+                    if ( ! isset($this->_events[$options['event_id']])) {
127 127
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128 128
                         // if event has default reg status of Not Approved, then don't display info on it
129 129
                         if (
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                             // unless there are registrations for it that are returning to pay
135 135
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
136 136
                                 foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
137
+                                    if ( ! $registration instanceof EE_Registration) {
138 138
                                         continue;
139 139
                                     }
140 140
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                                         : $display_event;
144 144
                                 }
145 145
                             }
146
-                            if (! $display_event) {
146
+                            if ( ! $display_event) {
147 147
                                 return '';
148 148
                             }
149 149
                         }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268 268
             (
269 269
                 $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
270
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
271 271
                     : ''
272 272
             ),
273 273
             $line_item,
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
         // start of row
312 312
         $row_class = $options['odd'] ? 'item odd' : 'item';
313 313
         $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
314
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
315 315
         // name && desc
316 316
         $name_and_desc = apply_filters(
317 317
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
318
+            $obj_name.$line_item->name(),
319 319
             $line_item
320 320
         );
321 321
         $name_and_desc .= apply_filters(
322 322
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323 323
             (
324 324
                 $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
325
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
326 326
                 : ''
327 327
             ),
328 328
             $line_item,
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334 334
         // price td
335 335
         if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
336
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
337 337
         } else {
338 338
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339 339
         }
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
                                                   . $line_item->desc()
378 378
                                                   . '</span>' : '';
379 379
         // name td
380
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
380
+        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
381 381
         $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
382 382
         // discount/surcharge td
383 383
         if ($line_item->is_percent()) {
@@ -417,13 +417,13 @@  discard block
 block discarded – undo
417 417
         // name && desc
418 418
         $name_and_desc = $line_item->name();
419 419
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
420
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
421
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
420
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
421
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
422 422
         // name td
423 423
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
424 424
             $name_and_desc, '', 'item_l sub-item');
425 425
         // percent td
426
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
426
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
427 427
         // empty td (price)
428 428
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
429 429
         // total td
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                     $registration_payments += $registration->registration_payments();
565 565
                 }
566 566
             }
567
-            if (! empty($registration_payments)) {
567
+            if ( ! empty($registration_payments)) {
568 568
                 foreach ($registration_payments as $registration_payment) {
569 569
                     if ($registration_payment instanceof EE_Registration_Payment) {
570 570
                         $owing -= $registration_payment->amount();
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
                             $payment_desc = sprintf(
575 575
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
576 576
                                 $payment->txn_id_chq_nmbr() !== ''
577
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
577
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
578 578
                                     : '',
579 579
                                 $payment->timestamp()
580 580
                             );
Please login to merge, or discard this patch.
core/libraries/line_item_filters/EE_Non_Zero_Line_Item_Filter.class.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -19,102 +19,102 @@  discard block
 block discarded – undo
19 19
 class EE_Non_Zero_Line_Item_Filter extends EE_Line_Item_Filter_Base
20 20
 {
21 21
 
22
-    /**
23
-     * EE_Non_Zero_Line_Item_Filter constructor.
24
-     */
25
-    public function __construct()
26
-    {
27
-    }
28
-
29
-
30
-
31
-    /**
32
-     * Creates a duplicate of the line item tree, except only includes billable items
33
-     * and the portion of line items attributed to billable things
34
-     *
35
-     * @param EEI_Line_Item $line_item
36
-     * @return EEI_Line_Item
37
-     */
38
-    public function process(EEI_Line_Item $line_item)
39
-    {
40
-        $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
-            return null;
43
-        }
44
-        //if this is an event subtotal, we want to only include it if it
45
-        //has a non-zero total and at least one ticket line item child
46
-        if ($line_item->children()) {
47
-            $ticket_or_subtotals_with_tkt_children_count = 0;
48
-            foreach ($line_item->children() as $child_line_item) {
49
-                $code = $child_line_item->code();
50
-                $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
52
-                    $line_item->delete_child_line_item($code);
53
-                    continue;
54
-                }
55
-                if (
56
-                    (
57
-                        $child_line_item instanceof EEI_Line_Item
58
-                        && $child_line_item->type() === EEM_Line_Item::type_sub_total
59
-                    )
60
-                    || (
61
-                        $child_line_item instanceof EEI_Line_Item
62
-                        && $child_line_item->type() === EEM_Line_Item::type_line_item
63
-                        && $child_line_item->OBJ_type() === 'Ticket'
64
-                    )
65
-                ) {
66
-                    $ticket_or_subtotals_with_tkt_children_count++;
67
-                }
68
-            }
69
-            // if this is an event subtotal with NO ticket children
70
-            // we basically want to ignore it
71
-            return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
-                $ticket_or_subtotals_with_tkt_children_count);
73
-        }
74
-        return $non_zero_line_item;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * Creates a new, unsaved line item, but if it's a ticket line item
81
-     * with a total of 0, or a subtotal of 0, returns null instead
82
-     *
83
-     * @param EEI_Line_Item $line_item
84
-     * @return EEI_Line_Item
85
-     */
86
-    protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
-    {
88
-        if (
89
-            $line_item->type() === EEM_Line_Item::type_line_item
90
-            && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
92
-        ) {
93
-            return null;
94
-        }
95
-        return $line_item;
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * Creates a new, unsaved line item, but if it's a ticket line item
102
-     * with a total of 0, or a subtotal of 0, returns null instead
103
-     *
104
-     * @param EEI_Line_Item $line_item
105
-     * @param int           $ticket_children
106
-     * @return EEI_Line_Item
107
-     */
108
-    protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
-    {
110
-        if (
111
-            (int)$ticket_children === 0
112
-            && $line_item->type() === EEM_Line_Item::type_sub_total
113
-        ) {
114
-            return null;
115
-        }
116
-        return $line_item;
117
-    }
22
+	/**
23
+	 * EE_Non_Zero_Line_Item_Filter constructor.
24
+	 */
25
+	public function __construct()
26
+	{
27
+	}
28
+
29
+
30
+
31
+	/**
32
+	 * Creates a duplicate of the line item tree, except only includes billable items
33
+	 * and the portion of line items attributed to billable things
34
+	 *
35
+	 * @param EEI_Line_Item $line_item
36
+	 * @return EEI_Line_Item
37
+	 */
38
+	public function process(EEI_Line_Item $line_item)
39
+	{
40
+		$non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
+		if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
+			return null;
43
+		}
44
+		//if this is an event subtotal, we want to only include it if it
45
+		//has a non-zero total and at least one ticket line item child
46
+		if ($line_item->children()) {
47
+			$ticket_or_subtotals_with_tkt_children_count = 0;
48
+			foreach ($line_item->children() as $child_line_item) {
49
+				$code = $child_line_item->code();
50
+				$child_line_item = $this->process($child_line_item);
51
+				if (! $child_line_item instanceof EEI_Line_Item) {
52
+					$line_item->delete_child_line_item($code);
53
+					continue;
54
+				}
55
+				if (
56
+					(
57
+						$child_line_item instanceof EEI_Line_Item
58
+						&& $child_line_item->type() === EEM_Line_Item::type_sub_total
59
+					)
60
+					|| (
61
+						$child_line_item instanceof EEI_Line_Item
62
+						&& $child_line_item->type() === EEM_Line_Item::type_line_item
63
+						&& $child_line_item->OBJ_type() === 'Ticket'
64
+					)
65
+				) {
66
+					$ticket_or_subtotals_with_tkt_children_count++;
67
+				}
68
+			}
69
+			// if this is an event subtotal with NO ticket children
70
+			// we basically want to ignore it
71
+			return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
+				$ticket_or_subtotals_with_tkt_children_count);
73
+		}
74
+		return $non_zero_line_item;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * Creates a new, unsaved line item, but if it's a ticket line item
81
+	 * with a total of 0, or a subtotal of 0, returns null instead
82
+	 *
83
+	 * @param EEI_Line_Item $line_item
84
+	 * @return EEI_Line_Item
85
+	 */
86
+	protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
+	{
88
+		if (
89
+			$line_item->type() === EEM_Line_Item::type_line_item
90
+			&& $line_item->OBJ_type() === 'Ticket'
91
+			&& (int)$line_item->quantity() === 0
92
+		) {
93
+			return null;
94
+		}
95
+		return $line_item;
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * Creates a new, unsaved line item, but if it's a ticket line item
102
+	 * with a total of 0, or a subtotal of 0, returns null instead
103
+	 *
104
+	 * @param EEI_Line_Item $line_item
105
+	 * @param int           $ticket_children
106
+	 * @return EEI_Line_Item
107
+	 */
108
+	protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
+	{
110
+		if (
111
+			(int)$ticket_children === 0
112
+			&& $line_item->type() === EEM_Line_Item::type_sub_total
113
+		) {
114
+			return null;
115
+		}
116
+		return $line_item;
117
+	}
118 118
 
119 119
 
120 120
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public function process(EEI_Line_Item $line_item)
39 39
     {
40 40
         $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
41
+        if ( ! $non_zero_line_item instanceof EEI_Line_Item) {
42 42
             return null;
43 43
         }
44 44
         //if this is an event subtotal, we want to only include it if it
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             foreach ($line_item->children() as $child_line_item) {
49 49
                 $code = $child_line_item->code();
50 50
                 $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
51
+                if ( ! $child_line_item instanceof EEI_Line_Item) {
52 52
                     $line_item->delete_child_line_item($code);
53 53
                     continue;
54 54
                 }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         if (
89 89
             $line_item->type() === EEM_Line_Item::type_line_item
90 90
             && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
91
+            && (int) $line_item->quantity() === 0
92 92
         ) {
93 93
             return null;
94 94
         }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109 109
     {
110 110
         if (
111
-            (int)$ticket_children === 0
111
+            (int) $ticket_children === 0
112 112
             && $line_item->type() === EEM_Line_Item::type_sub_total
113 113
         ) {
114 114
             return null;
Please login to merge, or discard this patch.
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -18,192 +18,192 @@  discard block
 block discarded – undo
18 18
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
19 19
 {
20 20
 
21
-    /**
22
-     * array of line item codes and their corresponding quantities for registrations
23
-     *
24
-     * @type array $_line_item_registrations
25
-     */
26
-    protected $_line_item_registrations = array();
27
-
28
-    /**
29
-     * Just kept in case we want it someday. Currently unused
30
-     *
31
-     * @var EE_Registration[]
32
-     */
33
-    protected $_registrations = array();
34
-
35
-    /**
36
-     * @var EE_Registration
37
-     */
38
-    protected $_current_registration;
39
-
40
-    /**
41
-     * these reg statuses should NOT increment the line item quantity
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_closed_reg_statuses = array();
46
-
47
-
48
-
49
-    /**
50
-     * EE_Billable_Line_Item_Filter constructor.
51
-     *
52
-     * @param EE_Registration[] $registrations
53
-     * @throws EE_Error
54
-     */
55
-    public function __construct($registrations)
56
-    {
57
-        $this->_registrations = $registrations;
58
-        $this->_calculate_registrations_per_line_item_code($registrations);
59
-        // these reg statuses should NOT increment the line item quantity
60
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * sets the _line_item_registrations from the provided registrations
67
-     *
68
-     * @param EE_Registration[] $registrations
69
-     * @return void
70
-     * @throws EE_Error
71
-     */
72
-    protected function _calculate_registrations_per_line_item_code($registrations)
73
-    {
74
-        foreach ($registrations as $registration) {
75
-            $line_item_code = EEM_Line_Item::instance()->get_var(
76
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
-                    $registration,
78
-                    array('limit' => 1)
79
-                ),
80
-                'LIN_code'
81
-            );
82
-            if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
84
-                    $this->_line_item_registrations[$line_item_code] = array();
85
-                }
86
-                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Creates a duplicate of the line item tree, except only includes billable items
95
-     * and the portion of line items attributed to billable things
96
-     *
97
-     * @param EEI_Line_Item $line_item
98
-     * @return EEI_Line_Item
99
-     * @throws EE_Error
100
-     */
101
-    public function process(EEI_Line_Item $line_item)
102
-    {
103
-        $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
105
-            return $line_item;
106
-        }
107
-        //the original running total (taking ALL tickets into account)
108
-        $running_total_of_children = 0;
109
-        //the new running total (only taking the specified ticket quantities into account)
110
-        $running_total_of_children_under_consideration = 0;
111
-        // let's also track the quantity of tickets that pertain to the registrations
112
-        $total_child_ticket_quantity = 0;
113
-        foreach ($line_item->children() as $child_line_item) {
114
-            $original_li_total = $child_line_item->is_percent()
115
-                ? $running_total_of_children * $child_line_item->percent() / 100
116
-                : $child_line_item->unit_price() * $child_line_item->quantity();
117
-            $this->process($child_line_item);
118
-            // If this line item is a normal line item that isn't for a ticket,
119
-            // we want to modify its total (and unit price if not a percentage line item)
120
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
121
-            if (
122
-                $child_line_item->type() === EEM_Line_Item::type_line_item
123
-                && $child_line_item->OBJ_type() !== 'Ticket'
124
-            ) {
125
-                $percent_of_running_total = $running_total_of_children
126
-                    ? $original_li_total / $running_total_of_children
127
-                    : 0;
128
-                $child_line_item->set_total(
129
-                    $running_total_of_children_under_consideration * $percent_of_running_total
130
-                );
131
-                if (! $child_line_item->is_percent()) {
132
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
-                }
134
-            } else if (
135
-                //make sure this item's quantity and total matches its parent
136
-                $line_item->type() === EEM_Line_Item::type_line_item
137
-                && $line_item->OBJ_type() === 'Ticket'
138
-                // but not if it's a percentage modifier
139
-                && ! $child_line_item->is_percent()
140
-                && ! (
141
-                    // or a cancellation
142
-                    $child_line_item->is_cancelled()
143
-                    && ! (
144
-                        // unless it IS a cancellation and the current registration is cancelled
145
-                        $child_line_item->is_cancelled()
146
-                        && $this->_current_registration instanceof EE_Registration
147
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
-                    )
149
-                )
150
-            ) {
151
-                $child_line_item->set_quantity($line_item->quantity());
152
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
-            }
154
-            $running_total_of_children += $original_li_total;
155
-            $running_total_of_children_under_consideration += $child_line_item->total();
156
-            if ($child_line_item->OBJ_type() === 'Ticket') {
157
-                $total_child_ticket_quantity += $child_line_item->quantity();
158
-            }
159
-        }
160
-        $line_item->set_total($running_total_of_children_under_consideration);
161
-        if ($line_item->quantity()) {
162
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
-        } else {
164
-            $line_item->set_unit_price(0);
165
-        }
166
-        if ($line_item->OBJ_type() === 'Event') {
167
-            $line_item->set_quantity($total_child_ticket_quantity);
168
-        }
169
-        return $line_item;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Adjusts quantities for line items for tickets according to the registrations provided
176
-     * in the constructor
177
-     *
178
-     * @param EEI_Line_Item $line_item
179
-     * @return EEI_Line_Item
180
-     */
181
-    protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
-    {
183
-        // is this a ticket ?
184
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
-            $this->_current_registration = null;
186
-            $quantity = 0;
187
-            // if this ticket is billable at this moment, then we should have a positive quantity
188
-            if (
189
-                isset($this->_line_item_registrations[$line_item->code()])
190
-                && is_array($this->_line_item_registrations[$line_item->code()])
191
-            ) {
192
-                // set quantity based on number of open registrations for this ticket
193
-                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
-                    if (
195
-                        $registration instanceof EE_Registration
196
-                    ) {
197
-                        $quantity++;
198
-                        $this->_current_registration = $registration;
199
-                    }
200
-                }
201
-            }
202
-            $line_item->set_quantity($quantity);
203
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
-        }
205
-        return $line_item;
206
-    }
21
+	/**
22
+	 * array of line item codes and their corresponding quantities for registrations
23
+	 *
24
+	 * @type array $_line_item_registrations
25
+	 */
26
+	protected $_line_item_registrations = array();
27
+
28
+	/**
29
+	 * Just kept in case we want it someday. Currently unused
30
+	 *
31
+	 * @var EE_Registration[]
32
+	 */
33
+	protected $_registrations = array();
34
+
35
+	/**
36
+	 * @var EE_Registration
37
+	 */
38
+	protected $_current_registration;
39
+
40
+	/**
41
+	 * these reg statuses should NOT increment the line item quantity
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_closed_reg_statuses = array();
46
+
47
+
48
+
49
+	/**
50
+	 * EE_Billable_Line_Item_Filter constructor.
51
+	 *
52
+	 * @param EE_Registration[] $registrations
53
+	 * @throws EE_Error
54
+	 */
55
+	public function __construct($registrations)
56
+	{
57
+		$this->_registrations = $registrations;
58
+		$this->_calculate_registrations_per_line_item_code($registrations);
59
+		// these reg statuses should NOT increment the line item quantity
60
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * sets the _line_item_registrations from the provided registrations
67
+	 *
68
+	 * @param EE_Registration[] $registrations
69
+	 * @return void
70
+	 * @throws EE_Error
71
+	 */
72
+	protected function _calculate_registrations_per_line_item_code($registrations)
73
+	{
74
+		foreach ($registrations as $registration) {
75
+			$line_item_code = EEM_Line_Item::instance()->get_var(
76
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
+					$registration,
78
+					array('limit' => 1)
79
+				),
80
+				'LIN_code'
81
+			);
82
+			if ($line_item_code) {
83
+				if (! isset($this->_line_item_registrations[$line_item_code])) {
84
+					$this->_line_item_registrations[$line_item_code] = array();
85
+				}
86
+				$this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Creates a duplicate of the line item tree, except only includes billable items
95
+	 * and the portion of line items attributed to billable things
96
+	 *
97
+	 * @param EEI_Line_Item $line_item
98
+	 * @return EEI_Line_Item
99
+	 * @throws EE_Error
100
+	 */
101
+	public function process(EEI_Line_Item $line_item)
102
+	{
103
+		$this->_adjust_line_item_quantity($line_item);
104
+		if (! $line_item->children()) {
105
+			return $line_item;
106
+		}
107
+		//the original running total (taking ALL tickets into account)
108
+		$running_total_of_children = 0;
109
+		//the new running total (only taking the specified ticket quantities into account)
110
+		$running_total_of_children_under_consideration = 0;
111
+		// let's also track the quantity of tickets that pertain to the registrations
112
+		$total_child_ticket_quantity = 0;
113
+		foreach ($line_item->children() as $child_line_item) {
114
+			$original_li_total = $child_line_item->is_percent()
115
+				? $running_total_of_children * $child_line_item->percent() / 100
116
+				: $child_line_item->unit_price() * $child_line_item->quantity();
117
+			$this->process($child_line_item);
118
+			// If this line item is a normal line item that isn't for a ticket,
119
+			// we want to modify its total (and unit price if not a percentage line item)
120
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
121
+			if (
122
+				$child_line_item->type() === EEM_Line_Item::type_line_item
123
+				&& $child_line_item->OBJ_type() !== 'Ticket'
124
+			) {
125
+				$percent_of_running_total = $running_total_of_children
126
+					? $original_li_total / $running_total_of_children
127
+					: 0;
128
+				$child_line_item->set_total(
129
+					$running_total_of_children_under_consideration * $percent_of_running_total
130
+				);
131
+				if (! $child_line_item->is_percent()) {
132
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
+				}
134
+			} else if (
135
+				//make sure this item's quantity and total matches its parent
136
+				$line_item->type() === EEM_Line_Item::type_line_item
137
+				&& $line_item->OBJ_type() === 'Ticket'
138
+				// but not if it's a percentage modifier
139
+				&& ! $child_line_item->is_percent()
140
+				&& ! (
141
+					// or a cancellation
142
+					$child_line_item->is_cancelled()
143
+					&& ! (
144
+						// unless it IS a cancellation and the current registration is cancelled
145
+						$child_line_item->is_cancelled()
146
+						&& $this->_current_registration instanceof EE_Registration
147
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
+					)
149
+				)
150
+			) {
151
+				$child_line_item->set_quantity($line_item->quantity());
152
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
+			}
154
+			$running_total_of_children += $original_li_total;
155
+			$running_total_of_children_under_consideration += $child_line_item->total();
156
+			if ($child_line_item->OBJ_type() === 'Ticket') {
157
+				$total_child_ticket_quantity += $child_line_item->quantity();
158
+			}
159
+		}
160
+		$line_item->set_total($running_total_of_children_under_consideration);
161
+		if ($line_item->quantity()) {
162
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
+		} else {
164
+			$line_item->set_unit_price(0);
165
+		}
166
+		if ($line_item->OBJ_type() === 'Event') {
167
+			$line_item->set_quantity($total_child_ticket_quantity);
168
+		}
169
+		return $line_item;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Adjusts quantities for line items for tickets according to the registrations provided
176
+	 * in the constructor
177
+	 *
178
+	 * @param EEI_Line_Item $line_item
179
+	 * @return EEI_Line_Item
180
+	 */
181
+	protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
+	{
183
+		// is this a ticket ?
184
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
+			$this->_current_registration = null;
186
+			$quantity = 0;
187
+			// if this ticket is billable at this moment, then we should have a positive quantity
188
+			if (
189
+				isset($this->_line_item_registrations[$line_item->code()])
190
+				&& is_array($this->_line_item_registrations[$line_item->code()])
191
+			) {
192
+				// set quantity based on number of open registrations for this ticket
193
+				foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
+					if (
195
+						$registration instanceof EE_Registration
196
+					) {
197
+						$quantity++;
198
+						$this->_current_registration = $registration;
199
+					}
200
+				}
201
+			}
202
+			$line_item->set_quantity($quantity);
203
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
+		}
205
+		return $line_item;
206
+	}
207 207
 
208 208
 
209 209
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                 'LIN_code'
81 81
             );
82 82
             if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
83
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
84 84
                     $this->_line_item_registrations[$line_item_code] = array();
85 85
                 }
86 86
                 $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function process(EEI_Line_Item $line_item)
102 102
     {
103 103
         $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
104
+        if ( ! $line_item->children()) {
105 105
             return $line_item;
106 106
         }
107 107
         //the original running total (taking ALL tickets into account)
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                 $child_line_item->set_total(
129 129
                     $running_total_of_children_under_consideration * $percent_of_running_total
130 130
                 );
131
-                if (! $child_line_item->is_percent()) {
131
+                if ( ! $child_line_item->is_percent()) {
132 132
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133 133
                 }
134 134
             } else if (
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use InvalidArgumentException;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -25,228 +25,228 @@  discard block
 block discarded – undo
25 25
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
26 26
 {
27 27
 
28
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
29
-
30
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
31
-
32
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
33
-
34
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
35
-
36
-    /**
37
-     * numerical value used for sorting form steps
38
-     *
39
-     * @var int $order
40
-     */
41
-    private $order = 1;
42
-
43
-    /**
44
-     * a final URL with all form related parameters added
45
-     * that will be used to advance to the next step
46
-     *
47
-     * @var string $redirect_url
48
-     */
49
-    private $redirect_url = '';
50
-
51
-    /**
52
-     * URL params in key value pairs
53
-     *
54
-     * @var array $redirect_args
55
-     */
56
-    private $redirect_args = array();
57
-
58
-    /**
59
-     * Which step should be redirected to after form processing.
60
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
61
-     * If a form is invalid and requires errors to be corrected,
62
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
63
-     * Some form handlers do not have a form that is displayable,
64
-     * and only perform data processing, but if an error occurs,
65
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
66
-     * since the current step has no displayable content.
67
-     * if the form is completely finished, and needs to redirect to somewhere
68
-     * completely different, then this value will be REDIRECT_TO_OTHER
69
-     *
70
-     * @var string $redirect_to
71
-     */
72
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
73
-
74
-
75
-
76
-    /**
77
-     * SequentialStepForm constructor
78
-     *
79
-     * @param int         $order
80
-     * @param string      $form_name
81
-     * @param string      $admin_name
82
-     * @param string      $slug
83
-     * @param string      $form_action
84
-     * @param string      $form_config
85
-     * @param EE_Registry $registry
86
-     * @throws InvalidArgumentException
87
-     * @throws InvalidDataTypeException
88
-     * @throws DomainException
89
-     */
90
-    public function __construct(
91
-        $order,
92
-        $form_name,
93
-        $admin_name,
94
-        $slug,
95
-        $form_action = '',
96
-        $form_config = 'add_form_tags_and_submit',
97
-        EE_Registry $registry
98
-    ) {
99
-        $this->setOrder($order);
100
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @return int
107
-     */
108
-    public function order()
109
-    {
110
-        return $this->order;
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param int $order
117
-     * @throws InvalidArgumentException
118
-     */
119
-    public function setOrder($order)
120
-    {
121
-        $order = absint($order);
122
-        if (! $order > 0) {
123
-            throw new InvalidArgumentException(
124
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
125
-            );
126
-        }
127
-        $this->order = $order;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return string
134
-     */
135
-    public function redirectUrl()
136
-    {
137
-        return ! empty($this->redirect_args)
138
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
139
-            : $this->redirect_url;
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * @param string $redirect_url
146
-     * @throws InvalidDataTypeException
147
-     * @throws InvalidArgumentException
148
-     */
149
-    public function setRedirectUrl($redirect_url)
150
-    {
151
-        if (! is_string($redirect_url)) {
152
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153
-        }
154
-        if (empty($redirect_url)) {
155
-            throw new InvalidArgumentException(
156
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
157
-            );
158
-        }
159
-        $this->redirect_url = $redirect_url;
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @param array $redirect_args
166
-     * @throws InvalidDataTypeException
167
-     * @throws InvalidArgumentException
168
-     */
169
-    public function addRedirectArgs($redirect_args = array())
170
-    {
171
-        if (is_object($redirect_args)) {
172
-            throw new InvalidDataTypeException(
173
-                '$redirect_args',
174
-                $redirect_args,
175
-                'anything other than an object was expected.'
176
-            );
177
-        }
178
-        if (empty($redirect_args)) {
179
-            throw new InvalidArgumentException(
180
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181
-            );
182
-        }
183
-        $this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @param array $redirect_arg_keys_to_remove
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidArgumentException
192
-     */
193
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
194
-    {
195
-        if (is_object($redirect_arg_keys_to_remove)) {
196
-            throw new InvalidDataTypeException(
197
-                '$redirect_arg_keys_to_remove',
198
-                $redirect_arg_keys_to_remove,
199
-                'anything other than an object was expected.'
200
-            );
201
-        }
202
-        if (empty($redirect_arg_keys_to_remove)) {
203
-            throw new InvalidArgumentException(
204
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
205
-            );
206
-        }
207
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
208
-            unset($this->redirect_args[$redirect_arg_key]);
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * @return string
216
-     */
217
-    public function redirectTo()
218
-    {
219
-        return $this->redirect_to;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * @param string $redirect_to
226
-     * @throws InvalidDataTypeException
227
-     */
228
-    public function setRedirectTo($redirect_to)
229
-    {
230
-        if (
231
-            ! in_array(
232
-                $redirect_to,
233
-                array(
234
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
235
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
236
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
237
-                    SequentialStepForm::REDIRECT_TO_OTHER,
238
-                ),
239
-                true
240
-            )
241
-        ) {
242
-            throw new InvalidDataTypeException(
243
-                'setRedirectTo()',
244
-                $redirect_to,
245
-                'one of the SequentialStepForm class constants was expected.'
246
-            );
247
-        }
248
-        $this->redirect_to = $redirect_to;
249
-    }
28
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
29
+
30
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
31
+
32
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
33
+
34
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
35
+
36
+	/**
37
+	 * numerical value used for sorting form steps
38
+	 *
39
+	 * @var int $order
40
+	 */
41
+	private $order = 1;
42
+
43
+	/**
44
+	 * a final URL with all form related parameters added
45
+	 * that will be used to advance to the next step
46
+	 *
47
+	 * @var string $redirect_url
48
+	 */
49
+	private $redirect_url = '';
50
+
51
+	/**
52
+	 * URL params in key value pairs
53
+	 *
54
+	 * @var array $redirect_args
55
+	 */
56
+	private $redirect_args = array();
57
+
58
+	/**
59
+	 * Which step should be redirected to after form processing.
60
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
61
+	 * If a form is invalid and requires errors to be corrected,
62
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
63
+	 * Some form handlers do not have a form that is displayable,
64
+	 * and only perform data processing, but if an error occurs,
65
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
66
+	 * since the current step has no displayable content.
67
+	 * if the form is completely finished, and needs to redirect to somewhere
68
+	 * completely different, then this value will be REDIRECT_TO_OTHER
69
+	 *
70
+	 * @var string $redirect_to
71
+	 */
72
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
73
+
74
+
75
+
76
+	/**
77
+	 * SequentialStepForm constructor
78
+	 *
79
+	 * @param int         $order
80
+	 * @param string      $form_name
81
+	 * @param string      $admin_name
82
+	 * @param string      $slug
83
+	 * @param string      $form_action
84
+	 * @param string      $form_config
85
+	 * @param EE_Registry $registry
86
+	 * @throws InvalidArgumentException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws DomainException
89
+	 */
90
+	public function __construct(
91
+		$order,
92
+		$form_name,
93
+		$admin_name,
94
+		$slug,
95
+		$form_action = '',
96
+		$form_config = 'add_form_tags_and_submit',
97
+		EE_Registry $registry
98
+	) {
99
+		$this->setOrder($order);
100
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @return int
107
+	 */
108
+	public function order()
109
+	{
110
+		return $this->order;
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param int $order
117
+	 * @throws InvalidArgumentException
118
+	 */
119
+	public function setOrder($order)
120
+	{
121
+		$order = absint($order);
122
+		if (! $order > 0) {
123
+			throw new InvalidArgumentException(
124
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
125
+			);
126
+		}
127
+		$this->order = $order;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return string
134
+	 */
135
+	public function redirectUrl()
136
+	{
137
+		return ! empty($this->redirect_args)
138
+			? add_query_arg($this->redirect_args, $this->redirect_url)
139
+			: $this->redirect_url;
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * @param string $redirect_url
146
+	 * @throws InvalidDataTypeException
147
+	 * @throws InvalidArgumentException
148
+	 */
149
+	public function setRedirectUrl($redirect_url)
150
+	{
151
+		if (! is_string($redirect_url)) {
152
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153
+		}
154
+		if (empty($redirect_url)) {
155
+			throw new InvalidArgumentException(
156
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
157
+			);
158
+		}
159
+		$this->redirect_url = $redirect_url;
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @param array $redirect_args
166
+	 * @throws InvalidDataTypeException
167
+	 * @throws InvalidArgumentException
168
+	 */
169
+	public function addRedirectArgs($redirect_args = array())
170
+	{
171
+		if (is_object($redirect_args)) {
172
+			throw new InvalidDataTypeException(
173
+				'$redirect_args',
174
+				$redirect_args,
175
+				'anything other than an object was expected.'
176
+			);
177
+		}
178
+		if (empty($redirect_args)) {
179
+			throw new InvalidArgumentException(
180
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181
+			);
182
+		}
183
+		$this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @param array $redirect_arg_keys_to_remove
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidArgumentException
192
+	 */
193
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
194
+	{
195
+		if (is_object($redirect_arg_keys_to_remove)) {
196
+			throw new InvalidDataTypeException(
197
+				'$redirect_arg_keys_to_remove',
198
+				$redirect_arg_keys_to_remove,
199
+				'anything other than an object was expected.'
200
+			);
201
+		}
202
+		if (empty($redirect_arg_keys_to_remove)) {
203
+			throw new InvalidArgumentException(
204
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
205
+			);
206
+		}
207
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
208
+			unset($this->redirect_args[$redirect_arg_key]);
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * @return string
216
+	 */
217
+	public function redirectTo()
218
+	{
219
+		return $this->redirect_to;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * @param string $redirect_to
226
+	 * @throws InvalidDataTypeException
227
+	 */
228
+	public function setRedirectTo($redirect_to)
229
+	{
230
+		if (
231
+			! in_array(
232
+				$redirect_to,
233
+				array(
234
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
235
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
236
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
237
+					SequentialStepForm::REDIRECT_TO_OTHER,
238
+				),
239
+				true
240
+			)
241
+		) {
242
+			throw new InvalidDataTypeException(
243
+				'setRedirectTo()',
244
+				$redirect_to,
245
+				'one of the SequentialStepForm class constants was expected.'
246
+			);
247
+		}
248
+		$this->redirect_to = $redirect_to;
249
+	}
250 250
 
251 251
 
252 252
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\InvalidDataTypeException;
8 8
 use InvalidArgumentException;
9 9
 
10
-if (! defined('EVENT_ESPRESSO_VERSION')) {
10
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11 11
     exit('No direct script access allowed');
12 12
 }
13 13
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     public function setOrder($order)
120 120
     {
121 121
         $order = absint($order);
122
-        if (! $order > 0) {
122
+        if ( ! $order > 0) {
123 123
             throw new InvalidArgumentException(
124 124
                 esc_html__('The form order property must be a positive integer.', 'event_espresso')
125 125
             );
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function setRedirectUrl($redirect_url)
150 150
     {
151
-        if (! is_string($redirect_url)) {
151
+        if ( ! is_string($redirect_url)) {
152 152
             throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153 153
         }
154 154
         if (empty($redirect_url)) {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181 181
             );
182 182
         }
183
-        $this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
183
+        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
184 184
     }
185 185
 
186 186
 
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepFormManager.php 3 patches
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use InvalidArgumentException;
19 19
 
20 20
 if (! defined('EVENT_ESPRESSO_VERSION')) {
21
-    exit('No direct script access allowed');
21
+	exit('No direct script access allowed');
22 22
 }
23 23
 
24 24
 
@@ -35,619 +35,619 @@  discard block
 block discarded – undo
35 35
 abstract class SequentialStepFormManager
36 36
 {
37 37
 
38
-    /**
39
-     * a simplified URL with no form related parameters
40
-     * that will be used to build the form's redirect URLs
41
-     *
42
-     * @var string $base_url
43
-     */
44
-    private $base_url = '';
45
-
46
-    /**
47
-     * the key used for the URL param that denotes the current form step
48
-     * defaults to 'ee-form-step'
49
-     *
50
-     * @var string $form_step_url_key
51
-     */
52
-    private $form_step_url_key = '';
53
-
54
-    /**
55
-     * @var string $default_form_step
56
-     */
57
-    private $default_form_step = '';
58
-
59
-    /**
60
-     * @var string $form_action
61
-     */
62
-    private $form_action;
63
-
64
-    /**
65
-     * value of one of the string constant above
66
-     *
67
-     * @var string $form_config
68
-     */
69
-    private $form_config;
70
-
71
-    /**
72
-     * @var string $progress_step_style
73
-     */
74
-    private $progress_step_style = '';
75
-
76
-    /**
77
-     * @var EE_Request $request
78
-     */
79
-    private $request;
80
-
81
-    /**
82
-     * @var Collection $form_steps
83
-     */
84
-    protected $form_steps;
85
-
86
-    /**
87
-     * @var ProgressStepManager $progress_step_manager
88
-     */
89
-    protected $progress_step_manager;
90
-
91
-
92
-
93
-    /**
94
-     * @return Collection|null
95
-     */
96
-    abstract protected function getFormStepsCollection();
97
-
98
-
99
-
100
-    /**
101
-     * StepsManager constructor
102
-     *
103
-     * @param string     $base_url
104
-     * @param string     $default_form_step
105
-     * @param string     $form_action
106
-     * @param string     $form_config
107
-     * @param EE_Request $request
108
-     * @param string     $progress_step_style
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidArgumentException
111
-     */
112
-    public function __construct(
113
-        $base_url,
114
-        $default_form_step,
115
-        $form_action = '',
116
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
117
-        $progress_step_style = 'number_bubbles',
118
-        EE_Request $request
119
-    ) {
120
-        $this->setBaseUrl($base_url);
121
-        $this->setDefaultFormStep($default_form_step);
122
-        $this->setFormAction($form_action);
123
-        $this->setFormConfig($form_config);
124
-        $this->setProgressStepStyle($progress_step_style);
125
-        $this->request = $request;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * @return string
132
-     * @throws InvalidFormHandlerException
133
-     */
134
-    public function baseUrl()
135
-    {
136
-        if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
137
-            add_query_arg(
138
-                array($this->form_step_url_key => $this->getCurrentStep()->slug()),
139
-                $this->base_url
140
-            );
141
-        }
142
-        return $this->base_url;
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * @param string $base_url
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidArgumentException
151
-     */
152
-    protected function setBaseUrl($base_url)
153
-    {
154
-        if (! is_string($base_url)) {
155
-            throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156
-        }
157
-        if (empty($base_url)) {
158
-            throw new InvalidArgumentException(
159
-                esc_html__('The base URL can not be an empty string.', 'event_espresso')
160
-            );
161
-        }
162
-        $this->base_url = $base_url;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @return string
169
-     * @throws InvalidDataTypeException
170
-     */
171
-    public function formStepUrlKey()
172
-    {
173
-        if (empty($this->form_step_url_key)) {
174
-            $this->setFormStepUrlKey();
175
-        }
176
-        return $this->form_step_url_key;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * @param string $form_step_url_key
183
-     * @throws InvalidDataTypeException
184
-     */
185
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186
-    {
187
-        if (! is_string($form_step_url_key)) {
188
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189
-        }
190
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * @return string
197
-     */
198
-    public function defaultFormStep()
199
-    {
200
-        return $this->default_form_step;
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * @param $default_form_step
207
-     * @throws InvalidDataTypeException
208
-     */
209
-    protected function setDefaultFormStep($default_form_step)
210
-    {
211
-        if (! is_string($default_form_step)) {
212
-            throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213
-        }
214
-        $this->default_form_step = $default_form_step;
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * @return void
221
-     * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
222
-     * @throws InvalidDataTypeException
223
-     */
224
-    protected function setCurrentStepFromRequest()
225
-    {
226
-        $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
228
-            throw new InvalidIdentifierException(
229
-                $current_step_slug,
230
-                $this->defaultFormStep(),
231
-                $message = sprintf(
232
-                    esc_html__(
233
-                        'The "%1$s" form step could not be set.',
234
-                        'event_espresso'
235
-                    ),
236
-                    $current_step_slug
237
-                )
238
-            );
239
-        }
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * @return object|SequentialStepFormInterface
246
-     * @throws InvalidFormHandlerException
247
-     */
248
-    public function getCurrentStep()
249
-    {
250
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
251
-            throw new InvalidFormHandlerException($this->form_steps->current());
252
-        }
253
-        return $this->form_steps->current();
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * @return string
260
-     * @throws InvalidFormHandlerException
261
-     */
262
-    public function formAction()
263
-    {
264
-        if (! is_string($this->form_action) || empty($this->form_action)) {
265
-            $this->form_action = $this->baseUrl();
266
-        }
267
-        return $this->form_action;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * @param string $form_action
274
-     * @throws InvalidDataTypeException
275
-     */
276
-    public function setFormAction($form_action)
277
-    {
278
-        if (! is_string($form_action)) {
279
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280
-        }
281
-        $this->form_action = $form_action;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param array $form_action_args
288
-     * @throws InvalidDataTypeException
289
-     * @throws InvalidFormHandlerException
290
-     */
291
-    public function addFormActionArgs($form_action_args = array())
292
-    {
293
-        if (! is_array($form_action_args)) {
294
-            throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295
-        }
296
-        $form_action_args = ! empty($form_action_args)
297
-            ? $form_action_args
298
-            : array($this->formStepUrlKey() => $this->form_steps->current()->slug());
299
-        $this->getCurrentStep()->setFormAction(
300
-            add_query_arg($form_action_args, $this->formAction())
301
-        );
302
-        $this->form_action = $this->getCurrentStep()->formAction();
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * @return string
309
-     */
310
-    public function formConfig()
311
-    {
312
-        return $this->form_config;
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * @param string $form_config
319
-     */
320
-    public function setFormConfig($form_config)
321
-    {
322
-        $this->form_config = $form_config;
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * @return string
329
-     */
330
-    public function progressStepStyle()
331
-    {
332
-        return $this->progress_step_style;
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     * @param string $progress_step_style
339
-     */
340
-    public function setProgressStepStyle($progress_step_style)
341
-    {
342
-        $this->progress_step_style = $progress_step_style;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * @return EE_Request
349
-     */
350
-    public function request()
351
-    {
352
-        return $this->request;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * @return Collection|null
359
-     * @throws InvalidInterfaceException
360
-     */
361
-    protected function getProgressStepsCollection()
362
-    {
363
-        static $collection = null;
364
-        if (! $collection instanceof ProgressStepCollection) {
365
-            $collection = new ProgressStepCollection();
366
-        }
367
-        return $collection;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * @param Collection $progress_steps_collection
374
-     * @return ProgressStepManager
375
-     * @throws InvalidInterfaceException
376
-     * @throws InvalidClassException
377
-     * @throws InvalidDataTypeException
378
-     * @throws InvalidEntityException
379
-     * @throws InvalidFormHandlerException
380
-     */
381
-    protected function generateProgressSteps(Collection $progress_steps_collection)
382
-    {
383
-        $current_step = $this->getCurrentStep();
384
-        /** @var SequentialStepForm $form_step */
385
-        foreach ($this->form_steps as $form_step) {
386
-            // is this step active ?
387
-            if (! $form_step->initialize()) {
388
-                continue;
389
-            }
390
-            $progress_steps_collection->add(
391
-                new ProgressStep(
392
-                    $form_step->order(),
393
-                    $form_step->slug(),
394
-                    $form_step->slug(),
395
-                    $form_step->formName()
396
-                ),
397
-                $form_step->slug()
398
-            );
399
-        }
400
-        // set collection pointer back to current step
401
-        $this->form_steps->setCurrentUsingObject($current_step);
402
-        return new ProgressStepManager(
403
-            $this->progressStepStyle(),
404
-            $this->defaultFormStep(),
405
-            $this->formStepUrlKey(),
406
-            $progress_steps_collection
407
-        );
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * @throws InvalidClassException
414
-     * @throws InvalidDataTypeException
415
-     * @throws InvalidEntityException
416
-     * @throws InvalidIdentifierException
417
-     * @throws InvalidInterfaceException
418
-     * @throws InvalidArgumentException
419
-     * @throws InvalidFormHandlerException
420
-     */
421
-    public function buildForm()
422
-    {
423
-        $this->buildCurrentStepFormForDisplay();
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @param array $form_data
430
-     * @throws InvalidArgumentException
431
-     * @throws InvalidClassException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidEntityException
434
-     * @throws InvalidFormHandlerException
435
-     * @throws InvalidIdentifierException
436
-     * @throws InvalidInterfaceException
437
-     */
438
-    public function processForm($form_data = array())
439
-    {
440
-        $this->buildCurrentStepFormForProcessing();
441
-        $this->processCurrentStepForm($form_data);
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * @throws InvalidClassException
448
-     * @throws InvalidDataTypeException
449
-     * @throws InvalidEntityException
450
-     * @throws InvalidInterfaceException
451
-     * @throws InvalidIdentifierException
452
-     * @throws InvalidArgumentException
453
-     * @throws InvalidFormHandlerException
454
-     */
455
-    public function buildCurrentStepFormForDisplay()
456
-    {
457
-        $form_step = $this->buildCurrentStepForm();
458
-        // no displayable content ? then skip straight to processing
459
-        if (! $form_step->displayable()) {
460
-            $this->addFormActionArgs();
461
-            $form_step->setFormAction($this->formAction());
462
-            wp_safe_redirect($form_step->formAction());
463
-        }
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * @throws InvalidClassException
470
-     * @throws InvalidDataTypeException
471
-     * @throws InvalidEntityException
472
-     * @throws InvalidInterfaceException
473
-     * @throws InvalidIdentifierException
474
-     * @throws InvalidArgumentException
475
-     * @throws InvalidFormHandlerException
476
-     */
477
-    public function buildCurrentStepFormForProcessing()
478
-    {
479
-        $this->buildCurrentStepForm(false);
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * @param bool $for_display
486
-     * @return SequentialStepFormInterface
487
-     * @throws InvalidArgumentException
488
-     * @throws InvalidClassException
489
-     * @throws InvalidDataTypeException
490
-     * @throws InvalidEntityException
491
-     * @throws InvalidFormHandlerException
492
-     * @throws InvalidIdentifierException
493
-     * @throws InvalidInterfaceException
494
-     */
495
-    private function buildCurrentStepForm($for_display = true)
496
-    {
497
-        $this->form_steps = $this->getFormStepsCollection();
498
-        $this->setCurrentStepFromRequest();
499
-        $form_step = $this->getCurrentStep();
500
-        if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
501
-            $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
502
-        }
503
-        if ($for_display && $form_step->displayable()) {
504
-            $this->progress_step_manager = $this->generateProgressSteps(
505
-                $this->getProgressStepsCollection()
506
-            );
507
-            $this->progress_step_manager->setCurrentStep(
508
-                $form_step->slug()
509
-            );
510
-            // mark all previous progress steps as completed
511
-            $this->progress_step_manager->setPreviousStepsCompleted();
512
-            $this->progress_step_manager->enqueueStylesAndScripts();
513
-            $this->addFormActionArgs();
514
-            $form_step->setFormAction($this->formAction());
515
-        } else {
516
-            $form_step->setRedirectUrl($this->baseUrl());
517
-            $form_step->addRedirectArgs(
518
-                array($this->formStepUrlKey() => $this->form_steps->current()->slug())
519
-            );
520
-        }
521
-        $form_step->generate();
522
-        if ($for_display) {
523
-            $form_step->enqueueStylesAndScripts();
524
-        }
525
-        return $form_step;
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * @param bool $return_as_string
532
-     * @return string
533
-     * @throws InvalidFormHandlerException
534
-     */
535
-    public function displayProgressSteps($return_as_string = true)
536
-    {
537
-        $form_step = $this->getCurrentStep();
538
-        if (! $form_step->displayable()) {
539
-            return '';
540
-        }
541
-        $progress_steps = apply_filters(
542
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
543
-            ''
544
-        );
545
-        $progress_steps .= $this->progress_step_manager->displaySteps();
546
-        $progress_steps .= apply_filters(
547
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
548
-            ''
549
-        );
550
-        if ($return_as_string) {
551
-            return $progress_steps;
552
-        }
553
-        echo $progress_steps;
554
-        return '';
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * @param bool $return_as_string
561
-     * @return string
562
-     * @throws InvalidFormHandlerException
563
-     */
564
-    public function displayCurrentStepForm($return_as_string = true)
565
-    {
566
-        if ($return_as_string) {
567
-            return $this->getCurrentStep()->display();
568
-        }
569
-        echo $this->getCurrentStep()->display();
570
-        return '';
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * @param array $form_data
577
-     * @return void
578
-     * @throws InvalidArgumentException
579
-     * @throws InvalidDataTypeException
580
-     * @throws InvalidFormHandlerException
581
-     */
582
-    public function processCurrentStepForm($form_data = array())
583
-    {
584
-        // grab instance of current step because after calling next() below,
585
-        // any calls to getCurrentStep() will return the "next" step because we advanced
586
-        $current_step = $this->getCurrentStep();
587
-        try {
588
-            // form processing should either throw exceptions or return true
589
-            $current_step->process($form_data);
590
-        } catch (Exception $e) {
591
-            // something went wrong, so...
592
-            // if WP_DEBUG === true, display the Exception and stack trace right now
593
-            new ExceptionStackTraceDisplay($e);
594
-            // else convert the Exception to an EE_Error
595
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
596
-            // prevent redirect to next step or other if exception was thrown
597
-            if (
598
-                $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
599
-                || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
600
-            ) {
601
-                $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
602
-            }
603
-        }
604
-        // save notices to a transient so that when we redirect back
605
-        // to the display portion for this step
606
-        // those notices can be displayed
607
-        EE_Error::get_notices(false, true);
608
-        $this->redirectForm($current_step);
609
-    }
610
-
611
-
612
-
613
-    /**
614
-     * handles where to go to next
615
-     *
616
-     * @param SequentialStepFormInterface $current_step
617
-     * @throws InvalidArgumentException
618
-     * @throws InvalidDataTypeException
619
-     * @throws InvalidFormHandlerException
620
-     */
621
-    public function redirectForm(SequentialStepFormInterface $current_step)
622
-    {
623
-        $redirect_step = $current_step;
624
-        switch ($current_step->redirectTo()) {
625
-            case SequentialStepForm::REDIRECT_TO_OTHER:
626
-                // going somewhere else, so just check out now
627
-                wp_safe_redirect($redirect_step->redirectUrl());
628
-                exit();
629
-                break;
630
-            case SequentialStepForm::REDIRECT_TO_PREV_STEP:
631
-                $redirect_step = $this->form_steps->previous();
632
-                break;
633
-            case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
634
-                $this->form_steps->next();
635
-                if ($this->form_steps->valid()) {
636
-                    $redirect_step = $this->form_steps->current();
637
-                }
638
-                break;
639
-            case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
640
-            default :
641
-                // $redirect_step is already set
642
-        }
643
-        $current_step->setRedirectUrl($this->baseUrl());
644
-        $current_step->addRedirectArgs(
645
-        // use the slug for whatever step we are redirecting too
646
-            array($this->formStepUrlKey() => $redirect_step->slug())
647
-        );
648
-        wp_safe_redirect($current_step->redirectUrl());
649
-        exit();
650
-    }
38
+	/**
39
+	 * a simplified URL with no form related parameters
40
+	 * that will be used to build the form's redirect URLs
41
+	 *
42
+	 * @var string $base_url
43
+	 */
44
+	private $base_url = '';
45
+
46
+	/**
47
+	 * the key used for the URL param that denotes the current form step
48
+	 * defaults to 'ee-form-step'
49
+	 *
50
+	 * @var string $form_step_url_key
51
+	 */
52
+	private $form_step_url_key = '';
53
+
54
+	/**
55
+	 * @var string $default_form_step
56
+	 */
57
+	private $default_form_step = '';
58
+
59
+	/**
60
+	 * @var string $form_action
61
+	 */
62
+	private $form_action;
63
+
64
+	/**
65
+	 * value of one of the string constant above
66
+	 *
67
+	 * @var string $form_config
68
+	 */
69
+	private $form_config;
70
+
71
+	/**
72
+	 * @var string $progress_step_style
73
+	 */
74
+	private $progress_step_style = '';
75
+
76
+	/**
77
+	 * @var EE_Request $request
78
+	 */
79
+	private $request;
80
+
81
+	/**
82
+	 * @var Collection $form_steps
83
+	 */
84
+	protected $form_steps;
85
+
86
+	/**
87
+	 * @var ProgressStepManager $progress_step_manager
88
+	 */
89
+	protected $progress_step_manager;
90
+
91
+
92
+
93
+	/**
94
+	 * @return Collection|null
95
+	 */
96
+	abstract protected function getFormStepsCollection();
97
+
98
+
99
+
100
+	/**
101
+	 * StepsManager constructor
102
+	 *
103
+	 * @param string     $base_url
104
+	 * @param string     $default_form_step
105
+	 * @param string     $form_action
106
+	 * @param string     $form_config
107
+	 * @param EE_Request $request
108
+	 * @param string     $progress_step_style
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidArgumentException
111
+	 */
112
+	public function __construct(
113
+		$base_url,
114
+		$default_form_step,
115
+		$form_action = '',
116
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
117
+		$progress_step_style = 'number_bubbles',
118
+		EE_Request $request
119
+	) {
120
+		$this->setBaseUrl($base_url);
121
+		$this->setDefaultFormStep($default_form_step);
122
+		$this->setFormAction($form_action);
123
+		$this->setFormConfig($form_config);
124
+		$this->setProgressStepStyle($progress_step_style);
125
+		$this->request = $request;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * @return string
132
+	 * @throws InvalidFormHandlerException
133
+	 */
134
+	public function baseUrl()
135
+	{
136
+		if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
137
+			add_query_arg(
138
+				array($this->form_step_url_key => $this->getCurrentStep()->slug()),
139
+				$this->base_url
140
+			);
141
+		}
142
+		return $this->base_url;
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * @param string $base_url
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidArgumentException
151
+	 */
152
+	protected function setBaseUrl($base_url)
153
+	{
154
+		if (! is_string($base_url)) {
155
+			throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156
+		}
157
+		if (empty($base_url)) {
158
+			throw new InvalidArgumentException(
159
+				esc_html__('The base URL can not be an empty string.', 'event_espresso')
160
+			);
161
+		}
162
+		$this->base_url = $base_url;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @return string
169
+	 * @throws InvalidDataTypeException
170
+	 */
171
+	public function formStepUrlKey()
172
+	{
173
+		if (empty($this->form_step_url_key)) {
174
+			$this->setFormStepUrlKey();
175
+		}
176
+		return $this->form_step_url_key;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * @param string $form_step_url_key
183
+	 * @throws InvalidDataTypeException
184
+	 */
185
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186
+	{
187
+		if (! is_string($form_step_url_key)) {
188
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189
+		}
190
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * @return string
197
+	 */
198
+	public function defaultFormStep()
199
+	{
200
+		return $this->default_form_step;
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * @param $default_form_step
207
+	 * @throws InvalidDataTypeException
208
+	 */
209
+	protected function setDefaultFormStep($default_form_step)
210
+	{
211
+		if (! is_string($default_form_step)) {
212
+			throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213
+		}
214
+		$this->default_form_step = $default_form_step;
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * @return void
221
+	 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
222
+	 * @throws InvalidDataTypeException
223
+	 */
224
+	protected function setCurrentStepFromRequest()
225
+	{
226
+		$current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
+		if (! $this->form_steps->setCurrent($current_step_slug)) {
228
+			throw new InvalidIdentifierException(
229
+				$current_step_slug,
230
+				$this->defaultFormStep(),
231
+				$message = sprintf(
232
+					esc_html__(
233
+						'The "%1$s" form step could not be set.',
234
+						'event_espresso'
235
+					),
236
+					$current_step_slug
237
+				)
238
+			);
239
+		}
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * @return object|SequentialStepFormInterface
246
+	 * @throws InvalidFormHandlerException
247
+	 */
248
+	public function getCurrentStep()
249
+	{
250
+		if (! $this->form_steps->current() instanceof SequentialStepForm) {
251
+			throw new InvalidFormHandlerException($this->form_steps->current());
252
+		}
253
+		return $this->form_steps->current();
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * @return string
260
+	 * @throws InvalidFormHandlerException
261
+	 */
262
+	public function formAction()
263
+	{
264
+		if (! is_string($this->form_action) || empty($this->form_action)) {
265
+			$this->form_action = $this->baseUrl();
266
+		}
267
+		return $this->form_action;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * @param string $form_action
274
+	 * @throws InvalidDataTypeException
275
+	 */
276
+	public function setFormAction($form_action)
277
+	{
278
+		if (! is_string($form_action)) {
279
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280
+		}
281
+		$this->form_action = $form_action;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param array $form_action_args
288
+	 * @throws InvalidDataTypeException
289
+	 * @throws InvalidFormHandlerException
290
+	 */
291
+	public function addFormActionArgs($form_action_args = array())
292
+	{
293
+		if (! is_array($form_action_args)) {
294
+			throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295
+		}
296
+		$form_action_args = ! empty($form_action_args)
297
+			? $form_action_args
298
+			: array($this->formStepUrlKey() => $this->form_steps->current()->slug());
299
+		$this->getCurrentStep()->setFormAction(
300
+			add_query_arg($form_action_args, $this->formAction())
301
+		);
302
+		$this->form_action = $this->getCurrentStep()->formAction();
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * @return string
309
+	 */
310
+	public function formConfig()
311
+	{
312
+		return $this->form_config;
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * @param string $form_config
319
+	 */
320
+	public function setFormConfig($form_config)
321
+	{
322
+		$this->form_config = $form_config;
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * @return string
329
+	 */
330
+	public function progressStepStyle()
331
+	{
332
+		return $this->progress_step_style;
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 * @param string $progress_step_style
339
+	 */
340
+	public function setProgressStepStyle($progress_step_style)
341
+	{
342
+		$this->progress_step_style = $progress_step_style;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * @return EE_Request
349
+	 */
350
+	public function request()
351
+	{
352
+		return $this->request;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * @return Collection|null
359
+	 * @throws InvalidInterfaceException
360
+	 */
361
+	protected function getProgressStepsCollection()
362
+	{
363
+		static $collection = null;
364
+		if (! $collection instanceof ProgressStepCollection) {
365
+			$collection = new ProgressStepCollection();
366
+		}
367
+		return $collection;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * @param Collection $progress_steps_collection
374
+	 * @return ProgressStepManager
375
+	 * @throws InvalidInterfaceException
376
+	 * @throws InvalidClassException
377
+	 * @throws InvalidDataTypeException
378
+	 * @throws InvalidEntityException
379
+	 * @throws InvalidFormHandlerException
380
+	 */
381
+	protected function generateProgressSteps(Collection $progress_steps_collection)
382
+	{
383
+		$current_step = $this->getCurrentStep();
384
+		/** @var SequentialStepForm $form_step */
385
+		foreach ($this->form_steps as $form_step) {
386
+			// is this step active ?
387
+			if (! $form_step->initialize()) {
388
+				continue;
389
+			}
390
+			$progress_steps_collection->add(
391
+				new ProgressStep(
392
+					$form_step->order(),
393
+					$form_step->slug(),
394
+					$form_step->slug(),
395
+					$form_step->formName()
396
+				),
397
+				$form_step->slug()
398
+			);
399
+		}
400
+		// set collection pointer back to current step
401
+		$this->form_steps->setCurrentUsingObject($current_step);
402
+		return new ProgressStepManager(
403
+			$this->progressStepStyle(),
404
+			$this->defaultFormStep(),
405
+			$this->formStepUrlKey(),
406
+			$progress_steps_collection
407
+		);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * @throws InvalidClassException
414
+	 * @throws InvalidDataTypeException
415
+	 * @throws InvalidEntityException
416
+	 * @throws InvalidIdentifierException
417
+	 * @throws InvalidInterfaceException
418
+	 * @throws InvalidArgumentException
419
+	 * @throws InvalidFormHandlerException
420
+	 */
421
+	public function buildForm()
422
+	{
423
+		$this->buildCurrentStepFormForDisplay();
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * @param array $form_data
430
+	 * @throws InvalidArgumentException
431
+	 * @throws InvalidClassException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidEntityException
434
+	 * @throws InvalidFormHandlerException
435
+	 * @throws InvalidIdentifierException
436
+	 * @throws InvalidInterfaceException
437
+	 */
438
+	public function processForm($form_data = array())
439
+	{
440
+		$this->buildCurrentStepFormForProcessing();
441
+		$this->processCurrentStepForm($form_data);
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * @throws InvalidClassException
448
+	 * @throws InvalidDataTypeException
449
+	 * @throws InvalidEntityException
450
+	 * @throws InvalidInterfaceException
451
+	 * @throws InvalidIdentifierException
452
+	 * @throws InvalidArgumentException
453
+	 * @throws InvalidFormHandlerException
454
+	 */
455
+	public function buildCurrentStepFormForDisplay()
456
+	{
457
+		$form_step = $this->buildCurrentStepForm();
458
+		// no displayable content ? then skip straight to processing
459
+		if (! $form_step->displayable()) {
460
+			$this->addFormActionArgs();
461
+			$form_step->setFormAction($this->formAction());
462
+			wp_safe_redirect($form_step->formAction());
463
+		}
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * @throws InvalidClassException
470
+	 * @throws InvalidDataTypeException
471
+	 * @throws InvalidEntityException
472
+	 * @throws InvalidInterfaceException
473
+	 * @throws InvalidIdentifierException
474
+	 * @throws InvalidArgumentException
475
+	 * @throws InvalidFormHandlerException
476
+	 */
477
+	public function buildCurrentStepFormForProcessing()
478
+	{
479
+		$this->buildCurrentStepForm(false);
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * @param bool $for_display
486
+	 * @return SequentialStepFormInterface
487
+	 * @throws InvalidArgumentException
488
+	 * @throws InvalidClassException
489
+	 * @throws InvalidDataTypeException
490
+	 * @throws InvalidEntityException
491
+	 * @throws InvalidFormHandlerException
492
+	 * @throws InvalidIdentifierException
493
+	 * @throws InvalidInterfaceException
494
+	 */
495
+	private function buildCurrentStepForm($for_display = true)
496
+	{
497
+		$this->form_steps = $this->getFormStepsCollection();
498
+		$this->setCurrentStepFromRequest();
499
+		$form_step = $this->getCurrentStep();
500
+		if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
501
+			$form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
502
+		}
503
+		if ($for_display && $form_step->displayable()) {
504
+			$this->progress_step_manager = $this->generateProgressSteps(
505
+				$this->getProgressStepsCollection()
506
+			);
507
+			$this->progress_step_manager->setCurrentStep(
508
+				$form_step->slug()
509
+			);
510
+			// mark all previous progress steps as completed
511
+			$this->progress_step_manager->setPreviousStepsCompleted();
512
+			$this->progress_step_manager->enqueueStylesAndScripts();
513
+			$this->addFormActionArgs();
514
+			$form_step->setFormAction($this->formAction());
515
+		} else {
516
+			$form_step->setRedirectUrl($this->baseUrl());
517
+			$form_step->addRedirectArgs(
518
+				array($this->formStepUrlKey() => $this->form_steps->current()->slug())
519
+			);
520
+		}
521
+		$form_step->generate();
522
+		if ($for_display) {
523
+			$form_step->enqueueStylesAndScripts();
524
+		}
525
+		return $form_step;
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * @param bool $return_as_string
532
+	 * @return string
533
+	 * @throws InvalidFormHandlerException
534
+	 */
535
+	public function displayProgressSteps($return_as_string = true)
536
+	{
537
+		$form_step = $this->getCurrentStep();
538
+		if (! $form_step->displayable()) {
539
+			return '';
540
+		}
541
+		$progress_steps = apply_filters(
542
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
543
+			''
544
+		);
545
+		$progress_steps .= $this->progress_step_manager->displaySteps();
546
+		$progress_steps .= apply_filters(
547
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
548
+			''
549
+		);
550
+		if ($return_as_string) {
551
+			return $progress_steps;
552
+		}
553
+		echo $progress_steps;
554
+		return '';
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * @param bool $return_as_string
561
+	 * @return string
562
+	 * @throws InvalidFormHandlerException
563
+	 */
564
+	public function displayCurrentStepForm($return_as_string = true)
565
+	{
566
+		if ($return_as_string) {
567
+			return $this->getCurrentStep()->display();
568
+		}
569
+		echo $this->getCurrentStep()->display();
570
+		return '';
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * @param array $form_data
577
+	 * @return void
578
+	 * @throws InvalidArgumentException
579
+	 * @throws InvalidDataTypeException
580
+	 * @throws InvalidFormHandlerException
581
+	 */
582
+	public function processCurrentStepForm($form_data = array())
583
+	{
584
+		// grab instance of current step because after calling next() below,
585
+		// any calls to getCurrentStep() will return the "next" step because we advanced
586
+		$current_step = $this->getCurrentStep();
587
+		try {
588
+			// form processing should either throw exceptions or return true
589
+			$current_step->process($form_data);
590
+		} catch (Exception $e) {
591
+			// something went wrong, so...
592
+			// if WP_DEBUG === true, display the Exception and stack trace right now
593
+			new ExceptionStackTraceDisplay($e);
594
+			// else convert the Exception to an EE_Error
595
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
596
+			// prevent redirect to next step or other if exception was thrown
597
+			if (
598
+				$current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
599
+				|| $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
600
+			) {
601
+				$current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
602
+			}
603
+		}
604
+		// save notices to a transient so that when we redirect back
605
+		// to the display portion for this step
606
+		// those notices can be displayed
607
+		EE_Error::get_notices(false, true);
608
+		$this->redirectForm($current_step);
609
+	}
610
+
611
+
612
+
613
+	/**
614
+	 * handles where to go to next
615
+	 *
616
+	 * @param SequentialStepFormInterface $current_step
617
+	 * @throws InvalidArgumentException
618
+	 * @throws InvalidDataTypeException
619
+	 * @throws InvalidFormHandlerException
620
+	 */
621
+	public function redirectForm(SequentialStepFormInterface $current_step)
622
+	{
623
+		$redirect_step = $current_step;
624
+		switch ($current_step->redirectTo()) {
625
+			case SequentialStepForm::REDIRECT_TO_OTHER:
626
+				// going somewhere else, so just check out now
627
+				wp_safe_redirect($redirect_step->redirectUrl());
628
+				exit();
629
+				break;
630
+			case SequentialStepForm::REDIRECT_TO_PREV_STEP:
631
+				$redirect_step = $this->form_steps->previous();
632
+				break;
633
+			case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
634
+				$this->form_steps->next();
635
+				if ($this->form_steps->valid()) {
636
+					$redirect_step = $this->form_steps->current();
637
+				}
638
+				break;
639
+			case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
640
+			default :
641
+				// $redirect_step is already set
642
+		}
643
+		$current_step->setRedirectUrl($this->baseUrl());
644
+		$current_step->addRedirectArgs(
645
+		// use the slug for whatever step we are redirecting too
646
+			array($this->formStepUrlKey() => $redirect_step->slug())
647
+		);
648
+		wp_safe_redirect($current_step->redirectUrl());
649
+		exit();
650
+	}
651 651
 
652 652
 
653 653
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use Exception;
18 18
 use InvalidArgumentException;
19 19
 
20
-if (! defined('EVENT_ESPRESSO_VERSION')) {
20
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
21 21
     exit('No direct script access allowed');
22 22
 }
23 23
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      */
152 152
     protected function setBaseUrl($base_url)
153 153
     {
154
-        if (! is_string($base_url)) {
154
+        if ( ! is_string($base_url)) {
155 155
             throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156 156
         }
157 157
         if (empty($base_url)) {
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186 186
     {
187
-        if (! is_string($form_step_url_key)) {
187
+        if ( ! is_string($form_step_url_key)) {
188 188
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189 189
         }
190 190
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      */
209 209
     protected function setDefaultFormStep($default_form_step)
210 210
     {
211
-        if (! is_string($default_form_step)) {
211
+        if ( ! is_string($default_form_step)) {
212 212
             throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213 213
         }
214 214
         $this->default_form_step = $default_form_step;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
     protected function setCurrentStepFromRequest()
225 225
     {
226 226
         $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
227
+        if ( ! $this->form_steps->setCurrent($current_step_slug)) {
228 228
             throw new InvalidIdentifierException(
229 229
                 $current_step_slug,
230 230
                 $this->defaultFormStep(),
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function getCurrentStep()
249 249
     {
250
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
250
+        if ( ! $this->form_steps->current() instanceof SequentialStepForm) {
251 251
             throw new InvalidFormHandlerException($this->form_steps->current());
252 252
         }
253 253
         return $this->form_steps->current();
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public function formAction()
263 263
     {
264
-        if (! is_string($this->form_action) || empty($this->form_action)) {
264
+        if ( ! is_string($this->form_action) || empty($this->form_action)) {
265 265
             $this->form_action = $this->baseUrl();
266 266
         }
267 267
         return $this->form_action;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
      */
276 276
     public function setFormAction($form_action)
277 277
     {
278
-        if (! is_string($form_action)) {
278
+        if ( ! is_string($form_action)) {
279 279
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280 280
         }
281 281
         $this->form_action = $form_action;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function addFormActionArgs($form_action_args = array())
292 292
     {
293
-        if (! is_array($form_action_args)) {
293
+        if ( ! is_array($form_action_args)) {
294 294
             throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295 295
         }
296 296
         $form_action_args = ! empty($form_action_args)
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
     protected function getProgressStepsCollection()
362 362
     {
363 363
         static $collection = null;
364
-        if (! $collection instanceof ProgressStepCollection) {
364
+        if ( ! $collection instanceof ProgressStepCollection) {
365 365
             $collection = new ProgressStepCollection();
366 366
         }
367 367
         return $collection;
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
         /** @var SequentialStepForm $form_step */
385 385
         foreach ($this->form_steps as $form_step) {
386 386
             // is this step active ?
387
-            if (! $form_step->initialize()) {
387
+            if ( ! $form_step->initialize()) {
388 388
                 continue;
389 389
             }
390 390
             $progress_steps_collection->add(
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     {
457 457
         $form_step = $this->buildCurrentStepForm();
458 458
         // no displayable content ? then skip straight to processing
459
-        if (! $form_step->displayable()) {
459
+        if ( ! $form_step->displayable()) {
460 460
             $this->addFormActionArgs();
461 461
             $form_step->setFormAction($this->formAction());
462 462
             wp_safe_redirect($form_step->formAction());
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
     public function displayProgressSteps($return_as_string = true)
536 536
     {
537 537
         $form_step = $this->getCurrentStep();
538
-        if (! $form_step->displayable()) {
538
+        if ( ! $form_step->displayable()) {
539 539
             return '';
540 540
         }
541 541
         $progress_steps = apply_filters(
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
     /**
206
-     * @param $default_form_step
206
+     * @param string $default_form_step
207 207
      * @throws InvalidDataTypeException
208 208
      */
209 209
     protected function setDefaultFormStep($default_form_step)
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 
243 243
 
244 244
     /**
245
-     * @return object|SequentialStepFormInterface
245
+     * @return SequentialStepForm
246 246
      * @throws InvalidFormHandlerException
247 247
      */
248 248
     public function getCurrentStep()
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +633 added lines, -633 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
13 13
 
14 14
 if (! defined('EVENT_ESPRESSO_VERSION')) {
15
-    exit('No direct script access allowed');
15
+	exit('No direct script access allowed');
16 16
 }
17 17
 
18 18
 
@@ -31,638 +31,638 @@  discard block
 block discarded – undo
31 31
 abstract class FormHandler implements FormHandlerInterface
32 32
 {
33 33
 
34
-    /**
35
-     * will add opening and closing HTML form tags as well as a submit button
36
-     */
37
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
-
39
-    /**
40
-     * will add opening and closing HTML form tags but NOT a submit button
41
-     */
42
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
-
44
-    /**
45
-     * will NOT add opening and closing HTML form tags but will add a submit button
46
-     */
47
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
-
49
-    /**
50
-     * will NOT add opening and closing HTML form tags NOR a submit button
51
-     */
52
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
-
54
-    /**
55
-     * if set to false, then this form has no displayable content,
56
-     * and will only be used for processing data sent passed via GET or POST
57
-     * defaults to true ( ie: form has displayable content )
58
-     *
59
-     * @var boolean $displayable
60
-     */
61
-    private $displayable = true;
62
-
63
-    /**
64
-     * @var string $form_name
65
-     */
66
-    private $form_name;
67
-
68
-    /**
69
-     * @var string $admin_name
70
-     */
71
-    private $admin_name;
72
-
73
-    /**
74
-     * @var string $slug
75
-     */
76
-    private $slug;
77
-
78
-    /**
79
-     * @var string $submit_btn_text
80
-     */
81
-    private $submit_btn_text;
82
-
83
-    /**
84
-     * @var string $form_action
85
-     */
86
-    private $form_action;
87
-
88
-    /**
89
-     * form params in key value pairs
90
-     * can be added to form action URL or as hidden inputs
91
-     *
92
-     * @var array $form_args
93
-     */
94
-    private $form_args = array();
95
-
96
-    /**
97
-     * value of one of the string constant above
98
-     *
99
-     * @var string $form_config
100
-     */
101
-    private $form_config;
102
-
103
-    /**
104
-     * whether or not the form was determined to be invalid
105
-     *
106
-     * @var boolean $form_has_errors
107
-     */
108
-    private $form_has_errors;
109
-
110
-    /**
111
-     * the absolute top level form section being used on the page
112
-     *
113
-     * @var \EE_Form_Section_Proper $form
114
-     */
115
-    private $form;
116
-
117
-    /**
118
-     * @var \EE_Registry $registry
119
-     */
120
-    protected $registry;
121
-
122
-
123
-
124
-    /**
125
-     * Form constructor.
126
-     *
127
-     * @param string       $form_name
128
-     * @param string       $admin_name
129
-     * @param string       $slug
130
-     * @param string       $form_action
131
-     * @param string       $form_config
132
-     * @param \EE_Registry $registry
133
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
134
-     * @throws \DomainException
135
-     * @throws \InvalidArgumentException
136
-     */
137
-    public function __construct(
138
-        $form_name,
139
-        $admin_name,
140
-        $slug,
141
-        $form_action = '',
142
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
143
-        \EE_Registry $registry
144
-    ) {
145
-        $this->setFormName($form_name);
146
-        $this->setAdminName($admin_name);
147
-        $this->setSlug($slug);
148
-        $this->setFormAction($form_action);
149
-        $this->setFormConfig($form_config);
150
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
151
-        $this->registry = $registry;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @return array
158
-     */
159
-    public static function getFormConfigConstants()
160
-    {
161
-        return array(
162
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
163
-            FormHandler::ADD_FORM_TAGS_ONLY,
164
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
165
-            FormHandler::DO_NOT_SETUP_FORM,
166
-        );
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @param bool $for_display
173
-     * @return \EE_Form_Section_Proper
174
-     * @throws \EE_Error
175
-     * @throws \LogicException
176
-     */
177
-    public function form($for_display = false)
178
-    {
179
-        if (! $this->formIsValid()) {
180
-            return null;
181
-        }
182
-        if ($for_display) {
183
-            $form_config = $this->formConfig();
184
-            if (
185
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
186
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
187
-            ) {
188
-                $this->appendSubmitButton();
189
-                $this->clearFormButtonFloats();
190
-            }
191
-        }
192
-        return $this->form;
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * @return boolean
199
-     * @throws LogicException
200
-     */
201
-    public function formIsValid()
202
-    {
203
-        if (! $this->form instanceof \EE_Form_Section_Proper) {
204
-            static $generated = false;
205
-            if (! $generated) {
206
-                $generated = true;
207
-                $form = $this->generate();
208
-                if ($form instanceof \EE_Form_Section_Proper) {
209
-                    $this->setForm($form);
210
-                }
211
-            }
212
-            return $this->verifyForm();
213
-        }
214
-        return true;
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * @return boolean
221
-     * @throws LogicException
222
-     */
223
-    public function verifyForm()
224
-    {
225
-        if ($this->form instanceof \EE_Form_Section_Proper) {
226
-            return true;
227
-        }
228
-        throw new LogicException(
229
-            sprintf(
230
-                esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
231
-                $this->form_name
232
-            )
233
-        );
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * @param \EE_Form_Section_Proper $form
240
-     */
241
-    public function setForm(\EE_Form_Section_Proper $form)
242
-    {
243
-        $this->form = $form;
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * @return boolean
250
-     */
251
-    public function displayable()
252
-    {
253
-        return $this->displayable;
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * @param boolean $displayable
260
-     */
261
-    public function setDisplayable($displayable = false)
262
-    {
263
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * a public name for the form that can be displayed on the frontend of a site
270
-     *
271
-     * @return string
272
-     */
273
-    public function formName()
274
-    {
275
-        return $this->form_name;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * @param string $form_name
282
-     * @throws InvalidDataTypeException
283
-     */
284
-    public function setFormName($form_name)
285
-    {
286
-        if (! is_string($form_name)) {
287
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
288
-        }
289
-        $this->form_name = $form_name;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * a public name for the form that can be displayed, but only in the admin
296
-     *
297
-     * @return string
298
-     */
299
-    public function adminName()
300
-    {
301
-        return $this->admin_name;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param string $admin_name
308
-     * @throws InvalidDataTypeException
309
-     */
310
-    public function setAdminName($admin_name)
311
-    {
312
-        if (! is_string($admin_name)) {
313
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
314
-        }
315
-        $this->admin_name = $admin_name;
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * a URL friendly string that can be used for identifying the form
322
-     *
323
-     * @return string
324
-     */
325
-    public function slug()
326
-    {
327
-        return $this->slug;
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     * @param string $slug
334
-     * @throws InvalidDataTypeException
335
-     */
336
-    public function setSlug($slug)
337
-    {
338
-        if (! is_string($slug)) {
339
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
340
-        }
341
-        $this->slug = $slug;
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * @return string
348
-     */
349
-    public function submitBtnText()
350
-    {
351
-        return $this->submit_btn_text;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * @param string $submit_btn_text
358
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
359
-     * @throws \InvalidArgumentException
360
-     */
361
-    public function setSubmitBtnText($submit_btn_text)
362
-    {
363
-        if (! is_string($submit_btn_text)) {
364
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
365
-        }
366
-        if (empty($submit_btn_text)) {
367
-            throw new InvalidArgumentException(
368
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
369
-            );
370
-        }
371
-        $this->submit_btn_text = $submit_btn_text;
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * @return string
378
-     */
379
-    public function formAction()
380
-    {
381
-        return ! empty($this->form_args)
382
-            ? add_query_arg($this->form_args, $this->form_action)
383
-            : $this->form_action;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * @param string $form_action
390
-     * @throws InvalidDataTypeException
391
-     */
392
-    public function setFormAction($form_action)
393
-    {
394
-        if (! is_string($form_action)) {
395
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
396
-        }
397
-        $this->form_action = $form_action;
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     * @param array $form_args
404
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
405
-     * @throws \InvalidArgumentException
406
-     */
407
-    public function addFormActionArgs($form_args = array())
408
-    {
409
-        if (is_object($form_args)) {
410
-            throw new InvalidDataTypeException(
411
-                '$form_args',
412
-                $form_args,
413
-                'anything other than an object was expected.'
414
-            );
415
-        }
416
-        if (empty($form_args)) {
417
-            throw new InvalidArgumentException(
418
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
419
-            );
420
-        }
421
-        $this->form_args = array_merge($this->form_args, $form_args);
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * @return string
428
-     */
429
-    public function formConfig()
430
-    {
431
-        return $this->form_config;
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     * @param string $form_config
438
-     * @throws DomainException
439
-     */
440
-    public function setFormConfig($form_config)
441
-    {
442
-        if (
443
-        ! in_array(
444
-            $form_config,
445
-            array(
446
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
447
-                FormHandler::ADD_FORM_TAGS_ONLY,
448
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
449
-                FormHandler::DO_NOT_SETUP_FORM,
450
-            ),
451
-            true
452
-        )
453
-        ) {
454
-            throw new DomainException(
455
-                sprintf(
456
-                    esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
457
-                        'event_espresso'),
458
-                    $form_config
459
-                )
460
-            );
461
-        }
462
-        $this->form_config = $form_config;
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * called after the form is instantiated
469
-     * and used for performing any logic that needs to occur early
470
-     * before any of the other methods are called.
471
-     * returns true if everything is ok to proceed,
472
-     * and false if no further form logic should be implemented
473
-     *
474
-     * @return boolean
475
-     */
476
-    public function initialize()
477
-    {
478
-        $this->form_has_errors = \EE_Error::has_error(true);
479
-        return true;
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * used for setting up css and js
486
-     *
487
-     * @return void
488
-     * @throws LogicException
489
-     * @throws \EE_Error
490
-     */
491
-    public function enqueueStylesAndScripts()
492
-    {
493
-        $this->form(false)->enqueue_js();
494
-    }
495
-
496
-
497
-
498
-    /**
499
-     * creates and returns the actual form
500
-     *
501
-     * @return EE_Form_Section_Proper
502
-     */
503
-    abstract public function generate();
504
-
505
-
506
-
507
-    /**
508
-     * creates and returns an EE_Submit_Input labeled "Submit"
509
-     *
510
-     * @param string $text
511
-     * @return \EE_Submit_Input
512
-     */
513
-    public function generateSubmitButton($text = '')
514
-    {
515
-        $text = ! empty($text) ? $text : $this->submitBtnText();
516
-        return new EE_Submit_Input(
517
-            array(
518
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
519
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
520
-                'html_class'            => 'ee-form-submit',
521
-                'html_label'            => '&nbsp;',
522
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
523
-                'default'               => $text,
524
-            )
525
-        );
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
532
-     *
533
-     * @param string $text
534
-     * @return void
535
-     * @throws \LogicException
536
-     * @throws \EE_Error
537
-     */
538
-    public function appendSubmitButton($text = '')
539
-    {
540
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
541
-            return;
542
-        }
543
-        $this->form->add_subsections(
544
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
545
-            null,
546
-            false
547
-        );
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * creates and returns an EE_Submit_Input labeled "Cancel"
554
-     *
555
-     * @param string $text
556
-     * @return \EE_Submit_Input
557
-     */
558
-    public function generateCancelButton($text = '')
559
-    {
560
-        $cancel_button = new EE_Submit_Input(
561
-            array(
562
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
563
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
564
-                'html_class'            => 'ee-cancel-form',
565
-                'html_label'            => '&nbsp;',
566
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
567
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
568
-            )
569
-        );
570
-        $cancel_button->set_button_css_attributes(false);
571
-        return $cancel_button;
572
-    }
573
-
574
-
575
-
576
-    /**
577
-     * appends a float clearing div onto end of form
578
-     *
579
-     * @return void
580
-     * @throws \EE_Error
581
-     */
582
-    public function clearFormButtonFloats()
583
-    {
584
-        $this->form->add_subsections(
585
-            array(
586
-                'clear-submit-btn-float' => new \EE_Form_Section_HTML(
587
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
588
-                ),
589
-            ),
590
-            null,
591
-            false
592
-        );
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
599
-     * returns a string of HTML that can be directly echoed in a template
600
-     *
601
-     * @return string
602
-     * @throws LogicException
603
-     * @throws \EE_Error
604
-     */
605
-    public function display()
606
-    {
607
-        $form_html = apply_filters(
608
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
609
-            ''
610
-        );
611
-        $form_config = $this->formConfig();
612
-        if (
613
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
614
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
615
-        ) {
616
-            $form_html .= $this->form()->form_open($this->formAction());
617
-        }
618
-        $form_html .= $this->form(true)->get_html($this->form_has_errors);
619
-        if (
620
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
-        ) {
623
-            $form_html .= $this->form()->form_close();
624
-        }
625
-        $form_html .= apply_filters(
626
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
627
-            ''
628
-        );
629
-        return $form_html;
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     * handles processing the form submission
636
-     * returns true or false depending on whether the form was processed successfully or not
637
-     *
638
-     * @param array $submitted_form_data
639
-     * @return array
640
-     * @throws \EE_Error
641
-     * @throws \LogicException
642
-     * @throws InvalidFormSubmissionException
643
-     */
644
-    public function process($submitted_form_data = array())
645
-    {
646
-        if (! $this->form()->was_submitted($submitted_form_data)) {
647
-            throw new InvalidFormSubmissionException($this->form_name);
648
-        }
649
-        $this->form(true)->receive_form_submission($submitted_form_data);
650
-        if (! $this->form()->is_valid()) {
651
-            throw new InvalidFormSubmissionException(
652
-                $this->form_name,
653
-                sprintf(
654
-                    esc_html__(
655
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
656
-                        'event_espresso'
657
-                    ),
658
-                    $this->form_name,
659
-                    '<br />',
660
-                    $this->form()->submission_error_message()
661
-                )
662
-            );
663
-        }
664
-        return $this->form()->valid_data();
665
-    }
34
+	/**
35
+	 * will add opening and closing HTML form tags as well as a submit button
36
+	 */
37
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
+
39
+	/**
40
+	 * will add opening and closing HTML form tags but NOT a submit button
41
+	 */
42
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
+
44
+	/**
45
+	 * will NOT add opening and closing HTML form tags but will add a submit button
46
+	 */
47
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
+
49
+	/**
50
+	 * will NOT add opening and closing HTML form tags NOR a submit button
51
+	 */
52
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
+
54
+	/**
55
+	 * if set to false, then this form has no displayable content,
56
+	 * and will only be used for processing data sent passed via GET or POST
57
+	 * defaults to true ( ie: form has displayable content )
58
+	 *
59
+	 * @var boolean $displayable
60
+	 */
61
+	private $displayable = true;
62
+
63
+	/**
64
+	 * @var string $form_name
65
+	 */
66
+	private $form_name;
67
+
68
+	/**
69
+	 * @var string $admin_name
70
+	 */
71
+	private $admin_name;
72
+
73
+	/**
74
+	 * @var string $slug
75
+	 */
76
+	private $slug;
77
+
78
+	/**
79
+	 * @var string $submit_btn_text
80
+	 */
81
+	private $submit_btn_text;
82
+
83
+	/**
84
+	 * @var string $form_action
85
+	 */
86
+	private $form_action;
87
+
88
+	/**
89
+	 * form params in key value pairs
90
+	 * can be added to form action URL or as hidden inputs
91
+	 *
92
+	 * @var array $form_args
93
+	 */
94
+	private $form_args = array();
95
+
96
+	/**
97
+	 * value of one of the string constant above
98
+	 *
99
+	 * @var string $form_config
100
+	 */
101
+	private $form_config;
102
+
103
+	/**
104
+	 * whether or not the form was determined to be invalid
105
+	 *
106
+	 * @var boolean $form_has_errors
107
+	 */
108
+	private $form_has_errors;
109
+
110
+	/**
111
+	 * the absolute top level form section being used on the page
112
+	 *
113
+	 * @var \EE_Form_Section_Proper $form
114
+	 */
115
+	private $form;
116
+
117
+	/**
118
+	 * @var \EE_Registry $registry
119
+	 */
120
+	protected $registry;
121
+
122
+
123
+
124
+	/**
125
+	 * Form constructor.
126
+	 *
127
+	 * @param string       $form_name
128
+	 * @param string       $admin_name
129
+	 * @param string       $slug
130
+	 * @param string       $form_action
131
+	 * @param string       $form_config
132
+	 * @param \EE_Registry $registry
133
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
134
+	 * @throws \DomainException
135
+	 * @throws \InvalidArgumentException
136
+	 */
137
+	public function __construct(
138
+		$form_name,
139
+		$admin_name,
140
+		$slug,
141
+		$form_action = '',
142
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
143
+		\EE_Registry $registry
144
+	) {
145
+		$this->setFormName($form_name);
146
+		$this->setAdminName($admin_name);
147
+		$this->setSlug($slug);
148
+		$this->setFormAction($form_action);
149
+		$this->setFormConfig($form_config);
150
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
151
+		$this->registry = $registry;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @return array
158
+	 */
159
+	public static function getFormConfigConstants()
160
+	{
161
+		return array(
162
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
163
+			FormHandler::ADD_FORM_TAGS_ONLY,
164
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
165
+			FormHandler::DO_NOT_SETUP_FORM,
166
+		);
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @param bool $for_display
173
+	 * @return \EE_Form_Section_Proper
174
+	 * @throws \EE_Error
175
+	 * @throws \LogicException
176
+	 */
177
+	public function form($for_display = false)
178
+	{
179
+		if (! $this->formIsValid()) {
180
+			return null;
181
+		}
182
+		if ($for_display) {
183
+			$form_config = $this->formConfig();
184
+			if (
185
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
186
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
187
+			) {
188
+				$this->appendSubmitButton();
189
+				$this->clearFormButtonFloats();
190
+			}
191
+		}
192
+		return $this->form;
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * @return boolean
199
+	 * @throws LogicException
200
+	 */
201
+	public function formIsValid()
202
+	{
203
+		if (! $this->form instanceof \EE_Form_Section_Proper) {
204
+			static $generated = false;
205
+			if (! $generated) {
206
+				$generated = true;
207
+				$form = $this->generate();
208
+				if ($form instanceof \EE_Form_Section_Proper) {
209
+					$this->setForm($form);
210
+				}
211
+			}
212
+			return $this->verifyForm();
213
+		}
214
+		return true;
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * @return boolean
221
+	 * @throws LogicException
222
+	 */
223
+	public function verifyForm()
224
+	{
225
+		if ($this->form instanceof \EE_Form_Section_Proper) {
226
+			return true;
227
+		}
228
+		throw new LogicException(
229
+			sprintf(
230
+				esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
231
+				$this->form_name
232
+			)
233
+		);
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * @param \EE_Form_Section_Proper $form
240
+	 */
241
+	public function setForm(\EE_Form_Section_Proper $form)
242
+	{
243
+		$this->form = $form;
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * @return boolean
250
+	 */
251
+	public function displayable()
252
+	{
253
+		return $this->displayable;
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * @param boolean $displayable
260
+	 */
261
+	public function setDisplayable($displayable = false)
262
+	{
263
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * a public name for the form that can be displayed on the frontend of a site
270
+	 *
271
+	 * @return string
272
+	 */
273
+	public function formName()
274
+	{
275
+		return $this->form_name;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * @param string $form_name
282
+	 * @throws InvalidDataTypeException
283
+	 */
284
+	public function setFormName($form_name)
285
+	{
286
+		if (! is_string($form_name)) {
287
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
288
+		}
289
+		$this->form_name = $form_name;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * a public name for the form that can be displayed, but only in the admin
296
+	 *
297
+	 * @return string
298
+	 */
299
+	public function adminName()
300
+	{
301
+		return $this->admin_name;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param string $admin_name
308
+	 * @throws InvalidDataTypeException
309
+	 */
310
+	public function setAdminName($admin_name)
311
+	{
312
+		if (! is_string($admin_name)) {
313
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
314
+		}
315
+		$this->admin_name = $admin_name;
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * a URL friendly string that can be used for identifying the form
322
+	 *
323
+	 * @return string
324
+	 */
325
+	public function slug()
326
+	{
327
+		return $this->slug;
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 * @param string $slug
334
+	 * @throws InvalidDataTypeException
335
+	 */
336
+	public function setSlug($slug)
337
+	{
338
+		if (! is_string($slug)) {
339
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
340
+		}
341
+		$this->slug = $slug;
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * @return string
348
+	 */
349
+	public function submitBtnText()
350
+	{
351
+		return $this->submit_btn_text;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * @param string $submit_btn_text
358
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
359
+	 * @throws \InvalidArgumentException
360
+	 */
361
+	public function setSubmitBtnText($submit_btn_text)
362
+	{
363
+		if (! is_string($submit_btn_text)) {
364
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
365
+		}
366
+		if (empty($submit_btn_text)) {
367
+			throw new InvalidArgumentException(
368
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
369
+			);
370
+		}
371
+		$this->submit_btn_text = $submit_btn_text;
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * @return string
378
+	 */
379
+	public function formAction()
380
+	{
381
+		return ! empty($this->form_args)
382
+			? add_query_arg($this->form_args, $this->form_action)
383
+			: $this->form_action;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * @param string $form_action
390
+	 * @throws InvalidDataTypeException
391
+	 */
392
+	public function setFormAction($form_action)
393
+	{
394
+		if (! is_string($form_action)) {
395
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
396
+		}
397
+		$this->form_action = $form_action;
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 * @param array $form_args
404
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
405
+	 * @throws \InvalidArgumentException
406
+	 */
407
+	public function addFormActionArgs($form_args = array())
408
+	{
409
+		if (is_object($form_args)) {
410
+			throw new InvalidDataTypeException(
411
+				'$form_args',
412
+				$form_args,
413
+				'anything other than an object was expected.'
414
+			);
415
+		}
416
+		if (empty($form_args)) {
417
+			throw new InvalidArgumentException(
418
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
419
+			);
420
+		}
421
+		$this->form_args = array_merge($this->form_args, $form_args);
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * @return string
428
+	 */
429
+	public function formConfig()
430
+	{
431
+		return $this->form_config;
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 * @param string $form_config
438
+	 * @throws DomainException
439
+	 */
440
+	public function setFormConfig($form_config)
441
+	{
442
+		if (
443
+		! in_array(
444
+			$form_config,
445
+			array(
446
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
447
+				FormHandler::ADD_FORM_TAGS_ONLY,
448
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
449
+				FormHandler::DO_NOT_SETUP_FORM,
450
+			),
451
+			true
452
+		)
453
+		) {
454
+			throw new DomainException(
455
+				sprintf(
456
+					esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
457
+						'event_espresso'),
458
+					$form_config
459
+				)
460
+			);
461
+		}
462
+		$this->form_config = $form_config;
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * called after the form is instantiated
469
+	 * and used for performing any logic that needs to occur early
470
+	 * before any of the other methods are called.
471
+	 * returns true if everything is ok to proceed,
472
+	 * and false if no further form logic should be implemented
473
+	 *
474
+	 * @return boolean
475
+	 */
476
+	public function initialize()
477
+	{
478
+		$this->form_has_errors = \EE_Error::has_error(true);
479
+		return true;
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * used for setting up css and js
486
+	 *
487
+	 * @return void
488
+	 * @throws LogicException
489
+	 * @throws \EE_Error
490
+	 */
491
+	public function enqueueStylesAndScripts()
492
+	{
493
+		$this->form(false)->enqueue_js();
494
+	}
495
+
496
+
497
+
498
+	/**
499
+	 * creates and returns the actual form
500
+	 *
501
+	 * @return EE_Form_Section_Proper
502
+	 */
503
+	abstract public function generate();
504
+
505
+
506
+
507
+	/**
508
+	 * creates and returns an EE_Submit_Input labeled "Submit"
509
+	 *
510
+	 * @param string $text
511
+	 * @return \EE_Submit_Input
512
+	 */
513
+	public function generateSubmitButton($text = '')
514
+	{
515
+		$text = ! empty($text) ? $text : $this->submitBtnText();
516
+		return new EE_Submit_Input(
517
+			array(
518
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
519
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
520
+				'html_class'            => 'ee-form-submit',
521
+				'html_label'            => '&nbsp;',
522
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
523
+				'default'               => $text,
524
+			)
525
+		);
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
532
+	 *
533
+	 * @param string $text
534
+	 * @return void
535
+	 * @throws \LogicException
536
+	 * @throws \EE_Error
537
+	 */
538
+	public function appendSubmitButton($text = '')
539
+	{
540
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
541
+			return;
542
+		}
543
+		$this->form->add_subsections(
544
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
545
+			null,
546
+			false
547
+		);
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
554
+	 *
555
+	 * @param string $text
556
+	 * @return \EE_Submit_Input
557
+	 */
558
+	public function generateCancelButton($text = '')
559
+	{
560
+		$cancel_button = new EE_Submit_Input(
561
+			array(
562
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
563
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
564
+				'html_class'            => 'ee-cancel-form',
565
+				'html_label'            => '&nbsp;',
566
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
567
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
568
+			)
569
+		);
570
+		$cancel_button->set_button_css_attributes(false);
571
+		return $cancel_button;
572
+	}
573
+
574
+
575
+
576
+	/**
577
+	 * appends a float clearing div onto end of form
578
+	 *
579
+	 * @return void
580
+	 * @throws \EE_Error
581
+	 */
582
+	public function clearFormButtonFloats()
583
+	{
584
+		$this->form->add_subsections(
585
+			array(
586
+				'clear-submit-btn-float' => new \EE_Form_Section_HTML(
587
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
588
+				),
589
+			),
590
+			null,
591
+			false
592
+		);
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
599
+	 * returns a string of HTML that can be directly echoed in a template
600
+	 *
601
+	 * @return string
602
+	 * @throws LogicException
603
+	 * @throws \EE_Error
604
+	 */
605
+	public function display()
606
+	{
607
+		$form_html = apply_filters(
608
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
609
+			''
610
+		);
611
+		$form_config = $this->formConfig();
612
+		if (
613
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
614
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
615
+		) {
616
+			$form_html .= $this->form()->form_open($this->formAction());
617
+		}
618
+		$form_html .= $this->form(true)->get_html($this->form_has_errors);
619
+		if (
620
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
+		) {
623
+			$form_html .= $this->form()->form_close();
624
+		}
625
+		$form_html .= apply_filters(
626
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
627
+			''
628
+		);
629
+		return $form_html;
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 * handles processing the form submission
636
+	 * returns true or false depending on whether the form was processed successfully or not
637
+	 *
638
+	 * @param array $submitted_form_data
639
+	 * @return array
640
+	 * @throws \EE_Error
641
+	 * @throws \LogicException
642
+	 * @throws InvalidFormSubmissionException
643
+	 */
644
+	public function process($submitted_form_data = array())
645
+	{
646
+		if (! $this->form()->was_submitted($submitted_form_data)) {
647
+			throw new InvalidFormSubmissionException($this->form_name);
648
+		}
649
+		$this->form(true)->receive_form_submission($submitted_form_data);
650
+		if (! $this->form()->is_valid()) {
651
+			throw new InvalidFormSubmissionException(
652
+				$this->form_name,
653
+				sprintf(
654
+					esc_html__(
655
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
656
+						'event_espresso'
657
+					),
658
+					$this->form_name,
659
+					'<br />',
660
+					$this->form()->submission_error_message()
661
+				)
662
+			);
663
+		}
664
+		return $this->form()->valid_data();
665
+	}
666 666
 
667 667
 
668 668
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use EventEspresso\core\exceptions\InvalidDataTypeException;
12 12
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
13 13
 
14
-if (! defined('EVENT_ESPRESSO_VERSION')) {
14
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
15 15
     exit('No direct script access allowed');
16 16
 }
17 17
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      */
177 177
     public function form($for_display = false)
178 178
     {
179
-        if (! $this->formIsValid()) {
179
+        if ( ! $this->formIsValid()) {
180 180
             return null;
181 181
         }
182 182
         if ($for_display) {
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
      */
201 201
     public function formIsValid()
202 202
     {
203
-        if (! $this->form instanceof \EE_Form_Section_Proper) {
203
+        if ( ! $this->form instanceof \EE_Form_Section_Proper) {
204 204
             static $generated = false;
205
-            if (! $generated) {
205
+            if ( ! $generated) {
206 206
                 $generated = true;
207 207
                 $form = $this->generate();
208 208
                 if ($form instanceof \EE_Form_Section_Proper) {
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      */
284 284
     public function setFormName($form_name)
285 285
     {
286
-        if (! is_string($form_name)) {
286
+        if ( ! is_string($form_name)) {
287 287
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
288 288
         }
289 289
         $this->form_name = $form_name;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      */
310 310
     public function setAdminName($admin_name)
311 311
     {
312
-        if (! is_string($admin_name)) {
312
+        if ( ! is_string($admin_name)) {
313 313
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
314 314
         }
315 315
         $this->admin_name = $admin_name;
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      */
336 336
     public function setSlug($slug)
337 337
     {
338
-        if (! is_string($slug)) {
338
+        if ( ! is_string($slug)) {
339 339
             throw new InvalidDataTypeException('$slug', $slug, 'string');
340 340
         }
341 341
         $this->slug = $slug;
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      */
361 361
     public function setSubmitBtnText($submit_btn_text)
362 362
     {
363
-        if (! is_string($submit_btn_text)) {
363
+        if ( ! is_string($submit_btn_text)) {
364 364
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
365 365
         }
366 366
         if (empty($submit_btn_text)) {
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
      */
392 392
     public function setFormAction($form_action)
393 393
     {
394
-        if (! is_string($form_action)) {
394
+        if ( ! is_string($form_action)) {
395 395
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
396 396
         }
397 397
         $this->form_action = $form_action;
@@ -515,11 +515,11 @@  discard block
 block discarded – undo
515 515
         $text = ! empty($text) ? $text : $this->submitBtnText();
516 516
         return new EE_Submit_Input(
517 517
             array(
518
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
519
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
518
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
519
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
520 520
                 'html_class'            => 'ee-form-submit',
521 521
                 'html_label'            => '&nbsp;',
522
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
522
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
523 523
                 'default'               => $text,
524 524
             )
525 525
         );
@@ -537,11 +537,11 @@  discard block
 block discarded – undo
537 537
      */
538 538
     public function appendSubmitButton($text = '')
539 539
     {
540
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
540
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
541 541
             return;
542 542
         }
543 543
         $this->form->add_subsections(
544
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
544
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
545 545
             null,
546 546
             false
547 547
         );
@@ -559,11 +559,11 @@  discard block
 block discarded – undo
559 559
     {
560 560
         $cancel_button = new EE_Submit_Input(
561 561
             array(
562
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
563
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
562
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
563
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
564 564
                 'html_class'            => 'ee-cancel-form',
565 565
                 'html_label'            => '&nbsp;',
566
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
566
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
567 567
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
568 568
             )
569 569
         );
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
         $this->form->add_subsections(
585 585
             array(
586 586
                 'clear-submit-btn-float' => new \EE_Form_Section_HTML(
587
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
587
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
588 588
                 ),
589 589
             ),
590 590
             null,
@@ -643,11 +643,11 @@  discard block
 block discarded – undo
643 643
      */
644 644
     public function process($submitted_form_data = array())
645 645
     {
646
-        if (! $this->form()->was_submitted($submitted_form_data)) {
646
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
647 647
             throw new InvalidFormSubmissionException($this->form_name);
648 648
         }
649 649
         $this->form(true)->receive_form_submission($submitted_form_data);
650
-        if (! $this->form()->is_valid()) {
650
+        if ( ! $this->form()->is_valid()) {
651 651
             throw new InvalidFormSubmissionException(
652 652
                 $this->form_name,
653 653
                 sprintf(
Please login to merge, or discard this patch.
core/EE_Error.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     /**
74 74
      *    error_handler
75 75
      *
76
-     * @param $code
76
+     * @param integer $code
77 77
      * @param $message
78 78
      * @param $file
79 79
      * @param $line
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     /**
178 178
      * _format_error
179 179
      *
180
-     * @param $code
180
+     * @param string $code
181 181
      * @param $message
182 182
      * @param $file
183 183
      * @param $line
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
 
212 212
     /**
213
-     * @return void
213
+     * @return string|null
214 214
      * @throws EE_Error
215 215
      * @throws ReflectionException
216 216
      */
Please login to merge, or discard this patch.
Indentation   +1086 added lines, -1086 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
 // if you're a dev and want to receive all errors via email
6 6
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
7 7
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
8
-    set_error_handler(array('EE_Error', 'error_handler'));
9
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
8
+	set_error_handler(array('EE_Error', 'error_handler'));
9
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
10 10
 }
11 11
 
12 12
 
@@ -23,259 +23,259 @@  discard block
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     *    name of the file to log exceptions to
28
-     *
29
-     * @var string
30
-     */
31
-    private static $_exception_log_file = 'espresso_error_log.txt';
32
-
33
-    /**
34
-     *    stores details for all exception
35
-     *
36
-     * @var array
37
-     */
38
-    private static $_all_exceptions = array();
39
-
40
-    /**
41
-     *    tracks number of errors
42
-     *
43
-     * @var int
44
-     */
45
-    private static $_error_count = 0;
46
-
47
-    /**
48
-     *    has shutdown action been added ?
49
-     *
50
-     * @var array $_espresso_notices
51
-     */
52
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
-
54
-
55
-
56
-    /**
57
-     * @override default exception handling
58
-     * @param string         $message
59
-     * @param int            $code
60
-     * @param Exception|null $previous
61
-     */
62
-    public function __construct($message, $code = 0, Exception $previous = null)
63
-    {
64
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
-            parent::__construct($message, $code);
66
-        } else {
67
-            parent::__construct($message, $code, $previous);
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    error_handler
75
-     *
76
-     * @param $code
77
-     * @param $message
78
-     * @param $file
79
-     * @param $line
80
-     * @return void
81
-     */
82
-    public static function error_handler($code, $message, $file, $line)
83
-    {
84
-        $type = EE_Error::error_type($code);
85
-        $site = site_url();
86
-        switch ($site) {
87
-            case 'http://ee4.eventespresso.com/' :
88
-            case 'http://ee4decaf.eventespresso.com/' :
89
-            case 'http://ee4hf.eventespresso.com/' :
90
-            case 'http://ee4a.eventespresso.com/' :
91
-            case 'http://ee4ad.eventespresso.com/' :
92
-            case 'http://ee4b.eventespresso.com/' :
93
-            case 'http://ee4bd.eventespresso.com/' :
94
-            case 'http://ee4d.eventespresso.com/' :
95
-            case 'http://ee4dd.eventespresso.com/' :
96
-                $to = '[email protected]';
97
-                break;
98
-            default :
99
-                $to = get_option('admin_email');
100
-        }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
103
-        if (function_exists('wp_mail')) {
104
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
-            wp_mail($to, $subject, $msg);
106
-        }
107
-        echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
-        echo '<br /></p></div>';
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * error_type
116
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
-     *
118
-     * @param $code
119
-     * @return string
120
-     */
121
-    public static function error_type($code)
122
-    {
123
-        switch ($code) {
124
-            case E_ERROR: // 1 //
125
-                return 'E_ERROR';
126
-            case E_WARNING: // 2 //
127
-                return 'E_WARNING';
128
-            case E_PARSE: // 4 //
129
-                return 'E_PARSE';
130
-            case E_NOTICE: // 8 //
131
-                return 'E_NOTICE';
132
-            case E_CORE_ERROR: // 16 //
133
-                return 'E_CORE_ERROR';
134
-            case E_CORE_WARNING: // 32 //
135
-                return 'E_CORE_WARNING';
136
-            case E_COMPILE_ERROR: // 64 //
137
-                return 'E_COMPILE_ERROR';
138
-            case E_COMPILE_WARNING: // 128 //
139
-                return 'E_COMPILE_WARNING';
140
-            case E_USER_ERROR: // 256 //
141
-                return 'E_USER_ERROR';
142
-            case E_USER_WARNING: // 512 //
143
-                return 'E_USER_WARNING';
144
-            case E_USER_NOTICE: // 1024 //
145
-                return 'E_USER_NOTICE';
146
-            case E_STRICT: // 2048 //
147
-                return 'E_STRICT';
148
-            case E_RECOVERABLE_ERROR: // 4096 //
149
-                return 'E_RECOVERABLE_ERROR';
150
-            case E_DEPRECATED: // 8192 //
151
-                return 'E_DEPRECATED';
152
-            case E_USER_DEPRECATED: // 16384 //
153
-                return 'E_USER_DEPRECATED';
154
-            case E_ALL: // 16384 //
155
-                return 'E_ALL';
156
-        }
157
-        return '';
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     *    fatal_error_handler
164
-     *
165
-     * @return void
166
-     */
167
-    public static function fatal_error_handler()
168
-    {
169
-        $last_error = error_get_last();
170
-        if ($last_error['type'] === E_ERROR) {
171
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
-        }
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * _format_error
179
-     *
180
-     * @param $code
181
-     * @param $message
182
-     * @param $file
183
-     * @param $line
184
-     * @return string
185
-     */
186
-    private static function _format_error($code, $message, $file, $line)
187
-    {
188
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
-        $html .= '</tbody></table>';
194
-        return $html;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * set_content_type
201
-     *
202
-     * @param $content_type
203
-     * @return string
204
-     */
205
-    public static function set_content_type($content_type)
206
-    {
207
-        return 'text/html';
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * @return void
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function get_error()
218
-    {
219
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
-            throw $this;
221
-        }
222
-        // get separate user and developer messages if they exist
223
-        $msg = explode('||', $this->getMessage());
224
-        $user_msg = $msg[0];
225
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
227
-        // add details to _all_exceptions array
228
-        $x_time = time();
229
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
233
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
-        self::$_error_count++;
237
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
238
-        $this->display_errors();
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     *    has_error
245
-     *
246
-     * @param bool   $check_stored
247
-     * @param string $type_to_check
248
-     * @return bool
249
-     */
250
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
251
-    {
252
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
253
-                     && ! empty(self::$_espresso_notices[$type_to_check])
254
-            ? true
255
-            : false;
256
-        if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
258
-            foreach ($notices as $type => $notice) {
259
-                if ($type === $type_to_check && $notice) {
260
-                    return true;
261
-                }
262
-            }
263
-        }
264
-        return $has_error;
265
-    }
266
-
267
-
268
-
269
-    /**
270
-     *    display_errors
271
-     *
272
-     * @echo   string
273
-     * @throws \ReflectionException
274
-     */
275
-    public function display_errors()
276
-    {
277
-        $trace_details = '';
278
-        $output = '
26
+	/**
27
+	 *    name of the file to log exceptions to
28
+	 *
29
+	 * @var string
30
+	 */
31
+	private static $_exception_log_file = 'espresso_error_log.txt';
32
+
33
+	/**
34
+	 *    stores details for all exception
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private static $_all_exceptions = array();
39
+
40
+	/**
41
+	 *    tracks number of errors
42
+	 *
43
+	 * @var int
44
+	 */
45
+	private static $_error_count = 0;
46
+
47
+	/**
48
+	 *    has shutdown action been added ?
49
+	 *
50
+	 * @var array $_espresso_notices
51
+	 */
52
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
+
54
+
55
+
56
+	/**
57
+	 * @override default exception handling
58
+	 * @param string         $message
59
+	 * @param int            $code
60
+	 * @param Exception|null $previous
61
+	 */
62
+	public function __construct($message, $code = 0, Exception $previous = null)
63
+	{
64
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
+			parent::__construct($message, $code);
66
+		} else {
67
+			parent::__construct($message, $code, $previous);
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    error_handler
75
+	 *
76
+	 * @param $code
77
+	 * @param $message
78
+	 * @param $file
79
+	 * @param $line
80
+	 * @return void
81
+	 */
82
+	public static function error_handler($code, $message, $file, $line)
83
+	{
84
+		$type = EE_Error::error_type($code);
85
+		$site = site_url();
86
+		switch ($site) {
87
+			case 'http://ee4.eventespresso.com/' :
88
+			case 'http://ee4decaf.eventespresso.com/' :
89
+			case 'http://ee4hf.eventespresso.com/' :
90
+			case 'http://ee4a.eventespresso.com/' :
91
+			case 'http://ee4ad.eventespresso.com/' :
92
+			case 'http://ee4b.eventespresso.com/' :
93
+			case 'http://ee4bd.eventespresso.com/' :
94
+			case 'http://ee4d.eventespresso.com/' :
95
+			case 'http://ee4dd.eventespresso.com/' :
96
+				$to = '[email protected]';
97
+				break;
98
+			default :
99
+				$to = get_option('admin_email');
100
+		}
101
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
103
+		if (function_exists('wp_mail')) {
104
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
+			wp_mail($to, $subject, $msg);
106
+		}
107
+		echo '<div id="message" class="espresso-notices error"><p>';
108
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
+		echo '<br /></p></div>';
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * error_type
116
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
+	 *
118
+	 * @param $code
119
+	 * @return string
120
+	 */
121
+	public static function error_type($code)
122
+	{
123
+		switch ($code) {
124
+			case E_ERROR: // 1 //
125
+				return 'E_ERROR';
126
+			case E_WARNING: // 2 //
127
+				return 'E_WARNING';
128
+			case E_PARSE: // 4 //
129
+				return 'E_PARSE';
130
+			case E_NOTICE: // 8 //
131
+				return 'E_NOTICE';
132
+			case E_CORE_ERROR: // 16 //
133
+				return 'E_CORE_ERROR';
134
+			case E_CORE_WARNING: // 32 //
135
+				return 'E_CORE_WARNING';
136
+			case E_COMPILE_ERROR: // 64 //
137
+				return 'E_COMPILE_ERROR';
138
+			case E_COMPILE_WARNING: // 128 //
139
+				return 'E_COMPILE_WARNING';
140
+			case E_USER_ERROR: // 256 //
141
+				return 'E_USER_ERROR';
142
+			case E_USER_WARNING: // 512 //
143
+				return 'E_USER_WARNING';
144
+			case E_USER_NOTICE: // 1024 //
145
+				return 'E_USER_NOTICE';
146
+			case E_STRICT: // 2048 //
147
+				return 'E_STRICT';
148
+			case E_RECOVERABLE_ERROR: // 4096 //
149
+				return 'E_RECOVERABLE_ERROR';
150
+			case E_DEPRECATED: // 8192 //
151
+				return 'E_DEPRECATED';
152
+			case E_USER_DEPRECATED: // 16384 //
153
+				return 'E_USER_DEPRECATED';
154
+			case E_ALL: // 16384 //
155
+				return 'E_ALL';
156
+		}
157
+		return '';
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 *    fatal_error_handler
164
+	 *
165
+	 * @return void
166
+	 */
167
+	public static function fatal_error_handler()
168
+	{
169
+		$last_error = error_get_last();
170
+		if ($last_error['type'] === E_ERROR) {
171
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
+		}
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * _format_error
179
+	 *
180
+	 * @param $code
181
+	 * @param $message
182
+	 * @param $file
183
+	 * @param $line
184
+	 * @return string
185
+	 */
186
+	private static function _format_error($code, $message, $file, $line)
187
+	{
188
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
+		$html .= '</tbody></table>';
194
+		return $html;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * set_content_type
201
+	 *
202
+	 * @param $content_type
203
+	 * @return string
204
+	 */
205
+	public static function set_content_type($content_type)
206
+	{
207
+		return 'text/html';
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * @return void
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function get_error()
218
+	{
219
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
+			throw $this;
221
+		}
222
+		// get separate user and developer messages if they exist
223
+		$msg = explode('||', $this->getMessage());
224
+		$user_msg = $msg[0];
225
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
227
+		// add details to _all_exceptions array
228
+		$x_time = time();
229
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
233
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
+		self::$_error_count++;
237
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
238
+		$this->display_errors();
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 *    has_error
245
+	 *
246
+	 * @param bool   $check_stored
247
+	 * @param string $type_to_check
248
+	 * @return bool
249
+	 */
250
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
251
+	{
252
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
253
+					 && ! empty(self::$_espresso_notices[$type_to_check])
254
+			? true
255
+			: false;
256
+		if ($check_stored && ! $has_error) {
257
+			$notices = (array)get_option('ee_notices', array());
258
+			foreach ($notices as $type => $notice) {
259
+				if ($type === $type_to_check && $notice) {
260
+					return true;
261
+				}
262
+			}
263
+		}
264
+		return $has_error;
265
+	}
266
+
267
+
268
+
269
+	/**
270
+	 *    display_errors
271
+	 *
272
+	 * @echo   string
273
+	 * @throws \ReflectionException
274
+	 */
275
+	public function display_errors()
276
+	{
277
+		$trace_details = '';
278
+		$output = '
279 279
 <style type="text/css">
280 280
 	#ee-error-message {
281 281
 		max-width:90% !important;
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
335
-            $output .= '
334
+		if (! WP_DEBUG) {
335
+			$output .= '
336 336
 	<p>';
337
-        }
338
-        // cycle thru errors
339
-        foreach (self::$_all_exceptions as $time => $ex) {
340
-            $error_code = '';
341
-            // process trace info
342
-            if (empty($ex['trace'])) {
343
-                $trace_details .= __('Sorry, but no trace information was available for this exception.',
344
-                    'event_espresso');
345
-            } else {
346
-                $trace_details .= '
337
+		}
338
+		// cycle thru errors
339
+		foreach (self::$_all_exceptions as $time => $ex) {
340
+			$error_code = '';
341
+			// process trace info
342
+			if (empty($ex['trace'])) {
343
+				$trace_details .= __('Sorry, but no trace information was available for this exception.',
344
+					'event_espresso');
345
+			} else {
346
+				$trace_details .= '
347 347
 			<div id="ee-trace-details">
348 348
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
349 349
 				<tr>
@@ -353,38 +353,38 @@  discard block
 block discarded – undo
353 353
 					<th scope="col" align="left">Class</th>
354 354
 					<th scope="col" align="left">Method( arguments )</th>
355 355
 				</tr>';
356
-                $last_on_stack = count($ex['trace']) - 1;
357
-                // reverse array so that stack is in proper chronological order
358
-                $sorted_trace = array_reverse($ex['trace']);
359
-                foreach ($sorted_trace as $nmbr => $trace) {
360
-                    $file = isset($trace['file']) ? $trace['file'] : '';
361
-                    $class = isset($trace['class']) ? $trace['class'] : '';
362
-                    $type = isset($trace['type']) ? $trace['type'] : '';
363
-                    $function = isset($trace['function']) ? $trace['function'] : '';
364
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
-                    $line = isset($trace['line']) ? $trace['line'] : '';
366
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
367
-                    if (empty($file) && ! empty($class)) {
368
-                        $a = new ReflectionClass($class);
369
-                        $file = $a->getFileName();
370
-                        if (empty($line) && ! empty($function)) {
371
-                            $b = new ReflectionMethod($class, $function);
372
-                            $line = $b->getStartLine();
373
-                        }
374
-                    }
375
-                    if ($nmbr === $last_on_stack) {
376
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
377
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
378
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
379
-                    }
380
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
382
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
383
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
384
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
385
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
-                    $trace_details .= '
356
+				$last_on_stack = count($ex['trace']) - 1;
357
+				// reverse array so that stack is in proper chronological order
358
+				$sorted_trace = array_reverse($ex['trace']);
359
+				foreach ($sorted_trace as $nmbr => $trace) {
360
+					$file = isset($trace['file']) ? $trace['file'] : '';
361
+					$class = isset($trace['class']) ? $trace['class'] : '';
362
+					$type = isset($trace['type']) ? $trace['type'] : '';
363
+					$function = isset($trace['function']) ? $trace['function'] : '';
364
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
+					$line = isset($trace['line']) ? $trace['line'] : '';
366
+					$zebra = ($nmbr % 2) ? ' odd' : '';
367
+					if (empty($file) && ! empty($class)) {
368
+						$a = new ReflectionClass($class);
369
+						$file = $a->getFileName();
370
+						if (empty($line) && ! empty($function)) {
371
+							$b = new ReflectionMethod($class, $function);
372
+							$line = $b->getStartLine();
373
+						}
374
+					}
375
+					if ($nmbr === $last_on_stack) {
376
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
377
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
378
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
379
+					}
380
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
381
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
382
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
383
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
384
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
385
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
386
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
+					$trace_details .= '
388 388
 					<tr>
389 389
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390 390
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -392,670 +392,670 @@  discard block
 block discarded – undo
392 392
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393 393
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
394 394
 					</tr>';
395
-                }
396
-                $trace_details .= '
395
+				}
396
+				$trace_details .= '
397 397
 			 </table>
398 398
 			</div>';
399
-            }
400
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
-            // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
403
-                $output .= '<span class="ee-error-user-msg-spn">'
404
-                           . trim($ex['msg'])
405
-                           . '</span> &nbsp; <sup>'
406
-                           . $ex['code']
407
-                           . '</sup><br />';
408
-            } else {
409
-                // or helpful developer messages if debugging is on
410
-                $output .= '
399
+			}
400
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401
+			// add generic non-identifying messages for non-privileged users
402
+			if (! WP_DEBUG) {
403
+				$output .= '<span class="ee-error-user-msg-spn">'
404
+						   . trim($ex['msg'])
405
+						   . '</span> &nbsp; <sup>'
406
+						   . $ex['code']
407
+						   . '</sup><br />';
408
+			} else {
409
+				// or helpful developer messages if debugging is on
410
+				$output .= '
411 411
 		<div class="ee-error-dev-msg-dv">
412 412
 			<p class="ee-error-dev-msg-pg">
413 413
 				<strong class="ee-error-dev-msg-str">An '
414
-                           . $ex['name']
415
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
-                           . $ex['code']
417
-                           . '</span><br />
414
+						   . $ex['name']
415
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
416
+						   . $ex['code']
417
+						   . '</span><br />
418 418
 				<span class="big-text">"'
419
-                           . trim($ex['msg'])
420
-                           . '"</span><br/>
419
+						   . trim($ex['msg'])
420
+						   . '"</span><br/>
421 421
 				<a id="display-ee-error-trace-'
422
-                           . self::$_error_count
423
-                           . $time
424
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
-                           . self::$_error_count
426
-                           . $time
427
-                           . '">
422
+						   . self::$_error_count
423
+						   . $time
424
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
425
+						   . self::$_error_count
426
+						   . $time
427
+						   . '">
428 428
 					'
429
-                           . __('click to view backtrace and class/method details', 'event_espresso')
430
-                           . '
429
+						   . __('click to view backtrace and class/method details', 'event_espresso')
430
+						   . '
431 431
 				</a><br />
432 432
 				<span class="small-text lt-grey-text">'
433
-                           . $ex['file']
434
-                           . ' &nbsp; ( line no: '
435
-                           . $ex['line']
436
-                           . ' )</span>
433
+						   . $ex['file']
434
+						   . ' &nbsp; ( line no: '
435
+						   . $ex['line']
436
+						   . ' )</span>
437 437
 			</p>
438 438
 			<div id="ee-error-trace-'
439
-                           . self::$_error_count
440
-                           . $time
441
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
439
+						   . self::$_error_count
440
+						   . $time
441
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443
-                           . $trace_details;
444
-                if (! empty($class)) {
445
-                    $output .= '
443
+						   . $trace_details;
444
+				if (! empty($class)) {
445
+					$output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449
-                    $a = new ReflectionClass($class);
450
-                    $output .= '
449
+					$a = new ReflectionClass($class);
450
+					$output .= '
451 451
 						<pre>' . $a . '</pre>
452 452
 					</div>
453 453
 				</div>';
454
-                }
455
-                $output .= '
454
+				}
455
+				$output .= '
456 456
 			</div>
457 457
 		</div>
458 458
 		<br />';
459
-            }
460
-            $this->write_to_error_log($time, $ex);
461
-        }
462
-        // remove last linebreak
463
-        $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
465
-            $output .= '
459
+			}
460
+			$this->write_to_error_log($time, $ex);
461
+		}
462
+		// remove last linebreak
463
+		$output = substr($output, 0, -6);
464
+		if (! WP_DEBUG) {
465
+			$output .= '
466 466
 	</p>';
467
-        }
468
-        $output .= '
467
+		}
468
+		$output .= '
469 469
 </div>';
470
-        $output .= self::_print_scripts(true);
471
-        if (defined('DOING_AJAX')) {
472
-            echo wp_json_encode(array('error' => $output));
473
-            exit();
474
-        }
475
-        echo $output;
476
-        die();
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     *    generate string from exception trace args
483
-     *
484
-     * @param array $arguments
485
-     * @param bool  $array
486
-     * @return string
487
-     */
488
-    private function _convert_args_to_string($arguments = array(), $array = false)
489
-    {
490
-        $arg_string = '';
491
-        if (! empty($arguments)) {
492
-            $args = array();
493
-            foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
495
-                    if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
497
-                    } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
-                    } elseif ($arg === null) {
500
-                        $args[] = ' NULL';
501
-                    } elseif (is_bool($arg)) {
502
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
503
-                    } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
505
-                    } elseif (is_resource($arg)) {
506
-                        $args[] = get_resource_type($arg);
507
-                    } else {
508
-                        $args[] = $arg;
509
-                    }
510
-                }
511
-            }
512
-            $arg_string = implode(', ', $args);
513
-        }
514
-        if ($array) {
515
-            $arg_string .= ' )';
516
-        }
517
-        return $arg_string;
518
-    }
519
-
520
-
521
-
522
-    /**
523
-     *    add error message
524
-     *
525
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
-     *                            separate messages for user || dev
527
-     * @param        string $file the file that the error occurred in - just use __FILE__
528
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
-     * @param        string $line the line number where the error occurred - just use __LINE__
530
-     * @return        void
531
-     */
532
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
-    {
534
-        self::_add_notice('errors', $msg, $file, $func, $line);
535
-        self::$_error_count++;
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
-     * adds an error
543
-     *
544
-     * @param string $msg
545
-     * @param string $file
546
-     * @param string $func
547
-     * @param string $line
548
-     * @throws EE_Error
549
-     */
550
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
-    {
552
-        if (WP_DEBUG) {
553
-            throw new EE_Error($msg);
554
-        }
555
-        EE_Error::add_error($msg, $file, $func, $line);
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     *    add success message
562
-     *
563
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
-     *                            separate messages for user || dev
565
-     * @param        string $file the file that the error occurred in - just use __FILE__
566
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
-     * @param        string $line the line number where the error occurred - just use __LINE__
568
-     * @return        void
569
-     */
570
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
-    {
572
-        self::_add_notice('success', $msg, $file, $func, $line);
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     *    add attention message
579
-     *
580
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
-     *                            separate messages for user || dev
582
-     * @param        string $file the file that the error occurred in - just use __FILE__
583
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
-     * @param        string $line the line number where the error occurred - just use __LINE__
585
-     * @return        void
586
-     */
587
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
-    {
589
-        self::_add_notice('attention', $msg, $file, $func, $line);
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     *    add success message
596
-     *
597
-     * @param        string $type whether the message is for a success or error notification
598
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
-     *                            separate messages for user || dev
600
-     * @param        string $file the file that the error occurred in - just use __FILE__
601
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
-     * @param        string $line the line number where the error occurred - just use __LINE__
603
-     * @return        void
604
-     */
605
-    private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
-    {
607
-        if (empty($msg)) {
608
-            EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
610
-                sprintf(
611
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612
-                        'event_espresso'),
613
-                    $type,
614
-                    $file,
615
-                    $line
616
-                ),
617
-                EVENT_ESPRESSO_VERSION
618
-            );
619
-        }
620
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
-            EE_Error::doing_it_wrong(
622
-                'EE_Error::add_error()',
623
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
-                    'event_espresso'),
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-        }
628
-        // get separate user and developer messages if they exist
629
-        $msg = explode('||', $msg);
630
-        $user_msg = $msg[0];
631
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
-        /**
633
-         * Do an action so other code can be triggered when a notice is created
634
-         *
635
-         * @param string $type     can be 'errors', 'attention', or 'success'
636
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
637
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
638
-         * @param string $file     file where error was generated
639
-         * @param string $func     function where error was generated
640
-         * @param string $line     line where error was generated
641
-         */
642
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
644
-        // add notice if message exists
645
-        if (! empty($msg)) {
646
-            // get error code
647
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
648
-            if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
-            }
651
-            // add notice. Index by code if it's not blank
652
-            if ($notice_code) {
653
-                self::$_espresso_notices[$type][$notice_code] = $msg;
654
-            } else {
655
-                self::$_espresso_notices[$type][] = $msg;
656
-            }
657
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
-        }
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     *    in some case it may be necessary to overwrite the existing success messages
665
-     *
666
-     * @return        void
667
-     */
668
-    public static function overwrite_success()
669
-    {
670
-        self::$_espresso_notices['success'] = false;
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     *    in some case it may be necessary to overwrite the existing attention messages
677
-     *
678
-     * @return        void
679
-     */
680
-    public static function overwrite_attention()
681
-    {
682
-        self::$_espresso_notices['attention'] = false;
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     *    in some case it may be necessary to overwrite the existing error messages
689
-     *
690
-     * @return        void
691
-     */
692
-    public static function overwrite_errors()
693
-    {
694
-        self::$_espresso_notices['errors'] = false;
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     *    reset_notices
701
-     *
702
-     * @return void
703
-     */
704
-    public static function reset_notices()
705
-    {
706
-        self::$_espresso_notices['success'] = false;
707
-        self::$_espresso_notices['attention'] = false;
708
-        self::$_espresso_notices['errors'] = false;
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     *    has_errors
715
-     *
716
-     * @return int
717
-     */
718
-    public static function has_notices()
719
-    {
720
-        $has_notices = 0;
721
-        // check for success messages
722
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
-            : $has_notices;
724
-        // check for attention messages
725
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
-            : $has_notices;
727
-        // check for error messages
728
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
-            : $has_notices;
730
-        return $has_notices;
731
-    }
732
-
733
-
734
-
735
-    /**
736
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
-     *
738
-     * @since 4.9.0
739
-     * @return array
740
-     */
741
-    public static function get_vanilla_notices()
742
-    {
743
-        return array(
744
-            'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
-            'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
-                : array(),
747
-            'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
-        );
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     *    compile all error or success messages into one string
755
-     *
756
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
-     * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
-     * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
-     *                                          - ONLY do this just before redirecting
760
-     * @param        boolean $remove_empty      whether or not to unset empty messages
761
-     * @return        array
762
-     */
763
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
-    {
765
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
-        $success_messages = '';
767
-        $attention_messages = '';
768
-        $error_messages = '';
769
-        $print_scripts = false;
770
-        // either save notices to the db
771
-        if ($save_to_transient) {
772
-            update_option('ee_notices', self::$_espresso_notices);
773
-            return array();
774
-        }
775
-        // grab any notices that have been previously saved
776
-        if ($notices = get_option('ee_notices', false)) {
777
-            foreach ($notices as $type => $notice) {
778
-                if (is_array($notice) && ! empty($notice)) {
779
-                    // make sure that existing notice type is an array
780
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
-                                                      && ! empty(self::$_espresso_notices[$type])
782
-                        ? self::$_espresso_notices[$type] : array();
783
-                    // merge stored notices with any newly created ones
784
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
-                    $print_scripts = true;
786
-                }
787
-            }
788
-            // now clear any stored notices
789
-            update_option('ee_notices', false);
790
-        }
791
-        // check for success messages
792
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
-            // combine messages
794
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
-            $print_scripts = true;
796
-        }
797
-        // check for attention messages
798
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
-            // combine messages
800
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
-            $print_scripts = true;
802
-        }
803
-        // check for error messages
804
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
806
-                ? __('The following errors have occurred:<br />', 'event_espresso')
807
-                : __('An error has occurred:<br />', 'event_espresso');
808
-            // combine messages
809
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
-            $print_scripts = true;
811
-        }
812
-        self::$_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
813
-        if ($format_output) {
814
-            $notices = '<div id="espresso-notices">';
815
-            $close = is_admin() ? ''
816
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
817
-            if ($success_messages !== '') {
818
-                $css_id = is_admin() ? 'message' : 'espresso-notices-success';
819
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
820
-                //showMessage( $success_messages );
821
-                $notices .= '<div id="'
822
-                            . $css_id
823
-                            . '" class="espresso-notices '
824
-                            . $css_class
825
-                            . '" style="display:none;"><p>'
826
-                            . $success_messages
827
-                            . '</p>'
828
-                            . $close
829
-                            . '</div>';
830
-            }
831
-            if ($attention_messages !== '') {
832
-                $css_id = is_admin() ? 'message' : 'espresso-notices-attention';
833
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
834
-                //showMessage( $error_messages, TRUE );
835
-                $notices .= '<div id="'
836
-                            . $css_id
837
-                            . '" class="espresso-notices '
838
-                            . $css_class
839
-                            . '" style="display:none;"><p>'
840
-                            . $attention_messages
841
-                            . '</p>'
842
-                            . $close
843
-                            . '</div>';
844
-            }
845
-            if ($error_messages !== '') {
846
-                $css_id = is_admin() ? 'message' : 'espresso-notices-error';
847
-                $css_class = is_admin() ? 'error' : 'error fade-away';
848
-                //showMessage( $error_messages, TRUE );
849
-                $notices .= '<div id="'
850
-                            . $css_id
851
-                            . '" class="espresso-notices '
852
-                            . $css_class
853
-                            . '" style="display:none;"><p>'
854
-                            . $error_messages
855
-                            . '</p>'
856
-                            . $close
857
-                            . '</div>';
858
-            }
859
-            $notices .= '</div>';
860
-        } else {
861
-            $notices = array(
862
-                'success'   => $success_messages,
863
-                'attention' => $attention_messages,
864
-                'errors'    => $error_messages,
865
-            );
866
-            if ($remove_empty) {
867
-                // remove empty notices
868
-                foreach ($notices as $type => $notice) {
869
-                    if (empty($notice)) {
870
-                        unset($notices[$type]);
871
-                    }
872
-                }
873
-            }
874
-        }
875
-        if ($print_scripts) {
876
-            self::_print_scripts();
877
-        }
878
-        return $notices;
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     *    add_persistent_admin_notice
885
-     *
886
-     * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
887
-     * @param        string $pan_message  the message to be stored persistently until dismissed
888
-     * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
889
-     * @return        void
890
-     */
891
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892
-    {
893
-        if (! empty($pan_name) && ! empty($pan_message)) {
894
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895
-            //maybe initialize persistent_admin_notices
896
-            if (empty($persistent_admin_notices)) {
897
-                add_option('ee_pers_admin_notices', array(), '', 'no');
898
-            }
899
-            $pan_name = sanitize_key($pan_name);
900
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901
-                $persistent_admin_notices[$pan_name] = $pan_message;
902
-                update_option('ee_pers_admin_notices', $persistent_admin_notices);
903
-            }
904
-        }
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     *    dismiss_persistent_admin_notice
911
-     *
912
-     * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
913
-     * @param bool          $purge
914
-     * @param bool          $return_immediately
915
-     * @return        void
916
-     */
917
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
918
-    {
919
-        $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920
-            ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
-        if (! empty($pan_name)) {
922
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923
-            // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924
-            if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
925
-                // completely delete nag notice, or just NULL message so that it can NOT be added again ?
926
-                if ($purge) {
927
-                    unset($persistent_admin_notices[$pan_name]);
928
-                } else {
929
-                    $persistent_admin_notices[$pan_name] = null;
930
-                }
931
-                if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
932
-                    EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
933
-                        'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
934
-                }
935
-            }
936
-        }
937
-        if ($return_immediately) {
938
-            return;
939
-        }
940
-        if (EE_Registry::instance()->REQ->ajax) {
941
-            // grab any notices and concatenate into string
942
-            echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
943
-            exit();
944
-        }
945
-        // save errors to a transient to be displayed on next request (after redirect)
946
-        EE_Error::get_notices(false, true);
947
-        $return_url = EE_Registry::instance()->REQ->is_set('return_url')
948
-            ? EE_Registry::instance()->REQ->get('return_url') : '';
949
-        wp_safe_redirect(urldecode($return_url));
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * display_persistent_admin_notices
956
-     *
957
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
958
-     * @param  string $pan_message the message to be stored persistently until dismissed
959
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
960
-     * @return string
961
-     */
962
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963
-    {
964
-        if (! empty($pan_name) && ! empty($pan_message)) {
965
-            $args = array(
966
-                'nag_notice'    => $pan_name,
967
-                'return_url'    => urlencode($return_url),
968
-                'ajax_url'      => WP_AJAX_URL,
969
-                'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
970
-                    'event_espresso'),
971
-            );
972
-            wp_localize_script('espresso_core', 'ee_dismiss', $args);
973
-            return '
470
+		$output .= self::_print_scripts(true);
471
+		if (defined('DOING_AJAX')) {
472
+			echo wp_json_encode(array('error' => $output));
473
+			exit();
474
+		}
475
+		echo $output;
476
+		die();
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 *    generate string from exception trace args
483
+	 *
484
+	 * @param array $arguments
485
+	 * @param bool  $array
486
+	 * @return string
487
+	 */
488
+	private function _convert_args_to_string($arguments = array(), $array = false)
489
+	{
490
+		$arg_string = '';
491
+		if (! empty($arguments)) {
492
+			$args = array();
493
+			foreach ($arguments as $arg) {
494
+				if (! empty($arg)) {
495
+					if (is_string($arg)) {
496
+						$args[] = " '" . $arg . "'";
497
+					} elseif (is_array($arg)) {
498
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
+					} elseif ($arg === null) {
500
+						$args[] = ' NULL';
501
+					} elseif (is_bool($arg)) {
502
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
503
+					} elseif (is_object($arg)) {
504
+						$args[] = ' OBJECT ' . get_class($arg);
505
+					} elseif (is_resource($arg)) {
506
+						$args[] = get_resource_type($arg);
507
+					} else {
508
+						$args[] = $arg;
509
+					}
510
+				}
511
+			}
512
+			$arg_string = implode(', ', $args);
513
+		}
514
+		if ($array) {
515
+			$arg_string .= ' )';
516
+		}
517
+		return $arg_string;
518
+	}
519
+
520
+
521
+
522
+	/**
523
+	 *    add error message
524
+	 *
525
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
526
+	 *                            separate messages for user || dev
527
+	 * @param        string $file the file that the error occurred in - just use __FILE__
528
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
529
+	 * @param        string $line the line number where the error occurred - just use __LINE__
530
+	 * @return        void
531
+	 */
532
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
533
+	{
534
+		self::_add_notice('errors', $msg, $file, $func, $line);
535
+		self::$_error_count++;
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
542
+	 * adds an error
543
+	 *
544
+	 * @param string $msg
545
+	 * @param string $file
546
+	 * @param string $func
547
+	 * @param string $line
548
+	 * @throws EE_Error
549
+	 */
550
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
551
+	{
552
+		if (WP_DEBUG) {
553
+			throw new EE_Error($msg);
554
+		}
555
+		EE_Error::add_error($msg, $file, $func, $line);
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 *    add success message
562
+	 *
563
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
564
+	 *                            separate messages for user || dev
565
+	 * @param        string $file the file that the error occurred in - just use __FILE__
566
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
567
+	 * @param        string $line the line number where the error occurred - just use __LINE__
568
+	 * @return        void
569
+	 */
570
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
571
+	{
572
+		self::_add_notice('success', $msg, $file, $func, $line);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 *    add attention message
579
+	 *
580
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
581
+	 *                            separate messages for user || dev
582
+	 * @param        string $file the file that the error occurred in - just use __FILE__
583
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
584
+	 * @param        string $line the line number where the error occurred - just use __LINE__
585
+	 * @return        void
586
+	 */
587
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
588
+	{
589
+		self::_add_notice('attention', $msg, $file, $func, $line);
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 *    add success message
596
+	 *
597
+	 * @param        string $type whether the message is for a success or error notification
598
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
599
+	 *                            separate messages for user || dev
600
+	 * @param        string $file the file that the error occurred in - just use __FILE__
601
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
602
+	 * @param        string $line the line number where the error occurred - just use __LINE__
603
+	 * @return        void
604
+	 */
605
+	private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
606
+	{
607
+		if (empty($msg)) {
608
+			EE_Error::doing_it_wrong(
609
+				'EE_Error::add_' . $type . '()',
610
+				sprintf(
611
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612
+						'event_espresso'),
613
+					$type,
614
+					$file,
615
+					$line
616
+				),
617
+				EVENT_ESPRESSO_VERSION
618
+			);
619
+		}
620
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
621
+			EE_Error::doing_it_wrong(
622
+				'EE_Error::add_error()',
623
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
624
+					'event_espresso'),
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+		}
628
+		// get separate user and developer messages if they exist
629
+		$msg = explode('||', $msg);
630
+		$user_msg = $msg[0];
631
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
632
+		/**
633
+		 * Do an action so other code can be triggered when a notice is created
634
+		 *
635
+		 * @param string $type     can be 'errors', 'attention', or 'success'
636
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
637
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
638
+		 * @param string $file     file where error was generated
639
+		 * @param string $func     function where error was generated
640
+		 * @param string $line     line where error was generated
641
+		 */
642
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
644
+		// add notice if message exists
645
+		if (! empty($msg)) {
646
+			// get error code
647
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
648
+			if (WP_DEBUG && $type === 'errors') {
649
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
650
+			}
651
+			// add notice. Index by code if it's not blank
652
+			if ($notice_code) {
653
+				self::$_espresso_notices[$type][$notice_code] = $msg;
654
+			} else {
655
+				self::$_espresso_notices[$type][] = $msg;
656
+			}
657
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
658
+		}
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 *    in some case it may be necessary to overwrite the existing success messages
665
+	 *
666
+	 * @return        void
667
+	 */
668
+	public static function overwrite_success()
669
+	{
670
+		self::$_espresso_notices['success'] = false;
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 *    in some case it may be necessary to overwrite the existing attention messages
677
+	 *
678
+	 * @return        void
679
+	 */
680
+	public static function overwrite_attention()
681
+	{
682
+		self::$_espresso_notices['attention'] = false;
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 *    in some case it may be necessary to overwrite the existing error messages
689
+	 *
690
+	 * @return        void
691
+	 */
692
+	public static function overwrite_errors()
693
+	{
694
+		self::$_espresso_notices['errors'] = false;
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 *    reset_notices
701
+	 *
702
+	 * @return void
703
+	 */
704
+	public static function reset_notices()
705
+	{
706
+		self::$_espresso_notices['success'] = false;
707
+		self::$_espresso_notices['attention'] = false;
708
+		self::$_espresso_notices['errors'] = false;
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 *    has_errors
715
+	 *
716
+	 * @return int
717
+	 */
718
+	public static function has_notices()
719
+	{
720
+		$has_notices = 0;
721
+		// check for success messages
722
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
723
+			: $has_notices;
724
+		// check for attention messages
725
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
726
+			: $has_notices;
727
+		// check for error messages
728
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
729
+			: $has_notices;
730
+		return $has_notices;
731
+	}
732
+
733
+
734
+
735
+	/**
736
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
737
+	 *
738
+	 * @since 4.9.0
739
+	 * @return array
740
+	 */
741
+	public static function get_vanilla_notices()
742
+	{
743
+		return array(
744
+			'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
745
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
746
+				: array(),
747
+			'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
748
+		);
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 *    compile all error or success messages into one string
755
+	 *
756
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
757
+	 * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
758
+	 * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
759
+	 *                                          - ONLY do this just before redirecting
760
+	 * @param        boolean $remove_empty      whether or not to unset empty messages
761
+	 * @return        array
762
+	 */
763
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
764
+	{
765
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
766
+		$success_messages = '';
767
+		$attention_messages = '';
768
+		$error_messages = '';
769
+		$print_scripts = false;
770
+		// either save notices to the db
771
+		if ($save_to_transient) {
772
+			update_option('ee_notices', self::$_espresso_notices);
773
+			return array();
774
+		}
775
+		// grab any notices that have been previously saved
776
+		if ($notices = get_option('ee_notices', false)) {
777
+			foreach ($notices as $type => $notice) {
778
+				if (is_array($notice) && ! empty($notice)) {
779
+					// make sure that existing notice type is an array
780
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
781
+													  && ! empty(self::$_espresso_notices[$type])
782
+						? self::$_espresso_notices[$type] : array();
783
+					// merge stored notices with any newly created ones
784
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
785
+					$print_scripts = true;
786
+				}
787
+			}
788
+			// now clear any stored notices
789
+			update_option('ee_notices', false);
790
+		}
791
+		// check for success messages
792
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
793
+			// combine messages
794
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
795
+			$print_scripts = true;
796
+		}
797
+		// check for attention messages
798
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
799
+			// combine messages
800
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
801
+			$print_scripts = true;
802
+		}
803
+		// check for error messages
804
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
805
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
806
+				? __('The following errors have occurred:<br />', 'event_espresso')
807
+				: __('An error has occurred:<br />', 'event_espresso');
808
+			// combine messages
809
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
810
+			$print_scripts = true;
811
+		}
812
+		self::$_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
813
+		if ($format_output) {
814
+			$notices = '<div id="espresso-notices">';
815
+			$close = is_admin() ? ''
816
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
817
+			if ($success_messages !== '') {
818
+				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
819
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
820
+				//showMessage( $success_messages );
821
+				$notices .= '<div id="'
822
+							. $css_id
823
+							. '" class="espresso-notices '
824
+							. $css_class
825
+							. '" style="display:none;"><p>'
826
+							. $success_messages
827
+							. '</p>'
828
+							. $close
829
+							. '</div>';
830
+			}
831
+			if ($attention_messages !== '') {
832
+				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
833
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
834
+				//showMessage( $error_messages, TRUE );
835
+				$notices .= '<div id="'
836
+							. $css_id
837
+							. '" class="espresso-notices '
838
+							. $css_class
839
+							. '" style="display:none;"><p>'
840
+							. $attention_messages
841
+							. '</p>'
842
+							. $close
843
+							. '</div>';
844
+			}
845
+			if ($error_messages !== '') {
846
+				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
847
+				$css_class = is_admin() ? 'error' : 'error fade-away';
848
+				//showMessage( $error_messages, TRUE );
849
+				$notices .= '<div id="'
850
+							. $css_id
851
+							. '" class="espresso-notices '
852
+							. $css_class
853
+							. '" style="display:none;"><p>'
854
+							. $error_messages
855
+							. '</p>'
856
+							. $close
857
+							. '</div>';
858
+			}
859
+			$notices .= '</div>';
860
+		} else {
861
+			$notices = array(
862
+				'success'   => $success_messages,
863
+				'attention' => $attention_messages,
864
+				'errors'    => $error_messages,
865
+			);
866
+			if ($remove_empty) {
867
+				// remove empty notices
868
+				foreach ($notices as $type => $notice) {
869
+					if (empty($notice)) {
870
+						unset($notices[$type]);
871
+					}
872
+				}
873
+			}
874
+		}
875
+		if ($print_scripts) {
876
+			self::_print_scripts();
877
+		}
878
+		return $notices;
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 *    add_persistent_admin_notice
885
+	 *
886
+	 * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
887
+	 * @param        string $pan_message  the message to be stored persistently until dismissed
888
+	 * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
889
+	 * @return        void
890
+	 */
891
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892
+	{
893
+		if (! empty($pan_name) && ! empty($pan_message)) {
894
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895
+			//maybe initialize persistent_admin_notices
896
+			if (empty($persistent_admin_notices)) {
897
+				add_option('ee_pers_admin_notices', array(), '', 'no');
898
+			}
899
+			$pan_name = sanitize_key($pan_name);
900
+			if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901
+				$persistent_admin_notices[$pan_name] = $pan_message;
902
+				update_option('ee_pers_admin_notices', $persistent_admin_notices);
903
+			}
904
+		}
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 *    dismiss_persistent_admin_notice
911
+	 *
912
+	 * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
913
+	 * @param bool          $purge
914
+	 * @param bool          $return_immediately
915
+	 * @return        void
916
+	 */
917
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
918
+	{
919
+		$pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920
+			? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
+		if (! empty($pan_name)) {
922
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923
+			// check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924
+			if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
925
+				// completely delete nag notice, or just NULL message so that it can NOT be added again ?
926
+				if ($purge) {
927
+					unset($persistent_admin_notices[$pan_name]);
928
+				} else {
929
+					$persistent_admin_notices[$pan_name] = null;
930
+				}
931
+				if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
932
+					EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
933
+						'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
934
+				}
935
+			}
936
+		}
937
+		if ($return_immediately) {
938
+			return;
939
+		}
940
+		if (EE_Registry::instance()->REQ->ajax) {
941
+			// grab any notices and concatenate into string
942
+			echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
943
+			exit();
944
+		}
945
+		// save errors to a transient to be displayed on next request (after redirect)
946
+		EE_Error::get_notices(false, true);
947
+		$return_url = EE_Registry::instance()->REQ->is_set('return_url')
948
+			? EE_Registry::instance()->REQ->get('return_url') : '';
949
+		wp_safe_redirect(urldecode($return_url));
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * display_persistent_admin_notices
956
+	 *
957
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
958
+	 * @param  string $pan_message the message to be stored persistently until dismissed
959
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
960
+	 * @return string
961
+	 */
962
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963
+	{
964
+		if (! empty($pan_name) && ! empty($pan_message)) {
965
+			$args = array(
966
+				'nag_notice'    => $pan_name,
967
+				'return_url'    => urlencode($return_url),
968
+				'ajax_url'      => WP_AJAX_URL,
969
+				'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.',
970
+					'event_espresso'),
971
+			);
972
+			wp_localize_script('espresso_core', 'ee_dismiss', $args);
973
+			return '
974 974
 			<div id="'
975
-                   . $pan_name
976
-                   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
975
+				   . $pan_name
976
+				   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
977 977
 				<p>'
978
-                   . $pan_message
979
-                   . '</p>
978
+				   . $pan_message
979
+				   . '</p>
980 980
 				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="'
981
-                   . $pan_name
982
-                   . '">
981
+				   . $pan_name
982
+				   . '">
983 983
 					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'
984
-                   . __('Dismiss', 'event_espresso')
985
-                   . '
984
+				   . __('Dismiss', 'event_espresso')
985
+				   . '
986 986
 				</a>
987 987
 				<div style="clear:both;"></div>
988 988
 			</div>';
989
-        }
990
-        return '';
991
-    }
992
-
993
-
994
-
995
-    /**
996
-     *    get_persistent_admin_notices
997
-     *
998
-     * @param string $return_url
999
-     * @return string
1000
-     */
1001
-    public static function get_persistent_admin_notices($return_url = '')
1002
-    {
1003
-        $notices = '';
1004
-        // check for persistent admin notices
1005
-        //filter the list though so plugins can notify the admin in a different way if they want
1006
-        $persistent_admin_notices = apply_filters(
1007
-            'FHEE__EE_Error__get_persistent_admin_notices',
1008
-            get_option('ee_pers_admin_notices', false),
1009
-            'ee_pers_admin_notices',
1010
-            $return_url
1011
-        );
1012
-        if ($persistent_admin_notices) {
1013
-            // load scripts
1014
-            wp_register_script(
1015
-                'espresso_core',
1016
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1017
-                array('jquery'),
1018
-                EVENT_ESPRESSO_VERSION,
1019
-                true
1020
-            );
1021
-            wp_register_script(
1022
-                'ee_error_js',
1023
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1024
-                array('espresso_core'),
1025
-                EVENT_ESPRESSO_VERSION,
1026
-                true
1027
-            );
1028
-            wp_enqueue_script('ee_error_js');
1029
-            // and display notices
1030
-            foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1031
-                $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1032
-            }
1033
-        }
1034
-        return $notices;
1035
-    }
1036
-
1037
-
1038
-
1039
-    /**
1040
-     * _print_scripts
1041
-     *
1042
-     * @param    bool $force_print
1043
-     * @return    string
1044
-     */
1045
-    private static function _print_scripts($force_print = false)
1046
-    {
1047
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1049
-                return '';
1050
-            }
1051
-            if (wp_script_is('ee_error_js', 'registered')) {
1052
-                add_filter('FHEE_load_css', '__return_true');
1053
-                add_filter('FHEE_load_js', '__return_true');
1054
-                wp_enqueue_script('ee_error_js');
1055
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1056
-            }
1057
-        } else {
1058
-            return '
989
+		}
990
+		return '';
991
+	}
992
+
993
+
994
+
995
+	/**
996
+	 *    get_persistent_admin_notices
997
+	 *
998
+	 * @param string $return_url
999
+	 * @return string
1000
+	 */
1001
+	public static function get_persistent_admin_notices($return_url = '')
1002
+	{
1003
+		$notices = '';
1004
+		// check for persistent admin notices
1005
+		//filter the list though so plugins can notify the admin in a different way if they want
1006
+		$persistent_admin_notices = apply_filters(
1007
+			'FHEE__EE_Error__get_persistent_admin_notices',
1008
+			get_option('ee_pers_admin_notices', false),
1009
+			'ee_pers_admin_notices',
1010
+			$return_url
1011
+		);
1012
+		if ($persistent_admin_notices) {
1013
+			// load scripts
1014
+			wp_register_script(
1015
+				'espresso_core',
1016
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1017
+				array('jquery'),
1018
+				EVENT_ESPRESSO_VERSION,
1019
+				true
1020
+			);
1021
+			wp_register_script(
1022
+				'ee_error_js',
1023
+				EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1024
+				array('espresso_core'),
1025
+				EVENT_ESPRESSO_VERSION,
1026
+				true
1027
+			);
1028
+			wp_enqueue_script('ee_error_js');
1029
+			// and display notices
1030
+			foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1031
+				$notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1032
+			}
1033
+		}
1034
+		return $notices;
1035
+	}
1036
+
1037
+
1038
+
1039
+	/**
1040
+	 * _print_scripts
1041
+	 *
1042
+	 * @param    bool $force_print
1043
+	 * @return    string
1044
+	 */
1045
+	private static function _print_scripts($force_print = false)
1046
+	{
1047
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1049
+				return '';
1050
+			}
1051
+			if (wp_script_is('ee_error_js', 'registered')) {
1052
+				add_filter('FHEE_load_css', '__return_true');
1053
+				add_filter('FHEE_load_js', '__return_true');
1054
+				wp_enqueue_script('ee_error_js');
1055
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1056
+			}
1057
+		} else {
1058
+			return '
1059 1059
 <script>
1060 1060
 /* <![CDATA[ */
1061 1061
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1065,143 +1065,143 @@  discard block
 block discarded – undo
1065 1065
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066 1066
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1067 1067
 ';
1068
-        }
1069
-        return '';
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     *    enqueue_error_scripts
1076
-     *
1077
-     * @return        void
1078
-     */
1079
-    public static function enqueue_error_scripts()
1080
-    {
1081
-        self::_print_scripts();
1082
-    }
1083
-
1084
-
1085
-
1086
-    /**
1087
-     *    create error code from filepath, function name,
1088
-     *    and line number where exception or error was thrown
1089
-     *
1090
-     * @param string $file
1091
-     * @param string $func
1092
-     * @param string $line
1093
-     * @return string
1094
-     */
1095
-    public static function generate_error_code($file = '', $func = '', $line = '')
1096
-    {
1097
-        $file = explode('.', basename($file));
1098
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1099
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1100
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1101
-        return $error_code;
1102
-    }
1103
-
1104
-
1105
-
1106
-    /**
1107
-     *    write exception details to log file
1108
-     *
1109
-     * @param int   $time
1110
-     * @param array $ex
1111
-     * @param bool  $clear
1112
-     * @return void
1113
-     */
1114
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1115
-    {
1116
-        if (empty($ex)) {
1117
-            return;
1118
-        }
1119
-        if (! $time) {
1120
-            $time = time();
1121
-        }
1122
-        $exception_log = '----------------------------------------------------------------------------------------'
1123
-                         . PHP_EOL;
1124
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1130
-        $exception_log .= $ex['string'] . PHP_EOL;
1131
-        $exception_log .= '----------------------------------------------------------------------------------------'
1132
-                          . PHP_EOL;
1133
-        try {
1134
-            EEH_File::ensure_file_exists_and_is_writable(
1135
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1136
-            );
1137
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
-            if (! $clear) {
1139
-                //get existing log file and append new log info
1140
-                $exception_log = EEH_File::get_file_contents(
1141
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
-                ) . $exception_log;
1143
-            }
1144
-            EEH_File::write_to_file(
1145
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1146
-                $exception_log
1147
-            );
1148
-        } catch (EE_Error $e) {
1149
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1150
-                'event_espresso'), $e->getMessage()));
1151
-            return;
1152
-        }
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1159
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1160
-     * but the code execution is done in a manner that could lead to unexpected results
1161
-     * (i.e. running to early, or too late in WP or EE loading process).
1162
-     * A good test for knowing whether to use this method is:
1163
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1164
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1165
-     * 2. If this is loaded before something else, it won't break anything,
1166
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1167
-     *
1168
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1169
-     * @param string $function      The function that was called
1170
-     * @param string $message       A message explaining what has been done incorrectly
1171
-     * @param string $version       The version of Event Espresso where the error was added
1172
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1173
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1174
-     *                              but not have any notices appear until a later version. This allows developers
1175
-     *                              extra time to update their code before notices appear.
1176
-     * @param int    $error_type
1177
-     */
1178
-    public static function doing_it_wrong(
1179
-        $function,
1180
-        $message,
1181
-        $version,
1182
-        $applies_when = '',
1183
-        $error_type = null
1184
-    ) {
1185
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1186
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1187
-        }
1188
-    }
1189
-
1190
-
1191
-
1192
-    /**
1193
-     * Like get_notices, but returns an array of all the notices of the given type.
1194
-     *
1195
-     * @return array {
1196
-     * @type array $success   all the success messages
1197
-     * @type array $errors    all the error messages
1198
-     * @type array $attention all the attention messages
1199
-     * }
1200
-     */
1201
-    public static function get_raw_notices()
1202
-    {
1203
-        return self::$_espresso_notices;
1204
-    }
1068
+		}
1069
+		return '';
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 *    enqueue_error_scripts
1076
+	 *
1077
+	 * @return        void
1078
+	 */
1079
+	public static function enqueue_error_scripts()
1080
+	{
1081
+		self::_print_scripts();
1082
+	}
1083
+
1084
+
1085
+
1086
+	/**
1087
+	 *    create error code from filepath, function name,
1088
+	 *    and line number where exception or error was thrown
1089
+	 *
1090
+	 * @param string $file
1091
+	 * @param string $func
1092
+	 * @param string $line
1093
+	 * @return string
1094
+	 */
1095
+	public static function generate_error_code($file = '', $func = '', $line = '')
1096
+	{
1097
+		$file = explode('.', basename($file));
1098
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1099
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1100
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1101
+		return $error_code;
1102
+	}
1103
+
1104
+
1105
+
1106
+	/**
1107
+	 *    write exception details to log file
1108
+	 *
1109
+	 * @param int   $time
1110
+	 * @param array $ex
1111
+	 * @param bool  $clear
1112
+	 * @return void
1113
+	 */
1114
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1115
+	{
1116
+		if (empty($ex)) {
1117
+			return;
1118
+		}
1119
+		if (! $time) {
1120
+			$time = time();
1121
+		}
1122
+		$exception_log = '----------------------------------------------------------------------------------------'
1123
+						 . PHP_EOL;
1124
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1130
+		$exception_log .= $ex['string'] . PHP_EOL;
1131
+		$exception_log .= '----------------------------------------------------------------------------------------'
1132
+						  . PHP_EOL;
1133
+		try {
1134
+			EEH_File::ensure_file_exists_and_is_writable(
1135
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1136
+			);
1137
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
+			if (! $clear) {
1139
+				//get existing log file and append new log info
1140
+				$exception_log = EEH_File::get_file_contents(
1141
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
+				) . $exception_log;
1143
+			}
1144
+			EEH_File::write_to_file(
1145
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1146
+				$exception_log
1147
+			);
1148
+		} catch (EE_Error $e) {
1149
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1150
+				'event_espresso'), $e->getMessage()));
1151
+			return;
1152
+		}
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1159
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1160
+	 * but the code execution is done in a manner that could lead to unexpected results
1161
+	 * (i.e. running to early, or too late in WP or EE loading process).
1162
+	 * A good test for knowing whether to use this method is:
1163
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1164
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1165
+	 * 2. If this is loaded before something else, it won't break anything,
1166
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1167
+	 *
1168
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1169
+	 * @param string $function      The function that was called
1170
+	 * @param string $message       A message explaining what has been done incorrectly
1171
+	 * @param string $version       The version of Event Espresso where the error was added
1172
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1173
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1174
+	 *                              but not have any notices appear until a later version. This allows developers
1175
+	 *                              extra time to update their code before notices appear.
1176
+	 * @param int    $error_type
1177
+	 */
1178
+	public static function doing_it_wrong(
1179
+		$function,
1180
+		$message,
1181
+		$version,
1182
+		$applies_when = '',
1183
+		$error_type = null
1184
+	) {
1185
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1186
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1187
+		}
1188
+	}
1189
+
1190
+
1191
+
1192
+	/**
1193
+	 * Like get_notices, but returns an array of all the notices of the given type.
1194
+	 *
1195
+	 * @return array {
1196
+	 * @type array $success   all the success messages
1197
+	 * @type array $errors    all the error messages
1198
+	 * @type array $attention all the attention messages
1199
+	 * }
1200
+	 */
1201
+	public static function get_raw_notices()
1202
+	{
1203
+		return self::$_espresso_notices;
1204
+	}
1205 1205
 
1206 1206
 
1207 1207
 
@@ -1217,27 +1217,27 @@  discard block
 block discarded – undo
1217 1217
  */
1218 1218
 function espresso_error_enqueue_scripts()
1219 1219
 {
1220
-    // js for error handling
1221
-    wp_register_script(
1222
-        'espresso_core',
1223
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1224
-        array('jquery'),
1225
-        EVENT_ESPRESSO_VERSION,
1226
-        false
1227
-    );
1228
-    wp_register_script(
1229
-        'ee_error_js',
1230
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1231
-        array('espresso_core'),
1232
-        EVENT_ESPRESSO_VERSION,
1233
-        false
1234
-    );
1220
+	// js for error handling
1221
+	wp_register_script(
1222
+		'espresso_core',
1223
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1224
+		array('jquery'),
1225
+		EVENT_ESPRESSO_VERSION,
1226
+		false
1227
+	);
1228
+	wp_register_script(
1229
+		'ee_error_js',
1230
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1231
+		array('espresso_core'),
1232
+		EVENT_ESPRESSO_VERSION,
1233
+		false
1234
+	);
1235 1235
 }
1236 1236
 
1237 1237
 if (is_admin()) {
1238
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1238
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1239 1239
 } else {
1240
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1240
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1241 1241
 }
1242 1242
 
1243 1243
 
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
             default :
99 99
                 $to = get_option('admin_email');
100 100
         }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
101
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
102 102
         $msg = EE_Error::_format_error($type, $message, $file, $line);
103 103
         if (function_exists('wp_mail')) {
104 104
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105 105
             wp_mail($to, $subject, $msg);
106 106
         }
107 107
         echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
108
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
109 109
         echo '<br /></p></div>';
110 110
     }
111 111
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             ? true
255 255
             : false;
256 256
         if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
257
+            $notices = (array) get_option('ee_notices', array());
258 258
             foreach ($notices as $type => $notice) {
259 259
                 if ($type === $type_to_check && $notice) {
260 260
                     return true;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
334
+        if ( ! WP_DEBUG) {
335 335
             $output .= '
336 336
 	<p>';
337 337
         }
@@ -383,14 +383,14 @@  discard block
 block discarded – undo
383 383
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
384 384
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
385 385
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
386
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
387 387
                     $trace_details .= '
388 388
 					<tr>
389
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
391
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
392
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
389
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
390
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
391
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
392
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
393
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
394 394
 					</tr>';
395 395
                 }
396 396
                 $trace_details .= '
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             }
400 400
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401 401
             // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
402
+            if ( ! WP_DEBUG) {
403 403
                 $output .= '<span class="ee-error-user-msg-spn">'
404 404
                            . trim($ex['msg'])
405 405
                            . '</span> &nbsp; <sup>'
@@ -441,14 +441,14 @@  discard block
 block discarded – undo
441 441
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443 443
                            . $trace_details;
444
-                if (! empty($class)) {
444
+                if ( ! empty($class)) {
445 445
                     $output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449 449
                     $a = new ReflectionClass($class);
450 450
                     $output .= '
451
-						<pre>' . $a . '</pre>
451
+						<pre>' . $a.'</pre>
452 452
 					</div>
453 453
 				</div>';
454 454
                 }
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         }
462 462
         // remove last linebreak
463 463
         $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
464
+        if ( ! WP_DEBUG) {
465 465
             $output .= '
466 466
 	</p>';
467 467
         }
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
     private function _convert_args_to_string($arguments = array(), $array = false)
489 489
     {
490 490
         $arg_string = '';
491
-        if (! empty($arguments)) {
491
+        if ( ! empty($arguments)) {
492 492
             $args = array();
493 493
             foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
494
+                if ( ! empty($arg)) {
495 495
                     if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
496
+                        $args[] = " '".$arg."'";
497 497
                     } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
498
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
499 499
                     } elseif ($arg === null) {
500 500
                         $args[] = ' NULL';
501 501
                     } elseif (is_bool($arg)) {
502 502
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
503 503
                     } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
504
+                        $args[] = ' OBJECT '.get_class($arg);
505 505
                     } elseif (is_resource($arg)) {
506 506
                         $args[] = get_resource_type($arg);
507 507
                     } else {
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
     {
607 607
         if (empty($msg)) {
608 608
             EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
609
+                'EE_Error::add_'.$type.'()',
610 610
                 sprintf(
611 611
                     __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612 612
                         'event_espresso'),
@@ -642,11 +642,11 @@  discard block
 block discarded – undo
642 642
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643 643
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
644 644
         // add notice if message exists
645
-        if (! empty($msg)) {
645
+        if ( ! empty($msg)) {
646 646
             // get error code
647 647
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
648 648
             if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
649
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
650 650
             }
651 651
             // add notice. Index by code if it's not blank
652 652
             if ($notice_code) {
@@ -890,14 +890,14 @@  discard block
 block discarded – undo
890 890
      */
891 891
     public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892 892
     {
893
-        if (! empty($pan_name) && ! empty($pan_message)) {
893
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
894 894
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895 895
             //maybe initialize persistent_admin_notices
896 896
             if (empty($persistent_admin_notices)) {
897 897
                 add_option('ee_pers_admin_notices', array(), '', 'no');
898 898
             }
899 899
             $pan_name = sanitize_key($pan_name);
900
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
900
+            if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901 901
                 $persistent_admin_notices[$pan_name] = $pan_message;
902 902
                 update_option('ee_pers_admin_notices', $persistent_admin_notices);
903 903
             }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
     {
919 919
         $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920 920
             ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
-        if (! empty($pan_name)) {
921
+        if ( ! empty($pan_name)) {
922 922
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923 923
             // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924 924
             if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
      */
962 962
     public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963 963
     {
964
-        if (! empty($pan_name) && ! empty($pan_message)) {
964
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
965 965
             $args = array(
966 966
                 'nag_notice'    => $pan_name,
967 967
                 'return_url'    => urlencode($return_url),
@@ -1013,14 +1013,14 @@  discard block
 block discarded – undo
1013 1013
             // load scripts
1014 1014
             wp_register_script(
1015 1015
                 'espresso_core',
1016
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1016
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1017 1017
                 array('jquery'),
1018 1018
                 EVENT_ESPRESSO_VERSION,
1019 1019
                 true
1020 1020
             );
1021 1021
             wp_register_script(
1022 1022
                 'ee_error_js',
1023
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1023
+                EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1024 1024
                 array('espresso_core'),
1025 1025
                 EVENT_ESPRESSO_VERSION,
1026 1026
                 true
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      */
1045 1045
     private static function _print_scripts($force_print = false)
1046 1046
     {
1047
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1047
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048 1048
             if (wp_script_is('ee_error_js', 'enqueued')) {
1049 1049
                 return '';
1050 1050
             }
@@ -1058,12 +1058,12 @@  discard block
 block discarded – undo
1058 1058
             return '
1059 1059
 <script>
1060 1060
 /* <![CDATA[ */
1061
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1061
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1062 1062
 /* ]]> */
1063 1063
 </script>
1064
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1065
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1064
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1065
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1066
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1067 1067
 ';
1068 1068
         }
1069 1069
         return '';
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
     {
1097 1097
         $file = explode('.', basename($file));
1098 1098
         $error_code = ! empty($file[0]) ? $file[0] : '';
1099
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1100
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1099
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1100
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1101 1101
         return $error_code;
1102 1102
     }
1103 1103
 
@@ -1116,33 +1116,33 @@  discard block
 block discarded – undo
1116 1116
         if (empty($ex)) {
1117 1117
             return;
1118 1118
         }
1119
-        if (! $time) {
1119
+        if ( ! $time) {
1120 1120
             $time = time();
1121 1121
         }
1122 1122
         $exception_log = '----------------------------------------------------------------------------------------'
1123 1123
                          . PHP_EOL;
1124
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1130
-        $exception_log .= $ex['string'] . PHP_EOL;
1124
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1125
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1126
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1127
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1128
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1129
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1130
+        $exception_log .= $ex['string'].PHP_EOL;
1131 1131
         $exception_log .= '----------------------------------------------------------------------------------------'
1132 1132
                           . PHP_EOL;
1133 1133
         try {
1134 1134
             EEH_File::ensure_file_exists_and_is_writable(
1135
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1135
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1136 1136
             );
1137
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
-            if (! $clear) {
1137
+            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
1138
+            if ( ! $clear) {
1139 1139
                 //get existing log file and append new log info
1140 1140
                 $exception_log = EEH_File::get_file_contents(
1141
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
-                ) . $exception_log;
1141
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1142
+                ).$exception_log;
1143 1143
             }
1144 1144
             EEH_File::write_to_file(
1145
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1145
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file,
1146 1146
                 $exception_log
1147 1147
             );
1148 1148
         } catch (EE_Error $e) {
@@ -1220,14 +1220,14 @@  discard block
 block discarded – undo
1220 1220
     // js for error handling
1221 1221
     wp_register_script(
1222 1222
         'espresso_core',
1223
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1223
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1224 1224
         array('jquery'),
1225 1225
         EVENT_ESPRESSO_VERSION,
1226 1226
         false
1227 1227
     );
1228 1228
     wp_register_script(
1229 1229
         'ee_error_js',
1230
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1230
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1231 1231
         array('espresso_core'),
1232 1232
         EVENT_ESPRESSO_VERSION,
1233 1233
         false
Please login to merge, or discard this patch.